diff --git a/src/main/java/com/glxp/udi/admin/controller/product/StackCodeController.java b/src/main/java/com/glxp/udi/admin/controller/product/StackCodeController.java index 24cd4de..7630125 100644 --- a/src/main/java/com/glxp/udi/admin/controller/product/StackCodeController.java +++ b/src/main/java/com/glxp/udi/admin/controller/product/StackCodeController.java @@ -7,10 +7,12 @@ import com.glxp.udi.admin.common.res.BaseResponse; import com.glxp.udi.admin.common.util.ResultVOUtils; import com.glxp.udi.admin.entity.product.StackCode; import com.glxp.udi.admin.req.inout.DeleteRequest; +import com.glxp.udi.admin.req.product.AddStackCodeRequest; import com.glxp.udi.admin.req.product.FilterStackCodeRequest; import com.glxp.udi.admin.res.PageSimpleResponse; import com.glxp.udi.admin.service.product.StackCodeService; import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -61,4 +63,20 @@ public class StackCodeController { return ResultVOUtils.success("删除成功"); } + /** + * 网页端建垛添加垛码接口 + * + * @param addStackCodeRequest + * @param bindingResult + * @return + */ + @PostMapping("/udims/stack/code/addCode") + public BaseResponse addStackCode(@RequestBody AddStackCodeRequest addStackCodeRequest, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + StackCode stackCode = stackCodeService.addCode(addStackCodeRequest); + return ResultVOUtils.success(stackCode); + } + } diff --git a/src/main/java/com/glxp/udi/admin/controller/product/StackOrderController.java b/src/main/java/com/glxp/udi/admin/controller/product/StackOrderController.java index 1cda588..274df76 100644 --- a/src/main/java/com/glxp/udi/admin/controller/product/StackOrderController.java +++ b/src/main/java/com/glxp/udi/admin/controller/product/StackOrderController.java @@ -51,11 +51,11 @@ public class StackOrderController { @AuthRuleAnnotation("") @PostMapping("/udims/stack/order/update") - public BaseResponse updateStack(@RequestBody StackOrder stackOrderEntity, BindingResult bindingResult) { + public BaseResponse updateStack(@RequestBody StackUploadRequest stackUploadRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } - stackOrderService.updateOrder(stackOrderEntity); + stackOrderService.updateOrder(stackUploadRequest); return ResultVOUtils.success("更新成功"); } diff --git a/src/main/java/com/glxp/udi/admin/req/product/AddStackCodeRequest.java b/src/main/java/com/glxp/udi/admin/req/product/AddStackCodeRequest.java new file mode 100644 index 0000000..100000c --- /dev/null +++ b/src/main/java/com/glxp/udi/admin/req/product/AddStackCodeRequest.java @@ -0,0 +1,27 @@ +package com.glxp.udi.admin.req.product; + +import lombok.Data; + +/** + * 建垛添加条码数据请求参数 + */ +@Data +public class AddStackCodeRequest { + + /** + * 垛码 + */ + private String orderId; + + /** + * 码 + */ + private String code; + + /** + * 客户ID + */ + private String customerId; + + +} diff --git a/src/main/java/com/glxp/udi/admin/service/product/StackCodeService.java b/src/main/java/com/glxp/udi/admin/service/product/StackCodeService.java index 1cc3d57..42a69e1 100644 --- a/src/main/java/com/glxp/udi/admin/service/product/StackCodeService.java +++ b/src/main/java/com/glxp/udi/admin/service/product/StackCodeService.java @@ -6,8 +6,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.glxp.udi.admin.dao.product.StackCodeDao; +import com.glxp.udi.admin.dao.product.StackOrderDao; import com.glxp.udi.admin.entity.product.StackCode; +import com.glxp.udi.admin.entity.product.StackOrder; +import com.glxp.udi.admin.req.product.AddStackCodeRequest; import com.glxp.udi.admin.req.product.FilterStackCodeRequest; +import com.glxp.udi.admin.util.IdUtil; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -16,6 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; import java.util.List; @Service @@ -27,6 +32,10 @@ public class StackCodeService { private SqlSessionFactory sqlSessionFactory; @Resource private StackCodeDao stackCodeDao; + @Resource + private StackOrderDao stackOrderDao; + @Resource + private IdUtil idUtil; public void batchInsert(List stackCodeEntityList) { @@ -38,8 +47,6 @@ public class StackCodeService { }); batchSession.commit(); } - - } /** @@ -64,4 +71,33 @@ public class StackCodeService { public void deleteById(String id) { stackCodeDao.deleteById(id); } + + /** + * 添加垛码 + * + * @param addStackCodeRequest + * @return + */ + public StackCode addCode(AddStackCodeRequest addStackCodeRequest) { + StackCode stackCode = new StackCode(); + stackCode.setCode(addStackCodeRequest.getCode()); + if (StrUtil.isBlank(addStackCodeRequest.getOrderId())) { + //垛号为空,此条码为这个垛的第一个条码数据,先生垛号和垛数据,再添加条码 + String stackId = idUtil.getStackId(addStackCodeRequest.getCustomerId()); + stackCode.setOrderIdFk(stackId); + //创建垛数据 + StackOrder stackOrder = new StackOrder(); + //垛码 + stackOrder.setOrderId(stackId); + stackOrder.setCreateTime(new Date()); + stackOrder.setExportStatus(0); + stackOrder.setCustomerId(addStackCodeRequest.getCustomerId()); + stackOrderDao.insert(stackOrder); + } else { + stackCode.setOrderIdFk(addStackCodeRequest.getOrderId()); + } + int id = stackCodeDao.insert(stackCode); + stackCode.setId(id); + return stackCode; + } } diff --git a/src/main/java/com/glxp/udi/admin/service/product/StackOrderService.java b/src/main/java/com/glxp/udi/admin/service/product/StackOrderService.java index 6f6358b..42ca352 100644 --- a/src/main/java/com/glxp/udi/admin/service/product/StackOrderService.java +++ b/src/main/java/com/glxp/udi/admin/service/product/StackOrderService.java @@ -1,18 +1,27 @@ package com.glxp.udi.admin.service.product; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.glxp.udi.admin.dao.product.StackCodeDao; import com.glxp.udi.admin.dao.product.StackOrderDao; +import com.glxp.udi.admin.entity.product.StackCode; import com.glxp.udi.admin.entity.product.StackOrder; import com.glxp.udi.admin.req.product.StackOrderFilterRequest; +import com.glxp.udi.admin.req.product.StackUploadRequest; import com.glxp.udi.admin.util.IdUtil; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.TransactionIsolationLevel; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; +import java.util.List; @Service @Transactional(rollbackFor = Exception.class) @@ -24,6 +33,8 @@ public class StackOrderService { private IdUtil idUtil; @Resource private StackCodeDao stackCodeDao; + @Resource + private SqlSessionFactory sqlSessionFactory; public IPage filterList(StackOrderFilterRequest stackOrderFilterRequest) { @@ -40,8 +51,25 @@ public class StackOrderService { } - public void updateOrder(StackOrder stackOrderEntity) { - stackOrderDao.updateById(stackOrderEntity); + public void updateOrder(StackUploadRequest stackUploadRequest) { + //更新垛数据 + stackOrderDao.updateById(stackUploadRequest.getStackOrderEntity()); + //更新码详情 + if (CollUtil.isNotEmpty(stackUploadRequest.getStackCodeEntityList())) { + stackUploadRequest.getStackCodeEntityList().forEach(stackCode -> {stackCode.setOrderIdFk(stackUploadRequest.getStackOrderEntity().getOrderId());}); + SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED); + StackCodeDao mapper = batchSession.getMapper(StackCodeDao.class); + List stackCodeEntityList = stackUploadRequest.getStackCodeEntityList(); + for (StackCode stackCode : stackCodeEntityList) { + if (null != stackCode.getId()) { + mapper.updateById(stackCode); + } else { + mapper.insert(stackCode); + } + } + batchSession.commit(); + batchSession.close(); + } } public boolean isExit(String orderId) { @@ -51,6 +79,9 @@ public class StackOrderService { public String insertOrder(StackOrder stackOrderEntity) { String stackId = idUtil.getStackId(stackOrderEntity.getCustomerId()); stackOrderEntity.setOrderId(stackId); + if (null == stackOrderEntity.getCreateTime()) { + stackOrderEntity.setCreateTime(new Date()); + } stackOrderDao.insert(stackOrderEntity); return stackId; }