Selaa lähdekoodia

佣金导入匹配

HULEI 2 kuukautta sitten
vanhempi
commit
e07225b461

BIN
com.awspaas.user.apps.donenow_ctt/com.awspaas.user.apps.donenow_ctt.jar


+ 137 - 3
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/controller/contractApproveController.java

@@ -1415,8 +1415,8 @@ public class contractApproveController {
         }
     }
 
-    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.checkCommissionPeriodExists")
-    public ResponseObject checkCommissionPeriodExists(UserContext uc,
+    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.checkCommissionPeriodExists2")
+    public ResponseObject checkCommissionPeriodExists2(UserContext uc,
                                                       String bindid,
                                                       String startDate,
                                                       String endDate) {
@@ -1452,7 +1452,7 @@ public class contractApproveController {
             int existCount = DBSql.getInt(checkSql, new Object[]{bindid});
 
             Map<String, Object> result = new HashMap<>();
-            result.put("exists", existCount > 0); // true 表示已存在
+            result.put("exists", existCount > 0);
 
             ResponseObject responseObject = ResponseObject.newOkResponse();
             responseObject.setData(result);
@@ -1669,6 +1669,140 @@ public class contractApproveController {
         return ResponseObject.newOkResponse();
     }
 
+    @Mapping("com.awspaas.user.apps.donenow_ctt.matchBillByHeadquartersFeePeriod2")
+    public ResponseObject matchBillByHeadquartersFeePeriod2(UserContext uc, String headquartersFeePeriod) throws SQLException {
+        Connection connUpdate = null;
+        try {
+            // 参数校验(不变)
+            if (StringUtils.isBlank(headquartersFeePeriod)) {
+                return ResponseObject.newErrResponse("总部费用账期不能为空");
+            }
+            String feePeriod = headquartersFeePeriod.trim();
+
+            // 1. 查询需要更新的数据:新增查询a表ID(a.ID AS a_id)
+            String querySql = "SELECT " +
+                    "a.ID AS a_id, " + // 【修改1:新增查询a表ID,用于存到c表COMMISSION_IMPORT_ID】
+                    "a.COMMISSION_DOLLARS AS 佣金, " +
+                    "a.TOTAL_DOLLARS AS 基数, " +
+                    "a.RATIO AS 比例, " +
+                    "a.ZB_BILLING_DATE AS 账单日期, " +
+                    "c.ID AS c_id  " +
+                    "FROM BO_EU_DNCTT_COMMISSION_IMPORT a " +
+                    "JOIN BO_EU_DNCTT_COMMISSION b " +
+                    "ON a.ACCOUNT_NO = b.NEW_ACCOUNT AND a.DEVICE_ID = b.DEVICE_ID " +
+                    "JOIN BO_EU_DNCTT_COMMISSION_PERIOD c " +
+                    "ON a.ZB_FEE_DATE = c.ZB_FEE_DATE AND b.bindid = c.bindid " +
+                    "WHERE a.ZB_FEE_DATE = ?";
+
+            List<RowMap> matchRecords = DBSql.getMaps(querySql, new Object[]{feePeriod});
+
+            if (matchRecords == null || matchRecords.isEmpty()) {
+                Map<String, Object> result = new HashMap<>();
+                result.put("totalMatched", 0);
+                result.put("message", "未找到对应账期的记录");
+                ResponseObject responseObject = ResponseObject.newOkResponse();
+                responseObject.setData(result);
+                return responseObject;
+            }
+
+            // 2. 初始化连接 + 事务控制(不变)
+            connUpdate = DBSql.open();
+            connUpdate.setAutoCommit(false);
+
+            int updateCount = 0;
+
+            // 3. 循环处理每条记录
+            for (RowMap record : matchRecords) {
+                // 键值处理(不变)
+                for (String key : record.keySet()) {
+                    record.put(key.toUpperCase(), record.get(key) == null ? "" : record.get(key));
+                }
+
+                // 【修改2:提取a表ID(a_id),用于更新到c表COMMISSION_IMPORT_ID】
+                String aId = record.getString("a_id"); // 从查询结果中获取a表ID
+
+                // 提取c表ID(不变)
+                String cId = record.getString("c_id");
+                if (StringUtils.isBlank(cId)) {
+                    System.out.println("跳过无c表ID的记录:" + record);
+                    continue;
+                }
+
+                // 提取其他字段(不变)
+                Double commission = record.getDouble("佣金");
+                Double total = record.getDouble("基数");
+                String ratioStr = record.getString("比例");
+                String zbBillingDate = record.getString("账单日期");
+
+                // 处理比例字段(不变)
+                Double ratio = 0.0;
+                if (StringUtils.isNotBlank(ratioStr)) {
+                    String pureRatio = ratioStr.replace("%", "").trim();
+                    if ((StringUtils.isNumeric(pureRatio) || pureRatio.contains("."))) {
+                        try {
+                            ratio = Double.parseDouble(pureRatio);
+                        } catch (NumberFormatException e) {
+                            System.out.println("比例格式错误(使用默认值0.0):" + ratioStr);
+                        }
+                    } else {
+                        System.out.println("比例非数字(使用默认值0.0):" + ratioStr);
+                    }
+                }
+
+                // 4. 执行更新:新增COMMISSION_IMPORT_ID字段的更新
+                DBSql.update(connUpdate,
+                        "UPDATE BO_EU_DNCTT_COMMISSION_PERIOD " +
+                                "SET COMMISSION_DOLLARS = ?, " +
+                                "TOTAL_DOLLARS_IMPORT = ?, " +
+                                "RATIO_IMPORT = ?, " +
+                                "ZB_BILLING_DATE = ?, " +
+                                "COMMISSION_IMPORT_ID = ? " + // 【修改3:新增字段,存a表ID】
+                                "WHERE ID = ?",
+                        new Object[]{
+                                commission,   // 1. 佣金
+                                total,        // 2. 基数
+                                ratio,        // 3. 处理后的比例
+                                zbBillingDate,// 4. 账单日期
+                                aId,          // 5. 【修改4:新增参数,传入a表ID】
+                                cId           // 6. 条件:c表ID
+                        }
+                );
+
+                updateCount++;
+            }
+
+            // 5. 提交事务(不变)
+            connUpdate.commit();
+
+            // 6. 响应结果(不变)
+            Map<String, Object> result = new HashMap<>();
+            result.put("totalMatched", matchRecords.size());
+            result.put("updateCount", updateCount);
+            result.put("message", "已按 revoke_commission 风格完成更新");
+
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+            return responseObject;
+
+        } catch (SQLException e) {
+            // 异常回滚(不变)
+            if (connUpdate != null && !connUpdate.isClosed()) {
+                try {
+                    connUpdate.rollback();
+                } catch (SQLException ex) {
+                    ex.printStackTrace();
+                }
+            }
+            e.printStackTrace();
+            return ResponseObject.newErrResponse("处理失败:" + e.getMessage());
+        } finally {
+            // 关闭连接(不变)
+            if (connUpdate != null && !connUpdate.isClosed()) {
+                DBSql.close(connUpdate);
+            }
+        }
+    }
+
 
 }