瀏覽代碼

佣金创建周期

HULEI 2 月之前
父節點
當前提交
0c08631573

+ 1 - 1
com.awspaas.user.apps.donenow_ctt/com.awspaas.user.apps.donenow_ctt.iml

@@ -5,7 +5,7 @@
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
     </content>
-    <orderEntry type="inheritedJdk" />
+    <orderEntry type="jdk" jdkName="temurin-11" jdkType="JavaSDK" />
     <orderEntry type="sourceFolder" forTests="false" />
     <orderEntry type="library" name="aws_lib" level="project" />
     <orderEntry type="module-library">

二進制
com.awspaas.user.apps.donenow_ctt/com.awspaas.user.apps.donenow_ctt.jar


+ 284 - 5
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/controller/contractApproveController.java

@@ -12,16 +12,14 @@ import com.actionsoft.sdk.local.api.Logger;
 import com.awspaas.user.apps.donenow_ctt.cttConstant;
 import com.awspaas.user.apps.donenow_ctt.service.contractService;
 import org.apache.commons.lang3.StringUtils;
-
+import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 import static com.awspaas.user.apps.donenow_ctt.service.contractService.GetEntryCost;
 import static com.awspaas.user.apps.donenow_ctt.service.contractService.getLocalDate;
@@ -1015,5 +1013,286 @@ public class contractApproveController {
         }
         return ResponseObject.newOkResponse();
     }
+    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.insertCommissionPeriods")
+    public ResponseObject insertCommissionPeriods(UserContext uc,
+                                                  String bindid,
+                                                  String startDate,
+                                                  String endDate,
+                                                  String amount) {
+
+        // 1. 参数校验
+        if (StringUtils.isBlank(bindid)) {
+            return ResponseObject.newErrResponse("bindid不能为空");
+        }
+        if (StringUtils.isBlank(startDate)) {
+            return ResponseObject.newErrResponse("开始日期不能为空");
+        }
+        if (StringUtils.isBlank(endDate)) {
+            return ResponseObject.newErrResponse("结束日期不能为空");
+        }
+        if (StringUtils.isBlank(amount)) {
+            return ResponseObject.newErrResponse("金额不能为空");
+        }
+
+        try {
+            // 2. 日期处理
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(sdf.parse(startDate));
+            int settleDay = cal.get(Calendar.DATE); // 固定结算日
+
+            Calendar endCal = Calendar.getInstance();
+            endCal.setTime(sdf.parse(endDate));
+
+            // 3. 插入 SQL
+            String insertSql = "INSERT INTO BO_EU_DNCTT_COMMISSION_PERIOD " +
+                    "(ID,ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, COMMISSION_DOLLARS,PERIOD_ADJUSTED_PRICE) " +
+                    "VALUES (UUID(),?, ?, ?, ?, ?,?)";
+
+            int rows = 0;
+
+            Calendar currentCal = Calendar.getInstance();
+            currentCal.setTime(sdf.parse(startDate));
+
+            // 4. 循环生成 12 个周期
+            for (int i = 0; i < 12; i++) {
+                Date periodStart = currentCal.getTime();
+
+                currentCal.add(Calendar.MONTH, 1);
+                currentCal.set(Calendar.DATE, settleDay);
+                currentCal.add(Calendar.DATE, -1);
+                Date periodEnd = currentCal.getTime();
+
+                if (periodEnd.after(endCal.getTime())) {
+                    periodEnd = endCal.getTime();
+                }
+
+                rows += DBSql.update(insertSql, new Object[]{
+                        bindid,
+                        uc.getCompanyModel().getId(),
+                        sdf.format(periodStart),
+                        sdf.format(periodEnd),
+                        amount,
+                        amount
+                });
+
+                currentCal.add(Calendar.DATE, 1);
+                currentCal.set(Calendar.DATE, settleDay);
+
+                if (periodStart.after(endCal.getTime())) {
+                    break;
+                }
+            }
+
+            // 5. 构造返回结果
+            Map<String, Object> result = new HashMap<>();
+            result.put("bindid", bindid);
+            result.put("startDate", startDate);
+            result.put("endDate", endDate);
+            result.put("amount", amount);
+            result.put("rows", rows);
+
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+
+            return responseObject;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseObject.newErrResponse("插入失败:" + e.getMessage());
+        }
+    }
+    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.batchInsertAgentPeriods")
+    public ResponseObject batchInsertAgentPeriods(UserContext uc,
+                                                  String bindid,
+                                                  String startDate,
+                                                  String endDate,
+                                                  String amount) {
+
+        // 1. 参数校验
+        if (StringUtils.isBlank(bindid)) {
+            return ResponseObject.newErrResponse("bindid不能为空");
+        }
+        if (StringUtils.isBlank(startDate)) {
+            return ResponseObject.newErrResponse("开始日期不能为空");
+        }
+        if (StringUtils.isBlank(endDate)) {
+            return ResponseObject.newErrResponse("结束日期不能为空");
+        }
+        if (StringUtils.isBlank(amount)) {
+            return ResponseObject.newErrResponse("基础金额不能为空");
+        }
+
+        try {
+            // 2. 分页查询所有代理(同时查 AGENT 和 RATIO)
+            List<Map<String, Object>> agentList = new ArrayList<>();
+            int offset = 0;
+            while (true) {
+                String querySql = "SELECT AGENT, RATIO FROM BO_EU_DNCTT_COMMISSION_AGENT WHERE bindid = ? LIMIT 1 OFFSET ?";
+                RowMap agentMap = DBSql.getMap(querySql, new Object[]{bindid, offset});
+                if (agentMap == null) {
+                    break; // 没有更多数据
+                }
+
+                String agent = agentMap.getString("AGENT");
+                BigDecimal ratio = null;
+
+                Object ratioObj = agentMap.get("RATIO");
+                if (ratioObj != null) {
+                    if (ratioObj instanceof BigDecimal) {
+                        ratio = (BigDecimal) ratioObj;
+                    } else if (ratioObj instanceof Double) {
+                        ratio = BigDecimal.valueOf((Double) ratioObj);
+                    } else if (ratioObj instanceof Float) {
+                        ratio = BigDecimal.valueOf(((Float) ratioObj).doubleValue());
+                    } else if (ratioObj instanceof Integer) {
+                        ratio = BigDecimal.valueOf(((Integer) ratioObj).longValue());
+                    } else {
+                        try {
+                            ratio = new BigDecimal(ratioObj.toString());
+                        } catch (Exception e) {
+                            return ResponseObject.newErrResponse("代理 " + agent + " 的比例格式错误:" + ratioObj);
+                        }
+                    }
+                }
+
+                if (ratio == null) {
+                    return ResponseObject.newErrResponse("代理 " + agent + " 的比例为空");
+                }
+
+                Map<String, Object> agentInfo = new HashMap<>();
+                agentInfo.put("AGENT", agent);
+                agentInfo.put("RATIO", ratio);
+                agentList.add(agentInfo);
+
+                offset++;
+            }
+
+            if (agentList.isEmpty()) {
+                return ResponseObject.newErrResponse("未找到二级代理数据");
+            }
+
+            // 3. 日期处理
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(sdf.parse(startDate));
+            int settleDay = cal.get(Calendar.DATE);
+
+            Calendar endCal = Calendar.getInstance();
+            endCal.setTime(sdf.parse(endDate));
+
+            // 4. 插入 SQL
+            String insertSql = "INSERT INTO BO_EU_DNCTT_COMMISSION_PERIOD_AGENT " +
+                    "(ID, AGENT, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, COMMISSION_DOLLARS) " +
+                    "VALUES (UUID(), ?, ?, ?, ?, ?)";
+
+            int rows = 0;
+            BigDecimal baseAmount = new BigDecimal(amount);
+
+            // 5. 循环每个代理
+            for (Map<String, Object> agentInfo : agentList) {
+                String agent = (String) agentInfo.get("AGENT");
+                BigDecimal ratio = (BigDecimal) agentInfo.get("RATIO");
+
+                // 百分比转小数(20 → 0.2)
+                BigDecimal ratioDecimal = ratio.divide(new BigDecimal("100"));
+
+                // 计算实际佣金
+                BigDecimal realCommission = baseAmount.multiply(ratioDecimal);
+
+                Calendar currentCal = Calendar.getInstance();
+                currentCal.setTime(sdf.parse(startDate));
+
+                for (int i = 0; i < 12; i++) {
+                    Date periodStart = currentCal.getTime();
+
+                    currentCal.add(Calendar.MONTH, 1);
+                    currentCal.set(Calendar.DATE, settleDay);
+                    currentCal.add(Calendar.DATE, -1);
+                    Date periodEnd = currentCal.getTime();
+
+                    if (periodEnd.after(endCal.getTime())) {
+                        periodEnd = endCal.getTime();
+                    }
+
+                    rows += DBSql.update(insertSql, new Object[]{
+                            agent,
+                            bindid,
+                            sdf.format(periodStart),
+                            sdf.format(periodEnd),
+                            realCommission.toPlainString()
+                    });
+
+                    currentCal.add(Calendar.DATE, 1);
+                    currentCal.set(Calendar.DATE, settleDay);
+
+                    if (periodStart.after(endCal.getTime())) {
+                        break;
+                    }
+                }
+            }
+
+            // 6. 返回结果
+            Map<String, Object> result = new HashMap<>();
+            result.put("bindid", bindid);
+            result.put("startDate", startDate);
+            result.put("endDate", endDate);
+            result.put("baseAmount", amount);
+            result.put("rows", rows);
+            result.put("agentCount", agentList.size());
+
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+
+            return responseObject;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseObject.newErrResponse("插入失败:" + e.getMessage());
+        }
+    }
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.checkCommissionPeriodExists")
+    public ResponseObject checkCommissionPeriodExists(UserContext uc,
+                                                      String bindid) {
+        try {
+            String checkSql = "SELECT COUNT(1) FROM BO_EU_DNCTT_COMMISSION_PERIOD " +
+                    "WHERE BINDID = ?";
+
+            int existCount = DBSql.getInt(checkSql, new Object[]{bindid});
+
+            Map<String, Object> result = new HashMap<>();
+            result.put("exists", existCount > 0); // true 表示已存在
+
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+            return responseObject;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseObject.newErrResponse("查询失败:" + e.getMessage());
+        }
+    }
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.checkAgentCommissionPeriodExists")
+    public ResponseObject checkAgentCommissionPeriodExists(UserContext uc,
+                                                           String bindid,
+                                                           String startDate,
+                                                           String endDate) {
+        try {
+            String checkSql = "SELECT COUNT(1) FROM BO_EU_DNCTT_COMMISSION_PERIOD_AGENT " +
+                    "WHERE BINDID = ?";
+
+            int existCount = DBSql.getInt(checkSql, new Object[]{bindid});
+
+            Map<String, Object> result = new HashMap<>();
+            result.put("exists", existCount > 0); // true 表示已存在
 
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+            return responseObject;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseObject.newErrResponse("查询失败:" + e.getMessage());
+        }
+    }
 }

+ 1 - 1
com.awspaas.user.apps.donenow_ivt/src/com/awspaas/user/apps/donenow_ivt/controller/ivtOrderController.java

@@ -670,7 +670,7 @@ public class ivtOrderController {
                 BO purchaseOrderProduct = new BO();
                 purchaseOrderProduct.setBindId(processInstance.getId());
 
-
+    
                 purchaseOrderProduct.set("PURCHASE_ACCOUNT_ID", cost.getString("ACCOUNT_ID"));
                 purchaseOrderProduct.set("NAME", cost.getString("NAME"));
                 purchaseOrderProduct.set("PRODUCT_ID", cost.getString("PRODUCT_ID"));