wangweiqun пре 6 година
комит
5c12c24b0d
100 измењених фајлова са 12632 додато и 0 уклоњено
  1. 1159 0
      ehr-cloud/pom.xml
  2. 606 0
      ehr-ms-parent-pom/pom.xml
  3. 170 0
      pom.xml
  4. 32 0
      src/main/java/com.yihu.ehr/SvrEhrBasic.java
  5. 123 0
      src/main/java/com.yihu.ehr/basic/address/controller/AddressDictEndPoint.java
  6. 133 0
      src/main/java/com.yihu.ehr/basic/address/controller/AddressEndPoint.java
  7. 35 0
      src/main/java/com.yihu.ehr/basic/address/dao/AddressDictRepository.java
  8. 22 0
      src/main/java/com.yihu.ehr/basic/address/dao/AddressRepository.java
  9. 58 0
      src/main/java/com.yihu.ehr/basic/address/service/AddressDictService.java
  10. 128 0
      src/main/java/com.yihu.ehr/basic/address/service/AddressService.java
  11. 45 0
      src/main/java/com.yihu.ehr/basic/address/service/PoUtil.java
  12. 243 0
      src/main/java/com.yihu.ehr/basic/appointment/controller/CombinationEndPoint.java
  13. 280 0
      src/main/java/com.yihu.ehr/basic/appointment/controller/RegistrationEndPoint.java
  14. 17 0
      src/main/java/com.yihu.ehr/basic/appointment/dao/RegistrationDao.java
  15. 300 0
      src/main/java/com.yihu.ehr/basic/appointment/entity/Registration.java
  16. 220 0
      src/main/java/com.yihu.ehr/basic/appointment/service/CombinationService.java
  17. 68 0
      src/main/java/com.yihu.ehr/basic/appointment/service/RegistrationService.java
  18. 118 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppApiCategoryEndPoint.java
  19. 324 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppApiEndPoint.java
  20. 108 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppApiErrorCodeEndPoint.java
  21. 98 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppApiParameterEndPoint.java
  22. 98 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppApiResponseEndPoint.java
  23. 522 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppEndPoint.java
  24. 143 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppFeatureEndPoint.java
  25. 49 0
      src/main/java/com.yihu.ehr/basic/apps/controller/AppVersionEndPoint.java
  26. 79 0
      src/main/java/com.yihu.ehr/basic/apps/controller/UserAppEndPoint.java
  27. 11 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppApiCategoryDao.java
  28. 24 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppApiDao.java
  29. 14 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppApiErrorCodeDao.java
  30. 17 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppApiParameterDao.java
  31. 16 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppApiResponseDao.java
  32. 19 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppDao.java
  33. 16 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppFeatureDao.java
  34. 11 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppVersionRepository.java
  35. 17 0
      src/main/java/com.yihu.ehr/basic/apps/dao/AppsRelationDao.java
  36. 11 0
      src/main/java/com.yihu.ehr/basic/apps/dao/OauthClientDetailsDao.java
  37. 11 0
      src/main/java/com.yihu.ehr/basic/apps/dao/ReportCategoryAppRelationDao.java
  38. 11 0
      src/main/java/com.yihu.ehr/basic/apps/dao/RsAppResourceDao.java
  39. 11 0
      src/main/java/com.yihu.ehr/basic/apps/dao/RsAppResourceMetadataDao.java
  40. 33 0
      src/main/java/com.yihu.ehr/basic/apps/dao/UserAppDao.java
  41. 226 0
      src/main/java/com.yihu.ehr/basic/apps/model/App.java
  42. 234 0
      src/main/java/com.yihu.ehr/basic/apps/model/AppApi.java
  43. 126 0
      src/main/java/com.yihu.ehr/basic/apps/model/AppApiParameter.java
  44. 90 0
      src/main/java/com.yihu.ehr/basic/apps/model/AppApiResponse.java
  45. 169 0
      src/main/java/com.yihu.ehr/basic/apps/model/AppFeature.java
  46. 81 0
      src/main/java/com.yihu.ehr/basic/apps/model/AppsRelation.java
  47. 104 0
      src/main/java/com.yihu.ehr/basic/apps/model/OrgApp.java
  48. 142 0
      src/main/java/com.yihu.ehr/basic/apps/model/UserApp.java
  49. 26 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppApiCategoryService.java
  50. 18 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppApiErrorCodeService.java
  51. 47 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppApiParameterService.java
  52. 47 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppApiResponseService.java
  53. 247 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppApiService.java
  54. 106 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppFeatureService.java
  55. 285 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppService.java
  56. 28 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppVersionService.java
  57. 43 0
      src/main/java/com.yihu.ehr/basic/apps/service/AppsRelationService.java
  58. 14 0
      src/main/java/com.yihu.ehr/basic/apps/service/OauthClientDetailsService.java
  59. 44 0
      src/main/java/com.yihu.ehr/basic/apps/service/UserAppService.java
  60. 26 0
      src/main/java/com.yihu.ehr/basic/config/TenantConfiguration.java
  61. 127 0
      src/main/java/com.yihu.ehr/basic/device/controller/DeviceEndPoint.java
  62. 16 0
      src/main/java/com.yihu.ehr/basic/device/dao/DeviceDao.java
  63. 89 0
      src/main/java/com.yihu.ehr/basic/device/service/DeviceService.java
  64. 843 0
      src/main/java/com.yihu.ehr/basic/dict/controller/ConventionalDictEndPoint.java
  65. 165 0
      src/main/java/com.yihu.ehr/basic/dict/controller/SystemDictEndPoint.java
  66. 204 0
      src/main/java/com.yihu.ehr/basic/dict/controller/SystemDictEntryEndPoint.java
  67. 56 0
      src/main/java/com.yihu.ehr/basic/dict/dao/SystemDictEntryRepository.java
  68. 27 0
      src/main/java/com.yihu.ehr/basic/dict/dao/SystemDictRepository.java
  69. 158 0
      src/main/java/com.yihu.ehr/basic/dict/service/SystemDictEntryService.java
  70. 77 0
      src/main/java/com.yihu.ehr/basic/dict/service/SystemDictService.java
  71. 277 0
      src/main/java/com.yihu.ehr/basic/emergency/controller/AmbulanceEndPoint.java
  72. 396 0
      src/main/java/com.yihu.ehr/basic/emergency/controller/AttendanceEndPoint.java
  73. 96 0
      src/main/java/com.yihu.ehr/basic/emergency/controller/LocationEndPoint.java
  74. 278 0
      src/main/java/com.yihu.ehr/basic/emergency/controller/ScheduleEndPoint.java
  75. 15 0
      src/main/java/com.yihu.ehr/basic/emergency/dao/AmbulanceDao.java
  76. 24 0
      src/main/java/com.yihu.ehr/basic/emergency/dao/AttendanceDao.java
  77. 13 0
      src/main/java/com.yihu.ehr/basic/emergency/dao/LocationDao.java
  78. 14 0
      src/main/java/com.yihu.ehr/basic/emergency/dao/ScheduleDao.java
  79. 86 0
      src/main/java/com.yihu.ehr/basic/emergency/service/AmbulanceService.java
  80. 102 0
      src/main/java/com.yihu.ehr/basic/emergency/service/AttendanceService.java
  81. 25 0
      src/main/java/com.yihu.ehr/basic/emergency/service/LocationService.java
  82. 238 0
      src/main/java/com.yihu.ehr/basic/emergency/service/ScheduleService.java
  83. 175 0
      src/main/java/com.yihu.ehr/basic/fileresource/controller/FileResourceEndPoint.java
  84. 101 0
      src/main/java/com.yihu.ehr/basic/fileresource/service/FileResource.java
  85. 106 0
      src/main/java/com.yihu.ehr/basic/fileresource/service/FileResourceManager.java
  86. 20 0
      src/main/java/com.yihu.ehr/basic/fileresource/service/XFileResourceRepository.java
  87. 80 0
      src/main/java/com.yihu.ehr/basic/fzopen/controller/OpenEndPoint.java
  88. 68 0
      src/main/java/com.yihu.ehr/basic/fzopen/service/OpenService.java
  89. 25 0
      src/main/java/com.yihu.ehr/basic/getui/ConstantUtil.java
  90. 91 0
      src/main/java/com.yihu.ehr/basic/getui/controller/AppPushMessageEndpoint.java
  91. 63 0
      src/main/java/com.yihu.ehr/basic/getui/controller/GeTuiClientEndpoint.java
  92. 40 0
      src/main/java/com.yihu.ehr/basic/getui/dao/GeTuiClientRepository.java
  93. 48 0
      src/main/java/com.yihu.ehr/basic/getui/model/GeTuiUserClient.java
  94. 367 0
      src/main/java/com.yihu.ehr/basic/getui/region_code.data
  95. 308 0
      src/main/java/com.yihu.ehr/basic/getui/service/AppPushMessageService.java
  96. 93 0
      src/main/java/com.yihu.ehr/basic/getui/service/GeTuiClientService.java
  97. 53 0
      src/main/java/com.yihu.ehr/basic/government/controller/GovernmentBrowseLogEndPoint.java
  98. 110 0
      src/main/java/com.yihu.ehr/basic/government/controller/GovernmentMenuEndPoint.java
  99. 55 0
      src/main/java/com.yihu.ehr/basic/government/controller/GovernmentMenuReportMonitorTypeEndPoint.java
  100. 0 0
      src/main/java/com.yihu.ehr/basic/government/dao/GovernmentBrowseLogRepository.java

+ 1159 - 0
ehr-cloud/pom.xml

@ -0,0 +1,1159 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yihu.ehr</groupId>
    <artifactId>ehr-cloud</artifactId>
    <version>1.2.0</version>
    <packaging>pom</packaging>
    <name>ehr-cloud</name>
    <description>EHR parent pom for all</description>
    <url>http://ehr.yihu.com</url>
    <organization>
        <name>JKZL Software, Inc.</name>
        <url>http://www.yihu.com</url>
    </organization>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <id>sand</id>
            <name>Sand Wen</name>
            <email>sand.fj.wen@gmail.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project lead</role>
                <role>Project designer</role>
                <role>Project programmer</role>
            </roles>
        </developer>
        <developer>
            <id>yzh</id>
            <name>叶泽华</name>
            <email>yzh@qq.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project programmer</role>
            </roles>
        </developer>
        <developer>
            <id>cws</id>
            <name>陈维山</name>
            <email>hill9868@qq.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project programmer</role>
            </roles>
        </developer>
        <developer>
            <id>hzy</id>
            <name>黄志勇</name>
            <email>hzy@qq.com</email>
            <organization>JKZL Software, Inc.</organization>
            <organizationUrl>http://www.yihu.com</organizationUrl>
            <roles>
                <role>Project programmer</role>
            </roles>
        </developer>
    </developers>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.spring-framework>4.3.13.RELEASE</version.spring-framework>
        <version.spring-boot>1.5.9.RELEASE</version.spring-boot>
        <version.spring-cloud-starter>1.3.2.RELEASE</version.spring-cloud-starter>
        <version.spring-cloud>1.4.2.RELEASE</version.spring-cloud>
        <version.spring-security>4.2.3.RELEASE</version.spring-security>
        <version.spring-oauth2>2.0.14.RELEASE</version.spring-oauth2>
        <version.spring-session>1.3.1.RELEASE</version.spring-session>
        <version.spring-session-hazelcast>2.0.1.RELEASE</version.spring-session-hazelcast>
        <version.spring-data-commons>1.13.9.RELEASE</version.spring-data-commons>
        <version.spring-data-hadoop>2.2.0.RELEASE</version.spring-data-hadoop>
        <version.spring-data-solr>2.1.3.RELEASE</version.spring-data-solr>
        <version.spring-data-redis>1.7.1.RELEASE</version.spring-data-redis>
        <version.spring-data-jpa>1.11.10.RELEASE</version.spring-data-jpa>
        <version.spring-kafka>1.0.5.RELEASE</version.spring-kafka>
        <version.commons-bean-utils>1.9.2</version.commons-bean-utils>
        <version.commons-codec>1.9</version.commons-codec>
        <version.commons-collections>3.2.1</version.commons-collections>
        <version.commons-compress>1.9</version.commons-compress>
        <version.commons-dbcp2>2.1.1</version.commons-dbcp2>
        <version.commons-dbutils>1.6</version.commons-dbutils>
        <version.commons-io>2.4</version.commons-io>
        <version.commons-lang3>3.2.1</version.commons-lang3>
        <version.commons-pool2>2.4.2</version.commons-pool2>
        <version.zookeeper>3.4.6</version.zookeeper>
        <version.hadoop-client>2.6.5</version.hadoop-client>
        <version.hbase-client>1.1.1</version.hbase-client>
        <version.solr>5.5.4</version.solr>
        <version.hibernate>4.3.11.Final</version.hibernate>
        <version.hibernate-validator>6.0.10.Final</version.hibernate-validator>
        <version.hibernate-jpa-api>1.0.0.Final</version.hibernate-jpa-api>
        <version.http-core>4.4.3</version.http-core>
        <version.http-client>4.5.1</version.http-client>
        <version.http-mime>4.5.1</version.http-mime>
        <version.io-dropwizard-metrics>3.1.2</version.io-dropwizard-metrics>
        <version.java>1.8</version.java>
        <version.jackson>2.6.6</version.jackson>
        <version.jedis>2.9.0</version.jedis>
        <version.jcl-over-slf4j>1.7.19</version.jcl-over-slf4j>
        <version.jul-over-slf4j>1.7.21</version.jul-over-slf4j>
        <version.joda-time>2.8.2</version.joda-time>
        <version.junit>4.12</version.junit>
        <version.logging>1.2</version.logging>
        <version.log4j>1.2.17</version.log4j>
        <version.log4j2>2.4.1</version.log4j2>
        <version.logback>1.1.7</version.logback>
        <version.mysql>5.1.45</version.mysql>
        <version.pinyin4j>2.5.0</version.pinyin4j>
        <version.quartz>2.2.3</version.quartz>
        <version.servlet-api>3.1.0</version.servlet-api>
        <version.slf4j>1.7.21</version.slf4j>
        <version.statsd-client>3.1.0</version.statsd-client>
        <version.swagger>2.7.0</version.swagger>
        <version.swagger-ui>2.7.0</version.swagger-ui>
        <version.thrift>0.9.1</version.thrift>
        <version.tomcat-embed>8.5.27</version.tomcat-embed>
        <version.websocket-api>1.1</version.websocket-api>
        <version.zip4j>1.3.2</version.zip4j>
        <version.poi>3.12</version.poi>
        <version.scala>2.10.6</version.scala>
        <version.elasticsearch>2.1.0</version.elasticsearch>
        <version.elasticsearch-sql>2.4.1.0</version.elasticsearch-sql>
        <version.jest>2.4.0</version.jest>
        <version.alibaba-druid>1.0.15</version.alibaba-druid>
        <version.feign>9.5.0</version.feign>
        <version.hystrix>1.5.10</version.hystrix>
        <version.archaius>0.7.5</version.archaius>
        <version.ehr>1.2.0</version.ehr>
        <version.eip>1.3.1</version.eip>
        <version.json>20160212</version.json>
        <version.json-lib>2.4</version.json-lib>
        <version.fastjson>1.2.17</version.fastjson>
        <version.commons-net>3.3</version.commons-net>
        <version.jxl>2.6</version.jxl>
        <version.fastdfs>1.27</version.fastdfs>
        <version.spring.boot.admin>1.5.7</version.spring.boot.admin>
        <version.jettison>1.3.7</version.jettison>
    </properties>
    <dependencyManagement>
        <dependencies>
            <!--<dependency>-->
                <!--<groupId>org.springframework.boot</groupId>-->
                <!--<artifactId>spring-boot-dependencies</artifactId>-->
                <!--<version>1.5.9.RELEASE</version>-->
                <!--<type>pom</type>-->
                <!--<scope>import</scope>-->
            <!--</dependency>-->
            <!--<dependency>-->
                <!--<groupId>org.springframework.cloud</groupId>-->
                <!--<artifactId>spring-cloud-dependencies</artifactId>-->
                <!--<version>Finchley.M5</version>-->
                <!--<type>pom</type>-->
                <!--<scope>import</scope>-->
            <!--</dependency>-->
            <!-- Base library-->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                <version>${version.servlet-api}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${version.junit}</version>
                <scope>test</scope>
            </dependency>
            <!-- Spring framework family -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-messaging</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-oxm</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${version.spring-framework}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.springframework.kafka/spring-kafka -->
            <dependency>
                <groupId>org.springframework.kafka</groupId>
                <artifactId>spring-kafka</artifactId>
                <version>${version.spring-kafka}</version>
            </dependency>
            <!-- Spring boot family -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-actuator</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-autoconfigure</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-aop</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-batch</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
                <optional>true</optional>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${version.spring-boot}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-mongodb</artifactId>
                <version>${version.spring-boot}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Spring cloud family -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter</artifactId>
                <version>${version.spring-cloud-starter}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-config-server</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-archaius</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-config</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka-server</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-netflix-eureka</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-feign</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-ribbon</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-zuul</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
                <version>${version.spring-cloud}</version>
            </dependency>
            <!-- Feign -->
            <dependency>
                <groupId>io.github.openfeign</groupId>
                <artifactId>feign-core</artifactId>
                <version>${version.feign}</version>
            </dependency>
            <!-- Hystrix -->
            <dependency>
                <groupId>com.netflix.hystrix</groupId>
                <artifactId>hystrix-core</artifactId>
                <version>${version.hystrix}</version>
            </dependency>
            <!-- Archaius -->
            <dependency>
                <groupId>com.netflix.archaius</groupId>
                <artifactId>archaius-core</artifactId>
                <version>${version.archaius}</version>
            </dependency>
            <!-- Spring data family -->
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-commons</artifactId>
                <version>${version.spring-data-commons}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-hadoop-hbase</artifactId>
                <version>${version.spring-data-hadoop}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-solr</artifactId>
                <version>${version.spring-data-solr}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Spring session family-->
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session-hazelcast</artifactId>
                <version>${version.spring-session-hazelcast}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session</artifactId>
                <version>${version.spring-session}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.session</groupId>
                <artifactId>spring-session-data-redis</artifactId>
                <version>${version.spring-session}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Spring Security -->
            <!--<dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-core</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-crypto</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>${version.spring-security}</version>
                <scope>${dependency.scope}</scope>
            </dependency>-->
            <!-- Oauth2 -->
            <dependency>
                <groupId>org.springframework.security.oauth</groupId>
                <artifactId>spring-security-oauth2</artifactId>
                <version>${version.spring-oauth2}</version>
                <scope>${dependency.scope}</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.security</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!--Jackson library -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>${version.jackson}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>${version.jackson}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${version.jackson}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Http library -->
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpcore</artifactId>
                <version>${version.http-core}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>${version.http-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpmime</artifactId>
                <version>${version.http-mime}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!--Apache commons library -->
            <dependency>
                <groupId>org.codehaus.woodstox</groupId>
                <artifactId>stax2-api</artifactId>
                <version>3.1.4</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.codehaus.woodstox</groupId>
                <artifactId>woodstox-core-asl</artifactId>
                <version>4.4.1</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.noggit</groupId>
                <artifactId>noggit</artifactId>
                <version>0.6</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${version.commons-lang3}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>${version.poi}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
                <version>${version.commons-bean-utils}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-pool2</artifactId>
                <version>${version.commons-pool2}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>${version.commons-dbutils}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-dbcp2</artifactId>
                <version>${version.commons-dbcp2}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>${version.commons-io}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-collections</groupId>
                <artifactId>commons-collections</artifactId>
                <version>${version.commons-collections}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>${version.commons-codec}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-compress</artifactId>
                <version>${version.commons-compress}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Mysql library -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${version.mysql}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Hibernate framework library -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>${version.hibernate}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>${version.hibernate-validator}</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>${version.hibernate}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.1-api</artifactId>
                <version>${version.hibernate-jpa-api}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Zookeeper library -->
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>${version.zookeeper}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Hadoop library -->
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-annotations</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-auth</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-distcp</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-hdfs</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-core</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-jobclient</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-mapreduce-client-shuffle</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-streaming</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-api</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-client</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-server-common</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hadoop</groupId>
                <artifactId>hadoop-yarn-server-nodemanager</artifactId>
                <version>${version.hadoop-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-client</artifactId>
                <version>${version.hbase-client}</version>
                <scope>${dependency.scope}</scope>
                <exclusions>
                    <exclusion>
                        <groupId>org.apache.hadoop</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-common</artifactId>
                <version>${version.hbase-client}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-protocol</artifactId>
                <version>${version.hbase-client}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-log4j12</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!-- export library -->
            <dependency>
                <groupId>net.sourceforge.jexcelapi</groupId>
                <artifactId>jxl</artifactId>
                <version>${version.jxl}</version>
            </dependency>
            <!-- Google library -->
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>18.0</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>jsr305</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.6.2</version>
            </dependency>
            <dependency>
                <groupId>com.google.protobuf</groupId>
                <artifactId>protobuf-java</artifactId>
                <version>2.5.0</version>
            </dependency>
            <dependency>
                <groupId>com.google.inject</groupId>
                <artifactId>guice</artifactId>
                <version>4.1.0</version>
            </dependency>
            <!-- Solr library -->
            <dependency>
                <groupId>org.apache.solr</groupId>
                <artifactId>solr-core</artifactId>
                <version>${version.solr}</version>
                <scope>${dependency.scope}</scope>
                <exclusions>
                    <exclusion>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.solr</groupId>
                <artifactId>solr-solrj</artifactId>
                <version>${version.solr}</version>
                <exclusions>
                    <exclusion>
                        <groupId>commons-lang</groupId>
                        <artifactId>commons-lang</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <!-- Elasticsearch -->
            <dependency>
                <groupId>org.elasticsearch</groupId>
                <artifactId>elasticsearch</artifactId>
                <version>${version.elasticsearch}</version>
            </dependency>
            <dependency>
                <groupId>org.nlpcn</groupId>
                <artifactId>elasticsearch-sql</artifactId>
                <version>${version.elasticsearch-sql}</version>
            </dependency>
            <!-- Jest -->
            <dependency>
                <groupId>io.searchbox</groupId>
                <artifactId>jest</artifactId>
                <version>${version.jest}</version>
            </dependency>
            <!-- Redis library -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>${version.jedis}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- FastDFS library -->
            <dependency>
                <groupId>org.csource</groupId>
                <artifactId>fastdfs-client-java</artifactId>
                <version>${version.fastdfs}</version>
            </dependency>
            <!-- Quartz library -->
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz</artifactId>
                <version>${version.quartz}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.quartz-scheduler</groupId>
                <artifactId>quartz-jobs</artifactId>
                <version>${version.quartz}</version>
            </dependency>
            <!-- Zip library -->
            <dependency>
                <groupId>net.lingala.zip4j</groupId>
                <artifactId>zip4j</artifactId>
                <version>${version.zip4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Pinyin library -->
            <dependency>
                <groupId>com.belerweb</groupId>
                <artifactId>pinyin4j</artifactId>
                <version>${version.pinyin4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Swagger-ui library -->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${version.swagger}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${version.swagger-ui}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- date Time util library -->
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>${version.joda-time}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.thrift</groupId>
                <artifactId>libthrift</artifactId>
                <version>${version.thrift}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>com.timgroup</groupId>
                <artifactId>java-statsd-client</artifactId>
                <version>${version.statsd-client}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>io.dropwizard.metrics</groupId>
                <artifactId>metrics-core</artifactId>
                <version>${version.io-dropwizard-metrics}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Log framework library -->
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>${version.logging}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${version.log4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${version.slf4j}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>${version.logback}</version>
                <scope>${dependency.scope}</scope>
            </dependency>
            <!-- Alibaba -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>${version.alibaba-druid}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${version.fastjson}</version>
            </dependency>
            <!-- Spring Boot Admin -->
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-server</artifactId>
                <version>${version.spring.boot.admin}</version>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-server-ui</artifactId>
                <version>${version.spring.boot.admin}</version>
            </dependency>
            <!-- Extend library-->
            <dependency>
                <groupId>org.codehaus.jettison</groupId>
                <artifactId>jettison</artifactId>
                <version>${version.jettison}</version>
            </dependency>
            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
                <version>${version.json}</version>
            </dependency>
            <dependency>
                <groupId>net.sf.json-lib</groupId>
                <artifactId>json-lib</artifactId>
                <version>${version.json-lib}</version>
            </dependency>
            <dependency>
                <groupId>commons-net</groupId>
                <artifactId>commons-net</artifactId>
                <version>${version.commons-net}</version>
            </dependency>
            <!-- 个推相关 -->
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-sdk-http</artifactId>
                <version>4.0.1.17</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-fastjson</artifactId>
                <version>1.0.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-sdk-base</artifactId>
                <version>4.0.0.22</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>gexin-rp-sdk-template</artifactId>
                <version>4.0.0.16</version>
            </dependency>
            <dependency>
                <groupId>com.gexin.platform</groupId>
                <artifactId>protobuf-java</artifactId>
                <version>2.5.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <repositories>
        <repository>
            <id>public</id>
            <name>public</name>
            <url>http://172.19.103.43:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>public</id>
            <name>public</name>
            <url>http://172.19.103.43:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>2.10</version>
            </extension>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-http-lightweight</artifactId>
                <version>2.10</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <verbose/>
                        <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>
                    </compilerArguments>
                </configuration>
                <version>3.1</version>
            </plugin>
        </plugins>
    </build>
</project>

+ 606 - 0
ehr-ms-parent-pom/pom.xml

@ -0,0 +1,606 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu.ehr</groupId>
        <artifactId>ehr-cloud</artifactId>
        <version>1.2.0</version>
        <relativePath>../ehr-cloud/pom.xml</relativePath>
    </parent>
    <artifactId>ehr-ms-parent-pom</artifactId>
    <packaging>pom</packaging>
    <description>EHR micro service parent pom</description>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq-codegen-maven</artifactId>
                    <version>${jooq.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.7</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <recompressZippedFiles>false</recompressZippedFiles>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.18</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-help-plugin</artifactId>
                    <version>2.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.10.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.7</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.3</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.3</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.doxia</groupId>
                            <artifactId>doxia-module-markdown</artifactId>
                            <version>1.5</version>
                        </dependency>
                    </dependencies>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.4</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.18.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.9.1</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.3.2</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.2</version>
                </plugin>
                <plugin>
                    <groupId>pl.project13.maven</groupId>
                    <artifactId>git-commit-id-plugin</artifactId>
                    <version>2.1.11</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${version.spring-boot}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <id>checkstyle-validation</id>
                        <phase>validate</phase>
                        <configuration>
                            <skip>true</skip>
                            <configLocation>src/checkstyle/checkstyle.xml</configLocation>
                            <suppressionsLocation>src/checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
                            <headerLocation>src/checkstyle/checkstyle-header.txt</headerLocation>
                            <propertyExpansion>checkstyle.build.directory=${project.build.directory}</propertyExpansion>
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>true</failsOnError>
                            <includeTestSourceDirectory>true</includeTestSourceDirectory>
                        </configuration>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${version.java}</source>
                    <target>${version.java}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>enforce-rules</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <requireJavaVersion>
                                    <version>[1.8,)</version>
                                </requireJavaVersion>
                                <!--<requireProperty>
                                    <property>main.basedir</property>
                                </requireProperty>-->
                                <!--<requireProperty>
                                    <property>project.organization.name</property>
                                </requireProperty>-->
                                <!--<requireProperty>
                                    <property>project.name</property>
                                </requireProperty>-->
                                <!--<requireProperty>
                                    <property>project.description</property>
                                </requireProperty>-->
                            </rules>
                            <fail>true</fail>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                    <excludes>
                        <exclude>**/Abstract*.java</exclude>
                    </excludes>
                    <!--<systemPropertyVariables>-->
                    <!--<java.security.egd>file:/dev/./urandom</java.security.egd>-->
                    <!--<java.awt.headless>true</java.awt.headless>-->
                    <!--</systemPropertyVariables>-->
                    <argLine>-Xmx1024m</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <configuration>
                    <skip>${disable.checks}</skip>
                    <signature>
                        <groupId>org.codehaus.mojo.signature</groupId>
                        <artifactId>java16</artifactId>
                        <version>1.0</version>
                    </signature>
                    <annotations>
                        <annotation>org.springframework.lang.UsesJava8</annotation>
                        <annotation>org.springframework.lang.UsesJava7</annotation>
                        <annotation>org.springframework.boot.lang.UsesUnsafeJava</annotation>
                    </annotations>
                </configuration>
                <executions>
                    <execution>
                        <id>enforce-java-6</id>
                        <phase>test</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>-->
        </plugins>
    </build>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-admin-gateway-model</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-elasticsearch</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-fastdfs</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-hbase</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-mysql</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-query</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-redis</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-data-solr</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-ehr-constants</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-entity</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <!--<dependency>-->
            <!--<groupId>com.yihu.ehr</groupId>-->
            <!--<artifactId>commons-metrics</artifactId>-->
            <!--<version>${version.ehr}</version>-->
            <!--</dependency>-->
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-profile-core</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-redis-mq</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-rest-model</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.hos</groupId>
                <artifactId>common-rest-model</artifactId>
                <version>${version.eip}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-ui-swagger</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-util</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-web</artifactId>
                <version>${version.ehr}</version>
            </dependency>
            <!--<dependency>
                <groupId>com.yihu.ehr</groupId>
                <artifactId>commons-metrics</artifactId>
                <version>${version.ehr}</version>
            </dependency>-->
        </dependencies>
    </dependencyManagement>
    <!--
    profiles分为三种场景(dev,test,prod),三种部署模式(jar,war,docker).预计是9种模式,
    但目前仅使用到dev,test,prod的jar,test的war.若有需要可以组合配置这些部署模式.
    - dev的可执行jar包,在本机调试,不需要配置wagon参数。
    - test,prod的可执行jar包,需要在编译后传送到服务器上部署,故需配置wagon参数,参数可根据服务需要自行配置。
    - dev,test,prod的war包,编译后使用tomcat api部署,故需配置tomcat参数,参数可根据服务需要自行配置。
    -->
    <profiles>
        <profile>
            <id>dev-jar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>jar</packaging.type>
                <dependency.scope>compile</dependency.scope>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </dependency>
                <!--<dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>-->
            </dependencies>
        </profile>
        <profile>
            <id>test-jar</id>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>jar</packaging.type>
                <dependency.scope>compile</dependency.scope>
                <wagonServerId/>
                <wagonUrl/>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>wagon-maven-plugin</artifactId>
                        <version>1.0</version>
                        <configuration>
                            <serverId>${wagonServerId}</serverId>
                            <fromFile>${project.build.directory}/${project.build.finalName}.jar</fromFile>
                            <url>${wagonUrl}</url>
                            <commands>
                                <command>pkill -f ${project.build.finalName}.jar</command>
                                <command>nohub java -Djava.security.egd=file:/dev/./urandom -jar
                                    ${project.build.finalName}.jar &amp;
                                </command>
                            </commands>
                            <displayCommandOutputs>true</displayCommandOutputs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>test-war</id>
            <activation>
                <property>
                    <name>spring.profiles.active</name>
                    <value>default,test</value>
                </property>
            </activation>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>war</packaging.type>
                <dependency.scope>provided</dependency.scope>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <scope>${dependency.scope}</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <url>http://localhost:8080/manager/text</url>
                            <server>tomcat8</server>
                            <username>deployer</username>
                            <password>jkzldeployer</password>
                            <path>/${project.artifactId}</path>
                            <update>true</update>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>prod-jar</id>
            <activation>
                <property>
                    <name>spring.profiles.active</name>
                    <value>default,prod</value>
                </property>
            </activation>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>war</packaging.type>
                <dependency.scope>compile</dependency.scope>
                <wagonServerId>11.1.2.21</wagonServerId>
                <wagonUrl>scp://user:password@11.1.2.21/home/root/ehr-release</wagonUrl>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <scope>${dependency.scope}</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </profile>
        <profile>
            <id>prod-war</id>
            <properties>
                <skipTests>true</skipTests>
                <packaging.type>war</packaging.type>
                <dependency.scope>provided</dependency.scope>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <scope>${dependency.scope}</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <scope>${dependency.scope}</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

+ 170 - 0
pom.xml

@ -0,0 +1,170 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu.ehr</groupId>
        <artifactId>ehr-ms-parent-pom</artifactId>
        <version>1.2.0</version>
        <relativePath>ehr-ms-parent-pom/pom.xml</relativePath>
    </parent>
    <artifactId>svr-basic</artifactId>
    <packaging>war</packaging>
    <properties>
        <wagonServerId>192.168.1.220</wagonServerId>
        <wagonUrl>scp://sand:timeneverstop@192.168.1.221/home/sand/ehr-release</wagonUrl>
        <springside.version>4.2.3-GA</springside.version>
    </properties>
    <dependencies>
        <!-- true -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-ehr-constants</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-util</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-mysql</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-rest-model</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-entity</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-ui-swagger</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-web</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-fastdfs</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-redis</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>
        <dependency>
            <groupId>org.nlpcn</groupId>
            <artifactId>elasticsearch-sql</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>io.searchbox</groupId>
            <artifactId>jest</artifactId>
            <version>${version.jest}</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.hos</groupId>
            <artifactId>common-rest-model</artifactId>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springside</groupId>
            <artifactId>springside-core</artifactId>
            <version>${springside.version}</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
            <artifactId>commons-data-query</artifactId>
            <scope>compile</scope>
        </dependency>
        <!--个推相关-->
        <dependency>
            <groupId>com.gexin.platform</groupId>
            <artifactId>gexin-rp-sdk-http</artifactId>
        </dependency>
        <dependency>
            <groupId>com.gexin.platform</groupId>
            <artifactId>gexin-rp-fastjson</artifactId>
        </dependency>
        <dependency>
            <groupId>com.gexin.platform</groupId>
            <artifactId>gexin-rp-sdk-base</artifactId>
        </dependency>
        <dependency>
            <groupId>com.gexin.platform</groupId>
            <artifactId>gexin-rp-sdk-template</artifactId>
        </dependency>
        <dependency>
            <groupId>com.gexin.platform</groupId>
            <artifactId>protobuf-java</artifactId>
        </dependency>
    </dependencies>
</project>

+ 32 - 0
src/main/java/com.yihu.ehr/SvrEhrBasic.java

@ -0,0 +1,32 @@
package com.yihu.ehr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
@Configuration
@EnableAutoConfiguration(exclude = {
		SecurityAutoConfiguration.class})
@ComponentScan
@EnableDiscoveryClient
@EnableFeignClients
@EnableSpringDataWebSupport
public class SvrEhrBasic extends SpringBootServletInitializer {
	public static void main(String[] args) {
		SpringApplication.run(SvrEhrBasic.class, args);
	}
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(SvrEhrBasic.class);
	}
}

+ 123 - 0
src/main/java/com.yihu.ehr/basic/address/controller/AddressDictEndPoint.java

@ -0,0 +1,123 @@
package com.yihu.ehr.basic.address.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.address.AddressDict;
import com.yihu.ehr.basic.address.service.AddressDictService;
import com.yihu.ehr.model.common.ObjectResult;
import com.yihu.ehr.model.geography.MGeographyDict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 *
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "Geography-Dict", description = "行政区划地址", tags = {"基础信息-行政区划地址"})
public class AddressDictEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AddressDictService geographyDictService;
    /**
     * 根据地址等级查询地址信息
     * @param level
     * @return
     */
    @RequestMapping(value = ServiceApi.Geography.AddressDictByLevel, method = RequestMethod.GET)
    @ApiOperation(value = "根据等级查询行政区划地址")
    public Collection<MGeographyDict> getAddressByLevel(
            @ApiParam(name = "level", value = "等级", defaultValue = "")
            @PathVariable(value = "level") Integer level) {
        List<AddressDict> addressDictList = geographyDictService.getLevelToAddr(level);
        return convertToModels(addressDictList,new ArrayList<>(addressDictList.size()), MGeographyDict.class,"");
    }
    @RequestMapping(value = ServiceApi.Geography.AddressDictByPid, method = RequestMethod.GET)
    @ApiOperation(value = "根据上级编号查询行政区划地址")
    public Collection<MGeographyDict> getAddressDictByPid(
        @ApiParam(name = "pid", value = "上级id", defaultValue = "")
        @PathVariable(value = "pid") Integer pid) {
        List<AddressDict> addressDictList = geographyDictService.getPidToAddr(pid);
        return convertToModels(addressDictList, new ArrayList<>(addressDictList.size()), MGeographyDict.class,"");
    }
    @RequestMapping(value = ServiceApi.Geography.AddressDict, method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询行政区划地址")
    public MGeographyDict getAddressDictById(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        AddressDict geographyDict =  geographyDictService.findById(id);
        return convertToModel(geographyDict, MGeographyDict.class);
    }
    @RequestMapping(value = ServiceApi.Geography.AddressDictList, method = RequestMethod.POST)
    @ApiOperation(value = "获取多条行政区划地址")
    public List<MGeographyDict> getAddressDictByIdList(
            @ApiParam(name = "idList", value = "idList", defaultValue = "")
            @RequestParam(value = "idList") List<String> idList) {
        List<MGeographyDict> list=new ArrayList<>();
        for(int i=0;i<idList.size();i++) {
            AddressDict geographyDict = geographyDictService.findById(idList.get(i));
            list.add(convertToModel(geographyDict, MGeographyDict.class));
        }
        return list;
    }
    @RequestMapping(value = ServiceApi.Geography.AddressDictAll, method = RequestMethod.POST)
    @ApiOperation(value = "获取全部行政区划地址")
    public List<AddressDict> getAllAddressDict(){
       return geographyDictService.getAllAddressDict();
    }
    @RequestMapping(value = ServiceApi.Geography.AddressDictByFields, method = RequestMethod.GET)
    @ApiOperation(value = "根据地址中文名 查询地址编号")
    Collection<MGeographyDict> getAddressDict(
            @ApiParam(name = "fields", value = "fields", defaultValue = "")
            @RequestParam(value = "fields") String[] fields ,
            @ApiParam(name = "values", value = "values", defaultValue = "")
            @RequestParam(value = "values") String[] values){
        List<AddressDict> geographyDictList = geographyDictService.findByFields(fields,values);
        return convertToModels(geographyDictList,new ArrayList<>(geographyDictList.size()), MGeographyDict.class,"");
    }
    @RequestMapping(value = ServiceApi.Geography.GetAddressNameByCode, method = RequestMethod.GET)
    @ApiOperation(value = "根据地址中文名 查询地址编号")
    ObjectResult getAddressNameByCode(
            @ApiParam(name = "name", value = "name", defaultValue = "")
            @RequestParam(value = "name") String name){
        AddressDict geographyDict = geographyDictService.findByName(name);
        if(geographyDict != null){
            ObjectResult objectResult = new ObjectResult();
            objectResult.setData(geographyDict);
            objectResult.setSuccessFlg(true);
            return objectResult;
        }
        return null;
    }
    /**
     * 根据地址等级查询地址信息
     * @param name
     * @return
     */
    @RequestMapping(value = "/OrgSaasAreaByname", method = RequestMethod.GET)
    @ApiOperation(value = "根据名称查询行政区划地址")
    public Collection<MGeographyDict> getOrgSaasAreaByname(
            @ApiParam(name = "name", value = "名称", defaultValue = "")
            @RequestParam(value = "name") String name) {
        List<AddressDict> addressDictList = geographyDictService.getAddrDictByname(name);
        return convertToModels(addressDictList,new ArrayList<>(addressDictList.size()), MGeographyDict.class,"");
    }
}

+ 133 - 0
src/main/java/com.yihu.ehr/basic/address/controller/AddressEndPoint.java

@ -0,0 +1,133 @@
package com.yihu.ehr.basic.address.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.address.service.AddressService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.entity.address.Address;
import com.yihu.ehr.model.geography.MGeography;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.id.BizObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @author zlf
 * @version 1.0
 * @created 2015.08.10 17:57
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AddressEndPoint", description = "获取常用地址,根据选择地址判断数据库中是否存在,否则保存为新地址", tags = {"基础信息-地址信息管理"})
public class AddressEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AddressService geographyService;
    @RequestMapping(value = ServiceApi.Geography.Address, method = RequestMethod.GET)
    @ApiOperation(value = "根据地址编号查询地址")
    public MGeography getAddressById(
            @ApiParam(name = "id", value = "地址编号", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Address address =  geographyService.getAddressById(id);
        return convertToModel(address, MGeography.class);
    }
    @RequestMapping(value = ServiceApi.Geography.AddressCanonical, method = RequestMethod.GET)
    @ApiOperation(value = "根据地址编号获取地址中文字符串全拼")
    public String getCanonicalAddress(
            @ApiParam(name = "id", value = "地址代码", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Address address = geographyService.getAddressById(id);
        String addressStr = "";
        if(address != null){
            addressStr = geographyService.getCanonicalAddress(address);
        }
        return addressStr;
    }
    /**
     * 地址检查并保存
     * @return
     */
    @RequestMapping(value = ServiceApi.Geography.Geographies, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "地址检查,如果地址在数据库中不存在,这新增这条记录,否则返回地址id")
    public String saveAddress(
            @ApiParam(name = "json_data", value = "地址json字符串")
            @RequestBody String jsonData) throws Exception{
//        ObjectMapper objectMapper = new ObjectMapper();
//        Geography geography = objectMapper.readValue(jsonData, Geography.class);
        Address geography = toEntity(jsonData,Address.class);
        if (geography.getCountry() == null) {
            geography.setCountry("中国");
        }
        List<Address> geographies = geographyService.isGeographyExist(geography);
        if(geographies==null || geographies.size()==0){
            geography.setId(getObjectId(BizObject.Geography));
            String addressId = geographyService.saveAddress(geography);
            return addressId;
        }else {
            return geographies.get(0).getId();
        }
    }
    /**
     * 根据省市县查询地址
     * @param province
     * @param city
     * @param district
     * @return
     */
    @RequestMapping(value = ServiceApi.Geography.Geographies , method = RequestMethod.GET)
    @ApiOperation(value = "根据省市县查询地址并返回地址编号列表")
    public List<String> search(
            @ApiParam(name = "province", value = "省", defaultValue = "")
            @RequestParam(value = "province",required = true) String province,
            @ApiParam(name = "city", value = "市", defaultValue = "")
            @RequestParam(value = "city",required = false) String city,
            @ApiParam(name = "district", value = "县", defaultValue = "")
            @RequestParam(value = "district",required = false) String district) {
        List<String> idList =  geographyService.search(province,city,district);
        return idList;
    }
    /**
     * 删除地址
     * @param id
     * @return
     */
    @RequestMapping(value = ServiceApi.Geography.GeographiesDelete , method = RequestMethod.DELETE)
    @ApiOperation(value = "根据地址编号删除地址")
    public boolean delete(
            @ApiParam(name = "id" , value = "地址代码" ,defaultValue = "")
            @PathVariable (value = "id") String id) {
        Address address = geographyService.getAddressById(id);
        if(address == null){
            throw new ApiException(ErrorCode.NOT_FOUND, "获取地址失败");
        }
        geographyService.deleteAddress(address);
        return true;
    }
    @RequestMapping(value = ServiceApi.Geography.GeographiesNull , method = RequestMethod.GET)
    @ApiOperation(value = "判断是否是个空地址")
    public boolean isNullAddress(
            @ApiParam(name = "json_data", value = "地址json字符串")
            @RequestParam( value = "json_data") String jsonData) throws Exception{
        ObjectMapper objectMapper = new ObjectMapper();
        Address geography = objectMapper.readValue(jsonData,Address.class);
        return geographyService.isNullAddress(geography);
    }
}

+ 35 - 0
src/main/java/com.yihu.ehr/basic/address/dao/AddressDictRepository.java

@ -0,0 +1,35 @@
package com.yihu.ehr.basic.address.dao;
import com.yihu.ehr.entity.address.AddressDict;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * @author Sand
 * @version 1.0
 * @created 2015.12.16 15:10
 */
public interface AddressDictRepository extends PagingAndSortingRepository<AddressDict, Integer> {
    @Query("select dict from AddressDict dict where dict.id = :id")
    AddressDict getAddressDictById(@Param("id") String id);
    @Query("select dict from AddressDict dict where dict.level = :level")
    List<AddressDict> getAddrDictByLevel(@Param("level") Integer level);
    @Query("select dict from AddressDict dict where dict.pid = :pid")
    List<AddressDict> getAddrDictByPid(@Param("pid") Integer pid);
    @Query("select dict from AddressDict dict where dict.name = :name")
    List<AddressDict> findByName(@Param("name") String pid);
    @Query("select dict from AddressDict dict where 1=1")
    List<AddressDict> getAll();
    @Query("select dict from AddressDict dict where dict.name like %:name% and dict.level > 0")
    List<AddressDict> getAddrDictByname(@Param("name") String name);
}

+ 22 - 0
src/main/java/com.yihu.ehr/basic/address/dao/AddressRepository.java

@ -0,0 +1,22 @@
package com.yihu.ehr.basic.address.dao;
import com.yihu.ehr.entity.address.Address;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * @author Sand
 * @version 1.0
 * @created 2015.12.16 15:10
 */
public interface AddressRepository extends PagingAndSortingRepository<Address, String> {
    @Query("select geography from Address geography where geography.country = :country")
    List<Address> findAddressListByCountry(@Param("country") String country);
    @Query("select geography.id from Address geography where geography.district in(:district)")
    List<String> findIdByDistrict(@Param("district") List<String> district);
}

+ 58 - 0
src/main/java/com.yihu.ehr/basic/address/service/AddressDictService.java

@ -0,0 +1,58 @@
package com.yihu.ehr.basic.address.service;
import com.yihu.ehr.entity.address.AddressDict;
import com.yihu.ehr.basic.address.dao.AddressDictRepository;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
 * 地址管理。对于相同地址,仅保存一份。
 * @author zqb
 * @version 1.0
 * @created 30-六月-2015 19:17:43
 */
@Transactional
@Service
public class AddressDictService extends BaseJpaService<AddressDict,AddressDictRepository>{
    @Autowired
    private AddressDictRepository geographyDictRepository;
	public List<AddressDict> getLevelToAddr(Integer level){
        List<AddressDict> addressDictList = geographyDictRepository.getAddrDictByLevel(level);
        return addressDictList;
	}
	public List<AddressDict> getPidToAddr(Integer pid){
        List<AddressDict> addressDictList = geographyDictRepository.getAddrDictByPid(pid);
        return addressDictList;
	}
    public AddressDict findById(String id) {
        return geographyDictRepository.findOne(Integer.valueOf(id));
    }
    public AddressDict findByName(String name) {
        List<AddressDict> DictList =geographyDictRepository.findByName(name);
        AddressDict geographyDict=new AddressDict();
        if (null != DictList & DictList.size() > 0) {
             geographyDict=DictList.get(0);
        }
        return geographyDict;
    }
    public List<AddressDict> getAllAddressDict() {
        return geographyDictRepository.getAll();
    }
    public List<AddressDict> getAddrDictByname(String name){
        List<AddressDict> addressDictList = geographyDictRepository.getAddrDictByname(name);
        return addressDictList;
    }
}

+ 128 - 0
src/main/java/com.yihu.ehr/basic/address/service/AddressService.java

@ -0,0 +1,128 @@
package com.yihu.ehr.basic.address.service;
import com.yihu.ehr.basic.address.dao.AddressRepository;
import com.yihu.ehr.entity.address.Address;
import com.yihu.ehr.query.BaseJpaService;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;
/**
 * 地址管理。对于相同地址,仅保存一份。
 * @author zqb
 * @version 1.0
 * @created 30-六月-2015 19:17:43
 */
@Transactional
@Service
public class AddressService extends BaseJpaService<Address,AddressRepository>{
    @PersistenceContext
    protected EntityManager entityManager;
    @Autowired
    private AddressRepository geographyRepository;
    /**
	 * 地址检查并保存
     * 返回新地址id
	 * @param geography
	 */
    public String saveAddress(Address geography) {
        return geographyRepository.save(geography).getId();
    }
    public boolean isNullAddress(Address geography) {
        return
                StringUtils.isEmpty(geography.getProvince())
                && StringUtils.isEmpty(geography.getCity())
                && StringUtils.isEmpty(geography.getDistrict())
                && StringUtils.isEmpty(geography.getTown())
                && StringUtils.isEmpty(geography.getCountry())
                && StringUtils.isEmpty(geography.getStreet());
    }
    public Address getAddressById(String Id) {
        return geographyRepository.findOne(Id);
    }
    public String getCanonicalAddress(Address address) {
        String addressStr = "";
        String province = address.getProvince();
        String city = address.getCity();
        String district = address.getDistrict();
        String town = address.getTown();
        String street = address.getStreet();
        String extra = address.getExtra();
        if (!StringUtils.isEmpty(province)){
            addressStr += province;
            if (!"".equals(city)) {
                if (!province.equals(city)){
                    addressStr += city;
                }
            }
        }
        if (!StringUtils.isEmpty(district)){
            addressStr += district;
        }
        if (!StringUtils.isEmpty(town)){
            addressStr += town;
        }
        if (!StringUtils.isEmpty(street)){
            addressStr += street;
        }
        if (!StringUtils.isEmpty(extra)){
            addressStr += extra;
        }
        return addressStr;
    }
    public List<String> search(String province, String city, String district) {
        Session session = entityManager.unwrap(org.hibernate.Session.class);
        String hql =
                "SELECT " +
                "addresses.id " +
                "FROM " +
                "addresses " +
                "WHERE 1=1 ";
        if (!StringUtils.isEmpty(province)) {
            hql += " AND addresses.province = '"+province+"'";
        }
        if (!StringUtils.isEmpty(city)) {
            hql += " AND addresses.city = '"+city+"'";
        }
        if (!StringUtils.isEmpty(district)) {
            hql += " AND addresses.district = '"+district+"'";
        }
        Query query = session.createSQLQuery(hql);
        List<String> idList = query.list();
        return idList;
    }
    public void deleteAddress(Address address) {
        geographyRepository.delete(address);
    }
    public List<Address> isGeographyExist(Address geography) throws Exception {
        String hql = PoUtil.getHql(geography,"id","postalCode");
        Session session = currentSession();
        Query query = session.createQuery(hql);
        List<Address> list = query.list();
        return list;
    }
    public List<String> getIdByDistrict(List<String> district) {
        return geographyRepository.findIdByDistrict(district);
    }
}

+ 45 - 0
src/main/java/com.yihu.ehr/basic/address/service/PoUtil.java

@ -0,0 +1,45 @@
package com.yihu.ehr.basic.address.service;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
/**
 * Created by Administrator on 2016/2/23.
 */
public class PoUtil {
    /**
     * 通过Bean对象获取查询语句
     * @param obj 对象
     * @return Hql
     */
    public static String getHql(Object obj,String... fieldNames) throws Exception {
        List<String> properties = Arrays.asList(fieldNames);
        StringBuffer strBuffer = new StringBuffer(" from "+ obj.getClass().getSimpleName()+" where 1=1");
        Class<? extends Object> objClass = obj.getClass();
        Field fields[] = objClass.getDeclaredFields();
        for (Field field:fields) {
            String fieldValue = getFieldValue(obj, field);
            if(!properties.contains(field.getName())){
                if (fieldValue!=null ) {
                    strBuffer.append(" and "+field.getName()+"='"+fieldValue+"'");
                }else{
                    strBuffer.append(" and ("+field.getName()+" is null)");
                }
            }
        }
        return strBuffer.toString();
    }
    public static String getFieldValue(Object obj, Field field) throws Exception {
        String name = field.getName();
        String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1);
        Method method = obj.getClass().getMethod(methodName);
        Object methodValue = method.invoke(obj);
        if(methodValue!=null){
            return methodValue.toString();
        }
        return null;
    }
}

+ 243 - 0
src/main/java/com.yihu.ehr/basic/appointment/controller/CombinationEndPoint.java

@ -0,0 +1,243 @@
package com.yihu.ehr.basic.appointment.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.appointment.service.CombinationService;
import com.yihu.ehr.basic.fzopen.service.OpenService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
/**
 * 组合福州总部的预约挂号接口为我方需要的数据结构
 *
 * @author 张进军
 * @date 2018/4/17 17:05
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0)
@Api(description = "组合福州总部的预约挂号接口为我方需要的数据结构", tags = {"预约挂号--组合福州总部的预约挂号接口为我方需要的数据结构"})
public class CombinationEndPoint {
    @Value("${fz-gateway.url}")
    private String fzGatewayUrl;
    @Value("${fz-gateway.clientId}")
    private String fzClientId;
    @Value("${fz-gateway.clientVersion}")
    private String fzClientVersion;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private OpenService openService;
    @Autowired
    private CombinationService combinationService;
    /**
     * 由于总部开放平台的医生列表接口,没有就诊日期筛选条件,所以不满足于医疗云PC端预约挂号的原型设计。
     * 另求他法,先从医生列表接口获取医生,再从排班接口获取医生sn,对比去掉没有排班的医生,再获取医生详情,最后获取每个医生的排班。
     */
    @ApiOperation("有排班的医生列表")
    @RequestMapping(value = ServiceApi.FzCombination.FindDoctorList, method = RequestMethod.GET)
    public Envelop findDoctorList(
            @ApiParam(value = "医生列表分页参数,起始页,从1开始", required = true)
            @RequestParam int pageIndex,
            @ApiParam(value = "医生列表分页参数,每页条数,不能超过100", required = true)
            @RequestParam int pageSize,
            @ApiParam(value = "医生总数,头次为 0,后续后台返回", required = true)
            @RequestParam int total,
            @ApiParam(value = "标记医生列表上次查询到第几页,头次为 0,后续后台返回", required = true)
            @RequestParam int lastPageIndex,
            @ApiParam(value = "标记医生列表上次那页遍历到第几条,头次为 0,后续后台返回", required = true)
            @RequestParam int lastPageNo,
            @ApiParam(value = "医院ID", required = true)
            @RequestParam String hospitalId,
            @ApiParam(value = "科室ID", required = true)
            @RequestParam String hosDeptId,
            @ApiParam(value = "就诊日期,yyyy-MM-dd")
            @RequestParam(required = false) String registerDate) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Map<String, Object> result = new HashMap<>();
            Map<String, Object> params = new HashMap<>();
            List<Map<String, Object>> doctorList = new ArrayList<>();
            // 获取一页数量有排班的医生,及其详情、排班列表
            params.clear();
            params.put("pageIndex", pageIndex);
            params.put("pageSize", pageSize);
            params.put("hospitalId", hospitalId);
            params.put("hosDeptId", hosDeptId);
            if (StringUtils.isNotEmpty(registerDate)) {
                params.put("registerDate", registerDate);
            }
            Map<String, Integer> flagMap = new HashMap<>();
            flagMap.put("lastPageIndex", lastPageIndex);
            flagMap.put("lastPageNo", lastPageNo);
            combinationService.getOnePageDoctorList(doctorList, flagMap, params);
            result.put("doctorList", doctorList);
            result.put("lastPageIndex", flagMap.get("lastPageIndex"));
            result.put("lastPageNo", flagMap.get("lastPageNo"));
            // 获取有排班的医生总数
            if (total == 0) {
                params.clear();
                params.put("pageIndex", 1);
                params.put("pageSize", 100);
                params.put("hospitalId", hospitalId);
                params.put("hosDeptId", hosDeptId);
                params.put("registerDate", registerDate);
                result.put("total", combinationService.getTotalDoctors(params));
            } else {
                result.put("total", total);
            }
            envelop.setObj(result);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("医院列表")
    @RequestMapping(value = ServiceApi.FzCombination.FindHospitalList, method = RequestMethod.GET)
    public Envelop findHospitalList(
            @ApiParam(value = "分页参数,起始页,从1开始", required = true)
            @RequestParam int pageIndex,
            @ApiParam(value = "分页参数,每页条数,不能超过100", required = true)
            @RequestParam int pageSize,
            @ApiParam(value = "省份行政编码", required = true)
            @RequestParam String provinceCode,
            @ApiParam(value = "城市行政编码,如果是直辖市,则此字段可以不用传递,表示查询该市下全部的区域", required = true)
            @RequestParam Integer cityCode,
            @ApiParam(value = "医院名称模块查询")
            @RequestParam(required = false) String hosNameLike,
            @ApiParam(value = "是否提供预约,2有提供预约的医院")
            @RequestParam(required = false) Integer state,
            @ApiParam(value = "医院等级")
            @RequestParam(required = false) Integer levelId,
            @ApiParam(value = "医院性质,(1公立,2民营,其他数字为尚未配置)")
            @RequestParam(required = false) Integer nature) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            // 从总部获取医院列表
            String hosApi = "baseinfo/HospitalApi/querySimpleHospitalList";
            Map<String, Object> hosParams = new HashMap<>();
            hosParams.put("pageIndex", pageIndex);
            hosParams.put("pageSize", 100);
            hosParams.put("provinceCode", provinceCode);
            hosParams.put("cityCode", cityCode);
            if (StringUtils.isNotEmpty(hosNameLike)) {
                hosParams.put("hosNameLike", hosNameLike);
            }
            if (state != null) {
                hosParams.put("state", state);
            }
            if (levelId != null) {
                hosParams.put("levelId", levelId);
            }
            if (nature != null) {
                hosParams.put("nature", nature);
            }
   /*         //region  正式线测试用
            List<Map<String, Object>> allHosList = new ArrayList<>();
            // 获取上饶医院
//            hosParams.put("provinceCode", "360000");
//            hosParams.put("cityCode", "361100");
            Map<String, Object> hosResMapSr = objectMapper.readValue(openService.callFzOpenApi(hosApi, hosParams), Map.class);
            if (!"10000".equals(hosResMapSr.get("Code").toString())) {
                envelop.setErrorMsg("获取福州总部医院列表," + hosResMapSr.get("Message").toString());
                return envelop;
            }
            List<Map<String, Object>> hosListSr = (ArrayList) hosResMapSr.get("Result");
            int totalSr = (int) hosResMapSr.get("Total");
            allHosList.addAll(hosListSr);
            // 获取林芝医院
            *//*hosParams.put("provinceCode", "540000");
            hosParams.put("cityCode", "540400");*//*
            Map<String, Object> hosResMapLz = objectMapper.readValue(openService.callFzOpenApi(hosApi, hosParams), Map.class);
            if (!"10000".equals(hosResMapLz.get("Code").toString())) {
                envelop.setErrorMsg("获取福州总部医院列表," + hosResMapLz.get("Message").toString());
                return envelop;
            }
            List<Map<String, Object>> hosListLz = (ArrayList) hosResMapLz.get("Result");
            int totalLz = (int) hosResMapLz.get("Total");
            allHosList.addAll(hosListLz);
            String hosInfoApi = "baseinfo/HospitalApi/querySimpleHospitalById";
            Map<String, Object> hosInfoParams = new HashMap<>();
            for (int i = 0, size = allHosList.size(); i < size; i++) {
                // 获取医院详情
                hosInfoParams.clear();
                hosInfoParams.put("hospitalId", allHosList.get(i).get("hospitalId").toString());
                Map<String, Object> hosInfoResultMap = objectMapper.readValue(openService.callFzOpenApi(hosInfoApi, hosInfoParams), Map.class);
                if (!"10000".equals(hosInfoResultMap.get("Code").toString())) {
                    envelop.setErrorMsg("获取福州总部医院详情," + hosInfoResultMap.get("Message").toString());
                    return envelop;
                }
                // 医生数
                allHosList.get(i).put("doctorCount", hosInfoResultMap.get("doctorCount"));
            }
            hosResMapLz.put("Result", allHosList);
            hosResMapLz.put("Total", totalLz + totalSr);
            envelop.setObj(hosResMapLz);
            envelop.setSuccessFlg(true);
            //endregion  正式线测试用
*/
            Map<String, Object> hosResMap = objectMapper.readValue(openService.callFzOpenApi(hosApi, hosParams), Map.class);
            if (!"10000".equals(hosResMap.get("Code").toString())) {
                envelop.setErrorMsg("获取福州总部医院列表," + hosResMap.get("Message").toString());
                return envelop;
            }
            List<Map<String, Object>> hosList = (ArrayList) hosResMap.get("Result");
            String hosInfoApi = "baseinfo/HospitalApi/querySimpleHospitalById";
            Map<String, Object> hosInfoParams = new HashMap<>();
            for (int i = 0, size = hosList.size(); i < size; i++) {
                // 获取医院详情
                hosInfoParams.clear();
                hosInfoParams.put("hospitalId", hosList.get(i).get("hospitalId").toString());
                Map<String, Object> hosInfoResultMap = objectMapper.readValue(openService.callFzOpenApi(hosInfoApi, hosInfoParams), Map.class);
                if (!"10000".equals(hosInfoResultMap.get("Code").toString())) {
                    envelop.setErrorMsg("获取福州总部医院详情," + hosInfoResultMap.get("Message").toString());
                    return envelop;
                }
                // 医生数
                hosList.get(i).put("doctorCount", hosInfoResultMap.get("doctorCount"));
            }
            hosResMap.put("Result", hosList);
            envelop.setObj(hosResMap);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
}

+ 280 - 0
src/main/java/com.yihu.ehr/basic/appointment/controller/RegistrationEndPoint.java

@ -0,0 +1,280 @@
package com.yihu.ehr.basic.appointment.controller;
import com.yihu.ehr.basic.appointment.entity.Registration;
import com.yihu.ehr.basic.appointment.service.RegistrationService;
import com.yihu.ehr.basic.fzopen.service.OpenService;
import com.yihu.ehr.basic.portal.model.ProtalMessageRemind;
import com.yihu.ehr.basic.portal.service.PortalMessageRemindService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.id.UuidUtil;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 挂号单 接口
 *
 * @author 张进军
 * @date 2018/4/16 19:18
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0)
@Api(description = "挂号单接口", tags = {"预约挂号--挂号单接口"})
public class RegistrationEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private RegistrationService registrationService;
    @Autowired
    private OpenService fzOpenService;
    @Autowired
    private PortalMessageRemindService messageRemindService;
    @ApiOperation("根据ID获取挂号单")
    @RequestMapping(value = ServiceApi.Registration.GetById, method = RequestMethod.GET)
    public Envelop getById(
            @ApiParam(name = "id", value = "主键", required = true)
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Registration registration = registrationService.getById(id);
            envelop.setObj(registration);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("根据orderId获取挂号单")
    @RequestMapping(value = ServiceApi.Registration.GetByOrderId, method = RequestMethod.GET)
    public Envelop getByOrderId(
            @ApiParam(name = "orderId", value = "福州总部挂号单Id", required = true)
            @PathVariable(value = "orderId") String orderId) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Registration registration = registrationService.getByOrderId(orderId);
            envelop.setObj(registration);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation(value = "根据条件获取挂号单")
    @RequestMapping(value = ServiceApi.Registration.Search, method = RequestMethod.GET)
    public Envelop search(
            @ApiParam(name = "fields", value = "返回的字段,为空则返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "筛选条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            List<Registration> list = registrationService.search(fields, filters, sorts, page, size);
            int count = (int) registrationService.getCount(filters);
            // 根据就诊日期判断,更新过期的还没结束的挂号单为已就诊状态。
            // 这是折中的办法,为了解决,成功预约、取消预约之外,没有触发点更新挂号单状态的问题。
            registrationService.updateStateByRegisterDate(list);
            envelop = getPageResult(list, count, page, size);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("新增挂号单")
    @RequestMapping(value = ServiceApi.Registration.Save, method = RequestMethod.POST)
    public Envelop add(
            @ApiParam(value = "挂号单JSON", required = true)
            @RequestParam String entityJson) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Registration newEntity = objectMapper.readValue(entityJson, Registration.class);
            newEntity.setId(UuidUtil.randomUUID());
            if (1 == newEntity.getRegisterType()) {
                newEntity.setRegisterTypeDesc("预约挂号");
            }
            newEntity = registrationService.save(newEntity);
            envelop.setObj(newEntity);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("更新福州总部挂号单到医疗云对应挂号单")
    @RequestMapping(value = ServiceApi.Registration.Update, method = RequestMethod.POST)
    public Envelop update(
            @ApiParam(value = "医疗云挂号单ID", required = true)
            @RequestParam String id,
            @ApiParam(value = "医疗云患者ID", required = true)
            @RequestParam String userId) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            // 获取福州总部的挂号单详情
            String fzOrderInfoUrl = "TradeMgmt/Open/getRegOrderInfo";
            Map<String, Object> params = new HashMap<>();
            params.put("thirdPartyUserId", userId);
            params.put("thirdPartyOrderId", id);
            String fzOrderInfoStr = fzOpenService.callFzOpenApi(fzOrderInfoUrl, params);
            Map<String, Object> fzOrderInfoMap = objectMapper.readValue(fzOrderInfoStr, Map.class);
            if ("10000".equals(fzOrderInfoMap.get("Code").toString())) {
                Registration oldEntity = registrationService.getById(id);
                oldEntity.setOrderId(fzOrderInfoMap.get("orderId").toString());
                oldEntity.setOrderCreateTime(fzOrderInfoMap.get("orderCreateTime").toString());
                oldEntity.setState((Integer) fzOrderInfoMap.get("state"));
                oldEntity.setStateDesc(fzOrderInfoMap.get("stateDesc").toString());
                Object visitClinicResultObj = fzOrderInfoMap.get("visitClinicResult");
                if (visitClinicResultObj != null) {
                    Integer visitClinicResult = Integer.valueOf(visitClinicResultObj.toString());
                    oldEntity.setVisitClinicResult(visitClinicResult);
                    if (0 == visitClinicResult) {
                        oldEntity.setVisitClinicResultDesc("确认中");
                    } else if (1 == visitClinicResult) {
                        oldEntity.setVisitClinicResultDesc("已到诊");
                    } else if (-1 == visitClinicResult) {
                        oldEntity.setVisitClinicResultDesc("爽约");
                    }
                }
                Integer timeId = (Integer) fzOrderInfoMap.get("timeId");
                if (1 == timeId) {
                    oldEntity.setTimeIdDesc("上午");
                } else if (2 == timeId) {
                    oldEntity.setTimeIdDesc("下午");
                } else if (3 == timeId) {
                    oldEntity.setTimeIdDesc("晚上");
                }
                registrationService.save(oldEntity);
                envelop.setSuccessFlg(true);
            } else {
                envelop.setErrorMsg("更新时获取福州总部挂号单详情" + fzOrderInfoMap.get("Message"));
            }
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("删除挂号单")
    @RequestMapping(value = ServiceApi.Registration.Delete, method = RequestMethod.DELETE)
    public Envelop delete(
            @ApiParam(name = "id", value = "挂号单ID", required = true)
            @RequestParam(value = "id") Integer id) {
        Envelop envelop = new Envelop();
        registrationService.delete(id);
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @ApiOperation("更新挂号单状态")
    @RequestMapping(value = ServiceApi.Registration.UpdateState, method = RequestMethod.POST)
    public Envelop updateState(
            @ApiParam(value = "挂号单ID", required = true)
            @RequestParam(value = "id") String id,
            @ApiParam(value = "订单状态", required = true)
            @RequestParam(value = "state") Integer state) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Registration updateEntity = registrationService.getById(id);
            updateEntity.setState(state);
            if (state == 1) {
                updateEntity.setStateDesc("待付款");
            } else if (state == 2) {
                updateEntity.setStateDesc("待就诊");
            } else if (state == 11) {
                updateEntity.setStateDesc("预约中");
            } else if (state == 22) {
                updateEntity.setStateDesc("退款中");
            } else if (state == 99) {
                updateEntity.setStateDesc("已退号");
            } else if (state == -1) {
                updateEntity.setStateDesc("系统取消");
            } else if (state == 3) {
                updateEntity.setStateDesc("已就诊");
            }
            updateEntity = registrationService.save(updateEntity);
            envelop.setObj(updateEntity);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("判断挂号是否成功")
    @RequestMapping(value = ServiceApi.Registration.IsSuccessfullyRegister, method = RequestMethod.GET)
    public Envelop isSuccessfullyRegister(
            @ApiParam(value = "挂号单ID", required = true)
            @RequestParam(value = "id") String id) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Registration registration = registrationService.getById(id);
            long startTime = System.currentTimeMillis();
            // 轮询获取总部推送过来的最新挂号消息
            List<ProtalMessageRemind> messageRemindList = new ArrayList<>();
            while (messageRemindList.size() == 0) {
                messageRemindList = messageRemindService.getRecentOneByOrderId(id, registration.getModifyDate());
                // 当超过一定时间结束轮询
                if ((System.currentTimeMillis() - startTime) > 300000) {
                    envelop.setErrorMsg("已经过了5分钟,没有获取到预约挂号成功与否的推送消息,请稍后查看就诊历史记录。");
                    break;
                }
            }
            if (messageRemindList.size() > 0) {
                Map<String, Object> message = objectMapper.readValue(messageRemindList.get(0).getReceivedMessages(), Map.class);
                Map<String, Object> dataNode = (Map<String, Object>) message.get("data");
                if (registration.getState() == -1) {
                    // 系统取消状态,表示挂号失败。
                    envelop.setErrorMsg(dataNode.get("failMsg").toString());
                } else {
                    envelop.setErrorMsg(dataNode.get("smsContent").toString());
                    envelop.setSuccessFlg(true);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
}

+ 17 - 0
src/main/java/com.yihu.ehr/basic/appointment/dao/RegistrationDao.java

@ -0,0 +1,17 @@
package com.yihu.ehr.basic.appointment.dao;
import com.yihu.ehr.basic.appointment.entity.Registration;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
/**
 * 挂号单 DAO
 *
 * @author 张进军
 * @date 2018/4/16 19:18
 */
public interface RegistrationDao extends PagingAndSortingRepository<Registration, String> {
    Registration getByOrderId(@Param("orderId") String orderId);
}

+ 300 - 0
src/main/java/com.yihu.ehr/basic/appointment/entity/Registration.java

@ -0,0 +1,300 @@
package com.yihu.ehr.basic.appointment.entity;
import com.yihu.ehr.entity.BaseAssignedEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * 挂号单
 *
 * @author 张进军
 * @date 2018/4/16 19:18
 */
@Entity
@Table(name = "registration")
public class Registration extends BaseAssignedEntity {
    public String orderId; // 订单号
    public String orderCreateTime; // 下单时间
    public String userId; // 患者ID
    public String patientName; // 患者姓名
    public Integer cardType; // 患者证件类型,默认身份证,1:中国大陆身份证
    public String cardNo; // 患者证件号
    public String phoneNo; // 患者手机号
    public String hospitalId; // 医院ID
    public String hospitalName; // 医院名称
    public String deptId; // 科室ID
    public String deptName; // 科室名称
    public String doctorId; // 医生ID
    public String doctorName; // 医生姓名
    public String lczcName; // 临床职称名称
    public String photoUri; // 医生头像URL
    public Integer state; // 订单状态。1:待付款  2:待就诊 11:预约中 22:退款中 99:已退号 -1:系统取消 3:已就诊
    public String stateDesc; // 订单状态描述
    public Integer visitClinicResult; // 到诊情况。0:确认中,1:已到诊,-1:爽约。(医院如果未提供到诊信息,该返回值将永远处于确认中)
    public String visitClinicResultDesc; // 到诊情况描述
    public String registerDate; // 就诊时间
    public Integer timeId; // 就诊午别。1:上午,2:下午,3:晚上
    public String timeIdDesc; // 就诊午别描述
    public String commendTime; // 就诊时间段
    public Integer serialNo; // 就诊号数
    public String invalidDate; // 退号截止时间(与预约截止时间相同)
    public Integer originType; // 来源类型,1:PC,2:APP
    public Integer registerType; // 挂号方式,1:预约挂号,2:现场挂号
    public String registerTypeDesc; // 挂号方式描述
    @Column(name = "order_id")
    public String getOrderId() {
        return orderId;
    }
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    @Column(name = "order_create_time")
    public String getOrderCreateTime() {
        return orderCreateTime;
    }
    public void setOrderCreateTime(String orderCreateTime) {
        this.orderCreateTime = orderCreateTime;
    }
    @Column(name = "user_id")
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    @Column(name = "patient_name")
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    @Column(name = "card_type")
    public Integer getCardType() {
        return cardType;
    }
    public void setCardType(Integer cardType) {
        this.cardType = cardType;
    }
    @Column(name = "card_no")
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    @Column(name = "phone_no")
    public String getPhoneNo() {
        return phoneNo;
    }
    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }
    @Column(name = "hospital_id")
    public String getHospitalId() {
        return hospitalId;
    }
    public void setHospitalId(String hospitalId) {
        this.hospitalId = hospitalId;
    }
    @Column(name = "hospital_name")
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    @Column(name = "dept_id")
    public String getDeptId() {
        return deptId;
    }
    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }
    @Column(name = "dept_name")
    public String getDeptName() {
        return deptName;
    }
    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }
    @Column(name = "doctor_id")
    public String getDoctorId() {
        return doctorId;
    }
    public void setDoctorId(String doctorId) {
        this.doctorId = doctorId;
    }
    @Column(name = "doctor_name")
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    @Column(name = "lczc_name")
    public String getLczcName() {
        return lczcName;
    }
    public void setLczcName(String lczcName) {
        this.lczcName = lczcName;
    }
    @Column(name = "photo_uri")
    public String getPhotoUri() {
        return photoUri;
    }
    public void setPhotoUri(String photoUri) {
        this.photoUri = photoUri;
    }
    @Column(name = "state")
    public Integer getState() {
        return state;
    }
    public void setState(Integer state) {
        this.state = state;
    }
    @Column(name = "state_desc")
    public String getStateDesc() {
        return stateDesc;
    }
    public void setStateDesc(String stateDesc) {
        this.stateDesc = stateDesc;
    }
    @Column(name = "visit_clinic_result")
    public Integer getVisitClinicResult() {
        return visitClinicResult;
    }
    public void setVisitClinicResult(Integer visitClinicResult) {
        this.visitClinicResult = visitClinicResult;
    }
    @Column(name = "visit_clinic_result_desc")
    public String getVisitClinicResultDesc() {
        return visitClinicResultDesc;
    }
    public void setVisitClinicResultDesc(String visitClinicResultDesc) {
        this.visitClinicResultDesc = visitClinicResultDesc;
    }
    @Column(name = "register_date")
    public String getRegisterDate() {
        return registerDate;
    }
    public void setRegisterDate(String registerDate) {
        this.registerDate = registerDate;
    }
    @Column(name = "time_id")
    public Integer getTimeId() {
        return timeId;
    }
    public void setTimeId(Integer timeId) {
        this.timeId = timeId;
    }
    @Column(name = "time_id_desc")
    public String getTimeIdDesc() {
        return timeIdDesc;
    }
    public void setTimeIdDesc(String timeIdDesc) {
        this.timeIdDesc = timeIdDesc;
    }
    @Column(name = "commend_time")
    public String getCommendTime() {
        return commendTime;
    }
    public void setCommendTime(String commendTime) {
        this.commendTime = commendTime;
    }
    @Column(name = "serial_no")
    public Integer getSerialNo() {
        return serialNo;
    }
    public void setSerialNo(Integer serialNo) {
        this.serialNo = serialNo;
    }
    @Column(name = "invalid_date")
    public String getInvalidDate() {
        return invalidDate;
    }
    public void setInvalidDate(String invalidDate) {
        this.invalidDate = invalidDate;
    }
    @Column(name = "origin_type")
    public Integer getOriginType() {
        return originType;
    }
    public void setOriginType(Integer originType) {
        this.originType = originType;
    }
    @Column(name = "register_type")
    public Integer getRegisterType() {
        return registerType;
    }
    public void setRegisterType(Integer registerType) {
        this.registerType = registerType;
    }
    @Column(name = "register_type_desc")
    public String getRegisterTypeDesc() {
        return registerTypeDesc;
    }
    public void setRegisterTypeDesc(String registerTypeDesc) {
        this.registerTypeDesc = registerTypeDesc;
    }
}

+ 220 - 0
src/main/java/com.yihu.ehr/basic/appointment/service/CombinationService.java

@ -0,0 +1,220 @@
package com.yihu.ehr.basic.appointment.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.fzopen.service.OpenService;
import com.yihu.ehr.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
 * 组合福州总部的预约挂号接口为我方需要的数据结构 Service
 *
 * @author 张进军
 * @date 2018/4/18 20:27
 */
@Service
public class CombinationService {
    // 排班接口
    private String schedulingApi = "gh/GhOpen/QueryGhtArrangeWater";
    // 医生列表接口
    private String doctorListApi = "baseinfo/DoctorInfoApi/querySimpleDoctorList";
    // 医生详情接口
    private String docInfoApi = "baseinfo/DoctorInfoApi/querySimpleDoctorBySn";
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private OpenService openService;
    /**
     * 从医生列表接口中,获取一页数量有排班的医生,
     * 根据排班接口确定医生是否有排班,没有则移除。
     *
     * @param doctorList 返回医生集合的容器
     * @param flagMap    标记容器,包括:
     *                   lastPageIndex:标记医生列表上次查询到第几页,头次为 0
     *                   lastPageNo:标记医生列表上次那页遍历到第几条,头次为 0
     * @param params     参数
     */
    public List<Map<String, Object>> getOnePageDoctorList(List<Map<String, Object>> doctorList,
                                                          Map<String, Integer> flagMap,
                                                          Map<String, Object> params) throws Exception {
        int lastPageIndex = (int) flagMap.get("lastPageIndex");
        int lastPageNo = (int) flagMap.get("lastPageNo");
        int pageSize = (int) params.get("pageSize");
        String hospitalId = params.get("hospitalId").toString();
        String hosDeptId = params.get("hosDeptId").toString();
        Object registerDate = params.get("registerDate");
        int originLastPageNo = lastPageNo;
        Map<String, Object> tParams = new HashMap<>();
        tParams.clear();
        // 判断上次那页医生数据是否用完,没用完则接着那页开始查询。
        if (originLastPageNo != 0 && originLastPageNo < pageSize) {
            tParams.put("pageIndex", lastPageIndex);
        } else {
            lastPageIndex++;
            tParams.put("pageIndex", lastPageIndex);
        }
        tParams.put("pageSize", pageSize);
        tParams.put("hospitalId", hospitalId);
        tParams.put("hosDeptId", hosDeptId);
        Map<String, Object> doctorsResMap = objectMapper.readValue(
                openService.callFzOpenApi(doctorListApi, tParams), Map.class);
        if (!"10000".equals(doctorsResMap.get("Code").toString())) {
            throw new ApiException("获取总部医生列表时," + doctorsResMap.get("Message").toString());
        }
        List<Map<String, Object>> resDoctorList = ((ArrayList) doctorsResMap.get("Result"));
        int doctorTotal = (int) doctorsResMap.get("Total");
        int resDocListSize = resDoctorList.size();
        if (resDocListSize == 0) {
            return doctorList;
        }
        for (int i = 0; i < resDocListSize; i++) {
            // 判断上次那页医生数据是否用完,没用完则接着那页未用的接着遍历。
            Map<String, Object> doctor = null;
            if (originLastPageNo != 0 && originLastPageNo < pageSize) {
                if (lastPageNo == resDocListSize) {
                    break;
                }
                doctor = resDoctorList.get(lastPageNo);
            } else {
                if (i == 0) {
                    lastPageNo = 0;
                }
                doctor = resDoctorList.get(i);
            }
            lastPageNo++;
            // 获取医生的排班
            tParams.clear();
            tParams.put("pageIndex", 1);
            tParams.put("pageSize", 100);
            tParams.put("hospitalId", hospitalId);
            tParams.put("doctorSn", doctor.get("doctorSn"));
            tParams.put("hosDeptId", hosDeptId);
            if (registerDate != null) {
                tParams.put("registerDate", registerDate);
            }
            Map<String, Object> schedulingResMap = objectMapper.readValue(
                    openService.callFzOpenApi(schedulingApi, tParams), Map.class);
            if (!"10000".equals(schedulingResMap.get("Code").toString())) {
                throw new ApiException("获取总部排班列表时," + schedulingResMap.get("Message").toString());
            }
            List<Map<String, Object>> schedulingList = (ArrayList) schedulingResMap.get("Result");
            if (schedulingList.size() > 0) {
                // 过滤掉需代缴挂号费的排班
                List<Map<String, Object>> freeSchedulingList = new ArrayList<>();
                for (int j = 0, jSize = schedulingList.size(); j < jSize; j++) {
                    if ((int) schedulingList.get(j).get("ghfeeWay") == 0) {
                        freeSchedulingList.add(schedulingList.get(j));
                    }
                }
                if (freeSchedulingList.size() != 0) {
                    // 赋值医生排班
                    doctor.put("schedulingList", freeSchedulingList);
                    // 获取医生详情
                    tParams.clear();
                    tParams.put("doctorSn", doctor.get("doctorSn"));
                    Map<String, Object> docResMap = objectMapper.readValue(
                            openService.callFzOpenApi(docInfoApi, tParams), Map.class);
                    if (!"10000".equals(docResMap.get("Code").toString())) {
                        throw new ApiException("获取总部医生详情时," + docResMap.get("Message").toString());
                    }
                    docResMap.remove("Code");
                    docResMap.remove("Message");
                    doctor.putAll(docResMap);
                    doctorList.add(doctor);
                }
            }
            // 当医生数据不足,或收集满当前分页条数的医生数量,则停止收集。
            if ((i == (resDocListSize - 1) && resDocListSize < pageSize) || doctorList.size() == pageSize) {
                break;
            }
        }
        flagMap.put("lastPageNo", lastPageNo);
        flagMap.put("lastPageIndex", lastPageIndex);
        // 当医生数据充足,并且之前存在没有排班的医生,则递归补满一页医生
        if (pageSize * lastPageIndex < doctorTotal && doctorList.size() < pageSize) {
            getOnePageDoctorList(doctorList, flagMap, params);
        }
        return doctorList;
    }
    /**
     * 从医生列表中,获取有排班的医生总数
     */
    public Integer getTotalDoctors(Map<String, Object> params) throws Exception {
        Map<String, Object> tParams = new HashMap<>();
        Integer count = 0;
        Integer pageIndex = (Integer) params.get("pageIndex");
        Integer pageSize = (Integer) params.get("pageSize");
        String hospitalId = params.get("hospitalId").toString();
        String hosDeptId = params.get("hosDeptId").toString();
        Object registerDate = params.get("registerDate");
        tParams.clear();
        tParams.put("pageIndex", pageIndex);
        tParams.put("pageSize", pageSize);
        tParams.put("hospitalId", hospitalId);
        tParams.put("hosDeptId", hosDeptId);
        Map<String, Object> doctorsResMap = objectMapper.readValue(
                openService.callFzOpenApi(doctorListApi, tParams), Map.class);
        if (!"10000".equals(doctorsResMap.get("Code").toString())) {
            throw new ApiException("获取总部医生列表时," + doctorsResMap.get("Message").toString());
        }
        List<Map<String, Object>> resDoctorList = ((ArrayList) doctorsResMap.get("Result"));
        for (Map<String, Object> doctor : resDoctorList) {
            // 获取医生的排班
            tParams.clear();
            tParams.put("pageIndex", 1);
            tParams.put("pageSize", 100);
            tParams.put("hospitalId", hospitalId);
            tParams.put("hosDeptId", hosDeptId);
            tParams.put("doctorSn", doctor.get("doctorSn"));
            if (registerDate != null) {
                tParams.put("registerDate", registerDate);
            }
            Map<String, Object> schedulingResMap = objectMapper.readValue(
                    openService.callFzOpenApi(schedulingApi, tParams), Map.class);
            if (!"10000".equals(schedulingResMap.get("Code").toString())) {
                throw new ApiException("获取总部排班列表时," + schedulingResMap.get("Message").toString());
            }
            List<Map<String, Object>> schedulingList = (ArrayList) schedulingResMap.get("Result");
            if (schedulingList.size() > 0) {
                // 过滤掉需代缴挂号费的排班
                List<Map<String, Object>> freeSchedulingList = new ArrayList<>();
                for (int j = 0, jSize = schedulingList.size(); j < jSize; j++) {
                    if ((int) schedulingList.get(j).get("ghfeeWay") == 0) {
                        freeSchedulingList.add(schedulingList.get(j));
                    }
                }
                if (freeSchedulingList.size() != 0) {
                    count++;
                }
            }
        }
        // 递归获取
        if (resDoctorList.size() == pageSize) {
            params.put("pageIndex", pageIndex + 1);
            count += getTotalDoctors(params);
        }
        return count;
    }
}

+ 68 - 0
src/main/java/com.yihu.ehr/basic/appointment/service/RegistrationService.java

@ -0,0 +1,68 @@
package com.yihu.ehr.basic.appointment.service;
import com.yihu.ehr.basic.appointment.dao.RegistrationDao;
import com.yihu.ehr.basic.appointment.entity.Registration;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.util.datetime.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
 * 挂号单 Service
 *
 * @author 张进军
 * @date 2018/4/16 19:18
 */
@Service
@Transactional
public class RegistrationService extends BaseJpaService<Registration, RegistrationDao> {
    @Autowired
    RegistrationDao registrationDao;
    public Registration getById(String id) {
        return registrationDao.findOne(id);
    }
    public Registration getByOrderId(String orderId) {
        return registrationDao.getByOrderId(orderId);
    }
    @Transactional(readOnly = false)
    public Registration save(Registration registration) {
        return registrationDao.save(registration);
    }
    @Transactional(readOnly = false)
    public void delete(String id) {
        registrationDao.delete(id);
    }
    /**
     * 根据就诊日期判断,更新过期的未就诊挂号单改为已就诊状态
     *
     * @param list 挂号单集合
     */
    @Transactional
    public void updateStateByRegisterDate(List<Registration> list) {
        Date currDate = DateUtil.getSysDate();
        for (int i = 0, size = list.size(); i < size; i++) {
            Registration registration = list.get(i);
            Integer state = registration.getState();
            if (state != null && (state == 1 || state == 2 || state == 11 || state == 22)) {
                Date registerDate = DateUtil.parseDate(registration.getRegisterDate(),
                        DateUtil.DEFAULT_DATE_YMD_FORMAT);
                if (DateUtil.compareDateTime(currDate, registerDate) > 0) {
                    registration.setState(3);
                    registration.setStateDesc("已就诊");
                    save(registration);
                }
            }
        }
    }
}

+ 118 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppApiCategoryEndPoint.java

@ -0,0 +1,118 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.service.AppApiCategoryService;
import com.yihu.ehr.basic.apps.service.AppApiService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.api.AppApiCategory;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * EndPoint - Api业务类别
 * Created by progr1mmer on 2018/3/14.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppApiCategory", description = "接口分类管理", tags = {"平台应用-接口分类管理"})
public class AppApiCategoryEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AppApiCategoryService appApiCategoryService;
    @Autowired
    private AppApiService appApiService;
    @RequestMapping(value = ServiceApi.AppApiCategory.Base, method = RequestMethod.POST)
    @ApiOperation("保存记录")
    public Envelop save(
            @ApiParam(name = "appApiCategory", value = "Json串", required = true)
            @RequestParam(value = "appApiCategory") String appApiCategory) throws Exception {
        AppApiCategory appApiCategory1 = toEntity(appApiCategory, AppApiCategory.class);
        AppApiCategory appApiCategory2 = appApiCategoryService.save(appApiCategory1);
        return success(appApiCategory2);
    }
    @RequestMapping(value = ServiceApi.AppApiCategory.Base, method = RequestMethod.DELETE)
    @ApiOperation("删除记录")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表xxxx,xxxx,xxxx,...", required = true)
            @RequestParam(value = "ids") String ids){
        String [] idArr = ids.split(",");
        String parent = "";
        for (String id : idArr) {
            if (appApiService.findByCateId(new Integer(id)).size() > 0) {
                parent += id + ",";
            }
        }
        if (StringUtils.isNotEmpty(parent)) {
            return failed("删除失败,请先删除该类别下关联的接口");
        }
        List<String> strIdList = Arrays.asList(idArr);
        List<Integer> intIdList = new ArrayList<>(idArr.length);
        strIdList.forEach(item -> intIdList.add(new Integer(item)));
        appApiCategoryService.delete(intIdList);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.AppApiCategory.Base, method = RequestMethod.PUT)
    @ApiOperation("更新记录")
    public Envelop update(
            @ApiParam(name = "appApiCategory", value = "Json串", required = true)
            @RequestParam(value = "appApiCategory") String appApiCategory) throws Exception {
        AppApiCategory appApiCategory1 = toEntity(appApiCategory, AppApiCategory.class);
        if (appApiCategory1.getId() == null || appApiCategoryService.findByField("id", appApiCategory1.getId()).size() <= 0) {
            return failed("操作对象不存在", ErrorCode.OBJECT_NOT_FOUND.value());
        }
        AppApiCategory appApiCategory2 = appApiCategoryService.save(appApiCategory1);
        return success(appApiCategory2);
    }
    @RequestMapping(value = ServiceApi.AppApiCategory.Base, method = RequestMethod.GET)
    @ApiOperation(value = "获取分页")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<AppApiCategory> appApiCategoryList = appApiCategoryService.search(fields, filters, sorts, page, size);
        int count = (int)appApiCategoryService.getCount(filters);
        Envelop envelop = getPageResult(appApiCategoryList, count, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiCategory.Check, method = RequestMethod.GET)
    @ApiOperation(value = "检查字段是否重复")
    public Boolean check(
            @ApiParam(name = "field", value = "检查字段")
            @RequestParam(value = "field", required = false) String field,
            @ApiParam(name = "value", value = "检查值")
            @RequestParam(value = "value", required = false) String value) throws Exception {
        if (appApiCategoryService.findByField(field, value).size() <= 0) {
            return false;
        }
        return true;
    }
}

+ 324 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppApiEndPoint.java

@ -0,0 +1,324 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.model.AppApi;
import com.yihu.ehr.basic.apps.model.AppApiParameter;
import com.yihu.ehr.basic.apps.model.AppApiResponse;
import com.yihu.ehr.basic.apps.service.*;
import com.yihu.ehr.basic.user.entity.RoleApiRelation;
import com.yihu.ehr.basic.user.entity.RoleAppRelation;
import com.yihu.ehr.basic.user.entity.Roles;
import com.yihu.ehr.basic.user.service.RoleApiRelationService;
import com.yihu.ehr.basic.user.service.RolesService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.api.AppApiCategory;
import com.yihu.ehr.entity.api.AppApiErrorCode;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.app.MAppApi;
import com.yihu.ehr.model.app.MAppApiDetail;
import com.yihu.ehr.model.app.MAppApiParameter;
import com.yihu.ehr.model.app.OpenAppApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javafx.beans.binding.ObjectExpression;
import org.springframework.aop.aspectj.annotation.LazySingletonAspectInstanceFactoryDecorator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.*;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:13
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppApi", description = "平台应用接口管理", tags = {"平台应用-接口管理"})
public class AppApiEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AppApiService appApiService;
    @Autowired
    private AppApiParameterService appApiParameterService;
    @Autowired
    private AppApiResponseService appApiResponseService;
    @Autowired
    private AppApiCategoryService appApiCategoryService;
    @Autowired
    private AppApiErrorCodeService appApiErrorCodeService;
    @RequestMapping(value = ServiceApi.AppApi.AppApis, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppApi")
    public MAppApi createAppApi(
            @ApiParam(name = "appApi", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appApiJson) throws Exception {
        AppApi appApi = toEntity(appApiJson, AppApi.class);
        appApi = appApiService.createAppApi(appApi);
        return convertToModel(appApi, MAppApi.class);
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApis, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi列表")
    public Collection<MAppApi> getAppApis(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        List<AppApi> appApiList = appApiService.search(fields, filters, sorts, page, size);
        pagedResponse(request, response, appApiService.getCount(filters), page, size);
        return convertToModels(appApiList, new ArrayList<>(appApiList.size()), MAppApi.class, fields);
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApis, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新appApi")
    public MAppApi updateAppApi(
            @ApiParam(name = "appApi", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson) throws Exception {
        AppApi appApi = toEntity(appJson, AppApi.class);
        if (appApiService.retrieve(appApi.getId()) == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "应用API不存在");
        }
        appApiService.save(appApi);
        return convertToModel(appApi, MAppApi.class);
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApi, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi")
    public MAppApi getAppApi(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        AppApi appApi = appApiService.retrieve(id);
        return convertToModel(appApi, MAppApi.class);
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApi, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppApi")
    public boolean deleteAppApi(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        appApiService.delete(id);
        return true;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApisNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取过滤App列表")
    public Collection<MAppApi> getAppApiNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters
    ) throws Exception {
        List<AppApi> appApiList = appApiService.search(filters);
        return convertToModels(appApiList, new ArrayList<>(appApiList.size()), MAppApi.class, "");
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApiSearch, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi列表")
    Collection<MAppApiDetail> searchApi(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        List<AppApi> appApiList = appApiService.search(fields, filters, sorts, page, size);
        pagedResponse(request, response, appApiService.getCount(filters), page, size);
        Collection<MAppApiDetail> mAppApiDetails = convertToModels(appApiList, new ArrayList<>(appApiList.size()), MAppApiDetail.class, "");
        mAppApiDetails.forEach(appApi -> {
            try {
                List apiParams = appApiParameterService.search("appApiId=" + appApi.getId());
                Collection<MAppApiParameter> mAppApiParameters = convertToModels(apiParams, new ArrayList<>(apiParams.size()), MAppApiParameter.class, "");
                appApi.setParameters(mAppApiParameters);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        });
        return mAppApiDetails;
    }
    //------------------------ 开放平台基本请求部分 -------------------------
    @RequestMapping(value = ServiceApi.AppApi.CheckName, method = RequestMethod.GET)
    @ApiOperation(value = "检查名称")
    public Boolean checkName(
            @ApiParam(name = "name", value = "api名称", required = true)
            @RequestParam(value = "name") String name,
            @ApiParam(name = "appApiId", value = "appApiId")
            @RequestParam(value = "appApiId", required = false) Integer appApiId) throws Exception {
        if (null == appApiId) {
            if (appApiService.findByName(name).size() > 0) {
                return true;
            }
            return false;
        } else {
            AppApi appApi = appApiService.findById(appApiId);
            if (!appApi.getName().equals(name) && appApiService.findByName(name).size() > 0) {
                return true;
            }
            return false;
        }
    }
    @RequestMapping(value = ServiceApi.AppApi.Save, method = RequestMethod.POST)
    @ApiOperation(value = "新增Api")
    public Envelop save(
            @ApiParam(name = "appApi", value = "对象JSON结构体", required = true, allowMultiple = true)
            @RequestParam(value = "appApi") String appApi,
            @ApiParam(name = "apiParam", value = "api请求参数集合")
            @RequestParam(value = "apiParam", required = false) String apiParam,
            @ApiParam(name = "apiResponse", value = "api响应参数集合")
            @RequestParam(value = "apiResponse", required = false) String apiResponse,
            @ApiParam(name = "apiErrorCode", value = "api错误码集合")
            @RequestParam(value = "apiErrorCode", required = false) String apiErrorCode) throws Exception {
        AppApi appApi1 = appApiService.completeSave(appApi, apiParam, apiResponse, apiErrorCode);
        List<AppApiParameter> appApiParameters = appApiParameterService.search("appApiId=" + appApi1.getId());
        List<AppApiResponse> appApiResponses = appApiResponseService.search("appApiId=" + appApi1.getId());
        List<AppApiErrorCode> appApiErrorCodes = appApiErrorCodeService.search("appApiId=" + appApi1.getId());
        List resultLis = new ArrayList();
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("param", appApiParameters);
        dataMap.put("response", appApiResponses);
        dataMap.put("errorCode", appApiErrorCodes);
        resultLis.add(dataMap);
        return success(appApi1, resultLis);
    }
    @RequestMapping(value = ServiceApi.AppApi.Delete, method = RequestMethod.POST)
    @ApiOperation(value = "删除Api")
    public Boolean delete(
            @ApiParam(name = "id", value = "ID", required = true)
            @RequestParam(value = "id") Integer id) throws Exception {
        appApiService.completeDelete(id);
        return true;
    }
    @RequestMapping(value = ServiceApi.AppApi.Update, method = RequestMethod.POST)
    @ApiOperation(value = "更新Api")
    public Envelop update(
            @ApiParam(name = "appApi", value = "对象JSON结构体", required = true, allowMultiple = true)
            @RequestParam(value = "appApi") String appApi,
            @ApiParam(name = "apiParam", value = "api请求参数集合")
            @RequestParam(value = "apiParam", required = false) String apiParam,
            @ApiParam(name = "apiResponse", value = "api响应参数集合")
            @RequestParam(value = "apiResponse", required = false) String apiResponse,
            @ApiParam(name = "apiErrorCode", value = "api错误码集合")
            @RequestParam(value = "apiErrorCode", required = false) String apiErrorCode) throws Exception {
        AppApi appApi1 = toEntity(appApi, AppApi.class);
        if (null == appApiService.findById(appApi1.getId()) ) {
            return failed("操作的API不存在", ErrorCode.OBJECT_NOT_FOUND.value());
        }
        AppApi newAppApi = appApiService.completeSave(appApi, apiParam, apiResponse, apiErrorCode);
        List<AppApiParameter> appApiParameters = appApiParameterService.search("appApiId=" + newAppApi.getId());
        List<AppApiResponse> appApiResponses = appApiResponseService.search("appApiId=" + newAppApi.getId());
        List<AppApiErrorCode> appApiErrorCodes = appApiErrorCodeService.search("appApiId=" + appApi1.getId());
        List resultLis = new ArrayList();
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("param", appApiParameters);
        dataMap.put("response", appApiResponses);
        dataMap.put("errorCode", appApiErrorCodes);
        resultLis.add(dataMap);
        return success(appApi1, resultLis);
    }
    @RequestMapping(value = ServiceApi.AppApi.Page, method = RequestMethod.GET)
    @ApiOperation(value = "Api分页")
    public Envelop page(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,规则参见说明文档")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size) throws Exception {
        List<AppApi> appApiList = appApiService.search(fields, filters, sorts, page, size);
        int count = (int)appApiService.getCount(filters);
        Envelop envelop = getPageResult(appApiList, count, page, size);
        List<AppApi> appApiList1 = envelop.getDetailModelList();
        List<AppApi> appApiList2 = new ArrayList<>(appApiList1.size());
        for (AppApi appApi : appApiList1) {
            if (appApi.getCategory() != null) {
                AppApiCategory appApiCategory = appApiCategoryService.findOne(appApi.getCategory());
                if (appApiCategory != null) {
                    appApi.setCategoryName(appApiCategory.getName());
                }
            }
            appApiList2.add(appApi);
        }
        envelop.setDetailModelList(appApiList2);
        return envelop;
    }
    // -------------------------------- 接入授权部分 --------------------------------
    @RequestMapping(value = ServiceApi.AppApi.AuthList, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi列表")
    public List<AppApi> authApiList(
            @ApiParam(name = "appId", value = "应用ID", required = true)
            @RequestParam(value = "appId") String appId) throws Exception{
        List<AppApi> appApiList = appApiService.authApiList(appId);
        List<AppApi> appApiList2 = new ArrayList<>(appApiList.size());
        for (AppApi appApi : appApiList) {
            if (appApi.getCategory() != null) {
                AppApiCategory appApiCategory = appApiCategoryService.findOne(appApi.getCategory());
                if (appApiCategory != null) {
                    appApi.setCategoryName(appApiCategory.getName());
                }
            }
            appApiList2.add(appApi);
        }
        return appApiList2;
    }
    @RequestMapping(value = ServiceApi.AppApi.AuthApi, method = RequestMethod.POST)
    @ApiOperation(value = "授权AppApi")
    public Boolean authApi(
            @ApiParam(name = "appId", value = "角色appId", required = true)
            @RequestParam(value = "appId") String appId,
            @ApiParam(name = "code", value = "角色编码", required = true)
            @RequestParam(value = "code") String code,
            @ApiParam(name = "apiId", value = "apiId", required = true)
            @RequestParam(value = "apiId") String apiId) throws Exception{
        appApiService.authApi(code, appId, apiId);
        return true;
    }
    @RequestMapping(value = ServiceApi.AppApi.AuthApi, method = RequestMethod.DELETE)
    @ApiOperation(value = "取消AppApi授权")
    public Boolean unAuthApi(
            @ApiParam(name = "appId", value = "角色appId", required = true)
            @RequestParam(value = "appId") String appId,
            @ApiParam(name = "code", value = "角色编码", required = true)
            @RequestParam(value = "code") String code,
            @ApiParam(name = "apiId", value = "apiId", required = true)
            @RequestParam(value = "apiId") String apiId) throws Exception{
        appApiService.unAuthApi(code, appId, apiId);
        return true;
    }
}

+ 108 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppApiErrorCodeEndPoint.java

@ -0,0 +1,108 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.service.AppApiErrorCodeService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.api.AppApiErrorCode;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * EndPoint - Api错误码
 * Created by progr1mmer on 2018/3/14.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppApiCategory", description = "接口错误码管理", tags = {"平台应用-接口错误码管理"})
public class AppApiErrorCodeEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AppApiErrorCodeService appApiErrorCodeService;
    @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.POST)
    @ApiOperation("保存记录")
    public Envelop save(
            @ApiParam(name = "appApiErrorCode", value = "Json串", required = true)
            @RequestParam(value = "appApiErrorCode") String appApiErrorCode) throws Exception {
        AppApiErrorCode appApiErrorCode1 = toEntity(appApiErrorCode, AppApiErrorCode.class);
        AppApiErrorCode appApiErrorCode2 = appApiErrorCodeService.save(appApiErrorCode1);
        return success(appApiErrorCode2);
    }
    @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.DELETE)
    @ApiOperation("删除记录")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表xxxx,xxxx,xxxx,...", required = true)
            @RequestParam(value = "ids") String ids){
        String [] idArr = ids.split(",");
        List<String> strIdList = Arrays.asList(idArr);
        List<Integer> intIdList = new ArrayList<>(idArr.length);
        strIdList.forEach(item -> intIdList.add(new Integer(item)));
        appApiErrorCodeService.delete(intIdList);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.PUT)
    @ApiOperation("更新记录")
    public Envelop update(
            @ApiParam(name = "appApiErrorCode", value = "Json串", required = true)
            @RequestParam(value = "appApiErrorCode") String appApiErrorCode) throws Exception {
        AppApiErrorCode appApiErrorCode1 = toEntity(appApiErrorCode, AppApiErrorCode.class);
        if (appApiErrorCode1.getId() == null || appApiErrorCodeService.findByField("id", appApiErrorCode1.getId()).size() <= 0) {
            return failed("操作对象不存在", ErrorCode.OBJECT_NOT_FOUND.value());
        }
        AppApiErrorCode appApiErrorCode2 = appApiErrorCodeService.save(appApiErrorCode1);
        return success(appApiErrorCode2);
    }
    @RequestMapping(value = ServiceApi.AppApiErrorCode.Base, method = RequestMethod.GET)
    @ApiOperation(value = "获取分页")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<AppApiErrorCode> appApiCategoryList = appApiErrorCodeService.search(fields, filters, sorts, page, size);
        int count = (int)appApiErrorCodeService.getCount(filters);
        Envelop envelop = getPageResult(appApiCategoryList, count, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiErrorCode.CheckCode, method = RequestMethod.GET)
    @ApiOperation(value = "更新时检查Code是否重复")
    public Boolean check(
            @ApiParam(name = "apiId", value = "apiId")
            @RequestParam(value = "apiId", required = false) Integer apiId,
            @ApiParam(name = "newCode", value = "检查值")
            @RequestParam(value = "newCode", required = false) Integer newCode) throws Exception {
        List<AppApiErrorCode> appApiErrorCodeList = appApiErrorCodeService.findByField("apiId", apiId);
        for (AppApiErrorCode appApiErrorCode : appApiErrorCodeList) {
            if (appApiErrorCode.getCode() == newCode) {
                return true;
            }
        }
        return false;
    }
}

+ 98 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppApiParameterEndPoint.java

@ -0,0 +1,98 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.model.AppApiParameter;
import com.yihu.ehr.basic.apps.service.AppApiParameterService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.app.MAppApiParameter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:13
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppApiParameter", description = "API应用请求参数", tags = {"平台应用-API应用请求参数"})
public class AppApiParameterEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AppApiParameterService appApiParameterService;
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppApiParameter")
    public MAppApiParameter createAppApiParameter(
            @ApiParam(name = "AppApiParameter", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appApiParameterJson) throws Exception {
        AppApiParameter appApiParameter = toEntity(appApiParameterJson, AppApiParameter.class);
        appApiParameter = appApiParameterService.createAppApiParameter(appApiParameter);
        return convertToModel(appApiParameter, MAppApiParameter.class);
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiParameter列表")
    public Collection<MAppApiParameter> getAppApiParameters(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
            List<AppApiParameter> appApiParameterList = appApiParameterService.search(fields, filters, sorts, page, size);
            pagedResponse(request, response, appApiParameterService.getCount(filters), page, size);
            return convertToModels(appApiParameterList, new ArrayList<>(appApiParameterList.size()), MAppApiParameter.class, fields);
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppApiParameter")
    public MAppApiParameter updateAppApiParameter(
            @ApiParam(name = "AppApiParameter", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson) throws Exception {
        AppApiParameter appApiParameter = toEntity(appJson, AppApiParameter.class);
        if (appApiParameterService.retrieve(appApiParameter.getId()) == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "应用不存在");
        }
        appApiParameterService.save(appApiParameter);
        return convertToModel(appApiParameter, MAppApiParameter.class);
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiParameter")
    public MAppApiParameter getAppApiParameter(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        AppApiParameter appApiParameter = appApiParameterService.retrieve(id);
        return convertToModel(appApiParameter, MAppApiParameter.class);
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppApiParameter")
    public boolean deleteAppApiParameter(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        appApiParameterService.delete(id);
        return true;
    }
}

+ 98 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppApiResponseEndPoint.java

@ -0,0 +1,98 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.model.AppApiResponse;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.app.MAppApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:13
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppApiResponse", description = "平台应用响应参数", tags = {"平台应用-平台应用响应参数"})
public class AppApiResponseEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private com.yihu.ehr.basic.apps.service.AppApiResponseService AppApiResponseService;
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppApiResponse")
    public MAppApiResponse createAppApiResponse(
            @ApiParam(name = "AppApiResponse", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appApiResponseJson) throws Exception {
        AppApiResponse appApiResponse = toEntity(appApiResponseJson, AppApiResponse.class);
        appApiResponse = AppApiResponseService.createAppApiResponse(appApiResponse);
        return convertToModel(appApiResponse, MAppApiResponse.class);
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiResponse列表")
    public Collection<MAppApiResponse> getAppApiResponses(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
            List<AppApiResponse> appApiResponseList = AppApiResponseService.search(fields, filters, sorts, page, size);
            pagedResponse(request, response, AppApiResponseService.getCount(filters), page, size);
            return convertToModels(appApiResponseList, new ArrayList<>(appApiResponseList.size()), MAppApiResponse.class, fields);
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppApiResponse")
    public MAppApiResponse updateAppApiResponse(
            @ApiParam(name = "AppApiResponse", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson) throws Exception {
        AppApiResponse appApiResponse = toEntity(appJson, AppApiResponse.class);
        if (AppApiResponseService.retrieve(appApiResponse.getId()) == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "应用不存在");
        }
        AppApiResponseService.save(appApiResponse);
        return convertToModel(appApiResponse, MAppApiResponse.class);
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponse, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiResponse")
    public MAppApiResponse getAppApiResponse(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        AppApiResponse appApiResponse = AppApiResponseService.retrieve(id);
        return convertToModel(appApiResponse, MAppApiResponse.class);
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponse, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppApiResponse")
    public boolean deleteAppApiResponse(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        AppApiResponseService.delete(id);
        return true;
    }
}

+ 522 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppEndPoint.java

@ -0,0 +1,522 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.model.App;
import com.yihu.ehr.basic.apps.model.AppsRelation;
import com.yihu.ehr.basic.apps.model.UserApp;
import com.yihu.ehr.basic.apps.service.AppService;
import com.yihu.ehr.basic.apps.service.AppsRelationService;
import com.yihu.ehr.basic.apps.service.OauthClientDetailsService;
import com.yihu.ehr.basic.apps.service.UserAppService;
import com.yihu.ehr.basic.dict.service.SystemDictEntryService;
import com.yihu.ehr.basic.getui.ConstantUtil;
import com.yihu.ehr.basic.user.entity.RoleAppRelation;
import com.yihu.ehr.basic.user.entity.Roles;
import com.yihu.ehr.basic.user.service.RoleAppRelationService;
import com.yihu.ehr.basic.user.service.RolesService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.dict.SystemDictEntry;
import com.yihu.ehr.entity.oauth2.OauthClientDetails;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.app.MApp;
import com.yihu.ehr.model.dict.SystemDictEntryAppModel;
import com.yihu.ehr.util.id.BizObject;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
/**
 * @author linaz
 * @version 1.0
 * @created 2015.8.12 16:53:06
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "Application", description = "EHR应用管理", tags = {"应用管理-EHR应用管理"})
public class AppEndPoint extends EnvelopRestEndPoint {
    @Value("${fast-dfs.public-server}")
    private String fastDfsPublicServers;
    @Autowired
    private AppService appService;
    @Autowired
    private UserAppService userAppService;
    @Autowired
    private RolesService roleAppRelation;
    @Autowired
    private SystemDictEntryService systemDictEntryService;
    @Autowired
    private AppsRelationService appsRelationService;
    @Autowired
    private OauthClientDetailsService oauthClientDetailsService;
    @Autowired
    private RoleAppRelationService roleAppRelationService;
    @RequestMapping(value = ServiceApi.Apps.Apps, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建App")
    public MApp createApp(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true, defaultValue = "{\"name\": \"\", \"url\": \"\", \"catalog\": \"\", \"description\": \"\", \"creator\":\"\"},\"icon\": \"\",\"releaseFlag\": \"\"")
            @RequestBody String appJson) throws Exception {
        App app = toEntity(appJson, App.class);
        app.setId(getObjectId(BizObject.App));
        app = appService.createApp(app);
        //为应用追加默认角色组
        Roles roles=null;
        RoleAppRelation relation =null;
        String[][] rolestr= ConstantUtil.roles;
        for (String[] role : rolestr) {
            roles=new Roles();
            roles.setAppId(app.getId());
            roles.setType("1");
            roles.setCode(role[0]);
            roles.setName(role[1]);
            roles= roleAppRelation.save(roles);
            relation = new RoleAppRelation();
            relation.setAppId(app.getId());
            relation.setRoleId(roles.getId());
            roleAppRelationService.save(relation);
        }
        return convertToModel(app, MApp.class);
    }
    @RequestMapping(value = ServiceApi.Apps.Apps, method = RequestMethod.GET)
    @ApiOperation(value = "获取App列表")
    public Collection<MApp> getApps(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,name,secret,url,createTime,icon,releaseFlag")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
            List<App> appList = appService.search(fields, filters, sorts, page, size);
            pagedResponse(request, response, appService.getCount(filters), page, size);
            return convertToModels(appList, new ArrayList<>(appList.size()), MApp.class, fields);
    }
    @RequestMapping(value = ServiceApi.Apps.AppsNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取app列表,不分页")
    public Collection<MApp> getAppsNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件",defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters) throws Exception {
        List<App> appList = appService.search(filters);
        return convertToModels(appList,new ArrayList<MApp>(appList.size()),MApp.class,"");
    }
    @RequestMapping(value = ServiceApi.Apps.Apps, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新App")
    public MApp updateApp(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson) throws Exception {
        App app = toEntity(appJson, App.class);
        if (appService.retrieve(app.getId()) == null) {
            throw new ApiException("不存在相应appId:" + app.getId());
        }
        OauthClientDetails oauthClientDetails = oauthClientDetailsService.retrieve(app.getId());
        if (null == oauthClientDetails) {
            oauthClientDetails = new OauthClientDetails();
            oauthClientDetails.setClientId(app.getId());
        }
        oauthClientDetails.setResourceIds("*");
        oauthClientDetails.setClientSecret(app.getSecret());
        oauthClientDetails.setScope("read");
        oauthClientDetails.setAuthorizedGrantTypes("authorization_code,refresh_token,password,implicit,verify_code");
        oauthClientDetails.setWebServerRedirectUri(app.getUrl());
        oauthClientDetails.setAuthorities(null);
        oauthClientDetails.setAccessTokenValidity(null);
        oauthClientDetails.setAccessTokenValidity(null);
        oauthClientDetails.setAdditionalInformation(null);
        oauthClientDetails.setAutoApprove("true");
        appService.update(app, oauthClientDetails);
        return convertToModel(app, MApp.class);
    }
    @RequestMapping(value = ServiceApi.Apps.getApp, method = RequestMethod.GET)
    @ApiOperation(value = "获取App")
    public MApp getApp(
            @ApiParam(name = "app_id", value = "id")
            @RequestParam(value = "app_id") String appId) throws Exception {
        App app = appService.retrieve(appId);
        if (app != null && StringUtils.isNotEmpty(app.getIcon())) {
            String iconUrl = fastDfsPublicServers + "/" + app.getIcon().replace(":", "/");
            app.setIcon(iconUrl);
        }
        return convertToModel(app, MApp.class);
    }
    @RequestMapping(value = ServiceApi.Apps.App, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除App")
    public boolean deleteApp(
            @ApiParam(name = "app_id", value = "id")
            @PathVariable(value = "app_id") String app_id) throws Exception {
        if (appService.retrieve(app_id) != null) {
            appService.delete(app_id);
        }
        return true;
    }
    @RequestMapping(value = ServiceApi.Apps.App, method = RequestMethod.GET)
    @ApiOperation(value = "获取App信息")
    public MApp app (
            @ApiParam(name = "app_id", value = "id")
            @PathVariable(value = "app_id") String app_id) throws Exception {
        App app = appService.retrieve(app_id);
        return convertToModel(app, MApp.class);
    }
    @RequestMapping(value = ServiceApi.Apps.AppStatus, method = RequestMethod.PUT)
    @ApiOperation(value = "修改状态")
    public boolean updateStatus(
            @ApiParam(name = "app_id", value = "id")
            @PathVariable(value = "app_id") String appId,
            @ApiParam(name = "app_status", value = "状态")
            @RequestParam(value = "app_status") String appStatus) throws Exception {
        appService.checkStatus(appId, appStatus);
        return true;
    }
    @RequestMapping(value = ServiceApi.Apps.AppExistence, method = RequestMethod.GET)
    @ApiOperation(value = "验证应用是否存在")
    public boolean isAppExistence(
            @ApiParam(name = "app_id", value = "id")
            @PathVariable(value = "app_id") String appId,
            @ApiParam(name = "secret", value = "")
            @RequestParam(value = "secret") String secret) throws Exception {
        return appService.findByIdAndSecret(appId, secret);
    }
    @RequestMapping(value = ServiceApi.Apps.AppNameExistence, method = RequestMethod.GET)
    @ApiOperation(value = "判断应用名称是否已经存在")
    public boolean isAppNameExists(
            @ApiParam(value = "app_name")
            @PathVariable(value = "app_name") String appName) {
        return appService.isAppNameExists(appName);
    }
    @RequestMapping(value = ServiceApi.Apps.FilterList, method = RequestMethod.GET)
    @ApiOperation(value = "获取过滤App列表")
    public Boolean getAppFilter(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters) throws Exception {
        Long count = appService.getCount(filters);
        return count > 0 ? true : false;
    }
    @RequestMapping(value =  ServiceApi.Apps.getApps, method = RequestMethod.GET)
    @ApiOperation(value = "根据条件,获取app列表")
    public Collection<MApp> getApps(
            @ApiParam(name = "userId", value = "userId", required = true)
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "catalog", value = "catalog", required = true)
            @RequestParam(value = "catalog") String catalog,
            @ApiParam(name = "manageType", value = "APP管理类型,backStage:后台管理,client:客户端。", required = true)
            @RequestParam(value = "manageType", required = false) String manageType) throws Exception {
        List<App> appList = appService.getApps(userId, catalog, manageType);
        return convertToModels(appList,new ArrayList<MApp>(appList.size()),MApp.class,"");
    }
    @RequestMapping(value = ServiceApi.Apps.getAppTypeAndApps, method = RequestMethod.GET)
    @ApiOperation(value = "根据条件,获取APP类型及其所拥有的应用")
    public Envelop getAppTypeAndApps(
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "manageType", value = "APP管理类型,backStage:后台管理,client:客户端。")
            @RequestParam(value = "manageType", required = false) String manageType) throws Exception {
        Envelop envelop = new Envelop();
        //获取系统字典项(App类型)
        String filters = "dictId=" + 1;
        String fields = "";
        String sort = "+sort";
        int page = 1;
        int size = 999;
        List<SystemDictEntry> systemDictEntryList = systemDictEntryService.search(fields, filters, sort, page, size);
        List<SystemDictEntryAppModel> systemDictEntryModelList = (List<SystemDictEntryAppModel>) convertToModels(systemDictEntryList, new ArrayList<SystemDictEntryAppModel>(systemDictEntryList.size()), SystemDictEntryAppModel.class, null);
        List<SystemDictEntryAppModel> DictEntryModelList=new ArrayList<>();
        if (systemDictEntryList.size() > 0) {
            for (SystemDictEntryAppModel dict : systemDictEntryModelList){
                Collection<App> mAppList = appService.getApps(userId, dict.getCode(), manageType);
                List<MApp> appModelList = (List<MApp>) convertToModels(mAppList, new ArrayList<MApp>(mAppList.size()), MApp.class, null);
                dict.setChildren(appModelList);
                DictEntryModelList.add(dict);
            }
        }
        //应用列表
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(DictEntryModelList);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Apps.GetUserApp, method = RequestMethod.GET)
    @ApiOperation(value = "基于新的菜单需求,根据用户获取授权内的应用列表信息")
    public Envelop getUserApp(
            @ApiParam(name = "userId", value = "用户APP对象json")
            @RequestParam(value = "userId", required = true) String userId) throws Exception {
        Envelop res  = new Envelop();
        //查询所有生效的应用列表
        String filters = "";
        List<App> appList = appService.search(filters);
        Collection<MApp> mAppList =  convertToModels(appList,new ArrayList<MApp>(appList.size()),MApp.class,"");
        if(mAppList != null && mAppList.size() > 0){
            res.setSuccessFlg(true);
        }else {
            res.setSuccessFlg(false);
            res.setErrorMsg("应用信息列表获取失败,请重试!");
            return res;
        }
        //查询所有的授权应用列表
        filters = "userId="+userId;
        List<UserApp> userAppList =  userAppService.search(filters);
        if(userAppList == null && userAppList.size() == 0){
            res.setDetailModelList(new ArrayList<MApp>(mAppList));
            return res;
        }
        //基于授权的应用列表,更新roleType状态
        //循环更新 roleType状态,初始化为0 ,存在授权的情况,赋值为 1
        for(MApp mApp :mAppList){
            mApp.setRoleType("0");
            String appId = mApp.getId();
            for(UserApp userApp: userAppList){
                if((appId).equals(userApp.getAppId())){
                    mApp.setRoleType("1");
                    break;
                }else{
                    continue;
                }
            }
        }
        res.setSuccessFlg(true);
        res.setDetailModelList(new ArrayList<MApp>(mAppList));
        return res;
    }
    // -------------------------- 开放平台 ---------------------------------
    @RequestMapping(value =  ServiceApi.Apps.CheckField, method = RequestMethod.POST)
    @ApiOperation(value = "注册时根据条件判断应用ID或者名称是否存在")
    public Boolean isFieldExist(
            @ApiParam(name = "field", value = "字段", required = true)
            @RequestParam(value = "field") String field,
            @ApiParam(name = "value", value = "值", required = true)
            @RequestParam(value = "value") String value) throws Exception{
        List<App> appList = appService.search(field + "=" + value);
        if (appList != null && appList.size() > 0) {
            return true;
        }
        return false;
    }
    @RequestMapping(value =  ServiceApi.Apps.CheckName, method = RequestMethod.POST)
    @ApiOperation(value = "更新的时候判断名字是否存在")
    public Boolean checkName(
            @ApiParam(name = "appId", value = "应用Id", required = true)
            @RequestParam(value = "appId") String appId,
            @ApiParam(name = "newName", value = "值", required = true)
            @RequestParam(value = "newName") String newName) throws Exception{
        App app = appService.findById(appId);
        if (!app.getName().equals(newName) && appService.findByField("name", newName).size() > 0) {
            return true;
        }
        return false;
    }
    @RequestMapping(value =  ServiceApi.Apps.AppAuthClient, method = RequestMethod.POST)
    @ApiOperation(value = "开放平台审核结果处理接口,包含App初始化和应用角色分配")
    public Envelop authClient(
            @ApiParam(name = "appJson", value = "App", required = true)
            @RequestParam(value = "appJson") String appJson,
            @ApiParam(name = "roleId", value = "基础角色ID", required = true)
            @RequestParam(value = "roleId") Long roleId) throws Exception{
        //app 表
        App app = objectMapper.readValue(appJson, App.class);
        app.setCreateTime(new Date());
        app.setAuditor("system");
        app.setAuditTime(new Date());
        app.setCatalog("ApplicationService");
        app.setStatus("Approved");
        app.setSourceType(0);
        app.setCode("DEFAULT");
        app.setManageType("client");
        app.setReleaseFlag(1);
        //oauth 表
        OauthClientDetails oauthClientDetails = new OauthClientDetails();
        oauthClientDetails.setClientId(app.getId());
        oauthClientDetails.setResourceIds("*");
        oauthClientDetails.setClientSecret(app.getSecret());
        oauthClientDetails.setScope("read");
        oauthClientDetails.setAuthorizedGrantTypes("authorization_code,refresh_token,password,implicit,verify_code");
        oauthClientDetails.setWebServerRedirectUri(app.getUrl());
        oauthClientDetails.setAuthorities(null);
        oauthClientDetails.setAccessTokenValidity(null);
        oauthClientDetails.setAccessTokenValidity(null);
        oauthClientDetails.setAdditionalInformation(null);
        oauthClientDetails.setAutoApprove("true");
        //验证基础角色
        Roles basicRole = roleAppRelation.retrieve(roleId);
        if (null == basicRole) {
            return failed("基础角色为空");
        }
        //创建扩展角色
        Roles additionRole = new Roles();
        additionRole.setCode(app.getId());
        additionRole.setName("扩展开发者");
        additionRole.setDescription("开放平台扩展开发者");
        additionRole.setAppId(basicRole.getAppId()); //此处设置角色所属的应用ID
        additionRole.setType("0");
        App newApp = appService.authClient(app, oauthClientDetails, basicRole, additionRole);
        return success(newApp);
    }
    @RequestMapping(value =  ServiceApi.Apps.SimpleUpdate, method = RequestMethod.POST)
    @ApiOperation(value = "开放平台应用简单更新")
    public Envelop simpleUpdate(
            @ApiParam(name = "appId", value = "AppId", required = true)
            @RequestParam(value = "appId") String appId,
            @ApiParam(name = "name", value = "名称", required = true)
            @RequestParam(value = "name") String name,
            @ApiParam(name = "url", value = "回调地址", required = true)
            @RequestParam(value = "url") String url) {
        List<App> appList = appService.findByField("id", appId);
        if (appList.size() <= 0) {
            return failed("操作对象不存在", ErrorCode.OBJECT_NOT_FOUND.value());
        }
        App app1 = appList.get(0);
        app1.setName(name);
        app1.setUrl(url);
        App app2 = appService.save(app1);
        return success(app2);
    }
    /**
     * 医生工作平台--显示应用列表
     * @param userId
     * @return
     * @throws Exception
     * create by zhangdan on 2018/04/19
     */
    @RequestMapping(value =  ServiceApi.Apps.GetAppsRelationByUserIdAndParentAppId, method = RequestMethod.POST)
    @ApiOperation(value = "医生工作平台个人平台应用列表")
    public Envelop getAppsRelationByUserID(
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId)throws Exception {
        if (StringUtils.isEmpty(userId)){
            return failed("请先登录!");
        }
        List<Map<String,Object>> list = appService.getAppByParentIdAndUserId(userId);
        return success(list);
    }
    @RequestMapping(value =  ServiceApi.Apps.GetAppsRelationByUserJson, method = RequestMethod.POST)
    @ApiOperation(value = "支撑平台配置应用之间的关系")
    public Envelop getAppsByUserJson(
            @ApiParam(name = "jsonData", value = "新增应用关系json字符串", required = true)
            @RequestBody String jsonData)throws Exception {
        AppsRelation appsRelation = toEntity(jsonData, AppsRelation.class);
        AppsRelation relation = appsRelationService.save(appsRelation);
        return success(relation);
    }
    @RequestMapping(value = ServiceApi.Apps.getDoctorAppsByType, method = RequestMethod.GET)
    @ApiOperation(value = "根据条件,医生工作站-获取用户所拥有的应用")
    public Envelop getDoctorAppsByType(
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId") String userId) throws Exception {
        Envelop envelop = new Envelop();
        //获取系统字典项(医生工作站App类型)
        String filters = "dictId=179";
        String sort = "+sort";
        int page = 1;
        int size = 999;
        List<SystemDictEntry> systemDictEntryList = systemDictEntryService.search(null, filters, sort, page, size);
        List<SystemDictEntryAppModel> systemDictEntryModelList = (List<SystemDictEntryAppModel>) convertToModels(systemDictEntryList, new ArrayList<SystemDictEntryAppModel>(systemDictEntryList.size()), SystemDictEntryAppModel.class, null);
        List<SystemDictEntryAppModel> DictEntryModelList=new ArrayList<>();
        if (systemDictEntryList.size() > 0) {
            for (SystemDictEntryAppModel dict : systemDictEntryModelList){
                Collection<App> mAppList = appService.getDoctorAppsByType(userId, dict.getCode());
                List<MApp> appModelList = (List<MApp>) convertToModels(mAppList, new ArrayList<MApp>(mAppList.size()), MApp.class, null);
                dict.setChildren(appModelList);
                DictEntryModelList.add(dict);
            }
        }
        //应用列表
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(DictEntryModelList);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Apps.createAppRolesByAppId, method = RequestMethod.POST)
    @ApiOperation(value = "创建默认的App角色组")
    public Envelop createAppRolesByAppId(
            @ApiParam(name = "appId", value = "appId")
            @RequestParam(value = "appId",required = false) String appId,
            @ApiParam(name = "allAppFlag", value = "allAppFlag",defaultValue = "false")
            @RequestParam(value = "allAppFlag") boolean allAppFlag){
        Envelop envelop =new Envelop();
        //为应用追加默认角色组
        String[][] rolestr= ConstantUtil.roles;
        try {
            if(allAppFlag){
                List<App> appList = appService.search("");
                appList.forEach(app -> {
                    Roles roles=null;
                    RoleAppRelation relation =null;
                    for (String[] role : rolestr) {
                        roles=new Roles();
                        roles.setAppId(app.getId());
                        roles.setType("1");
                        roles.setCode(role[0]);
                        roles.setName(role[1]);
                        roles= roleAppRelation.save(roles);
                        relation = new RoleAppRelation();
                        relation.setAppId(app.getId());
                        relation.setRoleId(roles.getId());
                        roleAppRelationService.save(relation);
                    }
                });
            }else {
                Roles roles=null;
                RoleAppRelation relation =null;
                for (String[] role : rolestr) {
                    roles=new Roles();
                    roles.setAppId(appId);
                    roles.setType("1");
                    roles.setCode(role[0]);
                    roles.setName(role[1]);
                    roles= roleAppRelation.save(roles);
                    relation = new RoleAppRelation();
                    relation.setAppId(appId);
                    relation.setRoleId(roles.getId());
                    roleAppRelationService.save(relation);
                }
            }
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg(e.getMessage());
        }
        return  envelop;
    }
}

+ 143 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppFeatureEndPoint.java

@ -0,0 +1,143 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.model.AppFeature;
import com.yihu.ehr.basic.apps.service.AppFeatureService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.app.MAppFeature;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:13
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppFeature", description = "功能管理", tags = {"平台应用-功能管理"})
public class AppFeatureEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AppFeatureService appFeatureService;
    @RequestMapping(value = ServiceApi.AppFeature.AppFeature, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature")
    public MAppFeature getAppFeature(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        AppFeature appFeature = appFeatureService.retrieve(id);
        return convertToModel(appFeature, MAppFeature.class);
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeatures, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature列表")
    public Collection<MAppFeature> getAppFeatures(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        List<AppFeature> appFeatureList = appFeatureService.search(fields, filters, sorts, page, size);
        pagedResponse(request, response, appFeatureService.getCount(filters), page, size);
        return convertToModels(appFeatureList, new ArrayList<>(appFeatureList.size()), MAppFeature.class, fields);
    }
    @RequestMapping(value = ServiceApi.AppFeature.FilterFeatureList, method = RequestMethod.GET)
    @ApiOperation(value = "获取过滤AppFeature列表")
    public Boolean getAppFeaturesFilter(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters) throws Exception {
        Long count = appFeatureService.getCount(filters);
        return count > 0 ? true : false;
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeatures, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppFeature")
    public MAppFeature createAppFeature(
            @ApiParam(name = "AppFeature", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String AppFeatureJson) throws Exception {
        AppFeature appFeature = toEntity(AppFeatureJson, AppFeature.class);
        appFeature = appFeatureService.createAppFeature(appFeature);
        // 拼接菜单JSON对象字符串,并保存
        appFeature = appFeatureService.joinMenuItemJsonStr(appFeature);
        appFeatureService.save(appFeature);
        return convertToModel(appFeature, MAppFeature.class);
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeatures, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppFeature")
    public MAppFeature updateAppFeature(
            @ApiParam(name = "AppFeature", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson) throws Exception {
        AppFeature appFeature = toEntity(appJson, AppFeature.class);
        if (appFeatureService.retrieve(appFeature.getId()) == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "应用不存在");
        }
        // 拼接菜单JSON对象字符串
        appFeature = appFeatureService.joinMenuItemJsonStr(appFeature);
        appFeatureService.save(appFeature);
        return convertToModel(appFeature, MAppFeature.class);
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeature, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppFeature")
    public boolean deleteAppFeature(
            @ApiParam(name = "id", value = "id")
            @PathVariable(value = "id") int id) throws Exception {
        appFeatureService.delete(id);
        return true;
    }
    @RequestMapping(value = ServiceApi.AppFeature.FilterFeatureNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature列表(不分页)")
    public Collection<MAppFeature> getAppFeatureNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters) throws Exception {
        List<AppFeature> appFeatureList = appFeatureService.search(filters);
        return convertToModels(appFeatureList, new ArrayList<>(appFeatureList.size()), MAppFeature.class, "");
    }
    @RequestMapping(value = ServiceApi.AppFeature.FilterFeatureNoPageSorts, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature排序后的列表(不分页)")
    public Collection<MAppFeature> getAppFeatureNoPageSorts(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        List<AppFeature> appFeatureList = appFeatureService.search(filters, sorts);
        return convertToModels(appFeatureList, new ArrayList<>(appFeatureList.size()), MAppFeature.class, "");
    }
    @RequestMapping(value = ServiceApi.AppFeature.FindAppMenus, method = RequestMethod.GET)
    @ApiOperation(value = "根据权限,获取应用菜单")
    public List<Map<String, Object>> findAppMenus(
            @ApiParam(name = "appId", value = "应用ID", required = true)
            @RequestParam(value = "appId", required = true) String appId,
            @ApiParam(name = "userId", value = "用户ID", required = true)
            @RequestParam(value = "userId", required = true) String userId) throws Exception {
        return appFeatureService.findAppMenus(appId, userId, 0);
    }
}

+ 49 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/AppVersionEndPoint.java

@ -0,0 +1,49 @@
package com.yihu.ehr.basic.apps.controller;
import com.yihu.ehr.basic.apps.service.AppVersionService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.app.version.AppVersion;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Trick on 2018/3/12.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AppVersion", description = "上饶APP资源版本", tags = {"上饶APP应用版本管理"})
public class AppVersionEndPoint extends EnvelopRestEndPoint{
    @Autowired
    private AppVersionService appVersionService;
    @RequestMapping(value = ServiceApi.AppVersion.FindAppVersion, method = RequestMethod.GET)
    @ApiOperation(value = "获取App版本")
    public Envelop getAppVersion(
            @ApiParam(name = "code", value = "当前版本ID", defaultValue = "")
            @RequestParam(value = "code")String code,
            @ApiParam(name = "version", value = "要获取的版本", defaultValue = "")
            @RequestParam(value = "version", required = false)String version){
        AppVersion temp = appVersionService.getAppVersionByCode(code);
        if (temp == null) {
            return failed("无效的APP类型失败!");
        }
        /*if (version > 0) {
            //将版本返回前端,前端判断版本是否一致,决定升级与否
            return success(temp);
        } else {
            return failed("版本号有误");
        }*/
        return success(temp);
    }
}

+ 79 - 0
src/main/java/com.yihu.ehr/basic/apps/controller/UserAppEndPoint.java

@ -0,0 +1,79 @@
package com.yihu.ehr.basic.apps.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.apps.model.UserApp;
import com.yihu.ehr.basic.apps.service.UserAppService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.model.app.MUserApp;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * @author yeshijie
 * @version 1.0
 * @created 2017年2月16日18:04:13
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "UserApp", description = "用户应用关联", tags = {"平台应用-用户应用关联"})
public class UserAppEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private UserAppService userAppService;
    @RequestMapping(value = ServiceApi.UserApp.UserAppList, method = RequestMethod.GET)
    @ApiOperation(value = "根据用户id获取App列表")
    public Collection<MUserApp> getAppApiNoPage(
            @ApiParam(name = "userId", value = "用户id")
            @RequestParam(value = "userId", required = true) String userId) throws Exception {
        String filters = "userId="+userId;
        List<UserApp> userAppList =  userAppService.search(filters);
        return convertToModels(userAppList,new ArrayList<>(userAppList.size()),MUserApp.class, "");
    }
    @RequestMapping(value = ServiceApi.UserApp.UserAppShow, method = RequestMethod.GET)
    @ApiOperation(value = "更新用户权限应用的云门户展示状态")
    public MUserApp updateUserAppShowFlag(
            @ApiParam(name = "id", value = "用户APP关联ID")
            @RequestParam(value = "id", required = true) String id,
            @ApiParam(name = "flag", value = "要更新的展示状态", defaultValue = "1")
            @RequestParam(value = "flag", required = true) String flag) throws Exception {
            List<UserApp> userAppList = userAppService.findByField("id", id);
            UserApp userApp = new UserApp();
            if(userAppList != null){
                userApp = userAppList.get(0);
                userApp.setShowFlag(Integer.parseInt(flag));
                MUserApp mUserApp = convertToModel(userAppService.save(userApp),MUserApp.class);
                return mUserApp;
            }else{
                return null;
        }
    }
    @RequestMapping(value = ServiceApi.UserApp.CreateUserApp, method = RequestMethod.GET)
    @ApiOperation(value = "创建用户与app关联")
    public MUserApp createUserApp(
            @ApiParam(name = "userAppJson", value = "用户APP对象json")
            @RequestParam(value = "userAppJson", required = true) String userAppJson) throws Exception {
            UserApp userApp =objectMapper.readValue(userAppJson, UserApp.class);
            userApp.setShowFlag(1);
            userApp.setOrgId("");
            userApp.setOrgName("");
            MUserApp mUserApp = convertToModel(userAppService.save(userApp),MUserApp.class);
            return mUserApp;
    }
}

+ 11 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppApiCategoryDao.java

@ -0,0 +1,11 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.api.AppApiCategory;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Dao - Api业务类别
 * Created by progr1mmer on 2018/3/14.
 */
public interface AppApiCategoryDao extends PagingAndSortingRepository<AppApiCategory, Integer> {
}

+ 24 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppApiDao.java

@ -0,0 +1,24 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.AppApi;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
 * AppApi 操作接口。
 *
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:05:46
 */
public interface AppApiDao extends JpaRepository<AppApi, Integer> {
    List<AppApi> findByCategory(Integer categoryId);
    List<AppApi> findByName(String name);
    void deleteByAppId(String appId);
    List<AppApi> findByAppId(String appId);
}

+ 14 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppApiErrorCodeDao.java

@ -0,0 +1,14 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.api.AppApiErrorCode;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Dao - Api错误码
 * Created by progr1mmer on 2018/3/15.
 */
public interface AppApiErrorCodeDao extends PagingAndSortingRepository<AppApiErrorCode, Integer> {
    void deleteByAppApiId(Integer apiId);
}

+ 17 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppApiParameterDao.java

@ -0,0 +1,17 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.AppApiParameter;
import org.springframework.data.jpa.repository.JpaRepository;
/**
 * AppApiParameter 操作接口。
 *
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:05:41
 */
public interface AppApiParameterDao extends JpaRepository<AppApiParameter, Integer> {
    void deleteByAppApiId(Integer id);
}

+ 16 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppApiResponseDao.java

@ -0,0 +1,16 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.AppApiResponse;
import org.springframework.data.jpa.repository.JpaRepository;
/**
 * AppApiResponse 操作接口。
 *
 * @author linz
 * @version 1.0
 * @created 2015.12.16 15:10
 */
public interface AppApiResponseDao extends JpaRepository<AppApiResponse, Integer> {
    void deleteByAppApiId(Integer id);
}

+ 19 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppDao.java

@ -0,0 +1,19 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.App;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
 * App 操作接口。
 *
 * @author Sand
 * @version 1.0
 * @created 2015.12.16 15:10
 */
public interface AppDao extends JpaRepository<App, String> {
    App findByName(String name);
    List<App> findByIdAndSecret(String appId, String secret);
}

+ 16 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppFeatureDao.java

@ -0,0 +1,16 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.AppFeature;
import org.springframework.data.jpa.repository.JpaRepository;
/**
 * AppApiFeature 操作接口。
 *
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:05:13
 */
public interface AppFeatureDao extends JpaRepository<AppFeature, String> {
    void deleteByAppId(String appId);
}

+ 11 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppVersionRepository.java

@ -0,0 +1,11 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.app.version.AppVersion;
import org.springframework.data.jpa.repository.JpaRepository;
/**
 * Created by Trick on 2018/3/12.
 */
public interface AppVersionRepository extends JpaRepository<AppVersion, String> {
    public AppVersion findBycode(String code);
}

+ 17 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/AppsRelationDao.java

@ -0,0 +1,17 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.AppsRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
 * App 操作接口。
 *
 * @author Sand
 * @version 1.0
 * @created 2015.12.16 15:10
 */
public interface AppsRelationDao extends JpaRepository<AppsRelation, String> {
}

+ 11 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/OauthClientDetailsDao.java

@ -0,0 +1,11 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.oauth2.OauthClientDetails;
import org.springframework.data.jpa.repository.JpaRepository;
/**
 * Created by progr1mmer on 2018/1/23.
 */
public interface OauthClientDetailsDao extends JpaRepository<OauthClientDetails, String> {
}

+ 11 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/ReportCategoryAppRelationDao.java

@ -0,0 +1,11 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.report.ReportCategoryAppRelation;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by progr1mmer on 2018/4/8.
 */
public interface ReportCategoryAppRelationDao  extends PagingAndSortingRepository<ReportCategoryAppRelation, Integer> {
    void deleteByAppId(String appId);
}

+ 11 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/RsAppResourceDao.java

@ -0,0 +1,11 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.resource.RsAppResource;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by progr1mmer on 2018/4/8.
 */
public interface RsAppResourceDao  extends PagingAndSortingRepository<RsAppResource, String> {
    void deleteByAppId(String appId);
}

+ 11 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/RsAppResourceMetadataDao.java

@ -0,0 +1,11 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.entity.resource.RsAppResourceMetadata;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by progr1mmer on 2018/4/8.
 */
public interface RsAppResourceMetadataDao  extends PagingAndSortingRepository<RsAppResourceMetadata, String> {
    void deleteByAppId(String appId);
}

+ 33 - 0
src/main/java/com.yihu.ehr/basic/apps/dao/UserAppDao.java

@ -0,0 +1,33 @@
package com.yihu.ehr.basic.apps.dao;
import com.yihu.ehr.basic.apps.model.UserApp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * @author yeshijie
 * @version 1.0
 * @created 2017年2月16日18:04:13
 */
public interface UserAppDao extends JpaRepository<UserApp, String> {
    @Query("select userApp from UserApp userApp where userApp.appId = :appId and userApp.userId = :userId" )
    UserApp findByAppIdAndUserId(@Param("appId") String appId, @Param("userId") String userId);
    @Modifying
//    @Query("update UserApp userApp set userApp.status = 1 where userApp.userId = :userId")
    void deleteByUserId(@Param("userId") String userId);
    @Modifying
    void deleteByAppId(@Param("appId") String appId);
    @Query("select userApp from UserApp userApp where userApp.appId = :appId " )
    List<UserApp> findByAppId(@Param("appId") String appId);
    @Query("select userApp from UserApp userApp where userApp.userId in (:userIds) " )
    List<UserApp> findByuserId(@Param("userIds") List<String> userIds);
}

+ 226 - 0
src/main/java/com.yihu.ehr/basic/apps/model/App.java

@ -0,0 +1,226 @@
package com.yihu.ehr.basic.apps.model;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
 * APP对象。
 *
 * @author Sand
 * @version 1.0
 * @created 03_8月_2015 16:53:21
 */
@Entity
@Table(name = "apps")
@Access(value = AccessType.FIELD)
public class App {
    @Id
    @GeneratedValue(generator = "Generator")
    @GenericGenerator(name = "Generator", strategy = "assigned")
    @Column(name = "id", unique = true, nullable = false)
    private String id;
    private String name;
    private String secret;
    private String url;
    private String outUrl;
    private String creator;
    private String auditor;
    private Date createTime;
    private Date auditTime;
    private String catalog;
    private String status;
    private String description;
    private String tags;
    private String org;
    private String code;
    private int sourceType;
    private String icon;
    private int releaseFlag;
    private String manageType; // 管理类型,dictId=94
    /**
     * 医生工作站的应用分类,与catalog并无父子关系,1、在线学习,2在线服务
     */
    private String doctorManageType;
    public App() {
    }
    @Column(name = "id", nullable = true)
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    @Column(name = "name", nullable = true)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "secret", nullable = true)
    public String getSecret() {
        return secret;
    }
    public void setSecret(String secret) {
        this.secret = secret;
    }
    @Column(name = "url", nullable = true)
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    @Column(name = "out_url", nullable = true)
    public String getOutUrl() {
        return outUrl;
    }
    public void setOutUrl(String outUrl) {
        this.outUrl = outUrl;
    }
    @Column(name = "creator", nullable = true)
    public String getCreator() {
        return creator;
    }
    public void setCreator(String creator) {
        this.creator = creator;
    }
    @Column(name = "auditor", nullable = true)
    public String getAuditor() {
        return auditor;
    }
    public void setAuditor(String auditor) {
        this.auditor = auditor;
    }
    @Column(name = "create_time", nullable = true)
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @Column(name = "audit_time", nullable = true)
    public Date getAuditTime() {
        return auditTime;
    }
    public void setAuditTime(Date auditTime) {
        this.auditTime = auditTime;
    }
    @Column(name = "catalog", nullable = true)
    public String getCatalog() {
        return catalog;
    }
    public void setCatalog(String catalog) {
        this.catalog = catalog;
    }
    @Column(name = "status", nullable = true)
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    @Column(name = "description", nullable = true)
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "tags", nullable = true)
    public List<String> getTags() {
        List<String> list = new ArrayList<>();
        if (StringUtils.isEmpty(tags)) {
        } else {
            String[] arr = tags.split(";|;");
            list = Arrays.asList(arr);
        }
        return list;
    }
    public void setTags(List<String> tags) {
        if (tags.size() > 0) {
            this.tags = StringUtils.join(tags.toArray(), ";");
        } else {
            this.tags = "";
        }
    }
    @Column(name = "org", nullable = true)
    public String getOrg() {
        return org;
    }
    public void setOrg(String org) {
        this.org = org;
    }
    @Column(name = "code", nullable = true)
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Column(name = "source_type", nullable = true)
    public int getSourceType() {
        return sourceType;
    }
    public void setSourceType(int sourceType) {
        this.sourceType = sourceType;
    }
    @Column(name = "icon", nullable = true)
    public String getIcon() {
        return icon;
    }
    public void setIcon(String icon) {
        this.icon = icon;
    }
    @Column(name = "release_flag", nullable = true)
    public int getReleaseFlag() {
        return releaseFlag;
    }
    public void setReleaseFlag(int releaseFlag) {
        this.releaseFlag = releaseFlag;
    }
    @Column(name = "manage_type")
    public String getManageType() {
        return manageType;
    }
    public void setManageType(String manageType) {
        this.manageType = manageType;
    }
    @Column(name = "doctor_manage_type")
    public String getDoctorManageType() {
        return doctorManageType;
    }
    public void setDoctorManageType(String doctorManageType) {
        this.doctorManageType = doctorManageType;
    }
}

+ 234 - 0
src/main/java/com.yihu.ehr/basic/apps/model/AppApi.java

@ -0,0 +1,234 @@
package com.yihu.ehr.basic.apps.model;
import javax.persistence.*;
/**
 * APP_api对象。
 *
 * @author linzhuo
 * @version 1.0
 * @created 2016年7月7日17:45:30
 */
@Entity
@Table(name = "apps_api")
@Access(value = AccessType.PROPERTY)
public class AppApi {
    public enum TransferProtocol {
        http,
        https
    }
    private int id;
    private String appId; //所属应用ID
    private String name; //Api名称
    private String description; //Api描述
    private String type; //类别 1 - API;  2 - 应用; 3 - SDK
    private String method; //请求方式 0 - GET;  1 - POST;  2 - DELETE;  3 - PUT
    private String protocol; //对外协议 0 - WebService;  1 - RESTful
    private String innerProtocol; //对内协议 0 - WebService;  1 - RESTful
    private TransferProtocol transferProtocol; //0 - HTTP;  1 - HTTPS
    private String version; //版本
    private int parentId; //该字段弃用
    private String activityType; //生失效标识 0 - 无效果;  1 - 有效
    private String parameterDemo; //请求参数示例
    private String responseDemo; //返回结果示例
    private String errorDemo; //接口请求错误示例
    private String openLevel; //开放程度 0 - 私有;  1 - 公开
    private String auditLevel; //审计程度 0 - 不审计;  1 - 审计
    private String methodName; //对外网关接口方法名
    private String microServiceUri; //对外接口实际IP地址和端口
    private String msMethodName; //内部实际微服务中方法名
    private String microServiceName; //内部实际微服务名称
    private Integer category; //业务类别
    private String categoryName; //业务类别名称
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name = "app_id", nullable = true)
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    @Column(name = "name", nullable = true)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "description", nullable = true)
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "type", nullable = true)
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Column(name = "method", nullable = true)
    public String getMethod() {
        return method;
    }
    public void setMethod(String method) {
        this.method = method;
    }
    @Column(name = "protocol")
    public String getProtocol() {
        return protocol;
    }
    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }
    @Column(name = "inner_protocol")
    public String getInnerProtocol() {
        return innerProtocol;
    }
    public void setInnerProtocol(String innerProtocol) {
        this.innerProtocol = innerProtocol;
    }
    @Column(name = "transfer_protocol")
    public TransferProtocol getTransferProtocol() {
        return transferProtocol;
    }
    public void setTransferProtocol(TransferProtocol transferProtocol) {
        this.transferProtocol = transferProtocol;
    }
    @Column(name = "version", nullable = true)
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
    @Column(name = "parent_id", nullable = true)
    public int getParentId() {
        return parentId;
    }
    public void setParentId(int parentId) {
        this.parentId = parentId;
    }
    @Column(name = "parameter_demo", nullable = true)
    public String getParameterDemo() {
        return parameterDemo;
    }
    public void setParameterDemo(String parameterDemo) {
        this.parameterDemo = parameterDemo;
    }
    @Column(name = "activity_type", nullable = true)
    public String getActivityType() {
        return activityType;
    }
    public void setActivityType(String activityType) {
        this.activityType = activityType;
    }
    @Column(name = "response_demo", nullable = true)
    public String getResponseDemo() {
        return responseDemo;
    }
    public void setResponseDemo(String responseDemo) {
        this.responseDemo = responseDemo;
    }
    @Column(name = "error_demo")
    public String getErrorDemo() {
        return errorDemo;
    }
    public void setErrorDemo(String errorDemo) {
        this.errorDemo = errorDemo;
    }
    @Column(name = "open_level", nullable = true)
    public String getOpenLevel() {
        return openLevel;
    }
    public void setOpenLevel(String openLevel) {
        this.openLevel = openLevel;
    }
    @Column(name = "audit_level", nullable = true)
    public String getAuditLevel() {
        return auditLevel;
    }
    public void setAuditLevel(String auditLevel) {
        this.auditLevel = auditLevel;
    }
    @Column(name = "method_name", nullable = true)
    public String getMethodName() {
        return methodName;
    }
    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }
    @Column(name = "micro_service_url", nullable = true)
    public String getMicroServiceUri() {
        return microServiceUri;
    }
    public void setMicroServiceUri(String microServiceUri) {
        this.microServiceUri = microServiceUri;
    }
    @Column(name = "ms_method_name", nullable = true)
    public String getMsMethodName() {
        return msMethodName;
    }
    public void setMsMethodName(String msMethodName) {
        this.msMethodName = msMethodName;
    }
    @Column(name = "micro_service_name", nullable = true)
    public String getMicroServiceName() {
        return microServiceName;
    }
    public void setMicroServiceName(String microServiceName) {
        this.microServiceName = microServiceName;
    }
    @Column(name = "category")
    public Integer getCategory() {
        return category;
    }
    public void setCategory(Integer category) {
        this.category = category;
    }
    @Transient
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
}

+ 126 - 0
src/main/java/com.yihu.ehr/basic/apps/model/AppApiParameter.java

@ -0,0 +1,126 @@
package com.yihu.ehr.basic.apps.model;
import javax.persistence.*;
/**
 * apps_api_parameter对象。
 *
 * @author linzhuo
 * @version 1.0
 * @created 2016年7月7日17:45:30
 */
@Entity
@Table(name = "apps_api_parameter")
public class AppApiParameter {
    private int id;
    private String name; //参数名
    private String type; //参数类型
    private String dataType; //数据类型
    private String description; //说明
    private String required; //是否必须
    private int appApiId; //apiId
    private String memo; //备注
    private String defaultValue; //默认值
    private Integer maxLength; //最大长度
    private Integer sort; //序号
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name = "name", nullable = true)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "description", nullable = true)
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "type", nullable = true)
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Column(name = "data_type", nullable = true)
    public String getDataType() {
        return dataType;
    }
    public void setDataType(String dataType) {
        this.dataType = dataType;
    }
    @Column(name = "required", nullable = true)
    public String getRequired() {
        return required;
    }
    public void setRequired(String required) {
        this.required = required;
    }
    @Column(name = "app_api_id", nullable = true)
    public int getAppApiId() {
        return appApiId;
    }
    public void setAppApiId(int appApiId) {
        this.appApiId = appApiId;
    }
    @Column(name = "memo", nullable = true)
    public String getMemo() {
        return memo;
    }
    public void setMemo(String memo) {
        this.memo = memo;
    }
    @Column(name = "default_value", nullable = true)
    public String getDefaultValue() {
        return defaultValue;
    }
    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }
    @Column(name = "max_length", nullable = true)
    public Integer getMaxLength() {
        return maxLength;
    }
    public void setMaxLength(Integer maxLength) {
        this.maxLength = maxLength;
    }
    @Column(name = "sort", nullable = false)
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
}

+ 90 - 0
src/main/java/com.yihu.ehr/basic/apps/model/AppApiResponse.java

@ -0,0 +1,90 @@
package com.yihu.ehr.basic.apps.model;
import javax.persistence.*;
/**
 * apps_api_response对象。
 *
 * @author linzhuo
 * @version 1.0
 * @created 2016年7月7日17:45:30
 */
@Entity
@Table(name = "apps_api_response")
public class AppApiResponse {
    private int id;
    private String name;
    private String dataType;
    private String description;
    private int appApiId;
    private String memo;
    private Integer sort; //序号
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name = "name", nullable = true)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "description", nullable = true)
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "data_type", nullable = true)
    public String getDataType() {
        return dataType;
    }
    public void setDataType(String dataType) {
        this.dataType = dataType;
    }
    @Column(name = "app_api_id", nullable = true)
    public int getAppApiId() {
        return appApiId;
    }
    public void setAppApiId(int appApiId) {
        this.appApiId = appApiId;
    }
    @Column(name = "memo", nullable = true)
    public String getMemo() {
        return memo;
    }
    public void setMemo(String memo) {
        this.memo = memo;
    }
    @Column(name = "sort", nullable = false)
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
}

+ 169 - 0
src/main/java/com.yihu.ehr/basic/apps/model/AppFeature.java

@ -0,0 +1,169 @@
package com.yihu.ehr.basic.apps.model;
import javax.persistence.*;
/**
 * apps_api_feature对象。
 *
 * @author linzhuo
 * @version 1.0
 * @created 2016年7月7日17:45:30
 */
@Entity
@Table(name = "apps_feature")
public class AppFeature {
    private int id;
    private String code; // 菜单编码
    private String name; // 菜单名称
    private String description; // 菜单描述
    private String type; // 类型,1:模块,2:菜单,3:功能按钮。
    private int parentId; // 父菜单
    private String url; // 菜单相对访问路径。模块时没有值,菜单时有值,按钮时不一定有值。
    private String prefixUrl; // 菜单相对访问路径前缀,即JavaWeb上下文路径或站点+上下文路径。
    private String iconUrl; // 图标访问路径
    private String auditLevel; // 审计类型,0:不审计,1:审计。
    private String openLevel; // 开放级别,0:私有(不作为授权对象),1:公开(收费/免费)
    private String appId; // 应用ID
    private Integer sort; // 菜单排序
    private Integer level; // 菜单级别
    private String content; // 页面菜单拼接对象
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name = "name", nullable = true)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Column(name = "description", nullable = true)
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "code", nullable = true)
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    @Column(name = "type", nullable = true)
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Column(name = "parent_id", nullable = true)
    public int getParentId() {
        return parentId;
    }
    public void setParentId(int parentId) {
        this.parentId = parentId;
    }
    @Column(name = "url", nullable = true)
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    @Column(name = "prefix_url", nullable = true)
    public String getPrefixUrl() {
        return prefixUrl;
    }
    public void setPrefixUrl(String prefixUrl) {
        this.prefixUrl = prefixUrl;
    }
    @Column(name = "icon_url", nullable = true)
    public String getIconUrl() {
        return iconUrl;
    }
    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }
    @Column(name = "audit_level", nullable = true)
    public String getAuditLevel() {
        return auditLevel;
    }
    public void setAuditLevel(String auditLevel) {
        this.auditLevel = auditLevel;
    }
    @Column(name = "open_level", nullable = true)
    public String getOpenLevel() {
        return openLevel;
    }
    public void setOpenLevel(String openLevel) {
        this.openLevel = openLevel;
    }
    @Column(name = "app_id", nullable = true)
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    @Column(name = "sort", nullable = true)
    public Integer getSort() {
        return sort;
    }
    public void setSort(Integer sort) {
        this.sort = sort;
    }
    @Column(name = "level", nullable = true)
    public Integer getLevel() {
        return level;
    }
    public void setLevel(Integer level) {
        this.level = level;
    }
    @Column(name = "content", nullable = true)
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
}

+ 81 - 0
src/main/java/com.yihu.ehr/basic/apps/model/AppsRelation.java

@ -0,0 +1,81 @@
package com.yihu.ehr.basic.apps.model;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
 * Created by Dell on 2017/2/13.
 */
@Entity
@Table(name = "apps_relation", schema = "", catalog = "healtharchive")
public class AppsRelation {
    private int id;
    private String parentAppId;
    private String parentAppName;
    private String appId;
    private String appName;
    private Integer type;
    @Id
    @GeneratedValue(generator = "Generator")
    @GenericGenerator(name = "Generator", strategy = "identity")
    @Column(name = "id", nullable = false, insertable = true, updatable = true)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name = "parent_app_id", nullable = false)
    public String getParentAppId() {
        return parentAppId;
    }
    public void setParentAppId(String parentAppId) {
        this.parentAppId = parentAppId;
    }
    @Column(name = "app_id", nullable = false)
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    @Column(name = "type", nullable = false)
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @Column(name = "app_name", nullable = false)
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
    @Column(name = "parent_app_name", nullable = true, insertable = true, updatable = true)
    public String getParentAppName() {
        return parentAppName;
    }
    public void setParentAppName(String parentAppName) {
        this.parentAppName = parentAppName;
    }
}

+ 104 - 0
src/main/java/com.yihu.ehr/basic/apps/model/OrgApp.java

@ -0,0 +1,104 @@
package com.yihu.ehr.basic.apps.model;
import javax.persistence.*;
/**
 * Created by Dell on 2017/2/13.
 */
@Entity
@Table(name = "org_app", schema = "", catalog = "healtharchive")
public class OrgApp {
    private int id;
    private String orgId;
    private String orgName;
    private String appId;
    private String appName;
    private Integer status;
    @Id
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Basic
    @Column(name = "org_id", nullable = false, insertable = true, updatable = true)
    public String getOrgId() {
        return orgId;
    }
    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }
    @Basic
    @Column(name = "org_name", nullable = true, insertable = true, updatable = true)
    public String getOrgName() {
        return orgName;
    }
    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
    @Basic
    @Column(name = "app_id", nullable = false, insertable = true, updatable = true)
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    @Basic
    @Column(name = "app_name", nullable = true, insertable = true, updatable = true)
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
    @Basic
    @Column(name = "status", nullable = true, insertable = true, updatable = true)
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OrgApp orgApp = (OrgApp) o;
        if (id != orgApp.id) return false;
        if (orgId != null ? !orgId.equals(orgApp.orgId) : orgApp.orgId != null) return false;
        if (orgName != null ? !orgName.equals(orgApp.orgName) : orgApp.orgName != null) return false;
        if (appId != null ? !appId.equals(orgApp.appId) : orgApp.appId != null) return false;
        if (appName != null ? !appName.equals(orgApp.appName) : orgApp.appName != null) return false;
        if (status != null ? !status.equals(orgApp.status) : orgApp.status != null) return false;
        return true;
    }
    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (orgId != null ? orgId.hashCode() : 0);
        result = 31 * result + (orgName != null ? orgName.hashCode() : 0);
        result = 31 * result + (appId != null ? appId.hashCode() : 0);
        result = 31 * result + (appName != null ? appName.hashCode() : 0);
        result = 31 * result + (status != null ? status.hashCode() : 0);
        return result;
    }
}

+ 142 - 0
src/main/java/com.yihu.ehr/basic/apps/model/UserApp.java

@ -0,0 +1,142 @@
package com.yihu.ehr.basic.apps.model;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
 * Created by Dell on 2017/2/13.
 */
@Entity
@Table(name = "user_app", schema = "", catalog = "healtharchive")
public class UserApp {
    private int id;
    private String userId;
    private String userName;
    private String orgId;
    private String orgName;
    private String appId;
    private String appName;
    private Integer status;
    private Integer showFlag;
    @Id
    @GeneratedValue(generator = "Generator")
    @GenericGenerator(name = "Generator", strategy = "identity")
    @Column(name = "id", nullable = false, insertable = true, updatable = true)
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    @Column(name = "user_id", nullable = false, insertable = true, updatable = true)
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    @Column(name = "user_name", nullable = true, insertable = true, updatable = true)
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    @Column(name = "org_id", nullable = false, insertable = true, updatable = true)
    public String getOrgId() {
        return orgId;
    }
    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }
    @Column(name = "org_name", nullable = true, insertable = true, updatable = true)
    public String getOrgName() {
        return orgName;
    }
    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
    @Column(name = "app_id", nullable = false, insertable = true, updatable = true)
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    @Column(name = "app_name", nullable = true, insertable = true, updatable = true)
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
    @Column(name = "status", nullable = true, insertable = true, updatable = true)
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    @Column(name = "show_flag", nullable = true, insertable = true, updatable = true)
    public Integer getShowFlag() {
        return showFlag;
    }
    public void setShowFlag(Integer showFlag) {
        this.showFlag = showFlag;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserApp userApp = (UserApp) o;
        if (id != userApp.id) return false;
        if (userId != null ? !userId.equals(userApp.userId) : userApp.userId != null) return false;
        if (userName != null ? !userName.equals(userApp.userName) : userApp.userName != null) return false;
        if (orgId != null ? !orgId.equals(userApp.orgId) : userApp.orgId != null) return false;
        if (orgName != null ? !orgName.equals(userApp.orgName) : userApp.orgName != null) return false;
        if (appId != null ? !appId.equals(userApp.appId) : userApp.appId != null) return false;
        if (appName != null ? !appName.equals(userApp.appName) : userApp.appName != null) return false;
        if (status != null ? !status.equals(userApp.status) : userApp.status != null) return false;
        if (showFlag != null ? !showFlag.equals(userApp.showFlag) : userApp.status != null) return false;
        return true;
    }
    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + (orgId != null ? orgId.hashCode() : 0);
        result = 31 * result + (orgName != null ? orgName.hashCode() : 0);
        result = 31 * result + (appId != null ? appId.hashCode() : 0);
        result = 31 * result + (appName != null ? appName.hashCode() : 0);
        result = 31 * result + (status != null ? status.hashCode() : 0);
        result = 31 * result + (showFlag != null ? showFlag.hashCode() : 0);
        return result;
    }
}

+ 26 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppApiCategoryService.java

@ -0,0 +1,26 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.AppApiCategoryDao;
import com.yihu.ehr.entity.api.AppApiCategory;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/**
 * Service - 接口分类
 * Created by progr1mmer on 2018/3/14.
 */
@Service
@Transactional
public class AppApiCategoryService extends BaseJpaService<AppApiCategory, AppApiCategoryDao> {
    @Autowired
    private AppApiCategoryDao appApiCategoryDao;
    public AppApiCategory findOne(Integer id) {
        return appApiCategoryDao.findOne(id);
    }
}

+ 18 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppApiErrorCodeService.java

@ -0,0 +1,18 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.AppApiErrorCodeDao;
import com.yihu.ehr.entity.api.AppApiErrorCode;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/**
 * Service - Api错误码
 * Created by progr1mmer on 2018/3/15.
 */
@Service
@Transactional
public class AppApiErrorCodeService extends BaseJpaService<AppApiErrorCode, AppApiErrorCodeDao> {
}

+ 47 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppApiParameterService.java

@ -0,0 +1,47 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.AppApiParameterDao;
import com.yihu.ehr.basic.apps.model.AppApiParameter;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:41
 */
@Service
@Transactional
public class AppApiParameterService extends BaseJpaService<AppApiParameter, AppApiParameterDao> {
    @Autowired
    private AppApiParameterDao appApiParameterRepository;
    public AppApiParameterService() {
    }
    public Page<AppApiParameter> getAppApiParameterList(String sorts, int page, int size){
        AppApiParameterDao repo = (AppApiParameterDao)getJpaRepository();
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return repo.findAll(pageable);
    }
    public AppApiParameter createAppApiParameter(AppApiParameter appApiParameter) {
        appApiParameterRepository.save(appApiParameter);
        return appApiParameter;
    }
    public AppApiParameter updateAppApiParameter(AppApiParameter appApiParameter){
        appApiParameterRepository.save(appApiParameter);
        return appApiParameter;
    }
    public void  deleteAppApiParameter(Integer id){
        appApiParameterRepository.delete(id);
    }
}

+ 47 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppApiResponseService.java

@ -0,0 +1,47 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.AppApiResponseDao;
import com.yihu.ehr.basic.apps.model.AppApiResponse;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:54
 */
@Service
@Transactional
public class AppApiResponseService extends BaseJpaService<AppApiResponse, AppApiResponseDao> {
    @Autowired
    private AppApiResponseDao xAppApiResponseRepository;
    public AppApiResponseService() {
    }
    public Page<AppApiResponse> getAppApiResponseList(String sorts, int page, int size){
        AppApiResponseDao repo = (AppApiResponseDao)getJpaRepository();
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return repo.findAll(pageable);
    }
    public AppApiResponse createAppApiResponse(AppApiResponse appApiResponse) {
        xAppApiResponseRepository.save(appApiResponse);
        return appApiResponse;
    }
    public AppApiResponse updateAppApiResponse(AppApiResponse appApiResponse){
        xAppApiResponseRepository.save(appApiResponse);
        return appApiResponse;
    }
    public void  deleteAppApiResponse(Integer id){
        xAppApiResponseRepository.delete(id);
    }
}

+ 247 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppApiService.java

@ -0,0 +1,247 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.AppApiErrorCodeDao;
import com.yihu.ehr.basic.apps.dao.AppApiParameterDao;
import com.yihu.ehr.basic.apps.dao.AppApiDao;
import com.yihu.ehr.basic.apps.dao.AppApiResponseDao;
import com.yihu.ehr.basic.apps.model.AppApi;
import com.yihu.ehr.basic.apps.model.AppApiParameter;
import com.yihu.ehr.basic.apps.model.AppApiResponse;
import com.yihu.ehr.basic.user.dao.RoleApiRelationDao;
import com.yihu.ehr.basic.user.dao.RoleAppRelationDao;
import com.yihu.ehr.basic.user.dao.RolesDao;
import com.yihu.ehr.basic.user.entity.RoleApiRelation;
import com.yihu.ehr.basic.user.entity.RoleAppRelation;
import com.yihu.ehr.basic.user.entity.Roles;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.entity.api.AppApiErrorCode;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:05:04
 */
@Service
@Transactional
public class AppApiService extends BaseJpaService<AppApi, AppApiDao> {
    private static final String ADD = "add";
    private static final String DELETE = "delete";
    private static final String UPDATE = "update";
    private static final String DATA_STATUS = "__status";
    private static final Integer NEW_DATA = 0;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private AppApiDao appApiRepository;
    @Autowired
    private AppApiParameterDao appApiParameterRepository;
    @Autowired
    private AppApiResponseDao appApiResponseRepository;
    @Autowired
    private RoleApiRelationDao xRoleApiRelationRepository;
    @Autowired
    private RoleAppRelationDao xRoleAppRelationRepository;
    @Autowired
    private AppApiErrorCodeDao appApiErrorCodeDao;
    @Autowired
    private RolesDao xRolesRepository;
    public Page<AppApi> getAppApiList(String sorts, int page, int size){
        AppApiDao repo = (AppApiDao)getJpaRepository();
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return repo.findAll(pageable);
    }
    public AppApi createAppApi(AppApi appApi) {
        if ("".equals(appApi.getMethodName())){
            appApi.setMethodName(null);
        }
        appApiRepository.save(appApi);
        return appApi;
    }
    public AppApi updateAppApi(AppApi appApi){
        appApiRepository.save(appApi);
        return appApi;
    }
    public void  deleteAppApi(Integer id){
        appApiRepository.delete(id);
    }
    public AppApi completeSave(String appApiStr, String apiParamStr, String apiResponseStr, String apiErrorCodeStr) throws IOException {
        AppApi appApi = objectMapper.readValue(appApiStr, AppApi.class);
        AppApi newAppApi = appApiRepository.save(appApi);
        saveParamAndResponseAndErrorCode(newAppApi.getId(), apiParamStr, apiResponseStr, apiErrorCodeStr);
        return newAppApi;
    }
    public void completeDelete(Integer id) {
        appApiParameterRepository.deleteByAppApiId(id);
        appApiResponseRepository.deleteByAppApiId(id);
        xRoleApiRelationRepository.deleteByApiId((long)id);
        appApiErrorCodeDao.deleteByAppApiId(id);
        appApiRepository.delete(id);
    }
    public AppApi findById(Integer id) {
        return appApiRepository.findOne(id);
    }
    public List<AppApi> findByCateId(Integer categoryId) {
        return appApiRepository.findByCategory(categoryId);
    }
    public List<AppApi> authApiList(String clientId) {
        String sql =  "SELECT aa.* FROM apps_api aa \n" +
                "\tLEFT JOIN role_api_relation rar ON rar.app_api_id = aa.id \n" +
                "\tWHERE rar.role_id IN (SELECT role_id FROM role_app_relation WHERE app_id ='" + clientId + "') \n" +
                "\tAND LENGTH(aa.micro_service_url) > 0 AND LENGTH(aa.ms_method_name) > 0";
        RowMapper rowMapper = BeanPropertyRowMapper.newInstance(AppApi.class);
        return (List<AppApi>)jdbcTemplate.query(sql, rowMapper);
    }
    public void authApi(String code, String appId, String appApiId) {
        Roles roles =  xRolesRepository.findByCodeAndAppId(code, appId);
        if (null == roles) {
            //创建扩展角色
            roles = new Roles();
            roles.setCode(code);
            roles.setName("扩展开发者");
            roles.setDescription("开放平台扩展开发者");
            roles.setAppId(appId);
            roles.setType("0");
            roles = xRolesRepository.save(roles);
            RoleAppRelation roleAppRelation = new RoleAppRelation();
            roleAppRelation.setAppId(code);
            roleAppRelation.setRoleId(roles.getId());
            xRoleAppRelationRepository.save(roleAppRelation);
        }
        String [] appApiIdArr = appApiId.split(",");
        for (String id : appApiIdArr) {
            if (null == xRoleApiRelationRepository.findRelation(new Long(id), roles.getId())) {
                RoleApiRelation roleApiRelation = new RoleApiRelation();
                roleApiRelation.setRoleId(roles.getId());
                roleApiRelation.setApiId(new Long(id));
                xRoleApiRelationRepository.save(roleApiRelation);
            }
        }
    }
    public void unAuthApi(String code, String appId, String appApiId) {
        Roles roles =  xRolesRepository.findByCodeAndAppId(code, appId);
        if (null == roles) {
            return;
        }
        String [] appApiIdArr = appApiId.split(",");
        for (String id : appApiIdArr) {
            xRoleApiRelationRepository.deleteByApiIdAndRoleId(new Long(id), roles.getId());
        }
    }
    /**
     * 操作apiParam及apiResponse及apiErrorCode
     *
     * @param apiId
     * @param apiParam
     * @param apiResponse
     */
    private void saveParamAndResponseAndErrorCode(Integer apiId, String apiParam, String apiResponse, String apiErrorCode) throws IOException {
        List<Map<String, Object>> list;
        if (!StringUtils.isEmpty(apiParam)) {
            list = objectMapper.readValue(apiParam, List.class);
            for (Map<String, Object> paramMap : list) {
                //删除的是新增的数据直接跳过
                if (DELETE.equals(paramMap.get(DATA_STATUS)) && NEW_DATA.equals(paramMap.get("id") + "")) {
                    continue;
                } else {
                    paramMap.put("appApiId", apiId);
                    String json = objectMapper.writeValueAsString(paramMap);
                    AppApiParameter appApiParameter = objectMapper.readValue(json, AppApiParameter.class);
                    if (ADD.equals(paramMap.get(DATA_STATUS))) {
                        appApiParameterRepository.save(appApiParameter);
                    } else if (UPDATE.equals(paramMap.get(DATA_STATUS))) {
                        AppApiParameter oldAppApiParameter = appApiParameterRepository.findOne(appApiParameter.getId());
                        if (oldAppApiParameter == null) {
                            throw new ApiException(ErrorCode.OBJECT_NOT_FOUND, "更新的请求参数不存在:" + appApiParameter.getId());
                        }
                        appApiParameterRepository.save(appApiParameter);
                    } else if (DELETE.equals(paramMap.get(DATA_STATUS))) {
                        appApiParameterRepository.delete(appApiParameter.getId());
                    }
                }
            }
        }
        if (!StringUtils.isEmpty(apiResponse)) {
            list = objectMapper.readValue(apiResponse, List.class);
            for (Map<String, Object> paramMap : list) {
                //删除的是新增的数据直接跳过
                if (DELETE.equals(paramMap.get(DATA_STATUS)) && NEW_DATA.equals(paramMap.get("id") + "")) {
                    continue;
                } else {
                    paramMap.put("appApiId", apiId);
                    String json = objectMapper.writeValueAsString(paramMap);
                    AppApiResponse appApiResponse = objectMapper.readValue(json, AppApiResponse.class);
                    if (ADD.equals(paramMap.get(DATA_STATUS))) {
                        appApiResponseRepository.save(appApiResponse);
                    } else if (UPDATE.equals(paramMap.get(DATA_STATUS))) {
                        AppApiResponse oldAppApiResponse = appApiResponseRepository.findOne(appApiResponse.getId());
                        if (oldAppApiResponse == null) {
                            throw new ApiException(ErrorCode.OBJECT_NOT_FOUND, "更新的返回参数不存在:" + appApiResponse.getId());
                        }
                        appApiResponseRepository.save(appApiResponse);
                    } else if (DELETE.equals(paramMap.get(DATA_STATUS))) {
                        appApiResponseRepository.delete(appApiResponse);
                    }
                }
            }
        }
        if (!StringUtils.isEmpty(apiErrorCode)) {
            list = objectMapper.readValue(apiErrorCode, List.class);
            for (Map<String, Object> paramMap : list) {
                //删除的是新增的数据直接跳过
                if (DELETE.equals(paramMap.get(DATA_STATUS)) && NEW_DATA.equals(paramMap.get("id") + "")) {
                    continue;
                } else {
                    paramMap.put("appApiId", apiId);
                    String json = objectMapper.writeValueAsString(paramMap);
                    AppApiErrorCode appApiErrorCode = objectMapper.readValue(json, AppApiErrorCode.class);
                    if (ADD.equals(paramMap.get(DATA_STATUS))) {
                        appApiErrorCodeDao.save(appApiErrorCode);
                    } else if (UPDATE.equals(paramMap.get(DATA_STATUS))) {
                        AppApiErrorCode oldAppApiErrorCode = appApiErrorCodeDao.findOne(appApiErrorCode.getId());
                        if (oldAppApiErrorCode == null) {
                            throw new ApiException(ErrorCode.OBJECT_NOT_FOUND, "更新的错误码说明不存在:" + appApiErrorCode.getId());
                        }
                        appApiErrorCodeDao.save(appApiErrorCode);
                    } else if (DELETE.equals(paramMap.get(DATA_STATUS))) {
                        appApiErrorCodeDao.delete(appApiErrorCode);
                    }
                }
            }
        }
    }
    public List<AppApi> findByName(String name) {
        return appApiRepository.findByName(name);
    }
}

+ 106 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppFeatureService.java

@ -0,0 +1,106 @@
package com.yihu.ehr.basic.apps.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.apps.dao.AppFeatureDao;
import com.yihu.ehr.basic.apps.model.AppFeature;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author linz
 * @version 1.0
 * @created 2016年7月7日21:04:33
 */
@Service
@Transactional
public class AppFeatureService extends BaseJpaService<AppFeature, AppFeatureDao> {
    @Autowired
    private AppFeatureDao xAppFeatureRepository;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    ObjectMapper objectMapper;
    public Page<AppFeature> getAppFeatureList(String sorts, int page, int size){
        AppFeatureDao repo = (AppFeatureDao)getJpaRepository();
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return repo.findAll(pageable);
    }
    public AppFeature createAppFeature(AppFeature appFeature) {
        xAppFeatureRepository.save(appFeature);
        return appFeature;
    }
    public AppFeature updateAppFeature(AppFeature appFeature){
        xAppFeatureRepository.save(appFeature);
        return appFeature;
    }
    public void  deleteAppFeature(String id){
        xAppFeatureRepository.delete(id);
    }
    /**
     * 生成菜单JSON对象字符串
     * @return AppFeature
     */
    public AppFeature joinMenuItemJsonStr(AppFeature appFeature) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> contentMap = new HashMap<>();
        contentMap.put("id", appFeature.getId());
        contentMap.put("code", appFeature.getCode());
        contentMap.put("level", appFeature.getLevel());
        contentMap.put("text", appFeature.getName());
        contentMap.put("type", appFeature.getType());
        contentMap.put("iconUrl", appFeature.getIconUrl());
        if (appFeature.getLevel() != 1) {
            contentMap.put("pid", appFeature.getParentId());
        }
        if (appFeature.getUrl().startsWith("/")) {
            contentMap.put("url", appFeature.getPrefixUrl() + appFeature.getUrl());
        }
        appFeature.setContent(objectMapper.writeValueAsString(contentMap));
        return appFeature;
    }
    /**
     * 根据权限,获取应用菜单
     *
     * @param appId 应用ID
     * @param userId 用户ID
     * @return 菜单JSON字符串集合
     */
    public List<Map<String, Object>> findAppMenus(String appId, String userId, int parentId) throws IOException {
        List<Map<String, Object>> menuList = new ArrayList<>();
        String sql = " SELECT DISTINCT af.id AS id, af.content AS content FROM apps_feature af " +
                " JOIN role_user ru ON ru.user_id = '" + userId + "' " +
                " JOIN role_feature_relation rfr ON rfr.feature_id = af.id AND rfr.role_id = ru.role_id " +
                " WHERE af.app_id = '" + appId + "' AND af.parent_id = " + parentId + " AND af.type <> 3 " +
                " ORDER BY af.sort ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> item : list) {
            Map<String, Object> conMap = objectMapper.readValue(item.get("content").toString(), Map.class);
            menuList.add(conMap);
            menuList.addAll(findAppMenus(appId, userId, (int) item.get("id")));
        }
        return menuList;
    }
}

+ 285 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppService.java

@ -0,0 +1,285 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.*;
import com.yihu.ehr.basic.apps.model.App;
import com.yihu.ehr.basic.apps.model.AppApi;
import com.yihu.ehr.basic.apps.model.UserApp;
import com.yihu.ehr.basic.user.dao.RoleApiRelationDao;
import com.yihu.ehr.basic.user.dao.RoleAppRelationDao;
import com.yihu.ehr.basic.user.dao.RoleReportRelationDao;
import com.yihu.ehr.basic.user.dao.RolesDao;
import com.yihu.ehr.basic.user.entity.RoleApiRelation;
import com.yihu.ehr.basic.user.entity.RoleAppRelation;
import com.yihu.ehr.basic.user.entity.Roles;
import com.yihu.ehr.entity.oauth2.OauthClientDetails;
import com.yihu.ehr.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
 * @author Sand
 * @version 1.0
 * @created 03-8月-2015 16:53:06
 */
@Service
@Transactional
public class AppService extends BaseJpaService<App, AppDao> {
    private static final int AppIdLength = 10;
    private static final int AppSecretLength = 16;
    @Autowired
    private UserAppDao userAppDao;
    @Autowired
    private AppDao appDao;
    @Autowired
    private OauthClientDetailsDao oauthClientDetailsDao;
    @Autowired
    private RoleAppRelationDao roleAppRelationDao;
    @Autowired
    private RoleApiRelationDao roleApiRelationDao;
    @Autowired
    private RolesDao rolesDao;
    @Autowired
    private AppApiDao appApiDao;
    @Autowired
    private AppApiErrorCodeDao appApiErrorCodeDao;
    @Autowired
    private AppApiParameterDao appApiParameterDao;
    @Autowired
    private AppApiResponseDao appApiResponseDao;
    @Autowired
    private AppFeatureDao appFeatureDao;
    @Autowired
    private ReportCategoryAppRelationDao reportCategoryAppRelationDao;
    @Autowired
    private RsAppResourceDao rsAppResourceDao;
    @Autowired
    private RsAppResourceMetadataDao rsAppResourceMetadataDao;
    @Autowired
    private RoleReportRelationDao roleReportRelationDao;
    @Value("${fast-dfs.public-server}")
    private String fastDfsPublicServers;
    public AppService() {
    }
    public Page<App> getAppList(String sorts, int page, int size){
        AppDao repo = (AppDao)getJpaRepository();
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return repo.findAll(pageable);
    }
    public App createApp(App app) {
        app.setId(getRandomString(AppIdLength));
        app.setSecret(getRandomString(AppSecretLength));
        app.setCreateTime(new Date());
        app.setStatus("WaitingForApprove");
        OauthClientDetails oauthClientDetails = new OauthClientDetails();
        oauthClientDetails.setClientId(app.getId());
        oauthClientDetails.setResourceIds("*");
        oauthClientDetails.setClientSecret(app.getSecret());
        oauthClientDetails.setScope("read");
        oauthClientDetails.setAuthorizedGrantTypes("authorization_code,refresh_token,password,implicit,verify_code");
        oauthClientDetails.setWebServerRedirectUri(app.getUrl());
        oauthClientDetails.setAuthorities(null);
        oauthClientDetails.setAccessTokenValidity(null);
        oauthClientDetails.setAccessTokenValidity(null);
        oauthClientDetails.setAdditionalInformation(null);
        oauthClientDetails.setAutoApprove("true");
        oauthClientDetailsDao.save(oauthClientDetails);
        return appDao.save(app);
    }
    /**
     * 检验App与密码是否正确。
     *
     * @param id
     * @param secret
     * @return
     */
    public boolean verifyApp(String id, String secret) {
        App app = appDao.findOne(id);
        return app != null && app.getSecret().equals(secret);
    }
    public boolean isAppNameExists(String name){
        App app = appDao.findByName(name);
        return app != null;
    }
    public void checkStatus(String appId, String status) {
        App app = appDao.getOne(appId);
        //开启:Approved;禁用:Forbidden;
        app.setStatus(status);
        appDao.save(app);
        //是否显示showFlag
        String showFlag="1";
        if(status.equals("Forbidden")){
            showFlag="0";
        }
        List<UserApp> userAppList = findByAppId(appId);
        if(userAppList != null) {
            for (UserApp userApp : userAppList) {
                userApp.setShowFlag(Integer.parseInt(showFlag));
                userAppDao.save(userApp);
            }
        }
    }
    public List<UserApp> findByAppId(String appId){
        return  userAppDao.findByAppId(appId);
    }
    public boolean findByIdAndSecret(String appId, String secret) {
        return appDao.findByIdAndSecret(appId, secret).size()>0;
    }
    /**
     * 机构资源授权获取
     */
    public List<App> getApps(String userId , String catalog, String manageType) {
        String sql =
                "SELECT * FROM (" +
                        "SELECT b.id, b.name as name, b.secret as secret, b.url as url, b.out_url as outUrl, b.creator as creator," +
                        "   b.auditor as auditor, b.create_time as createTime, b.audit_time as auditTime , b.catalog as catalog, b.status as status, " +
                        "   b.description as description, b.org as org, b.code as code," +
                        "   IF(b.icon IS NULL OR b.icon = '','',CONCAT('" + fastDfsPublicServers + "','/',REPLACE(b.icon,':','/'))) AS icon," +
                        "   b.source_type as sourceType, b.release_flag as releaseFlag, b.manage_type AS manageType" +
                        "   FROM apps b " +
                        "LEFT JOIN user_app m on m.app_id=b.id " +
                        "WHERE b.catalog= :catalog AND m.user_id=:userId AND m.show_flag='1' AND b.status='Approved'";
        if (!StringUtils.isEmpty(manageType)) {
            sql += "AND b.manage_type = :manageType";
        }
        sql += ") p ORDER BY p.id";
        SQLQuery query = currentSession().createSQLQuery(sql);
        query.setParameter("userId", userId);
        query.setParameter("catalog", catalog);
        if (!StringUtils.isEmpty(manageType)) {
            query.setParameter("manageType", manageType);
        }
        query.setResultTransformer(Transformers.aliasToBean(App.class));
        return query.list();
    }
    public App findById(String appId) {
        return appDao.findOne(appId);
    }
    public App update(App app, OauthClientDetails oauthClientDetails){
        oauthClientDetailsDao.save(oauthClientDetails);
        return appDao.save(app);
    }
    public void delete(String appId) {
        List<Roles> rolesList = rolesDao.findByAppId(appId);
        rolesList.forEach(item -> {
            roleReportRelationDao.deleteByRoleId(item.getId());
        });
        roleAppRelationDao.deleteByAppId(appId);
        rolesDao.deleteByAppId(appId);
        userAppDao.deleteByAppId(appId);
        List<AppApi> appApiList = appApiDao.findByAppId(appId);
        appApiList.forEach(item -> {
            roleApiRelationDao.deleteByApiId(item.getId());
            appApiErrorCodeDao.deleteByAppApiId(item.getId());
            appApiParameterDao.deleteByAppApiId(item.getId());
            appApiResponseDao.deleteByAppApiId(item.getId());
        });
        appApiDao.deleteByAppId(appId);
        appFeatureDao.deleteByAppId(appId);
        reportCategoryAppRelationDao.deleteByAppId(appId);
        rsAppResourceDao.deleteByAppId(appId);
        rsAppResourceMetadataDao.deleteByAppId(appId);
        if (oauthClientDetailsDao.findOne(appId) != null) {
            oauthClientDetailsDao.delete(appId);
        }
        appDao.delete(appId);
    }
    public App authClient(App app, OauthClientDetails oauthClientDetails, Roles basicRole, Roles additionRole) {
        App newApp = appDao.save(app);
        oauthClientDetailsDao.save(oauthClientDetails);
        //扩展角色关联
        if (null == rolesDao.findByCodeAndAppId(additionRole.getCode(), additionRole.getAppId())) {
            additionRole = rolesDao.save(additionRole);
        }
        additionRole = rolesDao.findByCodeAndAppId(additionRole.getCode(), additionRole.getAppId());
        RoleAppRelation additionRoleAppRelation = new RoleAppRelation();
        additionRoleAppRelation.setAppId(app.getId());
        additionRoleAppRelation.setRoleId(additionRole.getId());
        if (null == roleAppRelationDao.findRelation(additionRoleAppRelation.getAppId(), additionRoleAppRelation.getRoleId())) {
            roleAppRelationDao.save(additionRoleAppRelation);
        }
        //通过基础开发者角色扩展api关联
        List<RoleApiRelation> roleApiRelationList = roleApiRelationDao.findByRoleId(basicRole.getId());
        for (RoleApiRelation temp : roleApiRelationList) {
            RoleApiRelation roleApiRelation1 = new RoleApiRelation();
            roleApiRelation1.setRoleId(additionRole.getId());
            roleApiRelation1.setApiId(temp.getApiId());
            roleApiRelationDao.save(roleApiRelation1);
        }
        return newApp;
    }
    public List<Map<String,Object>> getAppByParentIdAndUserId(String userId)throws Exception{
        /*String Sql ="SELECT s.*,r.type " +
                    " FROM user_app a " +
                    " LEFT JOIN apps_relation r ON a.app_id = r.app_id " +
                    " LEFT JOIN apps s ON a.app_id = s.id"+
                    " WHERE a.user_id='"+userId+"' AND r.parent_app_id='"+parentAppId+
                    "' AND a.status=0 AND a.show_flag=1 ";*/
        String sql ="SELECT a.* FROM role_user ru LEFT JOIN roles r ON ru.role_id = r.id LEFT JOIN apps a ON r.app_id = a.id WHERE ru.user_id='"+userId+"' and r.name='医生' and a.release_flag=1";
        List<Map<String,Object>> resultList =  jdbcTemplate.queryForList(sql);
        return resultList;
    }
    /**
     * 医生工作站获取 医生授权的应用
     */
    public List<App> getDoctorAppsByType(String userId , String doctorManageType) {
        String sql =
                "SELECT * FROM (" +
                        "SELECT b.id, b.name as name, b.secret as secret, b.url as url, b.out_url as outUrl, b.creator as creator," +
                        "   b.auditor as auditor, b.create_time as createTime, b.audit_time as auditTime , b.catalog as catalog, b.status as status, " +
                        "   b.description as description, b.org as org, b.code as code," +
                        "   IF(b.icon IS NULL OR b.icon = '','',CONCAT('" + fastDfsPublicServers + "','/',REPLACE(b.icon,':','/'))) AS icon," +
                        "   b.source_type as sourceType, b.release_flag as releaseFlag, b.manage_type AS manageType" +
                        "   FROM apps b " +
                        "LEFT JOIN user_app m on m.app_id=b.id " +
                        "WHERE  m.user_id=:userId AND m.show_flag='1' AND b.status='Approved'";
        if (!StringUtils.isEmpty(doctorManageType)) {
            sql += "AND b.doctor_manage_type = :doctorManageType";
        }
        sql += ") p ORDER BY p.id";
        SQLQuery query = currentSession().createSQLQuery(sql);
        query.setParameter("userId", userId);
        if (!StringUtils.isEmpty(doctorManageType)) {
            query.setParameter("doctorManageType", doctorManageType);
        }
        query.setResultTransformer(Transformers.aliasToBean(App.class));
        return query.list();
    }
}

+ 28 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppVersionService.java

@ -0,0 +1,28 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.AppVersionRepository;
import com.yihu.ehr.entity.app.version.AppVersion;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Version;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * Created by Trick on 2018/3/12.
 */
@Service
@Transactional
public class AppVersionService extends BaseJpaService<AppVersion, AppVersionRepository> {
    @Autowired
    private AppVersionRepository appVersionRepository;
    public AppVersion getAppVersion(String id){
        return appVersionRepository.findOne(id);
    }
    public AppVersion getAppVersionByCode(String code){
        return appVersionRepository.findBycode(code);
    }
}

+ 43 - 0
src/main/java/com.yihu.ehr/basic/apps/service/AppsRelationService.java

@ -0,0 +1,43 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.*;
import com.yihu.ehr.basic.apps.model.App;
import com.yihu.ehr.basic.apps.model.AppApi;
import com.yihu.ehr.basic.apps.model.AppsRelation;
import com.yihu.ehr.basic.apps.model.UserApp;
import com.yihu.ehr.basic.user.dao.RoleApiRelationDao;
import com.yihu.ehr.basic.user.dao.RoleAppRelationDao;
import com.yihu.ehr.basic.user.dao.RoleReportRelationDao;
import com.yihu.ehr.basic.user.dao.RolesDao;
import com.yihu.ehr.basic.user.entity.RoleApiRelation;
import com.yihu.ehr.basic.user.entity.RoleAppRelation;
import com.yihu.ehr.basic.user.entity.Roles;
import com.yihu.ehr.entity.oauth2.OauthClientDetails;
import com.yihu.ehr.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
 * @author Sand
 * @version 1.0
 * @created 03-8月-2015 16:53:06
 */
@Service
@Transactional
public class AppsRelationService extends BaseJpaService<AppsRelation, AppsRelationDao> {
}

+ 14 - 0
src/main/java/com.yihu.ehr/basic/apps/service/OauthClientDetailsService.java

@ -0,0 +1,14 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.OauthClientDetailsDao;
import com.yihu.ehr.entity.oauth2.OauthClientDetails;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.stereotype.Service;
/**
 * Created by progr1mmer on 2018/1/23.
 */
@Service
public class OauthClientDetailsService extends BaseJpaService<OauthClientDetails, OauthClientDetailsDao> {
}

+ 44 - 0
src/main/java/com.yihu.ehr/basic/apps/service/UserAppService.java

@ -0,0 +1,44 @@
package com.yihu.ehr.basic.apps.service;
import com.yihu.ehr.basic.apps.dao.UserAppDao;
import com.yihu.ehr.basic.apps.model.UserApp;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
 * @author yeshijie
 * @version 1.0
 * @created 2017年2月16日18:04:13
 */
@Service
@Transactional
public class UserAppService extends BaseJpaService<UserApp, UserAppDao> {
    @Autowired
    private UserAppDao userAppRepository;
    public UserApp findByAppIdAndUserId(String appId, String userId){
        return  userAppRepository.findByAppIdAndUserId(appId,userId);
    }
    // 根据用户ID,删除所有的该用户关联的应用授权
    public void delUserAppByUserId(String userId){
        userAppRepository.deleteByUserId(userId);
    }
    /**
     * 根据userIds查询
     * @param userIds
     * @return
     */
    public List<UserApp> findListByUserIds(List<String> userIds){
        return userAppRepository.findByuserId(userIds);
    }
}

+ 26 - 0
src/main/java/com.yihu.ehr/basic/config/TenantConfiguration.java

@ -0,0 +1,26 @@
package com.yihu.ehr.config;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 *   ehr使用 feginClient 调用eip(涉及到app应用,标准等) 时,需要此类,增加请求头信息
 */
@Configuration
public class TenantConfiguration {
    @Value("${eip.tenant}")
    private String tenant;
    @Bean
    public RequestInterceptor tenantInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                requestTemplate.header("tenant_name", tenant);
            }
        };
    }
}

+ 127 - 0
src/main/java/com.yihu.ehr/basic/device/controller/DeviceEndPoint.java

@ -0,0 +1,127 @@
package com.yihu.ehr.basic.device.controller;
import com.yihu.ehr.basic.device.service.DeviceService;
import com.yihu.ehr.basic.dict.service.SystemDictEntryService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.device.Device;
import com.yihu.ehr.entity.dict.SystemDictEntry;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @Author: zhengwei
 * @Date: 2018/5/4 15:47
 * @Description: 设备管理
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "DeviceEndPoint", description = "设备管理", tags = {"基础信息-设备管理"})
public class DeviceEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private DeviceService deviceService;
    @Autowired
    private SystemDictEntryService systemDictEntryService;
    @RequestMapping(value = ServiceApi.Device.DeviceList, method = RequestMethod.GET)
    @ApiOperation(value = "获取所有列表")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<SystemDictEntry> systemDictEntryList = systemDictEntryService.search("","dictId=181","+sort",1,10000);
        List<Device> list = deviceService.search(fields, filters, sorts, page, size);
        for(Device model : list){
            model.setDeviceTypeName(getTypeName(systemDictEntryList,model.getDeviceType()));
        }
        int count = (int)deviceService.getCount(filters);
        Envelop envelop = getPageResult(list, count, page, size);
        return envelop;
    }
    /**
     * 获取数据字段名称
     * @param systemDictEntryList
     * @param code
     * @return
     */
    public String getTypeName(List<SystemDictEntry> systemDictEntryList,String code){
        String name = "";
        for(SystemDictEntry model : systemDictEntryList){
            if(code.equals(model.getCode())){
                name = model.getValue();
                break;
            }
        }
        return name;
    }
    @RequestMapping(value = ServiceApi.Device.DeviceSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存")
    public Envelop save(
            @ApiParam(name = "device", value = "实体类Json")
            @RequestParam(value = "device") String device) throws Exception {
        Device model = objectMapper.readValue(device, Device.class);
        model = deviceService.save(model);
        return success(model);
    }
    @RequestMapping(value = ServiceApi.Device.DeviceDelete, method = RequestMethod.POST)
    @ApiOperation("删除记录")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表", required = true)
            @RequestParam(value = "ids") String ids) throws Exception {
        String [] idArr = ids.split(",");
        Integer[] arr = new Integer[idArr.length];
        for (int i = 0; i <idArr.length; i++) {
            arr[i] = Integer.parseInt(idArr[i]);
        }
        deviceService.delete(arr);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.Device.FindById, method = RequestMethod.GET)
    @ApiOperation("获取单条记录")
    public Envelop findById(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") String id) throws Exception{
        Device model = deviceService.findById(Integer.parseInt(id));
        SystemDictEntry dict = systemDictEntryService.getDictEntry(181,model.getDeviceType());
        model.setDeviceTypeName(dict.getValue());
        if (null != model) {
            return success(model);
        }
        return failed("无相关数据");
    }
    @RequestMapping(value = ServiceApi.Device.DeviceBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入")
    public boolean addBatch(
            @ApiParam(name = "devices", value = "实体类列表Json")
            @RequestParam(value = "devices") String devices) throws Exception{
        List list = objectMapper.readValue(devices, List.class);
        deviceService.addBatch(list);
        return true;
    }
}

+ 16 - 0
src/main/java/com.yihu.ehr/basic/device/dao/DeviceDao.java

@ -0,0 +1,16 @@
package com.yihu.ehr.basic.device.dao;
import com.yihu.ehr.entity.device.Device;
import com.yihu.ehr.entity.emergency.Ambulance;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @Author: zhengwei
 * @Date: 2018/5/4 15:47
 * @Description: 设备管理
 */
public interface DeviceDao extends PagingAndSortingRepository<Device, String> {
    Device findById(int id);
}

+ 89 - 0
src/main/java/com.yihu.ehr/basic/device/service/DeviceService.java

@ -0,0 +1,89 @@
package com.yihu.ehr.basic.device.service;
import com.yihu.ehr.basic.device.dao.DeviceDao;
import com.yihu.ehr.entity.device.Device;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.util.datetime.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @Author: zhengwei
 * @Date: 2018/5/4 15:47
 * @Description: 设备管理
 */
@Service
@Transactional
public class DeviceService extends BaseJpaService<Device, DeviceDao> {
    @Autowired
    private DeviceDao deviceDao;
    public Device findById(int carId){
        return deviceDao.findById(carId);
    }
    /**
     * 批量导入救护车
     */
    public boolean addBatch(List<Map<String, Object>> list) {
        Map<String, Object> map;
        try{
            for(int i=1; i <= list.size(); i++){
                map = list.get(i-1);
                Device device = new Device();
                device.setDeviceName(map.get("deviceName").toString());
                device.setOrgCode(map.get("orgCode").toString());
                device.setOrgName(map.get("orgName").toString());
                device.setDeviceType(map.get("deviceType").toString());
                if(null!=map.get("purchaseNum")){
                    device.setPurchaseNum(Integer.valueOf(map .get("purchaseNum").toString()));
                }
                if("进口".equals(map.get("originPlace").toString())){
                    device.setOriginPlace("1");
                }else{
                    device.setOriginPlace("2");
                }
                device.setManufacturerName(map.get("manufacturerName").toString());
                device.setDeviceModel(map.get("deviceModel").toString());
                device.setPurchaseTime(DateUtil.strToDate(map.get("purchaseTime").toString(),"yyyy-MM-dd"));
                if("新设备".equals(map.get("isNew").toString())){
                    device.setIsNew("1");
                }else{
                    device.setIsNew("2");
                }
                if(null!=map.get("devicePrice")){
                    device.setDevicePrice(Double.valueOf(map .get("devicePrice").toString()));
                }
                if(null!=map.get("yearLimit")){
                    device.setYearLimit(Integer.valueOf(map .get("yearLimit").toString()));
                }
                if("启用".equals(map.get("status").toString())){
                    device.setStatus("1");
                }else if("未启用".equals(map.get("status").toString())){
                    device.setStatus("2");
                }else{
                    device.setStatus("3");
                }
                if("是".equals(map.get("isGps").toString())){
                    device.setIsGps("1");
                }else{
                    device.setIsGps("0");
                }
                device.setCreator(map.get("creator").toString());
                deviceDao.save(device);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}

+ 843 - 0
src/main/java/com.yihu.ehr/basic/dict/controller/ConventionalDictEndPoint.java

@ -0,0 +1,843 @@
package com.yihu.ehr.basic.dict.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.basic.dict.service.SystemDictEntryService;
import com.yihu.ehr.entity.dict.SystemDictEntry;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.model.dict.MDictionaryEntry;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * 惯用字典接口,用于快速提取常用的字典项。
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "Conventional-Dictionaries", description = "获取常用字典项", tags = {"系统字典-惯用字典"})
public class ConventionalDictEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private SystemDictEntryService dictEntryService;
    MConventionalDict getDictModel(Object dictEntry) {
        return convertToModel(dictEntry, MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/getDictionaries", method = RequestMethod.GET)
    @ApiOperation(value = "获取字典列表", notes = "根据查询条件获取字典列表")
    ListResult searchMConventionalDict(
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page) throws ParseException {
        ListResult listResult = new ListResult();
        List<MConventionalDict> conventionalDictList = dictEntryService.search(null, filters, sorts, page, size);
        if(conventionalDictList != null){
            listResult.setDetailModelList(conventionalDictList);
            listResult.setTotalCount((int)dictEntryService.getCount(filters));
            listResult.setCode(200);
            listResult.setCurrPage(page);
            listResult.setPageSize(size);
        }else{
            listResult.setCode(200);
            listResult.setMessage("查询无数据");
            listResult.setTotalCount(0);
        }
        return listResult;
    };
    @RequestMapping(value = "/dictionaries/app_catalog", method = RequestMethod.GET)
    @ApiOperation(value = "获取应用类别字典项", response = MConventionalDict.class)
    public MConventionalDict getAppCatalog(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry appCatalog = dictEntryService.getDictEntry(1, code);
        return getDictModel(appCatalog);
    }
    @RequestMapping(value = "/dictionaries/app_status", method = RequestMethod.GET)
    @ApiOperation(value = "获取应用状态字典项", response = MConventionalDict.class)
    public MConventionalDict getAppStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry appStatus = dictEntryService.getDictEntry(2, code);
        return getDictModel(appStatus);
    }
    @RequestMapping(value = "/dictionaries/gender", method = RequestMethod.GET)
    @ApiOperation(value = "获取性别字典项", response = MConventionalDict.class)
    public MConventionalDict getGender(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry gender = dictEntryService.getDictEntry(3, code);
        return getDictModel(gender);
    }
    @RequestMapping(value = "/dictionaries/martial_status", method = RequestMethod.GET)
    @ApiOperation(value = "获取婚姻状态字典项", response = MConventionalDict.class)
    public MConventionalDict getMartialStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry martialStatus = dictEntryService.getDictEntry(4, code);
        return getDictModel(martialStatus);
    }
    @RequestMapping(value = "/dictionaries/nation", method = RequestMethod.GET)
    @ApiOperation(value = "获取国家字典项", response = MConventionalDict.class)
    public MConventionalDict getNation(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry nation = dictEntryService.getDictEntry(5, code);
        return getDictModel(nation);
    }
    @RequestMapping(value = "/dictionaries/residence_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取人口居住类型字典项", response = MConventionalDict.class)
    public MConventionalDict getResidenceType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry residenceType = dictEntryService.getDictEntry(6, code);
        return getDictModel(residenceType);
    }
    @RequestMapping(value = "/dictionaries/org_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取组织机构类别字典项", response = MConventionalDict.class)
    public MConventionalDict getOrgType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry orgType = dictEntryService.getDictEntry(7, code);
        return getDictModel(orgType);
    }
    @RequestMapping(value = "/dictionaries/settled_way", method = RequestMethod.GET)
    @ApiOperation(value = "获取机构入驻方式字典项", response = MConventionalDict.class)
    public MConventionalDict getSettledWay(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry settledWay = dictEntryService.getDictEntry(8, code);
        return getDictModel(settledWay);
    }
    @RequestMapping(value = "/dictionaries/card_status", method = RequestMethod.GET)
    @ApiOperation(value = "获取卡状态字典项", response = MConventionalDict.class)
    public MConventionalDict getCardStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry cardStatus = dictEntryService.getDictEntry(9, code);
        return getDictModel(cardStatus);
    }
    @RequestMapping(value = "/dictionaries/card_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取卡类别字典项", response = MConventionalDict.class)
    public MConventionalDict getCardType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry cardType = dictEntryService.getDictEntry(10, code);
        return getDictModel(cardType);
    }
    @RequestMapping(value = "/dictionaries/request_state", method = RequestMethod.GET)
    @ApiOperation(value = "获取家庭成员请求消息状态字典项", response = MConventionalDict.class)
    public MConventionalDict getRequestState(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry requestState = dictEntryService.getDictEntry(11, code);
        return getDictModel(requestState);
    }
    @RequestMapping(value = "/dictionaries/key_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取密钥类型字典项", response = MConventionalDict.class)
    public MConventionalDict getKeyType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry keyType = dictEntryService.getDictEntry(12, code);
        return getDictModel(keyType);
    }
    @RequestMapping(value = "/dictionaries/medical_role", method = RequestMethod.GET)
    @ApiOperation(value = "获取医疗角色字典项", response = MConventionalDict.class)
    public MConventionalDict getMedicalRole(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry medicalRole = dictEntryService.getDictEntry(13, code);
        return getDictModel(medicalRole);
    }
    @RequestMapping(value = "/dictionaries/user_role", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户角色字典项", response = MConventionalDict.class)
    public MConventionalDict getUserRole(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry userRole = dictEntryService.getDictEntry(14, code);
        return getDictModel(userRole);
    }
    @RequestMapping(value = "/dictionaries/user_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户类型字典项", response = MConventionalDict.class)
    public MConventionalDict getUserType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry userType = dictEntryService.getDictEntry(15, code);
        return getDictModel(userType);
    }
    @RequestMapping(value = "/dictionaries/3rd_app", method = RequestMethod.GET)
    @ApiOperation(value = "获取连接的第三方应用字典项", response = MConventionalDict.class)
    public MConventionalDict getLoginAddress(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry loginAddress = dictEntryService.getDictEntry(20, code);
        return getDictModel(loginAddress);
    }
    @RequestMapping(value = "/dictionaries/yes_no", method = RequestMethod.GET)
    @ApiOperation(value = "获取是否字典项", response = MConventionalDict.class)
    public MConventionalDict getYesNo(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") boolean code) {
        String resultCode = code ? "true" : "false";
        SystemDictEntry yesNo = dictEntryService.getDictEntry(18, resultCode);
        return getDictModel(yesNo);
    }
    @RequestMapping(value = "/dictionaries/adaption_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取适配类型字典项", response = MConventionalDict.class)
    public MConventionalDict getAdapterType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry adapterType = dictEntryService.getDictEntry(21, code);
        return getDictModel(adapterType);
    }
    @RequestMapping(value = "/dictionaries/std_source_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取标准来源字典项", response = MConventionalDict.class)
    public MConventionalDict getStdSourceType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry stdSourceType = dictEntryService.getDictEntry(22, code);
        return getDictModel(stdSourceType);
    }
    @RequestMapping(value = "/dictionaries/std_source_types", method = RequestMethod.GET)
    @ApiOperation(value = "获取标准来源类型字典项", response = MConventionalDict.class)
    public Collection<MConventionalDict> getStdSourceTypeList(
            @ApiParam(name = "codes", value = "字典代码", defaultValue = "")
            @RequestParam(value = "codes") String[] codes) {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(22, codes);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/user_types", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户类型字典项", response = MConventionalDict.class)
    public Collection<MConventionalDict> getUserTypeList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(15, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/tags", method = RequestMethod.GET)
    @ApiOperation(value = "获取标签字典项", response = MConventionalDict.class)
    public Collection<MConventionalDict> getTagsList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(17, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/record_data_sources", method = RequestMethod.GET)
    @ApiOperation(value = "获取档案数据来源", response = MConventionalDict.class)
    public Collection<MConventionalDict> getRecordDataSourceList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(35, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/indicator_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取指标类型", response = MConventionalDict.class)
    public MConventionalDict getIndicatorType(
        @ApiParam(name = "code", value = "字典代码", defaultValue = "")
        @RequestParam(value = "code") String code) {
            SystemDictEntry indicatorType = dictEntryService.getDictEntry(23, code);
            return getDictModel(indicatorType);
    }
    @RequestMapping(value = "/dictionaries/drug_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取药品类型", response = MConventionalDict.class)
    public MConventionalDict getDrugType(
        @ApiParam(name = "code", value = "字典代码", defaultValue = "")
        @RequestParam(value = "code") String code) {
            SystemDictEntry drugType = dictEntryService.getDictEntry(24, code);
            return getDictModel(drugType);
    }
    @RequestMapping(value = "/dictionaries/drug_flag", method = RequestMethod.GET)
    @ApiOperation(value = "获取药品处方标识", response = MConventionalDict.class)
    public MConventionalDict getDrugFlag(
        @ApiParam(name = "code", value = "字典代码", defaultValue = "")
        @RequestParam(value = "code") String code) {
            SystemDictEntry drugFlag = dictEntryService.getDictEntry(25, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/user_source", method = RequestMethod.GET)
    @ApiOperation(value = "获取用户来源字典项", response = MConventionalDict.class)
    public MConventionalDict getUserSource(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(26, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/family_relationship", method = RequestMethod.GET)
    @ApiOperation(value = "获取家庭关系字典项", response = MConventionalDict.class)
    public MConventionalDict getFamilyRelationship(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(16, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/resource_adapt_scheme", method = RequestMethod.GET)
    @ApiOperation(value = "获取资源适配方案类别字典项", response = MConventionalDict.class)
    public MConventionalDict getResourceAdaptScheme(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(29, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/mete_data_field_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取数据元字段类型字典项", response = MConventionalDict.class)
    public MConventionalDict getMeteDataFieldType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(30, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/business_domain", method = RequestMethod.GET)
    @ApiOperation(value = "获取业务领域字典项", response = MConventionalDict.class)
    public MConventionalDict getBusinessDomain(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(31, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/resource_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取资源分类字典项", response = MConventionalDict.class)
    public MConventionalDict getResourceType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(32, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/resource_access_type", method = RequestMethod.GET)
    @ApiOperation(value = "获取资源访问方式字典项", response = MConventionalDict.class)
    public MConventionalDict getResourceAccessType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(33, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/logical_relationship", method = RequestMethod.GET)
    @ApiOperation(value = "获取逻辑关系", response = MConventionalDict.class)
    public MConventionalDict getLogicalRelationship(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(34, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/logical_relationship_list", method = RequestMethod.GET)
    @ApiOperation(value = "获取逻辑关系", response = MConventionalDict.class)
    public Collection<MConventionalDict> getLogicalRelationshipList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(34, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/record_data_source", method = RequestMethod.GET)
    @ApiOperation(value = "获取档案数据来源,", response = MConventionalDict.class)
    public MConventionalDict getRecordDataSource(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(35, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/archives_audit_status", method = RequestMethod.GET)
    @ApiOperation(value = "档案关联审批状态", response = MConventionalDict.class)
    public MConventionalDict getArchivesAuditStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(36, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/archives_audit_status_list", method = RequestMethod.GET)
    @ApiOperation(value = "档案关联审批状态", response = MConventionalDict.class)
    public Collection<MConventionalDict> getArchivesAuditStatusList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(36, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/archives_manage_status", method = RequestMethod.GET)
    @ApiOperation(value = "档案管理状态", response = MConventionalDict.class)
    public MConventionalDict getArchivesManageStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(37, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/archives_manage_status_list", method = RequestMethod.GET)
    @ApiOperation(value = "档案管理状态", response = MConventionalDict.class)
    public Collection<MConventionalDict> getArchivesManageStatusList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(37, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/application_source", method = RequestMethod.GET)
    @ApiOperation(value = "应用来源", response = MConventionalDict.class)
    public MConventionalDict getApplicationSource(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(38, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/application_source_list", method = RequestMethod.GET)
    @ApiOperation(value = "应用来源", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApplicationSourceList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(38, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/application_menu_type", method = RequestMethod.GET)
    @ApiOperation(value = "应用菜单类型", response = MConventionalDict.class)
    public MConventionalDict getApplicationMenuType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(39, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/application_menu_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "应用菜单类型", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApplicationMenuTypeList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(39, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/open_level", method = RequestMethod.GET)
    @ApiOperation(value = "开放等级", response = MConventionalDict.class)
    public MConventionalDict getOpenLevel(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(40, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/open_level_list", method = RequestMethod.GET)
    @ApiOperation(value = "开放等级", response = MConventionalDict.class)
    public Collection<MConventionalDict> getOpenLevelList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(40, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/audit_level", method = RequestMethod.GET)
    @ApiOperation(value = "审计等级", response = MConventionalDict.class)
    public MConventionalDict getAuditLevel(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(41, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/audit_level_list", method = RequestMethod.GET)
    @ApiOperation(value = "审计等级", response = MConventionalDict.class)
    public Collection<MConventionalDict> getAuditLevelList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(41, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/role_type", method = RequestMethod.GET)
    @ApiOperation(value = "角色组分类", response = MConventionalDict.class)
    public MConventionalDict getRoleType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(42, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/role_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "角色组分类", response = MConventionalDict.class)
    public Collection<MConventionalDict> getRoleTypeList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(42, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/valid_identification", method = RequestMethod.GET)
    @ApiOperation(value = "有效标识", response = MConventionalDict.class)
    public MConventionalDict getValidIdentification(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(43, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/valid_identification_list", method = RequestMethod.GET)
    @ApiOperation(value = "有效标识", response = MConventionalDict.class)
    public Collection<MConventionalDict> getValidIdentificationList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(43, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/api_protocol", method = RequestMethod.GET)
    @ApiOperation(value = "API协议", response = MConventionalDict.class)
    public MConventionalDict getApiProtocol(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(44, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/api_protocol_list", method = RequestMethod.GET)
    @ApiOperation(value = "API协议", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApiProtocolList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(44, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/api_method", method = RequestMethod.GET)
    @ApiOperation(value = "API方法", response = MConventionalDict.class)
    public MConventionalDict getApiMethod(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(45, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/api_method_list", method = RequestMethod.GET)
    @ApiOperation(value = "API方法", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApiMethodList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(45, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/api_type", method = RequestMethod.GET)
    @ApiOperation(value = "API类型", response = MConventionalDict.class)
    public MConventionalDict getApiType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(46, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/api_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "API类型", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApiTypeList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(46, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/api_parameter_type", method = RequestMethod.GET)
    @ApiOperation(value = "API参数类型", response = MConventionalDict.class)
    public MConventionalDict getApiParameterType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(47, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/api_parameter_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "API参数类型", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApiParameterTypeList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(47, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/api_parameter_data_type", method = RequestMethod.GET)
    @ApiOperation(value = "API参数数据类型", response = MConventionalDict.class)
    public MConventionalDict getApiParameterDataType(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(48, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/api_parameter_data_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "API参数数据类型", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApiParameterDataTypeList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(48, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/api_parameter_data_required", method = RequestMethod.GET)
    @ApiOperation(value = "API参数必输标识", response = MConventionalDict.class)
    public MConventionalDict getApiParameterDataRequired(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry drugFlag = dictEntryService.getDictEntry(49, code);
        return getDictModel(drugFlag);
    }
    @RequestMapping(value = "/dictionaries/api_parameter_data_required_list", method = RequestMethod.GET)
    @ApiOperation(value = "API参数必输标识", response = MConventionalDict.class)
    public Collection<MConventionalDict> getApiParameterDataRequiredList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(49, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/cda_type_browser_list", method = RequestMethod.GET)
    @ApiOperation(value = "浏览器用CDA类别清单", response = MConventionalDict.class)
    public Collection<MConventionalDict> getCdaTypeForBrowserList() {
        List<SystemDictEntry> list = dictEntryService.getDictEntries(50, null);
        return convertToModels(list, new ArrayList<MConventionalDict>(list.size()), MConventionalDict.class, null);
    }
    @RequestMapping(value = "/dictionaries/portal_notice_list", method = RequestMethod.GET)
    @ApiOperation(value = "通知公告类别清单", response = MConventionalDict.class)
    public MConventionalDict getPortalNoticeTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(55, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/portal_notice_protal_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "通知公告云类别清单", response = MConventionalDict.class)
    public MConventionalDict getPortalNoticeProtalTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(56, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/portal_resources_platform_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "资源平台类别类别清单", response = MConventionalDict.class)
    public MConventionalDict getPortalResourcesPlatformTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(57, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/portal_resources_develop_lan_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "资源应用开发环境类别清单", response = MConventionalDict.class)
    public MConventionalDict getPortalResourcesDevelopLanTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(58, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/portal_messageRemind_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "消息提醒类别清单", response = MConventionalDict.class)
    public MConventionalDict getMessageRemindTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(59, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/portal_columnRequest_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "栏目请求方式清单", response = MConventionalDict.class)
    public MConventionalDict getColumnRequestTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(60, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/medicalCard_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "就诊卡类型", response = MConventionalDict.class)
    public MConventionalDict getMedicalCardTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry noticeType = dictEntryService.getDictEntry(66, code);
        return getDictModel(noticeType);
    }
    @RequestMapping(value = "/dictionaries/dimension_main_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "指标主维度类型", response = MConventionalDict.class)
    MConventionalDict getDimensionMainTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code){
        SystemDictEntry type = dictEntryService.getDictEntry(72, code);
        return getDictModel(type);
    };
    @RequestMapping(value = "/dictionaries/dimension_slave_type_list", method = RequestMethod.GET)
        @ApiOperation(value = "指标从维度类型", response = MConventionalDict.class)
        MConventionalDict getDimensionSlaveTypeList(
                @ApiParam(name = "code", value = "字典代码", defaultValue = "")
                @RequestParam(value = "code") String code){
            SystemDictEntry type = dictEntryService.getDictEntry(73, code);
            return getDictModel(type);
        };
        @RequestMapping(value = "/dictionaries/dimension_status_list", method = RequestMethod.GET)
        @ApiOperation(value = "指标维度状态", response = MConventionalDict.class)
        MConventionalDict getDimensionStatusList(
                @ApiParam(name = "code", value = "字典代码", defaultValue = "")
                @RequestParam(value = "code") String code)  {
            SystemDictEntry type = dictEntryService.getDictEntry(74, code);
            return getDictModel(type);
    };
    @RequestMapping(value = "/dictionaries/tj_data_source_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "指标统计数据资源", response = MConventionalDict.class)
    MConventionalDict getTjDataSourceTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code){
        SystemDictEntry type = dictEntryService.getDictEntry(75, code);
        return getDictModel(type);
    };
    @RequestMapping(value = "/dictionaries/tj_data_save_list", method = RequestMethod.GET)
    @ApiOperation(value = "指标统计数据存储", response = MConventionalDict.class)
    MConventionalDict getTjDataSaveList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(76, code);
        return getDictModel(type);
    };
    @RequestMapping(value = "/dictionaries/tj_quota_exec_type_list", method = RequestMethod.GET)
    @ApiOperation(value = "指标统计指标管理", response = MConventionalDict.class)
    MConventionalDict getTjQuotaExecTypeList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(77, code);
        return getDictModel(type);
    };
    @RequestMapping(value = "/dictionaries/tj_quota_data_level_list", method = RequestMethod.GET)
    @ApiOperation(value = "指标统计存储方式", response = MConventionalDict.class)
    MConventionalDict getTjQuotaDataLevelList(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(78, code);
        return getDictModel(type);
    };
    @RequestMapping(value = "/dictionaries/org_dept_detail_display_status", method = RequestMethod.GET)
    @ApiOperation(value = "是否显示", response = MConventionalDict.class)
    MConventionalDict getOrgDeptDetailDisplayStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(79, code);
        return getDictModel(type);
    }
    @RequestMapping(value = "/dictionaries/org_dept_detail_py_code", method = RequestMethod.GET)
    @ApiOperation(value = "科室类型", response = MConventionalDict.class)
    MConventionalDict getOrgDeptDetailPyCode(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(80, code);
        return getDictModel(type);
    }
    @RequestMapping(value = "/dictionaries/org_dept_detail_glory_id", method = RequestMethod.GET)
    @ApiOperation(value = "科室荣誉", response = MConventionalDict.class)
    MConventionalDict getOrgDeptDetailGloryId(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(81, code);
        return getDictModel(type);
    };
    @RequestMapping(value ="/GetAlldictionariesByDictId",method = RequestMethod.GET)
    @ApiOperation(value = "获取卡状态所有字典项")
    public ListResult GetAlldictionariesByDictId() throws Exception{
        long dictId=66;
        int page=0;
        int size=1000;
        ListResult re = new ListResult(page,size);
        Page<SystemDictEntry> cardList = dictEntryService.findByDictId(dictId, page,size);
        if(cardList!=null) {
            re.setDetailModelList(cardList.getContent());
            re.setTotalCount(cardList.getTotalPages());
        }
        return re;
    }
    @RequestMapping(value = "/dictionaries/tj_quota_log_status", method = RequestMethod.GET)
    @ApiOperation(value = "指标日志状态", response = MConventionalDict.class)
    MConventionalDict getTjQuotaLogStatus(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntry(82, code);
        return getDictModel(type);
    }
    @RequestMapping(value = "/dictionaries/tj_quota_algorithm", method = RequestMethod.GET)
    @ApiOperation(value = "指标算法", response = MConventionalDict.class)
    public MConventionalDict getTjQuotaAlgorithm(
            @ApiParam(name = "code", value = "字典代码", defaultValue = "")
            @RequestParam(value = "code") String code) {
        SystemDictEntry type = dictEntryService.getDictEntryByValueAndDictId(code,93);
        return getDictModel(type);
    }
    @RequestMapping(value = ServiceApi.SystemDict.getDictEntryByDictId,method = RequestMethod.POST)
    @ApiOperation("根据字典代码获取字典项列表")
    public  List<MDictionaryEntry> getDictEntryByDictId(
            @ApiParam(name="dictId",value="dictId",defaultValue = "")
            @RequestParam(value ="dictId")  String dictId) throws Exception {
        List<SystemDictEntry> DictEntrys = dictEntryService.getDictEntries(Long.parseLong(dictId),null);
        return (List<MDictionaryEntry>)convertToModels(DictEntrys,new ArrayList<MDictionaryEntry>(DictEntrys.size()),MDictionaryEntry.class,null);
    }
}

+ 165 - 0
src/main/java/com.yihu.ehr/basic/dict/controller/SystemDictEndPoint.java

@ -0,0 +1,165 @@
package com.yihu.ehr.basic.dict.controller;
import com.yihu.ehr.basic.dict.service.SystemDictService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.entity.dict.SystemDict;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.dict.MSystemDict;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.phonics.PinyinUtil;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by linaz on 2015/8/12.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "Dictionary", description = "系统全局字典管理", tags = {"系统字典-系统全局字典管理"})
public class SystemDictEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private SystemDictService dictService;
    @ApiOperation(value = "获取字典列表", response = MSystemDict.class, responseContainer = "List")
    @RequestMapping(value = ServiceApi.SystemDict.Crud, method = RequestMethod.GET)
    public Collection<MSystemDict> getDictionaries(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) Integer size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        page = reducePage(page);
        if (StringUtils.isEmpty(filters)) {
            Page<SystemDict> systemDictPage = dictService.getDictList(sorts, page, size);
            pagedResponse(request, response, systemDictPage.getTotalElements(), page, size);
            return convertToModels(systemDictPage.getContent(), new ArrayList<>(systemDictPage.getNumber()), MSystemDict.class, fields);
        } else {
            List<SystemDict> systemDictList = dictService.search(fields, filters, sorts, page, size);
            pagedResponse(request, response, dictService.getCount(filters), page, size);
            return convertToModels(systemDictList, new ArrayList<>(systemDictList.size()), MSystemDict.class, fields);
        }
    }
    @ApiOperation(value = "创建字典", response = SystemDict.class)
    @RequestMapping(value = ServiceApi.SystemDict.Crud, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop createDictionary(
            @ApiParam(name = "dictionary", value = "字典JSON结构")
            @RequestBody SystemDict dict) throws IOException {
        if (StringUtils.isEmpty(dict.getName())) {
            return failed("字典名称不能为空");
        }
        if (StringUtils.isEmpty(dict.getPhoneticCode())) {
            dict.setPhoneticCode(PinyinUtil.getPinYinHeadChar(dict.getName(), true));
        }
        if (StringUtils.isEmpty(dict.getCode())) {
            dict.setCode(dict.getPhoneticCode());
        }
        SystemDict systemDict = dictService.createDict(dict);
        return success(systemDict);
    }
    @ApiOperation(value = "获取字典", response = MSystemDict.class)
    @RequestMapping(value = ServiceApi.SystemDict.FindById, method = RequestMethod.GET)
    public SystemDict getDictionary(
            @ApiParam(name = "id", value = "字典ID", defaultValue = "")
            @PathVariable(value = "id") long id) {
        SystemDict dict = dictService.retrieve(id);
        if (dict == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "字典不存在");
        }
        return dict;
    }
    @ApiOperation(value = "获取字典", response = SystemDict.class)
    @RequestMapping(value = ServiceApi.SystemDict.FindByPhoneticCode, method = RequestMethod.GET)
    public SystemDict getDictionaryByPhoneticCode(
            @ApiParam(name = "phoneticCode", value = "拼音编码", required = true)
            @PathVariable(value = "phoneticCode") String phoneticCode) {
        SystemDict dict = dictService.findByPhoneticCode(phoneticCode);
        if (dict == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "字典不存在");
        }
        return dict;
    }
    @ApiOperation(value = "更新字典")
    @RequestMapping(value = ServiceApi.SystemDict.Crud, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Envelop updateDictionary(
            @ApiParam(name = "dictionary", value = "字典JSON结构")
            @RequestBody SystemDict dict) throws Exception {
        SystemDict oldDict = dictService.findOne(dict.getId());
        if (null == oldDict) {
            return failed("字典不存在", ErrorCode.OBJECT_NOT_FOUND.value());
        }
        if (StringUtils.isEmpty(dict.getName())) {
            return failed("字典名称不能为空");
        }
        if (!oldDict.getName().equals(dict.getName()) && dictService.findByField("name", dict.getName()).size() > 0) {
            return failed("字典名称在系统中已存在");
        }
        if (StringUtils.isEmpty(dict.getPhoneticCode())) {
            dict.setPhoneticCode(PinyinUtil.getPinYinHeadChar(dict.getName(), true));
        }
        if (StringUtils.isEmpty(dict.getCode())) {
            dict.setCode(dict.getPhoneticCode());
        }
        oldDict.setName(dict.getName());
        oldDict.setPhoneticCode(dict.getPhoneticCode());
        oldDict.setCode(dict.getCode());
        dictService.updateDict(oldDict);
        return success(oldDict);
    }
    @ApiOperation(value = "删除字典")
    @RequestMapping(value = ServiceApi.SystemDict.DeleteById, method = RequestMethod.DELETE)
    public Boolean deleteDictionary(
            @ApiParam(name = "id", value = "字典ID")
            @PathVariable(value = "id") long id) throws Exception{
        dictService.deleteDict(id);
        return true;
    }
    @RequestMapping(value = ServiceApi.SystemDict.CheckName, method = RequestMethod.GET)
    @ApiOperation(value = "判断提交的字典名称是否已经存在")
    public boolean isDictNameExists(
            @ApiParam(name = "dict_name", value = "字典名称")
            @RequestParam(value = "dict_name") String dictName){
        return dictService.isDictNameExists(dictName);
    }
    @RequestMapping(value = ServiceApi.SystemDict.CheckCode, method = RequestMethod.GET)
    @ApiOperation(value = "判断提交的字典编码是否已经存在")
    public boolean checkCode(
            @ApiParam(name = "code", value = "编码")
            @RequestParam(value = "code") String code) {
        if (dictService.findByField("code", code).size() > 0) {
            return true;
        }
        return false;
    }
}

+ 204 - 0
src/main/java/com.yihu.ehr/basic/dict/controller/SystemDictEntryEndPoint.java

@ -0,0 +1,204 @@
package com.yihu.ehr.basic.dict.controller;
import com.yihu.ehr.basic.dict.service.SystemDictEntryService;
import com.yihu.ehr.basic.dict.service.SystemDictService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.entity.dict.DictEntryKey;
import com.yihu.ehr.entity.dict.SystemDict;
import com.yihu.ehr.entity.dict.SystemDictEntry;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.dict.MDictionaryEntry;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author Sand
 * @version 1.0
 * @created 2016.02.15 18:25
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "DictionaryEntry", description = "系统全局字典项管理", tags = {"系统字典-系统全局字典项管理"})
public class SystemDictEntryEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private SystemDictService dictService;
    @Autowired
    private SystemDictEntryService systemDictEntryService;
    @ApiOperation(value = "获取字典项列表")
    @RequestMapping(value = "/dictionaries/entries", method = RequestMethod.GET)
    public List<MDictionaryEntry> getDictEntries(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) Integer size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        List<SystemDictEntry> systemDictEntryList = systemDictEntryService.search(fields,filters,sorts,page,size);
        pagedResponse(request, response,systemDictEntryService.getCount(filters), page, size);
        return (List<MDictionaryEntry>)convertToModels(systemDictEntryList,new ArrayList<MDictionaryEntry>(systemDictEntryList.size()),MDictionaryEntry.class,null);
    }
    @ApiOperation(value = "创建字典项")
    @RequestMapping(value = "/dictionaries/entries", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public MDictionaryEntry createDictEntry (
            @ApiParam(name = "entry", value = "字典JSON结构")
            @RequestBody String entryJson) throws IOException{
        SystemDictEntry entry = toEntity(entryJson, SystemDictEntry.class);
        SystemDict systemDict = dictService.retrieve(entry.getDictId());
        if (systemDict == null) {
            throw new ApiException(ErrorCode.NOT_FOUND, "所属字典不存在");
        }
        int nextSort = systemDictEntryService.getNextSN(entry.getDictId());
        entry.setSort(nextSort);
        systemDictEntryService.createDictEntry(entry);
        return convertToModel(entry, MDictionaryEntry.class, null);
    }
    @ApiOperation(value = "获取字典项")
    @RequestMapping(value = "/dictionaries/{dict_id}/entries/{code}", method = RequestMethod.GET)
    public MDictionaryEntry getDictEntry(
            @ApiParam(name = "dict_id", value = "字典ID", required = true)
            @PathVariable(value = "dict_id") long dictId,
            @ApiParam(name = "code", value = "字典项代码", required = true)
            @PathVariable(value = "code") String code) {
        SystemDictEntry systemDictEntry = systemDictEntryService.getDictEntry(dictId, code);
        return convertToModel(systemDictEntry, MDictionaryEntry.class);
    }
    @ApiOperation(value = "删除字典项")
    @RequestMapping(value = "/dictionaries/{dict_id}/entries/{code}", method = RequestMethod.DELETE)
    public Object deleteDictEntry(
            @ApiParam(name = "dict_id", value = "字典ID", defaultValue = "")
            @PathVariable(value = "dict_id") long dictId,
            @ApiParam(name = "code", value = "字典ID", defaultValue = "")
            @PathVariable(value = "code") String code) throws Exception{
        systemDictEntryService.deleteDictEntry(dictId, code);
        return true;
    }
    @ApiOperation(value = "修改字典项")
    @RequestMapping(value = "/dictionaries/entries", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public MDictionaryEntry updateDictEntry(
            @ApiParam(name = "entry", value = "字典JSON结构")
            @RequestBody String entryJson) throws IOException {
        SystemDictEntry entry = toEntity(entryJson, SystemDictEntry.class);
        SystemDictEntry temp = systemDictEntryService.retrieve(new DictEntryKey(entry.getCode(), entry.getDictId()));
        if (null == temp) {
            throw new ApiException(ErrorCode.NOT_FOUND, "字典项不存在");
        }
        systemDictEntryService.saveDictEntry(entry);
        return convertToModel(entry, MDictionaryEntry.class, null);
    }
    @RequestMapping(value = "/dictionaries/existence/{dict_id}" , method = RequestMethod.GET)
    @ApiOperation(value = "根据dictId和code判断提交的字典项名称是否已经存在")
    public boolean isDictEntryCodeExists(
            @ApiParam(name = "dict_id", value = "dict_id", defaultValue = "")
            @PathVariable(value = "dict_id") long dictId,
            @ApiParam(name = "code", value = "code", defaultValue = "")
            @RequestParam(value = "code") String code){
        return systemDictEntryService.isDictContainEntry(dictId, code);
    }
    @RequestMapping(value ="/dictionaries/systemDictEntryList/{dict_id}",method = RequestMethod.GET)
    @ApiOperation(value = "根据dictId获取所有字典项")
    public ListResult GetSystemDictEntryListByDictId(
            @ApiParam(name = "dict_id", value = "dict_id", defaultValue = "")
            @PathVariable(value = "dict_id") long dictId) throws Exception{
        int page=0;
        int size=1000;
        ListResult re = new ListResult(page,size);
        Page<SystemDictEntry> cardList = systemDictEntryService.findByDictId(dictId, page,size);
        if(cardList!=null) {
            re.setDetailModelList(cardList.getContent());
            re.setTotalCount(cardList.getTotalPages());
        }
        return re;
    }
    @RequestMapping(value ="/dictionary/entryList/{dictId}", method = RequestMethod.GET)
    @ApiOperation(value = "根据dictId获取所有字典项")
    public Envelop listByDictId(
            @ApiParam(name = "dictId", value = "dictId", required =  true)
            @PathVariable(value = "dictId") long dictId) {
        Envelop envelop = new Envelop();
        int page = 0;
        int size = 1000;
        //ListResult re = new ListResult(page, size);
        Page<SystemDictEntry> page1 = systemDictEntryService.findByDictId(dictId, page,size);
        if(page1 != null) {
            envelop.setDetailModelList(page1.getContent());
            envelop.setSuccessFlg(true);
        }
        return envelop;
    }
    @ApiOperation(value = "未登录获取字典项")
    @RequestMapping(value = ServiceApi.SystemDict.GetDictEntryByDictIdAndEntryCode, method = RequestMethod.GET)
    public Envelop getDictEntryByDictIdAndEntryCode(
            @ApiParam(name = "dictId", value = "字典ID", required = true)
            @RequestParam(value = "dictId") long dictId,
            @ApiParam(name = "code", value = "字典项代码", required = true)
            @RequestParam(value = "code") String code) {
        Envelop envelop =new Envelop();
        SystemDictEntry systemDictEntry = systemDictEntryService.getDictEntry(dictId, code);
        MDictionaryEntry mDictionaryEntry=convertToModel(systemDictEntry, MDictionaryEntry.class);
        envelop.setObj(mDictionaryEntry);
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.SystemDict.getDictEntryCodeAndValueByDictId, method = RequestMethod.GET)
    @ApiOperation("根据字典id获取所有字典项的code和值")
    public Envelop getDictEntryCodeAndValueByDictId(
            @ApiParam(name = "dictId", value = "字典id")
            @RequestParam(value = "dictId", required = false) String dictId) throws Exception {
        Envelop envelop = new Envelop();
        Map<String, String> map = new HashMap<>();
        List list = systemDictEntryService.getDictEntryCodeAndValueByDictId(dictId);
        String code = "";
        String value = "";
        for (int i = 0; i < list.size(); i++) {
            Object[] obj = (Object[]) list.get(i);
            if (null != obj[0] && null != obj[1]) {
                code = obj[0].toString();
                value = obj[1].toString();
                map.put(code, value);
            }
        }
        envelop.setSuccessFlg(true);
        envelop.setObj(map);
        return envelop;
    }
}

+ 56 - 0
src/main/java/com.yihu.ehr/basic/dict/dao/SystemDictEntryRepository.java

@ -0,0 +1,56 @@
package com.yihu.ehr.basic.dict.dao;
import com.yihu.ehr.entity.dict.DictEntryKey;
import com.yihu.ehr.entity.dict.SystemDictEntry;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * 字典项DAO。
 *
 * @author Sand
 * @version 1.0
 * @created 2017.01.30 14:43
 */
public interface SystemDictEntryRepository extends JpaRepository<SystemDictEntry, DictEntryKey> {
    List<SystemDictEntry> findByDictId(long dictId);
    Page<SystemDictEntry> findByDictId(long dictId, Pageable pageable);
    Page<SystemDictEntry> findByDictIdAndValueLike(long dictId, String value, Pageable pageable);
    @Modifying
    void deleteByDictId(long dictId);
    /**
     * 获取字典项下一排序号.
     *
     * @param dictId
     * @return
     */
    @Query("select max(entry.sort) from SystemDictEntry entry where entry.dictId = :dictId")
    Integer getNextEntrySN(@Param("dictId") long dictId);
    /**
     * 批量获取字典项列表.
     *
     * @param dictId
     * @param codes
     * @return
     */
    @Query("select entry from SystemDictEntry entry where entry.dictId = :dictId and entry.code in (:codes) order by entry.sort asc")
    List<SystemDictEntry> findByDictIdAndCodes(@Param("dictId") long dictId, @Param("codes") String[] codes);
    @Query("select entry from SystemDictEntry entry where entry.dictId = :dictId and entry.value = :value")
    List<SystemDictEntry> findByDictIdAndValue(@Param("dictId") long dictId, @Param("value") String value);
    List<SystemDictEntry> findByDictIdAndCode(@Param("dictId") long dictId, @Param("code") String code);
}

+ 27 - 0
src/main/java/com.yihu.ehr/basic/dict/dao/SystemDictRepository.java

@ -0,0 +1,27 @@
package com.yihu.ehr.basic.dict.dao;
import com.yihu.ehr.entity.dict.SystemDict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
/**
 * 字典CRUD操作接口使用 PagingAndSortingRepository 中的方法,除非有特殊需要再添加自定义方法。
 *
 * @author CWS
 * @version 1.0
 * @created 2015.07.30 14:43
 */
public interface SystemDictRepository extends JpaRepository<SystemDict, Long> {
    SystemDict findByName(String name);
    Page<SystemDict> findByNameOrPhoneticCodeOrderByNameAsc(String name, String phoneticCode, Pageable pageable);
    @Query("select max(dict.id) from SystemDict dict where 1=1")
    long getNextId();
    SystemDict findByPhoneticCode(String phoneticCode);
}

+ 158 - 0
src/main/java/com.yihu.ehr/basic/dict/service/SystemDictEntryService.java

@ -0,0 +1,158 @@
package com.yihu.ehr.basic.dict.service;
import com.yihu.ehr.basic.dict.dao.SystemDictEntryRepository;
import com.yihu.ehr.entity.dict.DictEntryKey;
import com.yihu.ehr.entity.dict.SystemDictEntry;
import com.yihu.ehr.query.BaseJpaService;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
 * 字典项服务。
 *
 * @author Sand
 * @version 1.0
 * @created 2016.02.14 14:49
 */
@Service
@Transactional
public class SystemDictEntryService extends BaseJpaService<SystemDictEntry, SystemDictEntryRepository> {
    @Autowired
    private SystemDictEntryRepository systemDictEntryRepository;
    /**
     * 下一字典项排序号。
     *
     * @param dictId
     * @return
     */
    public int getNextSN(long dictId) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        Integer nextSort = repo.getNextEntrySN(dictId);
        return null == nextSort ? 1 : nextSort + 1;
    }
    /**
     * 获取所有字典项。对于大字典,若不分页效率可能会很低。
     *
     * @param dictId 字典ID
     * @param page   分页,-1 表示查找全部
     * @param size   页大小, page 为 -1 时忽略此参数
     * @return
     */
    public Page<SystemDictEntry> getDictEntries(long dictId, int page, int size) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        return repo.findByDictId(dictId, page == -1 ? null : new PageRequest(page, size));
    }
    /**
     * 获取简易字典项列表.
     *
     * @param dictId
     * @param codes  字典项代码列表,为空返回所有字典项. 但对于大字典效率会很低.
     * @return
     */
    public List<SystemDictEntry> getDictEntries(long dictId, String[] codes) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        if (codes == null) {
            return repo.findByDictId(dictId);
        } else {
            return repo.findByDictIdAndCodes(dictId, codes);
        }
    }
    /**
     * 获取字典项。
     *
     * @param dictId
     * @param code
     * @return
     */
    public SystemDictEntry getDictEntry(long dictId, String code) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        return repo.findOne(new DictEntryKey(code, dictId));
    }
    public SystemDictEntry getDictEntryByValueAndDictId(String value, long dictId) {
        List<SystemDictEntry> systemDictEntryList = systemDictEntryRepository.findByDictIdAndValue(dictId, value);
        if (null != systemDictEntryList && systemDictEntryList.size() > 0) {
            return systemDictEntryList.get(0);
        }
        return null;
    }
    /**
     * 按字典ID与字典项值查找字典项.
     *
     * @param dictId
     * @param value
     * @param page
     * @param size
     * @return
     */
    public Page<SystemDictEntry> findByDictIdAndValueLike(long dictId, String value, int page, int size) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        return repo.findByDictIdAndValueLike(dictId, value, new PageRequest(page, size));
    }
    /**
     * 按字典ID查找字典项.
     *
     * @param dictId
     * @param page
     * @param size
     * @return
     */
    public Page<SystemDictEntry> findByDictId(long dictId, int page, int size) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        return repo.findByDictId(dictId, new PageRequest(page, size));
    }
    public boolean isDictContainEntry(long dictId, String code) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        SystemDictEntry systemDictEntry = repo.findOne(new DictEntryKey(code, dictId));
        return systemDictEntry != null;
    }
    public SystemDictEntry saveDictEntry(SystemDictEntry systemDictEntry) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        return repo.save(systemDictEntry);
    }
    public void createDictEntry(SystemDictEntry systemDictEntry) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        repo.save(systemDictEntry);
    }
    public void deleteDictEntry(long dictId, String code) {
        SystemDictEntryRepository repo = (SystemDictEntryRepository) getJpaRepository();
        repo.delete(new DictEntryKey(code, dictId));
    }
    /**
     * 根据字典id获取字典项编码和值
     */
    public List getDictEntryCodeAndValueByDictId(String dict_id) {
        String sql = "SELECT code,value FROM system_dict_entries where dict_id=:dict_id";
        SQLQuery sqlQuery = currentSession().createSQLQuery(sql);
        sqlQuery.setParameter("dict_id", dict_id);
        return sqlQuery.list();
    }
}

+ 77 - 0
src/main/java/com.yihu.ehr/basic/dict/service/SystemDictService.java

@ -0,0 +1,77 @@
package com.yihu.ehr.basic.dict.service;
import com.yihu.ehr.basic.dict.dao.SystemDictEntryRepository;
import com.yihu.ehr.basic.dict.dao.SystemDictRepository;
import com.yihu.ehr.entity.dict.SystemDict;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
/**
 * 系统字典管理器.
 *
 * @author Sand
 * @version 1.0
 * @created 2015.07.30 11:46
 */
@Service
@Transactional
public class SystemDictService extends BaseJpaService<SystemDict, SystemDictRepository> {
    @Autowired
    private SystemDictRepository dictRepo;
    @Autowired
    private SystemDictEntryRepository entryRepo;
    public Page<SystemDict> getDictList(String sorts, int page, int size) {
        Pageable pageable = new PageRequest(page, size, parseSorts(sorts));
        return dictRepo.findAll(pageable);
    }
    public SystemDict createDict(SystemDict dict) {
        dict.setCreateDate(new Date());
        dict.setName(dict.getName());
        dictRepo.save(dict);
        return dict;
    }
    public void updateDict(SystemDict dict) {
        dictRepo.save(dict);
    }
    public void deleteDict(long dictId) {
        entryRepo.deleteByDictId(dictId);
        dictRepo.delete(dictId);
    }
    public boolean isDictNameExists(String name) {
        SystemDict systemDict = dictRepo.findByName(name);
        return systemDict != null;
    }
    public Page<SystemDict> searchDict(String name, String phoneticCode, int page, int size) {
        return dictRepo.findByNameOrPhoneticCodeOrderByNameAsc(name, phoneticCode, new PageRequest(page, size));
    }
    public long getNextId() {
        long id = dictRepo.getNextId()+1;
        return id;
    }
    public SystemDict findByPhoneticCode(String code) {
        return dictRepo.findByPhoneticCode(code);
    }
    public SystemDict findOne(long id) {
        return  dictRepo.findOne(id);
    }
}

+ 277 - 0
src/main/java/com.yihu.ehr/basic/emergency/controller/AmbulanceEndPoint.java

@ -0,0 +1,277 @@
package com.yihu.ehr.basic.emergency.controller;
import com.yihu.ehr.basic.emergency.service.AmbulanceService;
import com.yihu.ehr.basic.emergency.service.AttendanceService;
import com.yihu.ehr.basic.emergency.service.LocationService;
import com.yihu.ehr.basic.emergency.service.ScheduleService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.emergency.Ambulance;
import com.yihu.ehr.entity.emergency.Attendance;
import com.yihu.ehr.entity.emergency.Location;
import com.yihu.ehr.entity.emergency.Schedule;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
 * EndPoint - 救护车信息
 * Created by progr1mmer on 2017/11/8.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AmbulanceEndPoint", description = "救护车信息", tags = {"应急指挥-救护车信息"})
public class AmbulanceEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AmbulanceService ambulanceService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private AttendanceService attendanceService;
    @Autowired
    private LocationService locationService;
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceList, method = RequestMethod.GET)
    @ApiOperation(value = "获取所有救护车列表")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<Ambulance> ambulanceList = ambulanceService.search(fields, filters, sorts, page, size);
        int count = (int)ambulanceService.getCount(filters);
        Envelop envelop = getPageResult(ambulanceList, count, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceSearch , method = RequestMethod.GET)
    @ApiOperation(value = "查询救护车信息,包括执勤人员信息,以及最近一条执勤记录,检索条件只针对车辆")
    public Envelop search(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<Object> resultList = new ArrayList<Object>();
        List<Ambulance> ambulanceList = ambulanceService.search(fields, filters, sorts, page, size);
        Date date = new Date();
        for (Ambulance ambulance : ambulanceList) {
            if (ambulance.getStatus() != Ambulance.Status.down) {
                List<Schedule> scheduleList = scheduleService.findMatch(ambulance.getId(), date);
                if (scheduleList.size() >= 3) {
                    Map<String, Object> resultMap = new HashMap<String, Object>();
                    Attendance attendance = attendanceService.findByCreateDateAndCarId(date, ambulance.getId());
                    Location location = locationService.findById(ambulance.getLocation());
                    Map<String, Object> childMap = new HashMap<String, Object>();
                    childMap.put("id", ambulance.getId());
                    childMap.put("location", location.getId());
                    childMap.put("initLongitude", location.getInitLongitude());
                    childMap.put("initLatitude", location.getInitLatitude());
                    childMap.put("initAddress", location.getInitAddress());
                    childMap.put("district", location.getDistrict());
                    childMap.put("orgName", ambulance.getOrgName());
                    childMap.put("phone", ambulance.getPhone());
                    childMap.put("status", ambulance.getStatus());
                    childMap.put("entityName", ambulance.getEntityName());
                    childMap.put("dutyList", scheduleList);
                    childMap.put("attendance", attendance);
                    resultMap.put("car", childMap);
                    resultList.add(resultMap);
                }
            }
        }
        return success(resultList);
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceUpdateStatus, method = RequestMethod.PUT)
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @ApiOperation(value = "更新救护车状态信息")
    public Envelop updateStatus(
            @ApiParam(name = "carId", value = "车牌号码")
            @RequestParam(value = "carId") String carId,
            @ApiParam(name = "status", value = "车辆状态码(0为统一可用状态码,1为统一不可用状态码)")
            @RequestParam(value = "status") String status) {
        Ambulance ambulance = ambulanceService.findById(carId);
        if (ambulance != null) {
            if (status.equals("0")) {
                if (ambulance.getStatus() == Ambulance.Status.down) {
                    ambulance.setStatus(Ambulance.Status.wait);
                    ambulanceService.save(ambulance);
                    return success(true);
                } else {
                    return failed("该车辆不处于异常状态");
                }
            } else if(status.equals("1")) {
                ambulance.setStatus(Ambulance.Status.down);
                ambulanceService.save(ambulance);
                //如果有正在出勤中的任务,则设置为意外中止
                List<Attendance.Status> statuses = new ArrayList<Attendance.Status>();
                statuses.add(Attendance.Status.start);
                statuses.add(Attendance.Status.arrival);
                statuses.add(Attendance.Status.back);
                Attendance attendance = attendanceService.findByCarIdAndStatus(carId, statuses);
                if (attendance != null) {
                    attendance.setStatus(Attendance.Status.discontinue);
                    attendanceService.save(attendance);
                }
                return success(true);
            } else {
                return failed("状态码错误");
            }
        } else {
            return failed("无相关车辆信息", ErrorCode.OBJECT_NOT_FOUND.value());
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存单条记录")
    public Envelop save(
            @ApiParam(name = "ambulance", value = "救护车")
            @RequestBody String ambulance) throws Exception {
        Ambulance newAmbulance = objectMapper.readValue(ambulance, Ambulance.class);
        Ambulance oldAmbulance = ambulanceService.findById(newAmbulance.getId());
        if (oldAmbulance != null) {
            return failed("车辆:" + newAmbulance.getId() + "已存在");
        }
        oldAmbulance = ambulanceService.findByPhone(newAmbulance.getPhone());
        if (oldAmbulance != null) {
            return failed("手机号:" + newAmbulance.getPhone() + "已存在");
        }
        Location location = locationService.findById(newAmbulance.getLocation());
        if (null == location) {
            return failed("待命地点:" + newAmbulance.getLocation() + "不存在");
        }
        newAmbulance.setOrgName(location.getInitAddress());
        /**
        Organization organization = orgService.getOrg(newAmbulance.getOrgCode());
        if (organization == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("无相关机构");
            return envelop;
        }
         */
        if (newAmbulance.getStatus() == Ambulance.Status.wait || newAmbulance.getStatus() == Ambulance.Status.down) {
            Ambulance ambulance1 = ambulanceService.save(newAmbulance);
            return success(ambulance1);
        } else {
            return failed("车辆状态不能为执勤中");
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("更新单条记录")
    public Envelop update(
            @ApiParam(name = "ambulance", value = "救护车")
            @RequestBody String ambulance) throws Exception {
        Envelop envelop = new Envelop();
        Ambulance newAmbulance = objectMapper.readValue(ambulance, Ambulance.class);
        Ambulance oldAmbulance = ambulanceService.findById(newAmbulance.getId());
        if (oldAmbulance == null) {
            return failed("无相关车辆信息");
        } else {
            Ambulance oldAmbulance1 = ambulanceService.findByPhone(newAmbulance.getPhone());
            if (oldAmbulance1 != null && !oldAmbulance1.getId().equals(newAmbulance.getId())) {
                return failed("手机号码重复");
            }
            Location location = locationService.findById(newAmbulance.getLocation());
            if (null == location) {
                return failed("待命地点:" + newAmbulance.getLocation() + "不存在");
            }
            newAmbulance.setCreator(oldAmbulance.getCreator());
            newAmbulance.setStatus(oldAmbulance.getStatus());
            newAmbulance.setOrgName(location.getInitAddress());
            /**
            Organization organization = orgService.getOrg(newAmbulance.getOrgCode());
            if (organization == null) {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("无相关机构");
                return envelop;
            }
            */
            if (oldAmbulance.getStatus() == Ambulance.Status.wait || oldAmbulance.getStatus() == Ambulance.Status.down) {
                Ambulance ambulance1 = ambulanceService.save(newAmbulance);
                return success(ambulance1);
            } else {
                return failed("当前车辆处于执勤状态,无法更新");
            }
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除记录")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表xxxx,xxxx,xxxx,...", required = true)
            @RequestParam(value = "ids") String ids) throws Exception {
        //List<String> idList = toEntity(ids, List.class);
        String [] idArr = ids.split(",");
        for (String id : idArr) {
            Ambulance ambulance = ambulanceService.findById(id);
            if (ambulance.getStatus() != Ambulance.Status.wait && ambulance.getStatus() != Ambulance.Status.down) {
                return failed("车辆:" + id + ",处于执勤状态,无法删除");
            }
            List<Attendance> attendanceList = attendanceService.search("carId=" + id);
            if (attendanceList != null && attendanceList.size() > 0) {
                return failed("车辆:" + id + ",有执勤记录,无法删除");
            }
        }
        ambulanceService.delete(idArr);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.Emergency.Ambulance, method = RequestMethod.GET)
    @ApiOperation("获取单条记录")
    public Envelop findById(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") String id){
        Ambulance ambulance = ambulanceService.findById(id);
        if (null != ambulance) {
            return success(ambulance);
        }
        return failed("无相关车辆");
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceIdOrPhoneExistence, method = RequestMethod.POST)
    @ApiOperation("获取已存在车牌号、电话号码")
    public List idExistence(
            @ApiParam(name = "type", value = "字段名")
            @RequestParam(value ="type") String type,
            @ApiParam(name = "values", value = "车牌号、电话号码")
            @RequestParam(value ="values") String values) throws Exception {
        List existPhones = ambulanceService.idExist(type, toEntity(values, String[].class));
        return existPhones;
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulancesBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入救护车")
    public boolean createAmbulancesBatch(
            @ApiParam(name = "ambulances", value = "救护车")
            @RequestBody String ambulances) throws Exception{
        List models = objectMapper.readValue(ambulances, List.class);
        ambulanceService.addAmbulancesBatch(models);
        return true;
    }
}

+ 396 - 0
src/main/java/com.yihu.ehr/basic/emergency/controller/AttendanceEndPoint.java

@ -0,0 +1,396 @@
package com.yihu.ehr.basic.emergency.controller;
import com.yihu.ehr.basic.emergency.service.AmbulanceService;
import com.yihu.ehr.basic.emergency.service.AttendanceService;
import com.yihu.ehr.basic.emergency.service.LocationService;
import com.yihu.ehr.basic.emergency.service.ScheduleService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.emergency.Ambulance;
import com.yihu.ehr.entity.emergency.Attendance;
import com.yihu.ehr.entity.emergency.Location;
import com.yihu.ehr.entity.emergency.Schedule;
import com.yihu.ehr.basic.user.service.UserService;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * EndPoint - 出勤记录
 * Created by progr1mmer on 2017/11/8.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "AttendanceEndPoint", description = "出勤记录", tags = {"应急指挥-出勤记录"})
public class AttendanceEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private AttendanceService attendanceService;
    @Autowired
    private AmbulanceService ambulanceService;
    @Autowired
    private LocationService locationService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private UserService userManager;
    @RequestMapping(value = ServiceApi.Emergency.AttendanceSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    //@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @ApiOperation(value = "保存出勤记录")
    public Envelop save(
            @ApiParam(name = "attendance", value = "出勤记录")
            @RequestBody String attendance) throws Exception {
        Attendance newAttendance = toEntity(attendance, Attendance.class);
        if(newAttendance.getId()!=null){
            attendanceService.save(newAttendance);
            return success(newAttendance);
        }else {
            //验证车辆
            Ambulance ambulance = ambulanceService.findById(newAttendance.getCarId());
            if (ambulance == null || ambulance.getStatus() != Ambulance.Status.wait) {
                return failed("无相关车辆或该车辆不处于待命状态");
            }
            //验证出勤任务
            List<Attendance.Status> statuses = new ArrayList<Attendance.Status>();
            statuses.add(Attendance.Status.start);
            statuses.add(Attendance.Status.arrival);
            statuses.add(Attendance.Status.back);
            Attendance verification = attendanceService.findByCarIdAndStatus(newAttendance.getCarId(), statuses);
            if (verification != null) {
                return failed("该车辆有尚未完成的执勤任务");
            }
            //验证排班情况
            List<Schedule> scheduleList = scheduleService.findMatch(ambulance.getId(), new Date());
            if (scheduleList != null && scheduleList.size() >= 3) {
                //生成出勤记录
                List<Integer> idList = new ArrayList<Integer>();
                for (Schedule schedule : scheduleList) {
                    idList.add(schedule.getId());
                }
                newAttendance.setSchedules(objectMapper.writeValueAsString(idList));
                //开始任务
                newAttendance.setStatus(Attendance.Status.start);
                //更新车辆状态为前往中
                ambulance.setStatus(Ambulance.Status.onWay);
                Attendance newAttendance1 = attendanceService.attendance(newAttendance, ambulance);
                return success(newAttendance1);
            } else {
                return failed("该车辆当前时间点排班人员不足");
            }
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceUpdate, method = RequestMethod.PUT)
    //@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    @ApiOperation(value = "更新出勤记录")
    public Envelop update(
            @ApiParam(name = "carId", value = "车牌号码")
            @RequestParam(value = "carId") String carId,
            @ApiParam(name = "status", value = "任务状态")
            @RequestParam(value = "status") String status) {
        Ambulance ambulance = ambulanceService.findById(carId);
        if (ambulance == null) {
            return failed("无相关车辆信息", new Integer(-1));
        }
        if("5".equals(status)){
            List<Attendance.Status> statuses = new ArrayList<Attendance.Status>();
            statuses.add(Attendance.Status.start);
            statuses.add(Attendance.Status.arrival);
            statuses.add(Attendance.Status.back);
            Attendance attendance = attendanceService.findByCarIdAndStatus(carId, statuses);
            attendance.setStatus(Attendance.Status.complete);
            attendance.setCompleteTime(new Date());
            //完成任务,重新设置车辆为待命中
            ambulance.setStatus(Ambulance.Status.wait);
            attendanceService.attendance(attendance, ambulance);
            return success(status);
        }else {
            List<Attendance.Status> statuses = new ArrayList<Attendance.Status>();
            statuses.add(Attendance.Status.start);
            statuses.add(Attendance.Status.arrival);
            statuses.add(Attendance.Status.back);
            Attendance attendance = attendanceService.findByCarIdAndStatus(carId, statuses);
            if (attendance != null) {
                if (status.equals("1") && attendance.getStatus() == Attendance.Status.start) { //到达事故地点
                    attendance.setStatus(Attendance.Status.arrival);
                    attendance.setArrivalTime(new Date());
                    ambulance.setStatus(Ambulance.Status.arrival);
                    attendanceService.attendance(attendance, ambulance);
                    return success(status);
                } else if (status.equals("2")) { //返程中
                    attendance.setStatus(Attendance.Status.back);
                    ambulance.setStatus(Ambulance.Status.back);
                    attendanceService.attendance(attendance, ambulance);
                    return success(status);
                } else if (status.equals("3")) { //完成任务
                    attendance.setStatus(Attendance.Status.complete);
                    attendance.setCompleteTime(new Date());
                    //完成任务,重新设置车辆为待命中
                    ambulance.setStatus(Ambulance.Status.wait);
                    attendanceService.attendance(attendance, ambulance);
                    return success(status);
                } else if (status.equals("4")) { //意外中止
                    attendance.setStatus(Attendance.Status.discontinue);
                    attendance.setCompleteTime(new Date());
                    //设置车辆为异常状态
                    ambulance.setStatus(Ambulance.Status.down);
                    attendanceService.attendance(attendance, ambulance);
                    return success(status);
                } else {
                    return failed("请求更新状态:" + status + ",与当前状态:" + attendance.getStatus().ordinal() + ",不匹配", new Integer(status));
                }
            } else {
                return failed("该车辆无可更新的出勤记录", new Integer(-1));
            }
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceEdit, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("编辑出勤记录")
    public Envelop edit(
            @ApiParam(name = "attendance", value = "出勤记录")
            @RequestBody String attendance) throws IOException {
        Attendance newAttendance = objectMapper.readValue(attendance, Attendance.class);
        Attendance oldAttendance = attendanceService.findById(newAttendance.getId());
        if (!oldAttendance.getCarId().equals(newAttendance.getCarId())) {
            return failed("车牌号码有误");
        }
        attendanceService.save(newAttendance);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceList, method = RequestMethod.GET)
    @ApiOperation("获取出勤列表")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<Attendance> attendance = attendanceService.search(fields, filters, sorts, page, size);
        int count = (int)attendanceService.getCount(filters);
        Envelop envelop = getPageResult(attendance, count, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除出勤记录")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表(int)1,2,3,...")
            @RequestParam(value = "ids") String ids){
        //List<Integer> idList = toEntity(ids, List.class);
        String [] idArr = ids.split(",");
        Integer [] idArr1 = new Integer[idArr.length];
        for (int i = 0; i < idArr.length; i++) {
            idArr1[i] = new Integer(idArr[i]);
        }
        attendanceService.delete(idArr1);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceDetail, method = RequestMethod.GET)
    @ApiOperation("出勤详情")
    public Envelop detail(
            @ApiParam(name = "id", value = "出勤任务Id")
            @RequestParam(value = "id", required = false) int id) throws Exception {
        Map<String,Object> map = new HashMap<String,Object>();
        Attendance attendance = attendanceService.findById(id);
        if (attendance != null){
            if (attendance.getSchedules().length()>2) {
                map.put("schedule", scheduleService.findByIds(attendance.getSchedules().substring(1,attendance.getSchedules().length()-1)));
            }
            map.put("attendance",attendance);
            map.put("user", userManager.getUser(attendance.getCreator()));
            map.put("car", ambulanceService.findById(attendance.getCarId()));
            return success(map);
        } else {
            return failed("出勤任务Id不存在");
        }
    }
    @RequestMapping(value = "/attendance/queryChart1", method = RequestMethod.GET)
    @ApiOperation("出车次数分析")
    public Envelop queryChart1(
            @ApiParam(name = "flag", value = "查询类型月、季、年(1,2,3)")
            @RequestParam(value = "flag", required = false) String flag) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("chart1", attendanceService.queryChart1(flag));
        return success(map);
    }
    @RequestMapping(value = "/attendance/queryChart3", method = RequestMethod.GET)
    @ApiOperation("出勤地点热力图")
    public Envelop queryChart3() {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("chart3", attendanceService.queryChart3());
        return success(map);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceAnalysis, method = RequestMethod.GET)
    @ApiOperation("出勤记录分析")
    public Envelop analysis() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String,Object> map = new HashMap<String,Object>();
        List<Location> locations = locationService.search("");
        List<Map<String, Object>> list =  attendanceService.queryChart5();
        List<Map<String, Object>> list2 = new ArrayList<Map<String,Object>>();
        List<Map<String, Object>> list5 = new ArrayList<Map<String,Object>>();
        List<Map<String, Object>> list6 = new ArrayList<Map<String,Object>>();
        //时间占比分析
        if (!list.isEmpty()){
            for (Location model :locations) {
                List<Map<String, Object>> l1 = new ArrayList<Map<String, Object>>();
                Map<String, Object> m1 = new HashMap<String, Object>();
                int i1 = 0;
                int i2 = 0;
                int i3 = 0;
                int i4 = 0;
                for (Map<String, Object> map1 : list) {
                    if (map1.get("init_address").equals(model.getInitAddress())) {
                        Date createDate = sdf.parse(map1.get("create_date").toString());
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(createDate);
                        int hour = calendar.get(Calendar.HOUR_OF_DAY);
                        if (hour >= 0 && hour < 6) {
                            i1++;
                        } else if (hour >= 6 && hour < 12) {
                            i2++;
                        } else if (hour >= 12 && hour < 18) {
                            i3++;
                        } else if (hour >= 18 && hour < 24) {
                            i4++;
                        }
                    }
                }
                Map<String, Object> map11 = new HashMap<String, Object>();
                map11.put("name", "00:00-06:00");
                map11.put("value", i1);
                l1.add(map11);
                Map<String, Object> map12 = new HashMap<String, Object>();
                map12.put("name", "06:00-12:00");
                map12.put("value", i2);
                l1.add(map12);
                Map<String, Object> map13 = new HashMap<String, Object>();
                map13.put("name", "12:00-18:00");
                map13.put("value", i3);
                l1.add(map13);
                Map<String, Object> map14 = new HashMap<String, Object>();
                map14.put("name", "18:00-24:00");
                map14.put("value", i4);
                l1.add(map14);
                m1.put(model.getInitAddress(), l1);
                list6.add(m1);
            }
            //时间占比分析
            int i1 = 0;
            int i2 = 0;
            int i3 = 0;
            int i4 = 0;
            for (Map<String,Object> map1:list){
                Date createDate = sdf.parse(map1.get("create_date").toString());
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(createDate);
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                if (hour >= 0 && hour < 6){
                    i1++;
                } else if (hour >=6 && hour < 12){
                    i2++;
                } else if (hour >= 12 &&hour < 18){
                    i3++;
                } else if (hour >=18 && hour < 24){
                    i4++;
                }
            }
            Map<String,Object> map11 = new HashMap<String,Object>();
            map11.put("name", "00:00-06:00");
            map11.put("value", i1);
            list5.add(map11);
            Map<String,Object> map12 = new HashMap<String,Object>();
            map12.put("name", "06:00-12:00");
            map12.put("value", i2);
            list5.add(map12);
            Map<String,Object> map13 = new HashMap<String,Object>();
            map13.put("name", "12:00-18:00");
            map13.put("value", i3);
            list5.add(map13);
            Map<String,Object> map14 = new HashMap<String,Object>();
            map14.put("name", "18:00-24:00");
            map14.put("value", i4);
            list5.add(map14);
        }
        //出车趋势图
        List<String> dateList = getDate();
        List<Map<String, Object>> data = attendanceService.queryChart2(dateList.get(0), dateList.get(dateList.size() - 1));
        for (Location model : locations) {
            List<Map<String,Object>> l =  new ArrayList<Map<String,Object>>();
            Map<String,Object> address = new HashMap<String,Object>();
            for (int i = 0 ; i < dateList.size(); i++){
                Map<String,Object> m = new HashMap<String,Object>();
                m.put(dateList.get(i), getData(dateList.get(i), model.getInitAddress(), data));
                l.add(m);
            }
            address.put(model.getInitAddress(), l);
            list2.add(address);
        }
        map.put("chart1", attendanceService.queryChart1("1"));
        map.put("chart2", list2);
        map.put("chart4", attendanceService.queryChart4());
        map.put("chart5", list5);
        map.put("chart6", list6);
        map.put("chart7", attendanceService.queryChart7());
        return success(map);
    }
    /**
     * 获取近一个月日期
     * @return
     */
    public List<String> getDate(){
        List<String> list = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        for(int i = 29 ; i > 1 ; i--) {
            calendar.setTime(new Date());
            calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - i);
            list.add(sdf.format(calendar.getTime()));
        }
        calendar.setTime(new Date());
        list.add(sdf.format(calendar.getTime()));
        return list;
    }
    /**
     * 根据日期和地点获取总数
     * @param date
     * @param address
     * @return
     */
    public int getData(String date, String address,List<Map<String,Object>> data){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int i = 0;
        if(!data.isEmpty()){
            for(Map<String, Object> map : data){
                if (date.equals(sdf.format(map.get("create_date"))) && address.equals(map.get("name"))){
                    i += Integer.parseInt(map.get("value") + "");
                }
            }
        }
        return i;
    }
}

+ 96 - 0
src/main/java/com.yihu.ehr/basic/emergency/controller/LocationEndPoint.java

@ -0,0 +1,96 @@
package com.yihu.ehr.basic.emergency.controller;
import com.yihu.ehr.basic.emergency.service.AmbulanceService;
import com.yihu.ehr.basic.emergency.service.LocationService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.emergency.Ambulance;
import com.yihu.ehr.entity.emergency.Location;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * EndPoint - 待命地点
 * Created by progr1mmer on 2017/11/22.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "LocationEndPoint", description = "待命地点", tags = {"应急指挥-待命地点"})
public class LocationEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private LocationService locationService;
    @Autowired
    private AmbulanceService ambulanceService;
    @RequestMapping(value = ServiceApi.Emergency.LocationList, method = RequestMethod.GET)
    @ApiOperation("获取待命地点列表")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<Location> locations = locationService.search(fields, filters, sorts, page, size);
        int count = (int)locationService.getCount(filters);
        Envelop envelop = getPageResult(locations, count, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Emergency.LocationSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存单条记录")
    public Envelop save(
            @ApiParam(name = "location", value = "待命地点")
            @RequestBody String location) throws Exception {
        Location newLocation = objectMapper.readValue(location, Location.class);
        Location location1 = locationService.save(newLocation);
        return success(location1);
    }
    @RequestMapping(value = ServiceApi.Emergency.LocationUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("更新单条记录")
    public Envelop update(
            @ApiParam(name = "location", value = "排班")
            @RequestBody String location) throws Exception {
        Location newLocation = objectMapper.readValue(location, Location.class);
        Location oldLocation = locationService.findById(newLocation.getId());
        if (oldLocation == null) {
            return failed("无相关待命地点记录");
        }
        Location location1 = locationService.save(newLocation);
        return success(location1);
    }
    @RequestMapping(value = ServiceApi.Emergency.LocationDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除待命地点")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表(int)1,2,3,...")
            @RequestParam(value = "ids") String ids) throws Exception {
        //List<Integer> idList = toEntity(ids, List.class);
        List<Ambulance> ambulanceList = ambulanceService.search("location=" + ids);
        if (ambulanceList == null || ambulanceList.size() > 0) {
            return failed("不能删除已有关联车辆的待命地点");
        }
        String [] idArrStr = ids.split(",");
        Integer [] idArrInt = new Integer[idArrStr.length];
        for (int i = 0; i < idArrStr.length; i++) {
            idArrInt[i] = new Integer(idArrStr[i]);
        }
        locationService.delete(idArrInt);
        return success(true);
    }
}

+ 278 - 0
src/main/java/com.yihu.ehr/basic/emergency/controller/ScheduleEndPoint.java

@ -0,0 +1,278 @@
package com.yihu.ehr.basic.emergency.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import com.yihu.ehr.basic.emergency.service.AmbulanceService;
import com.yihu.ehr.basic.emergency.service.ScheduleService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.emergency.Ambulance;
import com.yihu.ehr.entity.emergency.Schedule;
import com.yihu.ehr.util.datetime.DateUtil;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.text.ParseException;
import java.util.*;
/**
 * EndPoint - 排班历史
 * Created by progr1mmer on 2017/11/8.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "ScheduleEndPoint", description = "排班历史", tags = {"应急指挥-排班历史"})
public class ScheduleEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private AmbulanceService ambulanceService;
    @RequestMapping(value = ServiceApi.Emergency.ScheduleList, method = RequestMethod.GET)
    @ApiOperation("获取排班列表")
    public Envelop list(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
        List<Schedule> schedules = scheduleService.search(fields, filters, sorts, page, size);
        int count = (int)scheduleService.getCount(filters);
        Envelop envelop = getPageResult(schedules, count, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleLevel, method = RequestMethod.GET)
    @ApiOperation("获取排班层级列表(年-月-日)")
    public Envelop level(
            @ApiParam(name = "date", value = "年-月")
            @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "page", value = "分页大小", required = true, defaultValue = "1")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "页码", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws ParseException {
        if (StringUtils.isEmpty(date)) {
            List<Object> resultList = scheduleService.getLevel(page, size);
            Integer count = scheduleService.getLevelCount();
            Envelop envelop = getPageResult(resultList, count, page, size);
            return envelop;
        } else {
            List<Object> resultList = new ArrayList<Object>();
            List<java.sql.Date> dateGroup = scheduleService.getDateGroup(date, page, size);
            for(int i = 0; i < dateGroup.size(); i ++) {
                for(int j = 1; j >= 0 ; j --) {
                    Map<String, Object> middleMap1 = new HashMap<String, Object>();
                    java.sql.Date date1 = dateGroup.get(i);
                    //时间节点
                    middleMap1.put("date", date1.toString());
                    //数据节点
                    List<Schedule> scheduleList = scheduleService.getDateMatch(date1, j);
                    Map<String, Map<String, Object>> carMap = new HashMap<String, Map<String, Object>>();
                    String carId;
                    for (Schedule schedule : scheduleList) {
                        carId = schedule.getCarId();
                        Ambulance ambulance = ambulanceService.findById(carId);
                        if (null != ambulance) {
                            String dutyRole = schedule.getDutyRole();
                            String dutyName = schedule.getDutyName();
                            String scheduleId = schedule.getId().toString();
                            if (carMap.containsKey(carId)) {
                                Map<String, Object> dataMap = carMap.get(carId);
                                String time = schedule.getStart().toString();
                                if (dataMap.containsKey(time)) {
                                    for (String timeKey : dataMap.keySet()) {
                                        if (time.equals(timeKey)) {
                                            Map<String, String> detailMap = (Map<String, String>) dataMap.get(time);
                                            String scheduleIds = detailMap.get("scheduleIds");
                                            detailMap.put("scheduleIds", scheduleIds + "," + scheduleId);
                                            if ("医生".equals(dutyRole)) {
                                                String doctors;
                                                if (StringUtils.isEmpty(detailMap.get("doctor"))) {
                                                    doctors = dutyName;
                                                } else {
                                                    doctors = detailMap.get("doctor") + "," + dutyName;
                                                }
                                                detailMap.put("doctor", doctors);
                                            } else if ("护士".equals(dutyRole)) {
                                                String nurses;
                                                if (StringUtils.isEmpty(detailMap.get("nurse"))) {
                                                    nurses = dutyName;
                                                } else {
                                                    nurses = detailMap.get("nurse") + "," + dutyName;
                                                }
                                                detailMap.put("nurse", nurses);
                                            } else if ("司机".equals(dutyRole)) {
                                                String drivers;
                                                if (StringUtils.isEmpty(detailMap.get("driver"))) {
                                                    drivers = dutyName;
                                                } else {
                                                    drivers = detailMap.get("driver") + "," + dutyName;
                                                }
                                                detailMap.put("driver", drivers);
                                            }
                                        }
                                    }
                                } else {
                                    //Map<String, Object> newDataMap = new HashMap<String, Object>();
                                    Map<String, String> detailMap = new HashMap<String, String>();
                                    detailMap.put("start", schedule.getStart().toString());
                                    detailMap.put("end", schedule.getEnd().toString());
                                    detailMap.put("carId", carId);
                                    detailMap.put("main", schedule.getMain().toString());
                                    detailMap.put("location", ambulance.getOrgName());
                                    detailMap.put("scheduleIds", scheduleId);
                                    if ("医生".equals(dutyRole)) {
                                        detailMap.put("doctor", dutyName);
                                    } else if ("护士".equals(dutyRole)) {
                                        detailMap.put("nurse", dutyName);
                                    } else if ("司机".equals(dutyRole)) {
                                        detailMap.put("driver", dutyName);
                                    }
                                    //dataMap.put("time", schedule.getStart().toString());
                                    dataMap.put(schedule.getStart().toString(), detailMap);
                                    //carMap.put(carId, newDataMap);
                                }
                            } else {
                                Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
                                Map<String, String> detailMap = new HashMap<String, String>();
                                detailMap.put("start", schedule.getStart().toString());
                                detailMap.put("end", schedule.getEnd().toString());
                                detailMap.put("carId", carId);
                                detailMap.put("main", schedule.getMain().toString());
                                detailMap.put("location", ambulance.getOrgName());
                                detailMap.put("scheduleIds", scheduleId);
                                if ("医生".equals(dutyRole)) {
                                    detailMap.put("doctor", dutyName);
                                } else if ("护士".equals(dutyRole)) {
                                    detailMap.put("nurse", dutyName);
                                } else if ("司机".equals(dutyRole)) {
                                    detailMap.put("driver", dutyName);
                                }
                                //dataMap.put("time", schedule.getStart().toString());
                                dataMap.put(schedule.getStart().toString(), detailMap);
                                carMap.put(carId, dataMap);
                            }
                        } else {
                            Map<String, Object> errorMap = new HashMap<String, Object>(1);
                            errorMap.put("error", "无相关车辆");
                            carMap.put(carId, errorMap);
                        }
                    }
                    List<Object> middleList = new ArrayList<Object>(carMap.size());
                    for (String car : carMap.keySet()) {
                        for (String timeKey : carMap.get(car).keySet()) {
                            middleList.add(carMap.get(car).get(timeKey));
                        }
                    }
                    middleMap1.put("data", middleList);
                    resultList.add(middleMap1);
                }
            }
            int count = scheduleService.getDateGroupCount(date);
            Envelop envelop = getPageResult(resultList, count, page, size);
            return envelop;
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存单条记录")
    public Envelop save(
            @ApiParam(name = "schedule", value = "排班")
            @RequestBody String schedule) throws Exception {
        Schedule newSchedule = objectMapper.readValue(schedule, Schedule.class);
        Ambulance ambulance = ambulanceService.findById(newSchedule.getCarId());
        if (ambulance == null) {
            return failed("无相关车辆信息");
        }
        scheduleService.save(newSchedule);
        return success(true);
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("更新单条记录,历史记录不能更新")
    public Envelop update(
            @ApiParam(name = "schedule", value = "排班")
            @RequestBody String schedule) throws Exception {
        Envelop envelop = new Envelop();
        Schedule newSchedule = objectMapper.readValue(schedule, Schedule.class);
        Schedule oldSchedule  = scheduleService.findById(newSchedule.getId());
        if (oldSchedule == null) {
            return failed("无相关排班信息");
        }
        if (new Date().getTime() > oldSchedule.getDate().getTime()) {
            return failed("历史记录不能更新");
        }
        Ambulance ambulance = ambulanceService.findById(newSchedule.getCarId());
        if (ambulance == null) {
            return failed("无相关车辆信息");
        } else if(ambulance.getStatus() == Ambulance.Status.wait || ambulance.getStatus() == Ambulance.Status.down) {
            scheduleService.save(newSchedule);
            return success(true);
        } else {
            return failed("相关车辆处于执勤状态");
        }
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleBathUpdate, method = RequestMethod.PUT)
    @ApiOperation("更新多条数据,历史记录不能更新")
    public Envelop bathUpdate(
            @ApiParam(name = "schedules", value = "排班")
            @RequestParam(value = "schedules") String schedules) throws IOException{
        List<Map<String, Object>> scheduleList = objectMapper.readValue(schedules, List.class);
        for (Map<String, Object> newSchedule : scheduleList) {
            Schedule old = scheduleService.findById((int)newSchedule.get("id"));
            Ambulance ambulance = ambulanceService.findById(old.getCarId());
            if (ambulance.getStatus() != Ambulance.Status.wait && ambulance.getStatus() != Ambulance.Status.down) {
                return failed("相关车辆正在执勤,不允许更新");
            }
            if ((new Date().getTime() - old.getDate().getTime()) > 0 ) {
                return failed("历史记录不能更新");
            }
            old.setDutyName(newSchedule.get("dutyName") == null? "": newSchedule.get("dutyName").toString());
            old.setGender(newSchedule.get("gender") == null? "": newSchedule.get("gender").toString());
            old.setDutyNum(newSchedule.get("dutyNum") == null? "": newSchedule.get("dutyNum").toString());
            old.setDutyPhone(newSchedule.get("dutyPhone") == null? "": newSchedule.get("dutyPhone").toString());
            scheduleService.save(old);
        }
        return success(true);
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入排班信息")
    public boolean createSchedulesBatch(
            @ApiParam(name = "schedules", value = "排班信息")
            @RequestParam(value = "schedules") String schedules) throws Exception{
        List models = objectMapper.readValue(schedules, new TypeReference<List>() {});
        scheduleService.addSchedulesBatch(models);
        return true;
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleCleanData, method = RequestMethod.POST)
    @ApiOperation("删除历史数据之外的某个时间段内的数据,基本单位为天")
    public int cleanData(
            @ApiParam(name = "carId", value = "车牌号码", required = true)
            @RequestParam(value = "carId") String carId,
            @ApiParam(name = "start", value = "开始时间", required = true)
            @RequestParam(value = "start") String start,
            @ApiParam(name = "end", value = "结束时间", required = true)
            @RequestParam(value = "end") String end) throws Exception{
        Date start1 = DateUtil.strToDate(start);
        Date end1 = DateUtil.strToDate(end);
        return scheduleService.cleanAllData(carId, start1, end1);
    }
}

+ 15 - 0
src/main/java/com.yihu.ehr/basic/emergency/dao/AmbulanceDao.java

@ -0,0 +1,15 @@
package com.yihu.ehr.basic.emergency.dao;
import com.yihu.ehr.entity.emergency.Ambulance;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Dao - 救护车信息
 * Created by progr1mmer on 2017/11/8.
 */
public interface AmbulanceDao extends PagingAndSortingRepository<Ambulance, String> {
    Ambulance findById(String id);
    Ambulance findByPhone(String phone);
}

+ 24 - 0
src/main/java/com.yihu.ehr/basic/emergency/dao/AttendanceDao.java

@ -0,0 +1,24 @@
package com.yihu.ehr.basic.emergency.dao;
import com.yihu.ehr.entity.emergency.Attendance;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.Date;
import java.util.List;
/**
 * Dao - 出勤记录
 * Created by progr1mmer on 2017/11/8.
 */
public interface AttendanceDao extends PagingAndSortingRepository<Attendance, Integer> {
    @Query("SELECT attendance FROM Attendance attendance WHERE attendance.carId = :carId AND attendance.status IN (:statuses)")
    Attendance findByCarIdAndStatus(@Param("carId") String carId, @Param("statuses") List<Attendance.Status> statuses);
    @Query("SELECT attendance FROM Attendance attendance WHERE attendance.createDate <= :createDate AND attendance.carId = :carId ORDER BY attendance.createDate DESC")
    List<Attendance> findByCreateDateAndCarId(@Param("createDate") Date createDate, @Param("carId") String carId);
    Attendance findById(int id);
}

+ 13 - 0
src/main/java/com.yihu.ehr/basic/emergency/dao/LocationDao.java

@ -0,0 +1,13 @@
package com.yihu.ehr.basic.emergency.dao;
import com.yihu.ehr.entity.emergency.Location;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Dao - 待命地点
 * Created by progr1mmer on 2017/11/22.
 */
public interface LocationDao extends PagingAndSortingRepository<Location, Integer> {
    Location findById(Integer id);
}

+ 14 - 0
src/main/java/com.yihu.ehr/basic/emergency/dao/ScheduleDao.java

@ -0,0 +1,14 @@
package com.yihu.ehr.basic.emergency.dao;
import com.yihu.ehr.entity.emergency.Schedule;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Dao - 排版历史
 * Created by progr1mmer on 2017/11/8.
 */
public interface ScheduleDao extends PagingAndSortingRepository<Schedule, Integer> {
    Schedule findById(int id);
}

+ 86 - 0
src/main/java/com.yihu.ehr/basic/emergency/service/AmbulanceService.java

@ -0,0 +1,86 @@
package com.yihu.ehr.basic.emergency.service;
import com.yihu.ehr.basic.emergency.dao.AmbulanceDao;
import com.yihu.ehr.entity.emergency.Ambulance;
import com.yihu.ehr.query.BaseJpaService;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;
/**
 * Service - 救护车信息
 * Created by progr1mmer on 2017/11/8.
 */
@Service
@Transactional
public class AmbulanceService extends BaseJpaService<Ambulance, AmbulanceDao> {
    @Autowired
    private AmbulanceDao ambulanceDao;
    public Ambulance findById(String carId){
        return ambulanceDao.findById(carId);
    }
    public Ambulance findByPhone(String phone) {
        return ambulanceDao.findByPhone(phone);
    }
    /**
     * 查询电话号码是否已存在, 返回已存在电话号码
     */
    public List idExist(String type, String[] values) {
        String sql ="";
        if(type.equals("id")){
           sql= "SELECT id FROM eme_ambulance WHERE id in(:values)";
        }else if(type.equals("phone")){
            sql= "SELECT phone FROM eme_ambulance WHERE phone in(:values)";
        }
        SQLQuery sqlQuery = currentSession().createSQLQuery(sql);
        sqlQuery.setParameterList("values", values);
        return sqlQuery.list();
    }
    /**
     * 批量导入救护车
     */
    public boolean addAmbulancesBatch(List<Map<String, Object>> ambulances) {
        Map<String, Object> map;
        try{
            for(int i=1; i <= ambulances.size(); i++){
                map = ambulances.get(i-1);
                Ambulance ambulance=new Ambulance();
                ambulance.setId(map .get("id").toString());
                /**
                if(null!=map .get("initLongitude")){
                    ambulance.setInitLongitude(Double.valueOf(map .get("initLongitude").toString()));
                }else{
                    ambulance.setInitLongitude(0.0);
                }
                if(null!=map .get("initLatitude")){
                    ambulance.setInitLatitude(Double.valueOf(map .get("initLatitude").toString()));
                }else{
                    ambulance.setInitLatitude(0.0);
                }
                ambulance.setDistrict(map .get("district").toString());
                */
                //ambulance.setOrgCode(map .get("orgCode").toString());
                ambulance.setOrgName(map .get("orgName").toString());
                ambulance.setPhone(map .get("phone").toString());
                ambulance.setStatus(Ambulance.Status.wait);
                ambulance.setEntityName(map .get("entityName").toString());
                ambulance.setCreator(map .get("creator").toString());
                ambulanceDao.save(ambulance);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}

+ 102 - 0
src/main/java/com.yihu.ehr/basic/emergency/service/AttendanceService.java

@ -0,0 +1,102 @@
package com.yihu.ehr.basic.emergency.service;
import com.yihu.ehr.basic.emergency.dao.AmbulanceDao;
import com.yihu.ehr.basic.emergency.dao.AttendanceDao;
import com.yihu.ehr.entity.emergency.Ambulance;
import com.yihu.ehr.entity.emergency.Attendance;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Service - 出勤记录
 * Created by progr1mmer on 2017/11/8.
 */
@Service
@Transactional
public class AttendanceService extends BaseJpaService<Attendance, AttendanceDao> {
    @Autowired
    private AttendanceDao attendanceDao;
    @Autowired
    private AmbulanceDao ambulanceDao;
    @Transactional(readOnly = true)
    public Attendance findByCarIdAndStatus(String carId, List<Attendance.Status> statuses) {
        return attendanceDao.findByCarIdAndStatus(carId, statuses);
    }
    @Transactional(readOnly = true)
    public Attendance findByCreateDateAndCarId(Date startTime, String carId) {
        List<Attendance> attendanceList = attendanceDao.findByCreateDateAndCarId(startTime, carId);
        if (attendanceList != null && attendanceList.size() > 0) {
            return attendanceList.get(0);
        } else {
            return null;
        }
    }
    @Transactional(readOnly = true)
    public Attendance findById(int id) {
        return attendanceDao.findById(id);
    }
    public Attendance attendance(Attendance attendance, Ambulance ambulance) {
        Attendance attendance1 = attendanceDao.save(attendance);
        ambulanceDao.save(ambulance);
        return attendance1;
    }
    public List<Map<String,Object>> queryChart1(String flag){
        String sql = "";
        if("1".equals(flag)){
            sql="select b.init_address name,count(b.init_address) value from eme_attendance a ,eme_location b,eme_ambulance c " +
                    " where c.location = b.id  and a.car_id = c.id and date_format(a.create_date,'%Y-%m')=date_format(now(),'%Y-%m') " +
                    " group by b.init_address order by b.init_address";
        }else if("2".equals(flag)){
            sql="select b.init_address name,count(b.init_address) value from eme_attendance a ,eme_location b,eme_ambulance c " +
                    " where c.location = b.id  and a.car_id = c.id and QUARTER(a.create_date)=QUARTER(now())" +
                    " group by b.init_address order by b.init_address";
        }else{
            sql="select b.init_address name,count(b.init_address) value from eme_attendance a ,eme_location b,eme_ambulance c " +
                    " where c.location = b.id  and a.car_id = c.id and YEAR(a.create_date)=YEAR(now())" +
                    " group by b.init_address order by b.init_address";
        }
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>> queryChart2(String startDate,String endDate){
        String sql = "select b.init_address name,count(b.init_address) value,a.create_date from" +
                " eme_attendance a ,eme_location b,eme_ambulance c where" +
                " c.location = b.id  and a.car_id = c.id and a.create_date>='"+startDate+"' and date_sub(a.create_date,interval 1 day)<='"+endDate+"'" +
                " group by b.init_address,a.create_date";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>> queryChart3(){
        String sql = "select longitude, latitude,count(longitude||latitude) value from eme_attendance group by longitude,latitude";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>> queryChart4(){
        String sql = "select b.init_address name,count(b.init_address) value from eme_attendance a ,eme_location b,eme_ambulance c" +
                " where c.location = b.id  and a.car_id = c.id group by b.init_address";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>> queryChart5(){
        String sql = "select a.create_date,a.car_id,b.init_address from" +
                " eme_attendance a ,eme_location b,eme_ambulance c where" +
                "  c.location = b.id  and a.car_id = c.id ";
        return jdbcTemplate.queryForList(sql);
    }
    public List<Map<String,Object>> queryChart7(){
        String sql = "select chief_complaint name,count(chief_complaint) value from eme_attendance group by chief_complaint";
        return jdbcTemplate.queryForList(sql);
    }
}

+ 25 - 0
src/main/java/com.yihu.ehr/basic/emergency/service/LocationService.java

@ -0,0 +1,25 @@
package com.yihu.ehr.basic.emergency.service;
import com.yihu.ehr.basic.emergency.dao.LocationDao;
import com.yihu.ehr.entity.emergency.Location;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
/**
 * Service - 待命地点
 * Created by progr1mmer on 2017/11/22.
 */
@Service
@Transactional
public class LocationService extends BaseJpaService<Location, LocationDao> {
    @Autowired
    private LocationDao locationDao;
    public Location findById(Integer id) {
        return locationDao.findById(id);
    }
}

+ 238 - 0
src/main/java/com.yihu.ehr/basic/emergency/service/ScheduleService.java

@ -0,0 +1,238 @@
package com.yihu.ehr.basic.emergency.service;
import com.yihu.ehr.basic.emergency.dao.ScheduleDao;
import com.yihu.ehr.entity.emergency.Schedule;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.util.datetime.DateUtil;
import org.apache.commons.lang.time.DateUtils;
import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Service - 排班历史
 * Created by progr1mmer on 2017/11/8.
 */
@Service
@Transactional
public class ScheduleService extends BaseJpaService<Schedule, ScheduleDao> {
    @Autowired
    private ScheduleDao scheduleDao;
    public Schedule findById(int id){
        return scheduleDao.findById(id);
    }
    public List<Schedule> findMatch(String carId, Date date){
        java.sql.Date date1 = new java.sql.Date(date.getTime());
        java.sql.Time time = new java.sql.Time(date.getTime());
        String sql = "SELECT schedule FROM Schedule schedule WHERE schedule.carId = :carId AND schedule.status = :status AND schedule.date = :date AND schedule.start <= :start AND schedule.end >= :end";
        Session session = currentSession();
        Query query = session.createQuery(sql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setParameter("carId", carId);
        query.setParameter("status", Schedule.Status.on);
        query.setParameter("date", date1);
        query.setParameter("start", time);
        query.setParameter("end", time);
        return query.list();
    }
    public List<Object> getLevel(int page, int size) throws ParseException{
        Session session = currentSession();
        String hql = "SELECT DATE_FORMAT(date, '%Y-%m') FROM Schedule schedule GROUP BY DATE_FORMAT(date, '%Y-%m')";
        Query query = session.createQuery(hql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setFirstResult((page - 1) * size);
        query.setMaxResults(size);
        return query.list();
    }
    public Integer getLevelCount() throws ParseException{
        Session session = currentSession();
        String hql = "SELECT DATE_FORMAT(date, '%Y-%m') FROM Schedule schedule GROUP BY DATE_FORMAT(date, '%Y-%m')";
        Query query = session.createQuery(hql);
        query.setFlushMode(FlushMode.COMMIT);
        return query.list().size();
    }
    public List<java.sql.Date> getDateGroup(String date, int page, int size) throws ParseException {
        Session session = currentSession();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Date date1 = dateFormat.parse(date);
        java.sql.Date date11 = new java.sql.Date(date1.getTime());
        Date date2 = new Date(DateUtils.addMonths(date1, 1).getTime() - 1);
        java.sql.Date date22 = new java.sql.Date(date2.getTime());
        String hql =  "SELECT schedule.date FROM Schedule schedule WHERE schedule.date BETWEEN :date1 AND :date2 GROUP BY schedule.date ORDER BY schedule.date ASC";
        Query query = session.createQuery(hql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setDate("date1", date11);
        query.setDate("date2", date22);
        //query.setParameter("date", "%" + date + "%");
        query.setFirstResult((page - 1) * size);
        query.setMaxResults(size);
        return query.list();
    }
    public Integer getDateGroupCount(String date) throws ParseException {
        Session session = currentSession();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Date date1 = dateFormat.parse(date);
        java.sql.Date date11 = new java.sql.Date(date1.getTime());
        Date date2 = new Date(DateUtils.addMonths(date1, 1).getTime() - 1);
        java.sql.Date date22 = new java.sql.Date(date2.getTime());
        String hql =  "SELECT schedule.date FROM Schedule schedule WHERE schedule.date BETWEEN :date1 AND :date2 GROUP BY schedule.date ORDER BY schedule.date ASC";
        Query query = session.createQuery(hql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setDate("date1", date11);
        query.setDate("date2", date22);
        return query.list().size();
    }
    public List<Schedule> getDateMatch(java.sql.Date date, int main) {
        Session session = currentSession();
        String hql = "SELECT schedule FROM Schedule schedule WHERE schedule.date = :date1 AND schedule.main = :main ORDER BY schedule.date ASC";
        Query query = session.createQuery(hql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setDate("date1", date);
        query.setInteger("main", main);
        return query.list();
    }
    /**
     * 批量导入排班信息
     * @param schedules
     * @return
     */
    public boolean addSchedulesBatch(List<Map<String, Object>> schedules) {
        Map<String, Object> map;
        Date now = new Date();
        try{
            for(int i = 1; i <= schedules.size(); i++){
                map = schedules.get(i - 1);
                String dutyName = map.get("dutyName").toString();
                String gender;
                //性别:0未知,1为男,2为女
                if(null != map.get("gender")) {
                    if("男".equals(map.get("gender").toString())){
                        gender = "1";
                    }else if("女".equals(map.get("gender").toString())){
                        gender = "2";
                    }else{
                        gender = "0";
                    }
                }else {
                    gender = "0";
                }
                boolean main;
                if(null != map.get("main")){
                    if("主班".equals(map .get("main").toString())){
                        main = true;
                    }else if("副班".equals(map.get("main").toString())){
                        main = false;
                    }else {
                        main = true;
                    }
                }else{
                    main = true;
                }
                String dutyNum = map .get("dutyNum").toString();
                String dutyRole = map .get("dutyRole").toString();
                String dutyPhone = map .get("dutyPhone").toString();
                String carId = map .get("carId").toString();
                String creator = map .get("creator").toString();
                Date start = DateUtil.strToDate(map.get("start").toString());
                Date end = DateUtil.strToDate(map.get("end").toString());
                int diff = DateUtil.getDifferenceOfDays(start, end);
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                if(start.getTime() > now.getTime()) { //历史记录不能更新
                    cleanData(carId, start, end, dutyRole, dutyName); //清除之前的数据, 基本单位为天
                    for(int j = 0; j <= diff; j ++) {
                        Schedule schedule = new Schedule();
                        java.sql.Date today = new java.sql.Date(DateUtils.addDays(start, j).getTime());
                        java.sql.Time startTime;
                        java.sql.Time endTime;
                        if (0 == j) {
                            startTime = new java.sql.Time(start.getTime());
                            Date tomorrow = DateUtils.addDays(dateFormat.parse(today.toString()), 1);
                            endTime = new java.sql.Time(tomorrow.getTime() - 1);
                        } else if (diff == j) {
                            startTime = new java.sql.Time(dateFormat.parse(today.toString()).getTime());
                            endTime = new java.sql.Time(end.getTime());
                        } else {
                            startTime = new java.sql.Time(dateFormat.parse(today.toString()).getTime());
                            Date tomorrow = DateUtils.addDays(dateFormat.parse(today.toString()), 1);
                            endTime = new java.sql.Time(tomorrow.getTime() - 1);
                        }
                        schedule.setDate(today);
                        schedule.setStart(startTime);
                        schedule.setEnd(endTime);
                        schedule.setDutyName(dutyName);
                        schedule.setGender(gender);
                        schedule.setMain(main);
                        schedule.setDutyNum(dutyNum);
                        schedule.setDutyRole(dutyRole);
                        schedule.setDutyPhone(dutyPhone);
                        schedule.setCarId(carId);
                        schedule.setCreator(creator);
                        schedule.setStatus(Schedule.Status.on);
                        scheduleDao.save(schedule);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    public List<Schedule> findByIds(String ids) throws Exception{
        String sql = "SELECT schedule FROM Schedule schedule WHERE schedule.id in ("+ids+")";
        Session session = currentSession();
        Query query = session.createQuery(sql);
        query.setFlushMode(FlushMode.COMMIT);
        return query.list();
    }
    @Transactional
    public int cleanData(String carId, Date start, Date end, String dutyRole, String dutyName) {
        java.sql.Date start1 = new java.sql.Date(start.getTime());
        java.sql.Date end1 = new java.sql.Date(end.getTime());
        String sql = "DELETE FROM eme_schedule WHERE car_id = :carId AND date BETWEEN :start AND :end AND duty_role = :dutyRole AND duty_name = :dutyName";
        Session session = currentSession();
        Query query = session.createSQLQuery(sql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setString("carId", carId);
        query.setDate("start", start1);
        query.setDate("end", end1);
        query.setString("dutyRole", dutyRole);
        query.setString("dutyName", dutyName);
        return query.executeUpdate();
    }
    @Transactional
    public int cleanAllData(String carId, Date start, Date end) {
        java.sql.Date start1 = new java.sql.Date(start.getTime());
        java.sql.Date end1 = new java.sql.Date(end.getTime());
        String sql = "DELETE FROM eme_schedule WHERE car_id = :carId AND date BETWEEN :start AND :end";
        Session session = currentSession();
        Query query = session.createSQLQuery(sql);
        query.setFlushMode(FlushMode.COMMIT);
        query.setString("carId", carId);
        query.setDate("start", start1);
        query.setDate("end", end1);
        return query.executeUpdate();
    }
}

+ 175 - 0
src/main/java/com.yihu.ehr/basic/fileresource/controller/FileResourceEndPoint.java

@ -0,0 +1,175 @@
package com.yihu.ehr.basic.fileresource.controller;
import com.yihu.ehr.basic.fileresource.service.FileResource;
import com.yihu.ehr.basic.fileresource.service.FileResourceManager;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.util.id.BizObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.12 8:53
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "files", description = "文件管理接口", tags = {"文件管理接口"})
public class FileResourceEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private FastDFSUtil fastDFSUtil;
    @Autowired
    private FileResourceManager fileResourceManager;
    @Value("${fast-dfs.public-server}")
    private String fastDfsPublicServers;
    @RequestMapping(value = "/files_upload", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件")
    public String fileUpload(
            @ApiParam(name = "file_str", value = "文件字符串", required = true)
            @RequestBody String fileStr,
            @ApiParam(name = "file_name", value = "文件名", required = true)
            @RequestParam(value = "file_name") String fileName,
            @ApiParam(name = "json_data", value = "文件资源属性", required = true)
            @RequestParam(value = "json_data") String jsonData) throws Exception {
        FileResource fileResource = toEntity(jsonData, FileResource.class);
        fileResource.setId(getObjectId(BizObject.FileResource));
        return fileResourceManager.saveFileResource(fileStr, fileName, fileResource);
    }
    @RequestMapping(value = "/files_upload_returnUrl", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件,并返回存储相对路径")
    public String fileUploadReturnUrl(
            @ApiParam(name = "file_str", value = "文件字符串", required = true)
            @RequestBody String fileStr,
            @ApiParam(name = "file_name", value = "文件名", required = true)
            @RequestParam(value = "file_name") String fileName,
            @ApiParam(name = "json_data", value = "文件资源属性", required = true)
            @RequestParam(value = "json_data") String jsonData) throws Exception {
            FileResource fileResource = toEntity(jsonData, FileResource.class);
            fileResource.setId(getObjectId(BizObject.FileResource));
            return fileResourceManager.saveFileResourceReturnUrl(fileStr, fileName, fileResource);
    }
    @RequestMapping(value = "/files_upload_returnHttpUrl", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件,并返回存储绝对路径")
    public String fileUploadReturnHttpUrl(
            @ApiParam(name = "file_str", value = "文件字符串", required = true)
            @RequestBody String fileStr,
            @ApiParam(name = "file_name", value = "文件名", required = true)
            @RequestParam(value = "file_name") String fileName,
            @ApiParam(name = "json_data", value = "文件资源属性", required = true)
            @RequestParam(value = "json_data") String jsonData) throws Exception {
        FileResource fileResource = toEntity(jsonData, FileResource.class);
        fileResource.setId(getObjectId(BizObject.FileResource));
        return fileResourceManager.saveFileResourceReturnHttpUrl(fileStr, fileName, fileResource);
    }
    @RequestMapping(value = "/files", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastdfs相对应文件")
    public boolean filesDelete(
            @ApiParam(name = "object_id", value = "文件字符串", required = true)
            @RequestParam(value = "object_id") String objectId) throws Exception {
        List<FileResource> fileResources = fileResourceManager.findByObjectId(objectId);
        return fileResourceManager.deleteFileResource(fileResources);
    }
    @RequestMapping(value = "/image_delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastdfs相对应文件")
    public boolean filesDeleteByPath(
            @ApiParam(name = "storagePath", value = "文件路径", required = true)
            @RequestParam(value = "storagePath") String storagePath) throws Exception {
        String s = java.net.URLDecoder.decode(storagePath, "UTF-8");
        List<FileResource> fileResources = fileResourceManager.findByStoragePath(s);
        return fileResourceManager.deleteFileResource(fileResources);
    }
    @RequestMapping(value = "/files_download", method = RequestMethod.GET)
    @ApiOperation(value = "下载文件")
    public List<String> filesDownload(
            @ApiParam(name = "object_id", value = "文件字符串", required = true)
            @RequestParam(value = "object_id") String objectId,
            @ApiParam(name = "mime", value = "所有者", required = true)
            @RequestParam(value = "mime", required = false) String mime) throws Exception {
        List<FileResource> fileResources;
        if (StringUtils.isEmpty(mime))
            fileResources = fileResourceManager.findByObjectId(objectId);
        else
            fileResources = fileResourceManager.findByObjectIdAndMime(objectId, mime);
        List<String> filesStrs = new ArrayList<>();
        for (FileResource fileResource : fileResources) {
            String storagePath = fileResource.getStoragePath();
            String groupName = storagePath.split(":")[0];
            String remoteFileName = storagePath.split(":")[1];
            byte[] bytes = fastDFSUtil.download(groupName, remoteFileName);
            String fileStream = new String(Base64.getEncoder().encode(bytes));
            filesStrs.add(fileStream);
        }
        return filesStrs;
    }
    @RequestMapping(value = "/files_path", method = RequestMethod.GET)
    @ApiOperation(value = "获取文件路径")
    public List<String> getFilePath(
            @ApiParam(name = "object_id", value = "文件字符串", required = true)
            @RequestParam(value = "object_id") String objectId) throws Exception {
        List<FileResource> fileResources = fileResourceManager.findByObjectId(objectId);
        List<String> filesStrs = new ArrayList<>();
        for (FileResource fileResource : fileResources) {
            String storagePath = fileResource.getStoragePath();
            storagePath = URLEncoder.encode(storagePath, "ISO8859-1");
            filesStrs.add(storagePath);
        }
        return filesStrs;
    }
    @RequestMapping(value = "/image_view", method = RequestMethod.GET)
    @ApiOperation(value = "下载文件")
    public String imageView(
            @ApiParam(name = "storagePath", value = "文件路径", required = true)
            @RequestParam(value = "storagePath") String storagePath) throws Exception {
        String s = java.net.URLDecoder.decode(storagePath, "UTF-8");
        String groupName = s.split(":")[0];
        String remoteFileName = s.split(":")[1];
        byte[] bytes = fastDFSUtil.download(groupName, remoteFileName);
        String fileStream = new String(Base64.getEncoder().encode(bytes));
        return fileStream;
    }
    @ApiOperation(value = "根据文件ID,获取文件的真实访问路径")
    @RequestMapping(value = "/file/getRealPathById", method = RequestMethod.GET)
    public String getRealPathById(
            @ApiParam(name = "fileId", value = "文件ID", required = true)
            @RequestParam(value = "fileId") String fileId) throws Exception {
        String s = java.net.URLDecoder.decode(fileId, "UTF-8");
        String path = fileResourceManager.getStoragePathById(s);
        path = path.replace(":", "/");
        path = fastDfsPublicServers + "/" + path;
        return path;
    }
    @ApiOperation(value = "根据文件的存储路径,获取文件的真实访问路径")
    @RequestMapping(value = "/file/getRealPathByStoragePath", method = RequestMethod.GET)
    public String getRealPathByStoragePath(
            @ApiParam(name = "storagePath", value = "文件存储路径", required = true)
            @RequestParam(value = "storagePath") String storagePath) throws Exception {
        String realPath = fastDfsPublicServers + "/" + storagePath.replace(":", "/");
        return realPath;
    }
}

+ 101 - 0
src/main/java/com.yihu.ehr/basic/fileresource/service/FileResource.java

@ -0,0 +1,101 @@
package com.yihu.ehr.basic.fileresource.service;
import javax.persistence.*;
import java.util.Date;
/**
 * @author linaz
 * @created 2016.05.12 8:53
 */
@Entity
@Table(name = "file_resource")
@Access(value = AccessType.PROPERTY)
public class FileResource {
    private String id;                   // objectId
    private String storagePath;          // FDS path
    private String mime;                 // user/org/patient 冗余字段,后继图片管理用
    private String objectId;             // userId/orgCode/patientId 各类编号都是唯一
    private String purpose;                // face/credentials  用途 头像 资质认证
    private Date createDate;
    private String createUser;
    private Date updateDate;
    private String updateUser;
    public static  final String MINE_ORG ="org";
    public static  final String MINE_USER ="user";
    public static  final String MINE_PATIENT ="patient";
    @Id
    @Column(name = "id", unique = true, nullable = false)
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    @Column(name = "storage_path",  nullable = true)
    public String getStoragePath() {
        return storagePath;
    }
    public void setStoragePath(String storagePath) {
        this.storagePath = storagePath;
    }
    @Column(name = "mime",  nullable = true)
    public String getMime() {
        return mime;
    }
    public void setMime(String mime) {
        this.mime = mime;
    }
    @Column(name = "object_id",  nullable = true)
    public String getObjectId() {
        return objectId;
    }
    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }
    @Column(name = "purpose",  nullable = true)
    public String getPurpose() {
        return purpose;
    }
    public void setPurpose(String usage) {
        this.purpose = purpose;
    }
    @Column(name = "create_date",  nullable = true)
    public Date getCreateDate() {
        return createDate;
    }
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
    @Column(name = "create_user",  nullable = true)
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    @Column(name = "update_date",  nullable = true)
    public Date getUpdateDate() {
        return updateDate;
    }
    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }
    @Column(name = "update_user",  nullable = true)
    public String getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
}

+ 106 - 0
src/main/java/com.yihu.ehr/basic/fileresource/service/FileResourceManager.java

@ -0,0 +1,106 @@
package com.yihu.ehr.basic.fileresource.service;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Base64;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.12 8:53
 */
@Service
@Transactional
public class FileResourceManager extends BaseJpaService<FileResource, XFileResourceRepository> {
    @Autowired
    private XFileResourceRepository resourceRepository;
    @Autowired
    private FastDFSUtil fastDFSUtil;
    @Value("${fast-dfs.public-server}")
    private String fastDfsPublicServers;
    public String saveFileResource(String fileStr, String fileName, FileResource fileResource) throws Exception {
        byte[] bytes = Base64.getDecoder().decode(fileStr);
        InputStream inputStream = new ByteArrayInputStream(bytes);
        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
        ObjectNode objectNode = fastDFSUtil.upload(inputStream, fileExtension, "");
        String groupName = objectNode.get("groupName").toString();
        String remoteFileName = objectNode.get("remoteFileName").toString();
        String path = groupName.substring(1,groupName.length()-1) + ":" + remoteFileName.substring(1,remoteFileName.length()-1);
        //保存到resource表中
        fileResource.setStoragePath(path);
        return resourceRepository.save(fileResource).getId();
    }
    public String saveFileResourceReturnUrl(String fileStr, String fileName, FileResource fileResource) throws Exception {
        byte[] bytes = Base64.getDecoder().decode(fileStr);
        InputStream inputStream = new ByteArrayInputStream(bytes);
        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
        ObjectNode objectNode = fastDFSUtil.upload(inputStream, fileExtension, "");
        String groupName = objectNode.get("groupName").toString();
        String remoteFileName = objectNode.get("remoteFileName").toString();
        String path = groupName.substring(1,groupName.length()-1) + ":" + remoteFileName.substring(1,remoteFileName.length()-1);
        //   保存到resource表中
        fileResource.setStoragePath(path);
        resourceRepository.save(fileResource).getId();
        return path ;
    }
    public String saveFileResourceReturnHttpUrl(String fileStr, String fileName, FileResource fileResource) throws Exception {
        byte[] bytes = Base64.getDecoder().decode(fileStr);
        InputStream inputStream = new ByteArrayInputStream(bytes);
        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
        ObjectNode objectNode = fastDFSUtil.upload(inputStream, fileExtension, "");
        String groupName = objectNode.get("groupName").toString();
        String remoteFileName = objectNode.get("remoteFileName").toString();
        String path = groupName.substring(1,groupName.length()-1) + ":" + remoteFileName.substring(1,remoteFileName.length()-1);
        //   保存到resource表中
        fileResource.setStoragePath(path);
        resourceRepository.save(fileResource).getId();
        path = path.replace(":","/");
        return fastDfsPublicServers +"/"+path ;
    }
    public List<FileResource> findByObjectId(String objectId) {
        return resourceRepository.findByObjectId(objectId);
    }
    public List<FileResource> findByObjectIdAndMime(String objectId, String mime) {
        return resourceRepository.findByObjectIdAndMime(objectId, mime);
    }
    public List<FileResource> findByStoragePath(String storagePath) {
        return resourceRepository.findByStoragePath(storagePath);
    }
    public boolean deleteFileResource(List<FileResource> fileResources) throws Exception {
        for(FileResource fileResource : fileResources){
            //删除表数据
            resourceRepository.delete(fileResource.getId());
            //删除fastdfs上的文件
            String storagePath = fileResource.getStoragePath();
            String groupName = storagePath.split(":")[0];
            String remoteFileName = storagePath.split(":")[1];
            fastDFSUtil.delete(groupName,remoteFileName);
        }
        return true;
    }
    public String getStoragePathById(String id) {
        FileResource file= resourceRepository.findById(id);
        String storage_path=file.getStoragePath();
        return storage_path;
    }
}

+ 20 - 0
src/main/java/com.yihu.ehr/basic/fileresource/service/XFileResourceRepository.java

@ -0,0 +1,20 @@
package com.yihu.ehr.basic.fileresource.service;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.12 8:53
 */
public interface XFileResourceRepository extends PagingAndSortingRepository<FileResource, String> {
    List<FileResource> findByObjectId(String objectId);
    List<FileResource> findByStoragePath(String storagePath);
    List<FileResource> findByObjectIdAndMime(String objectId, String mime);
    FileResource findById(String id);
}

+ 80 - 0
src/main/java/com.yihu.ehr/basic/fzopen/controller/OpenEndPoint.java

@ -0,0 +1,80 @@
package com.yihu.ehr.basic.fzopen.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.fzopen.service.OpenService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
 * 转发福州总部内网、开放平台接口
 *
 * @author 张进军
 * @date 2018/4/12 18:42
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0)
@Api(description = "转发福州总部内网、开放平台接口", tags = {"转发福州总部内网、开放平台接口"})
public class OpenEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private OpenService openService;
    @ApiOperation("转发福州总部开放平台接口")
    @RequestMapping(value = ServiceApi.Fz.OpenApi, method = RequestMethod.POST)
    public Envelop fzOpenApi(
            @ApiParam(name = "apiUrl", value = "", required = true)
            @RequestParam(value = "apiUrl") String apiUrl,
            @ApiParam(name = "paramsJson", value = "参数JSON字符串,timestamp 不用传,后台添加", required = true)
            @RequestParam(value = "paramsJson") String paramsJson) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Map<String, Object> params = objectMapper.readValue(paramsJson, Map.class);
            Map<String, Object> result = objectMapper.readValue(openService.callFzOpenApi(apiUrl, params), Map.class);
            envelop.setObj(result);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
    @ApiOperation("转发福州总部内网接口")
    @RequestMapping(value = ServiceApi.Fz.InnerApi, method = RequestMethod.POST)
    public Envelop fzInnerApi(
            @ApiParam(name = "api", value = "API 名称,格式为 a.b.c", required = true)
            @RequestParam(value = "api") String api,
            @ApiParam(name = "paramsJson", value = "参数JSON字符串", required = true)
            @RequestParam(value = "paramsJson") String paramsJson,
            @ApiParam(name = "apiVersion", value = "API 版本号,版本号为整型,从数字 1 开始递增", required = true)
            @RequestParam(value = "apiVersion") int apiVersion) {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        try {
            Map<String, Object> params = objectMapper.readValue(paramsJson, Map.class);
            String result = openService.callFzInnerApi(api, params, apiVersion);
            envelop.setObj(result);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg(e.getMessage());
        }
        return envelop;
    }
}

+ 68 - 0
src/main/java/com.yihu.ehr/basic/fzopen/service/OpenService.java

@ -0,0 +1,68 @@
package com.yihu.ehr.basic.fzopen.service;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.util.fzgateway.FzGatewayUtil;
import com.yihu.ehr.util.fzgateway.open.OPUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
/**
 * 转发福州总部网关接口 Service
 *
 * @author 张进军
 * @date 2018/4/14 17:39
 */
@Service
@Transactional
public class OpenService {
    @Value("${fz-gateway.secret}")
    private String fzSecret;
    @Value("${fz-gateway.clientId}")
    private String fzClientId;
    @Value("${fz-gateway.clientVersion}")
    private String fzClientVersion;
    @Autowired
    private DiscoveryClient discoveryClient;
    /**
     * 转发福州总部开放平台接口
     *
     * @param apiUrl 接口相对地址,不用"/"开头
     * @param params 接口入参,timestamp不用传
     * @return 响应结果
     * @throws Exception
     */
    public String callFzOpenApi(String apiUrl, Map<String, Object> params) throws Exception {
        ServiceInstance agZuulServiceInstance = discoveryClient.getInstances(MicroServices.AgZuul).get(0);
        // URL前缀与 ag-zuul 配置文件中的 zuul.routes.jkzl-server.path 前缀一致。
        String url = agZuulServiceInstance.getUri() + "/jkzl/" + apiUrl;
        String result = OPUtil.callApi(fzClientId, fzSecret, url, params);
        return result;
    }
    /**
     * 转发福州总部内部接口
     *
     * @param api        API 名称,格式为 a.b.c
     * @param apiParams  请求参数
     * @param apiVersion API 版本号,版本号为整型,从数字 1 开始递增
     * @return 响应结果
     * @throws Exception
     */
    public String callFzInnerApi(String api, Map<String, Object> apiParams, int apiVersion) throws Exception {
        ServiceInstance agZuulServiceInstance = discoveryClient.getInstances(MicroServices.AgZuul).get(0);
        // URL前缀与 ag-zuul 配置文件中的 zuul.routes.fz-gateway.path 前缀一致。
        String url = agZuulServiceInstance.getUri() + "/fzGateway/" + "WSGW/rest";
        String result = FzGatewayUtil.httpPost(url, fzClientId, fzClientVersion, api, apiParams, apiVersion);
        return result;
    }
}

+ 25 - 0
src/main/java/com.yihu.ehr/basic/getui/ConstantUtil.java

@ -0,0 +1,25 @@
package com.yihu.ehr.basic.getui;
/**
 * @author litaohong on 2018/4/17
 * @project ehr
 * 常量
 */
public class ConstantUtil {
//    public static String appId = "PHI08rYrmT68BxqQ7sRmw4";
//    public static String appKey = "rOhgfYYl9DAkSl8c35Hfk";
//    public static String masterSecret = "jTnpcu23yCALhmXyy3TtqA";
//个推相关的常量
    public static String appId = "NI9LdPxzjx9zL4nOEd81RA";
    public static String appKey = "LNffJVQfeg5fh99mog5JZA";
    public static String masterSecret = "aG1ostd7xe9qbE4VCfwPXA";
    //卫生人员初始化 用户类型id(编码是可变的)
    public static String DOCTORUSERTYPEID="2";
    public static String PATIENTUSERTYPEID="5";
    /**
     * 默认角色组,在新建应用时需要生成的角色组
     */
    public static String[][] roles={{"AdminManager","行政管理"},{"SuperAdmin","超级管理员"},{"MedicalStaff","医护人员"},{"Operation","运维人员"}};
}

+ 91 - 0
src/main/java/com.yihu.ehr/basic/getui/controller/AppPushMessageEndpoint.java

@ -0,0 +1,91 @@
package com.yihu.ehr.basic.getui.controller;
import com.yihu.ehr.basic.getui.service.AppPushMessageService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @author litaohong on 2018/4/18
 * @project ehr
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0)
@Api(description = "APP消息推送", tags = {"APP消息推送接口"})
public class AppPushMessageEndpoint extends EnvelopRestEndPoint {
    @Autowired
    private AppPushMessageService appPushMessageService;
    @ApiOperation("对单个用户推送消息")
    @RequestMapping(value = ServiceApi.AppPushMessage.single, method = RequestMethod.POST)
    public Envelop pushSingle(
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "title", value = "消息标题", required = true)
            @RequestParam(value = "title") String title,
            @ApiParam(name = "message", value = "消息内容", required = true)
            @RequestParam(value = "message") String message,
            @ApiParam(name = "targetUrl", value = "点击阅读消息后跳转的url", required = true)
            @RequestParam(value = "targetUrl") String targetUrl) {
        String result = appPushMessageService.pushMessageToSingle(userId, title, message, targetUrl);
        return success(result);
    }
    @ApiOperation("对用户组推送消息")
    @RequestMapping(value = ServiceApi.AppPushMessage.list, method = RequestMethod.POST)
    public Envelop pushList(
            @ApiParam(name = "userIds", value = "用户id列表", required = true)
            @RequestParam(value = "userIds") String userIds,
            @ApiParam(name = "title", value = "消息标题", required = true)
            @RequestParam(value = "title") String title,
            @ApiParam(name = "message", value = "消息内容", required = true)
            @RequestParam(value = "message") String message) {
        String result = appPushMessageService.pushMessageToList(userIds, title, message);
        return success(result);
    }
    @ApiOperation("对应用群推送消息")
    @RequestMapping(value = ServiceApi.AppPushMessage.app, method = RequestMethod.POST)
    public Envelop pushAPP(
            @ApiParam(name = "appIdList", value = "应用id列表", required = true)
            @RequestParam(value = "appIdList") List<String> appIdList,
            @ApiParam(name = "phoneList", value = "用户手机列表", required = false)
            @RequestParam(value = "phoneList") List<String> phoneList,
            @ApiParam(name = "cityList", value = "省,市编码列表", required = false)
            @RequestParam(value = "cityList") List<String> cityList,
            @ApiParam(name = "tagList", value = "标签名列表", required = false)
            @RequestParam(value = "tagList") List<String> tagList,
            @ApiParam(name = "title", value = "消息标题", required = true)
            @RequestParam(value = "title") String title,
            @ApiParam(name = "message", value = "消息内容", required = true)
            @RequestParam(value = "message") String message) {
        String result = appPushMessageService.pushMessageToAPP(appIdList, phoneList, cityList,tagList, title,message);
        return success(result);
    }
    @ApiOperation("透传消息")
    @RequestMapping(value = ServiceApi.AppPushMessage.tarns, method = RequestMethod.POST)
    public Envelop pushAPPTransimssion(
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "title", value = "消息标题", required = true)
            @RequestParam(value = "title") String title,
            @ApiParam(name = "message", value = "消息内容", required = true)
            @RequestParam(value = "message") String message) {
        String result = appPushMessageService.pushMessageTransimssion(userId, title, message);
        return success(result);
    }
}

+ 63 - 0
src/main/java/com.yihu.ehr/basic/getui/controller/GeTuiClientEndpoint.java

@ -0,0 +1,63 @@
package com.yihu.ehr.basic.getui.controller;
import com.yihu.ehr.basic.getui.service.GeTuiClientService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
 * @author litaohong on 2018/4/20
 * @project ehr
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0)
@Api(description = "APP消息推送用户和客户端映射关系控制器", tags = {"APP消息推送用户和客户端映射关系控制器"})
public class GeTuiClientEndpoint extends EnvelopRestEndPoint {
    @Autowired
    private GeTuiClientService geTuiClientService;
    @ApiOperation("根据userId获取clientId")
    @RequestMapping(value = ServiceApi.AppPushMessage.findClientId, method = RequestMethod.POST)
    public Envelop getClientIdByUserId(
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId) {
        String result = geTuiClientService.getClientIdByUserId(userId);
        return success(result);
    }
    @ApiOperation("根据userId获取clientId列表")
    @RequestMapping(value = ServiceApi.AppPushMessage.findClientIdList, method = RequestMethod.POST)
    public Envelop getListClientIdByUserId(
            @ApiParam(name = "userIds", value = "用户id", required = true)
            @RequestParam(value = "userIds") String userIds) {
        List<String> result = geTuiClientService.getListClientIdByUserId(userIds);
        return success(result);
    }
    @ApiOperation("根据userId更新clientId")
    @RequestMapping(value = ServiceApi.AppPushMessage.updateClientId, method = RequestMethod.POST)
    public Envelop updateClientIdByUserId(
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "clientId", value = "clientId", required = true)
            @RequestParam(value = "clientId") String clientId
    ) {
        String result = geTuiClientService.updateClientIdByUserId(userId,clientId);
        return success(result);
    }
}

+ 40 - 0
src/main/java/com.yihu.ehr/basic/getui/dao/GeTuiClientRepository.java

@ -0,0 +1,40 @@
package com.yihu.ehr.basic.getui.dao;
import com.yihu.ehr.basic.getui.model.GeTuiUserClient;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
 * @author litaohong on 2018/4/20
 * @project ehr
 */
public interface GeTuiClientRepository extends PagingAndSortingRepository<GeTuiUserClient, Long> {
    /**
     * 根据用户id获取对应的clientId
     * @param userId
     * @return
     */
    @Query("From GeTuiUserClient where userId = ?1")
    public GeTuiUserClient getUserGeTuiClientByUserId(String userId);
    /**
     * 根据用户id修改clientId
     * @param userId
     * @param clientId
     * @return
     */
    @Modifying
    @Query("update GeTuiUserClient set clientId = ?2  where userId = ?1")
    public void updateClientIdByUserId(String userId, String clientId);
    @Query("select geTuiUserClient from GeTuiUserClient geTuiUserClient where geTuiUserClient.userId in (:userIds) " )
    List<GeTuiUserClient> getListByuserId(@Param("userIds") List<String> userIds);
}

+ 48 - 0
src/main/java/com.yihu.ehr/basic/getui/model/GeTuiUserClient.java

@ -0,0 +1,48 @@
package com.yihu.ehr.basic.getui.model;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
/**
 * @author litaohong on 2018/4/20
 * @project ehr
 * 个推--用户id与客户端clientId的映射关系
 */
@Entity
@Table(name = "getui_user_client", schema = "", catalog = "healtharchive")
public class GeTuiUserClient {
    private Long id;
    private String userId;
    private String clientId;
    @Id
    @GeneratedValue(generator = "Generator")
    @GenericGenerator(name = "Generator", strategy = "identity")
    @Column(name = "id", nullable = false, insertable = true, updatable = true)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @Column(name = "user_id", nullable = false, insertable = true, updatable = true)
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    @Column(name = "client_id", nullable = false, insertable = true, updatable = true)
    public String getClientId() {
        return clientId;
    }
    public void setClientId(String clientId) {
        this.clientId = clientId;
    }
}

+ 367 - 0
src/main/java/com.yihu.ehr/basic/getui/region_code.data

@ -0,0 +1,367 @@
11000000|北京市
12000000|天津市
13000000|河北
13010000|石家庄市
13020000|唐山市
13030000|秦皇岛市
13040000|邯郸市
13050000|邢台市
13060000|保定市
13070000|张家口市
13080000|承德市
13090000|沧州市
13100000|廊坊市
13110000|衡水市
14000000|山西
14010000|太原市
14020000|大同市
14030000|阳泉市
14040000|长治市
14050000|晋城市
14060000|朔州市
14070000|晋中市
14080000|运城市
14090000|忻州市
14100000|临汾市
14110000|吕梁市
15000000|内蒙古
15010000|呼和浩特市
15020000|包头市
15030000|乌海市
15040000|赤峰市
15050000|通辽市
15060000|鄂尔多斯市
15070000|呼伦贝尔市
15080000|巴彦淖尔市
15090000|乌兰察布市
15220000|兴安盟
15250000|锡林郭勒盟
15290000|阿拉善盟
21000000|辽宁
21010000|沈阳市
21020000|大连市
21030000|鞍山市
21040000|抚顺市
21050000|本溪市
21060000|丹东市
21070000|锦州市
21080000|营口市
21090000|阜新市
21100000|辽阳市
21110000|盘锦市
21120000|铁岭市
21130000|朝阳市
21140000|葫芦岛市
22000000|吉林
22010000|长春市
22020000|吉林市
22030000|四平市
22040000|辽源市
22050000|通化市
22060000|白山市
22070000|松原市
22080000|白城市
22240000|延边州
23000000|黑龙江
23010000|哈尔滨市
23020000|齐齐哈尔市
23030000|鸡西市
23040000|鹤岗市
23050000|双鸭山市
23060000|大庆市
23070000|伊春市
23080000|佳木斯市
23090000|七台河市
23100000|牡丹江市
23110000|黑河市
23120000|绥化市
23270000|大兴安岭地区
31000000|上海市
32000000|江苏
32010000|南京市
32020000|无锡市
32030000|徐州市
32040000|常州市
32050000|苏州市
32060000|南通市
32070000|连云港市
32080000|淮安市
32090000|盐城市
32100000|扬州市
32110000|镇江市
32120000|泰州市
32130000|宿迁市
33000000|浙江
33010000|杭州市
33020000|宁波市
33030000|温州市
33040000|嘉兴市
33050000|湖州市
33060000|绍兴市
33070000|金华市
33080000|衢州市
33090000|舟山市
33100000|台州市
33110000|丽水市
34000000|安徽
34010000|合肥市
34020000|芜湖市
34030000|蚌埠市
34040000|淮南市
34050000|马鞍山市
34060000|淮北市
34070000|铜陵市
34080000|安庆市
34100000|黄山市
34110000|滁州市
34120000|阜阳市
34130000|宿州市
34140000|巢湖市
34150000|六安市
34160000|亳州市
34170000|池州市
34180000|宣城市
35000000|福建
35010000|福州市
35020000|厦门市
35030000|莆田市
35040000|三明市
35050000|泉州市
35060000|漳州市
35070000|南平市
35080000|龙岩市
35090000|宁德市
36000000|江西
36010000|南昌市
36020000|景德镇市
36030000|萍乡市
36040000|九江市
36050000|新余市
36060000|鹰潭市
36070000|赣州市
36080000|吉安市
36090000|宜春市
36100000|抚州市
36110000|上饶市
37000000|山东
37010000|济南市
37020000|青岛市
37030000|淄博市
37040000|枣庄市
37050000|东营市
37060000|烟台市
37070000|潍坊市
37080000|济宁市
37090000|泰安市
37100000|威海市
37110000|日照市
37120000|莱芜市
37130000|临沂市
37140000|德州市
37150000|聊城市
37160000|滨州市
37170000|菏泽市
41000000|河南
41010000|郑州市
41020000|开封市
41030000|洛阳市
41040000|平顶山市
41050000|安阳市
41060000|鹤壁市
41070000|新乡市
41080000|焦作市
41090000|濮阳市
41100000|许昌市
41110000|漯河市
41120000|三门峡市
41130000|南阳市
41140000|商丘市
41150000|信阳市
41160000|周口市
41170000|驻马店市
42000000|湖北
42010000|武汉市
42020000|黄石市
42030000|十堰市
42050000|宜昌市
42060000|襄樊市
42070000|鄂州市
42080000|荆门市
42090000|孝感市
42100000|荆州市
42110000|黄冈市
42120000|咸宁市
42130000|随州市
42280000|恩施州
43000000|湖南
43010000|长沙市
43020000|株洲市
43030000|湘潭市
43040000|衡阳市
43050000|邵阳市
43060000|岳阳市
43070000|常德市
43080000|张家界市
43090000|益阳市
43100000|郴州市
43110000|永州市
43120000|怀化市
43130000|娄底市
43310000|湘西州
44000000|广东
44010000|广州市
44020000|韶关市
44030000|深圳市
44040000|珠海市
44050000|汕头市
44060000|佛山市
44070000|江门市
44080000|湛江市
44090000|茂名市
44120000|肇庆市
44130000|惠州市
44140000|梅州市
44150000|汕尾市
44160000|河源市
44170000|阳江市
44180000|清远市
44190000|东莞市
44200000|中山市
44510000|潮州市
44520000|揭阳市
44530000|云浮市
45000000|广西
45010000|南宁市
45020000|柳州市
45030000|桂林市
45040000|梧州市
45050000|北海市
45060000|防城港市
45070000|钦州市
45080000|贵港市
45090000|玉林市
45100000|百色市
45110000|贺州市
45120000|河池市
45130000|来宾市
45140000|崇左市
46000000|海南
46010000|海口市
46020000|三亚市
50000000|重庆市
51000000|四川
51010000|成都市
51030000|自贡市
51040000|攀枝花市
51050000|泸州市
51060000|德阳市
51070000|绵阳市
51080000|广元市
51090000|遂宁市
51100000|内江市
51110000|乐山市
51130000|南充市
51140000|眉山市
51150000|宜宾市
51160000|广安市
51170000|达州市
51180000|雅安市
51190000|巴中市
51200000|资阳市
51320000|阿坝州
51330000|甘孜州
51340000|凉山州
52000000|贵州
52010000|贵阳市
52020000|六盘水市
52030000|遵义市
52040000|安顺市
52220000|铜仁地区
52230000|黔西南州
52240000|毕节市
52260000|黔东南州
52270000|黔南州
53000000|云南
53010000|昆明市
53030000|曲靖市
53040000|玉溪市
53050000|保山市
53060000|昭通市
53070000|丽江市
53080000|普洱市
53090000|临沧市
53230000|楚雄州
53250000|红河州
53260000|文山州
53280000|西双版纳州
53290000|大理州
53310000|德宏州
53330000|怒江州
53340000|迪庆州
54000000|西藏
54010000|拉萨市
54210000|昌都地区
54220000|山南地区
54230000|日喀则地区
54240000|那曲地区
54250000|阿里地区
54260000|林芝地区
61000000|陕西
61010000|西安市
61020000|铜川市
61030000|宝鸡市
61040000|咸阳市
61050000|渭南市
61060000|延安市
61070000|汉中市
61080000|榆林市
61090000|安康市
61100000|商洛市
62000000|甘肃
62010000|兰州市
62020000|嘉峪关市
62030000|金昌市
62040000|白银市
62050000|天水市
62060000|武威市
62070000|张掖市
62080000|平凉市
62090000|酒泉市
62100000|庆阳市
62110000|定西市
62120000|陇南市
62290000|临夏州
62300000|甘南州
63000000|青海
63010000|西宁市
63210000|海东地区
63220000|海北州
63230000|黄南州
63250000|海南州
63260000|果洛州
63270000|玉树州
63280000|海西州
64000000|宁夏
64010000|银川市
64020000|石嘴山市
64030000|吴忠市
64040000|固原市
64050000|中卫市
65000000|新疆
65010000|乌鲁木齐市
65020000|克拉玛依市
65210000|吐鲁番地区
65220000|哈密地区
65230000|昌吉回族自治州
65270000|博尔塔拉蒙古自治州
65280000|巴音郭楞蒙古自治州
65290000|阿克苏地区
65300000|克孜勒苏柯尔克孜自治州
65310000|喀什地区
65320000|和田地区
65400000|伊犁哈萨克自治州
65420000|塔城地区
65430000|阿勒泰地区
71000000|台湾
81000000|香港
82000000|澳门

Разлика између датотеке није приказан због своје велике величине
+ 308 - 0
src/main/java/com.yihu.ehr/basic/getui/service/AppPushMessageService.java


+ 93 - 0
src/main/java/com.yihu.ehr/basic/getui/service/GeTuiClientService.java

@ -0,0 +1,93 @@
package com.yihu.ehr.basic.getui.service;
import com.yihu.ehr.basic.apps.dao.UserAppDao;
import com.yihu.ehr.basic.apps.model.UserApp;
import com.yihu.ehr.basic.getui.dao.GeTuiClientRepository;
import com.yihu.ehr.basic.getui.model.GeTuiUserClient;
import com.yihu.ehr.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
 * @author litaohong on 2018/4/20
 * @project ehr
 */
@Service
@Transactional
public class GeTuiClientService extends BaseJpaService<UserApp, UserAppDao> {
    @Autowired
    private GeTuiClientRepository geTuiClientRepository;
    /**
     * 根据用户id获取对应的clientId
     * @param userId
     * @return
     */
    public String getClientIdByUserId(String userId){
        if(StringUtils.isEmpty(userId)){
            return "";
        }
        GeTuiUserClient geTuiUserClient = this.geTuiClientRepository.getUserGeTuiClientByUserId(userId);
        return null == geTuiUserClient ? "" : geTuiUserClient.getClientId();
    }
    /**
     * 根据用户id获取对应的clientId列表
     * @param userIds
     * @return
     */
    public List<String> getListClientIdByUserId(String userIds){
        if(StringUtils.isEmpty(userIds)){
            return null;
        }
        if(userIds.indexOf(",") == 0){
            return null;
        }
        String[] arr = userIds.split(",");
        if(arr.length == 0){
            return null;
        }
        List<String> list = new ArrayList<>();
        for(String str: arr){
            list.add(str);
        }
        List<GeTuiUserClient> geTuiUserClientList = this.geTuiClientRepository.getListByuserId(list);
        List<String> result = new ArrayList<>();
        geTuiUserClientList.forEach(
                one ->{
                    result.add(one.getClientId());
                }
        );
        return result;
    }
    /**
     * 根据用户id更新对应的clientId
     * @param userId
     * @return
     */
    public String updateClientIdByUserId(String userId, String clientId) {
        if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(clientId) ){
            return "params userId|clientId is empty";
        }
        GeTuiUserClient geTuiUserClient = this.geTuiClientRepository.getUserGeTuiClientByUserId(userId);
        if (null == geTuiUserClient) {
            geTuiUserClient = new GeTuiUserClient();
            geTuiUserClient.setUserId(userId);
            geTuiUserClient.setClientId(clientId);
            this.geTuiClientRepository.save(geTuiUserClient);
            return "success";
        }
        this.geTuiClientRepository.updateClientIdByUserId(userId, clientId);
        return "success";
    }
}

+ 53 - 0
src/main/java/com.yihu.ehr/basic/government/controller/GovernmentBrowseLogEndPoint.java

@ -0,0 +1,53 @@
package com.yihu.ehr.basic.government.controller;
import com.yihu.ehr.basic.government.service.GovernmentBrowseLogService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.government.GovernmentBrowseLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
 * Created by wxw on 2017/11/3.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "government_browse_log", description = "政府服务平台浏览记录", tags = {"政府服务平台"})
public class GovernmentBrowseLogEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private GovernmentBrowseLogService governmentBrowseLogService;
    @RequestMapping(value = ServiceApi.Government.AddGovernmentBrowseLog, method = RequestMethod.POST)
    @ApiOperation(value = "新增浏览记录")
    public GovernmentBrowseLog create(
            @ApiParam(name = "jsonData", value = " 记录信息Json", defaultValue = "")
            @RequestBody String jsonData) throws Exception {
        GovernmentBrowseLog governmentBrowseLog = toEntity(jsonData, GovernmentBrowseLog.class);
        governmentBrowseLog.setCreateTime(new Date());
        governmentBrowseLog = governmentBrowseLogService.saveGovernmentBrowseLog(governmentBrowseLog);
        return governmentBrowseLog;
    }
    @RequestMapping(value = ServiceApi.Government.searchGovernmentBrowseLog, method = RequestMethod.GET)
    @ApiOperation(value = "浏览记录")
    public List<GovernmentBrowseLog> getBrowseName(
            @ApiParam(name = "userId", value = " 用户Id", defaultValue = "")
            @RequestParam(value = "userId", required = false) String userId) {
        List<GovernmentBrowseLog> browseName = governmentBrowseLogService.getBrowseName(userId);
        return browseName;
    }
    @RequestMapping(value = ServiceApi.Government.searchHotBrowseLog, method = RequestMethod.GET)
    @ApiOperation(value = "热门监测报表")
    public List<GovernmentBrowseLog> getHotBrowseLog() {
        return governmentBrowseLogService.getHotBrowseLog();
    }
}

+ 110 - 0
src/main/java/com.yihu.ehr/basic/government/controller/GovernmentMenuEndPoint.java

@ -0,0 +1,110 @@
package com.yihu.ehr.basic.government.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.basic.government.service.GovernmentMenuService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.government.GovernmentMenu;
import com.yihu.ehr.model.common.ListResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
/**
 * Created by wxw on 2017/11/2.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "government_menu", description = "政府服务平台菜单", tags = {"政府服务平台-菜单"})
public class GovernmentMenuEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private GovernmentMenuService governmentMenuService;
    @RequestMapping(value = ServiceApi.Government.SearchGovernmentMenu, method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询政府服务平台菜单")
    public ListResult getGovernmentMenuList(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page) throws Exception {
        ListResult listResult = new ListResult();
        List<GovernmentMenu> governmentMenuList = governmentMenuService.search(fields, filters, sorts, page, size);
        if (governmentMenuList != null) {
            listResult.setDetailModelList(governmentMenuList);
            listResult.setTotalCount((int)governmentMenuService.getCount(filters));
            listResult.setCode(200);
            listResult.setCurrPage(page);
            listResult.setPageSize(size);
        } else {
            listResult.setCode(200);
            listResult.setMessage("查询无数据");
            listResult.setTotalCount(0);
        }
        return listResult;
    }
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuById , method = RequestMethod.GET)
    @ApiOperation(value = "根据Id查询详情")
    public GovernmentMenu detail(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") Integer id) {
        GovernmentMenu governmentMenu = governmentMenuService.getById(id);
        return governmentMenu;
    }
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuCheckCode, method = RequestMethod.GET)
    @ApiOperation(value = "检查编码是否唯一")
    public int checkCode(
            @ApiParam(name = "code", value = "编码")
            @RequestParam(value = "code") String code) throws Exception {
        int i = governmentMenuService.checkCode(code);
        return i;
    }
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuCheckName, method = RequestMethod.GET)
    @ApiOperation(value = "检查名称是否唯一")
    public int checkName(
            @ApiParam(name = "name", value = "名称")
            @RequestParam(value = "name") String name) throws Exception {
        int result = governmentMenuService.checkName(name);
        return result;
    }
    @RequestMapping(value = ServiceApi.Government.AddGovernmentMenu, method = RequestMethod.POST)
    @ApiOperation(value = "新增菜单")
    public GovernmentMenu create(
            @ApiParam(name = "jsonData", value = " 菜单信息Json", defaultValue = "")
            @RequestBody String jsonData,
            @ApiParam(name = "ids", value = "资源报表监测类型ids", defaultValue = "")
            @RequestParam(value = "ids", required = false) String ids) throws IOException {
        GovernmentMenu governmentMenu = toEntity(jsonData, GovernmentMenu.class);
        governmentMenu = governmentMenuService.saveGovernmentMenu(governmentMenu, ids);
        return governmentMenu;
    }
    @RequestMapping(value = ServiceApi.Government.UpdateGovernmentMenu, method = RequestMethod.POST)
    @ApiOperation(value = "修改菜单")
    public GovernmentMenu resetInfo(
            @ApiParam(name = "jsonData", value = " 菜单信息Json", defaultValue = "")
            @RequestBody String jsonData,
            @ApiParam(name = "ids", value = "资源报表监测类型ids", defaultValue = "")
            @RequestParam(value = "ids", required = false) String ids) throws IOException {
        GovernmentMenu governmentMenu = toEntity(jsonData, GovernmentMenu.class);
        governmentMenu = governmentMenuService.updateGovernmentMenu(governmentMenu, ids);
        return governmentMenu;
    }
}

+ 55 - 0
src/main/java/com.yihu.ehr/basic/government/controller/GovernmentMenuReportMonitorTypeEndPoint.java

@ -0,0 +1,55 @@
package com.yihu.ehr.basic.government.controller;
import com.yihu.ehr.basic.government.service.GovernmentMenuReportMonitorTypeService;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.entity.government.GovernmentMenuReportMonitorType;
import com.yihu.ehr.model.resource.MRsReportMonitorType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by jansny 2017年11月7日15:17:24
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0)
@Api(value = "GovernmentMenuReportMonitorType", description = "政府平台菜单资源报表监测监测分类服务接口", tags = {"政府服务平台"})
public class GovernmentMenuReportMonitorTypeEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private GovernmentMenuReportMonitorTypeService governmentMenuReportMonitorTypeService;
    @ApiOperation("新增政府平台菜单资源报表监测分类")
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuReportMonitorTypeSave, method = RequestMethod.POST)
    public MRsReportMonitorType add(
            @ApiParam(name = "rsReportMonitorType", value = "资源报表监测分类JSON", required = true)
            @RequestBody String rsReportMonitorType) throws Exception {
        GovernmentMenuReportMonitorType newGovernmentMenuMonitorType = toEntity(rsReportMonitorType, GovernmentMenuReportMonitorType.class);
        newGovernmentMenuMonitorType = governmentMenuReportMonitorTypeService.save(newGovernmentMenuMonitorType);
        return convertToModel(newGovernmentMenuMonitorType, MRsReportMonitorType.class);
    }
    @ApiOperation("删除政府平台菜单资源报表监测分类")
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuReportMonitorTypeDelete, method = RequestMethod.DELETE)
    public void delete(
            @ApiParam(name = "id", value = "资源报表监测分类ID", required = true)
            @RequestParam(value = "id") Integer id) throws Exception {
        governmentMenuReportMonitorTypeService.delete(id);
    }
    @ApiOperation("获取政府菜单资源报表监测类型Id")
    @RequestMapping(value = ServiceApi.Government.MonitorTypeList, method = RequestMethod.GET)
    public List<Integer> getMonitorTypeIdByGovernmentMenuId(
            @ApiParam(name = "menuId", value = "菜单ID", required = true)
            @RequestParam(value = "menuId") String menuId) {
        return governmentMenuReportMonitorTypeService.getMonitorTypeIdByGovernmentMenuId(menuId);
    }
}

+ 0 - 0
src/main/java/com.yihu.ehr/basic/government/dao/GovernmentBrowseLogRepository.java


Неке датотеке нису приказане због велике количине промена