diff --git a/docus-webservice/dataConfig/collectList.json b/docus-webservice/dataConfig/collectList.json index 0f1bd31..0f31cd3 100644 --- a/docus-webservice/dataConfig/collectList.json +++ b/docus-webservice/dataConfig/collectList.json @@ -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": "心电图" } ] diff --git a/docus-webservice/src/main/java/com/docus/webservice/DocusWebserviceApplication.java b/docus-webservice/src/main/java/com/docus/webservice/DocusWebserviceApplication.java index 24f26a1..b893fda 100644 --- a/docus-webservice/src/main/java/com/docus/webservice/DocusWebserviceApplication.java +++ b/docus-webservice/src/main/java/com/docus/webservice/DocusWebserviceApplication.java @@ -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 { diff --git a/docus-webservice/src/main/java/com/docus/webservice/config/MyScheduling.java b/docus-webservice/src/main/java/com/docus/webservice/config/MyScheduling.java new file mode 100644 index 0000000..81dd844 --- /dev/null +++ b/docus-webservice/src/main/java/com/docus/webservice/config/MyScheduling.java @@ -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)+"----"); + + } + +} diff --git a/docus-webservice/src/main/java/com/docus/webservice/controller/BeatController.java b/docus-webservice/src/main/java/com/docus/webservice/controller/BeatController.java new file mode 100644 index 0000000..d431c8c --- /dev/null +++ b/docus-webservice/src/main/java/com/docus/webservice/controller/BeatController.java @@ -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); + } + + +} diff --git a/docus-webservice/src/main/java/com/docus/webservice/entity/Pcmachine.java b/docus-webservice/src/main/java/com/docus/webservice/entity/Pcmachine.java new file mode 100644 index 0000000..4ee87ac --- /dev/null +++ b/docus-webservice/src/main/java/com/docus/webservice/entity/Pcmachine.java @@ -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; +} diff --git a/docus-webservice/src/main/java/com/docus/webservice/entity/TBasic.java b/docus-webservice/src/main/java/com/docus/webservice/entity/TBasic.java index c684805..da6a19d 100644 --- a/docus-webservice/src/main/java/com/docus/webservice/entity/TBasic.java +++ b/docus-webservice/src/main/java/com/docus/webservice/entity/TBasic.java @@ -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 = "住院次数") diff --git a/docus-webservice/src/main/java/com/docus/webservice/mapper/PcmachineMapper.java b/docus-webservice/src/main/java/com/docus/webservice/mapper/PcmachineMapper.java new file mode 100644 index 0000000..4ba9d19 --- /dev/null +++ b/docus-webservice/src/main/java/com/docus/webservice/mapper/PcmachineMapper.java @@ -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(); +} diff --git a/docus-webservice/src/main/java/com/docus/webservice/service/IPcmachineService.java b/docus-webservice/src/main/java/com/docus/webservice/service/IPcmachineService.java new file mode 100644 index 0000000..25205c1 --- /dev/null +++ b/docus-webservice/src/main/java/com/docus/webservice/service/IPcmachineService.java @@ -0,0 +1,9 @@ +package com.docus.webservice.service; + +public interface IPcmachineService { + void beat(String code, String ip); + + void isBeat(); + + Integer count(); +} diff --git a/docus-webservice/src/main/java/com/docus/webservice/service/PcmachineServiceImpl.java b/docus-webservice/src/main/java/com/docus/webservice/service/PcmachineServiceImpl.java new file mode 100644 index 0000000..aa0fbc7 --- /dev/null +++ b/docus-webservice/src/main/java/com/docus/webservice/service/PcmachineServiceImpl.java @@ -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(); + } +} diff --git a/docus-webservice/src/main/java/com/docus/webservice/utils/HttpUtils.java b/docus-webservice/src/main/java/com/docus/webservice/utils/HttpUtils.java index 333cd51..195160a 100644 --- a/docus-webservice/src/main/java/com/docus/webservice/utils/HttpUtils.java +++ b/docus-webservice/src/main/java/com/docus/webservice/utils/HttpUtils.java @@ -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; + } + + + } diff --git a/docus-webservice/src/main/resources/application.yml b/docus-webservice/src/main/resources/application.yml index 66920af..053a34e 100644 --- a/docus-webservice/src/main/resources/application.yml +++ b/docus-webservice/src/main/resources/application.yml @@ -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 \ No newline at end of file + url: jdbc:mysql://db.docus.cn:3306/docus_medicalrecord?characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai \ No newline at end of file diff --git a/docus-webservice/src/main/resources/mapper/PcmachineMapper.xml b/docus-webservice/src/main/resources/mapper/PcmachineMapper.xml new file mode 100644 index 0000000..852a331 --- /dev/null +++ b/docus-webservice/src/main/resources/mapper/PcmachineMapper.xml @@ -0,0 +1,38 @@ + + + + + update docus_archivefile.pcmachine + + + IPAddress=#{pcmachine.ipaddress}, + + + LastOnline=#{pcmachine.lastonline}, + + + PCStatus=#{pcmachine.pcstatus} + + + where id=#{pcmachine.id} + + + + + + + + update docus_archivefile.pcmachine set PCStatus=0 where LastOnline < SUBDATE(now(),interval 600 second) + + + + + \ No newline at end of file