Jelajahi Sumber

固话代缴费

HULEI 3 minggu lalu
induk
melakukan
89c6127fc6

+ 176 - 2
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/controller/contractApproveController.java

@@ -22,9 +22,11 @@ import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
-
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.text.ParseException;
 import static com.awspaas.user.apps.donenow_ctt.service.contractService.*;
-
+import java.net.URLDecoder;
 @Controller
 public class contractApproveController {
     private static final Logger contractLogger = SDK.getLogAPI().getLogger(contractApproveController.class);//记录日志
@@ -2331,5 +2333,177 @@ public class contractApproveController {
         }
     }
 
+
+    @Mapping(value = "com.awspaas.user.apps.donenow_ctt.updateAttachmentUrlByPhoneLast4")
+    public ResponseObject updateAttachmentUrlByPhoneLast4(UserContext uc, String certificateContent, String attachmentUrl, String feeDate) {
+        Map<String, Object> result = new HashMap<>();
+        try {
+            // 1. 合并参数校验(仅1个提前返回)
+            String errorMsg = "";
+            if (certificateContent == null || certificateContent.trim().isEmpty()) {
+                errorMsg = "凭证内容不能为空";
+            } else if (attachmentUrl == null || attachmentUrl.trim().isEmpty()) {
+                errorMsg = "图片URL不能为空";
+            } else if (feeDate == null || feeDate.trim().isEmpty()) {
+                errorMsg = "账期不能为空";
+            }
+            if (!errorMsg.isEmpty()) {
+                result.put("result", "ok");
+                result.put("message", errorMsg);
+                result.put("proxyPayUpdatedCount", 0);
+                result.put("periodUpdatedCount", 0);
+                ResponseObject responseObject = ResponseObject.newOkResponse();
+                responseObject.setData(result);
+                return responseObject;
+            }
+
+            // ========== 仅新增:账期转换为周期起止日期(用于更新条件) ==========
+            String periodBeginDate = ""; // 账期年月的当月1日(如2025-03 → 2025-03-01)
+            String periodEndDate = "";   // 账期年月的当月最后1日(如2025-03 → 2025-03-31)
+            try {
+                // 兼容账期格式:2025-03 或 202503
+                SimpleDateFormat sdfInput = feeDate.contains("-") ?
+                        new SimpleDateFormat("yyyy-MM") : new SimpleDateFormat("yyyyMM");
+                Date feeDateObj = sdfInput.parse(feeDate);
+                Calendar cal = Calendar.getInstance();
+                cal.setTime(feeDateObj);
+
+                // 当月1日
+                cal.set(Calendar.DAY_OF_MONTH, 1);
+                periodBeginDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
+
+                // 当月最后1日
+                cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
+                periodEndDate = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
+            } catch (ParseException e) {
+                result.put("result", "ok");
+                result.put("message", "账期格式错误(需为yyyy-MM或yyyyMM,如2025-03)");
+                result.put("proxyPayUpdatedCount", 0);
+                result.put("periodUpdatedCount", 0);
+                ResponseObject responseObject = ResponseObject.newOkResponse();
+                responseObject.setData(result);
+                return responseObject;
+            }
+
+            // 2. 提取fileName
+            String fileName = "";
+            Pattern fileNamePattern = Pattern.compile("fileName=([^&]+)");
+            Matcher fileNameMatcher = fileNamePattern.matcher(attachmentUrl);
+            if (fileNameMatcher.find()) {
+                fileName = fileNameMatcher.group(1);
+                try { fileName = URLDecoder.decode(fileName, "UTF-8"); } catch (Exception e) {e.printStackTrace();}
+            }
+
+            // 3. 提取手机号后四位
+            Pattern phonePattern = Pattern.compile("\\d{3}\\*{4}(\\d{4})");
+            Matcher phoneMatcher = phonePattern.matcher(certificateContent);
+            Set<String> lastFourSet = new HashSet<>();
+            while (phoneMatcher.find()) { lastFourSet.add(phoneMatcher.group(1)); }
+            List<String> lastFourList = new ArrayList<>(lastFourSet);
+
+            // 4. 更新PROXY_PAY表(原有逻辑,已匹配FEE_DATE)
+            int proxyPayUpdatedCount = 0;
+            if (!lastFourList.isEmpty() && !fileName.isEmpty()) {
+                StringBuilder updateProxyPaySql = new StringBuilder("UPDATE BO_EU_DNCTT_PROXY_PAY SET ATTACHMENT_URL = ?, PAY_PROOF = ?, ATTACHMENT = ? WHERE RIGHT(PHONE, 4) IN (");
+                for (int i = 0; i < lastFourList.size(); i++) { updateProxyPaySql.append(i == 0 ? "?" : ",?"); }
+                updateProxyPaySql.append(") AND FEE_DATE = ?");
+
+                Object[] proxyPayParams = new Object[lastFourList.size() + 4];
+                proxyPayParams[0] = attachmentUrl;
+                proxyPayParams[1] = certificateContent;
+                proxyPayParams[2] = fileName;
+                for (int i = 0; i < lastFourList.size(); i++) { proxyPayParams[i + 3] = lastFourList.get(i); }
+                proxyPayParams[lastFourList.size() + 3] = feeDate;
+                proxyPayUpdatedCount = DBSql.update(updateProxyPaySql.toString(), proxyPayParams);
+            }
+
+            // 5. 计算总金额(查询时返回账期+匹配账期,原有逻辑)
+            Map<String, BigDecimal> phoneAmountMap = new HashMap<>();
+            Map<String, String> phoneFeeDateMap = new HashMap<>();
+            if (!lastFourList.isEmpty()) {
+                StringBuilder queryAmountSql = new StringBuilder("SELECT " +
+                        "RIGHT(PHONE,4) AS PHONE_LAST4, " +
+                        "FEE_DATE, " +
+                        "IFNULL(EXTENDED_PRICE,0)+IFNULL(TAX_DOLLARS,0) AS TOTAL_AMOUNT " +
+                        "FROM BO_EU_DNCTT_PROXY_PAY " +
+                        "WHERE RIGHT(PHONE,4) IN (");
+                for (int i = 0; i < lastFourList.size(); i++) { queryAmountSql.append(i == 0 ? "?" : ",?"); }
+                queryAmountSql.append(") AND FEE_DATE = ?");
+
+                Object[] amountParams = new Object[lastFourList.size() + 1];
+                for (int i = 0; i < lastFourList.size(); i++) { amountParams[i] = lastFourList.get(i); }
+                amountParams[lastFourList.size()] = feeDate;
+
+                List<RowMap> amountList = DBSql.getMaps(queryAmountSql.toString(), amountParams);
+                for (RowMap row : amountList) {
+                    String phoneLast4 = row.getString("PHONE_LAST4");
+                    String feeDateFromDb = row.getString("FEE_DATE");
+                    Object totalAmountObj = row.get("TOTAL_AMOUNT");
+                    BigDecimal totalAmount = BigDecimal.ZERO;
+                    if (totalAmountObj != null) {
+                        totalAmount = new BigDecimal(totalAmountObj.toString());
+                    }
+                    phoneAmountMap.put(phoneLast4, totalAmount);
+                    phoneFeeDateMap.put(phoneLast4, feeDateFromDb);
+                }
+            }
+
+            // 6. 匹配合同服务ID + 更新周期价格(仅新增周期日期条件)
+            int periodUpdatedCount = 0;
+            if (!phoneAmountMap.isEmpty() && !lastFourList.isEmpty()) {
+                List<RowMap> contractList = DBSql.getMaps("SELECT RIGHT(REFERENCE_NUMBER,4) AS REF_LAST4, CONTRACT_SERVICE_ID FROM BO_EU_DNCRM_INSTALLED_PRODUCT WHERE RIGHT(REFERENCE_NUMBER,4) IN (" + String.join(",", Collections.nCopies(lastFourList.size(), "?")) + ")", lastFourList.toArray());
+                Map<String, String> phoneContractMap = new HashMap<>();
+                for (RowMap row : contractList) {
+                    String refLast4 = row.getString("REF_LAST4");
+                    String contractId = row.getString("CONTRACT_SERVICE_ID");
+                    if (contractId != null && !contractId.trim().isEmpty()) { phoneContractMap.put(refLast4, contractId); }
+                }
+
+                if (!phoneContractMap.isEmpty()) {
+                    StringBuilder batchUpdateSql = new StringBuilder("UPDATE BO_EU_DNCTT_CONTRACT_SERVICE_PERIOD SET PERIOD_PRICE = CASE CONTRACT_SERVICE_ID ");
+                    List<Object> batchParams = new ArrayList<>();
+                    List<String> contractIds = new ArrayList<>();
+                    for (Map.Entry<String, String> entry : phoneContractMap.entrySet()) {
+                        batchUpdateSql.append("WHEN ? THEN ? ");
+                        batchParams.add(entry.getValue());
+                        batchParams.add(phoneAmountMap.getOrDefault(entry.getKey(), BigDecimal.ZERO));
+                        contractIds.add(entry.getValue());
+                    }
+                    // ========== 核心修改:新增周期日期条件 ==========
+                    batchUpdateSql.append("END WHERE CONTRACT_SERVICE_ID IN (").append(String.join(",", Collections.nCopies(contractIds.size(), "?"))).append(") ");
+                    batchUpdateSql.append("AND PERIOD_BEGIN_DATE >= ? AND PERIOD_END_DATE <= ?"); // 新增周期条件
+
+                    // 添加合同ID参数 + 周期起止日期参数
+                    for (String id : contractIds) { batchParams.add(id); }
+                    batchParams.add(periodBeginDate); // 账期当月1日
+                    batchParams.add(periodEndDate);   // 账期当月最后1日
+
+                    periodUpdatedCount = DBSql.update(batchUpdateSql.toString(), batchParams.toArray());
+                }
+            }
+
+            // 7. 成功返回(原有逻辑,可选携带账期映射)
+            result.put("result", "ok");
+            result.put("message", fileName.isEmpty() ? "未提取到fileName" : (lastFourList.isEmpty() ? "未提取到手机号" : "处理完成"));
+            result.put("proxyPayUpdatedCount", proxyPayUpdatedCount);
+            result.put("periodUpdatedCount", periodUpdatedCount);
+            result.put("phoneFeeDateMap", phoneFeeDateMap); // 可选:返回查询到的账期
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+            return responseObject;
+
+        } catch (Exception e) {
+            // 8. 失败返回(原有逻辑)
+            e.printStackTrace();
+            result.put("result", "error");
+            result.put("message", "更新失败:" + e.getMessage());
+            result.put("proxyPayUpdatedCount", 0);
+            result.put("periodUpdatedCount", 0);
+            ResponseObject responseObject = ResponseObject.newOkResponse();
+            responseObject.setData(result);
+            return responseObject;
+        }
+    }
+
 }
 

+ 65 - 0
com.awspaas.user.apps.donenow_ctt/src/com/awspaas/user/apps/donenow_ctt/event/PeriodForm.java

@@ -0,0 +1,65 @@
+package com.awspaas.user.apps.donenow_ctt.event;
+
+import com.actionsoft.bpms.dw.design.event.DataWindowFormatSQLEventInterface;
+import com.actionsoft.bpms.dw.exec.component.DataView;
+import com.actionsoft.bpms.server.UserContext;
+import com.actionsoft.sdk.local.SDK;
+import com.actionsoft.sdk.local.api.Logger;
+import com.alibaba.fastjson.JSON;
+
+import java.util.Map;
+import java.util.regex.Pattern;
+
+/**
+ * 采购已付款 - 服务周期重合查询(强制生效版)
+ * 核心:只要参数存在就强制替换,放弃所有格式校验
+ */
+public class PeriodForm implements DataWindowFormatSQLEventInterface {
+    private static final Logger LOGGER = SDK.getLogAPI().getLogger(PeriodForm.class);
+    private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");
+
+    @Override
+    public String formatSQL(UserContext userContext, DataView dataView, String sql) {
+        try {
+            Map<String, Object> sqlParams = dataView.getDatagrid().getSqlParams();
+            LOGGER.info("【周期查询】初始SQL:" + sql);
+            LOGGER.info("【周期查询】查询参数:" + JSON.toJSONString(sqlParams));
+
+            String standardSql = WHITESPACE_PATTERN.matcher(sql).replaceAll(" ").trim();
+            LOGGER.info("【周期查询】标准化SQL:" + standardSql);
+
+            if (sqlParams.containsKey("PERIOD_BEGIN_DATE") && sqlParams.containsKey("PERIOD_BEGIN_DATE0")) {
+                String oldCondition = "AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE >= :PERIOD_BEGIN_DATE AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE <= :PERIOD_BEGIN_DATE0";
+                standardSql = standardSql.replace(oldCondition, "");
+
+                standardSql = standardSql.replace(" AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE >= :PERIOD_BEGIN_DATE", "");
+                standardSql = standardSql.replace(" AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE <= :PERIOD_BEGIN_DATE0", "");
+
+                String newCondition = "AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE <= :PERIOD_BEGIN_DATE0 AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_END_DATE >= :PERIOD_BEGIN_DATE";
+
+                if (standardSql.contains("AND 1=1")) {
+                    standardSql = standardSql.replace("AND 1=1", "AND 1=1 " + newCondition);
+                } else {
+                    standardSql += " " + newCondition;
+                }
+
+                LOGGER.info("周期查询替换完成,中间SQL:" + standardSql);
+            }
+
+            String finalSql = standardSql
+                    .replace(" FROM ", "\nFROM ")
+                    .replace(" WHERE ", "\nWHERE ")
+                    .replace(" AND orgid = ", "\nAND orgid = ")
+                    .replace(" AND 1=1", "\nAND 1=1")
+                    .replace(" AND VIEW_EU_DNV_PAYMENT_PLAN.PLAN_DATE", "\nAND VIEW_EU_DNV_PAYMENT_PLAN.PLAN_DATE")
+                    .replace(" AND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE", "\nAND VIEW_EU_DNV_PAYMENT_PLAN.PERIOD_BEGIN_DATE");
+
+            LOGGER.info("周期查询最终SQL:" + finalSql);
+            return finalSql;
+
+        } catch (Exception e) {
+            LOGGER.error("周期查询SQL格式化失败", e);
+            return sql;
+        }
+    }
+}