Forráskód Böngészése

修改标准版本没有定金

fubin 1 éve
szülő
commit
e8cc6a79e2

+ 7 - 8
src/main/java/com/dk/mdm/generator/Generator.java

@@ -79,11 +79,11 @@ public class Generator {
         PackageConfig pc = new PackageConfig();
 //        pc.setModuleName("task");                  //模块包名
         pc.setParent("com.dk.mdm");        //父包路径
-        pc.setEntity("model.pojo.ivt");                     //实体层路径
-        pc.setMapper("mapper.ivt");                 //mapper层路径
-        pc.setXml("mapper.ivt");                       //xml层路径
-        pc.setServiceImpl("service.ivt");                   //业务层路径
-        pc.setController("controller.ivt");             //控制层路径
+        pc.setEntity("model.pojo.mac");                     //实体层路径
+        pc.setMapper("mapper.mac");                 //mapper层路径
+        pc.setXml("mapper.mac");                       //xml层路径
+        pc.setServiceImpl("service.mac");                   //业务层路径
+        pc.setController("controller.mac");             //控制层路径
         //app相关路径
 //        pc.setEntity("model.app.pojo.pset");                     //实体层路径
 //        pc.setMapper("mapper.app.pset");                 //mapper层路径
@@ -94,9 +94,8 @@ public class Generator {
 
         //4、策略配置
         StrategyConfig strategy = new StrategyConfig();
-        strategy.setTablePrefix("t_psi");                                             //表名前缀
-        strategy.setInclude("t_psi_transfer");                                    //设置要映射的表名,只需改这里即可,可以是一个数组,一次性生成多张表。
-        strategy.setInclude("t_psi_transfer_item");
+        strategy.setTablePrefix("t_mac");                                             //表名前缀
+        strategy.setInclude("t_mac_transfer_item");                                    //设置要映射的表名,只需改这里即可,可以是一个数组,一次性生成多张表。
         strategy.setNaming(NamingStrategy.underline_to_camel);                      //转驼峰
         strategy.setColumnNaming(NamingStrategy.underline_to_camel);                //字段下划线转驼峰
         strategy.setEntityLombokModel(true);                                        //是否使用lombok开启注解

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

@@ -566,4 +566,11 @@ public interface CommonMapper extends BaseMapper<Map<String, Object>> {
      * @date   : 2024/5/30 10:42
      */
     Map<String,Object> selectUserCount(Map param);
+
+    /**
+     * @desc   : 获取公司
+     * @author : 付斌
+     * @date   : 2024-06-19 9:59
+     */
+    List<Map<String, Object>> getCompany(Map param);
 }

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

@@ -1969,4 +1969,20 @@
             ),
             CURRENT_DATE as "currentDate"
     </select>
+
+    <select id="getCompany" resultType="java.util.Map">
+        select t.cp_id         as "cpId",
+               t.cp_code       as "cpCode",
+               t.cp_name       as "cpName",
+               t.svc_code      as "svcCode",
+               t.opening_date  as "openingDate",
+               t.grade_code    as "gradeCode",
+               t.end_date      as "endDate",
+               t.max_staff_num as "maxStaffNum",
+               t.flg_valid     as "flgValid",
+               t.remarks,
+               t.owner
+        from dkic_a.t_a_company as t
+        where t.cp_id = #{cpId}
+    </select>
 </mapper>

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

@@ -1083,4 +1083,14 @@ public class CommonService extends BaseService<Map<String, Object>> {
         Map<String, Object> map = commonMapper.selectUserCount(param);
         return ResponseResultUtil.success(map);
     }
+
+    /**
+     * @desc   : 获取公司
+     * @author : 付斌
+     * @date   : 2024-06-19 10:00
+     */
+    public ResponseResultVO<List<Map<String, Object>>> getCompany(Map<String, Object> param) {
+        List<Map<String, Object>> list = commonMapper.getCompany(param);
+        return ResponseResultUtil.success(list);
+    }
 }

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

@@ -8,6 +8,7 @@ import com.dk.common.infrastructure.enums.ErrorCodeEnum;
 import com.dk.common.response.ResponseCodeEnum;
 import com.dk.common.response.ResponseResultUtil;
 import com.dk.common.response.ResponseResultVO;
+import com.dk.mdm.mapper.common.CommonMapper;
 import com.dk.mdm.mapper.ivt.InboundMapper;
 import com.dk.mdm.mapper.ivt.OutboundMapper;
 import com.dk.mdm.mapper.mac.*;
@@ -32,10 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 
 @Service
 @Transactional
@@ -99,6 +97,9 @@ public class AccountService extends BaseService<Account> {
     @Autowired
     private CommonService commonService;
 
+    @Autowired
+    private CommonMapper commonMapper;
+
     /**
      * @desc : 查看来源单据,总单加明细
      * @author : 姜永辉
@@ -356,120 +357,132 @@ public class AccountService extends BaseService<Account> {
                     .setObjectId(objectId);
             super.updateByUuid(accountUpdate);
 
-            // 如果当前出库单对应的订单全部出库了,并且订单有收款(锁定金额),则自动做应收核销
-            // 如果是销售出库
-            if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
-                Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
-                // 如果当前订单已经全部出库
-                if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
-                    RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId(),false);
-                    if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
-                        // 先把收款单解锁
-                        RecPay recPayUpdate = new RecPay();
-                        recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
-                        receiptService.updateByUuid(recPayUpdate);
-
-                        // 账款明细解锁
-                        List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
-                        for (RecPayItem recPayItem : recPayItemList) {
-                            AccountItem accountItemUpdate = new AccountItem();
-                            accountItemUpdate.setFlgLock(false).setItemId(recPayItem.getAccItemId());
-                            accountItemService.updateByUuid(accountItemUpdate);
-                        }
+            // 商户产品版本
+            String gradeCode = "PRO";
+            Map<String, Object> paramCompany = new HashMap<>();
+            paramCompany.put("cpId", outbound.getCpId());
+            List<Map<String, Object>> listCompany = commonMapper.getCompany(paramCompany);
+            if (listCompany.size() > 0) {
+                gradeCode = listCompany.get(0).get("gradeCode").toString();
+            }
 
-                        // 钱进到现金池中
-                        accountUpdate = new Account();
-                        accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayForUpdate.getSumAmtRec()))
-                                .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPayForUpdate.getSumAmtRec()))
-                                .setReceiptLock(accountForUpdate.getReceiptLock().subtract(recPayForUpdate.getSumAmtRec()))
-                                .setObjectId(objectId);
-                        super.updateByUuid(accountUpdate);
-
-                        // 查出当前订单需要核销的应收单据
-                        List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
-                                new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
-
-                        if (accountItemResponseList.size() > 0) {
-                            // 生成核销总单
-                            RecPay recPayHandle = new RecPay();
-                            // 获取单号
-                            Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
-                            recPayHandle.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
-                                    .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(objectId)
-                                    .setOrgId(recPayForUpdate.getOrgId()).setStaffId(recPayForUpdate.getStaffId()).setAccDate(LocalDate.now())
-                                    .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(recPayForUpdate.getBiznisId()).setBiznisNo(recPayForUpdate.getBiznisNo())
-                                    .setMakeStaff(recPayForUpdate.getMakeStaff()).setCpId(recPayForUpdate.getCpId()).setFlgOrderHandle(true);
-                            recPayMapper.insert(recPayHandle);
-
-                            // 记录核销了哪些应收账
-                            List<RecPayHandleItem> receivableList = new ArrayList<>();
-
-                            // 锁定金额
-                            BigDecimal lockAmt = recPayForUpdate.getSumAmtRec();
-
-                            for (AccountItemResponse accountItemResponse : accountItemResponseList) {
-                                RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
-                                recPayHandleItem.setRpId(recPayHandle.getRpId()).setCpId(recPayHandle.getCpId()).setAccDate(recPayHandle.getAccDate())
-                                        .setAccItemId(accountItemResponse.getAccItemId());
-                                // 如果定金比应收金额大
-                                if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
-                                    recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
-                                    lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
-                                } else {
-                                    recPayHandleItem.setAmtReceivableHandle(lockAmt);
-                                    lockAmt = BigDecimal.ZERO;
-                                }
-                                recPayHandleItemMapper.insert(recPayHandleItem);
-                                receivableList.add(recPayHandleItem);
+            // 专业版自动核销
+            if ("PRO".equals(gradeCode)){
+                // 如果当前出库单对应的订单全部出库了,并且订单有收款(锁定金额),则自动做应收核销
+                // 如果是销售出库
+                if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
+                    Order orderForUpdate = orderMapper.selectByIdForUpdate(outbound.getFromId());
+                    // 如果当前订单已经全部出库
+                    if (orderForUpdate != null && orderForUpdate.getOutQty().compareTo(orderForUpdate.getSumQuantity()) == 0) {
+                        RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(orderForUpdate.getOrderId(),false);
+                        if (recPayForUpdate != null && recPayForUpdate.getFlgLock()) {
+                            // 先把收款单解锁
+                            RecPay recPayUpdate = new RecPay();
+                            recPayUpdate.setFlgLock(false).setRpId(recPayForUpdate.getRpId());
+                            receiptService.updateByUuid(recPayUpdate);
 
-                                // 账款明细的核销金额和优惠金额
-                                AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
+                            // 账款明细解锁
+                            List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                            for (RecPayItem recPayItem : recPayItemList) {
                                 AccountItem accountItemUpdate = new AccountItem();
-                                // 核销金额,超出剩余应收金额
-                                if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtReceivableHandle()) == -1) {
-                                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
-                                }
-                                accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtReceivableHandle()))
-                                        .setItemId(recPayHandleItem.getAccItemId());
-                                // 剩余金额 = 应收金额-应收收款金额
-                                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                                accountItemUpdate.setFlgLock(false).setItemId(recPayItem.getAccItemId());
                                 accountItemService.updateByUuid(accountItemUpdate);
-
-                                // 如果定金都用完了,跳出循环
-                                if (lockAmt.compareTo(BigDecimal.ZERO) == 0) {
-                                    break;
-                                }
                             }
 
-                            // 计算明细的核销金额,优惠金额合计
-                            RecPayHandleItem recPayHandleItem = receivableList.stream().reduce((x, y) -> {
-                                RecPayHandleItem item = new RecPayHandleItem();
-                                item.setAmtReceivableHandle(x.getAmtReceivableHandle().add(y.getAmtReceivableHandle()));
-                                return item;
-                            }).get();
-
-                            // 更新收款单
-                            recPayUpdate = new RecPay();
-                            recPayUpdate.setSumAmtReceivableHandle(recPayHandleItem.getAmtReceivableHandle())
-                                    .setSumShouldHandle(recPayHandleItem.getAmtReceivableHandle())
-                                    .setRpId(recPayHandle.getRpId());
-                            receiptService.updateByUuid(recPayUpdate);
-
-                            // 更新总账上
-                            accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
+                            // 钱进到现金池中
                             accountUpdate = new Account();
-                            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
-                                    .setObjectId(accountForUpdate.getObjectId());
-                            // 剩余应收 = 总应收账款-总应收收款金额
-                            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
-                            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
-                            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+                            accountUpdate.setReceipt(accountForUpdate.getReceipt().add(recPayForUpdate.getSumAmtRec()))
+                                    .setReceiptResidue(accountForUpdate.getReceiptResidue().add(recPayForUpdate.getSumAmtRec()))
+                                    .setReceiptLock(accountForUpdate.getReceiptLock().subtract(recPayForUpdate.getSumAmtRec()))
+                                    .setObjectId(objectId);
+                            super.updateByUuid(accountUpdate);
 
-                            // 可用金额为负数,则不能保存
-                            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
-                                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+                            // 查出当前订单需要核销的应收单据
+                            List<AccountItemResponse> accountItemResponseList = accountItemMapper.getReceivableAccountItemForUpdate(
+                                    new AccountItemQuery().setObjectId(objectId).setOrderId(orderForUpdate.getOrderId()));
+
+                            if (accountItemResponseList.size() > 0) {
+                                // 生成核销总单
+                                RecPay recPayHandle = new RecPay();
+                                // 获取单号
+                                Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.RECPAY.getName(), false);
+                                recPayHandle.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                                        .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(objectId)
+                                        .setOrgId(recPayForUpdate.getOrgId()).setStaffId(recPayForUpdate.getStaffId()).setAccDate(LocalDate.now())
+                                        .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(recPayForUpdate.getBiznisId()).setBiznisNo(recPayForUpdate.getBiznisNo())
+                                        .setMakeStaff(recPayForUpdate.getMakeStaff()).setCpId(recPayForUpdate.getCpId()).setFlgOrderHandle(true);
+                                recPayMapper.insert(recPayHandle);
+
+                                // 记录核销了哪些应收账
+                                List<RecPayHandleItem> receivableList = new ArrayList<>();
+
+                                // 锁定金额
+                                BigDecimal lockAmt = recPayForUpdate.getSumAmtRec();
+
+                                for (AccountItemResponse accountItemResponse : accountItemResponseList) {
+                                    RecPayHandleItem recPayHandleItem = new RecPayHandleItem();
+                                    recPayHandleItem.setRpId(recPayHandle.getRpId()).setCpId(recPayHandle.getCpId()).setAccDate(recPayHandle.getAccDate())
+                                            .setAccItemId(accountItemResponse.getAccItemId());
+                                    // 如果定金比应收金额大
+                                    if (lockAmt.compareTo(accountItemResponse.getAmtResidue()) == 1) {
+                                        recPayHandleItem.setAmtReceivableHandle(accountItemResponse.getAmtResidue());
+                                        lockAmt = lockAmt.subtract(accountItemResponse.getAmtResidue());
+                                    } else {
+                                        recPayHandleItem.setAmtReceivableHandle(lockAmt);
+                                        lockAmt = BigDecimal.ZERO;
+                                    }
+                                    recPayHandleItemMapper.insert(recPayHandleItem);
+                                    receivableList.add(recPayHandleItem);
+
+                                    // 账款明细的核销金额和优惠金额
+                                    AccountItem accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItem.getAccItemId());
+                                    AccountItem accountItemUpdate = new AccountItem();
+                                    // 核销金额,超出剩余应收金额
+                                    if (accountItemForUpdate.getAmtResidue().compareTo(recPayHandleItem.getAmtReceivableHandle()) == -1) {
+                                        throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.AMT_HANDLE_NO_LESS_AMT_SHOULD.getMessage());
+                                    }
+                                    accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().add(recPayHandleItem.getAmtReceivableHandle()))
+                                            .setItemId(recPayHandleItem.getAccItemId());
+                                    // 剩余金额 = 应收金额-应收收款金额
+                                    accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                                    accountItemService.updateByUuid(accountItemUpdate);
+
+                                    // 如果定金都用完了,跳出循环
+                                    if (lockAmt.compareTo(BigDecimal.ZERO) == 0) {
+                                        break;
+                                    }
+                                }
+
+                                // 计算明细的核销金额,优惠金额合计
+                                RecPayHandleItem recPayHandleItem = receivableList.stream().reduce((x, y) -> {
+                                    RecPayHandleItem item = new RecPayHandleItem();
+                                    item.setAmtReceivableHandle(x.getAmtReceivableHandle().add(y.getAmtReceivableHandle()));
+                                    return item;
+                                }).get();
+
+                                // 更新收款单
+                                recPayUpdate = new RecPay();
+                                recPayUpdate.setSumAmtReceivableHandle(recPayHandleItem.getAmtReceivableHandle())
+                                        .setSumShouldHandle(recPayHandleItem.getAmtReceivableHandle())
+                                        .setRpId(recPayHandle.getRpId());
+                                receiptService.updateByUuid(recPayUpdate);
+
+                                // 更新总账上
+                                accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
+                                accountUpdate = new Account();
+                                accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().add(recPayHandleItem.getAmtReceivableHandle()))// 总应收收款金额
+                                        .setObjectId(accountForUpdate.getObjectId());
+                                // 剩余应收 = 总应收账款-总应收收款金额
+                                accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+                                // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+                                accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+
+                                // 可用金额为负数,则不能保存
+                                if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                                    throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+                                }
+                                super.updateByUuid(accountUpdate);
                             }
-                            super.updateByUuid(accountUpdate);
                         }
                     }
                 }
@@ -532,72 +545,84 @@ public class AccountService extends BaseService<Account> {
             if (outbound.getReceivableId() == null) {
                 throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.CURRENT_INVOICE_ISREVERSE.getMessage());
             }
-
             Account accountForUpdate;
             Account accountUpdate;
-            // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
-            // 如果是销售出库
-            if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
-                RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),false);        // 款
-                RecPay recPayHandleForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),true);   // 账
-                if (recPayForUpdate != null && recPayHandleForUpdate != null) {
-                    // 查出并锁定所有应收核销明细
-                    List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayHandleForUpdate.getRpId());
-                    if (recPayHandleItemForUpdateList.size() > 0) {
-                        for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
-                            // 更新账款明细应收收款
-                            accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
-                            AccountItem accountItemUpdate = new AccountItem();
-                            accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
-                                    .setItemId(recPayHandleItemForUpdate.getAccItemId());
-                            accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
-                            accountItemService.updateByUuid(accountItemUpdate);
-
-                            // 删掉核销明细
-                            recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
-                        }
 
-                        // 把总帐上的钱加回来
-                        accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
-                        accountUpdate = new Account();
-                        accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayHandleForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
-                                .setObjectId(objectId);
-                        // 剩余应收 = 总应收账款-总应收收款金额
-                        accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
-                        // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
-                        accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
-
-                        // 更新前的最后校验
-                        // 可用金额为负数,则不能保存
-                        if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
-                            throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
-                        }
-                        super.updateByUuid(accountUpdate);
-
-                        // 删掉收款核销单
-                        recPayMapper.deleteById(recPayHandleForUpdate.getRpId());
-
-                        // 先把收款单锁定
-                        RecPay recPayUpdate = new RecPay();
-                        recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
-                        receiptService.updateByUuid(recPayUpdate);
-
-                        // 账款明细解锁
-                        List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
-                        for (RecPayItem recPayItem : recPayItemList) {
-                            AccountItem accountItemUpdate = new AccountItem();
-                            accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
-                            accountItemService.updateByUuid(accountItemUpdate);
-                        }
+            // 商户产品版本
+            String gradeCode = "PRO";
+            Map<String, Object> paramCompany = new HashMap<>();
+            paramCompany.put("cpId", outbound.getCpId());
+            List<Map<String, Object>> listCompany = commonMapper.getCompany(paramCompany);
+            if (listCompany.size() > 0) {
+                gradeCode = listCompany.get(0).get("gradeCode").toString();
+            }
 
-                        // 钱进到锁定金额中
-                        accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
-                        accountUpdate = new Account();
-                        accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
-                                .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
-                                .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
-                                .setObjectId(objectId);
-                        super.updateByUuid(accountUpdate);
+            // 专业版自动核销
+            if ("PRO".equals(gradeCode)){
+                // 如果当前出库单对应的订单做了应收收款,则自动作废应收核销,并且锁定金额订单收款(锁定金额)
+                // 如果是销售出库
+                if (outbound.getOutType().equals(Constant.OutType.SALE.getName())) {
+                    RecPay recPayForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),false);        // 款
+                    RecPay recPayHandleForUpdate = recPayMapper.selectByBiznisIdForUpdate(outbound.getFromId(),true);   // 账
+                    if (recPayForUpdate != null && recPayHandleForUpdate != null) {
+                        // 查出并锁定所有应收核销明细
+                        List<RecPayHandleItem> recPayHandleItemForUpdateList = recPayHandleItemMapper.selectByZIdForUpdate(recPayHandleForUpdate.getRpId());
+                        if (recPayHandleItemForUpdateList.size() > 0) {
+                            for (RecPayHandleItem recPayHandleItemForUpdate : recPayHandleItemForUpdateList) {
+                                // 更新账款明细应收收款
+                                accountItemForUpdate = accountItemMapper.selectByIdForUpdate(recPayHandleItemForUpdate.getAccItemId());
+                                AccountItem accountItemUpdate = new AccountItem();
+                                accountItemUpdate.setAmtHandle(accountItemForUpdate.getAmtHandle().subtract(recPayHandleItemForUpdate.getAmtReceivableHandle()))
+                                        .setItemId(recPayHandleItemForUpdate.getAccItemId());
+                                accountItemUpdate.setAmtResidue(accountItemForUpdate.getAmtShould().subtract(accountItemUpdate.getAmtHandle()));
+                                accountItemService.updateByUuid(accountItemUpdate);
+
+                                // 删掉核销明细
+                                recPayHandleItemMapper.deleteById(recPayHandleItemForUpdate.getItemId());
+                            }
+
+                            // 把总帐上的钱加回来
+                            accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
+                            accountUpdate = new Account();
+                            accountUpdate.setReceivableHandle(accountForUpdate.getReceivableHandle().subtract(recPayHandleForUpdate.getSumAmtReceivableHandle()))// 总应收收款金额
+                                    .setObjectId(objectId);
+                            // 剩余应收 = 总应收账款-总应收收款金额
+                            accountUpdate.setReceivableResidue(accountForUpdate.getReceivable().subtract(accountUpdate.getReceivableHandle()));
+                            // 可退金额 = 总收款金额-总应收收款金额+总应收优惠金额
+                            accountUpdate.setReceiptResidue(accountForUpdate.getReceipt().subtract(accountUpdate.getReceivableHandle()));
+
+                            // 更新前的最后校验
+                            // 可用金额为负数,则不能保存
+                            if (accountUpdate.getReceiptResidue().compareTo(BigDecimal.ZERO) == -1) {
+                                throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.RESIDUE_NO_LESS.getMessage());
+                            }
+                            super.updateByUuid(accountUpdate);
+
+                            // 删掉收款核销单
+                            recPayMapper.deleteById(recPayHandleForUpdate.getRpId());
+
+                            // 先把收款单锁定
+                            RecPay recPayUpdate = new RecPay();
+                            recPayUpdate.setFlgLock(true).setRpId(recPayForUpdate.getRpId());
+                            receiptService.updateByUuid(recPayUpdate);
+
+                            // 账款明细解锁
+                            List<RecPayItem> recPayItemList = recPayItemMapper.selectByZIdForUpdate(recPayForUpdate.getRpId());
+                            for (RecPayItem recPayItem : recPayItemList) {
+                                AccountItem accountItemUpdate = new AccountItem();
+                                accountItemUpdate.setFlgLock(true).setItemId(recPayItem.getAccItemId());
+                                accountItemService.updateByUuid(accountItemUpdate);
+                            }
+
+                            // 钱进到锁定金额中
+                            accountForUpdate = accountMapper.selectByIdForUpdate(objectId);
+                            accountUpdate = new Account();
+                            accountUpdate.setReceipt(accountForUpdate.getReceipt().subtract(recPayForUpdate.getSumAmtRec()))
+                                    .setReceiptResidue(accountForUpdate.getReceiptResidue().subtract(recPayForUpdate.getSumAmtRec()))
+                                    .setReceiptLock(accountForUpdate.getReceiptLock().add(recPayForUpdate.getSumAmtRec()))
+                                    .setObjectId(objectId);
+                            super.updateByUuid(accountUpdate);
+                        }
                     }
                 }
             }

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

@@ -14,6 +14,7 @@ import com.dk.mdm.infrastructure.convert.mac.RecPayItemConvert;
 import com.dk.mdm.infrastructure.convert.sale.OrderConvert;
 import com.dk.mdm.infrastructure.convert.sale.OrderItemConvert;
 import com.dk.mdm.infrastructure.convert.sale.OutBoundDtoConvert;
+import com.dk.mdm.mapper.common.CommonMapper;
 import com.dk.mdm.mapper.mac.AccountItemMapper;
 import com.dk.mdm.mapper.mac.RecPayHandleItemMapper;
 import com.dk.mdm.mapper.mac.RecPayItemMapper;
@@ -92,6 +93,9 @@ public class OrderService extends BaseService<Order> {
     private CommonService commonService;
 
     @Autowired
+    private CommonMapper commonMapper;
+
+    @Autowired
     private CustomerMapper customerMapper;
 
     @Autowired
@@ -228,24 +232,24 @@ public class OrderService extends BaseService<Order> {
                     .setReportStaff(orderVO.getMakeStaff()).setSaleStatus(Constant.SaleStatus.CHENGJIAO.getName()).setCpId(orderVO.getCpId());
             customerMapper.insert(customer);
             orderVO.setCusId(customer.getCusId());
-        }else{
+        } else {
             // 如果当前跟进人
             Customer cus = customerMapper.selectByIdForUpdate(orderVO.getCusId());
             List<String> followStaffs = cus.getFollowStaffs();
             Boolean updateFollowFlag = false;
-            if(followStaffs == null ){
+            if (followStaffs == null) {
                 followStaffs.add(orderVO.getMakeStaff());
                 updateFollowFlag = true;
-            }else{
-                if(!followStaffs.contains(orderVO.getMakeStaff())){
+            } else {
+                if (!followStaffs.contains(orderVO.getMakeStaff())) {
                     followStaffs.add(orderVO.getMakeStaff());
                     updateFollowFlag = true;
                 }
             }
-            if(updateFollowFlag){
+            if (updateFollowFlag) {
                 // 更新当前跟进人
                 customerMapper.updateFollowStaffs(new Customer().setCusId(orderVO.getCusId())
-                                                    .setFollowStaffs(followStaffs));
+                        .setFollowStaffs(followStaffs));
             }
         }
 
@@ -299,71 +303,144 @@ public class OrderService extends BaseService<Order> {
 
         /**************************************** 客户收款begin ********************************/
         if (orderVO.getReceiptList() != null && orderVO.getReceiptList().size() > 0) {
-            RecPay recPay = new RecPay();
+            // 商户产品版本
+            String gradeCode = "PRO";
+            Map<String, Object> paramCompany = new HashMap<>();
+            paramCompany.put("cpId", orderVO.getCpId());
+            List<Map<String, Object>> listCompany = commonMapper.getCompany(paramCompany);
+            if (listCompany.size() > 0) {
+                gradeCode = listCompany.get(0).get("gradeCode").toString();
+            }
             // 获取单号
             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(orderVO.getCusId())
-                    .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
-                    .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
-                    .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId()).setFlgLock(true);
-            // 计算订单明细的出库中数量,金额合计
-            RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
-                RecPayItemVO item = new RecPayItemVO();
-                item.setAmtRec(x.getAmtRec().add(y.getAmtRec()));
-                return item;
-            }).get();
-            recPay.setSumAmtRec(itemSum.getAmtRec());
-
-            // 总单保存
-            recPayMapper.insert(recPay);
-
-            // 明细保存
-            for (RecPayItemVO recPayItemVO : orderVO.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(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
-                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId()).setFlgLock(true);
-                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);
+            RecPay recPay = new RecPay();
+
+            // 专业版有定金
+            if ("PRO".equals(gradeCode)) {
+                recPay.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                        .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(orderVO.getCusId())
+                        .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
+                        .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
+                        .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId()).setFlgLock(true);
+                // 计算订单明细的出库中数量,金额合计
+                RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
+                    RecPayItemVO item = new RecPayItemVO();
+                    item.setAmtRec(x.getAmtRec().add(y.getAmtRec()));
+                    return item;
+                }).get();
+                recPay.setSumAmtRec(itemSum.getAmtRec());
+
+                // 总单保存
+                recPayMapper.insert(recPay);
+
+                // 明细保存
+                for (RecPayItemVO recPayItemVO : orderVO.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(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
+                            .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId()).setFlgLock(true);
+                    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.setReceiptLock(accountForUpdate.getReceiptLock().add(recPay.getSumAmtRec()))//  锁定金额
+                        .setObjectId(accountForUpdate.getObjectId());
+                accountService.updateByUuid(accountUpdate);
+            } else if ("STD".equals(gradeCode)) {
+                recPay.setRpId(codeMap.get("outId").toString()).setRpNo(codeMap.get("outNote").toString())
+                        .setRpType(Constant.RpType.SHOU_KUAN.getName()).setObjectId(orderVO.getCusId())
+                        .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
+                        .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
+                        .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId());
+                // 计算订单明细的出库中数量,金额合计
+                RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
+                    RecPayItemVO item = new RecPayItemVO();
+                    item.setAmtRec(x.getAmtRec().add(y.getAmtRec()));
+                    return item;
+                }).get();
+                recPay.setSumAmtRec(itemSum.getAmtRec());
+
+                // 总单保存
+                recPayMapper.insert(recPay);
+
+                // 明细保存
+                for (RecPayItemVO recPayItemVO : orderVO.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(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).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);
             }
 
-            // 插入账款总表
-            Account accountForUpdate = accountService.getCusAccountForUpdate(recPay.getObjectId());
-            // 更新账款总表上收款的相关字段
-            Account accountUpdate = new Account();
-            accountUpdate.setReceiptLock(accountForUpdate.getReceiptLock().add(recPay.getSumAmtRec()))//  锁定金额
-                    .setObjectId(accountForUpdate.getObjectId());
-            accountService.updateByUuid(accountUpdate);
         }
         /**************************************** 客户收款end ********************************/
         //开单并出库办理
-        if (orderVO.getOutboundProcessingFlag()!=null&& orderVO.getOutboundProcessingFlag()){
+        if (orderVO.getOutboundProcessingFlag() != null && orderVO.getOutboundProcessingFlag()) {
             for (OrderItemVO orderItemVO : orderVO.getItemList()) {
                 orderItemVO.setOutingQty(orderItemVO.getItemQty());
                 orderItemVO.setOutingAmt(orderItemVO.getItemAmt());
@@ -407,7 +484,7 @@ public class OrderService extends BaseService<Order> {
         // 转化实体
         Order order = orderConvert.convertToPo(orderVO);
         //删除的
-        if(orderVO.getDeleteItemList() != null){
+        if (orderVO.getDeleteItemList() != null) {
             List<OrderItemVO> deleteOrderItemVOList = orderVO.getDeleteItemList().stream().filter(it -> it.getItemId() != null).collect(Collectors.toList());
             if (deleteOrderItemVOList.size() > 0) {
                 for (OrderItemVO orderItemVO : deleteOrderItemVOList) {
@@ -508,74 +585,154 @@ public class OrderService extends BaseService<Order> {
             }
         }
 
-        if (orderVO.getReceiptList() != null && orderVO.getReceiptList().size() > 0) {
+        // 商户产品版本
+        String gradeCode = "PRO";
+        Map<String, Object> paramCompany = new HashMap<>();
+        paramCompany.put("cpId", orderVO.getCpId());
+        List<Map<String, Object>> listCompany = commonMapper.getCompany(paramCompany);
+        if (listCompany.size() > 0) {
+            gradeCode = listCompany.get(0).get("gradeCode").toString();
+        }
 
-            // 计算订单明细的出库中数量,金额合计
-            RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
-                RecPayItemVO item = new RecPayItemVO();
-                item.setAmtRec(x.getAmtRec().add(y.getAmtRec()));
-                return item;
-            }).get();
-
-            RecPay recPay = null;
-            if (recPayForUpdate == null) {
-                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(orderVO.getCusId())
-                        .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
-                        .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
-                        .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId()).setFlgLock(true);
+        // 专业版有定金
+        if ("PRO".equals(gradeCode)) {
+            if (orderVO.getReceiptList() != null && orderVO.getReceiptList().size() > 0) {
+                // 计算订单明细的出库中数量,金额合计
+                RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
+                    RecPayItemVO item = new RecPayItemVO();
+                    item.setAmtRec(x.getAmtRec().add(y.getAmtRec()));
+                    return item;
+                }).get();
+
+                RecPay recPay = null;
+                if (recPayForUpdate == null) {
+                    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(orderVO.getCusId())
+                            .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
+                            .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
+                            .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId()).setFlgLock(true);
+
+                    recPay.setSumAmtRec(itemSum.getAmtRec());
+                    recPayMapper.insert(recPay);
+                } else {
+                    // 更新收款总额
+                    RecPay recPayUpdate = new RecPay();
+                    recPayUpdate.setSumAmtRec(itemSum.getAmtRec()).setRpId(recPayForUpdate.getRpId());
+                    receiptService.updateByUuid(recPayUpdate);
 
-                recPay.setSumAmtRec(itemSum.getAmtRec());
-                recPayMapper.insert(recPay);
-            } else {
-                // 更新收款总额
-                RecPay recPayUpdate = new RecPay();
-                recPayUpdate.setSumAmtRec(itemSum.getAmtRec()).setRpId(recPayForUpdate.getRpId());
-                receiptService.updateByUuid(recPayUpdate);
+                    // 赋值recPay,下面要用
+                    recPay = recPayForUpdate;
+                }
 
-                // 赋值recPay,下面要用
-                recPay = recPayForUpdate;
+                // 明细保存
+                for (RecPayItemVO recPayItemVO : orderVO.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(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
+                            .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId()).setFlgLock(true);
+                    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);
+
+                    if (!macList.contains(recPayItem.getMacId())) {
+                        macList.add(recPayItem.getMacId());
+                    }
+                }
             }
+            if (recPayForUpdate != null) {
+                // 更新总账表的锁定金额
+                accountService.updateReceiptLock(recPayForUpdate.getObjectId());
+            }
+        } else if ("STD".equals(gradeCode)) {
+            if (orderVO.getReceiptList() != null && orderVO.getReceiptList().size() > 0) {
+                // 计算订单明细的出库中数量,金额合计
+                RecPayItemVO itemSum = orderVO.getReceiptList().stream().reduce((x, y) -> {
+                    RecPayItemVO item = new RecPayItemVO();
+                    item.setAmtRec(x.getAmtRec().add(y.getAmtRec()));
+                    return item;
+                }).get();
+
+                RecPay recPay = null;
+                if (recPayForUpdate == null) {
+                    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(orderVO.getCusId())
+                            .setOrgId(orderVO.getOrgId()).setStaffId(orderVO.getStaffId()).setAccDate(LocalDate.now())
+                            .setBiznisType(Constant.InventoryDocCode.ORDER.getTableName()).setBiznisId(orderVO.getOrderId()).setBiznisNo(orderVO.getOrderNo())
+                            .setMakeStaff(orderVO.getMakeStaff()).setCpId(orderVO.getCpId());
+
+                    recPay.setSumAmtRec(itemSum.getAmtRec());
+                    recPayMapper.insert(recPay);
+                } else {
+                    // 更新收款总额
+                    RecPay recPayUpdate = new RecPay();
+                    recPayUpdate.setSumAmtRec(itemSum.getAmtRec()).setRpId(recPayForUpdate.getRpId());
+                    receiptService.updateByUuid(recPayUpdate);
 
-            // 明细保存
-            for (RecPayItemVO recPayItemVO : orderVO.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(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).setBiznisId(recPayItem.getItemId()).setBiznisNo(recPay.getRpNo())
-                        .setMakeStaff(recPay.getMakeStaff()).setCpId(recPay.getCpId()).setFlgLock(true);
-                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);
+                    // 赋值recPay,下面要用
+                    recPay = recPayForUpdate;
+                }
 
-                if (!macList.contains(recPayItem.getMacId())) {
-                    macList.add(recPayItem.getMacId());
+                // 明细保存
+                for (RecPayItemVO recPayItemVO : orderVO.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(Constant.InventoryDocCode.REC_PAY_ITEM.getTableName()).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);
+
+                    if (!macList.contains(recPayItem.getMacId())) {
+                        macList.add(recPayItem.getMacId());
+                    }
                 }
             }
+            if (recPayForUpdate != null) {
+                // 更新总账表的总收款额和可用额
+                accountService.updateReceipt(recPayForUpdate.getObjectId());
+            }
         }
-        if (recPayForUpdate != null) {
-            // 更新总账表的锁定金额
-            accountService.updateReceiptLock(recPayForUpdate.getObjectId());
-        }
+
 
         // 更新账户余额
         for (String macId : macList) {
@@ -664,7 +821,7 @@ public class OrderService extends BaseService<Order> {
         staffList.add(Constant.OwnerType.Z_STAFF.getName());
         staffList.add(Constant.OwnerType.C_STAFF.getName());
         List<MultiOwnerResponse> multiOwnersStaff = multiOwnerMapper.selectByType(new MultiOwnerQuery().setOrderId(id).setOwnerTypes(staffList));
-        if(multiOwnersStaff != null && multiOwnersStaff.size() > 0){
+        if (multiOwnersStaff != null && multiOwnersStaff.size() > 0) {
             dataInfo.put("staffList", multiOwnersStaff);
         }
         //查询主从业务部门
@@ -672,7 +829,7 @@ public class OrderService extends BaseService<Order> {
         orgList.add(Constant.OwnerType.Z_ORG.getName());
         orgList.add(Constant.OwnerType.C_ORG.getName());
         List<MultiOwnerResponse> multiOwnersOrg = multiOwnerMapper.selectByType(new MultiOwnerQuery().setOrderId(id).setOwnerTypes(orgList));
-        if(multiOwnersOrg != null && multiOwnersOrg.size() > 0){
+        if (multiOwnersOrg != null && multiOwnersOrg.size() > 0) {
             dataInfo.put("orgList", multiOwnersOrg);
         }