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.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.InOutRecordMapper; import com.dk.mdm.mapper.ivt.InboundItemMapper; import com.dk.mdm.mapper.ivt.InboundMapper; import com.dk.mdm.model.pojo.ivt.Inbound; import com.dk.mdm.model.pojo.ivt.InboundItem; import com.dk.mdm.model.pojo.ivt.Outbound; import com.dk.mdm.model.pojo.ivt.OutboundItem; 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.vo.ivt.InboundItemVO; import com.dk.mdm.model.vo.ivt.InboundVO; import com.dk.mdm.model.vo.ivt.OutboundItemVO; import com.dk.mdm.service.common.CommonService; import com.dk.mdm.service.ivt.inventory.InventoryService; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import javax.validation.Valid; import java.math.BigDecimal; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; /** * @author : 寇珊珊 * @desc : 其他入库业务层 * @date : 2024/3/7 14:11 */ @Service public class InboundOtherService 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 CommonService commonService; @Autowired private CommonMapper commonMapper; @Autowired private InventoryService inventoryService; /** * @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> selectOtherInboundItemInfoById(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 otherInboundInsert(InboundVO inboundVO) { //校验明细 if (inboundVO.getItemList().size() == 0) { throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(), ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage()); } //region 查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细 Boolean priceIntoFlag = false; for (InboundItemVO inboundItemVO : inboundVO.getItemList()) { if(inboundItemVO.getCostPrice()==null || inboundItemVO.getCostPrice().compareTo(BigDecimal.ZERO)==0){ priceIntoFlag = true; //查询库存批次最近一条入库价 InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO); //todo 2024年7月5日15:57:01 priceOut和outingAmt 前台传 z确认修改 //todo 2024年7月9日08:52:55 入库价和入库价总和后台计算 z确认修改 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); inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO); inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().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.setFlgAutoHandle(Constant.FlgAutoHandle.TRUE.getValue()); } //endregion //region 总单 //获取 id/单号 Map codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERINBOUND.getName(), false); inboundVO.setIntoId(codeMap.get("outId").toString()). setIntoNo(codeMap.get("outNote").toString()); //入库类型 inboundVO.setIntoType(Constant.IntoType.OTHER.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 明细 for (InboundItemVO inboundItemVO : inboundVO.getItemList()) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue()); inboundItemVO.setAddOrEditFlag(true); //endregion //总单id inboundItemVO.setIntoId(inboundVO.getIntoId()); //入库类型 inboundItemVO.setIntoType(inboundVO.getIntoType()); //出库数量 inboundItemVO.setOutQty(BigDecimal.ZERO); //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额 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.setIntoStatus(inboundVO.getIntoStatus()); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); } //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 otherInboundUpdate(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()); inboundItem.setRemarks(inboundItemVO.getRemarks()); inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); } } //endregion //region 大编辑 else { //region 明细数量金额 求和 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 已入库编辑 if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) { //region 修改明细 List itemList = inboundVO.getItemList(); for (InboundItemVO inboundItemVO : itemList) { //region 编辑明细赋值 if (inboundItemVO.getItemId() != null) { //根据id查询 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId()); //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.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()); //修改 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) ; inboundItemVO.setIntoId(inboundVO.getIntoId()); //入库状态 inboundItemVO.setIntoStatus(inboundVO.getIntoStatus()); inboundItemVO.setIntoType(Constant.IntoType.OTHER.getName()); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue()); inboundItemVO.setIntoQty(inboundItemVO.getIntoQty()); inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt()); inboundItemVO.setAddOrEditFlag(true); //endregion } //endregion } //endregion //region 删除明细 if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) { for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue()); //endregion 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 修改入库总单 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 todo调用库存 Map map = new HashMap<>(); map.put("intoDetail", inboundVO.getItemList()); map.put("delIntoDetail", inboundVO.getDeleteItemList()); inventoryService.operatingInventoryInformation(map); //endregion } //endregion //region 入库中编辑 if (Constant.IntoStatus.RUKUZHONG.getName().equals(inboundVO.getIntoStatus()) || Constant.IntoStatus.DAIRUKU.getName().equals(inboundVO.getIntoStatus())) { //region 修改明细 List itemList = inboundVO.getItemList(); for (InboundItemVO inboundItemVO : itemList) { if (inboundItemVO.getItemId() != null) { //region 编辑赋值 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) ; inboundItemVO.setIntoId(inboundVO.getIntoId()); //入库状态 inboundItemVO.setIntoStatus(inboundVO.getIntoStatus()); inboundItemVO.setIntoType(Constant.IntoType.OTHER.getName()); //实体转换 InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO); inboundItemMapper.insert(inboundItem); inboundItemVO.setItemId(inboundItem.getItemId()); } //endregion } //endregion //region 删除明细 if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) { for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) { 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 修改入库总单 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 } //endregion } //endregion return ResponseResultUtil.success(inboundVO); } /** * @desc : 其他入库作废 * @date : 2024/3/25 16:25 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO otherInboundRepeal(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 todo 退账 当单据红的账款id不为空说明有账, 要先退账才能进行操作 if (inboundResponse.getReceivableId() != null) { } //endregion //region 修改明细 for (InboundItemResponse inboundItemResponse : inboundItemResponseList) { //region 将库存需要的参数赋值 inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue()); inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty()); inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt()); //endregion //赋值 赋值明细 防止作废的单据查不到明细 故注掉下面代码 // 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 修改入库总单 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 库存 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) { //赋值 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 修改入库总单 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 } //endregion return ResponseResultUtil.success(); } /** * @desc : 其他入库办理 * @date : 2024/3/7 15:47 * @author : 寇珊珊 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO otherHandleInbound(InboundVO inboundVO) { //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()) { //region 修改明细 if (inboundItemVO.getIntoId() != null) { 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 编辑明细 inboundItemVO .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty())) .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt())) .setIntoingQty(BigDecimal.ZERO) .setIntoingAmt(BigDecimal.ZERO) ; //入库状态 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())) ); //endregion //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.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()) .setIntoType(Constant.IntoType.OTHER.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.OTHER_INBOUND.getValue()); inboundItemVO.setAddOrEditFlag(true); //endregion } //endregion } //endregion //region 删除明细 if (inboundVO.getDeleteItemList() != null && inboundVO.getDeleteItemList().size() > 0) { for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) { //region 将库存需要的参数赋值 inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue()); //endregion 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 编辑总单 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 修改库存 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 otherInboundCancel(InboundVO inboundVO) { //region 总单数据信息 InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId()); Inbound inbound = new Inbound(); inbound.setIntoId(inboundResponse.getIntoId()) .setIntoDate(null) .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName()) .setIntoingQty(inboundResponse.getIntoQty()) .setIntoingAmt(inboundResponse.getIntoAmt()) .setIntoQty(BigDecimal.ZERO) .setIntoAmt(BigDecimal.ZERO); //修改 inboundMapper.update(inbound, new UpdateWrapper().lambda() .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId())) ); //endregion //region 明细数据 InboundItemQuery inboundItemQuery = new InboundItemQuery().setIntoId(inbound.getIntoId()); //根据总单查明细 List inboundItemResponseList = inboundItemMapper.selectByCond(inboundItemQuery); for (InboundItemResponse inboundItemResponse : inboundItemResponseList) { //region 将库存需要的参数赋值 inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName()); inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue()); inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate()); inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate()); //region InboundItem inboundItem = new InboundItem(); inboundItem .setIntoId(inbound.getIntoId()) .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName()) .setIntoingQty(inboundItemResponse.getInvQty()) .setIntoingAmt(inboundItemResponse.getIntoAmt()) .setIntoQty(BigDecimal.ZERO) .setIntoAmt(BigDecimal.ZERO) .setCostPrice(BigDecimal.ZERO) .setCostAmt(BigDecimal.ZERO) .setItemId(inboundItemResponse.getItemId()); //修改 inboundItemMapper.update(inboundItem, new UpdateWrapper().lambda() .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId())) ); //数量金额取反 用于给库存使用 inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate()); inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate()); } //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 : 条件查询 --- web端入库办理用 * @date : 2024/3/23 9:24 * @author : 寇珊珊 */ @Pagination public ResponseResultVO> selectInbound(InboundQuery inboundQuery) { return super.mergeListWithCount(inboundQuery, inboundMapper.selectInbound(inboundQuery), inboundMapper.selectInboundCond(inboundQuery)); } /** * @desc : 查询明细查询 --- web端入库办理用 * @date : 2024/3/9 15:43 * @author : 寇珊珊 */ public ResponseResultVO> selectInboundItem(String id) { Map result = new HashMap<>(); // 商品明细 List inboundItemResponses = inboundItemMapper.selectInboundItem(new InboundItemQuery().setIntoId(id)); result.put("itemList", inboundItemResponses); // 收款 // 附件 return ResponseResultUtil.success(result); } /** * @desc : 查询待入库数量(小程序(我的)) * @date : 2024/4/9 15:43 * @author : 周兴 */ public ResponseResultVO selectWaitInboundCount(InboundQuery inboundQuery) { return ResponseResultUtil.success(inboundMapper.selectInboundCond(inboundQuery)); } }