日志修改
parent
e7121c5bf6
commit
9f2c342360
@ -0,0 +1,30 @@
|
||||
package com.docus.webservice.config;
|
||||
|
||||
import com.docus.webservice.service.IPcmachineService;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyScheduling {
|
||||
|
||||
@Autowired
|
||||
IPcmachineService pcmachineService;
|
||||
|
||||
private Logger logger= LogManager.getLogger(MyScheduling.class);
|
||||
|
||||
//10分钟执行一次
|
||||
@Scheduled(fixedRate = 1000*60*10)
|
||||
public void beat(){
|
||||
Integer count = pcmachineService.count();
|
||||
logger.info("----心跳执行开始,当前在线采集器数:"+count+"----");
|
||||
pcmachineService.isBeat();
|
||||
Integer count2 = pcmachineService.count();
|
||||
logger.info("----心跳执行结束,此次心跳下线采集数:"+(count-count2)+"----");
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.docus.webservice.controller;
|
||||
|
||||
import com.docus.webservice.service.IPcmachineService;
|
||||
import com.docus.webservice.utils.HttpUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@RestController
|
||||
@Api(value = "检测心跳接口",tags = "检测心跳接口")
|
||||
public class BeatController {
|
||||
|
||||
@Autowired
|
||||
IPcmachineService pcmachineService;
|
||||
|
||||
@ApiOperation("心跳")
|
||||
@GetMapping("/beat")
|
||||
public void beat(@RequestParam("code") String code, HttpServletRequest request){
|
||||
String ip = HttpUtils.getIpAddr(request);
|
||||
pcmachineService.beat(code,ip);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.docus.webservice.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "采集器状态表", description = "采集器状态表")
|
||||
public class Pcmachine {
|
||||
@ApiModelProperty(value = "病案主键")
|
||||
@TableId(value = "patient_id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private String machineinfo;
|
||||
private String ipaddress;
|
||||
private String showtext;
|
||||
private Integer enable;
|
||||
private String descrption;
|
||||
private Date createdtime;
|
||||
private String createdBy;
|
||||
private Integer pcstatus;
|
||||
private Date lastonline;
|
||||
private String c1;
|
||||
private String c2;
|
||||
private String c3;
|
||||
private Double d1;
|
||||
private Double d2;
|
||||
private Double d3;
|
||||
private Date t1;
|
||||
private Date t2;
|
||||
private Date t3;
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.docus.webservice.mapper;
|
||||
|
||||
import com.docus.webservice.entity.Pcmachine;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface PcmachineMapper {
|
||||
void update(@Param("pcmachine") Pcmachine pcmachine);
|
||||
|
||||
String getNameByCode(@Param("code") String code);
|
||||
|
||||
String getIdByName(@Param("name") String name);
|
||||
|
||||
void isBeat();
|
||||
|
||||
Integer count();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.docus.webservice.service;
|
||||
|
||||
public interface IPcmachineService {
|
||||
void beat(String code, String ip);
|
||||
|
||||
void isBeat();
|
||||
|
||||
Integer count();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.docus.webservice.service;
|
||||
|
||||
import com.docus.webservice.entity.Pcmachine;
|
||||
import com.docus.webservice.mapper.PcmachineMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class PcmachineServiceImpl implements IPcmachineService {
|
||||
|
||||
@Autowired
|
||||
PcmachineMapper pcmachineMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public void beat(String code, String ip) {
|
||||
String name=pcmachineMapper.getNameByCode(code);
|
||||
String id= pcmachineMapper.getIdByName(name);
|
||||
Pcmachine pcmachine=new Pcmachine();
|
||||
pcmachine.setId(Long.parseLong(id));
|
||||
pcmachine.setIpaddress(ip);
|
||||
pcmachine.setLastonline(new Date());
|
||||
pcmachine.setPcstatus(1);
|
||||
System.out.println(pcmachine);
|
||||
pcmachineMapper.update(pcmachine);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isBeat() {
|
||||
pcmachineMapper.isBeat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer count() {
|
||||
return pcmachineMapper.count();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?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.docus.webservice.mapper.PcmachineMapper">
|
||||
<insert id="update">
|
||||
update docus_archivefile.pcmachine
|
||||
<set>
|
||||
<if test="pcmachine.ipaddress != null">
|
||||
IPAddress=#{pcmachine.ipaddress},
|
||||
</if>
|
||||
<if test="pcmachine.lastonline != null">
|
||||
LastOnline=#{pcmachine.lastonline},
|
||||
</if>
|
||||
<if test="pcmachine.pcstatus != null">
|
||||
PCStatus=#{pcmachine.pcstatus}
|
||||
</if>
|
||||
</set>
|
||||
where id=#{pcmachine.id}
|
||||
</insert>
|
||||
|
||||
<select id="getNameByCode" resultType="string">
|
||||
select sys_name from docus_archivefile.af_collectsys_dictionary where sys_code=#{code}
|
||||
</select>
|
||||
|
||||
<select id="getIdByName" resultType="string">
|
||||
select id from docus_archivefile.pcmachine where MachineInfo=#{name}
|
||||
</select>
|
||||
|
||||
<update id="isBeat">
|
||||
update docus_archivefile.pcmachine set PCStatus=0 where LastOnline < SUBDATE(now(),interval 600 second)
|
||||
</update>
|
||||
|
||||
<select id="count" resultType="int">
|
||||
select count(1) from docus_archivefile.pcmachine where PCStatus=1
|
||||
</select>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue