添加更新重点人员定时任务

master
吴顺杰 1 year ago
parent 922e663e42
commit f9fb072baa

@ -0,0 +1,37 @@
package com.ruoyi.pt.entity;
import cn.hutool.core.annotation.Alias;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.io.Serializable;
/**
* (Keyperson)
*
* @author wu
* @since 2024-04-26 17:24:36
*/
@Data
@ApiModel("实体类")
@TableName(value = "keyperson")
public class Keyperson implements Serializable {
private static final long serialVersionUID = -45344189272733752L;
@TableId(type = IdType.AUTO)
private Long id;
@Alias(value = "RYLX_NAME")
private String aspect1;
@Alias(value = "RYLXDETAIL_NAME")
private String aspect2;
@Alias(value = "XM")
private String keypersonName;
@Alias(value = "LXDH")
private String keypersonTel;
}

@ -0,0 +1,19 @@
package com.ruoyi.pt.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.pt.entity.Keyperson;
/**
* (Keyperson)访
*
* @author wu
* @since 2024-04-26 17:24:36
*/
public interface KeypersonMapper extends BaseMapper<Keyperson> {
/**
*
*/
void delAll();
}

@ -0,0 +1,64 @@
package com.ruoyi.pt.quartz;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.pt.entity.Keyperson;
import com.ruoyi.pt.service.KeypersonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
/**
*
*
* @author wu
* @since 2024/4/26 5:30
*/
@Component
@EnableScheduling
@Async
@Transactional(rollbackFor = Exception.class)
//@RestController
//@RequestMapping("remoteCall/test")
//@Api(tags = "获取重点人员数据")
public class KeypersonQuartz {
public static final Logger log = LoggerFactory.getLogger(KeypersonQuartz.class);
@Resource
private KeypersonService keypersonService;
@Value("${keyPersonUrl}")
private String keyPersonUrl;
// @GetMapping("/zdry")
// @ApiOperation(value = "获取重点人员数据")
@Scheduled(cron = "0 30 2 * * ?")
public synchronized void pushData() {
log.info("==============获取重点人员数据开始" + LocalDateTime.now() + "============");
String res = HttpRequest.get(keyPersonUrl)
.header("appId", "szjsc")
.header("appSecret", "cUuC51fB").execute().body();
JSONObject resObj = JSON.parseObject(res);
String dataList = resObj.getString("data");
List<Keyperson> list = JSONUtil.toList(dataList, Keyperson.class);
log.info("==============获取重点人员数据条数" + list.size() + "============");
// 删除重点人员数据
keypersonService.delAll();
// 保存重点人员数据
keypersonService.saveBatch(list);
log.info("==============获取重点人员数据结束" + LocalDateTime.now() + "============");
}
}

@ -0,0 +1,19 @@
package com.ruoyi.pt.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.pt.entity.Keyperson;
/**
* (Keyperson)
*
* @author wu
* @since 2024-04-26 17:24:36
*/
public interface KeypersonService extends IService<Keyperson> {
/**
*
*/
void delAll();
}

@ -0,0 +1,26 @@
package com.ruoyi.pt.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.pt.mapper.KeypersonMapper;
import com.ruoyi.pt.entity.Keyperson;
import com.ruoyi.pt.service.KeypersonService;
import org.springframework.stereotype.Service;
/**
* (Keyperson)
*
* @author wu
* @since 2024-04-26 17:24:36
*/
@Service("keypersonService")
public class KeypersonServiceImpl extends ServiceImpl<KeypersonMapper, Keyperson> implements KeypersonService {
/**
*
*/
@Override
public void delAll() {
baseMapper.delAll();
}
}

@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.pt.entity.CasesImport;
import com.ruoyi.pt.entity.Events;
import com.ruoyi.pt.entity.dto.RemoteCallsDTO;
@ -62,6 +64,9 @@ public class RemoteCallsServiceImpl implements RemoteCallsService {
@Resource
private CasesImportService casesImportService;
@Resource
private RedisCache redisCache;
/**
* map
*
@ -106,14 +111,23 @@ public class RemoteCallsServiceImpl implements RemoteCallsService {
QueryWrapper<Events> queryWrapper = new QueryWrapper<>();
if (allPush != null && allPush == 1) {
// 获取当天的日期
// LocalDate localDate = LocalDate.now();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// // 当天
// String eventTime = localDate.format(formatter);
// LocalDate localDate = LocalDate.now();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// // 当天
// String eventTime = localDate.format(formatter);
String eventTime;
// 获取redis上次异常的时间
Object obj = redisCache.getCacheObject("eventTime");
if (BeanUtil.isNotEmpty(obj)) {
eventTime = (String) obj;
redisCache.deleteObject("eventTime");
} else {
//获取上个小时
String eventTime = DateUtil.offsetHour(DateUtil.date(), -1).toString("yyyy-MM-dd HH");
queryWrapper.and(wrapper -> wrapper.gt("eventTime", eventTime));
eventTime = DateUtil.offsetHour(DateUtil.date(), -1).toString("yyyy-MM-dd HH");
}
queryWrapper.and(wrapper -> wrapper.ge("eventTime", eventTime));
}
try {
queryWrapper.and(wrapper -> wrapper.isNotNull("innerEventId").ne("innerEventId", "")).isNull("state");
// 创建SimpleDateFormat对象指定日期格式为yyyy-MM-dd HH:mm:ss
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ -175,6 +189,10 @@ public class RemoteCallsServiceImpl implements RemoteCallsService {
return num;
}
}
} catch (HttpException e) {
redisCache.setCacheObject("eventTime", DateUtil.offsetHour(DateUtil.date(), -1).toString("yyyy-MM-dd HH"));
return 0;
}
}
/**
@ -362,9 +380,7 @@ public class RemoteCallsServiceImpl implements RemoteCallsService {
log.info("一共获取" + list.size() + "条数据");
if (CollectionUtil.isNotEmpty(list)) {
// 过滤数据
List<CasesImport> filteredList = list.stream()
.filter(casesImport -> !casesImport.getEventExt().contains("12345便民-咨询"))
.collect(Collectors.toList());
List<CasesImport> filteredList = list.stream().filter(casesImport -> !casesImport.getEventExt().contains("12345便民-咨询")).collect(Collectors.toList());
log.info("=======================================");
log.info("过滤后剩下" + filteredList.size() + "条数据");
num += filteredList.size();

@ -134,3 +134,5 @@ remote:
appKey: 7ae6c089a348b3565af38313f5610968
appSecret: 633e549c5b382cb8da14e36d9eeca3bc
grantType: client_credentials
keyPersonUrl: http://3.15.23.11/dc-easyapi/server/zhcg/getWsryToSF

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.pt.mapper.KeypersonMapper">
<delete id="delAll">
TRUNCATE TABLE keyperson
</delete>
</mapper>
Loading…
Cancel
Save