Bläddra i källkod

Merge branch 'master' of http://git.dongkesoft.com:9001/iBOSS-2.0-Mini/iboss-server-mdm

songyang 2 år sedan
förälder
incheckning
e39986a2d2
24 ändrade filer med 967 tillägg och 293 borttagningar
  1. 10 1
      src/main/java/com/dk/mdm/controller/common/CommonController.java
  2. 6 0
      src/main/java/com/dk/mdm/mapper/common/CommonMapper.java
  3. 61 0
      src/main/java/com/dk/mdm/mapper/common/CommonMapper.xml
  4. 9 0
      src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.java
  5. 10 0
      src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.xml
  6. 1 1
      src/main/java/com/dk/mdm/mapper/ivt/InventoryMapper.xml
  7. 11 0
      src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.java
  8. 10 0
      src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.xml
  9. 1 1
      src/main/java/com/dk/mdm/mapper/mac/OtherPayableMapper.xml
  10. 2 9
      src/main/java/com/dk/mdm/mapper/mst/GoodsSkuMapper.xml
  11. 2 0
      src/main/java/com/dk/mdm/mapper/mst/SupplierMapper.java
  12. 1 0
      src/main/java/com/dk/mdm/model/pojo/mst/Supplier.java
  13. 6 1
      src/main/java/com/dk/mdm/model/response/mst/SpplierResponse.java
  14. 3 0
      src/main/java/com/dk/mdm/model/vo/ivt/InboundItemVO.java
  15. 15 0
      src/main/java/com/dk/mdm/model/vo/mst/SupplierVo.java
  16. 13 0
      src/main/java/com/dk/mdm/service/common/CommonService.java
  17. 172 112
      src/main/java/com/dk/mdm/service/ivt/inbound/InboundCheckService.java
  18. 22 10
      src/main/java/com/dk/mdm/service/ivt/inbound/InboundOtherService.java
  19. 486 137
      src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java
  20. 62 0
      src/main/java/com/dk/mdm/service/ivt/outbound/OutboundCheckService.java
  21. 3 3
      src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java
  22. 1 1
      src/main/java/com/dk/mdm/service/mac/AccountService.java
  23. 11 11
      src/main/java/com/dk/mdm/service/mac/OtherPayableService.java
  24. 49 6
      src/main/java/com/dk/mdm/service/mst/SupplierService.java

+ 10 - 1
src/main/java/com/dk/mdm/controller/common/CommonController.java

@@ -447,7 +447,16 @@ public class CommonController extends BaseController<Map<String, Object>> {
     public ResponseResultVO<List<Map<String, Object>>> getGoodsCategoryNoPage(@RequestBody Map<String, Object> param) {
         return commonService.getGoodsCategoryNoPage(param);
     }
-
+    /**
+     * @desc :  商品种类查询
+     * @author : 王英杰
+     * @date : 2024/2/26 10:36
+     */
+    @ApiOperation(value = "分页、关联、条件查询", notes = "分页、关联、条件查询")
+    @PostMapping({"get_goods_category_tree"})
+    public ResponseResultVO<List<Map<String, Object>>> getGoodsCategoryTree(@RequestBody Map<String, Object> param) {
+        return commonService.getGoodsCategoryTree(param);
+    }
 
     /**
      * @desc :  计量单位查询

+ 6 - 0
src/main/java/com/dk/mdm/mapper/common/CommonMapper.java

@@ -285,6 +285,12 @@ public interface CommonMapper extends BaseMapper<Map<String, Object>> {
      * @date : 2024/3/1 9:21
      */
     List<Map<String, Object>> getGoodsBrand(Map param);
+    /**
+     * @desc : 获取商品品牌 树形查询
+     * @author : 王英杰
+     * @date : 2024/3/1 9:21
+     */
+    List<Map<String, Object>> getGoodsCategoryTree(Map param);
 
     /**
      * @desc : 获取商品品牌数量

+ 61 - 0
src/main/java/com/dk/mdm/mapper/common/CommonMapper.xml

@@ -715,6 +715,67 @@
         </if>
     </select>
 
+    <!--    查询商品种类-->
+    <select id="getGoodsCategoryTree" resultType="java.util.Map">
+        SELECT
+        T.cat_id AS "catId",
+        T.cat_code AS "catCode",
+        T.cat_name AS "catName",
+        T.parent_id AS "parentId",
+        T.flg_valid AS "flgValid"
+        FROM
+        (--当前数据
+        SELECT
+        tmgc.cat_id,
+        tmgc.cat_code,
+        tmgc.cat_name,
+        tmgc.parent_id,
+        tmgc.flg_valid
+        FROM
+        dkic_b.t_mst_goods_category tmgc
+        <where>
+            <if test="searchText !=null">
+                AND ( tmgc.cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
+                or tmgc.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
+            </if>
+            <if test="cpId != null">
+                AND tmgc.cp_id = #{cpId}
+            </if>
+        </where>
+        UNION ALL--父级
+        SELECT
+        tmgcp.cat_id,
+        tmgcp.cat_code,
+        tmgcp.cat_name,
+        tmgcp.parent_id,
+        tmgcp.flg_valid
+        FROM
+        dkic_b.t_mst_goods_category tmgc
+        LEFT JOIN dkic_b.t_mst_goods_category tmgcp ON tmgc.cat_id = ANY ( tmgcp.level_lower )
+        <where>
+            <if test="searchText !=null">
+                AND ( tmgc.cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
+                or tmgc.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
+            </if>
+            <if test="cpId != null">
+                AND tmgc.cp_id = #{cpId}
+            </if>
+        </where>
+        ) T
+        WHERE T.cat_id IS NOT NULL
+        GROUP BY
+        T.cat_id,
+        T.cat_code,
+        T.cat_name,
+        T.parent_id,
+        T.flg_valid
+
+        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            limit #{end} offset #{start}
+        </if>
+
+    </select>
+
     <!-- 查询表t_mst_goods_brand,(条件查询)个数 -->
     <select id="countGoodsBrand" resultType="Long">
         SELECT

+ 9 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.java

@@ -108,5 +108,14 @@ public interface InboundMapper extends BaseMapper<Inbound>{
      * @date : 2024/3/6 10:36
      */
     InboundResponse selectInboundReturnById(@Param("intoId") String intoId);
+
+    /**
+     * @desc   : 根据来源id查询
+     * @date   : 2024/3/9 9:14
+     * @author : 寇珊珊
+     */
+    InboundResponse selectByFromId(@Param("fromId") String fromId);
+
+
 }
 

+ 10 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.xml

@@ -1069,4 +1069,14 @@
         left join t_mac_account_item tmai on tmai.item_id = tpi.receivable_id
         WHERE tpi.into_id = #{intoId}::uuid AND tpi.flg_valid = true
     </select>
+
+
+    <!-- 根据来源id查询 -->
+    <select id="selectByFromId" resultMap="BaseResultMapResponse">
+        SELECT
+        <include refid="Base_Column_List_Response"/>
+        FROM dkic_b.t_psi_inbound tpi
+        WHERE tpi.from_id = #{fromId}::uuid
+        and tpi.flg_valid
+    </select>
 </mapper>

+ 1 - 1
src/main/java/com/dk/mdm/mapper/ivt/InventoryMapper.xml

@@ -66,7 +66,7 @@
     <sql id="Condition">
         <where>
             <if test="whId != null and whId != ''">
-                AND tpi.wh_id = #{whId}
+                AND tpi.wh_id = #{whId}::UUID
             </if>
             <if test="skuId != null and skuId != ''">
                 AND tpi.sku_id = #{skuId}

+ 11 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.java

@@ -7,6 +7,7 @@ import com.dk.mdm.model.query.ivt.InboundQuery;
 import com.dk.mdm.model.query.ivt.OutboundQuery;
 import com.dk.mdm.model.response.ivt.InboundResponse;
 import com.dk.mdm.model.response.ivt.OutboundResponse;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -72,5 +73,15 @@ public interface OutboundMapper extends BaseMapper<Outbound>{
      * @author : 寇珊珊
      */
     Long selectOutboundCond(OutboundQuery outboundQuery);
+
+    /**
+     * @desc   : 根据来源id查询
+     * @date   : 2024/4/16 13:34
+     * @author : 寇珊珊
+     */
+    OutboundResponse selectByFromId(@Param("fromId") String fromId);
+
+
+
 }
 

+ 10 - 0
src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.xml

@@ -883,4 +883,14 @@
         left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
     </sql>
 
+
+    <!-- 根据来源id查询 -->
+    <select id="selectByFromId" resultMap="BaseResultMapResponse">
+        SELECT
+        <include refid="Base_Column_List_Response"/>
+        FROM dkic_b.t_psi_outbound  tpo
+        WHERE tpo.from_id = #{fromId}::uuid
+        and tpo.flg_valid
+    </select>
+
 </mapper>

+ 1 - 1
src/main/java/com/dk/mdm/mapper/mac/OtherPayableMapper.xml

@@ -62,7 +62,7 @@
                 AND t.business_type = #{businessType}
             </if>
             <if test="objectId != null and objectId != ''">
-                AND t.object_id = #{objectId}
+                AND t.object_id = #{objectId}::uuid
             </if>
             <if test="orgId != null and orgId != ''">
                 AND t.org_id = #{orgId}

+ 2 - 9
src/main/java/com/dk/mdm/mapper/mst/GoodsSkuMapper.xml

@@ -139,7 +139,7 @@
                 )
             </if>
             <if test="searchText !=null">
-                AND ( tmgs.sku_name LIKE concat('%', #{searchText}, '%')
+                AND tmgs.sku_name LIKE concat('%', #{searchText}, '%')
             </if>
         </where>
     </sql>
@@ -163,14 +163,7 @@
         LEFT JOIN dkic_b.t_mst_goods_series tmgsr ON tmgsr.series_id = tmgs.series_id
         LEFT JOIN dkic_b.t_psi_inventory tpi ON tpi.sku_id = tmgs.sku_id
         <include refid="Condition"/>
-        ORDER BY CASE
-        WHEN #{sort}  = 2 THEN tpi.usable_qty
-        ELSE NULL
-        END ASC,
-        CASE
-        WHEN #{sort} != 2 THEN tpi.usable_qty
-        ELSE NULL
-        END DESC
+        order by  tmgs.op_create_time desc
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
             limit #{end} offset #{start}
         </if>

+ 2 - 0
src/main/java/com/dk/mdm/mapper/mst/SupplierMapper.java

@@ -35,6 +35,8 @@ public interface SupplierMapper extends BaseMapper<Supplier>{
         * @date   : 2024/2/29 17:49
         */
     int insertSupplierBrand(Supplier supplierVo);
+
+
     /**
      * @desc   : 保存供应商品牌
      * @author : 王英杰

+ 1 - 0
src/main/java/com/dk/mdm/model/pojo/mst/Supplier.java

@@ -17,6 +17,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import com.alibaba.fastjson.JSONObject;
 
+import java.math.BigDecimal;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;

+ 6 - 1
src/main/java/com/dk/mdm/model/response/mst/SpplierResponse.java

@@ -50,7 +50,12 @@ public class SpplierResponse extends PageInfo<SpplierResponse> implements Serial
     @TableField(typeHandler = UuidTypeHandler.class)
     private String supId;
 
-
+    /**
+     * 合计应付
+     */
+    @Excel(name = "合计应付")
+    @ApiModelProperty(value = "合计应付")
+    private BigDecimal sumAmtPayable;
     /**
      * 供应商编号
      */

+ 3 - 0
src/main/java/com/dk/mdm/model/vo/ivt/InboundItemVO.java

@@ -236,6 +236,9 @@ public class InboundItemVO  {
     @ApiModelProperty(value = "已入库金额编辑之前")
     private BigDecimal amtBeforeUpdate;
 
+    @ApiModelProperty(value = "新建编辑标识true:新建,false:编辑")
+    private Boolean addOrEditFlag;
+
 
     private static final long serialVersionUID = 1L;
 

+ 15 - 0
src/main/java/com/dk/mdm/model/vo/mst/SupplierVo.java

@@ -19,6 +19,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import com.alibaba.fastjson.JSONObject;
 
+import java.math.BigDecimal;
 import java.util.List;
 import java.time.LocalDateTime;
 
@@ -46,6 +47,13 @@ public class SupplierVo extends PageInfo<SupplierVo> implements Serializable {
     @ApiModelProperty(value = "供应商ID")
     @TableField(typeHandler = UuidTypeHandler.class)
     private String supId;
+    /**
+     * 制单员
+     */
+    @Excel(name = "制单员")
+    @ApiModelProperty(value = "制单员")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String makeStaff;
 
 
     /**
@@ -145,6 +153,13 @@ public class SupplierVo extends PageInfo<SupplierVo> implements Serializable {
     @ApiModelProperty(value = "商品品牌")
     private String brandId;
 
+    /**
+     * 初始金额
+     */
+    @Excel(name = "初始金额")
+    @ApiModelProperty(value = "初始金额")
+    private BigDecimal startAmount;
+
     @TableField(exist = false)
     @ApiModelProperty(value = "剩余应收付")
     private String sumResidue;

+ 13 - 0
src/main/java/com/dk/mdm/service/common/CommonService.java

@@ -673,7 +673,16 @@ public class CommonService extends BaseService<Map<String, Object>> {
     public ResponseResultVO<List<Map<String, Object>>> getGoodsCategoryNoPage(Map<String, Object> param) {
         List<Map<String, Object>> list = commonMapper.getGoodsCategory(param);
         return ResponseResultUtil.success(list);
+    }    /**
+     * @desc :  商品种类查询  树形
+     * @author : 王英杰
+     * @date : 2024/2/26 10:36
+     */
+    public ResponseResultVO<List<Map<String, Object>>> getGoodsCategoryTree(Map<String, Object> param) {
+        List<Map<String, Object>> list = commonMapper.getGoodsCategoryTree(param);
+        return ResponseResultUtil.success(list);
     }
+
     /**
      * @desc : 获取页面数据源集合 (小程序用)
      * @author : 于继渤
@@ -713,6 +722,10 @@ public class CommonService extends BaseService<Map<String, Object>> {
         if (dataSourceCode.equals("org")) {
             list = commonMapper.getOrg(map);
         }
+        //品牌
+        if (dataSourceCode.equals("brand")) {
+            list = commonMapper.getGoodsBrand(map);
+        }
         //员工
         if (dataSourceCode.equals("staff")) {
             list = commonMapper.getStaff(map);

+ 172 - 112
src/main/java/com/dk/mdm/service/ivt/inbound/InboundCheckService.java

@@ -3,6 +3,7 @@ package com.dk.mdm.service.ivt.inbound;
 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.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
@@ -16,6 +17,9 @@ 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.query.ivt.InboundItemQuery;
+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.service.common.CommonService;
@@ -28,132 +32,188 @@ 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;
 
 
 /**
- * @desc   : 盘盈入库业务层
- * @date   : 2024/3/7 14:11
  * @author : 寇珊珊
+ * @desc : 盘盈入库业务层
+ * @date : 2024/3/7 14:11
  */
 @Service
 public class InboundCheckService extends BaseService<Inbound> {
 
-	@Override
-	public BaseMapper<Inbound> getRepository() {
-		return inboundMapper;
-	}
-
-	@Autowired
-	private InboundMapper inboundMapper;
-
-	@Autowired
-	private InboundConvert inboundConvert;
-
-	@Autowired
-	private InboundItemMapper inboundItemMapper;
-
-	@Autowired
-	private InboundItemConvert inboundItemConvert;
-
-
-	@Autowired
-	private CommonService commonService;
-
-	@Autowired
-	private InventoryService inventoryService;
-
-
-	/**
-	 * @desc : 盘盈入库新建
-	 * @date : 2024/3/7 14:13
-	 * 入库中数量/金额  已入库数量/金额  由调用方传入
-	 * @author : 寇珊珊
-	 */
-	@Transactional(rollbackFor = {Exception.class})
-	public InboundVO checkInboundInsert(Map<String, Object> map) {
-
-		//region map转json
-		JSONObject total = new JSONObject();
-		JSONArray detail = new JSONArray();
-		//总单
-		if (map.get("total") != null) {
-			total = (JSONObject) JSON.toJSON(map.get("total"));
-		}
-		//明细
-		if (map.get("total") != null) {
-			detail = (JSONArray) JSON.toJSON(map.get("detail"));
-		}
-		InboundVO inboundVO = new InboundVO();
-		inboundVO = total.toJavaObject(InboundVO.class);
-		List<InboundItemVO> inboundItemVOList = detail.toJavaList(InboundItemVO.class);
-		inboundVO.setItemList(inboundItemVOList);
-		//endregion
-
-		//region  总单
-		//获取 id/单号
-		Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYPROFITINBOUND.getName(), false);
-		inboundVO.setIntoId(codeMap.get("outId").toString()).
-				setIntoNo(codeMap.get("outNote").toString());
-		//todo  入库类型可能是盘盈可能是库位移动 调用的时候传
+    @Override
+    public BaseMapper<Inbound> getRepository() {
+        return inboundMapper;
+    }
+
+    @Autowired
+    private InboundMapper inboundMapper;
+
+    @Autowired
+    private InboundConvert inboundConvert;
+
+    @Autowired
+    private InboundItemMapper inboundItemMapper;
+
+    @Autowired
+    private InboundItemConvert inboundItemConvert;
+
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private InventoryService inventoryService;
+
+
+    /**
+     * @desc : 盘盈入库新建、库存调整-入库
+     * @date : 2024/3/7 14:13
+     * 入库中数量/金额  已入库数量/金额  由调用方传入
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public InboundVO checkInboundInsert(Map<String, Object> map) {
+
+        //region map转json
+        JSONObject total = new JSONObject();
+        JSONArray detail = new JSONArray();
+        //总单
+        if (map.get("total") != null) {
+            total = (JSONObject) JSON.toJSON(map.get("total"));
+        }
+        //明细
+        if (map.get("total") != null) {
+            detail = (JSONArray) JSON.toJSON(map.get("detail"));
+        }
+        InboundVO inboundVO = new InboundVO();
+        inboundVO = total.toJavaObject(InboundVO.class);
+        List<InboundItemVO> inboundItemVOList = detail.toJavaList(InboundItemVO.class);
+        inboundVO.setItemList(inboundItemVOList);
+        //endregion
+
+        //region  总单
+        //获取 id/单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.INVENTORYPROFITINBOUND.getName(), false);
+        inboundVO.setIntoId(codeMap.get("outId").toString()).
+                setIntoNo(codeMap.get("outNote").toString());
+        //todo  入库类型可能是盘盈可能是库位移动 调用的时候传
 //		//入库类型
 //		inboundVO.setIntoType(Constant.IntoType.PROFIT.getName());
-		//已入库
-		inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
-		//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
-		inboundVO.setIntoQty(inboundVO.getIntoingQty())
-				.setIntoAmt(inboundVO.getIntoingAmt())
-				.setIntoingQty(BigDecimal.ZERO)
-				.setIntoingAmt(BigDecimal.ZERO)
-		;
-		//实体转换
-		Inbound inbound = inboundConvert.convertToPo(inboundVO);
-		inboundMapper.insert(inbound);
-		//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()) {
-			//region 将库存需要的参数赋值
-			inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
-			inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_PROFIT.getValue());
-			//endregion
-
-
-			//总单id
-			inboundItemVO.setIntoId(inboundVO.getIntoId());
-			//入库类型
-			inboundItemVO.setIntoType(inboundVO.getIntoType());
-			//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
-			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))
-			;
-			//入库状态
-			inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
-			//实体转换
-			InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-			inboundItemMapper.insert(inboundItem);
-			//endregion
-
-		}
-		//endregion
-
-		//region 修改库存
+        //已入库
+        inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
+        //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
+        inboundVO.setIntoQty(inboundVO.getIntoingQty())
+                .setIntoAmt(inboundVO.getIntoingAmt())
+                .setIntoingQty(BigDecimal.ZERO)
+                .setIntoingAmt(BigDecimal.ZERO)
+        ;
+        //实体转换
+        Inbound inbound = inboundConvert.convertToPo(inboundVO);
+        inboundMapper.insert(inbound);
+        //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()) {
+            //region 将库存需要的参数赋值
+            inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
+            inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.INVENTORY_PROFIT.getValue());
+            //endregion
+
+
+            //总单id
+            inboundItemVO.setIntoId(inboundVO.getIntoId());
+            //入库类型
+            inboundItemVO.setIntoType(inboundVO.getIntoType());
+            //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
+            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))
+            ;
+            //入库状态
+            inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
+            //实体转换
+            InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+            inboundItemMapper.insert(inboundItem);
+            //endregion
+
+        }
+        //endregion
+
+        //region 修改库存
 //		Map<String, Object> invMap = new HashMap<>();
 //		invMap.put("intoDetail", inboundVO.getItemList());
 //		inventoryService.operatingInventoryInformation(invMap);
-		//endregion
+        //endregion
+
+        return inboundVO;
+    }
+
+    /**
+     * @desc : 作废
+     * @date : 2024/4/16 13:27
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> inboundRepeal(String fromId) {
+        //region  查询总单  查询明细
+        //根据来源id查询 此条入库单的数据还未更改前的数据
+        InboundResponse inboundResponse = inboundMapper.selectByFromId(fromId);
+        //根据总单id查询
+        List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
+        //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
+
+            //赋值
+            InboundItem inboundItem = new InboundItem();
+            inboundItem.setItemId(inboundItemResponse.getItemId());
+            inboundItem.setFlgValid(false);
+            //修改
+            inboundItemMapper.update(inboundItem,
+                    new UpdateWrapper<InboundItem>().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<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+        );
+        //endregion
+
+        //region 库存
+        Map<String, Object> map = new HashMap<>();
+        map.put("intoDetail", inboundItemResponseList);
+        inventoryService.operatingInventoryInformation(map);
+        //endregion
+
+        return ResponseResultUtil.success();
+    }
 
-		return inboundVO;
-	}
 
 }

+ 22 - 10
src/main/java/com/dk/mdm/service/ivt/inbound/InboundOtherService.java

@@ -172,6 +172,7 @@ public class InboundOtherService extends BaseService<Inbound> {
             //region 将库存需要的参数赋值
             inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
             inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
+            inboundItemVO.setAddOrEditFlag(true);
             //endregion
 
             //总单id
@@ -204,7 +205,6 @@ public class InboundOtherService extends BaseService<Inbound> {
         //endregion
 
 
-        //todo 如果是已入库 调用库存  后续写库存这里补上
         //region 库存
         if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
             Map<String, Object> invMap = new HashMap<>();
@@ -264,14 +264,14 @@ public class InboundOtherService extends BaseService<Inbound> {
                     InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
                     //region 将库存需要的参数赋值
                     inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
-                    inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
+                    inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
                     //编辑之前的数
                     inboundItemVO.setQtyBeforeUpdate(inboundItemResponse.getIntoQty());
                     inboundItemVO.setAmtBeforeUpdate(inboundItemResponse.getIntoAmt());
                     //编辑之后的数
                     inboundItemVO.setIntoQty(inboundItemVO.getIntoQty());
                     inboundItemVO.setIntoAmt(inboundItemVO.getIntoAmt());
-
+                    inboundItemVO.setAddOrEditFlag(true);
                     //endregion
 
                     //region 编辑明细赋值
@@ -315,6 +315,10 @@ public class InboundOtherService extends BaseService<Inbound> {
                 //region 删除明细
                 if (inboundVO.getDeleteItemList() != null) {
                     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);
@@ -342,6 +346,7 @@ public class InboundOtherService extends BaseService<Inbound> {
                 //region  todo调用库存
                 Map<String, Object> map = new HashMap<>();
                 map.put("intoDetail", inboundVO.getItemList());
+                map.put("delIntoDetail", inboundVO.getDeleteItemList());
                 inventoryService.operatingInventoryInformation(map);
                 //endregion
             }
@@ -448,7 +453,7 @@ public class InboundOtherService extends BaseService<Inbound> {
             for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
                 //region 将库存需要的参数赋值
                 inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
-                inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.PURCHASE_ORDER.getValue());
+                inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
                 inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
                 inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
                 //endregion
@@ -475,9 +480,9 @@ public class InboundOtherService extends BaseService<Inbound> {
             );
             //endregion
 
-            //region
+            //region 库存
             Map<String, Object> map = new HashMap<>();
-            map.put("intoDetail", inboundItemResponseList);
+            map.put("delIntoDetail", inboundItemResponseList);
             inventoryService.operatingInventoryInformation(map);
             //endregion
         }
@@ -535,7 +540,9 @@ public class InboundOtherService extends BaseService<Inbound> {
             //region 将库存需要的参数赋值
             inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
             inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
+            inboundItemVO.setAddOrEditFlag(true);
             //endregion
+
             //region  修改明细
             if (inboundItemVO.getIntoId() != null) {
                 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
@@ -596,6 +603,10 @@ public class InboundOtherService extends BaseService<Inbound> {
         //region 删除明细
         if (inboundVO.getDeleteItemList() != null) {
             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);
@@ -629,9 +640,10 @@ public class InboundOtherService extends BaseService<Inbound> {
         //endregion
 
         //region 修改库存
-//        Map<String, Object> map = new HashMap<>();
-//        map.put("intoDetail", inboundVO.getItemList());
-//        inventoryService.operatingInventoryInformation(map);
+        Map<String, Object> map = new HashMap<>();
+        map.put("intoDetail", inboundVO.getItemList());
+        map.put("delIntoDetail", inboundVO.getDeleteItemList());
+        inventoryService.operatingInventoryInformation(map);
         //endregion
         return ResponseResultUtil.success(inboundVO);
     }
@@ -694,7 +706,7 @@ public class InboundOtherService extends BaseService<Inbound> {
 
         //region 修改库存
         Map<String, Object> map = new HashMap<>();
-        map.put("intoDetail", inboundItemResponseList);
+        map.put("delIntoDetail", inboundItemResponseList);
         inventoryService.operatingInventoryInformation(map);
         //endregion
 

+ 486 - 137
src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java

@@ -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

+ 62 - 0
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundCheckService.java

@@ -3,6 +3,7 @@ package com.dk.mdm.service.ivt.outbound;
 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.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
@@ -16,6 +17,9 @@ import com.dk.mdm.mapper.ivt.OutboundItemMapper;
 import com.dk.mdm.mapper.ivt.OutboundMapper;
 import com.dk.mdm.model.pojo.ivt.Outbound;
 import com.dk.mdm.model.pojo.ivt.OutboundItem;
+import com.dk.mdm.model.query.ivt.OutboundItemQuery;
+import com.dk.mdm.model.response.ivt.OutboundItemResponse;
+import com.dk.mdm.model.response.ivt.OutboundResponse;
 import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.model.vo.ivt.OutboundVO;
 import com.dk.mdm.service.common.CommonService;
@@ -25,8 +29,10 @@ 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;
 
 
 /**
@@ -156,4 +162,60 @@ public class OutboundCheckService extends BaseService<Outbound> {
         return outboundVO;
     }
 
+    /**
+     * @desc : 作废
+     * @date : 2024/4/16 13:32
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> outboundRepeal(String fromId) {
+        //region  查询总单  查询明细
+        //根据来源id查询 此条出库单的数据还未更改前的数据
+        OutboundResponse outboundResponse = outboundMapper.selectByFromId(fromId);
+        //根据总单id查询
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
+        //endregion
+
+        //region 修改明细
+        for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
+            //region 将库存需要的参数赋值
+            outboundItemResponse.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
+            outboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
+            outboundItemResponse.setOutQty(outboundItemResponse.getOutQty().negate());
+            outboundItemResponse.setOutAmt(outboundItemResponse.getOutAmt().negate());
+            //endregion
+
+            //赋值
+            OutboundItem outboundItem = new OutboundItem();
+            outboundItem.setItemId(outboundItemResponse.getItemId());
+            outboundItem.setFlgValid(false);
+            //修改
+            outboundItemMapper.update(outboundItem,
+                    new UpdateWrapper<OutboundItem>().lambda()
+                            .eq(OutboundItem::getItemId, UUID.fromString(outboundItem.getItemId()))
+            );
+        }
+        //endregion
+
+        //region  修改出库总单
+        Outbound outbound = new Outbound();
+        outbound.setOutId(outboundResponse.getOutId());
+        outbound.setFlgValid(false);
+        //修改
+        outboundMapper.update(outbound,
+                new UpdateWrapper<Outbound>().lambda().eq(Outbound::getOutId, UUID.fromString(outbound.getOutId()))
+        );
+        //endregion
+
+        //region  修改库存
+        Map<String, Object> map = new HashMap<>();
+        map.put("outDetail", outboundItemResponseList);
+        inventoryService.operatingInventoryInformation(map);
+        //endregion
+
+
+        return ResponseResultUtil.success();
+    }
+
+
 }

+ 3 - 3
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java

@@ -1091,7 +1091,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             order.setOutQty(outboundResponse.getOutQty().negate());
             order.setOutAmt(outboundResponse.getOutAmt().negate());
             //根据id查询
-            OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
+            OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
             //出库状态
             String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
                     orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
@@ -1108,7 +1108,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
         //region 修改总单数据信息
         Outbound outbound = new Outbound();
-        outbound.setOutId(outboundVO.getOutId());
+        outbound.setOutId(outboundResponse.getOutId());
         outbound.setOutDate(null);
         outbound.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
         outbound.setOutQty(BigDecimal.ZERO);
@@ -1124,7 +1124,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
         //region 明细数据
         //根据总单id查明细
-        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundVO.getOutId()));
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
         for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
             //region 修改销售退货明细数据信息
             if (outboundItemResponse.getFromItemId() != null) {

+ 1 - 1
src/main/java/com/dk/mdm/service/mac/AccountService.java

@@ -557,7 +557,7 @@ public class AccountService extends BaseService<Account> {
 
     /**
      * @desc : 获取应收,收款汇总(制单员权限)
-     * @author : 
+     * @author : 
      * @date : 2024-04-03 16:32
      */
     public ResponseResultVO<?> getReceivableAccountSum(AccountItemQuery accountItemQuery){

+ 11 - 11
src/main/java/com/dk/mdm/service/mac/OtherPayableService.java

@@ -111,17 +111,6 @@ public class OtherPayableService extends BaseService<OtherPayable> {
     private OtherPayableItemConvert otherPayableItemConvert;
 
     /**
-     * @desc : 条件查询
-     * @author : 付斌
-     * @date : 2023/1/9 10:40
-     */
-    @Pagination
-    public ResponseResultVO<PageList<OtherPayableResponse>> selectByCond(OtherPayableQuery otherPayableQuery) {
-        return super.mergeListWithCount(otherPayableQuery, otherPayableMapper.selectByCond(otherPayableQuery),
-                otherPayableMapper.countByCond(otherPayableQuery));
-    }
-
-    /**
      * @desc : 查询明细(货物、付款、附件)
      * @author : 付斌
      * @date : 2024-02-28 13:25
@@ -138,6 +127,17 @@ public class OtherPayableService extends BaseService<OtherPayable> {
     }
 
     /**
+     * @desc : 条件查询
+     * @author : 付斌
+     * @date : 2023/1/9 10:40
+     */
+    @Pagination
+    public ResponseResultVO<PageList<OtherPayableResponse>> selectByCond(OtherPayableQuery otherPayableQuery) {
+        return super.mergeListWithCount(otherPayableQuery, otherPayableMapper.selectByCond(otherPayableQuery),
+                otherPayableMapper.countByCond(otherPayableQuery));
+    }
+
+    /**
      * @desc : 新建方法
      * @author : 付斌
      * @date : 2023/1/9 10:49

+ 49 - 6
src/main/java/com/dk/mdm/service/mst/SupplierService.java

@@ -6,18 +6,30 @@ import com.dk.common.model.pojo.PageList;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.mst.SupplierConvert;
+import com.dk.mdm.mapper.mac.OtherPayableMapper;
 import com.dk.mdm.model.pojo.mst.Supplier;
 import com.dk.mdm.mapper.mst.SupplierMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.query.mac.MacTransferItemQuery;
+import com.dk.mdm.model.query.mac.OtherPayableQuery;
 import com.dk.mdm.model.query.mst.SupplierQuery;
+import com.dk.mdm.model.response.mac.MacTransferItemResponse;
+import com.dk.mdm.model.response.mac.MacTransferResponse;
+import com.dk.mdm.model.response.mac.OtherPayableResponse;
+import com.dk.mdm.model.response.mst.SpplierResponse;
+import com.dk.mdm.model.vo.mac.OtherPayableItemVO;
+import com.dk.mdm.model.vo.mac.OtherPayableVO;
 import com.dk.mdm.model.vo.mst.SupplierVo;
 import com.dk.mdm.service.common.CommonService;
+import com.dk.mdm.service.mac.OtherPayableService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
+import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -46,6 +58,11 @@ public class SupplierService extends BaseService<Supplier> {
     private SupplierConvert supplierConvert;
     @Autowired
     private CommonService commonService;
+
+    @Autowired
+    private OtherPayableService otherPayableService;
+    @Autowired
+    private OtherPayableMapper otherPayableMapper;
     /**
      * @desc : 条件查询
      * @author : 王英杰
@@ -53,7 +70,22 @@ public class SupplierService extends BaseService<Supplier> {
      */
     @Pagination
     public ResponseResultVO<PageList<Supplier>> selectByCond(SupplierQuery supplierQuery) {
-        return super.mergeListWithCount(supplierQuery, supplierMapper.selectByCond(supplierQuery),
+        List<SpplierResponse> list = new ArrayList<>();
+        list = supplierMapper.selectByCond(supplierQuery);
+
+
+
+        for(int i =0;i<list.size();i++){ //显示明细第一条的 内容
+            list.get(i).getSupId();
+            // 转账明细
+            List<OtherPayableResponse> itemList = otherPayableMapper.selectByCond(new OtherPayableQuery().setObjectId(list.get(i).getSupId()).setBusinessType(0));
+            if(itemList.size()>0){
+                list.get(i).setSumAmtPayable(itemList.get(0).getSumAmtPayable());
+            }
+        }
+
+
+        return super.mergeListWithCount(supplierQuery,list ,
                 supplierMapper.countByCond(supplierQuery));
     }
     /**
@@ -74,7 +106,7 @@ public class SupplierService extends BaseService<Supplier> {
         // 转化实体
         Supplier supplier = supplierConvert.convertToPo(supplierVo);
 
-        try {
+
             Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SUPPLIER.getName(), true);
 
             supplier.setSupId(codeMap.get("outId").toString());
@@ -94,12 +126,23 @@ public class SupplierService extends BaseService<Supplier> {
                  }
                 supplierMapper.insertSupplierBrandtBatch(Supplierlst); // 向供应商品牌表插入数据
             }
+
+             if(supplierVo.getStartAmount()!=null && supplierVo.getStartAmount().compareTo(BigDecimal.ZERO) > 0) { //说明有起始欠款  需要插入其他支出
+                 //先组装明细
+                 List<OtherPayableItemVO> itemList = new ArrayList<>();
+                 OtherPayableItemVO otherPayableItemVO = new OtherPayableItemVO();
+                 otherPayableItemVO.setPayableType("10112024-0415-0000-0000-0000300dd508");
+                 otherPayableItemVO.setAmtPayable(supplierVo.getStartAmount());
+                 itemList.add(otherPayableItemVO);
+                 //调用 新建其他支出
+                 OtherPayableVO otherPayableVO = new OtherPayableVO().setBusinessType(0).setObjectId(supplier.getSupId())
+                         .setSumAmtPayable(supplierVo .getStartAmount()).setStaffId(supplier.getStaffId())
+                         .setOrgId(supplier.getOrgId()).setAccDate(LocalDate.now()).setMakeStaff(supplierVo
+                                 .getMakeStaff()).setItemList(itemList).setSumAmtPay(BigDecimal.ZERO);
+                 otherPayableService.insert(otherPayableVO);
+             }
             return ResponseResultUtil.success();
-        } catch (Exception e) {
-            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 手动回滚事务
 
-            return ResponseResultUtil.error("保存失败");
-        }
 
     }
     /**