|
|
@@ -2,8 +2,17 @@ package com.dk.mdm.service.ivt.inventory;
|
|
|
|
|
|
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.dk.common.exception.BaseBusinessException;
|
|
|
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
+import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
+import com.dk.mdm.infrastructure.convert.ivt.InOutRecordConvert;
|
|
|
+import com.dk.mdm.mapper.ivt.InOutRecordMapper;
|
|
|
+import com.dk.mdm.model.pojo.ivt.InOutRecord;
|
|
|
import com.dk.mdm.model.pojo.ivt.Inventory;
|
|
|
import com.dk.mdm.mapper.ivt.InventoryMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
@@ -12,75 +21,291 @@ import com.dk.mdm.model.query.ivt.InventoryQuery;
|
|
|
import com.dk.mdm.model.query.ivt.OutboundQuery;
|
|
|
import com.dk.mdm.model.response.ivt.InboundResponse;
|
|
|
import com.dk.mdm.model.response.ivt.InventoryResponse;
|
|
|
+import com.dk.mdm.model.query.ivt.InventoryQuery;
|
|
|
+import com.dk.mdm.model.response.ivt.InventoryResponse;
|
|
|
+import com.dk.mdm.model.vo.ivt.InOutRecordVO;
|
|
|
+import com.dk.mdm.model.vo.ivt.InOutRecordVO;
|
|
|
import com.dk.mdm.model.vo.ivt.InventoryVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * @desc : 库存明细
|
|
|
- * @date : 2024/3/20 13:41
|
|
|
* @author : 寇珊珊
|
|
|
+ * @desc : 库存明细
|
|
|
+ * @date : 2024/3/20 13:41
|
|
|
*/
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class InventoryService extends BaseService<Inventory> {
|
|
|
|
|
|
- @Override
|
|
|
- public BaseMapper<Inventory> getRepository() {
|
|
|
- return inventoryMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private InventoryMapper inventoryMapper;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询
|
|
|
- * @date : 2024/3/18 11:20
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<InventoryResponse>> selectByCond(InventoryQuery query) {
|
|
|
- return super.mergeListWithCount(query, inventoryMapper.selectByCond(query),
|
|
|
- inventoryMapper.countByCond(query));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 新建
|
|
|
- * @date : 2024/3/20 13:46
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(
|
|
|
- rollbackFor = {Exception.class}
|
|
|
- )
|
|
|
- public ResponseResultVO<?> insertInbound(InventoryVO inventoryVO) {
|
|
|
- //1.判断库存数据是否存在,存在更细,不存在新建
|
|
|
-
|
|
|
-
|
|
|
- //2,库存明细插入
|
|
|
-
|
|
|
- //3.库存批次明细插入
|
|
|
-
|
|
|
- //4.存货流水插入
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 校验库存是否存在数据
|
|
|
- * @date : 2024/3/20 15:32
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(
|
|
|
- rollbackFor = {Exception.class}
|
|
|
- )
|
|
|
- public Boolean checkInventory(InventoryVO inventoryVO) {
|
|
|
- Boolean flag = false;
|
|
|
-
|
|
|
-
|
|
|
- return flag;
|
|
|
-
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public BaseMapper<Inventory> getRepository() {
|
|
|
+ return inventoryMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InventoryMapper inventoryMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InOutRecordMapper inOutRecordMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InOutRecordConvert inOutRecordConvert;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建
|
|
|
+ * @date : 2024/3/20 13:46
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<?> insertInbound(Map<String, Object> map) {
|
|
|
+ //region map转json
|
|
|
+ JSONObject total = (JSONObject) JSON.toJSON(map.get("total"));
|
|
|
+ JSONArray intoDetail = new JSONArray();
|
|
|
+ JSONArray outDetail = new JSONArray();
|
|
|
+ //入库
|
|
|
+ if (map.get("intoDetail") != null) {
|
|
|
+ intoDetail = (JSONArray) JSON.toJSON(map.get("intoDetail"));
|
|
|
+ }
|
|
|
+ //出库
|
|
|
+ if (map.get("outDetail") != null) {
|
|
|
+ outDetail = (JSONArray) JSON.toJSON(map.get("outDetail"));
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region json转实体
|
|
|
+ //入库集合
|
|
|
+ List<InOutRecordVO> intoList = new ArrayList<>();
|
|
|
+ //出库集合
|
|
|
+ List<InOutRecordVO> outList = new ArrayList<>();
|
|
|
+ //region 明细 取值
|
|
|
+ //入库操作库存
|
|
|
+ if (intoDetail.size() > 0 && outDetail.size() == 0) {
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ intoList = intoDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ intoList = this.setInOutRecordMessageByInto(intoList);
|
|
|
+ //新建库存流水
|
|
|
+ this.insertInboundRecord(intoList);
|
|
|
+ }
|
|
|
+ //出库操作库存
|
|
|
+ else if (outDetail.size() > 0 && intoDetail.size() == 0) {
|
|
|
+ //赋值并校验库存流水数据
|
|
|
+ outList = outDetail.toJavaList(InOutRecordVO.class);
|
|
|
+ outList = this.setInOutRecordMessageByOut(outList);
|
|
|
+ //新建库存流水
|
|
|
+ this.insertInboundRecord(outList);
|
|
|
+ }
|
|
|
+ //库位移动操作库存
|
|
|
+ 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);
|
|
|
+ //新建库存流水
|
|
|
+ this.insertInboundRecord(intoList);
|
|
|
+ this.insertInboundRecord(outList);
|
|
|
+ } else {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.NO_MESSAGE_OPERATE_INVENTORY.getMessage());
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ //endregion
|
|
|
+
|
|
|
+
|
|
|
+ //region 操作库存
|
|
|
+
|
|
|
+ //endregion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //2,库存明细插入
|
|
|
+
|
|
|
+ //3.库存批次明细插入
|
|
|
+
|
|
|
+ //4.存货流水插入
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 入库----赋值并校验库存流水数据
|
|
|
+ * @date : 2024/3/21 16:04
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public List<InOutRecordVO> setInOutRecordMessageByInto(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ //赋值
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //业务单据
|
|
|
+ inOutRecordVO.setBiznisType(Constant.InventoryDocCode.INTOBOUND.getValue());
|
|
|
+ //业务单ID
|
|
|
+ inOutRecordVO.setBiznisId(inOutRecordVO.getIntoId());
|
|
|
+ //业务单明细ID
|
|
|
+ inOutRecordVO.setBiznisItemId(inOutRecordVO.getItemId());
|
|
|
+ //入库价
|
|
|
+ inOutRecordVO.setPriceInto(inOutRecordVO.getPriceInto());
|
|
|
+ //入库日期
|
|
|
+ inOutRecordVO.setAccDate(inOutRecordVO.getIntoDate());
|
|
|
+ }
|
|
|
+ //region 校验是否传库存需要的数据
|
|
|
+ this.checkInventory(inOutRecordVOList);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ return inOutRecordVOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 出库----赋值并校验库存流水数据
|
|
|
+ * @date : 2024/3/21 16:06
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public List<InOutRecordVO> setInOutRecordMessageByOut(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ //赋值
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //业务单据
|
|
|
+ inOutRecordVO.setBiznisType(Constant.InventoryDocCode.OUTBOUND.getValue());
|
|
|
+ //业务单ID
|
|
|
+ inOutRecordVO.setBiznisId(inOutRecordVO.getOutId());
|
|
|
+ //业务单明细ID
|
|
|
+ inOutRecordVO.setBiznisItemId(inOutRecordVO.getItemId());
|
|
|
+ //入库价
|
|
|
+ inOutRecordVO.setPriceInto(inOutRecordVO.getPriceOut());
|
|
|
+ //入库数量
|
|
|
+ inOutRecordVO.setIntoQty(inOutRecordVO.getOutQty());
|
|
|
+ //入库金额
|
|
|
+ inOutRecordVO.setIntoAmt(inOutRecordVO.getOutAmt());
|
|
|
+ //入库日期
|
|
|
+ inOutRecordVO.setAccDate(inOutRecordVO.getOutDate());
|
|
|
+ }
|
|
|
+ //region 校验是否传库存需要的数据
|
|
|
+ this.checkInventory(inOutRecordVOList);
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ return inOutRecordVOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 校验是否传库存需要的数据
|
|
|
+ * @date : 2024/3/20 15:32
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void checkInventory(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ //校验明细中是否存在为空数据
|
|
|
+ if (inOutRecordVOList.size() == 0) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.DETAIL_LIST_IS_NUL.getMessage());
|
|
|
+ }
|
|
|
+ for (InOutRecordVO inventoryBatchVO : inOutRecordVOList) {
|
|
|
+ //商品ID
|
|
|
+ if (inventoryBatchVO.getSkuId() == null || "".equals(inventoryBatchVO.getSkuId())) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.SKU_IS_NULL.getMessage());
|
|
|
+ }
|
|
|
+ //仓库ID
|
|
|
+ if (inventoryBatchVO.getWhId() == null || "".equals(inventoryBatchVO.getWhId())) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.WAREHOUSE_IS_NULL.getMessage());
|
|
|
+ }
|
|
|
+// //单价不可为空
|
|
|
+// if(inventoryBatchVO.getCostPrice()==null || inventoryBatchVO.getCostPrice().compareTo(BigDecimal.ZERO)==0 ){
|
|
|
+// throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.COST_PRICE_IS_NULL.getMessage());
|
|
|
+// }
|
|
|
+ //总单id不可为空
|
|
|
+ if (inventoryBatchVO.getBiznisId() == null || "".equals(inventoryBatchVO.getBiznisId())) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.FROM_ID_IS_NULL.getMessage());
|
|
|
+ }
|
|
|
+ //明细id不可为空
|
|
|
+ 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) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.COST_PRICE_IS_NULL.getMessage());
|
|
|
+ }
|
|
|
+ //数量不为空
|
|
|
+ if (inventoryBatchVO.getIntoQty() == null) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.QTY_IS_NULL.getMessage());
|
|
|
+ }
|
|
|
+ //金额不为空
|
|
|
+ if (inventoryBatchVO.getIntoAmt() == null) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_IS_NULL.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建库存流水
|
|
|
+ * @date : 2024/3/21 14:47
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void insertInboundRecord(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ //循环传入的明细
|
|
|
+ for (InOutRecordVO inventoryBatchVO : inOutRecordVOList) {
|
|
|
+ //实体转换
|
|
|
+ InOutRecord inOutRecord = inOutRecordConvert.convertToPo(inventoryBatchVO);
|
|
|
+ //新建
|
|
|
+ inOutRecordMapper.insert(inOutRecord);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建库存
|
|
|
+ * @date : 2024/3/21 14:47
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void insertInventory(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+ //判断库存数据是否存在,存在更细,不存在新建
|
|
|
+ for (InOutRecordVO inOutRecordVO : inOutRecordVOList) {
|
|
|
+ //根据sku,仓库,非标号查询
|
|
|
+ InventoryResponse inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
|
|
|
+ .setSkuId(inOutRecordVO.getSkuId())
|
|
|
+ .setWhId(inOutRecordVO.getWhId())
|
|
|
+ .setNonStdCode(inOutRecordVO.getNonStdCode()));
|
|
|
+ //不存在 新建
|
|
|
+ if (inventoryResponse == null) {
|
|
|
+
|
|
|
+ }
|
|
|
+ //存在 出库校验库存是否充足重写updateById,入库加入数据
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建库存批次明细
|
|
|
+ * @date : 2024/3/21 14:47
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public void insertInventoryBatch(List<InOutRecordVO> inOutRecordVOList) {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|