Jelajahi Sumber

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

koushanshan 2 tahun lalu
induk
melakukan
4da6322097
37 mengubah file dengan 1428 tambahan dan 506 penghapusan
  1. 38 18
      src/main/java/com/dk/mdm/controller/FileController.java
  2. 9 1
      src/main/java/com/dk/mdm/controller/mac/OtherPayableController.java
  3. 9 0
      src/main/java/com/dk/mdm/controller/mac/OtherReceivableController.java
  4. 0 24
      src/main/java/com/dk/mdm/controller/mst/CusFollowStaffController.java
  5. 0 24
      src/main/java/com/dk/mdm/controller/mst/OrgMacController.java
  6. 0 24
      src/main/java/com/dk/mdm/controller/mst/OrgWhController.java
  7. 5 1
      src/main/java/com/dk/mdm/infrastructure/util/AuthUtils.java
  8. 13 0
      src/main/java/com/dk/mdm/mapper/common/CommonMapper.java
  9. 59 1
      src/main/java/com/dk/mdm/mapper/common/CommonMapper.xml
  10. 6 4
      src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.xml
  11. 5 0
      src/main/java/com/dk/mdm/mapper/ivt/OutboundMapper.xml
  12. 1 0
      src/main/java/com/dk/mdm/mapper/mac/OtherReceivableMapper.xml
  13. 9 1
      src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.java
  14. 14 3
      src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.xml
  15. 5 0
      src/main/java/com/dk/mdm/mapper/mst/CusFollowMapper.xml
  16. 1 1
      src/main/java/com/dk/mdm/mapper/mst/MoneyAccountMapper.xml
  17. 4 1
      src/main/java/com/dk/mdm/mapper/mst/RoleMapper.xml
  18. 2 1
      src/main/java/com/dk/mdm/mapper/mst/StaffPurviewMapper.xml
  19. 12 4
      src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.xml
  20. 2 0
      src/main/java/com/dk/mdm/mapper/wxapi/basic/WxCommonMapper.xml
  21. 1 1
      src/main/java/com/dk/mdm/model/pojo/mac/RecPay.java
  22. 3 0
      src/main/java/com/dk/mdm/model/pojo/sale/OrderItem.java
  23. 3 0
      src/main/java/com/dk/mdm/model/query/mst/RoleQuery.java
  24. 5 0
      src/main/java/com/dk/mdm/model/query/sale/OrderItemQuery.java
  25. 7 0
      src/main/java/com/dk/mdm/model/response/mac/OtherReceivableResponse.java
  26. 3 0
      src/main/java/com/dk/mdm/model/response/mst/CusFollowResponse.java
  27. 3 3
      src/main/java/com/dk/mdm/model/response/sale/OrderItemResponse.java
  28. 5 2
      src/main/java/com/dk/mdm/model/vo/mac/OtherPayableVO.java
  29. 5 2
      src/main/java/com/dk/mdm/model/vo/mac/OtherReceivableVO.java
  30. 3 0
      src/main/java/com/dk/mdm/model/vo/sale/OrderItemVO.java
  31. 8 0
      src/main/java/com/dk/mdm/service/common/CommonService.java
  32. 588 172
      src/main/java/com/dk/mdm/service/mac/OtherPayableService.java
  33. 587 166
      src/main/java/com/dk/mdm/service/mac/OtherReceivableService.java
  34. 11 3
      src/main/java/com/dk/mdm/service/mst/CustomerService.java
  35. 0 24
      src/main/java/com/dk/mdm/service/mst/OrgMacService.java
  36. 0 23
      src/main/java/com/dk/mdm/service/mst/OrgWhService.java
  37. 2 2
      src/main/java/com/dk/mdm/service/sale/OrderService.java

+ 38 - 18
src/main/java/com/dk/mdm/controller/FileController.java

@@ -1,10 +1,13 @@
 package com.dk.mdm.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.dk.common.infrastructure.constant.Constant;
 import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
+import com.dk.mdm.infrastructure.util.AuthUtils;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -21,10 +24,13 @@ public class FileController {
     @Value("${upload-path}")
     private String uploadPath;
 
+    @Autowired
+    private AuthUtils authUtils;
+
     /**
-     * @desc   : 上传文件
+     * @desc : 上传文件
      * @author : 洪旭东
-     * @date   : 2023-06-26 14:09
+     * @date : 2023-06-26 14:09
      */
     @ApiOperation(value = "上传文件", notes = "上传文件")
     @PostMapping("upload")
@@ -45,7 +51,7 @@ public class FileController {
             JSONObject json = new JSONObject();
             json.put("path", filePath.replace(uploadPath, ""));
             json.put("name", fileName);
-            json.put("type",getFileType(fileName));
+            json.put("type", getFileType(fileName));
             json.put("createTime", LocalDateTime.now());
             return ResponseResultUtil.success(json);
         } catch (IOException e) {
@@ -55,37 +61,51 @@ public class FileController {
     }
 
     /**
-     * @desc   : 获取文件类型
+     * @desc : 获取文件类型
      * @author : 周兴
-     * @date   : 2024-03-27 14:09
+     * @date : 2024-03-27 14:09
      */
     private String getFileType(String fileName) {
-        if(fileName.indexOf(".")>=0 ){
+        if (fileName.indexOf(".") >= 0) {
+            String appCode = authUtils.getStaff().getAppCode();
             String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
             fileType = fileType.toLowerCase();
 
-            if ("jpg".equals(fileType)  || "jepg".equals(fileType)  || "png".equals(fileType)) {
-                return "img";
-            }
             if ("mp4".equals(fileType) || "avi".equals(fileType) || "mov".equals(fileType)) {
                 return "video";
             }
-            if ("xls".equals(fileType) || "xlsx".equals(fileType)) {
-                return "excel";
-            }
-            if ("pdf".equals(fileType)) {
-                return "pdf";
+            // 小程序
+            if (Constant.AppCode.WEIXIN.getCode().equals(appCode)) {
+                if ("xls".equals(fileType) || "xlsx".equals(fileType)) {
+                    return "file";
+                }
+                if ("pdf".equals(fileType)) {
+                    return "file";
+                }
+                if ("jpg".equals(fileType) || "jepg".equals(fileType) || "png".equals(fileType)) {
+                    return "image";
+                }
+            } else {
+                if ("xls".equals(fileType) || "xlsx".equals(fileType)) {
+                    return "excel";
+                }
+                if ("pdf".equals(fileType)) {
+                    return "pdf";
+                }
+                if ("jpg".equals(fileType) || "jepg".equals(fileType) || "png".equals(fileType)) {
+                    return "img";
+                }
             }
         }
         return "";
     }
 
     /**
-     * @desc   : 根据类型创建目录文件夹
+     * @desc : 根据类型创建目录文件夹
      * @author : 洪旭东
-     * @date   : 2023-06-26 14:10
+     * @date : 2023-06-26 14:10
      */
-    private String createDirByPath(String folder){
+    private String createDirByPath(String folder) {
         //斜线
         final String diagonal = "/";
 
@@ -103,6 +123,6 @@ public class FileController {
                 dir.mkdir();
             }
         }
-        return base+diagonal;
+        return base + diagonal;
     }
 }

+ 9 - 1
src/main/java/com/dk/mdm/controller/mac/OtherPayableController.java

@@ -79,7 +79,15 @@ public class OtherPayableController{
     public ResponseResultVO<?> getOtherPayableForUpdate(@PathVariable String id) {
         return otherPayableService.getOtherPayableForUpdate(id);
     }
-
+    /**
+     * @desc : 通过ID查询
+     * @author : 王英杰
+     * @date : 2023/1/9 10:41
+     */
+    @PostMapping({"/{id}"})
+    public ResponseResultVO selectById(@PathVariable String id) {
+        return otherPayableService.getOtherPayableForUpdate(id);
+    }
     /**
      * @desc : 作废
      * @author : 付斌

+ 9 - 0
src/main/java/com/dk/mdm/controller/mac/OtherReceivableController.java

@@ -79,6 +79,15 @@ public class OtherReceivableController{
     public ResponseResultVO<?> getOtherReceivableForUpdate(@PathVariable String id) {
         return otherReceivableService.getOtherReceivableForUpdate(id);
     }
+    /**
+     * @desc : 通过ID查询
+     * @author : 王英杰
+     * @date : 2023/1/9 10:41
+     */
+    @PostMapping({"/{id}"})
+    public ResponseResultVO selectById(@PathVariable String id) {
+        return otherReceivableService.getOtherReceivableForUpdate(id);
+    }
 
     /**
      * @desc : 作废

+ 0 - 24
src/main/java/com/dk/mdm/controller/mst/CusFollowStaffController.java

@@ -1,24 +0,0 @@
-package com.dk.mdm.controller.mst;
-
-import com.dk.mdm.model.pojo.mst.CusFollowStaff;
-import com.dk.common.controller.BaseController;
-import com.dk.common.service.BaseService;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RestController;
-import io.swagger.annotations.Api;
-import com.dk.mdm.service.mst.CusFollowStaffService;
-
-@Api(tags = "客户跟进人API接口")
-@RestController
-@RequestMapping("/cusFollowStaff")
-public class CusFollowStaffController{
-
-    public BaseService<CusFollowStaff> getService() {
-        return cusFollowStaffService;
-    }
-
-    @Autowired
-    private CusFollowStaffService cusFollowStaffService;
-
-}

+ 0 - 24
src/main/java/com/dk/mdm/controller/mst/OrgMacController.java

@@ -1,24 +0,0 @@
-package com.dk.mdm.controller.mst;
-
-import com.dk.mdm.model.pojo.mst.OrgMac;
-import com.dk.common.controller.BaseController;
-import com.dk.common.service.BaseService;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RestController;
-import io.swagger.annotations.Api;
-import com.dk.mdm.service.mst.OrgMacService;
-
-@Api(tags = "组织资金账户API接口")
-@RestController
-@RequestMapping("/orgMac")
-public class OrgMacController{
-
-    public BaseService<OrgMac> getService() {
-        return orgMacService;
-    }
-
-    @Autowired
-    private OrgMacService orgMacService;
-
-}

+ 0 - 24
src/main/java/com/dk/mdm/controller/mst/OrgWhController.java

@@ -1,24 +0,0 @@
-package com.dk.mdm.controller.mst;
-
-import com.dk.mdm.model.pojo.mst.OrgWh;
-import com.dk.common.controller.BaseController;
-import com.dk.common.service.BaseService;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RestController;
-import io.swagger.annotations.Api;
-import com.dk.mdm.service.mst.OrgWhService;
-
-@Api(tags = "组织仓库API接口")
-@RestController
-@RequestMapping("/orgWh")
-public class OrgWhController{
-
-    public BaseService<OrgWh> getService() {
-        return orgWhService;
-    }
-
-    @Autowired
-    private OrgWhService orgWhService;
-
-}

+ 5 - 1
src/main/java/com/dk/mdm/infrastructure/util/AuthUtils.java

@@ -80,7 +80,11 @@ public class AuthUtils {
             if (json==null){
                 return null;
             }else{
-                return JSONObject.parseObject(JSONObject.toJSONString(JSONObject.parseObject(json)), StaffEntity.class);
+                StaffEntity staffEntity = JSONObject.parseObject(JSONObject.toJSONString(JSONObject.parseObject(json)), StaffEntity.class);
+                staffEntity.setAppCode(appCode);
+                staffEntity.setCpCode(cpCode);
+                staffEntity.setCpId(Integer.parseInt(cpId) );
+                return staffEntity;
             }
         } catch (Exception e) {
             log.error(e.toString(),e);

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

@@ -372,6 +372,12 @@ public interface CommonMapper extends BaseMapper<Map<String, Object>> {
     Long getInventoryCountByPage(Map param);
 
     List<Map<String, Object>> getSaleChannel(Map param);
+    /**
+     * @desc : 渠道-小程序
+     * @author : 姜永辉
+     * @date : 2024-03-05 10:52
+     */
+    List<Map<String, Object>> getSaleChannelPurviewType(Map param);
 
 
     /**
@@ -402,6 +408,13 @@ public interface CommonMapper extends BaseMapper<Map<String, Object>> {
      */
     List<Map<String, Object>> getStaff(Map param);
 
+    /**
+     * @desc   : 获取员工-范围权限
+     * @date   : 2024/3/13 16:24
+     * @author : 寇珊珊
+     */
+    List<Map<String, Object>> getStaffPurviewType(Map param);
+
 
     /**
      * @desc   : 获取组织机构

+ 59 - 1
src/main/java/com/dk/mdm/mapper/common/CommonMapper.xml

@@ -975,9 +975,38 @@
         channel_name AS "channelName"
         FROM dkic_b.t_mst_sale_channel
         <where>
+            flg_valid
             <if test="cpId != null">
                 AND cp_id = #{cpId}
             </if>
+            order by display_no
+        </where>
+    </select>
+
+    <!--    获取销售渠道-->
+    <select id="getSaleChannelPurviewType" resultType="java.util.Map">
+        SELECT
+        sc.channel_id AS "channelId",
+        sc.channel_id AS "id",
+        sc.channel_code AS "channelCode",
+        sc.channel_name AS "channelName",
+        COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
+        CASE WHEN  scsc.channel_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
+        FROM dkic_b.t_mst_sale_channel sc
+        left JOIN dkic_b.t_mst_sale_channel scsc ON scsc.channel_id = sc.channel_id and sc.channel_id::uuid =  any ( (
+        select  data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
+        <where>
+            sc.flg_valid
+            <if test="cpId != null">
+                AND sc.cp_id = #{cpId}
+            </if>
+            <if test="channelCode !=null and channelCode !=''">
+                AND sc.channel_code LIKE concat('%',my_ex.likequery(#{channelCode}),'%')
+            </if>
+            <if test="channelName !=null and channelName !=''">
+                AND sc.channel_name LIKE concat('%',my_ex.likequery(#{channelName}),'%')
+            </if>
+            order by sc.display_no
         </where>
     </select>
     <!--获取仓库档案-->
@@ -1041,9 +1070,11 @@
         tms.return_address as "addressFull"
         from dkic_b.t_mst_supplier tms
         <where >
+             tms.sup_type = '供应商类别-采购'
             <if test="flgValid">
                 AND tms.flgValid
             </if>
+
             <if test="objCode != null and objCode != ''">
                 AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
             </if>
@@ -1108,6 +1139,7 @@
         null as "addressFull"
         from dkic_b.t_mst_supplier tms
         <where>
+            tms.sup_type = '供应商类别-采购'
             <if test="flgValid">
                 AND tms.flgValid
             </if>
@@ -1176,7 +1208,9 @@
         left join dkic_b.t_mst_org o on o.org_id = s.org_id
         left join dkic_a.t_a_company c on c.cp_id = s.cp_id
         where
-        s.cp_id = #{cpId}
+        s.flg_valid
+        and s.hr_status = 1
+        and s.cp_id = #{cpId}
         <if test="staffCode !=null and staffCode !=''">
             AND s.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
         </if>
@@ -1191,6 +1225,30 @@
         </if>
     </select>
 
+    <!-- 获取用户 -->
+    <select id="getStaffPurviewType" resultType="java.util.Map">
+        select
+        s.staff_name as "staffName"
+        , s.staff_code as "staffCode"
+        , s.staff_id as "staffId",
+        COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
+        CASE WHEN  ss.staff_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
+        FROM dkic_b.t_mst_staff s
+        left JOIN dkic_b.t_mst_staff ss ON ss.staff_id = s.staff_id and s.staff_id::uuid =  any ( (
+            select  data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
+        where
+        s.flg_valid
+        and s.hr_status = 1
+        and s.cp_id = #{cpId}
+        <if test="staffCode !=null and staffCode !=''">
+            AND s.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
+        </if>
+        <if test="staffName !=null and staffName !=''">
+            AND s.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
+        </if>
+
+    </select>
+
 
     <!-- 获取组织机构 -->
     <select id="getOrganization" resultType="java.util.Map">

+ 6 - 4
src/main/java/com/dk/mdm/mapper/ivt/InboundMapper.xml

@@ -97,8 +97,8 @@
 <!--        <result column="orgName" property="orgName" />-->
 <!--        <result column="staff_name" property="staffName" />-->
         <result column="cus_code" property="cusCode" />
-        <result column="cus_name" property="cusName" />
-        <result column="cus_phone" property="cusPhone" />
+<!--        <result column="cus_name" property="cusName" />-->
+<!--        <result column="cus_phone" property="cusPhone" />-->
         <result column="contact_phone" property="contactPhone" />
         <result column="contact_name" property="contactName" />
         <result column="address_area" property="addressArea" typeHandler="JsonTypeHandler"/>
@@ -605,8 +605,8 @@
         ,tmo.org_name  as "orgName"
         ,tms.staff_name  as "staffName"
         ,tmc.cus_code
-        ,tmc.cus_name
-        ,tmc.cus_phone
+        ,tmc.cus_name                                      as "cusName"
+        ,tmc.cus_phone                                     as "cusPhone"
         ,tmc.contact_phone
         ,tmc.contact_name
         ,tmc.address_area
@@ -699,6 +699,7 @@
         tmc.cus_name                                      as "cusName",
         tmc.cus_phone                                     as "cusPhone",
         tmc.cus_from                                      as "cusFrom",
+        tmc.address_full,
         makestaff.staff_name                              as "makeStaffName",
         sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
         sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",
@@ -753,6 +754,7 @@
         tmc.cus_name                                      as "cusName",
         tmc.cus_phone                                     as "cusPhone",
         tmc.cus_from                                      as "cusFrom",
+        tmc.address_full,
         makestaff.staff_name                              as "makeStaffName",
         sys.f_get_name_i18n(tdktype.kind_name_i18n, 'zh_CN') AS  "intoTypeName",
         sys.f_get_name_i18n(tdk.kind_name_i18n, 'zh_CN') AS  "intoStatusName",

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

@@ -226,6 +226,11 @@
             <if test="flgValidList != null and flgValidList.size()>0">
                 AND t.flg_valid =any(#{flgValidList, typeHandler=BooleanListTypeHandler})
             </if>
+            <if test="searchText !=null">
+                AND (  t.out_no LIKE concat('%', my_ex.likequery(#{searchText}), '%')
+                OR   t.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%')
+                )
+            </if>
         </where>
     </sql>
 

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

@@ -175,6 +175,7 @@
                t.object_type,
                sys.f_get_name_i18n(tdk1.kind_name_i18n, #{i18n}) as "objectTypeName",
                t.object_id,
+               tmc.cus_id         as "cusId",
                tmc.cus_code         as "cusCode",
                tmc.cus_name         as "cusName",
                tmc.cus_phone        as "cusPhone",

+ 9 - 1
src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.java

@@ -4,6 +4,7 @@ import com.dk.mdm.model.pojo.mac.RecPay;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.query.mac.RecPayQuery;
 import com.dk.mdm.model.response.mac.RecPayResponse;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -39,7 +40,14 @@ public interface RecPayMapper extends BaseMapper<RecPay>{
      * @author : 付斌
      * @date   : 2024-03-03 9:25
      */
-    RecPay selectByBiznisIdIdForUpdate(String id);
+    RecPay selectByBiznisIdForUpdate(String id);
+
+    /**
+     * @desc   : 根据BiznisId进行查询
+     * @author : 付斌
+     * @date   : 2024-03-03 9:25
+     */
+    RecPay selectByBiznisId(String id);
 
     /**
      * @desc   : 根据条件进行查询

+ 14 - 3
src/main/java/com/dk/mdm/mapper/mac/RecPayMapper.xml

@@ -270,19 +270,30 @@
         SELECT
         <include refid="Base_Column_List"/>
         FROM dkic_b.t_mac_rec_pay
-        WHERE rp_id = #{id}::uuid
+        WHERE flg_valid
+          and rp_id = #{id}::uuid
         for update
     </select>
 
     <!-- 根据主键锁定表t_mac_rec_pay的一行数据 -->
-    <select id="selectByBiznisIdIdForUpdate" resultMap="BaseResultMap">
+    <select id="selectByBiznisIdForUpdate" resultMap="BaseResultMap">
         SELECT
         <include refid="Base_Column_List"/>
         FROM dkic_b.t_mac_rec_pay
-        WHERE biznis_id = #{id}::uuid
+        WHERE flg_valid
+          and biznis_id = #{id}::uuid
         for update
     </select>
 
+    <!-- 根据主键锁定表t_mac_rec_pay的一行数据 -->
+    <select id="selectByBiznisId" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM dkic_b.t_mac_rec_pay
+        WHERE flg_valid
+          and biznis_id = #{id}::uuid
+    </select>
+
     <!-- 根据主键锁定表t_mac_rec_pay的多行数据 -->
     <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
         SELECT

+ 5 - 0
src/main/java/com/dk/mdm/mapper/mst/CusFollowMapper.xml

@@ -67,6 +67,7 @@
         <result column="sale_status" property="saleStatus"/>
         <result column="channel_id" property="channelId"/>
         <result column="cusName" property="cusName"/>
+        <result column="cusCode" property="cusCode"/>
         <result column="orgName" property="orgName"/>
         <result column="staffName" property="staffName"/>
         <result column="follow_count" property="followCount"/>
@@ -74,6 +75,7 @@
         <result column="create_time" property="createTime"  typeHandler="TimestampTypeHandler"/>
         <result column="follow_status_name" property="followStatusName"/>
         <result column="cus_name" property="cusName"/>
+        <result column="cus_code" property="cusCode"/>
         <result column="cus_phone" property="cusPhone"/>
         <result column="address_full" property="addressFull"/>
         <result column="address_no" property="addressNo"/>
@@ -251,6 +253,7 @@
         (CASE
         WHEN tccf.follow_status = '跟进状态-接待' THEN '无联系人'
         ELSE tmc.cus_name END ) AS cus_name,
+        tmc.cus_code as cus_code,
         tmc.cus_phone AS cus_phone,
         tmc.sale_status AS sale_status,
         tmc.channel_id AS channel_id,
@@ -274,6 +277,7 @@
         LEFT JOIN sys.t_data_kind tdk2 on tdk2.kind_code = tccf.intention
         LEFT JOIN sys.t_data_kind tdk3 on tdk3.kind_code = tccf.stay_time_len
         <include refid="Condition_Join"/>
+        order by  tccf.follow_time desc
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
             limit #{end} offset #{start}
         </if>
@@ -284,6 +288,7 @@
         SELECT
         <include refid="Base_Column_List_Join"/>,
         tmc.cus_name AS "cusName",
+        tmc.cus_code as "cusCode",
         tmc.cus_phone AS "cusPhone",
         tmc.address_full AS "addressFull",
         tmo.org_name  AS  "orgName",

+ 1 - 1
src/main/java/com/dk/mdm/mapper/mst/MoneyAccountMapper.xml

@@ -140,7 +140,7 @@
         FROM
         dkic_b.t_mst_dictionary_data tmdd
         WHERE
-        tmdd.dict_code = '账户类别' UNION ALL
+        tmdd.dict_code = '基础资料-账户' UNION ALL
         SELECT
         t.mac_id AS "macId",
         t.mac_Type as "macType",

+ 4 - 1
src/main/java/com/dk/mdm/mapper/mst/RoleMapper.xml

@@ -102,7 +102,10 @@
             <if test="flgNolimitSen != null">
                 AND flg_nolimit_sen = #{flgNolimitSen}
             </if>
-
+            <if test="flgValidList != null and flgValidList.size()>0">
+                AND flg_valid =
+                any(#{flgValidList, typeHandler=BooleanListTypeHandler})
+            </if>
             <if  test="searchText != null">
                 AND (role_name  like concat('%', my_ex.likequery(#{searchText}) , '%')
                 OR  role_code  like concat('%', my_ex.likequery(#{searchText}) , '%')

+ 2 - 1
src/main/java/com/dk/mdm/mapper/mst/StaffPurviewMapper.xml

@@ -152,10 +152,11 @@
                orgb.org_id                                            AS "orgId",
                org.level_no                                           AS "levelNo",
                org.level_code                                         as "levelCode",
+               COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
                CASE WHEN orgb.org_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
         FROM dkic_b.t_mst_org org
                  left JOIN dkic_b.t_mst_org orgb ON orgb.org_id = org.org_id and org.org_id::uuid =  any ( (
-                 select  data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid)::uuid[])
+                 select  data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
         WHERE org.flg_valid
           AND org.cp_id = #{cpId}
         ORDER BY org.level_code;

+ 12 - 4
src/main/java/com/dk/mdm/mapper/sale/OrderItemMapper.xml

@@ -6,12 +6,12 @@
     <!-- 通用查询列 -->
     <sql id="Base_Column_List">
         item_id
-        , order_id, item_index, sku_id, item_qty, price_std, amt_std, price_sale, item_amt, price_discount, non_std_code, out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt, remarks, flg_valid, cp_id
+        , order_id, item_index, sku_id, item_qty, price_std, amt_std, price_sale, item_amt, price_discount, non_std_code, out_status, outing_qty, outing_amt, out_qty, out_amt, return_qty, return_amt, remarks, flg_valid, cp_id, wh_id
     </sql>
 
     <sql id="Base_Column_List_Response">
         t.item_id, t.order_id, t.item_index, t.sku_id, t.item_qty, t.price_std, t.amt_std, t.price_sale, t.item_amt, t.price_discount, t.non_std_code,
-        t.out_status, t.outing_qty, t.outing_amt, t.out_qty, t.out_amt, t.return_qty, t.return_amt, t.remarks, t.flg_valid, t.cp_id
+        t.out_status, t.outing_qty, t.outing_amt, t.out_qty, t.out_amt, t.return_qty, t.return_amt, t.remarks, t.flg_valid, t.cp_id, t.wh_id
     </sql>
 
     <!-- 通用查询映射结果 -->
@@ -37,6 +37,7 @@
                 <result column="remarks" property="remarks"/>
                 <result column="flg_valid" property="flgValid"/>
                 <result column="cp_id" property="cpId"/>
+                <result column="wh_id" property="whId"/>
     </resultMap>
 
     <!-- 通用查询映射结果 -->
@@ -62,6 +63,8 @@
                 <result column="remarks" property="remarks"/>
                 <result column="flg_valid" property="flgValid"/>
                 <result column="cp_id" property="cpId"/>
+                <result column="wh_id" property="whId"/>
+                <result column="wh_name" property="whName"/>
                 <result column="order_no" property="orderNo"/>
                 <result column="transferableQuantity" property="transferableQuantity"/>
     </resultMap>
@@ -163,9 +166,12 @@
                t.out_amt,
                t.return_qty,
                t.return_amt,
-               t.remarks
+               t.remarks,
+               t.wh_id,
+                tmw.wh_name
         FROM dkic_b.t_psi_order_item as t
                  inner join dkic_b.t_mst_goods_sku tmgs on t.sku_id = tmgs.sku_id
+                 left join dkic_b.t_mst_warehouse tmw on tmw.wh_id = t.wh_id
         <include refid="Condition"/>
         order by t.item_index
         <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
@@ -239,6 +245,7 @@
             return_amt,
             remarks,
             cp_id,
+            wh_id,
         </trim>
         )
         values
@@ -264,6 +271,7 @@
                 #{item.returnAmt},
                 #{item.remarks},
                 #{item.cpId},
+                #{item.whId},
             </trim>
             )
         </foreach>
@@ -291,7 +299,7 @@
                t.non_std_code,
                t.remarks,
                i.inv_id                                   as "invId",
-               i.wh_id                                    as "whId",
+               i.wh_id,
                i.inv_qty                                  as "invQty",
                i.usable_qty                               as "usableQty",
                i.wh_name                                  as "whName"

+ 2 - 0
src/main/java/com/dk/mdm/mapper/wxapi/basic/WxCommonMapper.xml

@@ -187,6 +187,7 @@
                 u.org_id as "orgId"
          from dkic_b.t_mst_staff u
          where u.flg_valid
+            and u.hr_status = 1
          and u.cp_id = #{cpId}
     </select>
     <!--    获取品牌-->
@@ -203,6 +204,7 @@
         select tmc.channel_id as id, tmc.channel_name as name
         from mst.t_m_channel tmc
         where tmc.flg_valid
+          and tmc.cp_id = #{cpId}
         order by tmc.display_no
     </select>
     <!--    仓库-->

+ 1 - 1
src/main/java/com/dk/mdm/model/pojo/mac/RecPay.java

@@ -118,7 +118,7 @@ public class RecPay extends PageInfo<RecPay> implements Serializable {
     private BigDecimal sumAmtPayableHandle;
 
 
-    @Excel(name = "合计核销金额")
+    @Excel(name = "合计优惠金额")
     @ApiModelProperty(value = "合计核销金额")
     private BigDecimal sumWaiveAmt;
 

+ 3 - 0
src/main/java/com/dk/mdm/model/pojo/sale/OrderItem.java

@@ -209,6 +209,9 @@ public class OrderItem extends PageInfo<OrderItem> implements Serializable {
     @TableField(fill = FieldFill.INSERT)
     private Integer cpId;
 
+    @ApiModelProperty(value = "仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whId;
 
     private static final long serialVersionUID = 1L;
 

+ 3 - 0
src/main/java/com/dk/mdm/model/query/mst/RoleQuery.java

@@ -22,6 +22,7 @@ import lombok.experimental.Accessors;
 
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  *  角色
@@ -173,6 +174,8 @@ public class RoleQuery extends PageInfo<Role> implements Serializable {
     @ApiModelProperty(value = "")
     private Boolean flgNolimitSen;
 
+    private List<Boolean> flgValidList;
+
     private String searchText;
 
 

+ 5 - 0
src/main/java/com/dk/mdm/model/query/sale/OrderItemQuery.java

@@ -212,6 +212,11 @@ public class OrderItemQuery extends PageInfo<OrderItemQuery> implements Serializ
     @ApiModelProperty(value = "订单单号")
     private String orderNo;
 
+
+    @ApiModelProperty(value = "仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whId;
+
     private static final long serialVersionUID = 1L;
 
 }

+ 7 - 0
src/main/java/com/dk/mdm/model/response/mac/OtherReceivableResponse.java

@@ -48,6 +48,13 @@ public class OtherReceivableResponse extends PageInfo<OtherReceivableResponse> i
     @ApiModelProperty(value = "其它收入单ID")
     @TableField(typeHandler = UuidTypeHandler.class)
     private String receivableId;
+    /**
+     * 客户ID
+     */
+    @Excel(name = "客户ID")
+    @ApiModelProperty(value = "客户ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String cusId;
 
 
     /**

+ 3 - 0
src/main/java/com/dk/mdm/model/response/mst/CusFollowResponse.java

@@ -215,6 +215,9 @@ public class CusFollowResponse implements Serializable {
     @ApiModelProperty(value = "客户名称")
     private String cusName;
 
+    @ApiModelProperty(value = "客户编号")
+    private String cusCode;
+
     @ApiModelProperty(value = "客户电话")
     private String cusPhone;
 

+ 3 - 3
src/main/java/com/dk/mdm/model/response/sale/OrderItemResponse.java

@@ -237,9 +237,6 @@ public class OrderItemResponse extends PageInfo<OrderItemResponse> implements Se
     @ApiModelProperty(value = "库存ID")
     private String invId;
 
-    @ApiModelProperty(value = "仓库ID")
-    private String whId;
-
     @ApiModelProperty(value = "库存数量")
     private BigDecimal invQty;
 
@@ -287,6 +284,9 @@ public class OrderItemResponse extends PageInfo<OrderItemResponse> implements Se
     @ApiModelProperty(value = "可转采购数量")
     private BigDecimal transferableQuantity;
 
+    @ApiModelProperty(value = "仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whId;
 
     private static final long serialVersionUID = 1L;
 

+ 5 - 2
src/main/java/com/dk/mdm/model/vo/mac/OtherPayableVO.java

@@ -177,8 +177,11 @@ public class OtherPayableVO extends PageInfo<OtherPayableVO> implements Serializ
     @ApiModelProperty(value = "明细")
     private List<OtherPayableItemVO> itemList;
 
-    @ApiModelProperty(value = "删除明细")
-    private List<OtherPayableItemVO> deleteItemList;
+    @ApiModelProperty(value = "合计付款")
+    private BigDecimal sumAmtPay;
+
+    @ApiModelProperty(value = "付款明细")
+    private List<RecPayItemVO> paymentList;
 
 
     private static final long serialVersionUID = 1L;

+ 5 - 2
src/main/java/com/dk/mdm/model/vo/mac/OtherReceivableVO.java

@@ -176,8 +176,11 @@ public class OtherReceivableVO extends PageInfo<OtherReceivableVO> implements Se
     @ApiModelProperty(value = "明细")
     private List<OtherReceivableItemVO> itemList;
 
-    @ApiModelProperty(value = "删除明细")
-    private List<OtherReceivableItemVO> deleteItemList;
+    @ApiModelProperty(value = "合计收款")
+    private BigDecimal sumAmtRec;
+
+    @ApiModelProperty(value = "收款明细")
+    private List<RecPayItemVO> receiptList;
 
     private static final long serialVersionUID = 1L;
 

+ 3 - 0
src/main/java/com/dk/mdm/model/vo/sale/OrderItemVO.java

@@ -209,6 +209,9 @@ public class OrderItemVO extends PageInfo<OrderItemVO> implements Serializable {
     @ApiModelProperty(value = "企业ID")
     private Integer cpId;
 
+    @ApiModelProperty(value = "仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whId;
 
     private static final long serialVersionUID = 1L;
 

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

@@ -694,6 +694,10 @@ public class CommonService extends BaseService<Map<String, Object>> {
         if (dataSourceCode.equals("saleChannel")) {
             list = commonMapper.getSaleChannel(map);
         }
+        //销售渠道
+        if (dataSourceCode.equals("saleChannelPurviewType")) {
+            list = commonMapper.getSaleChannelPurviewType(param);
+        }
         //部门
         if (dataSourceCode.equals("org")) {
             list = commonMapper.getOrg(map);
@@ -702,6 +706,10 @@ public class CommonService extends BaseService<Map<String, Object>> {
         if (dataSourceCode.equals("staff")) {
             list = commonMapper.getStaff(map);
         }
+        //员工
+        if (dataSourceCode.equals("staffPurviewType")) {
+            list = commonMapper.getStaffPurviewType(param);
+        }
         //仓库
         if (dataSourceCode.equals("warehouse")) {
             list = commonMapper.getWarehouse(map);

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

@@ -11,195 +11,611 @@ import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.mac.OtherPayableConvert;
 import com.dk.mdm.infrastructure.convert.mac.OtherPayableItemConvert;
-import com.dk.mdm.mapper.mac.OtherPayableItemMapper;
-import com.dk.mdm.model.pojo.mac.OtherPayable;
-import com.dk.mdm.mapper.mac.OtherPayableMapper;
+import com.dk.mdm.infrastructure.convert.mac.RecPayItemConvert;
+import com.dk.mdm.mapper.mac.*;
+import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
+import com.dk.mdm.mapper.mst.MoneyAccountMapper;
+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.OtherPayable;
-import com.dk.mdm.model.pojo.mac.OtherPayableItem;
+import com.dk.mdm.model.pojo.mst.MoneyAccount;
+import com.dk.mdm.model.pojo.mst.MoneyAccountItem;
 import com.dk.mdm.model.query.mac.OtherPayableItemQuery;
 import com.dk.mdm.model.query.mac.OtherPayableQuery;
+import com.dk.mdm.model.query.mac.RecPayItemQuery;
 import com.dk.mdm.model.response.mac.OtherPayableItemResponse;
 import com.dk.mdm.model.response.mac.OtherPayableResponse;
+import com.dk.mdm.model.response.mac.RecPayItemResponse;
 import com.dk.mdm.model.vo.mac.OtherPayableItemVO;
 import com.dk.mdm.model.vo.mac.OtherPayableVO;
+import com.dk.mdm.model.vo.mac.RecPayItemVO;
 import com.dk.mdm.service.common.CommonService;
+import com.dk.mdm.service.mst.MoneyAccountService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.math.BigDecimal;
+import java.util.*;
 
 @Service
 @Transactional
 public class OtherPayableService extends BaseService<OtherPayable> {
 
-	@Override
-	public String getPrimaryKey() {
-		return "payable_id";
-	}
-
-	@Override
-	public BaseMapper<OtherPayable> getRepository() {
-		return otherPayableMapper;
-	}
-
-	@Autowired
-	private OtherPayableMapper otherPayableMapper;
-
-	@Autowired
-	private OtherPayableItemMapper otherPayableItemMapper;
-
-	@Autowired
-	private CommonService commonService;
-
-	@Autowired
-	private AccountService accountService;
-
-	@Autowired
-	private OtherPayableConvert otherPayableConvert;
-
-	@Autowired
-	private OtherPayableItemConvert otherPayableItemConvert;
-
-	/**
-	 * @desc : 条件查询
-	 * @author : 付斌
-	 * @date : 2023/1/9 10:40
-	 */
-	@Pagination
-	public ResponseResultVO<PageList<OtherPayableResponse>> selectByCond(OtherPayableQuery otherPayableQuery) {
-		return super.mergeListWithCount(otherPayableQuery, otherPayableMapper.selectByCond(otherPayableQuery),
-				otherPayableMapper.countByCond(otherPayableQuery));
-	}
-
-	/**
-	 * @desc : 查询明细(货物、收款、附件)
-	 * @author : 付斌
-	 * @date : 2024-02-28 13:25
-	 */
-	@Pagination
-	public ResponseResultVO<Map<String, Object>> selectOtherPayableInfoById(String id) {
-		Map<String, Object> result = new HashMap<>();
-		// 商品明细
-		List<OtherPayableItemResponse> otherPayableItem = otherPayableItemMapper.selectByCond(new OtherPayableItemQuery().setPayableId(id));
-		result.put("otherPayableItem", otherPayableItem);
-
-		// 附件
-		return ResponseResultUtil.success(result);
-	}
-
-	/**
-	 * @desc : 新建方法
-	 * @author : 付斌
-	 * @date : 2023/1/9 10:49
-	 */
-	@Transactional(
-			rollbackFor = {Exception.class}
-	)
-	public ResponseResultVO<?> insert(OtherPayableVO otherPayableVO) {
-
-		// 获取单号
-		Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERPAYABLE.getName(), false);
-		otherPayableVO.setPayableId(codeMap.get("outId").toString()).setPayableNo(codeMap.get("outNote").toString())
-				.setObjectType(Constant.ObjectType.SUP.getName());
-		// 转化实体
-		OtherPayable otherPayable = otherPayableConvert.convertToPo(otherPayableVO);
-		// 总单保存
-		super.insert(otherPayable);
-
-		// 明细保存
-		if (otherPayableVO.getItemList() != null && otherPayableVO.getItemList().size() > 0) {
-			for (OtherPayableItemVO otherPayableItemVO : otherPayableVO.getItemList()) {
-				OtherPayableItem otherPayableItem = otherPayableItemConvert.convertToPo(otherPayableItemVO);
-				otherPayableItem.setPayableId(otherPayable.getPayableId()).setCpId(otherPayable.getCpId());
-				otherPayableItemMapper.insert(otherPayableItem);
-			}
-		}
-
-		// 应付记账
-		accountService.accPayable(otherPayable.getPayableId(),"t_mac_other_payable");
-		return ResponseResultUtil.success();
-	}
-
-	/**
-	 * @desc : 编辑方法
-	 * @author : 付斌
-	 * @date : 2023/1/9 10:49
-	 */
-	@Transactional(
-			rollbackFor = {Exception.class}
-	)
-	public ResponseResultVO<?> update(OtherPayableVO otherPayableVO) {
-
-		// 先更新收款单总表,否则id又更错了
-		OtherPayable otherPayable = otherPayableConvert.convertToPo(otherPayableVO);
-		super.update(otherPayable, new UpdateWrapper<OtherPayable>().lambda().eq(OtherPayable::getPayableId,
-				UUID.fromString(otherPayable.getPayableId())));
-
-		// 应付反记账
-		accountService.reversePayable(otherPayableVO.getPayableId(),"t_mac_other_payable");
-
-		// 将之前的明细全部删除
-		List<OtherPayableItem> otherPayableItemOriginalList = otherPayableItemMapper.selectByZIdForUpdate(otherPayableVO.getPayableId());
-		for (OtherPayableItem otherPayableItem : otherPayableItemOriginalList) {
-			otherPayableItemMapper.deleteById(otherPayableItem.getItemId());
-		}
-
-		// 明细保存
-		if (otherPayableVO.getItemList() != null && otherPayableVO.getItemList().size() > 0) {
-			for (OtherPayableItemVO otherPayableItemVO : otherPayableVO.getItemList()) {
-				OtherPayableItem otherPayableItem = otherPayableItemConvert.convertToPo(otherPayableItemVO);
-				otherPayableItem.setItemId(null).setPayableId(otherPayableVO.getPayableId()).setCpId(otherPayableVO.getCpId());
-				otherPayableItemMapper.insert(otherPayableItem);
-			}
-		}
-
-		// 应付记账
-		accountService.accPayable(otherPayableVO.getPayableId(),"t_mac_other_payable");
-		return ResponseResultUtil.success();
-	}
-
-	/**
-	 * @desc : 获取信息(编辑用)
-	 * @author : 付斌
-	 * @date : 2024-03-02 17:27
-	 */
-	public ResponseResultVO<?> getOtherPayableForUpdate(String id) {
-		Map<String, Object> dataInfo = new HashMap<>();
-		OtherPayableResponse otherPayableResponse = otherPayableMapper.selectById(id);
-		dataInfo.put("data", otherPayableResponse);
-
-		// 商品明细
-		List<OtherPayableItemResponse> otherPayableItemResponse = otherPayableItemMapper.selectByCond(new OtherPayableItemQuery().setPayableId(id));
-		dataInfo.put("dataItem", otherPayableItemResponse);
-		return ResponseResultUtil.success(dataInfo);
-	}
-
-	/**
-	 * @desc : 作废
-	 * @author : 付斌
-	 * @date : 2024-03-08 16:38
-	 */
-	public ResponseResultVO<?> invalid(String id) {
-		OtherPayable otherPayableForUpdate = otherPayableMapper.selectByIdForUpdate(id);
-		// 并发校验
-		if (!otherPayableForUpdate.getFlgValid()) {
-			throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
-		}
-		// 如果所在月份已结账,则不能作废 todo
-
-		// 应付反记账
-		accountService.reversePayable(id,"t_mac_other_payable");
-
-		// 作废
-		OtherPayable otherPayableUpdate = new OtherPayable();
-		otherPayableUpdate.setFlgValid(false).setPayableId(id);
-		super.updateByUuid(otherPayableUpdate);
-		return ResponseResultUtil.success();
-	}
+    @Override
+    public String getPrimaryKey() {
+        return "payable_id";
+    }
+
+    @Override
+    public BaseMapper<OtherPayable> getRepository() {
+        return otherPayableMapper;
+    }
+
+    @Autowired
+    private OtherPayableMapper otherPayableMapper;
+
+    @Autowired
+    private OtherPayableItemMapper otherPayableItemMapper;
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private AccountService accountService;
+
+    @Autowired
+    private AccountMapper accountMapper;
+
+    @Autowired
+    private AccountItemService accountItemService;
+
+    @Autowired
+    private MoneyAccountMapper moneyAccountMapper;
+
+    @Autowired
+    private AccountItemMapper accountItemMapper;
+
+    @Autowired
+    private MoneyAccountService moneyAccountService;
+
+    @Autowired
+    private MoneyAccountItemMapper moneyAccountItemMapper;
+
+    @Autowired
+    private RecPayHandleItemMapper recPayHandleItemMapper;
+
+    @Autowired
+    private RecPayMapper recPayMapper;
+
+    @Autowired
+    private RecPayHandleItemService recPayHandleItemService;
+
+    @Autowired
+    private PaymentService paymentService;
+
+    @Autowired
+    private RecPayItemService recPayItemService;
+
+    @Autowired
+    private RecPayItemMapper recPayItemMapper;
+
+    @Autowired
+    private RecPayItemConvert recPayItemConvert;
+
+    @Autowired
+    private OtherPayableConvert otherPayableConvert;
+
+    @Autowired
+    private OtherPayableItemConvert otherPayableItemConvert;
+
+    /**
+     * @desc : 条件查询
+     * @author : 付斌
+     * @date : 2023/1/9 10:40
+     */
+    @Pagination
+    public ResponseResultVO<PageList<OtherPayableResponse>> selectByCond(OtherPayableQuery otherPayableQuery) {
+        return super.mergeListWithCount(otherPayableQuery, otherPayableMapper.selectByCond(otherPayableQuery),
+                otherPayableMapper.countByCond(otherPayableQuery));
+    }
+
+    /**
+     * @desc : 查询明细(货物、付款、附件)
+     * @author : 付斌
+     * @date : 2024-02-28 13:25
+     */
+    @Pagination
+    public ResponseResultVO<Map<String, Object>> selectOtherPayableInfoById(String id) {
+        Map<String, Object> result = new HashMap<>();
+        // 商品明细
+        List<OtherPayableItemResponse> otherPayableItem = otherPayableItemMapper.selectByCond(new OtherPayableItemQuery().setPayableId(id));
+        result.put("otherPayableItem", otherPayableItem);
+
+        // 附件
+        return ResponseResultUtil.success(result);
+    }
+
+    /**
+     * @desc : 新建方法
+     * @author : 付斌
+     * @date : 2023/1/9 10:49
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> insert(OtherPayableVO otherPayableVO) {
+        // 付款金额不能大于支出金额
+        if(otherPayableVO.getSumAmtPay().compareTo(otherPayableVO.getSumAmtPayable()) == 1){
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.PAYABLE_NO_LESS_PAYMENT.getMessage());
+        }
+
+        // 获取单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERPAYABLE.getName(), false);
+        otherPayableVO.setPayableId(codeMap.get("outId").toString()).setPayableNo(codeMap.get("outNote").toString())
+                .setObjectType(Constant.ObjectType.SUP.getName());
+        // 转化实体
+        OtherPayable otherPayable = otherPayableConvert.convertToPo(otherPayableVO);
+        // 总单保存
+        super.insert(otherPayable);
+
+        // 明细保存
+        if (otherPayableVO.getItemList() != null && otherPayableVO.getItemList().size() > 0) {
+            for (OtherPayableItemVO otherPayableItemVO : otherPayableVO.getItemList()) {
+                OtherPayableItem otherPayableItem = otherPayableItemConvert.convertToPo(otherPayableItemVO);
+                otherPayableItem.setPayableId(otherPayable.getPayableId()).setCpId(otherPayable.getCpId());
+                otherPayableItemMapper.insert(otherPayableItem);
+            }
+        }
+
+        // 应付记账
+        accountService.accPayable(otherPayable.getPayableId(), "t_mac_other_payable");
+
+        // 如果有付款,再做应付付款
+        if (otherPayableVO.getPaymentList() != null && otherPayableVO.getPaymentList().size() > 0) {
+            /*******************************************  付款的处理 begin ********************************************/
+            RecPay recPay = new RecPay();
+            // 获取单号
+            codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+            recPay.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                    .setRpType(Constant.RpType.FU_KUAN.getName()).setObjectId(otherPayableVO.getObjectId())
+                    .setOrgId(otherPayableVO.getOrgId()).setStaffId(otherPayableVO.getStaffId())
+                    .setSumAmtPay(otherPayableVO.getSumAmtPay()).setSumAmtPayableHandle(otherPayableVO.getSumAmtPay())
+                    .setAccDate(otherPayableVO.getAccDate()).setBiznisType(Constant.InventoryDocCode.OTHER_PAYABLE.getTableName())
+                    .setBiznisId(otherPayableVO.getPayableId()).setBiznisNo(otherPayableVO.getPayableNo())
+                    .setMakeStaff(otherPayableVO.getMakeStaff()).setCpId(otherPayableVO.getCpId());
+            // 总单保存
+            recPayMapper.insert(recPay);
+
+            for (RecPayItemVO recPayItemVO : otherPayableVO.getPaymentList()) {
+                RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
+                recPayItem.setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setMakeStaff(recPay.getMakeStaff()).setAccDate(recPay.getAccDate());
+                recPayItemMapper.insert(recPayItem);
+
+                // 插入账款明细
+                AccountItem accountItem = new AccountItem();
+                accountItem.setAccItemType(Constant.accItemType.FU_KUAN.getName())
+                        .setObjectId(recPay.getObjectId()).setOrgId(recPay.getOrgId()).setStaffId(recPay.getStaffId())
+                        .setAccDate(recPay.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtPay(recPayItem.getAmtPay())
+                        .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
+                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId());
+                accountItemMapper.insert(accountItem);
+
+                // 更新付款单上的账款明细Id
+                RecPayItem recPayItemUpdate = new RecPayItem();
+                recPayItemUpdate.setAccItemId(accountItem.getItemId()).setItemId(recPayItem.getItemId());
+                recPayItemService.updateByUuid(recPayItemUpdate);
+
+                // 插入资金流水
+                MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+                moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
+                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtPay().negate()).setAccDate(recPay.getAccDate())
+                        .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
+                moneyAccountItemMapper.insert(moneyAccountItem);
+
+                // 更新资金账户
+                MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
+                MoneyAccount moneyAccountUpdate = new MoneyAccount();
+                moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtPay().negate()))
+                        .setMacId(moneyAccountForUpdate.getMacId());
+                moneyAccountService.updateByUuid(moneyAccountUpdate);
+            }
+            // 插入账款总表
+            Account accountForUpdate = accountService.getCusAccountForUpdate(recPay.getObjectId());
+            // 更新账款总表上付款的相关字段
+            Account accountUpdate = new Account();
+            accountUpdate.setPayment(accountForUpdate.getPayment().add(recPay.getSumAmtPay()))// 总付款金额
+                    .setPaymentResidue(accountForUpdate.getPaymentResidue().add(recPay.getSumAmtPay()))//  可退金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            accountService.updateByUuid(accountUpdate);
+            /*******************************************  付款的处理 end ********************************************/
+
+            /*******************************************  应付付款的处理 begin ********************************************/
+            OtherPayable otherPayableForUpdate = otherPayableMapper.selectByIdForUpdate(otherPayableVO.getPayableId());
+
+            // 应付付款的处理
+            RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
+            recPayHandleItem.setRpId(recPay.getRpId()).setAccItemId(otherPayableForUpdate.getAccItemId())
+                    .setAmtPayableHandle(recPay.getSumAmtPay()).setCpId(recPay.getCpId()).setAccDate(recPay.getAccDate());
+            recPayHandleItemMapper.insert(recPayHandleItem);
+
+            // 账款明细的核销金额和优惠金额
+            AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
+            AccountItem accountItemUpdate = new AccountItem();
+            // 核销金额,超出剩余应付金额
+            if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtPayableHandle()) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtPayableHandle()))
+                    .setAmtWaive(accountItemForUpdate.getAmtWaive())
+                    .setItemId(recPayHandleItem.getAccItemId());
+            // 剩余金额 = 应付金额-应付付款金额
+            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+            accountItemService.updateByUuid(accountItemUpdate);
+
+            // 更新总账上
+            accountForUpdate = accountMapper.selectByIdForUpdate(recPay.getObjectId());
+            accountUpdate = new Account();
+            accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().add(recPayHandleItem.getAmtPayableHandle()))// 总应付付款金额
+                    .setPayableWaive(accountForUpdate.getPayableWaive())//  总应付优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应付 = 总应付账款-总应付付款金额
+            accountUpdate.setPayableResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
+            // 可退金额 = 总付款金额-总应付付款金额+总应付优惠金额
+            accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应付为负数,则不能保存
+            if (accountUpdate.getPayableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+            /*******************************************  应付付款的处理 end ********************************************/
+        }
+        return ResponseResultUtil.success();
+    }
+
+    /**
+     * @desc : 编辑方法
+     * @author : 付斌
+     * @date : 2023/1/9 10:49
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> update(OtherPayableVO otherPayableVO) {
+        // 付款金额不能大于支出金额
+        if(otherPayableVO.getSumAmtPay().compareTo(otherPayableVO.getSumAmtPayable()) == 1){
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.PAYABLE_NO_LESS_PAYMENT.getMessage());
+        }
+
+        /*******************************************  应付付款的处理 begin ********************************************/
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(otherPayableVO.getPayableId());
+        if(recPayForUpdate != null && recPayForUpdate.getFlgValid()) {
+            // 查出并锁定所有应付核销明细
+            AccountItem accountItemForUpdate;
+            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.getAmtPayableHandle()))
+                        .setAmtWaive(accountItemForUpdate.getAmtWaive().subtract(recPayHandleItemForUpdate.getAmtWaive()))
+                        .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
+                accountItemService.updateByUuid(accountItemUpdate);
+
+                // 将核销明细有效标识置为false
+                RecPayHandleItem recPayHandleItemUpdate = new RecPayHandleItem();
+                recPayHandleItemUpdate.setFlgValid(false).setItemId(recPayHandleItemForUpdate.getItemId());
+                recPayHandleItemService.updateByUuid(recPayHandleItemUpdate);
+            }
+
+            // 把总帐上的钱加回来
+            Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+            Account accountUpdate = new Account();
+            accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().subtract(recPayForUpdate.getSumAmtPayableHandle()))// 总应付付款金额
+                    .setPayableWaive(accountForUpdate.getPayableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应付优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应付 = 总应付账款-总应付付款金额
+            accountUpdate.setPayableResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
+            // 可退金额 = 总付款金额-总应付付款金额+总应付优惠金额
+            accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应付为负数,则不能保存
+            if (accountUpdate.getPayableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+
+            // 将之前的明细全部删除
+            List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+            // 需要重新计算的资金账户
+            List<String> macList = new ArrayList<>();
+            for (RecPayItem recPayItem : recPayItemOriginalList) {
+                // 删除收付款明细
+                recPayItemMapper.deleteById(recPayItem.getItemId());
+                // 删除账款明细
+                accountItemMapper.deleteById(recPayItem.getAccItemId());
+                // 删除账户流水
+                moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
+
+                if (!macList.contains(recPayItem.getMacId())) {
+                    macList.add(recPayItem.getMacId());
+                }
+            }
+            // 更新总账表的总付款额和可用额
+            accountService.updatePayment(recPayForUpdate.getObjectId());
+            // 更新账户余额
+            for (String macId : macList) {
+                accountService.updateMac(macId);
+            }
+            // 作废
+            RecPay recPayUpdate = new RecPay();
+            recPayUpdate.setFlgValid(false).setRpId(recPayForUpdate.getRpId());
+            paymentService.updateByUuid(recPayUpdate);
+        }
+        /*******************************************  应付付款的处理 end ********************************************/
+
+        // 先更新付款单总表,否则id又更错了
+        OtherPayable otherPayable = otherPayableConvert.convertToPo(otherPayableVO);
+        super.update(otherPayable, new UpdateWrapper<OtherPayable>().lambda().eq(OtherPayable::getPayableId,
+                UUID.fromString(otherPayable.getPayableId())));
+
+        // 应付反记账
+        accountService.reversePayable(otherPayableVO.getPayableId(), "t_mac_other_payable");
+
+        // 将之前的明细全部删除
+        List<OtherPayableItem> otherPayableItemOriginalList = otherPayableItemMapper.selectByZIdForUpdate(otherPayableVO.getPayableId());
+        for (OtherPayableItem otherPayableItem : otherPayableItemOriginalList) {
+            otherPayableItemMapper.deleteById(otherPayableItem.getItemId());
+        }
+
+        // 明细保存
+        if (otherPayableVO.getItemList() != null && otherPayableVO.getItemList().size() > 0) {
+            for (OtherPayableItemVO otherPayableItemVO : otherPayableVO.getItemList()) {
+                OtherPayableItem otherPayableItem = otherPayableItemConvert.convertToPo(otherPayableItemVO);
+                otherPayableItem.setItemId(null).setPayableId(otherPayableVO.getPayableId()).setCpId(otherPayableVO.getCpId());
+                otherPayableItemMapper.insert(otherPayableItem);
+            }
+        }
+
+        // 应付记账
+        accountService.accPayable(otherPayableVO.getPayableId(), "t_mac_other_payable");
+
+        // 如果有付款,再做应付付款
+        if (otherPayableVO.getPaymentList() != null && otherPayableVO.getPaymentList().size() > 0) {
+            /*******************************************  付款的处理 begin ********************************************/
+            RecPay recPay = new RecPay();
+            // 获取单号
+            Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+            recPay.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                    .setRpType(Constant.RpType.FU_KUAN.getName()).setObjectId(otherPayableVO.getObjectId())
+                    .setOrgId(otherPayableVO.getOrgId()).setStaffId(otherPayableVO.getStaffId())
+                    .setSumAmtPay(otherPayableVO.getSumAmtPay()).setSumAmtPayableHandle(otherPayableVO.getSumAmtPay())
+                    .setAccDate(otherPayableVO.getAccDate()).setBiznisType(Constant.InventoryDocCode.OTHER_PAYABLE.getTableName())
+                    .setBiznisId(otherPayableVO.getPayableId()).setBiznisNo(otherPayableVO.getPayableNo())
+                    .setMakeStaff(otherPayableVO.getMakeStaff()).setCpId(otherPayableVO.getCpId());
+            // 总单保存
+            recPayMapper.insert(recPay);
+
+            for (RecPayItemVO recPayItemVO : otherPayableVO.getPaymentList()) {
+                RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
+                recPayItem.setItemId(null).setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setMakeStaff(recPay.getMakeStaff()).setAccDate(recPay.getAccDate());
+                recPayItemMapper.insert(recPayItem);
+
+                // 插入账款明细
+                AccountItem accountItem = new AccountItem();
+                accountItem.setAccItemType(Constant.accItemType.FU_KUAN.getName())
+                        .setObjectId(recPay.getObjectId()).setOrgId(recPay.getOrgId()).setStaffId(recPay.getStaffId())
+                        .setAccDate(recPay.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtPay(recPayItem.getAmtPay())
+                        .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
+                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId());
+                accountItemMapper.insert(accountItem);
+
+                // 更新付款单上的账款明细Id
+                RecPayItem recPayItemUpdate = new RecPayItem();
+                recPayItemUpdate.setAccItemId(accountItem.getItemId()).setItemId(recPayItem.getItemId());
+                recPayItemService.updateByUuid(recPayItemUpdate);
+
+                // 插入资金流水
+                MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+                moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
+                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtPay().negate()).setAccDate(recPay.getAccDate())
+                        .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
+                moneyAccountItemMapper.insert(moneyAccountItem);
+
+                // 更新资金账户
+                MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
+                MoneyAccount moneyAccountUpdate = new MoneyAccount();
+                moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtPay().negate()))
+                        .setMacId(moneyAccountForUpdate.getMacId());
+                moneyAccountService.updateByUuid(moneyAccountUpdate);
+            }
+            // 插入账款总表
+            Account accountForUpdate = accountService.getCusAccountForUpdate(recPay.getObjectId());
+            // 更新账款总表上付款的相关字段
+            Account accountUpdate = new Account();
+            accountUpdate.setPayment(accountForUpdate.getPayment().add(recPay.getSumAmtPay()))// 总付款金额
+                    .setPaymentResidue(accountForUpdate.getPaymentResidue().add(recPay.getSumAmtPay()))//  可退金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            accountService.updateByUuid(accountUpdate);
+            /*******************************************  付款的处理 end ********************************************/
+
+            /*******************************************  应付付款的处理 begin ********************************************/
+            OtherPayable otherPayableForUpdate = otherPayableMapper.selectByIdForUpdate(otherPayableVO.getPayableId());
+
+            // 应付付款的处理
+            RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
+            recPayHandleItem.setRpId(recPay.getRpId()).setAccItemId(otherPayableForUpdate.getAccItemId())
+                    .setAmtPayableHandle(recPay.getSumAmtPay()).setCpId(recPay.getCpId()).setAccDate(recPay.getAccDate());
+            recPayHandleItemMapper.insert(recPayHandleItem);
+
+            // 账款明细的核销金额和优惠金额
+            AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
+            AccountItem accountItemUpdate = new AccountItem();
+            // 核销金额,超出剩余应付金额
+            if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtPayableHandle()) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtPayableHandle()))
+                    .setAmtWaive(accountItemForUpdate.getAmtWaive())
+                    .setItemId(recPayHandleItem.getAccItemId());
+            // 剩余金额 = 应付金额-应付付款金额
+            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+            accountItemService.updateByUuid(accountItemUpdate);
+
+            // 更新总账上
+            accountForUpdate = accountMapper.selectByIdForUpdate(recPay.getObjectId());
+            accountUpdate = new Account();
+            accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().add(recPayHandleItem.getAmtPayableHandle()))// 总应付付款金额
+                    .setPayableWaive(accountForUpdate.getPayableWaive())//  总应付优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应付 = 总应付账款-总应付付款金额
+            accountUpdate.setPayableResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
+            // 可退金额 = 总付款金额-总应付付款金额+总应付优惠金额
+            accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应付为负数,则不能保存
+            if (accountUpdate.getPayableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+            /*******************************************  应付付款的处理 end ********************************************/
+        }
+        return ResponseResultUtil.success();
+    }
+
+    /**
+     * @desc : 获取信息(编辑用)
+     * @author : 付斌
+     * @date : 2024-03-02 17:27
+     */
+    public ResponseResultVO<?> getOtherPayableForUpdate(String id) {
+        Map<String, Object> dataInfo = new HashMap<>();
+        OtherPayableResponse otherPayableResponse = otherPayableMapper.selectById(id);
+        dataInfo.put("data", otherPayableResponse);
+
+        // 商品明细
+        List<OtherPayableItemResponse> otherPayableItemResponseList = otherPayableItemMapper.selectByCond(new OtherPayableItemQuery().setPayableId(id));
+        dataInfo.put("dataItem", otherPayableItemResponseList);
+
+        // 付款明细
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisId(id);
+        List<RecPayItemResponse> recPayItemResponseList = recPayItemMapper.selectByCond(new RecPayItemQuery().setRpId(recPayForUpdate.getRpId()));
+        dataInfo.put("paymentItem", recPayItemResponseList);
+
+        return ResponseResultUtil.success(dataInfo);
+    }
+
+    /**
+     * @desc : 作废
+     * @author : 付斌
+     * @date : 2024-03-08 16:38
+     */
+    public ResponseResultVO<?> invalid(String id) {
+        OtherPayable otherPayableForUpdate = otherPayableMapper.selectByIdForUpdate(id);
+        // 并发校验
+        if (!otherPayableForUpdate.getFlgValid()) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+        }
+        // 如果所在月份已结账,则不能作废 todo
+
+        /*******************************************  应付付款的处理 begin ********************************************/
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
+        if(recPayForUpdate != null && recPayForUpdate.getFlgValid()) {
+            // 查出并锁定所有应付核销明细
+            AccountItem accountItemForUpdate;
+            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.getAmtPayableHandle()))
+                        .setAmtWaive(accountItemForUpdate.getAmtWaive().subtract(recPayHandleItemForUpdate.getAmtWaive()))
+                        .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
+                accountItemService.updateByUuid(accountItemUpdate);
+
+                // 将核销明细有效标识置为false
+                RecPayHandleItem recPayHandleItemUpdate = new RecPayHandleItem();
+                recPayHandleItemUpdate.setFlgValid(false).setItemId(recPayHandleItemForUpdate.getItemId());
+                recPayHandleItemService.updateByUuid(recPayHandleItemUpdate);
+            }
+
+            // 把总帐上的钱加回来
+            Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+            Account accountUpdate = new Account();
+            accountUpdate.setPayableHandle(accountForUpdate.getPayableHandle().subtract(recPayForUpdate.getSumAmtPayableHandle()))// 总应付付款金额
+                    .setPayableWaive(accountForUpdate.getPayableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应付优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应付 = 总应付账款-总应付付款金额
+            accountUpdate.setPayableResidue(accountForUpdate.getPayable().subtract(accountUpdate.getPayableHandle()));
+            // 可退金额 = 总付款金额-总应付付款金额+总应付优惠金额
+            accountUpdate.setPaymentResidue(accountForUpdate.getPayment().subtract(accountUpdate.getPayableHandle()).add(accountUpdate.getPayableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应付为负数,则不能保存
+            if (accountUpdate.getPayableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getPaymentResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+
+            // 将之前的明细全部删除
+            List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+            // 需要重新计算的资金账户
+            List<String> macList = new ArrayList<>();
+            for (RecPayItem recPayItem : recPayItemOriginalList) {
+                // 删除收付款明细
+                recPayItemMapper.deleteById(recPayItem.getItemId());
+                // 删除账款明细
+                accountItemMapper.deleteById(recPayItem.getAccItemId());
+                // 删除账户流水
+                moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
+
+                if (!macList.contains(recPayItem.getMacId())) {
+                    macList.add(recPayItem.getMacId());
+                }
+            }
+            // 更新总账表的总付款额和可用额
+            accountService.updatePayment(recPayForUpdate.getObjectId());
+            // 更新账户余额
+            for (String macId : macList) {
+                accountService.updateMac(macId);
+            }
+            // 作废
+            RecPay recPayUpdate = new RecPay();
+            recPayUpdate.setFlgValid(false).setRpId(recPayForUpdate.getRpId());
+            paymentService.updateByUuid(recPayUpdate);
+        }
+        /*******************************************  应付付款的处理 end ********************************************/
+
+        // 应付反记账
+        accountService.reversePayable(id, "t_mac_other_payable");
+
+        // 作废
+        OtherPayable otherPayableUpdate = new OtherPayable();
+        otherPayableUpdate.setFlgValid(false).setPayableId(id);
+        super.updateByUuid(otherPayableUpdate);
+        return ResponseResultUtil.success();
+    }
 }

+ 587 - 166
src/main/java/com/dk/mdm/service/mac/OtherReceivableService.java

@@ -11,190 +11,611 @@ import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
 import com.dk.mdm.infrastructure.convert.mac.OtherReceivableConvert;
 import com.dk.mdm.infrastructure.convert.mac.OtherReceivableItemConvert;
-import com.dk.mdm.mapper.mac.OtherReceivableItemMapper;
+import com.dk.mdm.infrastructure.convert.mac.RecPayItemConvert;
+import com.dk.mdm.mapper.mac.*;
+import com.dk.mdm.mapper.mst.MoneyAccountItemMapper;
+import com.dk.mdm.mapper.mst.MoneyAccountMapper;
 import com.dk.mdm.model.pojo.mac.*;
-import com.dk.mdm.mapper.mac.OtherReceivableMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
+import com.dk.mdm.model.pojo.mst.MoneyAccount;
+import com.dk.mdm.model.pojo.mst.MoneyAccountItem;
 import com.dk.mdm.model.query.mac.OtherReceivableItemQuery;
 import com.dk.mdm.model.query.mac.OtherReceivableQuery;
+import com.dk.mdm.model.query.mac.RecPayItemQuery;
 import com.dk.mdm.model.response.mac.OtherReceivableItemResponse;
 import com.dk.mdm.model.response.mac.OtherReceivableResponse;
+import com.dk.mdm.model.response.mac.RecPayItemResponse;
 import com.dk.mdm.model.vo.mac.OtherReceivableItemVO;
 import com.dk.mdm.model.vo.mac.OtherReceivableVO;
+import com.dk.mdm.model.vo.mac.RecPayItemVO;
 import com.dk.mdm.service.common.CommonService;
+import com.dk.mdm.service.mst.MoneyAccountService;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 @Service
 @Transactional
 public class OtherReceivableService extends BaseService<OtherReceivable> {
 
-	@Override
-	public String getPrimaryKey() {
-		return "receivable_id";
-	}
-
-	@Override
-	public BaseMapper<OtherReceivable> getRepository() {
-		return otherReceivableMapper;
-	}
-
-	@Autowired
-	private OtherReceivableMapper otherReceivableMapper;
-
-	@Autowired
-	private OtherReceivableItemMapper otherReceivableItemMapper;
-
-	@Autowired
-	private CommonService commonService;
-
-	@Autowired
-	private AccountService accountService;
-
-	@Autowired
-	private OtherReceivableConvert otherReceivableConvert;
-
-	@Autowired
-	private OtherReceivableItemConvert otherReceivableItemConvert;
-
-	/**
-	 * @desc : 条件查询
-	 * @author : 付斌
-	 * @date : 2023/1/9 10:40
-	 */
-	@Pagination
-	public ResponseResultVO<PageList<OtherReceivableResponse>> selectByCond(OtherReceivableQuery otherReceivableQuery) {
-		return super.mergeListWithCount(otherReceivableQuery, otherReceivableMapper.selectByCond(otherReceivableQuery),
-				otherReceivableMapper.countByCond(otherReceivableQuery));
-	}
-
-	/**
-	 * @desc : 查询明细(货物、收款、附件)
-	 * @author : 付斌
-	 * @date : 2024-02-28 13:25
-	 */
-	@Pagination
-	public ResponseResultVO<Map<String, Object>> selectOtherReceivableInfoById(String id) {
-		Map<String, Object> result = new HashMap<>();
-		// 商品明细
-		List<OtherReceivableItemResponse> otherReceivableItem = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id));
-		result.put("otherReceivableItem", otherReceivableItem);
-
-		// 附件
-		return ResponseResultUtil.success(result);
-	}
-
-	/**
-	 * @desc : 新建方法
-	 * @author : 付斌
-	 * @date : 2023/1/9 10:49
-	 */
-	@Transactional(
-			rollbackFor = {Exception.class}
-	)
-	public ResponseResultVO<?> insert(OtherReceivableVO otherReceivableVO) {
-
-		// 获取单号
-		Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERRECEIVABLE.getName(), false);
-		otherReceivableVO.setReceivableId(codeMap.get("outId").toString()).setReceivableNo(codeMap.get("outNote").toString())
-				.setObjectType(Constant.ObjectType.CUS.getName());
-		// 转化实体
-		OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
-		// 总单保存
-		super.insert(otherReceivable);
-
-		// 明细保存
-		if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
-			for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
-				OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
-				otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId());
-				otherReceivableItemMapper.insert(otherReceivableItem);
-			}
-		}
-
-		// 应收记账
-		accountService.accReceivable(otherReceivable.getReceivableId(),"t_mac_other_receivable");
-		return ResponseResultUtil.success();
-	}
-
-	/**
-	 * @desc : 编辑方法
-	 * @author : 付斌
-	 * @date : 2023/1/9 10:49
-	 */
-	@Transactional(
-			rollbackFor = {Exception.class}
-	)
-	public ResponseResultVO<?> update(OtherReceivableVO otherReceivableVO) {
-
-		// 先更新收款单总表,否则id又更错了
-		OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
-		super.update(otherReceivable, new UpdateWrapper<OtherReceivable>().lambda().eq(OtherReceivable::getReceivableId,
-				UUID.fromString(otherReceivable.getReceivableId())));
-
-		// 应收反记账
-		accountService.reverseReceivable(otherReceivableVO.getReceivableId(),"t_mac_other_receivable");
-
-		// 将之前的明细全部删除
-		List<OtherReceivableItem> otherReceivableItemOriginalList = otherReceivableItemMapper.selectByZIdForUpdate(otherReceivableVO.getReceivableId());
-		for (OtherReceivableItem otherReceivableItem : otherReceivableItemOriginalList) {
-			otherReceivableItemMapper.deleteById(otherReceivableItem.getItemId());
-		}
-
-		// 明细保存
-		if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
-			for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
-				OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
-				otherReceivableItem.setItemId(null).setReceivableId(otherReceivableVO.getReceivableId()).setCpId(otherReceivableVO.getCpId());
-				otherReceivableItemMapper.insert(otherReceivableItem);
-			}
-		}
-
-		// 应收记账
-		accountService.accReceivable(otherReceivableVO.getReceivableId(),"t_mac_other_receivable");
-		return ResponseResultUtil.success();
-	}
-
-	/**
-	 * @desc : 获取信息(编辑用)
-	 * @author : 付斌
-	 * @date : 2024-03-02 17:27
-	 */
-	public ResponseResultVO<?> getOtherReceivableForUpdate(String id) {
-		Map<String, Object> dataInfo = new HashMap<>();
-		OtherReceivableResponse otherReceivableResponse = otherReceivableMapper.selectById(id);
-		dataInfo.put("data", otherReceivableResponse);
-
-		// 商品明细
-		List<OtherReceivableItemResponse> otherReceivableItemResponse = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id));
-		dataInfo.put("dataItem", otherReceivableItemResponse);
-		return ResponseResultUtil.success(dataInfo);
-	}
-
-	/**
-	 * @desc : 作废
-	 * @author : 付斌
-	 * @date : 2024-03-08 16:38
-	 */
-	public ResponseResultVO<?> invalid(String id) {
-		OtherReceivable otherReceivableForUpdate = otherReceivableMapper.selectByIdForUpdate(id);
-		// 并发校验
-		if (!otherReceivableForUpdate.getFlgValid()) {
-			throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
-		}
-		// 如果所在月份已结账,则不能作废 todo
-
-		// 应收反记账
-		accountService.reverseReceivable(id,"t_mac_other_receivable");
-
-		// 作废
-		OtherReceivable otherReceivableUpdate = new OtherReceivable();
-		otherReceivableUpdate.setFlgValid(false).setReceivableId(id);
-		super.updateByUuid(otherReceivableUpdate);
-		return ResponseResultUtil.success();
-	}
+    @Override
+    public String getPrimaryKey() {
+        return "receivable_id";
+    }
+
+    @Override
+    public BaseMapper<OtherReceivable> getRepository() {
+        return otherReceivableMapper;
+    }
+
+    @Autowired
+    private OtherReceivableMapper otherReceivableMapper;
+
+    @Autowired
+    private OtherReceivableItemMapper otherReceivableItemMapper;
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private AccountService accountService;
+
+    @Autowired
+    private AccountMapper accountMapper;
+
+    @Autowired
+    private AccountItemService accountItemService;
+
+    @Autowired
+    private MoneyAccountMapper moneyAccountMapper;
+
+    @Autowired
+    private AccountItemMapper accountItemMapper;
+
+    @Autowired
+    private MoneyAccountService moneyAccountService;
+
+    @Autowired
+    private MoneyAccountItemMapper moneyAccountItemMapper;
+
+    @Autowired
+    private RecPayHandleItemMapper recPayHandleItemMapper;
+
+    @Autowired
+    private RecPayMapper recPayMapper;
+
+    @Autowired
+    private RecPayHandleItemService recPayHandleItemService;
+
+    @Autowired
+    private ReceiptService receiptService;
+
+    @Autowired
+    private RecPayItemService recPayItemService;
+
+    @Autowired
+    private RecPayItemMapper recPayItemMapper;
+
+    @Autowired
+    private RecPayItemConvert recPayItemConvert;
+
+    @Autowired
+    private OtherReceivableConvert otherReceivableConvert;
+
+    @Autowired
+    private OtherReceivableItemConvert otherReceivableItemConvert;
+
+    /**
+     * @desc : 条件查询
+     * @author : 付斌
+     * @date : 2023/1/9 10:40
+     */
+    @Pagination
+    public ResponseResultVO<PageList<OtherReceivableResponse>> selectByCond(OtherReceivableQuery otherReceivableQuery) {
+        return super.mergeListWithCount(otherReceivableQuery, otherReceivableMapper.selectByCond(otherReceivableQuery),
+                otherReceivableMapper.countByCond(otherReceivableQuery));
+    }
+
+    /**
+     * @desc : 查询明细(货物、收款、附件)
+     * @author : 付斌
+     * @date : 2024-02-28 13:25
+     */
+    @Pagination
+    public ResponseResultVO<Map<String, Object>> selectOtherReceivableInfoById(String id) {
+        Map<String, Object> result = new HashMap<>();
+        // 商品明细
+        List<OtherReceivableItemResponse> otherReceivableItem = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id));
+        result.put("otherReceivableItem", otherReceivableItem);
+
+        // 附件
+        return ResponseResultUtil.success(result);
+    }
+
+    /**
+     * @desc : 新建方法
+     * @author : 付斌
+     * @date : 2023/1/9 10:49
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> insert(OtherReceivableVO otherReceivableVO) {
+        // 收款金额不能大于收入金额
+        if(otherReceivableVO.getSumAmtRec().compareTo(otherReceivableVO.getSumAmtReceivable()) == 1){
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RECEIVABLE_NO_LESS_RECEIPT.getMessage());
+        }
+
+        // 获取单号
+        Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.OTHERRECEIVABLE.getName(), false);
+        otherReceivableVO.setReceivableId(codeMap.get("outId").toString()).setReceivableNo(codeMap.get("outNote").toString())
+                .setObjectType(Constant.ObjectType.CUS.getName());
+        // 转化实体
+        OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
+        // 总单保存
+        super.insert(otherReceivable);
+
+        // 明细保存
+        if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
+            for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
+                OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
+                otherReceivableItem.setReceivableId(otherReceivable.getReceivableId()).setCpId(otherReceivable.getCpId());
+                otherReceivableItemMapper.insert(otherReceivableItem);
+            }
+        }
+
+        // 应收记账
+        accountService.accReceivable(otherReceivable.getReceivableId(), Constant.InventoryDocCode.OTHER_RECEIVABLE.getTableName());
+
+        // 如果有收款,再做应收付款
+        if (otherReceivableVO.getReceiptList() != null && otherReceivableVO.getReceiptList().size() > 0) {
+            /***********************************  收款的处理 begin ************************************/
+            RecPay recPay = new RecPay();
+            // 获取单号
+            codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+            recPay.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                    .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(otherReceivableVO.getObjectId())
+                    .setOrgId(otherReceivableVO.getOrgId()).setStaffId(otherReceivableVO.getStaffId())
+                    .setSumAmtRec(otherReceivableVO.getSumAmtRec()).setSumAmtReceivableHandle(otherReceivableVO.getSumAmtRec())
+                    .setAccDate(otherReceivableVO.getAccDate()).setBiznisType(Constant.InventoryDocCode.OTHER_RECEIVABLE.getTableName())
+                    .setBiznisId(otherReceivableVO.getReceivableId()).setBiznisNo(otherReceivableVO.getReceivableNo())
+                    .setMakeStaff(otherReceivableVO.getMakeStaff()).setCpId(otherReceivableVO.getCpId());
+            // 总单保存
+            recPayMapper.insert(recPay);
+
+            for (RecPayItemVO recPayItemVO : otherReceivableVO.getReceiptList()) {
+                RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
+                recPayItem.setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setMakeStaff(recPay.getMakeStaff()).setAccDate(recPay.getAccDate());
+                recPayItemMapper.insert(recPayItem);
+
+                // 插入账款明细
+                AccountItem accountItem = new AccountItem();
+                accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
+                        .setObjectId(recPay.getObjectId()).setOrgId(recPay.getOrgId()).setStaffId(recPay.getStaffId())
+                        .setAccDate(recPay.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
+                        .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
+                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId());
+                accountItemMapper.insert(accountItem);
+
+                // 更新收款单上的账款明细Id
+                RecPayItem recPayItemUpdate = new RecPayItem();
+                recPayItemUpdate.setAccItemId(accountItem.getItemId()).setItemId(recPayItem.getItemId());
+                recPayItemService.updateByUuid(recPayItemUpdate);
+
+                // 插入资金流水
+                MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+                moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
+                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtRec()).setAccDate(recPay.getAccDate())
+                        .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
+                moneyAccountItemMapper.insert(moneyAccountItem);
+
+                // 更新资金账户
+                MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
+                MoneyAccount moneyAccountUpdate = new MoneyAccount();
+                moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec()))
+                        .setMacId(moneyAccountForUpdate.getMacId());
+                moneyAccountService.updateByUuid(moneyAccountUpdate);
+            }
+            // 插入账款总表
+            Account accountForUpdate = accountService.getCusAccountForUpdate(recPay.getObjectId());
+            // 更新账款总表上收款的相关字段
+            Account accountUpdate = new Account();
+            accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPay.getSumAmtRec()))// 总收款金额
+                    .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPay.getSumAmtRec()))//  可退金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            accountService.updateByUuid(accountUpdate);
+            /***********************************  收款的处理 end ************************************/
+
+            /***********************************  应收收款的处理 begin ************************************/
+            OtherReceivable otherReceivableForUpdate = otherReceivableMapper.selectByIdForUpdate(otherReceivableVO.getReceivableId());
+
+            // 应收收款的处理
+            RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
+            recPayHandleItem.setRpId(recPay.getRpId()).setAccItemId(otherReceivableForUpdate.getAccItemId())
+                    .setAmtReceivableHandle(recPay.getSumAmtRec()).setCpId(recPay.getCpId()).setAccDate(recPay.getAccDate());
+            recPayHandleItemMapper.insert(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()))
+                    .setAmtWaive(accountItemForUpdate.getAmtWaive())
+                    .setItemId(recPayHandleItem.getAccItemId());
+            // 剩余金额 = 应收金额-应收收款金额
+            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+            accountItemService.updateByUuid(accountItemUpdate);
+
+            // 更新总账上
+            accountForUpdate = accountMapper.selectByIdForUpdate(recPay.getObjectId());
+            accountUpdate = new Account();
+            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
+                    .setReceivableWaive(accountForUpdate.getReceivableWaive())//  总应收优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应收 = 总应收账款-总应收收款金额
+            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应收为负数,则不能保存
+            if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+            /***********************************  应收收款的处理 end ************************************/
+        }
+        return ResponseResultUtil.success();
+    }
+
+    /**
+     * @desc : 编辑方法
+     * @author : 付斌
+     * @date : 2023/1/9 10:49
+     */
+    @Transactional(
+            rollbackFor = {Exception.class}
+    )
+    public ResponseResultVO<?> update(OtherReceivableVO otherReceivableVO) {
+        // 收款金额不能大于收入金额
+        if(otherReceivableVO.getSumAmtRec().compareTo(otherReceivableVO.getSumAmtReceivable()) == 1){
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RECEIVABLE_NO_LESS_RECEIPT.getMessage());
+        }
+
+        /***********************************  应收收款的处理 begin ************************************/
+        // 如果收款了,先把收款作废掉
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(otherReceivableVO.getReceivableId());
+        if(recPayForUpdate != null && recPayForUpdate.getFlgValid()){
+            // 查出并锁定所有应收核销明细
+            AccountItem accountItemForUpdate;
+            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()))
+                        .setAmtWaive(accountItemForUpdate.getAmtWaive().subtract(recPayHandleItemForUpdate.getAmtWaive()))
+                        .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
+                accountItemService.updateByUuid(accountItemUpdate);
+
+                // 将核销明细有效标识置为false
+                RecPayHandleItem recPayHandleItemUpdate = new RecPayHandleItem();
+                recPayHandleItemUpdate.setFlgValid(false).setItemId(recPayHandleItemForUpdate.getItemId());
+                recPayHandleItemService.updateByUuid(recPayHandleItemUpdate);
+            }
+
+            // 把总帐上的钱加回来
+            Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+            Account accountUpdate = new Account();
+            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                    .setReceivableWaive(accountForUpdate.getReceivableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应收优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应收 = 总应收账款-总应收收款金额
+            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应收为负数,则不能保存
+            if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+
+            // 将之前的明细全部删除
+            List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+            // 需要重新计算的资金账户
+            List<String> macList = new ArrayList<>();
+            for (RecPayItem recPayItem : recPayItemOriginalList) {
+                // 删除收付款明细
+                recPayItemMapper.deleteById(recPayItem.getItemId());
+                // 删除账款明细
+                accountItemMapper.deleteById(recPayItem.getAccItemId());
+                // 删除账户流水
+                moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
+
+                if (!macList.contains(recPayItem.getMacId())) {
+                    macList.add(recPayItem.getMacId());
+                }
+            }
+            // 更新总账表的总收款额和可用额
+            accountService.updateReceipt(recPayForUpdate.getObjectId());
+            // 更新账户余额
+            for (String macId : macList) {
+                accountService.updateMac(macId);
+            }
+            // 作废
+            RecPay recPayUpdate = new RecPay();
+            recPayUpdate.setFlgValid(false).setRpId(recPayForUpdate.getRpId());
+            receiptService.updateByUuid(recPayUpdate);
+        }
+        /***********************************  应收收款的处理 end ************************************/
+
+        // 先更新收款单总表,否则id又更错了
+        OtherReceivable otherReceivable = otherReceivableConvert.convertToPo(otherReceivableVO);
+        super.update(otherReceivable, new UpdateWrapper<OtherReceivable>().lambda().eq(OtherReceivable::getReceivableId,
+                UUID.fromString(otherReceivable.getReceivableId())));
+
+        // 应收反记账
+        accountService.reverseReceivable(otherReceivableVO.getReceivableId(), Constant.InventoryDocCode.OTHER_RECEIVABLE.getTableName());
+
+        // 将之前的明细全部删除
+        List<OtherReceivableItem> otherReceivableItemOriginalList = otherReceivableItemMapper.selectByZIdForUpdate(otherReceivableVO.getReceivableId());
+        for (OtherReceivableItem otherReceivableItem : otherReceivableItemOriginalList) {
+            otherReceivableItemMapper.deleteById(otherReceivableItem.getItemId());
+        }
+
+        // 明细保存
+        if (otherReceivableVO.getItemList() != null && otherReceivableVO.getItemList().size() > 0) {
+            for (OtherReceivableItemVO otherReceivableItemVO : otherReceivableVO.getItemList()) {
+                OtherReceivableItem otherReceivableItem = otherReceivableItemConvert.convertToPo(otherReceivableItemVO);
+                otherReceivableItem.setItemId(null).setReceivableId(otherReceivableVO.getReceivableId()).setCpId(otherReceivableVO.getCpId());
+                otherReceivableItemMapper.insert(otherReceivableItem);
+            }
+        }
+
+        // 应收记账
+        accountService.accReceivable(otherReceivableVO.getReceivableId(), Constant.InventoryDocCode.OTHER_RECEIVABLE.getTableName());
+
+        // 如果有收款,再做应收收款
+        if (otherReceivableVO.getReceiptList() != null && otherReceivableVO.getReceiptList().size() > 0) {
+            /***********************************  收款的处理 begin ************************************/
+            RecPay recPay = new RecPay();
+            // 获取单号
+            Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+            recPay.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                    .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(otherReceivableVO.getObjectId())
+                    .setOrgId(otherReceivableVO.getOrgId()).setStaffId(otherReceivableVO.getStaffId())
+                    .setSumAmtRec(otherReceivableVO.getSumAmtRec()).setSumAmtReceivableHandle(otherReceivableVO.getSumAmtRec())
+                    .setAccDate(otherReceivableVO.getAccDate()).setBiznisType(Constant.InventoryDocCode.OTHER_RECEIVABLE.getTableName())
+                    .setBiznisId(otherReceivableVO.getReceivableId()).setBiznisNo(otherReceivableVO.getReceivableNo())
+                    .setMakeStaff(otherReceivableVO.getMakeStaff()).setCpId(otherReceivableVO.getCpId());
+
+            // 总单保存
+            recPayMapper.insert(recPay);
+
+            for (RecPayItemVO recPayItemVO : otherReceivableVO.getReceiptList()) {
+                RecPayItem recPayItem = recPayItemConvert.convertToPo(recPayItemVO);
+                recPayItem.setItemId(null).setRpId(recPay.getRpId()).setCpId(recPay.getCpId()).setMakeStaff(recPay.getMakeStaff()).setAccDate(recPay.getAccDate());
+                recPayItemMapper.insert(recPayItem);
+
+                // 插入账款明细
+                AccountItem accountItem = new AccountItem();
+                accountItem.setAccItemType(Constant.accItemType.SHOU_KUAN.getName())
+                        .setObjectId(recPay.getObjectId()).setOrgId(recPay.getOrgId()).setStaffId(recPay.getStaffId())
+                        .setAccDate(recPay.getAccDate()).setRecStatus(Constant.recStatuse.QUE_DING.getName()).setAmtRec(recPayItem.getAmtRec())
+                        .setBiznisType("t_mac_rec_pay_item").setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
+                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId());
+                accountItemMapper.insert(accountItem);
+
+                // 更新收款单上的账款明细Id
+                RecPayItem recPayItemUpdate = new RecPayItem();
+                recPayItemUpdate.setAccItemId(accountItem.getItemId()).setItemId(recPayItem.getItemId());
+                recPayItemService.updateByUuid(recPayItemUpdate);
+
+                // 插入资金流水
+                MoneyAccountItem moneyAccountItem = new MoneyAccountItem();
+                moneyAccountItem.setMacId(recPayItem.getMacId()).setFlowType(Constant.FlowType.SHOU_FU_KUAN.getName())
+                        .setInvoiceId(recPayItem.getItemId()).setAmtInflow(recPayItem.getAmtRec()).setAccDate(recPay.getAccDate())
+                        .setMakeStaff(recPayItem.getMakeStaff()).setCpId(recPayItem.getCpId());
+                moneyAccountItemMapper.insert(moneyAccountItem);
+
+                // 更新资金账户
+                MoneyAccount moneyAccountForUpdate = moneyAccountMapper.selectByIdForUpdate(recPayItem.getMacId());
+                MoneyAccount moneyAccountUpdate = new MoneyAccount();
+                moneyAccountUpdate.setBalance(moneyAccountForUpdate.getBalance().add(recPayItem.getAmtRec()))
+                        .setMacId(moneyAccountForUpdate.getMacId());
+                moneyAccountService.updateByUuid(moneyAccountUpdate);
+            }
+            // 插入账款总表
+            Account accountForUpdate = accountService.getCusAccountForUpdate(recPay.getObjectId());
+            // 更新账款总表上收款的相关字段
+            Account accountUpdate = new Account();
+            accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPay.getSumAmtRec()))// 总收款金额
+                    .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPay.getSumAmtRec()))//  可退金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            accountService.updateByUuid(accountUpdate);
+            /***********************************  收款的处理 end ************************************/
+
+            /***********************************  应收收款的处理 begin ************************************/
+            OtherReceivable otherReceivableForUpdate = otherReceivableMapper.selectByIdForUpdate(otherReceivableVO.getReceivableId());
+            // 应收收款的处理
+            RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
+            recPayHandleItem.setRpId(recPay.getRpId()).setAccItemId(otherReceivableForUpdate.getAccItemId())
+                    .setAmtReceivableHandle(recPay.getSumAmtRec()).setCpId(recPay.getCpId()).setAccDate(recPay.getAccDate());
+            recPayHandleItemMapper.insert(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()))
+                    .setAmtWaive(accountItemForUpdate.getAmtWaive())
+                    .setItemId(recPayHandleItem.getAccItemId());
+            // 剩余金额 = 应收金额-应收收款金额
+            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+            accountItemService.updateByUuid(accountItemUpdate);
+
+            // 更新总账上
+            accountForUpdate = accountMapper.selectByIdForUpdate(recPay.getObjectId());
+            accountUpdate = new Account();
+            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
+                    .setReceivableWaive(accountForUpdate.getReceivableWaive())//  总应收优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应收 = 总应收账款-总应收收款金额
+            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应收为负数,则不能保存
+            if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+            /***********************************  应收收款的处理 end ************************************/
+        }
+        return ResponseResultUtil.success();
+    }
+
+    /**
+     * @desc : 获取信息(编辑用)
+     * @author : 付斌
+     * @date : 2024-03-02 17:27
+     */
+    public ResponseResultVO<?> getOtherReceivableForUpdate(String id) {
+        Map<String, Object> dataInfo = new HashMap<>();
+        OtherReceivableResponse otherReceivableResponse = otherReceivableMapper.selectById(id);
+        dataInfo.put("data", otherReceivableResponse);
+
+        // 收入明细
+        List<OtherReceivableItemResponse> otherReceivableItemResponseList = otherReceivableItemMapper.selectByCond(new OtherReceivableItemQuery().setReceivableId(id));
+        dataInfo.put("dataItem", otherReceivableItemResponseList);
+
+        // 收款明细
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisId(id);
+        List<RecPayItemResponse> recPayItemResponseList = recPayItemMapper.selectByCond(new RecPayItemQuery().setRpId(recPayForUpdate.getRpId()));
+        dataInfo.put("receiptItem", recPayItemResponseList);
+
+        return ResponseResultUtil.success(dataInfo);
+    }
+
+    /**
+     * @desc : 作废
+     * @author : 付斌
+     * @date : 2024-03-08 16:38
+     */
+    public ResponseResultVO<?> invalid(String id) {
+        OtherReceivable otherReceivableForUpdate = otherReceivableMapper.selectByIdForUpdate(id);
+        // 并发校验
+        if (!otherReceivableForUpdate.getFlgValid()) {
+            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
+        }
+        // 如果所在月份已结账,则不能作废 todo
+
+        /***********************************  应收收款的处理 begin ************************************/
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
+        if(recPayForUpdate != null && recPayForUpdate.getFlgValid()){
+            // 查出并锁定所有应收核销明细
+            AccountItem accountItemForUpdate;
+            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()))
+                        .setAmtWaive(accountItemForUpdate.getAmtWaive().subtract(recPayHandleItemForUpdate.getAmtWaive()))
+                        .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()).subtract(accountItemUpdate.getAmtWaive()));
+                accountItemService.updateByUuid(accountItemUpdate);
+
+                // 将核销明细有效标识置为false
+                RecPayHandleItem recPayHandleItemUpdate = new RecPayHandleItem();
+                recPayHandleItemUpdate.setFlgValid(false).setItemId(recPayHandleItemForUpdate.getItemId());
+                recPayHandleItemService.updateByUuid(recPayHandleItemUpdate);
+            }
+
+            // 把总帐上的钱加回来
+            Account accountForUpdate = accountMapper.selectByIdForUpdate(recPayForUpdate.getObjectId());
+            Account accountUpdate = new Account();
+            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                    .setReceivableWaive(accountForUpdate.getReceivableWaive().subtract(recPayForUpdate.getSumWaiveAmt()))//  总应收优惠金额
+                    .setObjectId(accountForUpdate.getObjectId());
+            // 剩余应收 = 总应收账款-总应收收款金额
+            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()).add(accountUpdate.getReceivableWaive()));
+
+            // 更新前的最后校验
+            // 剩余应收为负数,则不能保存
+            if (accountUpdate.getReceivableResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+            }
+            // 可用金额为负数,则不能保存
+            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.MAC_BALANCE_NO_LESS.getMessage());
+            }
+            accountService.updateByUuid(accountUpdate);
+
+            // 将之前的明细全部删除
+            List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+            // 需要重新计算的资金账户
+            List<String> macList = new ArrayList<>();
+            for (RecPayItem recPayItem : recPayItemOriginalList) {
+                // 删除收付款明细
+                recPayItemMapper.deleteById(recPayItem.getItemId());
+                // 删除账款明细
+                accountItemMapper.deleteById(recPayItem.getAccItemId());
+                // 删除账户流水
+                moneyAccountItemMapper.deleteByInvoiceId(recPayItem.getItemId());
+
+                if (!macList.contains(recPayItem.getMacId())) {
+                    macList.add(recPayItem.getMacId());
+                }
+            }
+            // 更新总账表的总收款额和可用额
+            accountService.updateReceipt(recPayForUpdate.getObjectId());
+            // 更新账户余额
+            for (String macId : macList) {
+                accountService.updateMac(macId);
+            }
+            // 作废
+            RecPay recPayUpdate = new RecPay();
+            recPayUpdate.setFlgValid(false).setRpId(recPayForUpdate.getRpId());
+            receiptService.updateByUuid(recPayUpdate);
+        }
+        /***********************************  应收收款的处理 end ************************************/
+
+        // 应收反记账
+        accountService.reverseReceivable(id, "t_mac_other_receivable");
+
+        // 作废
+        OtherReceivable otherReceivableUpdate = new OtherReceivable();
+        otherReceivableUpdate.setFlgValid(false).setReceivableId(id);
+        super.updateByUuid(otherReceivableUpdate);
+        return ResponseResultUtil.success();
+    }
 }

+ 11 - 3
src/main/java/com/dk/mdm/service/mst/CustomerService.java

@@ -108,7 +108,7 @@ public class CustomerService extends BaseService<Customer> {
 
 
         //设置公司id
-        customer.setCpId(authUtils.getStaff().getCpId());
+//        customer.setCpId(authUtils.getStaff().getCpId());
         //报备人
         customer.setReportStaff(authUtils.getStaff().getStaffId());
         //报备日期
@@ -136,7 +136,11 @@ public class CustomerService extends BaseService<Customer> {
         return ResponseResultUtil.success();
     }
 
-
+    /**
+     * @desc : 跟据id查询
+     * @author : 于继渤
+     * @date : 2023/1/5 9:39
+     */
     public ResponseResultVO<CustomerResponse> selectByIdRespone(@PathVariable String id) {
         CustomerResponse customerResponse = customerMapper.selectByIdRespone(id);
         if (customerResponse == null) {
@@ -144,7 +148,11 @@ public class CustomerService extends BaseService<Customer> {
         }
         return ResponseResultUtil.success(customerResponse);
     }
-
+    /**
+     * @desc : 不分页查询
+     * @author : 于继渤
+     * @date : 2023/1/5 9:39
+     */
     public ResponseResultVO<List<CustomerResponse>> selectByCondNoPage(CustomerQuery customerQuery) {
         List<CustomerResponse> customerResponses = customerMapper.selectByCond(customerQuery);
         return ResponseResultUtil.success(customerResponses);

+ 0 - 24
src/main/java/com/dk/mdm/service/mst/OrgMacService.java

@@ -1,24 +0,0 @@
-package com.dk.mdm.service.mst;
-
-import com.dk.mdm.model.pojo.mst.OrgMac;
-import com.dk.mdm.mapper.mst.OrgMacMapper;
-import com.dk.common.service.BaseService;
-import com.dk.common.mapper.BaseMapper;
-import org.springframework.stereotype.Service;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Service
-@Transactional
-public class OrgMacService extends BaseService<OrgMac> {
-
-
-	@Override
-	public BaseMapper<OrgMac> getRepository() {
-		return orgMacMapper;
-	}
-
-	@Autowired
-	private OrgMacMapper orgMacMapper;
-
-}

+ 0 - 23
src/main/java/com/dk/mdm/service/mst/OrgWhService.java

@@ -1,23 +0,0 @@
-package com.dk.mdm.service.mst;
-
-import com.dk.mdm.model.pojo.mst.OrgWh;
-import com.dk.mdm.mapper.mst.OrgWhMapper;
-import com.dk.common.service.BaseService;
-import com.dk.common.mapper.BaseMapper;
-import org.springframework.stereotype.Service;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Service
-@Transactional
-public class OrgWhService extends BaseService<OrgWh> {
-
-	@Override
-	public BaseMapper<OrgWh> getRepository() {
-		return orgWhMapper;
-	}
-
-	@Autowired
-	private OrgWhMapper orgWhMapper;
-
-}

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

@@ -404,7 +404,7 @@ public class OrderService extends BaseService<Order> {
         // 需要重新计算的资金账户
         List<String> macList = new ArrayList<>();
         // 收款明细
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdIdForUpdate(orderVO.getOrderId());
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderVO.getOrderId());
         if(recPayForUpdate != null){
             // 将之前的明细全部删除
             List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
@@ -526,7 +526,7 @@ public class OrderService extends BaseService<Order> {
         // 需要重新计算的资金账户
         List<String> macList = new ArrayList<>();
         // 收款明细
-        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdIdForUpdate(id);
+        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(id);
         if(recPayForUpdate != null){
             // 将之前的明细全部删除
             List<RecPayItem> recPayItemOriginalList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());