Browse Source

first commit

wangweiqun 6 years ago
commit
d2de1d9639
100 changed files with 16178 additions and 0 deletions
  1. 1159 0
      ehr-cloud/pom.xml
  2. 606 0
      ehr-ms-parent-pom/pom.xml
  3. 130 0
      pom.xml
  4. 44 0
      src/main/java/com/yihu/ehr/AgAdminApplication.java
  5. 282 0
      src/main/java/com/yihu/ehr/adapter/controller/AdapterDataSetController.java
  6. 296 0
      src/main/java/com/yihu/ehr/adapter/controller/AdapterDictController.java
  7. 242 0
      src/main/java/com/yihu/ehr/adapter/controller/AdapterOrgController.java
  8. 272 0
      src/main/java/com/yihu/ehr/adapter/controller/OrgAdapterPlanController.java
  9. 204 0
      src/main/java/com/yihu/ehr/adapter/controller/OrgDataSetController.java
  10. 187 0
      src/main/java/com/yihu/ehr/adapter/controller/OrgDictController.java
  11. 196 0
      src/main/java/com/yihu/ehr/adapter/controller/OrgDictEntryController.java
  12. 200 0
      src/main/java/com/yihu/ehr/adapter/controller/OrgMetaDataController.java
  13. 116 0
      src/main/java/com/yihu/ehr/adapter/service/AdapterDataSetClient.java
  14. 99 0
      src/main/java/com/yihu/ehr/adapter/service/AdapterDictClient.java
  15. 80 0
      src/main/java/com/yihu/ehr/adapter/service/AdapterOrgClient.java
  16. 77 0
      src/main/java/com/yihu/ehr/adapter/service/OrgDataSetClient.java
  17. 80 0
      src/main/java/com/yihu/ehr/adapter/service/OrgDictClient.java
  18. 90 0
      src/main/java/com/yihu/ehr/adapter/service/OrgDictEntryClient.java
  19. 82 0
      src/main/java/com/yihu/ehr/adapter/service/OrgMetaDataClient.java
  20. 110 0
      src/main/java/com/yihu/ehr/adapter/service/PlanClient.java
  21. 110 0
      src/main/java/com/yihu/ehr/adapter/utils/ExtendController.java
  22. 346 0
      src/main/java/com/yihu/ehr/apps/controller/AppApiController.java
  23. 156 0
      src/main/java/com/yihu/ehr/apps/controller/AppApiParameterController.java
  24. 133 0
      src/main/java/com/yihu/ehr/apps/controller/AppApiResponseController.java
  25. 471 0
      src/main/java/com/yihu/ehr/apps/controller/AppController.java
  26. 285 0
      src/main/java/com/yihu/ehr/apps/controller/AppFeatureController.java
  27. 86 0
      src/main/java/com/yihu/ehr/apps/service/AppApiClient.java
  28. 59 0
      src/main/java/com/yihu/ehr/apps/service/AppApiParameterClient.java
  29. 59 0
      src/main/java/com/yihu/ehr/apps/service/AppApiResponseClient.java
  30. 126 0
      src/main/java/com/yihu/ehr/apps/service/AppClient.java
  31. 89 0
      src/main/java/com/yihu/ehr/apps/service/AppFeatureClient.java
  32. 29 0
      src/main/java/com/yihu/ehr/config/FeignMultipartSupportConfig.java
  33. 27 0
      src/main/java/com/yihu/ehr/config/TenantConfiguration.java
  34. 70 0
      src/main/java/com/yihu/ehr/device/client/DeviceClient.java
  35. 86 0
      src/main/java/com/yihu/ehr/device/controller/DeviceController.java
  36. 75 0
      src/main/java/com/yihu/ehr/dfs/client/ElasticSearchClient.java
  37. 98 0
      src/main/java/com/yihu/ehr/dfs/client/FastDFSClient.java
  38. 136 0
      src/main/java/com/yihu/ehr/dfs/controller/ElasticSearchController.java
  39. 225 0
      src/main/java/com/yihu/ehr/dfs/controller/FastDFSController.java
  40. 82 0
      src/main/java/com/yihu/ehr/emergency/client/AmbulanceClient.java
  41. 79 0
      src/main/java/com/yihu/ehr/emergency/client/AttendanceClient.java
  42. 54 0
      src/main/java/com/yihu/ehr/emergency/client/LocationClient.java
  43. 67 0
      src/main/java/com/yihu/ehr/emergency/client/ScheduleClient.java
  44. 131 0
      src/main/java/com/yihu/ehr/emergency/controller/AmbulanceController.java
  45. 108 0
      src/main/java/com/yihu/ehr/emergency/controller/AttendanceController.java
  46. 68 0
      src/main/java/com/yihu/ehr/emergency/controller/LocationController.java
  47. 100 0
      src/main/java/com/yihu/ehr/emergency/controller/ScheduleController.java
  48. 47 0
      src/main/java/com/yihu/ehr/esb/client/HosAcqTaskClient.java
  49. 31 0
      src/main/java/com/yihu/ehr/esb/client/HosEsbMiniInstallLogClient.java
  50. 42 0
      src/main/java/com/yihu/ehr/esb/client/HosLogClient.java
  51. 49 0
      src/main/java/com/yihu/ehr/esb/client/HosReleaseClient.java
  52. 49 0
      src/main/java/com/yihu/ehr/esb/client/HosSqlTaskClient.java
  53. 150 0
      src/main/java/com/yihu/ehr/esb/controller/HosAcqTaskController.java
  54. 73 0
      src/main/java/com/yihu/ehr/esb/controller/HosEsbMiniInstallLogController.java
  55. 93 0
      src/main/java/com/yihu/ehr/esb/controller/HosLogController.java
  56. 130 0
      src/main/java/com/yihu/ehr/esb/controller/HosReleaseController.java
  57. 137 0
      src/main/java/com/yihu/ehr/esb/controller/HosSqlTaskController.java
  58. 133 0
      src/main/java/com/yihu/ehr/fileresource/controller/FileResourceController.java
  59. 78 0
      src/main/java/com/yihu/ehr/fileresource/service/FileResourceClient.java
  60. 35 0
      src/main/java/com/yihu/ehr/filter/TenantFilter.java
  61. 34 0
      src/main/java/com/yihu/ehr/filter/WritableHttpServletRequest.java
  62. 271 0
      src/main/java/com/yihu/ehr/geography/controller/AddressController.java
  63. 126 0
      src/main/java/com/yihu/ehr/geography/service/AddressClient.java
  64. 53 0
      src/main/java/com/yihu/ehr/government/controller/GovernmentBrowseLogController.java
  65. 272 0
      src/main/java/com/yihu/ehr/government/controller/GovernmentMenuController.java
  66. 61 0
      src/main/java/com/yihu/ehr/government/controller/GovernmentMenuReportMonitorTypeController.java
  67. 61 0
      src/main/java/com/yihu/ehr/government/controller/OutpatientsBoardController.java
  68. 37 0
      src/main/java/com/yihu/ehr/government/service/GovernmentBrowseLogClient.java
  69. 52 0
      src/main/java/com/yihu/ehr/government/service/GovernmentMenuClient.java
  70. 49 0
      src/main/java/com/yihu/ehr/government/service/GovernmentMenuReportMonitorTypeClient.java
  71. 44 0
      src/main/java/com/yihu/ehr/government/service/OutpatientsBoardClient.java
  72. 171 0
      src/main/java/com/yihu/ehr/log/controller/LogController.java
  73. 97 0
      src/main/java/com/yihu/ehr/log/service/LogClient.java
  74. 192 0
      src/main/java/com/yihu/ehr/msg/controller/TelVerificationController.java
  75. 42 0
      src/main/java/com/yihu/ehr/msg/service/TelVerificationClient.java
  76. 749 0
      src/main/java/com/yihu/ehr/organization/controller/OrgDeptController.java
  77. 89 0
      src/main/java/com/yihu/ehr/organization/controller/OrgDeptImportController.java
  78. 94 0
      src/main/java/com/yihu/ehr/organization/controller/OrgHealthCategoryController.java
  79. 231 0
      src/main/java/com/yihu/ehr/organization/controller/OrgSaasController.java
  80. 840 0
      src/main/java/com/yihu/ehr/organization/controller/OrganizationController.java
  81. 70 0
      src/main/java/com/yihu/ehr/organization/model/DeptModel.java
  82. 50 0
      src/main/java/com/yihu/ehr/organization/model/OrgDeptListModel.java
  83. 43 0
      src/main/java/com/yihu/ehr/organization/model/OrgDeptModel.java
  84. 173 0
      src/main/java/com/yihu/ehr/organization/model/OrgModel.java
  85. 141 0
      src/main/java/com/yihu/ehr/organization/service/OrgDeptClient.java
  86. 45 0
      src/main/java/com/yihu/ehr/organization/service/OrgDeptImportClient.java
  87. 124 0
      src/main/java/com/yihu/ehr/organization/service/OrgDeptMemberClient.java
  88. 74 0
      src/main/java/com/yihu/ehr/organization/service/OrgHealthCategoryClient.java
  89. 64 0
      src/main/java/com/yihu/ehr/organization/service/OrgSaasClient.java
  90. 231 0
      src/main/java/com/yihu/ehr/organization/service/OrganizationClient.java
  91. 171 0
      src/main/java/com/yihu/ehr/patient/controller/AuthenticationController.java
  92. 226 0
      src/main/java/com/yihu/ehr/patient/controller/CardController.java
  93. 193 0
      src/main/java/com/yihu/ehr/patient/controller/HomeRelationshipController.java
  94. 317 0
      src/main/java/com/yihu/ehr/patient/controller/PatientArchiveController.java
  95. 458 0
      src/main/java/com/yihu/ehr/patient/controller/PatientCardsController.java
  96. 1035 0
      src/main/java/com/yihu/ehr/patient/controller/PatientController.java
  97. 62 0
      src/main/java/com/yihu/ehr/patient/service/AuthenticationClient.java
  98. 118 0
      src/main/java/com/yihu/ehr/patient/service/CardClient.java
  99. 64 0
      src/main/java/com/yihu/ehr/patient/service/FamiliesClient.java
  100. 0 0
      src/main/java/com/yihu/ehr/patient/service/MembersClient.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>

+ 130 - 0
pom.xml

@ -0,0 +1,130 @@
<?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>ag-admin</artifactId>
    <!--<packaging>${packaging.type}</packaging>-->
    <packaging>war</packaging>
    <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-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.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
            <scope>${dependency.scope}</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--<dependency>-->
        <!--<groupId>com.yihu.ehr</groupId>-->
        <!--<artifactId>commons-thrift-client</artifactId>-->
        <!--<version>1.1.0</version>-->
        <!--</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-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-admin-gateway-model</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.github.openfeign.form</groupId>
            <artifactId>feign-form-spring</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.hos</groupId>
            <artifactId>common-rest-model</artifactId>
        </dependency>
    </dependencies>
</project>

+ 44 - 0
src/main/java/com/yihu/ehr/AgAdminApplication.java

@ -0,0 +1,44 @@
package com.yihu.ehr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
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.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/**
 * Created by AndyCai on 2016/1/19.
 */
@Configuration
@EnableAutoConfiguration(exclude = {
        SecurityAutoConfiguration.class,
        ManagementWebSecurityAutoConfiguration.class,
        DataSourceAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class})
@ComponentScan
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
@EnableZuulProxy
public class AgAdminApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        SpringApplication.run(AgAdminApplication.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AgAdminApplication.class);
    }
}

+ 282 - 0
src/main/java/com/yihu/ehr/adapter/controller/AdapterDataSetController.java

@ -0,0 +1,282 @@
package com.yihu.ehr.adapter.controller;
import com.yihu.ehr.adapter.service.AdapterDataSetClient;
import com.yihu.ehr.adapter.service.OrgMetaDataClient;
import com.yihu.ehr.adapter.service.PlanClient;
import com.yihu.ehr.agModel.adapter.AdapterDataSetDetailModel;
import com.yihu.ehr.agModel.adapter.AdapterDataSetModel;
import com.yihu.ehr.agModel.adapter.AdapterRelationshipModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.adapter.service.OrgDataSetClient;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.std.service.DataSetClient;
import com.yihu.ehr.model.adaption.*;
import com.yihu.hos.model.standard.MStdDataSet;
import com.yihu.hos.model.standard.MStdMetaData;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.util.validate.ValidateResult;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * @author lincl
 * @version 1.0
 * @created 2016.3.1
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter")
@RestController
@Api(protocols = "https", value = "adapter", description = "数据集适配", tags = {"适配管理-数据集适配"})
public class AdapterDataSetController extends ExtendController<AdapterDataSetModel> {
    @Autowired
    AdapterDataSetClient adapterDataSetClient;
    @Autowired
    DataSetClient dataSetClient;
    @Autowired
    OrgDataSetClient orgDataSetClient;
    @Autowired
    OrgMetaDataClient orgMetaDataClient;
    @Autowired
    PlanClient planClient;
    @RequestMapping(value = "/metadata/{id}", method = RequestMethod.GET)
    public Envelop getAdapterMetaDataById(
            @ApiParam(name = "id", value = "适配关系ID")
            @PathVariable(value = "id") Long id) {
        try {
            MAdapterDataSet dataSet = adapterDataSetClient.getAdapterMetaData(id);
            if (dataSet == null) {
                return failed("数据获取失败!");
            }
            return success(convertAdapterDataSetModel(dataSet));
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem() ;
        }
    }
    @RequestMapping(value = "/plan/data_set/{plan_id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据方案ID及查询条件查询数据集适配关系")
    public Envelop searchAdapterDataSet(
            @ApiParam(name = "plan_id", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "plan_id") long planId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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 {
        ResponseEntity<Collection<MAdapterRelationship>> responseEntity = adapterDataSetClient.searchAdapterDataSet(planId, code, name, sorts, size, page);
        List<MAdapterRelationship> mAdapterRelationships = (List<MAdapterRelationship>) responseEntity.getBody();
        List<AdapterRelationshipModel> adapterRelationshipModels = (List<AdapterRelationshipModel>) convertToModels(
                mAdapterRelationships,
                new ArrayList<AdapterRelationshipModel>(mAdapterRelationships.size()),
                AdapterRelationshipModel.class, null);
        return getResult(adapterRelationshipModels, getTotalCount(responseEntity), page, size);
    }
    @RequestMapping(value = "/plan/meta_data/{plan_id}/{set_id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据dataSetId搜索数据元适配关系")
    public Envelop searchAdapterMetaData(
            @ApiParam(name = "plan_id", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "plan_id") Long planId,
            @ApiParam(name = "set_id", value = "数据集id", defaultValue = "")
            @PathVariable(value = "set_id") Long dataSetId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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 {
        ResponseEntity<Collection<MAdapterDataVo>> responseEntity = adapterDataSetClient.searchAdapterMetaData(planId, dataSetId, code, name, sorts, size, page);
        List<MAdapterDataVo> mAdapterDataSets = (List<MAdapterDataVo>) responseEntity.getBody();
        List<AdapterDataSetModel> adapterDataSetModels = (List<AdapterDataSetModel>) convertToModels(
                mAdapterDataSets,
                new ArrayList<>(), AdapterDataSetModel.class, null);
        return getResult(adapterDataSetModels, getTotalCount(responseEntity), page, size);
    }
    @RequestMapping(value = "/metadata", method = RequestMethod.PUT)
    public Envelop updateAdapterMetaData(
            @ApiParam(name = "model", value = "说明")
            @RequestParam(value = "model") String model) {
        try {
            AdapterDataSetModel dataModel = jsonToObj(model);
            ValidateResult validateResult = validate(dataModel);
            if (!validateResult.isRs()) {
                return failed(validateResult.getMsg());
            }
            AdapterDataSetDetailModel detailModel = convertToModel(dataModel,AdapterDataSetDetailModel.class);
            MAdapterDataSet mAdapterDataSet = adapterDataSetClient.
                    updateAdapterMetaData(detailModel.getId(), toEncodeJson(detailModel));
            if (mAdapterDataSet == null) {
                return failed("保存失败!");
            }
            AdapterDataSetModel adapterDataSetModel = convertAdapterDataSetModel(mAdapterDataSet);
            return success(adapterDataSetModel);
        } catch (ApiException e) {
            e.printStackTrace();
            return failed(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/metadata", method = RequestMethod.POST)
    public Envelop addAdapterMetaData(
            @ApiParam(name = "model", value = "说明")
            @RequestParam(value = "model") String model) throws Exception {
        try {
            AdapterDataSetModel dataModel = jsonToObj(model);
            ValidateResult validateResult = validate(dataModel);
            if (!validateResult.isRs()) {
                return failed(validateResult.getMsg());
            }
            AdapterDataSetDetailModel detailModel = convertToModel(dataModel,AdapterDataSetDetailModel.class);
            MAdapterDataSet mAdapterDataSet = adapterDataSetClient.createAdapterMetaData(toEncodeJson(detailModel));
            if (mAdapterDataSet == null) {
                return failed("保存失败!");
            }
            AdapterDataSetModel adapterDataSetModel = convertAdapterDataSetModel(mAdapterDataSet);
            return success(adapterDataSetModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/meta_data", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除适配关系", notes = "根据适配关系ID删除适配关系,批量删除时ID以逗号隔开")
    public Envelop deleteAdapterMetaData(
            @ApiParam(name = "plan_id", value = "数据集id")
            @RequestParam(value = "plan_id") long planId,
            @ApiParam(name = "data_set_id", value = "数据集id")
            @RequestParam(value = "data_set_id") long dataSetId,
            @ApiParam(name = "ids", value = "适配关系ID")
            @RequestParam(value = "ids") String ids) {
        try {
            if(!adapterDataSetClient.isLeftMeta(planId, dataSetId, ids)){
                return failed("至少保留一条适配数据!");
            }
            ids = trimEnd(ids, ",");
            if (StringUtils.isEmpty(ids)) {
                return failed("请选择需要删除的数据!");
            }
            boolean result = adapterDataSetClient.delMetaData(ids);
            if (!result) {
                return failed("删除失败!");
            }
            return success(null);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 标准字典项的下拉
     * @return
     */
    @RequestMapping("/std_meta_data/combo")
    @ResponseBody
    public Envelop getStdDictEntry(
            @ApiParam(name = "plan_id", value = "方案编号")
            @RequestParam(value = "plan_id") Long planId,
            @ApiParam(name = "data_set_id", value = "字典编号")
            @RequestParam(value = "data_set_id") Long dataSetId,
            @ApiParam(name = "mode", value = "编辑模式: modify、new")
            @RequestParam(value = "mode") String mode,
            @ApiParam(name = "search_name", value = "查询字符串")
            @RequestParam(value = "search_name") String searchName,
            @ApiParam(name = "page", value = "当前页")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "大小")
            @RequestParam(value = "size") int size){
        try {
            ResponseEntity<Collection<MAdapterRelationship>> responseEntity = adapterDataSetClient.searchStdMeta(planId, dataSetId, searchName, mode, "", size, page);
            List<MAdapterRelationship> stdMeta = (List<MAdapterRelationship>) responseEntity.getBody();
            return getResult(stdMeta, getTotalCount(responseEntity), page, size);
        }
        catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    public AdapterDataSetModel convertAdapterDataSetModel(MAdapterDataSet mAdapterDataSet){
        AdapterDataSetModel adapterDataSetModel = convertToModel(mAdapterDataSet,AdapterDataSetModel.class);
        long planId = adapterDataSetModel.getAdapterPlanId();
        MAdapterPlan mAdapterPlan = planClient.getAdapterPlanById(planId);
        String versionCode = mAdapterPlan.getVersion();
        long dataSetId = adapterDataSetModel.getDataSetId()==null?0:adapterDataSetModel.getDataSetId();
        if (dataSetId != 0) {
            MStdDataSet mStdDataSet = dataSetClient.getDataSet(dataSetId, versionCode);
            adapterDataSetModel.setDataSetCode(mStdDataSet == null ? "" : mStdDataSet.getCode());
            adapterDataSetModel.setDataSetName(mStdDataSet == null ? "" : mStdDataSet.getName());
        }
        long metaDataId = adapterDataSetModel.getMetaDataId()==null?0:adapterDataSetModel.getMetaDataId();
        if (metaDataId != 0) {
            MStdMetaData mStdMetaData = dataSetClient.getMetaData(metaDataId, versionCode);
            adapterDataSetModel.setMetaDataCode(mStdMetaData == null ? "" : mStdMetaData.getCode());
            adapterDataSetModel.setMetaDataName(mStdMetaData == null ? "" : mStdMetaData.getName());
        }
        long orgDataSetSeq = adapterDataSetModel.getOrgDataSetSeq()==null?0:adapterDataSetModel.getOrgDataSetSeq();
        if (orgDataSetSeq != 0) {
            MOrgDataSet mOrgDataSet = orgDataSetClient.getDataSetBySequence(mAdapterPlan.getOrg(), orgDataSetSeq);
            adapterDataSetModel.setOrgDataSetCode(mOrgDataSet == null ? "" : mOrgDataSet.getCode());
            adapterDataSetModel.setOrgDataSetName(mOrgDataSet == null ? "" : mOrgDataSet.getName());
        }
        long orgMateDataSeq =  adapterDataSetModel.getOrgMetaDataSeq()==null?0:adapterDataSetModel.getOrgMetaDataSeq();
        if(orgMateDataSeq!=0)
        {
            MOrgMetaData mOrgMetaData = orgMetaDataClient.getMetaDataBySequence(mAdapterPlan.getOrg(),Integer.parseInt(String.valueOf(orgMateDataSeq)));
            adapterDataSetModel.setOrgMetaDataCode(mOrgMetaData==null?"":mOrgMetaData.getCode());
            adapterDataSetModel.setOrgMetaDataName(mOrgMetaData==null?"":mOrgMetaData.getName());
        }
        return adapterDataSetModel;
    }
}

+ 296 - 0
src/main/java/com/yihu/ehr/adapter/controller/AdapterDictController.java

@ -0,0 +1,296 @@
package com.yihu.ehr.adapter.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.adapter.service.AdapterDictClient;
import com.yihu.ehr.adapter.service.OrgDictClient;
import com.yihu.ehr.adapter.service.OrgDictEntryClient;
import com.yihu.ehr.adapter.service.PlanClient;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.agModel.adapter.AdapterDictDetailModel;
import com.yihu.ehr.agModel.adapter.AdapterDictModel;
import com.yihu.ehr.agModel.adapter.AdapterRelationshipModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.std.service.DictClient;
import com.yihu.ehr.model.adaption.*;
import com.yihu.hos.model.standard.MStdDict;
import com.yihu.hos.model.standard.MStdDictEntry;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.util.validate.ValidateResult;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
 * @author lincl
 * @version 1.0
 * @created 2016.3.1
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter")
@RestController
@Api(protocols = "https", value = "adapter", description = "字典适配", tags = {"适配管理-字典适配"})
public class AdapterDictController extends ExtendController<AdapterDictModel> {
    @Autowired
    AdapterDictClient adapterDictClient;
    @Autowired
    ObjectMapper objectMapper;
    @Autowired
    OrgDictClient orgDictClient;
    @Autowired
    OrgDictEntryClient orgDictEntryClient;
    @Autowired
    DictClient dictClient;
    @Autowired
    PlanClient planClient;
    @RequestMapping(value = "/plan/{plan_id}/dicts", method = RequestMethod.GET)
    public Envelop searchDicts(
            @ApiParam(name = "plan_id", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "plan_id") Long planId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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) {
        try {
            ResponseEntity<Collection<MAdapterRelationship>> responseEntity = adapterDictClient.searchAdapterDict(planId, code, name, sorts, size, page);
            List<MAdapterRelationship> mAdapterRelationships = (List<MAdapterRelationship>) responseEntity.getBody();
            List<AdapterRelationshipModel> relationshipModels = (List<AdapterRelationshipModel>) convertToModels(mAdapterRelationships,
                    new ArrayList<AdapterRelationshipModel>(mAdapterRelationships.size()),
                    AdapterRelationshipModel.class, null);
            return getResult(relationshipModels, getTotalCount(responseEntity), page, size);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/plan/dict/entrys/{plan_id}/{dict_id}", method = RequestMethod.GET)
    public Envelop getAdapterDictEntryByDictId(
            @ApiParam(name = "plan_id", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "plan_id") Long planId,
            @ApiParam(name = "dict_id", value = "字典编号", defaultValue = "")
            @PathVariable(value = "dict_id") Long dictId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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) {
        try {
            ResponseEntity<Collection<MAdapterDictVo>> responseEntity = adapterDictClient.searchAdapterDictEntry(planId, dictId, code, name, sorts, size, page);
            List<MAdapterDictVo> mAdapterDicts = (List<MAdapterDictVo>) responseEntity.getBody();
            List<AdapterDictModel> adapterDictModels = (List<AdapterDictModel>) convertToModels(mAdapterDicts, new ArrayList<AdapterDictModel>(mAdapterDicts.size())
                    , AdapterDictModel.class, null);
            return getResult(adapterDictModels, getTotalCount(responseEntity), page, size);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/dict/entry/{id}", method = RequestMethod.GET)
    public Envelop getAdapterDictEntry(
            @ApiParam(name = "id", value = "适配关系ID")
            @PathVariable(value = "id") long id) {
        try {
            MAdapterDict mAdapterDict = adapterDictClient.getAdapterDictEntry(id);
            AdapterDictModel adapterDictModel = convertAdapterDictModel(mAdapterDict);
            if (adapterDictModel == null) {
                return failed("数据获取失败!");
            }
            return success(adapterDictModel);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/dict/entry", method = RequestMethod.POST)
    @ApiOperation(value = "保存字典项映射关系")
    public Envelop createAdapterDictEntry(
            @ApiParam(name = "model", value = "数据模型")
            @RequestParam(value = "model") String model) {
        try {
            AdapterDictModel adapterDictModel = jsonToObj(model);
            ValidateResult validateResult = validate(adapterDictModel);
            if(!validateResult.isRs()){
                return failed(validateResult.getMsg());
            }
            AdapterDictDetailModel detailModel = convertToModel(adapterDictModel,AdapterDictDetailModel.class);
            MAdapterDict mAdapterDict = adapterDictClient.createAdapterDictEntry(toEncodeJson(detailModel));
            if(mAdapterDict==null)
            {
                return failed("保存失败!");
            }
            adapterDictModel = convertAdapterDictModel(mAdapterDict);
            return success(adapterDictModel);
        } catch (ApiException e){
            e.printStackTrace();
            return failed(e.getMessage());
        } catch (Exception e){
            e.printStackTrace();
            return failedSystem();
        }
    };
    @RequestMapping(value = "/dict/entry", method = RequestMethod.PUT)
    public Envelop updateAdapterDictEntry(
            @ApiParam(name = "model", value = "数据模型")
            @RequestParam(value = "model") String model) {
        try {
            AdapterDictModel adapterDictModel = jsonToObj(model);
            ValidateResult validateResult = validate(adapterDictModel);
            if(!validateResult.isRs()){
                return failed(validateResult.getMsg());
            }
            AdapterDictDetailModel detailModel = convertToModel(adapterDictModel,AdapterDictDetailModel.class);
            MAdapterDict mAdapterDict =adapterDictClient.updateAdapterDictEntry(detailModel.getId(), toEncodeJson(detailModel));
            if(mAdapterDict==null)
            {
                return  failed("保存失败!");
            }
            adapterDictModel = convertAdapterDictModel(mAdapterDict);
            return success(adapterDictModel);
        } catch (ApiException e){
            e.printStackTrace();
            return failed(e.getMessage());
        } catch (Exception e){
            e.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/dict/entrys", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除适配关系", notes = "根据适配关系ID删除适配关系,批量删除时ID以逗号隔开")
    public Envelop delAdapterDictEntry(
            @ApiParam(name = "ids", value = "适配关系ID")
            @RequestParam(value = "ids") String ids){
        try {
            ids = trimEnd(ids, ",");
            if (StringUtils.isEmpty(ids)) {
                return failed("请选择需要删除的数据!");
            }
            boolean result = adapterDictClient.delDictEntry(ids);
            if (!result) {
                return failed("删除失败!");
            }
            return success(null);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 标准字典项的下拉
     * @return
     */
    @RequestMapping("/std_dict_entries/combo")
    @ResponseBody
    public Envelop getStdDictEntry(
            @ApiParam(name = "plan_id", value = "方案编号")
            @RequestParam(value = "plan_id") Long planId,
            @ApiParam(name = "dict_id", value = "字典编号")
            @RequestParam(value = "dict_id") Long dictId,
            @ApiParam(name = "mode", value = "编辑模式: modify、new")
            @RequestParam(value = "mode") String mode,
            @ApiParam(name = "search_name", value = "查询字符串")
            @RequestParam(value = "search_name") String searchName,
            @ApiParam(name = "page", value = "当前页")
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "大小")
            @RequestParam(value = "size") int size){
        try {
            ResponseEntity<Collection<MAdapterRelationship>> responseEntity = adapterDictClient.searchStdDictEntry(planId, dictId, searchName, mode, "", size, page);
            List<MAdapterRelationship> stdDictEntries = (List<MAdapterRelationship>) responseEntity.getBody();
            return getResult(stdDictEntries, getTotalCount(responseEntity), page, size);
        }
        catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    public AdapterDictModel convertAdapterDictModel(MAdapterDict mAdapterDict)
    {
        AdapterDictModel dictModel = convertToModel(mAdapterDict,AdapterDictModel.class);
        MAdapterPlan mAdapterPlan = planClient.getAdapterPlanById(dictModel.getAdapterPlanId());
        String versionCode = mAdapterPlan.getVersion();
        long dictId = dictModel.getDictId()==null?0:dictModel.getDictId();
        if(dictId!=0)
        {
            MStdDict mStdDict = dictClient.getCdaDictInfo(dictId, versionCode);
            dictModel.setDictCode(mStdDict == null ? "" : mStdDict.getCode());
            dictModel.setDictName(mStdDict==null?"":mStdDict.getName());
        }
        long dictEntry = dictModel.getDictEntryId()==null?0:dictModel.getDictEntryId();
        if(dictEntry!=0)
        {
            MStdDictEntry dictEntry1 = dictClient.getDictEntry(dictEntry,versionCode);
            dictModel.setDictEntryCode(dictEntry1==null?"":dictEntry1.getCode());
            dictModel.setDictEntryName(dictEntry1 == null ? "" : dictEntry1.getValue());
        }
       long orgDictSeq = dictModel.getOrgDictSeq()==null?0:dictModel.getOrgDictSeq();
        if(orgDictSeq!=0)
        {
            MOrgDict mOrgDict = orgDictClient.getOrgDictBySequence(mAdapterPlan.getOrg(),Integer.parseInt(String.valueOf(orgDictSeq)));
            dictModel.setOrgDictCode(mOrgDict==null?"":mOrgDict.getCode());
            dictModel.setOrgDictName(mOrgDict == null ? "" : mOrgDict.getName());
        }
        long orgDictEntrySeq = dictModel.getOrgDictEntrySeq()==null?0:dictModel.getOrgDictEntrySeq();
        if(orgDictEntrySeq!=0)
        {
            MOrgDictItem mOrgDictItem = orgDictEntryClient.getOrgDicEntryBySequence(mAdapterPlan.getOrg(),Integer.parseInt(String.valueOf(orgDictEntrySeq)));
            dictModel.setOrgDictEntryCode(mOrgDictItem==null?"":mOrgDictItem.getCode());
            dictModel.setOrgDictEntryName(mOrgDictItem == null ? "" : mOrgDictItem.getName());
        }
        return dictModel;
    }
}

+ 242 - 0
src/main/java/com/yihu/ehr/adapter/controller/AdapterOrgController.java

@ -0,0 +1,242 @@
package com.yihu.ehr.adapter.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.agModel.thirdpartystandard.AdapterOrgDetailModel;
import com.yihu.ehr.agModel.thirdpartystandard.AdapterOrgModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.model.resource.MRsAdapterSchema;
import com.yihu.ehr.resource.client.RsAdapterSchemaClient;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.adapter.service.AdapterOrgClient;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.model.adaption.MAdapterOrg;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/26.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapterOrg")
@RestController
@Api(protocols = "https", value = "adapter", description = "适配机构管理", tags = {"适配管理-适配机构管理"})
public class AdapterOrgController extends BaseController {
    @Autowired
    private AdapterOrgClient adapterOrgClient;
    @Autowired
    private ConventionalDictEntryClient dictEntryClient;
    @Autowired
    private OrganizationClient organizationClient;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private RsAdapterSchemaClient adapterSchemaClient;
    @RequestMapping(value = "/orgs", method = RequestMethod.GET)
    @ApiOperation(value = "适配采集标准")
    public Envelop searchAdapterOrg(
            @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) {
        try {
            ResponseEntity<Collection<MAdapterOrg>> responseEntity = adapterOrgClient.searchAdapterOrg(fields, filters, sorts, size, page);
            List<MAdapterOrg> mAdapterOrgs = (List<MAdapterOrg>) responseEntity.getBody();
            List<AdapterOrgModel> adapterOrgModels = new ArrayList<>();
            for (MAdapterOrg mAdapterOrg : mAdapterOrgs) {
                AdapterOrgModel adapterOrgModel = convertToModel(mAdapterOrg, AdapterOrgModel.class);
                String type = adapterOrgModel.getType();
                if (StringUtils.isNotEmpty(type)) {
                    MConventionalDict dict = dictEntryClient.getAdapterType(type);
                    adapterOrgModel.setTypeValue(dict == null ? "" : dict.getValue());
                }
                String orgCode = adapterOrgModel.getOrg();
                if (StringUtils.isNotEmpty(orgCode)) {
                    MOrganization mOrganization = organizationClient.getOrg(orgCode);
                    adapterOrgModel.setOrgValue(mOrganization == null ? "" : mOrganization.getFullName());
                }
                String parentId = adapterOrgModel.getParent();
                if (StringUtils.isNotEmpty(parentId)) {
                    MAdapterOrg adapterOrg = adapterOrgClient.getAdapterOrg(parentId);
                    adapterOrgModel.setParentValue(adapterOrg == null ? "" : adapterOrg.getName());
                }
                adapterOrgModels.add(adapterOrgModel);
            }
            return getResult(adapterOrgModels, getTotalCount(responseEntity), page, size);
        } catch (Exception ex) {
            return failedSystem();
        }
    }
    @RequestMapping(value = "/org/{code}", method = RequestMethod.GET)
    @ApiOperation(value = "获取适配采集标准")
    public Envelop getAdapterOrg(
            @ApiParam(name = "code", value = "代码", defaultValue = "")
            @PathVariable(value = "code") String code) throws Exception {
        MAdapterOrg mAdapterOrg = adapterOrgClient.getAdapterOrg(code);
        AdapterOrgDetailModel adapterOrgModel = convertAdapterOrgDetailModel(mAdapterOrg);
        if (adapterOrgModel == null) {
            return failed("适配机构信息获取失败!");
        }
        return success(adapterOrgModel);
    }
    @RequestMapping(value = "/org", method = RequestMethod.POST)
    @ApiOperation(value = "新增采集标准")
    public Envelop addAdapterOrg(
            @ApiParam(name = "adapterOrg", value = "采集机构模型", defaultValue = "")
            @RequestParam(value = "adapterOrg", required = false) String adapterOrg) {
        MAdapterOrg mAdapterOrg = null;
        try {
            AdapterOrgDetailModel detailModel = objectMapper.readValue(adapterOrg, AdapterOrgDetailModel.class);
            String errorMsg = "";
            if (StringUtils.isEmpty(detailModel.getName())) {
                errorMsg += "名称不能为空!";
            }
            if (StringUtils.isEmpty(detailModel.getOrg())) {
                errorMsg += "机构代码不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            if (adapterOrgClient.isExistAdapterOrg(detailModel.getCode())) {
                return failed("该机构已存在采集标准!");
            }
            mAdapterOrg = convertToModel(detailModel, MAdapterOrg.class);
            mAdapterOrg = adapterOrgClient.addAdapterOrg(objectMapper.writeValueAsString(mAdapterOrg));
            if (mAdapterOrg == null) {
                return failed("新增失败!");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
        return success(convertAdapterOrgDetailModel(mAdapterOrg));
    }
    @RequestMapping(value = "/org/{code}", method = RequestMethod.PUT)
    @ApiOperation(value = "更新采集标准")
    public Envelop updateAdapterOrg(
            @ApiParam(name = "code", value = "代码", defaultValue = "")
            @PathVariable(value = "code") String code,
            @ApiParam(name = "name", value = "名称", defaultValue = "")
            @RequestParam(value = "name") String name,
            @ApiParam(name = "description", value = "描述", defaultValue = "")
            @RequestParam(value = "description", required = false) String description) throws Exception {
        String errorMsg = "";
        if (StringUtils.isEmpty(code)) {
            errorMsg += "代码不能为空!";
        }
        if (StringUtils.isEmpty(name)) {
            errorMsg += "名称不能为空!";
        }
        if (StringUtils.isNotEmpty(errorMsg)) {
            return failed(errorMsg);
        }
        MAdapterOrg mAdapterOrg = adapterOrgClient.updateAdapterOrg(code, name, description);
        if (mAdapterOrg == null) {
            return failed("修改失败!");
        }
        return success(convertAdapterOrgDetailModel(mAdapterOrg));
    }
    @RequestMapping(value = "/orgs", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除采集标准")
    public Envelop delAdapterOrg(
            @ApiParam(name = "codes", value = "代码", defaultValue = "")
            @RequestParam(value = "codes") String codes) {
        try {
            codes = trimEnd(codes, ",");
            ResponseEntity<List<MRsAdapterSchema>> responseEntity = adapterSchemaClient.getSchema("", "adapterVersion=" + codes + ";type=2", "", 1, 1);
            List<MRsAdapterSchema> mRsAdapterSchemas =  responseEntity.getBody();
            if(mRsAdapterSchemas!=null&&mRsAdapterSchemas.size()>0){
                return failed("删除失败,第三方标准已经被资源适配!");
            }
            if (StringUtils.isEmpty(codes)) {
                return failed("请选择需要删除的内容!");
            }
            boolean result = adapterOrgClient.delAdapterOrg(codes);
            if (!result) {
                return failed("删除失败!");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
        return success(null);
    }
    @RequestMapping(value = "/{org}/isExistAdapterData", method = RequestMethod.GET)
    @ApiOperation(value = "判断采集机构是否存在采集数据")
    public boolean orgIsExistData(
            @ApiParam(name = "org_code", value = "机构", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode) throws Exception {
        return adapterOrgClient.orgIsExistData(orgCode);
    }
    public AdapterOrgDetailModel convertAdapterOrgDetailModel(MAdapterOrg mAdapterOrg) {
        AdapterOrgDetailModel detailModel = convertToModel(mAdapterOrg, AdapterOrgDetailModel.class);
        String type = detailModel.getType();
        if (StringUtils.isNotEmpty(type)) {
            MConventionalDict dict = dictEntryClient.getAdapterType(type);
            detailModel.setTypeValue(dict == null ? "" : dict.getValue());
        }
        String orgCode = detailModel.getOrg();
        if (StringUtils.isNotEmpty(orgCode)) {
            MOrganization mOrganization = organizationClient.getOrg(orgCode);
            detailModel.setOrgValue(mAdapterOrg == null ? "" : mOrganization.getFullName());
        }
        String parentId = detailModel.getParent();
        if (StringUtils.isNotEmpty(parentId)) {
            MAdapterOrg adapterOrg = adapterOrgClient.getAdapterOrg(parentId);
            detailModel.setParentValue(adapterOrg == null ? "" : adapterOrg.getName());
        }
        return detailModel;
    }
}

+ 272 - 0
src/main/java/com/yihu/ehr/adapter/controller/OrgAdapterPlanController.java

@ -0,0 +1,272 @@
package com.yihu.ehr.adapter.controller;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.adapter.service.AdapterOrgClient;
import com.yihu.ehr.adapter.service.PlanClient;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.agModel.adapter.AdapterPlanDetailModel;
import com.yihu.ehr.agModel.adapter.AdapterPlanModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.exception.ApiException;
import com.yihu.ehr.model.adaption.MAdapterOrg;
import com.yihu.ehr.model.adaption.MAdapterPlan;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.hos.model.standard.MSTDVersion;
import com.yihu.ehr.std.service.CDAVersionClient;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.util.validate.ValidateResult;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 * @author lincl
 * @version 1.0
 * @created 2016.3.1
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter")
@RestController
@Api(protocols = "https", value = "adapter", description = "适配方案", tags = {"适配管理-适配方案"})
public class OrgAdapterPlanController extends ExtendController<AdapterPlanModel> {
    @Autowired
    PlanClient planClient;
    @Autowired
    ConventionalDictEntryClient dictEntryClient;
    @Autowired
    AdapterOrgClient adapterOrgClient;
    @Autowired
    CDAVersionClient cdaVersionClient;
    @RequestMapping(value = "/plan", method = RequestMethod.POST)
    @ApiOperation(value = "新增适配方案信息")
    public Envelop addAdapterPlan(
            @ApiParam(name = "model", value = "数据模型")
            @RequestParam(value = "model") String model,
            @ApiParam(name = "isCover", value = "是否覆盖")
            @RequestParam(value = "isCover") String isCover) {
        try {
            AdapterPlanModel dataModel = jsonToObj(model);
            ValidateResult validateResult = validate(dataModel);
            if (!validateResult.isRs()) {
                return failed(validateResult.getMsg());
            }
            AdapterPlanDetailModel detailModel = convertToModel(dataModel, AdapterPlanDetailModel.class);
            MAdapterPlan mAdapterPlan = planClient.saveAdapterPlan(toEncodeJson(detailModel), isCover);
            if (mAdapterPlan == null) {
                return failed("保存失败!");
            }
            AdapterPlanModel adapterPlanModel = ConvertAdapterPlanModel(convertToModel(mAdapterPlan, AdapterPlanModel.class));
            return success(adapterPlanModel);
        } catch (Exception e) {
            e.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/plan", method = RequestMethod.PUT)
    @ApiOperation(value = "修改适配方案信息")
    public Envelop updateAdapterPlan(
            @ApiParam(name = "model", value = "数据模型")
            @RequestParam(value = "model") String model) {
        try {
            AdapterPlanModel dataModel = jsonToObj(model);
            ValidateResult validateResult = validate(dataModel);
            if (!validateResult.isRs()) {
                return failed(validateResult.getMsg());
            }
            AdapterPlanDetailModel detailModel = convertToModel(dataModel, AdapterPlanDetailModel.class);
            MAdapterPlan mAdapterPlan = planClient.updateAdapterPlan(detailModel.getId(), toEncodeJson(detailModel));
            if (mAdapterPlan == null) {
                return failed("保存失败!");
            }
            AdapterPlanModel adapterPlanModel = ConvertAdapterPlanModel(convertToModel(mAdapterPlan, AdapterPlanModel.class));
            return success(adapterPlanModel);
        } catch (ApiException e) {
            e.printStackTrace();
            return failed(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/plans", method = RequestMethod.GET)
    @ApiOperation(value = "适配方案搜索")
    public Envelop searchAdapterPlan(
            @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) {
        try {
            ResponseEntity<Collection<MAdapterPlan>> responseEntity = planClient.searchAdapterPlan(fields, filters, sorts, size, page);
            List<MAdapterPlan> mAdapterPlans = (List<MAdapterPlan>) responseEntity.getBody();
            List<AdapterPlanModel> adapterPlanModels = (List<AdapterPlanModel>) convertToModels(
                    mAdapterPlans,
                    new ArrayList<AdapterPlanModel>(mAdapterPlans.size()), AdapterPlanModel.class, null);
            if (adapterPlanModels != null) {
                for (int i = 0; i < adapterPlanModels.size(); i++) {
                    ConvertAdapterPlanModel(adapterPlanModels.get(i));
                }
            }
            return getResult(adapterPlanModels, getTotalCount(responseEntity), page, size);
        } catch (Exception e) {
            e.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/plan/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取适配方案信息")
    public Envelop getAdapterPlanById(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") Long id) {
        try {
            AdapterPlanModel adapterPlanModel = getModel(planClient.getAdapterPlanById(id));
            if (adapterPlanModel == null) {
                return failed("数据获取失败!");
            }
            adapterPlanModel = ConvertAdapterPlanModel(adapterPlanModel);
            return success(adapterPlanModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/plans", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除适配方案", notes = "删除适配方案信息,批量删除时,Id以逗号隔开")
    public Envelop delAdapterPlan(
            @ApiParam(name = "ids", value = "方案ID")
            @RequestParam("ids") String ids) throws Exception {
        ids = trimEnd(ids, ",");
        if (StringUtils.isEmpty(ids)) {
            return failed("请选择需要删除的方案!");
        }
        boolean result = planClient.delAdapterPlan(ids);
        if (!result) {
            return failed("删除失败!");
        }
        return success(null);
    }
    @RequestMapping(value = "/plans/list", method = RequestMethod.GET)
    @ApiOperation(value = "适配方案信息下拉")
    public List<Map<String, String>> getAdapterPlanList(
            @ApiParam(name = "type", value = "类型")
            @RequestParam(value = "type") String type,
            @ApiParam(name = "versionCode", value = "版本号")
            @RequestParam(value = "versionCode") String versionCode) throws Exception {
        return planClient.getAdapterPlanList(type, versionCode);
    }
    @RequestMapping(value = "/plan/adapterCustomizes/{plan_id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取定制信息")
    public Map getAdapterCustomize(
            @ApiParam(name = "plan_id", value = "方案ID")
            @PathVariable(value = "plan_id") long planId,
            @ApiParam(name = "version", value = "版本", defaultValue = "")
            @RequestParam("version") String version) throws Exception {
        Map map = planClient.getAdapterCustomize(planId, version);
        return map;
    }
//    @RequestMapping(value = "/plan/adapterDataSet/{plan_id}", method = RequestMethod.POST)
//    @ApiOperation(value = "定制数据集")
//    public boolean adapterDataSet(
//            @ApiParam(name = "plan_id", value = "编号", defaultValue = "")
//            @PathVariable("plan_id") Long planId,
//            @ApiParam(name = "customizeData", value = "customizeData", allowMultiple = true, defaultValue = "")
//            @RequestParam("customizeData") String customizeData) throws Exception {
//
//        return planClient.adapterDataSet(planId, customizeData);
//    }
    @RequestMapping(value = "/plan/{plan_id}/public", method = RequestMethod.PUT)
    @ApiOperation(value = "发布方案")
    public boolean adapterDispatch(
            @ApiParam(name = "plan_id", value = "方案ID")
            @PathVariable(value = "plan_id") long planId) throws Exception {
        boolean b = planClient.adapterDispatch(planId);
        return b;
    }
    public AdapterPlanModel ConvertAdapterPlanModel(AdapterPlanModel adapterPlanModel)
    {
        if (adapterPlanModel == null) {
            return null;
        }
        Long parentId = adapterPlanModel.getParentId();
        if(parentId!=null && parentId!=0) {
            AdapterPlanModel parent = getModel(planClient.getAdapterPlanById(parentId));
            if(parent!=null)
                adapterPlanModel.setParentName(parent.getName());
        }
        String type = adapterPlanModel.getType();
        if(StringUtils.isNotEmpty(type))
        {
            MConventionalDict dict =dictEntryClient.getAdapterType(type);
            if(dict!=null)
            {
                adapterPlanModel.setTypeValue(dict.getValue());
            }
        }
        String orgCode = adapterPlanModel.getOrg();
        if(StringUtils.isNotEmpty(orgCode))
        {
            MAdapterOrg org = adapterOrgClient.getAdapterOrg(orgCode);
            if(org!=null)
            {
                adapterPlanModel.setOrgValue(org.getName());
            }
        }
        String versionId = adapterPlanModel.getVersion();
        if(StringUtils.isNotEmpty(versionId))
        {
            MSTDVersion version = cdaVersionClient.getVersion(versionId);
            if(version!=null)
            {
                adapterPlanModel.setVersionName(version.getVersionName());
            }
        }
        return adapterPlanModel;
    }
}

+ 204 - 0
src/main/java/com/yihu/ehr/adapter/controller/OrgDataSetController.java

@ -0,0 +1,204 @@
package com.yihu.ehr.adapter.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.agModel.thirdpartystandard.OrgDataSetDetailModel;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.adapter.service.OrgDataSetClient;
import com.yihu.ehr.model.adaption.MOrgDataSet;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/27.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter/org")
@RestController
@Api(protocols = "https", value = "adapter", description = "数据集", tags = {"第三方标准-数据集"})
public class OrgDataSetController extends BaseController {
    @Autowired
    private OrgDataSetClient orgDataSetClient;
    @Autowired
    private ObjectMapper objectMapper;
    @RequestMapping(value = "/data_set/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询实体")
    public Envelop getOrgDataSet(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) {
        try {
            MOrgDataSet mOrgDataSet = orgDataSetClient.getOrgDataSet(id);
            OrgDataSetDetailModel dataSetModel = convertToOrgDataSetDetailModel(mOrgDataSet);
            if (dataSetModel == null) {
                return failed("数据集信息获取失败!");
            }
            return success(dataSetModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/data_set", method = RequestMethod.POST)
    @ApiOperation(value = "创建机构数据集")
    public Envelop saveOrgDataSet(
            @ApiParam(name = "json_data", value = "json_data", defaultValue = "")
            @RequestParam(value = "json_data") String jsonData) {
        try {
            OrgDataSetDetailModel detailModel = objectMapper.readValue(jsonData, OrgDataSetDetailModel.class);
            String errorMsg = "";
            if (StringUtils.isEmpty(detailModel.getOrganization())) {
                errorMsg += "机构代码不能为空!";
            }
            if (StringUtils.isEmpty(detailModel.getCode())) {
                errorMsg += "数据集代码不能为空!";
            }
            if (StringUtils.isEmpty(detailModel.getName())) {
                errorMsg += "数据集名称不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            boolean isExist = orgDataSetClient.dataSetIsExist(detailModel.getOrganization(), detailModel.getCode());
            MOrgDataSet mOrgDataSet = convertToMOrgDataSet(detailModel);
            if (detailModel.getId() == 0) {
                if (isExist) {
                    return failed("数据集已存在!");
                }
                mOrgDataSet = orgDataSetClient.createOrgDataSet(objectMapper.writeValueAsString(mOrgDataSet));
            } else {
                MOrgDataSet orgDataSet = orgDataSetClient.getOrgDataSet(detailModel.getId());
                if (!orgDataSet.getCode().equals(detailModel.getCode())
                        && isExist) {
                    return failed("数据集已存在!");
                }
                BeanUtils.copyProperties(mOrgDataSet, orgDataSet, "id", "createDate", "createUser", "sequence");
                mOrgDataSet = orgDataSetClient.updateOrgDataSet(objectMapper.writeValueAsString(orgDataSet));
            }
            detailModel = convertToOrgDataSetDetailModel(mOrgDataSet);
            if (detailModel == null) {
                return failed("保存失败!");
            }
            return success(detailModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/data_set/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除机构数据集")
    public Envelop deleteOrgDataSet(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) {
        try {
            if (id == 0) {
                return failed("请选择需要删除数据集!");
            }
            boolean result = orgDataSetClient.deleteOrgDataSet(id);
            if (!result) {
                return failed("删除失败!");
            }
            return success(null);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/data_sets", method = RequestMethod.GET)
    @ApiOperation(value = "条件查询")
    public Envelop searchAdapterOrg(
            @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) {
        try {
            ResponseEntity<Collection<MOrgDataSet>> responseEntity = orgDataSetClient.searchAdapterOrg(fields, filters, sorts, size, page);
            List<MOrgDataSet> mOrgDataSets = (List<MOrgDataSet>) responseEntity.getBody();
            List<OrgDataSetDetailModel> detailModels =new ArrayList<> ();
            //List<OrgDataSetDetailModel>) convertToModels(mOrgDataSets, new ArrayList<OrgDataSetDetailModel>(mOrgDataSets.size()), OrgDataSetDetailModel.class, null);
            for(MOrgDataSet mOrgDataSet : mOrgDataSets)
            {
                OrgDataSetDetailModel detailModel = convertToOrgDataSetDetailModel(mOrgDataSet);
                detailModels.add(detailModel);
            }
            return getResult(detailModels, getTotalCount(responseEntity), page, size);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/data_set", method = RequestMethod.GET)
    public Envelop getDataSetBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") long sequence) {
        try {
            MOrgDataSet mOrgDataSet = orgDataSetClient.getDataSetBySequence(orgCode, sequence);
            OrgDataSetDetailModel dataSetModel = convertToOrgDataSetDetailModel(mOrgDataSet);
            return success(dataSetModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    public MOrgDataSet convertToMOrgDataSet(OrgDataSetDetailModel detailModel)
    {
        if(detailModel==null)
        {
            return null;
        }
        MOrgDataSet mOrgDataSet = convertToModel(detailModel,MOrgDataSet.class);
        mOrgDataSet.setCreateDate(StringToDate(detailModel.getCreateDate(), AgAdminConstants.DateTimeFormat));
        mOrgDataSet.setUpdateDate(StringToDate(detailModel.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return mOrgDataSet;
    }
    public OrgDataSetDetailModel convertToOrgDataSetDetailModel(MOrgDataSet mOrgDataSet)
    {
        if(mOrgDataSet==null)
        {
            return null;
        }
        OrgDataSetDetailModel detailModel = convertToModel(mOrgDataSet, OrgDataSetDetailModel.class);
        detailModel.setCreateDate(DateToString(mOrgDataSet.getCreateDate(),AgAdminConstants.DateTimeFormat));
        detailModel.setUpdateDate(DateToString(mOrgDataSet.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return detailModel;
    }
}

+ 187 - 0
src/main/java/com/yihu/ehr/adapter/controller/OrgDictController.java

@ -0,0 +1,187 @@
package com.yihu.ehr.adapter.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.adapter.service.OrgDictClient;
import com.yihu.ehr.agModel.thirdpartystandard.OrgDictDetailModel;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.model.adaption.MOrgDict;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/27.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter/org")
@RestController
@Api(protocols = "https", value = "adapter", description = "机构字典", tags = {"第三方标准-机构字典"})
public class OrgDictController extends BaseController {
    @Autowired
    private OrgDictClient orgDictClient;
    @Autowired
    private ObjectMapper objectMapper;
    @RequestMapping(value = "/dict", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询实体")
    public Envelop getOrgDict(
            @ApiParam(name = "id", value = "查询条件", defaultValue = "")
            @RequestParam(value = "id", required = false) long id) throws Exception {
        MOrgDict mOrgDict = orgDictClient.getOrgDict(id);
        if (mOrgDict == null) {
            return failed("字典明细获取失败!");
        }
        OrgDictDetailModel detailModel = convertToModel(mOrgDict, OrgDictDetailModel.class);
        return success(detailModel);
    }
    @RequestMapping(value = "/dict", method = RequestMethod.POST)
    @ApiOperation(value = "创建机构字典")
    public Envelop saveOrgDict(
            @ApiParam(name = "json_data", value = "字典信息", defaultValue = "")
            @RequestParam(value = "json_data") String jsonData) throws Exception {
        OrgDictDetailModel detailModel = objectMapper.readValue(jsonData, OrgDictDetailModel.class);
        String errorMsg = "";
        if (StringUtils.isEmpty(detailModel.getCode())) {
            errorMsg += "代码不能为空!";
        }
        if (StringUtils.isEmpty(detailModel.getName())) {
            errorMsg += "值不能为空!";
        }
        if (StringUtils.isEmpty(detailModel.getOrganization())) {
            errorMsg += "请先选择对应的机构!";
        }
        if (StringUtils.isNotEmpty(errorMsg)) {
            return failed(errorMsg);
        }
        boolean isExist = orgDictClient.isExistDict(detailModel.getOrganization(), detailModel.getCode());
        MOrgDict mOrgDict = convertToMOrgDict(detailModel);
        if (mOrgDict.getId() == 0) {
            if (isExist) {
                return failed("字典已存在!");
            }
            mOrgDict = orgDictClient.createOrgDict(objectMapper.writeValueAsString(mOrgDict));
        } else {
            MOrgDict orgDict = orgDictClient.getOrgDict(mOrgDict.getId());
            if (!orgDict.getCode().equals(mOrgDict.getCode())
                    && isExist) {
                return failed("字典已存在");
            }
            BeanUtils.copyProperties(mOrgDict, orgDict, "id", "createDate", "createUser", "sequence");
            mOrgDict = orgDictClient.updateOrgDict(objectMapper.writeValueAsString(orgDict));
        }
        if (mOrgDict == null) {
            return failed("保存失败");
        }
        detailModel = convertToOrgDictDetailModel(mOrgDict);
        return success(detailModel);
    }
    @RequestMapping(value = "/dict/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除机构字典")
    public Envelop deleteOrgDict(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) {
        boolean result = orgDictClient.deleteOrgDict(id);
        if (!result) {
            return failed("删除失败!");
        }
        return success(null);
    }
    @RequestMapping(value = "/dicts", method = RequestMethod.GET)
    @ApiOperation(value = "条件查询")
    public Envelop searchOrgDicts(
            @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) throws Exception {
        ResponseEntity<Collection<MOrgDict>> responseEntity = orgDictClient.searchOrgDicts(fields, filters, sorts, size, page);
        List<MOrgDict> dicts = (List<MOrgDict>) responseEntity.getBody();
        List<OrgDictDetailModel> detailModels =new ArrayList<> ();
        for(MOrgDict mOrgDict : dicts)
        {
            OrgDictDetailModel detailModel = convertToOrgDictDetailModel(mOrgDict);
            detailModels.add(detailModel);
        }
        return getResult(detailModels, getTotalCount(responseEntity), page, size);
    }
    @RequestMapping(value = "/dict/combo", method = RequestMethod.GET)
    @ApiOperation(value = "机构字典下拉")
    public List<String> getOrgDict(
            @ApiParam(name = "orgCode", value = "机构代码", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode) throws Exception {
        return orgDictClient.getOrgDict(orgCode);
    }
    @RequestMapping(value = "/dict/org_dict", method = RequestMethod.GET)
    public Envelop getOrgDictBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") int sequence) {
        try {
            MOrgDict mOrgDict = orgDictClient.getOrgDictBySequence(orgCode, sequence);
            OrgDictDetailModel detailModel = convertToOrgDictDetailModel(mOrgDict);
            return success(detailModel);
        } catch (Exception ex) {
            return failedSystem();
        }
    }
    public OrgDictDetailModel convertToOrgDictDetailModel(MOrgDict mOrgDict)
    {
        if(mOrgDict==null)
        {
            return null;
        }
        OrgDictDetailModel detailModel = convertToModel(mOrgDict,OrgDictDetailModel.class);
        detailModel.setCreateDate(DateToString(mOrgDict.getCreateDate(), AgAdminConstants.DateTimeFormat));
        detailModel.setUpdateDate(DateToString(mOrgDict.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return detailModel;
    }
    public MOrgDict convertToMOrgDict(OrgDictDetailModel detailModel)
    {
        if(detailModel==null)
        {
            return null;
        }
        MOrgDict mOrgDict = convertToModel(detailModel,MOrgDict.class);
        mOrgDict.setCreateDate(StringToDate(detailModel.getCreateDate(),AgAdminConstants.DateTimeFormat));
        mOrgDict.setUpdateDate(StringToDate(detailModel.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return mOrgDict;
    }
}

+ 196 - 0
src/main/java/com/yihu/ehr/adapter/controller/OrgDictEntryController.java

@ -0,0 +1,196 @@
package com.yihu.ehr.adapter.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.agModel.thirdpartystandard.OrgDictEntryDetailModel;
import com.yihu.ehr.agModel.thirdpartystandard.OrgDictEntryModel;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.adapter.service.OrgDictEntryClient;
import com.yihu.ehr.model.adaption.MOrgDictItem;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/3/2.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter/org")
@RestController
@Api(protocols = "https", value = "adapter", description = "机构字典项", tags = {"第三方标准-机构字典项"})
public class OrgDictEntryController extends BaseController {
    @Autowired
    private OrgDictEntryClient orgDictEntryClient;
    @Autowired
    private ObjectMapper objectMapper;
    @RequestMapping(value = "/item/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取字典项信息")
    public Envelop getOrgDictItem(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) throws Exception {
        MOrgDictItem mOrgDictItem = orgDictEntryClient.getOrgDictItem(id);
        if (mOrgDictItem == null) {
            return failed("字典明细获取失败!");
        }
        OrgDictEntryDetailModel detailModel = convertToOrgDictEntryDetailModel(mOrgDictItem);
        return success(detailModel);
    }
    @RequestMapping(value = "/item", method = RequestMethod.POST)
    @ApiOperation(value = "新增字典项")
    public Envelop saveOrgDictItem(
            @ApiParam(name = "json_data", value = "字典项信息", defaultValue = "")
            @RequestParam(value = "json_data") String jsonData) throws Exception {
        OrgDictEntryDetailModel detailModel = objectMapper.readValue(jsonData, OrgDictEntryDetailModel.class);
        String errorMsg = "";
        if (StringUtils.isEmpty(detailModel.getCode())) {
            errorMsg += "代码不能为空!";
        }
        if (StringUtils.isEmpty(detailModel.getName())) {
            errorMsg += "值不能为空!";
        }
        if (detailModel.getOrgDict() == 0) {
            errorMsg += "请先选择对应的字典!";
        }
        if (StringUtils.isEmpty(detailModel.getOrganization())) {
            errorMsg += "请先选择对应的机构!";
        }
        if (StringUtils.isNotEmpty(errorMsg)) {
            return failed(errorMsg);
        }
        boolean isExist = orgDictEntryClient.isExistDictItem(detailModel.getOrgDict(),detailModel.getOrganization(),detailModel.getCode());
        MOrgDictItem mOrgDictItem = convertToMOrgDictItem(detailModel);
        if (mOrgDictItem.getId() == 0) {
            if(isExist)
            {
                return failed("字典项已存在!");
            }
            mOrgDictItem = orgDictEntryClient.createOrgDictItem(objectMapper.writeValueAsString(mOrgDictItem));
        } else {
            MOrgDictItem dictItem = orgDictEntryClient.getOrgDictItem(detailModel.getId());
            if(!dictItem.getCode().equals(detailModel.getCode())
                    && isExist)
            {
                return failed("字典项已存在!");
            }
            BeanUtils.copyProperties(mOrgDictItem, dictItem, "id", "createDate", "createUser", "sequence");
            mOrgDictItem = orgDictEntryClient.updateDictItem(objectMapper.writeValueAsString(dictItem));
        }
        if (mOrgDictItem == null) {
            return failed("保存失败!");
        }
        detailModel = convertToOrgDictEntryDetailModel(mOrgDictItem);
        return success(detailModel);
    }
    @RequestMapping(value = "/item", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除字典项")
    public Envelop deleteOrgDictItem(
            @ApiParam(name = "ids", value = "编号", defaultValue = "")
            @RequestParam(value = "ids", required = false) String ids) throws Exception {
        ids = trimEnd(ids,",");
        boolean result = orgDictEntryClient.deleteOrgDictItemList(ids);
        if(!result)
        {
            return failed("删除失败!");
        }
        return success(null);
    }
    @RequestMapping(value = "/items", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询")
    public Envelop searchOrgDictItems(
            @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) throws Exception {
        ResponseEntity<Collection<MOrgDictItem>> responseEntity = orgDictEntryClient.searchOrgDictItems(fields, filters, sorts, size, page);
        List<MOrgDictItem> dictItems = (List<MOrgDictItem>) responseEntity.getBody();
        List<OrgDictEntryModel> detailModels = (List<OrgDictEntryModel>) convertToModels(dictItems,
                                                                                                    new ArrayList<OrgDictEntryModel>(dictItems.size()),
                                                                                                    OrgDictEntryModel.class,
                                                                                                    null);
        return getResult(detailModels,getTotalCount(responseEntity),page,size);
    }
    @RequestMapping(value = "/items/combo", method = RequestMethod.GET)
    @ApiOperation(value = "机构字典项下拉")
    public List<String> getOrgDictEntry(
            @ApiParam(name = "orgDictSeq", value = "字典seq", defaultValue = "")
            @RequestParam(value = "orgDictSeq") long orgDictSeq,
            @ApiParam(name = "orgCode", value = "机构代码", defaultValue = "")
            @RequestParam(value = "orgCode") String orgCode) throws Exception {
        return (List<String>)orgDictEntryClient.getOrgDictEntry(orgDictSeq,orgCode);
    }
    @RequestMapping(value = "/dict/dict_entry", method = RequestMethod.GET)
    public Envelop getOrgDictEntryBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") int sequence) {
        try {
            MOrgDictItem mOrgDictItem = orgDictEntryClient.getOrgDicEntryBySequence(orgCode, sequence);
            OrgDictEntryDetailModel detailModel = convertToOrgDictEntryDetailModel(mOrgDictItem);
            return success(detailModel);
        } catch (Exception ex) {
            return failedSystem();
        }
    }
    public OrgDictEntryDetailModel convertToOrgDictEntryDetailModel(MOrgDictItem mOrgDictItem)
    {
        if(mOrgDictItem==null)
        {
            return null;
        }
        OrgDictEntryDetailModel detailModel = convertToModel(mOrgDictItem,OrgDictEntryDetailModel.class);
        detailModel.setCreateDate(DateToString(mOrgDictItem.getCreateDate(), AgAdminConstants.DateTimeFormat));
        detailModel.setUpdateDate(DateToString(mOrgDictItem.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return detailModel;
    }
    public MOrgDictItem convertToMOrgDictItem(OrgDictEntryDetailModel detailModel)
    {
        if(detailModel==null)
        {
            return null;
        }
        MOrgDictItem mOrgDictItem = convertToModel(detailModel,MOrgDictItem.class);
        mOrgDictItem.setCreateDate(StringToDate(detailModel.getCreateDate(),AgAdminConstants.DateTimeFormat));
        mOrgDictItem.setUpdateDate(StringToDate(detailModel.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return mOrgDictItem;
    }
}

+ 200 - 0
src/main/java/com/yihu/ehr/adapter/controller/OrgMetaDataController.java

@ -0,0 +1,200 @@
package com.yihu.ehr.adapter.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.agModel.thirdpartystandard.OrgMetaDataDetailModel;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.adapter.service.OrgDataSetClient;
import com.yihu.ehr.adapter.service.OrgMetaDataClient;
import com.yihu.ehr.model.adaption.MOrgDataSet;
import com.yihu.ehr.model.adaption.MOrgMetaData;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/3/1.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/adapter/org")
@RestController
@Api(protocols = "https", value = "adapter", description = "数据元", tags = {"第三方标准-数据元"})
public class OrgMetaDataController extends BaseController {
    @Autowired
    private OrgMetaDataClient orgMetaDataClient;
    @Autowired
    private OrgDataSetClient orgDataSetClient;
    @Autowired
    private ObjectMapper objectMapper;
    @RequestMapping(value = "/meta_data/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取机构数据元")
    public Envelop getOrgMetaData(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) throws Exception {
        MOrgMetaData mOrgMetaData = orgMetaDataClient.getOrgMetaData(id);
        OrgMetaDataDetailModel detailModel = convertToOrgMetaDataDetailModel(mOrgMetaData);
        if (detailModel == null) {
            return failed("数据元信息获取失败!");
        }
        return success(detailModel);
    }
    @RequestMapping(value = "/meta_data", method = RequestMethod.POST)
    @ApiOperation(value = "新增数据元")
    public Envelop saveOrgMetaData(
            @ApiParam(name = "json_data", value = "json_data", defaultValue = "")
            @RequestParam(value = "json_data") String jsonData) throws Exception {
        OrgMetaDataDetailModel detailModel = objectMapper.readValue(jsonData, OrgMetaDataDetailModel.class);
        String errorMsg = "";
        if (StringUtils.isEmpty(detailModel.getCode())) {
            errorMsg += "代码不能为空!";
        }
        if (StringUtils.isEmpty(detailModel.getName())) {
            errorMsg += "名称不能为空!";
        }
        if (StringUtils.isEmpty(detailModel.getOrganization())) {
            errorMsg += "机构不能为空!";
        }
        if (StringUtils.isNotEmpty(errorMsg)) {
            return failed(errorMsg);
        }
        boolean isExist = orgMetaDataClient.isExistMetaData(detailModel.getOrgDataSet(),detailModel.getOrganization(),detailModel.getCode());
        MOrgMetaData mOrgMetaData = convertToMOrgMetaData(detailModel);
        if (detailModel.getId() == 0) {
            if(isExist)
            {
                return failed("数据元已存在!");
            }
            mOrgMetaData = orgMetaDataClient.createOrgMetaData(objectMapper.writeValueAsString(mOrgMetaData));
        } else {
            MOrgMetaData orgMetaData = orgMetaDataClient.getOrgMetaData(detailModel.getId());
            if(!orgMetaData.getCode().equals(mOrgMetaData.getCode())
                    && isExist){
                return failed("数据元已存在!");
            }
            BeanUtils.copyProperties(mOrgMetaData, orgMetaData, "id", "createDate", "createUser", "columnType", "columnLength", "sequence");
            mOrgMetaData = orgMetaDataClient.updateOrgMetaData(objectMapper.writeValueAsString(orgMetaData));
        }
        detailModel = convertToOrgMetaDataDetailModel(mOrgMetaData);
        if (detailModel == null) {
            return failed("保存失败!");
        }
        return success(detailModel);
    }
    @RequestMapping(value = "/meta_data", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除数据元")
    public Envelop deleteOrgMetaDataList(
            @ApiParam(name = "ids", value = "编号集", defaultValue = "")
            @RequestParam(value = "ids") String ids) throws Exception {
        ids = trimEnd(ids,",");
        if(StringUtils.isEmpty(ids))
        {
            return failed("请选择需要删除的数据元!");
        }
        boolean result = orgMetaDataClient.deleteOrgMetaDataList(ids);
        if(!result)
        {
            return failed("删除失败!");
        }
        return success(null);
    }
    @RequestMapping(value = "/meta_datas", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询")
    public Envelop searchOrgMetaData(
            @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) throws Exception {
        ResponseEntity<Collection<MOrgMetaData>> responseEntity = orgMetaDataClient.searchOrgMetaDatas(fields,filters,sorts,size,page);
        List<MOrgMetaData> mOrgMetaDatas = (List<MOrgMetaData>)responseEntity.getBody();
        List<OrgMetaDataDetailModel> detailModels = new ArrayList<> ();//List<OrgMetaDataDetailModel>)convertToModels(mOrgMetaDatas,new ArrayList<OrgMetaDataDetailModel>(mOrgMetaDatas.size()),OrgMetaDataDetailModel.class,null);
        for(MOrgMetaData mOrgMetaData:mOrgMetaDatas)
        {
            OrgMetaDataDetailModel detailModel = convertToOrgMetaDataDetailModel(mOrgMetaData);
            detailModels.add(detailModel);
        }
        return getResult(detailModels,getTotalCount(responseEntity),page,size);
    }
    @RequestMapping(value = "/meta_data", method = RequestMethod.GET)
    public Envelop getMetaDataBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") int sequence) {
        try {
            MOrgMetaData mOrgMetaData = orgMetaDataClient.getMetaDataBySequence(orgCode, sequence);
            OrgMetaDataDetailModel metaDataDetailModel = convertToOrgMetaDataDetailModel(mOrgMetaData);
            return success(metaDataDetailModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    public OrgMetaDataDetailModel convertToOrgMetaDataDetailModel(MOrgMetaData mOrgMetaData)
    {
        if(mOrgMetaData==null)
        {
            return null;
        }
        OrgMetaDataDetailModel metaDataDetailModel = convertToModel(mOrgMetaData, OrgMetaDataDetailModel.class);
        metaDataDetailModel.setCreateDate(DateToString(mOrgMetaData.getCreateDate(), AgAdminConstants.DateTimeFormat));
        metaDataDetailModel.setUpdateDate(DateToString(mOrgMetaData.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        int dataSetSeq = metaDataDetailModel.getOrgDataSet();
        if (dataSetSeq!=0)
        {
            MOrgDataSet mOrgDataSet = orgDataSetClient.getDataSetBySequence(metaDataDetailModel.getOrganization(),dataSetSeq);
            metaDataDetailModel.setDataSetCode(mOrgDataSet==null?"":mOrgDataSet.getCode());
            metaDataDetailModel.setDataSetName(mOrgDataSet==null?"":mOrgDataSet.getName());
        }
        return metaDataDetailModel;
    }
    public MOrgMetaData convertToMOrgMetaData(OrgMetaDataDetailModel detailModel)
    {
        if(detailModel==null)
        {
            return null;
        }
        MOrgMetaData mOrgMetaData = convertToModel(detailModel,MOrgMetaData.class);
        mOrgMetaData.setCreateDate(StringToDate(detailModel.getCreateDate(),AgAdminConstants.DateTimeFormat));
        mOrgMetaData.setUpdateDate(StringToDate(detailModel.getUpdateDate(),AgAdminConstants.DateTimeFormat));
        return mOrgMetaData;
    }
}

+ 116 - 0
src/main/java/com/yihu/ehr/adapter/service/AdapterDataSetClient.java

@ -0,0 +1,116 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MAdapterDataSet;
import com.yihu.ehr.model.adaption.MAdapterDataVo;
import com.yihu.ehr.model.adaption.MAdapterRelationship;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 *
 * @author lincl
 * @version 1.0
 * @created 2016.2.3
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0 + "/adapter")
@ApiIgnore
public interface AdapterDataSetClient {
    @RequestMapping(value = "/plan/{planId}/datasets", method = RequestMethod.GET)
    @ApiOperation(value = "根据方案ID及查询条件查询数据集适配关系")
    ResponseEntity<Collection<MAdapterRelationship>> searchAdapterDataSet(
            @ApiParam(name = "planId", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "planId") Long planId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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);
    @RequestMapping(value = "/plan/{planId}/datasets/{dataSetId}/datametas", method = RequestMethod.GET)
    @ApiOperation(value = "根据dataSetId搜索数据元适配关系")
    ResponseEntity<Collection<MAdapterDataVo>> searchAdapterMetaData(
            @ApiParam(name = "planId", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "planId") Long planId,
            @ApiParam(name = "dataSetId", value = "数据集id", defaultValue = "")
            @PathVariable(value = "dataSetId") Long dataSetId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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);
    @RequestMapping(value = "/datameta/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据数据集ID获取数据元适配关系明细")
    MAdapterDataSet getAdapterMetaData(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") Long id);
    @RequestMapping(value = "/datameta/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改数据元映射关系")
    MAdapterDataSet updateAdapterMetaData(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") Long id,
            @ApiParam(name = "jsonModel", value = "数据元模型", defaultValue = "")
            @RequestBody String jsonModel);
    @RequestMapping(value = "/datameta", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增数据元映射关系")
    MAdapterDataSet createAdapterMetaData(
            @ApiParam(name = "jsonModel", value = "数据元模型", defaultValue = "")
            @RequestBody String jsonModel);
    @RequestMapping(value = "/datametas", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除数据元映射关系")
    boolean delMetaData(
            @RequestParam("ids") String ids);
    @RequestMapping(value = "/data_set/{data_set_id}/is_left/meta", method = RequestMethod.GET)
    @ApiOperation(value = "判断除了metaIds之外是否还存在其他的数据元")
    boolean isLeftMeta(
            @RequestParam("plan_id") long planId,
            @PathVariable("data_set_id") long dataSetId,
            @RequestParam("meta_ids") String metaIds);
    @RequestMapping(value = "/plan/{planId}/data_set/{data_set_id}/std_meta", method = RequestMethod.GET)
    @ApiOperation(value = "过滤后的标准字典项分页查询")
    ResponseEntity<Collection<MAdapterRelationship>> searchStdMeta(
            @ApiParam(name = "planId", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "planId") Long planId,
            @ApiParam(name = "data_set_id", value = "字典编号", defaultValue = "")
            @PathVariable(value = "data_set_id") Long dataSetId,
            @ApiParam(name = "seach_name", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "seach_name", required = false) String searchName,
            @ApiParam(name = "mode", value = "编辑模式(new/modify)", defaultValue = "")
            @RequestParam(value = "mode", required = false) String mode,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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);
}

+ 99 - 0
src/main/java/com/yihu/ehr/adapter/service/AdapterDictClient.java

@ -0,0 +1,99 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MAdapterDict;
import com.yihu.ehr.model.adaption.MAdapterDictVo;
import com.yihu.ehr.model.adaption.MAdapterRelationship;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 *
 * @author lincl
 * @version 1.0
 * @created 2016.2.3
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0  + "/adapter")
@ApiIgnore
public interface AdapterDictClient {
    @RequestMapping(value = "/plan/{planId}/dicts", method = RequestMethod.GET)
    @ApiOperation(value = "字典适配关系分页查询")
    ResponseEntity<Collection<MAdapterRelationship>> searchAdapterDict(
            @ApiParam(name = "planId", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "planId") Long planId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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) ;
    @RequestMapping(value = "/plan/{planId}/dict/{dictId}/entrys", method = RequestMethod.GET)
    @ApiOperation(value = "字典项适配关系分页查询")
    ResponseEntity<Collection<MAdapterDictVo>> searchAdapterDictEntry(
            @ApiParam(name = "planId", value = "适配方案id", defaultValue = "")
            @PathVariable(value = "planId") Long planId,
            @ApiParam(name = "dictId", value = "字典编号", defaultValue = "")
            @PathVariable(value = "dictId") Long dictId,
            @ApiParam(name = "code", value = "代码查询值", defaultValue = "")
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "name", value = "名称查询值", defaultValue = "")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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);
    @RequestMapping(value = "/entry/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据字典ID获取字典项适配关系明细")
    MAdapterDict getAdapterDictEntry(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") Long id) ;
    @RequestMapping(value = "/entry", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "保存字典项映射关系")
    public MAdapterDict createAdapterDictEntry(
            @ApiParam(name = "adapterDictModel", value = "字典数据模型", defaultValue = "")
            @RequestBody String dictJsonModel) throws Exception ;
    @RequestMapping(value = "/entry/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改字典项映射关系")
    public MAdapterDict updateAdapterDictEntry(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") Long id,
            @ApiParam(name = "adapterDictModel", value = "字典数据模型", defaultValue = "")
            @RequestBody String dictJsonModel) throws Exception ;
    @RequestMapping(value = "/entrys", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除字典项映射")
    public boolean delDictEntry(
            @RequestParam("ids") String ids) throws Exception ;
    @RequestMapping(value = "/plan/{planId}/dict/{dictId}/std_entrys", method = RequestMethod.GET)
    @ApiOperation(value = "过滤后的标准字典项分页查询")
    ResponseEntity<Collection<MAdapterRelationship>> searchStdDictEntry(
            @PathVariable(value = "planId") Long planId,
            @PathVariable(value = "dictId") Long dictId,
            @RequestParam(value = "seach_name", required = false) String searchName,
            @RequestParam(value = "mode", required = false) String mode,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page);
}

+ 80 - 0
src/main/java/com/yihu/ehr/adapter/service/AdapterOrgClient.java

@ -0,0 +1,80 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MAdapterOrg;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 * Created by AndyCai on 2016/2/29.
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface AdapterOrgClient {
    @RequestMapping(value = "/adapter/orgs", method = RequestMethod.GET)
    @ApiOperation(value = "适配采集标准")
    ResponseEntity<Collection<MAdapterOrg>> searchAdapterOrg(
            @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);
    @RequestMapping(value = "/adapter/org/{code}", method = RequestMethod.GET)
    @ApiOperation(value = "获取适配采集标准")
    MAdapterOrg getAdapterOrg(
            @ApiParam(name = "code", value = "代码", defaultValue = "")
            @PathVariable(value = "code") String code) ;
    @RequestMapping(value = "/adapter/org", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增采集标准")
    MAdapterOrg addAdapterOrg(
            @ApiParam(name = "json_data", value = "采集机构模型", defaultValue = "")
            @RequestBody String jsonData) ;
    @RequestMapping(value = "/adapter/org/{code}", method = RequestMethod.PUT)
    @ApiOperation(value = "更新采集标准")
    MAdapterOrg updateAdapterOrg(
            @ApiParam(name = "code", value = "代码", defaultValue = "")
            @PathVariable(value = "code") String code,
            @ApiParam(name = "name", value = "名称", defaultValue = "")
            @RequestParam(value = "name") String name,
            @ApiParam(name = "description", value = "描述", defaultValue = "")
            @RequestParam(value = "description", required = false) String description) ;
    @RequestMapping(value = "/adapter/orgs", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除采集标准")
    boolean delAdapterOrg(
            @ApiParam(name = "codes", value = "代码", defaultValue = "")
            @RequestParam(value = "codes") String codes);
    @RequestMapping(value = "/adapter/isExistAdapterData/{org}", method = RequestMethod.GET)
    @ApiOperation(value = "判断采集机构是否存在采集数据")
    boolean orgIsExistData(
            @ApiParam(name = "org", value = "机构", defaultValue = "")
            @PathVariable(value = "org") String org) ;
    @RequestMapping(value = "/adapter/isExistAdapterOrg/{org}", method = RequestMethod.GET)
    @ApiOperation(value = "判断采集机构是否存在采集数据")
    boolean isExistAdapterOrg(@ApiParam(name = "org", value = "机构", defaultValue = "")
                                     @PathVariable(value = "org") String org);
}

+ 77 - 0
src/main/java/com/yihu/ehr/adapter/service/OrgDataSetClient.java

@ -0,0 +1,77 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MOrgDataSet;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 * Created by AndyCai on 2016/2/29.
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgDataSetClient {
    @RequestMapping(value = "/adapter/org/data_set/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询实体")
    MOrgDataSet getOrgDataSet(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id);
    @RequestMapping(value = "/adapter/org/data_set", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建机构数据集")
    MOrgDataSet createOrgDataSet(
            @ApiParam(name = "model", value = "json_data", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/data_set/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除机构数据集")
    boolean deleteOrgDataSet(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id);
    @RequestMapping(value = "/adapter/org/data_set", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改机构数据集")
    MOrgDataSet updateOrgDataSet(
            @ApiParam(name = "model", value = "json_data", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/data_sets", method = RequestMethod.GET)
    @ApiOperation(value = "条件查询")
    ResponseEntity<Collection<MOrgDataSet>> searchAdapterOrg(
            @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);
    @RequestMapping(value = "/adapter/org/is_exist", method = RequestMethod.GET)
    @ApiOperation(value = "条件查询")
    boolean dataSetIsExist(
            @ApiParam(name = "org_code",value = "机构代码",defaultValue = "")
            @RequestParam(value = "org_code")String orgCode,
            @ApiParam(name="code",value="数据集代码",defaultValue = "")
            @RequestParam(value = "code")String code);
    @RequestMapping(value = "/adapter/org/data_set",method = RequestMethod.GET)
    MOrgDataSet getDataSetBySequence(
            @RequestParam(value="org_code")String orgCode,
            @RequestParam(value = "sequence")long sequence);
}

+ 80 - 0
src/main/java/com/yihu/ehr/adapter/service/OrgDictClient.java

@ -0,0 +1,80 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MOrgDict;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/3/2.
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgDictClient {
    @RequestMapping(value = "/adapter/org/dict", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询实体")
    MOrgDict getOrgDict(
            @ApiParam(name = "id", value = "查询条件", defaultValue = "")
            @RequestParam(value = "id", required = false) long id);
    @RequestMapping(value = "/adapter/org/dict", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建机构字典")
    MOrgDict createOrgDict(
            @ApiParam(name = "model", value = "字典信息", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/dict/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除机构字典")
    boolean deleteOrgDict(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id);
    @RequestMapping(value = "/adapter/org/dict", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改机构字典")
    MOrgDict updateOrgDict(
            @ApiParam(name = "model", value = "字典信息", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/dicts", method = RequestMethod.GET)
    @ApiOperation(value = "条件查询")
    ResponseEntity<Collection<MOrgDict>> searchOrgDicts(
            @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);
    @RequestMapping(value = "/adapter/org/dict/combo", method = RequestMethod.GET)
    @ApiOperation(value = "机构字典下拉")
    List<String> getOrgDict(
            @ApiParam(name = "orgCode", value = "机构代码", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode);
    @RequestMapping(value = "/adapter/org/dict/is_exist",method = RequestMethod.GET)
    boolean isExistDict(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "dict_code") String dictCode);
    @RequestMapping(value = "/adapter/org/dict/org_dict",method = RequestMethod.GET)
    MOrgDict getOrgDictBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") int sequence);
}

+ 90 - 0
src/main/java/com/yihu/ehr/adapter/service/OrgDictEntryClient.java

@ -0,0 +1,90 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MOrgDictItem;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 * Created by AndyCai on 2016/3/2.
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgDictEntryClient {
    @RequestMapping(value = "/adapter/org/item/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取字典项信息")
    MOrgDictItem getOrgDictItem(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) ;
    @RequestMapping(value = "/adapter/org/item", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增字典项")
    MOrgDictItem createOrgDictItem(
            @ApiParam(name = "model", value = "字典项信息", defaultValue = "")
            @RequestBody String jsonData) ;
    @RequestMapping(value = "/adapter/org/item/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除字典项")
    boolean deleteOrgDictItem(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id) ;
    @RequestMapping(value = "/adapter/org/items", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除字典项")
    boolean deleteOrgDictItemList(
            @ApiParam(name = "ids", value = "编号集", defaultValue = "")
            @RequestParam(value = "ids") String ids) ;
    @RequestMapping(value = "/adapter/org/item", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改字典项")
    MOrgDictItem updateDictItem(
            @ApiParam(name = "model", value = "字典项信息", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/items", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询")
    ResponseEntity<Collection<MOrgDictItem>> searchOrgDictItems(
            @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);
    @RequestMapping(value = "/adapter/org/items/combo", method = RequestMethod.GET)
    @ApiOperation(value = "机构字典项下拉")
    Collection<String> getOrgDictEntry(
            @ApiParam(name = "orgDictSeq", value = "字典seq", defaultValue = "")
            @RequestParam(value = "orgDictSeq") long orgDictSeq,
            @ApiParam(name = "orgCode", value = "机构代码", defaultValue = "")
            @RequestParam(value = "orgCode") String orgCode);
    @RequestMapping(value = "/adapter/org/item/is_exist",method = RequestMethod.GET)
    boolean isExistDictItem(
            @RequestParam(value = "dict_id")long dictId,
            @RequestParam(value = "org_code")String orgCode,
            @RequestParam(value = "item_code")String itemCode);
    @RequestMapping(value = "/adapter/org/dict/dict_entry",method = RequestMethod.GET)
    MOrgDictItem getOrgDicEntryBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") int sequence);
}

+ 82 - 0
src/main/java/com/yihu/ehr/adapter/service/OrgMetaDataClient.java

@ -0,0 +1,82 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MOrgMetaData;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 * Created by AndyCai on 2016/3/1.
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgMetaDataClient {
    @RequestMapping(value = "/adapter/org/meta/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取机构数据元")
    MOrgMetaData getOrgMetaData(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id);
    @RequestMapping(value = "/adapter/org/meta", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增数据元")
    MOrgMetaData createOrgMetaData(
            @ApiParam(name = "model", value = "json_data", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/meta/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除数据元")
    boolean deleteOrgMetaData(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") long id);
    @RequestMapping(value = "/adapter/org/metas", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除数据元")
    boolean deleteOrgMetaDataList(
            @ApiParam(name = "ids", value = "编号集", defaultValue = "")
            @RequestParam(value = "ids") String ids);
    @RequestMapping(value = "/adapter/org/meta", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改数据元")
    MOrgMetaData updateOrgMetaData(
            @ApiParam(name = "model", value = "json_data", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/adapter/org/page", method = RequestMethod.GET)
    @ApiOperation(value = "分页查询")
    ResponseEntity<Collection<MOrgMetaData>> searchOrgMetaDatas(
            @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);
    @RequestMapping(value = "/adapter/org/meta/is_exist",method = RequestMethod.GET)
    boolean isExistMetaData(
            @RequestParam(value = "data_set_id") int dataSetId,
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "meta_data_code")String metaDataCode);
    @RequestMapping(value = "/adapter/org/meta_data",method = RequestMethod.GET)
    MOrgMetaData getMetaDataBySequence(
            @RequestParam(value = "org_code") String orgCode,
            @RequestParam(value = "sequence") int sequence);
}

+ 110 - 0
src/main/java/com/yihu/ehr/adapter/service/PlanClient.java

@ -0,0 +1,110 @@
package com.yihu.ehr.adapter.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.adaption.MAdapterPlan;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 *
 * @author lincl
 * @version 1.0
 * @created 2016.2.3
 */
@FeignClient(name=MicroServices.Adaption)
@RequestMapping(ApiVersion.Version1_0 )
@ApiIgnore
public interface PlanClient {
    @RequestMapping(value = "/adapter/plans", method = RequestMethod.GET)
    @ApiOperation(value = "适配方案搜索")
    ResponseEntity<Collection<MAdapterPlan>> searchAdapterPlan(
            @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) ;
    @RequestMapping(value = "/adapter/plan/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取适配方案信息")
    MAdapterPlan getAdapterPlanById(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") Long id) ;
    @RequestMapping(value = "/adapter/plan", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "保存适配方案")
    MAdapterPlan saveAdapterPlan(
            @ApiParam(name = "parmJson", value = "数据模型", defaultValue = "")
            @RequestBody String parmJson,
            @ApiParam(name = "isCover", value = "是否覆盖", defaultValue = "")
            @RequestParam(value = "isCover") String isCover) ;
    @RequestMapping(value = "/adapter/plan/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新适配方案")
    MAdapterPlan updateAdapterPlan(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") Long id,
            @ApiParam(name = "parmJson", value = "数据模型", defaultValue = "")
            @RequestBody String parmJson) ;
    @RequestMapping(value = "/adapter/plans", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除适配方案")
    boolean delAdapterPlan(
            @ApiParam(name = "ids", value = "编号列表", defaultValue = "")
            @RequestParam("ids") String ids);
    @RequestMapping(value = "/adapter/plans/list", method = RequestMethod.GET)
    @ApiOperation(value = "根据类型跟版本号获取适配方案列表")
    List<Map<String, String>> getAdapterPlanList(
            @ApiParam(name = "type", value = "类型", defaultValue = "")
            @RequestParam("type") String type,
            @ApiParam(name = "version", value = "版本号", defaultValue = "")
            @RequestParam(value = "version") String version) ;
    @RequestMapping(value = "/adapter/plan/{planId}/adapterCustomizes", method = RequestMethod.GET)
    @ApiOperation(value = "获取定制信息")
    Map getAdapterCustomize(
            @ApiParam(name = "planId", value = "编号", defaultValue = "")
            @PathVariable("planId") Long planId,
            @ApiParam(name = "version", value = "版本", defaultValue = "")
            @RequestParam("version") String version) ;
    @RequestMapping(value = "/adapter/plan/{planId}/adapterDataSet", method = RequestMethod.POST)
    @ApiOperation(value = "定制数据集")
    boolean adapterDataSet(
            @ApiParam(name = "planId", value = "编号", defaultValue = "")
            @PathVariable("planId") Long planId,
            @ApiParam(name = "customizeData", value = "customizeData", defaultValue = "")
            @RequestParam("customizeData") String customizeData) ;
    /**
     * 适配版本发布
     * 1.生成适配版本文件并记录文件位置;2.修改适配方案状态
     */
    @RequestMapping(value = "/adapter/plan/{planId}/dispatch", method = RequestMethod.POST)
    @ApiOperation(value = "适配版本发布")
    boolean adapterDispatch(
            @ApiParam(name = "planId", value = "方案编号", defaultValue = "")
            @PathVariable("planId") Long planId) ;
}

+ 110 - 0
src/main/java/com/yihu/ehr/adapter/utils/ExtendController.java

@ -0,0 +1,110 @@
package com.yihu.ehr.adapter.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.util.validate.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
 * @author lincl
 * @version 1.0
 * @created 2016/3/1
 */
public class ExtendController<T> extends BaseController {
    public static String ERR_SYSREM_DES = "系统错误!";
    protected String objToJson(Object obj) throws JsonProcessingException {
        return objectMapper.writeValueAsString(obj);
    }
    protected String toEncodeJson(Object obj) throws JsonProcessingException, UnsupportedEncodingException {
        return URLEncoder.encode(objectMapper.writeValueAsString(obj), "UTF-8") ;
    }
    protected <T> T jsonToObj(String json) throws IOException {
        return (T) jsonToObj(json, getModelClass());
    }
    protected <T> T jsonToObj(String json , Class<T> clz) throws IOException {
        return objectMapper.readValue(json, clz);
    }
    protected Class getModelClass() {
        Type genType = this.getClass().getGenericSuperclass();
        Type[] parameters = ((ParameterizedType) genType).getActualTypeArguments();
        return (Class) parameters[0];
    }
    protected T getModel(Object obj){
        return (T) convertToModel(obj, getModelClass());
    }
    public Envelop failed(String errMsg){
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(false);
        envelop.setErrorMsg(errMsg);
        return envelop;
    }
    protected Envelop failedSystem(){
        return failed(ERR_SYSREM_DES);
    }
    protected Envelop successList(List ls){
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList((List) convertToModels(ls, new ArrayList<>(), getModelClass(), ""));
        return envelop;
    }
    public Envelop success(Object object){
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        envelop.setObj(convertToModel(object, getModelClass()));
        return envelop;
    }
    public Envelop successMsg(String msg){
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        envelop.setErrorMsg(msg);
        return envelop;
    }
    public Envelop successObj(Object object){
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        envelop.setObj(object);
        return envelop;
    }
    protected ValidateResult validate(T dataModel) {
        try {
            return ValidateUtil.validate(dataModel);
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        ValidateResult validateResult = new ValidateResult();
        validateResult.setMsg("数据验证失败!");
        validateResult.setRs(false);
        return validateResult;
    }
}

+ 346 - 0
src/main/java/com/yihu/ehr/apps/controller/AppApiController.java

@ -0,0 +1,346 @@
package com.yihu.ehr.apps.controller;
import com.yihu.ehr.agModel.app.AppApiModel;
import com.yihu.ehr.apps.service.AppApiClient;
import com.yihu.ehr.apps.service.AppApiParameterClient;
import com.yihu.ehr.apps.service.AppApiResponseClient;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.model.app.MAppApi;
import com.yihu.ehr.model.app.MAppApiDetail;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.user.MRoleApiRelation;
import com.yihu.ehr.model.user.MRoleAppRelation;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.users.service.RoleApiRelationClient;
import com.yihu.ehr.users.service.RoleAppRelationClient;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * Created by linz on 2016年7月8日11:30:18.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@Api(value = "AppApiController", description = "应用开放接口维护", tags = {"应用管理-应用开放接口维护"})
public class AppApiController extends BaseController {
    private static final String DELETE = "delete";
    private static final String ADD = "add";
    private static final String UPDATE = "update";
    private static final String NEW_DATA = "0";
    private static final String DATA_STATUS = "__status";
    @Autowired
    private AppApiClient appApiClient;
    @Autowired
    private RoleApiRelationClient roleApiRelationClient;
    @Autowired
    private AppApiParameterClient appApiParameterClient;
    @Autowired
    private AppApiResponseClient appApiResponseClient;
    @Autowired
    private ConventionalDictEntryClient conDictEntryClient;
    @Autowired
    private RoleAppRelationClient roleAppRelationClient;
    @RequestMapping(value = ServiceApi.AppApi.AppApis, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi列表")
    public Envelop getAppApis(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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) {
        ResponseEntity<List<MAppApi>> responseEntity = appApiClient.getAppApis(fields, filters, sort, size, page);
        List<MAppApi> mAppApiList = responseEntity.getBody();
        List<AppApiModel> appApiModels = new ArrayList<>();
        for (MAppApi mAppApi : mAppApiList) {
            AppApiModel appApiModel = new AppApiModel();
            BeanUtils.copyProperties(mAppApi, appApiModel);
            appApiModels.add(appApiModel);
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = getResult(appApiModels, totalCount, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApis, method = RequestMethod.POST)
    @ApiOperation(value = "创建AppApi")
    public Envelop createAppApi(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestParam(value = "model", required = false) String model,
            @ApiParam(name = "apiParms", value = "api请求参数集合")
            @RequestParam(value = "apiParms", required = false) String apiParms,
            @ApiParam(name = "apiResponse", value = "api响应参数集合")
            @RequestParam(value = "apiResponse", required = false) String apiResponse) {
        Envelop envelop = new Envelop();
        MAppApi mAppApi = appApiClient.createAppApi(model);
        if (mAppApi == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("保存失败!");
            return envelop;
        }
        AppApiModel appApiModel = new AppApiModel();
        BeanUtils.copyProperties(mAppApi, appApiModel);
        saveApiParmsResponse(appApiModel.getId() + "", apiParms, apiResponse);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApi, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi")
    public Envelop getAppApi(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        MAppApi mAppApi = appApiClient.getAppApi(id);
        AppApiModel appApiModel = new AppApiModel();
        if (mAppApi == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("获取数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppApi, appApiModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApis, method = RequestMethod.PUT)
    @ApiOperation(value = "更新AppApi")
    public Envelop updateAppApi(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true)
            @RequestParam(value = "model", required = false) String AppApi,
            @ApiParam(name = "apiParms", value = "api请求参数集合")
            @RequestParam(value = "apiParms", required = false) String apiParms,
            @ApiParam(name = "apiResponse", value = "api响应参数集合")
            @RequestParam(value = "apiResponse", required = false) String apiResponse) {
        Envelop envelop = new Envelop();
        MAppApi mAppApi = appApiClient.createAppApi(AppApi);
        AppApiModel appApiModel = new AppApiModel();
        if (mAppApi == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("更新数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppApi, appApiModel);
        saveApiParmsResponse(appApiModel.getId() + "", apiParms, apiResponse);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApi, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppApi")
    public Envelop deleteAppApi(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        Boolean isDelete = appApiClient.deleteAppApi(id);
        envelop.setSuccessFlg(isDelete);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApisNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取过滤App列表")
    public Envelop getAppApiNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "roleId", value = "角色组ID,需要知道是否被关联才需要传入")
            @RequestParam(value = "roleId", required = false) String roleId) {
        Collection<MAppApi> mAppApis = appApiClient.getAppApiNoPage(filters);
        Envelop envelop = new Envelop();
        List<AppApiModel> appApiModels = new ArrayList<>();
        for (MAppApi mAppApi : mAppApis) {
            AppApiModel appApiModel = convertToModel(mAppApi, AppApiModel.class);
            if (StringUtils.isNotBlank(roleId)) {
                appApiModel.setRoleId(roleId);
            }
            converModelName(appApiModel);
            appApiModels.add(appApiModel);
        }
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(appApiModels);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApi.AppApiSearch, method = RequestMethod.GET)
    @ApiOperation(value = "查询Api详情")
    public Envelop 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
    ) {
        ResponseEntity<List<MAppApiDetail>> responseEntity = appApiClient.searchApi(fields, filters, sorts, size, page);
        List<MAppApiDetail> mAppApiList = responseEntity.getBody();
        Integer totalCount = getTotalCount(responseEntity);
        return getResult(mAppApiList, totalCount, page, size);
    }
    @RequestMapping(value = "/role_app_api/no_paging", method = RequestMethod.GET)
    @ApiOperation(value = "获取角色组的AppApi列表")
    public Envelop getRoleAppFeatureNoPage(
            @ApiParam(name = "role_id", value = "角色组id")
            @RequestParam(value = "role_id") String roleId) {
        Collection<MRoleApiRelation> mRoleApiRelations = roleApiRelationClient.searchRoleApiRelationNoPaging("roleId=" + roleId);
        String apiIds = "";
        for (MRoleApiRelation m : mRoleApiRelations) {
            apiIds += m.getApiId() + ",";
        }
        if (!StringUtils.isEmpty(apiIds)) {
            apiIds = apiIds.substring(0, apiIds.length() - 1);
        }
        Collection<MAppApi> mAppApis = appApiClient.getAppApiNoPage("id=" + apiIds);
        Envelop envelop = new Envelop();
        List<AppApiModel> appApiModels = new ArrayList<>();
        for (MAppApi mAppApi : mAppApis) {
            AppApiModel appApiModel = convertToModel(mAppApi, AppApiModel.class);
            appApiModels.add(appApiModel);
        }
        envelop.setDetailModelList(appApiModels);
        return envelop;
    }
    /**
     * 格式化字典数据
     *
     * @param appApiModel
     */
    private void converModelName(AppApiModel appApiModel) {
        //是否已经被角色组适配,界面适配用
        if (!StringUtils.isEmpty(appApiModel.getRoleId())) {
            ResponseEntity<Collection<MRoleApiRelation>> responseEntity = roleApiRelationClient.searchRoleApiRelations("", "roleId=" + appApiModel.getRoleId() + ";apiId=" + appApiModel.getId(), "", 1, 1);
            Collection<MRoleApiRelation> mRoleFeatureRelations = responseEntity.getBody();
            if (mRoleFeatureRelations != null && mRoleFeatureRelations.size() > 0) {
                appApiModel.setIschecked(true);
            }
        }
        //审计等级
        if (!StringUtils.isEmpty(appApiModel.getAuditLevel())) {
            MConventionalDict catalopDict = conDictEntryClient.getAuditLevel(appApiModel.getAuditLevel());
            appApiModel.setAuditLevelName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //开放等级
        if (!StringUtils.isEmpty(appApiModel.getOpenLevel())) {
            MConventionalDict catalopDict = conDictEntryClient.getOpenLevel(appApiModel.getOpenLevel());
            appApiModel.setOpenLevelName(catalopDict == null ? "" : catalopDict.getValue());
        }
    }
    /**
     * 保存apiParms及apiResponse
     *
     * @param apiId
     * @param apiParms
     * @param apiResponse
     */
    private void saveApiParmsResponse(String apiId, String apiParms, String apiResponse) {
        try {
            List<Map<String, Object>> list;
            if (!StringUtils.isEmpty(apiParms)) {
                list = objectMapper.readValue(apiParms, List.class);
                for (Map<String, Object> parmsMap : list) {
                    //删除的是新增的数据直接跳过
                    if (DELETE.equals(parmsMap.get(DATA_STATUS)) && NEW_DATA.equals(parmsMap.get("id") + "")) {
                        continue;
                    } else {
                        parmsMap.put("appApiId", apiId);
                        String json = toJson(parmsMap);
                        if (NEW_DATA.equals(parmsMap.get("id") + "")) {
                            appApiParameterClient.createAppApiParameter(json);
                        } else if (UPDATE.equals(parmsMap.get(DATA_STATUS))) {
                            appApiParameterClient.updateAppApiParameter(json);
                        } else if (DELETE.equals(parmsMap.get(DATA_STATUS))) {
                            appApiParameterClient.deleteAppApiParameter(parmsMap.get("id") + "");
                        }
                    }
                }
            }
            if (!StringUtils.isEmpty(apiResponse)) {
                list = objectMapper.readValue(apiResponse, List.class);
                for (Map<String, Object> parmsMap : list) {
                    //删除的是新增的数据直接跳过
                    if (DELETE.equals(parmsMap.get(DATA_STATUS)) && NEW_DATA.equals(parmsMap.get("id") + "")) {
                        continue;
                    } else {
                        parmsMap.put("appApiId", apiId);
                        String json = toJson(parmsMap);
                        if (ADD.equals(parmsMap.get(DATA_STATUS))) {
                            appApiResponseClient.createAppApiResponse(json);
                        } else if (UPDATE.equals(parmsMap.get(DATA_STATUS))) {
                            appApiResponseClient.updateAppApiResponse(json);
                        } else if (DELETE.equals(parmsMap.get(DATA_STATUS))) {
                            appApiResponseClient.deleteAppApiResponse(parmsMap.get("id") + "");
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    
    @RequestMapping(value = ServiceApi.AppApi.AppApiAuth, method = RequestMethod.GET)
    @ApiOperation(value = "验证应用的api调用权限")
    public Envelop checkAppApi(
            @ApiParam(name = "appId", value = "应用ID")
            @RequestParam(value = "appId") String appId,
            @ApiParam(name = "apiName", value = "api名称")
            @RequestParam(value = "apiName") String apiName) {
        Envelop envelop = new Envelop();
        try {
            //获取应用和api关系
            Collection<MRoleAppRelation> mRoleAppRelations = roleAppRelationClient.searchRoleAppNoPaging("appId=" + appId);
            String roleIds = mRoleAppRelations.stream().map(MRoleAppRelation::getRoleId).collect(Collectors.toList()).stream().map(roleId -> roleId.toString()).collect(Collectors.joining(","));
            if("".equals(roleIds)){
                return failed("应用无该API的访问权限");
            }
            //获取角色和api关系
            Collection<MRoleApiRelation> mRoleApiRelations = roleApiRelationClient.searchRoleApiRelationNoPaging("roleId=" + roleIds);
            String apiIds = mRoleApiRelations.stream().map(MRoleApiRelation::getApiId).collect(Collectors.toList()).stream().map(apiId -> apiId.toString()).collect(Collectors.joining(","));
            //获取角色相关的所有api
            Collection<MAppApi> mAppApis = appApiClient.getAppApiNoPage("id=" + apiIds + ";methodName=" + apiName);
            List<MAppApi> appApiList = mAppApis.stream().collect(Collectors.toList());
            if (appApiList!=null && appApiList.size()>0){
                return success("");
            }else {
                return failed("无该应用API的访问权限");
            }
//            envelop.setDetailModelList(appApiList);
//            return envelop;
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}

+ 156 - 0
src/main/java/com/yihu/ehr/apps/controller/AppApiParameterController.java

@ -0,0 +1,156 @@
package com.yihu.ehr.apps.controller;
import com.yihu.ehr.agModel.app.AppApiParameterModel;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.apps.service.AppApiParameterClient;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.model.app.MAppApiParameter;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by linz on 2016年7月8日11:30:18.
 */
@RequestMapping(ApiVersion.Version1_0+"/admin" )
@RestController
@Api(value = "AppApiParameter", description = "应用开放接口参数管理", tags = {"应用管理-应用开放接口参数管理"})
public class AppApiParameterController extends BaseController {
    @Autowired
    AppApiParameterClient appApiParameterClient;
    @Autowired
    private ConventionalDictEntryClient conDictEntryClient;
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiParameter列表")
    public Envelop getAppApiParameters(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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){
        ResponseEntity<List<MAppApiParameter>> responseEntity =  appApiParameterClient.getAppApiParameters(fields, filters, sort, size, page);
        List<MAppApiParameter> mAppApiParameterList = responseEntity.getBody();
        List<AppApiParameterModel> AppApiParameterModels = new ArrayList<>();
        for(MAppApiParameter mAppApiParameter: mAppApiParameterList){
            AppApiParameterModel appApiParameterModel  = new AppApiParameterModel();
            BeanUtils.copyProperties(mAppApiParameter,appApiParameterModel);
            converModelName(appApiParameterModel);
            AppApiParameterModels.add(appApiParameterModel);
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = getResult(AppApiParameterModels,totalCount,page,size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.POST)
    @ApiOperation(value = "创建AppApiParameter")
    public Envelop createAppApiParameter(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestParam(value = "model", required = false) String model){
        Envelop envelop = new Envelop();
        MAppApiParameter mAppApiParameter =  appApiParameterClient.createAppApiParameter(model);
        if(mAppApiParameter==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("保存失败!");
            return envelop;
        }
        AppApiParameterModel appApiParameterModel = new AppApiParameterModel();
        BeanUtils.copyProperties(mAppApiParameter,appApiParameterModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiParameterModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiParameter")
    public Envelop getAppApiParameter(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id){
        Envelop envelop = new Envelop();
        MAppApiParameter mAppApiParameter =  appApiParameterClient.getAppApiParameter(id);
        AppApiParameterModel appApiParameterModel = new AppApiParameterModel();
        if(mAppApiParameter==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("获取数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppApiParameter,appApiParameterModel);
        converModelName(appApiParameterModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiParameterModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.PUT)
    @ApiOperation(value = "更新AppApiParameter")
    public Envelop updateAppApiParameter(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true)
            @RequestParam(value = "model", required = false) String AppApiParameter){
        Envelop envelop = new Envelop();
        MAppApiParameter mAppApiParameter =  appApiParameterClient.createAppApiParameter(AppApiParameter);
        AppApiParameterModel appApiParameterModel = new AppApiParameterModel();
        if(mAppApiParameter==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("更新数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppApiParameter,appApiParameterModel);
        converModelName(appApiParameterModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiParameterModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppApiParameter")
    Envelop deleteAppApiParameter(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id){
        Envelop envelop = new Envelop();
        Boolean isDelete  = appApiParameterClient.deleteAppApiParameter(id);
        envelop.setSuccessFlg(isDelete);
        return envelop;
    }
    /**
     * 格式化字典数据
     * @param appApiParameterModel
     */
    private void converModelName(AppApiParameterModel appApiParameterModel){
        //参数类型
        if(!StringUtils.isEmpty(appApiParameterModel.getType())){
            MConventionalDict catalopDict = conDictEntryClient.getApiParameterType(appApiParameterModel.getType());
            appApiParameterModel.setTypeName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //参数数据类型
        if(!StringUtils.isEmpty(appApiParameterModel.getDataType())){
            MConventionalDict catalopDict = conDictEntryClient.getApiParameterDataType(appApiParameterModel.getDataType());
            appApiParameterModel.setDataTypeName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //参数必输
        if(!StringUtils.isEmpty(appApiParameterModel.getRequired())){
            MConventionalDict catalopDict = conDictEntryClient.getApiParameterDataRequired(appApiParameterModel.getRequired());
            appApiParameterModel.setRequiredName(catalopDict == null ? "" : catalopDict.getValue());
        }
    }
}

+ 133 - 0
src/main/java/com/yihu/ehr/apps/controller/AppApiResponseController.java

@ -0,0 +1,133 @@
package com.yihu.ehr.apps.controller;
import com.yihu.ehr.agModel.app.AppApiResponseModel;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.apps.service.AppApiResponseClient;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.model.app.MAppApiResponse;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by linz on 2016年7月8日11:30:18.
 */
@RequestMapping(ApiVersion.Version1_0+"/admin" )
@RestController
@Api(value = "AppApiResponse", description = "应用开放接口返回值管理", tags = {"应用管理-应用开放接口返回值管理"})
public class AppApiResponseController extends BaseController {
    @Autowired
    AppApiResponseClient appApiResponseClient;
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiResponse列表")
    public Envelop getAppApiResponses(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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){
        ResponseEntity<List<MAppApiResponse>> responseEntity =  appApiResponseClient.getAppApiResponses(fields, filters, sort, size, page);
        List<MAppApiResponse> mAppApiResponseList = responseEntity.getBody();
        List<AppApiResponseModel> appApiResponseModels = new ArrayList<>();
        for(MAppApiResponse mAppApiResponse: mAppApiResponseList){
            AppApiResponseModel appApiResponseModel  = new AppApiResponseModel();
            BeanUtils.copyProperties(mAppApiResponse,appApiResponseModel);
            appApiResponseModels.add(appApiResponseModel);
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = getResult(appApiResponseModels,totalCount,page,size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.POST)
    @ApiOperation(value = "创建AppApiResponse")
    public Envelop createAppApiResponse(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestParam(value = "model", required = false) String model){
        Envelop envelop = new Envelop();
        MAppApiResponse mAppApiResponse =  appApiResponseClient.createAppApiResponse(model);
        if(mAppApiResponse==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("保存失败!");
            return envelop;
        }
        AppApiResponseModel appApiResponseModel = new AppApiResponseModel();
        BeanUtils.copyProperties(mAppApiResponse,appApiResponseModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiResponseModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponse, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiResponse")
    public Envelop getAppApiResponse(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id){
        Envelop envelop = new Envelop();
        MAppApiResponse mAppApiResponse =  appApiResponseClient.getAppApiResponse(id);
        AppApiResponseModel appApiResponseModel = new AppApiResponseModel();
        if(mAppApiResponse==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("获取数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppApiResponse,appApiResponseModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiResponseModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.PUT)
    @ApiOperation(value = "更新AppApiResponse")
    public Envelop updateAppApiResponse(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true)
            @RequestParam(value = "model", required = false) String AppApiResponse){
        Envelop envelop = new Envelop();
        MAppApiResponse mAppApiResponse =  appApiResponseClient.createAppApiResponse(AppApiResponse);
        AppApiResponseModel appApiResponseModel = new AppApiResponseModel();
        if(mAppApiResponse==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("更新数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppApiResponse,appApiResponseModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appApiResponseModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppApiResponse.AppApiResponse, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppApiResponse")
    Envelop deleteAppApiResponse(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id){
        Envelop envelop = new Envelop();
        Boolean isDelete  = appApiResponseClient.deleteAppApiResponse(id);
        envelop.setSuccessFlg(isDelete);
        return envelop;
    }
    /**
     * 格式化字典数据
     * @param appApiResponseModel
     */
    private void converModelName(AppApiResponseModel appApiResponseModel){
    }
}

+ 471 - 0
src/main/java/com/yihu/ehr/apps/controller/AppController.java

@ -0,0 +1,471 @@
package com.yihu.ehr.apps.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.agModel.dict.SystemDictEntryModel;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.apps.service.AppApiClient;
import com.yihu.ehr.model.app.MAppApi;
import com.yihu.ehr.model.dict.MDictionaryEntry;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.model.resource.MRsAppResource;
import com.yihu.ehr.model.resource.MRsResources;
import com.yihu.ehr.model.user.MRoleAppRelation;
import com.yihu.ehr.model.user.MRoles;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.resource.client.RsResourceClient;
import com.yihu.ehr.resource.client.RsResourceGrantClient;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.apps.service.AppClient;
import com.yihu.ehr.agModel.app.AppDetailModel;
import com.yihu.ehr.agModel.app.AppModel;
import com.yihu.ehr.model.app.MApp;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.systemdict.service.SystemDictClient;
import com.yihu.ehr.users.service.RoleAppRelationClient;
import com.yihu.ehr.users.service.RolesClient;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
 * Created by AndyCai on 2016/1/19.
 */
@RequestMapping(ApiVersion.Version1_0+"/admin" )
@RestController
@Api(value = "app", description = "应用管理接口", tags = {"应用管理接口"})
public class AppController extends BaseController {
    @Autowired
    private AppClient appClient;
    @Autowired
    private ConventionalDictEntryClient conDictEntryClient;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private OrganizationClient organizationClient;
    @Autowired
    private RsResourceGrantClient resourcesGrantClient;
    @Autowired
    private RsResourceClient resourcesClient;
    @Autowired
    private RoleAppRelationClient roleAppRelationClient;
    @Autowired
    private RolesClient rolesClient;
    @Autowired
    private AppApiClient appApiClient;
    @Autowired
    private SystemDictClient systemDictClient;
    @RequestMapping(value = "test", method = RequestMethod.GET)
    @ApiOperation(value = "获取app列表,不分页")
    public Envelop test() throws Exception {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        return envelop;
    }
    
    @RequestMapping(value = "/apps", method = RequestMethod.GET)
    @ApiOperation(value = "获取App列表")
    public Envelop getApps(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "-createTime")
            @RequestParam(value = "sort", required = false) String sort,
            @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 {
        List<AppModel> appModelList = new ArrayList<>();
        ResponseEntity<List<MApp>> responseEntity = appClient.getApps(fields,filters,sort,size,page);
        List<MApp> mAppList = responseEntity.getBody();
        for(MApp app :mAppList){
            appModelList.add(convertToAppModel(app));
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = getResult(appModelList,totalCount,page,size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Apps.AppsNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取app列表,不分页")
    public Envelop getAppsNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件",defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters) throws Exception {
        Envelop envelop = new Envelop();
        Collection<MApp> mAppList = appClient.getAppsNoPage(filters);
        List<AppModel> appModelList = new ArrayList<>();
        for(MApp app :mAppList){
            appModelList.add(convertToAppModel(app));
        }
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(appModelList);
        return envelop;
    }
    /**
     * @param appJson
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/apps", method = RequestMethod.POST)
    @ApiOperation(value = "创建App")
    public Envelop createApp(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true, defaultValue = "{\"name\": \"\", \"url\": \"\", \"catalog\": \"\", \"description\": \"\", \"creator\":\"\",\"icon\": \"\",\"releaseFlag\": \"\"}")
            @RequestParam(value = "app", required = false) String appJson) throws Exception {
        Envelop envelop = new Envelop();
        //传入的appJson里包含userId
        AppDetailModel appDetailModel = objectMapper.readValue(appJson,AppDetailModel.class);
        MApp app = convertToMApp(appDetailModel);
        MApp mApp = appClient.createApp(objectMapper.writeValueAsString(app));
        if(mApp == null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("app创建失败!");
        }else{
            String role =  appDetailModel.getRole();
            if(StringUtils.isNotBlank(role)){
                //role 为角色组ids,以逗号隔开
                roleAppRelationClient.batchCreateRoleAppRelation(mApp.getId(), role);
            }
            envelop.setSuccessFlg(true);
            envelop.setObj(convertToAppDetailModel(mApp));
        }
        return envelop;
    }
    @RequestMapping(value = "/apps/{app_id}", method = RequestMethod.GET)
    @ApiOperation(value = "获取App")
    public Envelop getApp(
            @ApiParam(name = "app_id", value = "id", defaultValue = "")
            @PathVariable(value = "app_id") String appId) throws Exception {
        Envelop envelop = new Envelop();
        MApp mApp = appClient.getApp(appId);
        if (mApp == null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("app获取失败");
        }else{
            //格式化角色
            if("0".equals(mApp.getSourceType()+"")){
                Collection<MRoleAppRelation> mRoleAppRelations =  roleAppRelationClient.searchRoleAppNoPaging("appId=" + appId);
                Map<String,Object> roleMap = new HashMap<>();
                for(MRoleAppRelation mRoleAppRelation:mRoleAppRelations){
                    MRoles mRoles =  rolesClient.getRolesById(mRoleAppRelation.getRoleId());
                    if(mRoles!=null){
                        roleMap.put(mRoles.getId()+"",mRoles.getName());
                    }
                }
               AppDetailModel appDetailModel =  convertToAppDetailModel(mApp);
                if(roleMap.keySet().size()>0){
                    appDetailModel.setRoleJson(toJson(roleMap));
                }
                envelop.setSuccessFlg(true);
                envelop.setObj(appDetailModel);
            }else{
                envelop.setSuccessFlg(true);
                envelop.setObj(convertToAppDetailModel(mApp));
            }
        }
        return envelop;
    }
    @RequestMapping(value = "/apps", method = RequestMethod.PUT)
    @ApiOperation(value = "更新App")
    public Envelop updateApp(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestParam(value = "app", required = false) String appJson) throws Exception {
        Envelop envelop = new Envelop();
        AppDetailModel appDetailModel = objectMapper.readValue(appJson,AppDetailModel.class);
        MApp app = convertToMApp(appDetailModel);
        MApp mApp = appClient.updateApp(objectMapper.writeValueAsString(app));
        if(mApp==null){
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("app更新失败!");
        }else{
            String role =  appDetailModel.getRole();
            if(StringUtils.isNotBlank(role)){
                //role 为角色组ids,以逗号隔开
                roleAppRelationClient.batchUpdateRoleAppRelation(mApp.getId(),role);
            }
            envelop.setSuccessFlg(true);
            envelop.setObj(convertToAppDetailModel(mApp));
        }
        return envelop;
    }
    @RequestMapping(value = "/apps/{app_id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除app")
    public Envelop deleteApp(
            @ApiParam(name = "app_id", value = "id", defaultValue = "")
            @PathVariable(value = "app_id") String app_id){
        try {
            boolean result = appClient.deleteApp(app_id);
            if(!result)
            {
                return failed("删除失败!");
            }
            return success(null);
        }
        catch (Exception ex)
        {
            return failedSystem();
        }
    }
    @RequestMapping(value = "/apps/status",method = RequestMethod.PUT)
    @ApiOperation(value = "修改状态")
    public boolean updateStatus(
            @ApiParam(name= "app_id",value = "app_id",defaultValue = "")
            @RequestParam(value = "app_id") String appId,
            @ApiParam(name = "app_status",value = "状态",defaultValue = "")
            @RequestParam(value = "app_status") String appStatus)throws Exception{
        return appClient.updateStatus(appId, appStatus);
    }
    @RequestMapping(value = "apps/existence/app_id/{app_id}",method = RequestMethod.GET)
    @ApiOperation(value = "验证app")
    public boolean isAppExistence(
            @ApiParam(name= "app_id",value = "app_id",defaultValue = "")
            @PathVariable(value = "app_id") String appId,
            @ApiParam(name = "secret",value = "密钥",defaultValue = "")
            @RequestParam(value = "secret") String secret)throws Exception{
        return appClient.isAppExists(appId, secret);
    }
    @RequestMapping(value = "apps/existence/app_name/{app_name}",method = RequestMethod.GET)
    @ApiOperation(value = "验证app名字是否存在")
    public boolean isAppNameExists(
            @ApiParam(value = "app_name")
            @PathVariable(value = "app_name") String appName){
        return appClient.isAppNameExists(appName);
    }
    /**
     *  将微服务返回的MApp转化为前端AppModel
     * @param mApp
     * @return AppModel
     */
    private AppModel convertToAppModel(MApp mApp) {
        if(mApp==null) {
            return null;
        }
        AppModel appModel = convertToModel(mApp, AppModel.class);
        //获取app类别字典值
        if(!StringUtils.isEmpty(mApp.getCatalog())){
            MConventionalDict catalogDict = conDictEntryClient.getAppCatalog(mApp.getCatalog());
            appModel.setCatalogName(catalogDict == null ? "" : catalogDict.getValue());
        }
        //获取状态字典值
        if(!StringUtils.isEmpty(mApp.getStatus())){
            MConventionalDict statusDict = conDictEntryClient.getAppStatus(mApp.getStatus());
            appModel.setStatusName(statusDict == null ? "" : statusDict.getValue());
        }
        //获取机构名称
        if(!StringUtils.isEmpty(mApp.getOrg())){
            MOrganization organization = organizationClient.getOrg(mApp.getOrg());
            appModel.setOrgName(organization == null ? "" : organization.getFullName());
        }
/*       update by zdm 20180505 此处根据应用已授权的资源rsIds获取资源,filters会出现过长,导致app查询失败。此处也不需要查看资源名称。所以注释。
        //获取已授权资源名称
        //根据appId获取授权资源rsIds
        //TODO 提供根据appId获取RsAppResourceModel集合接口来替代
        ResponseEntity<List<MRsAppResource>> responseEntity = resourcesGrantClient.queryAppResourceGrant("", "appId=" + mApp.getId(), "", 1, 999);
        List<MRsAppResource> rsAppResources = responseEntity.getBody();
        if(rsAppResources.size()==0){
            return appModel;
        }
        String rsIds = "";
        for (MRsAppResource m:rsAppResources){
            rsIds += m.getResourceId()+",";
        }
        rsIds = rsIds.substring(0,rsIds.length()-1);
        //根据rsIds获取资源对象集合-再获取资源名字字符串
        //TODO 提供查询资源不分页方法替代
        ResponseEntity<List<MRsResources>> entity = resourcesClient.queryResources("", "id=" + rsIds, "", 1, 999, null, null);
        List<MRsResources> mRsResources = entity.getBody();
        if(mRsResources.size() == 0){
            return appModel;
        }
        String rsNames = "";
        for(MRsResources m:mRsResources){
            rsNames += m.getName()+",";
        }
        rsNames = rsNames.substring(0,rsNames.length()-1);
        appModel.setResourceNames(rsNames);*/
        return appModel;
    }
    /**
     * 将微服务返回的MApp转化为前端显示的appDetailModel
     * @param mApp
     * @return
     */
    private AppDetailModel convertToAppDetailModel(MApp mApp){
        if(mApp==null)
        {
            return null;
        }
        AppDetailModel app = convertToModel(mApp, AppDetailModel.class);
        app.setCreateTime(DateToString(mApp.getCreateTime(), AgAdminConstants.DateTimeFormat));
        app.setAuditTime(DateToString(mApp.getAuditTime(),AgAdminConstants.DateTimeFormat));
        //获取app类别字典值
        if(!StringUtils.isEmpty(mApp.getCatalog())){
            MConventionalDict catalopDict = conDictEntryClient.getAppCatalog(mApp.getCatalog());
            app.setCatalogName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //获取app状态字典值
        if(!StringUtils.isEmpty(mApp.getStatus())){
            MConventionalDict statusDict = conDictEntryClient.getAppStatus(mApp.getStatus());
            app.setStatusName(statusDict == null ? "" : statusDict.getValue());
        }
        //获取机构名称
        if(!StringUtils.isEmpty(mApp.getOrg())){
            MOrganization organization = organizationClient.getOrg(mApp.getOrg());
            app.setOrgName(organization == null ? "" : organization.getFullName());
        }
     /*   MConventionalDict sourceType = conDictEntryClient.getApplicationSource(mApp.getSourceType()+"");
        app.setSourceTypeName(sourceType == null ? "" : sourceType.getValue());*/
        return app;
    }
    private MApp convertToMApp(AppDetailModel detailModel) {
        if(detailModel==null) {
            return null;
        }
        MApp mApp = convertToModel(detailModel,MApp.class);
        mApp.setCreateTime(StringToDate(detailModel.getCreateTime(),AgAdminConstants.DateTimeFormat));
        mApp.setAuditTime(StringToDate(detailModel.getAuditTime(),AgAdminConstants.DateTimeFormat));
        return mApp;
    }
    @RequestMapping(value = "/apps/filterList", method = RequestMethod.GET)
    @ApiOperation(value = "存在性校验")
    Envelop isExitAppFeature(
            @ApiParam(name = "filters", value = "filters", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters){
        Envelop envelop = new Envelop();
        try{
            Boolean isExit  = appClient.isExitApp(filters);
            envelop.setSuccessFlg(true);
            envelop.setObj(isExit);
        }catch (Exception e){
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/appsExitApi", method = RequestMethod.GET)
    @ApiOperation(value = "获取App列表")
    public Envelop getAppsExitApi(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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 {
        List<AppModel> appModelList = new ArrayList<>();
        Collection<MAppApi> mAppApis =  appApiClient.getAppApiNoPage("type=2");
        if(mAppApis!=null&&mAppApis.size()>0){
            StringBuffer buffer = new StringBuffer();
            for(MAppApi mAppApi: mAppApis){
                buffer.append(mAppApi.getAppId()).append(",");
            }
            String queryInfo = buffer.toString();
            queryInfo = queryInfo.substring(0,queryInfo.lastIndexOf(","));
            if(StringUtils.isNotBlank(filters)){
                filters+=";appId<>"+queryInfo;
            }else{
                filters="appId<>"+queryInfo;
            }
        }
        ResponseEntity<List<MApp>> responseEntity = appClient.getApps(fields,filters,sort,size,page);
        List<MApp> mAppList = responseEntity.getBody();
        for(MApp app :mAppList){
            appModelList.add(convertToAppModel(app));
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = getResult(appModelList,totalCount,page,size);
        return envelop;
    }
    @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) {
        Envelop envelop = new Envelop();
        //获取系统字典项(App类型)
        String filters="dictId="+1;
        String fields="";
        String sort="+sort";
        int size=999;
        int page=1;
        ResponseEntity<List<MDictionaryEntry>> responseEntity = systemDictClient.getDictEntries(fields, filters, sort, size, page);
        List<MDictionaryEntry> dictionaryEntries = responseEntity.getBody();
        List<SystemDictEntryModel> systemDictEntryModelList = (List<SystemDictEntryModel>) convertToModels(dictionaryEntries, new ArrayList<SystemDictEntryModel>(dictionaryEntries.size()), SystemDictEntryModel.class, null);
        List<SystemDictEntryModel> DictEntryModelList=new ArrayList<>();
        List<AppModel> appModelList=new ArrayList<>();
        Map<String,String> map=new HashedMap();
        if(null!=systemDictEntryModelList&&systemDictEntryModelList.size()>0){
            for(SystemDictEntryModel dict:systemDictEntryModelList){
                Collection<MApp> mAppList = appClient.getApps(userId, dict.getCode(), manageType);
                appModelList = (List<AppModel>) convertToModels(mAppList, new ArrayList<AppModel>(mAppList.size()), AppModel.class, null);
                dict.setChildren(appModelList);
                DictEntryModelList.add(dict);
            }
        }
        //应用列表
        envelop.setSuccessFlg(true);
        envelop.setDetailModelList(DictEntryModelList);
        return envelop;
    }
    @RequestMapping(value =  ServiceApi.Apps.CheckField, method = RequestMethod.POST)
    @ApiOperation(value = "根据条件判断应用ID或者名称是否存在")
    public Envelop isFieldExist(
            @ApiParam(name = "field", value = "字段", required = true)
            @RequestParam(value = "field") String field,
            @ApiParam(name = "value", value = "值", required = true)
            @RequestParam(value = "value") String value) {
        return appClient.isFieldExist(field, value);
    }
    @RequestMapping(value =  ServiceApi.Apps.AppAuthClient, method = RequestMethod.POST)
    @ApiOperation(value = "开放平台审核结果处理接口,包含App初始化和应用角色分配")
    public Envelop authClient(
            @ApiParam(name = "appJson", value = "App")
            @RequestParam(value = "appJson") String appJson,
            @ApiParam(name = "roleId", value = "角色ID")
            @RequestParam(value = "roleId") Integer roleId) throws Exception{
        return appClient.authClient(appJson, roleId);
    }
}

+ 285 - 0
src/main/java/com/yihu/ehr/apps/controller/AppFeatureController.java

@ -0,0 +1,285 @@
package com.yihu.ehr.apps.controller;
import com.yihu.ehr.agModel.app.AppFeatureModel;
import com.yihu.ehr.apps.service.AppFeatureClient;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.model.app.MAppFeature;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.user.MRoleFeatureRelation;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.users.service.RoleFeatureRelationClient;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 * Created by linz on 2016年7月8日11:30:18.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "AppFeature", description = "应用功能列表维护", tags = {"应用管理-应用功能列表维护"})
public class AppFeatureController extends BaseController {
    @Autowired
    AppFeatureClient appFeatureClient;
    @Autowired
    private ConventionalDictEntryClient conDictEntryClient;
    @Autowired
    private RoleFeatureRelationClient roleFeatureRelationClient;
    @RequestMapping(value = ServiceApi.AppFeature.AppFeatures, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature列表")
    public Envelop getAppFeatures(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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, @RequestParam(value = "roleId", required = false) String roleId) {
        ResponseEntity<List<MAppFeature>> responseEntity = appFeatureClient.getAppFeatures(fields, filters, sort, size, page);
        List<MAppFeature> mAppFeatureList = responseEntity.getBody();
        List<AppFeatureModel> appFeatureModels = new ArrayList<>();
        for (MAppFeature mAppFeature : mAppFeatureList) {
            AppFeatureModel appFeatureModel = new AppFeatureModel();
            BeanUtils.copyProperties(mAppFeature, appFeatureModel);
            appFeatureModel.setRoleId(roleId);
            converModelName(appFeatureModel);
            appFeatureModels.add(appFeatureModel);
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = getResult(appFeatureModels, totalCount, page, size);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeatures, method = RequestMethod.POST)
    @ApiOperation(value = "创建AppFeature")
    public Envelop createAppFeature(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestParam(value = "model", required = false) String model) {
        Envelop envelop = new Envelop();
        MAppFeature mAppFeature = appFeatureClient.createAppFeature(model);
        if (mAppFeature == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("保存失败!");
            return envelop;
        }
        AppFeatureModel appFeatureModel = new AppFeatureModel();
        BeanUtils.copyProperties(mAppFeature, appFeatureModel);
        converModelName(appFeatureModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appFeatureModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeature, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature")
    public Envelop getAppFeature(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        MAppFeature mAppFeature = appFeatureClient.getAppFeature(id);
        AppFeatureModel appFeatureModel = new AppFeatureModel();
        if (mAppFeature == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("获取数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppFeature, appFeatureModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appFeatureModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeatures, method = RequestMethod.PUT)
    @ApiOperation(value = "更新AppFeature")
    public Envelop updateAppFeature(
            @ApiParam(name = "model", value = "对象JSON结构体", allowMultiple = true)
            @RequestParam(value = "model", required = false) String appFeature) {
        Envelop envelop = new Envelop();
        MAppFeature mAppFeature = appFeatureClient.updateAppFeature(appFeature);
        AppFeatureModel appFeatureModel = new AppFeatureModel();
        if (mAppFeature == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("更新数据失败!");
            return envelop;
        }
        BeanUtils.copyProperties(mAppFeature, appFeatureModel);
        converModelName(appFeatureModel);
        envelop.setSuccessFlg(true);
        envelop.setObj(appFeatureModel);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.AppFeature, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppFeature")
    Envelop deleteAppFeature(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        Boolean isDelete = appFeatureClient.deleteAppFeature(id);
        envelop.setSuccessFlg(isDelete);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.FilterFeatureList, method = RequestMethod.GET)
    @ApiOperation(value = "存在性校验")
    Envelop isExitAppFeature(
            @ApiParam(name = "filters", value = "filters", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters) {
        Envelop envelop = new Envelop();
        try {
            Boolean isExit = appFeatureClient.isExitAppFeature(filters);
            envelop.setSuccessFlg(true);
            envelop.setObj(isExit);
        } catch (Exception e) {
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.FilterFeatureNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature排序后的列表(不分页)")
    public Envelop getAppFeatureNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "roleId", value = "角色ID")
            @RequestParam(value = "roleId", required = false) String roleId) {
        Collection<MAppFeature> mAppFeatures = appFeatureClient.getAppFeatureNoPageSorts(filters, sorts);
        Envelop envelop = new Envelop();
        List<AppFeatureModel> appFeatureModels = new ArrayList<>();
        for (MAppFeature mAppFeature : mAppFeatures) {
            AppFeatureModel appFeatureModel = convertToModel(mAppFeature, AppFeatureModel.class);
            if (StringUtils.isNotBlank(roleId)) {
                appFeatureModel.setRoleId(roleId);
            }
            converModelName(appFeatureModel);
            appFeatureModels.add(appFeatureModel);
        }
        envelop.setDetailModelList(appFeatureModels);
        return envelop;
    }
    @RequestMapping(value = "/role_app_feature/no_paging", method = RequestMethod.GET)
    @ApiOperation(value = "获取角色组的AppFeature列表")
    public Envelop getRoleAppFeatureNoPage(
            @ApiParam(name = "role_id", value = "角色组id")
            @RequestParam(value = "role_id") String roleId) {
        Collection<MRoleFeatureRelation> mRoleFeatureRelations = roleFeatureRelationClient.searchRoleFeatureNoPaging("roleId=" + roleId);
        String featureIds = "";
        String filters = "";
        for (MRoleFeatureRelation m : mRoleFeatureRelations) {
            featureIds += m.getFeatureId() + ",";
        }
        if (!StringUtils.isEmpty(featureIds)) {
            featureIds = featureIds.substring(0, featureIds.length() - 1);
        }
        if(StringUtils.isNotEmpty(featureIds)){
            filters = "id=" + featureIds;
        }
        Collection<MAppFeature> mAppFeatures = appFeatureClient.getAppFeatureNoPageSorts(filters, "+sort");
        Envelop envelop = new Envelop();
        List<AppFeatureModel> appFeatureModels = new ArrayList<>();
        for (MAppFeature mAppFeature : mAppFeatures) {
            AppFeatureModel appFeatureModel = convertToModel(mAppFeature, AppFeatureModel.class);
            appFeatureModels.add(appFeatureModel);
        }
        if (appFeatureModels.size() > 0) {
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(appFeatureModels);
            return envelop;
        }
        return failed("");
    }
    /**
     * 格式化字典数据
     *
     * @param appFeatureModel
     */
    private void converModelName(AppFeatureModel appFeatureModel) {
        //应用菜单类型
        if (!StringUtils.isEmpty(appFeatureModel.getType())) {
            MConventionalDict catalopDict = conDictEntryClient.getApplicationMenuType(appFeatureModel.getType());
            appFeatureModel.setTypeName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //审计等级
        if (!StringUtils.isEmpty(appFeatureModel.getAuditLevel())) {
            MConventionalDict catalopDict = conDictEntryClient.getAuditLevel(appFeatureModel.getAuditLevel());
            appFeatureModel.setAuditLevelName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //开放等级
        if (!StringUtils.isEmpty(appFeatureModel.getOpenLevel())) {
            MConventionalDict catalopDict = conDictEntryClient.getOpenLevel(appFeatureModel.getOpenLevel());
            appFeatureModel.setOpenLevelName(catalopDict == null ? "" : catalopDict.getValue());
        }
        //是否已经被角色组适配,界面适配用
        if (!StringUtils.isEmpty(appFeatureModel.getRoleId())) {
            ResponseEntity<Collection<MRoleFeatureRelation>> responseEntity = roleFeatureRelationClient.searchRoleFeature("", "roleId=" + appFeatureModel.getRoleId() + ";featureId=" + appFeatureModel.getId(), "", 1, 1);
            Collection<MRoleFeatureRelation> mRoleFeatureRelations = responseEntity.getBody();
            if (mRoleFeatureRelations != null && mRoleFeatureRelations.size() > 0) {
                appFeatureModel.setIschecked(true);
            } else {
                appFeatureModel.setIschecked(false);
            }
        }
    }
    @RequestMapping(value = "/AppFeatureFindUrl", method = RequestMethod.GET)
    @ApiOperation(value = "根据url获取对象")
    public Envelop AppFeatureFindUrl(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters) {
        Collection<MAppFeature> mAppFeatures = appFeatureClient.getAppFeatureNoPage(filters);
        Envelop envelop = new Envelop();
        List<AppFeatureModel> appFeatureModels = new ArrayList<>();
        if (mAppFeatures != null && mAppFeatures.size() > 0) {
            for (MAppFeature mAppFeature : mAppFeatures) {
                AppFeatureModel appFeatureModel = convertToModel(mAppFeature, AppFeatureModel.class);
                converModelName(appFeatureModel);
                appFeatureModels.add(appFeatureModel);
            }
            envelop.setSuccessFlg(true);
        }
        envelop.setDetailModelList(appFeatureModels);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.AppFeature.FindAppMenus, method = RequestMethod.GET)
    @ApiOperation(value = "根据权限,获取应用菜单")
    public Envelop 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) {
        try {
            Envelop envelop = new Envelop();
            List<Map<String, Object>> menuList = appFeatureClient.findAppMenus(appId, userId);
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(menuList);
            return envelop;
        } catch (Exception e) {
            return failed("获取应用菜单发生异常。");
        }
    }
}

+ 86 - 0
src/main/java/com/yihu/ehr/apps/service/AppApiClient.java

@ -0,0 +1,86 @@
package com.yihu.ehr.apps.service;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.app.MAppApi;
import com.yihu.ehr.model.app.MAppApiDetail;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
import java.util.List;
/**
 * Created by linz on 2016年7月8日11:30:03.
 */
@ApiIgnore
@FeignClient(name=MicroServices.Application)
public interface AppApiClient {
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApi.AppApis, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi列表")
    ResponseEntity<List<MAppApi>> getAppApis(
            @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);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApi.AppApis, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppApi")
    MAppApi createAppApi(
            @ApiParam(name = "AppApi", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestBody String AppApiJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApi.AppApi, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi")
    MAppApi getAppApi(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApi.AppApis, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppApi")
    MAppApi updateAppApi(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApi.AppApi, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppFeature")
    boolean deleteAppApi(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value =  ApiVersion.Version1_0 +ServiceApi.AppApi.AppApisNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取过滤App列表")
    public Collection<MAppApi> getAppApiNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApi.AppApiSearch, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApi列表")
    ResponseEntity<List<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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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);
}

+ 59 - 0
src/main/java/com/yihu/ehr/apps/service/AppApiParameterClient.java

@ -0,0 +1,59 @@
package com.yihu.ehr.apps.service;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.app.MAppApiParameter;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by linz on 2016年7月8日11:30:03.
 */
@FeignClient(name=MicroServices.Application)
public interface AppApiParameterClient {
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiParameter列表")
    ResponseEntity<List<MAppApiParameter>> getAppApiParameters(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppApiParameter")
    MAppApiParameter createAppApiParameter(
            @ApiParam(name = "AppApiParameter", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestBody String AppApiParameterJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiParameter")
    MAppApiParameter getAppApiParameter(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiParameter.AppApiParameters, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppApiParameter")
    MAppApiParameter updateAppApiParameter(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiParameter.AppApiParameter, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppFeature")
    boolean deleteAppApiParameter(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
}

+ 59 - 0
src/main/java/com/yihu/ehr/apps/service/AppApiResponseClient.java

@ -0,0 +1,59 @@
package com.yihu.ehr.apps.service;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.app.MAppApiResponse;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by linz on 2016年7月8日11:30:03.
 */
@FeignClient(name=MicroServices.Application)
public interface AppApiResponseClient {
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiResponse列表")
    ResponseEntity<List<MAppApiResponse>> getAppApiResponses(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppApiResponse")
    MAppApiResponse createAppApiResponse(
            @ApiParam(name = "AppApiResponse", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestBody String AppApiResponseJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiResponse.AppApiResponse, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppApiResponse")
    MAppApiResponse getAppApiResponse(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiResponse.AppApiResponses, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppApiResponse")
    MAppApiResponse updateAppApiResponse(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppApiResponse.AppApiResponse, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppFeature")
    boolean deleteAppApiResponse(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
}

+ 126 - 0
src/main/java/com/yihu/ehr/apps/service/AppClient.java

@ -0,0 +1,126 @@
package com.yihu.ehr.apps.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.app.MApp;
import com.yihu.ehr.model.app.MUserApp;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/19.
 */
@FeignClient(name=MicroServices.Application)
public interface AppClient {
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.Apps, method = RequestMethod.GET)
    @ApiOperation(value = "获取App列表")
    ResponseEntity<List<MApp>> getApps(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.AppsNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取app列表,不分页")
    Collection<MApp> getAppsNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件",defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.Apps, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建App")
    MApp createApp(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true, defaultValue = "{\"name\": \"\", \"url\": \"\", \"catalog\": \"\", \"description\": \"\", \"creator\":\"\",\"icon\": \"\",\"releaseFlag\": \"\"}")
            @RequestBody String appJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.getApp, method = RequestMethod.GET)
    @ApiOperation(value = "获取App")
    MApp getApp(
            @ApiParam(name = "app_id", value = "id", defaultValue = "")
            @RequestParam(value = "app_id") String appId);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.Apps, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新App")
    MApp updateApp(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.App, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除app")
    boolean deleteApp(
            @ApiParam(name = "app_id", value = "id", defaultValue = "")
            @PathVariable(value = "app_id") String app_id);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.AppStatus, method = RequestMethod.PUT)
    @ApiOperation(value = "修改状态")
    boolean updateStatus(
            @ApiParam(name = "app_id", value = "id", defaultValue = "")
            @PathVariable(value = "app_id") String appId,
            @ApiParam(name = "app_status", value = "状态", defaultValue = "")
            @RequestParam(value = "app_status") String appStatus);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.AppExistence, method = RequestMethod.GET)
    boolean isAppExists(
            @ApiParam(name = "app_id", value = "id", defaultValue = "")
            @PathVariable(value = "app_id") String appId,
            @ApiParam(name = "secret", value = "", defaultValue = "")
            @RequestParam(value = "secret") String secret);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.AppNameExistence, method = RequestMethod.GET)
    boolean isAppNameExists(
            @ApiParam(value = "app_name")
            @PathVariable(value = "app_name") String appName);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.FilterList, method = RequestMethod.GET)
    @ApiOperation(value = "存在性校验")
    boolean isExitApp(
            @ApiParam(name = "filters", value = "filters", defaultValue = "")
            @RequestParam(value = "filters") String filters);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.Apps.getApps, method = RequestMethod.GET)
    @ApiOperation(value = "根据条件,获取App列表")
    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:客户端。")
            @RequestParam(value = "manageType", required = false) String manageType);
    @RequestMapping(value =  ApiVersion.Version1_0 + ServiceApi.Apps.CheckField, method = RequestMethod.POST)
    @ApiOperation(value = "根据条件判断应用ID或者名称是否存在")
    Envelop isFieldExist(
            @ApiParam(name = "field", value = "字段", required = true)
            @RequestParam(value = "field") String field,
            @ApiParam(name = "value", value = "值", required = true)
            @RequestParam(value = "value") String value);
    @RequestMapping(value =  ApiVersion.Version1_0 + ServiceApi.Apps.AppAuthClient, method = RequestMethod.POST)
    @ApiOperation(value = "开放平台审核结果处理接口,包含App初始化和应用角色分配")
    Envelop authClient(
            @ApiParam(name = "appJson", value = "App")
            @RequestParam(value = "appJson") String appJson,
            @ApiParam(name = "roleId", value = "角色ID")
            @RequestParam(value = "roleId") Integer roleId);
    @RequestMapping(value = ApiVersion.Version1_0 +  ServiceApi.UserApp.CreateUserApp, method = RequestMethod.GET)
    @ApiOperation(value = "创建用户与app关联")
    MUserApp createUserApp(
            @ApiParam(name = "userAppJson", value = "用户APP对象json")
            @RequestParam(value = "userAppJson", required = true) String userAppJson);
}

+ 89 - 0
src/main/java/com/yihu/ehr/apps/service/AppFeatureClient.java

@ -0,0 +1,89 @@
package com.yihu.ehr.apps.service;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.app.MAppFeature;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 * Created by linz on 2016年7月8日11:30:03.
 */
@FeignClient(name = MicroServices.Application)
public interface AppFeatureClient {
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.AppFeatures, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature列表")
    ResponseEntity<List<MAppFeature>> getAppFeatures(
            @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 = "sort", value = "排序,规则参见说明文档", defaultValue = "")
            @RequestParam(value = "sort", required = false) String sort,
            @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);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.AppFeatures, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建AppFeature")
    MAppFeature createAppFeature(
            @ApiParam(name = "appFeature", value = "对象JSON结构体", allowMultiple = true, defaultValue = "")
            @RequestBody String appFeatureJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.AppFeature, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature")
    MAppFeature getAppFeature(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.AppFeatures, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "更新AppFeature")
    MAppFeature updateAppFeature(
            @ApiParam(name = "app", value = "对象JSON结构体", allowMultiple = true)
            @RequestBody String appJson);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.AppFeature, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除AppFeature")
    boolean deleteAppFeature(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.FilterFeatureList, method = RequestMethod.GET)
    @ApiOperation(value = "存在性校验")
    boolean isExitAppFeature(
            @ApiParam(name = "filters", value = "filters", defaultValue = "")
            @RequestParam(value = "filters") String filters);
    @RequestMapping(value = ApiVersion.Version1_0 + ServiceApi.AppFeature.FilterFeatureNoPage, method = RequestMethod.GET)
    @ApiOperation(value = "获取AppFeature列表(不分页)")
    public Collection<MAppFeature> getAppFeatureNoPage(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters);
    @RequestMapping(value = ApiVersion.Version1_0 + 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);
    @RequestMapping(value = ApiVersion.Version1_0 + 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);
}

+ 29 - 0
src/main/java/com/yihu/ehr/config/FeignMultipartSupportConfig.java

@ -0,0 +1,29 @@
package com.yihu.ehr.config;
import feign.codec.Encoder;
//import feign.form.spring.SpringFormEncoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
/**
 * Created by progr1mmer on 2017/12/16.
 */
//@Configuration
public class FeignMultipartSupportConfig {
    @Bean
    @Primary
    @Scope("prototype")
    public Encoder multipartFormEncoder() {
        return new SpringFormEncoder();
    }
    @Bean
    public feign.Logger.Level multipartLoggerLevel() {
        return feign.Logger.Level.FULL;
    }
}

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

@ -0,0 +1,27 @@
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);
            }
        };
    }
}

+ 70 - 0
src/main/java/com/yihu/ehr/device/client/DeviceClient.java

@ -0,0 +1,70 @@
package com.yihu.ehr.device.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.entity.device.Device;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @Author: zhengwei
 * @Date: 2018/5/4 15:47
 * @Description: 设备管理
 */
@ApiIgnore
@FeignClient(name = MicroServices.Basic)
@RequestMapping(ApiVersion.Version1_0)
public interface DeviceClient {
    @RequestMapping(value = ServiceApi.Device.DeviceList, method = RequestMethod.GET)
    @ApiOperation(value = "获取所有列表")
    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);
    @RequestMapping(value = ServiceApi.Device.DeviceSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存")
    Envelop save(
            @ApiParam(name = "device", value = "实体类Json")
            @RequestParam(value = "device") String device);
    @RequestMapping(value = ServiceApi.Device.DeviceDelete, method = RequestMethod.POST)
    @ApiOperation("删除记录")
    Envelop delete(
            @ApiParam(name = "ids", value = "id列表", required = true)
            @RequestParam(value = "ids") String ids);
    @RequestMapping(value = ServiceApi.Device.FindById, method = RequestMethod.GET)
    @ApiOperation("获取单条记录")
    Envelop findById(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.Device.DeviceBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入")
    boolean addBatch(
            @ApiParam(name = "devices", value = "实体类列表Json")
            @RequestParam(value = "devices") String devices);
}

+ 86 - 0
src/main/java/com/yihu/ehr/device/controller/DeviceController.java

@ -0,0 +1,86 @@
package com.yihu.ehr.device.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.device.client.DeviceClient;
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.*;
/**
 * @Author: zhengwei
 * @Date: 2018/5/4 15:47
 * @Description: 设备管理
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "DeviceController", description = "设备管理", tags = {"基础信息-设备管理"})
public class DeviceController extends BaseController {
    @Autowired
    private DeviceClient deviceClient;
    @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 {
        return deviceClient.list(fields, filters, sorts, page, size);
    }
    @RequestMapping(value = ServiceApi.Device.DeviceSave, method = RequestMethod.POST)
    @ApiOperation("保存")
    public Envelop save(
            @ApiParam(name = "device", value = "实体类Json")
            @RequestParam(value = "device") String device) throws Exception {
       return deviceClient.save(device);
    }
    @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 {
        return deviceClient.delete(ids);
    }
    @RequestMapping(value = ServiceApi.Device.FindById, method = RequestMethod.GET)
    @ApiOperation("获取单条记录")
    public Envelop findById(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") String id){
        return deviceClient.findById(id);
    }
    @RequestMapping(value = ServiceApi.Device.DeviceBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入")
    public Envelop addBatch(
            @ApiParam(name = "devices", value = "实体类列表Json")
            @RequestParam(value = "devices") String devices) throws Exception{
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        try{
            deviceClient.addBatch(devices);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("导入失败!"+e.getMessage());
        }
        return envelop;
    }
}

+ 75 - 0
src/main/java/com/yihu/ehr/dfs/client/ElasticSearchClient.java

@ -0,0 +1,75 @@
package com.yihu.ehr.dfs.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Client - Es搜索服务
 * Created by progr1mmer on 2017/12/2.
 */
@ApiIgnore
@FeignClient(name = MicroServices.Dfs)
@RequestMapping(ApiVersion.Version1_0)
public interface ElasticSearchClient {
    @RequestMapping(value = ServiceApi.ElasticSearch.Mapping, method = RequestMethod.POST)
    @ApiOperation(value = "建立索引")
    Envelop mapping(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @RequestParam(value = "source") String source);
    @RequestMapping(value = ServiceApi.ElasticSearch.Index, method = RequestMethod.POST)
    @ApiOperation(value = "添加数据")
    Envelop index(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @RequestParam(value = "source") String source);
    @RequestMapping(value = ServiceApi.ElasticSearch.Delete, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除数据")
    Envelop delete(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.ElasticSearch.Update, method = RequestMethod.PUT)
    @ApiOperation(value = "更新数据")
    Envelop update(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @RequestParam(value = "id") String id,
            @RequestParam(value = "source") String source);
    @RequestMapping(value = ServiceApi.ElasticSearch.FindById, method = RequestMethod.GET)
    @ApiOperation(value = "获取单条数据")
    Envelop findById(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @PathVariable(value = "id") String id);
    @RequestMapping(value = ServiceApi.ElasticSearch.FindByField, method = RequestMethod.GET)
    @ApiOperation(value = "获取结果集")
    Envelop findByField(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @RequestParam(value = "field") String field,
            @RequestParam(value = "value") String value);
    @RequestMapping(value = ServiceApi.ElasticSearch.Page, method = RequestMethod.GET)
    @ApiOperation(value = "获取结果集")
    Envelop page(
            @RequestParam(value = "index") String index,
            @RequestParam(value = "type") String type,
            @RequestParam(value = "filter", required = false) String filter,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
}

+ 98 - 0
src/main/java/com/yihu/ehr/dfs/client/FastDFSClient.java

@ -0,0 +1,98 @@
package com.yihu.ehr.dfs.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Client - 文件服务
 * Created by progr1mmer on 2017/12/1.
 */
@ApiIgnore
@FeignClient(name = MicroServices.Dfs)
@RequestMapping(ApiVersion.Version1_0)
public interface FastDFSClient {
    @RequestMapping(value = ServiceApi.FastDFS.Upload, method = RequestMethod.POST)
    @ApiOperation(value = "文件上传", notes = "返回相关索引信息,以及HttpUrl下载连接")
    Envelop upload(
            @RequestPart(value = "file") MultipartFile file,
            @RequestParam(value = "creator") String creator,
            @RequestParam(value = "objectId") String objectId);
    @RequestMapping(value = ServiceApi.FastDFS.OldUpload, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "文件上传", notes = "返回相关索引信息,以及HttpUrl下载连接(兼容旧接口)")
    Envelop upload(
            @RequestBody String jsonData);
    @RequestMapping(value = ServiceApi.FastDFS.DeleteById, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastDfs相对应文件")
    Envelop deleteById(
            @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.FastDFS.DeleteByPath, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastDfs相对应文件")
    Envelop deleteByPath(
            @RequestParam(value = "path") String path);
    @RequestMapping(value = ServiceApi.FastDFS.DeleteByObjectId, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastDfs相对应文件")
    Envelop deleteByObjectId(
            @RequestParam(value = "objectId") String objectId);
    @RequestMapping(value = ServiceApi.FastDFS.FileInfo, method = RequestMethod.GET)
    @ApiOperation(value = "获取文件信息")
    Envelop getFileInfo(
            @RequestParam(value = "path") String path);
    @RequestMapping(value = ServiceApi.FastDFS.DownloadById, method = RequestMethod.GET)
    @ApiOperation(value = "下载文件(byId)")
    Envelop downloadById (
            @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.FastDFS.DeleteByPath, method = RequestMethod.GET)
    @ApiOperation(value = "下载文件(byPath)")
    Envelop downloadByPath(
            @RequestParam(value = "path") String path);
    @RequestMapping(value = ServiceApi.FastDFS.DownloadByObjectId, method = RequestMethod.GET)
    @ApiOperation(value = "下载文件(byObjectId)")
    Envelop downloadByObjectId(
            @RequestParam(value = "objectId") String objectId);
    @RequestMapping(value = ServiceApi.FastDFS.GetFilePath, method = RequestMethod.GET)
    @ApiOperation(value = "获取文件路径(byObjectId)")
    Envelop getFilePath(
            @RequestParam(value = "objectId") String objectId);
    @RequestMapping(value = ServiceApi.FastDFS.Page, method = RequestMethod.GET)
    @ApiOperation(value = "获取结果集")
    Envelop page(
            @RequestParam(value = "filter", required = false) String filter,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = "/fastDfs/status", method = RequestMethod.GET)
    @ApiOperation(value = "获取服务器状态信息")
    Envelop status();
    @RequestMapping(value = ServiceApi.FastDFS.GetPublicUrl, method = RequestMethod.GET)
    @ApiOperation(value = "获取外链地址")
    Envelop getPublicUrl();
    @RequestMapping(value = ServiceApi.FastDFS.SetPublicUrl, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "设置外链地址")
    Envelop setPublicUrl(
            @RequestBody String jsonData);
}

+ 136 - 0
src/main/java/com/yihu/ehr/dfs/controller/ElasticSearchController.java

@ -0,0 +1,136 @@
package com.yihu.ehr.dfs.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.dfs.client.ElasticSearchClient;
import com.yihu.ehr.quota.service.TjQuotaJobClient;
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.*;
/**
 * EndPoint - Es搜索服务
 * Created by progr1mmer on 2017/12/2.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "ElasticSearchController", description = "Es搜索服务", tags = {"分布式综合服务-Es搜索服务"})
public class ElasticSearchController extends EnvelopRestEndPoint {
    @Autowired
    private ElasticSearchClient elasticSearchClient;
    @Autowired
    private TjQuotaJobClient tjQuotaJobClient;
    @RequestMapping(value = ServiceApi.ElasticSearch.Mapping, method = RequestMethod.POST)
    @ApiOperation(value = "建立索引")
    public Envelop mapper(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "source", value = "Json串值", required = true)
            @RequestParam(value = "source") String source) {
        return elasticSearchClient.mapping(index, type, source);
    }
    @RequestMapping(value = ServiceApi.ElasticSearch.Index, method = RequestMethod.POST)
    @ApiOperation(value = "添加数据")
    public Envelop index(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "source", value = "值", required = true)
            @RequestParam(value = "source") String source) {
        return elasticSearchClient.index(index, type, source);
    }
    @RequestMapping(value = ServiceApi.ElasticSearch.Delete, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除数据")
    public Envelop delete(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "id", value = "id(多个id值以,分隔)", required = true)
            @RequestParam(value = "id") String id) {
        return elasticSearchClient.delete(index, type, id);
    }
    @RequestMapping(value = ServiceApi.ElasticSearch.Update, method = RequestMethod.PUT)
    @ApiOperation(value = "更新数据")
    public Envelop update(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id,
            @ApiParam(name = "source", value = "值", required = true)
            @RequestParam(value = "source") String source) {
        return elasticSearchClient.update(index, type, id, source);
    }
    @RequestMapping(value = ServiceApi.ElasticSearch.FindById, method = RequestMethod.GET)
    @ApiOperation(value = "获取单条数据")
    public Envelop findById(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "id", value = "id", required = true)
            @PathVariable(value = "id") String id) {
        return elasticSearchClient.findById(index, type, id);
    }
    @RequestMapping(value = ServiceApi.ElasticSearch.FindByField, method = RequestMethod.GET)
    @ApiOperation(value = "获取结果集")
    public Envelop findByField(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "field", value = "字段", required = true)
            @RequestParam(value = "field") String field,
            @ApiParam(name = "value", value = "字段值", required = true)
            @RequestParam(value = "value") String value) {
        return elasticSearchClient.findByField(index, type, field, value);
    }
    @RequestMapping(value = ServiceApi.ElasticSearch.Page, method = RequestMethod.GET)
    @ApiOperation(value = "获取结果集")
    public Envelop page(
            @ApiParam(name = "index", value = "索引名称", required = true)
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型", required = true)
            @RequestParam(value = "type") String type,
            @ApiParam(name = "filter", value = "过滤条件")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "page", value = "页码", required = true)
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "分页大小", required = true)
            @RequestParam(value = "size") int size) {
        return elasticSearchClient.page(index, type, filter, page, size);
    }
    @RequestMapping(value = "/elasticSearch/addElasticSearch", method = RequestMethod.POST)
    @ApiOperation("elasticsearch文档数据")
    public Envelop addElasticSearch(
            @ApiParam(name = "index", value = "索引名称")
            @RequestParam(value = "index") String index,
            @ApiParam(name = "type", value = "索引类型")
            @RequestParam(value = "type") String type,
            @ApiParam(name = "sourceList", value = "值")
            @RequestParam(value = "sourceList") String sourceList) throws Exception {
        Envelop envelop = new Envelop();
        boolean flag = tjQuotaJobClient.addElasticSearch(index, type, sourceList);
        envelop.setSuccessFlg(flag);
        return envelop;
    }
}

+ 225 - 0
src/main/java/com/yihu/ehr/dfs/controller/FastDFSController.java

@ -0,0 +1,225 @@
package com.yihu.ehr.dfs.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.dfs.client.FastDFSClient;
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 org.springframework.web.multipart.MultipartFile;
/**
 * EndPoint - 文件服务
 * Created by progr1mmer on 2017/12/1.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "FastDFSController", description = "FastDFS服务", tags = {"分布式综合服务-FastDfs服务"})
public class FastDFSController extends EnvelopRestEndPoint {
    @Autowired
    private FastDFSClient fastDFSClient;
    /**
     * 文件上传 - 返回相关索引信息,以及HttpUrl下载连接
     * @param file
     * @param creator
     * @param objectId
     * @return
     */
    @RequestMapping(value = ServiceApi.FastDFS.Upload, method = RequestMethod.POST)
    @ApiOperation(value = "文件上传", notes = "返回相关索引信息,以及HttpUrl下载连接")
    public Envelop upload(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestPart(value = "file") MultipartFile file,
            @ApiParam(name = "creator", value = "创建者", required = true)
            @RequestParam(value = "creator") String creator,
            @ApiParam(name = "objectId", value = "创建者标识", required = true, defaultValue = "EHR")
            @RequestParam(value = "objectId") String objectId) {
        return fastDFSClient.upload(file, creator, objectId);
    }
    /**
     * 文件上传 - 返回相关索引信息,以及HttpUrl下载连接(兼容旧接口)
     * @param jsonData
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.OldUpload, method = RequestMethod.POST)
    @ApiOperation(value = "上传文件", notes = "返回相关索引信息,以及HttpUrl下载连接(兼容旧接口)")
    public Envelop upload(
            @ApiParam(name = "jsonData", value = "文件资源", required = true)
            @RequestParam(value = "jsonData") String jsonData) {
        return fastDFSClient.upload(jsonData);
    }
    /**
     * 删除资源表对应关系,并且删除fastDfs相对应当文件
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.DeleteById, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastDfs相对应文件")
    public Envelop deleteById(
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id) {
        return fastDFSClient.deleteById(id);
    }
    /**
     * 删除资源表对应关系,并且删除fastDfs相对应当文件
     * @param path
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.DeleteByPath, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastDfs相对应文件")
    public Envelop deleteByPath(
            @ApiParam(name = "path", value = "文件路径", required = true)
            @RequestParam(value = "path") String path) {
        return fastDFSClient.deleteByPath(path);
    }
    /**
     * 删除资源表对应关系,并且删除fastDfs相对应当文件
     * @param objectId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.DeleteByObjectId, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastDfs相对应文件")
    public Envelop deleteByObjectId(
            @ApiParam(name = "objectId", value = "对象ID", required = true)
            @RequestParam(value = "objectId") String objectId) {
        return fastDFSClient.deleteByObjectId(objectId);
    }
    /**
     * 获取文件信息
     * @param path
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.FileInfo, method = RequestMethod.GET)
    @ApiOperation(value = "获取文件信息")
    public Envelop getFileInfo(
            @ApiParam(name = "path", value = "路径", required = true)
            @RequestParam(value = "path") String path) {
        return fastDFSClient.getFileInfo(path);
    }
    /**
     * 下载文件
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.DownloadById, method = RequestMethod.GET)
    @ApiOperation(value = "下载文件(byId)")
    public Envelop downloadById (
            @ApiParam(name = "id", value = "id", required = true)
            @RequestParam(value = "id") String id) {
        return fastDFSClient.downloadById(id);
    }
    /**
     * 下载文件
     * @param path
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.DownloadByPath, method = RequestMethod.GET)
    @ApiOperation(value = "下载文件(byPath)")
    public Envelop downloadByPath(
            @ApiParam(name = "path", value = "文件路径", required = true)
            @RequestParam(value = "path") String path) {
       return fastDFSClient.downloadByPath(path);
    }
    /**
     * 下载文件
     * @param objectId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.DownloadByObjectId, method = RequestMethod.GET)
    @ApiOperation(value = "下载文件(byObjectId)")
    public Envelop downloadByObjectId(
            @ApiParam(name = "objectId", value = "对象ID", required = true)
            @RequestParam(value = "objectId") String objectId) {
        return fastDFSClient.downloadByObjectId(objectId);
    }
    /**
     * 获取文件下载路径
     * @param objectId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.GetFilePath, method = RequestMethod.GET)
    @ApiOperation(value = "获取文件路径(byObjectId)")
    public Envelop getFilePath(
            @ApiParam(name = "objectId", value = "对象ID", required = true)
            @RequestParam(value = "objectId") String objectId) {
       return fastDFSClient.getFilePath(objectId);
    }
    /**
     * 获取分页
     * @param filter
     * @param page
     * @param size
     * @return
     * @throws Exception
     */
    @RequestMapping(value = ServiceApi.FastDFS.Page, method = RequestMethod.GET)
    @ApiOperation(value = "获取结果集")
    public Envelop page(
            @ApiParam(name = "filter", value = "过滤条件")
            @RequestParam(value = "filter", required = false) String filter,
            @ApiParam(name = "page", value = "页码", required = true)
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "分页大小", required = true)
            @RequestParam(value = "size") int size) {
        return fastDFSClient.page(filter, page, size);
    }
    /**
     * 获取服务器状态信息
     * @return
     */
    @RequestMapping(value = ServiceApi.FastDFS.Status, method = RequestMethod.GET)
    @ApiOperation(value = "获取服务器状态信息")
    public Envelop status() {
        return fastDFSClient.status();
    }
    /**
     * 获取外链地址
     * @return
     */
    @RequestMapping(value = ServiceApi.FastDFS.GetPublicUrl, method = RequestMethod.GET)
    @ApiOperation(value = "获取外链地址")
    public Envelop getPublicUrl() {
        return fastDFSClient.getPublicUrl();
    }
    /**
     * 设置外链地址
     * @return
     */
    @RequestMapping(value = ServiceApi.FastDFS.SetPublicUrl, method = RequestMethod.POST)
    @ApiOperation(value = "设置外链地址")
    public Envelop setPublicUrl(
            @ApiParam(name = "jsonData", value = "字典项JSON结构")
            @RequestParam(value = "jsonData") String jsonData) {
        return fastDFSClient.setPublicUrl(jsonData);
    }
}

+ 82 - 0
src/main/java/com/yihu/ehr/emergency/client/AmbulanceClient.java

@ -0,0 +1,82 @@
package com.yihu.ehr.emergency.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Client - 救护车信息
 * Created by progr1mmer on 2017/11/8.
 */
@ApiIgnore
@FeignClient(name = MicroServices.Basic)
@RequestMapping(ApiVersion.Version1_0)
public interface AmbulanceClient{
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceList, method = RequestMethod.GET)
    @ApiOperation(value = "获取所有救护车列表")
    Envelop list(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceSearch, method = RequestMethod.GET)
    @ApiOperation(value = "查询救护车信息,包括执勤人员信息")
    Envelop search(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceUpdateStatus, method = RequestMethod.PUT)
    @ApiOperation(value = "更新救护车状态信息")
    Envelop updateStatus(
            @RequestParam(value = "carId") String carId,
            @RequestParam(value = "status") String status);
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存单条记录")
    Envelop save(
            @RequestBody String ambulance);
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("更新单条记录")
    Envelop update(
            @RequestBody String ambulance);
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除记录")
    Envelop delete(
            @RequestParam(value = "ids") String ids);
    @RequestMapping(value = ServiceApi.Emergency.Ambulance, method = RequestMethod.GET)
    @ApiOperation("获取单条记录")
    Envelop findById(
            @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceIdOrPhoneExistence, method = RequestMethod.POST)
    @ApiOperation("获取已存在车牌号、电话号码")
    List idExistence(
            @ApiParam(name = "type", value = "字段名")
            @RequestParam(value = "type") String type,
            @ApiParam(name = "values", value = "值")
            @RequestParam(value = "values") String values);
    @RequestMapping(value = ServiceApi.Emergency.AmbulancesBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入救护车")
    boolean createAmbulancesBatch(
            @RequestBody String ambulances);
}

+ 79 - 0
src/main/java/com/yihu/ehr/emergency/client/AttendanceClient.java

@ -0,0 +1,79 @@
package com.yihu.ehr.emergency.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Client - 出勤记录
 * Created by progr1mmer on 2017/11/8.
 */
@ApiIgnore
@FeignClient(name = MicroServices.Basic)
@RequestMapping(ApiVersion.Version1_0)
public interface AttendanceClient {
    @RequestMapping(value = ServiceApi.Emergency.AttendanceSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "保存出勤记录")
    Envelop save(
            @RequestBody String attendance);
    @RequestMapping(value = ServiceApi.Emergency.AttendanceUpdate, method = RequestMethod.PUT)
    @ApiOperation(value = "更新出勤记录")
    Envelop update(
            @RequestParam(value = "carId") String carId,
            @RequestParam(value = "status") String status);
    @RequestMapping(value = ServiceApi.Emergency.AttendanceEdit, method = RequestMethod.PUT)
    @ApiOperation("编辑出勤记录")
    Envelop edit(
            @RequestBody String attendance);
    @RequestMapping(value = ServiceApi.Emergency.AttendanceList, method = RequestMethod.GET)
    @ApiOperation("获取出勤列表")
    Envelop list(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = ServiceApi.Emergency.AttendanceDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除出勤记录")
    Envelop delete(
            @ApiParam(name = "ids", value = "id列表[1,2,3...] int")
            @RequestParam(value = "ids") String ids);
    @RequestMapping(value = ServiceApi.Emergency.AttendanceDetail, method = RequestMethod.GET)
    @ApiOperation("出勤记录详情")
    Envelop detail(
            @ApiParam(name = "id", value = "出勤记录id")
            @RequestParam(value = "id") String id);
    @RequestMapping(value = ServiceApi.Emergency.AttendanceAnalysis, method = RequestMethod.GET)
    @ApiOperation("出勤记录分析")
    Envelop analysis();
    @RequestMapping(value = "/attendance/queryChart1", method = RequestMethod.GET)
    @ApiOperation("出车次数分析")
    Envelop queryChart1(
            @ApiParam(name = "flag", value = "查询类型月、季、年(1,2,3)")
            @RequestParam(value = "flag") String flag);
    @RequestMapping(value = "/attendance/queryChart3", method = RequestMethod.GET)
    @ApiOperation("出勤地点热力图")
    Envelop queryChart3();
}

+ 54 - 0
src/main/java/com/yihu/ehr/emergency/client/LocationClient.java

@ -0,0 +1,54 @@
package com.yihu.ehr.emergency.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Client - 待命地点
 * Created by progr1mmer on 2017/11/22.
 */
@ApiIgnore
@FeignClient(name = MicroServices.Basic)
@RequestMapping(ApiVersion.Version1_0)
public interface LocationClient {
    @RequestMapping(value = ServiceApi.Emergency.LocationList, method = RequestMethod.GET)
    @ApiOperation("获取待命地点列表")
    Envelop list(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = ServiceApi.Emergency.LocationSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存单条记录")
    Envelop save(
            @ApiParam(name = "location", value = "待命地点")
            @RequestBody String location);
    @RequestMapping(value = ServiceApi.Emergency.LocationUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("更新单条记录")
    Envelop update(
            @ApiParam(name = "location", value = "排班")
            @RequestBody String location);
    @RequestMapping(value = ServiceApi.Emergency.LocationDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除待命地点")
    Envelop delete(
            @ApiParam(name = "ids", value = "id列表[1,2,3...] int")
            @RequestParam(value = "ids") String ids);
}

+ 67 - 0
src/main/java/com/yihu/ehr/emergency/client/ScheduleClient.java

@ -0,0 +1,67 @@
package com.yihu.ehr.emergency.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Client - 排班历史
 * Created by progr1mmer on 2017/11/8.
 */
@ApiIgnore
@FeignClient(name = MicroServices.Basic)
@RequestMapping(ApiVersion.Version1_0)
public interface ScheduleClient {
    @RequestMapping(value = ServiceApi.Emergency.ScheduleList, method = RequestMethod.GET)
    @ApiOperation("获取排班列表")
    Envelop list(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = ServiceApi.Emergency.ScheduleLevel, method = RequestMethod.GET)
    @ApiOperation("获取排班层级列表(年-月-日)")
    Envelop level(
            @RequestParam(value = "date", required = false) String date,
            @RequestParam(value = "page") int page,
            @RequestParam(value = "size") int size);
    @RequestMapping(value = ServiceApi.Emergency.ScheduleSave, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("保存单条记录")
    Envelop save(
            @ApiParam(name = "schedule", value = "排班")
            @RequestBody String schedule);
    @RequestMapping(value = ServiceApi.Emergency.ScheduleUpdate, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation("更新单条记录")
    Envelop update(
            @ApiParam(name = "schedule", value = "排班")
            @RequestBody String schedule);
    @RequestMapping(value = ServiceApi.Emergency.ScheduleBathUpdate, method = RequestMethod.PUT)
    @ApiOperation("更新多条数据")
    Envelop bathUpdate(
            @ApiParam(name = "schedules", value = "排班")
            @RequestParam(value = "schedules") String schedules);
    @RequestMapping(value = ServiceApi.Emergency.ScheduleBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入排班信息")
    boolean createSchedulesBatch(
            @ApiParam(name = "schedules", value = "排班")
            @RequestParam(value = "schedules") String schedules);
}

+ 131 - 0
src/main/java/com/yihu/ehr/emergency/controller/AmbulanceController.java

@ -0,0 +1,131 @@
package com.yihu.ehr.emergency.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.emergency.client.AmbulanceClient;
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;
/**
 * Controller - 救护车信息
 * Created by progr1mmer on 2017/11/8.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "AmbulanceController", description = "救护车信息", tags = {"应急指挥-救护车信息"})
public class AmbulanceController extends BaseController {
    @Autowired
    private AmbulanceClient ambulanceClient;
    @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) {
        return ambulanceClient.list(fields, filters, sorts, page, size);
    }
    @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) {
        return ambulanceClient.search(fields, filters, sorts, page, size);
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceUpdateStatus, method = RequestMethod.PUT)
    @ApiOperation(value = "更新救护车状态信息")
    public Envelop update(
            @ApiParam(name = "carId", value = "车牌号码")
            @RequestParam(value = "carId") String carId,
            @ApiParam(name = "status", value = "车辆状态码(0为统一可用状态码,1为统一不可用状态码)")
            @RequestParam(value = "status") String status) {
        return ambulanceClient.updateStatus(carId, status);
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceSave, method = RequestMethod.POST)
    @ApiOperation("保存单条记录")
    public Envelop save(
            @ApiParam(name = "ambulance", value = "救护车")
            @RequestParam(value = "ambulance") String ambulance){
        return ambulanceClient.save(ambulance);
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceUpdate, method = RequestMethod.PUT)
    @ApiOperation("更新单条记录")
    public Envelop update(
            @ApiParam(name = "ambulance", value = "救护车")
            @RequestParam(value = "ambulance") String ambulance){
        return ambulanceClient.update(ambulance);
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulanceDelete, method = RequestMethod.DELETE)
    @ApiOperation("删除记录")
    public Envelop delete(
            @ApiParam(name = "ids", value = "id列表xxxx,xxxx,xxxx,...")
            @RequestParam(value = "ids") String ids){
        return ambulanceClient.delete(ids);
    }
    @RequestMapping(value = ServiceApi.Emergency.Ambulance, method = RequestMethod.GET)
    @ApiOperation("获取单条记录")
    public Envelop findById(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") String id){
        return ambulanceClient.findById(id);
    }
    @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 vals = ambulanceClient.idExistence(type, values);
        return vals;
    }
    @RequestMapping(value = ServiceApi.Emergency.AmbulancesBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入救护车")
    public Envelop createAmbulancesBatch(
            @ApiParam(name = "ambulances", value = "救护车", defaultValue = "")
            @RequestParam(value = "ambulances") String ambulances) throws Exception {
        Envelop envelop = new Envelop();
        try{
            ambulanceClient.createAmbulancesBatch(ambulances);
            envelop.setSuccessFlg(true);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("导入失败!" + e.getMessage());
        }
        return envelop;
    }
}

+ 108 - 0
src/main/java/com/yihu/ehr/emergency/controller/AttendanceController.java

@ -0,0 +1,108 @@
package com.yihu.ehr.emergency.controller;
import com.netflix.eureka.V1AwareInstanceInfoConverter;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.emergency.client.AttendanceClient;
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;
/**
 * Controller - 出勤记录
 * Created by progr1mmer on 2017/11/8.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "AttendanceController", description = "出勤记录", tags = {"应急指挥-出勤记录"})
public class AttendanceController extends BaseController {
    @Autowired
    private AttendanceClient attendanceClient;
    @RequestMapping(value = ServiceApi.Emergency.AttendanceSave, method = RequestMethod.POST)
    @ApiOperation(value = "保存出勤记录")
    public Envelop save(
            @ApiParam(name = "attendance", value = "出勤记录")
            @RequestParam(value = "attendance") String attendance) {
        return attendanceClient.save(attendance);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceUpdate, method = RequestMethod.PUT)
    @ApiOperation(value = "更新出勤记录")
    public Envelop update(
            @ApiParam(name = "carId", value = "车牌号码")
            @RequestParam(value = "carId") String carId,
            @ApiParam(name = "status", value = "任务状态")
            @RequestParam(value = "status") String status) {
        return attendanceClient.update(carId, status);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceEdit, method = RequestMethod.PUT)
    @ApiOperation("编辑出勤记录")
    public Envelop edit(
            @ApiParam(name = "attendance", value = "出勤记录")
            @RequestParam(value = "attendance") String attendance) {
        return attendanceClient.edit(attendance);
    }
    @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) {
        return attendanceClient.list(fields, filters, sorts, page, size);
    }
    @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){
        return attendanceClient.delete(ids);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceDetail, method = RequestMethod.GET)
    @ApiOperation("出勤记录详情")
    public Envelop detail(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") String id){
        return attendanceClient.detail(id);
    }
    @RequestMapping(value = ServiceApi.Emergency.AttendanceAnalysis, method = RequestMethod.GET)
    @ApiOperation("出勤记录分析")
    public Envelop analysis(){
        return attendanceClient.analysis();
    }
    @RequestMapping(value = "/attendance/queryChart1", method = RequestMethod.GET)
    @ApiOperation("出车次数分析")
    public Envelop queryChart1(
            @ApiParam(name = "flag", value = "查询类型月、季、年(1,2,3)")
            @RequestParam(value = "flag") String flag){
        return attendanceClient.queryChart1(flag);
    }
    @RequestMapping(value = "/attendance/queryChart3", method = RequestMethod.GET)
    @ApiOperation("出勤地点热力图")
    public Envelop queryChart3(){
        return attendanceClient.queryChart3();
    }
}

+ 68 - 0
src/main/java/com/yihu/ehr/emergency/controller/LocationController.java

@ -0,0 +1,68 @@
package com.yihu.ehr.emergency.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseRestEndPoint;
import com.yihu.ehr.emergency.client.LocationClient;
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.List;
/**
 * Controller - 待命地点
 * Created by progr1mmer on 2017/11/22.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "LocationController", description = "待命地点", tags = {"应急指挥-待命地点"})
public class LocationController extends BaseRestEndPoint {
    @Autowired
    private LocationClient locationClient;
    @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) {
        return locationClient.list(fields, filters, sorts, page, size);
    }
    @RequestMapping(value = ServiceApi.Emergency.LocationSave, method = RequestMethod.POST)
    @ApiOperation("保存单条记录")
    public Envelop save(
            @ApiParam(name = "location", value = "待命地点")
            @RequestParam(value = "location") String location){
        return locationClient.save(location);
    }
    @RequestMapping(value = ServiceApi.Emergency.LocationUpdate, method = RequestMethod.PUT)
    @ApiOperation("更新单条记录")
    public Envelop update(
            @ApiParam(name = "location", value = "排班")
            @RequestParam(value = "location") String location){
        return locationClient.update(location);
    }
    @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){
        return locationClient.delete(ids);
    }
}

+ 100 - 0
src/main/java/com/yihu/ehr/emergency/controller/ScheduleController.java

@ -0,0 +1,100 @@
package com.yihu.ehr.emergency.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.emergency.client.ScheduleClient;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Controller - 排班历史
 * Created by progr1mmer on 2017/11/8.
 */
@RestController
@RequestMapping(ApiVersion.Version1_0 + ServiceApi.GateWay.admin)
@Api(value = "ScheduleController", description = "排班历史", tags = {"应急指挥-排班历史"})
public class ScheduleController extends BaseController {
    @Autowired
    private ScheduleClient scheduleClient;
    @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) {
        return scheduleClient.list(fields, filters, sorts, page, size);
    }
    @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) {
        return scheduleClient.level(date, page, size);
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleSave, method = RequestMethod.POST)
    @ApiOperation("保存单条记录")
    public Envelop save(
            @ApiParam(name = "schedule", value = "排班")
            @RequestParam(value = "schedule") String schedule){
        return scheduleClient.save(schedule);
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleUpdate, method = RequestMethod.PUT)
    @ApiOperation("更新单条记录")
    public Envelop update(
            @ApiParam(name = "schedule", value = "排班")
            @RequestParam(value = "schedule") String schedule){
        return scheduleClient.update(schedule);
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleBathUpdate, method = RequestMethod.PUT)
    @ApiOperation("更新多条记录")
    public Envelop bathUpdate(
            @ApiParam(name = "schedules", value = "排班")
            @RequestParam(value = "schedules") String schedules){
        return scheduleClient.bathUpdate(schedules);
    }
    @RequestMapping(value = ServiceApi.Emergency.ScheduleBatch, method = RequestMethod.POST)
    @ApiOperation("批量导入排班信息")
    public Envelop createSchedulesBatch(
            @ApiParam(name = "schedules", value = "排班信息", defaultValue = "")
            @RequestParam(value = "schedules") String schedules) throws Exception {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        try{
            scheduleClient.createSchedulesBatch(schedules);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("导入失败!"+e.getMessage());
        }
        return envelop;
    }
}

+ 47 - 0
src/main/java/com/yihu/ehr/esb/client/HosAcqTaskClient.java

@ -0,0 +1,47 @@
package com.yihu.ehr.esb.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.esb.MHosAcqTask;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.13 14:15
 */
@FeignClient(name=MicroServices.ESB)
@RequestMapping(value = ApiVersion.Version1_0 + "/esb")
@ApiIgnore
public interface HosAcqTaskClient {
    @RequestMapping(value = "/searchHosAcqTasks", method = RequestMethod.GET)
    ResponseEntity<List<MHosAcqTask>> searchHosAcqTasks(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
    @RequestMapping(value = "/hosAcqTask/{id}",method = RequestMethod.GET)
    MHosAcqTask getHosAcqTask(
            @PathVariable(value = "id") String id);
    @RequestMapping(value = "/createHosAcqTask", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    MHosAcqTask createHosAcqTask(
            @RequestBody String jsonData);
    @RequestMapping(value = "/updateHosAcqTask", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    MHosAcqTask updateHosAcqTask(
            @RequestBody String jsonData);
    @RequestMapping(value = "/deleteHosAcqTask/{id}", method = RequestMethod.DELETE)
    boolean deleteHosAcqTask(
            @PathVariable(value = "id") String id);
}

+ 31 - 0
src/main/java/com/yihu/ehr/esb/client/HosEsbMiniInstallLogClient.java

@ -0,0 +1,31 @@
package com.yihu.ehr.esb.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.esb.MHosEsbMiniInstallLog;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.13 14:15
 */
@FeignClient(name=MicroServices.ESB)
@RequestMapping(value = ApiVersion.Version1_0 + "/esb")
@ApiIgnore
public interface HosEsbMiniInstallLogClient {
    @RequestMapping(value = "/searchInstallLogs", method = RequestMethod.GET)
    ResponseEntity<List<MHosEsbMiniInstallLog>> searchHosEsbMiniInstallLogs(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
}

+ 42 - 0
src/main/java/com/yihu/ehr/esb/client/HosLogClient.java

@ -0,0 +1,42 @@
package com.yihu.ehr.esb.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.esb.MHosLog;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.13 14:15
 */
@FeignClient(name=MicroServices.ESB)
@RequestMapping(value = ApiVersion.Version1_0 + "/esb")
@ApiIgnore
public interface HosLogClient {
    @RequestMapping(value = "/searchHosLogs", method = RequestMethod.GET)
    ResponseEntity<List<MHosLog>> searchHosLogs(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
    @RequestMapping(value = "/deleteHosLog/{id}", method = RequestMethod.DELETE)
    boolean deleteHosLog(
            @PathVariable(value = "id") String id);
    @RequestMapping(value = "/deleteHosLogs", method = RequestMethod.DELETE)
    boolean deleteHosLogs(@RequestParam(value = "filters", required = false) String filters);
}

+ 49 - 0
src/main/java/com/yihu/ehr/esb/client/HosReleaseClient.java

@ -0,0 +1,49 @@
package com.yihu.ehr.esb.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.esb.MHosEsbMiniRelease;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.13 14:15
 */
@FeignClient(name=MicroServices.ESB)
@RequestMapping(value = ApiVersion.Version1_0 + "/esb")
@ApiIgnore
public interface HosReleaseClient {
    @RequestMapping(value = "/searchHosEsbMiniReleases", method = RequestMethod.GET)
    ResponseEntity<List<MHosEsbMiniRelease>> searchHosEsbMiniReleases(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
    @RequestMapping(value = "/deleteHosEsbMiniRelease/{id}", method = RequestMethod.DELETE)
    String deleteHosEsbMiniRelease(
            @PathVariable(value = "id") String id);
    @RequestMapping(value = "/createHosEsbMiniRelease", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增软件包")
    MHosEsbMiniRelease createHosEsbMiniRelease(
            @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
            @RequestBody String model);
    @RequestMapping(value = "/updateHosEsbMiniRelease", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改软件包")
    MHosEsbMiniRelease updateHosEsbMiniRelease(
            @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
            @RequestBody String model);
}

+ 49 - 0
src/main/java/com/yihu/ehr/esb/client/HosSqlTaskClient.java

@ -0,0 +1,49 @@
package com.yihu.ehr.esb.client;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.esb.MHosSqlTask;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.13 14:15
 */
@FeignClient(name=MicroServices.ESB)
@RequestMapping(value = ApiVersion.Version1_0 + "/esb")
@ApiIgnore
public interface HosSqlTaskClient {
    @RequestMapping(value = "/searchHosSqlTasks", method = RequestMethod.GET)
    ResponseEntity<List<MHosSqlTask>> searchHosSqlTasks(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
    @RequestMapping(value = "/hosSqlTask/{id}",method = RequestMethod.GET)
    MHosSqlTask getHosSqlTask(
            @PathVariable(value = "id") String id);
    @RequestMapping(value = "/createHosSqlTask", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    MHosSqlTask createHosSqlTask(
            @RequestBody String jsonData);
    @RequestMapping(value = "/updateHosSqlTask", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    MHosSqlTask updateHosSqlTask(
            @RequestBody String jsonData);
    @RequestMapping(value = "/deleteHosSqlTask/{id}", method = RequestMethod.DELETE)
    boolean deleteHosSqlTask(
            @PathVariable(value = "id") String id);
}

+ 150 - 0
src/main/java/com/yihu/ehr/esb/controller/HosAcqTaskController.java

@ -0,0 +1,150 @@
package com.yihu.ehr.esb.controller;
import com.yihu.ehr.agModel.esb.HosAcqTaskModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.esb.client.HosAcqTaskClient;
import com.yihu.ehr.model.esb.MHosAcqTask;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.12 18:00
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/esb")
@RestController
@Api(value = "补采任务管理接口", description = "补采任务管理接口" ,tags = {"ESB管理 -补采任务管理接口"})
public class HosAcqTaskController extends BaseController {
    @Autowired
    private HosAcqTaskClient hosAcqTaskClient;
    @RequestMapping(value = "/searchHosAcqTasks", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件获取补采任务信息", notes = "根据查询条件获取补采任务信息")
    public Envelop searchHosAcqTasks(
            @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)  {
        ResponseEntity<List<MHosAcqTask>> responseEntity = hosAcqTaskClient.searchHosAcqTasks(fields,filters,sorts,size,page);
        List<MHosAcqTask> hosAcqTasks = responseEntity.getBody();
        List<HosAcqTaskModel> hosAcqTaskModels = new ArrayList<>();
        for(MHosAcqTask mHosAcqTask : hosAcqTasks) {
            HosAcqTaskModel hosAcqTaskModel = null;
            try {
                hosAcqTaskModel = convertToModelDetail(mHosAcqTask,HosAcqTaskModel.class);
                hosAcqTaskModel = utcTimeChange(hosAcqTaskModel,mHosAcqTask);
            } catch (Exception e) {
                e.printStackTrace();
            }
            hosAcqTaskModels.add(hosAcqTaskModel);
        }
        Envelop envelop = getResult(hosAcqTaskModels, getTotalCount(responseEntity), page, size);
        return envelop;
    }
    /**
     * utc时间转化成yyyy-MM-dd HH:mm:ss
     */
    public HosAcqTaskModel utcTimeChange(HosAcqTaskModel hosAcqTaskModel,MHosAcqTask mHosAcqTask){
        hosAcqTaskModel.setStartTime(DateTimeUtil.simpleDateTimeFormat(mHosAcqTask.getStartTime()));
        hosAcqTaskModel.setEndTime(DateTimeUtil.simpleDateTimeFormat(mHosAcqTask.getEndTime()));
        hosAcqTaskModel.setCreateTime(DateTimeUtil.simpleDateTimeFormat(mHosAcqTask.getCreateTime()));
        return hosAcqTaskModel;
    }
    @RequestMapping(value = "/hosAcqTask/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取补采任务信息",notes = "根据id获取补采任务信息")
    public Envelop getHosAcqTask(
            @ApiParam(name = "id",value ="",defaultValue = "")
            @PathVariable(value = "id") String id){
        Envelop envelop = new Envelop();
        MHosAcqTask mHosAcqTask = hosAcqTaskClient.getHosAcqTask(id);
        try{
            HosAcqTaskModel hosAcqTaskModel = convertToModelDetail(mHosAcqTask,HosAcqTaskModel.class);
            hosAcqTaskModel = utcTimeChange(hosAcqTaskModel,mHosAcqTask);
            envelop.setObj(hosAcqTaskModel);
            envelop.setSuccessFlg(true);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/createHosAcqTask", method = RequestMethod.POST)
    @ApiOperation(value = "创建补采任务信息", notes = "创建补采任务信息")
    public Envelop createHosAcqTask(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestParam(value = "json_data") String jsonData) throws IOException {
        Envelop envelop = new Envelop();
        HosAcqTaskModel hosAcqTaskModel = toEntity(jsonData,HosAcqTaskModel.class);
        try {
            MHosAcqTask hosAcqTask = convertToMModel(hosAcqTaskModel,MHosAcqTask.class);
            MHosAcqTask mHosAcqTaskNew = hosAcqTaskClient.createHosAcqTask(toJson(hosAcqTask));
            convertToModelDetail(mHosAcqTaskNew,HosAcqTaskModel.class);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/updateHosAcqTask", method = RequestMethod.PUT)
    @ApiOperation(value = "修改补采任务信息", notes = "修改补采任务信息")
    public Envelop updateHosAcqTask(
            @ApiParam(name = "json_data", value = "")
            @RequestParam(value = "json_data") String jsonData)  {
        Envelop envelop = new Envelop();
        try {
            HosAcqTaskModel hosAcqTaskModel = toEntity(jsonData,HosAcqTaskModel.class);
            MHosAcqTask hosAcqTask = convertToMModel(hosAcqTaskModel,MHosAcqTask.class);
            hosAcqTaskClient.updateHosAcqTask(toJson(hosAcqTask));
            convertToModelDetail(hosAcqTask,HosAcqTaskModel.class);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/deleteHosAcqTask/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除补采任务信息", notes = "删除补采任务信息")
    public Envelop deleteHosAcqTask(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        try {
            hosAcqTaskClient.deleteHosAcqTask(id);
            envelop.setSuccessFlg(true);
        }catch (Exception e){e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
}

+ 73 - 0
src/main/java/com/yihu/ehr/esb/controller/HosEsbMiniInstallLogController.java

@ -0,0 +1,73 @@
package com.yihu.ehr.esb.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.esb.client.HosEsbMiniInstallLogClient;
import com.yihu.ehr.model.esb.MHosEsbMiniInstallLog;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @author linaz
 * @created 2016.05.12 18:00
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/esb")
@RestController
@Api(value = "程序版本发布信息管理接口", description = "程序版本发布信息管理接口" ,tags = {"ESB管理 -程序版本发布信息管理接口"})
public class HosEsbMiniInstallLogController extends BaseController {
    @Autowired
    private HosEsbMiniInstallLogClient hosEsbMiniInstallLogClient;
    @Autowired
    private OrganizationClient organizationClient;
    @RequestMapping(value = "/searchHosEsbMiniInstallLog", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件获取程序版本发布信息", notes = "根据查询条件获取程序版本发布信息")
    public Envelop searchHosEsbMiniInstallLogs(
            @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) throws ParseException {
            ResponseEntity<List<MHosEsbMiniInstallLog>> responseEntity = hosEsbMiniInstallLogClient.searchHosEsbMiniInstallLogs(fields, filters, sorts, size, page);
        List<MHosEsbMiniInstallLog> mHosEsbMiniInstallLogList = responseEntity.getBody();
        if(mHosEsbMiniInstallLogList.size()>0){
            for(MHosEsbMiniInstallLog mHosEsbMiniInstallLog:mHosEsbMiniInstallLogList){
                if(StringUtils.isNotBlank(mHosEsbMiniInstallLog.getOrgCode())){
                    String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
                    Pattern p   =   Pattern.compile(regEx);
                    Matcher m   =   p.matcher(mHosEsbMiniInstallLog.getOrgCode());
                    MOrganization mOrganization =  organizationClient.getOrg(m.replaceAll("").trim());
                    if(mOrganization!=null){
                        mHosEsbMiniInstallLog.setOrgName(mOrganization.getFullName());
                    }
                }
                if(mHosEsbMiniInstallLog.getInstallTime()!=null){
                    SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    mHosEsbMiniInstallLog.setInstallDate(sm.format(mHosEsbMiniInstallLog.getInstallTime()));
                }
            }
        }
        int totalCount = getTotalCount (responseEntity);
        return getResult(mHosEsbMiniInstallLogList, totalCount, page, size);
    }
}

+ 93 - 0
src/main/java/com/yihu/ehr/esb/controller/HosLogController.java

@ -0,0 +1,93 @@
package com.yihu.ehr.esb.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.esb.client.HosLogClient;
import com.yihu.ehr.model.esb.MHosLog;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @author linaz
 * @created 2016.05.12 18:00
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/esb")
@RestController
@Api(value = "上传日志管理接口", description = "上传日志管理接口" ,tags = {"ESB管理 -上传日志管理接口"})
public class HosLogController extends BaseController {
    @Autowired
    private HosLogClient hosLogClient;
    @Autowired
    private OrganizationClient organizationClient;
    @RequestMapping(value = "/searchHosLogs", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件获取上传日志信息", notes = "根据查询条件获取用户列表在前端表格展示")
    public Envelop searchHosLogs(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档")
            @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 {
        ResponseEntity<List<MHosLog>> responseEntity = hosLogClient.searchHosLogs(fields, filters,sorts,size,page);
        List<MHosLog> hosLogs = responseEntity.getBody();
        if(hosLogs.size()>0){
            for (MHosLog mHosLog :hosLogs){
                if(StringUtils.isNotBlank(mHosLog.getUploadTime())){
                    SimpleDateFormat sm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    mHosLog.setUploadTime(sm.format(sm.parse(mHosLog.getUploadTime())));
                }
                if(StringUtils.isNotBlank(mHosLog.getOrgCode())){
                    //过滤特殊字符,防止GET出错
                    String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
                    Pattern p   =   Pattern.compile(regEx);
                    Matcher m   =   p.matcher(mHosLog.getOrgCode());
                    MOrganization mOrganization =  organizationClient.getOrg(m.replaceAll("").trim());
                    if(mOrganization!=null){
                        mHosLog.setOrgName(mOrganization.getFullName());
                    }
                }
            }
        }
        int totalCount = getTotalCount (responseEntity);
        return getResult(hosLogs, totalCount, page, size);
    }
    @RequestMapping(value = "/deleteHosLog/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除上传日志", notes = "根据id删除上传日志")
    public boolean deleteHosLog(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) throws Exception {
        return hosLogClient.deleteHosLog(id);
    }
    @RequestMapping(value = "/deleteHosLogs", method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除上传日志", notes = "根据id删除上传日志")
    public boolean deleteHosLogs(
            @ApiParam(name = "filters", value = "filters", defaultValue = "")
            @RequestParam(value = "filters") String filters) throws Exception {
        return hosLogClient.deleteHosLogs(filters);
    }
}

+ 130 - 0
src/main/java/com/yihu/ehr/esb/controller/HosReleaseController.java

@ -0,0 +1,130 @@
package com.yihu.ehr.esb.controller;
import com.yihu.ehr.agModel.esb.HostReleaseModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.esb.client.HosReleaseClient;
import com.yihu.ehr.model.esb.MHosEsbMiniRelease;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.12 18:00
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/esb")
@RestController
@Api(value = "程序版本发布信息管理接口", description = "程序版本发布信息管理接口" ,tags = {"ESB管理 -程序版本发布信息管理接口"})
public class HosReleaseController extends BaseController {
    @Autowired
    private HosReleaseClient hosReleaseClient;
    @RequestMapping(value = "/searchHosEsbMiniReleases", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件获取程序版本发布信息", notes = "根据查询条件获取程序版本发布信息")
    public Envelop searchHosEsbMiniReleases(
            @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) throws ParseException {
        ResponseEntity<List<MHosEsbMiniRelease>> responseEntity = hosReleaseClient.searchHosEsbMiniReleases(fields,filters,sorts,size,page);
        List<MHosEsbMiniRelease> mHosEsbMiniReleases = responseEntity.getBody();
        List<HostReleaseModel>  hostReleaseModels = new ArrayList<>();
        for(MHosEsbMiniRelease mHosEsbMiniRelease: mHosEsbMiniReleases){
            HostReleaseModel  hostReleaseModel = new HostReleaseModel();
            BeanUtils.copyProperties(mHosEsbMiniRelease,hostReleaseModel);
            if(mHosEsbMiniRelease.getReleaseTime()!=null) {
                hostReleaseModel.setReleaseDate(DateTimeUtil.simpleDateTimeFormat(mHosEsbMiniRelease.getReleaseTime()));
            }
            hostReleaseModels.add(hostReleaseModel);
        }
        int totalCount = getTotalCount (responseEntity);
        return getResult(hostReleaseModels, totalCount, page, size);
    }
    @RequestMapping(value = "/deleteHosEsbMiniRelease/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除程序版本发布信息", notes = "删除程序版本发布信息")
    public Envelop  deleteHosEsbMiniRelease(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) throws Exception {
            String result =  hosReleaseClient.deleteHosEsbMiniRelease(id);
            if(result!="success"&&!"success".equals(result)){
                return failed(result);
            }else{
                return success("删除成功!");
            }
    }
    @RequestMapping(value = "/saveReleaseInfo", method = RequestMethod.POST)
    public Envelop saveDict(
            @ApiParam(name = "json_data", value = "软件版本信息")
            @RequestParam(value = "json_data") String jsonData) {
        try {
            MHosEsbMiniRelease mHosEsbMiniRelease = objectMapper.readValue(jsonData, MHosEsbMiniRelease.class);
            String errorMsg = "";
            if (StringUtils.isEmpty(mHosEsbMiniRelease.getSystemCode())) {
                errorMsg += "系统代码为空!";
            }
            if (StringUtils.isEmpty(mHosEsbMiniRelease.getFile())) {
                errorMsg += "文件路径不能为空!";
            }
            if (StringUtils.isEmpty(mHosEsbMiniRelease.getVersionName())) {
                errorMsg += "版本名称不能为空!";
            }
            if (StringUtils.isEmpty(""+mHosEsbMiniRelease.getVersionCode())) {
                errorMsg += "版本编号不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            //系统代码唯一性校验
            if (StringUtils.isBlank(mHosEsbMiniRelease.getId())) {
                ResponseEntity<List<MHosEsbMiniRelease>> responseEntity = hosReleaseClient.searchHosEsbMiniReleases("","systemCode="+mHosEsbMiniRelease.getSystemCode(),"",1,1);
                List<MHosEsbMiniRelease> mHosEsbMiniReleases = responseEntity.getBody();
                if(mHosEsbMiniReleases.size()>0){
                    return failed("系统编码已经存在请修改!");
                }
                mHosEsbMiniRelease = hosReleaseClient.createHosEsbMiniRelease(objectMapper.writeValueAsString(mHosEsbMiniRelease));
            } else {
                ResponseEntity<List<MHosEsbMiniRelease>> responseEntity = hosReleaseClient.searchHosEsbMiniReleases("","systemCode="+mHosEsbMiniRelease.getSystemCode()+";id<>"+mHosEsbMiniRelease.getId(),"",1,1);
                List<MHosEsbMiniRelease> mHosEsbMiniReleases = responseEntity.getBody();
                if(mHosEsbMiniReleases.size()>0){
                    return failed("系统编码已经存在请修改!");
                }
                mHosEsbMiniRelease = hosReleaseClient.updateHosEsbMiniRelease(objectMapper.writeValueAsString(mHosEsbMiniRelease));
            }
             MHosEsbMiniRelease hosEsbMiniRelease = convertToModel(mHosEsbMiniRelease, MHosEsbMiniRelease.class);
            if (hosEsbMiniRelease == null) {
                return failed("保存失败!");
            }
            return success(hosEsbMiniRelease);
        } catch (Exception ex) {
            return failedSystem();
        }
    }
}

+ 137 - 0
src/main/java/com/yihu/ehr/esb/controller/HosSqlTaskController.java

@ -0,0 +1,137 @@
package com.yihu.ehr.esb.controller;
import com.yihu.ehr.agModel.esb.HosSqlTaskModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.esb.client.HosSqlTaskClient;
import com.yihu.ehr.model.esb.MHosSqlTask;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.12 18:00
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin/esb")
@RestController
@Api(value = "his穿透管理接口", description = "his穿透管理接口" ,tags = {"ESB管理 -his穿透管理接口"})
public class HosSqlTaskController extends BaseController {
    @Autowired
    private HosSqlTaskClient hosSqlTaskClient;
    @RequestMapping(value = "/searchHosSqlTasks", method = RequestMethod.GET)
    @ApiOperation(value = "根据条件进行his穿透查询", notes = "根据条件进行his穿透查询")
    public Envelop searchHosSqlTasks(
            @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) throws Exception {
        ResponseEntity<List<MHosSqlTask>> responseEntity = hosSqlTaskClient.searchHosSqlTasks(fields,filters,sorts,size,page);
        List<MHosSqlTask> hosSqlTasks = responseEntity.getBody();
        List<HosSqlTaskModel> hosSqlTaskModels = new ArrayList<>();
        for(MHosSqlTask mHosSqlTask : hosSqlTasks) {
            HosSqlTaskModel hosSqlTaskModel = null;
            try {
                hosSqlTaskModel = convertToModelDetail(mHosSqlTask,HosSqlTaskModel.class);
                hosSqlTaskModel.setCreateTime(DateTimeUtil.simpleDateTimeFormat(mHosSqlTask.getCreateTime()));
            } catch (Exception e) {
                e.printStackTrace();
            }
            hosSqlTaskModels.add(hosSqlTaskModel);
        }
        Envelop envelop = getResult(hosSqlTaskModels, getTotalCount(responseEntity), page, size);
        return envelop;
    }
    @RequestMapping(value = "/hosSqlTask/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取his穿透信息",notes = "根据id获取his穿透信息")
    public Envelop getHosSqlTask(
            @ApiParam(name = "id",value ="",defaultValue = "")
            @PathVariable(value = "id") String id) throws  Exception{
        Envelop envelop = new Envelop();
        MHosSqlTask mHosSqlTask = hosSqlTaskClient.getHosSqlTask(id);
        try{
            HosSqlTaskModel hosSqlTaskModel = convertToModelDetail(mHosSqlTask,HosSqlTaskModel.class);
            hosSqlTaskModel.setCreateTime(DateTimeUtil.simpleDateTimeFormat(mHosSqlTask.getCreateTime()));
            envelop.setObj(hosSqlTaskModel);
            envelop.setSuccessFlg(true);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/createHosSqlTask", method = RequestMethod.POST)
    @ApiOperation(value = "创建his穿透信息", notes = "创建his穿透信息")
    public Envelop createHosSqlTask(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestParam(value = "json_data", required = true) String jsonData) throws Exception {
        Envelop envelop = new Envelop();
        HosSqlTaskModel hosSqlTaskModel = toEntity(jsonData,HosSqlTaskModel.class);
        try {
            MHosSqlTask hosSqlTask = convertToMModel(hosSqlTaskModel,MHosSqlTask.class);
            hosSqlTaskClient.createHosSqlTask(toJson(hosSqlTask));
            convertToModelDetail(hosSqlTask,HosSqlTaskModel.class);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/updateHosSqlTask", method = RequestMethod.PUT)
    @ApiOperation(value = "修改his穿透信息", notes = "修改his穿透信息")
    public Envelop updateHosSqlTask(
            @ApiParam(name = "json_data", value = "")
            @RequestParam(value = "json_data") String jsonData) throws Exception {
        Envelop envelop = new Envelop();
        HosSqlTaskModel hosSqlTaskModel = toEntity(jsonData,HosSqlTaskModel.class);
        try {
            MHosSqlTask hosSqlTask = convertToMModel(hosSqlTaskModel,MHosSqlTask.class);
            hosSqlTaskClient.updateHosSqlTask(toJson(hosSqlTask));
            convertToModelDetail(hosSqlTask,HosSqlTaskModel.class);
            envelop.setSuccessFlg(true);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;
    }
    @RequestMapping(value = "/deleteHosSqlTask/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除his穿透信息", notes = "删除his穿透信息")
    public Envelop deleteHosSqlTask(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) throws Exception {
        Envelop envelop = new Envelop();
        try {
            hosSqlTaskClient.deleteHosSqlTask(id);
            envelop.setSuccessFlg(true);
        }catch (Exception e){e.printStackTrace();
            e.printStackTrace();
            envelop.setSuccessFlg(false);
        }
        return envelop;    }
}

+ 133 - 0
src/main/java/com/yihu/ehr/fileresource/controller/FileResourceController.java

@ -0,0 +1,133 @@
package com.yihu.ehr.fileresource.controller;
import com.netflix.eureka.V1AwareInstanceInfoConverter;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.fileresource.service.FileResourceClient;
import com.yihu.ehr.util.log.LogService;
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 javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.11 11:32
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "文件管理接口", description = "文件管理接口", tags = {"文件管理接口"})
public class FileResourceController {
    @Autowired
    private FileResourceClient fileResourceClient;
    @RequestMapping(value = "/files", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件")
    public String pictureUpload(
            @ApiParam(name = "file_str", value = "文件流转化后的字符串")
            @RequestParam(value = "file_str") String fileStr,
            @ApiParam(name = "file_name", value = "文件名")
            @RequestParam(value = "file_name") String fileName,
            @ApiParam(name = "json_data", value = "文件资源属性")
            @RequestParam(value = "json_data") String jsonData) {
        return fileResourceClient.fileUpload(fileStr, fileName, jsonData);
    }
    @RequestMapping(value = "/filesReturnUrl", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件,并返回存储相对路径")
    public String pictureUploadReturnUrl(
            @ApiParam(name = "file_str", value = "文件流转化后的字符串")
            @RequestParam(value = "file_str") String fileStr,
            @ApiParam(name = "file_name", value = "文件名")
            @RequestParam(value = "file_name") String fileName,
            @ApiParam(name = "json_data", value = "文件资源属性")
            @RequestParam(value = "json_data") String jsonData) {
        return fileResourceClient.fileUploadReturnUrl(fileStr, fileName, jsonData);
    }
    @RequestMapping(value = "/filesReturnHttpUrl", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件,并返回存储绝对路径")
    public String pictureUploadReturnHttpUrl(
            @ApiParam(name = "file_str", value = "文件流转化后的字符串")
            @RequestParam(value = "file_str") String fileStr,
            @ApiParam(name = "file_name", value = "文件名")
            @RequestParam(value = "file_name") String fileName,
            @ApiParam(name = "json_data", value = "文件资源属性")
            @RequestParam(value = "json_data") String jsonData) {
        return fileResourceClient.fileUploadReturnHttpUrl(fileStr, fileName, jsonData);
    }
    @RequestMapping(value = "/files", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastdfs相对应当文件")
    public boolean filesDelete(
            @ApiParam(name = "object_id", value = "文件字符串")
            @RequestParam(value = "object_id") String objectId) throws Exception {
        return fileResourceClient.filesDelete(objectId);
    }
    @RequestMapping(value = "/image_delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastdfs相对应当文件")
    public boolean delete(
            @ApiParam(name = "storagePath", value = "文件路径")
            @RequestParam(value = "storagePath") String storagePath) throws Exception {
        return fileResourceClient.filesDeleteByPath(storagePath);
    }
    @RequestMapping(value = "/files", method = RequestMethod.GET)
    @ApiOperation(value = "下载文件")
    public Envelop fileDownload(
            @ApiParam(name = "object_id", value = "文件字符串")
            @RequestParam(value = "object_id") String objectId,
            @ApiParam(name = "mime", value = "所有者")
            @RequestParam(value = "mime", required = false) String mime) throws Exception {
        List<String> filesStr = fileResourceClient.filesDownload(objectId, mime);
        Envelop envelop = new Envelop();
        envelop.setDetailModelList(filesStr);
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @RequestMapping(value = "/image_view", method = RequestMethod.GET)
    @ApiOperation(value = "查看图片")
    public String imageView(
            @ApiParam(value = "查看图片")
            @RequestParam(value = "storagePath") String storagePath) throws Exception {
        String filesStr = fileResourceClient.imageView(storagePath);
        return filesStr;
    }
    @RequestMapping(value = "/files_path", method = RequestMethod.GET)
    @ApiOperation(value = "获取文件路径")
    public Envelop filePath(
            @ApiParam(name = "object_id", value = "文件字符串")
            @RequestParam(value = "object_id") String objectId) throws Exception {
        List<String> filesStr = fileResourceClient.filesPath(objectId);
        Envelop envelop = new Envelop();
        envelop.setDetailModelList(filesStr);
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @ApiOperation(value = "根据文件ID,获取文件的真实访问路径")
    @RequestMapping(value = "/file/getRealPathById", method = RequestMethod.GET)
    public String getRealPathById(
            @ApiParam(value = "文件ID", required = true)
            @RequestParam(value = "fileId") String fileId) throws Exception {
        return fileResourceClient.getRealPathById(fileId);
    }
    @ApiOperation(value = "根据文件的存储路径,获取文件的真实访问路径")
    @RequestMapping(value = "/file/getRealPathByStoragePath", method = RequestMethod.GET)
    public String getRealPathByStoragePath(
            @ApiParam(value = "文件存储路径", required = true)
            @RequestParam(value = "storagePath") String storagePath) throws Exception {
        return fileResourceClient.getRealPathByStoragePath(storagePath);
    }
}

+ 78 - 0
src/main/java/com/yihu/ehr/fileresource/service/FileResourceClient.java

@ -0,0 +1,78 @@
package com.yihu.ehr.fileresource.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
 * @author linaz
 * @created 2016.05.11 11:32
 */
@FeignClient(name = MicroServices.FileResource)
public interface FileResourceClient {
    @RequestMapping(value = ApiVersion.Version1_0 + "/files_upload", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件")
    String fileUpload(
            @RequestBody String fileStr,
            @RequestParam(value = "file_name") String fileName,
            @RequestParam(value = "json_data") String jsonData);
    @RequestMapping(value = ApiVersion.Version1_0 + "/files_upload_returnUrl", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件,并返回存储相对路径")
    String fileUploadReturnUrl(
            @RequestBody String fileStr,
            @RequestParam(value = "file_name") String fileName,
            @RequestParam(value = "json_data") String jsonData);
    @RequestMapping(value = ApiVersion.Version1_0 + "/files_upload_returnHttpUrl", method = RequestMethod.POST)
    @ApiOperation(value = "上传文件,并返回存储绝对路径")
    String fileUploadReturnHttpUrl(
            @RequestBody String fileStr,
            @RequestParam(value = "file_name") String fileName,
            @RequestParam(value = "json_data") String jsonData);
    @RequestMapping(value = ApiVersion.Version1_0 + "/files", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastdfs相对应当文件")
    boolean filesDelete(
            @RequestParam(value = "object_id") String objectId);
    @RequestMapping(value = ApiVersion.Version1_0 + "/files_download", method = RequestMethod.GET)
    @ApiOperation(value = "下载文件")
    List<String> filesDownload(
            @RequestParam(value = "object_id") String objectId,
            @RequestParam(value = "mime", required = false) String mime);
    @RequestMapping(value = ApiVersion.Version1_0 + "/image_view", method = RequestMethod.GET)
    @ApiOperation(value = "查看图片")
    String imageView(
            @RequestParam(value = "storagePath") String storagePath);
    @RequestMapping(value = ApiVersion.Version1_0 + "/files_path", method = RequestMethod.GET)
    @ApiOperation(value = "获取文件路径")
    List<String> filesPath(
            @RequestParam(value = "object_id") String objectId);
    @RequestMapping(value = ApiVersion.Version1_0 + "/image_delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除资源表对应关系,并且删除fastdfs相对应当文件")
    boolean filesDeleteByPath(
            @RequestParam(value = "storagePath") String storagePath);
    @ApiOperation(value = "根据文件的id,获取文件的真实访问路径")
    @RequestMapping(value = ApiVersion.Version1_0 + "/file/getRealPathById", method = RequestMethod.GET)
    String getRealPathById(
            @RequestParam(value = "fileId") String fileId);
    @ApiOperation(value = "根据文件的存储路径,获取文件的真实访问路径")
    @RequestMapping(value = ApiVersion.Version1_0 + "/file/getRealPathByStoragePath", method = RequestMethod.GET)
    String getRealPathByStoragePath(
            @RequestParam(value = "storagePath") String storagePath);
}

+ 35 - 0
src/main/java/com/yihu/ehr/filter/TenantFilter.java

@ -0,0 +1,35 @@
package com.yihu.ehr.filter;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@Component
public class TenantFilter implements Filter {
    private ServletContext servletContext;
    public TenantFilter(){
        super();
    }
    public void init(FilterConfig filterConfig) throws ServletException {
        servletContext = filterConfig.getServletContext();
    }
    public void doFilter( ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
        //设置请求头,调用app,标准的微服务需要该请求头
        WritableHttpServletRequest httpReq = new WritableHttpServletRequest((HttpServletRequest)req);
        httpReq.addHeader("Tenant","ehr");
        filterChain.doFilter(httpReq, res);
    }
    public void destroy(){
    }
}

+ 34 - 0
src/main/java/com/yihu/ehr/filter/WritableHttpServletRequest.java

@ -0,0 +1,34 @@
package com.yihu.ehr.filter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.util.*;
public class WritableHttpServletRequest extends HttpServletRequestWrapper {
    private final Set<String> names = new HashSet<>();
    private final Map<String, String> headers = new HashMap<>();
    public WritableHttpServletRequest(HttpServletRequest request) {
        super(request);
        Enumeration<String> e = super.getHeaderNames();
        while (e.hasMoreElements()) {
            names.add(e.nextElement());
        }
    }
    public void addHeader(String name, String value) {
        headers.put(name, value);
        names.add(name);
    }
    @Override
    public String getHeader(String name) {
        if (headers.containsKey(name)) {
            return headers.get(name);
        } else {
            return super.getHeader(name);
        }
    }
    @Override
    public Enumeration<String> getHeaderNames() {
        return Collections.enumeration(names);
    }
}

+ 271 - 0
src/main/java/com/yihu/ehr/geography/controller/AddressController.java

@ -0,0 +1,271 @@
package com.yihu.ehr.geography.controller;
import com.yihu.ehr.agModel.geogrephy.GeographyDictModel;
import com.yihu.ehr.agModel.geogrephy.GeographyModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.geography.service.AddressClient;
import com.yihu.ehr.model.geography.MGeography;
import com.yihu.ehr.model.geography.MGeographyDict;
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.cloud.netflix.feign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/20.
 */
@EnableFeignClients
@RequestMapping(ApiVersion.Version1_0+"/admin")
@RestController
@Api(value = "address", description = "地址信息管理", tags = {"基础信息"})
public class AddressController extends BaseController{
    @Autowired
    private AddressClient addressClient;
    @RequestMapping(value = "/geography_entries/level/{level}", method = RequestMethod.GET)
    @ApiOperation(value = "根据地址等级查询地址字典")
    public Envelop getAddressByLevel(
            @ApiParam(name = "level", value = "地址级别", defaultValue = "")
            @PathVariable(value = "level") Integer level) {
        Envelop envelop = new Envelop();
        List<GeographyDictModel> geographyDictModels = new ArrayList<>();
        List<MGeographyDict> mGeographyDictList = addressClient.getAddressByLevel(level);
        for (MGeographyDict mGeographyDict : mGeographyDictList){
            GeographyDictModel geographyDictModel = convertToModel(mGeographyDict,GeographyDictModel.class);
            geographyDictModels.add(geographyDictModel);
        }
        if(geographyDictModels.size()>0){
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(geographyDictModels);
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("根据地址等级查询地址字典失败");
        }
        return envelop;
    }
    @RequestMapping(value = "/geography_entries/pid/{pid}", method = RequestMethod.GET)
    @ApiOperation(value = "根据上级编号查询行政区划地址")
    public Envelop getAddressDictByPid(
            @ApiParam(name = "pid", value = "上级id", defaultValue = "")
            @PathVariable(value = "pid") Integer pid) {
        Envelop envelop = new Envelop();
        List<GeographyDictModel> geographyDictModels = new ArrayList<>();
        List<MGeographyDict> mGeographyDictList = addressClient.getAddressDictByPid(pid);
        for (MGeographyDict mGeographyDict : mGeographyDictList){
            GeographyDictModel geographyDictModel = convertToModel(mGeographyDict,GeographyDictModel.class);
            geographyDictModels.add(geographyDictModel);
        }
        if(geographyDictModels.size()>0){
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(geographyDictModels);
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("根据上级编号查询行政区划地址失败");
        }
        return envelop;
    }
    @RequestMapping(value = "/geography_entries/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询行政区划地址")
    public Envelop getAddressDictById(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        MGeographyDict addressDict = addressClient.getAddressDictById(id);
        if(addressDict!=null){
            envelop.setSuccessFlg(true);
            envelop.setObj(addressDict);
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("根据id查询行政区划失败");
        }
        return envelop;
    }
    @RequestMapping(value = "/geographies/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询地址")
    public Envelop getAddressById(
            @ApiParam(name = "id", value = "地址编号", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        MGeography mGeography = addressClient.getAddressById(id);
        GeographyModel geographyModel = convertToModel(mGeography,GeographyModel.class);
        if(geographyModel != null){
            envelop.setSuccessFlg(true);
            envelop.setObj(geographyModel);
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("地址查询失败");
        }
        return envelop;
    }
    @RequestMapping(value = "geographies/canonical/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据地址编号获取地址中文字符串全拼")
    public Envelop getCanonicalAddress(
            @ApiParam(name = "id", value = "地址代码", defaultValue = "")
            @PathVariable(value = "id") String id) {
        Envelop envelop = new Envelop();
        GeographyDictModel geographyDictModel = new GeographyDictModel();
        String address = addressClient.getCanonicalAddress(id);
        if(address != null){
            geographyDictModel.setName(address);
            envelop.setSuccessFlg(true);
            envelop.setObj(geographyDictModel);
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("地址查询失败");
        }
        return envelop;
    }
    /**
     * 地址检查并保存
     * @return
     */
    @RequestMapping(value = "/geographies", method = RequestMethod.POST)
    @ApiOperation(value = "地址检查,如果地址在数据库中不存在,这新增这条记录,否则返回地址id")
    public Envelop saveAddress(
            @ApiParam(name = "geography_model_json_data", value = "地址json字符串")
            @RequestParam( value = "geography_model_json_data") String geographyModelJsonData) throws Exception{
        Envelop envelop = new Envelop();
        GeographyModel geographyModel = new GeographyModel();
        String id = addressClient.saveAddress(geographyModelJsonData);
        if(id != null){
            envelop.setSuccessFlg(true);
            geographyModel.setId(id);
        }else{
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("地址新增失败");
        }
        envelop.setObj(geographyModel);
        return envelop;
    }
    /**
 * 根据省市县查询地址
 * @param province
 * @param city
 * @param district
 * @return
 */
        @RequestMapping(value = "/geographies" , method = RequestMethod.GET)
        @ApiOperation(value = "根据省市县查询地址并返回地址编号列表")
        public Envelop search(
                @ApiParam(name = "province", value = "省", defaultValue = "")
                @RequestParam(value = "province",required=false) 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) {
        Envelop envelop = new Envelop();
        List<String> geographyList = addressClient.search(province,city,district);
        if(geographyList.size()>0){
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(geographyList);
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("地址查询失败");
        }
        return envelop;
    }
    /**
     * 删除地址
     * @param id
     * @return
     */
    @RequestMapping(value = "geographies/{id}" , method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除地址")
    public Envelop delete(
            @ApiParam(name = "/id" , value = "地址代码" ,defaultValue = "")
            @PathVariable (value = "id") String id) {
        Envelop envelop = new Envelop();
        Boolean bo = addressClient.delete(id);
        if(bo){
            envelop.setSuccessFlg(true);
        }else{
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("地址删除失败");
        }
        return envelop;
    }
    @RequestMapping(value = "/geographies/existence" , method = RequestMethod.GET)
    @ApiOperation(value = "判断是否是个地址")
    public Envelop isNullAddress(
            @ApiParam(name = "json_data", value = "地址json字符串")
            @RequestParam( value = "json_data") String jsonData) throws Exception{
        Envelop envelop = new Envelop();
        Boolean bo = addressClient.isNullAddress(jsonData);
        envelop.setSuccessFlg(bo);
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Geography.AddressDictByFields, method = RequestMethod.GET)
    @ApiOperation(value = "根据名称查询行政区划地址id")
    public Envelop getAddressDictByName(
            @ApiParam(name = "fields", value = "fields", defaultValue = "")
            @RequestParam(value = "fields") String[] fields ,
            @ApiParam(name = "values", value = "values", defaultValue = "")
            @RequestParam(value = "values") String[] values) {
        Envelop envelop = new Envelop();
        Collection<MGeographyDict> addressDict = addressClient.getAddressDict(fields,values);
        if(addressDict!=null){
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(new ArrayList<>(addressDict));
        }else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("根据名称查询行政区划地址id失败");
        }
        return envelop;
    }
}

+ 126 - 0
src/main/java/com/yihu/ehr/geography/service/AddressClient.java

@ -0,0 +1,126 @@
package com.yihu.ehr.geography.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.common.ObjectResult;
import com.yihu.ehr.model.geography.MGeography;
import com.yihu.ehr.model.geography.MGeographyDict;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/20.
 */
@FeignClient(name=MicroServices.Geography)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface AddressClient {
    @RequestMapping(value = "/geography_entries/level/{level}", method = RequestMethod.GET)
    @ApiOperation(value = "根据等级查询行政区划地址")
    List<MGeographyDict> getAddressByLevel(
            @ApiParam(name = "level", value = "地址级别", defaultValue = "")
            @PathVariable(value = "level") Integer level) ;
    @RequestMapping(value = "/geography_entries/pid/{pid}", method = RequestMethod.GET)
    @ApiOperation(value = "根据上级编号查询行政区划地址")
    List<MGeographyDict> getAddressDictByPid(
            @ApiParam(name = "pid", value = "上级id", defaultValue = "")
            @PathVariable(value = "pid") Integer pid) ;
    @RequestMapping(value = "/geographies/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询地址")
    MGeography getAddressById(
            @ApiParam(name = "id", value = "地址编号", defaultValue = "")
            @PathVariable(value = "id") String id) ;
    @RequestMapping(value = "/geographies/{id}/canonical", method = RequestMethod.GET)
    @ApiOperation(value = "根据地址编号获取地址中文字符串全拼")
    String getCanonicalAddress(
            @ApiParam(name = "id", value = "地址代码", defaultValue = "")
            @PathVariable(value = "id") String id) ;
    /**
     * 地址检查并保存
     * @return
     */
    @RequestMapping(value = "/geographies", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "地址检查,如果地址在数据库中不存在,这新增这条记录,否则返回地址id")
    String saveAddress(
            @ApiParam(name = "json_data", value = "地址json字符串")
            @RequestBody String GeographyModelJsonData) ;
    /**
     * 根据省市县查询地址
     * @param province
     * @param city
     * @param district
     * @return
     */
    @RequestMapping(value = "/geographies" , method = RequestMethod.GET)
    @ApiOperation(value = "根据省市县查询地址并返回地址编号列表")
    List<String> search(
            @ApiParam(name = "province", value = "省", defaultValue = "")
            @RequestParam(value = "province") String province,
            @ApiParam(name = "city", value = "市", defaultValue = "")
            @RequestParam(value = "city") String city,
            @ApiParam(name = "district", value = "县", defaultValue = "")
            @RequestParam(value = "district") String district) ;
    /**
     * 删除地址
     * @param id
     * @return
     */
    @RequestMapping(value = "/geographies/{id}" , method = RequestMethod.DELETE)
    @ApiOperation(value = "根据id删除地址")
    boolean delete(
            @ApiParam(name = "/id" , value = "地址代码" ,defaultValue = "")
            @PathVariable (value = "id") String id) ;
    @RequestMapping(value = "/geographies/existence" , method = RequestMethod.GET)
    @ApiOperation(value = "判断是否是个地址")
    boolean isNullAddress(
            @ApiParam(name = "json_data", value = "地址json字符串")
            @RequestParam( value = "json_data") String jsonData) ;
    @RequestMapping(value = "/geography_entries/getAddressDict" , 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);
    @RequestMapping(value = "/geography_entries/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询行政区划地址")
    MGeographyDict getAddressDictById(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @PathVariable(value = "id") String id) ;
    @RequestMapping(value = ServiceApi.Geography.GetAddressNameByCode, method = RequestMethod.GET)
    @ApiOperation(value = "根据地址中文名 查询地址编号")
    ObjectResult getAddressNameByCode(
            @ApiParam(name = "name", value = "name", defaultValue = "")
            @RequestParam(value = "name") String name);
    @RequestMapping(value = "/OrgSaasAreaByname", method = RequestMethod.GET)
    @ApiOperation(value = "根据名称查询行政区划地址")
    List<MGeographyDict> getOrgSaasAreaByname(
            @ApiParam(name = "name", value = "名称", defaultValue = "")
            @RequestParam(value = "name") String name) ;
}

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

@ -0,0 +1,53 @@
package com.yihu.ehr.government.controller;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.agModel.government.GovernmentBrowseLogModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.entity.government.GovernmentBrowseLog;
import com.yihu.ehr.government.service.GovernmentBrowseLogClient;
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.List;
/**
 * Created by wxw on 2017/11/3.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "government_browse_log", description = "政府服务平台浏览记录", tags = {"政府服务平台"})
public class GovernmentBrowseLogController extends ExtendController<GovernmentBrowseLogModel> {
    @Autowired
    private GovernmentBrowseLogClient governmentBrowseLogClient;
    @RequestMapping(value = ServiceApi.Government.AddGovernmentBrowseLog, method = RequestMethod.POST)
    @ApiOperation(value = "新增浏览记录")
    public Envelop create(
            @ApiParam(name = "jsonData", value = " 记录信息Json", defaultValue = "")
            @RequestParam(value = "jsonData", required = false) String jsonData) {
        GovernmentBrowseLog governmentBrowseLog = governmentBrowseLogClient.saveGovernmentBrowseLog(jsonData);
        if (null == governmentBrowseLog) {
            return failed("保存失败!");
        }
        return success(governmentBrowseLog);
    }
    @RequestMapping(value = ServiceApi.Government.searchGovernmentBrowseLog, method = RequestMethod.GET)
    @ApiOperation(value = "浏览记录")
    public List<GovernmentBrowseLogModel> getBrowseName(
            @ApiParam(name = "userId", value = " 用户Id", defaultValue = "")
            @RequestParam(value = "userId", required = false) String userId) {
        return governmentBrowseLogClient.getBrowseName(userId);
    }
    @RequestMapping(value = ServiceApi.Government.searchHotBrowseLog, method = RequestMethod.GET)
    @ApiOperation(value = "热门监测报表")
    public List<GovernmentBrowseLog> getHotBrowseLog() {
        return governmentBrowseLogClient.getHotBrowseLog();
    }
}

+ 272 - 0
src/main/java/com/yihu/ehr/government/controller/GovernmentMenuController.java

@ -0,0 +1,272 @@
package com.yihu.ehr.government.controller;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.agModel.government.GovernmentMenuModel;
import com.yihu.ehr.agModel.resource.RsReportCategoryInfoModel;
import com.yihu.ehr.agModel.resource.RsReportModel;
import com.yihu.ehr.agModel.resource.RsReportMonitorTypeModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.government.service.GovernmentMenuClient;
import com.yihu.ehr.government.service.GovernmentMenuReportMonitorTypeClient;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.resource.MRsReportMonitorType;
import com.yihu.ehr.model.user.MUser;
import com.yihu.ehr.resource.client.RsReportCategoryClient;
import com.yihu.ehr.resource.client.RsReportClient;
import com.yihu.ehr.resource.client.RsReportMonitorTypeClient;
import com.yihu.ehr.users.service.UserClient;
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.List;
import java.util.Map;
/**
 * Created by wxw on 2017/11/2.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "government_menu", description = "政府服务平台菜单", tags = {"政府服务平台-菜单"})
public class GovernmentMenuController extends ExtendController<GovernmentMenuModel> {
    @Autowired
    private GovernmentMenuClient governmentMenuClient;
    @Autowired
    private UserClient userClient;
    @Autowired
    private GovernmentMenuReportMonitorTypeClient reportMonitorTypeClient;
    @Autowired
    private RsReportMonitorTypeClient monitorTypeClient;
    @Autowired
    private RsReportCategoryClient rsReportCategoryClient;
    @Autowired
    private RsReportClient rsReportClient;
    @RequestMapping(value = ServiceApi.Government.SearchGovernmentMenu, method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询政府服务平台菜单")
    public Envelop 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) {
        Envelop envelop = new Envelop();
        try {
            ListResult governmentMenuList = governmentMenuClient.getGovernmentMenuList(fields, filters, sorts, size, page);
            List<GovernmentMenuModel> governmentMenus = new ArrayList<>();
            if (governmentMenuList.getTotalCount() != 0) {
                List<Map<String,Object>> modelList = governmentMenuList.getDetailModelList();
                for(Map<String,Object> map : modelList) {
                    GovernmentMenuModel governmentMenuModel = objectMapper.convertValue(map,GovernmentMenuModel.class);
                    if (null != governmentMenuModel && StringUtils.isNotEmpty(governmentMenuModel.getCreateUser())) {
                        MUser user = userClient.getUser(governmentMenuModel.getCreateUser());
                        governmentMenuModel.setCreateUser((null != user) ? user.getRealName() : "" );
                    }
                    if (null != governmentMenuModel && StringUtils.isNotEmpty(governmentMenuModel.getUpdateUser())) {
                        MUser user = userClient.getUser(governmentMenuModel.getUpdateUser());
                        governmentMenuModel.setUpdateUser((null != user) ? user.getRealName() : "" );
                    }
                    governmentMenus.add(governmentMenuModel);
                }
                return getResult(governmentMenus, governmentMenuList.getTotalCount(), governmentMenuList.getCurrPage(), governmentMenuList.getPageSize());
            } else {
                envelop.setSuccessFlg(true);
                return envelop;
            }
        } catch (Exception e) {
            envelop.setErrorMsg("请求发生异常");
            return envelop;
        }
    }
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuById , method = RequestMethod.GET)
    @ApiOperation(value = "根据Id查询详情")
    public Envelop detail(
            @ApiParam(name = "id", value = "id")
            @RequestParam(value = "id") Integer id) {
        try {
            String errorMsg = "";
            if (id == null) {
                errorMsg += "id不能为空!";
            }
            if(StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            GovernmentMenuModel governmentMenuModel = governmentMenuClient.getGovernmentMenuById(id);
            if (governmentMenuModel == null) {
                return failed("获取详情失败!");
            }
            return success(governmentMenuModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuCheckCode, method = RequestMethod.GET)
    @ApiOperation(value = "检查编码是否唯一")
    public Envelop checkCode(
            @ApiParam(name = "code", value = "编码")
            @RequestParam(value = "code") String code) {
        try {
            Envelop envelop = new Envelop();
            if (StringUtils.isEmpty(code)) {
                envelop.setErrorMsg("编码不能为空!");
            }
            int num = governmentMenuClient.getCountByCode(code);
            if (num > 0) {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("已经存在此编码!");
            }else{
                envelop.setSuccessFlg(true);
            }
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuCheckName, method = RequestMethod.GET)
    @ApiOperation(value = "检查名称是否唯一")
    public Envelop checkName(
            @ApiParam(name = "name", value = "名称")
            @RequestParam(value = "name") String name) {
        try {
            Envelop envelop = new Envelop();
            if (StringUtils.isEmpty(name)) {
                envelop.setErrorMsg("名称不能为空!");
            }
            int num = governmentMenuClient.getCountByName(name);
            if (num > 0) {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("已经存在此名称!");
            } else {
                envelop.setSuccessFlg(true);
            }
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Government.AddGovernmentMenu, method = RequestMethod.POST)
    @ApiOperation(value = "新增菜单")
    public Envelop create(
            @ApiParam(name = "jsonData", value = " 菜单信息Json", defaultValue = "")
            @RequestParam(value = "jsonData", required = false) String jsonData,
            @ApiParam(name = "ids", value = "资源报表监测类型ids", defaultValue = "")
            @RequestParam(value = "ids", required = false) String ids){
        try {
            String errorMsg = "";
            GovernmentMenuModel governmentMenuModel = objectMapper.readValue(jsonData, GovernmentMenuModel.class);
            if (StringUtils.isEmpty(governmentMenuModel.getCode())) {
                errorMsg+="编码不能为空!";
            }
            if (StringUtils.isEmpty(governmentMenuModel.getName())) {
                errorMsg+="名称不能为空!";
            }
            if (StringUtils.isEmpty(governmentMenuModel.getUrl())) {
                errorMsg+="链接地址不能为空!";
            }
            if(StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            String json = objectMapper.writeValueAsString(governmentMenuModel);
            GovernmentMenuModel mQuotaCategory = governmentMenuClient.saveGovernmentMenu(json, ids);
            if (mQuotaCategory == null) {
                return failed("保存失败!");
            }
            return success(mQuotaCategory);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Government.UpdateGovernmentMenu, method = RequestMethod.POST)
    @ApiOperation(value = "修改菜单")
    public Envelop resetInfo(
            @ApiParam(name = "jsonData", value = " 菜单信息Json", defaultValue = "")
            @RequestParam(value = "jsonData", required = false) String jsonData,
            @ApiParam(name = "ids", value = "资源报表监测类型ids", defaultValue = "")
            @RequestParam(value = "ids", required = false) String ids){
        try {
            String errorMsg = "";
            GovernmentMenuModel governmentMenuModel = objectMapper.readValue(jsonData, GovernmentMenuModel.class);
            if (null == governmentMenuModel) {
                errorMsg += "内容出错!";
            }
            if (StringUtils.isEmpty(governmentMenuModel.getName())) {
                errorMsg += "名称不能为空!";
            }
            if (StringUtils.isEmpty(governmentMenuModel.getName())) {
                errorMsg+="名称不能为空!";
            }
            if (StringUtils.isEmpty(governmentMenuModel.getUrl())) {
                errorMsg+="链接地址不能为空!";
            }
            if(StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            String json = objectMapper.writeValueAsString(governmentMenuModel);
            GovernmentMenuModel mQuotaCategory = governmentMenuClient.updateGovernmentMenu(json, ids);
            if (mQuotaCategory == null) {
                return failed("修改菜单失败!");
            }
            return success(mQuotaCategory);
        } catch (Exception ex){
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Government.GetReportByMenuCode, method = RequestMethod.GET)
    @ApiOperation(value = "根据菜单id获取报表内容")
    public Envelop getReportByMenuId(
            @ApiParam(name = "code", value = "分类编码", defaultValue = "")
            @RequestParam(value = "code", required = false) String code) {
        Envelop envelop = new Envelop();
        List<RsReportCategoryInfoModel> list = new ArrayList<>();
        try {
            List<Integer> CategoryIds = rsReportCategoryClient.getCategoryIdsByCode(code);
            if (null != CategoryIds && CategoryIds.size() > 0) {
                List<RsReportCategoryInfoModel> categoryInfoModelList = rsReportCategoryClient.getCategoryByIds(CategoryIds);
                if (null != categoryInfoModelList && categoryInfoModelList.size() > 0) {
                    for (RsReportCategoryInfoModel m : categoryInfoModelList) {
                        if (null != m) {
                            // 根据categoryId获取报表信息
                            List<RsReportModel> rsReportModels = rsReportClient.getByCategoryId(m.getId());
                            m.setReportList(rsReportModels);
                        }
                        list.add(m);
                    }
                }
            }
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(list);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setErrorMsg("请求发生异常");
        }
        return envelop;
    }
}

+ 61 - 0
src/main/java/com/yihu/ehr/government/controller/GovernmentMenuReportMonitorTypeController.java

@ -0,0 +1,61 @@
package com.yihu.ehr.government.controller;
import com.yihu.ehr.agModel.government.GovernmentMenuReportMonitorTypeModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ErrorCode;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.government.service.GovernmentMenuReportMonitorTypeClient;
import com.yihu.ehr.quota.service.TjQuotaJobClient;
import com.yihu.ehr.users.service.UserClient;
import com.yihu.ehr.util.log.LogService;
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 wxw on 2017/11/2.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "governmentMenuReportMonitorType", description = "政府服务平台菜单报表监测类型接口", tags = {"政府服务平台-菜单"})
public class GovernmentMenuReportMonitorTypeController extends BaseController {
    @Autowired
    private GovernmentMenuReportMonitorTypeClient governmentMenuReportMonitorTypeClient;
    @Autowired
    private UserClient userClient;
    @Autowired
    private TjQuotaJobClient tjQuotaJobClient;
    @ApiOperation("政府服务平台菜单报表监测类型")
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuReportMonitorTypeSave, method = RequestMethod.POST)
    public Envelop add(
            @ApiParam(name = "rsReoportMonitorTypeId", value = "资源报表监测分类ID", required = true)
            @RequestParam(value = "rsReoportMonitorTypeId") String rsReoportMonitorTypeId) throws Exception {
        Envelop envelop = new Envelop();
        GovernmentMenuReportMonitorTypeModel newMGovernmentMenuReportMonitorType = governmentMenuReportMonitorTypeClient.add(rsReoportMonitorTypeId);
        envelop.setObj(newMGovernmentMenuReportMonitorType);
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @ApiOperation("删除政府服务平台菜单报表监测类型")
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuReportMonitorTypeDelete, method = RequestMethod.DELETE)
    public Envelop delete(
            @ApiParam(name = "id", value = "主键", required = true)
            @RequestParam(value = "id") Integer id) throws Exception {
        Envelop envelop = new Envelop();
        governmentMenuReportMonitorTypeClient.delete(id);
        envelop.setSuccessFlg(true);
        return envelop;
    }
}

+ 61 - 0
src/main/java/com/yihu/ehr/government/controller/OutpatientsBoardController.java

@ -0,0 +1,61 @@
package com.yihu.ehr.government.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.government.service.OutpatientsBoardClient;
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 zdm on 2017/12/28.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "outpatientsBoard", description = "政府服务平台-门诊仪表盘", tags = {"政府服务平台-门诊仪表盘"})
public class OutpatientsBoardController extends BaseController {
        @Autowired
        private OutpatientsBoardClient outpatientsBoardClient;
        @RequestMapping(value = ServiceApi.Government.OutpatientsBoardCount, method = RequestMethod.POST)
        @ApiOperation(value = "统计门诊 当月相关数据")
        public Envelop outpatientsBoardCount(
                @ApiParam(name = "core", value = "集合", required = true)
                @RequestParam(value = "core") String core,
                @ApiParam(name = "position", value = "指标位置", required = true)
                @RequestParam(value = "position") String position) {
            Envelop envelop = new Envelop();
            envelop=outpatientsBoardClient.outpatientsBoardCount(core,position);
            return envelop;
        }
    @ApiOperation("医院门急诊人次分布")
    @RequestMapping(value = ServiceApi.Government.GetMonthDistribution, method = RequestMethod.POST)
    public Envelop getMonthDistribution(
            @ApiParam(name = "core", value = "集合", required = true)
            @RequestParam(value = "core") String core,
            @ApiParam(name = "year", value = "年份", required = true)
            @RequestParam(value = "year") String year) {
        Envelop envelop = new Envelop();
        envelop=outpatientsBoardClient.getMonthDistribution(core,year);
        return envelop;
    }
    @ApiOperation("本月各类医院门急诊人次")
    @RequestMapping(value = ServiceApi.Government.GetRescue, method = RequestMethod.POST)
    public Envelop getRescue() {
        Envelop envelop =outpatientsBoardClient.getRescue();
        return envelop;
    }
}

+ 37 - 0
src/main/java/com/yihu/ehr/government/service/GovernmentBrowseLogClient.java

@ -0,0 +1,37 @@
package com.yihu.ehr.government.service;
import com.yihu.ehr.agModel.government.GovernmentBrowseLogModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.entity.government.GovernmentBrowseLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Created by wxw on 2017/11/3.
 */
@FeignClient(name= MicroServices.User)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface GovernmentBrowseLogClient {
    @RequestMapping(value = ServiceApi.Government.AddGovernmentBrowseLog, method = RequestMethod.POST)
    @ApiOperation(value = "新增浏览记录")
    GovernmentBrowseLog saveGovernmentBrowseLog(@RequestBody String jsonData);
    @RequestMapping(value = ServiceApi.Government.searchGovernmentBrowseLog, method = RequestMethod.GET)
    @ApiOperation(value = "浏览记录")
    List<GovernmentBrowseLogModel> getBrowseName(@RequestParam(value = "userId", required = false) String userId);
    @RequestMapping(value = ServiceApi.Government.searchHotBrowseLog, method = RequestMethod.GET)
    @ApiOperation(value = "热门监测报表")
    List<GovernmentBrowseLog> getHotBrowseLog();
}

+ 52 - 0
src/main/java/com/yihu/ehr/government/service/GovernmentMenuClient.java

@ -0,0 +1,52 @@
package com.yihu.ehr.government.service;
import com.yihu.ehr.agModel.government.GovernmentMenuModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.common.ListResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Created by wxw on 2017/11/2.
 */
@FeignClient(name= MicroServices.User)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface GovernmentMenuClient {
    @RequestMapping(value = ServiceApi.Government.SearchGovernmentMenu, method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询政府服务平台菜单")
    ListResult getGovernmentMenuList(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuById , method = RequestMethod.GET)
    @ApiOperation(value = "根据Id查询详情")
    GovernmentMenuModel getGovernmentMenuById(@RequestParam(value = "id") Integer id);
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuCheckCode, method = RequestMethod.GET)
    @ApiOperation(value = "检查编码是否唯一")
    int getCountByCode(@RequestParam(value = "code") String code);
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuCheckName, method = RequestMethod.GET)
    @ApiOperation(value = "检查名称是否唯一")
    int getCountByName(@RequestParam(value = "name") String name);
    @RequestMapping(value = ServiceApi.Government.AddGovernmentMenu, method = RequestMethod.POST)
    @ApiOperation(value = "新增菜单")
    GovernmentMenuModel saveGovernmentMenu(@RequestBody String jsonData, @RequestParam(value = "ids") String ids);
    @RequestMapping(value = ServiceApi.Government.UpdateGovernmentMenu, method = RequestMethod.POST)
    @ApiOperation(value = "修改菜单")
    GovernmentMenuModel updateGovernmentMenu(@RequestBody String jsonData, @RequestParam(value = "ids") String ids);
}

+ 49 - 0
src/main/java/com/yihu/ehr/government/service/GovernmentMenuReportMonitorTypeClient.java

@ -0,0 +1,49 @@
package com.yihu.ehr.government.service;
import com.yihu.ehr.agModel.government.GovernmentMenuReportMonitorTypeModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * 资源报表监测监测分类 client
 *
 * @author janseny
 * @created 2017年11月7日15:05:53
 */
@FeignClient(name = MicroServices.User)
@RequestMapping(value = ApiVersion.Version1_0)
@ApiIgnore
public interface GovernmentMenuReportMonitorTypeClient {
    @ApiOperation("新增政府菜单资源报表监测分类")
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuReportMonitorTypeSave, method = RequestMethod.POST)
    GovernmentMenuReportMonitorTypeModel add(
            @ApiParam(name = "governmentMenuReportMonitorType", value = "政府菜单资源报表监测分类JSON字符串", required = true)
            @RequestBody String governmentMenuReportMonitorType);
    @ApiOperation("删除政府菜单资源报表监测分类")
    @RequestMapping(value = ServiceApi.Government.GovernmentMenuReportMonitorTypeDelete, method = RequestMethod.DELETE)
    void delete(
            @ApiParam(name = "id", value = "政府菜单资源报表监测分类ID", required = true)
            @RequestParam(value = "id") Integer id);
    @ApiOperation("获取政府菜单资源报表监测类型Id")
    @RequestMapping(value = ServiceApi.Government.MonitorTypeList, method = RequestMethod.GET)
    List<Integer> getMonitorTypeIdByGovernmentMenuId(
            @ApiParam(name = "menuId", value = "菜单ID", required = true)
            @RequestParam(value = "menuId") String menuId);
}

+ 44 - 0
src/main/java/com/yihu/ehr/government/service/OutpatientsBoardClient.java

@ -0,0 +1,44 @@
package com.yihu.ehr.government.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Created by zdm on 2017/12/28.
 */
@FeignClient(name= MicroServices.Quota)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OutpatientsBoardClient {
    @ApiOperation("本月门急诊人次")
    @RequestMapping(value = "/statistics/{position}", method = RequestMethod.POST)
    Envelop outpatientsBoardCount(
            @ApiParam(name = "core", value = "集合", required = true)
            @RequestParam(value = "core") String core,
            @ApiParam(name = "position", value = "指标位置", required = true)
            @RequestParam(value = "position") String position);
    @ApiOperation("医院门急诊人次分布")
    @RequestMapping(value = ServiceApi.Government.GetMonthDistribution, method = RequestMethod.POST)
    Envelop getMonthDistribution(
            @ApiParam(name = "core", value = "集合", required = true)
            @RequestParam(value = "core") String core,
            @ApiParam(name = "year", value = "年份", required = true)
            @RequestParam(value = "year") String year);
    @ApiOperation("医院门急诊人次分布")
    @RequestMapping(value = ServiceApi.Government.GetRescue, method = RequestMethod.POST)
    Envelop getRescue();
}

+ 171 - 0
src/main/java/com/yihu/ehr/log/controller/LogController.java

@ -0,0 +1,171 @@
package com.yihu.ehr.log.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.log.service.LogClient;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
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.cloud.netflix.feign.EnableFeignClients;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Created by zhoujie on 2017/3/11.
 */
@EnableFeignClients
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "log", description = "日志页面展示", tags = {"云门户-日志页面展示"})
public class LogController extends BaseController {
    @Autowired
    private LogClient logClient;
    @Autowired
    private ConventionalDictEntryClient conventionalDictClient;
    @RequestMapping(value = "/getLogList", method = RequestMethod.GET)
    @ApiOperation(value = "获取业务日志列表", notes = "根据查询条件业务日志列表在前端展示")
    public Envelop getLogList(
            @ApiParam(name = "logType", value = "日志类型", defaultValue = "")
            @RequestParam(value = "logType", required = false) String logType,
            @ApiParam(name = "data", value = "数据", defaultValue = "")
            @RequestParam(value = "data", required = false) String data,
            @ApiParam(name = "startDate", value = "查询开始时间", defaultValue = "")
            @RequestParam(value = "startDate", required = false) String startDate,
            @ApiParam(name = "endDate", value = "查询结束时间", defaultValue = "")
            @RequestParam(value = "endDate", required = false) String endDate,
            @ApiParam(name = "caller", value = "调用者", defaultValue = "")
            @RequestParam(value = "caller", required = false) String caller,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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) {
        ListResult listResult = null;
        if(logType !=null){
            if(logType.equals("1")){
                listResult = logClient.getOperatorLogs(data, startDate, endDate, caller, sorts, size, page);
            }else if(logType.equals("2")){
                listResult = logClient.getBussinessLogs(data, startDate, endDate, caller, sorts, size, page);
            }
        }else {
            Envelop envelop = new Envelop();
            return envelop;
        }
        if(listResult.getTotalCount() != 0){
            List<Map<String,Object>> list = listResult.getDetailModelList();
            return getResult(list, listResult.getTotalCount(), listResult.getCurrPage(), listResult.getPageSize());
        }else{
            Envelop envelop = new Envelop();
            return envelop;
        }
    }
    @RequestMapping(value = "/getLogByIdAndType", method = RequestMethod.GET)
    @ApiOperation(value = "获取log信息", notes = "log信息")
    public Envelop getLogByIdAndType(
            @ApiParam(name = "logId", value = "日志id", defaultValue = "")
            @RequestParam(value = "logId") String logId,
            @ApiParam(name = "logType", value = "日志类型", defaultValue = "2")
            @RequestParam(value = "logType") String logType) {
        try {
            ListResult listResult = null;
            if(logType !=null){
                if(logType.equals("1")){
                    listResult = logClient.getOperatorLogById(logId);
                }else if(logType.equals("2")){
                    listResult = logClient.getBussinessLogById(logId);
                }else{
                    listResult = logClient.getBussinessLogById(logId);
                }
            }else {
                Envelop envelop = new Envelop();
                return envelop;
            }
            if(null!=listResult&&listResult.getTotalCount() != 0){
                List<Map<String,Object>> list = listResult.getDetailModelList();
                if(null!=list&&list.size()>0&&null!=list.get(0).get("response")){
                    list.get(0).put("response", list.get(0).get("response").toString().replace("\"","\\"+"\""));
                    //"response" -> "{"result":{"successFlg":true,"message":"登录成功!","errorCode":0,"data":{"userCode":"admin","token":"78df2308-deea-42c3-8939-12b11a1a917f","schema":"hos1","tenant":"yichang","schemaTemp":"hos1","role":null}}}"
                }
                return getResult(list, listResult.getTotalCount(), listResult.getCurrPage(), listResult.getPageSize());
            }else{
                Envelop envelop = new Envelop();
                return envelop;
            }
        }
        catch (Exception ex){
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/searchListLogs", method = RequestMethod.GET)
    @ApiOperation(value = "获取业务日志列表,姓名模糊查询", notes = "根据查询条件业务日志列表在前端展示")
    public Envelop searchListLogs(
            @ApiParam(name = "patient", value = "操作者", defaultValue = "")
            @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "logType", value = "日志类型", defaultValue = "")
            @RequestParam(value = "logType", required = false) String logType,
            @ApiParam(name = "startDate", value = "查询开始时间", defaultValue = "")
            @RequestParam(value = "startDate", required = false) String startDate,
            @ApiParam(name = "endDate", value = "查询结束时间", defaultValue = "")
            @RequestParam(value = "endDate", required = false) String endDate,
            @ApiParam(name = "caller", value = "调用者", defaultValue = "")
            @RequestParam(value = "caller", required = false) String caller,
            @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) {
        String data="";
        String sorts="";
        ListResult listResult = null;
        if(logType !=null){
            if(logType.equals("1")){
                listResult = logClient.getOperatorListLogs(patient,data, startDate, endDate, caller, sorts, size, page);
            }else if(logType.equals("2")){
                listResult = logClient.getBussinessListLogs(patient,data, startDate, endDate, caller, sorts, size, page);
            }
        }else {
            Envelop envelop = new Envelop();
            return envelop;
        }
        if(listResult.getTotalCount() != 0){
            List<Map<String,Object>> list = listResult.getDetailModelList();
            return getResult(list, listResult.getTotalCount(), listResult.getCurrPage(), listResult.getPageSize());
        }else{
            Envelop envelop = new Envelop();
            return envelop;
        }
    }
    @RequestMapping(value = "/getOperatorLogByAppKey", method = RequestMethod.GET)
    @ApiOperation(value = "根据id进行MONGODB日志的查询")
    public Envelop getOperatorLogByAppKey(
            @ApiParam(name = "appKey", value = "应用ID appkey就是appId", defaultValue = "")
            @RequestParam(value = "appKey", required = true) String appKey,
            @ApiParam(name = "responseFlag", value = "接口请求返回标识 1 成功 2 失败", defaultValue = "1")
            @RequestParam(value = "responseFlag", required = false) int responseFlag) throws Exception{
        return logClient.getOperatorLogByAppKey(appKey,responseFlag);
    }
}

+ 97 - 0
src/main/java/com/yihu/ehr/log/service/LogClient.java

@ -0,0 +1,97 @@
package com.yihu.ehr.log.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.portal.MPortalSetting;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Created by yeshijie on 2017/2/17.
 */
@FeignClient(name= MicroServices.Portal)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface LogClient {
    @RequestMapping(value = "/log/getBussinessLogs", method = RequestMethod.GET)
    @ApiOperation(value = "业务日志列表")
    ListResult getBussinessLogs(
            @RequestParam(value = "data", required = false) String data,
            @RequestParam(value = "startDate", required = false) String startDate,
            @RequestParam(value = "endDate", required = false) String endDate,
            @RequestParam(value = "caller", required = false) String caller,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page
    );
    @RequestMapping(value = "/log/getOperatorLogs", method = RequestMethod.GET)
    @ApiOperation(value = "操作日志列表")
    ListResult getOperatorLogs(
            @RequestParam(value = "data", required = false) String data,
            @RequestParam(value = "startDate", required = false) String startDate,
            @RequestParam(value = "endDate", required = false) String endDate,
            @RequestParam(value = "caller", required = false) String caller,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page
    );
    @RequestMapping(value = "/getBussinessLogById/{logId}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取业务日志详情")
    ListResult getBussinessLogById(
            @RequestParam(value = "logId", required = false) String logId
    );
    @RequestMapping(value = "/getOperatorLogById/{logId}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取操作日志详情")
    ListResult getOperatorLogById(
            @RequestParam(value = "logId", required = false) String logId
    );
    @RequestMapping(value = "/log/getBussinessListLogs", method = RequestMethod.GET)
    @ApiOperation(value = "业务日志列表,姓名模糊查询")
    ListResult getBussinessListLogs(
            @RequestParam(value = "patient", required = false) String patient,
            @RequestParam(value = "data", required = false) String data,
            @RequestParam(value = "startDate", required = false) String startDate,
            @RequestParam(value = "endDate", required = false) String endDate,
            @RequestParam(value = "caller", required = false) String caller,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page
    );
    @RequestMapping(value = "/log/getOperatorListLogs", method = RequestMethod.GET)
    @ApiOperation(value = "操作日志列表,姓名模糊查询")
    ListResult getOperatorListLogs(
            @RequestParam(value = "patient", required = false) String patient,
            @RequestParam(value = "data", required = false) String data,
            @RequestParam(value = "startDate", required = false) String startDate,
            @RequestParam(value = "endDate", required = false) String endDate,
            @RequestParam(value = "caller", required = false) String caller,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page
    );
    @RequestMapping(value = "/getOperatorLogByAppKey", method = RequestMethod.GET)
    @ApiOperation(value = "根据id进行MONGODB日志的查询")
    Envelop getOperatorLogByAppKey(
            @ApiParam(name = "appKey", value = "应用ID appkey就是appId", defaultValue = "")
            @RequestParam(value = "appKey", required = false) String appKey,
            @ApiParam(name = "responseFlag", value = "接口请求返回标识 1 成功 2 失败", defaultValue = "1")
            @RequestParam(value = "responseFlag", required = true) int responseFlag
    );
}

+ 192 - 0
src/main/java/com/yihu/ehr/msg/controller/TelVerificationController.java

@ -0,0 +1,192 @@
package com.yihu.ehr.msg.controller;
import com.yihu.ehr.apps.service.AppClient;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.model.app.MApp;
import com.yihu.ehr.model.user.MUser;
import com.yihu.ehr.msg.service.TelVerificationClient;
import com.yihu.ehr.users.service.UserClient;
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.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
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 yeshijie on 2017/2/14.
 */
@EnableFeignClients
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "TelVerification", description = "手机验证码接口管理", tags = {"基础信息 - 手机短信验证"})
public class TelVerificationController extends BaseController {
    @Autowired
    private AppClient appClient;
    @Autowired
    private UserClient userClient;
    @Autowired
    private TelVerificationClient telVerificationClient;
    @Value("${service-gateway.url}")
    private String gatewayUrl;
    @Value("${service-gateway.handlerId}")
    private String handlerId;
    @Value("${service-gateway.clientId}")
    private String clientId;
    @Value("${service-gateway.clientVersion}")
    private String clientVersion;
    /*
     * 1.1验证APPID的有效性
     * 1.2生成随机6位验证码,并存储
     * 1.3调用短信发送接口,进行短信的发送
     */
    @RequestMapping(value = "/msg/sendMsg", method = RequestMethod.GET)
    @ApiOperation(value = "验证码获取接口", notes = "根据手机号及应用的ID获取短信验证码信息")
    public Envelop sendMsg(
            @ApiParam(name = "appId", value = "应用ID")
            @RequestParam(value = "appId", required = false) String appId,
            @ApiParam(name = "tel", value = "手机号码", defaultValue = "")
            @RequestParam(value = "tel", required = false) String tel) throws Exception {
        Envelop envelop = new Envelop();
        //1.1验证APPID的有效性
        MApp mApp = appClient.getApp(appId);
        if (mApp == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("对不起,你所使用的应用尚未进行注册。");
            return envelop;
        }
        //1.2生成随机6位验证码,并存储验证信息
        Envelop result = telVerificationClient.createTelVerification(tel, appId);
        return result;
    }
    /*
     * 1.1直接验证验证码的有效性
     */
    @RequestMapping(value = "/msg/validate", method = RequestMethod.GET)
    @ApiOperation(value = "验证码有效性验证", notes = "根据手机号及应用的ID获取短信验证码信息,并校验")
    public Envelop validate(
            @ApiParam(name = "appId", value = "应用ID")
            @RequestParam(value = "appId", required = false) String appId,
            @ApiParam(name = "tel", value = "手机号码", defaultValue = "")
            @RequestParam(value = "tel", required = false) String tel,
            @ApiParam(name = "verificationCode", value = "手机验证码", defaultValue = "")
            @RequestParam(value = "verificationCode", required = false) String verificationCode) throws Exception {
        Envelop envelop = new Envelop();
        envelop = telVerificationClient.validationTelVerification(tel, appId, verificationCode);
        if (envelop == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("验证失败,请联系管理员!");
        }
        return envelop;
    }
    /*
    * 1.1直接验证验证码的有效性
    * 1.2根据手机号获取用户信息
    * 1.3修改该用户的密码信息
    * 1.4删除验证码信息
    */
    @RequestMapping(value = "/users/updatePasswordByVerificationCode", method = RequestMethod.GET)
    @ApiOperation(value = "忘记密码 - 修改密码", notes = "根据验证码修改用户密码信息")
    public Envelop updatePasswordByVerificationCode(
            @ApiParam(name = "appId", value = "应用ID")
            @RequestParam(value = "appId", required = false) String appId,
            @ApiParam(name = "tel", value = "手机号码", defaultValue = "")
            @RequestParam(value = "tel", required = false) String tel,
            @ApiParam(name = "verificationCode", value = "验证码", defaultValue = "")
            @RequestParam(value = "verificationCode", required = false) String verificationCode,
            @ApiParam(name = "password", value = "新密码", defaultValue = "")
            @RequestParam(value = "password", required = false) String password) throws Exception {
        Envelop envelop = new Envelop();
        envelop = telVerificationClient.validationTelVerification(tel, appId, verificationCode);
        if (envelop == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("验证失败,请联系管理员!");
            return envelop;
        }
        if (envelop.isSuccessFlg()) {
            //获取用户信息,根据手机号码
            MUser mUser = userClient.getUserByTel(tel);
            if (mUser == null) {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("对不起,手机号码无法验证,请确认!");
                return envelop;
            }
            String userId = mUser.getId().toString();
            //在微服务中会将该密码信息进行MD5加密
            Boolean result = userClient.changePassWord(userId, password);
            if (result) {
                envelop.setSuccessFlg(true);
                envelop.setErrorMsg("密码修改成功!");
            } else {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("密码修改失败,请联系管理员!");
            }
        }
        return envelop;
    }
    /*
   * 1.1直接验证验证码的有效性
   * 1.2根据手机号获取用户信息
   * 1.3修改该用户的密码信息
   * 1.4删除验证码信息
   */
    @RequestMapping(value = "/users/updatePasswordByOldPwd", method = RequestMethod.GET)
    @ApiOperation(value = "修改密码", notes = "根据旧密码修改用户的密码信息")
    public Envelop updatePasswordByOldPwd(
            @ApiParam(name = "appId", value = "应用ID")
            @RequestParam(value = "appId", required = false) String appId,
            @ApiParam(name = "userId", value = "手机号码", defaultValue = "")
            @RequestParam(value = "userId", required = false) String userId,
            @ApiParam(name = "passwordOld", value = "验证码", defaultValue = "")
            @RequestParam(value = "passwordOld", required = false) String passwordOld,
            @ApiParam(name = "passwordNew", value = "新密码", defaultValue = "")
            @RequestParam(value = "passwordNew", required = false) String passwordNew) throws Exception {
        Envelop envelop = new Envelop();
        //获取用户信息,根据用户ID
        MUser mUser = userClient.getUser(userId);
        if (mUser == null) {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("对不起,该用户不存在,请确认!");
            return envelop;
        }
        //对旧密码进行MD5加密后,进行对比验证
        String hashPassWordOld = DigestUtils.md5Hex(passwordOld);
        if (StringUtils.equals(hashPassWordOld, mUser.getPassword().toString())) {
            //当验证通过后,进行新密码的更新在微服务中会将该密码信息进行MD5加密
            Boolean result = userClient.changePassWord(userId, passwordNew);
            if (result) {
                envelop.setSuccessFlg(true);
                envelop.setErrorMsg("密码修改成功!");
            } else {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("密码修改失败,请联系管理员!");
            }
        } else {
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("对不起,密码验证失败,请确认!");
        }
        return envelop;
    }
}

+ 42 - 0
src/main/java/com/yihu/ehr/msg/service/TelVerificationClient.java

@ -0,0 +1,42 @@
package com.yihu.ehr.msg.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
/**
 * Created by AndyCai on 2016/2/1.
 */
@FeignClient(name= MicroServices.Organization)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface TelVerificationClient {
    @RequestMapping(value = ServiceApi.TelVerification.TelVerificationMsgSendMsg, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建手机验证信息", notes = "创建手机验证信息")
    Envelop createTelVerification(
            @ApiParam(name = "telNo", value = "", defaultValue = "")
            @RequestParam(value = "telNo", required = false) String tel,
            @ApiParam(name = "appId", value = "", defaultValue = "")
            @RequestParam(value = "appId", required = false) String appId) throws Exception ;
    @RequestMapping(value = ServiceApi.TelVerification.TelVerificationMsgValidate, method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "验证手机验证信息", notes = "验证手机验证信息")
    Envelop validationTelVerification(
            @ApiParam(name = "telNo", value = "", defaultValue = "")
            @RequestParam(value = "telNo", required = false) String tel,
            @ApiParam(name = "appId", value = "", defaultValue = "")
            @RequestParam(value = "appId", required = false) String appId,
            @ApiParam(name = "verificationCode", value = "", defaultValue = "")
            @RequestParam(value = "verificationCode", required = false) String verificationCode) throws Exception ;
}

+ 749 - 0
src/main/java/com/yihu/ehr/organization/controller/OrgDeptController.java

@ -0,0 +1,749 @@
package com.yihu.ehr.organization.controller;
import com.yihu.ehr.agModel.org.OrgDeptDetailModel;
import com.yihu.ehr.agModel.org.OrgDeptMemberModel;
import com.yihu.ehr.agModel.org.OrgDeptModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.org.MOrgDept;
import com.yihu.ehr.model.org.MOrgDeptData;
import com.yihu.ehr.model.org.MOrgDeptDetail;
import com.yihu.ehr.model.org.MOrgMemberRelation;
import com.yihu.ehr.model.user.MUser;
import com.yihu.ehr.organization.service.OrgDeptClient;
import com.yihu.ehr.organization.service.OrgDeptMemberClient;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.users.service.UserClient;
import com.yihu.ehr.util.fzgateway.FzGatewayUtil;
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.cloud.netflix.feign.EnableFeignClients;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2017/2/20.
 */
@EnableFeignClients
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "orgDept", description = "机构信息部门管理", tags = {"机构管理 - 机构部门管理"})
public class OrgDeptController extends BaseController {
    @Autowired
    private OrgDeptClient orgDeptClient;
    @Autowired
    private OrgDeptMemberClient orgDeptMemberClient;
    @Autowired
    private UserClient userClient;
    @Autowired
    private ConventionalDictEntryClient conventionalDictClient;
    @Autowired
    private OrganizationClient orgClient;
    @Value("${service-gateway.url}")
    private String gatewayUrl;
    @Value("${service-gateway.clientId}")
    private String clientId;
    @Value("${service-gateway.clientVersion}")
    private String clientVersion;
    @ApiOperation(value = "获取所有部门列表")
    @RequestMapping(value = "/orgDept/getAllOrgDepts", method = RequestMethod.GET)
    public Envelop getAllOrgDepts() {
        try {
            Envelop envelop = new Envelop();
            envelop.setDetailModelList(orgDeptClient.getAllOrgDepts());
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @ApiOperation(value = "根据组织机构ID获取部门列表")
    @RequestMapping(value = "/orgDept/list", method = RequestMethod.GET)
    public Envelop getOrgDeptsByOrgId(
            @ApiParam(name = "orgId", value = "机构ID", defaultValue = "")
            @RequestParam(value = "orgId") String orgId) {
        try {
            Envelop envelop = new Envelop();
            envelop.setDetailModelList(orgDeptClient.searchOrgDepts(orgId));
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @ApiOperation(value = "根据父级部门ID获取子部门列表")
    @RequestMapping(value = "/orgDept/childs", method = RequestMethod.POST)
    public Envelop searchChildOrgDepts(
            @ApiParam(name = "parentDeptId", value = "父级部门ID")
            @RequestParam(value = "parentDeptId") Integer parentDeptId) {
        try {
            Envelop envelop = new Envelop();
            envelop.setDetailModelList(orgDeptClient.searchChildOrgDepts(parentDeptId));
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept/detail", method = RequestMethod.POST)
    @ApiOperation(value = "查询部门&科室详情")
    public Envelop detail(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId
    ) {
        try {
            String errorMsg = "";
            if (deptId == null) {
                errorMsg += "部门不能为空!";
            }
            MOrgDept mOrgDeptNew = orgDeptClient.searchDeptDetail(deptId);
            if (mOrgDeptNew == null) {
                return failed("获取部门详情失败!");
            }
            return success(mOrgDeptNew);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept/detailById", method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询部门&科室详情")
    public Envelop detailById(
            @ApiParam(name = "deptId", value = "deptId")
            @RequestParam(value = "deptId", required = true) Integer deptId) {
        try {
            String errorMsg = "";
            if (deptId == null) {
                errorMsg += "部门不能为空!";
            }
            MOrgDept mOrgDeptNew = orgDeptClient.searchDeptDetail(deptId);
            if (mOrgDeptNew == null) {
                return failed("获取部门详情失败!");
            }
            if (mOrgDeptNew.getDeptDetail() != null) {
                //获取类别字典
                MConventionalDict dict = conventionalDictClient.getOrgDeptDetailDisplayStatus(String.valueOf(mOrgDeptNew.getDeptDetail().getDisplayStatus()));
                mOrgDeptNew.getDeptDetail().setDisplayStatusName(dict == null ? "" : dict.getValue());
                MConventionalDict dict2 = conventionalDictClient.getOrgDeptDetailPyCode(String.valueOf(mOrgDeptNew.getDeptDetail().getPyCode()));
                mOrgDeptNew.getDeptDetail().setPyCodeName(dict2 == null ? "" : dict2.getValue());
                String[] glory = mOrgDeptNew.getDeptDetail().getGloryId().split(",");
                String gloryName = "";
                for (int i = 0; i < glory.length; i++) {
                    MConventionalDict dict3 = conventionalDictClient.getOrgDeptDetailGloryId(glory[i]);
                    gloryName += (dict3 == null ? "" : dict3.getValue()) + ",";
                }
                mOrgDeptNew.getDeptDetail().setGloryName(gloryName.substring(0, gloryName.length() - 1));
            }
            return success(mOrgDeptNew);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept", method = RequestMethod.POST)
    @ApiOperation(value = "新增机构部门")
    public Envelop create(
            @ApiParam(name = "orgDeptsJsonData", value = " 部门信息Json", defaultValue = "")
            @RequestParam(value = "orgDeptsJsonData", required = false) String orgDeptsJsonData) {
        try {
            String errorMsg = "";
            OrgDeptModel orgDeptModel = objectMapper.readValue(orgDeptsJsonData, OrgDeptModel.class);
//            MOrgDept mOrgDept = convertToModel(orgDeptModel, MOrgDept.class);
            if (StringUtils.isEmpty(orgDeptModel.getCode())) {
                errorMsg += "部门代码不能为空!";
            }
            if (StringUtils.isEmpty(orgDeptModel.getName())) {
                errorMsg += "部门不能为空!";
            }
            if (StringUtils.isEmpty(orgDeptModel.getOrgId())) {
                errorMsg += "机构不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            //云门户保存
            String mOrganizationJson = objectMapper.writeValueAsString(orgDeptModel);
            MOrgDept mOrgDeptNew = orgDeptClient.saveOrgDept(mOrganizationJson);
            if (mOrgDeptNew == null) {
                return failed("保存失败!");
            }
          /*  //同步科室信息-因为在预约挂号后台追加排班信息时,会判断是否存在科室,若不存在,总部自动追加。EHR使用标准科室。
            Map<String, Object> result = saveSynDept(orgDeptModel);
            if (result.get("Code").toString().equals("10000")) {
                //同步成功
                mOrgDeptNew.setJkzlHosDeptId(Integer.parseInt(result.get("hosDeptId").toString()));
                String mOrgDeptNewJson = objectMapper.writeValueAsString(orgDeptModel);
                orgDeptClient.updateOrgDept(mOrgDeptNewJson);
            } else {
                //同步失败
                return failed("保存失败!");
            }*/
            return success(mOrgDeptNew);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 同步科室信息
     *
     * @param orgDeptModel
     */
    private Map<String, Object> saveSynDept(OrgDeptModel orgDeptModel) throws Exception {
        String api = "baseinfo.HosDeptApi.insertHosDept";
        String orgId = orgClient.getOrgById(orgDeptModel.getOrgId()).getJkzlOrgId();
        int parentDeptId = 0;
        if (orgDeptModel.getParentDeptId() != 0) {
            MOrgDept dept = orgDeptClient.searchDeptDetail(orgDeptModel.getParentDeptId());
            parentDeptId = dept.getJkzlHosDeptId();
        }
        Map<String, Object> apiParamMap = new HashMap<>();
        apiParamMap.put("orgId", orgId);//医院orgId
        apiParamMap.put("parentDeptID", parentDeptId);//上级科室 如果没有上级科室传0
        if(null == orgDeptModel.getDeptDetail().getTypeId()){
            apiParamMap.put("typeId", 2);//科室类型
        }else{
            apiParamMap.put("typeId", orgDeptModel.getDeptDetail().getTypeId());//科室类型
        }
        apiParamMap.put("deptName", orgDeptModel.getDeptDetail().getName());//科室名称
        apiParamMap.put("intro", orgDeptModel.getDeptDetail().getIntroduction());//科室简介
        apiParamMap.put("place", orgDeptModel.getDeptDetail().getPlace());//科室位置
        apiParamMap.put("deptCode", orgDeptModel.getDeptDetail().getDeptId());//科室代码
        apiParamMap.put("displayStatus", orgDeptModel.getDeptDetail().getDisplayStatus());//显示状态
        String resultStr = FzGatewayUtil.httpPost(gatewayUrl, clientId, clientVersion, api, apiParamMap, 1);
        logger.info(resultStr);
        return objectMapper.readValue(resultStr, Map.class);
    }
    @RequestMapping(value = "/orgDept", method = RequestMethod.PUT)
    @ApiOperation(value = "修改部门&科室详情")
    public Envelop update(
            @ApiParam(name = "orgDeptJsonData", value = " 部门信息Json", defaultValue = "")
            @RequestParam(value = "orgDeptJsonData", required = false) String orgDeptJsonData) {
        try {
            String errorMsg = "";
            OrgDeptModel orgDeptModel = objectMapper.readValue(orgDeptJsonData, OrgDeptModel.class);
            OrgDeptDetailModel deptDetailModel = orgDeptModel.getDeptDetail();
            MOrgDeptDetail mOrgDeptDetail = convertToModel(deptDetailModel, MOrgDeptDetail.class);
            MOrgDept mOrgDept = convertToModel(orgDeptModel, MOrgDept.class);
            mOrgDept.setDeptDetail(mOrgDeptDetail);
            if (StringUtils.isEmpty(mOrgDept.getCode())) {
                errorMsg += "部门代码不能为空!";
            }
            if (StringUtils.isEmpty(mOrgDept.getName())) {
                errorMsg += "部门不能为空!";
            }
            if (StringUtils.isEmpty(mOrgDept.getOrgId())) {
                errorMsg += "机构不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            String mOrganizationJson = objectMapper.writeValueAsString(mOrgDept);
            MOrgDept mOrgDeptNew = orgDeptClient.updateOrgDept(mOrganizationJson);
            if (mOrgDeptNew == null) {
                return failed("保存失败!");
            }
            return success(mOrgDeptNew);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept/checkDeptName", method = RequestMethod.PUT)
    @ApiOperation(value = "检查机构下部门名称是否唯一")
    public Envelop checkDeptName(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId", required = true) Integer orgId,
            @ApiParam(name = "name", value = "新部门名称")
            @RequestParam(value = "name", required = true) String name
    ) {
        try {
            Envelop envelop = new Envelop();
            String errorMsg = "";
            if (orgId == null) {
                envelop.setErrorMsg("机构不能为空!");
            }
            if (StringUtils.isEmpty(name)) {
                envelop.setErrorMsg("新部门名称不能为空!");
            }
            int num = orgDeptClient.getCountByDeptName(orgId, name);
            if (num > 0) {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("所在机构已经存在此部门!");
            } else {
                envelop.setSuccessFlg(true);
            }
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept/resetName", method = RequestMethod.POST)
    @ApiOperation(value = "修改机构部们名称")
    public Envelop resetDeptName(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId,
            @ApiParam(name = "name", value = "新部门名称")
            @RequestParam(value = "name", required = true) String name
    ) {
        try {
            String errorMsg = "";
            if (deptId == null) {
                errorMsg += "部门不能为空!";
            }
            if (StringUtils.isEmpty(name)) {
                errorMsg += "新部门名称不能为空!";
            }
            MOrgDept mOrgDeptNew = orgDeptClient.updateOrgDeptName(deptId, name);
            if (mOrgDeptNew == null) {
                return failed("修改部门失败!");
            }
            return success(mOrgDeptNew);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除机构部门")
    public boolean delete(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId
    ) {
        try {
            boolean succ = orgDeptClient.deleteOrgDept(deptId);
            return succ;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    @RequestMapping(value = "/orgDept/checkMembers", method = RequestMethod.POST)
    @ApiOperation(value = "机构部门下是否有成员存在")
    public boolean isHasMember(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId) {
        try {
            boolean succ = orgDeptClient.isHasMember(deptId);
            return succ;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    @RequestMapping(value = "/orgDept/changeSort", method = RequestMethod.POST)
    @ApiOperation(value = "部门排序")
    public boolean changeSort(
            @ApiParam(name = "preDeptId", value = "第一个部门ID")
            @RequestParam(value = "preDeptId", required = true) Integer preDeptId,
            @ApiParam(name = "afterDeptId", value = "第二个部门ID")
            @RequestParam(value = "afterDeptId", required = true) Integer afterDeptId) {
        try {
            boolean succ = orgDeptClient.changeSort(preDeptId, afterDeptId);
            return succ;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    /* ****************************     部门成员相关   ********************************************/
    @RequestMapping(value = "/orgDeptMember/list", method = RequestMethod.POST)
    @ApiOperation(value = "获取部门下成员列表", notes = "根据查询条件获取部门成员列表在前端表格展示")
    public Envelop searchOrgDeptMembers(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,userName,dutyName")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+deptId")
            @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) {
        try {
            List<OrgDeptMemberModel> orgMemberModels = new ArrayList<>();
            ResponseEntity<List<MOrgMemberRelation>> responseEntity = orgDeptMemberClient.searchOrgDeptMembers(fields, filters, sorts, size, page);
            List<MOrgMemberRelation> members = responseEntity.getBody();
            for (MOrgMemberRelation deptMember : members) {
                OrgDeptMemberModel memberModel = convertToModel(deptMember, OrgDeptMemberModel.class);
//                if (StringUtils.isNotEmpty(memberModel.getUserId()) ){
//                    MUser mUser = userClient.getUser(memberModel.getUserId());
//                    memberModel.setUserName(mUser == null ? "" : mUser.getRealName());
//                }
//                if (memberModel.getDeptId()!=null && memberModel.getDeptId()!=0 ){
//                    MOrgDept mOrgDept = orgDeptClient.searchDeptDetail(memberModel.getDeptId());
//                    memberModel.setDeptName(mOrgDept == null ? "" : mOrgDept.getName());
//                }
                orgMemberModels.add(memberModel);
            }
            int totalCount = getTotalCount(responseEntity);
            return getResult(orgMemberModels, totalCount, page, size);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDeptMember/getOrgDeptMembers", method = RequestMethod.POST)
    @ApiOperation(value = "获取部门下成员列表", notes = "根据查询条件获取机构成员去重复列表在前端表格展示")
    public Envelop getOrgDeptMembers(
            @ApiParam(name = "orgId", value = "机构ID", defaultValue = "")
            @RequestParam(value = "orgId", required = false) String orgId,
            @ApiParam(name = "searchParm", value = "关键字查询", defaultValue = "")
            @RequestParam(value = "searchParm", required = false) String searchParm,
            @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) {
        try {
            ResponseEntity<List<MOrgMemberRelation>> responseEntity = orgDeptMemberClient.getOrgDeptMembers(orgId, searchParm, size, page);
            List<MOrgMemberRelation> members = responseEntity.getBody();
            int totalCount = getTotalCount(responseEntity);
            return getResult(members, totalCount, page, size);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @ApiOperation(value = "获取所有成员列表")
    @RequestMapping(value = "/orgDeptMember/getAllOrgDeptMember", method = RequestMethod.GET)
    public Envelop getAllOrgDeptMember(
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters) {
        try {
            Envelop envelop = new Envelop();
            List<MOrgMemberRelation> memberRelationList = new ArrayList<MOrgMemberRelation>();
            ResponseEntity<List<MOrgMemberRelation>> responseEntity = orgDeptMemberClient.getAllOrgDeptMember(filters);
            memberRelationList = responseEntity.getBody();
            if (memberRelationList != null && memberRelationList.size() > 0) {
                for (MOrgMemberRelation memberRelation : memberRelationList) {
                    if (StringUtils.isNotEmpty(memberRelation.getUserId()) && StringUtils.isEmpty(memberRelation.getUserName())) {
                        MUser mUser = userClient.getUser(memberRelation.getUserId());
                        memberRelation.setUserName(mUser == null ? "" : mUser.getRealName());
                    }
                }
            }
            envelop.setDetailModelList(memberRelationList);
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @ApiOperation(value = "获取所有成员列表去重复")
    @RequestMapping(value = "/orgDeptMember/getAllOrgDeptMemberDistinct", method = RequestMethod.GET)
    public Envelop getAllOrgDeptMemberDistinct(
            @ApiParam(name = "orgId", value = "机构ID", defaultValue = "")
            @RequestParam(value = "orgId", required = false) String orgId,
            @ApiParam(name = "searchNm", value = "关键字查询", defaultValue = "")
            @RequestParam(value = "searchNm", required = false) String searchNm
    ) {
        try {
            Envelop envelop = new Envelop();
            List<MOrgMemberRelation> memberRelationList = new ArrayList<MOrgMemberRelation>();
            ResponseEntity<List<MOrgMemberRelation>> responseEntity = orgDeptMemberClient.getAllOrgDeptMemberDistinct(orgId, searchNm);
            memberRelationList = responseEntity.getBody();
            if (memberRelationList != null && memberRelationList.size() > 0) {
                for (MOrgMemberRelation memberRelation : memberRelationList) {
                    if (StringUtils.isNotEmpty(memberRelation.getUserId()) && StringUtils.isEmpty(memberRelation.getUserName())) {
                        MUser mUser = userClient.getUser(memberRelation.getUserId());
                        memberRelation.setUserName(mUser == null ? "" : mUser.getRealName());
                    }
                }
            }
            envelop.setDetailModelList(memberRelationList);
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDept/checkUser", method = RequestMethod.PUT)
    @ApiOperation(value = "检查机构下用户是否唯一")
    public Envelop checkUser(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId", required = true) Integer orgId,
            @ApiParam(name = "userId", value = "用户ID")
            @RequestParam(value = "userId", required = true) String userId,
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId
    ) {
        try {
            Envelop envelop = new Envelop();
            String errorMsg = "";
            if (orgId == null) {
                errorMsg += "机构不能为空!";
                envelop.setErrorMsg(errorMsg);
            }
            if (StringUtils.isEmpty(userId)) {
                errorMsg += "用户不能为空!";
                envelop.setErrorMsg(errorMsg);
            }
            int num = orgDeptClient.getCountByUserId(orgId, userId, deptId);
            if (num > 0) {
                envelop.setSuccessFlg(false);
                envelop.setErrorMsg("所在机构中的部门已经存在此用户!");
            } else {
                envelop.setSuccessFlg(true);
            }
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "orgDeptMember/admin/{memRelationId}", method = RequestMethod.GET)
    @ApiOperation(value = "获取部门成员信息", notes = "部门成员信息")
    public Envelop getOrgMemberRelation(
            @ApiParam(name = "memRelationId", value = "", defaultValue = "")
            @PathVariable(value = "memRelationId") Long memRelationId) {
        try {
            MOrgMemberRelation mOrgMemberRelation = orgDeptMemberClient.getOrgMemberRelation(memRelationId);
            if (mOrgMemberRelation == null) {
                return failed("提醒消息信息获取失败!");
            }
            OrgDeptMemberModel detailModel = convertToModel(mOrgMemberRelation, OrgDeptMemberModel.class);
            if (StringUtils.isNotEmpty(detailModel.getUserId())) {
                MUser mUser = userClient.getUser(detailModel.getUserId());
                detailModel.setUserName(mUser == null ? detailModel.getUserName() : mUser.getRealName());
            }
            if (StringUtils.isNotEmpty(detailModel.getParentUserId())) {
                MUser mUser = userClient.getUser(detailModel.getParentUserId());
                detailModel.setParentUserName(mUser == null ? detailModel.getParentUserName() : mUser.getRealName());
            }
            if (detailModel.getDeptId() != null && detailModel.getDeptId() != 0) {
                MOrgDept mOrgDept = orgDeptClient.searchDeptDetail(detailModel.getDeptId());
                detailModel.setDeptName(mOrgDept == null ? detailModel.getDeptName() : mOrgDept.getName());
            }
            return success(detailModel);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 创建部门成员
     *
     * @param memberRelationJsonData
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/orgDeptMember", method = RequestMethod.POST)
    @ApiOperation(value = "新增部门成员")
    public Envelop createDeptMember(
            @ApiParam(name = "memberRelationJsonData", value = " 部门成员信息Json", defaultValue = "")
            @RequestParam(value = "memberRelationJsonData", required = false) String memberRelationJsonData) {
        try {
            String errorMsg = "";
            OrgDeptMemberModel deptMemberModel = objectMapper.readValue(memberRelationJsonData, OrgDeptMemberModel.class);
            MOrgMemberRelation mDeptMember = convertToModel(deptMemberModel, MOrgMemberRelation.class);
            if (StringUtils.isEmpty(mDeptMember.getOrgId())) {
                errorMsg += "机构不能为空!";
            }
            if (StringUtils.isEmpty(mDeptMember.getUserId())) {
                errorMsg += "用户不能为空!";
            }
            if (mDeptMember.getDeptId() == null) {
                errorMsg += "部门不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
         /*   MUser mUser = userClient.getUser(mDeptMember.getUserId());
            mDeptMember.setUserName(mUser == null ? "" : mUser.getRealName());
            MUser mUserp = userClient.getUser(mDeptMember.getParentUserId());
            mDeptMember.setParentUserName(mUserp == null ? "" : mUserp.getRealName());*/
            MOrgDept mOrgDept = orgDeptClient.searchDeptDetail(mDeptMember.getDeptId());
            mDeptMember.setDeptName(mOrgDept == null ? "" : mOrgDept.getName());
            String deptMemberJsonStr = objectMapper.writeValueAsString(mDeptMember);
            MOrgMemberRelation deptMember = orgDeptMemberClient.saveOrgDeptMember(deptMemberJsonStr);
            if (deptMember == null) {
                return failed("保存失败!");
            }
            return success(deptMember);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 修改上级成员
     *
     * @param memberRelationJsonData
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/updateOrgDeptMemberParent", method = RequestMethod.POST)
    @ApiOperation(value = "修改部门成员上级成员")
    public Envelop updateDeptMember(
            @ApiParam(name = "memberRelationJsonData", value = " 部门成员信息Json", defaultValue = "")
            @RequestParam(value = "memberRelationJsonData", required = false) String memberRelationJsonData) {
        try {
            boolean succ = orgDeptMemberClient.updateOrgDeptMemberParent(memberRelationJsonData);
            if (!succ) {
                return failed("保存失败!");
            }
            return success(null);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/orgDeptMember/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除机构部门成员")
    public Envelop deleteDeptMember(
            @ApiParam(name = "memberRelationId", value = "部门成员关系ID")
            @RequestParam(value = "memberRelationId", required = true) Integer memberRelationId
    ) {
        try {
            boolean succ = orgDeptMemberClient.deleteOrgDeptMember(memberRelationId);
            if (!succ) {
                return failed("删除失败!");
            }
            return success(null);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 更新成员状态
     *
     * @param memberRelationId
     * @return
     */
    @RequestMapping(value = "/orgDeptMember/updateStatus", method = RequestMethod.PUT)
    @ApiOperation(value = "更新成员状态")
    public boolean updateDeptMemberStatus(
            @ApiParam(name = "memberRelationId", value = "memberRelationId", defaultValue = "")
            @RequestParam(value = "memberRelationId") Integer memberRelationId,
            @ApiParam(name = "status", value = "状态", defaultValue = "")
            @RequestParam(value = "status") Integer status) {
        try {
            return orgDeptMemberClient.updateStatusOrgDeptMember(memberRelationId, status);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    @ApiOperation(value = "根据用户ID获取部门列表")
    @RequestMapping(value = ServiceApi.Org.getUserOrglistByUserId, method = RequestMethod.GET)
    public Envelop getUserOrglistByUserId(
            @ApiParam(name = "userId", value = "用户ID", defaultValue = "")
            @RequestParam(value = "userId") String userId) {
        try {
            Envelop envelop = new Envelop();
            envelop.setDetailModelList(orgDeptClient.getUserOrglistByUserId(userId));
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Org.GetOrgDeptsDate, method = RequestMethod.GET)
    @ApiOperation(value = "根据机构id获取机构及部门列表")
    public Envelop getOrgDeptsDate(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId") String orgId) {
        try {
            Envelop envelop = new Envelop();
            MOrgDeptData orgDeptsDate = orgDeptClient.getOrgDeptsDate(orgId);
            List<MOrgDeptData> orgDeptDataList = new ArrayList<>();
            orgDeptDataList.add(orgDeptsDate);
            envelop.setDetailModelList(orgDeptDataList);
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @ApiOperation(value = "根据用户ID获取机构及部门列表")
    @RequestMapping(value = ServiceApi.Users.GetOrgAndDeptRelation, method = RequestMethod.GET)
    public Envelop getOrgAndDeptRelation(
            @ApiParam(name = "userId", value = "用户ID", defaultValue = "")
            @RequestParam(value = "userId") String userId) {
        Envelop envelop = new Envelop();
        try {
            List<MOrgDeptData> orgDeptJsonList = orgDeptMemberClient.getOrgAndDeptRelation(userId);
            envelop.setDetailModelList(orgDeptJsonList);
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            envelop.setErrorMsg(ex.getMessage());
            envelop.setSuccessFlg(false);
            return envelop;
        }
    }
}

+ 89 - 0
src/main/java/com/yihu/ehr/organization/controller/OrgDeptImportController.java

@ -0,0 +1,89 @@
package com.yihu.ehr.organization.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.organization.service.OrgDeptImportClient;
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.cloud.netflix.feign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by Administrator on 2017/7/14.
 */
@EnableFeignClients
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "orgDept", description = "机构&部门批量导入接口", tags = {"基础信息 - 机构&部门批量导入接口"})
public class OrgDeptImportController extends BaseController {
    @Autowired
    private OrgDeptImportClient orgDeptImportClient;
    @RequestMapping(value = "/orgDept/batch", method = RequestMethod.POST)
    @ApiOperation("批量导入机构&部门")
    public Envelop createOrgDeptsBatch(
            @ApiParam(name = "orgDepts", value = "JSON", defaultValue = "")
            @RequestParam(value = "orgDepts") String orgDepts) throws Exception {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        try{
            orgDeptImportClient.createOrgDeptsBatch(orgDepts);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("系统出错!");
        }
        return envelop;
    }
    @RequestMapping(value = "/code/existence",method = RequestMethod.POST)
    @ApiOperation("获取已存在部门编号")
    public List codeExistence(
            @ApiParam(name = "code", value = "", defaultValue = "")
            @RequestParam("code") String code) throws Exception {
        List existCode = orgDeptImportClient.codeExistence(code);
        return existCode;
    }
    @RequestMapping(value = "/name/existence",method = RequestMethod.POST)
    @ApiOperation("获取已存在部门名称")
    public List nameExistence(
            @ApiParam(name = "name", value = "", defaultValue = "")
            @RequestParam("name") String name) throws Exception {
        List existName = orgDeptImportClient.nameExistence(name);
        return existName;
    }
    @RequestMapping(value = "/orgCode/existence",method = RequestMethod.POST)
    @ApiOperation("获取已存在的机构代码")
    public List orgCodeExistence(
            @ApiParam(name = "orgCode", value = "", defaultValue = "")
            @RequestParam("orgCode") String orgCode) throws Exception {
        List existOrgCode = orgDeptImportClient.orgCodeExistence(orgCode);
        return existOrgCode;
    }
    @RequestMapping(value = "/orgDept/code/existence", method = RequestMethod.GET)
    @ApiOperation("根据过滤条件判断是否存在")
    public Envelop isExistence(
            @ApiParam(name = "filters", value = "filters", defaultValue = "")
            @RequestParam(value = "filters") String filters) {
        try {
            return success(orgDeptImportClient.isExistence(filters));
        } catch (Exception e) {
            e.printStackTrace();
            return failed("查询出错!");
        }
    }
}

+ 94 - 0
src/main/java/com/yihu/ehr/organization/controller/OrgHealthCategoryController.java

@ -0,0 +1,94 @@
package com.yihu.ehr.organization.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.organization.service.OrgHealthCategoryClient;
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.*;
/**
 * 卫生机构类别 Controller
 *
 * @author 张进军
 * @date 2017/12/21 12:00
 */
@RestController
@RequestMapping(value = ApiVersion.Version1_0 + "/admin")
@Api(description = "卫生机构类别接口", tags = {"机构管理--卫生机构类别接口"})
public class OrgHealthCategoryController extends BaseController {
    @Autowired
    private OrgHealthCategoryClient orgHealthCategoryClient;
    @ApiOperation("根据ID获取卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.GetById, method = RequestMethod.GET)
    public Envelop getById(
            @ApiParam(name = "id", value = "主键", required = true)
            @PathVariable(value = "id") Integer id) {
        return orgHealthCategoryClient.getById(id);
    }
    @ApiOperation("获取所有的卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.FindAll, method = RequestMethod.GET)
    public Envelop findAll() {
        return orgHealthCategoryClient.findAll();
    }
    @ApiOperation(value = "根据条件获取卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Search, method = RequestMethod.GET)
    public Envelop search(
            @ApiParam(name = "codeName", value = "卫生机构类别编码或名称")
            @RequestParam(value = "codeName", required = false) String codeName) {
        return orgHealthCategoryClient.search(codeName);
    }
    @ApiOperation("新增卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Save, method = RequestMethod.POST)
    public Envelop add(
            @ApiParam(name = "entityJson", value = "卫生机构类别JSON", required = true)
            @RequestParam(value = "entityJson") String entityJson) {
        return orgHealthCategoryClient.add(entityJson);
    }
    @ApiOperation("更新卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Save, method = RequestMethod.PUT)
    public Envelop update(
            @ApiParam(name = "entityJson", value = "卫生机构类别JSON", required = true)
            @RequestParam(value = "entityJson") String entityJson) {
        return orgHealthCategoryClient.update(entityJson);
    }
    @ApiOperation("删除卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Delete, method = RequestMethod.DELETE)
    public Envelop delete(
            @ApiParam(name = "id", value = "卫生机构类别ID", required = true)
            @RequestParam(value = "id") Integer id) {
        return orgHealthCategoryClient.delete(id);
    }
    @ApiOperation("验证卫生机构类别编码是否唯一")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.IsUniqueCode, method = RequestMethod.GET)
    public Envelop isUniqueChannel(
            @ApiParam(name = "id", value = "卫生机构类别ID", required = true)
            @RequestParam(value = "id") Integer id,
            @ApiParam(name = "code", value = "卫生机构类别编码", required = true)
            @RequestParam(value = "code") String code) {
        return orgHealthCategoryClient.isUniqueCode(id, code);
    }
    @ApiOperation("验证卫生机构类别名称是否唯一")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.IsUniqueName, method = RequestMethod.GET)
    public Envelop isUniqueChannelName(
            @ApiParam(name = "id", value = "卫生机构类别ID", required = true)
            @RequestParam(value = "id") Integer id,
            @ApiParam(name = "name", value = "卫生机构类别名称", required = true)
            @RequestParam(value = "name") String name) {
        return orgHealthCategoryClient.isUniqueName(id, name);
    }
}

+ 231 - 0
src/main/java/com/yihu/ehr/organization/controller/OrgSaasController.java

@ -0,0 +1,231 @@
package com.yihu.ehr.saas.controller;
import com.yihu.ehr.agModel.orgSaas.AreaSaasModel;
import com.yihu.ehr.agModel.orgSaas.OrgSaasModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.geography.service.AddressClient;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.geography.MGeographyDict;
import com.yihu.ehr.organization.service.OrgSaasClient;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.redis.client.RedisUpdateClient;
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.cloud.netflix.feign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;
import java.net.URLDecoder;
import java.util.*;
/**
 * Created by zdm on 2017/5/26.
 */
@EnableFeignClients
@RequestMapping(ApiVersion.Version1_0+"/admin")
@RestController
@Api(value = "OrgSaas", description = "机构Saas授权", tags = {"基础信息"})
public class OrgSaasController extends BaseController{
    @Autowired
    private OrgSaasClient orgSaasClient;
    @Autowired
    private OrganizationClient orgClient;
    @Autowired
    private AddressClient addressClient;
    @Autowired
    private RedisUpdateClient redisUpdateClient;
    @RequestMapping(value = "/OrgSaasByOrg", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构获取机构相关授权")
    public Envelop getOrgSaasByorgCode(
            @ApiParam(name = "orgCode", value = "机构", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode,
            @ApiParam(name = "type", value = "类别", defaultValue = "")
            @RequestParam(value = "type", required = false) String type,
            @ApiParam(name = "saasName", value = "名称", defaultValue = "")
            @RequestParam(value = "saasName", required = false) String saasName)throws Exception {
        Envelop envelop = new Envelop();
        //根据机构id在asaas表中获取数据
        ListResult listResult =orgSaasClient.getOrgSaasByorgCode(orgCode,type);
        List<Map<String,Object>> saasList = listResult.getDetailModelList();
        Map<String,Object> orgSaasMap=new TreeMap();
        if(null!=saasList&&saasList.size()>0){
            for(int i=0;i<saasList.size();i++){
                Object obj=(Object)saasList.get(i);
                if(null!=((ArrayList) obj).get(3)){
                    orgSaasMap.put(((ArrayList) obj).get(3).toString(),obj);
                }
            }
        }
            //授权类型 1区域 2机构
        OrgSaasModel osm=null;
        List<OrgSaasModel> OrgSaasModelList=new ArrayList<>();
        List<OrgSaasModel> OrgSaasModelRightList=new ArrayList<>();
        if(!"".equals(type)&&type.equals("2")){
            List<Map<String,Object>> orgList =new ArrayList<>();
            //在机构表中获取所有机构数据
            if(null!=saasName&&!"".equals(saasName)){
                orgList =orgClient.getAllSaasOrgs(saasName);
            }else{
                orgList =orgClient.getAllOrgs();
            }
            if(null!=orgList&&orgList.size()>0){
                for(int i=0;i<orgList.size();i++){
                    Map<String,Object> obj=orgList.get(i);
                    osm=new OrgSaasModel();
                    if(null!=obj.get("id")){
                        osm.setId(obj.get("id").toString());
                    }
                    osm.setOrgCode(orgCode);
                    osm.setType(type);
                    if(null!=obj.get("levelId")){
                        osm.setLevel(obj.get("levelId").toString());
                    }
                    if(null!=obj.get("orgCode")){
                        osm.setSaasCode(obj.get("orgCode").toString());
                    }
                    if(null!=obj.get("fullName")){
                        osm.setSaasName(obj.get("fullName").toString());
                    }
                    if(null!=obj.get("parentHosId")){
                        osm.setParent_hos_id(obj.get("parentHosId").toString());
                    }
                    if(null!=obj.get("orgCode")&&null!=orgSaasMap.get(obj.get("orgCode").toString())){
                        osm.setIschecked(true);
                        OrgSaasModelRightList.add(osm);
                    }else{
                        osm.setIschecked(false);
                    }
                    OrgSaasModelList.add(osm);
                }
            }
            if(OrgSaasModelList.size()>0){
                envelop.setDetailModelList(OrgSaasModelList);
                envelop.setObj(OrgSaasModelRightList);
                envelop.setSuccessFlg(true);
            }else {
            }
        }else{
            //查找所有区域
            List<MGeographyDict> mGeographyDictList =new ArrayList<MGeographyDict>();
            List<AreaSaasModel> AreaSaasModelList=new ArrayList<>();
            List<AreaSaasModel> AreaSaasModelRightList=new ArrayList<>();
            AreaSaasModel asm=null;
            List<MGeographyDict> newMGeographyDictList =new ArrayList<>();
            if(null!=saasName&&!"".equals(saasName)){
                newMGeographyDictList=addressClient.getOrgSaasAreaByname(saasName);
                mGeographyDictList.addAll(newMGeographyDictList);
            }else{
                for(int i=1;i<4;i++ ){
                    newMGeographyDictList = addressClient.getAddressByLevel(i);
                    mGeographyDictList.addAll(newMGeographyDictList);
                }
            }
            if(null!=mGeographyDictList&&mGeographyDictList.size()>0){
                for(int i=0;i<mGeographyDictList.size();i++){
                    MGeographyDict obj=mGeographyDictList.get(i);
                    asm=new AreaSaasModel();
                    asm.setId(String.valueOf(obj.getId()));
                    asm.setOrgCode(orgCode);
                    asm.setType(type);
                    asm.setSaasCode(String.valueOf(obj.getId()));
                    asm.setSaasName(obj.getName());
                    asm.setParent_hos_id(String.valueOf(obj.getPid()));
                    asm.setLevel(obj.getLevel());
                    if(null!=orgSaasMap.get(String.valueOf(obj.getId()))){
                        asm.setIschecked(true);
                        AreaSaasModelRightList.add(asm);
                    }else{
                        asm.setIschecked(false);
                    }
                    AreaSaasModelList.add(asm);
                }
            }
            if(AreaSaasModelList.size()>0){
                envelop.setDetailModelList(AreaSaasModelList);
                envelop.setObj(AreaSaasModelRightList);
                envelop.setSuccessFlg(true);
            }else {
            }
        }
        return envelop;
    }
    /**
     * 机构授权检查并保存
     * @return
     */
    @RequestMapping(value = "/orgSaasSave", method = RequestMethod.POST)
    @ApiOperation(value = "机构授权检查,如果被授权的机构或者区域在指定机构总不存在,这新增这条记录,否则返回地址id")
    public Envelop saveOrgSaas(
            @ApiParam(name = "orgCode", value = "机构", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode,
            @ApiParam(name = "type", value = "类别", defaultValue = "")
            @RequestParam(value = "type", required = false) String type,
            @ApiParam(name = "jsonData", value = "json数据", defaultValue = "")
            @RequestBody String jsonData) throws Exception{
        Envelop envelop = new Envelop();
        OrgSaasModel orgSaasModel = new OrgSaasModel();
        jsonData=URLDecoder.decode(jsonData);
        String[] newJsonData=jsonData.split("&");
        boolean succe = orgSaasClient.saveOrgSaas(orgCode,type,newJsonData[0]);
        if(succe){
            envelop.setSuccessFlg(true);
            //更新相关缓存数据(原则上如果更新失败不能影响实际更新结果)
            try {
                if (type.equals("1")) {
                    redisUpdateClient.updateOrgSaasArea(orgCode);
                } else {
                    redisUpdateClient.updateOrgSaasOrg(orgCode);
                }
            }catch (Exception e) {
                e.printStackTrace();
            }
            //orgSaasModel.setId(id);
        }else{
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("机构授权新增失败");
        }
        return envelop;
    }
    /**
     * 机构授权检查并保存
     * @return
     */
    @RequestMapping(value=ServiceApi.Org.getUserOrgSaasByUserOrgCode,method=RequestMethod.GET)
    @ApiOperation(value="根据用户的机构id,获取Saas化的机构或者区域id")
    public Envelop getUserOrgSaasByUserOrgCode(
            @ApiParam(name = "orgCodeStr", value = "用户所在机构")
            @RequestParam(value = "orgCodeStr", required = false) String orgCodeStr){
        Envelop envelop = new Envelop();
        List<String> orgCodeList = Arrays.asList(orgCodeStr.split(","));;
        //授权类型 1区域 2机构
        List<String> areaResult =orgSaasClient.getUserOrgSaasByUserOrgCode(orgCodeList,"1");
        List<String> orgResult =orgSaasClient.getUserOrgSaasByUserOrgCode(orgCodeList,"2");
        envelop.setSuccessFlg(true);
        envelop.setObj(areaResult);
        envelop.setDetailModelList(orgResult);
        return envelop;
    }
}

+ 840 - 0
src/main/java/com/yihu/ehr/organization/controller/OrganizationController.java

@ -0,0 +1,840 @@
package com.yihu.ehr.organization.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.adapter.service.AdapterOrgClient;
import com.yihu.ehr.adapter.service.PlanClient;
import com.yihu.ehr.agModel.geogrephy.GeographyModel;
import com.yihu.ehr.agModel.org.OrgDetailModel;
import com.yihu.ehr.agModel.org.OrgModel;
import com.yihu.ehr.apps.service.AppClient;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.controller.BaseController;
import com.yihu.ehr.fileresource.service.FileResourceClient;
import com.yihu.ehr.geography.service.AddressClient;
import com.yihu.ehr.model.adaption.MAdapterOrg;
import com.yihu.ehr.model.adaption.MAdapterPlan;
import com.yihu.ehr.model.app.MApp;
import com.yihu.ehr.model.common.ObjectResult;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.geography.MGeography;
import com.yihu.ehr.model.geography.MGeographyDict;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.model.profile.MTemplate;
import com.yihu.ehr.model.security.MKey;
import com.yihu.ehr.model.user.MUser;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.redis.client.RedisUpdateClient;
import com.yihu.ehr.security.service.SecurityClient;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.template.service.TemplateClient;
import com.yihu.ehr.users.service.UserClient;
import com.yihu.ehr.util.datetime.DateUtil;
import com.yihu.ehr.util.fzgateway.FzGatewayUtil;
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.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
 * Created by AndyCai on 2016/1/21.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "OrganizationController", description = "机构信息管理", tags = {"机构管理 - 机构信息管理"})
public class OrganizationController extends BaseController {
    @Autowired
    private OrganizationClient orgClient;
    @Autowired
    private ConventionalDictEntryClient conDictEntryClient;
    @Autowired
    private AddressClient addressClient;
    @Autowired
    private SecurityClient securityClient;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private UserClient userClient;
    @Autowired
    private AdapterOrgClient adapterOrgClient;
    @Autowired
    private PlanClient planClient;
    @Autowired
    private TemplateClient templateClient;
    @Autowired
    private FileResourceClient fileResourceClient;
    @Autowired
    private AppClient appClient;
    @Autowired
    private RedisUpdateClient redisUpdateClient;
    @Value("${service-gateway.url}")
    private String gatewayUrl;
    @Value("${service-gateway.clientId}")
    private String clientId;
    @Value("${service-gateway.clientVersion}")
    private String clientVersion;
    @ApiOperation(value = "获取所有部门列表")
    @RequestMapping(value = "/organizations/getAllOrgs", method = RequestMethod.GET)
    public Envelop getAllOrgDepts() {
        Envelop envelop = new Envelop();
        envelop.setDetailModelList(orgClient.getAllOrgs());
        envelop.setSuccessFlg(true);
        return envelop;
    }
    @RequestMapping(value = "/organizations", method = RequestMethod.GET)
    @ApiOperation(value = "根据条件查询机构列表")
    public Envelop searchOrgs(
            @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 = "-createDate")
            @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,
            @ApiParam(name = "userOrgList", value = "登录者授权机构", defaultValue = "1")
            @RequestParam(value = "userOrgList", required = false) List<String> userOrgList,
            @ApiParam(name = "province", value = "省", defaultValue = "")
            @RequestParam(value = "province", required = false) 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) {
        //根据登录人的机构获取saas化机构 --start
        String userOrgCode = "";
        if (userOrgList != null) {
            if (!(userOrgList.size() == 1 && userOrgList.get(0).equals("null"))) {
                userOrgCode = StringUtils.strip(String.join(",", userOrgList), "[]");
                if (StringUtils.isNotEmpty(userOrgCode)) {
                    filters += "orgCode=" + userOrgCode;
                }
            }
        }
        //根据登录人的机构获取saas化机构 --end
        String address = "";
        if (StringUtils.isNotBlank(province)) {
            List<String> addressList = addressClient.search(province, city, district);
            String[] addrIdsArrays = addressList.toArray(new String[addressList.size()]);
            address = String.join(",", addrIdsArrays);
        }
        if (StringUtils.isNotBlank(address)) {
            filters = StringUtils.isNotBlank(filters) ? (filters + "location=" + address) : "location=" + address;
        }
        List<OrgModel> orgModelList = new ArrayList<>();
        ResponseEntity<List<MOrganization>> responseEntity = orgClient.searchOrgs(fields, filters, sorts, size, page);
        List<MOrganization> organizations = responseEntity.getBody();
        for (MOrganization mOrg : organizations) {
            OrgModel orgModel = convertToOrgModel(mOrg);
            orgModelList.add(orgModel);
        }
        int totalCount = getTotalCount(responseEntity);
        return getResult(orgModelList, totalCount, page, size);
    }
    @RequestMapping(value = "/organizations/combo", method = RequestMethod.GET)
    @ApiOperation(value = "机构下拉列表")
    public Envelop searchOrgsForCombo(
            @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) {
        ResponseEntity<List<MOrganization>> responseEntity = orgClient.searchOrgs(fields, filters, sorts, size, page);
        int totalCount = getTotalCount(responseEntity);
        return getResult(responseEntity.getBody(), totalCount, page, size);
    }
    /**
     * 将微服务返回的结果转化为前端OrgModel模型
     *
     * @param mOrg
     * @return
     */
    public OrgModel convertToOrgModel(MOrganization mOrg) {
        if (mOrg == null) {
            return null;
        }
        OrgModel orgModel = convertToModel(mOrg, OrgModel.class);
        // 获取机构类别字典
        if (!StringUtils.isEmpty(mOrg.getOrgType())) {
            MConventionalDict orgTypeDict = conDictEntryClient.getOrgType(mOrg.getOrgType());
            orgModel.setOrgTypeName(orgTypeDict == null ? "" : orgTypeDict.getValue());
        } else {
            orgModel.setOrgTypeName("");
        }
        if (StringUtils.isNotEmpty(mOrg.getLocation())) {
            // 获取机构地址信息
            String locationStrName = addressClient.getCanonicalAddress(mOrg.getLocation());
            if (StringUtils.isNotEmpty(locationStrName)) {
                orgModel.setLocationStrName(locationStrName);
            }
        }
        //获取机构接入方式
        if (!StringUtils.isEmpty(mOrg.getSettledWay())) {
            MConventionalDict settledWayDict = conDictEntryClient.getSettledWay(mOrg.getSettledWay());
            orgModel.setSettledWayName(settledWayDict == null ? "" : settledWayDict.getValue());
        } else {
            orgModel.setSettledWayName("");
        }
        // 判断机构状态(是否已激活)
        orgModel.setActivityFlagName(mOrg.getActivityFlag() == 1 ? "是" : "否");
        //创建时间转化
        try {
            orgModel.setCreateDate(DateUtil.formatDate(mOrg.getCreateDate(), DateUtil.DEFAULT_YMDHMSDATE_FORMAT));
        } catch (Exception e) {
            orgModel.setCreateDate("");
        }
        return orgModel;
    }
    /**
     * 删除机构
     *
     * @param orgCode
     * @return
     */
    @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.DELETE)
    @ApiOperation(value = "根据机构代码删除机构")
    public Envelop deleteOrg(
            @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode) {
        try {
            if (StringUtils.isEmpty(orgCode)) {
                return failed("机构代码不能为空!");
            }
            //用户
            ResponseEntity<List<MUser>> userEntity = userClient.searchUsers("", "organization=" + orgCode, "", 1, 1, null);
            List<MUser> users = userEntity.getBody();
            if (users.size() > 0) {
                return failed("删除失败!该组织机构下面存在用户,请先删除用户!");
            }
            //第三方标准
            ResponseEntity<Collection<MAdapterOrg>> mAdapterEntity = adapterOrgClient.searchAdapterOrg("", "org=" + orgCode, "", 1, 1);
            List<MAdapterOrg> mAdapterOrgs = (List<MAdapterOrg>) mAdapterEntity.getBody();
            if (mAdapterOrgs.size() > 0) {
                return failed("删除失败!该组织机构下面存在第三方标准,请先删除第三方标准!");
            }
            //标准适配
            ResponseEntity<Collection<MAdapterPlan>> mAdapterPlanEntity = planClient.searchAdapterPlan("", "org=" + orgCode, "", 1, 1);
            List<MAdapterPlan> mAdapterPlans = (List<MAdapterPlan>) mAdapterPlanEntity.getBody();
            if (mAdapterPlans.size() > 0) {
                return failed("删除失败!该组织机构下面存在标准适配,请先删除标准适配!");
            }
            //应用
            ResponseEntity<List<MApp>> mAppEntity = appClient.getApps("", "org=" + orgCode, "", 1, 1);
            List<MApp> mApps = mAppEntity.getBody();
            if (mApps.size() > 0) {
                return failed("删除失败!该组织机构下面存在应用,请先删除应用!");
            }
            if (!securityClient.deleteKeyByOrgCode(orgCode)) {
                return failed("删除失败!");
            }
            if (!orgClient.deleteOrg(orgCode)) {
                return failed("删除失败!");
            }
            try {
                fileResourceClient.filesDelete(orgCode);
            } catch (Exception e) {
                return success("数据删除成功!图片删除失败!");
            }
            return success(null);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 创建机构
     *
     * @param mOrganizationJsonData
     * @param geographyModelJsonData
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/organizations", method = RequestMethod.POST)
    @ApiOperation(value = "创建机构")
    public Envelop create(
            @ApiParam(name = "mOrganizationJsonData", value = "机构信息Json")
            @RequestParam(value = "mOrganizationJsonData", required = false) String mOrganizationJsonData,
            @ApiParam(name = "geography_model_json_data", value = "地址信息Json")
            @RequestParam(value = "geography_model_json_data", required = false) String geographyModelJsonData,
            @ApiParam(name = "inputStream", value = "转换后的输入流")
            @RequestParam(value = "inputStream", required = false) String inputStream,
            @ApiParam(name = "imageName", value = "图片全名")
            @RequestParam(value = "imageName", required = false) String imageName) throws Exception {
        String errorMsg = "";
        //头像上传,接收头像保存的远程路径  path
        String path = null;
        if (!StringUtils.isEmpty(inputStream)) {
            String jsonData = inputStream + "," + imageName;
            path = orgClient.uploadPicture(jsonData);
        }
        OrgDetailModel orgDetailModel = objectMapper.readValue(mOrganizationJsonData, OrgDetailModel.class);
        if (!StringUtils.isEmpty(path)) {
            orgDetailModel.setImgRemotePath(path);
            orgDetailModel.setImgLocalPath("");
        }
        MOrganization mOrganization = convertToMOrganization(orgDetailModel);
        if (null == mOrganization.getBerth()) {
            mOrganization.setBerth(0);
        }
        if (StringUtils.isEmpty(mOrganization.getOrgCode())) {
            errorMsg += "机构代码不能为空!";
        }
        if (StringUtils.isEmpty(mOrganization.getFullName())) {
            errorMsg += "机构全名不能为空!";
        }
        if (StringUtils.isEmpty(mOrganization.getShortName())) {
            errorMsg += "机构简称不能为空!";
        }
        if (StringUtils.isEmpty(mOrganization.getOrgType())) {
            errorMsg += "机构类型不能为空!";
        }
        if (StringUtils.isEmpty(mOrganization.getTel())) {
            errorMsg += "联系方式不能为空!";
        }
        if (StringUtils.isEmpty(mOrganization.getTel())) {
            errorMsg += "入驻方式不能为空!";
        }
        if (StringUtils.isNotEmpty(errorMsg)) {
            return failed(errorMsg);
        }
        String locationId = null;
        if (!StringUtils.isEmpty(geographyModelJsonData)) {
            GeographyModel geographyModel = objectMapper.readValue(geographyModelJsonData, GeographyModel.class);
            if (geographyModel.nullAddress()) {
                errorMsg += "机构地址不能为空!";
            }
            locationId = addressClient.saveAddress(objectMapper.writeValueAsString(geographyModel));
            if (StringUtils.isEmpty(locationId)) {
                return failed("保存地址失败!");
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
        }
        mOrganization.setLocation(locationId);
        mOrganization.setActivityFlag(1);
        String mOrganizationJson = objectMapper.writeValueAsString(mOrganization);
        MOrganization mOrgNew = orgClient.create(mOrganizationJson);
        if (mOrgNew == null) {
            return failed("保存失败!");
        }
        //新增机构名称缓存(原则上如果缓存新增失败不能影响实际新增结果)
        try {
            redisUpdateClient.updateOrgName(mOrgNew.getOrgCode());
            redisUpdateClient.updateOrgArea(mOrgNew.getOrgCode());
        } catch (Exception e) {
            e.printStackTrace();
        }
   /*     //新增同步到总部逻辑
        Map<String, Object> result = saveSynOrg(mOrganization, orgDetailModel);
        if (result.get("Code").toString().equals("10000")) {
            //同步成功
            mOrgNew.setJkzlOrgId(result.get("orgId").toString());
            String mOrgNewJson = objectMapper.writeValueAsString(mOrgNew);
            orgClient.update(mOrgNewJson);
        } else {
            //同步失败
            //TODO
        }*/
        return success(convertToOrgDetailModel(mOrgNew));
    }
    /**
     * 新增同步到总部逻辑
     *
     * @param mOrganization
     * @param orgDetailModel
     * @throws Exception
     */
    private Map<String, Object> saveSynOrg(MOrganization mOrganization, OrgDetailModel orgDetailModel) throws Exception {
        String api = "baseinfo.HospitalApi.addLevelHosptial";
        Map<String, Object> apiParamMap = new HashMap<>();
        apiParamMap.put("typeId", mOrganization.getHosTypeId());//医院类型
        apiParamMap.put("levelId", mOrganization.getLevelId());//医院等级
        apiParamMap.put("displayStatus", mOrganization.getDisplayStatus());//是否开放显示
        apiParamMap.put("nature", mOrganization.getNature());//机构性质I
        apiParamMap.put("branchType", mOrganization.getBranchType());//机构性质II
        apiParamMap.put("ascriptionType", mOrganization.getAscriptionType());//医院归属
        apiParamMap.put("provinceId", orgDetailModel.getProvinceId());//省份id
        apiParamMap.put("provinceName", orgDetailModel.getProvince());//省份名称
        apiParamMap.put("cityId", orgDetailModel.getCityId());//城市id
        apiParamMap.put("cityName", orgDetailModel.getCity());//城市名称
        apiParamMap.put("address", orgDetailModel.getStreet());//医院地址
        apiParamMap.put("areaId", orgDetailModel.getDistrictId());//区县id
        apiParamMap.put("areaName", orgDetailModel.getDistrict());//县区名称
        apiParamMap.put("operatorId", clientId);//填写渠道ID
        apiParamMap.put("operatorName", "EHR");//填写渠道名称
        String resultStr = FzGatewayUtil.httpPost(gatewayUrl, clientId, clientVersion, api, apiParamMap, 1);
        logger.info(resultStr);
        return objectMapper.readValue(resultStr, Map.class);
    }
    @RequestMapping(value = "/organizations/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改机构")
    public Envelop update(
            @ApiParam(name = "mOrganizationJsonDatas", value = "机构信息Json", defaultValue = "")
            @RequestParam(value = "mOrganizationJsonDatas", required = true) String mOrganizationJsonData,
            @ApiParam(name = "geography_model_json_data", value = "地址信息Json", defaultValue = "")
            @RequestParam(value = "geography_model_json_data", required = false) String geographyModelJsonData,
            @ApiParam(name = "inputStream", value = "转换后的输入流", defaultValue = "")
            @RequestParam(value = "inputStream", required = false) String inputStream,
            @ApiParam(name = "imageName", value = "图片全名", defaultValue = "")
            @RequestParam(value = "imageName", required = false) String imageName) {
        try {
            String errorMsg = "";
            //头像上传,接收头像保存的远程路径  path
            String path = null;
            if (!StringUtils.isEmpty(inputStream)) {
                String jsonData = inputStream + "," + imageName;
                path = orgClient.uploadPicture(jsonData);
            }
            String locationId = null;
            if (!StringUtils.isEmpty(geographyModelJsonData)) {
                GeographyModel geographyModel = objectMapper.readValue(geographyModelJsonData, GeographyModel.class);
                if (geographyModel.nullAddress()) {
                    errorMsg += "机构地址不能为空!";
                }
                locationId = addressClient.saveAddress(objectMapper.writeValueAsString(geographyModel));
                if (StringUtils.isEmpty(locationId)) {
                    return failed("保存地址失败!");
                }
                if (StringUtils.isNotEmpty(errorMsg)) {
                    return failed(errorMsg);
                }
            }
            OrgDetailModel orgDetailModel = null;
            if (!StringUtils.isEmpty(mOrganizationJsonData)) {
                orgDetailModel = objectMapper.readValue(mOrganizationJsonData, OrgDetailModel.class);
            }
            if (!StringUtils.isEmpty(path)) {
                orgDetailModel.setImgRemotePath(path);
                orgDetailModel.setImgLocalPath("");
            }
            MOrganization mOrganization = convertToMOrganization(orgDetailModel);
            if (null == mOrganization.getBerth()) {
                mOrganization.setBerth(0);
            }
            if (StringUtils.isEmpty(mOrganization.getOrgCode())) {
                errorMsg += "机构代码不能为空!";
            }
            if (StringUtils.isEmpty(mOrganization.getFullName())) {
                errorMsg += "机构全名不能为空!";
            }
            if (StringUtils.isEmpty(mOrganization.getShortName())) {
                errorMsg += "机构简称不能为空!";
            }
            if (StringUtils.isEmpty(mOrganization.getOrgType())) {
                errorMsg += "机构类型不能为空!";
            }
            if (StringUtils.isEmpty(mOrganization.getTel())) {
                errorMsg += "联系方式不能为空!";
            }
            if (StringUtils.isEmpty(mOrganization.getTel())) {
                errorMsg += "入驻方式不能为空!";
            }
            if (StringUtils.isNotEmpty(errorMsg)) {
                return failed(errorMsg);
            }
            mOrganization.setLocation(locationId);
            String mOrganizationJson = objectMapper.writeValueAsString(mOrganization);
            MOrganization mOrgNew = orgClient.update(mOrganizationJson);
            if (mOrgNew == null) {
                return failed("更新失败");
            }
            //更新机构名称缓存(原则上如果缓存更新失败不能影响实际更新结果)
            try {
                redisUpdateClient.updateOrgName(mOrgNew.getOrgCode());
                redisUpdateClient.updateOrgArea(mOrgNew.getOrgCode());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return success(convertToOrgDetailModel(mOrgNew));
        } catch (Exception e) {
            e.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 根据机构代码获取机构
     *
     * @param orgCode
     * @return
     */
    @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构代码获取机构")
    public Envelop getOrg(
            @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode) {
        try {
            if (StringUtils.isEmpty(orgCode)) {
                return failed("机构代码不能为空!");
            }
            MOrganization mOrg = orgClient.getOrg(orgCode);
            if (mOrg == null) {
                return failed("机构获取失败");
            }
            if (!StringUtils.isEmpty(mOrg.getImgRemotePath())) {
                try {
                    String imagePath[] = mOrg.getImgRemotePath().split(":");
                    String localPath = orgClient.downloadPicture(imagePath[0], imagePath[1]);
                    mOrg.setImgLocalPath(localPath);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mOrg.getParentHosId() != null) {
                MOrganization org = orgClient.getOrgById(String.valueOf(mOrg.getParentHosId()));
                if (org != null) {
                    mOrg.setParentHosName(org.getFullName());
                }
            }
            OrgDetailModel org = convertToOrgDetailModel(mOrg);
            return success(org);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 根据机构Id获取机构
     *
     * @param orgId
     * @return
     */
    @RequestMapping(value = "/organizations/getOrgById/{org_id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构代码获取机构")
    public Envelop getOrgById(
            @ApiParam(name = "org_id", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_id") String orgId) {
        try {
            if (StringUtils.isEmpty(orgId)) {
                return failed("机构ID不能为空!");
            }
            MOrganization mOrg = orgClient.getOrgById(orgId);
            if (!StringUtils.isEmpty(mOrg.getImgRemotePath())) {
                try {
                    String imagePath[] = mOrg.getImgRemotePath().split(":");
                    String localPath = orgClient.downloadPicture(imagePath[0], imagePath[1]);
                    mOrg.setImgLocalPath(localPath);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (mOrg == null) {
                return failed("机构获取失败");
            }
            OrgDetailModel org = convertToOrgDetailModel(mOrg);
            return success(org);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 将微服务返回结果转化为OrgDetailModel
     *
     * @param mOrg
     * @return
     */
    public OrgDetailModel convertToOrgDetailModel(MOrganization mOrg) {
        OrgDetailModel org = convertToModel(mOrg, OrgDetailModel.class);
        org.setCreateDate(DateToString(mOrg.getCreateDate(), AgAdminConstants.DateTimeFormat));
        //获取机构类别字典值
        if (StringUtils.isNotBlank(mOrg.getOrgType())) {
            MConventionalDict orgTypeDict = conDictEntryClient.getOrgType(mOrg.getOrgType());
            org.setOrgTypeName(orgTypeDict == null ? "" : orgTypeDict.getValue());
        }
        //获取接入方式字典字典值
        if (StringUtils.isNotBlank(mOrg.getSettledWay())) {
            MConventionalDict settledWayDict = conDictEntryClient.getSettledWay(mOrg.getSettledWay());
            org.setSettledWayName(settledWayDict == null ? "" : settledWayDict.getValue());
        }
        //org.setTags(mOrg.getTags());
        //获取地址字典值明细
        if (StringUtils.isNotBlank(mOrg.getLocation())) {
            MGeography addr = addressClient.getAddressById(mOrg.getLocation());
            if (addr != null) {
                org.setProvince(addr.getProvince());
                org.setCity(addr.getCity());
                org.setDistrict(addr.getDistrict());
                org.setTown(addr.getTown());
                org.setStreet(addr.getStreet());
                org.setExtra(addr.getExtra());
                if (StringUtils.isNotEmpty(addr.getProvince())) {
                    org.setProvinceId(getGeographyIdByName(addr.getProvince().toString()));
                }
                if (StringUtils.isNotEmpty(addr.getCity())) {
                    org.setCityId(getGeographyIdByName(addr.getCity().toString()));
                }
                if (StringUtils.isNotEmpty(addr.getDistrict())) {
                    org.setDistrictId(getGeographyIdByName(addr.getDistrict().toString()));
                }
            }
        }
        //获取公钥信息(公钥、有效区间、开始时间)
        MKey security = securityClient.getOrgKey(mOrg.getOrgCode());
        if (security != null) {
            org.setPublicKey(security.getPublicKey());
            org.setValidTime(DateUtil.toString(security.getFromDate(), DateUtil.DEFAULT_DATE_YMD_FORMAT)
                    + "~" + DateUtil.toString(security.getExpiryDate(), DateUtil.DEFAULT_DATE_YMD_FORMAT));
            org.setStartTime(DateUtil.toString(security.getFromDate(), DateUtil.DEFAULT_DATE_YMD_FORMAT));
        }
        return org;
    }
    public int getGeographyIdByName(String name) {
        if (StringUtils.isEmpty(name)) {
            return 0;
        }
        ObjectResult result = addressClient.getAddressNameByCode(name);
        if (result != null) {
            Map<String, Object> info = (HashMap) result.getData();
            int id = Integer.parseInt(info.get("id").toString());
            return id;
        }
        return 0;
    }
    public int geographyToCode(String name, int code) {
        String[] fields = {"name", "pid"};
        String[] values = {name, String.valueOf(code)};
        List<MGeographyDict> geographyDictList = (List<MGeographyDict>) addressClient.getAddressDict(fields, values);
        return geographyDictList.get(0).getId();
    }
    /**
     * 根据name获取机构ids
     *
     * @param name
     * @return
     */
    @ApiOperation(value = "根据名称获取机构编号列表ids")
    @RequestMapping(value = "/organizations/name", method = RequestMethod.GET)
    public Envelop getIdsByName(
            @ApiParam(name = "name", value = "机构名称", defaultValue = "")
            @RequestParam(value = "name") String name) {
        try {
            Envelop envelop = new Envelop();
            envelop.setDetailModelList(orgClient.getIdsByName(name));
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    /**
     * 更新机构激活状态
     *
     * @param orgCode
     * @return
     */
    @RequestMapping(value = "organizations/{org_code}/{activity_flag}", method = RequestMethod.PUT)
    @ApiOperation(value = "更新机构激活状态")
    public boolean activity(
            @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode,
            @ApiParam(name = "activity_flag", value = "状态", defaultValue = "")
            @PathVariable(value = "activity_flag") int activityFlag) {
        try {
            return orgClient.activity(orgCode, activityFlag);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    /**
     * 根据地址获取机构下拉列表
     *
     * @param province
     * @param city
     * @param district
     * @return
     */
    @RequestMapping(value = "organizations/geography", method = RequestMethod.GET)
    @ApiOperation(value = "根据地址获取机构下拉列表")
    public Envelop getOrgsByAddress(
            @ApiParam(name = "province", value = "省")
            @RequestParam(value = "province") String province,
            @ApiParam(name = "city", value = "市")
            @RequestParam(value = "city") String city,
            @ApiParam(name = "district", value = "县")
            @RequestParam(value = "district") String district) {
        try {
            Envelop envelop = new Envelop();
            Collection<MOrganization> mOrganizations = orgClient.getOrgsByAddress(province, city, district);
            envelop.setDetailModelList(mOrganizations == null ? null : (List) mOrganizations);
            envelop.setSuccessFlg(true);
            return envelop;
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "organizations/key", method = RequestMethod.POST)
    @ApiOperation(value = "机构分发密钥")
    public Envelop distributeKey(
            @ApiParam(name = "org_code", value = "机构代码")
            @RequestParam(value = "org_code") String orgCode) {
        try {
            Map<String, String> key = orgClient.distributeKey(orgCode);
            if (key.size() == 0) {
                return failed("机构秘钥分发失败!");
            }
            return success(key);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "organizations/existence/{org_code}", method = RequestMethod.GET)
    @ApiOperation(value = "判断提交的机构代码是否已经存在")
    public boolean isOrgCodeExists(
            @ApiParam(name = "org_code", value = "org_code", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode) {
        try {
            return orgClient.isOrgCodeExists(orgCode);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    @RequestMapping(value = "organizations/checkSunOrg", method = RequestMethod.PUT)
    @ApiOperation(value = "判断机构是否已经是子机构")
    public boolean checkSunOrg(
            @ApiParam(name = "org_pId", value = "org_pId", defaultValue = "")
            @RequestParam(value = "org_pId") String orgPid,
            @ApiParam(name = "org_id", value = "org_id", defaultValue = "")
            @RequestParam(value = "org_id") String orgId) {
        try {
            return orgClient.checkSunOrg(orgPid, orgId);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
    public MOrganization convertToMOrganization(OrgDetailModel detailModel) {
        if (detailModel == null) {
            return null;
        }
        MOrganization mOrganization = convertToModel(detailModel, MOrganization.class);
        mOrganization.setCreateDate(StringToDate(detailModel.getCreateDate(), AgAdminConstants.DateTimeFormat));
        return mOrganization;
    }
    @RequestMapping(value = "/organizations/batch", method = RequestMethod.POST)
    @ApiOperation("批量导入机构")
    public Envelop createOrgBatch(
            @ApiParam(name = "orgs", value = "JSON", defaultValue = "")
            @RequestParam(value = "orgs") String orgs) throws Exception {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        try {
            orgClient.createOrgBatch(orgs);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("系统出错!");
        }
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Org.getseaOrgsByOrgCode, method = RequestMethod.POST)
    @ApiOperation("根据机构code获取机构code和name")
    public Envelop seaOrgsByOrgCode(
            @ApiParam(name = "org_codes", value = "机构org_codes", defaultValue = "")
            @RequestParam(value = "org_codes") String org_codes) throws Exception {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        try {
            Map<String, String> orgMap = orgClient.seaOrgsByOrgCode(org_codes);
            envelop.setObj(orgMap);
        } catch (Exception e) {
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("系统出错!");
        }
        return envelop;
    }
    @RequestMapping(value = "/organizations/getHospital", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有经纬度医院列表")
    public Envelop getHospital() throws Exception {
        return orgClient.getHospital();
    }
    @RequestMapping(value = "/organizations/getOrgListByAddressPid", method = RequestMethod.GET)
    @ApiOperation(value = "根据区域查询机构列表")
    public Envelop getOrgListByAddressPid(
            @ApiParam(name = "pid", value = "区域id", defaultValue = "")
            @RequestParam(value = "pid") Integer pid,
            @ApiParam(name = "fullName", value = "机构名称", defaultValue = "")
            @RequestParam(value = "fullName", required = false) String fullName) {
        Envelop envelop = orgClient.getOrgListByAddressPid(pid, fullName);
        return envelop;
    }
    @RequestMapping(value = "/organizations/getOrgListTreeByAddressPid", method = RequestMethod.GET)
    @ApiOperation(value = "根据区域、机构区县查询机构列表")
    public List<Map<String, Object>> getOrgListTreeByAddressPid(
            @ApiParam(name = "pid", value = "区域id", defaultValue = "")
            @RequestParam(value = "pid") Integer pid) {
        List<Map<String, Object>> listMap = orgClient.getOrgListTreeByAddressPid(pid);
        return listMap;
    }
}

+ 70 - 0
src/main/java/com/yihu/ehr/organization/model/DeptModel.java

@ -0,0 +1,70 @@
package com.yihu.ehr.organization.model;
public class DeptModel {
    int id;
    int parentDeptId;
    String orgId;
    String code;
    String name;
    Integer delFlag;
    Integer sortNo;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getParentDeptId() {
        return parentDeptId;
    }
    public void setParentDeptId(int parentDeptId) {
        this.parentDeptId = parentDeptId;
    }
    public String getOrgId() {
        return orgId;
    }
    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getDelFlag() {
        return delFlag;
    }
    public void setDelFlag(Integer delFlag) {
        this.delFlag = delFlag;
    }
    public Integer getSortNo() {
        return sortNo;
    }
    public void setSortNo(Integer sortNo) {
        this.sortNo = sortNo;
    }
}

+ 50 - 0
src/main/java/com/yihu/ehr/organization/model/OrgDeptListModel.java

@ -0,0 +1,50 @@
package com.yihu.ehr.organization.model;
import com.yihu.ehr.agModel.org.OrgDeptModel;
import java.util.List;
/**
 * @author zdm
 * @vsrsion 1.0
 * Created at 2017/5/25
 */
public class OrgDeptListModel {
     int id;
     String orgId;
     String orgName;
     List<OrgDeptModel> orgDept;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getOrgId() {
        return orgId;
    }
    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }
    public String getOrgName() {
        return orgName;
    }
    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
    public List<OrgDeptModel> getOrgDept() {
        return orgDept;
    }
    public void setOrgDept(List<OrgDeptModel> orgDept) {
        this.orgDept = orgDept;
    }
}

+ 43 - 0
src/main/java/com/yihu/ehr/organization/model/OrgDeptModel.java

@ -0,0 +1,43 @@
package com.yihu.ehr.organization.model;
public class OrgDeptModel {
    String orgCode="";
    String fullName="";
    String shortName="";
    String id="";
    public String getOrgCode() {
        return orgCode;
    }
    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }
    public String getFullName() {
        return fullName;
    }
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    public String getShortName() {
        return shortName;
    }
    public void setShortName(String shortName) {
        this.shortName = shortName;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
}

+ 173 - 0
src/main/java/com/yihu/ehr/organization/model/OrgModel.java

@ -0,0 +1,173 @@
package com.yihu.ehr.organization.model;
public class OrgModel {
    String orgCode="";
    String fullName="";
    String shortName="";
    String location="";
    String orgType="";
    String settledWay="";
    String province="";
    String city="";
    String district="";
    String town="";
    String street = "";
    String tel="";
    String publicKey="";
    String validTime="";
    String startTime="";
    String updateFlg="";
    String tags="";
    String admin = "";
    String url = "";
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getAdmin() {
        return admin;
    }
    public void setAdmin(String admin) {
        this.admin = admin;
    }
    public String getStreet() {
        return street;
    }
    public void setStreet(String street) {
        this.street = street;
    }
    public String getOrgCode() {
        return orgCode;
    }
    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }
    public String getFullName() {
        return fullName;
    }
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    public String getShortName() {
        return shortName;
    }
    public void setShortName(String shortName) {
        this.shortName = shortName;
    }
    public String getLocation() {
        return location;
    }
    public void setLocation(String location) {
        this.location = location;
    }
    public String getOrgType() {
        return orgType;
    }
    public void setOrgType(String orgType) {
        this.orgType = orgType;
    }
    public String getSettledWay() {
        return settledWay;
    }
    public void setSettledWay(String settledWay) {
        this.settledWay = settledWay;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getDistrict() {
        return district;
    }
    public void setDistrict(String district) {
        this.district = district;
    }
    public String getTown() {
        return town;
    }
    public void setTown(String town) {
        this.town = town;
    }
    public String getTel() {
        return tel;
    }
    public void setTel(String tel) {
        this.tel = tel;
    }
    public String getPublicKey() {
        return publicKey;
    }
    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }
    public String getValidTime() {
        return validTime;
    }
    public void setValidTime(String validTime) {
        this.validTime = validTime;
    }
    public String getStartTime() {
        return startTime;
    }
    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }
    public String getUpdateFlg() {
        return updateFlg;
    }
    public void setUpdateFlg(String updateFlg) {
        this.updateFlg = updateFlg;
    }
    public String getTags() {return tags;}
    public void setTags(String tags) {this.tags = tags;}
}

+ 141 - 0
src/main/java/com/yihu/ehr/organization/service/OrgDeptClient.java

@ -0,0 +1,141 @@
package com.yihu.ehr.organization.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.org.MOrgDept;
import com.yihu.ehr.model.org.MOrgDeptData;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2017/2/20.
 */
@FeignClient(name= MicroServices.Organization)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgDeptClient {
    @RequestMapping(value = "/orgDept/list", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据条件查询机构下的部门列表")
    List<MOrgDept> searchOrgDepts(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId", required = true) String orgId);
    @RequestMapping(value = "/orgDept/childs", method = RequestMethod.POST)
    @ApiOperation(value = "根据父级部门ID查询其下的子部门列表")
    List<MOrgDept> searchChildOrgDepts(
            @RequestParam(value = "parentDeptId", required = true) Integer parentDeptId
    );
    @RequestMapping(value = "/orgDept/detail", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询部门&科室详情")
    public MOrgDept searchDeptDetail(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId
    );
    @RequestMapping(value = "/orgDept", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增部门")
    MOrgDept saveOrgDept(
            @ApiParam(name = "deptJsonData", value = "新增部门json信息")
            @RequestBody String deptJsonData
    ) ;
    @RequestMapping(value = "/orgDept", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改部门&科室详情")
    public MOrgDept updateOrgDept(
            @ApiParam(name = "deptJsonData", value = "部门&科室详情json信息")
            @RequestBody String deptJsonData
    ) ;
    @RequestMapping(value = "/orgDept/getCountByDeptName", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "检查机构下部门相同名称的个数")
    int getCountByDeptName(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId", required = true) Integer orgId,
            @ApiParam(name = "name", value = "新部门名称")
            @RequestParam(value = "name", required = true) String name
    );
    @RequestMapping(value = "/orgDeptMember/getCountByUserId", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "检查机构下部门成员相同的个数")
    int getCountByUserId(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId", required = true) Integer orgId,
            @ApiParam(name = "userId", value = "用户ID")
            @RequestParam(value = "userId", required = true) String userId,
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId
    );
    @RequestMapping(value = "/orgDept/resetName", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改部门名称")
    MOrgDept updateOrgDeptName(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId,
            @ApiParam(name = "name", value = "新部门名称")
            @RequestParam(value = "name", required = true) String name
    );
    @RequestMapping(value = "/orgDept/delete", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "删除部门" ,notes = "可以根据前端需求修改该接口,添加判断部门下是否有成员")
    boolean deleteOrgDept(
            @ApiParam(name = "deptId", value = "部门ID")
            @RequestParam(value = "deptId", required = true) Integer deptId
    ) ;
    @RequestMapping(value = "/orgDept/checkMembers", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询部门下是否有成员" ,notes = "检查部门下是否有成员存在")
    boolean isHasMember(
            @RequestParam(value = "deptId", required = true) Integer deptId
    ) ;
    @RequestMapping(value = "/orgDept/changeSort", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改部门的排序" ,notes = "修改部门的排序")
    boolean changeSort(
            @ApiParam(name = "preDeptId", value = "第一个部门ID")
            @RequestParam(value = "preDeptId", required = true) Integer preDeptId,
            @ApiParam(name = "afterDeptId", value = "第二个部门ID")
            @RequestParam(value = "afterDeptId", required = true) Integer afterDeptId
    );
    @RequestMapping(value = "/orgDept/getAllOrgDepts", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有的部门列表")
    List getAllOrgDepts();
    @RequestMapping(value = ServiceApi.Org.getUserOrglistByUserId, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据用户ID获取部门列表")
    List<String> getUserOrglistByUserId(
            @ApiParam(name = "userId", value = "用户ID")
            @RequestParam(value = "userId", required = true) String userId);
    @RequestMapping(value =ServiceApi.Org.GetOrgDeptsDate, method = RequestMethod.GET)
    @ApiOperation(value = "根据机构id获取机构及部门列表")
    MOrgDeptData getOrgDeptsDate(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId") String orgId);
    @RequestMapping(value =ApiVersion.Version1_0 + "/orgDept/getOrgDeptByDeptName", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "检查机构下部门相同名称的个数")
    MOrgDept getOrgDeptByDeptName(
            @ApiParam(name = "orgId", value = "机构ID")
            @RequestParam(value = "orgId", required = true) Integer orgId,
            @ApiParam(name = "name", value = "新部门名称")
            @RequestParam(value = "name", required = true) String name);
}

+ 45 - 0
src/main/java/com/yihu/ehr/organization/service/OrgDeptImportClient.java

@ -0,0 +1,45 @@
package com.yihu.ehr.organization.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Created by Administrator on 2017/7/14.
 */
@FeignClient(name= MicroServices.User)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgDeptImportClient {
    @RequestMapping(value = "/orgDept/batch", method = RequestMethod.POST)
    @ApiOperation("批量导入机构&部门")
    boolean createOrgDeptsBatch(@RequestBody String orgDepts);
    @RequestMapping(value = "/code/existence",method = RequestMethod.POST)
    @ApiOperation("获取已存在部门编号")
    List codeExistence(@RequestBody String code);
    @RequestMapping(value = "/name/existence",method = RequestMethod.POST)
    @ApiOperation("获取已存在部门名称")
    List nameExistence(@RequestBody String name);
    @RequestMapping(value = "/orgCode/existence",method = RequestMethod.POST)
    @ApiOperation("获取已存在的机构代码")
    List orgCodeExistence(@RequestBody String orgCode);
    @RequestMapping(value = "/orgDept/code/existence", method = RequestMethod.GET)
    @ApiOperation("根据过滤条件判断是否存在")
    boolean isExistence(
            @RequestParam(value="filters") String filters);
}

+ 124 - 0
src/main/java/com/yihu/ehr/organization/service/OrgDeptMemberClient.java

@ -0,0 +1,124 @@
package com.yihu.ehr.organization.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.org.MOrgDeptData;
import com.yihu.ehr.model.org.MOrgDeptJson;
import com.yihu.ehr.model.org.MOrgMemberRelation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2017/2/20.
 */
@FeignClient(name= MicroServices.Organization)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgDeptMemberClient {
    @RequestMapping(value = "/orgDeptMember/list", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据条件 查询部门下成员列表")
    ResponseEntity<List<MOrgMemberRelation>> searchOrgDeptMembers(
            @RequestParam(value = "fields", required = false) String fields,
            @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
    ) ;
    @RequestMapping(value = "/orgDeptMember/getOrgDeptMembers", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "根据条件 查询部门下成员列表")
    ResponseEntity<List<MOrgMemberRelation>> getOrgDeptMembers(
            @RequestParam(value = "orgId", required = false) String orgId,
            @RequestParam(value = "searchParm", required = false) String searchParm,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page
    ) ;
    @RequestMapping(value = "orgDeptMember/admin/{memRelationId}", method = RequestMethod.GET)
    @ApiOperation(value = "获取部门成员信息", notes = "部门成员信息")
    MOrgMemberRelation getOrgMemberRelation(@PathVariable(value = "memRelationId") Long memRelationId);
    @RequestMapping(value = "/orgDeptMember", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增部门成员")
    MOrgMemberRelation saveOrgDeptMember(
            @ApiParam(name = "memberRelationJsonData", value = "新增部门成员信息")
            @RequestBody String memberRelationJsonData
    );
    @RequestMapping(value = "/orgDeptMember", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改部门成员")
    MOrgMemberRelation updateOrgDeptMember(
            @ApiParam(name = "memberRelationJsonData", value = "修改部门成员信息")
            @RequestBody String memberRelationJsonData
    ) ;
    @RequestMapping(value = "/updateOrgDeptMemberParent", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改部门成员上级成员")
    boolean updateOrgDeptMemberParent(
            @ApiParam(name = "memberRelationJsonData", value = "修改部门成员信息")
            @RequestBody String memberRelationJsonData
    ) ;
    @RequestMapping(value = "/orgDeptMember/updateStatus", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改部门成员状态" )
    boolean updateStatusOrgDeptMember(
            @ApiParam(name = "memberRelationId", value = "部门成员ID")
            @RequestParam(value = "memberRelationId", required = true) int memberRelationId,
            @ApiParam(name = "status", value = "状态", defaultValue = "")
            @RequestParam(value = "status") int status
    ) ;
    @RequestMapping(value = "/orgDeptMember/delete", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "删除部门成员" )
    boolean deleteOrgDeptMember(
            @ApiParam(name = "memberRelationId", value = "部门成员ID")
            @RequestParam(value = "memberRelationId", required = true) Integer memberRelationId
    ) ;
    @RequestMapping(value = "/orgDeptMember/getAllOrgDeptMember", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有成员列表")
    ResponseEntity<List<MOrgMemberRelation>> getAllOrgDeptMember(
            @RequestParam(value = "filters", required = false) String filters);
    @RequestMapping(value = "/orgDeptMember/getAllOrgDeptMemberDistinct", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有成员列表去重复")
    ResponseEntity<List<MOrgMemberRelation>> getAllOrgDeptMemberDistinct(
            @ApiParam(name = "orgId", value = "机构ID", defaultValue = "")
            @RequestParam(value = "orgId",required = false) String orgId,
            @ApiParam(name = "searchNm", value = "关键字查询", defaultValue = "")
            @RequestParam(value = "searchNm",required = false) String searchNm);
    @RequestMapping(value = "/orgDeptMember/getOrgIds", method = RequestMethod.GET)
    @ApiOperation(value = "根据userId获取orgId列表")
    List<String> getOrgIds(@RequestParam(value = "userId")String userId);
    @RequestMapping(value = "/orgDeptMember/getDeptIds", method = RequestMethod.GET)
    @ApiOperation(value = "根据userId获取DeptId列表")
    List<Integer> getDeptIds(
            @RequestParam(value = "userId")String userId);
    @RequestMapping(value = "/orgDeptMember/getByUserId", method = RequestMethod.GET)
    @ApiOperation(value = "根据userId获取orgDeptJson列表")
    List<MOrgDeptJson> getByUserId(
            @ApiParam(name = "userId", value = "用户id")
            @RequestParam(value = "userId") String userId);
    @RequestMapping(value = ServiceApi.Users.GetOrgAndDeptRelation, method = RequestMethod.GET)
    @ApiOperation(value = "根据userId获取机构及部门列表")
    List<MOrgDeptData> getOrgAndDeptRelation(
            @ApiParam(name = "userId", value = "用户id")
            @RequestParam(value = "userId") String userId);
}

+ 74 - 0
src/main/java/com/yihu/ehr/organization/service/OrgHealthCategoryClient.java

@ -0,0 +1,74 @@
package com.yihu.ehr.organization.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
/**
 * 卫生机构类别 Client
 *
 * @author 张进军
 * @date 2017/12/21 12:00
 */
@FeignClient(name = MicroServices.Organization)
@RequestMapping(value = ApiVersion.Version1_0)
@ApiIgnore
public interface OrgHealthCategoryClient {
    @ApiOperation("根据ID获取卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.GetById, method = RequestMethod.GET)
    public Envelop getById(
            @ApiParam(name = "id", value = "主键", required = true)
            @PathVariable(value = "id") Integer id);
    @ApiOperation("获取所有的卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.FindAll, method = RequestMethod.GET)
    public Envelop findAll();
    @ApiOperation(value = "根据条件获取卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Search, method = RequestMethod.GET)
    public Envelop search(
            @ApiParam(name = "codeName", value = "卫生机构类别编码或名称")
            @RequestParam(value = "codeName", required = false) String codeName);
    @ApiOperation("新增卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Save, method = RequestMethod.POST)
    public Envelop add(
            @ApiParam(value = "卫生机构类别JSON", required = true)
            @RequestBody String entityJson);
    @ApiOperation("更新卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Save, method = RequestMethod.PUT)
    public Envelop update(
            @ApiParam(value = "卫生机构类别JSON", required = true)
            @RequestBody String entityJson);
    @ApiOperation("删除卫生机构类别")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.Delete, method = RequestMethod.DELETE)
    public Envelop delete(
            @ApiParam(name = "id", value = "卫生机构类别ID", required = true)
            @RequestParam(value = "id") Integer id);
    @ApiOperation("验证卫生机构类别编码是否唯一")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.IsUniqueCode, method = RequestMethod.GET)
    public Envelop isUniqueCode(
            @ApiParam(name = "id", value = "卫生机构类别ID", required = true)
            @RequestParam(value = "id") Integer id,
            @ApiParam(name = "code", value = "卫生机构类别编码", required = true)
            @RequestParam(value = "code") String code);
    @ApiOperation("验证卫生机构类别名称是否唯一")
    @RequestMapping(value = ServiceApi.Org.HealthCategory.IsUniqueName, method = RequestMethod.GET)
    public Envelop isUniqueName(
            @ApiParam(name = "id", value = "卫生机构类别ID", required = true)
            @RequestParam(value = "id") Integer id,
            @ApiParam(name = "name", value = "卫生机构类别名称", required = true)
            @RequestParam(value = "name") String name);
}

+ 64 - 0
src/main/java/com/yihu/ehr/organization/service/OrgSaasClient.java

@ -0,0 +1,64 @@
package com.yihu.ehr.organization.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.common.ListResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Created by zdm on 2017/5/26.
 */
@FeignClient(name=MicroServices.Geography)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrgSaasClient {
    @ApiOperation(value = "根据机构获取机构相关授权")
    @RequestMapping(value = "/OrgSaasByOrg", method = RequestMethod.GET)
    ListResult getOrgSaasByorgCode(
            @ApiParam(name = "orgCode", value = "机构", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode,
            @ApiParam(name = "type", value = "类别", defaultValue = "")
            @RequestParam(value = "type", required = false) String type) ;
    /**
     * 机构授权并保存
     * @return
     */
    @ApiOperation(value = "机构授权检查,如果被授权的机构或者区域在指定机构总不存在,这新增这条记录,否则返回地址id")
    @RequestMapping(value = "/orgSaasSave", method = RequestMethod.POST)
    boolean saveOrgSaas(
            @ApiParam(name = "orgCode", value = "机构", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode,
            @ApiParam(name = "type", value = "类别", defaultValue = "")
            @RequestParam(value = "type", required = false) String type,
            @ApiParam(name = "jsonData", value = "json数据", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/orgSaasDel", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除机构授权", notes = "根据机构code和授权类别删除机构授权")
    boolean deleteOrgSaas(
            @ApiParam(name = "orgCode", value = "机构", defaultValue = "")
            @RequestParam(value = "orgCode", required = false) String orgCode,
            @ApiParam(name = "type", value = "类别", defaultValue = "")
            @RequestParam(value = "type", required = false) String type);
    @ApiOperation(value = "根据用户的机构id,获取Saas化的机构或者区域id")
    @RequestMapping(value=ServiceApi.Org.getUserOrgSaasByUserOrgCode, method = RequestMethod.GET)
    List<String> getUserOrgSaasByUserOrgCode(
            @ApiParam(name = "userOrgCode", value = "用户所在机构", defaultValue = "")
            @RequestParam(value = "userOrgCode", required = false) List<String> userOrgCode,
            @ApiParam(name = "type", value = "saas类型", defaultValue = "")
            @RequestParam(value = "type", required = false) String type) ;
}

+ 231 - 0
src/main/java/com/yihu/ehr/organization/service/OrganizationClient.java

@ -0,0 +1,231 @@
package com.yihu.ehr.organization.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 * Created by AndyCai on 2016/2/1.
 */
@FeignClient(name=MicroServices.Organization)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface OrganizationClient {
    @RequestMapping(value = "/organizations/getAllOrgs", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有的机构列表")
    List getAllOrgs();
    @RequestMapping(value = "/organizations/list", method = RequestMethod.POST)
    @ApiOperation(value = "根据条件查询机构列表")
    ResponseEntity<List<MOrganization>> searchOrgs(
            @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) ;
    /**
     * 删除机构
     * @param orgCode
     * @return
     */
    @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.DELETE)
    @ApiOperation(value = "根据机构代码删除机构")
    boolean deleteOrg(
            @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode) ;
    /**
     * 创建机构
     * @param orgModelJsonData
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/organizations" , method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建机构")
    MOrganization create(
            @ApiParam(name = "mOrganizationJsonData", value = "机构代码", defaultValue = "")
            @RequestBody String orgModelJsonData ) ;
    @RequestMapping(value = "/organizations" , method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改机构")
    MOrganization update(
            @ApiParam(name = "mOrganizationJsonData", value = "机构代码", defaultValue = "")
            @RequestBody String orgModelJsonData ) ;
    /**
     * 根据机构代码获取机构
     * @param orgCode
     * @return
     */
    @RequestMapping(value = "/organizations/{org_code}", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构代码获取机构")
    MOrganization getOrg(
            @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode) ;
    /**
     * 根据机构ID获取机构
     * @param orgId
     * @return
     */
    @RequestMapping(value = "/organizations/getOrgById/{org_id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构ID获取机构")
    MOrganization getOrgById(
            @ApiParam(name = "org_id", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_id") String orgId) ;
    /**
     * 根据name获取机构ids
     * @param name
     * @return
     */
    @ApiOperation(value = "根据地名称取机构ids")
    @RequestMapping(value = "/organizations/name", method = RequestMethod.GET)
    List<String> getIdsByName(
            @ApiParam(name = "name", value = "机构名称", defaultValue = "")
            @RequestParam(value = "name") String name);
    /**
     * 跟新机构激活状态
     * @param orgCode
     * @return
     */
    @RequestMapping(value = "/organizations/{org_code}/{activity_flag}" , method = RequestMethod.PUT)
    @ApiOperation(value = "跟新机构激活状态")
    boolean activity(
            @ApiParam(name = "org_code", value = "机构代码", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode,
            @ApiParam(name = "activity_flag", value = "状态", defaultValue = "")
            @PathVariable(value = "activity_flag") int activityFlag) ;
    /**
     * 根据地址获取机构下拉列表
     * @param province
     * @param city
     * @param district
     * @return
     */
    @RequestMapping(value = "/organizations/geography" , method = RequestMethod.GET)
    @ApiOperation(value = "根据地址获取机构下拉列表")
    Collection<MOrganization> getOrgsByAddress(
            @ApiParam(name = "province", value = "省")
            @RequestParam(value = "province") String province,
            @ApiParam(name = "city", value = "市")
            @RequestParam(value = "city") String city,
            @ApiParam(name = "district", value = "市")
            @RequestParam(value = "district") String district);
    @RequestMapping( value = "/organizations/key" , method = RequestMethod.POST)
    @ApiOperation(value = "机构分发密钥")
    Map<String, String> distributeKey(
            @ApiParam(name = "org_code", value = "机构代码")
            @RequestParam(value = "org_code") String orgCode) ;
    @RequestMapping(value = "/organizations/existence/{org_code}" , method = RequestMethod.GET)
    @ApiOperation(value = "判断提交的机构代码是否已经存在")
    boolean isOrgCodeExists(
            @ApiParam(name = "org_code", value = "org_code", defaultValue = "")
            @PathVariable(value = "org_code") String orgCode);
    @RequestMapping(value = "/organizations/checkSunOrg" , method = RequestMethod.PUT)
    @ApiOperation(value = "判断机构是否已经是子机构")
    boolean checkSunOrg(
            @ApiParam(name = "org_pId", value = "org_pId", defaultValue = "")
            @RequestParam(value = "org_pId") String orgPid,
            @ApiParam(name = "org_id", value = "org_id", defaultValue = "")
            @RequestParam(value = "org_id") String orgId);
    @RequestMapping(value = "/organizations/images" , method = RequestMethod.POST)
    @ApiOperation(value = "机构资质图片上传")
    public String uploadPicture(
            @ApiParam(name = "jsonData", value = "jsonData", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/organizations/images",method = RequestMethod.GET)
    @ApiOperation(value = "头像下载")
    String downloadPicture(
            @ApiParam(name = "group_name", value = "分组", defaultValue = "")
            @RequestParam(value = "group_name") String groupName,
            @ApiParam(name = "remote_file_name", value = "服务器头像名称", defaultValue = "")
            @RequestParam(value = "remote_file_name") String remoteFileName);
    @RequestMapping(value = "/orgDept/getAllOrgAndDepts", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有的机构列表")
    List<Object> getOrgs();
    @RequestMapping(value = "/organizations/getAllSaasOrgs", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有的机构列表")
    List getAllSaasOrgs(
            @ApiParam(name = "saasName", value = "名称", defaultValue = "")
            @RequestParam(value = "saasName", required = false) String saasName);
    /**
     * 根据机构ID获取机构
     * @param userOrgCode
     * @return
     */
    @RequestMapping(value = "/organizations/getOrgListById", method = RequestMethod.GET)
    @ApiOperation(value = "根据机构ID获取机构")
    List<String> getOrgListById(
            @ApiParam(name = "userOrgCode", value = "用户所在机构", defaultValue = "")
            @RequestParam(value = "userOrgCode", required = false) List<Long> userOrgCode) ;
    @RequestMapping(value = "/organizations/getAllOrgsNoPaging", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询所有机构列表不分页")
    List<MOrganization> getAllOrgsNoPaging();
    @RequestMapping(value = "/organizations/batch", method = RequestMethod.POST)
    @ApiOperation("批量导入机构")
    boolean createOrgBatch(@RequestBody String orgs);
    @RequestMapping(value = ServiceApi.Org.getseaOrgsByOrgCode, method = RequestMethod.POST)
    @ApiOperation("根据机构code获取机构code和name")
    Map<String,String> seaOrgsByOrgCode(
            @ApiParam(name = "org_codes", value = "机构org_codes", defaultValue = "")
            @RequestBody String org_codes);
    @RequestMapping(value = "/organizations/getHospital", method = RequestMethod.GET)
    @ApiOperation("查询所有经纬度医院列表")
    Envelop getHospital();
    @RequestMapping(value = "/organizations/getOrgListByAddressPid", method = RequestMethod.GET)
    @ApiOperation(value = "根据区域查询机构列表")
    Envelop getOrgListByAddressPid(
            @RequestParam(value = "pid") Integer pid,
            @RequestParam(value = "fullName", required = false) String fullName);
    @RequestMapping(value = "/organizations/getOrgListTreeByAddressPid", method = RequestMethod.GET)
    @ApiOperation(value = "根据区域、机构区县查询机构列表")
    List<Map<String, Object>> getOrgListTreeByAddressPid(
            @RequestParam(value = "pid") Integer pid);
}

+ 171 - 0
src/main/java/com/yihu/ehr/patient/controller/AuthenticationController.java

@ -0,0 +1,171 @@
package com.yihu.ehr.patient.controller;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.agModel.patient.AuthenticationModel;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.model.dict.MDictionaryEntry;
import com.yihu.ehr.model.patient.MAuthentication;
import com.yihu.ehr.patient.service.AuthenticationClient;
import com.yihu.ehr.systemdict.service.SystemDictClient;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.util.FeignExceptionUtils;
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.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author lincl
 * @version 1.0
 * @created 2016.3.1
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(protocols = "https", value = "Authentication", description = "人口身份认证", tags = {"人口管理-人口身份认证"})
public class AuthenticationController extends ExtendController<AuthenticationModel> {
    @Autowired
    AuthenticationClient authenticationClient;
    @Autowired
    SystemDictClient systemDictClient;
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.GET)
    @ApiOperation(value = "人口身份认证申请列表")
    public Envelop search(
            @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){
        ResponseEntity<List<MAuthentication>> responseEntity = authenticationClient.search(fields, filters, sorts, size, page);
        return getResult(convertModels(responseEntity.getBody()), getTotalCount(responseEntity), page, size);
    }
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.POST)
    @ApiOperation(value = "新增认证申请")
    public Envelop add(
            @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
            @RequestParam("model") String model) {
        try {
            return success(convertModel(authenticationClient.add(model)) );
        }catch (Exception e){
            e.printStackTrace();
            return failed(FeignExceptionUtils.getErrorMsg(e));
        }
    }
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.PUT)
    @ApiOperation(value = "修改认证申请")
    public Envelop update(
            @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
            @RequestParam("model") String model) {
        try {
            AuthenticationModel authenticationModel = toEntity(model,AuthenticationModel.class);
            MAuthentication authentication = convertToMModel(authenticationModel, MAuthentication.class);
            if(authentication.getId()==0)
                return failed("编号不能为空");
            return success(convertModel(authenticationClient.update(authentication)) );
        }catch (Exception e){
            e.printStackTrace();
            return failed(FeignExceptionUtils.getErrorMsg(e));
        }
    }
    @RequestMapping(value = ServiceApi.Patients.Authentication, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除认证申请")
    public Envelop delete(
            @ApiParam(name = "id", value = "编号", defaultValue = "")
            @PathVariable(value = "id") int id) {
        try {
            authenticationClient.delete(id);
            return success("");
        }catch (Exception e){
            e.printStackTrace();
            return failed(FeignExceptionUtils.getErrorMsg(e));
        }
    }
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除认证申请")
    public boolean batchDelete(
            @ApiParam(name = "ids", value = "编号集", defaultValue = "")
            @RequestParam(value = "ids") String ids) {
        return authenticationClient.batchDelete(ids.split(","));
    }
    @RequestMapping(value = ServiceApi.Patients.Authentication, method = RequestMethod.GET)
    @ApiOperation(value = "获取认证申请信息")
    public Envelop getInfo(
            @ApiParam(name = "id", value = "档案关联编号", defaultValue = "")
            @PathVariable(value = "id") int id) {
        try {
            MAuthentication authentication = authenticationClient.getInfo(id);
            if(authentication == null)
                return failed("没有找到该认证申请信息!");
            return success(convertModel(authentication));
        }catch (Exception e){
            e.printStackTrace();
            return failed("获取信息出错!");
        }
    }
    private AuthenticationModel convertModel(MAuthentication authentication){
        AuthenticationModel model = getModel(authentication);
        if(!StringUtils.isEmpty(model.getStatus())){
            MDictionaryEntry statusDicts = systemDictClient.getDictEntry(36, model.getStatus());
            if(statusDicts!=null)
                model.setStatusName(statusDicts.getValue());
        }
        if(!StringUtils.isEmpty(model.getMedicalCardType())){
            MDictionaryEntry statusDicts = systemDictClient.getDictEntry(10, model.getMedicalCardType());
            if(statusDicts!=null)
                model.setMedicalCardTypeName(statusDicts.getValue());
        }
        model.setApplyDate(dt2Str(authentication.getApplyDate()));
        model.setAuditDate(dt2Str(authentication.getAuditDate()));
        return model;
    }
    private List convertModels(List<MAuthentication> authentications){
        List<MDictionaryEntry> statusDicts = systemDictClient.getDictEntries("", "dictId=36", "", 10, 1).getBody();
        Map<String, String> statusMap = new HashMap<>();
        for(MDictionaryEntry entry : statusDicts){
            statusMap.put(entry.getCode(), entry.getValue());
        }
        List ls = new ArrayList<>();
        AuthenticationModel model;
        for(MAuthentication authentication : authentications){
            model = getModel(authentication);
            model.setStatusName(statusMap.get(authentication.getStatus()));
            model.setApplyDate(dt2Str(authentication.getApplyDate()));
            model.setAuditDate(dt2Str(authentication.getAuditDate()));
            ls.add(model);
        }
        return ls;
    }
}

+ 226 - 0
src/main/java/com/yihu/ehr/patient/controller/CardController.java

@ -0,0 +1,226 @@
package com.yihu.ehr.patient.controller;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.agModel.patient.CardDetailModel;
import com.yihu.ehr.agModel.patient.CardModel;
import com.yihu.ehr.constants.AgAdminConstants;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.organization.service.OrganizationClient;
import com.yihu.ehr.patient.service.CardClient;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.org.MOrganization;
import com.yihu.ehr.model.patient.MAbstractCard;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by AndyCai on 2016/1/21.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "card", description = "就诊卡管理(旧)", tags = {"就诊卡管理(旧)"})
public class CardController extends BaseController {
    @Autowired
    private CardClient cardClient;
    @Autowired
    private ConventionalDictEntryClient conventionalDictEntryClient;
    @Autowired
    private OrganizationClient orgClient;
    /**
     * 根据身份证好查询相对应的卡列表
     *
     * @param idCardNo
     * @param number
     * @param cardType
     * @param page
     * @param rows
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/binding", method = RequestMethod.GET)
    @ApiOperation(value = "根据身份证好查询相对应的卡列表")
    public Envelop searchCardBinding(
            @ApiParam(name = "id_card_no", value = "身份证号", defaultValue = "")
            @RequestParam(value = "id_card_no") String idCardNo,
            @ApiParam(name = "number", value = "卡号", defaultValue = "")
            @RequestParam(value = "number") String number,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType,
            @ApiParam(name = "page", value = "当前页", defaultValue = "")
            @RequestParam(value = "page") Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows") Integer rows) throws Exception {
        ResponseEntity<List<MAbstractCard>> responseEntity = cardClient.searchCardBinding(idCardNo, number, cardType, page, rows);
        List<MAbstractCard> mAbstractCards=responseEntity.getBody();
        List<CardModel> cardModels = new ArrayList<>();
        for (MAbstractCard info : mAbstractCards) {
            CardModel cardModel = convertToModel(info, CardModel.class);
            cardModel.setCreateDate(DateToString(info.getCreateDate(),AgAdminConstants.DateFormat));
            MConventionalDict dict =null;
            if(!StringUtils.isEmpty(cardModel.getCardType())) {
                dict = conventionalDictEntryClient.getCardType(cardModel.getCardType());
                cardModel.setTypeName(dict.getValue());
            }
            if (!StringUtils.isEmpty(cardModel.getStatus())) {
                dict = conventionalDictEntryClient.getCardStatus(cardModel.getStatus());
                cardModel.setStatusName(dict.getValue());
            }
            if(!StringUtils.isEmpty(cardModel.getReleaseOrg())) {
                MOrganization organization = orgClient.getOrg(cardModel.getReleaseOrg());
                cardModel.setReleaseOrgName(organization.getFullName());
            }
            cardModels.add(cardModel);
        }
        Envelop envelop = getResult(cardModels, getTotalCount(responseEntity), page, rows);
        return envelop;
    }
    /**
     * 查询未绑定的卡列表
     *
     * @param number
     * @param cardType
     * @param page
     * @param rows
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/un_binding", method = RequestMethod.GET)
    @ApiOperation(value = "查询未绑定的卡列表")
    public Envelop searchCardUnBinding(
            @ApiParam(name = "number", value = "卡号", defaultValue = "")
            @RequestParam(value = "number") String number,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType,
            @ApiParam(name = "page", value = "当前页", defaultValue = "")
            @RequestParam(value = "page") Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows") Integer rows) throws Exception {
        ResponseEntity<List<MAbstractCard>> responseEntity  = cardClient.searchCardUnBinding(number, cardType, page, rows);
        List<MAbstractCard> mAbstractCards =responseEntity.getBody();
        List<CardModel> cardModels = new ArrayList<>();
        for (MAbstractCard info : mAbstractCards){
            CardModel cardModel = convertToModel(info, CardModel.class);
            cardModel.setCreateDate(info.getCreateDate() == null?"": DateTimeUtil.simpleDateTimeFormat(info.getCreateDate()).substring(0, 10) );
            MConventionalDict dict =null;
            if(!StringUtils.isEmpty(cardModel.getCardType())) {
                dict = conventionalDictEntryClient.getCardType(cardModel.getCardType());
                cardModel.setTypeName(dict.getValue());
            }
            if (!StringUtils.isEmpty(cardModel.getStatus())) {
                dict = conventionalDictEntryClient.getCardStatus(cardModel.getStatus());
                cardModel.setStatusName(dict.getValue());
            }
            if(!StringUtils.isEmpty(cardModel.getReleaseOrg())) {
                MOrganization organization = orgClient.getOrg(cardModel.getReleaseOrg());
                cardModel.setReleaseOrgName(organization.getFullName());
            }
            cardModels.add(cardModel);
        }
        Envelop envelop = getResult(cardModels, getTotalCount(responseEntity), page, rows);
        return envelop;
    }
    /**
     * 根据卡号和卡类型查找卡
     *
     * @param id
     * @param cardType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据卡号和卡类型查找卡")
    public Envelop getCard(
            @ApiParam(name = "id", value = "卡号", defaultValue = "")
            @PathVariable(value = "id") String id,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType) throws Exception {
        MAbstractCard cardInfo = cardClient.getCard(id, cardType);
        CardDetailModel detailModel = convertToModel(cardInfo,CardDetailModel.class);
        if(detailModel==null)
        {
            return failed("数据获取失败!");
        }
        detailModel.setCreateDate(DateToString(cardInfo.getCreateDate(), AgAdminConstants.DateFormat));
        detailModel.setReleaseDate(DateToString(cardInfo.getReleaseDate(),AgAdminConstants.DateTimeFormat));
        detailModel.setValidityDateBegin(DateToString(cardInfo.getValidityDateBegin(),AgAdminConstants.DateTimeFormat));
        detailModel.setValidityDateEnd(DateToString(cardInfo.getValidityDateEnd(),AgAdminConstants.DateTimeFormat));
        MConventionalDict dict=null;
        if (!StringUtils.isEmpty(detailModel.getCardType())) {
            dict = conventionalDictEntryClient.getCardType(detailModel.getCardType());
            detailModel.setTypeName(dict.getValue());
        }
        if (!StringUtils.isEmpty(detailModel.getStatus())) {
            dict = conventionalDictEntryClient.getCardStatus(detailModel.getStatus());
            detailModel.setStatusName(dict.getValue());
        }
        if (!StringUtils.isEmpty(detailModel.getReleaseOrg())){
            MOrganization organization = orgClient.getOrg(detailModel.getReleaseOrg());
            detailModel.setReleaseOrgName(organization.getFullName());
        }
        return success(detailModel);
    }
    /**
     * 根据卡编号和卡类型解绑卡
     *
     * @param id
     * @param cardType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/detach/{id}", method = RequestMethod.PUT)
    @ApiOperation(value = "根据卡号和卡类型解绑卡")
    public boolean detachCard(
            @ApiParam(name = "id", value = "卡号", defaultValue = "")
            @PathVariable(value = "id") String id,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType) throws Exception {
        return cardClient.detachCard(id, cardType);
    }
    /**
     * 根据卡编号,身份证号,卡类型绑定卡
     *
     * @param id
     * @param idCardNo
     * @param cardType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/attach/{id}", method = RequestMethod.PUT)
    @ApiOperation(value = "根据卡编号(卡主键,卡的唯一标识),身份证号,卡类型绑定卡")
    public boolean attachCard(
            @ApiParam(name = "id", value = "卡号", defaultValue = "")
            @PathVariable(value = "id") String id,
            @ApiParam(name = "id_card_no", value = "身份证号", defaultValue = "")
            @RequestParam(value = "id_card_no") String idCardNo,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType) throws Exception {
        return cardClient.attachCard(id, idCardNo, cardType);
    }
}

+ 193 - 0
src/main/java/com/yihu/ehr/patient/controller/HomeRelationshipController.java

@ -0,0 +1,193 @@
package com.yihu.ehr.patient.controller;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.agModel.patient.HomeGroupModel;
import com.yihu.ehr.agModel.patient.HomeRelationshipModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.family.MFamilies;
import com.yihu.ehr.model.family.MMembers;
import com.yihu.ehr.model.patient.MDemographicInfo;
import com.yihu.ehr.patient.service.FamiliesClient;
import com.yihu.ehr.patient.service.MembersClient;
import com.yihu.ehr.patient.service.PatientClient;
import com.yihu.ehr.util.datetime.DateTimeUtil;
import com.yihu.ehr.util.rest.Envelop;
import com.yihu.ehr.controller.BaseController;
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.http.ResponseEntity;
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.*;
/**
 * Created by AndyCai on 2016/4/20.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "home_relationship", description = "家庭关系管理", tags = {"人口管理-家庭关系管理"})
public class HomeRelationshipController extends BaseController {
    @Autowired
    private MembersClient membersClient;
    @Autowired
    private FamiliesClient familiesClient;
    @Autowired
    private PatientClient patientClient;
    @Autowired
    private ConventionalDictEntryClient conventionalDictClient;
    @RequestMapping(value = "/home_relationship", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查家庭关系")
    public Envelop getHomeRelationship(
            @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) {
        try {
            // 根据查询条件查询家庭组ID
            List<MFamilies> mFamilies = (List<MFamilies>)familiesClient.searchFamilies(fields, filters, sorts, size, page).getBody();
            if(mFamilies==null || mFamilies.size()==0)
            {
                return getResult(null, 0, page, size);
            }
            //根据查询所得的家庭组ID查询家庭成员
            filters="familyId="+mFamilies.get(0).getId();
            ResponseEntity<Collection<MMembers>> membersResponseEntity = membersClient.searchMembers(fields, filters, sorts, size, page);
            List<MMembers> mMemberses = (List<MMembers>)membersResponseEntity.getBody();
            List<HomeRelationshipModel> relationshipModels = new ArrayList<>();
            for(MMembers mMembers :mMemberses )
            {
                HomeRelationshipModel relationshipModel = convertToHomeRelationshipModel(mMembers);
                if(StringUtils.isNotBlank(mMembers.getFamilyRelation())){
                  MConventionalDict dict = conventionalDictClient.getFamilyRelationship(mMembers.getFamilyRelation());
                  if(dict!=null){
                    relationshipModel.setRelationShipName(dict.getValue());
                  }
                }
                relationshipModels.add(relationshipModel);
            }
            return getResult(relationshipModels, getTotalCount(membersResponseEntity), page, size);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = "/home_group", method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询家庭群组")
    public Envelop getHomeGroup(
            @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) {
        try {
            //根据查询条件获取家庭组ID
            List<MMembers> mMemberses = (List<MMembers>)membersClient.searchMembers(fields, filters, sorts, size, page).getBody();
            if(mMemberses==null || mMemberses.size()==0)
            {
                return getResult(null, 0, page, size);
            }
            String id="";
            String idCardNo = mMemberses.get(0).getIdCardNo();
            HashMap<String,String> familyRelationMap = new HashMap<String,String>();
            for(MMembers mMembers : mMemberses)
            {
                familyRelationMap.put(mMembers.getFamilyId(),mMembers.getFamilyRelation());
                id+=mMembers.getFamilyId()+",";
            }
            id = trimEnd(id,",");
            //根据家庭组ID获取家庭组信息
            filters="id="+id;
            ResponseEntity<Collection<MFamilies>> familyResponseEntity = familiesClient.searchFamilies(fields, filters, sorts, size, page);
            List<MFamilies> mFamiliesList = (List<MFamilies>)familyResponseEntity.getBody();
            List<HomeGroupModel> homeGroupModels = new ArrayList<>();
            for(MFamilies mFamilies:mFamiliesList)
            {
                HomeGroupModel groupModel = convertToHomeGroupModel(mFamilies,idCardNo);
                if(StringUtils.isNotBlank(familyRelationMap.get(mFamilies.getId()))){
                    MConventionalDict dict = conventionalDictClient.getFamilyRelationship(familyRelationMap.get(mFamilies.getId()));
                    if(dict!=null){
                        groupModel.setRelationshipName(dict.getValue());
                    }
                }
                homeGroupModels.add(groupModel);
            }
            return getResult(homeGroupModels, getTotalCount(familyResponseEntity), page, size);
        } catch (Exception ex) {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    public HomeRelationshipModel convertToHomeRelationshipModel(MMembers mMembers)
    {
        HomeRelationshipModel relationshipModel = new HomeRelationshipModel();
        relationshipModel.setId(mMembers.getId());
        if(StringUtils.isNotEmpty(mMembers.getIdCardNo()))
        {
            MDemographicInfo info =patientClient.getPatient(mMembers.getIdCardNo());
            relationshipModel.setAge(info==null?"0":String.valueOf(getAgeByBirthday(info.getBirthday())));
            relationshipModel.setName(info==null?"0":info.getName());
        }
//        relationshipModel.setRelationTime(DateToString(mMembers.getCreateDate(), AgAdminConstants.DateFormat));
        relationshipModel.setRelationTime(DateTimeUtil.simpleDateTimeFormat(mMembers.getCreateDate()));
        //TODO:获取关系字典信息
        return relationshipModel;
    }
    public HomeGroupModel convertToHomeGroupModel(MFamilies mFamilies,String idCardNo)
    {
        HomeGroupModel groupModel = new HomeGroupModel();
        groupModel.setId(mFamilies.getId());
        if(StringUtils.isNotEmpty(mFamilies.getHouseholderIdCardNo()))
        {
            MDemographicInfo info =patientClient.getPatient(mFamilies.getHouseholderIdCardNo());
            groupModel.setName(info==null?"0":info.getName());
        }
//        groupModel.setCreateTime(DateToString(mFamilies.getCreateDate(), AgAdminConstants.DateFormat));
        groupModel.setCreateTime(DateTimeUtil.simpleDateTimeFormat(mFamilies.getCreateDate()));
        String filters="familyId="+mFamilies.getId()+";idCardNo="+idCardNo;
        List<MMembers> mMemberses = (List<MMembers>)membersClient.searchMembers("", filters, "", 15, 1).getBody();
        if(mMemberses!=null && mMemberses.size()>0)
        {
            //获取关系ID
           // String relationId = mMemberses.get(0).getFamilyRelation();
            //TODO:获取关系字典信息
        }
        return groupModel;
    }
}

+ 317 - 0
src/main/java/com/yihu/ehr/patient/controller/PatientArchiveController.java

@ -0,0 +1,317 @@
package com.yihu.ehr.patient.controller;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.entity.patient.ArchiveApply;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.common.ObjectResult;
import com.yihu.ehr.model.common.Result;
import com.yihu.ehr.model.dict.MDictionaryEntry;
import com.yihu.ehr.model.user.MUser;
import com.yihu.ehr.patient.service.PatientArchiveClient;
import com.yihu.ehr.systemdict.service.SystemDictClient;
import com.yihu.ehr.users.service.UserClient;
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.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(protocols = "https", value = "archive_apply", description = "居民档案申领关联接口" , tags = {"人口管理-居民档案申领关联接口"})
public class PatientArchiveController extends ExtendController<ArchiveApply> {
    String appId = "ag-admin";
    @Autowired
    PatientArchiveClient patientArchiveClient;
    @Autowired
    SystemDictClient systemDictClient;
    @Autowired
    UserClient userClient;
    @RequestMapping(value = ServiceApi.Patients.GetArchiveList, method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询档案列表(arApply)")
    public Envelop getMCards(
            @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 = "+name,+createTime")
            @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 = patientArchiveClient.getApplyList(fields, filters, sorts, size, page);
        if(listResult.getTotalCount() != 0){
            List<Map<String,Object>> list = listResult.getDetailModelList();
            list = convertArApplyModels(list);
            return getResult(list, listResult.getTotalCount(), listResult.getCurrPage(), listResult.getPageSize());
        }else{
            Envelop envelop = new Envelop();
            return envelop;
        }
    }
    @RequestMapping(value = ServiceApi.Patients.GetArchiveRelationList, method = RequestMethod.GET)
    @ApiOperation(value = "根据查询条件查询档案关联列表(arRelation)")
    public Envelop getArRelationList(
            @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 = "+name,+createTime")
            @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 = patientArchiveClient.getArRelationList(fields, filters, sorts, size, page);
        if(listResult.getTotalCount() != 0){
            List<Map<String,Object>> list = listResult.getDetailModelList();
            list = convertArRelaModels(list);
            return getResult(list, listResult.getTotalCount(), listResult.getCurrPage(), listResult.getPageSize());
        }else{
            Envelop envelop = new Envelop();
            return envelop;
        }
    }
    @RequestMapping(value = ServiceApi.Patients.GetArchiveRelation,method = RequestMethod.GET)
    @ApiOperation(value = "档案关联详情")
    public Envelop getArRelation(
            @ApiParam(name = "applyId", value = "applyId", defaultValue = "")
            @PathVariable(value = "applyId") Long applyId) throws Exception{
        ObjectResult objectResult = patientArchiveClient.getArRelation(applyId);
        if(objectResult.getData() != null){
            Map<String,Object> info = (HashMap)objectResult.getData();
            info = convertArRelaModel(info);
            return successObj(info);
        }
        return null;
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveApplyList,method = RequestMethod.GET)
    @ApiOperation(value = "居民查看提交的档案申请列表")
    public Envelop archiveApplyList(
            @ApiParam(name = "userId", value = "用户ID", defaultValue = "0dae00035715c8906db7084cdb79f56b")
            @RequestParam String userId,
            @ApiParam(name = "status", value = "审核状态 -1审核不通过 0待审核 1审核通过", defaultValue = "1")
            @RequestParam(required = false) String status,
            @ApiParam(name = "page", value = "当前页(从0开始)", defaultValue = "0")
            @RequestParam Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "15")
            @RequestParam Integer rows) {
        ListResult result = patientArchiveClient.archiveApplyList(userId,status,page,rows);
        List<Map<String,Object>> list = result.getDetailModelList();
        list = convertArApplyModels(list);
        return getResult(list, result.getTotalCount(), result.getCurrPage(), result.getPageSize());
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveApply,method = RequestMethod.GET)
    @ApiOperation(value = "档案认领信息详情")
    public Envelop getArchiveApply(
            @ApiParam(name = "id", value = "id", defaultValue = "1")
            @RequestParam(value = "id", required = false) Long id) throws Exception{
        ObjectResult objectResult = patientArchiveClient.getArchiveApply(id);
        if(objectResult.getData() != null){
            Map<String,Object> info = (HashMap)objectResult.getData();
            info = convertArApplyModel(info);
            return successObj(info);
        }
        return null;
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveApply,method = RequestMethod.POST)
    @ApiOperation(value = "档案认领申请(临时卡)新增/修改")
    public Envelop archiveApply(
            @ApiParam(name = "data", value = "json数据", defaultValue = "")
            @RequestBody String data) throws Exception{
        ObjectResult objectResult = patientArchiveClient.archiveApply(data);
        if(objectResult.getCode() == 200){
            return successObj(objectResult.getData());
        }else{
            return null;
        }
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveApply,method = RequestMethod.DELETE)
    @ApiOperation(value = "档案认领删除")
    public Envelop archiveApplyDelete(
            @ApiParam(name = "id", value = "档案认领ID", defaultValue = "")
            @RequestParam(value = "id", required = false) Long id) throws Exception{
        Result result = patientArchiveClient.archiveApplyDelete(id);
        if(result.getCode() == 200){
            return successMsg(result.getMessage());
        }else{
            return failed("档案认领申请删除失败!");
        }
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveApplyListManager,method = RequestMethod.GET)
    @ApiOperation(value = "管理员--档案认领列表")
    public Envelop archiveApplyListManager(
            @ApiParam(name = "status", value = "审核状态 -1审核不通过 0待审核 1审核通过", defaultValue = "0")
            @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "page", value = "当前页(从0开始)", defaultValue = "")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows", required = false) Integer rows) throws Exception{
        ListResult result = patientArchiveClient.archiveApplyListManager(status, page, rows);
        List<Map<String,Object>> list = result.getDetailModelList();
        list = convertArApplyModels(list);
        return getResult(list, result.getTotalCount(), result.getCurrPage(), result.getPageSize());
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveVerifyManager,method = RequestMethod.GET)
    @ApiOperation(value = "管理员--档案认领审核操作")
    public Envelop archiveVerifyManager(
            @ApiParam(name = "id", value = "档案认领ID", defaultValue = "")
            @RequestParam(value = "id", required = false) Long id,
            @ApiParam(name = "status", value = "审核状态 2 审核不通过 0待审核 1审核通过", defaultValue = "")
            @RequestParam(value = "status", required = false) String status,
            @ApiParam(name = "auditor", value = "审核者", defaultValue = "")
            @RequestParam(value = "auditor", required = false) String auditor,
            @ApiParam(name = "auditReason", value = "审核不通过原因", defaultValue = "")
            @RequestParam(value = "auditReason",required = false) String auditReason,
            @ApiParam(name = "archiveRelationIds", value = "档案关联ID,多条用逗号分隔", defaultValue = "")
            @RequestParam(value = "archiveRelationIds", required = false) String archiveRelationIds) throws Exception{
        Result result = patientArchiveClient.archiveVerifyManager(id,status, auditor,auditReason,archiveRelationIds);
        if(result.getCode() == 200){
            return successMsg(result.getMessage());
        }else{
            return failed(result.getMessage());
        }
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveList,method = RequestMethod.GET)
    @ApiOperation(value = "个人档案列表")
    public Envelop archiveList(
            @ApiParam(name = "idCardNo", value = "身份证号码", defaultValue = "")
            @RequestParam(value = "idCardNo", required = false) String idCardNo,
            @ApiParam(name = "page", value = "当前页(从0开始)", defaultValue = "")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows", required = false) Integer rows) throws Exception{
        ListResult result = patientArchiveClient.archiveList(idCardNo, page, rows);
        List<Map<String,Object>> list = result.getDetailModelList();
        list = convertArRelaModels(list);
        return getResult(list, result.getTotalCount(), result.getCurrPage(), result.getPageSize());
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveUnbind,method = RequestMethod.GET)
    @ApiOperation(value = "管理员--通过卡号获取未认领档案")
    public Envelop archiveUnbind(
            @ApiParam(name = "cardNo", value = "就诊卡号", defaultValue = "")
            @RequestParam(value = "cardNo",required = false) String cardNo,
            @ApiParam(name = "page", value = "当前页(从0开始)", defaultValue = "")
            @RequestParam(value = "page",required = false) Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows",required = false) Integer rows) throws Exception{
        ListResult result = patientArchiveClient.archiveUnbind(cardNo, page, rows);
        List<Map<String,Object>> list = result.getDetailModelList();
        list = convertArRelaModels(list);
        return getResult(list, result.getTotalCount(), result.getCurrPage(), result.getPageSize());
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveRelation,method = RequestMethod.POST)
    @ApiOperation(value = "新建档案关联")
    public Envelop archiveRelation(
            @ApiParam(name = "data", value = "json数据", defaultValue = "")
            @RequestBody String data) throws Exception{
        ObjectResult objectResult = patientArchiveClient.archiveRelation(data);
        if(objectResult.getCode() == 200){
            return successObj(objectResult.getData());
        }else{
            return null;
        }
    }
    private Map<String,Object>  convertArRelaModel(Map<String,Object> ArRela){
        List<MDictionaryEntry>  eventTypeDicts = systemDictClient.getDictEntries("", "dictId=64", "", 10, 1).getBody();
        Map<String, String>  eventTypeMap = new HashMap<>();
        for(MDictionaryEntry entry : eventTypeDicts){
            eventTypeMap.put(entry.getCode(), entry.getValue());
        }
        List<MDictionaryEntry>  relaStatusDicts = systemDictClient.getDictEntries("", "dictId=65", "", 10, 1).getBody();
        Map<String, String> relaStatusMap = new HashMap<>();
        for(MDictionaryEntry entry : relaStatusDicts){
            relaStatusMap.put(entry.getCode(), entry.getValue());
        }
        ArRela.put("eventTypeName",eventTypeMap.get(ArRela.get("eventType")));
        ArRela.put("statusName",relaStatusMap.get(ArRela.get("status")));
        return ArRela;
    }
    private List convertArRelaModels(List<Map<String,Object>> ArRelaL){
        List<MDictionaryEntry>  eventTypeDicts = systemDictClient.getDictEntries("", "dictId=64", "", 10, 1).getBody();
        Map<String, String>  eventTypeMap = new HashMap<>();
        for(MDictionaryEntry entry : eventTypeDicts){
            eventTypeMap.put(entry.getCode(), entry.getValue());
        }
        List<MDictionaryEntry>  relaStatusDicts = systemDictClient.getDictEntries("", "dictId=65", "", 10, 1).getBody();
        Map<String, String> relaStatusMap = new HashMap<>();
        for(MDictionaryEntry entry : relaStatusDicts){
            relaStatusMap.put(entry.getCode(), entry.getValue());
        }
        List<MDictionaryEntry>  cardTypeDicts = systemDictClient.getDictEntries("", "dictId=66", "", 10, 1).getBody();
        Map<String, String>  cardTypeMap = new HashMap<>();
        for(MDictionaryEntry entry : cardTypeDicts){
            cardTypeMap.put(entry.getCode(), entry.getValue());
        }
        for(Map<String,Object> ArRela : ArRelaL){
            ArRela.put("eventTypeName",eventTypeMap.get(ArRela.get("eventType")));
            ArRela.put("statusName",relaStatusMap.get(ArRela.get("status")));
            ArRela.put("cardTypeName",cardTypeMap.get(ArRela.get("cardType")));
        }
        return ArRelaL;
    }
    private Map<String,Object>  convertArApplyModel(Map<String,Object> arApp){
        List<MDictionaryEntry> statusDicts = systemDictClient.getDictEntries("", "dictId=36", "", 10, 1).getBody();
        Map<String, String> statusMap = new HashMap<>();
        for(MDictionaryEntry entry : statusDicts){
            statusMap.put(entry.getCode(), entry.getValue());
        }
        arApp.put("statusName",statusMap.get(arApp.get("status")));
        return arApp;
    }
    private List convertArApplyModels(List<Map<String,Object>> arApplies){
        List<MDictionaryEntry> statusDicts = systemDictClient.getDictEntries("", "dictId=36", "", 10, 1).getBody();
        Map<String, String> statusMap = new HashMap<>();
        for(MDictionaryEntry entry : statusDicts){
            statusMap.put(entry.getCode(), entry.getValue());
        }
        for(Map<String,Object> info : arApplies){
            if(info.get("auditor") != null){
                MUser user = userClient.getUser(info.get("auditor").toString());
                if(user!=null){
                    info.put("auditor",user.getRealName());
                }
            }
            info.put("statusName",statusMap.get(info.get("status")));
        }
        return arApplies;
    }
}

+ 458 - 0
src/main/java/com/yihu/ehr/patient/controller/PatientCardsController.java

@ -0,0 +1,458 @@
package com.yihu.ehr.patient.controller;
import com.yihu.ehr.adapter.utils.ExtendController;
import com.yihu.ehr.agModel.patient.MedicalCardsModel;
import com.yihu.ehr.agModel.patient.UserCardsModel;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.model.common.ListResult;
import com.yihu.ehr.model.common.ObjectResult;
import com.yihu.ehr.model.common.Result;
import com.yihu.ehr.model.dict.MConventionalDict;
import com.yihu.ehr.model.dict.MDictionaryEntry;
import com.yihu.ehr.entity.patient.MedicalCards;
import com.yihu.ehr.entity.patient.UserCards;
import com.yihu.ehr.model.user.MUser;
import com.yihu.ehr.patient.service.PatientCardsClient;
import com.yihu.ehr.systemdict.service.ConventionalDictEntryClient;
import com.yihu.ehr.systemdict.service.SystemDictClient;
import com.yihu.ehr.users.service.UserClient;
import com.yihu.ehr.util.datetime.DateTimeUtil;
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.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by AndyCai on 2016/1/21.
 */
@RequestMapping(ApiVersion.Version1_0 + "/admin")
@RestController
@Api(value = "card", description = "就诊卡管理及卡认领接口", tags = {"人口管理-就诊卡管理及卡认领接口"})
public class PatientCardsController extends ExtendController<UserCards> {
    @Autowired
    PatientCardsClient patientCardsClient;
    @Autowired
    SystemDictClient systemDictClient;
    @Autowired
    private ConventionalDictEntryClient conventionalDictClient;
    @Autowired
    UserClient userClient;
    @RequestMapping(value = ServiceApi.Patients.GetUserCards, method = RequestMethod.GET)
    @ApiOperation(value = "获取用户关联卡列表", notes = "根据查询条件获取用户关联卡列表在前端表格展示")
    public Envelop searchPatientUserCards(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,ownerName,cardNo,createDate")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @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) {
        List<UserCardsModel> userCardsModelList = new ArrayList<>();
        ResponseEntity<List<UserCards>> responseEntity = patientCardsClient.getUserCardList(fields, filters, sorts, size, page);
        List<UserCards> userCardss = responseEntity.getBody();
        for (UserCards userCard : userCardss) {
            UserCardsModel userCardsModel = convertToModel(userCard, UserCardsModel.class);
            userCardsModel.setCreateDate(userCard.getCreateDate() == null?"": DateTimeUtil.simpleDateTimeFormat(userCard.getCreateDate()).substring(0, 10) );
            userCardsModel.setReleaseDate(userCard.getReleaseDate() == null?"": DateTimeUtil.simpleDateTimeFormat(userCard.getReleaseDate()).substring(0,10) );
            userCardsModel.setValidityDateBegin(userCard.getValidityDateBegin() == null ? "" : DateTimeUtil.simpleDateTimeFormat(userCard.getValidityDateBegin()).substring(0, 10) );
            userCardsModel.setValidityDateEnd(userCard.getValidityDateEnd() == null ? "" : DateTimeUtil.simpleDateTimeFormat(userCard.getValidityDateEnd()).substring(0, 10) );
            MConventionalDict dict = conventionalDictClient.getMedicalCardTypeList(String.valueOf(userCard.getCardType()));
            userCardsModel.setCardTypeName(dict == null ? "" : dict.getValue());
            userCardsModelList.add(userCardsModel);
        }
        Envelop envelop =new Envelop();
        Integer totalCount = getTotalCount(responseEntity);
        if(totalCount > 0){
            envelop = getResult(userCardsModelList, totalCount, page, size);
        }
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Patients.CardList,method = RequestMethod.GET)
    @ApiOperation(value = "获取个人卡列表")
    public Envelop cardList(
            @ApiParam(name = "userId", value = "用户ID", defaultValue = "")
            @RequestParam(value = "userId",required = false) String userId,
            @ApiParam(name = "cardType", value = "卡类别", defaultValue = "")
            @RequestParam(value = "cardType",required = false) String cardType,
            @ApiParam(name = "page", value = "当前页(从0开始)", defaultValue = "")
            @RequestParam(value = "page",required = false) Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows",required = false) Integer rows) throws Exception{
        ListResult result = patientCardsClient.cardList(userId, cardType, page, rows);
        List<Map<String,Object>> list = result.getDetailModelList();
        list = convertCardModels(list);
        return getResult(list, result.getTotalCount(), result.getCurrPage(), result.getPageSize());
    }
    @RequestMapping(value = ServiceApi.Patients.CardApply,method = RequestMethod.GET)
    @ApiOperation(value = "卡认证详情")
    public Envelop getCardApply(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @RequestParam(value = "id",required = false) Long id) throws Exception{
        ObjectResult objectResult = patientCardsClient.getCardApply(id);
        if(objectResult.getData() != null){
            Map<String,Object> info = (HashMap)objectResult.getData();
            info = convertCardModel(info);
            return successObj(info);
        }
        return null;
    }
    @RequestMapping(value = ServiceApi.Patients.CardApply,method = RequestMethod.POST)
    @ApiOperation(value = "卡认证申请新增/修改")
    public Envelop cardApply(
            @ApiParam(name = "data", value = "json数据", defaultValue = "")
            @RequestParam String data,
            @ApiParam(name = "operator", value = "操作者", defaultValue = "")
            @RequestParam(value = "operator",required = false) String operator) throws Exception{
        ObjectResult objectResult = patientCardsClient.cardApply(data,operator);
        if(objectResult.getCode() == 200){
            return successObj(objectResult.getData());
        }else{
            return null;
        }
    }
    @RequestMapping(value = ServiceApi.Patients.CardApply,method = RequestMethod.DELETE)
    @ApiOperation(value = "卡认证申请删除")
    public Envelop cardApplyDelete(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @RequestParam(value = "id",required = false) Long id) throws Exception{
        Result result = patientCardsClient.cardApplyDelete(id);
        if(result.getCode() == 200){
            return successMsg(result.getMessage());
        }else{
            return failed("档案认领申请删除失败!");
        }
    }
    @RequestMapping(value = ServiceApi.Patients.CardApplyListManager,method = RequestMethod.GET)
    @ApiOperation(value = "管理员--卡认证列表")
    public Envelop cardApplyListManager(
            @ApiParam(name = "status", value = "卡状态 -1审核不通过 0待审核 1审核通过", defaultValue = "0")
            @RequestParam(value = "status",required = false) String status,
            @ApiParam(name = "cardType", value = "卡类别", defaultValue = "")
            @RequestParam(value = "cardType",required = false) String cardType,
            @ApiParam(name = "page", value = "当前页(从0开始)", defaultValue = "")
            @RequestParam(value = "page",required = false) Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows",required = false) Integer rows) throws Exception{
        ListResult result = patientCardsClient.cardApplyListManager(status, cardType, page, rows);
        List<Map<String,Object>> list = result.getDetailModelList();
        list = convertCardModels(list);
        return getResult(list, result.getTotalCount(), result.getCurrPage(), result.getPageSize());
    }
    @RequestMapping(value = ServiceApi.Patients.CardVerifyManager,method = RequestMethod.POST)
    @ApiOperation(value = "管理员--卡认证审核操作")
    public Envelop cardVerifyManager(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @RequestParam(value = "id",required = false) Long id,
            @ApiParam(name = "status", value = "status", defaultValue = "")
            @RequestParam(value = "status",required = false) String status,
            @ApiParam(name = "auditor", value = "审核者", defaultValue = "")
            @RequestParam(value = "auditor",required = false) String auditor,
            @ApiParam(name = "auditReason", value = "审核不通过原因", defaultValue = "")
            @RequestParam(value = "auditReason",required = false) String auditReason) throws Exception{
        Result result = patientCardsClient.cardVerifyManager(id, status, auditor, auditReason);
        if (result.getCode() == 200){
            return successMsg(result.getMessage());
        }else{
            return failed(result.getMessage());
        }
    }
    @RequestMapping(value = ServiceApi.Patients.ArchiveRelationManager,method = RequestMethod.GET)
    @ApiOperation(value = "管理员--卡关联档案审核操作")
    public Envelop archiveRelationManager(
            @ApiParam(name = "cardId", value = "cardId", defaultValue = "")
            @RequestParam(value = "cardId",required = false) Long cardId,
            @ApiParam(name = "archiveRelationIds", value = "档案关联ID,多条用逗号分隔", defaultValue = "")
            @RequestParam(value = "archiveRelationIds", required = false) String archiveRelationIds) throws Exception{
        Result result = patientCardsClient.archiveRelationManager(cardId,archiveRelationIds);
        if(result.getCode() == 200){
            return successMsg(result.getMessage());
        }else{
            return failed(result.getMessage());
        }
    }
    @RequestMapping(value = ServiceApi.Patients.CardBindManager,method = RequestMethod.POST)
    @ApiOperation(value = "管理员--后台绑卡操作")
    public Envelop cardBindManager(
            @ApiParam(name = "data", value = "json数据", defaultValue = "")
            @RequestBody String data,
            @ApiParam(name = "operator", value = "操作者", defaultValue = "")
            @RequestParam(value = "operator",required = false) String operator) throws Exception{
        ObjectResult objectResult = patientCardsClient.cardBindManager(data,operator);
        if(objectResult.getCode() == 200){
            Map<String,Object> info = (HashMap)objectResult.getData();
            info = convertCardModel(info);
            return successObj(info);
        }else{
            return failed(objectResult.getMessage());
        }
    }
    // ------------------------------ 就诊卡基础信息管理 --------------------------------------
    @RequestMapping(value = ServiceApi.Patients.GetMCards, method = RequestMethod.GET)
    @ApiOperation(value = "获取就诊卡列表信息")
    public Envelop getMCards(
            @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 = "+name,+createTime")
            @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 {
        List<MedicalCardsModel> medicalCardsModelList = new ArrayList<>();
        ResponseEntity<List<MedicalCards>> responseEntity = patientCardsClient.getMCards(fields, filters, sorts, size, page);
        List<MedicalCards> medicalCardss = responseEntity.getBody();
        for (MedicalCards medicalCards : medicalCardss) {
            MedicalCardsModel medicalCardsModel = convertToModel(medicalCards, MedicalCardsModel.class);
            medicalCardsModel.setCreateDate(medicalCards.getCreateDate() == null?"": DateTimeUtil.simpleDateTimeFormat(medicalCards.getCreateDate()).substring(0, 10) );
            medicalCardsModel.setReleaseDate(medicalCards.getReleaseDate() == null?"": DateTimeUtil.simpleDateTimeFormat(medicalCards.getReleaseDate()).substring(0,10) );
            medicalCardsModel.setValidityDateBegin(medicalCards.getValidityDateBegin() == null ? "" : DateTimeUtil.simpleDateTimeFormat(medicalCards.getValidityDateBegin()).substring(0, 10) );
            medicalCardsModel.setValidityDateEnd(medicalCards.getValidityDateEnd() == null ? "" : DateTimeUtil.simpleDateTimeFormat(medicalCards.getValidityDateEnd()).substring(0, 10) );
            MConventionalDict dict = conventionalDictClient.getMedicalCardTypeList(String.valueOf(medicalCards.getCardType()));
            medicalCardsModel.setCardTypeName(dict == null ? "" : dict.getValue());
            medicalCardsModelList.add(medicalCardsModel);
        }
        Integer totalCount = getTotalCount(responseEntity);
        Envelop envelop = new Envelop();
        if(totalCount > 0){
            envelop = getResult(medicalCardsModelList, totalCount, page, size);
        }
        return envelop;
    }
    @RequestMapping(value = ServiceApi.Patients.GetMCard,method = RequestMethod.GET)
    @ApiOperation(value = "就诊卡详情")
    public Envelop getMCard(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @RequestParam(value = "id",required = false) Long id) throws Exception{
        ObjectResult objectResult = patientCardsClient.getMCard(id);
        if(objectResult.getData() != null){
            Map<String,Object> info = (HashMap)objectResult.getData();
            info = convertCardModel(info);
            return successObj(info);
        }
        return null;
    }
    @RequestMapping(value = ServiceApi.Patients.MCardSave,method = RequestMethod.POST)
    @ApiOperation(value = "就诊卡新增/修改")
    public Envelop mCardSave(
            @ApiParam(name = "data", value = "json数据", defaultValue = "")
            @RequestParam(value = "data") String data,
            @ApiParam(name = "operator", value = "操作者", defaultValue = "")
            @RequestParam(value = "operator",required = false) String operator) throws Exception{
        ObjectResult objectResult = patientCardsClient.mCardSave(data,operator);
        if(objectResult.getCode() == 200){
            return successObj(objectResult.getData());
        }else{
            return null;
        }
    }
    @RequestMapping(value = ServiceApi.Patients.MCardDel,method = RequestMethod.DELETE)
    @ApiOperation(value = "就诊卡删除")
    public Envelop mCardDel(
            @ApiParam(name = "id", value = "id", defaultValue = "")
            @RequestParam(value = "id",required = false) Long id) throws Exception{
        Result result = patientCardsClient.mCardDelete(id);
        if(result.getCode() == 200){
            return successMsg(result.getMessage());
        }else{
            return failed("就诊卡删除失败!");
        }
    }
    @RequestMapping(value = ServiceApi.Patients.MCardCheckCardNo , method = RequestMethod.PUT)
    @ApiOperation(value = "校验卡是否唯一")
    public Envelop checkCard(
            @ApiParam(name = "cardNo", value = "卡号")
            @RequestParam(value = "cardNo", required = true) String cardNo
    ){
        try {
            Envelop envelop = new Envelop();
            String errorMsg = "";
            if (cardNo == null) {
                errorMsg+="卡号不能为空!";
                envelop.setErrorMsg(errorMsg);
            }
            int num = patientCardsClient.getCountByCardNo(cardNo);
            if (num > 0) {
                envelop.setSuccessFlg(true);
                envelop.setErrorMsg("卡号已存在!");
            }else{
                envelop.setSuccessFlg(false);
            }
            return envelop;
        } catch (Exception ex)
        {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Patients.MCardGetMutiCardNo , method = RequestMethod.PUT)
    @ApiOperation(value = "查询导入时重复卡列表")
    public Envelop getMutiCard(
            @ApiParam(name = "cardNoStr", value = "卡号字符串")
            @RequestParam(value = "cardNoStr", required = true) String cardNoStr
    ){
        try {
            List<MedicalCardsModel> medicalCardsModelList = new ArrayList<>();
            Envelop envelop = new Envelop();
            String errorMsg = "";
            if (cardNoStr == null) {
                errorMsg+="卡号不能为空!";
                envelop.setErrorMsg(errorMsg);
            }
            List<MedicalCards> medicalCardss = patientCardsClient.getBycardNoStr(cardNoStr);
            for (MedicalCards medicalCards : medicalCardss) {
                MedicalCardsModel medicalCardsModel = convertToModel(medicalCards, MedicalCardsModel.class);
                medicalCardsModelList.add(medicalCardsModel);
            }
            envelop.setSuccessFlg(true);
            envelop.setDetailModelList(medicalCardsModelList);
            return envelop;
        } catch (Exception ex)
        {
            ex.printStackTrace();
            return failedSystem();
        }
    }
    @RequestMapping(value = ServiceApi.Patients.MCarddataBatch, method = RequestMethod.POST)
    @ApiOperation("批量创建就诊卡")
    public Envelop createPatientCardsPatch(
            @ApiParam(name = "medicalCars", value = "就诊卡JSON", defaultValue = "")
            @RequestParam(value = "medicalCars") String medicalCars,
            @ApiParam(name = "operator", value = "操作者", defaultValue = "")
            @RequestParam(value = "operator",required = false) String operator) throws Exception {
        Envelop envelop = new Envelop();
        envelop.setSuccessFlg(true);
        try{
            patientCardsClient.createPatientCardsPatch(medicalCars,operator);
        }catch (Exception e){
            e.printStackTrace();
            envelop.setSuccessFlg(false);
            envelop.setErrorMsg("系统出错!");
        }
        return envelop;
    }
    private Map<String,Object> convertCardModel(Map<String,Object> userCard){
        List<MDictionaryEntry> statusDicts = systemDictClient.getDictEntries("", "dictId=43", "", 10, 1).getBody();
        List<MDictionaryEntry> typeDicts = systemDictClient.getDictEntries("", "dictId=66", "", 10, 1).getBody();
        if(!StringUtils.isEmpty(userCard.get("auditor"))){
            MUser user = userClient.getUser(userCard.get("auditor").toString());
            if(user!=null){
                userCard.put("auditor",user.getRealName());
            } else {
                userCard.put("auditor", "");
            }
        }
        Map<String, String> statusMap = new HashMap<>();
        for(MDictionaryEntry entry : statusDicts){
            statusMap.put(entry.getCode(), entry.getValue());
        }
        for(MDictionaryEntry entry : typeDicts){
            statusMap.put(entry.getCode(), entry.getValue());
        }
        userCard.put("statusName",statusMap.get(userCard.get("status")));
        userCard.put("cardTypeName",statusMap.get(userCard.get("cardType")));
        return userCard;
    }
    private List convertCardModels(List<Map<String,Object>> userCards){
        List<MDictionaryEntry> statusDicts = systemDictClient.getDictEntries("", "dictId=43", "", 10, 1).getBody();
        Map<String, String> statusMap = new HashMap<>();
        for(MDictionaryEntry entry : statusDicts){
            statusMap.put(entry.getCode(), entry.getValue());
        }
        for(Map<String,Object> info : userCards){
            info.put("statusName",statusMap.get(info.get("status")));
        }
        return userCards;
    }
    @RequestMapping(value = ServiceApi.Patients.FindArchiveRelation,method = RequestMethod.POST)
    @ApiOperation(value = "档案关联详情")
    public Envelop findArchiveRelation(
            @ApiParam(name = "id", value = "档案关联ID", defaultValue = "")
            @RequestParam(value = "id",required = false) Long id) throws Exception{
        ObjectResult objectResult = patientCardsClient.findArchiveRelation(id);
        if(objectResult.getData() != null){
            Map<String,Object> info = (HashMap)objectResult.getData();
            info = convertCardModel(info);
            return successObj(info);
        }
        return null;
    }
    @RequestMapping(value = ServiceApi.Patients.UpdateArchiveRelation,method = RequestMethod.POST)
    @ApiOperation(value = "档案关联新增/修改")
    public Envelop updateArchiveRelation(
            @ApiParam(name = "data", value = "json数据", defaultValue = "")
            @RequestParam String data){
        ObjectResult objectResult = patientCardsClient.updateArchiveRelation(data);
        if(objectResult.getCode() == 200){
            return successObj(objectResult.getData());
        }else{
            return null;
        }
    }
    @RequestMapping(value =  ServiceApi.Patients.DelArchiveRelation, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除档案关联", notes = "根据档案关联id")
    public Envelop delArchiveRelation(
            @ApiParam(name = "id", value = "档案关联ID", defaultValue = "")
            @RequestParam(value = "id") Long id) {
                Result result = patientCardsClient.delArchiveRelation(id);
                if(result.getCode() == 200){
                    return successMsg(result.getMessage());
                }else{
                    return failed("档案关联删除失败!");
                }
        }
}

File diff suppressed because it is too large
+ 1035 - 0
src/main/java/com/yihu/ehr/patient/controller/PatientController.java


+ 62 - 0
src/main/java/com/yihu/ehr/patient/service/AuthenticationClient.java

@ -0,0 +1,62 @@
package com.yihu.ehr.patient.service;
import com.yihu.ehr.constants.ServiceApi;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.patient.MAuthentication;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * @author lincl
 * @version 1.0
 * @created 2016/6/22
 */
@FeignClient(name=MicroServices.Patient)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface AuthenticationClient {
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.GET)
    @ApiOperation(value = "人口身份认证申请列表")
    ResponseEntity<List<MAuthentication>> search(
            @RequestParam(value = "fields", required = false) String fields,
            @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);
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "新增认证申请")
    MAuthentication add(
            @RequestBody String model) ;
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改认证申请")
    MAuthentication update(
            @RequestBody MAuthentication model);
    @RequestMapping(value = ServiceApi.Patients.Authentication, method = RequestMethod.DELETE)
    @ApiOperation(value = "删除认证申请")
    boolean delete(
            @PathVariable(value = "id") int id);
    @RequestMapping(value = ServiceApi.Patients.Authentications, method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除认证申请")
    boolean batchDelete(
            @RequestParam(value = "ids") Object[] ids);
    @RequestMapping(value = ServiceApi.Patients.Authentication, method = RequestMethod.GET)
    @ApiOperation(value = "获取认证申请信息")
    MAuthentication getInfo(
            @PathVariable(value = "id") int id) ;
}

+ 118 - 0
src/main/java/com/yihu/ehr/patient/service/CardClient.java

@ -0,0 +1,118 @@
package com.yihu.ehr.patient.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.patient.MAbstractCard;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
 * Created by AndyCai on 2016/2/16.
 */
@FeignClient(name=MicroServices.Patient)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface CardClient {
    /**
     * 根据身份证好查询相对应的卡列表
     * @param idCardNo
     * @param number
     * @param cardType
     * @param page
     * @param rows
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/id_card_no",method = RequestMethod.GET)
    @ApiOperation(value = "根据身份证好查询相对应的卡列表")
    ResponseEntity<List<MAbstractCard>> searchCardBinding(
            @ApiParam(name = "id_card_no", value = "身份证号", defaultValue = "")
            @RequestParam(value = "id_card_no") String idCardNo,
            @ApiParam(name = "number", value = "卡号", defaultValue = "")
            @RequestParam(value = "number") String number,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType,
            @ApiParam(name = "page", value = "当前页", defaultValue = "")
            @RequestParam(value = "page") Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows") Integer rows) ;
    /**
     * 查询未绑定的卡列表
     * @param number
     * @param cardType
     * @param page
     * @param rows
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards",method = RequestMethod.GET)
    @ApiOperation(value = "查询未绑定的卡列表")
    ResponseEntity<List<MAbstractCard>> searchCardUnBinding(
            @ApiParam(name = "number", value = "卡号", defaultValue = "")
            @RequestParam(value = "number") String number,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType,
            @ApiParam(name = "page", value = "当前页", defaultValue = "")
            @RequestParam(value = "page") Integer page,
            @ApiParam(name = "rows", value = "行数", defaultValue = "")
            @RequestParam(value = "rows") Integer rows) ;
    /**
     * 根据卡号和卡类型查找卡
     * @param id
     * @param cardType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/card_type/{id}",method = RequestMethod.GET)
    @ApiOperation(value = "根据卡号和卡类型查找卡")
    MAbstractCard getCard(
            @ApiParam(name = "id", value = "卡号", defaultValue = "")
            @PathVariable(value = "id") String id,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType) ;
    /**
     * 根据卡编号和卡类型解绑卡
     * @param id
     * @param cardType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/card_type/{id}",method = RequestMethod.PUT)
    @ApiOperation(value = "根据卡号和卡类型解绑卡")
        boolean detachCard(
            @ApiParam(name = "id", value = "卡号", defaultValue = "")
            @PathVariable(value = "id") String id,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType) ;
    /**
     * 根据卡编号,身份证号,卡类型绑定卡
     * @param id
     * @param idCardNo
     * @param cardType
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/cards/attach/{id}",method = RequestMethod.PUT)
    @ApiOperation(value = "根据卡编号(卡主键,卡的唯一标识),身份证号,卡类型绑定卡")
    boolean attachCard(
            @ApiParam(name = "id", value = "卡号", defaultValue = "")
            @PathVariable(value = "id") String id,
            @ApiParam(name = "id_card_no", value = "身份证号", defaultValue = "")
            @RequestParam(value = "id_card_no") String idCardNo,
            @ApiParam(name = "card_type", value = "卡类别", defaultValue = "")
            @RequestParam(value = "card_type") String cardType);
}

+ 64 - 0
src/main/java/com/yihu/ehr/patient/service/FamiliesClient.java

@ -0,0 +1,64 @@
package com.yihu.ehr.patient.service;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.constants.MicroServices;
import com.yihu.ehr.model.family.MFamilies;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Collection;
/**
 * Created by AndyCai on 2016/4/21.
 */
@FeignClient(name= MicroServices.Family)
@RequestMapping(ApiVersion.Version1_0)
@ApiIgnore
public interface FamiliesClient {
    @RequestMapping(value = "/families", method = RequestMethod.GET)
    @ApiOperation(value = "获取家庭关系列表")
    ResponseEntity<Collection<MFamilies>> searchFamilies(
            @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) ;
    @RequestMapping(value = "/families", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建家庭关系")
    MFamilies createFamily(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) ;
    @RequestMapping(value = "/families", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改家庭关系")
    MFamilies updateFamily(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData);
    @RequestMapping(value = "/families/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "根据id获取家庭关系")
    MFamilies getFamily(
            @ApiParam(name = "id", value = "", defaultValue = "")
            @PathVariable(value = "id") String id) ;
    @RequestMapping(value = "/families/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除家庭关系")
    boolean deleteFamily(
            @ApiParam(name = "id", value = "用户编号", defaultValue = "")
            @PathVariable(value = "id") String id) ;
}

+ 0 - 0
src/main/java/com/yihu/ehr/patient/service/MembersClient.java


Some files were not shown because too many files changed in this diff