|
@@ -1,6 +1,7 @@
|
|
|
package com.rongwei.zhsw.system.controller;
|
|
|
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.zhsw.system.dao.SwBillManagementUnpaidDao;
|
|
|
import com.rongwei.zhsw.system.dao.SwEnterpriseConfigInfoDao;
|
|
|
import com.rongwei.zhsw.system.service.impl.SwEnterpriseConfigInfoServiceImpl;
|
|
|
import com.rongwei.zhsw.system.utils.WxMessageUtils;
|
|
@@ -25,6 +26,9 @@ public class WeChatOfficialController {
|
|
|
@Autowired
|
|
|
private SwEnterpriseConfigInfoServiceImpl swEnterpriseConfigInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SwBillManagementUnpaidDao swBillManagementUnpaidDao;
|
|
|
+
|
|
|
@PostMapping("/sendRepairMessage")
|
|
|
public R sendRepairMessage(@RequestBody Map<String, Object> dataInfo) {
|
|
|
try {
|
|
@@ -133,4 +137,151 @@ public class WeChatOfficialController {
|
|
|
return R.error("发送报修消息提醒失败:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送水费缴费通知消息
|
|
|
+ * 模板内容:
|
|
|
+ * - 标题: 水费缴费通知
|
|
|
+ * - 内容: 您有年月1、年月2水费账单未缴,请及时缴纳
|
|
|
+ * - 客户姓名: {{keyword1.DATA}}
|
|
|
+ * - 客户编号: {{keyword2.DATA}}
|
|
|
+ * - 用水地址: {{keyword3.DATA}}
|
|
|
+ * - 欠费笔数: {{keyword4.DATA}}
|
|
|
+ * - 欠费金额: {{keyword5.DATA}}
|
|
|
+ * - 备注: 请您及时缴费,可通过微信公众号进入用水宝小程序缴费,超期将停水。
|
|
|
+ */
|
|
|
+ @PostMapping("/sendFeeMessage")
|
|
|
+ public R sendFeeMessage(@RequestBody Map<String, Object> dataInfo) {
|
|
|
+ try {
|
|
|
+ log.info("开始处理水费缴费通知消息,消息内容:{}", dataInfo);
|
|
|
+
|
|
|
+ // 参数验证
|
|
|
+ if (dataInfo == null || !dataInfo.containsKey("mbtype")) {
|
|
|
+ return R.error("请求参数不完整");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取模板类型,直接作为字符串使用
|
|
|
+ String mbtype = String.valueOf(dataInfo.get("mbtype"));
|
|
|
+ log.info("mbtype的值: {}, 类型: {}", mbtype, dataInfo.get("mbtype") != null ? dataInfo.get("mbtype").getClass().getName() : "null");
|
|
|
+ if (mbtype == null || mbtype.isEmpty()) {
|
|
|
+ return R.error("请求参数格式不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取企业配置信息
|
|
|
+ SwEnterpriseConfigInfoDo config = swEnterpriseConfigInfoService.getBaseMapper().getEnterpriseConfig();
|
|
|
+ if (config == null) {
|
|
|
+ return R.error("未找到企业配置信息");
|
|
|
+ }
|
|
|
+ log.info("企业配置信息: {}", config);
|
|
|
+
|
|
|
+ // 获取模板ID
|
|
|
+ JSONObject templateConfig = JSON.parseObject(config.getTemplateconfiguration());
|
|
|
+
|
|
|
+ boolean containsKey = templateConfig.containsKey(mbtype);
|
|
|
+
|
|
|
+ String templateId = templateConfig.getString(mbtype);
|
|
|
+
|
|
|
+ if (templateId == null) {
|
|
|
+ // 尝试手动获取
|
|
|
+ Object directValue = templateConfig.get(mbtype);
|
|
|
+ return R.error("未找到对应的模板ID");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断是否为水费通知模板
|
|
|
+ if (!"cstz".equals(mbtype)) {
|
|
|
+ return R.error("不支持的模板类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询欠费用户信息
|
|
|
+ List<Map<String, Object>> arrearsInfoList = swBillManagementUnpaidDao.getWaterFeeArrearsInfo();
|
|
|
+ if (arrearsInfoList == null || arrearsInfoList.isEmpty()) {
|
|
|
+ return R.error("未找到欠费用户信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ int successCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+
|
|
|
+ // 循环发送消息给每个欠费用户
|
|
|
+ for (Map<String, Object> userInfo : arrearsInfoList) {
|
|
|
+ String userNumber = String.valueOf(userInfo.get("USERNUMBER"));
|
|
|
+ String userName = String.valueOf(userInfo.get("USERNAME"));
|
|
|
+
|
|
|
+ // 获取用户微信公众号ID
|
|
|
+ Object gzhOpenIdObj = userInfo.get("GZHOPENID");
|
|
|
+ String openId = (gzhOpenIdObj != null) ? String.valueOf(gzhOpenIdObj) : null;
|
|
|
+
|
|
|
+ // 严格检查openId是否为有效值
|
|
|
+ if (openId == null || openId.isEmpty() || "null".equalsIgnoreCase(openId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ log.info("准备向用户 {} ({}) 发送消息,GZHOPENID: {}", userName, userNumber, openId);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 构建模板消息数据
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+
|
|
|
+ Map<String, String> firstMap = new HashMap<>();
|
|
|
+ String billMonths = (String) userInfo.get("BLILYEARMONTH");
|
|
|
+ firstMap.put("value", "您有" + billMonths + "水费账单未缴,请及时缴纳");
|
|
|
+ data.put("first", firstMap);
|
|
|
+
|
|
|
+ Map<String, String> keyword1Map = new HashMap<>();
|
|
|
+ keyword1Map.put("value", userName);
|
|
|
+ data.put("keyword1", keyword1Map);
|
|
|
+
|
|
|
+ Map<String, String> keyword2Map = new HashMap<>();
|
|
|
+ keyword2Map.put("value", userNumber);
|
|
|
+ data.put("keyword2", keyword2Map);
|
|
|
+
|
|
|
+ Map<String, String> keyword3Map = new HashMap<>();
|
|
|
+ keyword3Map.put("value", (String) userInfo.get("ADDRESS"));
|
|
|
+ data.put("keyword3", keyword3Map);
|
|
|
+
|
|
|
+ // 计算欠费笔数
|
|
|
+ String billMonthsStr = (String) userInfo.get("BLILYEARMONTH");
|
|
|
+ int billCount = billMonthsStr.split("、").length;
|
|
|
+
|
|
|
+ Map<String, String> keyword4Map = new HashMap<>();
|
|
|
+ keyword4Map.put("value", String.valueOf(billCount));
|
|
|
+ data.put("keyword4", keyword4Map);
|
|
|
+
|
|
|
+ Map<String, String> keyword5Map = new HashMap<>();
|
|
|
+ keyword5Map.put("value", userInfo.get("ARR") + "元");
|
|
|
+ data.put("keyword5", keyword5Map);
|
|
|
+
|
|
|
+ Map<String, String> remarkMap = new HashMap<>();
|
|
|
+ remarkMap.put("value", "请您及时缴费,可通过微信公众号进入用水宝小程序缴费,超期将停水。");
|
|
|
+ data.put("remark", remarkMap);
|
|
|
+
|
|
|
+ // 发送模板消息
|
|
|
+ boolean result = WxMessageUtils.sendTemplateMessage(
|
|
|
+ config.getGzhapppid(),
|
|
|
+ config.getGzappsecret(),
|
|
|
+ templateId,
|
|
|
+ openId,
|
|
|
+ data
|
|
|
+ );
|
|
|
+
|
|
|
+ if (result) {
|
|
|
+ successCount++;
|
|
|
+ log.info("成功发送水费缴费通知给用户: {}, 户号: {}", userName, userNumber);
|
|
|
+ } else {
|
|
|
+ failCount++;
|
|
|
+ log.error("发送水费缴费通知给用户 {} ({}) 失败", userName, userNumber);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ failCount++;
|
|
|
+ log.error("发送水费缴费通知给用户 {} ({}) 时发生异常: {}", userName, userNumber, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String message = String.format("水费缴费通知发送完成,成功:%d条,失败:%d条", successCount, failCount);
|
|
|
+ log.info(message);
|
|
|
+ return R.ok(message);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送水费缴费通知失败", e);
|
|
|
+ return R.error("发送水费缴费通知失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|