koushanshan 2 лет назад
Родитель
Сommit
c0335f82f9

+ 24 - 0
src/main/java/com/dk/mdm/controller/ivt/inbound/InboundOtherController.java

@@ -115,4 +115,28 @@ public class InboundOtherController {
         return inboundService.selectByUpdate(id);
     }
 
+
+
+    /**
+     * @desc   : 条件查询 --- web端入库办理用
+     * @date   : 2024/3/7 14:09
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "条件查询", notes = "条件查询")
+    @PostMapping({"select_inbound"})
+    public ResponseResultVO<PageList<InboundResponse>> selectInbound(@Valid @RequestBody InboundQuery inboundQuery) {
+        return inboundOtherService.selectInbound(inboundQuery);
+    }
+
+    /**
+     * @desc   : 条件查询 --- web端入库办理用
+     * @date   : 2024/3/7 14:09
+     * @author : 寇珊珊
+     */
+    @ApiOperation(value = "明细信息条件查询web端入库办理用", notes = "明细信息条件查询web端入库办理用")
+    @PostMapping({"select_inbound_item/{id}"})
+    public ResponseResultVO<Map<String, Object>> selectInboundItem(@PathVariable String id) {
+        return inboundOtherService.selectInboundItem(id);
+    }
+
 }

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

@@ -47,6 +47,15 @@ public interface InboundItemMapper extends BaseMapper<InboundItem>{
     int  updateAmount(InboundItem inboundItem);
 
 
+    /**
+     * @desc   : 条件查询 --- web端入库办理用
+     * @date   : 2024/3/23 9:24
+     * @author : 寇珊珊
+     */
+    List<InboundItemResponse> selectInboundItem(InboundItemQuery inboundItemQuery);
+
+
+
 
 }
 

+ 98 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.xml

@@ -266,4 +266,102 @@
     </update>
 
 
+    <!-- 入库办理显示字段 -->
+    <sql id="Base_Column_List_Response_Into">
+        tpii.item_id,
+        tpii.into_id,
+        tpii.into_type,
+        tpii.from_id,
+        tpii.from_item_id,
+        tpii.item_index,
+        tpii.sku_id,
+        tpii.price_into,
+        tpii.non_std_code,
+        tpii.into_status,
+        tpii.intoing_qty,
+        tpii.intoing_amt,
+        tpii.into_qty,
+        tpii.into_amt,
+        tpii.return_qty,
+        tpii.return_amt,
+        tpii.remarks,
+        tpii.inv_id,
+        tpii.cost_price,
+        tpii.cost_amt,
+        tpii.wh_id,
+        tpii.inv_qty
+    </sql>
+    <sql id="Base_Column_List_Response_Out">
+        tpoi.item_id,
+        tpoi.out_id as into_id,
+        tpoi.out_type as into_type,
+        tpoi.from_id,
+        tpoi.from_item_id,
+        tpoi.item_index,
+        tpoi.sku_id,
+        tpoi.price_out as price_into,
+        tpoi.non_std_code,
+        tpoi.out_status as into_status,
+        tpoi.outing_qty as intoing_amt ,
+        tpoi.outing_amt as intoing_qty ,
+        tpoi.out_qty as into_qty ,
+        tpoi.out_amt as into_amt ,
+        tpoi.return_qty,
+        tpoi.return_amt,
+        tpoi.remarks,
+        tpoi.inv_id,
+        tpoi.cost_price,
+        tpoi.cost_amt,
+        null as  wh_id,
+        null  as inv_qty
+    </sql>
+    <!--条件查询 web端入库办理用-->
+    <select id="selectInboundItem" resultMap="BaseResultMapResponse">
+        SELECT
+        <include refid="Base_Column_List_Response_Into"/>
+        ,tmgs.sku_code  as "skuCode"
+        ,tmgs.sku_model as "skuModel"
+        ,tmgs.sku_name  as "skuName"
+        ,tmgs.sku_spec  as "skuSpec"
+        ,tmgb.brand_name  as "brandName"
+        ,tmgb.short_name  as "shortName"
+        ,tmw.wh_name as "whName"
+        FROM dkic_b.t_psi_inbound_item tpii
+        <include refid="Select_Inbound_Join_Table_Into"/>
+        <where>
+            <if test="intoId != null and intoId != ''">
+                AND tpii.into_id = #{intoId}::uuid
+            </if>
+        </where>
+        union all
+        select
+        <include refid="Base_Column_List_Response_Out"/>
+        ,tmgs.sku_code  as "skuCode"
+        ,tmgs.sku_model as "skuModel"
+        ,tmgs.sku_name  as "skuName"
+        ,tmgs.sku_spec  as "skuSpec"
+        ,tmgb.brand_name  as "brandName"
+        ,tmgb.short_name  as "shortName"
+        ,null as "whName"
+        from dkic_b.t_psi_outbound_item tpoi
+        <include refid="Select_Inbound_Join_Table_Out"/>
+        <where>
+            <if test="intoId != null and intoId != ''">
+                AND tpoi.out_id = #{intoId}::uuid
+            </if>
+        </where>
+    </select>
+    <!--入库办理显示入库关联表-->
+    <sql id="Select_Inbound_Join_Table_Into">
+        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpii.sku_id
+        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
+        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpii.inv_id
+        left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpii.wh_id
+    </sql>
+    <sql id="Select_Inbound_Join_Table_Out">
+        left join dkic_b.t_mst_goods_sku tmgs on tmgs.sku_id = tpoi.sku_id
+        left join dkic_b.t_mst_goods_brand tmgb on tmgb.brand_id = tmgs.brand_id
+        left join dkic_b.t_psi_inventory tpi on tpi.inv_id = tpoi.inv_id
+    </sql>
+
 </mapper>

+ 16 - 1
src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.java

@@ -65,11 +65,26 @@ public interface InboundMapper extends BaseMapper<Inbound>{
 
 
     /**
-     * @desc   : 根据传入的信息查询数据(销售退货入库办理用)
+     * @desc   : 根据传入的信息查询数据(采购退货入库办理用)
      * @date   : 2024/3/16 16:28
      * @author : 寇珊珊
      */
     InboundResponse selectMessageByOtherQuery(InboundQuery inboundQuery);
 
+
+    /**
+     * @desc   : 条件查询 --- web端入库办理用
+     * @date   : 2024/3/23 9:24
+     * @author : 寇珊珊
+     */
+    List<InboundResponse> selectInbound(InboundQuery inboundQuery);
+
+    /**
+     * @desc   : 条件查询 --- web端入库办理用查个数
+     * @date   : 2024/3/23 9:24
+     * @author : 寇珊珊
+     */
+    Long selectInboundCond(InboundQuery inboundQuery);
+
 }
 

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

@@ -548,7 +548,7 @@
     </update>
 
 
-    <!-- 根据id查询带出销售退货单数据(销售退货入库办理用)-->
+    <!-- 根据id查询带出销售退货单数据(采购退货入库办理用)-->
     <select id="selectMessageByOtherQuery" resultMap="BaseResultMapResponse">
         SELECT
         <include refid="Base_Column_List_Response"/>
@@ -585,4 +585,220 @@
     </select>
 
 
+
+    <!-- 入库办理显示字段 -->
+    <sql id="Base_Column_List_Response_Into">
+        tpi.into_id,
+        tpi.into_no,
+        tpi.into_type,
+        tpi.from_id,
+        tpi.from_no,
+        tpi.org_id,
+        tpi.staff_id,
+        tpi.cus_id,
+        tpi.sup_id,
+        tpi.into_status,
+        tpi.intoing_qty,
+        tpi.intoing_amt,
+        tpi.into_qty,
+        tpi.into_amt,
+        tpi.return_qty,
+        tpi.return_amt,
+        tpi.into_date,
+        tpi.remarks,
+        tpi.annex_paths,
+        tpi.make_staff,
+        tpi.make_time,
+        tpi.wh_id,
+        tpi.into_reason
+    </sql>
+    <sql id="Base_Column_List_Response_Out">
+        tpo.out_id  as into_id,
+        tpo.out_no  as into_no,
+        tpo.out_type as into_type,
+        tpo.from_id,
+        tpo.from_no,
+        tpo.org_id,
+        tpo.staff_id,
+        tpo.cus_id,
+        tpo.sup_id,
+        tpo.out_status,
+        tpo.outing_qty as intoing_qty,
+        tpo.outing_amt as intoing_amt,
+        tpo.out_qty as into_qty,
+        tpo.out_amt as into_amt,
+        tpo.return_qty,
+        tpo.return_amt,
+        tpo.out_date as into_date,
+        tpo.remarks,
+        tpo.annex_paths,
+        tpo.make_staff,
+        tpo.make_time,
+        null as wh_id,
+        tpo.out_reason as into_reason
+    </sql>
+    <!-- 条件查询 web端入库办理用,-->
+    <select id="selectInbound" resultMap="BaseResultMapResponse">
+        SELECT
+        <include refid="Base_Column_List_Response_Into"/>,
+        tmo.org_name AS "orgName",
+        tmp.sup_name AS "supplierName",
+        tms.staff_name AS "staffName",
+        tms.staff_name AS "makeStaffName",
+        tmw.wh_name as "whName",
+        tmc.cus_name                                      as "cusName",
+        tmc.cus_phone                                     as "cusPhone",
+        tmc.cus_from                                      as "cusFrom",
+        makestaff.staff_name                              as "makeStaffName",
+        sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
+        sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",
+        tmd.data_value                                   as into_reason_name
+        FROM dkic_b.t_psi_inbound tpi
+        <include refid="Select_Inbound_Join_Table_Into"/>
+        <where>
+            <if test="intoTypes != null and intoTypes.size()>0">
+                AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="intoTypes == null || intoTypes.size()==0">
+                AND (tpi.into_type = '入库类型-其他入库'
+                or tpi.into_type =  '入库类型-采购入库')
+            </if>
+            <if test=" intoStatus != null and intoStatus != '' ">
+                AND  tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
+            </if>
+            <if test="intoDateStart != null and intoDateEnd != null">
+                AND tpi.make_time &gt;= #{intoDateStart}::timestamp with time zone
+                AND tpi.make_time &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
+            </if>
+        </where>
+        union all
+        select
+          <include refid="Base_Column_List_Response_Out"/>,
+        tmo.org_name AS "orgName",
+        tmp.sup_name AS "supplierName",
+        tms.staff_name AS "staffName",
+        tms.staff_name AS "makeStaffName",
+        null as "whName",
+        tmc.cus_name                                      as "cusName",
+        tmc.cus_phone                                     as "cusPhone",
+        tmc.cus_from                                      as "cusFrom",
+        makestaff.staff_name                              as "makeStaffName",
+        sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
+        sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",
+        tmd.data_value                                   as into_reason_name
+        from dkic_b.t_psi_outbound tpo
+        <include refid="Select_Inbound_Join_Table_Out"/>
+        <where>
+            <if test="intoTypes != null and intoTypes.size()>0">
+                AND tpo.out_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="intoTypes == null || intoTypes.size()==0">
+                AND tpo.out_type = '出库类型-销退出库'
+            </if>
+            <if test="outStatus != null and outStatus != '' ">
+                AND  tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
+            </if>
+            <if test="intoDateStart != null and intoDateEnd != null">
+                AND tpo.make_time &gt;= #{intoDateStart}::timestamp with time zone
+                AND tpo.make_time &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
+            </if>
+        </where>
+        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            limit #{end} offset #{start}
+        </if>
+    </select>
+    <!--  条件查询 web端入库办理用个数 -->
+    <select id="selectInboundCond" resultType="Long">
+        SELECT
+        count(1) from (
+        SELECT
+        <include refid="Base_Column_List_Response_Into"/>,
+        tmo.org_name AS "orgName",
+        tmp.sup_name AS "supplierName",
+        tms.staff_name AS "staffName",
+        tms.staff_name AS "makeStaffName",
+        tmw.wh_name as "whName",
+        tmc.cus_name                                      as "cusName",
+        tmc.cus_phone                                     as "cusPhone",
+        tmc.cus_from                                      as "cusFrom",
+        makestaff.staff_name                              as "makeStaffName",
+        sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
+        sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",
+        tmd.data_value                                   as into_reason_name
+        FROM dkic_b.t_psi_inbound tpi
+        <include refid="Select_Inbound_Join_Table_Into"/>
+        <where>
+            <if test="intoTypes != null and intoTypes.size()>0">
+                AND tpi.into_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="intoTypes == null || intoTypes.size()==0">
+                AND (tpi.into_type = '入库类型-其他入库'
+                or tpi.into_type =  '入库类型-采购入库')
+            </if>
+            <if test="intoStatus != null and intoStatus != '' ">
+                AND tpi.into_status LIKE concat('%',my_ex.likequery(#{intoStatus}),'%')
+            </if>
+            <if test="intoDateStart != null and intoDateEnd != null">
+                AND tpi.make_time &gt;= #{intoDateStart}::timestamp with time zone
+                AND tpi.make_time &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
+            </if>
+        </where>
+        union all
+        select
+        <include refid="Base_Column_List_Response_Out"/>,
+        tmo.org_name AS "orgName",
+        tmp.sup_name AS "supplierName",
+        tms.staff_name AS "staffName",
+        tms.staff_name AS "makeStaffName",
+        null as "whName",
+        tmc.cus_name                                      as "cusName",
+        tmc.cus_phone                                     as "cusPhone",
+        tmc.cus_from                                      as "cusFrom",
+        makestaff.staff_name                              as "makeStaffName",
+        sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
+        sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",
+        tmd.data_value                                   as into_reason_name
+        from dkic_b.t_psi_outbound tpo
+        <include refid="Select_Inbound_Join_Table_Out"/>
+        <where>
+            <if test="intoTypes != null and intoTypes.size()>0">
+                AND tpo.out_type =any(#{intoTypes,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="intoTypes == null || intoTypes.size()==0">
+                AND tpo.out_type = '出库类型-销退出库'
+            </if>
+            <if test="outStatus != null and outStatus != '' ">
+                AND  tpo.out_status LIKE concat('%',my_ex.likequery(#{outStatus}),'%')
+            </if>
+            <if test="intoDateStart != null and intoDateEnd != null">
+                AND tpo.make_time &gt;= #{intoDateStart}::timestamp with time zone
+                AND tpo.make_time &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
+            </if>
+        </where>
+        ) tt
+    </select>
+    <!--入库办理显示入库关联表-->
+    <sql id="Select_Inbound_Join_Table_Into">
+        Left join dkic_b.t_mst_org tmo on tmo.org_id = tpi.org_id
+        Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpi.sup_id
+        Left join dkic_b.t_mst_staff tms on tms.staff_id = tpi.staff_id
+        Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpi.make_staff
+        LEFT JOIN sys.t_data_kind tdk   ON tdk.kind_code = tpi.into_status
+        LEFT JOIN sys.t_data_kind tdktype   ON tdktype.kind_code = tpi.into_type
+        Left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = tpi.wh_id
+        left join dkic_b.t_mst_customer tmc on tpi.cus_id = tmc.cus_id
+        left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpi.into_reason
+    </sql>
+    <!--入库办理显示出库关联表-->
+    <sql id="Select_Inbound_Join_Table_Out">
+        Left join dkic_b.t_mst_org tmo on tmo.org_id = tpo.org_id
+        Left join dkic_b.t_mst_supplier tmp on tmp.sup_id = tpo.sup_id
+        Left join dkic_b.t_mst_staff tms on tms.staff_id = tpo.staff_id
+        Left join dkic_b.t_mst_staff makestaff on makestaff.staff_id = tpo.make_staff
+        LEFT JOIN sys.t_data_kind tdk   ON tdk.kind_code = tpo.out_status
+        LEFT JOIN sys.t_data_kind tdktype   ON tdktype.kind_code = tpo.out_type
+        left join dkic_b.t_mst_customer tmc on tpo.cus_id = tmc.cus_id
+        left join dkic_b.t_mst_dictionary_data tmd on tmd.data_id = tpo.out_reason
+    </sql>
+
 </mapper>

+ 4 - 0
src/main/java/com/dk/mdm/model/query/ivt/InboundQuery.java

@@ -216,6 +216,10 @@ public class InboundQuery extends PageInfo<InboundQuery>{
     private String skuName;
 
 
+    @ApiModelProperty(value = "出库状态 (【系统字典】)")
+    private String outStatus;
+
+
 
 
     private static final long serialVersionUID = 1L;

+ 8 - 0
src/main/java/com/dk/mdm/model/response/ivt/InboundItemResponse.java

@@ -290,6 +290,14 @@ public class InboundItemResponse  {
     @ApiModelProperty(value = "仓库名称")
     private String whName;
 
+
+
+    @ApiModelProperty(value = "库存类型(入库,出库)")
+    private String inventoryType;
+
+    @ApiModelProperty(value = "库存业务类型(入库4种,出库4中)")
+    private String inventoryDocCode;
+
     private static final long serialVersionUID = 1L;
 
 }

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

@@ -208,6 +208,11 @@ public class InboundItemVO  {
      * @TableField(exist = false)
      */
 
+    @ApiModelProperty(value = "库存类型(入库,出库)")
+    private String inventoryType;
+
+    @ApiModelProperty(value = "库存业务类型(入库4种,出库4中)")
+    private String inventoryDocCode;
 
     private static final long serialVersionUID = 1L;
 

+ 106 - 32
src/main/java/com/dk/mdm/service/ivt/inbound/InboundOtherService.java

@@ -22,10 +22,15 @@ 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;
+import com.dk.mdm.service.ivt.inventory.InventoryService;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
+import javax.validation.Valid;
 import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.List;
@@ -61,6 +66,9 @@ public class InboundOtherService extends BaseService<Inbound> {
 	@Autowired
 	private CommonService commonService;
 
+	@Autowired
+	private InventoryService inventoryService;
+
 
 	/**
 	 * @desc   : 条件查询
@@ -137,6 +145,9 @@ public class InboundOtherService extends BaseService<Inbound> {
 					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
 		}
 		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+			//将库存需要的参数赋值
+			inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
+			inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
 			//总单id
 			inboundItemVO.setIntoId(inboundVO.getIntoId());
 			//入库类型
@@ -166,8 +177,11 @@ public class InboundOtherService extends BaseService<Inbound> {
 
 		//todo 如果是已入库 调用库存  后续写库存这里补上
 		//region 库存
-
-
+		if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
+			Map<String, Object> map = new HashMap<>();
+			map.put("intoDetail",inboundVO.getItemList());
+			inventoryService.updateInventoryInformation(map);
+		}
 		//endregion
 
 
@@ -190,14 +204,20 @@ public class InboundOtherService extends BaseService<Inbound> {
 					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
 		}
 		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+			//将库存需要的参数赋值
+			inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
+			inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
 			if (inboundItemVO.getIntoId() != null) {
 				InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
 				//编辑明细
 				inboundItemVO
 						.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
 						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
-						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
-						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
+						.setIntoingQty(BigDecimal.ZERO)
+						.setIntoingAmt(BigDecimal.ZERO)
+				//todo 2024年3月23日15:15:56  上午开会改了  改成 每次办理的时候  中数量清零
+//						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
+//						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
 				;
 				//入库状态
 				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
@@ -220,7 +240,11 @@ public class InboundOtherService extends BaseService<Inbound> {
 						.setIntoId(inboundVO.getIntoId())
 						.setCostPrice(inboundItemVO.getPriceInto())
 						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-						.setIntoType(Constant.IntoType.OTHER.getName());
+						.setIntoType(Constant.IntoType.OTHER.getName())
+				//todo 这里添加  入库中数量和金额  改成0
+						.setIntoingQty(BigDecimal.ZERO)
+						.setIntoingAmt(BigDecimal.ZERO)
+				;
 				//入库状态
 				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
 				inboundItemVO.setIntoStatus(intoStatus);
@@ -232,20 +256,20 @@ public class InboundOtherService extends BaseService<Inbound> {
 		}
 		//endregion
 
-		//region 删除明细 todo 2024年3月20日13:12:02 这里可能用不到
-//		if (inboundVO.getDeleteItemList() != null) {
-//			for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
-//				if (inboundItemVO.getItemId() != null) {
-//					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-//					inboundItem.setFlgValid(false);
-//					//修改
-//					inboundItemMapper.update(inboundItem,
-//							new UpdateWrapper<InboundItem>().lambda()
-//									.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-//					);
-//				}
-//			}
-//		}
+		//region 删除明细
+		if (inboundVO.getDeleteItemList() != null) {
+			for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
+				if (inboundItemVO.getItemId() != null) {
+					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+					inboundItem.setFlgValid(false);
+					//修改
+					inboundItemMapper.update(inboundItem,
+							new UpdateWrapper<InboundItem>().lambda()
+									.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+					);
+				}
+			}
+		}
 		//endregion
 
 		//region 编辑总单
@@ -254,8 +278,11 @@ public class InboundOtherService extends BaseService<Inbound> {
 		BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
 		inboundVO.setIntoQty(sumIntoQty);
 		inboundVO.setIntoAmt(sumIntoAmt);
-		inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoQty));
-		inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
+		//todo  2024年3月23日15:32:14  这里 改成清零
+//		inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoQty));
+//		inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
+		inboundVO.setIntoingQty(BigDecimal.ZERO);
+		inboundVO.setIntoingAmt(BigDecimal.ZERO);
 		//入库状态
 		String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
 		inboundVO.setIntoStatus(intoStatus);
@@ -270,7 +297,9 @@ public class InboundOtherService extends BaseService<Inbound> {
 
 		//todo 如果是已入库 调用库存  后续写库存这里补上
 		//region 修改库存
-
+		Map<String, Object> map = new HashMap<>();
+		map.put("intoDetail", inboundVO.getItemList());
+		inventoryService.updateInventoryInformation(map);
 		//endregion
 		return ResponseResultUtil.success(inboundVO);
 	}
@@ -289,8 +318,11 @@ public class InboundOtherService extends BaseService<Inbound> {
 		inbound.setIntoId(inboundResponse.getIntoId())
 				.setIntoDate(null)
 				.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
-				.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()))
-				.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()))
+				//todo 2024年3月23日15:33:58  这里改成直接取已入库数量
+//				.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()))
+//				.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()))
+				.setIntoingQty(inboundResponse.getIntoQty())
+				.setIntoingAmt(inboundResponse.getIntoAmt())
 				.setIntoQty(BigDecimal.ZERO)
 				.setIntoAmt(BigDecimal.ZERO);
 		//修改
@@ -303,14 +335,20 @@ public class InboundOtherService extends BaseService<Inbound> {
 		//region 明细数据
 		InboundItemQuery inboundItemQuery = new InboundItemQuery().setIntoId(inbound.getIntoId());
 		//根据总单查明细
-		List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(inboundItemQuery);
-		for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
+		List<InboundItemResponse> inboundItemResponseList = inboundItemMapper.selectByCond(inboundItemQuery);
+		for (InboundItemResponse inboundItemResponse : inboundItemResponseList) {
+			//将库存需要的参数赋值
+			inboundItemResponse.setInventoryType(Constant.InventoryType.INBOUND.getName());
+			inboundItemResponse.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());
 			InboundItem inboundItem = new InboundItem();
 			inboundItem
 					.setIntoId(inbound.getIntoId())
 					.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
-					.setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
-					.setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
+					//todo  2024年3月23日15:34:51  改成直接取已入库数量
+//					.setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
+//					.setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
+					.setIntoingQty(inboundItemResponse.getInvQty())
+					.setIntoingAmt(inboundItemResponse.getIntoAmt())
 					.setIntoQty(BigDecimal.ZERO)
 					.setIntoAmt(BigDecimal.ZERO)
 					.setCostPrice(BigDecimal.ZERO)
@@ -321,11 +359,16 @@ public class InboundOtherService extends BaseService<Inbound> {
 					new UpdateWrapper<InboundItem>().lambda()
 							.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
 			);
+			//数量金额取反 用于给库存使用
+			inboundItemResponse.setIntoQty(inboundItemResponse.getIntoQty().negate());
+			inboundItemResponse.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
 		}
 		//endregion
 
 		//region 修改库存
-
+		Map<String, Object> map = new HashMap<>();
+		map.put("intoDetail", inboundItemResponseList);
+		inventoryService.updateInventoryInformation(map);
 		//endregion
 
 		return ResponseResultUtil.success();
@@ -340,8 +383,8 @@ public class InboundOtherService extends BaseService<Inbound> {
 	public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
 		//入库状态
 		String intoStatus = null;
-		//已入库数量>0 入库中数量>0
-		if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
+		//已入库数量==0 入库中数量>0
+		if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
 			//入库中
 			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
 		}
@@ -359,5 +402,36 @@ public class InboundOtherService extends BaseService<Inbound> {
 	}
 
 
-	
+
+
+	/**
+	 * @desc   : 条件查询 --- web端入库办理用
+	 * @date   : 2024/3/23 9:24
+	 * @author : 寇珊珊
+	 */
+	@Pagination
+	public ResponseResultVO<PageList<InboundResponse>> selectInbound(InboundQuery inboundQuery) {
+		return super.mergeListWithCount(inboundQuery, inboundMapper.selectInbound(inboundQuery),
+				inboundMapper.selectInboundCond(inboundQuery));
+	}
+
+	/**
+	 * @desc   : 查询明细查询 --- web端入库办理用
+	 * @date   : 2024/3/9 15:43
+	 * @author : 寇珊珊
+	 */
+	public ResponseResultVO<Map<String, Object>> selectInboundItem(String id) {
+		Map<String, Object> result = new HashMap<>();
+		// 商品明细
+		List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectInboundItem(new InboundItemQuery().setIntoId(id));
+		result.put("itemList", inboundItemResponses);
+		// 收款
+
+		// 附件
+		return ResponseResultUtil.success(result);
+	}
+
+
+
+
 }

+ 150 - 98
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseReturnService.java

@@ -29,6 +29,7 @@ import com.dk.mdm.model.response.ivt.IntoReturnItemResponse;
 import com.dk.mdm.model.response.ivt.IntoReturnResponse;
 import com.dk.mdm.model.vo.ivt.InboundItemVO;
 import com.dk.mdm.model.vo.ivt.InboundVO;
+import com.dk.mdm.model.vo.ivt.OutboundItemVO;
 import com.dk.mdm.service.common.CommonService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -118,7 +119,7 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         inboundVO.setIntoId(codeMap.get("outId").toString()).
                 setIntoNo(codeMap.get("outNote").toString());
         //入库类型
-        inboundVO.setIntoType(Constant.IntoType.PURRETURN.getName());
+        inboundVO.setIntoType(Constant.IntoType.PURRETURN_RETURN.getName());
         //自动入库标识
         if (inboundVO.getAutomaticFlg()) {
             //已入库
@@ -160,16 +161,19 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
             //已入库
             if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
-                //第一次已入库
-                if(intoReturnResponse.getOutingQty().compareTo(inboundVO.getIntoingQty()) == 0){
-                    intoReturn.setOutingQty(BigDecimal.ZERO);
-                    intoReturn.setOutingAmt(BigDecimal.ZERO);
-                }
-                //多次已入库
-                else{
-                    intoReturn.setOutingQty(inboundVO.getIntoQty());
-                    intoReturn.setOutingAmt(inboundVO.getIntoQty());
-                }
+//                //第一次已入库
+//                if(intoReturnResponse.getOutingQty().compareTo(inboundVO.getIntoingQty()) == 0){
+//                    intoReturn.setOutingQty(BigDecimal.ZERO);
+//                    intoReturn.setOutingAmt(BigDecimal.ZERO);
+//                }
+//                //多次已入库
+//                else{
+//                    intoReturn.setOutingQty(inboundVO.getIntoQty());
+//                    intoReturn.setOutingAmt(inboundVO.getIntoAmt());
+//                }
+                //todo  2024年3月23日16:39:50  已入库情况下  入库中数量赋值为零
+                intoReturn.setOutingQty(BigDecimal.ZERO);
+                intoReturn.setOutingAmt(BigDecimal.ZERO);
                 intoReturn.setOutQty(inboundVO.getIntoQty().abs());
                 intoReturn.setOutAmt(inboundVO.getIntoQty().abs());
             }
@@ -236,16 +240,19 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
                 //已入库
                 if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
-                    //第一次已入库
-                    if(intoReturnItemResponse.getOutingQty().compareTo(BigDecimal.ZERO)==0){
-                        intoReturnItem.setOutingQty(BigDecimal.ZERO);
-                        intoReturnItem.setOutingAmt(BigDecimal.ZERO);
-                    }
-                    //多次已入库
-                    else{
-                        intoReturnItem.setOutingQty(inboundItemVO.getIntoQty());
-                        intoReturnItem.setOutingAmt(inboundItemVO.getIntoQty());
-                    }
+//                    //第一次已入库
+//                    if(intoReturnItemResponse.getOutingQty().compareTo(BigDecimal.ZERO)==0){
+//                        intoReturnItem.setOutingQty(BigDecimal.ZERO);
+//                        intoReturnItem.setOutingAmt(BigDecimal.ZERO);
+//                    }
+//                    //多次已入库
+//                    else{
+//                        intoReturnItem.setOutingQty(inboundItemVO.getIntoQty());
+//                        intoReturnItem.setOutingAmt(inboundItemVO.getIntoQty());
+//                    }
+                    //todo  2024年3月23日16:37:54  已入库情况下  入库中数量赋值为零
+                    intoReturnItem.setOutingQty(BigDecimal.ZERO);
+                    intoReturnItem.setOutingAmt(BigDecimal.ZERO);
                     intoReturnItem.setOutQty(inboundItemVO.getIntoQty().abs());
                     intoReturnItem.setOutAmt(inboundItemVO.getIntoQty().abs());
                 }
@@ -290,6 +297,10 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> saleReturnHandleInbound(InboundVO inboundVO) {
+        //region 根据id查询数据,得到入库单还没操作时在数据中的 入库中数量,入库中金额  后续用于反写采购退货单
+        InboundResponse inboundWriteBack = inboundMapper.selectById(inboundVO.getIntoId());
+        //endregion
+
         //region 编辑明细
         //校验明细
         if (inboundVO.getItemList().size() == 0) {
@@ -302,10 +313,13 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
                 //编辑明细
                 inboundItemVO
-                        .setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
-                        .setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
                         .setIntoQty(inboundItemResponse.getIntoingQty().add(inboundItemVO.getIntoingQty()))
                         .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+//                        .setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
+//                        .setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
+                        //todo  2024年3月23日16:55:23   赋值为0
+                        .setIntoingQty(BigDecimal.ZERO)
+                        .setIntoAmt(BigDecimal.ZERO)
                         .setCostPrice(inboundItemVO.getPriceInto())
                         .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP));
                 //入库状态
@@ -318,36 +332,17 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                         new UpdateWrapper<InboundItem>().lambda()
                                 .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
                 );
-            }
-            //endregion
-            //region 新建明细
-            else {
-                inboundItemVO
-                        .setIntoQty(inboundItemVO.getIntoingQty())
-                        .setIntoAmt(inboundItemVO.getIntoingAmt())
-                        .setIntoId(inboundVO.getIntoId())
-                        .setCostPrice(inboundItemVO.getPriceInto())
-                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-                        .setIntoType(Constant.IntoType.PURRETURN.getName());
-                //入库状态
-                String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-                inboundItemVO.setIntoStatus(intoStatus);
-                //实体转换
-                InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-                //新建
-                inboundItemMapper.insert(inboundItem);
-            }
-            //endregion
-
-            //region  采购退货明细
-            if (inboundItemVO.getFromItemId() != null) {
+                //region  采购退货明细
                 //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
                 IntoReturnItem intoReturnItem = new IntoReturnItem();
                 intoReturnItem.setItemId(inboundItemVO.getFromItemId());
                 intoReturnItem.setOutQty(inboundItemVO.getIntoQty().abs());
                 intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt().abs());
-                intoReturnItem.setOutingQty(inboundItemVO.getIntoQty());
-                intoReturnItem.setOutingAmt(inboundItemVO.getIntoAmt());
+                //todo 2024年3月23日17:04:50   赋值为0 并且把退货单上所有数量金额相关字段反写
+//                intoReturnItem.setOutingQty(inboundItemVO.getIntoQty());
+//                intoReturnItem.setOutingAmt(inboundItemVO.getIntoAmt());
+                intoReturnItem.setOutingQty(BigDecimal.ZERO);
+                intoReturnItem.setOutAmt(BigDecimal.ZERO);
                 //根据id查询
                 IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
                 //出库状态
@@ -360,71 +355,119 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
                 if (countRow == 0) {
                     throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
                 }
+                //endregion
             }
             //endregion
+
+//            //region todo  2024年3月23日17:26:02  采购退货入库是自动生成的 不会有下面这种情况 新建明细
+//            else {
+//                inboundItemVO
+//                        .setIntoQty(inboundItemVO.getIntoingQty())
+//                        .setIntoAmt(inboundItemVO.getIntoingAmt())
+//                        .setIntoId(inboundVO.getIntoId())
+//                        .setCostPrice(inboundItemVO.getPriceInto())
+//                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+//                        .setIntoType(Constant.IntoType.PURRETURN_RETURN.getName());
+//                //入库状态
+//                String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+//                inboundItemVO.setIntoStatus(intoStatus);
+//                //实体转换
+//                InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+//                //新建
+//                inboundItemMapper.insert(inboundItem);
+//            }
+//            //endregion
+
+            //region  todo 2024年3月23日17:26:46  配合上面代码进行注释  采购退货明细
+//            if (inboundItemVO.getFromItemId() != null) {
+//                //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+//                IntoReturnItem intoReturnItem = new IntoReturnItem();
+//                intoReturnItem.setItemId(inboundItemVO.getFromItemId());
+//                intoReturnItem.setOutQty(inboundItemVO.getIntoQty().abs());
+//                intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt().abs());
+//                //todo 2024年3月23日17:04:50   原数据+  -原的入库明细
+////                intoReturnItem.setOutingQty(inboundItemVO.getIntoQty());
+////                intoReturnItem.setOutingAmt(inboundItemVO.getIntoAmt());
+//                //根据id查询
+//                IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
+//                //出库状态
+//                String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
+//                        intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
+//                intoReturnItem.setOutStatus(outStatus);
+//                //修改
+//                int countRow = intoReturnItemMapper.updateById(intoReturnItem);
+//                //数量超出
+//                if (countRow == 0) {
+//                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+//                }
+//            }
+            //endregion
         }
         //endregion
 
-        //region 删除明细  todo 2024年3月20日13:12:02 这里可能用不到
+        //region 删除明细
 //        BigDecimal sumDelIntoQty = BigDecimal.ZERO;
 //        BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
 //        BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
 //        BigDecimal sumDelIntoingAmt = BigDecimal.ZERO;
-//        if (inboundVO.getDeleteItemList() != null) {
+        if (inboundVO.getDeleteItemList() != null) {
 //            sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
 //            sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
 //            sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
 //            sumDelIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-//            for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
-//                if (inboundItemVO.getItemId() != null) {
-//                    InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-//                    inboundItem.setFlgValid(false);
-//                    //修改
-//                    inboundItemMapper.update(inboundItem,
-//                            new UpdateWrapper<InboundItem>().lambda()
-//                                    .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-//                    );
-//                }
-//                //region  采购退货明细
-//                if (inboundItemVO.getFromItemId() != null) {
-//                    //采购退货单明细
-//                    //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-//                    IntoReturnItem intoReturnItem = new IntoReturnItem();
-//                    intoReturnItem.setItemId(inboundItemVO.getFromItemId());
-//                    intoReturnItem.setOutQty(inboundItemVO.getIntoQty());
-//                    intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt());
-//                    intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty());
-//                    intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt());
-//                    //根据id查询
-//                    IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
-//                    //出库状态
-//                    String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
-//                            intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
-//                    intoReturnItem.setOutStatus(outStatus);
-//                    //修改
-//                    int countRow = intoReturnItemMapper.updateById(intoReturnItem);
-//                    //数量超出
-//                    if (countRow == 0) {
-//                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-//                    }
-//
-//                }
-//                //endregion
-//
-//            }
-//        }
-//        //endregion
+            for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
+                if (inboundItemVO.getItemId() != null) {
+                    InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+                    inboundItem.setFlgValid(false);
+                    //修改
+                    inboundItemMapper.update(inboundItem,
+                            new UpdateWrapper<InboundItem>().lambda()
+                                    .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+                    );
+                }
+                //region  采购退货明细
+                if (inboundItemVO.getFromItemId() != null) {
+                    //采购退货单明细
+                    //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                    IntoReturnItem intoReturnItem = new IntoReturnItem();
+                    intoReturnItem.setItemId(inboundItemVO.getFromItemId());
+                    intoReturnItem.setOutQty(inboundItemVO.getIntoQty());
+                    intoReturnItem.setOutAmt(inboundItemVO.getIntoAmt());
+                    intoReturnItem.setOutingQty(inboundItemVO.getIntoingQty());
+                    intoReturnItem.setOutingAmt(inboundItemVO.getIntoingAmt());
+                    //根据id查询
+                    IntoReturnItemResponse intoReturnItemResponse = intoReturnItemMapper.selectById(inboundItemVO.getFromItemId());
+                    //出库状态
+                    String outStatus = this.setOutStatus(intoReturnItemResponse.getOutingQty().add(intoReturnItem.getOutingQty()),
+                            intoReturnItemResponse.getOutQty().add(intoReturnItem.getOutQty()));
+                    intoReturnItem.setOutStatus(outStatus);
+                    //修改
+                    int countRow = intoReturnItemMapper.updateById(intoReturnItem);
+                    //数量超出
+                    if (countRow == 0) {
+                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                    }
+
+                }
+                //endregion
+
+            }
+        }
+        //endregion
 
         //region 编辑总单
-        InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
+//        InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
         BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
         BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
 //        BigDecimal sumIntoingQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
 //        BigDecimal sumIntoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
         inboundVO.setIntoQty(sumIntoQty);
         inboundVO.setIntoAmt(sumIntoAmt);
-        inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoQty));
-        inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
+        //todo 2024年3月25日08:50:04   直接赋值给0
+//        inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoQty));
+//        inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
+        inboundVO.setIntoingQty(BigDecimal.ZERO);
+        inboundVO.setIntoingAmt(BigDecimal.ZERO);
         //入库状态
         String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
         inboundVO.setIntoStatus(intoStatus);
@@ -452,8 +495,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
 
             intoReturn.setOutQty(sumIntoQty.abs());
             intoReturn.setOutAmt(sumIntoAmt.abs());
-            intoReturn.setOutingQty(sumIntoQty);
-            intoReturn.setOutingAmt(sumIntoAmt);
+            //todo  这里取次方法刚进入时候查询的入库总单上的数量
+//            intoReturn.setOutingQty(sumIntoQty);
+//            intoReturn.setOutingAmt(sumIntoAmt);
+            intoReturn.setOutingQty(inboundWriteBack.getIntoingQty());
+            intoReturn.setOutingAmt(inboundWriteBack.getIntoAmt());
             //根据id查询
             IntoReturnResponse intoReturnResponse = intoReturnMapper.selectById(inboundVO.getFromId());
             //出库状态
@@ -490,7 +536,7 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
 
         //region 修改订单数据信息
         if (inboundVO.getFromId() != null) {
-            //赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            //赋值  (这里重写了更新方法,数量在更新方法中有数据库原始数量+本次数量)
             IntoReturn intoReturn = new IntoReturn();
             intoReturn.setReturnId(inboundVO.getFromId());
             intoReturn.setOutQty(inboundResponse.getIntoQty());
@@ -519,6 +565,9 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
         inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
         inbound.setIntoQty(BigDecimal.ZERO);
         inbound.setIntoAmt(BigDecimal.ZERO);
+        //todo 2024年3月25日09:46:52  添加入库中数量
+        inbound.setIntoingQty(inboundResponse.getIntoQty());
+        inbound.setIntoingAmt(inboundResponse.getIntoAmt());
         //修改
         inboundMapper.update(inbound,
                 new UpdateWrapper<Inbound>().lambda()
@@ -559,8 +608,11 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
             inboundItem
                     .setIntoId(inbound.getIntoId())
                     .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
-                    .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
-                    .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
+                    //todo  2024年3月25日10:07:16 取数据库中已入库数量
+//                    .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
+//                    .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
+                    .setIntoQty(inboundItemResponse.getIntoQty())
+                    .setIntoAmt(inboundItemResponse.getIntoAmt())
                     .setIntoQty(BigDecimal.ZERO)
                     .setIntoAmt(BigDecimal.ZERO)
                     .setItemId(inboundItemResponse.getItemId())
@@ -592,7 +644,7 @@ public class InboundPurchaseReturnService extends BaseService<Inbound> {
      * @author : 寇珊珊
      */
     public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
-        //入库状态
+        //入库状态+
         String intoStatus = null;
         //已入库数量>0 入库中数量>0
         if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {

+ 603 - 544
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseService.java

@@ -42,561 +42,620 @@ import java.util.UUID;
 
 
 /**
- * @desc   : 采购入库业务层
- * @date   : 2024/3/7 14:11
  * @author : 寇珊珊
+ * @desc : 采购入库业务层
+ * @date : 2024/3/7 14:11
  */
 @Service
 public class InboundPurchaseService 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 PurchaseMapper purchaseMapper;
-
-	@Autowired
-	private PurchaseItemMapper purchaseItemMapper;
-
-	@Autowired
-	private CommonService commonService;
-
-
-	/**
-	 * @desc   : 条件查询
-	 * @date   : 2024/3/7 14:12
-	 * @author : 寇珊珊
-	 */
-	@Pagination
-	public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
-		return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
-				inboundMapper.countByCond(inboundQuery));
-	}
-
-
-	/**
-	 * @desc   : 查询明细
-	 * @date   : 2024/3/9 15:43
-	 * @author : 寇珊珊
-	 */
-	@Pagination
-	public ResponseResultVO<Map<String, Object>> selectPurchaseInboundItemInfoById(String id) {
-		Map<String, Object> result = new HashMap<>();
-		// 商品明细
-		List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
-		result.put("itemList", inboundItemResponses);
-		// 收款
-
-		// 附件
-		return ResponseResultUtil.success(result);
-	}
-
-	/**
-	 * @desc   : 采购入库新建
-	 * @date   : 2024/3/7 14:13
-	 * 入库中数量/金额  已入库数量/金额  由调用方传入
-	 * @author : 寇珊珊
-	 */
-	@Transactional(rollbackFor = {Exception.class})
-	public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
-		//region  总单
-		//获取 id/单号
-		Map<String , Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(),false);
-		inboundVO.setIntoId(codeMap.get("outId").toString()).
-				setIntoNo(codeMap.get("outNote").toString());
-		//入库类型
-		inboundVO.setIntoType(Constant.IntoType.SALE.getName());
-		//自动入库标识
-		if (inboundVO.getAutomaticFlg()) {
-			//已入库
-			inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
-		} else {
-			//入库中
-			inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
-		}
-		//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
-		if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
-			inboundVO.setIntoQty(inboundVO.getIntoingQty())
-					.setIntoAmt(inboundVO.getIntoingAmt())
-					.setIntoingQty(BigDecimal.ZERO)
-					.setIntoingAmt(BigDecimal.ZERO)
-			;
-		}else{
-			inboundVO.setIntoQty(BigDecimal.ZERO)
-					.setIntoAmt(BigDecimal.ZERO)
-			;
-		}
-		//实体转换
-		Inbound inbound = inboundConvert.convertToPo(inboundVO);
-		inboundMapper.insert(inbound);
-		//endregion
-
-		//region 采购总单
-		if(inboundVO.getFromId()!=null){
-			//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-			Purchase purchaseUpdate = new Purchase();
-			purchaseUpdate.setPurId(inboundVO.getFromId());
-			//根据id查询
-			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
-			//已入库
-			if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
-				//直接已入库
-				if(purchaseResponse.getIntoingQty().compareTo(BigDecimal.ZERO)==0){
-					purchaseUpdate.setIntoingQty(BigDecimal.ZERO);
-					purchaseUpdate.setIntoingAmt(BigDecimal.ZERO);
-				}
-				//多次已入库
-				else{
-					purchaseUpdate.setIntoingQty(inboundVO.getIntoQty().negate());
-					purchaseUpdate.setIntoingAmt(inboundVO.getIntoAmt().negate());
-				}
-				purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
-				purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
-			}
-			//入库中
-			else{
-				purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty());
-				purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt());
-				purchaseUpdate.setIntoQty(BigDecimal.ZERO);
-				purchaseUpdate.setIntoAmt(BigDecimal.ZERO);
-			}
-			//入库状态
-			String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()),
-					purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()));
-			purchaseUpdate.setIntoStatus(intoStatus);
-			//修改
-			int countRow = purchaseMapper.updateById(purchaseUpdate);
-			//数量超出
-			if (countRow == 0) {
-				throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-			}
-		}
-		//endregion
-
-
-		//region 明细
-		//校验明细
-		if (inboundVO.getItemList().size() == 0) {
-			return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
-		}
-		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-			//总单id
-			inboundItemVO.setIntoId(inboundVO.getIntoId());
-			//入库类型
-			inboundItemVO.setIntoType(inboundVO.getIntoType());
-			//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
-			if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
-				inboundItemVO
-						.setIntoQty(inboundItemVO.getIntoingQty())
-						.setIntoAmt(inboundItemVO.getIntoingAmt())
-						.setIntoingQty(BigDecimal.ZERO)
-						.setIntoingAmt(BigDecimal.ZERO)
-						.setCostPrice(inboundItemVO.getPriceInto())
-						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-				;
-			}else{
-				inboundItemVO
-						.setIntoQty(BigDecimal.ZERO)
-						.setIntoAmt(BigDecimal.ZERO);
-			}
-			//入库状态
-			inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
-			//实体转换
-			InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-			inboundItemMapper.insert(inboundItem);
-			//endregion
-
-			//region 采购明细
-			if(inboundItemVO.getFromItemId()!=null){
-				//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-				PurchaseItem  purchaseItem = new PurchaseItem();
-				purchaseItem.setItemId(inboundItemVO.getFromItemId());
-				//根据id查询
-				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
-				//已入库
-				if(Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())){
-					//第一次已入库
-					if(purchaseItemResponse.getIntoingQty().compareTo(BigDecimal.ZERO)==0){
-						purchaseItem.setIntoingQty(BigDecimal.ZERO);
-						purchaseItem.setIntoingAmt(BigDecimal.ZERO);
-					}
-					//多次已入库
-					else{
-						purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
-						purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
-					}
-					purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
-					purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
-				}
-				//入库中
-				else{
-					purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
-					purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
-					purchaseItem.setIntoQty(BigDecimal.ZERO);
-					purchaseItem.setIntoAmt(BigDecimal.ZERO);
-				}
-				//入库状态
-				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
-						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
-				purchaseItem.setIntoStatus(intoStatus);
-				int countRow = purchaseItemMapper.updateById(purchaseItem);
-				//数量超出
-				if (countRow == 0) {
-					throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-				}
-			}
-			//endregion
-		}
-		//endregion
-
-		//todo 如果是已入库 调用库存  后续写库存这里补上
-		//region 库存
-
-
-		//endregion
-
-
-		return ResponseResultUtil.success(inboundVO);
-	}
-
-
-	/**
-	 * @desc   : 采购入库办理
-	 * @date   : 2024/3/7 15:47
-	 * @author : 寇珊珊
-	 */
-	@Transactional(rollbackFor = {Exception.class})
-	public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
-		//region 编辑明细
-		//校验明细
-		if (inboundVO.getItemList().size() == 0) {
-			return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-					ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
-		}
-		for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
-			if (inboundItemVO.getIntoId() != null) {
-				InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
-				//编辑明细
-				inboundItemVO
-						.setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
-						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
-						.setIntoQty(inboundItemResponse.getOutQty().add(inboundItemVO.getIntoQty()))
-						.setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()))
-						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
-						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
-						.setCostPrice(inboundItemVO.getPriceInto())
-						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-				;
-				//入库状态
-				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-				inboundItemVO.setIntoStatus(intoStatus);
-				//实体转换
-				InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-				//修改
-				inboundItemMapper.update(inboundItem,
-						new UpdateWrapper<InboundItem>().lambda()
-								.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-				);
-			}
-			//endregion
-			//region 新建明细
-			else {
-				inboundItemVO
-						.setIntoQty(inboundItemVO.getIntoingQty())
-						.setIntoAmt(inboundItemVO.getIntoingAmt())
-						.setIntoId(inboundVO.getIntoId())
-						.setCostPrice(inboundItemVO.getPriceInto())
-						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
-						.setIntoType(Constant.IntoType.SALE.getName());
-				//入库状态
-				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
-				inboundItemVO.setIntoStatus(intoStatus);
-				//实体转换
-				InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-				//新建
-				inboundItemMapper.insert(inboundItem);
-			}
-			//region  采购
-			//采购明细
-			if (inboundItemVO.getFromItemId() != null) {
-				//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-				PurchaseItem purchaseItem = new PurchaseItem();
-				purchaseItem.setItemId(inboundItemVO.getFromItemId());
-				purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
-				purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
-				purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
-				purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
-				//根据id查询
-				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
-				//入库状态
-				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
-						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
-				purchaseItem.setIntoStatus(intoStatus);
-				int countRow = purchaseItemMapper.updateById(purchaseItem);
-				//数量超出
-				if (countRow == 0) {
-					throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-				}
-			}
-			//endregion
-		}
-		//endregion
-
-		//region 删除明细 todo 2024年3月20日13:14:20 这里可能用不到
-//		BigDecimal sumDelIntoQty = BigDecimal.ZERO;
-//		BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
-//		BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
-//		BigDecimal sumDelIntoingAmt = BigDecimal.ZERO;
-//		if (inboundVO.getDeleteItemList() != null) {
-//			sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-//			sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-//			sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-//			sumDelIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-//			for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
-//				if (inboundItemVO.getItemId() != null) {
-//					InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
-//					inboundItem.setFlgValid(false);
-//					//修改
-//					inboundItemMapper.update(inboundItem,
-//							new UpdateWrapper<InboundItem>().lambda()
-//									.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-//					);
+    @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 PurchaseMapper purchaseMapper;
+
+    @Autowired
+    private PurchaseItemMapper purchaseItemMapper;
+
+    @Autowired
+    private CommonService commonService;
+
+
+    /**
+     * @desc : 条件查询
+     * @date : 2024/3/7 14:12
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
+        return super.mergeListWithCount(inboundQuery, inboundMapper.selectByCond(inboundQuery),
+                inboundMapper.countByCond(inboundQuery));
+    }
+
+
+    /**
+     * @desc : 查询明细
+     * @date : 2024/3/9 15:43
+     * @author : 寇珊珊
+     */
+    @Pagination
+    public ResponseResultVO<Map<String, Object>> selectPurchaseInboundItemInfoById(String id) {
+        Map<String, Object> result = new HashMap<>();
+        // 商品明细
+        List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(id));
+        result.put("itemList", inboundItemResponses);
+        // 收款
+
+        // 附件
+        return ResponseResultUtil.success(result);
+    }
+
+    /**
+     * @desc : 采购入库新建
+     * @date : 2024/3/7 14:13
+     * 入库中数量/金额  已入库数量/金额  由调用方传入
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
+        //region  总单
+        //获取 id/单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.PURCASEINBOUND.getName(), false);
+        inboundVO.setIntoId(codeMap.get("outId").toString()).
+                setIntoNo(codeMap.get("outNote").toString());
+        //入库类型
+        inboundVO.setIntoType(Constant.IntoType.SALE.getName());
+        //自动入库标识
+        if (inboundVO.getAutomaticFlg()) {
+            //已入库
+            inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
+        } else {
+            //入库中
+            inboundVO.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
+        }
+        //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
+        if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
+            inboundVO.setIntoQty(inboundVO.getIntoingQty())
+                    .setIntoAmt(inboundVO.getIntoingAmt())
+                    .setIntoingQty(BigDecimal.ZERO)
+                    .setIntoingAmt(BigDecimal.ZERO)
+            ;
+        } else {
+            inboundVO.setIntoQty(BigDecimal.ZERO)
+                    .setIntoAmt(BigDecimal.ZERO)
+            ;
+        }
+        //实体转换
+        Inbound inbound = inboundConvert.convertToPo(inboundVO);
+        inboundMapper.insert(inbound);
+        //endregion
+
+        //region 采购总单
+        if (inboundVO.getFromId() != null) {
+            //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            Purchase purchaseUpdate = new Purchase();
+            purchaseUpdate.setPurId(inboundVO.getFromId());
+            //根据id查询
+            PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
+            //已入库
+            if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
+//				//直接已入库
+//				if(purchaseResponse.getIntoingQty().compareTo(BigDecimal.ZERO)==0){
+//					purchaseUpdate.setIntoingQty(BigDecimal.ZERO);
+//					purchaseUpdate.setIntoingAmt(BigDecimal.ZERO);
 //				}
-//				//region  采购
-//				if (inboundItemVO.getFromItemId() != null) {
-//					//region 采购订单明细
-//					//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-//					PurchaseItem purchaseItem = new PurchaseItem();
-//					purchaseItem.setItemId(inboundItemVO.getFromItemId());
-//					purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
-//					purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
-//					purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
-//					purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
-//					//根据id查询
-//					PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
-//					//入库状态
-//					String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
-//							purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
-//					purchaseItem.setIntoStatus(intoStatus);
-//					int countRow = purchaseItemMapper.updateById(purchaseItem);
-//					//数量超出
-//					if (countRow == 0) {
-//						throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+//				//多次已入库
+//				else{
+//					purchaseUpdate.setIntoingQty(inboundVO.getIntoQty().negate());
+//					purchaseUpdate.setIntoingAmt(inboundVO.getIntoAmt().negate());
+//				}
+                //todo  2024年3月25日11:31:52  这里直接赋值0
+                purchaseUpdate.setIntoingQty(BigDecimal.ZERO);
+                purchaseUpdate.setIntoingAmt(BigDecimal.ZERO);
+                purchaseUpdate.setIntoQty(inboundVO.getIntoQty());
+                purchaseUpdate.setIntoAmt(inboundVO.getIntoAmt());
+            }
+            //入库中
+            else {
+                purchaseUpdate.setIntoingQty(inboundVO.getIntoingQty());
+                purchaseUpdate.setIntoingAmt(inboundVO.getIntoingAmt());
+                purchaseUpdate.setIntoQty(BigDecimal.ZERO);
+                purchaseUpdate.setIntoAmt(BigDecimal.ZERO);
+            }
+            //入库状态
+            String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchaseUpdate.getIntoingQty()),
+                    purchaseResponse.getIntoQty().add(purchaseUpdate.getIntoQty()));
+            purchaseUpdate.setIntoStatus(intoStatus);
+            //修改
+            int countRow = purchaseMapper.updateById(purchaseUpdate);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+            }
+        }
+        //endregion
+
+
+        //region 明细
+        //校验明细
+        if (inboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+            //总单id
+            inboundItemVO.setIntoId(inboundVO.getIntoId());
+            //入库类型
+            inboundItemVO.setIntoType(inboundVO.getIntoType());
+            //入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
+            if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
+                inboundItemVO
+                        .setIntoQty(inboundItemVO.getIntoingQty())
+                        .setIntoAmt(inboundItemVO.getIntoingAmt())
+                        .setIntoingQty(BigDecimal.ZERO)
+                        .setIntoingAmt(BigDecimal.ZERO)
+                        .setCostPrice(inboundItemVO.getPriceInto())
+                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                ;
+            } else {
+                inboundItemVO
+                        .setIntoQty(BigDecimal.ZERO)
+                        .setIntoAmt(BigDecimal.ZERO);
+            }
+            //入库状态
+            inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
+            //实体转换
+            InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+            inboundItemMapper.insert(inboundItem);
+            //endregion
+
+            //region 采购明细
+            if (inboundItemVO.getFromItemId() != null) {
+                //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                PurchaseItem purchaseItem = new PurchaseItem();
+                purchaseItem.setItemId(inboundItemVO.getFromItemId());
+                //根据id查询
+                PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
+                //已入库
+                if (Constant.IntoStatus.YIRUKU.getName().equals(inboundVO.getIntoStatus())) {
+//					//第一次已入库
+//					if(purchaseItemResponse.getIntoingQty().compareTo(BigDecimal.ZERO)==0){
+//						purchaseItem.setIntoingQty(BigDecimal.ZERO);
+//						purchaseItem.setIntoingAmt(BigDecimal.ZERO);
+//					}
+//					//多次已入库
+//					else{
+//						purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
+//						purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
 //					}
-//					//endregion
+                    //2024年3月25日11:49:17  直接赋值为0
+                    purchaseItem.setIntoingQty(BigDecimal.ZERO);
+                    purchaseItem.setIntoingAmt(BigDecimal.ZERO);
+                    purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
+                    purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+                }
+                //入库中
+                else {
+                    purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty());
+                    purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt());
+                    purchaseItem.setIntoQty(BigDecimal.ZERO);
+                    purchaseItem.setIntoAmt(BigDecimal.ZERO);
+                }
+                //入库状态
+                String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+                        purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
+                purchaseItem.setIntoStatus(intoStatus);
+                int countRow = purchaseItemMapper.updateById(purchaseItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                }
+            }
+            //endregion
+        }
+        //endregion
+
+        //todo 如果是已入库 调用库存  后续写库存这里补上
+        //region 库存
+
+
+        //endregion
+
+
+        return ResponseResultUtil.success(inboundVO);
+    }
+
+
+    /**
+     * @desc : 采购入库办理
+     * @date : 2024/3/7 15:47
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> purchaseHandleInbound(InboundVO inboundVO) {
+        //region 根据订单id查询入库数据
+        List<InboundResponse> inboundResponses = inboundMapper.selectByCond(new InboundQuery().setFromId(inboundVO.getFromId()));
+        BigDecimal intoingQtyTotal = BigDecimal.ZERO;
+        BigDecimal intoingAmtTotal = BigDecimal.ZERO;
+        if (inboundResponses != null && inboundResponses.size() > 0) {
+            //入库中数据  汇总
+            intoingQtyTotal = inboundResponses.stream().map(InboundResponse::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            intoingAmtTotal = inboundResponses.stream().map(InboundResponse::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        }
+        //endregion
+        //region 根据id查询 此条入库单的数据还未更改前的数据
+        InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
+        //endregion
+
+        //region 编辑明细
+        //校验明细
+        if (inboundVO.getItemList().size() == 0) {
+            return ResponseResultUtil.error(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+            //入库明细根据id查询
+            InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId());
+            if (inboundItemVO.getIntoId() != null) {
+                //region 采购明细
+                //根据id查询
+                PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
+                //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                PurchaseItem purchaseItem = new PurchaseItem();
+                purchaseItem.setItemId(inboundItemVO.getFromItemId());
+                //todo 取入库单的入库中数据
+//                purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
+//                purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
+                purchaseItem.setIntoingQty(inboundItemResponse.getIntoingQty().negate());
+                purchaseItem.setIntoingAmt(inboundItemResponse.getIntoingAmt().negate());
+                purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
+                purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+                //入库状态
+                String purItemIntoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+                        purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
+                purchaseItem.setIntoStatus(purItemIntoStatus);
+                int countRow = purchaseItemMapper.updateById(purchaseItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                }
+                //endregion
+                //region 编辑入库明细
+                inboundItemVO
+                        .setIntoQty(inboundItemResponse.getIntoQty().add(inboundItemVO.getIntoingQty()))
+                        .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoingAmt()))
+                        .setIntoQty(inboundItemResponse.getOutQty().add(inboundItemVO.getIntoQty()))
+                        .setIntoAmt(inboundItemResponse.getIntoAmt().add(inboundItemVO.getIntoAmt()))
+//						.setIntoingQty(inboundItemResponse.getIntoingQty().subtract(inboundItemVO.getIntoingQty()))
+//						.setIntoingAmt(inboundItemResponse.getIntoingAmt().subtract(inboundItemVO.getIntoingAmt()))
+                        //todo  2024年3月25日12:57:07 直接赋值为0
+                        .setIntoingQty(BigDecimal.ZERO)
+                        .setIntoingAmt(BigDecimal.ZERO)
+                        .setCostPrice(inboundItemVO.getPriceInto())
+                        .setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+                ;
+                //入库状态
+                String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+                inboundItemVO.setIntoStatus(intoStatus);
+                //实体转换
+                InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+                //修改
+                inboundItemMapper.update(inboundItem,
+                        new UpdateWrapper<InboundItem>().lambda()
+                                .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+                );
+                //endregion
+            }
+        }
+        //endregion
+//			//region 新建明细 todo 注释掉
+//			else {
+//				inboundItemVO
+//						.setIntoQty(inboundItemVO.getIntoingQty())
+//						.setIntoAmt(inboundItemVO.getIntoingAmt())
+//						//todo 2024年3月25日12:58:01  赋值0
+//						.setIntoingQty(BigDecimal.ZERO)
+//						.setIntoAmt(BigDecimal.ZERO)
+//						.setIntoId(inboundVO.getIntoId())
+//						.setCostPrice(inboundItemVO.getPriceInto())
+//						.setCostAmt(inboundItemVO.getIntoQty().multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
+//						.setIntoType(Constant.IntoType.SALE.getName());
+//				//入库状态
+//				String intoStatus = this.setIntoStatus(inboundItemVO.getIntoingQty(), inboundItemVO.getIntoQty());
+//				inboundItemVO.setIntoStatus(intoStatus);
+//				//实体转换
+//				InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+//				//新建
+//				inboundItemMapper.insert(inboundItem);
+//			}
+//			//endregion
+
+        //region  采购 todo  注释掉
+        //采购明细
+//			if (inboundItemVO.getFromItemId() != null) {
+//				//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+//				PurchaseItem purchaseItem = new PurchaseItem();
+//				purchaseItem.setItemId(inboundItemVO.getFromItemId());
+//				purchaseItem.setIntoingQty(inboundItemVO.getIntoQty().negate());
+//				purchaseItem.setIntoingAmt(inboundItemVO.getIntoAmt().negate());
+//				purchaseItem.setIntoQty(inboundItemVO.getIntoQty());
+//				purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt());
+//				//根据id查询
+//				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
+//				//入库状态
+//				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+//						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
+//				purchaseItem.setIntoStatus(intoStatus);
+//				int countRow = purchaseItemMapper.updateById(purchaseItem);
+//				//数量超出
+//				if (countRow == 0) {
+//					throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
 //				}
-//				//endregion
-//
 //			}
-//		}
-		//endregion
-
-		//region 编辑总单
-		InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
-		BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
-		BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
-		inboundVO.setIntoQty(sumIntoQty);
-		inboundVO.setIntoAmt(sumIntoAmt);
-		inboundVO.setIntoingQty(inboundResponse.getIntoingQty().subtract(sumIntoQty));
-		inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
-		//入库状态
-		String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
-		inboundVO.setIntoStatus(intoStatus);
-		//实体转换
-		Inbound inbound = inboundConvert.convertToPo(inboundVO);
-		//修改
-		inboundMapper.update(inbound,
-				new UpdateWrapper<Inbound>().lambda()
-						.eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
-		);
-		//endregion
-
-		//region  修改采购订单
-		if (inboundVO.getFromId() != null) {
-			//赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-			Purchase purchase = new Purchase();
-			purchase.setPurId(inboundVO.getFromId());
-			//region  todo 2024年3月20日13:14:51 这里可能用不到
+        //endregion
+//    }
+        //endregion
+
+        //region 删除明细 todo 2024年3月20日13:14:20 这里可能用不到
+//        BigDecimal sumDelIntoQty = BigDecimal.ZERO;
+//        BigDecimal sumDelIntoAmt = BigDecimal.ZERO;
+//        BigDecimal sumDelIntoingQty = BigDecimal.ZERO;
+//        BigDecimal sumDelIntoingAmt = BigDecimal.ZERO;
+        if (inboundVO.getDeleteItemList() != null) {
+//            sumDelIntoQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+//            sumDelIntoAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+//            sumDelIntoingQty = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+//            sumDelIntoingAmt = inboundVO.getDeleteItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+            for (InboundItemVO inboundItemVO : inboundVO.getDeleteItemList()) {
+                if (inboundItemVO.getItemId() != null) {
+                    InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
+                    inboundItem.setFlgValid(false);
+                    //修改
+                    inboundItemMapper.update(inboundItem,
+                            new UpdateWrapper<InboundItem>().lambda()
+                                    .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+                    );
+                }
+                //region  采购
+                if (inboundItemVO.getFromItemId() != null) {
+                    //region 采购订单明细
+                    //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                    PurchaseItem purchaseItem = new PurchaseItem();
+                    purchaseItem.setItemId(inboundItemVO.getFromItemId());
+                    purchaseItem.setIntoingQty(inboundItemVO.getIntoingQty().negate());
+                    purchaseItem.setIntoingAmt(inboundItemVO.getIntoingAmt().negate());
+                    purchaseItem.setIntoQty(inboundItemVO.getIntoQty().negate());
+                    purchaseItem.setIntoAmt(inboundItemVO.getIntoAmt().negate());
+                    //根据id查询
+                    PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemVO.getFromItemId());
+                    //入库状态
+                    String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+                            purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
+                    purchaseItem.setIntoStatus(intoStatus);
+                    int countRow = purchaseItemMapper.updateById(purchaseItem);
+                    //数量超出
+                    if (countRow == 0) {
+                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                    }
+                    //endregion
+                }
+                //endregion
+
+            }
+        }
+        //endregion
+
+        //region 编辑总单
+        BigDecimal sumIntoQty = inboundVO.getItemList().stream().map(InboundItemVO::getIntoQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+        BigDecimal sumIntoAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        inboundVO.setIntoQty(sumIntoQty);
+        inboundVO.setIntoAmt(sumIntoAmt);
+        inboundVO.setIntoingQty(BigDecimal.ZERO);
+        inboundVO.setIntoingAmt(BigDecimal.ZERO);
+//		inboundVO.setIntoingQty(inboundResponse.getIntoingQty());
+//		inboundVO.setIntoingAmt(inboundResponse.getIntoingAmt().subtract(sumIntoAmt));
+        //入库状态
+        String intoStatus = this.setIntoStatus(inboundVO.getIntoingQty(), inboundVO.getIntoQty());
+        inboundVO.setIntoStatus(intoStatus);
+        //实体转换
+        Inbound inbound = inboundConvert.convertToPo(inboundVO);
+        //修改
+        inboundMapper.update(inbound,
+                new UpdateWrapper<Inbound>().lambda().eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+        );
+        //endregion
+
+        //region  修改采购订单
+        if (inboundVO.getFromId() != null) {
+            //赋值(这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            Purchase purchase = new Purchase();
+            purchase.setPurId(inboundVO.getFromId());
+            //region  todo 2024年3月20日13:14:51 这里可能用不到
 //			purchase.setIntoQty(sumIntoQty.subtract(sumDelIntoQty));
 //			purchase.setIntoAmt(sumIntoAmt.subtract(sumDelIntoAmt));
 //			purchase.setIntoingQty((sumIntoingQty.add(sumDelIntoingQty)).negate());
 //			purchase.setIntoingAmt((sumIntoingAmt.add(sumDelIntoingAmt)).negate());
-			//endregion
-			purchase.setIntoQty(sumIntoQty);
-			purchase.setIntoAmt(sumIntoAmt);
-			purchase.setIntoingQty(sumIntoQty.negate());
-			purchase.setIntoingAmt(sumIntoAmt.negate());
-			//根据id查询
-			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
-			//入库状态
-			String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
-					purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
-			purchase.setIntoStatus(purIntoStatus);
-			//修改
-			int countRow = purchaseMapper.updateById(purchase);
-			//数量超出
-			if (countRow == 0) {
-				throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-			}
-		}
-		//endregion
-
-		//todo 如果是已入库 调用库存  后续写库存这里补上
-		//region 修改库存
-
-		//endregion
-		return ResponseResultUtil.success(inboundVO);
-	}
-
-
-	/**
-	 * @desc   : 采购入库撤销
-	 * @date   : 2024/3/7 17:06
-	 * @author : 寇珊珊
-	 */
-	@Transactional(rollbackFor = {Exception.class})
-	public ResponseResultVO<?> purchaseInboundCancel(InboundVO inboundVO) {
-		//region 查询入库总单数据信息
-		InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
-		//endregion
-
-		//region 修改订单数据信息
-		if (inboundResponse.getFromId() != null) {
-			//赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-			Purchase purchase = new Purchase();
-			purchase.setPurId(inboundResponse.getFromId());
-			purchase.setIntoQty(inboundResponse.getIntoQty().negate());
-			purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
-			purchase.setIntoingQty(inboundResponse.getIntoQty());
-			purchase.setIntoingAmt(inboundResponse.getIntoAmt());
-			//根据id查询
-			PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
-			//入库状态
-			String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
-					purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
-			purchase.setIntoStatus(intoStatus);
-			int countRow =  purchaseMapper.updateById(purchase);
-			//数量超出
-			if (countRow == 0) {
-				throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-			}
-		}
-		//endregion
-
-		//region 修改总单数据信息
-		Inbound inbound = new Inbound();
-		inbound.setIntoId(inboundVO.getIntoId());
-		inbound.setIntoDate(null);
-		inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
-		inbound.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
-		inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
-		inbound.setIntoQty(BigDecimal.ZERO);
-		inbound.setIntoAmt(BigDecimal.ZERO);
-		//修改
-		inboundMapper.update(inbound,
-				new UpdateWrapper<Inbound>().lambda()
-						.eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
-		);
-		//endregion
-
-		//region 明细数据
-		//根据总单id查明细
-		List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
-		for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
-			//region 修改采购明细数据信息
-			if(inboundItemResponse.getFromItemId()!=null){
-				//赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
-				PurchaseItem  purchaseItem = new PurchaseItem();
-				purchaseItem.setItemId(inboundItemResponse.getFromItemId());
-				purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
-				purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
-				purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
-				purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
-				//根据id查询
-				PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
-				//入库状态
-				String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
-						purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
-				purchaseItem.setIntoStatus(intoStatus);
-				//修改
-				int countRow = purchaseItemMapper.updateById(purchaseItem);
-				//数量超出
-				if (countRow == 0) {
-					throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
-				}
-			}
-			//endregion
-
-			//region修改入库明细信息
-			InboundItem inboundItem = new InboundItem();
-			inboundItem
-					.setIntoId(inbound.getIntoId())
-					.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
-					.setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
-					.setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
-					.setIntoQty(BigDecimal.ZERO)
-					.setIntoAmt(BigDecimal.ZERO)
-					.setCostPrice(BigDecimal.ZERO)
-					.setCostAmt(BigDecimal.ZERO)
-					.setItemId(inboundItemResponse.getItemId());
-			//修改
-			inboundItemMapper.update(inboundItem,
-					new UpdateWrapper<InboundItem>().lambda()
-							.eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
-			);
-			//endregion
-		}
-		//endregion
-
-
-		//todo 调用库存  后续写库存这里补上
-		//region 修改库存
-
-		//endregion
-
-		return ResponseResultUtil.success();
-	}
-
-
-	/**
-	 * @desc : 入库状态通用(目前本页面)
-	 * @date : 2024/3/9 8:59
-	 * @author : 寇珊珊
-	 */
-	public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
-		//入库状态
-		String intoStatus = null;
-		//已入库数量>0 入库中数量>0
-		if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0 ) {
-			//入库中
-			intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
-		}
-		//已入库数量=0 入库中数量=0
-		else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
-			//待入库
-			intoStatus = Constant.IntoStatus.DAIRUKU.getName();
-		}
-		//已入库数量>0 入库中数量=0
-		else if (intoQty.compareTo(BigDecimal.ZERO) >0 && intoingQty.compareTo(BigDecimal.ZERO)==0) {
-			//已入库
-			intoStatus = Constant.IntoStatus.YIRUKU.getName();
-		}
-		return intoStatus;
-	}
-	
+            //endregion
+            purchase.setIntoQty(sumIntoQty);
+            purchase.setIntoAmt(sumIntoAmt);
+            //todo 2024年3月25日14:50:41  取
+            if (inboundResponse != null) {
+                purchase.setIntoingQty(inboundResponse.getIntoingQty().negate());
+                purchase.setIntoingAmt(inboundResponse.getIntoingAmt().negate());
+            }
+//            purchase.setIntoingQty(sumIntoQty.negate());
+//            purchase.setIntoingAmt(sumIntoAmt.negate());
+            //根据id查询
+            PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
+            //入库状态
+            String purIntoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
+                    purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
+            purchase.setIntoStatus(purIntoStatus);
+            //修改
+            int countRow = purchaseMapper.updateById(purchase);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+            }
+        }
+        //endregion
+
+        //todo 如果是已入库 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
+        return ResponseResultUtil.success(inboundVO);
+    }
+
+
+    /**
+     * @desc : 采购入库撤销
+     * @date : 2024/3/7 17:06
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public ResponseResultVO<?> purchaseInboundCancel(InboundVO inboundVO) {
+        //region 查询入库总单数据信息
+        InboundResponse inboundResponse = inboundMapper.selectById(inboundVO.getIntoId());
+        //endregion
+
+        //region 修改订单数据信息
+        if (inboundResponse.getFromId() != null) {
+            //赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+            Purchase purchase = new Purchase();
+            purchase.setPurId(inboundResponse.getFromId());
+            purchase.setIntoQty(inboundResponse.getIntoQty().negate());
+            purchase.setIntoAmt(inboundResponse.getIntoAmt().negate());
+            purchase.setIntoingQty(inboundResponse.getIntoQty());
+            purchase.setIntoingAmt(inboundResponse.getIntoAmt());
+            //根据id查询
+            PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundVO.getFromId());
+            //入库状态
+            String intoStatus = this.setIntoStatus(purchaseResponse.getIntoingQty().add(purchase.getIntoingQty()),
+                    purchaseResponse.getIntoQty().add(purchase.getIntoQty()));
+            purchase.setIntoStatus(intoStatus);
+            int countRow = purchaseMapper.updateById(purchase);
+            //数量超出
+            if (countRow == 0) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+            }
+        }
+        //endregion
+
+        //region 修改总单数据信息
+        Inbound inbound = new Inbound();
+        inbound.setIntoId(inboundVO.getIntoId());
+        inbound.setIntoDate(null);
+        inbound.setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName());
+        inbound.setIntoingQty(inboundResponse.getIntoingQty().add(inboundResponse.getIntoQty()));
+        inbound.setIntoingAmt(inboundResponse.getIntoingAmt().add(inboundResponse.getIntoAmt()));
+        inbound.setIntoQty(BigDecimal.ZERO);
+        inbound.setIntoAmt(BigDecimal.ZERO);
+        //修改
+        inboundMapper.update(inbound,
+                new UpdateWrapper<Inbound>().lambda()
+                        .eq(Inbound::getIntoId, UUID.fromString(inbound.getIntoId()))
+        );
+        //endregion
+
+        //region 明细数据
+        //根据总单id查明细
+        List<InboundItemResponse> orderEntryItemResponsesList = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inbound.getIntoId()));
+        for (InboundItemResponse inboundItemResponse : orderEntryItemResponsesList) {
+            //region 修改采购明细数据信息
+            if (inboundItemResponse.getFromItemId() != null) {
+                //赋值  (这里重写了更新方法,数量在更新方法中有数据库院士数量+本次数量)
+                PurchaseItem purchaseItem = new PurchaseItem();
+                purchaseItem.setItemId(inboundItemResponse.getFromItemId());
+                purchaseItem.setIntoQty(inboundItemResponse.getIntoQty().negate());
+                purchaseItem.setIntoAmt(inboundItemResponse.getIntoAmt().negate());
+                purchaseItem.setIntoingQty(inboundItemResponse.getIntoQty());
+                purchaseItem.setIntoingAmt(inboundItemResponse.getIntoAmt());
+                //根据id查询
+                PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemResponse.getFromItemId());
+                //入库状态
+                String intoStatus = this.setIntoStatus(purchaseItemResponse.getIntoingQty().add(purchaseItem.getIntoingQty()),
+                        purchaseItemResponse.getIntoQty().add(purchaseItem.getIntoQty()));
+                purchaseItem.setIntoStatus(intoStatus);
+                //修改
+                int countRow = purchaseItemMapper.updateById(purchaseItem);
+                //数量超出
+                if (countRow == 0) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.INVENTORY_QUANTITY_EXCEEDED.getMessage());
+                }
+            }
+            //endregion
+
+            //region修改入库明细信息
+            InboundItem inboundItem = new InboundItem();
+            inboundItem
+                    .setIntoId(inbound.getIntoId())
+                    .setIntoStatus(Constant.IntoStatus.RUKUZHONG.getName())
+                    .setIntoingQty(inboundItemResponse.getIntoingQty().add(inboundItemResponse.getIntoQty()))
+                    .setIntoingAmt(inboundItemResponse.getIntoingAmt().add(inboundItemResponse.getIntoAmt()))
+                    .setIntoQty(BigDecimal.ZERO)
+                    .setIntoAmt(BigDecimal.ZERO)
+                    .setCostPrice(BigDecimal.ZERO)
+                    .setCostAmt(BigDecimal.ZERO)
+                    .setItemId(inboundItemResponse.getItemId());
+            //修改
+            inboundItemMapper.update(inboundItem,
+                    new UpdateWrapper<InboundItem>().lambda()
+                            .eq(InboundItem::getItemId, UUID.fromString(inboundItem.getItemId()))
+            );
+            //endregion
+        }
+        //endregion
+
+
+        //todo 调用库存  后续写库存这里补上
+        //region 修改库存
+
+        //endregion
+
+        return ResponseResultUtil.success();
+    }
+
+
+    /**
+     * @desc : 入库状态通用(目前本页面)
+     * @date : 2024/3/9 8:59
+     * @author : 寇珊珊
+     */
+    public String setIntoStatus(BigDecimal intoingQty, BigDecimal intoQty) {
+        //入库状态
+        String intoStatus = null;
+        //已入库数量>0 入库中数量>0
+        if (intoQty.compareTo(BigDecimal.ZERO) >= 0 && intoingQty.compareTo(BigDecimal.ZERO) > 0) {
+            //入库中
+            intoStatus = Constant.IntoStatus.RUKUZHONG.getName();
+        }
+        //已入库数量=0 入库中数量=0
+        else if (intoQty.compareTo(BigDecimal.ZERO) == 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
+            //待入库
+            intoStatus = Constant.IntoStatus.DAIRUKU.getName();
+        }
+        //已入库数量>0 入库中数量=0
+        else if (intoQty.compareTo(BigDecimal.ZERO) > 0 && intoingQty.compareTo(BigDecimal.ZERO) == 0) {
+            //已入库
+            intoStatus = Constant.IntoStatus.YIRUKU.getName();
+        }
+        return intoStatus;
+    }
+
 }

+ 0 - 3
src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java

@@ -76,9 +76,6 @@ public class InventoryService extends BaseService<Inventory> {
     private InventoryBatchMapper inventoryBatchMapper;
 
     @Autowired
-    private InventoryBatchConvert  inventoryBatchConvert;
-
-    @Autowired
     private OutboundItemCostMapper outboundItemCostMapper;