|
@@ -1,6 +1,7 @@
|
|
|
package com.comtika.ctkcloud.server.service.impl;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
import com.comtika.ctkcloud.common.base.constant.ProjectConstant;
|
|
|
import com.comtika.ctkcloud.server.core.MessageConstant;
|
|
@@ -11,9 +12,9 @@ import com.comtika.ctkcloud.server.core.enums.PhoneSendType;
|
|
|
import com.comtika.ctkcloud.server.dao.EquipTerminalDao;
|
|
|
import com.comtika.ctkcloud.server.dao.SmallMessageDao;
|
|
|
import com.comtika.ctkcloud.server.entity.*;
|
|
|
-import com.comtika.ctkcloud.server.entity.message.CtkMchMessage;
|
|
|
import com.comtika.ctkcloud.server.entity.message.help.MessageHandleHelp;
|
|
|
import com.comtika.ctkcloud.server.entity.message.help.SimpleUserInfoHelp;
|
|
|
+import com.comtika.ctkcloud.server.entity.third.WxOpenType;
|
|
|
import com.comtika.ctkcloud.server.entity.warn.WarnMessageEntity;
|
|
|
import com.comtika.ctkcloud.server.service.SendMessageService;
|
|
|
import net.sf.json.JSONObject;
|
|
@@ -38,16 +39,18 @@ import com.comtika.ctkcloud.server.service.MessageService;
|
|
|
import com.comtika.ctkcloud.server.util.HttpRequest;
|
|
|
import com.comtika.ctkcloud.server.util.MessageDataHandle;
|
|
|
|
|
|
+import javax.persistence.Transient;
|
|
|
+
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class MessageServiceImpl implements MessageService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private MessageHandleUtil messageHandleUtil;
|
|
|
+ @Autowired
|
|
|
+ private MessageHandleUtil messageHandleUtil;
|
|
|
|
|
|
- @Autowired
|
|
|
- private MessageConfig messageConfig;
|
|
|
+ @Autowired
|
|
|
+ private MessageConfig messageConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private MessagePushDao messagePushDao;
|
|
@@ -55,360 +58,380 @@ public class MessageServiceImpl implements MessageService {
|
|
|
/*@Autowired
|
|
|
private ThirdUserDao thirdUserDao;*/
|
|
|
|
|
|
- @Autowired
|
|
|
- private SmallMessageDao smallMessageDao;
|
|
|
- @Autowired
|
|
|
- private MessageCache messageCache;
|
|
|
+ @Autowired
|
|
|
+ private SmallMessageDao smallMessageDao;
|
|
|
+ @Autowired
|
|
|
+ private MessageCache messageCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SendMessageService sendMessageService;
|
|
|
+ @Autowired
|
|
|
+ private EquipTerminalDao equipTerminalDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private SendMessageService sendMessageService;
|
|
|
- @Autowired
|
|
|
- private EquipTerminalDao equipTerminalDao;
|
|
|
/**
|
|
|
- *
|
|
|
- * @Title: pushWxMessage
|
|
|
- * @Description: TODO(微信消息推送 需根据不同模版推送)
|
|
|
* @param order
|
|
|
* @param formId
|
|
|
* @param template
|
|
|
- * @return
|
|
|
- * RespWrapper<String>
|
|
|
+ * @return RespWrapper<String>
|
|
|
* @throws
|
|
|
- * @变更记录 2018年9月12日 下午11:27:31 actor_miss create
|
|
|
+ * @Title: pushWxMessage
|
|
|
+ * @Description: TODO(微信消息推送 需根据不同模版推送)
|
|
|
+ * @变更记录 2018年9月12日 下午11:27:31 actor_miss create
|
|
|
*/
|
|
|
private RespWrapper<String> pushWxMessage(CtkServiceOrder order,
|
|
|
- String formId, String template,String openId,boolean isEnd) {
|
|
|
- try{
|
|
|
- // 这里需要修改下
|
|
|
- String token = messageHandleUtil.getTocken(WXTokenType.XCX);
|
|
|
- if(token == null) {
|
|
|
- System.out.println("获取token 失败");
|
|
|
- return RespWrapper.makeFailResp("获取token");
|
|
|
- }
|
|
|
- return pushWxMessage(order,formId,template,openId,isEnd,token);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeErrorResp("异常:"+e.getMessage());
|
|
|
+ String formId, String template, String openId, boolean isEnd) {
|
|
|
+ try {
|
|
|
+ // 这里需要修改下
|
|
|
+ String token = messageHandleUtil.getTocken(WXTokenType.XCX);
|
|
|
+ if (token == null) {
|
|
|
+ System.out.println("获取token 失败");
|
|
|
+ return RespWrapper.makeFailResp("获取token");
|
|
|
+ }
|
|
|
+ return pushWxMessage(order, formId, template, openId, isEnd, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("异常:" + e.getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
private RespWrapper<String> pushWxMessage(CtkServiceOrder order,
|
|
|
- String formId, String template,String openId,boolean isEnd,String token) {
|
|
|
- try {
|
|
|
- if(StringUtil.isEmpty(openId)){
|
|
|
- openId = messagePushDao.findCustomerById(order.getCustomerId());
|
|
|
- if(StringUtil.isEmpty(openId))return RespWrapper.makeFailResp("根据用户id查询openId失败");
|
|
|
- }
|
|
|
- RespWrapper<String> returnMap = MessageDataHandle.createTempalteReturnMap(order,isEnd,true);
|
|
|
- if(!returnMap.isSuccess()){
|
|
|
- return RespWrapper.makeFailResp(returnMap.getMsg());
|
|
|
+ String formId, String template, String openId, boolean isEnd, String token) {
|
|
|
+ try {
|
|
|
+ if (StringUtil.isEmpty(openId)) {
|
|
|
+ openId = messagePushDao.findCustomerById(order.getCustomerId());
|
|
|
+ if (StringUtil.isEmpty(openId)) return RespWrapper.makeFailResp("根据用户id查询openId失败");
|
|
|
+ }
|
|
|
+ RespWrapper<String> returnMap = MessageDataHandle.createTempalteReturnMap(order, isEnd, true);
|
|
|
+ if (!returnMap.isSuccess()) {
|
|
|
+ return RespWrapper.makeFailResp(returnMap.getMsg());
|
|
|
}
|
|
|
|
|
|
- String json = MessageDataHandle.toJson(true,openId,template,messageConfig.getWxPage(),formId,returnMap.getData());
|
|
|
- JSONObject jsonObject = messageHandleUtil.sendMessage(token,json);
|
|
|
- System.out.println("发送公众号消息结果:"+jsonObject.toString());
|
|
|
+ String json = MessageDataHandle.toJson(true, openId, template, messageConfig.getWxPage(), formId, returnMap.getData());
|
|
|
+ JSONObject jsonObject = messageHandleUtil.sendMessage(token, json);
|
|
|
+ System.out.println("发送公众号消息结果:" + jsonObject.toString());
|
|
|
return RespWrapper.makeSuccessResp(jsonObject.toString());
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeErrorResp("异常:"+e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> sendSubscribeMessageToWeChat(CtkServiceOrder order, Integer type) {
|
|
|
+ SmallMessageHelp help = messagePushDao.findCustomerMessageInfo(order.getCustomerId());
|
|
|
+ if (help == null) return RespWrapper.makeFailResp("根据用户查询基本信息错误");
|
|
|
+ if (help.getLoginType() == 2)
|
|
|
+ return RespWrapper.makeFailResp("暂时不支持支付宝订阅消息");
|
|
|
+ TemplateHelp template = null;
|
|
|
+ switch (type) {
|
|
|
+ case 1:
|
|
|
+ template = messageCache.findTemplateId(help.getAppId(), 3, smallMessageDao);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (template == null) return RespWrapper.makeFailResp("暂时不支持该类型的订阅消息");
|
|
|
+ template.checkSmall(messageConfig);
|
|
|
+ String token = HttpRequest.findSubAccessToken(template.getWxAppId(), template.getSecret());
|
|
|
+ RespWrapper<String> res = sendSubscribeMessageToWeChat(order, template.getTemplate(), help.getOpenId(), type, token);
|
|
|
+ if (res.isSuccess()) return RespWrapper.makeSuccessResp(true);
|
|
|
+ return RespWrapper.makeFailResp(res.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询消息接收人 与处理人
|
|
|
+ // select cs.site_manager site_admin,m.manager_id merchant_admin,m.marketer_id from ctk_site cs LEFT JOIN ctk_merchant_detail m on cs.merchant_id = m.id limit 1
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Map<String, Object>> findMessageAcceptList(Integer siteId) {
|
|
|
+ MessageHandleHelp handleHelp = messagePushDao.findMessageAcceptList(siteId);
|
|
|
+ Integer handleId = handleHelp.getSiteAdmin();
|
|
|
+ if (handleId == null) handleHelp.getMerchantAdmin();
|
|
|
+ List<SimpleUserInfoHelp> list = messagePushDao.findSimpleUserInfo(handleHelp);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("acceptUserList", list);
|
|
|
+ list.forEach(s -> {
|
|
|
+ if (s.getId().intValue() == handleId)
|
|
|
+ map.put("handleUser", s);
|
|
|
+ });
|
|
|
+ return RespWrapper.makeSuccessResp(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<WxOpenType> sendMissTest(Integer id) {
|
|
|
+ return messagePushDao.findWxOpenTypeList(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送订阅消息在微信小陈那个小
|
|
|
+ private RespWrapper<String> sendSubscribeMessageToWeChat(CtkServiceOrder order, String template, String openId, int type, String token) {
|
|
|
+ try {
|
|
|
+ if (StringUtil.isEmpty(openId)) {
|
|
|
+ openId = messagePushDao.findCustomerById(order.getCustomerId());
|
|
|
+ if (StringUtil.isEmpty(openId)) return RespWrapper.makeFailResp("根据用户id查询openId失败");
|
|
|
+ }
|
|
|
+ // 这里需要修改下 使用订单消息模版
|
|
|
+ String dataStr = MessageDataHandle.createSubscribeTemplate(order, type);
|
|
|
+ String json = MessageDataHandle.toJsonInSubscribeWx(openId, template, "pages/subpages/pages/order", dataStr);
|
|
|
+ JSONObject jsonObject = HttpRequest.sendSubMsgNew(token, json);
|
|
|
+ //JSONObject jsonObject = messageHandleUtil.sendMessage(token,json);
|
|
|
+ System.out.println("发送订阅消息结果:" + jsonObject.toString());
|
|
|
+ return RespWrapper.makeSuccessResp(jsonObject.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("异常:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- @Override
|
|
|
- public RespWrapper<Boolean> sendSubscribeMessageToWeChat(CtkServiceOrder order, Integer type) {
|
|
|
- SmallMessageHelp help = messagePushDao.findCustomerMessageInfo(order.getCustomerId());
|
|
|
- if(help == null) return RespWrapper.makeFailResp("根据用户查询基本信息错误");
|
|
|
- if(help.getLoginType() == 2)
|
|
|
- return RespWrapper.makeFailResp("暂时不支持支付宝订阅消息");
|
|
|
- TemplateHelp template = null;
|
|
|
- switch (type){
|
|
|
- case 1:
|
|
|
- template = messageCache.findTemplateId(help.getAppId(),3,smallMessageDao);
|
|
|
- break;
|
|
|
- }
|
|
|
- if(template == null) return RespWrapper.makeFailResp("暂时不支持该类型的订阅消息");
|
|
|
- template.checkSmall(messageConfig);
|
|
|
- String token = HttpRequest.findSubAccessToken(template.getWxAppId(),template.getSecret());
|
|
|
- RespWrapper<String> res = sendSubscribeMessageToWeChat(order,template.getTemplate(),help.getOpenId(),type,token);
|
|
|
- if(res.isSuccess())return RespWrapper.makeSuccessResp(true);
|
|
|
- return RespWrapper.makeFailResp(res.getMsg());
|
|
|
- }
|
|
|
- // 查询消息接收人 与处理人
|
|
|
- // select cs.site_manager site_admin,m.manager_id merchant_admin,m.marketer_id from ctk_site cs LEFT JOIN ctk_merchant_detail m on cs.merchant_id = m.id limit 1
|
|
|
- @Override
|
|
|
- public RespWrapper<Map<String, Object>> findMessageAcceptList(Integer siteId) {
|
|
|
- MessageHandleHelp handleHelp = messagePushDao.findMessageAcceptList(siteId);
|
|
|
- Integer handleId = handleHelp.getSiteAdmin();
|
|
|
- if(handleId == null) handleHelp.getMerchantAdmin();
|
|
|
- List<SimpleUserInfoHelp> list = messagePushDao.findSimpleUserInfo(handleHelp);
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("acceptUserList",list);
|
|
|
- list.forEach(s->{
|
|
|
- if(s.getId().intValue() == handleId)
|
|
|
- map.put("handleUser",s);
|
|
|
- });
|
|
|
- return RespWrapper.makeSuccessResp(map);
|
|
|
- }
|
|
|
-
|
|
|
- // 发送订阅消息在微信小陈那个小
|
|
|
- private RespWrapper<String> sendSubscribeMessageToWeChat(CtkServiceOrder order,String template,String openId,int type,String token){
|
|
|
- try {
|
|
|
- if(StringUtil.isEmpty(openId)){
|
|
|
- openId = messagePushDao.findCustomerById(order.getCustomerId());
|
|
|
- if(StringUtil.isEmpty(openId))return RespWrapper.makeFailResp("根据用户id查询openId失败");
|
|
|
- }
|
|
|
- // 这里需要修改下 使用订单消息模版
|
|
|
- String dataStr = MessageDataHandle.createSubscribeTemplate(order,type);
|
|
|
- String json = MessageDataHandle.toJsonInSubscribeWx(openId,template,"pages/subpages/pages/order",dataStr);
|
|
|
- JSONObject jsonObject = HttpRequest.sendSubMsgNew(token,json);
|
|
|
- //JSONObject jsonObject = messageHandleUtil.sendMessage(token,json);
|
|
|
- System.out.println("发送订阅消息结果:"+jsonObject.toString());
|
|
|
- return RespWrapper.makeSuccessResp(jsonObject.toString());
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeErrorResp("异常:"+e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @Title: pushAliMessage
|
|
|
- * @Description: TODO(支付宝推送消息)
|
|
|
- * @param order
|
|
|
- * @param formId
|
|
|
- * @param template
|
|
|
- * @return
|
|
|
- * RespWrapper<String>
|
|
|
- * @throws
|
|
|
- * @变更记录 2018年9月12日 下午11:25:56 actor_miss create
|
|
|
- */
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param order
|
|
|
+ * @param formId
|
|
|
+ * @param template
|
|
|
+ * @return RespWrapper<String>
|
|
|
+ * @throws
|
|
|
+ * @Title: pushAliMessage
|
|
|
+ * @Description: TODO(支付宝推送消息)
|
|
|
+ * @变更记录 2018年9月12日 下午11:25:56 actor_miss create
|
|
|
+ */
|
|
|
private RespWrapper<String> pushAliMessage(CtkServiceOrder order,
|
|
|
- String formId, String template,String openId) {
|
|
|
- try {
|
|
|
- /**
|
|
|
- * 先检验测试数据
|
|
|
- */
|
|
|
- List<String> list = new ArrayList<String>();
|
|
|
- if(order.getEquipSocketId() == null){
|
|
|
- return RespWrapper.makeFailResp("插座编号不能为空");
|
|
|
- }
|
|
|
- if(order.getStartTime() == null){
|
|
|
- return RespWrapper.makeFailResp("充电开始时间不能为空");
|
|
|
- }
|
|
|
- if(order.getSocketSeq() == null){
|
|
|
- return RespWrapper.makeFailResp("设备流水号不能为空");
|
|
|
- }
|
|
|
- if(StringUtil.isEmpty(openId)){
|
|
|
- openId = messagePushDao.findCustomerById(order.getCustomerId());
|
|
|
- if(StringUtil.isEmpty(openId)){
|
|
|
- return RespWrapper.makeFailResp("根据用户id查询openId失败");
|
|
|
- }
|
|
|
- }
|
|
|
- String socketSeq = order.getSocketSeq();
|
|
|
-
|
|
|
- list.add(socketSeq.substring(socketSeq.length()-2));//插座
|
|
|
- list.add(DateTimeUtils.formatDate(new Date(order.getStartTime()), DateTimeUtils.FORMAT));
|
|
|
- list.add(MessageDataHandle.orderNoDateAdjust(StringUtil.convertInt(order.getActChargerTime()+"", 0)));
|
|
|
- list.add(StringUtil.convertInt(order.getTotalFee()+"", 0)*1.0/100+"元");
|
|
|
- list.add(StringUtil.convertInt(order.getTotalCharge()+"", 0)*1.0/100+"度");
|
|
|
- list.add(StringUtil.convertString(order.getOrderRes(), "异常结束"));
|
|
|
- list.add(socketSeq);
|
|
|
-
|
|
|
- AlipayClient alipayClient =new DefaultAlipayClient(messageConfig.getOppenUrl(),messageConfig.getAliAppid(),messageConfig.getPrivateKey(),"json","UTF-8",messageConfig.getPublicKey(),"RSA2");
|
|
|
- AlipayOpenAppMiniTemplatemessageSendRequest request =new AlipayOpenAppMiniTemplatemessageSendRequest();
|
|
|
- //下面ok
|
|
|
+ String formId, String template, String openId) {
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 先检验测试数据
|
|
|
+ */
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ if (order.getEquipSocketId() == null) {
|
|
|
+ return RespWrapper.makeFailResp("插座编号不能为空");
|
|
|
+ }
|
|
|
+ if (order.getStartTime() == null) {
|
|
|
+ return RespWrapper.makeFailResp("充电开始时间不能为空");
|
|
|
+ }
|
|
|
+ if (order.getSocketSeq() == null) {
|
|
|
+ return RespWrapper.makeFailResp("设备流水号不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtil.isEmpty(openId)) {
|
|
|
+ openId = messagePushDao.findCustomerById(order.getCustomerId());
|
|
|
+ if (StringUtil.isEmpty(openId)) {
|
|
|
+ return RespWrapper.makeFailResp("根据用户id查询openId失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String socketSeq = order.getSocketSeq();
|
|
|
+
|
|
|
+ list.add(socketSeq.substring(socketSeq.length() - 2));//插座
|
|
|
+ list.add(DateTimeUtils.formatDate(new Date(order.getStartTime()), DateTimeUtils.FORMAT));
|
|
|
+ list.add(MessageDataHandle.orderNoDateAdjust(StringUtil.convertInt(order.getActChargerTime() + "", 0)));
|
|
|
+ list.add(StringUtil.convertInt(order.getTotalFee() + "", 0) * 1.0 / 100 + "元");
|
|
|
+ list.add(StringUtil.convertInt(order.getTotalCharge() + "", 0) * 1.0 / 100 + "度");
|
|
|
+ list.add(StringUtil.convertString(order.getOrderRes(), "异常结束"));
|
|
|
+ list.add(socketSeq);
|
|
|
+
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient(messageConfig.getOppenUrl(), messageConfig.getAliAppid(), messageConfig.getPrivateKey(), "json", "UTF-8", messageConfig.getPublicKey(), "RSA2");
|
|
|
+ AlipayOpenAppMiniTemplatemessageSendRequest request = new AlipayOpenAppMiniTemplatemessageSendRequest();
|
|
|
+ //下面ok
|
|
|
/*request.setBizContent("{"+
|
|
|
"\"to_user_id\":\""+OPEN_ID+"\","+
|
|
|
"\"form_id\":\""+formId+"\","+
|
|
|
"\"user_template_id\":\""+template.getTemplateId()+"\","+
|
|
|
"\"page\":\""+messageConfig.getAliPage()+"\","+
|
|
|
"\"data\":\""+MessageDataHandle.createTemplateMessage(list,false)+"\"}");*/
|
|
|
- String data = MessageDataHandle.createTemplateMessage(list,false,false);
|
|
|
- request.setBizContent(MessageDataHandle.toJson(false, openId,formId,template,messageConfig.getAliPage(),data));
|
|
|
- AlipayOpenAppMiniTemplatemessageSendResponse response = alipayClient.execute(request);
|
|
|
- if(response.isSuccess()){
|
|
|
- return RespWrapper.makeSuccessResp("发生成功");
|
|
|
- }else{
|
|
|
- System.out.println("如果发送失败:"+response.getMsg());
|
|
|
- }
|
|
|
- return RespWrapper.makeFailResp(response.getMsg());
|
|
|
+ String data = MessageDataHandle.createTemplateMessage(list, false, false);
|
|
|
+ request.setBizContent(MessageDataHandle.toJson(false, openId, formId, template, messageConfig.getAliPage(), data));
|
|
|
+ AlipayOpenAppMiniTemplatemessageSendResponse response = alipayClient.execute(request);
|
|
|
+ if (response.isSuccess()) {
|
|
|
+ return RespWrapper.makeSuccessResp("发生成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("如果发送失败:" + response.getMsg());
|
|
|
+ }
|
|
|
+ return RespWrapper.makeFailResp(response.getMsg());
|
|
|
} catch (AlipayApiException e) {
|
|
|
e.printStackTrace();
|
|
|
- return RespWrapper.makeErrorResp("异常:"+e.getMessage());
|
|
|
+ return RespWrapper.makeErrorResp("异常:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
- @Override
|
|
|
- public RespWrapper<String> fadPushChargerMessage(CtkServiceOrder order, String formId) {
|
|
|
- // 这里根据用户唯一小程序用户唯一id 查询是哪个模块的
|
|
|
- SmallMessageHelp help = messagePushDao.findCustomerMessageInfo(order.getCustomerId());
|
|
|
- if(help == null) return RespWrapper.makeFailResp("根据用户查询基本信息错误");
|
|
|
- TemplateHelp template = messageCache.findTemplateId(help.getAppId(),help.getLoginType(),smallMessageDao);
|
|
|
- template.checkSmall(messageConfig);
|
|
|
- if(help.getLoginType() == 2){
|
|
|
- return pushAliMessage(order,formId,template.getTemplate(),help.getOpenId());
|
|
|
- // 支付宝
|
|
|
- }
|
|
|
- String token = messageHandleUtil.getTocken(template);
|
|
|
- if(token == null){
|
|
|
- System.out.println("获取微信token 失败");
|
|
|
- return RespWrapper.makeFailResp("获取微信token");
|
|
|
- }
|
|
|
- // 微信
|
|
|
- return pushWxMessage(order,formId,template.getTemplate(),help.getOpenId(),true,token);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public RespWrapper<String> pushChargerMessage(CtkServiceOrder order,
|
|
|
- String formId, MessageTemplateType template,String openId) {
|
|
|
- try {
|
|
|
- if(template.getTemplateType() == 1){
|
|
|
- return pushAliMessage(order,formId,template.getTemplateId(),openId);
|
|
|
- }else if(template.getTemplateType() == 2){
|
|
|
- return pushWxMessage(order,formId,template.getTemplateId(),openId,template == MessageTemplateType.WX_CHAGER_END);
|
|
|
- }
|
|
|
- return RespWrapper.makeFailResp("没有对应的模版");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeErrorResp("异常:"+e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- private static final String TMP_TOUSER = "WARN_TOUSER";
|
|
|
- /**公众号消息推送*/
|
|
|
- @Override
|
|
|
- public RespWrapper<Boolean> publicNumberMessagePush(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy) {
|
|
|
- try{
|
|
|
- return publicMessageGZH(users,template,warnEntiy,false);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeFailResp("异常:"+e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- private static final String ONE_TO_FOUR = "0014";
|
|
|
- @Override
|
|
|
- public RespWrapper<Boolean> sendWarnMessageToManage(CtkServiceOrder order) {
|
|
|
- String socketNo = order.getSocketSeq();
|
|
|
- if(StringUtil.isEmpty(socketNo)) return RespWrapper.makeFailResp("设备唯一id 不能为空");
|
|
|
- //TODO
|
|
|
- TerminalBase help = messagePushDao.findMerchantConfigBase(socketNo);
|
|
|
- if(help == null) return RespWrapper.makeFailResp("查询充电数据错误");
|
|
|
- CtkManageHelp siteHelp = equipTerminalDao.findSiteAdminAction(order.getSiteId());
|
|
|
-
|
|
|
- WarnMessageEntity entity = new WarnMessageEntity();
|
|
|
- entity.setSerialNo(socketNo);
|
|
|
- entity.setSiteName(siteHelp.getName());
|
|
|
- entity.setStartTime(System.currentTimeMillis());
|
|
|
- entity.setTerminalNo(help.getTerminalNo());
|
|
|
- entity.setWarnLevl(2);
|
|
|
- entity.setWarnType("断网或断电结束充电");
|
|
|
- if(help.getTerminalNo().startsWith(ONE_TO_FOUR)){
|
|
|
- entity.setEquipName("1拖四电单车交流");
|
|
|
- }else entity.setEquipName("16路电单车交流");
|
|
|
- List<Integer> users = new ArrayList<>(4);
|
|
|
- CtkManageHelp mchHelp = equipTerminalDao.findMerchantAdmin(order.getMerchantId().intValue());
|
|
|
- if(siteHelp.getAdminId() != null)
|
|
|
- users.add(siteHelp.getAdminId());
|
|
|
- if(mchHelp.getAdminId() != null)
|
|
|
- users.add(mchHelp.getAdminId());
|
|
|
- if(mchHelp.getMarketerId() != null)
|
|
|
- users.add(mchHelp.getMarketerId());
|
|
|
- try {
|
|
|
- return publicMessageGZH(users,MessageTemplateType.WX_WARN_PUBLIC_NUMBER,entity,true,"设备断网或断电结束充电,请检查设备!");
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeFailResp("异常:"+e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- @Override
|
|
|
- public void fadSendWarnMessageToManage(String terminalNo){
|
|
|
- // 这里需要处理下是否发生断电、断网消息
|
|
|
- FadTerminalWarn warn = messagePushDao.findFadTerminalWarn(terminalNo);
|
|
|
- // 商户没有配置时不提供断电、断网消息
|
|
|
- CtkMchMessage mchMessage = messagePushDao.findMchMessageConfig(warn.getMerchantId());
|
|
|
- if(mchMessage == null || !mchMessage.getWarn())
|
|
|
- return;
|
|
|
- WarnMessageEntity entity = new WarnMessageEntity();
|
|
|
- entity.setSerialNo("设备编号["+terminalNo+"]");
|
|
|
- entity.setSiteName(warn.getSiteName());
|
|
|
- entity.setStartTime(System.currentTimeMillis());
|
|
|
- entity.setTerminalNo(terminalNo);
|
|
|
- entity.setWarnLevl(2);
|
|
|
- entity.setWarnType("断网或断电");
|
|
|
- warn.check();
|
|
|
- // TODO
|
|
|
- // entity.setEquipName(warn.getEquipType() == null || warn.getEquipType() == 16?"16路电单车交流":"1拖四电单车交流");
|
|
|
- if(terminalNo.startsWith(ONE_TO_FOUR)){
|
|
|
- entity.setEquipName("1拖四电单车交流");
|
|
|
- }else entity.setEquipName("16路电单车交流");
|
|
|
- List<Integer> users = new ArrayList<>(4);
|
|
|
- CtkManageHelp mchHelp = equipTerminalDao.findMerchantAdmin(warn.getMerchantId());
|
|
|
- if(warn.getAdminId() != null)
|
|
|
- users.add(warn.getAdminId());
|
|
|
- if(mchHelp.getAdminId() != null)
|
|
|
- users.add(mchHelp.getAdminId());
|
|
|
- if(mchHelp.getMarketerId() != null)
|
|
|
- users.add(mchHelp.getMarketerId());
|
|
|
- try {
|
|
|
- publicMessageGZH(users,MessageTemplateType.WX_WARN_PUBLIC_NUMBER,entity,true,"设备发送断网或断电,请检查设备!");
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public RespWrapper<Boolean> autoHandleWarnPublicMessage(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy) {
|
|
|
- try {
|
|
|
- return publicMessageGZH(users,template,warnEntiy,true);
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- return RespWrapper.makeFailResp(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**公众号消息推送*/
|
|
|
- private RespWrapper<Boolean> publicMessageGZH(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy,boolean isAuto,String msg)throws Exception{
|
|
|
- int size = users.size();
|
|
|
- if(size < 0 ) return RespWrapper.makeFailResp("发送消息到用户唯一标识不能为空");
|
|
|
- //组装数据
|
|
|
- RespWrapper<String> data = MessageDataHandle.createWarnMessage(warnEntiy,isAuto,msg);
|
|
|
- if(!data.isSuccess()) return RespWrapper.makeFailResp(data.getMsg());
|
|
|
- //回调地址
|
|
|
- String json = MessageDataHandle.toJsonPN(TMP_TOUSER, template.getTemplateId(), data.getData());
|
|
|
- //下面通过用户id 查询 用户微信公众号oppenId 与 用户登入名
|
|
|
- UserThirdBaseHelp help;
|
|
|
- for(int i=0;i<size;i++){
|
|
|
- help = messagePushDao.findUserBaseInfo(users.get(i));
|
|
|
- if (StringUtil.isNotEmpty(help.getWechatPnOppenId())){
|
|
|
- String replace = json.replace(TMP_TOUSER, help.getWechatPnOppenId());
|
|
|
- Optional.ofNullable(messageHandleUtil.getTocken(WXTokenType.GZH)).ifPresent(p->{
|
|
|
- messageHandleUtil.sendMessagePublicNumber(p, replace);
|
|
|
- });
|
|
|
- }
|
|
|
- //自动处理告警(不发送手机短信)
|
|
|
- if(!isAuto || StringUtil.isNotEmpty(msg)){
|
|
|
- if(MessageConstant.PATTERN_MOBILE.matcher(help.getPhoneNo()).matches() && StringUtil.isNotEmpty(help.getPhoneNo()) && !ProjectConstant.ADMIN.equals(help.getPhoneNo())){
|
|
|
- sendMessageService.send(help.getPhoneNo(), PhoneSendType.WARN,warnEntiy);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return RespWrapper.makeSuccessResp(true);
|
|
|
- }
|
|
|
-
|
|
|
- private RespWrapper<Boolean> publicMessageGZH(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy,boolean isAuto)throws Exception{
|
|
|
- return publicMessageGZH(users,template,warnEntiy,isAuto,null);
|
|
|
- }
|
|
|
- public static void main(String[] args){
|
|
|
- System.out.println(MessageConstant.PATTERN_MOBILE.matcher("12588458430").matches());
|
|
|
- String key = null;
|
|
|
- Optional.ofNullable(key).ifPresent(s->{
|
|
|
- System.out.println(1);
|
|
|
- System.out.println(s);
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<String> fadPushChargerMessage(CtkServiceOrder order, String formId) {
|
|
|
+ // 这里根据用户唯一小程序用户唯一id 查询是哪个模块的
|
|
|
+ SmallMessageHelp help = messagePushDao.findCustomerMessageInfo(order.getCustomerId());
|
|
|
+ if (help == null) return RespWrapper.makeFailResp("根据用户查询基本信息错误");
|
|
|
+ TemplateHelp template = messageCache.findTemplateId(help.getAppId(), help.getLoginType(), smallMessageDao);
|
|
|
+ template.checkSmall(messageConfig);
|
|
|
+ if (help.getLoginType() == 2) {
|
|
|
+ return pushAliMessage(order, formId, template.getTemplate(), help.getOpenId());
|
|
|
+ // 支付宝
|
|
|
+ }
|
|
|
+ String token = messageHandleUtil.getTocken(template);
|
|
|
+ if (token == null) {
|
|
|
+ System.out.println("获取微信token 失败");
|
|
|
+ return RespWrapper.makeFailResp("获取微信token");
|
|
|
+ }
|
|
|
+ // 微信
|
|
|
+ return pushWxMessage(order, formId, template.getTemplate(), help.getOpenId(), true, token);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<String> pushChargerMessage(CtkServiceOrder order,
|
|
|
+ String formId, MessageTemplateType template, String openId) {
|
|
|
+ try {
|
|
|
+ if (template.getTemplateType() == 1) {
|
|
|
+ return pushAliMessage(order, formId, template.getTemplateId(), openId);
|
|
|
+ } else if (template.getTemplateType() == 2) {
|
|
|
+ return pushWxMessage(order, formId, template.getTemplateId(), openId, template == MessageTemplateType.WX_CHAGER_END);
|
|
|
+ }
|
|
|
+ return RespWrapper.makeFailResp("没有对应的模版");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeErrorResp("异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String TMP_TOUSER = "WARN_TOUSER";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公众号消息推送
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> publicNumberMessagePush(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy) {
|
|
|
+ try {
|
|
|
+ return publicMessageGZH(users, template, warnEntiy, false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeFailResp("异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String ONE_TO_FOUR = "0014";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> sendWarnMessageToManage(CtkServiceOrder order) {
|
|
|
+ String socketNo = order.getSocketSeq();
|
|
|
+ if (StringUtil.isEmpty(socketNo)) return RespWrapper.makeFailResp("设备唯一id 不能为空");
|
|
|
+ //TODO
|
|
|
+ TerminalBase help = messagePushDao.findMerchantConfigBase(socketNo);
|
|
|
+ if (help == null) return RespWrapper.makeFailResp("查询充电数据错误");
|
|
|
+ CtkManageHelp siteHelp = equipTerminalDao.findSiteAdminAction(order.getSiteId());
|
|
|
+
|
|
|
+ WarnMessageEntity entity = new WarnMessageEntity();
|
|
|
+ entity.setSerialNo(socketNo);
|
|
|
+ entity.setSiteName(siteHelp.getName());
|
|
|
+ entity.setStartTime(System.currentTimeMillis());
|
|
|
+ entity.setTerminalNo(help.getTerminalNo());
|
|
|
+ entity.setWarnLevl(2);
|
|
|
+ entity.setWarnType("断网或断电结束充电");
|
|
|
+ if (help.getTerminalNo().startsWith(ONE_TO_FOUR)) {
|
|
|
+ entity.setEquipName("1拖四电单车交流");
|
|
|
+ } else entity.setEquipName("16路电单车交流");
|
|
|
+ List<Integer> users = new ArrayList<>(4);
|
|
|
+ CtkManageHelp mchHelp = equipTerminalDao.findMerchantAdmin(order.getMerchantId().intValue());
|
|
|
+ if (siteHelp.getAdminId() != null)
|
|
|
+ users.add(siteHelp.getAdminId());
|
|
|
+ if (mchHelp.getAdminId() != null)
|
|
|
+ users.add(mchHelp.getAdminId());
|
|
|
+ if (mchHelp.getMarketerId() != null)
|
|
|
+ users.add(mchHelp.getMarketerId());
|
|
|
+ try {
|
|
|
+ return publicMessageGZH(users, MessageTemplateType.WX_WARN_PUBLIC_NUMBER, entity, true, "设备断网或断电结束充电,请检查设备!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeFailResp("异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void fadSendWarnMessageToManage(String terminalNo) {
|
|
|
+ FadTerminalWarn warn = messagePushDao.findFadTerminalWarn(terminalNo);
|
|
|
+ if(warn == null || warn.getMerchantId() == null){
|
|
|
+ System.out.println("告警消息有误,设备编号:"+terminalNo);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ WarnMessageEntity entity = new WarnMessageEntity();
|
|
|
+ entity.setSerialNo("设备编号[" + terminalNo + "]");
|
|
|
+ entity.setSiteName(warn.getSiteName());
|
|
|
+ entity.setStartTime(System.currentTimeMillis());
|
|
|
+ entity.setTerminalNo(terminalNo);
|
|
|
+ entity.setWarnLevl(2);
|
|
|
+ entity.setWarnType("断网或断电");
|
|
|
+ warn.check();
|
|
|
+ // TODO
|
|
|
+ // entity.setEquipName(warn.getEquipType() == null || warn.getEquipType() == 16?"16路电单车交流":"1拖四电单车交流");
|
|
|
+ if (terminalNo.startsWith(ONE_TO_FOUR)) {
|
|
|
+ entity.setEquipName("1拖四电单车交流");
|
|
|
+ } else entity.setEquipName("16路电单车交流");
|
|
|
+ List<Integer> users = new ArrayList<>(4);
|
|
|
+ CtkManageHelp mchHelp = equipTerminalDao.findMerchantAdmin(warn.getMerchantId());
|
|
|
+ if (warn.getAdminId() != null)
|
|
|
+ users.add(warn.getAdminId());
|
|
|
+ if (mchHelp.getAdminId() != null)
|
|
|
+ users.add(mchHelp.getAdminId());
|
|
|
+ if (mchHelp.getMarketerId() != null)
|
|
|
+ users.add(mchHelp.getMarketerId());
|
|
|
+ try {
|
|
|
+ publicMessageGZH(users, MessageTemplateType.WX_WARN_PUBLIC_NUMBER, entity, true, "设备发送断网或断电,请检查设备!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RespWrapper<Boolean> autoHandleWarnPublicMessage(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy) {
|
|
|
+ try {
|
|
|
+ return publicMessageGZH(users, template, warnEntiy, true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return RespWrapper.makeFailResp(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公众号消息推送
|
|
|
+ */
|
|
|
+ private RespWrapper<Boolean> publicMessageGZH(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy, boolean isAuto, String msg) throws Exception {
|
|
|
+ int size = users.size();
|
|
|
+ if (size < 0) return RespWrapper.makeFailResp("发送消息到用户唯一标识不能为空");
|
|
|
+ //组装数据
|
|
|
+ RespWrapper<String> data = MessageDataHandle.createWarnMessage(warnEntiy, isAuto, msg);
|
|
|
+ if (!data.isSuccess()) return RespWrapper.makeFailResp(data.getMsg());
|
|
|
+ //下面通过用户id 查询 用户微信公众号oppenId 与 用户登入名
|
|
|
+ String phoneNo;
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ phoneNo = messagePushDao.findUserPhoneNo(users.get(i));
|
|
|
+ doSendWeChatOpenMessage(users.get(i),data.getData());
|
|
|
+ //自动处理告警(不发送手机短信)
|
|
|
+ if (!isAuto || StringUtil.isNotEmpty(msg)) {
|
|
|
+ if (StringUtil.isNotEmpty(phoneNo) && MessageConstant.PATTERN_MOBILE.matcher(phoneNo).matches()) {
|
|
|
+ sendMessageService.send(phoneNo, PhoneSendType.WARN, warnEntiy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return RespWrapper.makeSuccessResp(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送公众号模版消息
|
|
|
+ private void doSendWeChatOpenMessage(Integer userId, String data) {
|
|
|
+ try {
|
|
|
+ // 增加消息回调地址
|
|
|
+ List<WxOpenType> list = messagePushDao.findWxOpenTypeList(userId);
|
|
|
+ list.forEach(s->{
|
|
|
+ String openId = s.getOpenId();
|
|
|
+ if(openId != null){
|
|
|
+ String token = messageHandleUtil.getWeChatOpenToken(s);
|
|
|
+ Optional.ofNullable(token).ifPresent(p -> {
|
|
|
+ //回调地址
|
|
|
+ String replace = MessageDataHandle.toJsonPN(s.getNotifyUrl(),openId, s.getTemplateId(), data);
|
|
|
+ messageHandleUtil.sendMessagePublicNumber(p, replace);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ list.clear();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private RespWrapper<Boolean> publicMessageGZH(List<Integer> users, MessageTemplateType template, WarnMessageEntity warnEntiy, boolean isAuto) throws Exception {
|
|
|
+ return publicMessageGZH(users, template, warnEntiy, isAuto, null);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|