package com.glxp.api.controller.purchase; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.annotation.RepeatSubmit; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.Constant; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.entity.basic.BasicCorpEntity; import com.glxp.api.entity.purchase.PurApplyDetailEntity; import com.glxp.api.entity.purchase.PurApplyEntity; import com.glxp.api.entity.purchase.PurPlanDetailEntity; import com.glxp.api.entity.purchase.PurPlanEntity; import com.glxp.api.req.purchase.PostPurPlanRequest; import com.glxp.api.req.purchase.PurApplyDetailRequest; import com.glxp.api.req.purchase.PurPlanDetailRequest; import com.glxp.api.req.purchase.PurPlanRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.UdiRelevanceResponse; import com.glxp.api.res.purchase.PurPlanResponse; import com.glxp.api.service.auth.CustomerService; import com.glxp.api.service.basic.BasicCorpService; import com.glxp.api.service.basic.UdiRelevanceService; import com.glxp.api.service.purchase.PurApplyDetailService; import com.glxp.api.service.purchase.PurApplyService; import com.glxp.api.service.purchase.PurPlanDetailService; import com.glxp.api.service.purchase.PurPlanService; import com.glxp.api.util.GennerOrderUtils; import com.glxp.api.util.OrderNoTypeBean; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.constraints.NotEmpty; import java.util.*; import java.util.stream.Collectors; /** * pur * * @author anthony.ywj * @date 2022-10-12 */ @Validated @RequiredArgsConstructor @RestController public class PurPlanController { @Resource PurPlanService purPlanService; @Resource PurApplyService purApplyService; @Resource PurApplyDetailService purApplyDetailService; @Resource PurPlanDetailService purPlanDetailService; @Resource CustomerService customerService; // @Resource // GennerOrderUtils gennerOrderUtils; // @Resource // BasicCorpService basicCorpService; // @Resource // UdiRelevanceService udiRelevanceService; // @Resource // StockOrderDetailService stockOrderDetailService; // // @Resource // StockOrderService stockOrderService; // // /** // * 新增采购计划 // */ // @RepeatSubmit() // @AuthRuleAnnotation("") // @PostMapping("/purchase/plan/postOrder") // public BaseResponse postOrder(@RequestBody PostPurPlanRequest postPurPlanRequest) { // // Long userId = customerService.getUserId(); // PurPlanEntity purApplyEntity = postPurPlanRequest.getPurPlanEntity(); // // purApplyEntity.setCreateUser(userId + ""); // purApplyEntity.setCreateTime(new Date()); // purApplyEntity.setUpdateTime(new Date()); // purApplyEntity.setStatus(postPurPlanRequest.getEditStatus()); //草稿状态 // if (purApplyEntity.getId() == null) { // String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.JH_ORDER, "yyyyMMdd")); // purApplyEntity.setBillNo(billNo); // purPlanService.insert(purApplyEntity); // } else { // purPlanService.update(purApplyEntity); // if (CollUtil.isNotEmpty(postPurPlanRequest.getSubErpOrders())) { // purPlanDetailService.deleteByOrderId(purApplyEntity.getId() + ""); // } // } // List purPlanDetailEntities = new ArrayList<>(); // if (CollUtil.isNotEmpty(postPurPlanRequest.getSubErpOrders())) { // for (StockOrderDetailEntity stockOrderDetailEntity : postPurPlanRequest.getSubErpOrders()) { // PurPlanDetailEntity purApplyDetailEntity = new PurPlanDetailEntity(); // BeanUtils.copyProperties(stockOrderDetailEntity, purApplyDetailEntity); // purApplyDetailEntity.setOrderIdFk(purApplyEntity.getId() + ""); // purApplyDetailEntity.setCount(Integer.valueOf(stockOrderDetailEntity.getCount())); // purPlanDetailService.insert(purApplyDetailEntity); // purPlanDetailEntities.add(purApplyDetailEntity); // } // } // // // return ResultVOUtils.success("提交成功!"); // } // // /** * 查询采购计划列表 */ @GetMapping("/purchase/plan/list") public BaseResponse list(PurPlanRequest purApplyRequest) { if (purApplyRequest.getStatus() == null) { purApplyRequest.setStatus(11); //查询未审核和草稿状态 } List purApplyEntities = purPlanService.queryPageList(purApplyRequest); PageInfo pageInfo; pageInfo = new PageInfo<>(purApplyEntities); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(purApplyEntities); return ResultVOUtils.success(pageSimpleResponse); } // // // /** // * 查询采购计划列表 // */ // @GetMapping("/purchase/plan/auditList") // public BaseResponse auditList(PurPlanRequest purApplyRequest) { // // if (purApplyRequest.getStatus() == null) { // purApplyRequest.setStatus(10); //查询未审核和已审核状态 // } // List purApplyEntities = purPlanService.queryPageList(purApplyRequest); // PageInfo pageInfo; // pageInfo = new PageInfo<>(purApplyEntities); // PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); // pageSimpleResponse.setTotal(pageInfo.getTotal()); // pageSimpleResponse.setList(purApplyEntities); // return ResultVOUtils.success(pageSimpleResponse); // // } // // // /** // * 审核采购计划 // */ // @RepeatSubmit() // @PostMapping("/purchase/plan/auditOrder") // public BaseResponse auditOrder(@RequestBody PostPurPlanRequest postPurPlanRequest) { // Long userId = customerService.getUserId(); // PurPlanEntity purApplyEntity = postPurPlanRequest.getPurPlanEntity(); // purApplyEntity.setUpdateTime(new Date()); // purApplyEntity.setAuditUser(userId + ""); // purApplyEntity.setStatus(postPurPlanRequest.getEditStatus()); // purPlanService.update(purApplyEntity); // // List purPlanDetailEntities = purPlanDetailService.findByOrderId(purApplyEntity.getId() + ""); // //// BasicBusTypeChangeEntity basicBusTypeChangeEntity = basicBusTypeChangeService.findByAction(purApplyEntity.getBillType()); // //转换成业务单据 // if (postPurPlanRequest.getEditStatus() == ConstantStatus.APPLY_AUDIT_ED // && StrUtil.isNotEmpty(purApplyEntity.getTargetSubInv()) && StrUtil.isNotEmpty(purApplyEntity.getTargetBillAction())) { // // if (CollUtil.isNotEmpty(purPlanDetailEntities)) { // //1.根据供应商分组 // Map> filterSupMaps = new HashMap<>(); // for (PurPlanDetailEntity purPlanDetailEntity : purPlanDetailEntities) { // if (StrUtil.isNotEmpty(purPlanDetailEntity.getSupId())) { // if (filterSupMaps.get(purPlanDetailEntity.getSupId()) == null) { // List temps = new ArrayList<>(); // temps.add(purPlanDetailEntity); // filterSupMaps.put(purPlanDetailEntity.getSupId(), temps); // } else { // filterSupMaps.get(purPlanDetailEntity.getSupId()).add(purPlanDetailEntity); // } // } // } // //2.生成业务单据 // String stockOrderNo = ";"; // for (String supId : filterSupMaps.keySet()) { // //2.构建业务单据 // StockOrderEntity stockOrderEntity = new StockOrderEntity(); // String billNo = gennerOrderUtils.createStOrderNo(new OrderNoTypeBean(Constant.BUS_ORDER, "yyyyMMdd")); // stockOrderNo = stockOrderNo + billNo; // stockOrderEntity.setBillNo(billNo); // stockOrderEntity.setSourceType(ConstantStatus.ST_APPLY_ADD); // stockOrderEntity.setCorpId(supId); // stockOrderEntity.setUnitIdFk(supId); // BasicCorpEntity basicCorpEntity = basicCorpService.selectByErpId(supId); // stockOrderEntity.setCorpName(basicCorpEntity.getName()); // stockOrderEntity.setBilldate(DateUtil.formatDateTime(new Date())); // stockOrderEntity.setStatus(ConstantStatus.SORDER_ALLOC); // stockOrderEntity.setBillType(purApplyEntity.getTargetBillAction()); // stockOrderEntity.setInvWarehouseCode(purApplyEntity.getTargetSubInv()); // stockOrderEntity.setLocStorageCode(purApplyEntity.getTargetInv()); // stockOrderEntity.setCreateUser(userId); //// stockOrderEntity.setDept(purApplyEntity.getDeptCode()); // stockOrderService.insertStockOrder(stockOrderEntity); // //3.构建单据详情 // List temps = filterSupMaps.get(supId); // if (CollUtil.isNotEmpty(temps)) { // List stockOrderDetailEntities = new ArrayList<>(); // for (PurPlanDetailEntity purPlanDetailEntity : temps) { // StockOrderDetailEntity stockOrderDetailEntity = new StockOrderDetailEntity(); // UdiRelevanceResponse udiRelevanceEntity = udiRelevanceService.selectGroupById(purPlanDetailEntity.getProductId()); // stockOrderDetailEntity.setProductName(udiRelevanceEntity.getCpmctymc()); // stockOrderDetailEntity.setRelId(udiRelevanceEntity.getId() + ""); // stockOrderDetailEntity.setProductId(udiRelevanceEntity.getId() + ""); // stockOrderDetailEntity.setSpec(udiRelevanceEntity.getGgxh()); // stockOrderDetailEntity.setCount(purPlanDetailEntity.getCount()); // stockOrderDetailEntity.setReCount(purPlanDetailEntity.getCount()); // stockOrderDetailEntity.setManufactory(udiRelevanceEntity.getManufactory()); // stockOrderDetailEntity.setYlqxzcrbarmc(udiRelevanceEntity.getYlqxzcrbarmc()); // stockOrderDetailEntity.setZczbhhzbapzbh(udiRelevanceEntity.getZczbhhzbapzbh()); // stockOrderDetailEntity.setMeasname(udiRelevanceEntity.getMeasname()); // stockOrderDetailEntity.setOrderIdFk(stockOrderEntity.getId()); // stockOrderDetailEntities.add(stockOrderDetailEntity); // } // if (CollUtil.isNotEmpty(stockOrderDetailEntities)) { // stockOrderDetailService.insertStockOrderDetails(stockOrderDetailEntities); // } // } // } // // purApplyEntity.setStockOrderNo(stockOrderNo.substring(1)); // purPlanService.update(purApplyEntity); // } // } // return ResultVOUtils.success("更新成功!"); // } // // // /** // * 新增采购计划 // */ // @RepeatSubmit() // @PostMapping("/purchase/plan") // public BaseResponse add(@RequestBody PurPlanEntity purApplyRequest) { // // purPlanService.insert(purApplyRequest); // return ResultVOUtils.success("新增成功!"); // } // // /** // * 修改采购计划 // */ // @RepeatSubmit() // @PutMapping("/purchase/plan") // public BaseResponse edit(@RequestBody PurPlanEntity purApplyRequest) { // purPlanService.update(purApplyRequest); // return ResultVOUtils.success("删除成功"); // } // // //// /** //// * 查询采购计划列表 //// */ //// @GetMapping("/purchase/plan/list/detail") //// public BaseResponse detailList(PurPlanDetailRequest purApplyDetailRequest) { //// //// List purApplyDetailEntities = purPlanDetailService.joinQueryList(purApplyDetailRequest); //// PageInfo pageInfo; //// pageInfo = new PageInfo<>(purApplyDetailEntities); //// PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); //// pageSimpleResponse.setTotal(pageInfo.getTotal()); //// pageSimpleResponse.setList(purApplyDetailEntities); //// return ResultVOUtils.success(pageSimpleResponse); //// //// } // // // /** // * 删除采购计划 // * // * @param ids 主键串 // */ // @DeleteMapping("/purchase/plan/{ids}") // public BaseResponse remove(@NotEmpty(message = "主键不能为空") // @PathVariable Integer[] ids) { // // // List idArray = Arrays.asList(ids); // if (CollUtil.isNotEmpty(idArray)) { // purPlanService.deleteByIds(idArray); // for (Integer id : idArray) { // purPlanDetailService.deleteByOrderId(id + ""); // } // } // return ResultVOUtils.success("删除成功"); // // } // // // /** // * 新增采购计划 // */ // @RepeatSubmit() // @PostMapping("/purchase/plan/detail") // public BaseResponse detailAdd(@RequestBody PurPlanDetailEntity purPlanDetailRequest) { // // purPlanDetailService.insert(purPlanDetailRequest); // return ResultVOUtils.success("新增成功"); // } // // /** // * 修改采购计划 // */ // @RepeatSubmit() // @PutMapping("/purchase/plan/detail") // public BaseResponse detailEdit(@RequestBody PurPlanDetailEntity purPlanDetailRequest) { // purPlanDetailService.update(purPlanDetailRequest); // return ResultVOUtils.success("修改成功"); // } // // /** // * 删除采购计划 // * // * @param ids 主键串 // */ // @DeleteMapping("/purchase/plan/detail/{ids}") // public BaseResponse detailRemove(@NotEmpty(message = "主键不能为空") // @PathVariable Long[] ids) { // // purPlanDetailService.deleteByIds(Arrays.asList(ids)); // return ResultVOUtils.success("删除成功"); // } /** * 添加申购单到采购单里面 */ @PostMapping("/purchase/plan/addPlanDetail") public BaseResponse addPlanDetail(@RequestBody PurPlanRequest purApplyRequest) { if (purApplyRequest.getRId() == null && purApplyRequest.getId() == null) { return ResultVOUtils.error(999,"参数错误!"); } //查询申购单详情 PurApplyDetailRequest purApplyDetailRequest=new PurApplyDetailRequest(); purApplyDetailRequest.setOrderIdFk(purApplyRequest.getRId()); List purApplyDetailEntityList=purApplyDetailService.selectPurApplyDetailList(purApplyDetailRequest); //使用stream拷贝list List purPlanDetailEntityList = purApplyDetailEntityList.stream() .map(e-> { PurPlanDetailEntity d = new PurPlanDetailEntity(); BeanUtils.copyProperties(e, d); return d; }) .collect(Collectors.toList()); for (PurPlanDetailEntity obj:purPlanDetailEntityList){ obj.setOrderIdFk(purApplyRequest.getId()+""); } boolean falg= purPlanDetailService.insertPurPlanDetailEntity(purPlanDetailEntityList); if(falg){ //查询申购单 return ResultVOUtils.success("添加成功"); }else{ return ResultVOUtils.success("添加失败"); } } /** * 新增计划单 */ @AuthRuleAnnotation("") @PostMapping("/purchase/plan/add") public BaseResponse add() { Long userId = customerService.getUserId(); PurPlanEntity purPlanEntity= new PurPlanEntity(); purPlanEntity.setCreateUser(userId + ""); purPlanEntity.setCreateTime(new Date()); purPlanEntity.setUpdateTime(new Date()); purPlanEntity.setUpdateUser(userId + ""); purPlanService.insert(purPlanEntity); Long id=purPlanEntity.getId(); return ResultVOUtils.success(id); } }