添加job任务
This commit is contained in:
parent
186fc8ddfb
commit
e2e30d99e7
|
|
@ -0,0 +1,18 @@
|
|||
package com.bonus.job.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeviceStatusVo {
|
||||
/**
|
||||
* 设备编码
|
||||
*/
|
||||
private String deviceCode;
|
||||
/**
|
||||
* 设备状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.bonus.job.mapper;
|
||||
|
||||
import com.bonus.job.domain.DeviceStatusVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DeviceStatusMapper {
|
||||
|
||||
/**
|
||||
* 查询设备信息
|
||||
* @return
|
||||
*/
|
||||
List<DeviceStatusVo> getAllDeviceList();
|
||||
|
||||
/**
|
||||
* 批量更新数据
|
||||
* @param list
|
||||
*/
|
||||
void updateDeviceStatus(List<DeviceStatusVo> list);
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.bonus.job.task;
|
||||
|
||||
import com.bonus.common.redis.service.RedisService;
|
||||
import com.bonus.job.domain.DeviceStatusVo;
|
||||
import com.bonus.job.mapper.DeviceStatusMapper;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component("deviceStatusTask")
|
||||
@Slf4j
|
||||
public class DeviceStatusTask {
|
||||
|
||||
@Autowired
|
||||
private DeviceStatusMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisUtils;
|
||||
|
||||
public final static int PAGE_SIZE=100;
|
||||
|
||||
/**
|
||||
* 查询全部考情机进行
|
||||
*/
|
||||
public void updateDeviceStatus(){
|
||||
try{
|
||||
updateDeviceStatus(1);
|
||||
}catch (Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
public void updateDeviceStatus(int pageNum){
|
||||
PageHelper.startPage(pageNum,PAGE_SIZE);
|
||||
List<DeviceStatusVo> list=mapper.getAllDeviceList();
|
||||
for (DeviceStatusVo vo:list){
|
||||
String status=redisUtils.getCacheObject("att_dev:status:"+vo.getDeviceCode());
|
||||
if(StringUtils.isEmpty(status)){
|
||||
vo.setStatus("0");
|
||||
}else{
|
||||
vo.setStatus(status);
|
||||
}
|
||||
}
|
||||
mapper.updateDeviceStatus(list);
|
||||
PageInfo<DeviceStatusVo> pageInfo =new PageInfo<DeviceStatusVo>(list);
|
||||
int pageSize=pageInfo.getPageNum();
|
||||
int pageTotal=pageInfo.getPages();
|
||||
if(pageSize<pageTotal){
|
||||
pageNum++;
|
||||
updateDeviceStatus(pageNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?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.bonus.job.mapper.DeviceStatusMapper">
|
||||
<update id="updateDeviceStatus">
|
||||
<foreach collection="list" separator=";" item="item" index="index">
|
||||
update pm_att_device set on_line=#{item.status} where device_code=#{item.deviceCode}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
|
||||
<select id="getAllDeviceList" resultType="com.bonus.job.domain.DeviceStatusVo">
|
||||
select device_code deviceCode
|
||||
from pm_att_device
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -47,7 +47,6 @@ public class DeviceHandle {
|
|||
}else{
|
||||
System.err.println("数据新增失败---->"+devId);
|
||||
}
|
||||
|
||||
}
|
||||
deviceVo.setTransId(transId);
|
||||
return deviceVo;
|
||||
|
|
|
|||
Loading…
Reference in New Issue