Commit 5103f830 authored by Shen's avatar Shen

1. 推送时间问题修复

2. 机构PC端添加微信公众号信息配置
2. 机构PC端派单添加消息推送
parent 45b721e1
package io.hmit.common.config;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
/**
* @Description :
* @Author : Shen Yuanfeng
* @Date: 2021/3/12 16:03
*/
@Component
public class WeChatMpConfig {
@Autowired
private WechatAccountConfig wechatAccountConfig;
@Bean
public WxMpService wxMpService(){
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
return wxMpService;
}
@Bean
public WxMpConfigStorage wxMpConfigStorage(){
WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
wxMpConfigStorage.setAppId(wechatAccountConfig.getMpAppId());
wxMpConfigStorage.setSecret(wechatAccountConfig.getMpAppSecret());
return wxMpConfigStorage;
}
}
package io.hmit.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Description :
* @Author : Shen Yuanfeng
* @Date: 2021/3/12 16:02
*/
@Data
@Component
@ConfigurationProperties(prefix = "wechat")
public class WechatAccountConfig {
private String mpAppId;
private String mpAppSecret;
private String userTemplateId;
private String serviceTemplateId;
}
......@@ -14,6 +14,7 @@ import io.hmit.modules.serviceOrder.service.PensionOrderService;
import io.hmit.modules.serviceOrder.service.PensionOrderServiceService;
import io.hmit.modules.serviceOrder.service.PensionOrganizationService;
import io.hmit.modules.serviceOrder.service.UserService;
import io.hmit.modules.sys.service.PushMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -46,6 +47,9 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
@Autowired
private UserService userService;
@Autowired
private PushMessage pushMessage;
@Override
public QueryWrapper<PensionOrderEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get("id");
......@@ -98,10 +102,6 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
if (pensionOrderEntity.getStatus() == 0) {
pensionOrderEntity.setStatus(5);
pensionOrderEntity.setStatusName(Constant.OrderStatus.HAND_OUT.getMessage());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
pensionOrderEntity.setAppointmentTime(sdf.parse(params.get("appointmentTime").toString()));
}catch (Exception ignored){}
update(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class));
}else {
return false;
......@@ -117,6 +117,8 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
pensionOrderEntity.setOrderRecipientPhone(recipient.getMobile());
pensionOrderEntity.setOrderRecipientTime(new Date());
update(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class));
pushMessage.sendServiceWeChatMsg(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class), recipient.getOpenid());
pushMessage.sendWeChatMsg(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class), userService.getUserByUserId(pensionOrderEntity.getCreator()).getOpenid(), "oldman");
}else {
return false;
}
......
package io.hmit.modules.sys.service;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
/**
* @Description : TODO
* @Author : Shen Yuanfeng
* @Date : 2021/5/17 13:33
*/
public interface PushMessage {
void sendWeChatMsg(PensionOrderDTO pensionOrderDTO, String openId, String flag);
void sendServiceWeChatMsg(PensionOrderDTO pensionOrderDTO, String openId);
}
package io.hmit.modules.sys.service.impl;
import io.hmit.modules.serviceOrder.dto.PensionOrderDTO;
import io.hmit.modules.sys.service.PushMessage;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
/**
* @Description : TODO
* @Author : Shen Yuanfeng
* @Date : 2021/5/17 13:37
*/
@Slf4j
@Service
public class PushMessageImpl implements PushMessage {
@Value("${wechat.serviceTemplateId}")
private String WECHAT_SERVICE_TP;
@Value("${wechat.userTemplateId}")
private String WECHAT_USER_TP;
@Value("${SYSURL.url}")
private String SYSURL;
@Autowired
private WxMpService wxMpService;
@Override
public void sendWeChatMsg(PensionOrderDTO pensionOrderDTO, String openId, String flag) {
WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
templateMessage.setTemplateId(WECHAT_USER_TP);
templateMessage.setToUser(openId);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String appointmentTime = "待分配";
if (null != pensionOrderDTO.getAppointmentTime()) {
appointmentTime = sdf.format(pensionOrderDTO.getAppointmentTime());
}
List<WxMpTemplateData> data = Arrays.asList(
new WxMpTemplateData("first", "【智慧养老】您的订单提醒"),
new WxMpTemplateData("keyword1", pensionOrderDTO.getId().toString()),
new WxMpTemplateData("keyword2", pensionOrderDTO.getServiceName()),
new WxMpTemplateData("keyword3", appointmentTime),
new WxMpTemplateData("remark", "当前状态:" + pensionOrderDTO.getStatusName())
);
templateMessage.setData(data);
String url = SYSURL + "/#/orderDetail/?openid=" + openId + "&id=" + pensionOrderDTO.getId()+"&flag="+flag;
templateMessage.setUrl(url);
try{
wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
}catch (WxErrorException e){
log.error("【微信模板消息】发送失败,{}", e);
}
}
@Override
public void sendServiceWeChatMsg(PensionOrderDTO pensionOrderDTO, String openId) {
WxMpTemplateMessage templateMessage = new WxMpTemplateMessage();
templateMessage.setTemplateId(WECHAT_SERVICE_TP);
templateMessage.setToUser(openId);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String appointmentTime = sdf.format(pensionOrderDTO.getAppointmentTime());
List<WxMpTemplateData> data = Arrays.asList(
new WxMpTemplateData("first", "【智慧养老】您的服务单提醒"),
new WxMpTemplateData("keyword1", pensionOrderDTO.getAppointmentPerson() + " - "+ pensionOrderDTO.getAppointmentPhone()),
new WxMpTemplateData("keyword2", appointmentTime),
new WxMpTemplateData("keyword3", pensionOrderDTO.getAddress()),
new WxMpTemplateData("keyword4", pensionOrderDTO.getServiceName()),
new WxMpTemplateData("keyword5", pensionOrderDTO.getRemark()),
new WxMpTemplateData("remark", "当前状态:" + pensionOrderDTO.getStatusName())
);
templateMessage.setData(data);
String url = SYSURL + "/#/orderDetail/?openid=" + openId + "&id=" + pensionOrderDTO.getId()+"&flag=attendant";
templateMessage.setUrl(url);
try{
wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
}catch (WxErrorException e){
log.error("【微信模板消息】发送失败,{}", e);
}
}
}
......@@ -76,4 +76,14 @@ QR:
# download-path: /home/websoft/java_jar/pension_service/myfile/
# download-path: /home/resourse/bsqzc/ D:/123/ /home/websoft/java_jar/pension_service/myfile/
domain: 192.168.10.61:8088
# domain: byyl.zjhmit.com
\ No newline at end of file
# domain: byyl.zjhmit.com
wechat:
mpAppId: wx35380be533d0e4f9
mpAppSecret: f7b1120a49de078dd1be0080832ad42f
userTemplateId: gU3gtQxrwX0Z6khAL_9tuwzT83KlXk3oV6jbPNuNHbc
serviceTemplateId: xAaQHjjq17i9ONly90rEXfdRj3yPQsjELRmFEUh4idQ
SYSURL:
url: https://byyl.zjhmit.com
\ No newline at end of file
......@@ -325,7 +325,7 @@ public class PensionOrderController {
todto = URLDecoder.decode(dto,"UTF-8");
}catch (Exception ignored){}
ReservationDTO reservationDTO = JSON.parseObject(todto, ReservationDTO.class);
reservationDTO.setAppointmentTime(null);
PensionOrderDTO data = new PensionOrderDTO().assemblePensionOrder(reservationDTO,user);
data.setCommunityId(user.getCommunityId());
data.setCommunityName(user.getCommunityName());
......
......@@ -133,7 +133,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
list.addAll(list2);
}
// page.setTotal(list.size());
List<PensionOrderDTO> sortList = list.stream().sorted(Comparator.comparing(PensionOrderDTO::getAppointmentTime)).collect(Collectors.toList());
List<PensionOrderDTO> sortList = list.stream().sorted(Comparator.comparing(PensionOrderDTO::getId)).collect(Collectors.toList());
Collections.reverse(sortList);
return getPageData(getSubList(params, sortList), sortList.size(), PensionOrderDTO.class);
}
......@@ -167,7 +167,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
result.addAll(list);
}
// page.setTotal(result.size());
List<PensionOrderDTO> sortList = result.stream().sorted(Comparator.comparing(PensionOrderDTO::getAppointmentTime)).collect(Collectors.toList());
List<PensionOrderDTO> sortList = result.stream().sorted(Comparator.comparing(PensionOrderDTO::getId)).collect(Collectors.toList());
Collections.reverse(sortList);
return getPageData(getSubList(params, sortList), sortList.size(), PensionOrderDTO.class);
}
......@@ -195,6 +195,10 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
Long recipient_id = Long.parseLong(params.get("recipientId").toString());
if (pensionOrderEntity.getStatus() == 5 || pensionOrderEntity.getStatus() == 0) {
pensionOrderEntity.setStatus(1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
pensionOrderEntity.setAppointmentTime(sdf.parse(params.get("appointmentTime").toString()));
}catch (Exception ignored){}
pensionOrderEntity.setStatusName(Constant.OrderStatus.ORDER.getMessage());
UserEntity recipient = userService.getUserByUserId(recipient_id);
pensionOrderEntity.setOrderRecipientId(recipient_id);
......@@ -203,6 +207,7 @@ public class PensionOrderServiceImpl extends CrudServiceImpl<PensionOrderDao, Pe
pensionOrderEntity.setOrderRecipientTime(new Date());
update(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class));
pushMessage.sendServiceWeChatMsg(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class), recipient.getOpenid());
pushMessage.sendWeChatMsg(ConvertUtils.sourceToTarget(pensionOrderEntity, PensionOrderDTO.class), userService.getUserByUserId(pensionOrderEntity.getCreator()).getOpenid(), "oldman");
}else {
return false;
}
......
......@@ -49,8 +49,11 @@ public class PushMessageImpl implements PushMessage {
templateMessage.setTemplateId(wechatAccountConfig.getTemplateId());
templateMessage.setToUser(openId);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
String appointmentTime = sdf.format(pensionOrderDTO.getAppointmentTime());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String appointmentTime = "待分配";
if (null != pensionOrderDTO.getAppointmentTime()) {
appointmentTime = sdf.format(pensionOrderDTO.getAppointmentTime());
}
List<WxMpTemplateData> data = Arrays.asList(
new WxMpTemplateData("first", "【智慧养老】您的订单提醒"),
......@@ -75,7 +78,7 @@ public class PushMessageImpl implements PushMessage {
templateMessage.setTemplateId(wechatAccountConfig.getServiceTemplateId());
templateMessage.setToUser(openId);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String appointmentTime = sdf.format(pensionOrderDTO.getAppointmentTime());
List<WxMpTemplateData> data = Arrays.asList(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment