| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
- package com.dk.mdm.service.ivt;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.dk.common.exception.BaseBusinessException;
- import com.dk.common.infrastructure.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.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.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.service.common.CommonService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- 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;
- /**
- * @desc : 采购入库业务层
- * @date : 2024/3/7 14:11
- * @author : 寇珊珊
- */
- @Service
- public class InboundPurchaseService 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>> selectByCond(InboundQuery inboundQuery) {
- return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
- inboundMapper.countByCond(inboundQuery));
- }
- /**
- * @desc : 查询明细
- * @date : 2024/3/9 15:43
- * @author : 寇珊珊
- */
- @Pagination
- public ResponseResultVO<Map<String, Object>> selectPurchaseInboundItemInfoById(String id) {
- Map<String, Object> result = new HashMap<>();
- // 商品明细
- List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
- result.put("itemList", inboundItemResponses);
- // 收款
- // 附件
- return ResponseResultUtil.success(result);
- }
- /**
- * @desc : 采购入库新建
- * @date : 2024/3/7 14:13
- * 入库中数量/金额 已入库数量/金额 由调用方传入
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
- //region 总单
- //获取 id/单号
- Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(),false);
- inboundVO.setIntoId(codeMap.get("outId").toString()).
- setIntoNo(codeMap.get("outNote").toString());
- //入库类型
- inboundVO.setIntoType(Constant.IntoType.SALE.getName());
- //自动入库标识
- if (inboundVO.getAutomaticFlg()) {
- //已入库
- inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
- } else {
- //入库中
- inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
- }
- //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
- 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.getFromId()!=null){
- Purchase purchaseUpdate = new Purchase();
- purchaseUpdate.setPurId(inboundVO.getFromId());
- purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty().negate());
- purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt().negate());
- purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
- purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseUpdate.getIntoingQty(), purchaseUpdate.getIntoQty());
- purchaseUpdate.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchaseUpdate);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //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)
- ;
- }else{
- inboundItemVO
- .setIntoQty(BigDecimal.ZERO)
- .setIntoAmt(BigDecimal.ZERO);
- }
- //成本单价
- inboundItemVO.setCostPrice(inboundItemVO.getPriceInto());
- //成本金额
- inboundItemVO.setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
- //库存数量 已入库-出库
- inboundItemVO.setInvQty(inboundItemVO.getIntoQty().subtract(inboundItemVO.getOutQty()));
- //入库状态
- inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- inboundItemMapper.insert(inboundItem);
- //endregion
- //region 采购明细
- if(inboundItemVO.getFromItemId()!=null){
- //根据id查询
- // PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- // purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()));
- // purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().add(inboundItemVO.getIntoingAmt()));
- // purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().add(inboundItemVO.getIntoQty()));
- // purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()));
- purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //todo 如果是已入库 调用库存 后续写库存这里补上
- //region 库存
- //endregion
- return ResponseResultUtil.success(inboundVO);
- }
- /**
- * @desc : 采购入库办理
- * @date : 2024/3/7 15:47
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
- //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) {
- InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
- //编辑明细
- inboundItemVO
- .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
- .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
- .setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
- .setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
- ;
- //入库状态
- String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
- inboundItemVO.setIntoStatus(intoStatus);
- //实体转换
- InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
- //修改
- inboundItemMapper.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //endregion
- //region 新建明细
- else {
- inboundItemVO
- .setIntoQty(inboundItemVO.getIntoingQty())
- .setIntoAmt(inboundItemVO.getIntoingAmt())
- .setIntoId(inboundVO.getIntoId())
- .setCostPrice(inboundItemVO.getPriceInto())
- .setCostAmt((inboundItemVO.getIntoingQty().add(inboundItemVO.getIntoQty())).multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
- .setIntoType(Constant.IntoType.SALE.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(inboundItemVO.getFromItemId());
- // purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()));
- // purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().add(inboundItemVO.getIntoingAmt()));
- // purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().add(inboundItemVO.getIntoQty()));
- // purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()));
- purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- }
- //endregion
- //region 删除明细
- BigDecimal sumDelIntoQty = BigDecimal.ZERO;
- BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
- BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
- BigDecimal sumDelIntoingAmt = 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);
- sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- sumDelIntoingAmt = 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.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- }
- //region 采购
- if (inboundItemVO.getFromItemId() != null) {
- //region 采购订单明细
- // PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
- PurchaseItem purchaseItem = new PurchaseItem();
- purchaseItem.setItemId(inboundItemVO.getFromItemId());
- // purchaseItem.setIntoingQty(purchaseItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()));
- // purchaseItem.setIntoingAmt(purchaseItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()));
- // purchaseItem.setIntoQty(purchaseItemResponse.getIntoQty().subtract(inboundItemVO.getIntoQty()));
- // purchaseItem.setIntoAmt(purchaseItemResponse.getIntoAmt().subtract(inboundItemVO.getIntoAmt()));
- purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
- purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
- purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
- purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
- purchaseItem.setIntoStatus(intoStatus);
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- //endregion
- }
- //endregion
- }
- }
- //endregion
- //region 编辑总单
- InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
- 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);
- BigDecimal sumIntoingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
- BigDecimal sumIntoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
- inboundVO.setIntoQty(sumIntoQty);
- inboundVO.setIntoAmt(sumIntoAmt);
- inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoingQty));
- inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoingAmt));
- //已入库数量==入库中数量 入库完成
- 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.update(inbound,
- new UpdateWrapper<Inbound>().lambda()
- .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //endregion
- //region 修改采购订单
- if (inboundVO.getFromId() != null) {
- PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
- Purchase purchase = new Purchase();
- purchase.setPurId(purchaseResponse.getPurId());
- // purchase.setIntoQty(purchaseResponse.getIntoQty().add(sumIntoQty).subtract(sumDelIntoQty));
- // purchase.setIntoAmt(purchaseResponse.getIntoAmt().add(sumIntoAmt).subtract(sumDelIntoAmt));
- // purchase.setIntoingQty(purchaseResponse.getIntoingQty().subtract(sumIntoingQty).subtract(sumDelIntoingQty));
- // purchase.setIntoingAmt(purchaseResponse.getIntoingAmt().subtract(sumIntoingAmt).subtract(sumDelIntoingAmt));
- purchase.setIntoQty(sumIntoQty.subtract(sumDelIntoQty));
- purchase.setIntoAmt(sumIntoAmt.subtract(sumDelIntoAmt));
- purchase.setIntoingQty((sumIntoingQty.add(sumDelIntoingQty)).negate());
- purchase.setIntoingAmt((sumIntoingAmt.add(sumDelIntoingAmt)).negate());
- //入库状态
- String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
- purchase.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //todo 如果是已入库 调用库存 后续写库存这里补上
- //region 修改库存
- //endregion
- return ResponseResultUtil.success(inboundVO);
- }
- /**
- * @desc : 采购入库撤销
- * @date : 2024/3/7 17:06
- * @author : 寇珊珊
- */
- @Transactional(rollbackFor = {Exception.class})
- public ResponseResultVO<?> purchaseInboundCancel(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()));
- purchase.setIntoQty(inboundResponse.getIntoQty().negate());
- purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
- purchase.setIntoingQty(inboundResponse.getIntoQty());
- purchase.setIntoingAmt(inboundResponse.getIntoAmt());
- //入库状态
- String intoStatus = this.setIntoStatus(purchase.getIntoingQty(), purchase.getIntoQty());
- purchase.setIntoStatus(intoStatus);
- int countRow = purchaseMapper.updateById(purchase);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //endregion
- //region 修改总单数据信息
- Inbound inbound = new Inbound();
- inbound.setIntoId(inboundVO.getIntoId());
- inbound.setIntoDate(null);
- inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
- inbound.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
- inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
- inbound.setIntoQty(BigDecimal.ZERO);
- inbound.setIntoAmt(BigDecimal.ZERO);
- //修改
- inboundMapper.update(inbound,
- new UpdateWrapper<Inbound>().lambda()
- .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
- );
- //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(inboundItemResponse.getFromItemId());
- // 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()));
- purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
- purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
- purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
- purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
- //入库状态
- String intoStatus= this.setIntoStatus(purchaseItem.getIntoingQty(), purchaseItem.getIntoQty());
- purchaseItem.setIntoStatus(intoStatus);
- //修改
- int countRow = purchaseItemMapper.updateById(purchaseItem);
- //数量超出
- if (countRow == 0) {
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
- }
- }
- //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.update(inboundItem,
- new UpdateWrapper<InboundItem>().lambda()
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
- );
- //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.YIRUKU.getName();
- }
- return intoStatus;
- }
-
- }
|