|
|
@@ -1,13 +1,36 @@
|
|
|
package com.dk.mdm.service.ivt;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.dk.common.exception.BaseBusinessException;
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
+import com.dk.common.response.ResponseCodeEnum;
|
|
|
+import com.dk.common.response.ResponseResultUtil;
|
|
|
+import com.dk.common.response.ResponseResultVO;
|
|
|
+import com.dk.mdm.infrastructure.convert.ivt.OutboundConvert;
|
|
|
+import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
|
|
|
+import com.dk.mdm.mapper.ivt.OutboundItemMapper;
|
|
|
import com.dk.mdm.model.pojo.ivt.Outbound;
|
|
|
import com.dk.mdm.mapper.ivt.OutboundMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
+import com.dk.mdm.model.pojo.ivt.OutboundItem;
|
|
|
+import com.dk.mdm.model.query.ivt.OutboundItemQuery;
|
|
|
+import com.dk.mdm.model.response.ivt.OutboundItemResponse;
|
|
|
+import com.dk.mdm.model.response.ivt.OutboundResponse;
|
|
|
+import com.dk.mdm.model.vo.ivt.OutboundItemVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.OutboundVO;
|
|
|
+import com.dk.mdm.service.common.CommonService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class OutboundService extends BaseService<Outbound> {
|
|
|
@@ -20,4 +43,91 @@ public class OutboundService extends BaseService<Outbound> {
|
|
|
@Autowired
|
|
|
private OutboundMapper outboundMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OutboundItemService outboundItemService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutboundItemMapper outboundItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutboundConvert outboundConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutboundItemConvert outboundItemConvert;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建方法
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2023/1/9 10:49
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<?> insert(OutboundVO outboundVO) {
|
|
|
+
|
|
|
+ // 获取单号
|
|
|
+ Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OUTBOUND.getName(),false);
|
|
|
+ outboundVO.setOutId(codeMap.get("outId").toString()).setOutNo(codeMap.get("outNote").toString()).setOutType(Constant.OutType.SALE.getName());
|
|
|
+ // 转化实体
|
|
|
+ Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
+ // 总单保存
|
|
|
+ super.insert(outbound);
|
|
|
+
|
|
|
+ // 明细保存
|
|
|
+ if (outboundVO.getOutboundItemList() != null && outboundVO.getOutboundItemList().size() > 0) {
|
|
|
+ for (OutboundItemVO outboundItemVO : outboundVO.getOutboundItemList()) {
|
|
|
+ OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+ outboundItem.setOutId(outbound.getOutId()).setCpId(outbound.getCpId()).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
|
|
|
+ outboundItemMapper.insert(outboundItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 获取订单信息(编辑用)
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2024-03-02 17:27
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> getOutboundForUpdate(String id) {
|
|
|
+ Map<String, Object> outboundInfo = new HashMap<>();
|
|
|
+ OutboundResponse outboundResponse = outboundMapper.selectById(id);
|
|
|
+ outboundInfo.put("outbound", outboundResponse);
|
|
|
+
|
|
|
+ // 商品明细
|
|
|
+ List<OutboundItemResponse> outboundItemResponse = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
|
|
|
+ outboundInfo.put("outboundItem", outboundItemResponse);
|
|
|
+ return ResponseResultUtil.success(outboundInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 编辑方法
|
|
|
+ * @author : 付斌
|
|
|
+ * @date : 2023/1/9 10:49
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<Boolean> update(OutboundVO outboundVO) {
|
|
|
+ // 转化实体
|
|
|
+ Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
+
|
|
|
+ // 编辑的
|
|
|
+ List<OutboundItemVO> editOutboundItemVOList = outboundVO.getOutboundItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
|
|
|
+ for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
|
|
|
+ // 商品数量不能小于出库中数量
|
|
|
+ if(outboundItemVO.getItemQty().compareTo(outboundItemVO.getOutingQty()) == -1){
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
+ } else {
|
|
|
+ OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+ outboundItemService.updateByUuid(outboundItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
+ UUID.fromString(outbound.getOutId()))));
|
|
|
+ }
|
|
|
}
|