|
|
@@ -7,10 +7,13 @@ import com.usoftchina.smartschool.device.mapper.IcCardMapper;
|
|
|
import com.usoftchina.smartschool.device.po.Transaction;
|
|
|
import com.usoftchina.smartschool.device.service.IcCardService;
|
|
|
import com.usoftchina.smartschool.school.dto.SysSchoolDTO;
|
|
|
+import com.usoftchina.smartschool.school.enums.NoticeTemplate;
|
|
|
import com.usoftchina.smartschool.utils.ObjectUtils;
|
|
|
import com.usoftchina.smartschool.utils.http.HmacUtils;
|
|
|
import com.usoftchina.smartschool.wechat.api.WechatApi;
|
|
|
import com.usoftchina.smartschool.wechat.dto.MessageInfoDTO;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -39,6 +42,8 @@ public class IcCardServiceImpl implements IcCardService {
|
|
|
@Autowired
|
|
|
private WechatApi wechatApi;
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(AccessControlServiceImpl.class);
|
|
|
+
|
|
|
@Value("${smartschool.wechat.pushUrl}")
|
|
|
private String targetURL;
|
|
|
|
|
|
@@ -49,41 +54,45 @@ public class IcCardServiceImpl implements IcCardService {
|
|
|
String appId = sysSchoolDTO.getSchool_appid();
|
|
|
String secret = sysSchoolDTO.getSchool_secret();
|
|
|
Long schoolId = sysSchoolDTO.getSchool_id();
|
|
|
- String templateId = icCardMapper.selectTemplateId(schoolId);
|
|
|
+ String templateId = icCardMapper.selectTemplateId(schoolId, NoticeTemplate.MONEY_NOTICE.getCode());
|
|
|
+ if(!StringUtils.hasText(templateId)){
|
|
|
+ logger.error("学校[{}] 模板[{}]未设置",schoolId,NoticeTemplate.MONEY_NOTICE.getCode());
|
|
|
+ return "";
|
|
|
+ }
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
accTransDetailList.forEach(accTransDetail -> {
|
|
|
- sb.append(accTransDetail.getGuid() + ",");
|
|
|
String oldType = accTransDetail.getAccTransType();
|
|
|
accTransDetail.setAccTransType(Transaction.getName(accTransDetail.getAccTransType()));
|
|
|
//构造messageInfo对象
|
|
|
- MessageInfoDTO messageInfo = new MessageInfoDTO();
|
|
|
- messageInfo.setMsgId(accTransDetail.getGuid());
|
|
|
String openId = icCardMapper.SelectParentOpenId(accTransDetail.getEmpNo(), schoolId);
|
|
|
- //openId为空,不生成messageInfo对象,(消息消费后会调用微信推送,此时会对openId为空做判断,空 直接跳过,消息消费成功)
|
|
|
- if (StringUtils.isEmpty(openId)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- messageInfo.setTouser(openId);
|
|
|
- messageInfo.setAppId(appId);
|
|
|
- messageInfo.setSecret(secret);
|
|
|
- messageInfo.setTemplateId(templateId);
|
|
|
- String accNo = accTransDetail.getAccNo();
|
|
|
- String cardNo = StringUtils.isEmpty(accNo) ? null : accNo.substring(accTransDetail.getAccNo().length() - 4);
|
|
|
- String header = "您好,您的小孩" + accTransDetail.getEmpName() + "在校的校园卡(卡号:*** " + cardNo + ")发生如下交易";
|
|
|
- messageInfo.setTitle(header);
|
|
|
- Date accTransDay = accTransDetail.getAccTransDay();
|
|
|
- if (null != accTransDay) {
|
|
|
- messageInfo.setKeyword1(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(accTransDetail.getAccTransDay()));
|
|
|
+ if(!StringUtils.hasText(openId)){
|
|
|
+ MessageInfoDTO messageInfo = new MessageInfoDTO();
|
|
|
+ messageInfo.setMsgId(accTransDetail.getGuid());
|
|
|
+ sb.append(accTransDetail.getGuid() + ",");
|
|
|
+ messageInfo.setTouser(openId);
|
|
|
+ messageInfo.setAppId(appId);
|
|
|
+ messageInfo.setSecret(secret);
|
|
|
+ //messageInfo.setUserType(2);
|
|
|
+ messageInfo.setTemplateId(templateId);
|
|
|
+ String accNo = accTransDetail.getAccNo();
|
|
|
+ String cardNo = StringUtils.isEmpty(accNo) ? null : accNo.substring(accTransDetail.getAccNo().length() - 4);
|
|
|
+ String header = "您好,您的小孩" + accTransDetail.getEmpName() + "在校的校园卡(卡号:*** " + cardNo + ")发生如下交易";
|
|
|
+ messageInfo.setTitle(header);
|
|
|
+ Date accTransDay = accTransDetail.getAccTransDay();
|
|
|
+ if (null != accTransDay) {
|
|
|
+ messageInfo.setKeyword1(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(accTransDetail.getAccTransDay()));
|
|
|
+ }
|
|
|
+ if (Integer.parseInt(oldType) > 15) {
|
|
|
+ messageInfo.setKeyword2(String.format("%.2f", accTransDetail.getoMoneyValue()));
|
|
|
+ } else {
|
|
|
+ messageInfo.setKeyword2(String.format("%.2f", accTransDetail.getiMoneyValue()));
|
|
|
+ }
|
|
|
+ messageInfo.setKeyword3(accTransDetail.getAccTransType());
|
|
|
+ messageInfo.setKeyword4(String.format("%.2f", accTransDetail.getCardMoneyValue()));
|
|
|
+ messageInfo.setRemark("感谢您使用");
|
|
|
+ messageInfoList.add(messageInfo);
|
|
|
}
|
|
|
- if (Integer.parseInt(oldType) > 15) {
|
|
|
- messageInfo.setKeyword2(String.format("%.2f", accTransDetail.getoMoneyValue()));
|
|
|
- } else {
|
|
|
- messageInfo.setKeyword2(String.format("%.2f", accTransDetail.getiMoneyValue()));
|
|
|
- }
|
|
|
- messageInfo.setKeyword3(accTransDetail.getAccTransType());
|
|
|
- messageInfo.setKeyword4(String.format("%.2f", accTransDetail.getCardMoneyValue()));
|
|
|
- messageInfo.setRemark("感谢您使用");
|
|
|
- messageInfoList.add(messageInfo);
|
|
|
+
|
|
|
});
|
|
|
//3.传输
|
|
|
Result result = wechatApi.sendOutMessages(JSON.toJSONString(messageInfoList));
|
|
|
@@ -109,6 +118,8 @@ public class IcCardServiceImpl implements IcCardService {
|
|
|
return ids;
|
|
|
}
|
|
|
}*/
|
|
|
+ }else {
|
|
|
+ logger.error("对应学校名{}或学校{}未找到",sysSchoolDTO.getSchool_name(),sysSchoolDTO.getSchool_id());
|
|
|
}
|
|
|
return null;
|
|
|
}
|