|
@@ -13,8 +13,10 @@ import com.jpsoft.picc.modules.base.entity.CompanyUser;
|
|
|
import com.jpsoft.picc.modules.base.entity.Message;
|
|
|
import com.jpsoft.picc.modules.business.dao.InsuranceApplicationDAO;
|
|
|
import com.jpsoft.picc.modules.business.dao.InsurancePolicyDAO;
|
|
|
+import com.jpsoft.picc.modules.business.dao.StudentApplicationDAO;
|
|
|
import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
|
|
|
import com.jpsoft.picc.modules.business.entity.InsurancePolicy;
|
|
|
+import com.jpsoft.picc.modules.business.entity.StudentApplication;
|
|
|
import com.jpsoft.picc.modules.common.config.WeixinConfig;
|
|
|
import com.jpsoft.picc.modules.common.constant.PolicyStatus;
|
|
|
import com.jpsoft.picc.modules.common.utils.JsonUtil;
|
|
@@ -65,6 +67,9 @@ public class TemplateMessageServiceImpl implements TemplateMessageService {
|
|
|
@Autowired
|
|
|
private UserDAO userDAO;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StudentApplicationDAO studentApplicationDAO;
|
|
|
+
|
|
|
@Override
|
|
|
public TemplateMessage get(String id) {
|
|
|
// TODO Auto-generated method stub
|
|
@@ -392,4 +397,98 @@ public class TemplateMessageServiceImpl implements TemplateMessageService {
|
|
|
|
|
|
messageDAO.insert(message);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean sendTemplateStudentMessage(String sApplicationId,int policyStatus) {
|
|
|
+ boolean result = false;
|
|
|
+
|
|
|
+ try {
|
|
|
+ StudentApplication studentApplication = studentApplicationDAO.get(sApplicationId);
|
|
|
+
|
|
|
+ List<TemplateMessage> templateMessageList = templateMessageDAO.findByPolicyStatus(policyStatus);
|
|
|
+
|
|
|
+ for (TemplateMessage templateMessage : templateMessageList) {
|
|
|
+ if (templateMessage==null){
|
|
|
+ throw new Exception("对应模板消息不存在!");
|
|
|
+ }
|
|
|
+ List<Map> targetList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (templateMessage.getTarget().equals("JZRCCS") || templateMessage.getTarget().equals("PICC")) {
|
|
|
+ List<User> userList = userDAO.findByRoleName(templateMessage.getTarget());
|
|
|
+
|
|
|
+ for (User user : userList) {
|
|
|
+ Map<String, Object> userMap = new HashMap<>();
|
|
|
+ userMap.put("userId", user.getId());
|
|
|
+ userMap.put("openId", user.getOpenId());
|
|
|
+ userMap.put("target", templateMessage.getTarget());
|
|
|
+
|
|
|
+ targetList.add(userMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map map : targetList) {
|
|
|
+ String userId = (String) map.get("userId");
|
|
|
+ String openId = (String) map.get("openId");
|
|
|
+ String target = (String) map.get("target");
|
|
|
+
|
|
|
+ sendStudentMessage(userId, openId,templateMessage, studentApplication);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result = true;
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ log.error(ex.getMessage(),ex);
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param userId 接收消息用户编号
|
|
|
+ * @param openId 接收消息用户微信openId
|
|
|
+ * @param templateMessage 模板消息
|
|
|
+ */
|
|
|
+ private void sendStudentMessage(String userId,String openId,
|
|
|
+ TemplateMessage templateMessage,
|
|
|
+ StudentApplication studentApplication){
|
|
|
+ String content = templateMessage.getContent();
|
|
|
+
|
|
|
+ Map<String,Object> contentVars = new HashMap<>();
|
|
|
+ contentVars.put("userName", studentApplication.getInsuredName());
|
|
|
+ contentVars.put("companyName", studentApplication.getInsuredName());
|
|
|
+
|
|
|
+ content = VelocityHelper.format(content,contentVars);
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ Map<String,Object> jsonVars = new HashMap<>();
|
|
|
+
|
|
|
+ jsonVars.put("content",content);
|
|
|
+
|
|
|
+ String json = VelocityHelper.format(templateMessage.getJson(),jsonVars);
|
|
|
+ JSONObject jsonObject = new JSONObject(json);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(openId)) {
|
|
|
+ //发送微信模板消息
|
|
|
+ new Thread(() -> WeixinUtil.sendTemplateMessage(weixinConfig,
|
|
|
+ openId, templateMessage.getCode(), jsonObject)
|
|
|
+ ).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ //写站内消息
|
|
|
+ Message message = new Message();
|
|
|
+ message.setId(UUID.randomUUID().toString());
|
|
|
+ message.setTitle(templateMessage.getTitle());
|
|
|
+ message.setContent(content);
|
|
|
+ message.setRecipientId(userId);
|
|
|
+ message.setStatus(false);
|
|
|
+ message.setDelFlag(false);
|
|
|
+ message.setCreateTime(new Date());
|
|
|
+
|
|
|
+ messageDAO.insert(message);
|
|
|
+ }
|
|
|
}
|