|
|
@@ -0,0 +1,282 @@
|
|
|
+
|
|
|
+package org.jeecg.modules.quartz.job;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.jeecg.modules.smscheck.controller.SmsCheckCustomerDataController;
|
|
|
+import org.jeecg.modules.smscheck.entity.SmsCheckCinfoResult;
|
|
|
+import org.jeecg.modules.smscheck.entity.SmsCheckCustomerData;
|
|
|
+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.ISmsCheckCustomerDataService;
|
|
|
+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 java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 客户信息稽核任务
|
|
|
+ *
|
|
|
+ * @Author Scott
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class CustomerCheckJob implements Job {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 若参数变量名修改 QuartzJobController中也需对应修改
|
|
|
+ */
|
|
|
+ private String parameter;
|
|
|
+ private JSONObject parameterMap = new JSONObject();
|
|
|
+ private Date now;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISmsCheckTaskService smsCheckTaskService;
|
|
|
+ @Autowired
|
|
|
+ private ISmsCheckCustomerInfoService customerInfoService;
|
|
|
+ @Autowired
|
|
|
+ private ISmsCheckCinfoResultService smsCheckCinfoResultService;
|
|
|
+
|
|
|
+ public void setParameter(String parameter) {
|
|
|
+ this.parameter = parameter;
|
|
|
+
|
|
|
+ if(StringUtils.isNoneBlank(parameter)){
|
|
|
+ try{
|
|
|
+ parameterMap = JSONObject.parseObject(parameter);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.warn("任务参数解析失败【"+parameter+"】,"+e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ now = new Date();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
+ log.info(" Job Execution key:"+jobExecutionContext.getJobDetail().getKey());
|
|
|
+ log.info(" 时间:" + DateUtils.now());
|
|
|
+ log.info(" 参数:" + parameterMap);
|
|
|
+
|
|
|
+ // 告警检测字段
|
|
|
+ String[] params = {"contract","sms_number_certificate","record_notice","value_added_licence","business_licence"};
|
|
|
+ Object params_obj = parameterMap.get("params");
|
|
|
+ if(params_obj!=null){
|
|
|
+ params = params_obj.toString().split(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预警天数:0;到期当天预警,>0:提前预警,<0,延后预警
|
|
|
+ int warn_days = 0;
|
|
|
+ Object warn_days_obj = parameterMap.get("warn_days");
|
|
|
+ if(warn_days_obj!=null){
|
|
|
+ warn_days = Integer.valueOf(warn_days_obj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预警短信级别:0:不发送,1:客户经理,2:三级部门,2:二级部门
|
|
|
+ int msg_level = 0;
|
|
|
+ Object msg_level_obj = parameterMap.get("msg_level");
|
|
|
+ if(msg_level_obj!=null){
|
|
|
+ msg_level = Integer.valueOf(msg_level_obj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 短信发送最高次数(0:不限制次数)
|
|
|
+ int msg_num = 0;
|
|
|
+ Object msg_num_obj = parameterMap.get("msg_num");
|
|
|
+ if(msg_num_obj!=null){
|
|
|
+ msg_num_obj = Integer.valueOf(msg_num_obj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 短信发送间隔(天)
|
|
|
+ int msg_interval = 0;
|
|
|
+ Object msg_interval_obj = parameterMap.get("msg_interval");
|
|
|
+ if(msg_interval_obj!=null){
|
|
|
+ msg_interval_obj = Integer.valueOf(msg_interval_obj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SmsCheckTask> task_queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ task_queryWrapper.eq(SmsCheckTask::getTaskState,1);
|
|
|
+
|
|
|
+ // 查询数据总数
|
|
|
+ long task_num = smsCheckTaskService.count(task_queryWrapper);
|
|
|
+ log.info("客户信息稽核开始,共计【"+task_num+"】条任务");
|
|
|
+ // 任务信息 分页查询
|
|
|
+ int pageNo = 1,size = 50;
|
|
|
+ for(;((pageNo-1)*size)<=task_num;pageNo++){
|
|
|
+ Page<SmsCheckTask> page = new Page<>(pageNo, size);
|
|
|
+ Page<SmsCheckTask> task_page = smsCheckTaskService.page(page,task_queryWrapper);
|
|
|
+ List<SmsCheckTask> task_list = task_page.getRecords();
|
|
|
+
|
|
|
+ if(task_list!=null && task_list.size()>0){
|
|
|
+ for(int i=0;i<task_list.size();i++){
|
|
|
+ SmsCheckTask task = task_list.get(i);
|
|
|
+ String task_id = task.getId();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<SmsCheckCustomerInfo> info_queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ info_queryWrapper.eq(SmsCheckCustomerInfo::getTaskId,task_id);
|
|
|
+
|
|
|
+ // 查询数据总数
|
|
|
+ long info_num = customerInfoService.count(info_queryWrapper);
|
|
|
+ log.info("任务【"+task_id+"】开始处理,共计【"+info_num+"】条用户服务信息");
|
|
|
+ // 分页查询客户信息并讲稽核结果入库
|
|
|
+ int info_pageNo = 1,info_size = 50;
|
|
|
+ for(;((info_pageNo-1)*info_size)<=info_num;info_pageNo++){
|
|
|
+ Page<SmsCheckCustomerInfo> page2 = new Page<>(info_pageNo, info_size);
|
|
|
+ Page<SmsCheckCustomerInfo> info_page = customerInfoService.page(page2, info_queryWrapper);
|
|
|
+ List<SmsCheckCustomerInfo> info_list = info_page.getRecords();
|
|
|
+
|
|
|
+ if(info_list!=null && info_list.size()>0){
|
|
|
+ List<SmsCheckCinfoResult> save_cinfoResult_list = new ArrayList<>();
|
|
|
+ for(int i2=0;i2<info_list.size();i2++){
|
|
|
+ // 客户信息稽核
|
|
|
+ SmsCheckCustomerInfo info = info_list.get(i2);
|
|
|
+ try {
|
|
|
+ List<SmsCheckCinfoResult> check_list = cinfo_check(info, task_id, params, warn_days, msg_level, msg_num, msg_interval);
|
|
|
+ save_cinfoResult_list.addAll(check_list);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ smsCheckCinfoResultService.saveOrUpdateBatch_bymap(save_cinfoResult_list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("任务【"+task_id+"】处理完成");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("客户信息稽核结束");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SmsCheckCinfoResult> cinfo_check(SmsCheckCustomerInfo info,String task_id,String[] params,int warn_days,int msg_level,int msg_num,int msg_interval) throws ParseException {
|
|
|
+ List<SmsCheckCinfoResult> save_cinfoResult_list = new ArrayList<>();
|
|
|
+
|
|
|
+ String customerNo = info.getCustomerNo();
|
|
|
+ String userNo = info.getUserNo();
|
|
|
+
|
|
|
+ String msg_context = "";
|
|
|
+
|
|
|
+ // 对各字段进行稽核
|
|
|
+ for (int ip = 0; ip < params.length; ip++) {
|
|
|
+ String param = params[ip];
|
|
|
+
|
|
|
+ SmsCheckCinfoResult cinfoResult = new SmsCheckCinfoResult();
|
|
|
+ cinfoResult.setTaskId(task_id);
|
|
|
+ cinfoResult.setCustomerNo(customerNo);
|
|
|
+ cinfoResult.setUserNo(userNo);
|
|
|
+
|
|
|
+ cinfoResult.setMsgLevel(msg_level);
|
|
|
+ cinfoResult.setMsgTotal(msg_num);
|
|
|
+ cinfoResult.setMsgInterval(msg_interval);
|
|
|
+
|
|
|
+ Map<String, Object> check_result = customerInfo_check(info, param, warn_days);
|
|
|
+ String date_str = (String) check_result.get("date");
|
|
|
+ Object type_obj = check_result.get("type");
|
|
|
+ int type_int = 0;
|
|
|
+ if (type_obj != null) {
|
|
|
+ type_int = Integer.valueOf(type_obj.toString());
|
|
|
+ }
|
|
|
+ cinfoResult.setDateType(ip + 1);
|
|
|
+ cinfoResult.setDateVal(date_str);
|
|
|
+ cinfoResult.setDateState(type_int);
|
|
|
+
|
|
|
+ cinfoResult.setCheckTime(new Date());
|
|
|
+
|
|
|
+ save_cinfoResult_list.add(cinfoResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ return save_cinfoResult_list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查指定日期参数是否过期超过阈值
|
|
|
+ * @param info
|
|
|
+ * @param param
|
|
|
+ * @param warn_days
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ private Map<String,Object> customerInfo_check(SmsCheckCustomerInfo info, String param, int warn_days) throws ParseException {
|
|
|
+ Map<String,Object> result = new HashMap<>();
|
|
|
+ boolean flag = false;
|
|
|
+ Date date = null;
|
|
|
+ String date_str = null;
|
|
|
+ int days = 0;
|
|
|
+ int type = 0;
|
|
|
+ switch (param){
|
|
|
+ case "contract":
|
|
|
+ date = info.getContractExpireTime();
|
|
|
+ break;
|
|
|
+ case "sms_number_certificate":
|
|
|
+ date = info.getSmsNumberCertificateExpireTime();
|
|
|
+ break;
|
|
|
+ case "record_notice":
|
|
|
+ date = info.getRecordNoticeExpireTime();
|
|
|
+ break;
|
|
|
+ case "value_added_licence":
|
|
|
+ date = info.getValueAddedLicenceExpireTime();
|
|
|
+ break;
|
|
|
+ case "business_licence":
|
|
|
+ date = info.getBusinessLicenceExpireTime();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ type = 4;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(date!=null){
|
|
|
+ date_str = DateUtils.formatDate(date,"yyyy-MM-dd");
|
|
|
+ days = time_diff_days_byNow(date);
|
|
|
+ if(days<=warn_days){
|
|
|
+ flag = true;
|
|
|
+ type = 2;
|
|
|
+ }else{
|
|
|
+ type = 1;
|
|
|
+ }
|
|
|
+ result.put("flag",flag);
|
|
|
+ }else if(type==0){
|
|
|
+ type = 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("type",type);
|
|
|
+ result.put("param",param);
|
|
|
+ result.put("date",date_str);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算与当前时间差多少天
|
|
|
+ * @param date
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ private int time_diff_days_byNow(Date date) throws ParseException {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|