初始化

master
linjj 4 weeks ago
commit 814c40bd68

@ -0,0 +1,11 @@
springboot项目集成工具
mvc
mybatis-plus
mybatis-plus分页
springTest
logback日志
全局异常
knife4j API界面
druid数据库监控界面
redis
拦截器

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springbootDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springbootDemo</name>
<description>springbootDemo</description>
<properties>
<java.version>1.8</java.version>
<skipTests>true</skipTests>
<mybatisPlus.version>3.4.1</mybatisPlus.version>
<alibabadruid.version>1.2.1</alibabadruid.version>
<knife4j.version>2.0.9</knife4j.version>
<fastjson.version>2.0.11</fastjson.version>
<commons-pool2.version>2.6.0</commons-pool2.version>
<itext.version>2.1.7</itext.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatisPlus.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>${mybatisPlus.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>org.bgee.log4jdbc-log4j2</groupId>
<artifactId>log4jdbc-log4j2-jdbc4.1</artifactId>
<version>1.16</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.4</version>
<scope>compile</scope>
</dependency>
<!--druid监控-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${alibabadruid.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!-- swaggerui相关依赖 -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- spring2.X集成redis所需common-pool2-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>${commons-pool2.version}</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime.3_7_1</groupId>
<artifactId>com.lowagie.text</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>wsjz-releases</id>
<name>Releases Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>wsjz-snapshots</id>
<name>Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,19 @@
package com.example;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@MapperScan("com.example.duplicate.infrastructure.dao")
@Slf4j
public class SpringbootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootDemoApplication.class, args);
log.info("------------------启动完成----------------------");
}
}

@ -0,0 +1,57 @@
package com.example.aother.annotation.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import java.util.ArrayList;
import java.util.List;
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {
/**
* controller
*/
String controllerPackagePath = "com.example";
@Bean(value = "defaultApi2")
public Docket defaultApi2() {
List<Parameter> pars = new ArrayList<>();
ParameterBuilder tokenPar = new ParameterBuilder();
tokenPar.name("token")
.description("用户token")
.defaultValue("")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(false)
.build();
pars.add(tokenPar.build());
//添加head参数end
Docket docket=new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
//.title("swagger-bootstrap-ui-demo RESTful APIs")
.description("# swagger-bootstrap-ui-demo RESTful APIs")
.termsOfServiceUrl("www.codeleader.top")
.version("1.0")
.build())
.globalOperationParameters(pars)
//分组名称
.groupName("2.X版本")
.select()
//这里指定Controller扫描包路径
.apis(RequestHandlerSelectors.basePackage(controllerPackagePath))
.paths(PathSelectors.any())
.build();
return docket;
}
}

@ -0,0 +1,27 @@
package com.example.aother.annotation.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig{
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
paginationInnerInterceptor.setDbType(DbType.MYSQL);
paginationInnerInterceptor.setOverflow(true);
interceptor.addInnerInterceptor(paginationInnerInterceptor);
OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor = new OptimisticLockerInnerInterceptor();
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor);
return interceptor;
}
}

@ -0,0 +1,4 @@
package com.example.aother.annotation.exception;
public class Package {
}

@ -0,0 +1,4 @@
package com.example.aother.common;
public class Package {
}

@ -0,0 +1,51 @@
package com.example.duplicate.controller;
import com.example.duplicate.controller.param.PageRequest;
import com.example.duplicate.controller.vo.PageBasic;
import com.example.duplicate.controller.vo.RcvBasic;
import com.example.duplicate.service.RcvBasicService;
import com.example.utils.CommonResult;
import com.example.utils.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @ClassName RcvBasicController
* @Description
* @Author linjj
* @Date 2025/6/20 12:21
* @Version 1.0
*/
@RestController
@RequestMapping("/rcv/basic")
@Api(value = "示踪接口", tags = "示踪接口")
@Slf4j
public class RcvBasicController {
@Autowired
private RcvBasicService rcvBasicService;
@ApiOperation("签收接口")
@PostMapping("/Sign")
public CommonResult<?> Sign(String patientId) {
return rcvBasicService.Sign(patientId);
}
@ApiOperation("分页查询")
@PostMapping("/pageAll")
public CommonResult<PageResult<PageBasic>> pageAll(@RequestBody PageRequest pageRequest) {
return rcvBasicService.pageAll(pageRequest);
}
@ApiOperation("修改签收状态")
@PostMapping("/UpdateSign")
public CommonResult<?> UpdateSign(@RequestParam @ApiParam(required = false, name = "patientId", value = "患者patientId")String patientId,
@RequestParam @ApiParam(required = false, name = "revoveryState", value = "签收状态")String revoveryState) {
return rcvBasicService.UpdateSign(patientId,revoveryState);
}
}

@ -0,0 +1,29 @@
package com.example.duplicate.controller.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @ClassName AddEmr
* @Description 2.0
* @Author linjj
* @Date 2025/6/22 14:51
* @Version 1.0
*/
@Data
public class AddEmr {
@ApiModelProperty(value = "住院次数")
private Integer admissTimes;
@ApiModelProperty(value = "住院号")
private String inpatientNo;
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "性别")
private String sex;
@ApiModelProperty(value = "出院日期")
private Date disDate;
@ApiModelProperty(value = "主治医师")
private String attending;
}

@ -0,0 +1,21 @@
package com.example.duplicate.controller.param;
import lombok.Data;
/**
* @ClassName PageRequest
* @Description
* @Author linjj
* @Date 2025/6/20 21:43
* @Version 1.0
*/
@Data
public class PageRequest {
private int page; // 页码通常从1开始
private int size; // 每页大小
private String patientId; // 病人ID
private String name; // 病人姓名
}

@ -0,0 +1,49 @@
package com.example.duplicate.controller.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @ClassName SginBasic
* @Description
* @Author linjj
* @Date 2025/6/20 19:24
* @Version 1.0
*/
@Data
public class SginBasicDto {
@ApiModelProperty(value = "病案主键")
private String patientId;
@ApiModelProperty(value = "住院次数")
private Integer admissTimes;
@ApiModelProperty(value = "出院日期")
private Date disDate;
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "性别")
private String sex;
@ApiModelProperty(value = "住院医师")
private String attendingName;
@ApiModelProperty(value = "床位号")
private String bedNumber;
@ApiModelProperty(value = "回收时间")
private Date revoveryTime;
@ApiModelProperty(value = "回收状态")
private String revoveryState;
}

@ -0,0 +1,80 @@
package com.example.duplicate.controller.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
/**
* @ClassName PageBasic
* @Description
* @Author linjj
* @Date 2025/6/20 21:46
* @Version 1.0
*/
@Data
public class PageBasic {
@ApiModelProperty(value = "病案主键")
private String patientId;
@ApiModelProperty(value = "住院次数")
private Integer admissTimes;
@ApiModelProperty(value = "出院日期")
private Date disDate;
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "性别")
private String sex;
@ApiModelProperty(value = "住院医师")
private String attendingName;
@ApiModelProperty(value = "床位号")
private String bedNumber;
@ApiModelProperty(value = "出院天数")
private Integer outNum;
@ApiModelProperty(value = "回收时间")
private Date revoveryTime;
@ApiModelProperty(value = "回收状态")
private String revoveryState;
// 格式化 disDate
public String getFormattedDisDate() {
if (disDate != null) {
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return formatter.format(disDate);
} catch (Exception e) {
return null;
}
} else {
return null;
}
}
// 格式化 revoveryTime
public String getFormattedRevoveryTime() {
if (revoveryTime != null) {
try {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return formatter.format(revoveryTime);
} catch (Exception e) {
return null;
}
} else {
return null;
}
}
}

@ -0,0 +1,55 @@
package com.example.duplicate.controller.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import java.util.Date;
/**
*
*
* @author AutoGenerator
* @since 2023-09-13
*/
@Data
public class RcvBasic {
@ApiModelProperty(value = "病案主键")
private String patientId;
@ApiModelProperty(value = "住院次数")
private Integer admissTimes;
@ApiModelProperty(value = "出院日期")
private Date disDate;
@ApiModelProperty(value = "姓名")
private String name;
@ApiModelProperty(value = "性别")
private String sex;
@ApiModelProperty(value = "住院医师")
private String attendingName;
@ApiModelProperty(value = "床位号")
private String bedNumber;
@ApiModelProperty(value = "出院天数")
private String outNum;
@ApiModelProperty(value = "回收时间")
private Date revoveryTime;
@ApiModelProperty(value = "回收状态")
private String revoveryState;
}

@ -0,0 +1,4 @@
package com.example.duplicate.infrastructure;
public class Package {
}

@ -0,0 +1,30 @@
package com.example.duplicate.infrastructure.dao;
import com.example.duplicate.controller.param.PageRequest;
import com.example.duplicate.controller.param.SginBasicDto;
import com.example.duplicate.controller.vo.PageBasic;
import com.example.duplicate.controller.vo.RcvBasic;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @InterfaceName BasicMapper
* @Description
* @Author linjj
* @Date 2025/6/20 13:23
* @Version 1.0
*/
@Mapper
public interface BasicMapper {
List<PageBasic> getPageAll(PageRequest pageRequest);
Boolean addBasic(SginBasicDto sginBasicDto);
List<String> getIDByPatientId(String patientId);
Boolean UpdateState(@Param("patientId") String patientId, @Param("revoveryState") String revoveryState);
}

@ -0,0 +1,25 @@
package com.example.duplicate.service;
import com.example.duplicate.controller.param.PageRequest;
import com.example.duplicate.controller.vo.PageBasic;
import com.example.duplicate.controller.vo.RcvBasic;
import com.example.utils.CommonResult;
import com.example.utils.PageResult;
import org.springframework.web.bind.annotation.RequestBody;
/**
* @InterfaceName RcvBasicService
* @Description
* @Author linjj
* @Date 2025/6/20 12:24
* @Version 1.0
*/
public interface RcvBasicService {
CommonResult<?> Sign(String patientId);
CommonResult<PageResult<PageBasic>> pageAll(PageRequest pageRequest);
CommonResult<?> UpdateSign(String patientId,String revoveryState);
}

@ -0,0 +1,185 @@
package com.example.duplicate.service.impl;
import com.example.duplicate.controller.param.PageRequest;
import com.example.duplicate.controller.param.SginBasicDto;
import com.example.duplicate.controller.vo.PageBasic;
import com.example.duplicate.controller.vo.RcvBasic;
import com.example.duplicate.infrastructure.dao.BasicMapper;
import com.example.duplicate.service.RcvBasicService;
import com.example.utils.CommonResult;
import com.example.utils.PageResult;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.sql.*;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @ClassName RcvBasicServiceImpl
* @Description
* @Author linjj
* @Date 2025/6/20 12:25
* @Version 1.0
*/
@Service
@Slf4j
public class RcvBasicServiceImpl implements RcvBasicService {
@Autowired
private BasicMapper basicMapper;
@Override
public CommonResult<?> Sign(String patientId) {
try {
if (StringUtils.isBlank(patientId)){
return CommonResult.failed("病案号不能为空!");
}
//查询是否已经存在数据,存在数据不在新增,直接返回已经签收
List<String> idByPatientId = basicMapper.getIDByPatientId(patientId);
if (!CollectionUtils.isEmpty(idByPatientId)) {
return CommonResult.failed("病案ID【" + patientId + "】已签收过,不能重复签收");
}
SginBasicDto sginBasicDto=new SginBasicDto();
// SQL Server连接信息
String url = "jdbc:sqlserver://10.1.1.21:1433;databaseName=trasen;encrypt=false;useUnicode=true;characterEncoding=utf-8";
String username = "SZJK";
String password = "SZJK";
// String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=trasen;encrypt=false;useUnicode=true;characterEncoding=utf-8";
// String username = "sa";
// String password = "admin123";
// SQL语句根据patientId查询患者基础信息
String selectQuery = "SELECT * FROM dbo.V_sz_cybrxx WHERE 病案号='" + patientId + "'";
log.info("查询语句为:"+selectQuery);
// 1. 加载SQL Server JDBC驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 2. 建立数据库连接
Connection connection = DriverManager.getConnection(url, username, password);
// 3. 创建Statement对象用于执行SQL语句
Statement statement = connection.createStatement();
// 4. 执行查询操作
ResultSet resultSet = statement.executeQuery(selectQuery);
// 5. 处理查询结果并映射到RcvBasicVO对象
while (resultSet.next()) {
sginBasicDto.setPatientId(resultSet.getString("病案号"));
sginBasicDto.setAdmissTimes(resultSet.getInt("住院次数"));
sginBasicDto.setDisDate(resultSet.getDate("出院日期"));
sginBasicDto.setName(resultSet.getString("姓名"));
String sex = resultSet.getString("性别");
if (sex.equals("1")){
sginBasicDto.setSex("男");
}
if (sex.equals("2")){
sginBasicDto.setSex("女");
}
if (sex.equals("3")){
sginBasicDto.setSex("不详");
}
sginBasicDto.setBedNumber(resultSet.getString("床位号"));
sginBasicDto.setAttendingName(resultSet.getString("责任人"));
sginBasicDto.setRevoveryState("已签收");
sginBasicDto.setRevoveryTime(new Timestamp(System.currentTimeMillis()));
}
// 6. 关闭资源
resultSet.close();
statement.close();
connection.close();
//先插入数据到2.0中
if (!getObjectCommonResult(sginBasicDto)){
log.error("传送到病案数码系统失败");
return CommonResult.failed("传送到病案数码系统失败,请联系管理员");
}
//插入数据
if (!basicMapper.addBasic(sginBasicDto)){
log.error("签收失败");
return CommonResult.failed("签收失败");
}
} catch (Exception e) {
log.error("签收失败: " + e,e.getMessage());
return CommonResult.failed("签收失败: " + e.getMessage());
}
return CommonResult.success("签收完成");
}
private Boolean getObjectCommonResult(SginBasicDto sginBasicDto) {
// SQL Server连接信息
// String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=gm_record;encrypt=false;useUnicode=true;characterEncoding=utf-8";
// String username = "sa";
// String password = "admin123";
String url = "jdbc:sqlserver://10.1.1.147:1433;databaseName=csssemrrcord;encrypt=false;useUnicode=true;characterEncoding=utf-8";
String username = "sa";
String password = "xjgs+docus911";
// 插入语句
String insertQuery = "INSERT INTO commomtable (patient_id,admiss_times, inpatient_no, name, sex, dis_date, attending) VALUES (replace(newid(), '-', ''),?, ?, ?, ?, ?, ?);";
log.info("执行的SQL语句为: " + insertQuery);
try {
// 1. 加载SQL Server JDBC驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// 2. 建立数据库连接
Connection connection = DriverManager.getConnection(url, username, password);
// 3. 创建PreparedStatement对象用于执行SQL语句
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
// 4. 设置参数
preparedStatement.setInt(1, sginBasicDto.getAdmissTimes());
preparedStatement.setString(2, sginBasicDto.getPatientId());
preparedStatement.setString(3, sginBasicDto.getName());
preparedStatement.setString(4, sginBasicDto.getSex());
preparedStatement.setDate(5, new java.sql.Date(sginBasicDto.getDisDate().getTime()));
preparedStatement.setString(6, sginBasicDto.getAttendingName());
// 5. 执行插入操作
preparedStatement.executeUpdate();
// 6. 关闭资源
preparedStatement.close();
connection.close();
} catch (Exception e) {
log.error("传送到病案数码系统失败: " + e,e.getMessage());
return false;
}
log.info("插入2.0中成功");
return true;
}
@Override
public CommonResult<PageResult<PageBasic>>pageAll(PageRequest pageRequest) {
PageResult<PageBasic> pageResult = null;
try {
// 设置分页参数
PageHelper.startPage(pageRequest.getPage(), pageRequest.getSize());
List<PageBasic> pageAll = basicMapper.getPageAll(pageRequest);
pageResult = new PageResult<>(pageAll);
} catch (Exception e) {
log.error("系统异常: " + e.getMessage());
return CommonResult.failed("系统异常");
}
return CommonResult.success(pageResult);
}
@Override
public CommonResult<?> UpdateSign(String patientId,String revoveryState) {
if (revoveryState.equals("已签收")){
basicMapper.UpdateState(patientId,"未签收");
return CommonResult.success("取消签收成功");
}
if (revoveryState.equals("未签收")){
basicMapper.UpdateState(patientId,"已签收");
return CommonResult.success("签收成功");
}
return null;
}
}

@ -0,0 +1,152 @@
package com.example.utils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*
* @author docus
* @date 2020/3/28 16:23
*/
@Data
@ApiModel("响应")
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> {
@ApiModelProperty("响应码")
private Integer code;
@ApiModelProperty("响应消息")
private String msg;
@ApiModelProperty("响应实体")
private T data;
public CommonResult(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> CommonResult<T> success(T data) {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
}
/**
*
*
* @param data
* @param message
* @param <T>
* @return
*/
public static <T> CommonResult<T> success(T data, String message) {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
}
/**
*
*
* @param errorCode
* @param <T>
* @return
*/
public static <T> CommonResult<T> failed(IErrorCode errorCode) {
return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
}
/**
*
*
* @param errorCode
* @param message
* @param <T>
* @return
*/
public static <T> CommonResult<T> failed(IErrorCode errorCode, String message) {
return new CommonResult<T>(errorCode.getCode(), message, null);
}
/**
*
*
* @param message
* @param <T>
* @return
*/
public static <T> CommonResult<T> failed(String message) {
return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
}
/**
*
*
* @param <T>
* @return
*/
public static <T> CommonResult<T> failed() {
return failed(ResultCode.FAILED);
}
/**
*
*
* @param <T>
* @return
*/
public static <T> CommonResult<T> validateFailed() {
return failed(ResultCode.VALIDATE_FAILED);
}
/**
*
*
* @param message
* @param <T>
* @return
*/
public static <T> CommonResult<T> validateFailed(String message) {
return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> CommonResult<T> unauthorized(T data) {
return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> CommonResult<T> preventreplay(T data) {
return new CommonResult<T>(ResultCode.PREVENT_REPLAY.getCode(), ResultCode.PREVENT_REPLAY.getMessage(), data);
}
/**
*
*
* @param data
* @param <T>
* @return
*/
public static <T> CommonResult<T> forbidden(T data) {
return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
}
}

@ -0,0 +1,12 @@
package com.example.utils;
/**
* @Description API
* @Author JacksonTu
* @Date 2020/3/28 16:26
*/
public interface IErrorCode {
Integer getCode();
String getMessage();
}

@ -0,0 +1,37 @@
package com.example.utils;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class IpUtil {
public static String getIp(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;
}
}

@ -0,0 +1,21 @@
package com.example.utils;
import java.security.MessageDigest;
public class Md5Util {
public static String encrypt(String dataStr) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(dataStr.getBytes("UTF8"));
byte[] s = m.digest();
StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length; i++) {
result.append(Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6));
}
return result.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}

@ -0,0 +1,79 @@
package com.example.utils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageSerializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/**
* @ClassName PageResult
* @Description
* @Author linjj
* @Date 2025/6/20 12:37
* @Version 1.0
*/
@ApiModel(
value = "PageResult对象",
description = "分页管理"
)
public class PageResult<T> extends PageSerializable<T> {
@ApiModelProperty("页码")
private int pageNum;
@ApiModelProperty("每页的条数")
private int pageSize;
@ApiModelProperty("总页数")
private int pageCount;
public PageResult() {
}
public PageResult(List<T> list) {
super(list);
if (list instanceof Page) {
Page page = (Page)list;
this.pageNum = page.getPageNum();
this.pageSize = page.getPageSize();
this.pageCount = page.getPages();
} else {
this.pageNum = 1;
this.pageSize = list.size();
this.pageCount = 1;
}
}
public PageResult(List<T> list, long total, int pageNum, int pageSize) {
this.setTotal(total);
this.pageNum = pageNum;
this.pageSize = pageSize;
this.pageCount = (int)((total + (long)pageSize - 1L) / (long)pageSize);
this.setList(list);
}
public int getPageNum() {
return this.pageNum;
}
public int getPageSize() {
return this.pageSize;
}
public int getPageCount() {
return this.pageCount;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
}

@ -0,0 +1,42 @@
package com.example.utils;
/**
* @Description API
* @Author JacksonTu
* @Date 2020/3/28 16:26
*/
public enum ResultCode implements IErrorCode {
SUCCESS(0, "操作成功"),
FAILED(500, "操作失败"),
VALIDATE_FAILED(404, "参数检验失败"),
UNAUTHORIZED(401, "暂未登录或token已经过期"),
FORBIDDEN(403, "没有相关权限"),
PREVENT_REPLAY(405,"重复请求"),
NOT_EXIST(601,"数据不存在"),
NOT_ENABLE(600,"数据未启用");
private Integer code;
private String message;
private ResultCode(Integer code, String message) {
this.code = code;
this.message = message;
}
@Override
public Integer getCode() {
return code;
}
@Override
public String getMessage() {
return message;
}
}

@ -0,0 +1,139 @@
package com.example.utils;
public class SnowflakeIdWorker {
/**
* (2015-01-01)
*/
private final long twepoch = 1420041600000L;
/**
* id
*/
private final long workerIdBits = 5L;
/**
* id
*/
private final long datacenterIdBits = 5L;
/**
* id31 ()
*/
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/**
* id31
*/
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/**
* id
*/
private final long sequenceBits = 12L;
/**
* ID12
*/
private final long workerIdShift = sequenceBits;
/**
* id17(12+5)
*/
private final long datacenterIdShift = sequenceBits + workerIdBits;
/**
* 22(5+5+12)
*/
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/**
* 4095 (0b111111111111=0xfff=4095)
*/
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
/**
* ID(0~31)
*/
private long workerId;
/**
* ID(0~31)
*/
private long datacenterId;
/**
* (0~4095)
*/
private long sequence = 0L;
/**
* ID
*/
private long lastTimestamp = -1L;
/**
*
* @param workerId ID (0~31)
* @param datacenterId ID (0~31)
*/
public SnowflakeIdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* ID (线)
* @return SnowflakeId
*/
public synchronized long nextId() {
long timestamp = timeGen();
// 如果当前时间小于上一次ID生成的时间戳说明系统时钟回退过这个时候应当抛出异常
if (timestamp < lastTimestamp) {
throw new RuntimeException(
String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
// 如果是同一时间生成的,则进行毫秒内序列
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
// 毫秒内序列溢出
if (sequence == 0) {
//阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
}
// 时间戳改变,毫秒内序列重置
else {
sequence = 0L;
}
// 上次生成ID的时间截
lastTimestamp = timestamp;
// 移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (datacenterId << datacenterIdShift) //
| (workerId << workerIdShift) //
| sequence;
}
/**
*
* @param lastTimestamp ID
* @return
*/
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
/**
*
* @return ()
*/
protected long timeGen() {
return System.currentTimeMillis();
}
public static void main(String[] args) throws InterruptedException {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 10; i++) {
long id = idWorker.nextId();
Thread.sleep(1);
System.out.println(id);
}
}
}

@ -0,0 +1,54 @@
server:
port: 8003
spring:
datasource:
url: jdbc:log4jdbc:mysql://127.0.0.1:3306/docus_recovery?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
type: com.alibaba.druid.pool.DruidDataSource
#加快springboot初始化延缓初始化加载
main:
lazy-initialization: true
#加快springboot初始化关闭jmx监控
jmx:
enabled: false
redis:
# Redis 服务器地址
host: localhost
# 连接端口号
port: 6379
# 数据库索引0 - 15
database: 0
# 连接超时时间(毫秒)
timeout: 10000
# lettuce 参数
lettuce:
pool:
# 最大连接数(使用负值表示没有限制) 默认为 8
max-active: 10
# 最大阻塞等待时间(使用负值表示没有限制) 默认为 -1 ms
max-wait: -1
# 最大空闲连接 默认为 8
max-idle: 5
# 最小空闲连接 默认为 0
min-idle: 0
mybatis:
mapper-locations: classpath*:mapper/*Mapper.xml
type-aliases-package: com.example.entity
# 控制台打印sql语句
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
logging:
config : classpath:logback-spring.xml
level:
com.example.mapper: debug
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-args: true
params: count=countSql

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,%i索引【从数字0开始递增】,,, -->
<!-- appender是configuration的子节点是负责写日志的组件。 -->
<!-- ConsoleAppender把日志输出到控制台 -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%contextName] [%thread] [%X{traceId}] %-5level %logger{36} - %msg%n</pattern>
<!-- 控制台也要使用UTF-8不要使用GBK否则会中文乱码 -->
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- RollingFileAppender滚动记录文件先将日志记录到指定文件当符合某个条件时将日志记录到其他文件 -->
<!-- 以下的大概意思是1.先按日期存日志日期变了将前一天的日志文件名重命名为XXX%日期%索引新的日志仍然是demo.log -->
<!-- 2.如果日期没有发生变化但是当前日志的文件大小超过1KB时对当前日志进行分割 重命名-->
<appender name="demolog" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>toDayLog/log.log</File>
<!-- rollingPolicy:当发生滚动时,决定 RollingFileAppender 的行为,涉及文件移动和重命名。 -->
<!-- TimeBasedRollingPolicy 最常用的滚动策略,它根据时间来制定滚动策略,既负责滚动也负责出发滚动 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 活动文件的名字会根据fileNamePattern的值每隔一段时间改变一次 -->
<!-- 文件名log/demo.2017-12-05.0.log -->
<fileNamePattern>log/demo.%d.%i.log</fileNamePattern>
<!-- 每产生一个日志文件该日志文件的保存期限为15天 -->
<maxHistory>15</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- maxFileSize:这是活动文件的大小默认值是10MB测试时可改成1KB看效果 -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<!-- pattern节点用来设置日志的输入格式 -->
<pattern>
[%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%C] [%t] [%X{traceId}] [%L] [%-5p] %m%n
</pattern>
<charset>utf-8</charset>
<!-- 记录日志的编码:此处设置字符集 - -->
<charset>UTF-8</charset>
</encoder>
</appender>
<!-- 控制台输出日志级别 -->
<root level="info">
<appender-ref ref="STDOUT" />
</root>
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
<!-- com.liyan为根包也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
<!-- 级别依次为【从高到低】FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger name="com.example" level="INFO">
<appender-ref ref="demolog" />
</logger>
</configuration>

@ -0,0 +1,31 @@
<?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.example.duplicate.infrastructure.dao.BasicMapper">
<insert id="addBasic">
INSERT INTO basic (patientId,admissTimes,disDate,name,sex, bedNumber,attendingName,revoveryState,revoveryTime)
values (#{patientId},#{admissTimes},#{disDate},#{name},#{sex},#{bedNumber},#{attendingName},#{revoveryState}, #{revoveryTime})
</insert>
<update id="UpdateState">
update basic set revoveryState=#{revoveryState}, revoveryTime=NOW() where patientId=#{patientId}
</update>
<select id="getPageAll" resultType="com.example.duplicate.controller.vo.PageBasic">
select *,DATEDIFF(NOW(), disDate) as outNum from basic
<where>
1=1
<if test="patientId != null and patientId!=''">
AND patientId=#{patientId}
</if>
<if test="name != null and name!=''">
AND name=#{name}
</if>
</where>
order by disDate DESC
</select>
<select id="getIDByPatientId" resultType="java.lang.String">
select patientId from basic where patientId=#{patientId}
</select>
</mapper>

@ -0,0 +1,16 @@
package com.example;
import com.example.utils.Md5Util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = com.example.SpringbootDemoApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DemoApplicationTests {
}
Loading…
Cancel
Save