|
|
@@ -10,12 +10,18 @@ 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.IntoReturnConvert;
|
|
|
+import com.dk.mdm.infrastructure.convert.ivt.IntoReturnItemConvert;
|
|
|
import com.dk.mdm.mapper.ivt.InboundItemMapper;
|
|
|
import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
|
+import com.dk.mdm.mapper.ivt.IntoReturnItemMapper;
|
|
|
+import com.dk.mdm.mapper.ivt.IntoReturnMapper;
|
|
|
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;
|
|
|
@@ -23,10 +29,13 @@ import com.dk.mdm.model.query.ivt.InboundQuery;
|
|
|
import com.dk.mdm.model.query.pur.PurchaseItemQuery;
|
|
|
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.pur.PurchaseVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -38,382 +47,488 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @desc : 销售退货入库业务层
|
|
|
- * @date : 2024/3/7 14:11
|
|
|
* @author : 寇珊珊
|
|
|
+ * @desc : 销售退货入库业务层
|
|
|
+ * @date : 2024/3/7 14:11
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class InboundSaleReturnService extends BaseService<Inbound> {
|
|
|
|
|
|
- @Override
|
|
|
- public BaseMapper<Inbound> getRepository() {
|
|
|
- return inboundMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private InboundMapper inboundMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private InboundConvert inboundConvert;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private InboundItemMapper inboundItemMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private InboundItemConvert inboundItemConvert;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PurchaseMapper purchaseMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PurchaseItemMapper purchaseItemMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommonService commonService;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询
|
|
|
- * @date : 2024/3/7 14:12
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<InboundResponse>> selectInboundAndItem(InboundQuery inboundQuery) {
|
|
|
- return super.mergeListWithCount(inboundQuery, inboundMapper.selectInboundAndItem(inboundQuery),
|
|
|
- inboundMapper.selectInboundAndItemCountByCond(inboundQuery));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 销售退货入库新建
|
|
|
- * @date : 2024/3/7 14:13
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- public ResponseResultVO<?> saleReturnInboundInsert(InboundVO inboundVO) {
|
|
|
- //region 总单
|
|
|
- //获取 id/单号
|
|
|
- Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUND.getName(),false);
|
|
|
- inboundVO.setIntoId(codeMap.get("outId").toString()).
|
|
|
- setIntoNo(codeMap.get("outNote").toString());
|
|
|
- //入库类型
|
|
|
- inboundVO.setIntoType(Constant.IntoType.PURRETURN.getName());
|
|
|
- //入库状态 待入库
|
|
|
- inboundVO.setIntoStatus(Constant.IntoStatus.DAIRUKU.getName());
|
|
|
- //退货数量
|
|
|
- inboundVO.setReturnQty(inboundVO.getIntoingQty());
|
|
|
- //退货金额
|
|
|
- inboundVO.setReturnAmt(inboundVO.getIntoingAmt());
|
|
|
- //实体转换
|
|
|
- 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()) {
|
|
|
- Map<String , Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(),true);
|
|
|
- //明细id
|
|
|
- inboundItemVO.setItemId(map.get("outId").toString());
|
|
|
- //总单id
|
|
|
- inboundItemVO.setIntoId(inboundVO.getIntoId());
|
|
|
- //入库类型
|
|
|
- inboundItemVO.setIntoType(inboundVO.getIntoType());
|
|
|
- //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
|
- if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
|
|
|
- inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
- .setIntoAmt(inboundItemVO.getIntoingAmt());
|
|
|
- }
|
|
|
- //成本单价
|
|
|
- inboundItemVO.setCostPrice(inboundItemVO.getCostPrice());
|
|
|
- //成本金额
|
|
|
- inboundItemVO.setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
- //库存数量 已入库-出库
|
|
|
- inboundItemVO.setInvQty(inboundItemVO.getIntoQty().subtract(inboundItemVO.getOutQty()));
|
|
|
- //入库状态
|
|
|
- inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
|
|
|
- //退货数量
|
|
|
- inboundItemVO.setReturnQty(inboundItemVO.getIntoingQty());
|
|
|
- //退货金额
|
|
|
- inboundItemVO.setReturnAmt(inboundItemVO.getIntoingAmt());
|
|
|
- //实体转换
|
|
|
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
- inboundItemMapper.insert(inboundItem);
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //todo 如果是已入库 调用库存 后续写库存这里补上
|
|
|
- //region 库存
|
|
|
-
|
|
|
-
|
|
|
- //endregion
|
|
|
-
|
|
|
-
|
|
|
- return ResponseResultUtil.success(inboundVO);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 销售退货入库办理
|
|
|
- * @date : 2024/3/7 15:47
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- public ResponseResultVO<?> saleReturnHandleInbound(InboundVO inboundVO) {
|
|
|
- //大编辑标识
|
|
|
- if (inboundVO.getAllEdit() != null && inboundVO.getAllEdit()) {
|
|
|
- //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()) {
|
|
|
- if (inboundItemVO.getIntoId() != null) {
|
|
|
- //编辑明细
|
|
|
- inboundItemVO.setCostPrice(inboundItemVO.getPriceInto())
|
|
|
- .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
- .setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
- .setIntoAmt(inboundItemVO.getIntoingAmt());
|
|
|
- //入库状态
|
|
|
- String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
|
|
|
- inboundItemVO.setIntoStatus(intoStatus);
|
|
|
- //实体转换
|
|
|
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
- //修改
|
|
|
- inboundItemMapper.updateById(inboundItem);
|
|
|
- }
|
|
|
- //endregion
|
|
|
- //region 新建明细
|
|
|
- else {
|
|
|
- Map<String , Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(),true);
|
|
|
- inboundItemVO
|
|
|
- .setItemId(map.get("outId").toString())
|
|
|
- .setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
- .setIntoAmt(inboundItemVO.getIntoingAmt())
|
|
|
- .setIntoId(inboundVO.getIntoId())
|
|
|
- .setCostPrice(inboundItemVO.getPriceInto())
|
|
|
- .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
- .setIntoType(Constant.IntoType.PURRETURN.getName());
|
|
|
- //入库状态
|
|
|
- String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
|
|
|
- inboundItemVO.setIntoStatus(intoStatus);
|
|
|
- //实体转换
|
|
|
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
- //新建
|
|
|
- inboundItemMapper.insert(inboundItem);
|
|
|
- }
|
|
|
- //region 销售退货
|
|
|
- //销售退货明细
|
|
|
- if(inboundItemVO.getFromItemId()!=null){
|
|
|
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
|
|
|
- PurchaseItem purchaseItem = new PurchaseItem();
|
|
|
- purchaseItem.setItemId(purchaseItemResponse.getItemId());
|
|
|
- purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoQty()));
|
|
|
- purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoAmt()));
|
|
|
- purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().add(inboundItemVO.getIntoQty()));
|
|
|
- purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()));
|
|
|
- //入库状态
|
|
|
- String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
|
|
|
- purchaseItem.setIntoStatus(intoStatus);
|
|
|
- purchaseItemMapper.updateById(purchaseItem);
|
|
|
- }
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 删除明细
|
|
|
- BigDecimal sumDelIntoQty = BigDecimal.ZERO;
|
|
|
- BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
|
|
|
- if (inboundVO.getDeleteItemList() != null) {
|
|
|
- sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
- sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
|
|
|
- if (inboundItemVO.getItemId() != null) {
|
|
|
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
- inboundItem.setFlgValid(false);
|
|
|
- inboundItemMapper.updateById(inboundItem);
|
|
|
- }
|
|
|
- //region 销售退货
|
|
|
- if(inboundVO.getFromId()!=null){
|
|
|
- //region 销售退货订单明细
|
|
|
- List<PurchaseItemResponse> purchaseItemResponses = purchaseItemMapper.selectByCond(new PurchaseItemQuery().setPurId(inboundVO.getFromId()));
|
|
|
- for (PurchaseItemResponse purchaseItemResponse : purchaseItemResponses) {
|
|
|
- PurchaseItem purchaseItem = new PurchaseItem();
|
|
|
- purchaseItem.setItemId(purchaseItemResponse.getItemId());
|
|
|
- purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().add(purchaseItemResponse.getIntoQty()));
|
|
|
- purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().add(purchaseItemResponse.getIntoAmt()));
|
|
|
- purchaseItem.setIntoQty(BigDecimal.ZERO);
|
|
|
- purchaseItem.setIntoingAmt(BigDecimal.ZERO);
|
|
|
- //入库状态
|
|
|
- String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
|
|
|
- purchaseItem.setIntoStatus(intoStatus);
|
|
|
- purchaseItemMapper.updateById(purchaseItem);
|
|
|
- }
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 编辑总单
|
|
|
- BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
- BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- inboundVO.setIntoQty(sumIntoQty);
|
|
|
- inboundVO.setIntoAmt(sumIntoAmt);
|
|
|
- //已入库数量==入库中数量 入库完成
|
|
|
- if(sumIntoQty.compareTo(inboundVO.getIntoQty())==0){
|
|
|
- //已入库
|
|
|
- inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
|
- } else {
|
|
|
- //入库中
|
|
|
- inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
|
|
|
- }
|
|
|
- //实体转换
|
|
|
- Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
|
- //修改
|
|
|
- super.update(inbound);
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 修改销售退货订单
|
|
|
- if(inboundVO.getFromId()!=null){
|
|
|
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
|
|
|
- Purchase purchase = new Purchase();
|
|
|
- purchase.setPurId(purchaseResponse.getPurId());
|
|
|
- purchase.setIntoQty(purchaseResponse.getIntoQty().subtract(sumIntoQty.add(sumDelIntoQty)));
|
|
|
- purchase.setIntoAmt(purchaseResponse.getIntoAmt().subtract(sumIntoAmt.add(sumDelIntoAmt)));
|
|
|
- purchase.setIntoingQty(purchaseResponse.getIntoingQty().add(sumIntoQty).subtract(sumDelIntoQty));
|
|
|
- purchase.setIntoingAmt(purchaseResponse.getIntoingAmt().add(sumIntoAmt).subtract(sumDelIntoAmt));
|
|
|
- //入库状态
|
|
|
- String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
|
|
|
- purchase.setIntoStatus(intoStatus);
|
|
|
- //修改
|
|
|
- purchaseMapper.updateById(purchase);
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //todo 如果是已入库 调用库存 后续写库存这里补上
|
|
|
- //region 修改库存
|
|
|
-
|
|
|
- //endregion
|
|
|
- }
|
|
|
- return ResponseResultUtil.success(inboundVO);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 销售退货入库撤销
|
|
|
- * @date : 2024/3/7 17:06
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- public ResponseResultVO<?> saleReturnInboundCancel(InboundVO inboundVO) {
|
|
|
- //region 查询入库总单数据信息
|
|
|
- InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 修改订单数据信息
|
|
|
- if (inboundVO.getFromId() != null) {
|
|
|
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
|
|
|
- Purchase purchase = new Purchase();
|
|
|
- purchase.setPurId(inboundResponse.getFromId());
|
|
|
- purchase.setIntoQty(purchaseResponse.getIntoQty().subtract(inboundResponse.getIntoQty()));
|
|
|
- purchase.setIntoAmt(purchaseResponse.getIntoAmt().subtract(inboundResponse.getIntoAmt()));
|
|
|
- purchase.setIntoingQty(purchaseResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
|
|
|
- purchase.setIntoingAmt(purchaseResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
|
|
|
- //入库状态
|
|
|
- String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
|
|
|
- purchase.setIntoStatus(intoStatus);
|
|
|
- purchaseMapper.updateById(purchase);
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 修改总单数据信息
|
|
|
- Inbound inbound = new Inbound();
|
|
|
- inbound.setIntoId(inboundVO.getIntoId());
|
|
|
- inbound.setIntoDate(null);
|
|
|
- inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
|
|
|
- inbound.setIntoQty(BigDecimal.ZERO);
|
|
|
- inbound.setIntoAmt(BigDecimal.ZERO);
|
|
|
- inboundMapper.updateById(inbound);
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 明细数据
|
|
|
- //根据总单id查明细
|
|
|
- List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
|
|
|
- for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
|
|
|
- //region 修改销售退货明细数据信息
|
|
|
- if(inboundItemResponse.getFromItemId()!=null){
|
|
|
- //查询
|
|
|
- PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
|
|
|
- PurchaseItem purchaseItem = new PurchaseItem();
|
|
|
- purchaseItem.setItemId(purchaseItemResponse.getItemId());
|
|
|
- purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().subtract(inboundItemResponse.getIntoQty()));
|
|
|
- purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().subtract(inboundItemResponse.getIntoAmt()));
|
|
|
- purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()));
|
|
|
- purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()));
|
|
|
- //入库状态
|
|
|
- String intoStatusItem = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
|
|
|
- purchaseItem.setIntoStatus(intoStatusItem);
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region修改入库明细信息
|
|
|
- InboundItem inboundItem = new InboundItem();
|
|
|
- inboundItem.setIntoId(inbound.getIntoId())
|
|
|
- .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
|
|
|
- .setIntoQty(BigDecimal.ZERO)
|
|
|
- .setIntoAmt(BigDecimal.ZERO)
|
|
|
- .setItemId(inboundItemResponse.getItemId());
|
|
|
- inboundItemMapper.updateById(inboundItem);
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
-
|
|
|
- //todo 调用库存 后续写库存这里补上
|
|
|
- //region 修改库存
|
|
|
-
|
|
|
- //endregion
|
|
|
-
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 入库状态通用(目前本页面)
|
|
|
- * @date : 2024/3/9 8:59
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
|
|
|
- //入库状态
|
|
|
- String intoStatus = null;
|
|
|
- //已入库数量=0 入库中数量>0
|
|
|
- if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- //入库中
|
|
|
- intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
|
|
|
- }
|
|
|
- //已入库数量=0 入库中数量=0
|
|
|
- else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- //待入库
|
|
|
- intoStatus = Constant.IntoStatus.DAIRUKU.getName();
|
|
|
- }
|
|
|
- //已入库数量>0 入库中数量>0
|
|
|
- else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- //入库中
|
|
|
- intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
|
|
|
- }
|
|
|
- return intoStatus;
|
|
|
- }
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public BaseMapper<Inbound> getRepository() {
|
|
|
+ return inboundMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundMapper inboundMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundConvert inboundConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundItemMapper inboundItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InboundItemConvert inboundItemConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseMapper purchaseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseItemMapper purchaseItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IntoReturnMapper intoReturnMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IntoReturnConvert intoReturnConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IntoReturnItemMapper intoReturnItemMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IntoReturnItemConvert intoReturnItemConvert;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonService commonService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 条件查询
|
|
|
+ * @date : 2024/3/7 14:12
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<InboundResponse>> selectInboundAndItem(InboundQuery inboundQuery) {
|
|
|
+ return super.mergeListWithCount(inboundQuery, inboundMapper.selectInboundAndItem(inboundQuery),
|
|
|
+ inboundMapper.selectInboundAndItemCountByCond(inboundQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 销售退货入库新建
|
|
|
+ * @date : 2024/3/7 14:13
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public ResponseResultVO<?> saleReturnInboundInsert(InboundVO inboundVO) {
|
|
|
+ //region 总单
|
|
|
+ //获取 id/单号
|
|
|
+ Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUND.getName(), false);
|
|
|
+ inboundVO.setIntoId(codeMap.get("outId").toString()).
|
|
|
+ setIntoNo(codeMap.get("outNote").toString());
|
|
|
+ //入库类型
|
|
|
+ inboundVO.setIntoType(Constant.IntoType.PURRETURN.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)
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ //实体转换
|
|
|
+ Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
|
+ inboundMapper.insert(inbound);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 销售退货
|
|
|
+ if (inboundVO.getFromId() != null) {
|
|
|
+ IntoReturn intoReturn = new IntoReturn();
|
|
|
+ IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
|
|
|
+ intoReturn.setReturnId(inboundVO.getFromId());
|
|
|
+ intoReturn.setOutingQty(intoReturnResponse.getOutingQty().subtract(inboundVO.getIntoingQty()));
|
|
|
+ intoReturn.setOutingAmt(intoReturnResponse.getOutingAmt().subtract(inboundVO.getIntoingAmt()));
|
|
|
+ intoReturn.setOutQty(intoReturnResponse.getOutQty().add(inboundVO.getIntoAmt()));
|
|
|
+ intoReturn.setOutAmt(intoReturnResponse.getOutAmt().add(inboundVO.getIntoQty()));
|
|
|
+ //出库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
|
|
|
+ intoReturn.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnMapper.updateById(intoReturn);
|
|
|
+ }
|
|
|
+ //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()) {
|
|
|
+ //region 明细
|
|
|
+ Map<String, Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(), true);
|
|
|
+ //明细id
|
|
|
+ inboundItemVO.setItemId(map.get("outId").toString());
|
|
|
+ //总单id
|
|
|
+ inboundItemVO.setIntoId(inboundVO.getIntoId());
|
|
|
+ //入库类型
|
|
|
+ inboundItemVO.setIntoType(inboundVO.getIntoType());
|
|
|
+ //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
|
+ if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
|
|
|
+ inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
+ .setIntoAmt(inboundItemVO.getIntoingAmt());
|
|
|
+ }
|
|
|
+ //成本单价
|
|
|
+ inboundItemVO.setCostPrice(inboundItemVO.getCostPrice());
|
|
|
+ //成本金额
|
|
|
+ inboundItemVO.setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ //库存数量 已入库-出库
|
|
|
+ inboundItemVO.setInvQty(inboundItemVO.getIntoQty().subtract(inboundItemVO.getOutQty()));
|
|
|
+ //入库状态
|
|
|
+ inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
|
|
|
+ //退货数量
|
|
|
+ inboundItemVO.setReturnQty(inboundItemVO.getIntoingQty());
|
|
|
+ //退货金额
|
|
|
+ inboundItemVO.setReturnAmt(inboundItemVO.getIntoingAmt());
|
|
|
+ //实体转换
|
|
|
+ InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
+ inboundItemMapper.insert(inboundItem);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 销售退货明细
|
|
|
+ if (inboundItemVO.getFromItemId() != null) {
|
|
|
+ IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
|
|
|
+ IntoReturnItem intoReturnItem = new IntoReturnItem();
|
|
|
+ intoReturnItem.setItemId(inboundItemVO.getFromItemId());
|
|
|
+ intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().add(inboundItemVO.getIntoQty()));
|
|
|
+ intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().add(inboundItemVO.getIntoAmt()));
|
|
|
+ intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().add(inboundItemVO.getIntoingQty()));
|
|
|
+ intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().add(inboundItemVO.getIntoingAmt()));
|
|
|
+ //出库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
|
|
|
+ intoReturnItem.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnItemMapper.updateById(intoReturnItem);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //todo 如果是已入库 调用库存 后续写库存这里补上
|
|
|
+ //region 库存
|
|
|
+
|
|
|
+
|
|
|
+ //endregion
|
|
|
+
|
|
|
+
|
|
|
+ return ResponseResultUtil.success(inboundVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 销售退货入库办理
|
|
|
+ * @date : 2024/3/7 15:47
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public ResponseResultVO<?> saleReturnHandleInbound(InboundVO inboundVO) {
|
|
|
+ //大编辑标识
|
|
|
+ if (inboundVO.getAllEdit() != null && inboundVO.getAllEdit()) {
|
|
|
+ //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()) {
|
|
|
+ if (inboundItemVO.getIntoId() != null) {
|
|
|
+ //编辑明细
|
|
|
+ inboundItemVO.setCostPrice(inboundItemVO.getPriceInto())
|
|
|
+ .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
+ .setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
+ .setIntoAmt(inboundItemVO.getIntoingAmt());
|
|
|
+ //入库状态
|
|
|
+ String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
|
|
|
+ inboundItemVO.setIntoStatus(intoStatus);
|
|
|
+ //实体转换
|
|
|
+ InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
+ //修改
|
|
|
+ inboundItemMapper.updateById(inboundItem);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ //region 新建明细
|
|
|
+ else {
|
|
|
+ Map<String, Object> map = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUNDITEM.getName(), true);
|
|
|
+ inboundItemVO
|
|
|
+ .setItemId(map.get("outId").toString())
|
|
|
+ .setIntoQty(inboundItemVO.getIntoingQty())
|
|
|
+ .setIntoAmt(inboundItemVO.getIntoingAmt())
|
|
|
+ .setIntoId(inboundVO.getIntoId())
|
|
|
+ .setCostPrice(inboundItemVO.getPriceInto())
|
|
|
+ .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
+ .setIntoType(Constant.IntoType.PURRETURN.getName());
|
|
|
+ //入库状态
|
|
|
+ String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
|
|
|
+ inboundItemVO.setIntoStatus(intoStatus);
|
|
|
+ //实体转换
|
|
|
+ InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
+ //新建
|
|
|
+ inboundItemMapper.insert(inboundItem);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 销售退货明细
|
|
|
+ if (inboundItemVO.getFromItemId() != null) {
|
|
|
+ IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
|
|
|
+ IntoReturnItem intoReturnItem = new IntoReturnItem();
|
|
|
+ intoReturnItem.setItemId(inboundItemVO.getFromItemId());
|
|
|
+ intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().add(inboundItemVO.getIntoQty()));
|
|
|
+ intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().add(inboundItemVO.getIntoAmt()));
|
|
|
+ intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().add(inboundItemVO.getIntoingQty()));
|
|
|
+ intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().add(inboundItemVO.getIntoingAmt()));
|
|
|
+ //出库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
|
|
|
+ intoReturnItem.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnItemMapper.updateById(intoReturnItem);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 删除明细
|
|
|
+ BigDecimal sumDelOutQty = BigDecimal.ZERO;
|
|
|
+ BigDecimal sumDelOutAmt = BigDecimal.ZERO;
|
|
|
+ BigDecimal sumDelOutingQty = BigDecimal.ZERO;
|
|
|
+ BigDecimal sumDelOutingAmt = BigDecimal.ZERO;
|
|
|
+ if (inboundVO.getDeleteItemList() != null) {
|
|
|
+ sumDelOutQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ sumDelOutAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ sumDelOutingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ sumDelOutingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
|
|
|
+ if (inboundItemVO.getItemId() != null) {
|
|
|
+ InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
+ inboundItem.setFlgValid(false);
|
|
|
+ inboundItemMapper.updateById(inboundItem);
|
|
|
+ }
|
|
|
+ //region 销售退货明细
|
|
|
+ if (inboundItemVO.getFromItemId() != null) {
|
|
|
+ //region 销售退货订单明细
|
|
|
+ IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
|
|
|
+ IntoReturnItem intoReturnItem = new IntoReturnItem();
|
|
|
+ intoReturnItem.setItemId(inboundItemVO.getFromItemId());
|
|
|
+ intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().subtract(inboundItemVO.getIntoQty()));
|
|
|
+ intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().subtract(inboundItemVO.getIntoAmt()));
|
|
|
+ intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().subtract(inboundItemVO.getIntoingQty()));
|
|
|
+ intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().subtract(inboundItemVO.getIntoingAmt()));
|
|
|
+ //出库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
|
|
|
+ intoReturnItem.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnItemMapper.updateById(intoReturnItem);
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 编辑总单
|
|
|
+ BigDecimal sumOutQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal sumOutAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal sumOutingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal sumOutingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ inboundVO.setIntoQty(sumOutQty);
|
|
|
+ inboundVO.setIntoAmt(sumOutAmt);
|
|
|
+ inboundVO.setIntoingQty(sumOutingQty);
|
|
|
+ inboundVO.setIntoAmt(sumOutingAmt);
|
|
|
+ //已入库数量==入库中数量 入库完成
|
|
|
+ if (inboundVO.getIntoQty().compareTo(inboundVO.getIntoingQty()) == 0) {
|
|
|
+ //已入库
|
|
|
+ inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
|
+ } else {
|
|
|
+ //入库中
|
|
|
+ inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
|
|
|
+ }
|
|
|
+ //实体转换
|
|
|
+ Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
|
+ //修改
|
|
|
+ inboundMapper.updateById(inbound);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 修改销售退货订单
|
|
|
+ if (inboundVO.getFromId() != null) {
|
|
|
+ IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
|
|
|
+ IntoReturn intoReturn = new IntoReturn();
|
|
|
+ intoReturn.setReturnId(inboundVO.getFromId());
|
|
|
+ intoReturn.setOutQty(intoReturnResponse.getOutQty().add(sumOutQty).subtract(sumDelOutQty));
|
|
|
+ intoReturn.setOutAmt(intoReturnResponse.getOutAmt().add(sumOutAmt).subtract(sumDelOutAmt));
|
|
|
+ intoReturn.setOutingQty(intoReturnResponse.getOutingQty().subtract(sumOutQty).subtract(sumDelOutingQty));
|
|
|
+ intoReturn.setOutingAmt(intoReturnResponse.getOutingAmt().subtract(sumOutAmt).subtract(sumDelOutingAmt));
|
|
|
+ //入库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
|
|
|
+ intoReturn.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnMapper.updateById(intoReturn);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //todo 如果是已入库 调用库存 后续写库存这里补上
|
|
|
+ //region 修改库存
|
|
|
+
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ return ResponseResultUtil.success(inboundVO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 销售退货入库撤销
|
|
|
+ * @date : 2024/3/7 17:06
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public ResponseResultVO<?> saleReturnInboundCancel(InboundVO inboundVO) {
|
|
|
+ //region 查询入库总单数据信息
|
|
|
+ InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 修改订单数据信息
|
|
|
+ if (inboundVO.getFromId() != null) {
|
|
|
+ //查询
|
|
|
+ IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
|
|
|
+ //赋值
|
|
|
+ IntoReturn intoReturn = new IntoReturn();
|
|
|
+ intoReturn.setReturnId(inboundVO.getFromId());
|
|
|
+ intoReturn.setOutQty(intoReturnResponse.getOutQty().add(inboundResponse.getIntoQty()));
|
|
|
+ intoReturn.setOutAmt(intoReturnResponse.getOutAmt().add(inboundResponse.getIntoAmt()));
|
|
|
+ intoReturn.setOutingQty(intoReturnResponse.getOutingQty().subtract(inboundResponse.getIntoQty()));
|
|
|
+ intoReturn.setOutingAmt(intoReturnResponse.getOutingAmt().subtract(inboundResponse.getIntoAmt()));
|
|
|
+ //出库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturn.getOutingQty(), intoReturn.getOutQty());
|
|
|
+ intoReturn.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnMapper.updateById(intoReturn);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 修改总单数据信息
|
|
|
+ Inbound inbound = new Inbound();
|
|
|
+ inbound.setIntoId(inboundVO.getIntoId());
|
|
|
+ inbound.setIntoDate(null);
|
|
|
+ inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
|
|
|
+ inbound.setIntoQty(BigDecimal.ZERO);
|
|
|
+ inbound.setIntoAmt(BigDecimal.ZERO);
|
|
|
+ inboundMapper.updateById(inbound);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 明细数据
|
|
|
+ //根据总单id查明细
|
|
|
+ List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
|
|
|
+ for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
|
|
|
+ //region 修改销售退货明细数据信息
|
|
|
+ if (inboundItemResponse.getFromItemId() != null) {
|
|
|
+ //查询
|
|
|
+ IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemResponse.getFromItemId());
|
|
|
+ IntoReturnItem intoReturnItem = new IntoReturnItem();
|
|
|
+ intoReturnItem.setItemId(inboundItemResponse.getFromItemId());
|
|
|
+ intoReturnItem.setOutQty(intoReturnItemResponse.getOutQty().subtract(inboundItemResponse.getIntoQty()));
|
|
|
+ intoReturnItem.setOutAmt(intoReturnItemResponse.getOutAmt().subtract(inboundItemResponse.getIntoAmt()));
|
|
|
+ intoReturnItem.setOutingQty(intoReturnItemResponse.getOutingQty().add(inboundItemResponse.getIntoQty()));
|
|
|
+ intoReturnItem.setOutingAmt(intoReturnItemResponse.getOutingAmt().add(inboundItemResponse.getIntoAmt()));
|
|
|
+ //出库状态
|
|
|
+ String outStatus = this.setOutStatus(intoReturnItem.getOutingQty(), intoReturnItem.getOutQty());
|
|
|
+ intoReturnItem.setOutStatus(outStatus);
|
|
|
+ //修改
|
|
|
+ intoReturnItemMapper.updateById(intoReturnItem);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region修改入库明细信息
|
|
|
+ InboundItem inboundItem = new InboundItem();
|
|
|
+ inboundItem.setIntoId(inbound.getIntoId())
|
|
|
+ .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
|
|
|
+ .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
|
|
|
+ .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
|
|
|
+ .setIntoQty(BigDecimal.ZERO)
|
|
|
+ .setIntoAmt(BigDecimal.ZERO)
|
|
|
+ .setItemId(inboundItemResponse.getItemId());
|
|
|
+ inboundItemMapper.updateById(inboundItem);
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+
|
|
|
+ //todo 调用库存 后续写库存这里补上
|
|
|
+ //region 修改库存
|
|
|
+
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 入库状态通用(目前本页面)
|
|
|
+ * @date : 2024/3/9 8:59
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
|
|
|
+ //入库状态
|
|
|
+ String intoStatus = null;
|
|
|
+ //已入库数量=0 入库中数量>0
|
|
|
+ if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //入库中
|
|
|
+ intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
|
|
|
+ }
|
|
|
+ //已入库数量=0 入库中数量=0
|
|
|
+ else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ //待入库
|
|
|
+ intoStatus = Constant.IntoStatus.DAIRUKU.getName();
|
|
|
+ }
|
|
|
+ //已入库数量>0 入库中数量>0
|
|
|
+ else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //入库中
|
|
|
+ intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
|
|
|
+ }
|
|
|
+ return intoStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 出库状态通用(目前本页面)
|
|
|
+ * @date : 2024/3/9 8:59
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ public String setOutStatus(BigDecimal outingQty, BigDecimal outQty) {
|
|
|
+ //入库状态
|
|
|
+ String outStatus = null;
|
|
|
+ //已入库数量=0 入库中数量>0
|
|
|
+ if (outQty.compareTo(BigDecimal.ZERO) == 0 && outingQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //入库中
|
|
|
+ outStatus = Constant.OutStatus.CHUKUZHONG.getName();
|
|
|
+ }
|
|
|
+ //已入库数量=0 入库中数量=0
|
|
|
+ else if (outQty.compareTo(BigDecimal.ZERO) == 0 && outingQty.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ //待入库
|
|
|
+ outStatus = Constant.OutStatus.DAICHUKU.getName();
|
|
|
+ }
|
|
|
+ //已入库数量>0 入库中数量>0
|
|
|
+ else if (outQty.compareTo(BigDecimal.ZERO) > 0 && outingQty.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ //入库中
|
|
|
+ outStatus = Constant.OutStatus.YICHUKU.getName();
|
|
|
+ }
|
|
|
+ return outStatus;
|
|
|
+ }
|
|
|
+
|
|
|
}
|