|
|
@@ -0,0 +1,232 @@
|
|
|
+
|
|
|
+package org.jeecg.modules.quartz.job;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.api.dto.message.MessageDTO;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.api.ISysBaseAPI;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.modules.smscheck.entity.SmsCheckCinfoResult;
|
|
|
+import org.jeecg.modules.smscheck.entity.SmsCheckCustomerInfo;
|
|
|
+import org.jeecg.modules.smscheck.entity.SmsCheckTask;
|
|
|
+import org.jeecg.modules.smscheck.service.ISmsCheckCinfoResultService;
|
|
|
+import org.jeecg.modules.smscheck.service.ISmsCheckCustomerInfoService;
|
|
|
+import org.jeecg.modules.smscheck.service.ISmsCheckTaskService;
|
|
|
+import org.quartz.Job;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.quartz.JobExecutionException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 客户信息稽核-发送信息任务
|
|
|
+ *
|
|
|
+ * @Author Scott
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class CustomerSendMsgJob implements Job {
|
|
|
+
|
|
|
+ private String template = "您好,【${system_name}】【${task_name}】提醒,您管理的客户有共计【${user_no_num}】服务号码的【${check_type}】${date_pre_str}【${date}】到期(${days_text}),请尽快处理。";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISmsCheckTaskService smsCheckTaskService;
|
|
|
+ @Autowired
|
|
|
+ private ISmsCheckCustomerInfoService customerInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ISmsCheckCinfoResultService smsCheckCinfoResultService;
|
|
|
+ @Autowired
|
|
|
+ private ISysBaseAPI sysBaseAPI;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
+ log.info("自动发信任务开始处理");
|
|
|
+ List<Map<String,Object>> cinfo_notice_list = smsCheckCinfoResultService.list2notice();
|
|
|
+ if(cinfo_notice_list!=null){
|
|
|
+ for (int i=0;i<cinfo_notice_list.size();i++){
|
|
|
+ Map<String, Object> cinfo = cinfo_notice_list.get(i);;
|
|
|
+ try {
|
|
|
+ notice(cinfo);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("短信任务处理完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发站内信
|
|
|
+ * @param cinfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean notice(Map<String, Object> cinfo) throws ParseException {
|
|
|
+ /*LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();*/
|
|
|
+
|
|
|
+ String taskId = (String)cinfo.get("task_id");
|
|
|
+ String customerNo = (String)cinfo.get("customer_no");
|
|
|
+ String userNo = (String)cinfo.get("user_no");
|
|
|
+ if(StringUtils.isBlank(taskId) || StringUtils.isBlank(customerNo) || StringUtils.isBlank(userNo)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询任务信息
|
|
|
+ LambdaQueryWrapper<SmsCheckTask> task_queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ task_queryWrapper.eq(SmsCheckTask::getId,taskId);
|
|
|
+ SmsCheckTask task = smsCheckTaskService.getOne(task_queryWrapper);
|
|
|
+ // 查询客户信息
|
|
|
+ LambdaQueryWrapper<SmsCheckCustomerInfo> info_queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ info_queryWrapper.eq(SmsCheckCustomerInfo::getTaskId,taskId);
|
|
|
+ info_queryWrapper.eq(SmsCheckCustomerInfo::getCustomerNo,customerNo);
|
|
|
+ info_queryWrapper.eq(SmsCheckCustomerInfo::getUserNo,userNo);
|
|
|
+ SmsCheckCustomerInfo info = customerInfoService.getOne(info_queryWrapper);
|
|
|
+
|
|
|
+ Object date_type_obj = cinfo.get("date_type");
|
|
|
+ String date_type = date_type_obj==null?"":date_type_obj.toString();
|
|
|
+ // 稽核字段(1:合同到期时间,2:码号证书到期时间,3:备案通知到期时间,4:增值业务许可证到期时间,5:营业执照到期时间)
|
|
|
+ switch (date_type){
|
|
|
+ case "1":
|
|
|
+ date_type = "服务合同";
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ date_type = "码号证书";
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ date_type = "备案";
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ date_type = "增值业务许可证";
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ date_type = "营业执照";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收信人
|
|
|
+ String accountManager = info.getAccountManager();
|
|
|
+ LoginUser toUser = sysBaseAPI.getUserByWorkNo(accountManager);
|
|
|
+ String username = "B12345";
|
|
|
+ if(toUser!=null){
|
|
|
+ username = toUser.getUsername();
|
|
|
+ }
|
|
|
+
|
|
|
+ String msg_text = get_msg_text(cinfo, task, info);
|
|
|
+
|
|
|
+ log.info("发信详情:"+username+","+msg_text);
|
|
|
+ MessageDTO message = new MessageDTO();
|
|
|
+ message.setTitle("行短稽核:"+date_type+"到期提醒");
|
|
|
+ message.setContent(msg_text);
|
|
|
+ message.setFromUser("北区稽核平台");
|
|
|
+ message.setToUser(username);
|
|
|
+ sysBaseAPI.sendSysAnnouncement(message);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建信息文本
|
|
|
+ * @param info
|
|
|
+ * @param task
|
|
|
+ * @param info
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String get_msg_text(Map<String, Object> cinfo,SmsCheckTask task,SmsCheckCustomerInfo info) throws ParseException {
|
|
|
+ String taskName = task.getTaskName();
|
|
|
+ taskName = taskName==null?"":taskName;
|
|
|
+
|
|
|
+ Object date_type_obj = cinfo.get("date_type");
|
|
|
+ String date_type = date_type_obj==null?"":date_type_obj.toString();
|
|
|
+ // 稽核字段(1:合同到期时间,2:码号证书到期时间,3:备案通知到期时间,4:增值业务许可证到期时间,5:营业执照到期时间)
|
|
|
+ switch (date_type){
|
|
|
+ case "1":
|
|
|
+ date_type = "服务合同";
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ date_type = "码号证书";
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ date_type = "备案";
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ date_type = "增值业务许可证";
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ date_type = "营业执照";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ Object date_val_obj = cinfo.get("date_val");
|
|
|
+ String date_val = date_val_obj==null?"":date_val_obj.toString();
|
|
|
+ String date_str = "";
|
|
|
+ String date_pre_str = "";
|
|
|
+ String days_str = "";
|
|
|
+ if(StringUtils.isNoneBlank(date_val)){
|
|
|
+ Date date_date = DateUtils.parseDate(date_val, "yyyy-MM-dd");
|
|
|
+ int diff_days = time_diff_days_byNow(date_date);
|
|
|
+ int diff_days_abs = Math.abs(diff_days);
|
|
|
+ if(diff_days>0){
|
|
|
+ days_str = diff_days_abs + "天后";
|
|
|
+ date_pre_str = "将于";
|
|
|
+ }else if(diff_days<0){
|
|
|
+ days_str = diff_days_abs + "天前";
|
|
|
+ date_pre_str = "已于";
|
|
|
+ }else{
|
|
|
+ days_str = "当天";
|
|
|
+ date_pre_str = "将于";
|
|
|
+ }
|
|
|
+
|
|
|
+ date_str = DateUtils.formatDate(date_date);
|
|
|
+ }
|
|
|
+
|
|
|
+ Object num_obj = cinfo.get("num");
|
|
|
+ String num = num_obj==null?"":num_obj.toString();
|
|
|
+ if(StringUtils.isNoneBlank(num)){
|
|
|
+ num = num+"个";
|
|
|
+ }else{
|
|
|
+ num = "0个";
|
|
|
+ }
|
|
|
+
|
|
|
+ String text = template.replace("${system_name}", "北区稽核平台")
|
|
|
+ .replace("${task_name}",taskName)
|
|
|
+ .replace("${user_no_num}",num)
|
|
|
+ .replace("${check_type}",date_type)
|
|
|
+ .replace("${date}",date_str)
|
|
|
+ .replace("${date_pre_str}",date_pre_str)
|
|
|
+ .replace("${days_text}",days_str);
|
|
|
+ return text;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算与当前时间差多少天
|
|
|
+ * @param date
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ private int time_diff_days_byNow(Date date) throws ParseException {
|
|
|
+ Date now = new Date();
|
|
|
+ int days = 0;
|
|
|
+
|
|
|
+ long now_time = now.getTime();
|
|
|
+ long date_time = date.getTime();
|
|
|
+
|
|
|
+ long diff_time = date_time - now_time;
|
|
|
+
|
|
|
+ long diff_days = diff_time / 1000 / 60 / 60 / 24;
|
|
|
+
|
|
|
+ days = Integer.valueOf(String.valueOf(diff_days));
|
|
|
+
|
|
|
+ System.out.println("test_long:"+now_time +","+ date_time+","+diff_time+","+diff_days+","+days);
|
|
|
+
|
|
|
+ return days;
|
|
|
+ }
|
|
|
+}
|