|
|
@@ -1,46 +1,17 @@
|
|
|
package com.dk.mdm.service.ivt.outbound;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-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.model.pojo.PageList;
|
|
|
-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.mapper.pur.PurchaseItemMapper;
|
|
|
-import com.dk.mdm.mapper.sale.OrderItemMapper;
|
|
|
-import com.dk.mdm.mapper.sale.OrderMapper;
|
|
|
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.pojo.sale.Order;
|
|
|
-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.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 com.dk.mdm.service.sale.OrderItemService;
|
|
|
-import com.dk.mdm.service.sale.OrderService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
-
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class OutboundService extends BaseService<Outbound> {
|
|
|
@@ -59,24 +30,9 @@ public class OutboundService extends BaseService<Outbound> {
|
|
|
private OutboundMapper outboundMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private OutboundItemService outboundItemService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private OutboundItemMapper outboundItemMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private OrderService orderService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private OrderMapper orderMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private OrderItemService orderItemService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private OrderItemMapper orderItemMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private CommonService commonService;
|
|
|
|
|
|
@Autowired
|
|
|
@@ -85,304 +41,606 @@ public class OutboundService extends BaseService<Outbound> {
|
|
|
@Autowired
|
|
|
private OutboundItemConvert outboundItemConvert;
|
|
|
|
|
|
- @Autowired
|
|
|
- private PurchaseItemMapper purchaseItemMapper;
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询
|
|
|
- * @author : 付斌
|
|
|
- * @date : 2023/1/9 10:40
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<OutboundResponse>> selectByCond(OutboundQuery outboundQuery) {
|
|
|
- return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
|
|
|
- outboundMapper.countByCond(outboundQuery));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 查询订单明细(货物、收款、附件)
|
|
|
- * @author : 付斌
|
|
|
- * @date : 2024-02-28 13:25
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<Map<String, Object>> selectOutboundInfoById(String id) {
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- // 商品明细
|
|
|
- List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
|
|
|
- result.put("outboundItem", outboundItem);
|
|
|
-
|
|
|
- // 收款
|
|
|
-
|
|
|
- // 附件
|
|
|
- return ResponseResultUtil.success(result);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 查询订单明细(货物、收款、附件)
|
|
|
- * @author : 付斌
|
|
|
- * @date : 2024-02-28 13:25
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO selectById(String id) {
|
|
|
-
|
|
|
- OutboundResponse outboundResponse = outboundMapper.selectById(id);
|
|
|
- // 商品明细
|
|
|
- List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
|
|
|
- outboundResponse.setGoodsList(outboundItem);
|
|
|
-
|
|
|
- // 收款
|
|
|
-
|
|
|
- // 附件
|
|
|
- return ResponseResultUtil.success(outboundResponse);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @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.getItemList() != null && outboundVO.getItemList().size() > 0) {
|
|
|
- double sumOutingQty = 0; // 合计出库中数量
|
|
|
- double sumOutingAmt = 0; // 合计出库中金额
|
|
|
- OrderItem orderItemForUpdate;
|
|
|
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
|
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
- outboundItem.setOutId(outbound.getOutId()).setCpId(outbound.getCpId()).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
- .setOutType(Constant.OutType.SALE.getName());
|
|
|
- outboundItemMapper.insert(outboundItem);
|
|
|
-
|
|
|
- // 反写订单出库中数量、金额
|
|
|
- orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItem.getFromItemId());
|
|
|
- // 如果(商品数量-已出库数量) 小于(订单出库中数量+本次出库单出库中数量)
|
|
|
- if ((orderItemForUpdate.getItemQty().subtract(orderItemForUpdate.getOutQty())).compareTo(orderItemForUpdate.getOutingQty().add(outboundItem.getOutingQty())) == -1) {
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
- }
|
|
|
- OrderItem orderItemUpdate = new OrderItem();
|
|
|
- orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().add(outboundItem.getOutingQty()))
|
|
|
- .setOutingAmt(orderItemForUpdate.getOutingAmt().add(outboundItem.getOutingAmt()))
|
|
|
- .setItemId(orderItemForUpdate.getItemId());
|
|
|
- orderItemService.updateByUuid(orderItemUpdate);
|
|
|
- // 累加出库中数量,金额
|
|
|
- sumOutingQty += outboundItem.getOutingQty().doubleValue();
|
|
|
- sumOutingAmt += outboundItem.getOutingAmt().doubleValue();
|
|
|
-
|
|
|
- }
|
|
|
- // 更新订单上的出库中数量,金额,状态
|
|
|
- Order orderForUpdate = orderMapper.selectByIdForUpdate(outboundVO.getFromId());
|
|
|
- Order orderUpdate = new Order();
|
|
|
- orderUpdate.setOutingQty(orderForUpdate.getOutingQty().add(new BigDecimal(sumOutingQty)))
|
|
|
- .setOutingAmt(orderForUpdate.getOutingAmt().add(new BigDecimal(sumOutingAmt)))
|
|
|
- .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
- .setOrderId(outboundVO.getFromId());
|
|
|
- orderService.updateByUuid(orderUpdate);
|
|
|
- }
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 编辑方法
|
|
|
- * @author : 付斌
|
|
|
- * @date : 2023/1/9 10:49
|
|
|
- */
|
|
|
- @Transactional(
|
|
|
- rollbackFor = {Exception.class}
|
|
|
- )
|
|
|
- public ResponseResultVO<Boolean> update(OutboundVO outboundVO) {
|
|
|
- // 订单明细实体
|
|
|
- OrderItem orderItemForUpdate;
|
|
|
- // 出库明细实体
|
|
|
- OutboundItem outboundItemForUpdate;
|
|
|
-
|
|
|
- // 编辑出库明细
|
|
|
- List<OutboundItemVO> editOutboundItemVOList = outboundVO.getItemList();
|
|
|
- for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
|
|
|
- outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getItemId());
|
|
|
- // 出库中数量不能小于出库数量
|
|
|
- if (outboundItemForUpdate.getOutingQty().compareTo(outboundItemVO.getOutQty()) == -1) {
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTINGQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
- }
|
|
|
- orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemVO.getFromItemId());
|
|
|
-
|
|
|
- // (订单的商品数量-订单已出库数量)不能小于(订单之前的出库中数量 - 出库明细之前的出库中数量 + 出库明细现在的出库中数量)
|
|
|
- if ((orderItemForUpdate.getItemQty().subtract(orderItemForUpdate.getOutQty())).compareTo(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty())) == -1) {
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
- }
|
|
|
- // 更新订单明细出库中数量
|
|
|
- OrderItem orderItemUpdate = new OrderItem();
|
|
|
- orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty()))
|
|
|
- .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()).add(outboundItemVO.getOutingAmt()))
|
|
|
- .setItemId(orderItemForUpdate.getItemId());
|
|
|
- orderItemService.updateByUuid(orderItemUpdate);
|
|
|
- // 更新出库明细
|
|
|
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
- outboundItemService.updateByUuid(outboundItem);
|
|
|
- }
|
|
|
-
|
|
|
- // 计算订单明细的出库中数量,金额合计
|
|
|
- List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(outboundVO.getFromId());
|
|
|
- OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
- OrderItem item = new OrderItem();
|
|
|
- item.setOutingQty(x.getOutingQty().add(y.getOutingQty()));
|
|
|
- item.setOutingAmt(x.getOutingAmt().add(y.getOutingAmt()));
|
|
|
- return item;
|
|
|
- }).get();
|
|
|
- // 更新订单上的出库中数量,金额
|
|
|
- Order orderUpdate = new Order();
|
|
|
- orderUpdate.setOutingQty(orderItem.getOutingQty()).setOutingAmt(orderItem.getOutingAmt()).setOrderId(outboundVO.getFromId());
|
|
|
- orderService.updateByUuid(orderUpdate);
|
|
|
-
|
|
|
- // 转化实体、更新出库单总表
|
|
|
- Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
- return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
- UUID.fromString(outbound.getOutId()))));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 作废
|
|
|
- * @author : 付斌
|
|
|
- * @date : 2024-03-08 16:38
|
|
|
- */
|
|
|
- public ResponseResultVO<?> invalid(String id) {
|
|
|
- Outbound outboundForUpdate = outboundMapper.selectByIdForUpdate(id);
|
|
|
- // 并发校验
|
|
|
- if(!outboundForUpdate.getFlgValid()){
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
|
|
|
- }
|
|
|
- // 如果出库数量或退货数量不是0,不能作废
|
|
|
- if (outboundForUpdate.getOutQty().compareTo(BigDecimal.ZERO) != 0 || outboundForUpdate.getReturnQty().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 查出并锁定所有的出库明细
|
|
|
- List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(id);
|
|
|
- OrderItem orderItemForUpdate;
|
|
|
- for (OutboundItem outboundItemForUpdate : outboundItemList) {
|
|
|
- orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemForUpdate.getFromItemId());
|
|
|
- // 更新订单明细出库中数量
|
|
|
- OrderItem orderItemUpdate = new OrderItem();
|
|
|
- orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()))
|
|
|
- .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()))
|
|
|
- .setItemId(orderItemForUpdate.getItemId());
|
|
|
- if(orderItemUpdate.getOutingQty().compareTo(BigDecimal.ZERO) == 0){
|
|
|
- orderItemUpdate.setOutStatus(Constant.OutStatus.DAICHUKU.getName());
|
|
|
- }
|
|
|
- orderItemService.updateByUuid(orderItemUpdate);
|
|
|
- }
|
|
|
-
|
|
|
- // 计算订单明细的出库中数量,金额合计
|
|
|
- List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(outboundForUpdate.getFromId());
|
|
|
- OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
- OrderItem item = new OrderItem();
|
|
|
- item.setOutingQty(x.getOutingQty().add(y.getOutingQty()));
|
|
|
- item.setOutingAmt(x.getOutingAmt().add(y.getOutingAmt()));
|
|
|
- return item;
|
|
|
- }).get();
|
|
|
- // 更新订单上的出库中数量,金额
|
|
|
- Order orderUpdate = new Order();
|
|
|
- orderUpdate.setOutingQty(orderItem.getOutingQty()).setOutingAmt(orderItem.getOutingAmt()).setOrderId(outboundForUpdate.getFromId());
|
|
|
- if(orderUpdate.getOutingQty().compareTo(BigDecimal.ZERO) == 0){
|
|
|
- orderUpdate.setOutStatus(Constant.OutStatus.DAICHUKU.getName());
|
|
|
- }
|
|
|
-
|
|
|
- orderService.updateByUuid(orderUpdate);
|
|
|
-
|
|
|
- // 作废
|
|
|
- Outbound outboundUpdate = new Outbound();
|
|
|
- outboundUpdate.setFlgValid(false).setOutId(id);
|
|
|
- super.update(outboundUpdate, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
- UUID.fromString(outboundUpdate.getOutId())));
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 获取订单信息(编辑用)
|
|
|
- * @author : 付斌
|
|
|
- * @date : 2024-03-02 17:27
|
|
|
- */
|
|
|
- public ResponseResultVO<?> getOutboundForUpdate(String id) {
|
|
|
- Map<String, Object> dataInfo = new HashMap<>();
|
|
|
- OutboundResponse outboundResponse = outboundMapper.selectById(id);
|
|
|
- dataInfo.put("data", outboundResponse);
|
|
|
-
|
|
|
- // 商品明细
|
|
|
- List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCondForOutEdit(id);
|
|
|
- dataInfo.put("dataItem", outboundItemResponseList);
|
|
|
- return ResponseResultUtil.success(dataInfo);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 采购退货出库
|
|
|
- * @author : 于继渤
|
|
|
- * @date : 2023/1/9 10:49
|
|
|
- */
|
|
|
- @Transactional(
|
|
|
- rollbackFor = {Exception.class}
|
|
|
- )
|
|
|
- public ResponseResultVO<?> insertOutBound(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.PURRETURN.getName());
|
|
|
- // 转化实体
|
|
|
- Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
- // 总单保存
|
|
|
- super.insert(outbound);
|
|
|
-
|
|
|
- // 明细保存
|
|
|
- if (outboundVO.getItemList() != null && outboundVO.getItemList().size() > 0) {
|
|
|
- double sumOutingQty = 0; // 合计出库中数量
|
|
|
- double sumOutingAmt = 0; // 合计出库中金额
|
|
|
- for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
|
- OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
- outboundItem
|
|
|
- .setOutId(outbound.getOutId())
|
|
|
- .setCpId(outbound.getCpId())
|
|
|
- .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
- .setOutType(Constant.OutType.PURRETURN.getName());
|
|
|
- outboundItemMapper.insert(outboundItem);
|
|
|
-
|
|
|
-// PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(outboundItem.getFromItemId());
|
|
|
-
|
|
|
- // 如果商品数量小于订单+本次出库单上的出库中数量
|
|
|
-// if(orderItem.getItemQty().compareTo(orderItem.getOutingQty().add(outboundItem.getOutingQty())) == -1){
|
|
|
-// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
-// }else{
|
|
|
-// OrderItem orderItemUpdate = new OrderItem();
|
|
|
-// orderItemUpdate.setOutingQty(orderItem.getOutingQty().add(outboundItem.getOutingQty()))
|
|
|
-// .setOutingAmt(orderItem.getOutingAmt().add(outboundItem.getOutingAmt()))
|
|
|
-// .setItemId(orderItem.getItemId());
|
|
|
-// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
-// // 累加出库中数量,金额
|
|
|
-// sumOutingQty += outboundItem.getOutingQty().doubleValue();
|
|
|
-// sumOutingAmt += outboundItem.getOutingAmt().doubleValue();
|
|
|
-// }
|
|
|
- }
|
|
|
-// // 更新订单上的出库中数量,金额,状态
|
|
|
-// OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
|
|
|
-// Order orderUpdate = new Order();
|
|
|
-// orderUpdate.setOutingQty(orderResponse.getOutingQty().add(new BigDecimal(sumOutingQty)))
|
|
|
-// .setOutingAmt(orderResponse.getOutingAmt().add(new BigDecimal(sumOutingAmt)))
|
|
|
-// .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
-// .setOrderId(outboundVO.getFromId());
|
|
|
-// orderService.updateByUuid(orderUpdate);
|
|
|
- }
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
|
|
|
+// /**
|
|
|
+// * @desc : 一览页销售出库
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2023/1/9 10:40
|
|
|
+// */
|
|
|
+// @Pagination
|
|
|
+// public ResponseResultVO<PageList<OutboundResponse>> selectByCond(OutboundQuery outboundQuery) {
|
|
|
+// return super.mergeListWithCount(outboundQuery, outboundMapper.selectByCond(outboundQuery),
|
|
|
+// outboundMapper.countByCond(outboundQuery));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 一览页销售出库明细(货物、附件)
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2024-02-28 13:25
|
|
|
+// */
|
|
|
+// @Pagination
|
|
|
+// public ResponseResultVO<Map<String, Object>> selectOutboundInfoById(String id) {
|
|
|
+// Map<String, Object> result = new HashMap<>();
|
|
|
+// // 商品明细
|
|
|
+// List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
|
|
|
+// result.put("outboundItem", outboundItem);
|
|
|
+//
|
|
|
+//
|
|
|
+// // 附件
|
|
|
+// return ResponseResultUtil.success(result);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 查询出库明细(货物、附件)
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2024-02-28 13:25
|
|
|
+// */
|
|
|
+// @Pagination
|
|
|
+// public ResponseResultVO selectById(String id) {
|
|
|
+//
|
|
|
+// OutboundResponse outboundResponse = outboundMapper.selectById(id);
|
|
|
+// // 商品明细
|
|
|
+// List<OutboundItemResponse> outboundItem = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(id));
|
|
|
+// outboundResponse.setGoodsList(outboundItem);
|
|
|
+//
|
|
|
+// // 附件
|
|
|
+// return ResponseResultUtil.success(outboundResponse);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 获取销售出库信息(编辑用)
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2024-03-02 17:27
|
|
|
+// */
|
|
|
+// public ResponseResultVO<?> getOutboundForUpdate(String id) {
|
|
|
+// Map<String, Object> dataInfo = new HashMap<>();
|
|
|
+// OutboundResponse outboundResponse = outboundMapper.selectById(id);
|
|
|
+// dataInfo.put("data", outboundResponse);
|
|
|
+//
|
|
|
+// // 商品明细
|
|
|
+// List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCondForOutEdit(id);
|
|
|
+// dataInfo.put("dataItem", outboundItemResponseList);
|
|
|
+// return ResponseResultUtil.success(dataInfo);
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 获取销售退货信息(编辑用)
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2024-03-02 17:27
|
|
|
+// */
|
|
|
+// public ResponseResultVO<?> getOutReturnForUpdate(String id) {
|
|
|
+// Map<String, Object> dataInfo = new HashMap<>();
|
|
|
+// OutboundResponse outboundResponse = outboundMapper.selectById(id);
|
|
|
+// dataInfo.put("data", outboundResponse);
|
|
|
+//
|
|
|
+// // 商品明细
|
|
|
+// List<OutboundItemResponse> outboundItemResponse = outboundItemMapper.selectByCondForReturnEdit(id);
|
|
|
+// dataInfo.put("dataItem", outboundItemResponse);
|
|
|
+// return ResponseResultUtil.success(dataInfo);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * @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.getItemList() != null && outboundVO.getItemList().size() > 0) {
|
|
|
+// double sumOutingQty = 0; // 合计出库中数量
|
|
|
+// double sumOutingAmt = 0; // 合计出库中金额
|
|
|
+// OrderItem orderItemForUpdate;
|
|
|
+// for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
|
+// OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+// outboundItem.setOutId(outbound.getOutId()).setCpId(outbound.getCpId()).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
+// .setOutType(Constant.OutType.SALE.getName());
|
|
|
+// outboundItemMapper.insert(outboundItem);
|
|
|
+//
|
|
|
+// // 反写订单出库中数量、金额
|
|
|
+// orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItem.getFromItemId());
|
|
|
+// // 如果(商品数量-已出库数量) 小于(订单出库中数量+本次出库单出库中数量)
|
|
|
+// if ((orderItemForUpdate.getItemQty().subtract(orderItemForUpdate.getOutQty())).compareTo(orderItemForUpdate.getOutingQty().add(outboundItem.getOutingQty())) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
+// }
|
|
|
+// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+// orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().add(outboundItem.getOutingQty()))
|
|
|
+// .setOutingAmt(orderItemForUpdate.getOutingAmt().add(outboundItem.getOutingAmt()))
|
|
|
+// .setItemId(orderItemForUpdate.getItemId());
|
|
|
+// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+// // 累加出库中数量,金额
|
|
|
+// sumOutingQty += outboundItem.getOutingQty().doubleValue();
|
|
|
+// sumOutingAmt += outboundItem.getOutingAmt().doubleValue();
|
|
|
+//
|
|
|
+// }
|
|
|
+// // 更新订单上的出库中数量,金额,状态
|
|
|
+// Order orderForUpdate = orderMapper.selectByIdForUpdate(outboundVO.getFromId());
|
|
|
+// Order orderUpdate = new Order();
|
|
|
+// orderUpdate.setOutingQty(orderForUpdate.getOutingQty().add(new BigDecimal(sumOutingQty)))
|
|
|
+// .setOutingAmt(orderForUpdate.getOutingAmt().add(new BigDecimal(sumOutingAmt)))
|
|
|
+// .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
+// .setOrderId(outboundVO.getFromId());
|
|
|
+// orderService.updateByUuid(orderUpdate);
|
|
|
+// }
|
|
|
+// return ResponseResultUtil.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 编辑方法
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2023/1/9 10:49
|
|
|
+// */
|
|
|
+// @Transactional(
|
|
|
+// rollbackFor = {Exception.class}
|
|
|
+// )
|
|
|
+// public ResponseResultVO<Boolean> update(OutboundVO outboundVO) {
|
|
|
+// // 订单明细实体
|
|
|
+// OrderItem orderItemForUpdate;
|
|
|
+// // 出库明细实体
|
|
|
+// OutboundItem outboundItemForUpdate;
|
|
|
+//
|
|
|
+// // 编辑出库明细
|
|
|
+// List<OutboundItemVO> editOutboundItemVOList = outboundVO.getItemList();
|
|
|
+// for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
|
|
|
+// outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getItemId());
|
|
|
+// // 出库中数量不能小于出库数量
|
|
|
+// if (outboundItemForUpdate.getOutingQty().compareTo(outboundItemVO.getOutQty()) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTINGQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
+// }
|
|
|
+// orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemVO.getFromItemId());
|
|
|
+//
|
|
|
+// // (订单的商品数量-订单已出库数量)不能小于(订单之前的出库中数量 - 出库明细之前的出库中数量 + 出库明细现在的出库中数量)
|
|
|
+// if ((orderItemForUpdate.getItemQty().subtract(orderItemForUpdate.getOutQty())).compareTo(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty())) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
+// }
|
|
|
+// // 更新订单明细出库中数量
|
|
|
+// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+// orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()).add(outboundItemVO.getOutingQty()))
|
|
|
+// .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()).add(outboundItemVO.getOutingAmt()))
|
|
|
+// .setItemId(orderItemForUpdate.getItemId());
|
|
|
+// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+// // 更新出库明细
|
|
|
+// OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+// outboundItemService.updateByUuid(outboundItem);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 计算订单明细的出库中数量,金额合计
|
|
|
+// List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(outboundVO.getFromId());
|
|
|
+// OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
+// OrderItem item = new OrderItem();
|
|
|
+// item.setOutingQty(x.getOutingQty().add(y.getOutingQty()));
|
|
|
+// item.setOutingAmt(x.getOutingAmt().add(y.getOutingAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新订单上的出库中数量,金额
|
|
|
+// Order orderUpdate = new Order();
|
|
|
+// orderUpdate.setOutingQty(orderItem.getOutingQty()).setOutingAmt(orderItem.getOutingAmt()).setOrderId(outboundVO.getFromId());
|
|
|
+// orderService.updateByUuid(orderUpdate);
|
|
|
+//
|
|
|
+// // 转化实体、更新出库单总表
|
|
|
+// Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
+// return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
+// UUID.fromString(outbound.getOutId()))));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 作废
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2024-03-08 16:38
|
|
|
+// */
|
|
|
+// public ResponseResultVO<?> invalid(String id) {
|
|
|
+// Outbound outboundForUpdate = outboundMapper.selectByIdForUpdate(id);
|
|
|
+// // 并发校验
|
|
|
+// if (!outboundForUpdate.getFlgValid()) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
|
|
|
+// }
|
|
|
+// // 如果出库数量或退货数量不是0,不能作废
|
|
|
+// if (outboundForUpdate.getOutQty().compareTo(BigDecimal.ZERO) != 0 || outboundForUpdate.getReturnQty().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 查出并锁定所有的出库明细
|
|
|
+// List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(id);
|
|
|
+// OrderItem orderItemForUpdate;
|
|
|
+// for (OutboundItem outboundItemForUpdate : outboundItemList) {
|
|
|
+// orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemForUpdate.getFromItemId());
|
|
|
+// // 更新订单明细出库中数量
|
|
|
+// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+// orderItemUpdate.setOutingQty(orderItemForUpdate.getOutingQty().subtract(outboundItemForUpdate.getOutingQty()))
|
|
|
+// .setOutingAmt(orderItemForUpdate.getOutingAmt().subtract(outboundItemForUpdate.getOutingAmt()))
|
|
|
+// .setItemId(orderItemForUpdate.getItemId());
|
|
|
+// if (orderItemUpdate.getOutingQty().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// orderItemUpdate.setOutStatus(Constant.OutStatus.DAICHUKU.getName());
|
|
|
+// }
|
|
|
+// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 计算订单明细的出库中数量,金额合计
|
|
|
+// List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(outboundForUpdate.getFromId());
|
|
|
+// OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
+// OrderItem item = new OrderItem();
|
|
|
+// item.setOutingQty(x.getOutingQty().add(y.getOutingQty()));
|
|
|
+// item.setOutingAmt(x.getOutingAmt().add(y.getOutingAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新订单上的出库中数量,金额
|
|
|
+// Order orderUpdate = new Order();
|
|
|
+// orderUpdate.setOutingQty(orderItem.getOutingQty()).setOutingAmt(orderItem.getOutingAmt()).setOrderId(outboundForUpdate.getFromId());
|
|
|
+// if (orderUpdate.getOutingQty().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+// orderUpdate.setOutStatus(Constant.OutStatus.DAICHUKU.getName());
|
|
|
+// }
|
|
|
+//
|
|
|
+// orderService.updateByUuid(orderUpdate);
|
|
|
+//
|
|
|
+// // 作废
|
|
|
+// Outbound outboundUpdate = new Outbound();
|
|
|
+// outboundUpdate.setFlgValid(false).setOutId(id);
|
|
|
+// super.update(outboundUpdate, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
+// UUID.fromString(outboundUpdate.getOutId())));
|
|
|
+// return ResponseResultUtil.success();
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * @desc : 新建销售出库退货
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2023/1/9 10:49
|
|
|
+// */
|
|
|
+// @Transactional(
|
|
|
+// rollbackFor = {Exception.class}
|
|
|
+// )
|
|
|
+// public ResponseResultVO<?> insertOutReturn(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.getItemList() != null && outboundVO.getItemList().size() > 0) {
|
|
|
+// OrderItem orderItemForUpdate;
|
|
|
+// OutboundItem outboundItemForUpdate;
|
|
|
+// String sOrderId = null;
|
|
|
+//
|
|
|
+// // 出库IdList,一个退货单可能有多个出库单
|
|
|
+// List<String> outIdList = new ArrayList<>();
|
|
|
+// for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
|
+// // 把出库Id存起来
|
|
|
+// if (!outIdList.contains(outboundItemVO.getSOutId())) {
|
|
|
+// outIdList.add(outboundItemVO.getSOutId());
|
|
|
+// }
|
|
|
+// OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+// outboundItem.setOutId(outbound.getOutId()).setCpId(outbound.getCpId()).setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
+// .setOutType(Constant.OutType.SALE.getName());
|
|
|
+// outboundItemMapper.insert(outboundItem);
|
|
|
+//
|
|
|
+// /********************* 反写出库明细退货数量、金额 begin **********************/
|
|
|
+// outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getSOutItemId());
|
|
|
+// // 如果出库数量小于订单上已退货+本次退货数量
|
|
|
+// if (outboundItemForUpdate.getOutQty().compareTo(outboundItemForUpdate.getReturnQty().add(outboundItemVO.getOutingQty().abs())) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTQTY_NO_LESS_RETURNQTY.getMessage());
|
|
|
+// }
|
|
|
+// OutboundItem outboundItemUpdate = new OutboundItem();
|
|
|
+// outboundItemUpdate.setReturnQty(outboundItemForUpdate.getReturnQty().add(outboundItemVO.getOutingQty().abs()))
|
|
|
+// .setReturnAmt(outboundItemForUpdate.getReturnAmt().add(outboundItemVO.getOutingAmt().abs()))
|
|
|
+// .setItemId(outboundItemForUpdate.getItemId());
|
|
|
+// outboundItemService.updateByUuid(outboundItemUpdate);
|
|
|
+// /********************* 反写出库明细退货数量、金额 end **********************/
|
|
|
+//
|
|
|
+//
|
|
|
+// /********************* 反写订单明细退货数量、金额 begin **********************/
|
|
|
+// // 没有订单的化,不需要更新
|
|
|
+// if (outboundItemVO.getSOrderItemId() != null) {
|
|
|
+// sOrderId = outboundItemVO.getSOrderId();
|
|
|
+// orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemVO.getSOrderItemId());
|
|
|
+// // 如果出库数量小于订单上已退货+本次退货数量
|
|
|
+// if (orderItemForUpdate.getOutQty().compareTo(orderItemForUpdate.getReturnQty().add(outboundItemVO.getOutingQty().abs())) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTQTY_NO_LESS_RETURNQTY.getMessage());
|
|
|
+// }
|
|
|
+// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+// orderItemUpdate.setReturnQty(orderItemForUpdate.getReturnQty().add(outboundItemVO.getOutingQty().abs()))
|
|
|
+// .setReturnAmt(orderItemForUpdate.getReturnAmt().add(outboundItemVO.getOutingAmt().abs()))
|
|
|
+// .setItemId(orderItemForUpdate.getItemId());
|
|
|
+// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+// }
|
|
|
+// /********************* 反写订单明细退货数量、金额 end **********************/
|
|
|
+//
|
|
|
+// }
|
|
|
+// // 可能有多个出库单,所以要循环更新总单
|
|
|
+// for (String outId : outIdList) {
|
|
|
+// // 计算出库明细的退货数量,金额合计
|
|
|
+// List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(outId);
|
|
|
+// OutboundItem outboundItem = outboundItemList.stream().reduce((x, y) -> {
|
|
|
+// OutboundItem item = new OutboundItem();
|
|
|
+// item.setReturnQty(x.getReturnQty().add(y.getReturnQty()));
|
|
|
+// item.setReturnAmt(x.getReturnAmt().add(y.getReturnAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新出库单上的退货数量,金额
|
|
|
+// Outbound outboundUpdate = new Outbound();
|
|
|
+// outboundUpdate.setReturnQty(outboundItem.getReturnQty()).setReturnAmt(outboundItem.getReturnAmt()).setOutId(outId);
|
|
|
+// super.updateByUuid(outboundUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 如果有订单,更新订单总单
|
|
|
+// if (sOrderId != null) {
|
|
|
+// // 计算订单明细的退货数量,金额合计
|
|
|
+// List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(sOrderId);
|
|
|
+// OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
+// OrderItem item = new OrderItem();
|
|
|
+// item.setReturnQty(x.getReturnQty().add(y.getReturnQty()));
|
|
|
+// item.setReturnAmt(x.getReturnAmt().add(y.getReturnAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新订单上的退货数量,金额
|
|
|
+// Order orderUpdate = new Order();
|
|
|
+// orderUpdate.setReturnQty(orderItem.getReturnQty()).setReturnAmt(orderItem.getReturnAmt()).setOrderId(sOrderId);
|
|
|
+// orderService.updateByUuid(orderUpdate);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return ResponseResultUtil.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 编辑方法
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2023/1/9 10:49
|
|
|
+// */
|
|
|
+// @Transactional(
|
|
|
+// rollbackFor = {Exception.class}
|
|
|
+// )
|
|
|
+// public ResponseResultVO<Boolean> updateOutReturn(OutboundVO outboundVO) {
|
|
|
+// // 订单明细实体
|
|
|
+// OrderItem orderItemForUpdate;
|
|
|
+// // 出库明细实体
|
|
|
+// OutboundItem outboundItemForUpdate;// 出库退货明细
|
|
|
+// OutboundItem outboundItemSourceForUpdate;// 源出库明细
|
|
|
+// // 源出库IdList,一个退货单可能有多个出库单
|
|
|
+// List<String> outIdList = new ArrayList<>();
|
|
|
+// String sOrderId = null;
|
|
|
+//
|
|
|
+// // 编辑退货明细
|
|
|
+// List<OutboundItemVO> editOutboundItemVOList = outboundVO.getItemList();
|
|
|
+// for (OutboundItemVO outboundItemVO : editOutboundItemVOList) {
|
|
|
+// // 把源出库Id存起来
|
|
|
+// if (!outIdList.contains(outboundItemVO.getSOutId())) {
|
|
|
+// outIdList.add(outboundItemVO.getSOutId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getItemId());
|
|
|
+// outboundItemSourceForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemVO.getSOutItemId());
|
|
|
+//
|
|
|
+// // |出库退货明细出库中数量|不能小于|出库退货明细已出库中数量|
|
|
|
+// if (outboundItemForUpdate.getOutQty().compareTo(outboundItemSourceForUpdate.getReturnQty().subtract(outboundItemForUpdate.getOutingQty().abs()).add(outboundItemVO.getOutingQty().abs())) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.OUTQTY_NO_LESS_RETURNQTY.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 源入库明细已出库数量不能小于|出库退货明细数量|
|
|
|
+// if (outboundItemSourceForUpdate.getOutQty().compareTo(outboundItemVO.getOutingQty().abs()) == -1) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RETURNQTY_NO_LESS_INTOINGQTY.getMessage());
|
|
|
+// }
|
|
|
+// // 更新出库明细退货数量
|
|
|
+// OutboundItem outboundItemUpdate = new OutboundItem();
|
|
|
+// outboundItemUpdate.setReturnQty(outboundItemSourceForUpdate.getReturnQty().subtract(outboundItemForUpdate.getOutingQty().abs()).add(outboundItemVO.getOutingQty().abs()))
|
|
|
+// .setReturnAmt(outboundItemSourceForUpdate.getReturnAmt().subtract(outboundItemForUpdate.getOutingAmt().abs()).add(outboundItemVO.getOutingAmt().abs()))
|
|
|
+// .setItemId(outboundItemSourceForUpdate.getItemId());
|
|
|
+// outboundItemService.updateByUuid(outboundItemUpdate);
|
|
|
+//
|
|
|
+// // 没有订单的化,不需要更新
|
|
|
+// if (outboundItemVO.getSOrderItemId() != null) {
|
|
|
+// sOrderId = outboundItemVO.getSOrderId();
|
|
|
+// // 更新订单明细退货数量
|
|
|
+// orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemVO.getSOrderItemId());
|
|
|
+// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+// orderItemUpdate.setReturnQty(orderItemForUpdate.getReturnQty().subtract(outboundItemForUpdate.getOutingQty().abs()).add(outboundItemVO.getOutingQty().abs()))
|
|
|
+// .setReturnAmt(orderItemForUpdate.getReturnAmt().subtract(outboundItemForUpdate.getOutingAmt().abs()).add(outboundItemVO.getOutingAmt().abs()))
|
|
|
+// .setItemId(orderItemForUpdate.getItemId());
|
|
|
+// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 更新出库明细
|
|
|
+// OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+// outboundItemService.updateByUuid(outboundItem);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 可能有多个出库单,所以要循环更新总单
|
|
|
+// for (String outId : outIdList) {
|
|
|
+// // 计算出库明细的退货数量,金额合计
|
|
|
+// List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(outId);
|
|
|
+// OutboundItem outboundItem = outboundItemList.stream().reduce((x, y) -> {
|
|
|
+// OutboundItem item = new OutboundItem();
|
|
|
+// item.setReturnQty(x.getReturnQty().add(y.getReturnQty()));
|
|
|
+// item.setReturnAmt(x.getReturnAmt().add(y.getReturnAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新订单上的出库中数量,金额
|
|
|
+// Outbound outboundUpdate = new Outbound();
|
|
|
+// outboundUpdate.setReturnQty(outboundItem.getReturnQty()).setReturnAmt(outboundItem.getReturnAmt()).setOutId(outId);
|
|
|
+// super.updateByUuid(outboundUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 如果有订单,更新订单总单
|
|
|
+// if (sOrderId != null) {
|
|
|
+// // 计算订单明细的退货数量,金额合计
|
|
|
+// List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(sOrderId);
|
|
|
+// OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
+// OrderItem item = new OrderItem();
|
|
|
+// item.setReturnQty(x.getReturnQty().add(y.getReturnQty()));
|
|
|
+// item.setReturnAmt(x.getReturnAmt().add(y.getReturnAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新订单上的出库中数量,金额
|
|
|
+// Order orderUpdate = new Order();
|
|
|
+// orderUpdate.setReturnQty(orderItem.getReturnQty()).setReturnAmt(orderItem.getReturnAmt()).setOrderId(sOrderId);
|
|
|
+// orderService.updateByUuid(orderUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 转化实体、更新出库单总表
|
|
|
+// Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
+// return ResponseResultUtil.success(super.update(outbound, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
+// UUID.fromString(outbound.getOutId()))));
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * @desc : 作废
|
|
|
+// * @author : 付斌
|
|
|
+// * @date : 2024-03-08 16:38
|
|
|
+// */
|
|
|
+// public ResponseResultVO<?> invalidOutReturn(String id) {
|
|
|
+// Outbound outboundForUpdate = outboundMapper.selectByIdForUpdate(id);
|
|
|
+// // 并发校验
|
|
|
+// if (!outboundForUpdate.getFlgValid()) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
|
|
|
+// }
|
|
|
+// // 如果出库数量或退货数量不是0,不能作废
|
|
|
+// if (outboundForUpdate.getOutQty().compareTo(BigDecimal.ZERO) != 0 || outboundForUpdate.getReturnQty().compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_AFTER_OPERATE.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 查出并锁定所有的出库明细
|
|
|
+// List<OutboundItem> outboundItemForUpdateList = outboundItemMapper.selectByZIdForUpdate(id);
|
|
|
+// // 出库IdList,一个退货单可能有多个出库单
|
|
|
+// List<String> outIdList = new ArrayList<>();
|
|
|
+// OrderItem orderItemForUpdate;
|
|
|
+// String sOrderId = null;
|
|
|
+//
|
|
|
+// for (OutboundItem outboundItemForUpdate : outboundItemForUpdateList) {
|
|
|
+// // 把出库Id存起来
|
|
|
+// if (!outIdList.contains(outboundItemForUpdate.getSOutId())) {
|
|
|
+// outIdList.add(outboundItemForUpdate.getSOutId());
|
|
|
+// }
|
|
|
+// sOrderId = outboundItemForUpdate.getSOrderId();
|
|
|
+//
|
|
|
+// // 更新出库明细退货数量
|
|
|
+// outboundItemForUpdate = outboundItemMapper.selectByIdForUpdate(outboundItemForUpdate.getSOutItemId());
|
|
|
+// OutboundItem outboundItemUpdate = new OutboundItem();
|
|
|
+// outboundItemUpdate.setReturnQty(outboundItemForUpdate.getReturnQty().subtract(outboundItemForUpdate.getOutingQty()))
|
|
|
+// .setReturnAmt(outboundItemForUpdate.getReturnAmt().subtract(outboundItemForUpdate.getOutAmt()))
|
|
|
+// .setItemId(outboundItemForUpdate.getItemId());
|
|
|
+// outboundItemService.updateByUuid(outboundItemUpdate);
|
|
|
+//
|
|
|
+// // 更新订单明细退货数量
|
|
|
+// orderItemForUpdate = orderItemMapper.selectByIdForUpdate(outboundItemForUpdate.getSOrderItemId());
|
|
|
+// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+// orderItemUpdate.setReturnQty(orderItemForUpdate.getReturnQty().subtract(outboundItemForUpdate.getOutingQty()))
|
|
|
+// .setReturnAmt(orderItemForUpdate.getReturnAmt().subtract(outboundItemForUpdate.getOutAmt()))
|
|
|
+// .setItemId(orderItemForUpdate.getItemId());
|
|
|
+// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 可能有多个出库单,所以要循环更新总单
|
|
|
+// for (String outId : outIdList) {
|
|
|
+// // 计算出库明细的退货数量,金额合计
|
|
|
+// List<OutboundItem> outboundItemList = outboundItemMapper.selectByZIdForUpdate(outId);
|
|
|
+// OutboundItem outboundItem = outboundItemList.stream().reduce((x, y) -> {
|
|
|
+// OutboundItem item = new OutboundItem();
|
|
|
+// item.setReturnQty(x.getReturnQty().add(y.getReturnQty()));
|
|
|
+// item.setReturnAmt(x.getReturnAmt().add(y.getReturnAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新出库单上的退货数量,金额
|
|
|
+// Outbound outboundUpdate = new Outbound();
|
|
|
+// outboundUpdate.setReturnQty(outboundItem.getReturnQty()).setReturnAmt(outboundItem.getReturnAmt()).setOutId(outId);
|
|
|
+// super.updateByUuid(outboundUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (sOrderId != null) {
|
|
|
+// // 计算订单明细的退货数量,金额合计
|
|
|
+// List<OrderItem> orderItemList = orderItemMapper.selectByZIdForUpdate(sOrderId);
|
|
|
+// OrderItem orderItem = orderItemList.stream().reduce((x, y) -> {
|
|
|
+// OrderItem item = new OrderItem();
|
|
|
+// item.setReturnQty(x.getReturnQty().add(y.getReturnQty()));
|
|
|
+// item.setReturnAmt(x.getReturnAmt().add(y.getReturnAmt()));
|
|
|
+// return item;
|
|
|
+// }).get();
|
|
|
+// // 更新订单上的退货数量,金额
|
|
|
+// Order orderUpdate = new Order();
|
|
|
+// orderUpdate.setReturnQty(orderItem.getReturnQty()).setReturnAmt(orderItem.getReturnAmt()).setOrderId(sOrderId);
|
|
|
+// orderService.updateByUuid(orderUpdate);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 作废
|
|
|
+// Outbound outboundUpdate = new Outbound();
|
|
|
+// outboundUpdate.setFlgValid(false).setOutId(id);
|
|
|
+// super.update(outboundUpdate, new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId,
|
|
|
+// UUID.fromString(outboundUpdate.getOutId())));
|
|
|
+// return ResponseResultUtil.success();
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * @desc : 采购退货出库
|
|
|
+// * @author : 于继渤
|
|
|
+// * @date : 2023/1/9 10:49
|
|
|
+// */
|
|
|
+// @Transactional(
|
|
|
+// rollbackFor = {Exception.class}
|
|
|
+// )
|
|
|
+// public ResponseResultVO<?> insertOutBound(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.PURRETURN.getName());
|
|
|
+// // 转化实体
|
|
|
+// Outbound outbound = outboundConvert.convertToPo(outboundVO);
|
|
|
+// // 总单保存
|
|
|
+// super.insert(outbound);
|
|
|
+//
|
|
|
+// // 明细保存
|
|
|
+// if (outboundVO.getItemList() != null && outboundVO.getItemList().size() > 0) {
|
|
|
+// double sumOutingQty = 0; // 合计出库中数量
|
|
|
+// double sumOutingAmt = 0; // 合计出库中金额
|
|
|
+// for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
|
+// OutboundItem outboundItem = outboundItemConvert.convertToPo(outboundItemVO);
|
|
|
+// outboundItem
|
|
|
+// .setOutId(outbound.getOutId())
|
|
|
+// .setCpId(outbound.getCpId())
|
|
|
+// .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
+// .setOutType(Constant.OutType.PURRETURN.getName());
|
|
|
+// outboundItemMapper.insert(outboundItem);
|
|
|
+//
|
|
|
+//// PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(outboundItem.getFromItemId());
|
|
|
+//
|
|
|
+// // 如果商品数量小于订单+本次出库单上的出库中数量
|
|
|
+//// if(orderItem.getItemQty().compareTo(orderItem.getOutingQty().add(outboundItem.getOutingQty())) == -1){
|
|
|
+//// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
|
|
|
+//// }else{
|
|
|
+//// OrderItem orderItemUpdate = new OrderItem();
|
|
|
+//// orderItemUpdate.setOutingQty(orderItem.getOutingQty().add(outboundItem.getOutingQty()))
|
|
|
+//// .setOutingAmt(orderItem.getOutingAmt().add(outboundItem.getOutingAmt()))
|
|
|
+//// .setItemId(orderItem.getItemId());
|
|
|
+//// orderItemService.updateByUuid(orderItemUpdate);
|
|
|
+//// // 累加出库中数量,金额
|
|
|
+//// sumOutingQty += outboundItem.getOutingQty().doubleValue();
|
|
|
+//// sumOutingAmt += outboundItem.getOutingAmt().doubleValue();
|
|
|
+//// }
|
|
|
+// }
|
|
|
+//// // 更新订单上的出库中数量,金额,状态
|
|
|
+//// OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
|
|
|
+//// Order orderUpdate = new Order();
|
|
|
+//// orderUpdate.setOutingQty(orderResponse.getOutingQty().add(new BigDecimal(sumOutingQty)))
|
|
|
+//// .setOutingAmt(orderResponse.getOutingAmt().add(new BigDecimal(sumOutingAmt)))
|
|
|
+//// .setOutStatus(Constant.OutStatus.CHUKUZHONG.getName())
|
|
|
+//// .setOrderId(outboundVO.getFromId());
|
|
|
+//// orderService.updateByUuid(orderUpdate);
|
|
|
+// }
|
|
|
+// return ResponseResultUtil.success();
|
|
|
+// }
|
|
|
}
|