diff --git a/src/main/java/com/glxp/api/controller/inout/IoOrderController.java b/src/main/java/com/glxp/api/controller/inout/IoOrderController.java index 27826c7f..6144db73 100644 --- a/src/main/java/com/glxp/api/controller/inout/IoOrderController.java +++ b/src/main/java/com/glxp/api/controller/inout/IoOrderController.java @@ -1,6 +1,8 @@ package com.glxp.api.controller.inout; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; @@ -9,9 +11,11 @@ import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.BusinessType; +import com.glxp.api.constant.Constant; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.auth.InvBusUserEntity; +import com.glxp.api.entity.auth.InvWarehouseEntity; import com.glxp.api.entity.basic.BasicBussinessTypeEntity; import com.glxp.api.entity.basic.EntrustReceEntity; import com.glxp.api.entity.inout.*; @@ -26,9 +30,13 @@ import com.glxp.api.res.inout.IoOrderDetailCodeResponse; import com.glxp.api.res.inout.IoOrderResponse; import com.glxp.api.res.inout.PdaBusOrderResponse; import com.glxp.api.service.auth.InvBusUserService; +import com.glxp.api.service.auth.InvWarehouseService; import com.glxp.api.service.basic.EntrustReceService; import com.glxp.api.service.basic.IBasicBussinessTypeService; import com.glxp.api.service.inout.*; +import com.glxp.api.util.CustomUtil; +import com.glxp.api.util.GennerOrderUtils; +import com.glxp.api.util.OrderNoTypeBean; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -40,10 +48,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; import static com.glxp.api.constant.ConstantStatus.ORDER_STATUS_CHECK_PROCESS; @@ -683,4 +689,108 @@ public class IoOrderController extends BaseController { return ResultVOUtils.success(); } + + @Resource + GennerOrderUtils gennerOrderUtils; + @Resource + InvWarehouseService invWarehouseService; + + @AuthRuleAnnotation("") + @PostMapping("/udiwms/stock/order/change") + public BaseResponse stockOrderChange(@RequestBody AddOrderChangeRequest addOrderChangeRequest) { + + + IoOrderEntity originOrder = orderService.findByBillNo(addOrderChangeRequest.getOrderId()); + IoOrderEntity newOrder = new IoOrderEntity(); + List originCodes = codeService.findByOrderId(originOrder.getBillNo()); + newOrder.setCreateTime(new Date()); + newOrder.setFromCorp(addOrderChangeRequest.getFromCorp()); + + newOrder.setFromInvCode(addOrderChangeRequest.getFromInvCode()); + if (addOrderChangeRequest.getFromInvCode() != null) { + InvWarehouseEntity fromInv = invWarehouseService.findByInvSubByCode(addOrderChangeRequest.getFromInvCode()); + newOrder.setFromDeptCode(fromInv.getParentId()); + } + + + InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderChangeRequest.getInvCode()); + newOrder.setInvCode(addOrderChangeRequest.getInvCode()); + newOrder.setDeptCode(invWarehouseEntity.getParentId()); + newOrder.setCorpOrderId(CustomUtil.getId() + "x"); + + BasicBussinessTypeEntity basicBussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderChangeRequest.getAction()); + newOrder.setAction(addOrderChangeRequest.getAction()); + newOrder.setMainAction(basicBussinessTypeEntity.getMainAction()); + newOrder.setRelKey(originOrder.getRelKey()); + newOrder.setExportStatus(0); //设置导出状态为未导出 + newOrder.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);//设置单据未草稿状态 + newOrder.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE); //设置验收状态为未验收 + newOrder.setFromType(ConstantStatus.FROM_COPY); + newOrder.setOrderType(2); + BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderChangeRequest.getAction()); + String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); + String supplementOrderNo = orderNo; + newOrder.setBillNo(supplementOrderNo); + newOrder.setReplicateNo(null); //新单据的复制单号置空 + originOrder.setReplicateNo(orderNo); + List supplementCodes = new ArrayList<>(); + + List products = addOrderChangeRequest.getProducts(); + List orderDetailBizEntities = orderDetailBizService.findByOrderId(originOrder.getBillNo()); + // 计算出两个集合之间产品批次号组成的差异 + List IoStatDayEntityList = orderDetailBizEntities.stream() + .filter(comment -> products.stream() + .anyMatch(p -> Objects.equals(p.getBatchNo(), comment.getBatchNo()) // 使用 Objects.equals 来进行非空判断 + && Objects.equals(p.getRelId(), comment.getBindRlFk()))) + .collect(Collectors.toList()); + //生成业务单 + if (CollUtil.isNotEmpty(IoStatDayEntityList)) { + for (IoOrderDetailBizEntity orderDetailBizEntity : IoStatDayEntityList) { + orderDetailBizEntity.setOrderIdFk(newOrder.getBillNo()); + orderDetailBizEntity.setId(IdUtil.getSnowflakeNextId()); + orderDetailBizService.insert(orderDetailBizEntity); + } + } + + + originCodes.forEach( + code -> { + //复制选中的产品 + for (IoCodeEntity product : products) { + if (product.getRelId().equals(code.getRelId())) { + if ((StrUtil.isNotBlank(product.getBatchNo()) && StrUtil.isNotBlank(code.getBatchNo()) && product.getBatchNo().equals(code.getBatchNo())) + || (StrUtil.isBlank(product.getBatchNo()) && StrUtil.isBlank(code.getBatchNo()))) { + IoCodeTempEntity supplementCode = new IoCodeTempEntity(); + BeanUtil.copyProperties(code, supplementCode); + supplementCode.setInvCode(newOrder.getInvCode()); + supplementCode.setDeptCode(newOrder.getDeptCode()); + supplementCode.setOrderId(newOrder.getBillNo()); + supplementCode.setCorpOrderId(newOrder.getCorpOrderId()); + //查询补单设置 + supplementCode.setAction(newOrder.getAction()); + supplementCode.setMainAction(newOrder.getMainAction()); + supplementCode.setUpdateTime(new Date()); + supplementCode.setCreateTime(new Date()); + supplementCode.setId(null); + supplementCodes.add(supplementCode); + break; + } + } + } + } + ); + newOrder.setUpdateTime(new Date()); + orderService.insertOrder(newOrder); + codeTempService.insertBatch(supplementCodes); + orderService.update(originOrder); + + ioAddInoutService.dealProcess(newOrder); + //不需要手动校验,则走正常单据校验处理流程 + if (!ioCheckInoutService.checkManual(newOrder.getBillNo())) { + ioCheckInoutService.check(newOrder.getBillNo()); + } + + return ResultVOUtils.success(); + } + } diff --git a/src/main/java/com/glxp/api/req/inout/AddOrderChangeRequest.java b/src/main/java/com/glxp/api/req/inout/AddOrderChangeRequest.java new file mode 100644 index 00000000..9c190c0d --- /dev/null +++ b/src/main/java/com/glxp/api/req/inout/AddOrderChangeRequest.java @@ -0,0 +1,27 @@ +package com.glxp.api.req.inout; + +import com.glxp.api.entity.inout.IoCodeEntity; +import lombok.Data; + +import java.util.List; + + +@Data +public class AddOrderChangeRequest { + + private String corpOrderId; + private String mainAction; + private String action; + private String fromCorp; + private String fromDeptCode; + private String fromInvCode; + private Integer fromType; + private String actDate; + private String deptCode; + private String invCode; + private String orderId; + + private List products; + + +} diff --git a/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java b/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java index ea428065..aa69a6ca 100644 --- a/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java +++ b/src/main/java/com/glxp/api/service/inout/IoCheckInoutService.java @@ -304,16 +304,20 @@ public class IoCheckInoutService { orderDetailBizService.deleteByOrderId(orderEntity.getBillNo()); } orderDetailResultService.deleteByOrderId(orderEntity.getBillNo()); + if (!orderDetailBizService.isExit(orderEntity.getBillNo())) { + orderDetailCodeEntities.forEach(orderDetailCodeEntity -> + { + //生成业务单据 + IoOrderDetailBizEntity orderDetailBizEntity = new IoOrderDetailBizEntity(); + BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailBizEntity); + orderDetailBizEntity.setCount(orderDetailCodeEntity.getReCount()); + orderDetailBizEntity.setId(null); + orderDetailBizService.insert(orderDetailBizEntity); + }); + + } orderDetailCodeEntities.forEach(orderDetailCodeEntity -> { - //生成业务单据 - IoOrderDetailBizEntity orderDetailBizEntity = new IoOrderDetailBizEntity(); - BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailBizEntity); - orderDetailBizEntity.setCount(orderDetailCodeEntity.getReCount()); - orderDetailBizEntity.setId(null); - orderDetailBizService.insert(orderDetailBizEntity); - - //生成单据结果 IoOrderDetailResultEntity orderDetailResultEntity = new IoOrderDetailResultEntity(); BeanUtils.copyProperties(orderDetailCodeEntity, orderDetailResultEntity);