|
|
@@ -1,25 +1,50 @@
|
|
|
package com.dk.mdm.service.ivt;
|
|
|
|
|
|
+import com.dk.common.exception.BaseBusinessException;
|
|
|
import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
import com.dk.common.model.pojo.PageList;
|
|
|
+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.mapper.ivt.InboundItemMapper;
|
|
|
import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
|
+import com.dk.mdm.mapper.pur.PurchaseItemMapper;
|
|
|
+import com.dk.mdm.mapper.pur.PurchaseMapper;
|
|
|
import com.dk.mdm.model.pojo.ivt.Inbound;
|
|
|
+import com.dk.mdm.model.pojo.ivt.InboundItem;
|
|
|
+import com.dk.mdm.model.pojo.ivt.IntoReturn;
|
|
|
+import com.dk.mdm.model.pojo.ivt.IntoReturnItem;
|
|
|
+import com.dk.mdm.model.pojo.pur.Purchase;
|
|
|
+import com.dk.mdm.model.pojo.pur.PurchaseItem;
|
|
|
import com.dk.mdm.model.query.ivt.InboundItemQuery;
|
|
|
import com.dk.mdm.model.query.ivt.InboundQuery;
|
|
|
import com.dk.mdm.model.response.ivt.InboundItemResponse;
|
|
|
import com.dk.mdm.model.response.ivt.InboundResponse;
|
|
|
+import com.dk.mdm.model.response.ivt.IntoReturnItemResponse;
|
|
|
+import com.dk.mdm.model.response.ivt.IntoReturnResponse;
|
|
|
+import com.dk.mdm.model.response.pur.PurchaseItemResponse;
|
|
|
+import com.dk.mdm.model.response.pur.PurchaseResponse;
|
|
|
+import com.dk.mdm.model.vo.ivt.InboundItemVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.InboundVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.IntoReturnItemVO;
|
|
|
+import com.dk.mdm.service.common.CommonService;
|
|
|
+import com.dk.mdm.service.ivt.inbound.InboundPurchaseReturnService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service("inboundReturn")
|
|
|
@Transactional
|
|
|
@@ -36,6 +61,24 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
@Autowired
|
|
|
private InboundItemMapper inboundItemMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PurchaseMapper purchaseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseItemMapper purchaseItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundConvert inboundConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundItemConvert inboundItemConvert;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundPurchaseReturnService inboundPurchaseReturnService;
|
|
|
|
|
|
@Pagination
|
|
|
public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
|
|
|
@@ -60,4 +103,164 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
inboundResponse.setGoodsList(inboundItemResponselist);
|
|
|
return ResponseResultUtil.success(inboundResponse);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建采购退货
|
|
|
+ * @author : 于继渤
|
|
|
+ * @date : 2023/1/5 9:39
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<?> insert(InboundVO inboundVO) {
|
|
|
+ //校验明细长度
|
|
|
+ List<InboundItemVO> itemList = inboundVO.getItemList();
|
|
|
+ //明细不存在
|
|
|
+ if (itemList == null || itemList.size() == 0) {
|
|
|
+ //返回 采购退货明细不可为空,请重新操作
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.PURCHASE_RETURN_DETAIL_NOT_EXIST.getMessage());
|
|
|
+ }
|
|
|
+ //查询采购订单
|
|
|
+ PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
|
|
|
+
|
|
|
+ inboundVO.setReturnQty(inboundVO.getReturnQty().abs());
|
|
|
+ inboundVO.setReturnAmt(inboundVO.getReturnAmt().abs());
|
|
|
+ //反写采购订单已入库退货数量、金额
|
|
|
+ purchaseMapper.updateAmount(new Purchase().setPurId(inboundVO.getFromId())
|
|
|
+ .setReturnQty(purchaseResponse.getReturnQty().add(inboundVO.getReturnQty()))
|
|
|
+ .setReturnAmt(purchaseResponse.getReturnAmt().add(inboundVO.getReturnAmt()))
|
|
|
+ );
|
|
|
+ BigDecimal sumReturnQty = BigDecimal.ZERO;
|
|
|
+ BigDecimal sumReturnAmt = BigDecimal.ZERO;
|
|
|
+ //反写入库订单明细、反写订单明细
|
|
|
+ for (InboundItemVO inboundItemVO : itemList) {
|
|
|
+ //根据退货明细中入库明细id查询入库明细数据
|
|
|
+ InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
|
|
|
+ BigDecimal returnQty = inboundItemResponse.getReturnQty().add(inboundItemVO.getReturnQty().setScale(6, BigDecimal.ROUND_HALF_UP));
|
|
|
+ BigDecimal returnAmt = inboundItemResponse.getReturnAmt().add(inboundItemVO.getReturnAmt().setScale(6, BigDecimal.ROUND_HALF_UP));
|
|
|
+ sumReturnQty = sumReturnQty.add(returnQty);
|
|
|
+ sumReturnAmt = sumReturnAmt.add(returnAmt);
|
|
|
+ //反写入库单退货数量金额 todo
|
|
|
+ InboundResponse inboundResponse = inboundMapper.selectById(inboundItemVO.getIntoId());
|
|
|
+ inboundMapper.updateAmount(new Inbound().setIntoId(inboundItemVO.getIntoId())
|
|
|
+ .setReturnQty(inboundResponse.getReturnQty().add(sumReturnQty))
|
|
|
+ .setReturnAmt(inboundResponse.getReturnAmt().add(sumReturnAmt)));
|
|
|
+ inboundItemMapper.updateAmount(
|
|
|
+ new InboundItem()
|
|
|
+ .setItemId(inboundItemResponse.getItemId())
|
|
|
+ .setReturnQty(returnQty)
|
|
|
+ .setReturnAmt(returnAmt)
|
|
|
+ );
|
|
|
+ //反写订单出库明细 退货数量和退货金额
|
|
|
+ //查询采购订单明细数据
|
|
|
+ PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
|
|
|
+ //反写订单明细退货数量和退货金额
|
|
|
+ purchaseItemMapper.updateAmount(
|
|
|
+ new PurchaseItem()
|
|
|
+ .setItemId(inboundItemVO.getFromItemId())
|
|
|
+ .setReturnQty(purchaseItemResponse.getReturnQty().add(inboundItemVO.getReturnQty().setScale(6, BigDecimal.ROUND_HALF_UP)))
|
|
|
+ .setReturnAmt(purchaseItemResponse.getReturnAmt().add(inboundItemVO.getReturnAmt().setScale(6, BigDecimal.ROUND_HALF_UP)))
|
|
|
+
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //获取 id/单号
|
|
|
+ Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALERETURN.getName(), false);
|
|
|
+ inboundVO.setIntoId(codeMap.get("outId").toString()).
|
|
|
+ setIntoNo(codeMap.get("outNote").toString());
|
|
|
+ //入库类型
|
|
|
+ inboundVO.setIntoType(Constant.IntoType.PURRETURN_RETURN.getName());
|
|
|
+ //自动入库标识
|
|
|
+ if (inboundVO.getAutomaticFlg()) {
|
|
|
+ //已入库
|
|
|
+ inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
|
+ } else {
|
|
|
+ //入库中
|
|
|
+ inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
|
|
|
+ }
|
|
|
+ //退货数量
|
|
|
+ inboundVO.setReturnQty(inboundVO.getIntoingQty());
|
|
|
+ //退货金额
|
|
|
+ inboundVO.setReturnAmt(inboundVO.getIntoingAmt());
|
|
|
+ //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
|
+ if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
|
|
|
+ inboundVO
|
|
|
+ .setIntoQty(inboundVO.getIntoingQty())
|
|
|
+ .setIntoAmt(inboundVO.getIntoingAmt())
|
|
|
+ .setIntoingQty(BigDecimal.ZERO)
|
|
|
+ .setIntoingAmt(BigDecimal.ZERO)
|
|
|
+ ;
|
|
|
+ } else {
|
|
|
+ inboundVO
|
|
|
+ .setIntoQty(BigDecimal.ZERO)
|
|
|
+ .setIntoAmt(BigDecimal.ZERO)
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ //实体转换
|
|
|
+ Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
|
+ inboundMapper.insert(inbound);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 明细
|
|
|
+ //校验明细
|
|
|
+ if (inboundVO.getItemList().size() == 0) {
|
|
|
+ return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
|
|
|
+ ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
|
|
|
+ }
|
|
|
+ for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
|
|
|
+ //总单id
|
|
|
+ inboundItemVO.setIntoId(inboundVO.getIntoId());
|
|
|
+ //入库类型
|
|
|
+ inboundItemVO.setIntoType(inboundVO.getIntoType());
|
|
|
+ //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
|
+ if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
|
|
|
+ inboundItemVO
|
|
|
+ .setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
+ .setIntoAmt(inboundItemVO.getIntoingAmt())
|
|
|
+ .setIntoingQty(BigDecimal.ZERO)
|
|
|
+ .setIntoingAmt(BigDecimal.ZERO)
|
|
|
+ .setCostPrice(inboundItemVO.getPriceInto())
|
|
|
+ .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
+ ;
|
|
|
+ } else {
|
|
|
+ inboundItemVO
|
|
|
+ .setIntoQty(BigDecimal.ZERO)
|
|
|
+ .setIntoAmt(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ //入库状态
|
|
|
+ inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
|
|
|
+ //实体转换
|
|
|
+ InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
+ inboundItemMapper.insert(inboundItem);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ inboundVO.setFromId(inboundVO.getIntoId());
|
|
|
+ inboundVO.setFromNo(inboundVO.getIntoNo());
|
|
|
+
|
|
|
+ inboundVO.setIntoingQty(inboundVO.getReturnQty().multiply(new BigDecimal(-1)));
|
|
|
+ inboundVO.setIntoingAmt(inboundVO.getReturnAmt().multiply(new BigDecimal(-1)));
|
|
|
+ List<InboundItemVO> list = new ArrayList<>();
|
|
|
+ for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
|
|
|
+
|
|
|
+ inboundItemVO.setIntoingQty(inboundItemVO.getReturnQty().multiply(new BigDecimal(-1)));
|
|
|
+ inboundItemVO.setIntoingAmt(inboundItemVO.getReturnAmt().multiply(new BigDecimal(-1)));
|
|
|
+ inboundItemVO.setPriceInto(inboundItemVO.getPriceInto());
|
|
|
+ inboundItemVO.setFromItemId(inboundItemVO.getItemId());
|
|
|
+ inboundItemVO.setSkuId(inboundItemVO.getSkuId());
|
|
|
+ inboundItemVO.setItemIndex(inboundItemVO.getItemIndex());
|
|
|
+ inboundItemVO.setNonStdCode(inboundItemVO.getNonStdCode());
|
|
|
+ inboundItemVO.setReturnQty(inboundItemVO.getReturnQty());
|
|
|
+ inboundItemVO.setReturnAmt(inboundItemVO.getReturnAmt());
|
|
|
+ list.add(inboundItemVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ inboundVO.setItemList(list);
|
|
|
+
|
|
|
+ inboundPurchaseReturnService.purchaseReturnInboundInsert(inboundVO);
|
|
|
+
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
}
|