commit 814c40bd683ac8ecb4b0e31453d9777161aebd30 Author: linjj <850658129@qq.com> Date: Tue Jun 24 11:19:51 2025 +0800 初始化 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e3ec5ad --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +springboot项目集成工具: +mvc +mybatis-plus +mybatis-plus分页 +springTest +logback日志 +全局异常 +knife4j API界面 +druid数据库监控界面 +redis +拦截器 \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..07cecb1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,164 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.8.RELEASE + + + com.example + springbootDemo + 0.0.1-SNAPSHOT + springbootDemo + springbootDemo + + 1.8 + true + 3.4.1 + 1.2.1 + 2.0.9 + 2.0.11 + 2.6.0 + 2.1.7 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatisPlus.version} + + + com.baomidou + mybatis-plus-generator + ${mybatisPlus.version} + + + mysql + mysql-connector-java + + + mysql + mysql-connector-java + 8.0.28 + + + org.bgee.log4jdbc-log4j2 + log4jdbc-log4j2-jdbc4.1 + 1.16 + + + com.alibaba + druid + 1.2.4 + compile + + + + com.alibaba + druid-spring-boot-starter + ${alibabadruid.version} + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.3.0 + + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j.version} + + + + com.alibaba + fastjson + ${fastjson.version} + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.apache.commons + commons-pool2 + ${commons-pool2.version} + + + + com.lowagie + itext + 2.1.7 + + + org.eclipse.birt.runtime.3_7_1 + com.lowagie.text + 2.1.7 + + + + + com.microsoft.sqlserver + sqljdbc4 + 4.0 + + + org.apache.commons + commons-lang3 + 3.10 + + + + + wsjz-releases + Releases Repository + http://localhost:8081/nexus/content/repositories/releases/ + + + wsjz-snapshots + Snapshot Repository + http://localhost:8081/nexus/content/repositories/snapshots/ + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + diff --git a/src/main/java/com/example/SpringbootDemoApplication.java b/src/main/java/com/example/SpringbootDemoApplication.java new file mode 100644 index 0000000..9760308 --- /dev/null +++ b/src/main/java/com/example/SpringbootDemoApplication.java @@ -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("------------------启动完成----------------------"); + } + +} diff --git a/src/main/java/com/example/aother/annotation/config/Knife4jConfiguration.java b/src/main/java/com/example/aother/annotation/config/Knife4jConfiguration.java new file mode 100644 index 0000000..26c4e3b --- /dev/null +++ b/src/main/java/com/example/aother/annotation/config/Knife4jConfiguration.java @@ -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 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; + } +} diff --git a/src/main/java/com/example/aother/annotation/config/MybatisPlusConfig.java b/src/main/java/com/example/aother/annotation/config/MybatisPlusConfig.java new file mode 100644 index 0000000..05c1453 --- /dev/null +++ b/src/main/java/com/example/aother/annotation/config/MybatisPlusConfig.java @@ -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; + } + +} diff --git a/src/main/java/com/example/aother/annotation/exception/Package.java b/src/main/java/com/example/aother/annotation/exception/Package.java new file mode 100644 index 0000000..1764b17 --- /dev/null +++ b/src/main/java/com/example/aother/annotation/exception/Package.java @@ -0,0 +1,4 @@ +package com.example.aother.annotation.exception; + +public class Package { +} diff --git a/src/main/java/com/example/aother/common/Package.java b/src/main/java/com/example/aother/common/Package.java new file mode 100644 index 0000000..63e582e --- /dev/null +++ b/src/main/java/com/example/aother/common/Package.java @@ -0,0 +1,4 @@ +package com.example.aother.common; + +public class Package { +} diff --git a/src/main/java/com/example/duplicate/controller/RcvBasicController.java b/src/main/java/com/example/duplicate/controller/RcvBasicController.java new file mode 100644 index 0000000..8e4e08e --- /dev/null +++ b/src/main/java/com/example/duplicate/controller/RcvBasicController.java @@ -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> 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); + } +} diff --git a/src/main/java/com/example/duplicate/controller/param/AddEmr.java b/src/main/java/com/example/duplicate/controller/param/AddEmr.java new file mode 100644 index 0000000..1359ce7 --- /dev/null +++ b/src/main/java/com/example/duplicate/controller/param/AddEmr.java @@ -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; +} diff --git a/src/main/java/com/example/duplicate/controller/param/PageRequest.java b/src/main/java/com/example/duplicate/controller/param/PageRequest.java new file mode 100644 index 0000000..17fefec --- /dev/null +++ b/src/main/java/com/example/duplicate/controller/param/PageRequest.java @@ -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; // 病人姓名 + +} diff --git a/src/main/java/com/example/duplicate/controller/param/SginBasicDto.java b/src/main/java/com/example/duplicate/controller/param/SginBasicDto.java new file mode 100644 index 0000000..0d1a14c --- /dev/null +++ b/src/main/java/com/example/duplicate/controller/param/SginBasicDto.java @@ -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; + + + +} diff --git a/src/main/java/com/example/duplicate/controller/vo/PageBasic.java b/src/main/java/com/example/duplicate/controller/vo/PageBasic.java new file mode 100644 index 0000000..b0bd13f --- /dev/null +++ b/src/main/java/com/example/duplicate/controller/vo/PageBasic.java @@ -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; + } + } + + +} diff --git a/src/main/java/com/example/duplicate/controller/vo/RcvBasic.java b/src/main/java/com/example/duplicate/controller/vo/RcvBasic.java new file mode 100644 index 0000000..f4c3ed4 --- /dev/null +++ b/src/main/java/com/example/duplicate/controller/vo/RcvBasic.java @@ -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; + + + + + + + +} diff --git a/src/main/java/com/example/duplicate/infrastructure/Package.java b/src/main/java/com/example/duplicate/infrastructure/Package.java new file mode 100644 index 0000000..4596f2d --- /dev/null +++ b/src/main/java/com/example/duplicate/infrastructure/Package.java @@ -0,0 +1,4 @@ +package com.example.duplicate.infrastructure; + +public class Package { +} diff --git a/src/main/java/com/example/duplicate/infrastructure/dao/BasicMapper.java b/src/main/java/com/example/duplicate/infrastructure/dao/BasicMapper.java new file mode 100644 index 0000000..c7ec09b --- /dev/null +++ b/src/main/java/com/example/duplicate/infrastructure/dao/BasicMapper.java @@ -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 getPageAll(PageRequest pageRequest); + + Boolean addBasic(SginBasicDto sginBasicDto); + + List getIDByPatientId(String patientId); + + Boolean UpdateState(@Param("patientId") String patientId, @Param("revoveryState") String revoveryState); + +} diff --git a/src/main/java/com/example/duplicate/service/RcvBasicService.java b/src/main/java/com/example/duplicate/service/RcvBasicService.java new file mode 100644 index 0000000..ba81a45 --- /dev/null +++ b/src/main/java/com/example/duplicate/service/RcvBasicService.java @@ -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> pageAll(PageRequest pageRequest); + + CommonResult UpdateSign(String patientId,String revoveryState); +} diff --git a/src/main/java/com/example/duplicate/service/impl/RcvBasicServiceImpl.java b/src/main/java/com/example/duplicate/service/impl/RcvBasicServiceImpl.java new file mode 100644 index 0000000..93ae298 --- /dev/null +++ b/src/main/java/com/example/duplicate/service/impl/RcvBasicServiceImpl.java @@ -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 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>pageAll(PageRequest pageRequest) { + PageResult pageResult = null; + try { + // 设置分页参数 + PageHelper.startPage(pageRequest.getPage(), pageRequest.getSize()); + List 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; + } +} diff --git a/src/main/java/com/example/utils/CommonResult.java b/src/main/java/com/example/utils/CommonResult.java new file mode 100644 index 0000000..4f54577 --- /dev/null +++ b/src/main/java/com/example/utils/CommonResult.java @@ -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 { + @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 + * @return + */ + public static CommonResult success(T data) { + return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); + } + + /** + * 成功返回结果 + * + * @param data 获取的数据 + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult success(T data, String message) { + return new CommonResult(ResultCode.SUCCESS.getCode(), message, data); + } + + /** + * 失败返回结果 + * + * @param errorCode 错误码 + * @param + * @return + */ + public static CommonResult failed(IErrorCode errorCode) { + return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null); + } + + /** + * 失败返回结果 + * + * @param errorCode 错误码 + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult failed(IErrorCode errorCode, String message) { + return new CommonResult(errorCode.getCode(), message, null); + } + + /** + * 失败返回结果 + * + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult failed(String message) { + return new CommonResult(ResultCode.FAILED.getCode(), message, null); + } + + + /** + * 失败返回结果 + * + * @param + * @return + */ + public static CommonResult failed() { + return failed(ResultCode.FAILED); + } + + /** + * 参数验证失败返回结果 + * + * @param + * @return + */ + public static CommonResult validateFailed() { + return failed(ResultCode.VALIDATE_FAILED); + } + + /** + * 提示信息 + * + * @param message 提示信息 + * @param + * @return + */ + public static CommonResult validateFailed(String message) { + return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null); + } + + /** + * 未登录返回结果 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult unauthorized(T data) { + return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); + } + + /** + * 重防及重复请求 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult preventreplay(T data) { + return new CommonResult(ResultCode.PREVENT_REPLAY.getCode(), ResultCode.PREVENT_REPLAY.getMessage(), data); + } + + /** + * 未授权返回结果 + * + * @param data 获取的数据 + * @param + * @return + */ + public static CommonResult forbidden(T data) { + return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); + } +} diff --git a/src/main/java/com/example/utils/IErrorCode.java b/src/main/java/com/example/utils/IErrorCode.java new file mode 100644 index 0000000..d1852ac --- /dev/null +++ b/src/main/java/com/example/utils/IErrorCode.java @@ -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(); +} diff --git a/src/main/java/com/example/utils/IpUtil.java b/src/main/java/com/example/utils/IpUtil.java new file mode 100644 index 0000000..7bec9a4 --- /dev/null +++ b/src/main/java/com/example/utils/IpUtil.java @@ -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; + } +} diff --git a/src/main/java/com/example/utils/Md5Util.java b/src/main/java/com/example/utils/Md5Util.java new file mode 100644 index 0000000..a357057 --- /dev/null +++ b/src/main/java/com/example/utils/Md5Util.java @@ -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 ""; + } +} diff --git a/src/main/java/com/example/utils/PageResult.java b/src/main/java/com/example/utils/PageResult.java new file mode 100644 index 0000000..040e3a3 --- /dev/null +++ b/src/main/java/com/example/utils/PageResult.java @@ -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 extends PageSerializable { + + @ApiModelProperty("页码") + private int pageNum; + @ApiModelProperty("每页的条数") + private int pageSize; + @ApiModelProperty("总页数") + private int pageCount; + + public PageResult() { + } + + public PageResult(List 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 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; + } +} diff --git a/src/main/java/com/example/utils/ResultCode.java b/src/main/java/com/example/utils/ResultCode.java new file mode 100644 index 0000000..d2b5446 --- /dev/null +++ b/src/main/java/com/example/utils/ResultCode.java @@ -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; + } + + +} diff --git a/src/main/java/com/example/utils/SnowflakeIdWorker.java b/src/main/java/com/example/utils/SnowflakeIdWorker.java new file mode 100644 index 0000000..fef3202 --- /dev/null +++ b/src/main/java/com/example/utils/SnowflakeIdWorker.java @@ -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; + /** + * 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) + */ + private final long maxWorkerId = -1L ^ (-1L << workerIdBits); + /** + * 支持的最大数据标识id,结果是31 + */ + private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); + /** + * 序列在id中占的位数 + */ + private final long sequenceBits = 12L; + /** + * 机器ID向左移12位 + */ + private final long workerIdShift = sequenceBits; + /** + * 数据标识id向左移17位(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); + } + } + + +} + + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..9bdefd9 --- /dev/null +++ b/src/main/resources/application.yml @@ -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 diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..aa49f35 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,51 @@ + + + + + + + + [%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%contextName] [%thread] [%X{traceId}] %-5level %logger{36} - %msg%n + + UTF-8 + + + + + + + toDayLog/log.log + + + + + + log/demo.%d.%i.log + + 15 + + + 10MB + + + + + + [%d{yyyy-MM-dd' 'HH:mm:ss.sss}] [%C] [%t] [%X{traceId}] [%L] [%-5p] %m%n + + utf-8 + + UTF-8 + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapper/BasicMapper.xml b/src/main/resources/mapper/BasicMapper.xml new file mode 100644 index 0000000..ba87f2e --- /dev/null +++ b/src/main/resources/mapper/BasicMapper.xml @@ -0,0 +1,31 @@ + + + + + INSERT INTO basic (patientId,admissTimes,disDate,name,sex, bedNumber,attendingName,revoveryState,revoveryTime) + values (#{patientId},#{admissTimes},#{disDate},#{name},#{sex},#{bedNumber},#{attendingName},#{revoveryState}, #{revoveryTime}) + + + update basic set revoveryState=#{revoveryState}, revoveryTime=NOW() where patientId=#{patientId} + + + + + + \ No newline at end of file diff --git a/src/test/java/com/example/DemoApplicationTests.java b/src/test/java/com/example/DemoApplicationTests.java new file mode 100644 index 0000000..28017da --- /dev/null +++ b/src/test/java/com/example/DemoApplicationTests.java @@ -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 { + +}