package com.dk.mdm.service.ivt.inbound; 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.model.vo.AnnexVO; 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.common.CommonMapper; 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 com.dk.mdm.service.ivt.inventory.InventoryService; import com.dk.mdm.service.mac.AccountService; 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; /** * @author : 寇珊珊 * @desc : 采购入库业务层 * @date : 2024/3/7 14:11 */ @Service public class InboundPurchaseService extends BaseService { @Override public BaseMapper 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; @Autowired private CommonMapper commonMapper; @Autowired private InventoryService inventoryService; @Autowired private AccountService accountService; /** * @desc : 条件查询 * @date : 2024/3/7 14:12 * @author : 寇珊珊 */ @Pagination public ResponseResultVO> selectByCond(InboundQuery inboundQuery) { return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery), inboundMapper.countByCond(inboundQuery)); } /** * @desc : 查询明细 * @date : 2024/3/9 15:43 * @author : 寇珊珊 */ @Pagination public ResponseResultVO> selectPurchaseInboundItemInfoById(String id) { Map result = new HashMap<>(); // 商品明细 List inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id)); result.put("itemList", inboundItemResponses); // 收款 // 附件 return ResponseResultUtil.success(result); } /** * @desc : 查询入库价 * @date : 2024/7/1 11:29 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public InboundItemResponse selectPriceInto(InboundItemVO inboundItemVO) { List inboundItemResponses = inboundItemMapper.selectPriceInto(new InboundItemQuery().setSkuId(inboundItemVO.getSkuId()) .setNonStdCode(inboundItemVO.getNonStdCode()) .setWhId(inboundItemVO.getWhId())); if (inboundItemResponses != null && inboundItemResponses.size() > 0) { return inboundItemResponses.get(0); } return null; } /** * @desc : 采购入库新建 * @date : 2024/3/7 14:13 * 入库中数量/金额 已入库数量/金额 由调用方传入 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO purchaseInboundInsert(InboundVO inboundVO) { //region 校验明细 if (inboundVO.getItemList().size() == 0) { throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(), ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage()); } //endregion //region 查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细 Boolean priceIntoFlag = false; for (InboundItemVO inboundItemVO : inboundVO.getItemList()) { if(inboundItemVO.getPriceInto() == null || inboundItemVO.getPriceInto().compareTo(BigDecimal.ZERO)==0){ priceIntoFlag = true; //查询库存批次最近一条入库价 InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO); inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getPriceInto() : BigDecimal.ZERO); inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO); inboundItemVO.setCostPrice(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO); inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO); } } if(priceIntoFlag){ BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP); inboundVO.setIntoingAmt(intoingAmt); } //endregion //region 查询当前公司的系统参数 自动办理信息 并赋值 Map map = new HashMap<>(); map.put("cpId", inboundVO.getCpId()); map.put("code", Constant.SystemConstant.IVT_001.getValue()); //自动办理标识 String flgHandleSetting = commonMapper.getSettingValue(map); //自动办理标识为1 自动办理入库 if (Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)) { inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue()); inboundVO.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue()); } //endregion //region 总单 //获取 id/单号 Map 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.getFlgAutoHandle()) { //已入库 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()); //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId()); //已入库 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) { purchaseUpdate.setIntoingQty(BigDecimal.ZERO); purchaseUpdate.setIntoingAmt(BigDecimal.ZERO); purchaseUpdate.setIntoQty(inboundVO.getIntoQty()); purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt()); } //入库中 else { purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty()); purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt()); purchaseUpdate.setIntoQty(BigDecimal.ZERO); purchaseUpdate.setIntoAmt(BigDecimal.ZERO); } //入库状态 String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()), purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()), purchaseResponse.getSumQuantity()); 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 明细 for (InboundItemVO inboundItemVO : inboundVO.getItemList()) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); inboundItemVO.setAddOrEditFlag(true); //endregion //总单id inboundItemVO.setIntoId(inboundVO.getIntoId()); //入库类型 inboundItemVO.setIntoType(inboundVO.getIntoType()); //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) { inboundItemVO .setIntoQty(inboundItemVO.getIntoingQty()) .setIntoAmt(inboundItemVO.getIntoingAmt()) .setIntoingQty(BigDecimal.ZERO) .setIntoingAmt(BigDecimal.ZERO) .setCostPrice(inboundItemVO.getPriceInto()) .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP)) ; } else { inboundItemVO .setIntoQty(BigDecimal.ZERO) .setIntoAmt(BigDecimal.ZERO); } //入库状态 inboundItemVO.setIntoStatus(inboundVO.getIntoStatus()); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); //endregion //region 采购明细 if (inboundItemVO.getFromItemId() != null) { //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量) PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); //已入库 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) { purchaseItem.setIntoingQty(BigDecimal.ZERO); purchaseItem.setIntoingAmt(BigDecimal.ZERO); purchaseItem.setIntoQty(inboundItemVO.getIntoQty()); purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt()); } //入库中 else { purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty()); purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt()); purchaseItem.setIntoQty(BigDecimal.ZERO); purchaseItem.setIntoAmt(BigDecimal.ZERO); } //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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 入账 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) { accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 库存 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) { Map invMap = new HashMap<>(); invMap.put("intoDetail", inboundVO.getItemList()); inventoryService.operatingInventoryInformation(invMap); } //endregion return ResponseResultUtil.success(inboundVO); } /** * @desc : 采购入库编辑 * @date : 2024/3/25 16:25 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO purchaseInboundUpdate(InboundVO inboundVO) { //region 小编辑 if (!inboundVO.getLimitEdit()) { Inbound inbound = new Inbound(); inbound.setIntoId(inboundVO.getIntoId()); inbound.setRemarks(inboundVO.getRemarks()); inbound.setAnnexPaths(inboundVO.getAnnexPaths()); inboundMapper.update(inbound, new UpdateWrapper().lambda() .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); for (InboundItemVO inboundItemVO : inboundVO.getItemList()) { InboundItem inboundItem = new InboundItem(); inboundItem.setItemId(inboundItemVO.getItemId()); if (inboundItemVO.getRemarks() != null && inboundItemVO.getRemarks() != "") { inboundItem.setRemarks(inboundItemVO.getRemarks()); inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } } } //endregion //region 大编辑 else { //region 根据id查询 此条入库单的数据还未更改前的数据 InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId()); BigDecimal sumQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP); BigDecimal sumAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP); //endregion //region 自动办理参数为true 已入库编辑 //自动办理参数为true if (Constant.FlgHandleSetting.TRUE.getValue().equals(inboundVO.getFlgHandleSetting())) { //region 退账 if (inboundVO.getReceivableId() != null) { accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 修改明细 List itemList = inboundVO.getItemList(); for (InboundItemVO inboundItemVO : itemList) { //根据id查询 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId()); //region 编辑明细 赋值 if (inboundItemVO.getItemId() != null) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); //编辑之前的数 inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty()); inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt()); //编辑之后的数 inboundItemVO.setIntoQty(inboundItemVO.getIntoingQty()); inboundItemVO.setIntoAmt(inboundItemVO.getIntoingAmt()); inboundItemVO.setAddOrEditFlag(false); //endregion InboundItem inboundItem = new InboundItem(); inboundItem.setItemId(inboundItemVO.getItemId()); inboundItem.setIntoQty(inboundItemVO.getIntoingQty()); inboundItem.setIntoAmt(inboundItemVO.getIntoingAmt()); inboundItem.setCostPrice(inboundItemVO.getPriceInto()); inboundItem.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(6, BigDecimal.ROUND_HALF_UP)); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } //endregion //region 新建明细 else { inboundItemVO .setIntoQty(inboundItemVO.getIntoingQty()) .setIntoAmt(inboundItemVO.getIntoingAmt()) .setIntoingQty(BigDecimal.ZERO) .setIntoingAmt(BigDecimal.ZERO) .setCostPrice(inboundItemVO.getPriceInto()) .setCostAmt(inboundItemVO.getOutQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP)) ; inboundItemVO.setIntoId(inboundVO.getIntoId()); //入库状态 inboundItemVO.setIntoStatus(inboundVO.getIntoStatus()); inboundItemVO.setIntoType(Constant.IntoType.SALE.getName()); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); inboundItemVO.setIntoQty(inboundItemVO.getIntoQty()); inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt()); inboundItemVO.setAddOrEditFlag(true); //endregion } //endregion //region 销售明细 if (inboundItemVO.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate().add(inboundItemVO.getIntoingQty())); purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate().add(inboundItemVO.getIntoingAmt())); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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 delIntoQty = BigDecimal.ZERO; BigDecimal delIntoAmt = BigDecimal.ZERO; if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) { delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP); delIntoAmt = 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) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); inboundItemVO.setIntoQty(inboundItemVO.getIntoQty()); inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt()); //endregion InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItem.setFlgValid(false); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } //region 销售明细 if (inboundItemVO.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate()); purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate()); purchaseItem.setIntoingQty(inboundItemVO.getIntoQty()); purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt()); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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 修改入库总单 Inbound inbound = new Inbound(); inbound.setIntoId(inboundVO.getIntoId()); inbound.setIntoQty(sumQty); inbound.setIntoAmt(sumAmt); //修改 inboundMapper.update(inbound, new UpdateWrapper().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 修改销售总单 if (inboundVO.getFromId() != null) { //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId()); Purchase purchase = new Purchase(); purchase.setPurId(inboundVO.getFromId()); purchase.setIntoQty(inboundResponse.getIntoQty().negate().add(sumQty).subtract(delIntoQty)); purchase.setIntoAmt(inboundResponse.getIntoAmt().negate().add(sumAmt).subtract(delIntoAmt)); purchase.setIntoingQty(delIntoQty); purchase.setIntoingAmt(delIntoAmt); //入库状态 String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()), purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity()); purchase.setIntoStatus(intoStatus); //修改 int countRow = purchaseMapper.updateById(purchase); //数量超出 if (countRow == 0) { throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage()); } //endregion } //endregion //region 入账 if (inboundVO.getReceivableId() != null) { accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 调用库存 Map map = new HashMap<>(); map.put("intoDetail", inboundVO.getItemList()); map.put("delIntoDetail", inboundVO.getDeleteItemList()); inventoryService.operatingInventoryInformation(map); //endregion } else{ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage()); } //endregion //region 自动办理参数false 入库中编辑 //自动办理标识为false 并且 自动办理参数为false 入库中 if (!inboundVO.getFlgAutoHandle() && Constant.FlgHandleSetting.FALSE.getValue().equals(inboundVO.getFlgHandleSetting())) { //region 修改明细 List itemList = inboundVO.getItemList(); for (InboundItemVO inboundItemVO : itemList) { //根据id查询 获取到还未进行修改的数据 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId()); //region 编辑明细 if (inboundItemVO.getItemId() != null) { InboundItem inboundItem = new InboundItem(); inboundItem.setItemId(inboundItemVO.getItemId()); inboundItem.setIntoingQty(inboundItemVO.getIntoingQty()); inboundItem.setIntoingAmt(inboundItemVO.getIntoingAmt()); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } //endregion //region 新建明细 else { inboundItemVO .setIntoQty(BigDecimal.ZERO) .setIntoAmt(BigDecimal.ZERO) .setCostPrice(inboundItemVO.getPriceInto()) .setCostAmt(inboundItemVO.getIntoingQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP)) ; inboundItemVO.setIntoId(inboundVO.getIntoId()); //入库状态 inboundItemVO.setIntoStatus(inboundVO.getIntoStatus()); inboundItemVO.setIntoType(Constant.IntoType.SALE.getName()); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); } //endregion //region 销售明细 if (inboundItemVO.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); //本次修改几个传几个(负数) sql中是原数据+本次修改数据 purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate().add(inboundItemVO.getIntoingQty())); purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate().add(inboundItemVO.getIntoingAmt())); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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 delIntoQty = BigDecimal.ZERO; BigDecimal delIntoAmt = BigDecimal.ZERO; if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) { delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP); delIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP); for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) { //region 明细 if (inboundItemVO.getItemId() != null) { InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItem.setFlgValid(false); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } //endregion //region 销售明细 if (inboundItemVO.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate()); purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate()); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty()); 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 修改入库总单 Inbound inbound = new Inbound(); inbound.setIntoId(inboundVO.getIntoId()); inbound.setIntoingQty(sumQty); inbound.setIntoingAmt(sumAmt); //修改 inboundMapper.update(inbound, new UpdateWrapper().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 修改采购总单 if (inboundVO.getFromId() != null) { //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId()); Purchase purchase = new Purchase(); purchase.setPurId(inboundVO.getFromId()); purchase.setIntoingQty(inboundResponse.getIntoingQty().negate().add(sumQty).subtract(delIntoQty)); purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate().add(sumAmt).subtract(delIntoAmt)); //入库状态 String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()), purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity()); purchase.setIntoStatus(intoStatus); //修改 int countRow = purchaseMapper.updateById(purchase); //数量超出 if (countRow == 0) { throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage()); } } //endregion } else{ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FLG_HANDLE_SETTING_NOT_ENABLED_INTO.getMessage()); } //endregion } //endregion return ResponseResultUtil.success(inboundVO); } /** * @desc : 采购入库作废 * @date : 2024/3/26 9:24 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO purchaseInboundRepeal(String intoId) { //region 查询总单 查询明细 //根据id查询 此条入库单的数据还未更改前的数据 InboundResponse inboundResponse = inboundMapper.selectById(intoId); //根据总单id查询 List inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId())); //endregion //region 已入库作废 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundResponse.getIntoStatus())) { //region 退账 if (inboundResponse.getReceivableId() != null) { accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 修改明细 for (InboundItemResponse inboundItemResponse : inboundItemResponseList) { //region 将库存需要的参数赋值 inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate()); inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate()); //endregion //region 编辑明细 赋值 赋值明细 防止作废的单据查不到明细 故注掉下面代码 // InboundItem inboundItem = new InboundItem(); // inboundItem.setItemId(inboundItemResponse.getItemId()); // inboundItem.setFlgValid(false); // //修改 // inboundItemMapper.update(inboundItem, // new UpdateWrapper().lambda() // .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) // ); //endregion //region 销售明细 if (inboundItemResponse.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId()); PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemResponse.getFromItemId()); purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate()); purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate()); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty(), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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 修改入库总单 Inbound inbound = new Inbound(); inbound.setIntoId(inboundResponse.getIntoId()); inbound.setFlgValid(false); //修改 inboundMapper.update(inbound, new UpdateWrapper().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 修改销售总单 if (inboundResponse.getFromId() != null) { //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId()); Purchase purchase = new Purchase(); purchase.setPurId(inboundResponse.getFromId()); purchase.setIntoQty(inboundResponse.getIntoQty().negate()); purchase.setIntoAmt(inboundResponse.getIntoAmt().negate()); //入库状态 String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty(), purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity()); 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 入账 if (inboundResponse.getReceivableId() != null) { accountService.accPayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 调用库存 Map map = new HashMap<>(); map.put("delIntoDetail", inboundItemResponseList); inventoryService.operatingInventoryInformation(map); //endregion } //endregion //region 入库中、待入库作废 if (Constant.IntoStatus.RUKUZHONG.getName().equals(inboundResponse.getIntoStatus()) || Constant.IntoStatus.DAIRUKU.getName().equals(inboundResponse.getIntoStatus())) { //region 修改明细 for (InboundItemResponse inboundItemResponse : inboundItemResponseList) { //region 编辑明细 赋值 InboundItem inboundItem = new InboundItem(); inboundItem.setItemId(inboundItemResponse.getItemId()); inboundItem.setIntoingQty(BigDecimal.ZERO); inboundItem.setIntoingAmt(BigDecimal.ZERO); // inboundItem.setFlgValid(false); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); //endregion //region 销售明细 if (inboundItemResponse.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId()); PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemResponse.getFromItemId()); purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate()); purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate()); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty(), purchaseItemResponse.getItemQty()); 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 修改入库总单 Inbound inbound = new Inbound(); inbound.setIntoId(inboundResponse.getIntoId()); inbound.setIntoingQty(BigDecimal.ZERO); inbound.setIntoAmt(BigDecimal.ZERO); inbound.setFlgValid(false); //修改 inboundMapper.update(inbound, new UpdateWrapper().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 修改销售总单 if (inboundResponse.getFromId() != null) { //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId()); Purchase purchase = new Purchase(); purchase.setPurId(inboundResponse.getFromId()); purchase.setIntoingQty(inboundResponse.getIntoingQty().negate()); purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate()); //入库状态 String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()), purchaseResponse.getIntoQty(), purchaseResponse.getSumQuantity()); purchase.setIntoStatus(intoStatus); //修改 int countRow = purchaseMapper.updateById(purchase); //数量超出 if (countRow == 0) { throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage()); } } //endregion } //endregion return ResponseResultUtil.success(); } /** * @desc : 采购入库办理 * @date : 2024/3/7 15:47 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO purchaseHandleInbound(InboundVO inboundVO) { //region 根据id查询 此条入库单的数据还未更改前的数据 InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId()); //endregion //region 退账 if (inboundResponse.getReceivableId() != null) { accountService.reversePayable(inboundResponse.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 编辑明细 //校验明细 if (inboundVO.getItemList().size() == 0) { throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(), ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage()); } for (InboundItemVO inboundItemVO : inboundVO.getItemList()) { //入库明细根据id查询 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId()); //region 校验数量是否超出 if (inboundItemVO.getIntoingQty().compareTo(inboundItemResponse.getIntoingQty()) > 0) { throw new BaseBusinessException(ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getCode(), ErrorCodeEnum.CANNOT_EXCEED_THE_QUANTITY_IN_THE_OUTBOUND_SHIPMENT.getMessage()); } //endregion //region 编辑明细 if (inboundItemVO.getItemId() != null) { inboundItemVO .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty())) .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt())) .setIntoingQty(BigDecimal.ZERO) .setIntoingAmt(BigDecimal.ZERO) .setCostPrice(inboundItemVO.getPriceInto()) .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP)) ; //入库状态 String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty()); inboundItemVO.setIntoStatus(intoStatus); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); //编辑之前的数 if(inboundItemResponse.getIntoQty().compareTo(BigDecimal.ZERO)>0) { inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty()); inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt()); } inboundItemVO.setAddOrEditFlag(true); //endregion } //endregion //region 新建明细 else { inboundItemVO .setIntoQty(inboundItemVO.getIntoingQty()) .setIntoAmt(inboundItemVO.getIntoingAmt()) .setIntoId(inboundVO.getIntoId()) .setCostPrice(inboundItemVO.getPriceInto()) .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP)) .setIntoType(Constant.IntoType.SALE.getName()) .setIntoingQty(BigDecimal.ZERO) .setIntoingAmt(BigDecimal.ZERO) ; //入库状态 String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty()); inboundItemVO.setIntoStatus(intoStatus); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); //新建 inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); inboundItemVO.setAddOrEditFlag(true); //endregion } //endregion //region 采购明细 if(inboundItemVO.getFromItemId()!=null){ //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量) PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate()); purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate()); purchaseItem.setIntoQty(inboundItemVO.getIntoQty()); purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt()); //入库状态 String purItemIntoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); purchaseItem.setIntoStatus(purItemIntoStatus); int countRow = purchaseItemMapper.updateById(purchaseItem); //数量超出 if (countRow == 0) { throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage()); } } //endregion } //endregion //region 删除明细 BigDecimal delIntoingQty = BigDecimal.ZERO; BigDecimal delIntoingAmt = BigDecimal.ZERO; BigDecimal delIntoQty = BigDecimal.ZERO; BigDecimal delIntoAmt = BigDecimal.ZERO; if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) { delIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP); delIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP); delIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP); delIntoAmt = 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) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); //endregion InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItem.setFlgValid(false); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } //region 采购 if (inboundItemVO.getFromItemId() != null) { //region 采购订单明细 //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量) PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemVO.getFromItemId()); purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate()); purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate()); purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate()); purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate()); //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId()); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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 编辑总单 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); inboundVO.setIntoingQty(BigDecimal.ZERO); inboundVO.setIntoingAmt(BigDecimal.ZERO); //入库状态 String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty()); inboundVO.setIntoStatus(intoStatus); //实体转换 Inbound inbound = inboundConvert.convertToPo(inboundVO); //修改 inboundMapper.update(inbound, new UpdateWrapper().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 修改采购订单 if (inboundVO.getFromId() != null) { //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量) Purchase purchase = new Purchase(); purchase.setPurId(inboundVO.getFromId()); purchase.setIntoQty(sumIntoQty.subtract(delIntoQty)); purchase.setIntoAmt(sumIntoAmt.subtract(delIntoAmt)); purchase.setIntoingQty((inboundResponse.getIntoingQty().add(delIntoingQty)).negate()); purchase.setIntoingAmt((inboundResponse.getIntoingAmt().add(delIntoingAmt)).negate()); //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId()); //入库状态 String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()), purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity()); purchase.setIntoStatus(purIntoStatus); //修改 int countRow = purchaseMapper.updateById(purchase); //数量超出 if (countRow == 0) { throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage()); } } //endregion //region 入账 accountService.accPayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); //endregion //region 调用库存 Map map = new HashMap<>(); map.put("intoDetail", inboundVO.getItemList()); map.put("delIntoDetail", inboundVO.getDeleteItemList()); inventoryService.operatingInventoryInformation(map); //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 (inboundResponse.getReceivableId() != null) { accountService.reversePayable(inboundVO.getIntoId(), Constant.InventoryDocCode.INTOBOUND.getTableName()); } //endregion //region 修改订单数据信息 if (inboundResponse.getFromId() != null) { //根据id查询 PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId()); //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量) Purchase purchase = new Purchase(); purchase.setPurId(inboundResponse.getFromId()); purchase.setIntoQty(inboundResponse.getIntoQty().negate()); purchase.setIntoAmt(inboundResponse.getIntoAmt().negate()); purchase.setIntoingQty(inboundResponse.getIntoQty()); purchase.setIntoingAmt(inboundResponse.getIntoAmt()); //入库状态 String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()), purchaseResponse.getIntoQty().add(purchase.getIntoQty()), purchaseResponse.getSumQuantity()); 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().lambda() .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 明细数据 //根据总单id查明细 List inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId())); for (InboundItemResponse inboundItemResponse : inboundItemResponseList) { //region 修改采购明细数据信息 if (inboundItemResponse.getFromItemId() != null) { //根据id查询 PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId()); //赋值 (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量) PurchaseItem purchaseItem = new PurchaseItem(); purchaseItem.setItemId(inboundItemResponse.getFromItemId()); purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate()); purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate()); purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty()); purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt()); //入库状态 String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()), purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()), purchaseItemResponse.getItemQty()); 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(); //region 将库存需要的参数赋值 inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue()); inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate()); inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate()); //endregion 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) .setCostPrice(BigDecimal.ZERO) .setCostAmt(BigDecimal.ZERO) .setItemId(inboundItemResponse.getItemId()); //入库状态 String intoStatus = this.setIntoStatus(inboundItem.getIntoingQty(), inboundItem.getIntoQty()); inboundItem.setIntoStatus(intoStatus); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); //endregion } //endregion //region 调用库存 Map map = new HashMap<>(); map.put("delIntoDetail", inboundItemResponseList); inventoryService.operatingInventoryInformation(map); //endregion return ResponseResultUtil.success(); } /** * @desc : 入库状态通用(目前本页面) * @date : 2024/3/9 8:59 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) 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; } /** * @desc : 上游单据入库状态通用(目前本页面) * @date : 2024/4/1 17:14 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty, BigDecimal sumQty) { //入库状态 String intoStatus = null; //入库中+已入库 小于 总数 并且 入库中数量 等于订单总数量 if (intoingQty.compareTo(sumQty) <= 0 && intoingQty.add(intoQty).compareTo(sumQty) <= 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(); } //入库中+已入库 等于 总数 并且 入库中数量 小于等于订单总数量 else if (intoingQty.compareTo(sumQty) < 0 && intoingQty.add(intoQty).compareTo(sumQty) == 0) { //已入库 intoStatus = Constant.IntoStatus.YIRUKU.getName(); } return intoStatus; } }