|
|
@@ -11,18 +11,25 @@ import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
+import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
|
|
|
+import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
|
|
|
import com.dk.mdm.infrastructure.convert.ivt.OutboundConvert;
|
|
|
import com.dk.mdm.infrastructure.convert.ivt.OutboundItemConvert;
|
|
|
import com.dk.mdm.mapper.common.CommonMapper;
|
|
|
+import com.dk.mdm.mapper.ivt.InboundItemMapper;
|
|
|
+import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
|
import com.dk.mdm.mapper.ivt.OutboundItemMapper;
|
|
|
import com.dk.mdm.mapper.ivt.OutboundMapper;
|
|
|
import com.dk.mdm.mapper.mst.CustomerMapper;
|
|
|
import com.dk.mdm.mapper.sale.MultiOwnerMapper;
|
|
|
import com.dk.mdm.mapper.sale.OrderItemMapper;
|
|
|
import com.dk.mdm.mapper.sale.OrderMapper;
|
|
|
+import com.dk.mdm.model.pojo.ivt.Inbound;
|
|
|
+import com.dk.mdm.model.pojo.ivt.InboundItem;
|
|
|
import com.dk.mdm.model.pojo.ivt.Outbound;
|
|
|
import com.dk.mdm.model.pojo.ivt.OutboundItem;
|
|
|
import com.dk.mdm.model.pojo.mst.Customer;
|
|
|
+import com.dk.mdm.model.pojo.pur.Purchase;
|
|
|
import com.dk.mdm.model.pojo.pur.PurchaseItem;
|
|
|
import com.dk.mdm.model.pojo.sale.MultiOwner;
|
|
|
import com.dk.mdm.model.pojo.sale.Order;
|
|
|
@@ -30,11 +37,15 @@ import com.dk.mdm.model.pojo.sale.OrderItem;
|
|
|
import com.dk.mdm.model.query.ivt.OutboundItemQuery;
|
|
|
import com.dk.mdm.model.query.ivt.OutboundQuery;
|
|
|
import com.dk.mdm.model.query.sale.OrderQuery;
|
|
|
+import com.dk.mdm.model.response.ivt.InboundResponse;
|
|
|
import com.dk.mdm.model.response.ivt.OutboundItemResponse;
|
|
|
import com.dk.mdm.model.response.ivt.OutboundResponse;
|
|
|
+import com.dk.mdm.model.response.pur.PurchaseItemResponse;
|
|
|
+import com.dk.mdm.model.response.pur.PurchaseResponse;
|
|
|
import com.dk.mdm.model.response.sale.OrderItemResponse;
|
|
|
import com.dk.mdm.model.response.sale.OrderResponse;
|
|
|
import com.dk.mdm.model.vo.ivt.InboundItemVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.InboundVO;
|
|
|
import com.dk.mdm.model.vo.ivt.OutboundItemVO;
|
|
|
import com.dk.mdm.model.vo.ivt.OutboundVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
@@ -45,10 +56,12 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -97,6 +110,142 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
@Autowired
|
|
|
private OutCommon outCommon;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private InboundMapper inboundMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundConvert inboundConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundItemMapper inboundItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundItemConvert inboundItemConvert;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 删除外协品生产外协入库单
|
|
|
+ * @date : 2024/5/10 10:31
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public void deleteOutsideGoodsInto(OutboundVO outboundVO,List<OutboundItemVO> outboundItemVOList){
|
|
|
+ //根据出库单id分组
|
|
|
+ Map<String, List<OutboundItemVO>> outboundItemVOMap = outboundItemVOList.stream().collect(Collectors.groupingBy(OutboundItemVO::getOutId));
|
|
|
+ for (String str : outboundItemVOMap.keySet()) {
|
|
|
+ InboundResponse inboundResponse = inboundMapper.selectByFromId(str);
|
|
|
+ // 退账
|
|
|
+ if (inboundResponse.getReceivableId() != null) {
|
|
|
+ accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除外协入库单
|
|
|
+ //外协入库总单
|
|
|
+ inboundMapper.deleteByFromId(outboundItemVOList.get(0).getOutId());
|
|
|
+ //外协入库明细
|
|
|
+ inboundItemMapper.deleteByFromId(outboundItemVOList.get(0).getOutId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建外协品生产外协入库单
|
|
|
+ * @date : 2024/5/10 10:31
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public void insertOutsideGoodsInto(OutboundVO outboundVO,List<OutboundItemVO> outboundItemVOList){
|
|
|
+ Map<String, List<OutboundItemVO>> outboundItemVOMap = outboundItemVOList.stream().collect(Collectors.groupingBy(OutboundItemVO::getSkuId));
|
|
|
+ for (String str : outboundItemVOMap.keySet()) {
|
|
|
+ //提取分组后的明细
|
|
|
+ List<OutboundItemVO> outboundItemVOListGroup = outboundItemVOMap.get(str);
|
|
|
+
|
|
|
+ //region 新建总单
|
|
|
+ //已入库金额
|
|
|
+ BigDecimal sumIntoAmt = outboundItemVOListGroup.stream().map(OutboundItemVO::getOutAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ //已入库数量
|
|
|
+ BigDecimal sumIntoQty= outboundItemVOListGroup.stream().map(OutboundItemVO::getOutQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ //总单实体
|
|
|
+ InboundVO inboundVO = new InboundVO();
|
|
|
+ //获取 id/单号
|
|
|
+ Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OUTSOURCED.getName(), false);
|
|
|
+ inboundVO.setIntoId(codeMap.get("outId").toString()).
|
|
|
+ setIntoNo(codeMap.get("outNote").toString());
|
|
|
+ //入库类型
|
|
|
+ inboundVO.setIntoType(Constant.IntoType.OUTSOURCED.getName());
|
|
|
+ //已入库
|
|
|
+ inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
|
+ //供应商
|
|
|
+ inboundVO.setSupId(outboundItemVOListGroup.get(0).getSupId());
|
|
|
+ //入库状态等于已入库
|
|
|
+ inboundVO.setIntoQty(sumIntoAmt)
|
|
|
+ .setIntoAmt(sumIntoQty)
|
|
|
+ .setIntoingQty(BigDecimal.ZERO)
|
|
|
+ .setIntoingAmt(BigDecimal.ZERO);
|
|
|
+ //来源id
|
|
|
+ inboundVO.setFromId(outboundItemVOListGroup.get(0).getFromId());
|
|
|
+ //来源单号
|
|
|
+ inboundVO.setFromNo(outboundVO.getOutNo());
|
|
|
+ //部门
|
|
|
+ inboundVO.setOrgId(outboundVO.getOrgId());
|
|
|
+ //员工
|
|
|
+ inboundVO.setStaffId(outboundVO.getStaffId());
|
|
|
+ //入库日期
|
|
|
+ inboundVO.setIntoDate(LocalDate.now());
|
|
|
+ //制单人
|
|
|
+ inboundVO.setMakeStaff(outboundVO.getMakeStaff());
|
|
|
+ //公司
|
|
|
+ inboundVO.setCpId(outboundVO.getCpId());
|
|
|
+ //实体转换
|
|
|
+ Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
|
+ inboundMapper.insert(inbound);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 明细
|
|
|
+ Integer count = 0;
|
|
|
+ for (OutboundItemVO outboundItemVO : outboundItemVOListGroup) {
|
|
|
+ InboundItemVO inboundItemVO = new InboundItemVO();
|
|
|
+ //总单id
|
|
|
+ inboundItemVO.setIntoId(inboundVO.getIntoId());
|
|
|
+ //入库类型
|
|
|
+ inboundItemVO.setIntoType(inboundVO.getIntoType());
|
|
|
+ //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
|
+ inboundItemVO
|
|
|
+ .setIntoQty(outboundItemVO.getOutQty())
|
|
|
+ .setIntoAmt(outboundItemVO.getOutQty())
|
|
|
+ .setIntoingQty(BigDecimal.ZERO)
|
|
|
+ .setIntoingAmt(BigDecimal.ZERO)
|
|
|
+ .setCostPrice(outboundItemVO.getPriceOut())
|
|
|
+ .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
+ ;
|
|
|
+ //入库状态
|
|
|
+ inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
|
|
|
+ //商品顺序
|
|
|
+ inboundItemVO.setItemIndex(count);
|
|
|
+ //箱(入库中)
|
|
|
+ inboundItemVO.setIntoingBox(outboundItemVO.getOutingBox());
|
|
|
+ //片(入库中)
|
|
|
+ inboundItemVO.setIntoingPiece(outboundItemVO.getOutingPiece());
|
|
|
+ //箱(已入库)
|
|
|
+ inboundItemVO.setIntoBox(outboundItemVO.getOutBox());
|
|
|
+ //片(已入库)
|
|
|
+ inboundItemVO.setIntoPiece(outboundItemVO.getOutPiece());
|
|
|
+ //入库仓库
|
|
|
+ inboundItemVO.setWhId(outboundItemVO.getWhId());
|
|
|
+ //企业ID
|
|
|
+ inboundItemVO.setCpId(outboundItemVO.getCpId());
|
|
|
+ //实体转换
|
|
|
+ InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
+ inboundItemMapper.insert(inboundItem);
|
|
|
+ //用来填写商品顺序
|
|
|
+ count++;
|
|
|
+ inboundItemVO.setItemId(inboundItem.getItemId());
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 入账
|
|
|
+ accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName());
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @desc : 销售出库新建
|
|
|
@@ -236,6 +385,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
//实体转换
|
|
|
OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
outboundItemMapper.insert(outboundItem);
|
|
|
+ //明细id
|
|
|
outboundItemVO.setItemId(outboundItem.getItemId());
|
|
|
//endregion
|
|
|
|
|
|
@@ -282,11 +432,24 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
- //region 库存
|
|
|
+ //region 外协品+库存
|
|
|
if(Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())){
|
|
|
+ //region 外协品新建外协入库单
|
|
|
+ //筛选出skuId为空的 走外协品逻辑
|
|
|
+ List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outboundVO,outsideGoods);
|
|
|
+ //新建外协品生产外协入库单
|
|
|
+ this.insertOutsideGoodsInto(outboundVO,outsideGoods);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 库存
|
|
|
+ //筛选出skuId不为空的 走库存
|
|
|
+ List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
Map<String, Object> invMap = new HashMap<>();
|
|
|
- invMap.put("outDetail",outboundVO.getItemList());
|
|
|
+ invMap.put("outDetail",invList);
|
|
|
inventoryService.operatingInventoryInformation(invMap);
|
|
|
+ //endregion
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
@@ -512,10 +675,25 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
+ //region 外协品新建外协入库单
|
|
|
+ //筛选出skuId为空的 走外协品逻辑
|
|
|
+ List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outboundVO,outsideGoods);
|
|
|
+ //新建外协品生产外协入库单
|
|
|
+ this.insertOutsideGoodsInto(outboundVO,outsideGoods);
|
|
|
+ List<OutboundItemVO> delOutsideGoods = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outboundVO,delOutsideGoods);
|
|
|
+ //endregion
|
|
|
+
|
|
|
//region 修改库存
|
|
|
+ //筛选出skuId不为空的 走库存
|
|
|
+ List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
+ List<OutboundItemVO> invDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
Map<String, Object> invMap = new HashMap<>();
|
|
|
- invMap.put("outDetail", outboundVO.getItemList());
|
|
|
- invMap.put("delOutDetail", outboundVO.getDeleteItemList());
|
|
|
+ invMap.put("outDetail", invList);
|
|
|
+ invMap.put("delOutDetail",invDelList);
|
|
|
inventoryService.operatingInventoryInformation(invMap);
|
|
|
//endregion
|
|
|
}
|
|
|
@@ -686,7 +864,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
- //region 自动办理参数为true 已入库编辑
|
|
|
+ //region 自动办理参数为true 已入库作废
|
|
|
//自动办理参数为true
|
|
|
if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundResponse.getFlgHandleSetting())) {
|
|
|
//region 应收反记账
|
|
|
@@ -768,9 +946,21 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
|
|
|
//endregion
|
|
|
|
|
|
+
|
|
|
+ //region 外协品新建外协入库单
|
|
|
+ //筛选出skuId为空的 走外协品逻辑
|
|
|
+ OutboundVO outboundVO = outboundConvert.convertResToVO(outboundResponse);
|
|
|
+ List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outboundVO,outsideGoodsVOList);
|
|
|
+ //endregion
|
|
|
+
|
|
|
//region 修改库存
|
|
|
+ //筛选出skuId不为空的 走库存
|
|
|
+ List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("delOutDetail", outboundItemResponseList);
|
|
|
+ map.put("delOutDetail", invList);
|
|
|
inventoryService.operatingInventoryInformation(map);
|
|
|
//endregion
|
|
|
}
|
|
|
@@ -779,7 +969,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
- //region 自动办理参数false 入库中编辑
|
|
|
+ //region 自动办理参数false 入库中作废
|
|
|
//自动办理标识为false 并且 自动办理参数为false 入库中
|
|
|
if (!outboundResponse.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(outboundResponse.getFlgHandleSetting())) {
|
|
|
//region 修改明细
|
|
|
@@ -1088,10 +1278,26 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
accountService.accReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
|
|
|
//endregion
|
|
|
|
|
|
+
|
|
|
+ //region 外协品新建外协入库单
|
|
|
+ //筛选出skuId为空的 走外协品逻辑
|
|
|
+ List<OutboundItemVO> outsideGoods = outboundVO.getItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outboundVO,outsideGoods);
|
|
|
+ //新建外协品生产外协入库单
|
|
|
+ this.insertOutsideGoodsInto(outboundVO,outsideGoods);
|
|
|
+ List<OutboundItemVO> delOutsideGoods = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outboundVO,delOutsideGoods);
|
|
|
+ //endregion
|
|
|
+
|
|
|
//region 调用库存
|
|
|
+ //筛选出skuId不为空的 走库存
|
|
|
+ List<OutboundItemVO> invList = outboundVO.getItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
+ List<OutboundItemVO> invDelList = outboundVO.getDeleteItemList().stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("outDetail", outboundVO.getItemList());
|
|
|
- map.put("delOutDetail", outboundVO.getDeleteItemList());
|
|
|
+ map.put("outDetail", invList);
|
|
|
+ map.put("delOutDetail",invDelList);
|
|
|
inventoryService.operatingInventoryInformation(map);
|
|
|
//endregion
|
|
|
return ResponseResultUtil.success(outboundVO);
|
|
|
@@ -1213,9 +1419,21 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
+
|
|
|
+ //region 外协品新建外协入库单
|
|
|
+ //筛选出skuId为空的 走外协品逻辑
|
|
|
+ OutboundVO outsideGoodVO = outboundConvert.convertResToVO(outboundResponse);
|
|
|
+ List<OutboundItemResponse> outsideGoods = outboundItemResponseList.stream().filter(it -> it.getSkuId() == null).collect(Collectors.toList());
|
|
|
+ List<OutboundItemVO> outsideGoodsVOList = outboundItemConvert.convertResListToVOList(outsideGoods);
|
|
|
+ //删除外协品生产外协入库单
|
|
|
+ this.deleteOutsideGoodsInto(outsideGoodVO,outsideGoodsVOList);
|
|
|
+ //endregion
|
|
|
+
|
|
|
//region 调用库存
|
|
|
+ //筛选出skuId不为空的 走库存
|
|
|
+ List<OutboundItemResponse> invList = outboundItemResponseList.stream().filter(it -> it.getSkuId() != null).collect(Collectors.toList());
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("delOutDetail", outboundItemResponseList);
|
|
|
+ map.put("delOutDetail", invList);
|
|
|
inventoryService.operatingInventoryInformation(map);
|
|
|
//endregion
|
|
|
|