|
@@ -1,23 +1,28 @@
|
|
|
package com.rongwei.zhsw.system.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.rongwe.zhsw.system.domain.SwEnterpriseConfigInfoDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwNoticeRecordDo;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.zhsw.system.dao.SwBillManagementUnpaidDao;
|
|
|
-import com.rongwei.zhsw.system.dao.SwEnterpriseConfigInfoDao;
|
|
|
+import com.rongwei.zhsw.system.dao.SwNoticeRecordDao;
|
|
|
import com.rongwei.zhsw.system.service.impl.SwEnterpriseConfigInfoServiceImpl;
|
|
|
+import com.rongwei.zhsw.system.service.impl.SwNoticeRecordServiceImpl;
|
|
|
import com.rongwei.zhsw.system.utils.WxMessageUtils;
|
|
|
-import com.rongwe.zhsw.system.domain.SwEnterpriseConfigInfoDo;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Arrays;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Slf4j
|
|
|
@RestController
|
|
@@ -28,6 +33,8 @@ public class WeChatOfficialController {
|
|
|
|
|
|
@Autowired
|
|
|
private SwBillManagementUnpaidDao swBillManagementUnpaidDao;
|
|
|
+ @Autowired
|
|
|
+ private SwNoticeRecordServiceImpl swNoticeRecordService;
|
|
|
|
|
|
@PostMapping("/sendRepairMessage")
|
|
|
public R sendRepairMessage(@RequestBody Map<String, Object> dataInfo) {
|
|
@@ -43,7 +50,7 @@ public class WeChatOfficialController {
|
|
|
Map<String, String> receiverRoleMap = (Map<String, String>) dataInfo.get("receiverrole");
|
|
|
|
|
|
if (mbtypeMap == null || !mbtypeMap.containsKey("value") ||
|
|
|
- receiverRoleMap == null || !receiverRoleMap.containsKey("value")) {
|
|
|
+ receiverRoleMap == null || !receiverRoleMap.containsKey("value")) {
|
|
|
return R.error("请求参数格式不正确");
|
|
|
}
|
|
|
|
|
@@ -77,28 +84,28 @@ public class WeChatOfficialController {
|
|
|
Map<String, String> firstMap = new HashMap<>();
|
|
|
firstMap.put("value", ((Map<String, String>) dataInfo.get("first")).get("value"));
|
|
|
data.put("first", firstMap);
|
|
|
-
|
|
|
+
|
|
|
// 新模板字段
|
|
|
Map<String, String> thing5Map = new HashMap<>();
|
|
|
thing5Map.put("value", ((Map<String, String>) dataInfo.get("thing5")).get("value"));
|
|
|
data.put("thing5", thing5Map);
|
|
|
-
|
|
|
+
|
|
|
Map<String, String> phoneNumber6Map = new HashMap<>();
|
|
|
phoneNumber6Map.put("value", ((Map<String, String>) dataInfo.get("phone_number6")).get("value"));
|
|
|
data.put("phone_number6", phoneNumber6Map);
|
|
|
-
|
|
|
+
|
|
|
Map<String, String> thing4Map = new HashMap<>();
|
|
|
thing4Map.put("value", ((Map<String, String>) dataInfo.get("thing4")).get("value"));
|
|
|
data.put("thing4", thing4Map);
|
|
|
-
|
|
|
+
|
|
|
Map<String, String> time27Map = new HashMap<>();
|
|
|
time27Map.put("value", ((Map<String, String>) dataInfo.get("time27")).get("value"));
|
|
|
data.put("time27", time27Map);
|
|
|
-
|
|
|
+
|
|
|
Map<String, String> thing11Map = new HashMap<>();
|
|
|
thing11Map.put("value", ((Map<String, String>) dataInfo.get("thing11")).get("value"));
|
|
|
data.put("thing11", thing11Map);
|
|
|
-
|
|
|
+
|
|
|
Map<String, String> remarkMap = new HashMap<>();
|
|
|
remarkMap.put("value", "请尽快处理!");
|
|
|
data.put("remark", remarkMap);
|
|
@@ -183,7 +190,10 @@ public class WeChatOfficialController {
|
|
|
return R.error("未找到企业配置信息");
|
|
|
}
|
|
|
log.info("企业配置信息: {}", config);
|
|
|
-
|
|
|
+ String selectIds = (String) dataInfo.getOrDefault("selectId", "");
|
|
|
+ if (StringUtils.isBlank(selectIds)) {
|
|
|
+ throw new CustomException("参数异常,为选择数据");
|
|
|
+ }
|
|
|
// 获取模板ID
|
|
|
JSONObject templateConfig = JSON.parseObject(config.getTemplateconfiguration());
|
|
|
|
|
@@ -201,18 +211,21 @@ public class WeChatOfficialController {
|
|
|
if (!"cstz".equals(mbtype)) {
|
|
|
return R.error("不支持的模板类型");
|
|
|
}
|
|
|
-
|
|
|
+ List<String> ids = Arrays.asList(selectIds.split(","));
|
|
|
// 查询欠费用户信息
|
|
|
- List<Map<String, Object>> arrearsInfoList = swBillManagementUnpaidDao.getWaterFeeArrearsInfo();
|
|
|
+ List<Map<String, Object>> arrearsInfoList = swBillManagementUnpaidDao.getWaterFeeArrearsInfo(ids);
|
|
|
if (arrearsInfoList == null || arrearsInfoList.isEmpty()) {
|
|
|
return R.error("未找到欠费用户信息");
|
|
|
}
|
|
|
|
|
|
int successCount = 0;
|
|
|
int failCount = 0;
|
|
|
-
|
|
|
+ List<SwNoticeRecordDo> saveDataList = new ArrayList<>();
|
|
|
+ SwNoticeRecordDo swNoticeRecordDo = null;
|
|
|
+ SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
// 循环发送消息给每个欠费用户
|
|
|
for (Map<String, Object> userInfo : arrearsInfoList) {
|
|
|
+
|
|
|
String userNumber = String.valueOf(userInfo.get("USERNUMBER"));
|
|
|
String userName = String.valueOf(userInfo.get("USERNAME"));
|
|
|
|
|
@@ -271,7 +284,8 @@ public class WeChatOfficialController {
|
|
|
openId,
|
|
|
data
|
|
|
);
|
|
|
-
|
|
|
+ // 记录推送记录
|
|
|
+ saveDataList.add(createNoticeRecord(swNoticeRecordDo, currentUser, result, data, templateId, userNumber, openId));
|
|
|
if (result) {
|
|
|
successCount++;
|
|
|
log.info("成功发送水费缴费通知给用户: {}, 户号: {}", userName, userNumber);
|
|
@@ -284,7 +298,7 @@ public class WeChatOfficialController {
|
|
|
log.error("发送水费缴费通知给用户 {} ({}) 时发生异常: {}", userName, userNumber, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ swNoticeRecordService.saveBatch(saveDataList,2000);
|
|
|
String message = String.format("水费缴费通知发送完成,成功:%d条,失败:%d条", successCount, failCount);
|
|
|
log.info(message);
|
|
|
return R.ok(message);
|
|
@@ -294,4 +308,19 @@ public class WeChatOfficialController {
|
|
|
return R.error("发送水费缴费通知失败:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public SwNoticeRecordDo createNoticeRecord(SwNoticeRecordDo swNoticeRecordDo, SysUserVo currentUser, boolean result,
|
|
|
+ Map<String, Object> tempData, String tempId, String userNum, String sign) {
|
|
|
+ swNoticeRecordDo = new SwNoticeRecordDo();
|
|
|
+ ZHSWCommonUtils.initModelGeneralParameters(swNoticeRecordDo, currentUser);
|
|
|
+ swNoticeRecordDo.setId(SecurityUtil.getUUID());
|
|
|
+
|
|
|
+ swNoticeRecordDo.setUsernum(userNum);
|
|
|
+ tempData.put("tempId", tempId);
|
|
|
+ swNoticeRecordDo.setNoticepara(tempData.toString());
|
|
|
+ swNoticeRecordDo.setNoticetime(new Date());
|
|
|
+ swNoticeRecordDo.setNoticestate(String.valueOf(result));
|
|
|
+ swNoticeRecordDo.setNoticesign(sign);
|
|
|
+ return swNoticeRecordDo;
|
|
|
+ }
|
|
|
}
|