Explorar o código

Merge remote-tracking branch 'origin/master'

dongke %!s(int64=2) %!d(string=hai) anos
pai
achega
a6fe825eef
Modificáronse 28 ficheiros con 1522 adicións e 506 borrados
  1. 3 2
      src/main/java/com/dk/mdm/controller/FileController.java
  2. 10 0
      src/main/java/com/dk/mdm/controller/report/ReportController.java
  3. 9 0
      src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.java
  4. 10 0
      src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.xml
  5. 11 0
      src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.java
  6. 10 0
      src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.xml
  7. 22 1
      src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.java
  8. 151 87
      src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.xml
  9. 1 1
      src/main/java/com/dk/mdm/mapper/mac/AccountMapper.xml
  10. 5 0
      src/main/java/com/dk/mdm/mapper/mac/RecPayHandleItemMapper.xml
  11. 7 0
      src/main/java/com/dk/mdm/mapper/report/ReportMapper.java
  12. 111 23
      src/main/java/com/dk/mdm/mapper/report/ReportMapper.xml
  13. 1 1
      src/main/java/com/dk/mdm/mapper/sale/OrderMapper.xml
  14. 8 0
      src/main/java/com/dk/mdm/model/pojo/mac/AccountItem.java
  15. 10 0
      src/main/java/com/dk/mdm/model/query/mac/AccountItemQuery.java
  16. 8 0
      src/main/java/com/dk/mdm/model/response/mac/AccountItemResponse.java
  17. 3 0
      src/main/java/com/dk/mdm/model/vo/ivt/InboundItemVO.java
  18. 91 62
      src/main/java/com/dk/mdm/service/ivt/TransferService.java
  19. 172 112
      src/main/java/com/dk/mdm/service/ivt/inbound/InboundCheckService.java
  20. 22 10
      src/main/java/com/dk/mdm/service/ivt/inbound/InboundOtherService.java
  21. 486 137
      src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java
  22. 62 0
      src/main/java/com/dk/mdm/service/ivt/outbound/OutboundCheckService.java
  23. 16 16
      src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java
  24. 245 28
      src/main/java/com/dk/mdm/service/mac/AccountService.java
  25. 7 7
      src/main/java/com/dk/mdm/service/mac/ReceiptService.java
  26. 1 0
      src/main/java/com/dk/mdm/service/mst/StaffService.java
  27. 14 0
      src/main/java/com/dk/mdm/service/report/ReportService.java
  28. 26 19
      src/main/java/com/dk/mdm/service/sale/OrderService.java

+ 3 - 2
src/main/java/com/dk/mdm/controller/FileController.java

@@ -15,6 +15,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.File;
 import java.io.IOException;
 import java.time.LocalDateTime;
+import java.util.Optional;
 import java.util.UUID;
 
 @RestController
@@ -34,14 +35,14 @@ public class FileController {
      */
     @ApiOperation(value = "上传文件", notes = "上传文件")
     @PostMapping("upload")
-    public ResponseResultVO<?> upload(@RequestPart("file") MultipartFile file, @RequestParam("folder") String folder) {
+    public ResponseResultVO<?> upload(@RequestPart("file") MultipartFile file, @RequestParam("folder") String folder,@RequestParam(required=false) String uuid) {
         if (file.isEmpty()) {
             return ResponseResultUtil.error(ErrorCodeEnum.FILE_UPLOAD_FAIL.getCode(), ErrorCodeEnum.FILE_UPLOAD_FAIL.getMessage());
         }
 
         //生产文件名称
         String fileName = file.getOriginalFilename();
-        String uuidName = UUID.randomUUID().toString() + "." + fileName.substring(fileName.lastIndexOf(".") + 1);
+        String uuidName = Optional.ofNullable(uuid).orElse(UUID.randomUUID().toString()) + "." + fileName.substring(fileName.lastIndexOf(".") + 1);
         String filePath = this.createDirByPath(folder) + uuidName;
         File dest = new File(filePath);
 

+ 10 - 0
src/main/java/com/dk/mdm/controller/report/ReportController.java

@@ -79,6 +79,16 @@ public class ReportController  {
     public ResponseResultVO<List<Map<String, Object>>> getInboundDetailReport(@RequestBody Map<String, Object> param) {
         return reportService.getInboundDetailReport(param);
     }
+
+    /**
+     * @desc   : 客户收款明细表
+     * @author : 宋扬
+     * @date   : 2024/4/16 11:27
+     */
+    @PostMapping("rec_pay_detail_report")
+    public ResponseResultVO<List<Map<String, Object>>> getRecPayDetailReport(@RequestBody Map<String, Object> param) {
+        return reportService.getRecPayDetailReport(param);
+    }
 }
 
 

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

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

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

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

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

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

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

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

+ 22 - 1
src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.java

@@ -35,11 +35,32 @@ public interface AccountItemMapper extends BaseMapper<AccountItem>{
     List<AccountItemResponse> getPayableAccountItem(AccountItemQuery accountItemQuery);
 
     /**
+     * @desc : 查询应收账款明细(锁表)
+     * @author : 付斌
+     * @date : 2024-02-28 10:18
+     */
+    List<AccountItemResponse> getReceivableAccountItemForUpdate(AccountItemQuery accountItemQuery);
+
+    /**
      * @desc   : 查询收款总额
      * @author : 付斌
      * @date   : 2024-03-09 11:36
      */
-    Map<String, Object> getSumAmtRecPay(String id);
+    Map<String, Object> getSumAmtRec(String id);
+
+    /**
+     * @desc   : 查询收款总额(锁定金额)
+     * @author : 付斌
+     * @date   : 2024-03-09 11:36
+     */
+    Map<String, Object> getSumAmtRecLock(String id);
+
+    /**
+     * @desc   : 查询付款总额
+     * @author : 付斌
+     * @date   : 2024-03-09 11:36
+     */
+    Map<String, Object> getSumAmtPay(String id);
 
     /**
      * @desc   : 查询订单未出库金额

+ 151 - 87
src/main/java/com/dk/mdm/mapper/mac/AccountItemMapper.xml

@@ -5,8 +5,7 @@
     <!-- 通用设置 -->
     <!-- 通用查询列 -->
     <sql id="Base_Column_List">
-        item_id
-        , acc_item_type, object_id, org_id, staff_id, biznis_type, biznis_id, biznis_no, acc_date, rec_status, amt_rec, amt_pay, amt_should, amt_handle, amt_waive, amt_residue, remarks, make_staff, make_time, flg_valid, cp_id
+        item_id, acc_item_type, object_id, org_id, staff_id, biznis_type, biznis_id, biznis_no, acc_date, rec_status, amt_rec, amt_pay, amt_should, amt_handle, amt_waive, amt_residue, flg_lock, remarks, make_staff, make_time, flg_valid, cp_id
     </sql>
 
     <!-- 通用查询映射结果 -->
@@ -27,6 +26,7 @@
         <result column="amt_handle" property="amtHandle"/>
         <result column="amt_waive" property="amtWaive"/>
         <result column="amt_residue" property="amtResidue"/>
+        <result column="flg_lock" property="flgLock"/>
         <result column="remarks" property="remarks"/>
         <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
         <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
@@ -52,6 +52,7 @@
         <result column="amt_handle" property="amtHandle"/>
         <result column="amt_waive" property="amtWaive"/>
         <result column="amt_residue" property="amtResidue"/>
+        <result column="flg_lock" property="flgLock"/>
         <result column="remarks" property="remarks"/>
         <result column="make_staff" property="makeStaff" typeHandler="UuidTypeHandler"/>
         <result column="make_time" property="makeTime" typeHandler="TimestampTypeHandler"/>
@@ -112,6 +113,9 @@
         <if test="amtResidue != null">
             AND t.amt_residue = #{amtResidue}
         </if>
+        <if test="flgLock != null">
+            AND t.flg_lock = #{flgLock}
+        </if>
         <if test="remarks != null and remarks != ''">
             AND t.remarks = #{remarks}
         </if>
@@ -131,6 +135,9 @@
         <if test="formType == 'refund'">
             AND t.amt_residue <![CDATA[ < ]]> 0
         </if>
+        <if test="orderId != null">
+            AND tpo.from_id = #{orderId}::uuid
+        </if>
     </sql>
 
     <sql id="idsForeach">
@@ -187,48 +194,48 @@
     <!-- 查询应收账款明细 -->
     <select id="getReceivableAccountItem" resultMap="BaseResultMapResponse">
         SELECT t.item_id,
-        t.item_id as "accItemId",
-        t.acc_item_type,
-        t.object_id,
-        tmc.cus_code as "cusCode",
-        tmc.cus_name as "cusName",
-        tmc.cus_phone as "cusPhone",
-        tmc.address_full as "addressFull",
-        t.org_id,
-        tmo.org_name as "orgName",
-        t.staff_id,
-        tms.staff_name as "staffName",
-        t.biznis_type,
-        t.biznis_id,
-        t.biznis_no,
-        t.acc_date,
-        t.rec_status,
-        sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
-        coalesce(sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}), '其他收入') as "biznisTypeName",
-        t.amt_rec,
-        t.amt_pay,
-        t.amt_should,
-        t.amt_handle,
-        t.amt_waive,
-        t.amt_residue as "amtNotHandle",
-        t.amt_residue as "amtReceivableHandle",
-        t.amt_residue,
-        t.remarks,
-        t.make_staff,
-        t.make_time,
-        t.flg_valid,
-        t.cp_id
+               t.item_id        as "accItemId",
+               t.acc_item_type,
+               t.object_id,
+               tmc.cus_code     as "cusCode",
+               tmc.cus_name     as "cusName",
+               tmc.cus_phone    as "cusPhone",
+               tmc.address_full as "addressFull",
+               t.org_id,
+               tmo.org_name     as "orgName",
+               t.staff_id,
+               tms.staff_name   as "staffName",
+               t.biznis_type,
+               t.biznis_id,
+               t.biznis_no,
+               t.acc_date,
+               t.rec_status,
+               sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
+               coalesce(sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}), '其他收入') as "biznisTypeName",
+               t.amt_rec,
+               t.amt_pay,
+               t.amt_should,
+               t.amt_handle,
+               t.amt_waive,
+               t.amt_residue    as "amtNotHandle",
+               t.amt_residue    as "amtReceivableHandle",
+               t.amt_residue,
+               t.remarks,
+               t.make_staff,
+               t.make_time,
+               t.flg_valid,
+               t.cp_id
         FROM dkic_b.t_mac_account_item as t
-        left join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
-        LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpo.out_type
-        left join dkic_b.t_mac_other_receivable as tmor
-        on tmor.receivable_id = t.biznis_id and t.biznis_type = 't_mac_other_receivable'
-        left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
-        left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
-        left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
-        left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
+                 left join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
+                 LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpo.out_type
+                 left join dkic_b.t_mac_other_receivable as tmor
+                           on tmor.receivable_id = t.biznis_id and t.biznis_type = 't_mac_other_receivable'
+                 left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
+                 left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
+                 left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
+                 left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
         where t.flg_valid
-        and t.acc_item_type = '账款类型-应收'
+          and t.acc_item_type = '账款类型-应收'
         and t.amt_residue <![CDATA[ <> ]]> 0
         <include refid="Condition"/>
         order by t.acc_date
@@ -240,45 +247,45 @@
     <!-- 查询应付账款明细 -->
     <select id="getPayableAccountItem" resultMap="BaseResultMapResponse">
         SELECT t.item_id,
-        t.item_id as "accItemId",
-        t.acc_item_type,
-        t.object_id,
-        supplier.sup_code as "supCode",
-        supplier.sup_name as "supName",
-        t.org_id,
-        tmo.org_name as "orgName",
-        t.staff_id,
-        tms.staff_name as "staffName",
-        t.biznis_type,
-        t.biznis_id,
-        t.biznis_no,
-        t.acc_date,
-        t.rec_status,
-        sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
-        sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "biznisTypeName",
-        t.amt_rec,
-        t.amt_pay,
-        t.amt_should,
-        t.amt_handle,
-        t.amt_waive,
-        t.amt_residue,
-        t.amt_residue as "amtNotHandle",
-        t.amt_residue as "amtPayableHandle",
-        t.remarks,
-        t.make_staff,
-        t.make_time,
-        t.flg_valid,
-        t.cp_id
+               t.item_id         as "accItemId",
+               t.acc_item_type,
+               t.object_id,
+               supplier.sup_code as "supCode",
+               supplier.sup_name as "supName",
+               t.org_id,
+               tmo.org_name      as "orgName",
+               t.staff_id,
+               tms.staff_name    as "staffName",
+               t.biznis_type,
+               t.biznis_id,
+               t.biznis_no,
+               t.acc_date,
+               t.rec_status,
+               sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "recStatusName",
+               sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "biznisTypeName",
+               t.amt_rec,
+               t.amt_pay,
+               t.amt_should,
+               t.amt_handle,
+               t.amt_waive,
+               t.amt_residue,
+               t.amt_residue     as "amtNotHandle",
+               t.amt_residue     as "amtPayableHandle",
+               t.remarks,
+               t.make_staff,
+               t.make_time,
+               t.flg_valid,
+               t.cp_id
         FROM dkic_b.t_mac_account_item as t
-        left join dkic_b.t_psi_inbound as tpi on tpi.into_id = t.biznis_id and t.biznis_type = 't_psi_inbound'
-        LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpi.into_type
-        left join dkic_b.t_mst_supplier supplier on supplier.sup_id = t.object_id
-        left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
-        left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
-        left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
+                 left join dkic_b.t_psi_inbound as tpi on tpi.into_id = t.biznis_id and t.biznis_type = 't_psi_inbound'
+                 LEFT JOIN sys.t_data_kind tdk2 ON tdk2.kind_code = tpi.into_type
+                 left join dkic_b.t_mst_supplier supplier on supplier.sup_id = t.object_id
+                 left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
+                 left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
+                 left join sys.t_data_kind as tdk1 on t.rec_status = tdk1.kind_code
         where t.flg_valid
-        and t.acc_item_type = '账款类型-应付'
-        and t.amt_residue <![CDATA[ <> ]]> 0
+          and t.acc_item_type = '账款类型-应付'
+          and t.amt_residue <![CDATA[<>]]> 0
         <include refid="Condition"/>
         order by t.acc_date
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
@@ -286,6 +293,43 @@
         </if>
     </select>
 
+    <!-- 查询应收账款明细 -->
+    <select id="getReceivableAccountItemForUpdate" resultMap="BaseResultMapResponse">
+        SELECT t.item_id,
+               t.item_id     as "accItemId",
+               t.acc_item_type,
+               t.object_id,
+               t.org_id,
+               t.staff_id,
+               t.biznis_type,
+               t.biznis_id,
+               t.biznis_no,
+               t.acc_date,
+               t.rec_status,
+               t.amt_rec,
+               t.amt_pay,
+               t.amt_should,
+               t.amt_handle,
+               t.amt_waive,
+               t.amt_residue as "amtNotHandle",
+               t.amt_residue as "amtReceivableHandle",
+               t.amt_residue,
+               t.remarks,
+               t.make_staff,
+               t.make_time,
+               t.flg_valid,
+               t.cp_id
+        FROM dkic_b.t_mac_account_item as t
+                 inner join dkic_b.t_psi_outbound as tpo on tpo.out_id = t.biznis_id and t.biznis_type = 't_psi_outbound'
+        where t.flg_valid
+          and t.acc_item_type = '账款类型-应收'
+          and t.amt_residue <![CDATA[<>]]> 0
+          AND t.object_id = #{objectId}::uuid
+          AND tpo.from_id = #{orderId}::uuid
+        order by t.acc_date
+            for update
+    </select>
+
     <!-- 根据主键查询表t_mac_account_item的一行数据 -->
     <select id="selectById" resultMap="BaseResultMap">
         SELECT
@@ -368,12 +412,32 @@
     </insert>
 
     <!-- 查询收款总额 -->
-    <select id="getSumAmtRecPay" resultType="java.util.Map">
-        SELECT COALESCE(sum(tmai.amt_rec), 0) as "sumAmtRec",
-               COALESCE(sum(tmai.amt_pay), 0) as "sumAmtPay"
-        FROM dkic_b.t_mac_account_item as tmai
-        where tmai.flg_valid
-          and tmai.object_id = #{id}::uuid
+    <select id="getSumAmtRec" resultType="java.util.Map">
+        SELECT COALESCE(sum(t.amt_rec), 0) as "sumAmtRec"
+        FROM dkic_b.t_mac_account_item as t
+        where t.flg_valid
+          and t.flg_lock = false
+          and t.acc_item_type = '账款类型-收款'
+          and t.object_id = #{id}::uuid
+    </select>
+
+    <!-- 查询收款总额(锁定金额) -->
+    <select id="getSumAmtRecLock" resultType="java.util.Map">
+        SELECT COALESCE(sum(t.amt_rec), 0) as "sumAmtRecLock"
+        FROM dkic_b.t_mac_account_item as t
+        where t.flg_valid
+          and t.flg_lock
+          and t.acc_item_type = '账款类型-收款'
+          and t.object_id = #{id}::uuid
+    </select>
+
+    <!-- 查询付款总额 -->
+    <select id="getSumAmtPay" resultType="java.util.Map">
+        SELECT COALESCE(sum(t.amt_pay), 0) as "sumAmtPay"
+        FROM dkic_b.t_mac_account_item as t
+        where t.flg_valid
+          and t.acc_item_type = '账款类型-付款'
+          and t.object_id = #{id}::uuid
     </select>
 
     <!-- 查询订单未出库金额  -->
@@ -381,7 +445,7 @@
         SELECT COALESCE(sum(tpo.sum_amount - tpo.out_amt), 0) as "sumAmtOrder"
         FROM dkic_b.t_psi_order as tpo
         where tpo.flg_valid
-          and tpo.out_status in('出库状态-出库中','出库状态-待出库')
+          and tpo.out_status in ('出库状态-出库中', '出库状态-待出库')
           and tpo.cus_id = #{id}::uuid
     </select>
 
@@ -390,7 +454,7 @@
         SELECT COALESCE(sum(tpp.sum_amount - tpp.into_amt), 0) as "sumAmtPur"
         FROM dkic_b.t_psi_purchase as tpp
         where tpp.flg_valid
-          and tpp.into_status in('入库状态-待入库','入库状态-入库中')
+          and tpp.into_status in ('入库状态-待入库', '入库状态-入库中')
           and tpp.sup_id = #{id}::uuid
     </select>
 

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

@@ -154,7 +154,7 @@
                t.remarks,
                t.flg_valid,
                t.cp_id,
-               t.receipt - t.receivable as "receivableBalance"
+               t.receivable - t.receipt as "receivableBalance"
         FROM dkic_b.t_mac_account as t
         <include refid="Condition"/>
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">

+ 5 - 0
src/main/java/com/dk/mdm/mapper/mac/RecPayHandleItemMapper.xml

@@ -171,4 +171,9 @@
             )
         </foreach>
     </insert>
+
+    <delete id="deleteById">
+        DELETE FROM dkic_b.t_mac_rec_pay_handle_item
+        WHERE item_id = #{id}::uuid;
+    </delete>
 </mapper>

+ 7 - 0
src/main/java/com/dk/mdm/mapper/report/ReportMapper.java

@@ -79,4 +79,11 @@ public interface ReportMapper extends BaseMapper<JSONObject> {
      * @date   : 2024/4/11 16:56
      */
     List<Map<String, Object>> getInboundDetailReport(Map param);
+
+    /**
+     * @desc   : 客户收款明细表(主表)
+     * @author : 宋扬
+     * @date   : 2024/4/16 11:30
+     */
+    List<Map<String, Object>> getRecPayDetailReport(Map param);
 }

+ 111 - 23
src/main/java/com/dk/mdm/mapper/report/ReportMapper.xml

@@ -69,6 +69,12 @@
             <if test="purNo != null and purNo != ''">
                 AND tpp.pur_no like concat('%', my_ex.likequery(#{purNo}) , '%')
             </if>
+            <if test="purTypeList != null and purTypeList.size()>0">
+                AND tpp.pur_type =any(#{purTypeList,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="purStatusList != null and purStatusList.size()>0">
+                AND tpp.pur_status =any(#{purStatusList,typeHandler=StringListTypeHandler})
+            </if>
             <if test="supIdlist != null and supIdlist.size()>0">
                 AND tpp.sup_id = any(#{supIdlist,typeHandler=UuidListTypeHandler})
             </if>
@@ -125,6 +131,12 @@
             <if test="purNo != null and purNo != ''">
                 AND tpp.pur_no like concat('%', my_ex.likequery(#{purNo}) , '%')
             </if>
+            <if test="purTypeList != null and purTypeList.size()>0">
+                AND tpp.pur_type =any(#{purTypeList,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="purStatusList != null and purStatusList.size()>0">
+                AND tpp.pur_status =any(#{purStatusList,typeHandler=StringListTypeHandler})
+            </if>
             <if test="supIdlist != null and supIdlist.size()>0">
                 AND tpp.sup_id = any(#{supIdlist,typeHandler=UuidListTypeHandler})
             </if>
@@ -163,6 +175,9 @@
             <if test="orderNo != null and orderNo != ''">
                 AND t.order_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%')
             </if>
+            <if test="ordTypeList != null and ordTypeList.size()>0">
+                AND t.ord_type =any(#{ordTypeList,typeHandler=StringListTypeHandler})
+            </if>
             <if test="addressFull != null and addressFull != ''">
                 AND t.address_full LIKE concat('%',my_ex.likequery(#{addressFull}),'%')
             </if>
@@ -190,8 +205,8 @@
             <if test="staffIdList != null and staffIdList.size() > 0">
                 AND t.staff_id  =any(#{staffIdList, typeHandler=uuidListTypeHandler})
             </if>
-            <if test="outStatusList != null and outStatusList.size() > 0">
-                AND t.out_status  =any(#{outStatusList, typeHandler=StringListTypeHandler})
+            <if test="ordStatusList != null and ordStatusList.size() > 0">
+                AND t.ord_status  =any(#{ordStatusList, typeHandler=StringListTypeHandler})
             </if>
             <if test="deliveryDateStart != null and deliveryDateEnd != null">
                 AND t.delivery_date &gt;= #{deliveryDateStart}::timestamp with time zone
@@ -232,6 +247,12 @@
             <if test="orderNo != null and orderNo != ''">
                 AND t.order_no LIKE concat('%',my_ex.likequery(#{orderNo}),'%')
             </if>
+            <if test="ordTypeList != null and ordTypeList.size()>0">
+                AND t.ord_type =any(#{ordTypeList,typeHandler=StringListTypeHandler})
+            </if>
+            <if test="ordStatusList != null and ordStatusList.size() > 0">
+                AND t.ord_status  =any(#{ordStatusList, typeHandler=StringListTypeHandler})
+            </if>
             <if test="addressFull != null and addressFull != ''">
                 AND t.address_full LIKE concat('%',my_ex.likequery(#{addressFull}),'%')
             </if>
@@ -259,9 +280,6 @@
             <if test="staffIdList != null and staffIdList.size() > 0">
                 AND t.staff_id  =any(#{staffIdList, typeHandler=uuidListTypeHandler})
             </if>
-            <if test="outStatusList != null and outStatusList.size() > 0">
-                AND t.out_status  =any(#{outStatusList, typeHandler=StringListTypeHandler})
-            </if>
             <if test="deliveryDateStart != null and deliveryDateEnd != null">
                 AND t.delivery_date &gt;= #{deliveryDateStart}::timestamp with time zone
                 AND t.delivery_date &lt; #{deliveryDateEnd}::timestamp with time zone + interval '1 day'
@@ -389,8 +407,8 @@
             <if test="cpId != null">
                 AND t.cp_id = #{cpId}
             </if>
-            <if test="outNo != null and outNo != ''">
-                AND t.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
+            <if test="intoNo != null and intoNo != ''">
+                AND t.into_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
             </if>
             <if test="supIdlist != null and supIdlist.size()>0">
                 AND t.sup_id = any(#{supIdlist,typeHandler=UuidListTypeHandler})
@@ -398,8 +416,8 @@
             <if test="contactPhone != null and contactPhone != ''">
                 AND t.contact_phone LIKE concat('%',my_ex.likequery(#{contactPhone}),'%')
             </if>
-            <if test="outTypeList != null and outTypeList.size()>0">
-                AND t.out_type =any(#{outTypeList,typeHandler=StringListTypeHandler})
+            <if test="intoTypeList != null and intoTypeList.size()>0">
+                AND t.into_type =any(#{intoTypeList,typeHandler=StringListTypeHandler})
             </if>
             <if test="fromNo != null and fromNo != ''">
                 AND t.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
@@ -413,12 +431,12 @@
             <if test="staffIdList != null and staffIdList.size() > 0">
                 AND t.staff_id  =any(#{staffIdList, typeHandler=uuidListTypeHandler})
             </if>
-            <if test="outStatusList != null and outStatusList.size() > 0">
-                AND t.out_status  =any(#{outStatusList, typeHandler=StringListTypeHandler})
+            <if test="intoStatusList != null and intoStatusList.size() > 0">
+                AND t.into_status  =any(#{intoStatusList, typeHandler=StringListTypeHandler})
             </if>
-            <if test="outDateStart != null and outDateEnd != null">
-                AND t.out_date &gt;= #{outDateStart}::timestamp with time zone
-                AND t.out_date &lt; #{outDateEnd}::timestamp with time zone + interval '1 day'
+            <if test="intoDateStart != null and intoDateEnd != null">
+                AND t.into_date &gt;= #{intoDateStart}::timestamp with time zone
+                AND t.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
             </if>
             <if test="makeTimeStart != null and makeTimeEnd != null">
                 AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
@@ -455,8 +473,8 @@
             <if test="cpId != null">
                 AND t.cp_id = #{cpId}
             </if>
-            <if test="outNo != null and outNo != ''">
-                AND t.out_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
+            <if test="intoNo != null and intoNo != ''">
+                AND t.into_no LIKE concat('%',my_ex.likequery(#{outNo}),'%')
             </if>
             <if test="supIdlist != null and supIdlist.size()>0">
                 AND t.sup_id = any(#{supIdlist,typeHandler=UuidListTypeHandler})
@@ -464,8 +482,8 @@
             <if test="contactPhone != null and contactPhone != ''">
                 AND t.contact_phone LIKE concat('%',my_ex.likequery(#{contactPhone}),'%')
             </if>
-            <if test="outTypeList != null and outTypeList.size()>0">
-                AND t.out_type =any(#{outTypeList,typeHandler=StringListTypeHandler})
+            <if test="intoTypeList != null and intoTypeList.size()>0">
+                AND t.into_type =any(#{intoTypeList,typeHandler=StringListTypeHandler})
             </if>
             <if test="fromNo != null and fromNo != ''">
                 AND t.from_no LIKE concat('%',my_ex.likequery(#{fromNo}),'%')
@@ -479,12 +497,48 @@
             <if test="staffIdList != null and staffIdList.size() > 0">
                 AND t.staff_id  =any(#{staffIdList, typeHandler=uuidListTypeHandler})
             </if>
-            <if test="outStatusList != null and outStatusList.size() > 0">
-                AND t.out_status  =any(#{outStatusList, typeHandler=StringListTypeHandler})
+            <if test="intoStatusList != null and intoStatusList.size() > 0">
+                AND t.into_status  =any(#{intoStatusList, typeHandler=StringListTypeHandler})
             </if>
-            <if test="outDateStart != null and outDateEnd != null">
-                AND t.out_date &gt;= #{outDateStart}::timestamp with time zone
-                AND t.out_date &lt; #{outDateEnd}::timestamp with time zone + interval '1 day'
+            <if test="intoDateStart != null and intoDateEnd != null">
+                AND t.into_date &gt;= #{intoDateStart}::timestamp with time zone
+                AND t.into_date &lt; #{intoDateEnd}::timestamp with time zone + interval '1 day'
+            </if>
+            <if test="makeTimeStart != null and makeTimeEnd != null">
+                AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
+                AND t.make_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
+            </if>
+        </where>
+    </sql>
+
+    <!-- 客户收款明细表条件列 -->
+    <sql id="Condition_RecPayDetailReport">
+        <where>
+            t.rp_type in ('收付款类型-收款', '收付款类型-退收款')
+            <if test="cpId != null">
+                AND t.cp_id = #{cpId}
+            </if>
+            <if test="rpNo != null and rpNo != ''">
+                AND t.rp_no LIKE concat('%',my_ex.likequery(#{rpNo}),'%')
+            </if>
+            <if test="contactPhone != null and contactPhone != ''">
+                AND t.contact_phone LIKE concat('%',my_ex.likequery(#{contactPhone}),'%')
+            </if>
+            <if test="biznisNo != null and biznisNo != ''">
+                AND t.biznis_no LIKE concat('%',my_ex.likequery(#{biznisNo}),'%')
+            </if>
+            <if test="cusName != null and cusName != ''">
+                AND tmc.cus_name LIKE concat('%',my_ex.likequery(#{cusName}),'%')
+            </if>
+            <if test="orgIdList != null and orgIdList.size() > 0">
+                AND t.org_id  =any(#{orgIdList, typeHandler=uuidListTypeHandler})
+            </if>
+            <if test="staffIdList != null and staffIdList.size() > 0">
+                AND t.staff_id  =any(#{staffIdList, typeHandler=uuidListTypeHandler})
+            </if>
+            <if test="accDateStart != null and accDateEnd != null">
+                AND t.acc_date &gt;= #{accDateStart}::timestamp with time zone
+                AND t.acc_date &lt; #{accDateEnd}::timestamp with time zone + interval '1 day'
             </if>
             <if test="makeTimeStart != null and makeTimeEnd != null">
                 AND t.make_time &gt;= #{makeTimeStart}::timestamp with time zone
@@ -503,6 +557,7 @@
         ,tmp.sup_name as "supplierName"
         ,tpp.pickup_date as "pickupDate"
         ,sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "purStatusName"
+        ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "purTypeName"
         ,tpp.contact_name as "contactName"
         ,tpp.contact_phone as "contactPhone"
         ,tpp.intoing_qty as "intoingQtySum"
@@ -521,6 +576,7 @@
         Left join dkic_b.t_mst_staff tms1 on tpp.make_staff = tms1.staff_id
         Left join dkic_b.t_mst_warehouse tmw on tpp.wh_id = tmw.wh_id
         left join sys.t_data_kind tdk2 on tdk2.kind_code = tpp.pur_status
+        left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.pur_type
         <include refid="Condition_PurReport"/>
         order by  tpp.op_create_time desc
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
@@ -538,6 +594,7 @@
         ,tmp.sup_name as "supplierName"
         ,tpp.pickup_date as "pickupDate"
         ,sys.f_get_name_i18n(tdk2.kind_name_i18n, #{i18n}) as "purStatusName"
+        ,sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "purTypeName"
         ,tpp.contact_name as "contactName"
         ,tpp.contact_phone as "contactPhone"
         ,tpp.intoing_qty as "intoingQtySum"
@@ -574,6 +631,7 @@
         Left join dkic_b.t_mst_staff as tms1  on tpp.make_staff = tms1.staff_id
         Left join dkic_b.t_mst_warehouse as tmw on tpp.wh_id = tmw.wh_id
         left join sys.t_data_kind as tdk2 on tdk2.kind_code = tpp.pur_status
+        left join sys.t_data_kind tdk1 on tdk1.kind_code = tpp.pur_type
         left join dkic_b.t_psi_purchase_item as tppi on tppi.pur_id = tpp.pur_id
         left join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tppi.sku_id
         left join dkic_b.t_mst_goods_brand as tmgb on tmgb.brand_id = tmgs.brand_id
@@ -905,4 +963,34 @@
         </if>
     </select>
 
+    <!-- 客户收款明细报表主表 -->
+    <select id="getRecPayDetailReport" resultType="java.util.Map">
+        SELECT
+        t.rp_no                                             as "rpNo",
+        t.biznis_no                                         as "biznisNo",
+        tmo.org_name                                        as "orgName",
+        tms.staff_name                                      as "staffName",
+        tmc.cus_name                                        as "cusName",
+        tmc.cus_phone                                       as "cusPhone",
+        sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n})   as "rpTypeName",
+        tmma.mac_name                                       as "macName",
+        tmrpi.amt_rec                                           as "amtRec",
+        t.acc_date                                          as "accDate",
+        t.remarks,
+        makestaff.staff_name                                as "makeStaffName"
+        FROM dkic_b.t_mac_rec_pay_item as tmrpi
+        left join dkic_b.t_mac_rec_pay t on tmrpi.rp_id = t.rp_id
+        left join dkic_b.t_mst_org tmo on tmo.org_id = t.org_id
+        left join dkic_b.t_mst_staff tms on tms.staff_id = t.staff_id
+        left join dkic_b.t_mst_staff as makestaff on makestaff.staff_id = t.make_staff
+        left join dkic_b.t_mst_customer tmc on tmc.cus_id = t.object_id
+        left join sys.t_data_kind as tdk1 on tdk1.kind_code = t.rp_type
+        left join dkic_b.t_mst_money_account tmma on tmma.mac_id = tmrpi.mac_id
+        <include refid="Condition_RecPayDetailReport"/>
+        order by  t.op_create_time desc
+        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            limit #{end} offset #{start}
+        </if>
+    </select>
+
 </mapper>

+ 1 - 1
src/main/java/com/dk/mdm/mapper/sale/OrderMapper.xml

@@ -679,7 +679,7 @@
                  left join sys.t_data_kind as tdk1 on t.order_type = tdk1.kind_code
                  left join sys.t_data_kind as tdk2 on t.order_status = tdk2.kind_code
                  left join sys.t_data_kind as tdk3 on t.out_status = tdk3.kind_code
-        WHERE t.order_id = #{orderId}::uuid
+        WHERE t.order_id = #{id}::uuid
     </select>
 
     <!-- 根据主键锁定表t_psi_order的一行数据 -->

+ 8 - 0
src/main/java/com/dk/mdm/model/pojo/mac/AccountItem.java

@@ -171,6 +171,14 @@ public class AccountItem extends PageInfo<AccountItem> implements Serializable {
 
 
     /**
+     * 锁定标识 (开单收款,自动锁定)
+     */
+    @Excel(name = "锁定标识 (开单收款,自动锁定)")
+    @ApiModelProperty(value = "锁定标识 (开单收款,自动锁定)")
+    private Boolean flgLock;
+
+
+    /**
      * 备注
      */
     @Excel(name = "备注")

+ 10 - 0
src/main/java/com/dk/mdm/model/query/mac/AccountItemQuery.java

@@ -173,6 +173,14 @@ public class AccountItemQuery extends PageInfo<AccountItemQuery> implements Seri
 
 
     /**
+     * 锁定标识 (开单收款,自动锁定)
+     */
+    @Excel(name = "锁定标识 (开单收款,自动锁定)")
+    @ApiModelProperty(value = "锁定标识 (开单收款,自动锁定)")
+    private Boolean flgLock;
+
+
+    /**
      * 备注
      */
     @Excel(name = "备注")
@@ -242,6 +250,8 @@ public class AccountItemQuery extends PageInfo<AccountItemQuery> implements Seri
     @ApiModelProperty(value = "功能入口类型:add/refund")
     private String formType;
 
+    @ApiModelProperty(value = "订单Id")
+    private String orderId;
 
     private static final long serialVersionUID = 1L;
 

+ 8 - 0
src/main/java/com/dk/mdm/model/response/mac/AccountItemResponse.java

@@ -173,6 +173,14 @@ public class AccountItemResponse extends PageInfo<AccountItemResponse> implement
 
 
     /**
+     * 锁定标识 (开单收款,自动锁定)
+     */
+    @Excel(name = "锁定标识 (开单收款,自动锁定)")
+    @ApiModelProperty(value = "锁定标识 (开单收款,自动锁定)")
+    private Boolean flgLock;
+
+
+    /**
      * 备注
      */
     @Excel(name = "备注")

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

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

+ 91 - 62
src/main/java/com/dk/mdm/service/ivt/TransferService.java

@@ -12,19 +12,18 @@ import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.ivt.TransferConvert;
 import com.dk.mdm.infrastructure.convert.ivt.TransferItemConvert;
 import com.dk.mdm.mapper.ivt.InboundItemMapper;
+import com.dk.mdm.mapper.ivt.OutboundItemMapper;
 import com.dk.mdm.mapper.ivt.TransferItemMapper;
-import com.dk.mdm.model.pojo.ivt.CheckItem;
-import com.dk.mdm.model.pojo.ivt.InboundItem;
-import com.dk.mdm.model.pojo.ivt.Transfer;
+import com.dk.mdm.model.pojo.ivt.*;
 import com.dk.mdm.mapper.ivt.TransferMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
-import com.dk.mdm.model.pojo.ivt.TransferItem;
 import com.dk.mdm.model.pojo.mac.RecPay;
 import com.dk.mdm.model.pojo.mac.RecPayItem;
 import com.dk.mdm.model.pojo.sale.Order;
 import com.dk.mdm.model.query.ivt.TransferQuery;
 import com.dk.mdm.model.response.ivt.InboundItemResponse;
+import com.dk.mdm.model.response.ivt.OutboundItemResponse;
 import com.dk.mdm.model.response.ivt.TransferResponse;
 import com.dk.mdm.model.vo.ivt.*;
 import com.dk.mdm.service.common.CommonService;
@@ -78,6 +77,9 @@ public class TransferService extends BaseService<Transfer> {
 	@Autowired
 	private InboundItemMapper inboundItemMapper;
 
+    @Autowired
+    private OutboundItemMapper outboundItemMapper;
+
 
 	/**
 	 * @desc   : 重写主键
@@ -145,7 +147,7 @@ public class TransferService extends BaseService<Transfer> {
 						.setScale(6, BigDecimal.ROUND_HALF_UP);*/
 				// 获取入库表实体
 				InboundVO inboundVO = new InboundVO();
-				List<InboundItem> inboundItemList=new ArrayList<>();
+				List<InboundItemVO> inboundItemVOList=new ArrayList<>();
 				// 获取出库表实体
 				OutboundVO outboundVO = new OutboundVO();
 				List<OutboundItemVO> outboundItemVOList=new ArrayList<>();
@@ -167,28 +169,46 @@ public class TransferService extends BaseService<Transfer> {
 					// 获取入库明细实体
 					for (TransferItemVO transferItemVO : transferVO.getItemList()) {
 						// 赋值入库明细实体
-						InboundItem inboundItem=new InboundItem();
-						inboundItem.setIntoingQty(transferItemVO.getTransferQty()).setFromId(transfer.getTransferId())
-								.setIntoingAmt(BigDecimal.ZERO).setPriceInto(BigDecimal.ZERO).setIntoId(transferItemVO.getInvId())
-								.setWhId(transferItemVO.getWhId()).setSkuId(transferItemVO.getSkuId())
-								.setNonStdCode(transferItemVO.getONonStdCode()).setItemIndex(transferItemVO.getItemIndex());
-						inboundItemList.add(inboundItem);
+						InboundItemVO inboundItemVO=new InboundItemVO();
+                        inboundItemVO.setItemIndex(transferItemVO.getItemIndex()).setSkuId(transferItemVO.getSkuId())
+                                .setIntoingQty(transferItemVO.getTransferQty()).setFromId(transfer.getTransferId())
+								.setIntoingAmt(BigDecimal.ZERO).setPriceInto(BigDecimal.ZERO)
+                                .setWhId(transferItemVO.getWhId()).setNonStdCode(transferItemVO.getONonStdCode());
+
+                        inboundItemVOList.add(inboundItemVO);
+
+                        // 赋值出库明细信息。
+                        OutboundItemVO outboundItemVO =new OutboundItemVO();
+                        outboundItemVO.setItemIndex(transferItemVO.getItemIndex()).setSkuId(transferItemVO.getSkuId())
+                                .setOutingQty(transferItemVO.getTransferQty()).setFromId(transfer.getTransferId())
+                                .setOutingAmt(BigDecimal.ZERO).setPriceOut(BigDecimal.ZERO)
+                                .setWhId(transferItemVO.getWhId()).setNonStdCode(transferItemVO.getONonStdCode());
+
+                        outboundItemVOList.add(outboundItemVO);
 					}
+
+                    // 赋值出库接口参数 总表和明细
+                    outboundCheckMap.put("total",outboundVO);
+                    outboundCheckMap.put("detail",outboundItemVOList);
+                    // 调用盘点出库接口
+                    OutboundVO outboundTransferVO = outboundCheckService.otherOutboundInsert(outboundCheckMap);
+
 					// 赋值入库接口参数 总表和明细
 					inboundMap.put("total", inboundVO);
-					inboundMap.put("detail", inboundItemList);
+					inboundMap.put("detail", inboundItemVOList);
 					// 调用入库接口
 					InboundVO inboundTransferVO = inboundCheckService.checkInboundInsert(inboundMap);
 					// 如果库存接口返回成功,则插入调整单明细数据
 					if (transferVO.getItemList() != null && transferVO.getItemList().size() > 0) {
 						for (TransferItemVO transferItemVO : transferVO.getItemList()) {
-							// 转换
+							// 转换库存调整单明细
 							TransferItem transferItem = transferItemConvert.convertToPo(transferItemVO);
 							// 在入库接口中获取入库明细数据
-							List<InboundItemVO> inboundItemVOList = inboundTransferVO.getItemList().stream()
+							inboundItemVOList = inboundTransferVO.getItemList().stream()
 									.filter(it -> it.getItemIndex().equals(transferItemVO.getItemIndex())).collect(Collectors.toList());
 							// 通过入库明细数据的item_id查询出inv_id
 							InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVOList.get(0).getItemId());
+
 							// 获取调整主表uuid
 							transferItem.setTransferId(transfer.getTransferId()).setTransferDate(LocalDate.now())
 									.setInvId(inboundItemResponse.getInvId());
@@ -198,19 +218,18 @@ public class TransferService extends BaseService<Transfer> {
 							InboundItem inboundItem= new InboundItem();
 							inboundItem.setFromItemId(transferItem.getItemId()).setItemId(inboundItemResponse.getItemId());
 							inboundItemService.updateByUuid(inboundItem);
-							// 赋值出库明细信息。
-							OutboundItemVO outboundItemVO =new OutboundItemVO();
-							outboundItemVO.setFromItemId(transferItem.getItemId()).setItemIndex(transferItem.getItemIndex())
-									.setOutingQty(transferItem.getTransferQty()).setFromId(transferItem.getTransferId())
-									.setSkuId(transferItem.getSkuId()).setNonStdCode(transferItem.getONonStdCode())
-									.setInvId(transferItem.getOInvId()).setPriceOut(BigDecimal.ZERO).setOutingAmt(BigDecimal.ZERO);
-							outboundItemVOList.add(outboundItemVO);
+
+                            // 在出库接口中获取入库明细数据
+                            outboundItemVOList = outboundTransferVO.getItemList().stream()
+                                    .filter(it -> it.getItemIndex().equals(transferItemVO.getItemIndex())).collect(Collectors.toList());
+                            // 通过出库明细数据的item_id查询出inv_id
+                            OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVOList.get(0).getItemId());
+
+                            // 赋值出库明细值 并修改出库明细from_item_id值
+                            OutboundItem outboundItem= new OutboundItem();
+                            outboundItem.setFromItemId(transferItem.getItemId()).setItemId(outboundItemResponse.getItemId());
+                            inboundItemService.updateByUuid(inboundItem);
 						}
-						// 赋值出库接口参数 总表和明细
-						outboundCheckMap.put("total",outboundVO);
-						outboundCheckMap.put("detail",outboundItemVOList);
-						// 调用盘点出库接口
-						outboundCheckService.otherOutboundInsert(outboundCheckMap);
 					}
 				}
 				// 非标号调整
@@ -231,50 +250,60 @@ public class TransferService extends BaseService<Transfer> {
 					// 获取入库明细实体
 					for (TransferItemVO transferItemVO : transferVO.getItemList()) {
 						// 赋值入库明细实体
-						InboundItem inboundItem=new InboundItem();
-						inboundItem.setIntoingQty(transferItemVO.getTransferQty()).setFromId(transfer.getTransferId())
-								.setIntoingAmt(BigDecimal.ZERO).setPriceInto(BigDecimal.ZERO).setIntoId(transferItemVO.getInvId())
-								.setWhId(transferItemVO.getOWhId()).setSkuId(transferItemVO.getSkuId())
-								.setNonStdCode(transferItemVO.getNonStdCode()).setItemIndex(transferItemVO.getItemIndex());
-						inboundItemList.add(inboundItem);
+                        InboundItemVO inboundItemVO=new InboundItemVO();
+                        inboundItemVO.setItemIndex(transferItemVO.getItemIndex()).setSkuId(transferItemVO.getSkuId())
+                                .setIntoingQty(transferItemVO.getTransferQty()).setFromId(transfer.getTransferId())
+								.setIntoingAmt(BigDecimal.ZERO).setPriceInto(BigDecimal.ZERO)
+								.setWhId(transferItemVO.getOWhId()).setNonStdCode(transferItemVO.getNonStdCode());
+                        inboundItemVOList.add(inboundItemVO);
+
+                        // 赋值出库明细信息。
+                        OutboundItemVO outboundItemVO =new OutboundItemVO();
+                        outboundItemVO.setItemIndex(transferItemVO.getItemIndex()).setSkuId(transferItemVO.getSkuId())
+                                .setOutingQty(transferItemVO.getTransferQty()).setFromId(transfer.getTransferId())
+                                .setOutingAmt(BigDecimal.ZERO).setPriceOut(BigDecimal.ZERO)
+                                .setWhId(transferItemVO.getWhId()).setNonStdCode(transferItemVO.getONonStdCode());
+                        outboundItemVOList.add(outboundItemVO);
 					}
+                    // 赋值出库接口参数 总表和明细
+                    outboundCheckMap.put("total",outboundVO);
+                    outboundCheckMap.put("detail",outboundItemVOList);
+                    // 调用盘点出库接口
+                    OutboundVO outboundTransferVO = outboundCheckService.otherOutboundInsert(outboundCheckMap);
+
 					// 赋值入库接口参数 总表和明细
 					inboundMap.put("total", inboundVO);
-					inboundMap.put("detail", inboundItemList);
+					inboundMap.put("detail", inboundItemVOList);
 					// 调用入库接口
 					InboundVO inboundTransferVO = inboundCheckService.checkInboundInsert(inboundMap);
 					// 如果库存接口返回成功,则插入调整单明细数据
 					if (transferVO.getItemList() != null && transferVO.getItemList().size() > 0) {
 						for (TransferItemVO transferItemVO : transferVO.getItemList()) {
-							// 转换
+                            // 转换库存调整单明细
 							TransferItem transferItem = transferItemConvert.convertToPo(transferItemVO);
-							// 在入库接口中获取入库明细数据
-							List<InboundItemVO> inboundItemVOList = inboundTransferVO.getItemList().stream()
-									.filter(it -> it.getItemIndex().equals(transferItemVO.getItemIndex())).collect(Collectors.toList());
-							// 通过入库明细数据的item_id查询出inv_id
-							InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVOList.get(0).getItemId());
-							// 获取调整主表uuid
-							transferItem.setTransferId(transfer.getTransferId()).setTransferDate(LocalDate.now())
-									.setInvId(inboundItemResponse.getInvId());
-							// 插入调整单明细数据
-							transferItemMapper.insert(transferItem);
-							// 赋值入库明细值 并修改入库明细from_item_id值
-							InboundItem inboundItem= new InboundItem();
-							inboundItem.setFromItemId(transferItem.getItemId()).setItemId(inboundItemResponse.getItemId());
-							inboundItemService.updateByUuid(inboundItem);
-							// 赋值出库明细信息。
-							OutboundItemVO outboundItemVO =new OutboundItemVO();
-							outboundItemVO.setFromItemId(transferItem.getItemId()).setItemIndex(transferItem.getItemIndex())
-									.setOutingQty(transferItem.getTransferQty()).setFromId(transferItem.getTransferId())
-									.setSkuId(transferItem.getSkuId()).setNonStdCode(transferItem.getONonStdCode())
-									.setInvId(transferItem.getOInvId()).setPriceOut(BigDecimal.ZERO).setOutingAmt(BigDecimal.ZERO);
-							outboundItemVOList.add(outboundItemVO);
+                            // 在入库接口中获取入库明细数据
+                            inboundItemVOList = inboundTransferVO.getItemList().stream()
+                                    .filter(it -> it.getItemIndex().equals(transferItemVO.getItemIndex())).collect(Collectors.toList());
+                            // 通过入库明细数据的item_id查询出inv_id
+                            InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVOList.get(0).getItemId());
+
+                            // 获取调整主表uuid
+                            transferItem.setTransferId(transfer.getTransferId()).setTransferDate(LocalDate.now())
+                                    .setInvId(inboundItemResponse.getInvId());
+                            // 插入调整单明细数据
+                            transferItemMapper.insert(transferItem);
+                            // 赋值入库明细值 并修改入库明细from_item_id值
+                            InboundItem inboundItem= new InboundItem();
+                            inboundItem.setFromItemId(transferItem.getItemId()).setItemId(inboundItemResponse.getItemId());
+                            inboundItemService.updateByUuid(inboundItem);
+
+                            // 在出库接口中获取入库明细数据
+                            outboundItemVOList = outboundTransferVO.getItemList().stream()
+                                    .filter(it -> it.getItemIndex().equals(transferItemVO.getItemIndex())).collect(Collectors.toList());
+                            // 通过出库明细数据的item_id查询出inv_id
+                            OutboundItemResponse outboundItemResponse = outboundItemMapper.selectById(outboundItemVOList.get(0).getItemId());
 						}
-						// 赋值出库接口参数 总表和明细
-						outboundCheckMap.put("total",outboundVO);
-						outboundCheckMap.put("detail",outboundItemVOList);
-						// 调用盘点出库接口
-						outboundCheckService.otherOutboundInsert(outboundCheckMap);
+
 					}
 				}
 			}
@@ -304,9 +333,9 @@ public class TransferService extends BaseService<Transfer> {
 		super.updateByUuid(transferUpdate);
 
 		// 调用入库作废接口
-
+		inboundCheckService.inboundRepeal(id);
 		// 调用出库作废接口
-
+		outboundCheckService.outboundRepeal(id);
 		return ResponseResultUtil.success();
 	}
 }

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

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

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

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

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

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

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

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

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

@@ -270,7 +270,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region  已出库  账
+        //region  已出库  应收记
         if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
             accountService.accReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
         }
@@ -326,9 +326,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             //region  自动办理参数为true  已入库编辑
             //自动办理参数为true
             if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundVO.getFlgHandleSetting())) {
-                //region 退
+                //region 应收反记
                 if (outboundVO.getReceivableId() != null) {
-                    accountService.reversePayable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+                    accountService.reverseReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
                 }
                 //endregion
 
@@ -493,9 +493,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
                 }
                 //endregion
 
-                //region  账
+                //region  应收记
                 if (outboundVO.getReceivableId() != null) {
-                    accountService.reversePayable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+                    accountService.reverseReceivable(outboundVO.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
                 }
                 //endregion
 
@@ -676,9 +676,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         //region  自动办理参数为true  已入库编辑
         //自动办理参数为true
         if (Constant.FlgHandleSetting.TRUE.getValue().equals(outboundResponse.getFlgHandleSetting())) {
-            //region 退
+            //region 应收反记
             if (outboundResponse.getReceivableId() != null) {
-                accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+                accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -755,9 +755,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
             //endregion
 
-            //region  
+            //region  应收反记
             if (outboundResponse.getReceivableId() != null) {
-                accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+                accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
             }
             //endregion
 
@@ -1051,8 +1051,8 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         }
         //endregion
 
-        //region  
-        accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+        //region  应收记
+        accountService.accReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
         //endregion
 
         //region   调用库存
@@ -1075,9 +1075,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         OutboundResponse outboundResponse = outboundMapper.selectById(outboundVO.getOutId());
         //endregion
 
-        //region    退
+        //region    应收反记
         if (outboundResponse.getReceivableId() != null) {
-            accountService.reversePayable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
+            accountService.reverseReceivable(outboundResponse.getOutId(), Constant.InventoryDocCode.OUTBOUND.getTableName());
         }
         //endregion
 
@@ -1091,7 +1091,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             order.setOutQty(outboundResponse.getOutQty().negate());
             order.setOutAmt(outboundResponse.getOutAmt().negate());
             //根据id查询
-            OrderResponse orderResponse = orderMapper.selectById(outboundVO.getFromId());
+            OrderResponse orderResponse = orderMapper.selectById(outboundResponse.getFromId());
             //出库状态
             String outStatus = this.setOutStatus(orderResponse.getOutingQty().add(order.getOutingQty()),
                     orderResponse.getOutQty().add(order.getOutQty()), orderResponse.getSumQuantity());
@@ -1108,7 +1108,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
         //region 修改总单数据信息
         Outbound outbound = new Outbound();
-        outbound.setOutId(outboundVO.getOutId());
+        outbound.setOutId(outboundResponse.getOutId());
         outbound.setOutDate(null);
         outbound.setOutStatus(Constant.OutStatus.CHUKUZHONG.getName());
         outbound.setOutQty(BigDecimal.ZERO);
@@ -1124,7 +1124,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
         //region 明细数据
         //根据总单id查明细
-        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundVO.getOutId()));
+        List<OutboundItemResponse> outboundItemResponseList = outboundItemMapper.selectByCond(new OutboundItemQuery().setOutId(outboundResponse.getOutId()));
         for (OutboundItemResponse outboundItemResponse : outboundItemResponseList) {
             //region 修改销售退货明细数据信息
             if (outboundItemResponse.getFromItemId() != null) {

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

@@ -10,21 +10,17 @@ import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.mapper.ivt.InboundMapper;
 import com.dk.mdm.mapper.ivt.OutboundMapper;
-import com.dk.mdm.mapper.mac.AccountItemMapper;
-import com.dk.mdm.mapper.mac.OtherPayableMapper;
-import com.dk.mdm.mapper.mac.OtherReceivableMapper;
+import com.dk.mdm.mapper.mac.*;
 import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
 import com.dk.mdm.mapper.mst.MoneyAccountMapper;
+import com.dk.mdm.mapper.sale.OrderMapper;
 import com.dk.mdm.model.pojo.ivt.Inbound;
 import com.dk.mdm.model.pojo.ivt.Outbound;
-import com.dk.mdm.model.pojo.mac.Account;
-import com.dk.mdm.mapper.mac.AccountMapper;
+import com.dk.mdm.model.pojo.mac.*;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
-import com.dk.mdm.model.pojo.mac.AccountItem;
-import com.dk.mdm.model.pojo.mac.OtherPayable;
-import com.dk.mdm.model.pojo.mac.OtherReceivable;
 import com.dk.mdm.model.pojo.mst.MoneyAccount;
+import com.dk.mdm.model.pojo.sale.Order;
 import com.dk.mdm.model.query.mac.AccountItemQuery;
 import com.dk.mdm.model.response.mac.AccountItemResponse;
 import com.dk.mdm.model.response.mac.AccountResponse;
@@ -34,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -56,6 +53,9 @@ public class AccountService extends BaseService<Account> {
     private AccountMapper accountMapper;
 
     @Autowired
+    private AccountItemService accountItemService;
+
+    @Autowired
     private AccountItemMapper accountItemMapper;
 
     @Autowired
@@ -79,6 +79,21 @@ public class AccountService extends BaseService<Account> {
     @Autowired
     private OtherPayableMapper otherPayableMapper;
 
+    @Autowired
+    private OrderMapper orderMapper;
+
+    @Autowired
+    private RecPayMapper recPayMapper;
+
+    @Autowired
+    private ReceiptService receiptService;
+
+    @Autowired
+    private RecPayItemMapper recPayItemMapper;
+
+    @Autowired
+    private RecPayHandleItemMapper recPayHandleItemMapper;
+
     /**
      * @desc : 查看来源单据,总单加明细
      * @author : 姜永辉
@@ -163,7 +178,7 @@ public class AccountService extends BaseService<Account> {
      */
     public void updateReceipt(String objectId) {
         Account accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
-        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtRecPay(objectId);
+        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtRec(objectId);
         BigDecimal sumAmtRec = new BigDecimal(mapSumAmtRecPay.get("sumAmtRec").toString());
         // 可退金额 = 总收款额-应收应款额+优惠金额
         BigDecimal sumReceiptResidue = sumAmtRec.subtract(accountForUpdate.getReceivableHandle()).add(accountForUpdate.getReceivableWaive());
@@ -180,13 +195,29 @@ public class AccountService extends BaseService<Account> {
     }
 
     /**
+     * @desc : 更新总帐上收款类字段
+     * @author : 付斌
+     * @date : 2024-03-22 11:08
+     */
+    public void updateReceiptLock(String objectId) {
+        Account accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
+        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtRecLock(objectId);
+        BigDecimal sumAmtRecLock = new BigDecimal(mapSumAmtRecPay.get("sumAmtRecLock").toString());
+
+        // 更新账款总表上的收款总额和可用金额
+        Account accountUpdate = new Account();
+        accountUpdate.setReceiptLock(sumAmtRecLock).setObjectId(accountForUpdate.getObjectId());
+        super.updateByUuid(accountUpdate);
+    }
+
+    /**
      * @desc : 更新总帐上付款类字段
      * @author : 付斌
      * @date : 2024-03-22 11:08
      */
     public void updatePayment(String objectId) {
         Account accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
-        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtRecPay(objectId);
+        Map<String, Object> mapSumAmtRecPay = accountItemMapper.getSumAmtPay(objectId);
         BigDecimal sumAmtPay = new BigDecimal(mapSumAmtRecPay.get("sumAmtPay").toString());
         // 可退金额 = 总收款额-应收应款额+优惠金额
         BigDecimal sumPaymentResidue = sumAmtPay.subtract(accountForUpdate.getPayableHandle()).add(accountForUpdate.getPayableWaive());
@@ -311,6 +342,121 @@ public class AccountService extends BaseService<Account> {
             LambdaUpdateWrapper<Outbound> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.set(Outbound::getReceivableId, UUID.fromString(accountItemInsert.getItemId())).eq(Outbound::getOutId, UUID.fromString(invoiceId));
             outboundMapper.update(null, updateWrapper);
+
+            // 更新账款总表上的总应收账款和总剩余应收
+            Account accountForUpdate = getCusAccountForUpdate(objectId);
+            Account accountUpdate = new Account();
+            accountUpdate.setReceivable(accountForUpdate.getReceivable().add(accountItemInsert.getAmtShould()))
+                    .setReceivableResidue(accountForUpdate.getReceivableResidue().add(accountItemInsert.getAmtShould()))
+                    .setObjectId(objectId);
+            super.updateByUuid(accountUpdate);
+
+            // 如果当前出库单对应的订单全部出库了,并且订单有收款(锁定金额),则自动做应收核销
+            // 如果是销售出库
+            if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
+                Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
+                // 如果当前订单已经全部出库
+                if(orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0){
+                    RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId());
+                    if(recPayForUpdate != null && recPayForUpdate.getFlgLock()){
+                        // 先把收款单解锁
+                        RecPay recPayUpdate = new RecPay();
+                        recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
+                        receiptService.updateByUuid(recPayUpdate);
+
+                        // 账款明细解锁
+                        List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                        for (RecPayItem recPayItem : recPayItemList) {
+                            AccountItem accountItemUpdate = new AccountItem();
+                            accountItemUpdate.setFlgLock(false).setItemId(recPayItem.getAccItemId());
+                            accountItemService.updateByUuid(accountItemUpdate);
+                        }
+
+                        // 钱进到现金池中
+                        accountUpdate = new Account();
+                        accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayForUpdate.getSumAmtRec()))
+                                .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPayForUpdate.getSumAmtRec()))
+                                .setReceiptLock(accountForUpdate.getReceiptLock().subtract(recPayForUpdate.getSumAmtRec()))
+                                .setObjectId(objectId);
+                        super.updateByUuid(accountUpdate);
+
+                        List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
+                                new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
+
+                        if(accountItemResponseList.size() > 0){
+                            // 记录核销了哪些应收账
+                            List<RecPayHandleItem> receivableList = new ArrayList<>();
+
+                            // 锁定金额
+                            BigDecimal lockAmt = recPayForUpdate.getSumAmtRec();
+
+                            for (AccountItemResponse accountItemResponse : accountItemResponseList) {
+                                RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
+                                recPayHandleItem.setRpId(recPayForUpdate.getRpId()).setCpId(recPayForUpdate.getCpId()).setAccDate(recPayForUpdate.getAccDate())
+                                        .setAccItemId(accountItemResponse.getAccItemId());
+                                // 如果定金比应收金额大
+                                if(lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1){
+                                    recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
+                                    lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
+                                }else{
+                                    recPayHandleItem.setAmtReceivableHandle(lockAmt);
+                                    lockAmt = BigDecimal.ZERO;
+                                }
+                                recPayHandleItemMapper.insert(recPayHandleItem);
+                                receivableList.add(recPayHandleItem);
+
+                                // 账款明细的核销金额和优惠金额
+                                AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
+                                AccountItem accountItemUpdate = new AccountItem();
+                                // 核销金额,超出剩余应收金额
+                                if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtReceivableHandle()) == -1) {
+                                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+                                }
+                                accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtReceivableHandle()))
+                                        .setItemId(recPayHandleItem.getAccItemId());
+                                // 剩余金额 = 应收金额-应收收款金额
+                                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                                accountItemService.updateByUuid(accountItemUpdate);
+
+                                // 如果定金都用完了,跳出循环
+                                if(lockAmt.compareTo(BigDecimal.ZERO)==0){
+                                    break;
+                                }
+                            }
+
+                            // 计算明细的核销金额,优惠金额合计
+                            RecPayHandleItem recPayHandleItem = receivableList.stream().reduce((x, y) -> {
+                                RecPayHandleItem item = new RecPayHandleItem();
+                                item.setAmtReceivableHandle(x.getAmtReceivableHandle().add(y.getAmtReceivableHandle()));
+                                return item;
+                            }).get();
+
+                            // 更新收款单
+                            recPayUpdate = new RecPay();
+                            recPayUpdate.setSumAmtReceivableHandle(recPayHandleItem.getAmtReceivableHandle())
+                                    .setSumShouldHandle(recPayHandleItem.getAmtReceivableHandle())
+                                    .setRpId(recPayForUpdate.getRpId());
+                            receiptService.updateByUuid(recPayUpdate);
+
+                            // 更新总账上
+                            accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+                            accountUpdate = new Account();
+                            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
+                                    .setObjectId(accountForUpdate.getObjectId());
+                            // 剩余应收 = 总应收账款-总应收收款金额
+                            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+                            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+                            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+
+                            // 可用金额为负数,则不能保存
+                            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+                            }
+                            super.updateByUuid(accountUpdate);
+                        }
+                    }
+                }
+            }
         }
         // 其他收入单
         else if ("t_mac_other_receivable".equals(biznisType)) {
@@ -339,15 +485,15 @@ public class AccountService extends BaseService<Account> {
             LambdaUpdateWrapper<OtherReceivable> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.set(OtherReceivable::getAccItemId, UUID.fromString(accountItemInsert.getItemId())).eq(OtherReceivable::getReceivableId, UUID.fromString(invoiceId));
             otherReceivableMapper.update(null, updateWrapper);
-        }
 
-        // 更新账款总表上的总应收账款和总剩余应收
-        Account accountForUpdate = getCusAccountForUpdate(objectId);
-        Account accountUpdate = new Account();
-        accountUpdate.setReceivable(accountForUpdate.getReceivable().add(accountItemInsert.getAmtShould()))
-                .setReceivableResidue(accountForUpdate.getReceivableResidue().add(accountItemInsert.getAmtShould()))
-                .setObjectId(objectId);
-        super.updateByUuid(accountUpdate);
+            // 更新账款总表上的总应收账款和总剩余应收
+            Account accountForUpdate = getCusAccountForUpdate(objectId);
+            Account accountUpdate = new Account();
+            accountUpdate.setReceivable(accountForUpdate.getReceivable().add(accountItemInsert.getAmtShould()))
+                    .setReceivableResidue(accountForUpdate.getReceivableResidue().add(accountItemInsert.getAmtShould()))
+                    .setObjectId(objectId);
+            super.updateByUuid(accountUpdate);
+        }
     }
 
     /**
@@ -370,6 +516,66 @@ public class AccountService extends BaseService<Account> {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISREVERSE.getMessage());
             }
 
+            Account accountForUpdate;
+            Account accountUpdate;
+            // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
+            // 如果是销售出库
+            if(outbound.getOutType().equals(Constant.OutType.SALE.getName())){
+                RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId());
+                // 查出并锁定所有应收核销明细
+                List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
+                    // 更新账款明细应收收款
+                    accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
+                    AccountItem accountItemUpdate = new AccountItem();
+                    accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
+                            .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                    accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                    accountItemService.updateByUuid(accountItemUpdate);
+
+                    // 删掉核销明细
+                    recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
+                }
+
+                // 把总帐上的钱加回来
+                accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+                accountUpdate = new Account();
+                accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                        .setObjectId(accountForUpdate.getObjectId());
+                // 剩余应收 = 总应收账款-总应收收款金额
+                accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+                // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+                accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+
+                // 更新前的最后校验
+                // 可用金额为负数,则不能保存
+                if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+                }
+                super.updateByUuid(accountUpdate);
+
+                // 先把收款单锁定
+                RecPay recPayUpdate = new RecPay();
+                recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
+                receiptService.updateByUuid(recPayUpdate);
+
+                // 账款明细解锁
+                List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                for (RecPayItem recPayItem : recPayItemList) {
+                    AccountItem accountItemUpdate = new AccountItem();
+                    accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
+                    accountItemService.updateByUuid(accountItemUpdate);
+                }
+
+                // 钱进到锁定金额中
+                accountUpdate = new Account();
+                accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
+                        .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
+                        .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
+                        .setObjectId(objectId);
+                super.updateByUuid(accountUpdate);
+            }
+
             accountItemForUpdate = accountItemMapper.selectByIdForUpdate(outbound.getReceivableId());
             // 如果核销金额不为0,说明当前单据已核销
             if (accountItemForUpdate.getAmtHandle().compareTo(BigDecimal.ZERO) != 0) {
@@ -380,6 +586,17 @@ public class AccountService extends BaseService<Account> {
             LambdaUpdateWrapper<Outbound> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.set(Outbound::getReceivableId, null).eq(Outbound::getOutId, UUID.fromString(invoiceId));
             outboundMapper.update(null, updateWrapper);
+
+            // 删除账款明细
+            accountItemMapper.deleteById(accountItemForUpdate.getItemId());
+
+            // 更新账款总表上的总应收账款和总剩余应收
+            accountForUpdate = getCusAccountForUpdate(objectId);
+            accountUpdate = new Account();
+            accountUpdate.setReceivable(accountForUpdate.getReceivable().subtract(accountItemForUpdate.getAmtShould()))
+                    .setReceivableResidue(accountForUpdate.getReceivableResidue().subtract(accountItemForUpdate.getAmtShould()))
+                    .setObjectId(objectId);
+            super.updateByUuid(accountUpdate);
         }
         // 其他收入单
         else if ("t_mac_other_receivable".equals(biznisType)) {
@@ -401,18 +618,18 @@ public class AccountService extends BaseService<Account> {
             LambdaUpdateWrapper<OtherReceivable> updateWrapper = new LambdaUpdateWrapper<>();
             updateWrapper.set(OtherReceivable::getAccItemId, null).eq(OtherReceivable::getReceivableId, UUID.fromString(invoiceId));
             otherReceivableMapper.update(null, updateWrapper);
-        }
 
-        // 删除账款明细
-        accountItemMapper.deleteById(accountItemForUpdate.getItemId());
+            // 删除账款明细
+            accountItemMapper.deleteById(accountItemForUpdate.getItemId());
 
-        // 更新账款总表上的总应收账款和总剩余应收
-        Account accountForUpdate = getCusAccountForUpdate(objectId);
-        Account accountUpdate = new Account();
-        accountUpdate.setReceivable(accountForUpdate.getReceivable().subtract(accountItemForUpdate.getAmtShould()))
-                .setReceivableResidue(accountForUpdate.getReceivableResidue().subtract(accountItemForUpdate.getAmtShould()))
-                .setObjectId(objectId);
-        super.updateByUuid(accountUpdate);
+            // 更新账款总表上的总应收账款和总剩余应收
+            Account accountForUpdate = getCusAccountForUpdate(objectId);
+            Account accountUpdate = new Account();
+            accountUpdate.setReceivable(accountForUpdate.getReceivable().subtract(accountItemForUpdate.getAmtShould()))
+                    .setReceivableResidue(accountForUpdate.getReceivableResidue().subtract(accountItemForUpdate.getAmtShould()))
+                    .setObjectId(objectId);
+            super.updateByUuid(accountUpdate);
+        }
     }
 
     /**

+ 7 - 7
src/main/java/com/dk/mdm/service/mac/ReceiptService.java

@@ -208,9 +208,9 @@ public class ReceiptService extends BaseService<RecPay> {
 
         // 查总账,看可退金额是否满足
         Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayVO.getObjectId());
-        if (accountForUpdate == null || accountForUpdate.getReceiptResidue().compareTo(recPayVO.getSumAmtRec().abs()) == -1) {
-            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
-        }
+//        if (accountForUpdate == null || accountForUpdate.getReceiptResidue().compareTo(recPayVO.getSumAmtRec().abs()) == -1) {
+//            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+//        }
 
         // 获取单号
         Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
@@ -251,10 +251,10 @@ public class ReceiptService extends BaseService<RecPay> {
                 // 更新资金账户
                 MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
 
-                // 如果转账之后账户余额小于0,则提示资金账户余额不足,不能退款
-                if ((moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec())).compareTo(BigDecimal.ZERO) == -1) {
-                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
-                }
+//                // 如果转账之后账户余额小于0,则提示资金账户余额不足,不能退款
+//                if ((moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec())).compareTo(BigDecimal.ZERO) == -1) {
+//                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+//                }
 
                 MoneyAccount moneyAccountUpdate = new MoneyAccount();
                 moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec()))

+ 1 - 0
src/main/java/com/dk/mdm/service/mst/StaffService.java

@@ -331,6 +331,7 @@ public class StaffService extends BaseService<Staff> {
         Dictionary<String, Object> dic = new Hashtable<>();
         dic.put("menuList", menuList);
         dic.put("comMenuList", comMenuList.getData());
+        dic.put("dataKindList",  commonMapper.getDataKind(param));
         dic.put("settingValue", allSettingValue);
         dic.put("staff", staff);
         return ResponseResultUtil.success(dic);

+ 14 - 0
src/main/java/com/dk/mdm/service/report/ReportService.java

@@ -117,4 +117,18 @@ public class ReportService {
         return ResponseResultUtil.success(list);
     }
 
+    /**
+     * @desc   : 客户收款明细表
+     * @author : 宋扬
+     * @date   : 2024/4/16 11:29
+     */
+    public ResponseResultVO<List<Map<String, Object>>> getRecPayDetailReport(Map<String, Object> param) {
+        // 获取系统基础数据
+        List<Map<String, Object>> list=new ArrayList<>();
+        // 查询主表
+        list= reportMapper.getRecPayDetailReport(param);
+        return ResponseResultUtil.success(list);
+    }
+
+
 }

+ 26 - 19
src/main/java/com/dk/mdm/service/sale/OrderService.java

@@ -171,10 +171,10 @@ public class OrderService extends BaseService<Order> {
 
         // 收款明细
         List<RecPayResponse> recPayList = recPayMapper.selectByCond(new RecPayQuery().setBiznisId(id));
-        if(recPayList != null && recPayList.size() > 0){
+        if (recPayList != null && recPayList.size() > 0) {
             List<RecPayItemResponse> receiptItem = recPayItemMapper.selectByCond(new RecPayItemQuery().setRpId(recPayList.get(0).getRpId()));
             result.put("receiptItem", receiptItem);
-        }else{
+        } else {
             result.put("receiptItem", new ArrayList<RecPayResponse>());
         }
         return ResponseResultUtil.success(result);
@@ -267,7 +267,7 @@ public class OrderService extends BaseService<Order> {
                     .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(orderVO.getCusId())
                     .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
                     .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
-                    .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId());
+                    .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId()).setFlgLock(true);
             // 计算订单明细的出库中数量,金额合计
             RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
                 RecPayItemVO item = new RecPayItemVO();
@@ -291,7 +291,7 @@ public class OrderService extends BaseService<Order> {
                         .setObjectId(recPay.getObjectId()).setOrgId(recPay.getOrgId()).setStaffId(recPay.getStaffId())
                         .setAccDate(recPay.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
                         .setBiznisType(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
-                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId());
+                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId()).setFlgLock(true);
                 accountItemMapper.insert(accountItem);
 
                 // 更新收款单上的账款明细Id
@@ -318,8 +318,7 @@ public class OrderService extends BaseService<Order> {
             Account accountForUpdate = accountService.getCusAccountForUpdate(recPay.getObjectId());
             // 更新账款总表上收款的相关字段
             Account accountUpdate = new Account();
-            accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPay.getSumAmtRec()))// 总收款金额
-                    .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPay.getSumAmtRec()))//  可退金额
+            accountUpdate.setReceiptLock(accountForUpdate.getReceiptLock().add(recPay.getSumAmtRec()))//  锁定金额
                     .setObjectId(accountForUpdate.getObjectId());
             accountService.updateByUuid(accountUpdate);
         }
@@ -364,10 +363,18 @@ public class OrderService extends BaseService<Order> {
         List<OrderItemVO> editOrderItemVOList = orderVO.getItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
         for (OrderItemVO orderItemVO : editOrderItemVOList) {
             orderItemForUpdate = orderItemMapper.selectByIdForUpdate(orderItemVO.getItemId());
+            // 出库数量
+            BigDecimal outintOrOutQty = orderItemForUpdate.getOutingQty().add(orderItemForUpdate.getOutQty());
             // 商品数量不能小于(出库中数量+已出库数量)
-            if (orderItemVO.getItemQty().compareTo(orderItemForUpdate.getOutingQty().add(orderItemForUpdate.getOutQty())) == -1) {
+            if (orderItemVO.getItemQty().compareTo(outintOrOutQty) == -1) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ITEMQTY_NO_LESS_OUTQTY.getMessage());
             }
+            // 如果出库数量不是0,则不能改仓库
+            if (outintOrOutQty.compareTo(BigDecimal.ZERO) != 0) {
+                if (!orderItemForUpdate.getWhId().equals(orderItemVO.getWhId())) {
+                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORDER_ISOUT.getMessage());
+                }
+            }
             OrderItem orderItem = orderItemConvert.convertToPo(orderItemVO);
             orderItemService.updateByUuid(orderItem);
         }
@@ -414,7 +421,7 @@ public class OrderService extends BaseService<Order> {
         List<String> macList = new ArrayList<>();
         // 收款明细
         RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderVO.getOrderId());
-        if(recPayForUpdate != null){
+        if (recPayForUpdate != null) {
             // 将之前的明细全部删除
             List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
             for (RecPayItem recPayItem : recPayItemOriginalList) {
@@ -441,7 +448,7 @@ public class OrderService extends BaseService<Order> {
             }).get();
 
             RecPay recPay = null;
-            if(recPayForUpdate == null){
+            if (recPayForUpdate == null) {
                 recPay = new RecPay();
                 // 获取单号
                 Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
@@ -449,11 +456,11 @@ public class OrderService extends BaseService<Order> {
                         .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(orderVO.getCusId())
                         .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
                         .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
-                        .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId());
+                        .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId()).setFlgLock(true);
 
                 recPay.setSumAmtRec(itemSum.getAmtRec());
                 recPayMapper.insert(recPay);
-            }else{
+            } else {
                 // 更新收款总额
                 RecPay recPayUpdate = new RecPay();
                 recPayUpdate.setSumAmtRec(itemSum.getAmtRec()).setRpId(recPayForUpdate.getRpId());
@@ -475,7 +482,7 @@ public class OrderService extends BaseService<Order> {
                         .setObjectId(recPay.getObjectId()).setOrgId(recPay.getOrgId()).setStaffId(recPay.getStaffId())
                         .setAccDate(recPay.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
                         .setBiznisType(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
-                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId());
+                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId()).setFlgLock(true);
                 accountItemMapper.insert(accountItem);
 
                 // 更新收款单上的账款明细Id
@@ -495,9 +502,9 @@ public class OrderService extends BaseService<Order> {
                 }
             }
         }
-        if(recPayForUpdate != null) {
-            // 更新总账表的总收款额和可用
-            accountService.updateReceipt(recPayForUpdate.getObjectId());
+        if (recPayForUpdate != null) {
+            // 更新总账表的锁定金
+            accountService.updateReceiptLock(recPayForUpdate.getObjectId());
         }
 
         // 更新账户余额
@@ -536,7 +543,7 @@ public class OrderService extends BaseService<Order> {
         List<String> macList = new ArrayList<>();
         // 收款明细
         RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
-        if(recPayForUpdate != null){
+        if (recPayForUpdate != null) {
             // 将之前的明细全部删除
             List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
             for (RecPayItem recPayItem : recPayItemOriginalList) {
@@ -553,7 +560,7 @@ public class OrderService extends BaseService<Order> {
             }
 
             // 更新总账表的总收款额和可用额
-            accountService.updateReceipt(recPayForUpdate.getObjectId());
+            accountService.updateReceiptLock(recPayForUpdate.getObjectId());
 
             // 更新账户余额
             for (String macId : macList) {
@@ -584,10 +591,10 @@ public class OrderService extends BaseService<Order> {
 
         // 收款明细
         List<RecPayResponse> recPayList = recPayMapper.selectByCond(new RecPayQuery().setBiznisId(id));
-        if(recPayList != null && recPayList.size() > 0){
+        if (recPayList != null && recPayList.size() > 0) {
             List<RecPayItemResponse> receiptItem = recPayItemMapper.selectByCond(new RecPayItemQuery().setRpId(recPayList.get(0).getRpId()));
             dataInfo.put("receiptItem", receiptItem);
-        }else{
+        } else {
             dataInfo.put("receiptItem", new ArrayList<RecPayResponse>());
         }
         return ResponseResultUtil.success(dataInfo);