日志修改

docus_webservice_1.1
lzy 4 years ago
parent e7121c5bf6
commit 9f2c342360

@ -8,17 +8,17 @@
},
{
"collectsys_code": "3",
"requestUrl": "http://localhost:9302/collect",
"requestUrl": "http://localhost:9303/collect",
"remark": "PACS"
},
{
"collectsys_code": "14",
"requestUrl": "http://localhost:9303/collect",
"requestUrl": "http://localhost:9304/collect",
"remark": "内镜"
},
{
"collectsys_code": "4",
"requestUrl": "http://localhost:9304/collect",
"requestUrl": "http://localhost:9305/collect",
"remark": "心电图"
}
]

@ -2,7 +2,9 @@ package com.docus.webservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication
public class DocusWebserviceApplication {

@ -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;
}

@ -26,7 +26,7 @@ public class TBasic implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "病案主键")
@TableId(value = "patient_id", type = IdType.ASSIGN_ID)
@TableId(value = "patient_id", type = IdType.ASSIGN_ID)
private String patientId;
@ApiModelProperty(value = "住院次数")

@ -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();
}
}

@ -15,9 +15,12 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Map;
@ -208,4 +211,42 @@ public class HttpUtils {
return EMPTY_STR;
}
/**
* ip
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request){
String ipAddress = request.getHeader("x-forwarded-for");
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if(ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ipAddress= inet.getHostAddress();
}
}
//对于通过多个代理的情况第一个IP为客户端真实IP,多个IP按照','分割
if(ipAddress!=null && ipAddress.length()>15){ //"***.***.***.***".length() = 15
if(ipAddress.indexOf(",")>0){
ipAddress = ipAddress.substring(0,ipAddress.indexOf(","));
}
}
return ipAddress;
}
}

@ -1,5 +1,5 @@
server:
port: 9696
port: 9399
mybatis-plus:
configuration:
@ -16,4 +16,4 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
username: docus
password: docus702
url: jdbc:mysql://db.docus.cn:3306/docus_medicalrecord?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
url: jdbc:mysql://db.docus.cn:3306/docus_medicalrecord?characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai

@ -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 &lt; SUBDATE(now(),interval 600 second)
</update>
<select id="count" resultType="int">
select count(1) from docus_archivefile.pcmachine where PCStatus=1
</select>
</mapper>
Loading…
Cancel
Save