|
|
@@ -1,35 +1,33 @@
|
|
|
package com.dk.mdm.service.ivt.inventory;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
-import com.dk.common.model.pojo.PageList;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+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.InOutRecordConvert;
|
|
|
-import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
|
|
|
-import com.dk.mdm.infrastructure.convert.ivt.InventoryBatchConvert;
|
|
|
import com.dk.mdm.infrastructure.convert.ivt.InventoryConvert;
|
|
|
import com.dk.mdm.mapper.common.CommonMapper;
|
|
|
import com.dk.mdm.mapper.ivt.*;
|
|
|
import com.dk.mdm.model.pojo.ivt.*;
|
|
|
-import com.dk.common.service.BaseService;
|
|
|
-import com.dk.common.mapper.BaseMapper;
|
|
|
import com.dk.mdm.model.query.ivt.*;
|
|
|
import com.dk.mdm.model.response.ivt.*;
|
|
|
-import com.dk.mdm.model.query.ivt.InventoryQuery;
|
|
|
-import com.dk.mdm.model.response.ivt.InventoryResponse;
|
|
|
-import com.dk.mdm.model.vo.ivt.*;
|
|
|
+import com.dk.mdm.model.vo.ivt.InOutRecordVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.InventoryBatchVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.InventoryVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import com.dk.common.infrastructure.constant.Constant;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
@@ -144,7 +142,7 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
inOutRecordVO.setBiznisId(inOutRecordVO.getOutId());
|
|
|
//业务单明细ID
|
|
|
inOutRecordVO.setBiznisItemId(inOutRecordVO.getItemId());
|
|
|
- //是负库存逻辑
|
|
|
+ //region 是负库存逻辑
|
|
|
if (inOutRecordVO.getCanNegativeFlag()) {
|
|
|
//入库数量
|
|
|
inOutRecordVO.setIntoQty(inOutRecordVO.getOutQty());
|
|
|
@@ -153,7 +151,8 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
//入库金额
|
|
|
inOutRecordVO.setIntoAmt(BigDecimal.ZERO);
|
|
|
}
|
|
|
- //不是负库存逻辑
|
|
|
+ //endregion
|
|
|
+ //region 不是负库存逻辑
|
|
|
else {
|
|
|
//入库数量
|
|
|
inOutRecordVO.setIntoQty(inOutRecordVO.getOutQty());
|
|
|
@@ -162,6 +161,7 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
//入库金额
|
|
|
inOutRecordVO.setIntoAmt(inOutRecordVO.getOutAmt());
|
|
|
}
|
|
|
+ //endregion
|
|
|
//入库日期
|
|
|
inOutRecordVO.setAccDate(inOutRecordVO.getOutDate());
|
|
|
}
|
|
|
@@ -217,8 +217,8 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
if (inventoryBatchVO.getBiznisItemId() == null || "".equals(inventoryBatchVO.getBiznisItemId())) {
|
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FROM_ITEM_ID_IS_NULL.getMessage());
|
|
|
}
|
|
|
- //库存业务类型是盘亏出库 不校验 入库价不为空
|
|
|
- if (inventoryBatchVO.getPriceInto() == null && !Constant.InventoryDocCode.INVENTORY_LOSS.getValue().equals(inventoryBatchVO.getInventoryDocCode())) {
|
|
|
+ //入库价不为空
|
|
|
+ if (inventoryBatchVO.getPriceInto() == null) {
|
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.COST_PRICE_IS_NULL.getMessage());
|
|
|
}
|
|
|
//数量不为空 并且 >0
|
|
|
@@ -250,140 +250,202 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
List<InOutRecordVO> deleteOutList = new ArrayList<>();
|
|
|
//endregion
|
|
|
|
|
|
- //region map转json
|
|
|
+ // region 库存接收类型对应 和 新建还是删除标识
|
|
|
+ String inventoryDocCode = null;
|
|
|
+ Boolean addOrEditFlag = true;
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region map转json ---用来存储传过来的数据
|
|
|
JSONArray intoDetail = new JSONArray();
|
|
|
JSONArray delIntoDetail = new JSONArray();
|
|
|
JSONArray outDetail = new JSONArray();
|
|
|
JSONArray delOutDetail = new JSONArray();
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region json转实体 ----用来存储传过来的数据转完jsonArray后再转成对应实体List
|
|
|
+ //入库集合
|
|
|
+ List<InOutRecordVO> intoList = new ArrayList<>();
|
|
|
+ //入库删除集合
|
|
|
+ List<InOutRecordVO> delIntoList = new ArrayList<>();
|
|
|
+ //出库集合
|
|
|
+ List<InOutRecordVO> outList = new ArrayList<>();
|
|
|
+ //出库删除集合
|
|
|
+ List<InOutRecordVO> delOutList = new ArrayList<>();
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region map转json 提取数据
|
|
|
//入库
|
|
|
if (map.get("intoDetail") != null) {
|
|
|
intoDetail = (JSONArray) JSON.toJSON(map.get("intoDetail"));
|
|
|
+ JSONObject obj = (JSONObject) intoDetail.get(0);
|
|
|
+ inventoryDocCode = obj.get("inventoryDocCode").toString();
|
|
|
+ addOrEditFlag = obj.getBoolean("addOrEditFlag");
|
|
|
}
|
|
|
//入库删除
|
|
|
if (map.get("delIntoDetail") != null) {
|
|
|
delIntoDetail = (JSONArray) JSON.toJSON(map.get("delIntoDetail"));
|
|
|
+ JSONObject obj = (JSONObject) intoDetail.get(0);
|
|
|
+ inventoryDocCode = obj.get("inventoryDocCode").toString();
|
|
|
}
|
|
|
//出库
|
|
|
if (map.get("outDetail") != null) {
|
|
|
outDetail = (JSONArray) JSON.toJSON(map.get("outDetail"));
|
|
|
+ JSONObject obj = (JSONObject) intoDetail.get(0);
|
|
|
+ inventoryDocCode = obj.get("inventoryDocCode").toString();
|
|
|
}
|
|
|
//出库删除
|
|
|
if (map.get("delOutDetail") != null) {
|
|
|
delOutDetail = (JSONArray) JSON.toJSON(map.get("delOutDetail"));
|
|
|
+ JSONObject obj = (JSONObject) intoDetail.get(0);
|
|
|
+ inventoryDocCode = obj.get("inventoryDocCode").toString();
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
- //region json转实体
|
|
|
- //入库集合
|
|
|
- List<InOutRecordVO> intoList = new ArrayList<>();
|
|
|
- //入库删除集合
|
|
|
- List<InOutRecordVO> delIntoList = new ArrayList<>();
|
|
|
- //出库集合
|
|
|
- List<InOutRecordVO> outList = new ArrayList<>();
|
|
|
- //出库删除集合
|
|
|
- List<InOutRecordVO> delOutList = new ArrayList<>();
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 明细 取值
|
|
|
|
|
|
- //region 入库删除库存
|
|
|
- if (delIntoDetail.size() > 0) {
|
|
|
- //赋值并校验库存流水数据
|
|
|
- delIntoList = delIntoDetail.toJavaList(InOutRecordVO.class);
|
|
|
- delIntoList = this.setInOutRecordMessageByInto(delIntoList);
|
|
|
- //删除库存、库存批次,库存流水,出库成本
|
|
|
- this.deleteInventory(delIntoList);
|
|
|
- }
|
|
|
- //endregion
|
|
|
+ //region 判断是库位调整还是其他类型操作库存然后走对应的逻辑
|
|
|
+ //库位移动
|
|
|
+ if (Constant.InventoryDocCode.MOVE.getValue().equals(inventoryDocCode)) {
|
|
|
+ //region 新建
|
|
|
+ if (addOrEditFlag) {
|
|
|
+ //先出
|
|
|
+ if (outDetail.size() > 0) {
|
|
|
+ outList = outDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ outList = this.setInOutRecordMessageByOut(outList);
|
|
|
+ //出库
|
|
|
+ outList = this.warehouseAdjustmentOut(outList);
|
|
|
+ //反写出库单金额等信息
|
|
|
+ this.updateOutbound(outList);
|
|
|
+ } else {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.NO_DATA_MOVED_OUT.getMessage());
|
|
|
|
|
|
- //region 出库删除库存
|
|
|
- if (delOutDetail.size() > 0) {
|
|
|
- //赋值并校验库存流水数据
|
|
|
- delOutList = delOutDetail.toJavaList(InOutRecordVO.class);
|
|
|
- delOutList = this.setInOutRecordMessageByInto(delOutList);
|
|
|
- //是负库存逻辑
|
|
|
- if (outList.get(0).getCanNegativeFlag()) {
|
|
|
- //操作负库存--删除(作废)
|
|
|
- this.operatingNegativeInventoryDelete(delOutList);
|
|
|
- }
|
|
|
- //不是负库存逻辑
|
|
|
- else{
|
|
|
- //删除库存、库存批次,库存流水,出库成本
|
|
|
- this.deleteInventory(delOutList);
|
|
|
+ }
|
|
|
+ //后入
|
|
|
+ if (intoDetail.size() > 0) {
|
|
|
+ intoList = intoDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ intoList = this.setInOutRecordMessageByInto(intoList);
|
|
|
+ //根据来源id明细查询移动的出库单的单价、成本单价、金额等信息 赋值给需要已入的入库单
|
|
|
+ intoList = this.selectOutbound(intoList);
|
|
|
+ //入库
|
|
|
+ this.warehouseAdjustmentInto(intoList);
|
|
|
+ //修改入库单单价、金额、成本等信息
|
|
|
+ this.updateIntobound(intoList);
|
|
|
+ } else {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.NO_DATA_MOVED_IN.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- //endregion
|
|
|
+ //endregion
|
|
|
+ //region 删除
|
|
|
+ else {
|
|
|
+ //入库
|
|
|
+ if (delIntoList.size() > 0) {
|
|
|
+ delIntoList = delIntoDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ delIntoList = this.setInOutRecordMessageByInto(delIntoList);
|
|
|
+ //入库相关删除
|
|
|
+ this.warehouseAdjustmentDelInto(delIntoList);
|
|
|
+ } else {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.NO_DATA_MOVED_OUT_DEL.getMessage());
|
|
|
+ }
|
|
|
|
|
|
- //region 入库操作库存
|
|
|
- if (intoDetail.size() > 0 && outDetail.size() == 0) {
|
|
|
- //赋值并校验库存流水数据
|
|
|
- intoList = intoDetail.toJavaList(InOutRecordVO.class);
|
|
|
- intoList = this.setInOutRecordMessageByInto(intoList);
|
|
|
- //新建
|
|
|
- if (intoList.get(0).getAddOrEditFlag()) {
|
|
|
- //正常逻辑 新建库存
|
|
|
- this.operatingInsertInventory(intoList);
|
|
|
- } else {
|
|
|
- //正常逻辑 编辑库存
|
|
|
- this.operatingUpdateInventory(intoList);
|
|
|
+ //出库
|
|
|
+ if (delOutList.size() > 0) {
|
|
|
+
|
|
|
+ delOutList = delOutDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ delOutList = this.setInOutRecordMessageByInto(delOutList);
|
|
|
+ //库存相关反写
|
|
|
+ this.warehouseAdjustmentDelOut(delOutList);
|
|
|
+ } else {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.NO_DATA_MOVED_IN_DEL.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
+ //endregion
|
|
|
}
|
|
|
- //endregion
|
|
|
+ //其他库存操作
|
|
|
+ else {
|
|
|
+ //region 入库删除库存
|
|
|
+ if (delIntoDetail.size() > 0) {
|
|
|
+ delIntoList = delIntoDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ delIntoList = this.setInOutRecordMessageByInto(delIntoList);
|
|
|
+ //删除库存、库存批次,库存流水,出库成本
|
|
|
+ this.deleteInventory(delIntoList);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
|
|
|
- //region 出库操作库存
|
|
|
- else if (outDetail.size() > 0 && intoDetail.size() == 0) {
|
|
|
- //赋值并校验库存流水数据
|
|
|
- outList = outDetail.toJavaList(InOutRecordVO.class);
|
|
|
- outList = this.setInOutRecordMessageByOut(outList);
|
|
|
- //是否可以输入负数出库标
|
|
|
- //可以 走负库存逻辑
|
|
|
- if (outList.get(0).getCanNegativeFlag()) {
|
|
|
- //新建
|
|
|
- if (outList.get(0).getAddOrEditFlag()) {
|
|
|
- //新建入库单
|
|
|
- intoList = this.insertOrUpdateInbound(intoList);
|
|
|
- //操作负库存
|
|
|
- this.operatingNegativeInventory(intoList);
|
|
|
+ //region 出库删除库存
|
|
|
+ if (delOutDetail.size() > 0) {
|
|
|
+ delOutList = delOutDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ delOutList = this.setInOutRecordMessageByInto(delOutList);
|
|
|
+ //是负库存逻辑
|
|
|
+ if (outList.get(0).getCanNegativeFlag()) {
|
|
|
+ //操作负库存--删除(作废)
|
|
|
+ this.operatingNegativeInventoryDelete(delOutList);
|
|
|
}
|
|
|
- //编辑
|
|
|
+ //不是负库存逻辑
|
|
|
else {
|
|
|
- //编辑入库单
|
|
|
- intoList = this.insertOrUpdateInbound(intoList);
|
|
|
- //操作负库存
|
|
|
- this.operatingNegativeInventory(intoList);
|
|
|
+ //删除库存、库存批次,库存流水,出库成本
|
|
|
+ this.deleteInventory(delOutList);
|
|
|
}
|
|
|
}
|
|
|
- //不可以走正常逻辑
|
|
|
- else {
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 入库操作库存
|
|
|
+ if (intoDetail.size() > 0 && outDetail.size() == 0) {
|
|
|
+ intoList = intoDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ intoList = this.setInOutRecordMessageByInto(intoList);
|
|
|
//新建
|
|
|
- if (outList.get(0).getAddOrEditFlag()) {
|
|
|
+ if (intoList.get(0).getAddOrEditFlag()) {
|
|
|
//正常逻辑 新建库存
|
|
|
- this.operatingInsertInventory(outList);
|
|
|
+ this.operatingInsertInventory(intoList);
|
|
|
} else {
|
|
|
//正常逻辑 编辑库存
|
|
|
- this.operatingUpdateInventory(outList);
|
|
|
+ this.operatingUpdateInventory(intoList);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- //endregion
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 出库操作库存
|
|
|
+ else if (outDetail.size() > 0 && intoDetail.size() == 0) {
|
|
|
+ outList = outDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ outList = this.setInOutRecordMessageByOut(outList);
|
|
|
+ //是否可以输入负数出库标
|
|
|
+ //可以 走负库存逻辑
|
|
|
+ if (outList.get(0).getCanNegativeFlag()) {
|
|
|
+ //新建
|
|
|
+ if (outList.get(0).getAddOrEditFlag()) {
|
|
|
+ //新建入库单
|
|
|
+ outList = this.insertOrUpdateInbound(outList);
|
|
|
+ //操作负库存
|
|
|
+ this.operatingNegativeInventory(outList);
|
|
|
+ }
|
|
|
+ //编辑
|
|
|
+ else {
|
|
|
+ //编辑入库单
|
|
|
+ outList = this.insertOrUpdateInbound(outList);
|
|
|
+ //操作负库存
|
|
|
+ this.operatingNegativeInventory(outList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //不可以走正常逻辑
|
|
|
+ else {
|
|
|
+ //新建
|
|
|
+ if (outList.get(0).getAddOrEditFlag()) {
|
|
|
+ //正常逻辑 新建库存
|
|
|
+ this.operatingInsertInventory(outList);
|
|
|
+ } else {
|
|
|
+ //正常逻辑 编辑库存
|
|
|
+ this.operatingUpdateInventory(outList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
|
|
|
- //库位移动操作库存
|
|
|
- else if (intoDetail.size() > 0 && outDetail.size() > 0) {
|
|
|
- //赋值并校验库存流水数据
|
|
|
- intoList = intoDetail.toJavaList(InOutRecordVO.class);
|
|
|
- intoList = this.setInOutRecordMessageByInto(intoList);
|
|
|
- //赋值并校验库存流水数据
|
|
|
- outList = outDetail.toJavaList(InOutRecordVO.class);
|
|
|
- outList = this.setInOutRecordMessageByOut(outList);
|
|
|
-// //新建库存、库存批次,库存流水,出库成本
|
|
|
-// //修改入库信息
|
|
|
-// intoReturnList = this.insertAllInventory(intoList);
|
|
|
-// this.updateIntobound(intoReturnList);
|
|
|
-// //修改出库信息
|
|
|
-// outReturnList = this.insertAllInventory(outList);
|
|
|
-// this.updateOutbound(outReturnList);
|
|
|
- } else {
|
|
|
- throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.NO_MESSAGE_OPERATE_INVENTORY.getMessage());
|
|
|
}
|
|
|
//endregion
|
|
|
return ResponseResultUtil.success();
|
|
|
@@ -581,8 +643,8 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
this.deleteInventory(inOutRecordVOList);
|
|
|
//新建
|
|
|
this.operatingInsertInventory(inOutRecordVOList);
|
|
|
- //修改出库信息
|
|
|
- this.updateOutbound(inOutRecordVOList);
|
|
|
+ //修改源出库信息
|
|
|
+ this.updateOutboundPri(inOutRecordVOList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -659,7 +721,6 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
-
|
|
|
//region 库存数量重算 库存数量-删除数量
|
|
|
Inventory inventory = new Inventory();
|
|
|
//库存id
|
|
|
@@ -727,11 +788,11 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
inOutRecordVO.setIntoQty(inOutRecordVO.getIntoQty().abs());
|
|
|
//入库金额
|
|
|
inOutRecordVO.setIntoAmt(inOutRecordVO.getIntoAmt().abs());
|
|
|
- //实体转换
|
|
|
- InOutRecord inOutRecord = inOutRecordConvert.convertToPo(inOutRecordVO);
|
|
|
- //新建
|
|
|
- inOutRecordMapper.insert(inOutRecord);
|
|
|
}
|
|
|
+ //实体转换
|
|
|
+ InOutRecord inOutRecord = inOutRecordConvert.convertToPo(inOutRecordVO);
|
|
|
+ //新建
|
|
|
+ inOutRecordMapper.insert(inOutRecord);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1039,7 +1100,6 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
}
|
|
|
//endregion
|
|
|
|
|
|
-
|
|
|
//region 库存数量重算 库存数量-删除数量
|
|
|
Inventory inventory = new Inventory();
|
|
|
//库存id
|
|
|
@@ -1066,14 +1126,14 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @desc : 修改出库信息
|
|
|
+ * @desc : 修改源出库信息
|
|
|
* @date : 2024/4/1 14:30
|
|
|
* @author : 寇珊珊
|
|
|
*/
|
|
|
@Transactional(
|
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
|
- public void updateOutbound(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ public void updateOutboundPri(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
//根据源出库单分组
|
|
|
Map<String, List<InOutRecordVO>> InOutRecordVOListMap = inOutRecordVOList.stream().collect(Collectors.groupingBy(InOutRecordVO::getSOutId));
|
|
|
for (String str : InOutRecordVOListMap.keySet()) {
|
|
|
@@ -1092,7 +1152,7 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
outboundItem.setPriceOut(inOutRecordVO.getCostPrice());
|
|
|
}
|
|
|
outboundItem.setCostPrice(inOutRecordVO.getCostPrice());
|
|
|
- outboundItem.setCostAmt(inOutRecordVO.getIntoQty());
|
|
|
+ outboundItem.setCostAmt(inOutRecordVO.getIntoAmt());
|
|
|
//修改
|
|
|
outboundItemMapper.update(outboundItem,
|
|
|
new UpdateWrapper<OutboundItem>().lambda()
|
|
|
@@ -1284,13 +1344,13 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
//region 判断是否需要删除库存
|
|
|
InventoryResponse inventoryResponse = this.checkInventoryNumber(inOutRecordVO);
|
|
|
- if(inventoryResponse == null){
|
|
|
+ if (inventoryResponse == null) {
|
|
|
//删除的商品在库存中不存在
|
|
|
throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_DOES_NOT_EXIST.getMessage());
|
|
|
}
|
|
|
//库存数量为0 直接删除
|
|
|
- if(inventoryResponse.getInvQty().compareTo(BigDecimal.ZERO)==0){
|
|
|
- Inventory inventory = new Inventory();
|
|
|
+ if (inventoryResponse.getInvQty().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ Inventory inventory = new Inventory();
|
|
|
inventory.setInvId(inventoryResponse.getInvId());
|
|
|
inventoryMapper.deleteData(inventory);
|
|
|
}
|
|
|
@@ -1334,37 +1394,326 @@ public class InventoryService extends BaseService<Inventory> {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**************************************************仓位调整**********************************************************************/
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc : 仓库调整出库
|
|
|
+ * @date : 2024/4/12 15:37
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public List<InOutRecordVO> warehouseAdjustmentOut(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //校验库存是否存在
|
|
|
+ InventoryResponse inventoryResponse = this.checkInventoryNumber(inOutRecordVO);
|
|
|
+ //region 库存不存在
|
|
|
+ if (inventoryResponse == null) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //region 库存存在
|
|
|
+ else {
|
|
|
+ inOutRecordVO.setInvId(inventoryResponse.getInvId());
|
|
|
+
|
|
|
+ //region 库存批次 编辑
|
|
|
+ this.updateInventoryBatch(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
|
|
|
+ //region 修改/新建 库存数量,可用量,金额等信息
|
|
|
+ this.updateInventoryMessageAdd(inventoryResponse, inOutRecordVO);
|
|
|
+ //endregion
|
|
|
|
|
|
+ //region 库存流水
|
|
|
+ this.insertInboundRecord(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ return inOutRecordVOList;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @desc : 修改入库信息
|
|
|
- * @date : 2024/4/1 14:30
|
|
|
+ * @desc : 修改出库
|
|
|
+ * @date : 2024/4/16 9:59
|
|
|
* @author : 寇珊珊
|
|
|
*/
|
|
|
@Transactional(
|
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
|
- public void updateIntobound(List<InOutRecordVO> intoReturnList) {
|
|
|
- //反写出库单金额 单价
|
|
|
- if (Constant.InventoryType.INBOUND.getName().equals(intoReturnList.get(0).getInventoryType())) {
|
|
|
- for (InOutRecordVO inOutRecordVO : intoReturnList) {
|
|
|
- //明细
|
|
|
- InboundItem inboundItem = new InboundItem();
|
|
|
- inboundItem.setItemId(inOutRecordVO.getBiznisItemId());
|
|
|
- inboundItem.setInvId(inOutRecordVO.getInvId());
|
|
|
+ public void updateOutbound(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ //根据源出库单分组
|
|
|
+ Map<String, List<InOutRecordVO>> InOutRecordVOListMap = inOutRecordVOList.stream().collect(Collectors.groupingBy(InOutRecordVO::getBiznisId));
|
|
|
+ for (String str : InOutRecordVOListMap.keySet()) {
|
|
|
+ //提取分组后的明细
|
|
|
+ List<InOutRecordVO> inOutRecordVOListGroup = InOutRecordVOListMap.get(str);
|
|
|
+ //提取总额,总量
|
|
|
+ BigDecimal sumOutAmt = inOutRecordVOListGroup.stream().map(InOutRecordVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOListGroup) {
|
|
|
+ //修改明细
|
|
|
+ OutboundItem outboundItem = new OutboundItem();
|
|
|
+ outboundItem.setItemId(inOutRecordVO.getBiznisItemId());
|
|
|
+ outboundItem.setOutAmt(inOutRecordVO.getIntoAmt());
|
|
|
+ outboundItem.setPriceOut(inOutRecordVO.getCostPrice());
|
|
|
+ outboundItem.setCostPrice(inOutRecordVO.getCostPrice());
|
|
|
+ outboundItem.setCostAmt(inOutRecordVO.getIntoAmt());
|
|
|
//修改
|
|
|
- inboundItemMapper.update(inboundItem,
|
|
|
- new UpdateWrapper<InboundItem>().lambda()
|
|
|
- .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
|
|
|
+ outboundItemMapper.update(outboundItem,
|
|
|
+ new UpdateWrapper<OutboundItem>().lambda()
|
|
|
+ .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getSOutItemId()))
|
|
|
);
|
|
|
}
|
|
|
+ //修改总单
|
|
|
+ Outbound outbound = new Outbound();
|
|
|
+ outbound.setOutId(str);
|
|
|
+ outbound.setOutAmt(sumOutAmt);
|
|
|
+ //修改
|
|
|
+ outboundMapper.update(outbound,
|
|
|
+ new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 仓库调整入库
|
|
|
+ * @date : 2024/4/12 15:37
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public List<InOutRecordVO> warehouseAdjustmentInto(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //校验库存是否存在
|
|
|
+ InventoryResponse inventoryResponse = this.checkInventoryNumber(inOutRecordVO);
|
|
|
+ //region 库存不存在---新建
|
|
|
+ if (inventoryResponse == null) {
|
|
|
+
|
|
|
+ //region 新建库存
|
|
|
+ inOutRecordVO = this.insertInventory(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 库存批次
|
|
|
+ this.insertInventoryBatch(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 库存流水
|
|
|
+ this.insertInboundRecord(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //region 库存存在
|
|
|
+ else {
|
|
|
+ inOutRecordVO.setInvId(inventoryResponse.getInvId());
|
|
|
+
|
|
|
+ //region 库存批次
|
|
|
+ this.insertInventoryBatch(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 修改/新建 库存数量,可用量,金额等信息
|
|
|
+ this.updateInventoryMessageAdd(inventoryResponse, inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 库存流水
|
|
|
+ this.insertInboundRecord(inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ return inOutRecordVOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 根据来源id和来源明细id查找出库单获取单价,金额等信息
|
|
|
+ * @date : 2024/4/16 10:19
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public List<InOutRecordVO> selectOutbound(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(inOutRecordVO.getSOutItemId());
|
|
|
+ //单价
|
|
|
+ inOutRecordVO.setPriceInto(outboundItemResponse.getPriceOut());
|
|
|
+ //金额
|
|
|
+ inOutRecordVO.setIntoAmt(outboundItemResponse.getOutAmt());
|
|
|
+ //成本单价
|
|
|
+ inOutRecordVO.setCostPrice(outboundItemResponse.getCostPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ return inOutRecordVOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 修改入库单---单价、金额、成本等信息
|
|
|
+ * @date : 2024/4/16 10:18
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void updateIntobound(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ BigDecimal sumOutQty = inOutRecordVOList.stream().map(InOutRecordVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal sumOutAmt = inOutRecordVOList.stream().map(InOutRecordVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ //region 编辑入库单数量
|
|
|
+ InboundResponse inboundResponse = inboundMapper.selectMessageByOtherQuery(new InboundQuery().setFromId(inOutRecordVOList.get(0).getBiznisId()));
|
|
|
+ Inbound inbound = new Inbound();
|
|
|
+ inbound.setIntoId(inboundResponse.getIntoId());
|
|
|
+ inbound.setIntoQty(sumOutQty.abs());
|
|
|
+ inbound.setIntoAmt(sumOutAmt.abs());
|
|
|
+ inboundMapper.update(inbound,
|
|
|
+ new UpdateWrapper<Inbound>().lambda()
|
|
|
+ .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
|
|
|
+ );
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 明细
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().
|
|
|
+ setFromId(inOutRecordVO.getBiznisId()).setFromItemId(inOutRecordVO.getBiznisItemId()));
|
|
|
+ InboundItemResponse inboundItemResponse = inboundItemResponses.get(0);
|
|
|
+ InboundItem inboundItem = new InboundItem();
|
|
|
+ //总单id
|
|
|
+ inboundItem.setItemId(inboundItemResponse.getItemId());
|
|
|
+ //出库数量
|
|
|
+ inboundItem.setOutQty(inOutRecordVO.getIntoQty().abs());
|
|
|
+ //已入库数量
|
|
|
+ inboundItem.setIntoQty(inOutRecordVO.getIntoQty().abs());
|
|
|
+ //已入库金额
|
|
|
+ inboundItem.setIntoAmt(inOutRecordVO.getIntoAmt().abs());
|
|
|
+ //成本单价
|
|
|
+ inboundItem.setCostPrice(inOutRecordVO.getCostPrice().abs());
|
|
|
+ //成本金额
|
|
|
+ inboundItem.setCostAmt(inOutRecordVO.getIntoAmt().abs());
|
|
|
+ //库存id
|
|
|
+ inboundItem.setInvId(inOutRecordVO.getInvId());
|
|
|
+ inboundItemMapper.update(inboundItem,
|
|
|
+ new UpdateWrapper<InboundItem>().lambda()
|
|
|
+ .eq(InboundItem::getIntoId, UUID.fromString(inboundItem.getItemId()))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 调整仓库-入库删除
|
|
|
+ * @date : 2024/4/10 13:09
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void warehouseAdjustmentDelInto(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //region 校验库存 根据sku,仓库,非标号查询
|
|
|
+ InventoryResponse inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
|
|
|
+ .setSkuId(inOutRecordVO.getSkuId())
|
|
|
+ .setWhId(inOutRecordVO.getWhId())
|
|
|
+ .setNonStdCode(inOutRecordVO.getNonStdCode()));
|
|
|
+ //库存是否存在
|
|
|
+ if (inventoryResponse == null) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 根据来源id和来源明细id查询数据 库存批次删除
|
|
|
+ InventoryBatchResponse inventoryBatchResponse = inventoryBatchMapper.selectByFromCondition(new InventoryBatchQuery()
|
|
|
+ .setFromId(inOutRecordVO.getBiznisId()).setFromItemId(inOutRecordVO.getBiznisItemId()));
|
|
|
+ if (inventoryBatchResponse == null) {
|
|
|
+ //当前编辑的数据在库存批次中不存在
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_BATCH_DOES_NOT_EXIST.getMessage());
|
|
|
+ } else {
|
|
|
+ //数据库中库存批次数量和传入数量一致 可以更改
|
|
|
+ if (inventoryResponse.getInvQty().compareTo(inOutRecordVO.getIntoQty().abs()) == 0) {
|
|
|
+ InventoryBatch inventoryBatch = new InventoryBatch();
|
|
|
+ //来源单ID
|
|
|
+ inventoryBatch.setFromId(inOutRecordVO.getBiznisId());
|
|
|
+ //来源单明细ID
|
|
|
+ inventoryBatch.setFromItemId(inOutRecordVO.getBiznisItemId());
|
|
|
+ inventoryBatchMapper.deleteData(inventoryBatch);
|
|
|
+ } else {
|
|
|
+ //不允许编辑,对应库存数据已被修改
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_DATA_HAS_BEEN_MODIFIED.getMessage());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 修改库存数量,可用量,金额等信息
|
|
|
+ this.updateInventoryMessageDelete(inventoryResponse, inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 根据来源id和来源明细id查询数据 库存流水删除
|
|
|
+ InOutRecord inOutRecord = new InOutRecord();
|
|
|
+ //来源id
|
|
|
+ inOutRecord.setBiznisId(inOutRecordVO.getBiznisId());
|
|
|
+ //来源明细Id
|
|
|
+ inOutRecord.setBiznisItemId(inOutRecordVO.getBiznisItemId());
|
|
|
+ inOutRecordMapper.deleteData(inOutRecord);
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 调整仓库-出库反写
|
|
|
+ * @date : 2024/4/10 13:09
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void warehouseAdjustmentDelOut(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //region 校验库存 根据sku,仓库,非标号查询
|
|
|
+ InventoryResponse inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
|
|
|
+ .setSkuId(inOutRecordVO.getSkuId())
|
|
|
+ .setWhId(inOutRecordVO.getWhId())
|
|
|
+ .setNonStdCode(inOutRecordVO.getNonStdCode()));
|
|
|
+ //库存是否存在
|
|
|
+ if (inventoryResponse == null) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 根据来源id和来源明细id查询数据 库存批次删除
|
|
|
+ if ((Constant.InventoryType.OUTBOUND.getName().equals(inOutRecordVO.getInventoryType()) &&
|
|
|
+ !Constant.InventoryDocCode.SALE_RETURN.getValue().equals(inOutRecordVO.getInventoryDocCode())) ||
|
|
|
+ Constant.InventoryDocCode.PURCHASE_RETURN.getValue().equals(inOutRecordVO.getInventoryDocCode())
|
|
|
+ ) {
|
|
|
+ //根据outItemId查找出库成本数据
|
|
|
+ List<OutboundItemCostResponse> outboundItemCostResponses = outboundItemCostMapper.selectByCond(new OutboundItemCostQuery().setOutItemId(inOutRecordVO.getBiznisItemId()));
|
|
|
+ for (OutboundItemCostResponse outboundItemCostResponse : outboundItemCostResponses) {
|
|
|
+ //查找库存批次
|
|
|
+ InventoryBatchResponse inventoryBatchResponse = inventoryBatchMapper.selectById(outboundItemCostResponse.getBatchId());
|
|
|
+ InventoryBatch inventoryBatch = new InventoryBatch();
|
|
|
+ inventoryBatch.setBatchId(outboundItemCostResponse.getBatchId());
|
|
|
+ inventoryBatch.setInvQty(inventoryBatchResponse.getInvQty().add(outboundItemCostResponse.getOutQty()));
|
|
|
+ inventoryBatch.setCostAmt(inventoryBatch.getInvQty().multiply(inventoryBatch.getCostPrice()));
|
|
|
+ inventoryBatchMapper.updateAmtAndQty(inventoryBatch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 修改库存数量,可用量,金额等信息
|
|
|
+ this.updateInventoryMessageDelete(inventoryResponse, inOutRecordVO);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 根据来源id和来源明细id查询数据 库存流水删除
|
|
|
+ InOutRecord inOutRecord = new InOutRecord();
|
|
|
+ //来源id
|
|
|
+ inOutRecord.setBiznisId(inOutRecordVO.getBiznisId());
|
|
|
+ //来源明细Id
|
|
|
+ inOutRecord.setBiznisItemId(inOutRecordVO.getBiznisItemId());
|
|
|
+ inOutRecordMapper.deleteData(inOutRecord);
|
|
|
+ //endregion
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**********************************************************************暂时废弃**********************************************************************/
|
|
|
+
|
|
|
/**
|
|
|
* @desc : 新建库存、库存批次,库存流水,出库成本
|
|
|
* @date : 2024/3/21 14:47
|