Commit e2822531b384da2952784a98991d144fa97938e0

Authored by 陈杰
1 parent 6f262f5b
Exists in master

用户中心

Showing 21 changed files with 856 additions and 8 deletions   Show diff stats
cloud/common/src/main/java/com/sincere/common/exception/ResultException.java 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +package com.sincere.common.exception;
  2 +
  3 +public class ResultException extends Exception {
  4 +
  5 + private int code ;
  6 + private String message ;
  7 +
  8 + public int getCode() {
  9 + return code;
  10 + }
  11 +
  12 + public void setCode(int code) {
  13 + this.code = code;
  14 + }
  15 +
  16 + @Override
  17 + public String getMessage() {
  18 + return message;
  19 + }
  20 +
  21 + public void setMessage(String message) {
  22 + this.message = message;
  23 + }
  24 +
  25 + public ResultException(int code, String message) {
  26 + this.code = code;
  27 + this.message = message;
  28 + }
  29 +}
cloud/common/src/main/java/com/sincere/common/util/TokenUtils.java 0 → 100644
@@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
  1 +package com.sincere.common.util;
  2 +
  3 +import com.nimbusds.jose.*;
  4 +import com.nimbusds.jose.crypto.MACSigner;
  5 +import com.nimbusds.jose.crypto.MACVerifier;
  6 +import com.nimbusds.jwt.JWTClaimsSet;
  7 +import com.nimbusds.jwt.SignedJWT;
  8 +import com.sincere.common.exception.ResultException;
  9 +
  10 +import java.util.Date;
  11 +import java.util.Objects;
  12 +
  13 +public class TokenUtils {
  14 +
  15 + /**
  16 + * 创建秘钥
  17 + */
  18 + private static final byte[] SECRET = "6MNSobBRCHGIO0fS6MNSobBRCHGWO0fS".getBytes();
  19 +
  20 + /**
  21 + * 过期时间5秒
  22 + */
  23 + private static final long EXPIRE_TIME = 1000 * 60 * 60 * 24;
  24 +
  25 +
  26 + /**
  27 + * 生成Token
  28 + * @param account
  29 + * @return
  30 + */
  31 + public static String buildToken(String account) {
  32 + try {
  33 + /**
  34 + * 1.创建一个32-byte的密匙
  35 + */
  36 + MACSigner macSigner = new MACSigner(SECRET);
  37 + /**
  38 + * 2. 建立payload 载体
  39 + */
  40 + JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
  41 + .expirationTime(new Date(System.currentTimeMillis() + EXPIRE_TIME))
  42 + .claim("ACCOUNT",account)
  43 + .build();
  44 +
  45 + /**
  46 + * 3. 建立签名
  47 + */
  48 + SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet);
  49 + signedJWT.sign(macSigner);
  50 +
  51 + /**
  52 + * 4. 生成token
  53 + */
  54 + String token = signedJWT.serialize();
  55 + return token;
  56 + } catch (KeyLengthException e) {
  57 + e.printStackTrace();
  58 + } catch (JOSEException e) {
  59 + e.printStackTrace();
  60 + }
  61 + return null;
  62 + }
  63 +
  64 + /**
  65 + * 校验token
  66 + * @param token
  67 + * @return
  68 + */
  69 + public static String validToken(String token) throws ResultException {
  70 + try {
  71 + SignedJWT jwt = SignedJWT.parse(token);
  72 + JWSVerifier verifier = new MACVerifier(SECRET);
  73 + //校验是否有效
  74 + if (!jwt.verify(verifier)) {
  75 + throw new ResultException(-1, "Token 无效");
  76 + }
  77 +
  78 + //校验超时
  79 + Date expirationTime = jwt.getJWTClaimsSet().getExpirationTime();
  80 + if (new Date().after(expirationTime)) {
  81 + throw new ResultException(-2, "Token 已过期");
  82 + }
  83 +
  84 + //获取载体中的数据
  85 + Object account = jwt.getJWTClaimsSet().getClaim("ACCOUNT");
  86 + //是否有openUid
  87 + if (Objects.isNull(account)){
  88 + throw new ResultException(-3, "账号为空");
  89 + }
  90 + return account.toString();
  91 + } catch (Exception e) {
  92 + throw new ResultException(-4, "系统繁忙");
  93 + }
  94 + }
  95 +}
cloud/search_smartCampus/src/main/resources/mapper/SyncMapper.xml
@@ -68,35 +68,35 @@ @@ -68,35 +68,35 @@
68 <result column="yxyUserId" property="yxyUserId" /> 68 <result column="yxyUserId" property="yxyUserId" />
69 </resultMap> 69 </resultMap>
70 <select id="selectUser" parameterType="java.lang.Integer" resultMap="UserDtp"> 70 <select id="selectUser" parameterType="java.lang.Integer" resultMap="UserDtp">
71 - select HS_StudentUpdateCard.ID , HS_StudentUpdateCard.UserType , HS_StudentUpdateCard.Name , HS_StudentUpdateCard.ClassId , HS_StudentUpdateCard.CustomerId , HS_StudentUpdateCard.Sex , HS_StudentUpdateCard.mobile , HS_StudentUpdateCard.UpdateType , YXY_UserRelation.yxyUserId from HS_StudentUpdateCard  
72 - left join YXY_UserRelation on HS_StudentUpdateCard.CustomerId = YXY_UserRelation.hxyCustomerId 71 + select HS_StudentUpdateCard.ID , HS_StudentUpdateCard.UserType , HS_StudentUpdateCard.Name , HS_StudentUpdateCard.ClassId , HS_StudentUpdateCard.CustomerId , HS_StudentUpdateCard.Sex , HS_StudentUpdateCard.mobile , HS_StudentUpdateCard.UpdateType , YXT_UserRelation.yxyUserId from HS_StudentUpdateCard
  72 + left join YXT_UserRelation on HS_StudentUpdateCard.CustomerId = YXT_UserRelation.hxyCustomerId
73 where SchoolId =#{schoolId} and Yxy_IsNew = 0 73 where SchoolId =#{schoolId} and Yxy_IsNew = 0
74 </select> 74 </select>
75 75
76 <insert id="insertDeptRelation" parameterType="com.sincere.common.dto.smartCampus.DeptRelationDto"> 76 <insert id="insertDeptRelation" parameterType="com.sincere.common.dto.smartCampus.DeptRelationDto">
77 - insert into YXY_DeptRelation (hxyDeptId,yxyDeptId,usertype,updateTime,createTime,state) 77 + insert into YXT_DeptRelation (hxyDeptId,yxyDeptId,usertype,updateTime,createTime,state)
78 values (#{hxyDeptId},#{yxyDeptId},#{userType},GETDATE(),GETDATE(),#{state}) 78 values (#{hxyDeptId},#{yxyDeptId},#{userType},GETDATE(),GETDATE(),#{state})
79 </insert> 79 </insert>
80 80
81 <update id="updateDeptRelation" parameterType="com.sincere.common.dto.smartCampus.DeptRelationDto"> 81 <update id="updateDeptRelation" parameterType="com.sincere.common.dto.smartCampus.DeptRelationDto">
82 - update YXY_DeptRelation set updateTime = GETDATE() , state = #{state} where hxyDeptId = #{hxyDeptId} 82 + update YXT_DeptRelation set updateTime = GETDATE() , state = #{state} where hxyDeptId = #{hxyDeptId}
83 </update> 83 </update>
84 84
85 <select id="selectYxyIdByHxyId" parameterType="java.lang.Integer" resultType="java.lang.String"> 85 <select id="selectYxyIdByHxyId" parameterType="java.lang.Integer" resultType="java.lang.String">
86 - select yxyDeptId from YXY_DeptRelation where hxyDeptId = #{hxyDeptId} 86 + select yxyDeptId from YXT_DeptRelation where hxyDeptId = #{hxyDeptId}
87 </select> 87 </select>
88 88
89 89
90 <insert id="insertUserRelation" parameterType="com.sincere.common.dto.smartCampus.UserRelationDto"> 90 <insert id="insertUserRelation" parameterType="com.sincere.common.dto.smartCampus.UserRelationDto">
91 - insert into YXY_UserRelation (hxyCustomerId,yxyUserId,userType,updateTime,createTime,state) 91 + insert into YXT_UserRelation (hxyCustomerId,yxyUserId,userType,updateTime,createTime,state)
92 values (#{hxyCustomerId},#{yxyUserId},#{userType},GETDATE(),GETDATE(),#{state}) 92 values (#{hxyCustomerId},#{yxyUserId},#{userType},GETDATE(),GETDATE(),#{state})
93 </insert> 93 </insert>
94 94
95 <update id="updateUserRelation" parameterType="com.sincere.common.dto.smartCampus.DeptRelationDto"> 95 <update id="updateUserRelation" parameterType="com.sincere.common.dto.smartCampus.DeptRelationDto">
96 - update YXY_UserRelation set updateTime = GETDATE() , state = #{state} where hxyCustomerId = #{hxyCustomerId} 96 + update YXT_UserRelation set updateTime = GETDATE() , state = #{state} where hxyCustomerId = #{hxyCustomerId}
97 </update> 97 </update>
98 98
99 <select id="selectUserYxyIdByHxyId" parameterType="java.lang.String" resultType="java.lang.String"> 99 <select id="selectUserYxyIdByHxyId" parameterType="java.lang.String" resultType="java.lang.String">
100 - select yxyUserId from YXY_UserRelation where hxyCustomerId = #{hxyCustomerId} 100 + select yxyUserId from YXT_UserRelation where hxyCustomerId = #{hxyCustomerId}
101 </select> 101 </select>
102 </mapper> 102 </mapper>
103 \ No newline at end of file 103 \ No newline at end of file
cloud/user_search/pom.xml 0 → 100644
@@ -0,0 +1,158 @@ @@ -0,0 +1,158 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5 + <parent>
  6 + <artifactId>cloud</artifactId>
  7 + <groupId>com.sincere</groupId>
  8 + <version>1.0.0</version>
  9 + </parent>
  10 + <modelVersion>4.0.0</modelVersion>
  11 +
  12 + <artifactId>user_search</artifactId>
  13 +
  14 + <dependencies>
  15 + <dependency>
  16 + <groupId>com.sincere</groupId>
  17 + <artifactId>common</artifactId>
  18 + <version>1.0.0</version>
  19 + </dependency>
  20 + <dependency>
  21 + <groupId>org.springframework.boot</groupId>
  22 + <artifactId>spring-boot-starter-test</artifactId>
  23 + <scope>test</scope>
  24 + </dependency>
  25 + <dependency>
  26 + <groupId>org.springframework.cloud</groupId>
  27 + <artifactId>spring-cloud-starter-feign</artifactId>
  28 + <version>1.3.6.RELEASE</version>
  29 + </dependency>
  30 + <dependency>
  31 + <groupId>org.springframework.cloud</groupId>
  32 + <artifactId>spring-cloud-openfeign-core</artifactId>
  33 + <version>2.1.2.RELEASE</version>
  34 + </dependency>
  35 + <dependency>
  36 + <groupId>org.apache.commons</groupId>
  37 + <artifactId>commons-lang3</artifactId>
  38 + <version>3.3.2</version>
  39 + </dependency>
  40 + <dependency>
  41 + <groupId>org.mybatis.spring.boot</groupId>
  42 + <artifactId>mybatis-spring-boot-starter</artifactId>
  43 + <version>1.3.0</version>
  44 + </dependency>
  45 + <dependency>
  46 + <groupId>com.microsoft.sqlserver</groupId>
  47 + <artifactId>mssql-jdbc</artifactId>
  48 + <version>6.4.0.jre8</version>
  49 + </dependency>
  50 + <dependency>
  51 + <groupId>io.springfox</groupId>
  52 + <artifactId>springfox-swagger2</artifactId>
  53 + <version>2.5.0</version>
  54 + </dependency>
  55 + <dependency>
  56 + <groupId>io.springfox</groupId>
  57 + <artifactId>springfox-swagger-ui</artifactId>
  58 + <version>2.5.0</version>
  59 + </dependency>
  60 + </dependencies>
  61 +
  62 + <dependencyManagement>
  63 + <dependencies>
  64 + <dependency>
  65 + <groupId>org.springframework.cloud</groupId>
  66 + <artifactId>spring-cloud-dependencies</artifactId>
  67 + <version>${spring-cloud.version}</version>
  68 + <type>pom</type>
  69 + <scope>import</scope>
  70 + </dependency>
  71 + </dependencies>
  72 + </dependencyManagement>
  73 +
  74 + <build>
  75 + <!--打包文件名-->
  76 + <finalName>quartz_server</finalName>
  77 + <!--打包方式-->
  78 + <plugins>
  79 + <!-- 设置编译版本 -->
  80 + <plugin>
  81 + <groupId>org.apache.maven.plugins</groupId>
  82 + <artifactId>maven-compiler-plugin</artifactId>
  83 + <version>3.1</version>
  84 + <configuration>
  85 + <source>1.8</source>
  86 + <target>1.8</target>
  87 + <encoding>UTF-8</encoding>
  88 + </configuration>
  89 + </plugin>
  90 + <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
  91 + <!-- 本地启动需要注释-->
  92 + <plugin>
  93 + <groupId>org.apache.maven.plugins</groupId>
  94 + <artifactId>maven-jar-plugin</artifactId>
  95 + <configuration>
  96 + <archive>
  97 + <manifest>
  98 + <mainClass>com.sincere.quartz.QuartzApplication</mainClass>
  99 + <addClasspath>true</addClasspath>
  100 + <classpathPrefix>lib/</classpathPrefix>
  101 + </manifest>
  102 + <manifestEntries>
  103 + <Class-Path>./config/</Class-Path>
  104 + </manifestEntries>
  105 + </archive>
  106 + <excludes>
  107 + <exclude>config/**</exclude>
  108 + </excludes>
  109 + <classesDirectory></classesDirectory>
  110 + </configuration>
  111 + </plugin>
  112 + <!-- 拷贝依赖的jar包到lib目录 -->
  113 + <plugin>
  114 + <groupId>org.apache.maven.plugins</groupId>
  115 + <artifactId>maven-dependency-plugin</artifactId>
  116 + <executions>
  117 + <execution>
  118 + <id>copy</id>
  119 + <phase>package</phase>
  120 + <goals>
  121 + <goal>copy-dependencies</goal>
  122 + </goals>
  123 + <configuration>
  124 + <outputDirectory>
  125 + ${project.build.directory}/lib
  126 + </outputDirectory>
  127 + </configuration>
  128 + </execution>
  129 + </executions>
  130 + </plugin>
  131 + <!-- 解决资源文件的编码问题 -->
  132 + <plugin>
  133 + <groupId>org.apache.maven.plugins</groupId>
  134 + <artifactId>maven-resources-plugin</artifactId>
  135 + <version>2.5</version>
  136 + <configuration>
  137 + <encoding>UTF-8</encoding>
  138 + </configuration>
  139 + </plugin>
  140 + <!-- 打包source文件为jar文件 -->
  141 + <plugin>
  142 + <artifactId>maven-source-plugin</artifactId>
  143 + <version>2.2</version>
  144 + <configuration>
  145 + <attach>true</attach>
  146 + </configuration>
  147 + <executions>
  148 + <execution>
  149 + <phase>compile</phase>
  150 + <goals>
  151 + <goal>jar</goal>
  152 + </goals>
  153 + </execution>
  154 + </executions>
  155 + </plugin>
  156 + </plugins>
  157 + </build>
  158 +</project>
0 \ No newline at end of file 159 \ No newline at end of file
cloud/user_search/src/main/java/com/sincere/userSearch/Swagger2.java 0 → 100644
@@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
  1 +package com.sincere.userSearch;
  2 +
  3 +import io.swagger.annotations.ApiOperation;
  4 +import org.springframework.context.annotation.Bean;
  5 +import org.springframework.context.annotation.Configuration;
  6 +import springfox.documentation.builders.ApiInfoBuilder;
  7 +import springfox.documentation.builders.ParameterBuilder;
  8 +import springfox.documentation.builders.PathSelectors;
  9 +import springfox.documentation.builders.RequestHandlerSelectors;
  10 +import springfox.documentation.schema.ModelRef;
  11 +import springfox.documentation.service.ApiInfo;
  12 +import springfox.documentation.service.Parameter;
  13 +import springfox.documentation.spi.DocumentationType;
  14 +import springfox.documentation.spring.web.plugins.Docket;
  15 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.List;
  19 +
  20 +@EnableSwagger2
  21 +@Configuration //让Spring来加载该类配置
  22 +public class Swagger2 {
  23 +
  24 + @Bean
  25 + public Docket createRestApi() {
  26 + ParameterBuilder ticketPar = new ParameterBuilder();
  27 + List<Parameter> pars = new ArrayList<Parameter>();
  28 + ticketPar.name("X-Authorization").description("user token")
  29 + .modelRef(new ModelRef("string")).parameterType("header")
  30 + .required(false).build(); //header中的ticket参数非必填,传空也可以
  31 + pars.add(ticketPar.build());
  32 +
  33 +
  34 + return new Docket(DocumentationType.SWAGGER_2)
  35 + .apiInfo(apiInfo())
  36 + .enableUrlTemplating(true)
  37 + .select()
  38 + // 扫描所有有注解的api,用这种方式更灵活
  39 + .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
  40 + .paths(PathSelectors.any())
  41 + .build().globalOperationParameters(pars);
  42 +
  43 + }
  44 + private ApiInfo apiInfo() {
  45 + return new ApiInfoBuilder()
  46 + .title("Spring Boot中使用Swagger2构建RESTful APIs")
  47 + .description("接口文档")
  48 + .termsOfServiceUrl("")
  49 + .version("1.0")
  50 + .build();
  51 + }
  52 +}
cloud/user_search/src/main/java/com/sincere/userSearch/UserApplication.java 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +package com.sincere.userSearch;
  2 +
  3 +import org.mybatis.spring.annotation.MapperScan;
  4 +import org.springframework.boot.SpringApplication;
  5 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  6 +import org.springframework.boot.web.servlet.ServletComponentScan;
  7 +import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  8 +
  9 +@ServletComponentScan
  10 +@EnableEurekaClient
  11 +@SpringBootApplication
  12 +@MapperScan("com.sincere.userSearch.mapper")
  13 +public class UserApplication {
  14 +
  15 + public static void main(String[] args) {
  16 + SpringApplication.run(UserApplication.class, args);
  17 + }
  18 +}
cloud/user_search/src/main/java/com/sincere/userSearch/access/MemberFilter.java 0 → 100644
@@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
  1 +package com.sincere.userSearch.access;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.sincere.common.exception.ResultException;
  5 +import com.sincere.common.util.TokenUtils;
  6 +import com.sincere.userSearch.vo.UserInfo;
  7 +import org.apache.commons.lang3.StringUtils;
  8 +
  9 +import javax.servlet.*;
  10 +import javax.servlet.annotation.WebFilter;
  11 +import javax.servlet.http.HttpServletRequest;
  12 +import java.io.IOException;
  13 +import java.util.HashMap;
  14 +import java.util.Map;
  15 +
  16 +@WebFilter(urlPatterns = "/user/*")
  17 +public class MemberFilter implements Filter {
  18 +
  19 + private static String token_string = "X-Authorization" ;
  20 +
  21 + @Override
  22 + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  23 +
  24 + HttpServletRequest req = (HttpServletRequest) request;
  25 +
  26 + String token = req.getHeader(token_string);
  27 + if (StringUtils.isBlank(token)) {
  28 + respFail(response,-5,"token 没有");
  29 + return;
  30 + }
  31 +
  32 +// MemberDetails memberDetails = memberService.getMemberDetailsByToken(tokenId);
  33 +// if (memberDetails == null) this.respFail(response);
  34 + String userId = "" ;
  35 + try{
  36 + userId = TokenUtils.validToken(token);
  37 + }catch (ResultException e){
  38 + respFail(response,e.getCode(),e.getMessage());
  39 + return;
  40 + }
  41 + ParameterRequestWrapper requestWrapper = new ParameterRequestWrapper(req);
  42 + UserInfo userInfo = new UserInfo() ;
  43 + userInfo.setUserId(userId);
  44 + requestWrapper.addObject(userInfo);
  45 + chain.doFilter(requestWrapper, response);
  46 + }
  47 +
  48 + private void respFail(ServletResponse response , int code , String message) throws IOException {
  49 + Map<String, Object> map = new HashMap<>();
  50 + map.put("status", code);
  51 + map.put("message", message);
  52 + map.put("data", null);
  53 + ObjectMapper objectMapper = new ObjectMapper();
  54 + String s = objectMapper.writeValueAsString(map);
  55 + response.setCharacterEncoding("UTF-8");
  56 + response.setContentType("application/json; charset=utf-8");
  57 + response.getWriter().write(s);
  58 + }
  59 +
  60 +}
cloud/user_search/src/main/java/com/sincere/userSearch/access/ParameterRequestWrapper.java 0 → 100644
@@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
  1 +package com.sincere.userSearch.access;
  2 +
  3 +import org.apache.commons.lang.WordUtils;
  4 +
  5 +import javax.servlet.http.HttpServletRequest;
  6 +import javax.servlet.http.HttpServletRequestWrapper;
  7 +import java.lang.reflect.InvocationTargetException;
  8 +import java.lang.reflect.Method;
  9 +import java.util.*;
  10 +
  11 +/**
  12 + * 重写HttpServletRequestWrapper ,为把token 转化为userinfo 带入到request中
  13 + */
  14 +public class ParameterRequestWrapper extends HttpServletRequestWrapper {
  15 +
  16 + private Map<String , String[]> params = new HashMap<String, String[]>();
  17 +
  18 +
  19 + @SuppressWarnings("unchecked")
  20 + public ParameterRequestWrapper(HttpServletRequest request) {
  21 + // 将request交给父类,以便于调用对应方法的时候,将其输出,其实父亲类的实现方式和第一种new的方式类似
  22 + super(request);
  23 + //将参数表,赋予给当前的Map以便于持有request中的参数
  24 + this.params.putAll(request.getParameterMap());
  25 + }
  26 + //重载一个构造方法
  27 + public ParameterRequestWrapper(HttpServletRequest request , Map<String , Object> extendParams) {
  28 + this(request);
  29 + addAllParameters(extendParams);//这里将扩展参数写入参数表
  30 + }
  31 +
  32 + /**
  33 + * 复写获取key的方法
  34 + */
  35 + @Override
  36 + public Enumeration getParameterNames() {
  37 + Vector names = new Vector(params.keySet());
  38 + return names.elements();
  39 + }
  40 +
  41 + /**
  42 + * 复写获取值value的方法
  43 + */
  44 + @Override
  45 + public String getParameter(String name) {
  46 + Object v = params.get(name);
  47 + if (v == null) {
  48 + return null;
  49 + } else if (v instanceof String[]) {
  50 + String[] strArr = (String[]) v;
  51 + if (strArr.length > 0) {
  52 + return strArr[0];
  53 + } else {
  54 + return null;
  55 + }
  56 + } else if (v instanceof String) {
  57 + return (String) v;
  58 + } else {
  59 + return v.toString();
  60 + }
  61 + }
  62 +
  63 + @Override
  64 + public String[] getParameterValues(String name) {
  65 + Object v = params.get(name);
  66 + if (v == null) {
  67 + return null;
  68 + } else if (v instanceof String[]) {
  69 + return (String[]) v;
  70 + } else if (v instanceof String) {
  71 + return new String[] { (String) v };
  72 + } else {
  73 + return new String[] { v.toString() };
  74 + }
  75 + }
  76 +
  77 + public void addAllParameters(Map<String , Object>otherParams) {//增加多个参数
  78 + for(Map.Entry<String , Object>entry : otherParams.entrySet()) {
  79 + addParameter(entry.getKey() , entry.getValue());
  80 + }
  81 + }
  82 +
  83 +
  84 + public void addParameter(String name , Object value) {//增加参数
  85 + if(value != null) {
  86 + if(value instanceof String[]) {
  87 + params.put(name , (String[])value);
  88 + }else if(value instanceof String) {
  89 + params.put(name , new String[] {(String)value});
  90 + }else {
  91 + params.put(name , new String[] {String.valueOf(value)});
  92 + }
  93 + }
  94 + }
  95 +
  96 + /** 简单封装,请根据需求改进 */
  97 + public void addObject(Object obj) {
  98 + Class<?> clazz = obj.getClass();
  99 + Method[] methods = clazz.getMethods();
  100 + try {
  101 + for (Method method : methods) {
  102 + if (!method.getName().startsWith("get")) {
  103 + continue;
  104 + }
  105 + Object invoke = method.invoke(obj);
  106 + if (invoke == null || "".equals(invoke)) {
  107 + continue;
  108 + }
  109 +
  110 + String filedName = method.getName().replace("get", "");
  111 + filedName = WordUtils.uncapitalize(filedName);
  112 +
  113 + if (invoke instanceof Collection) {
  114 + Collection collections = (Collection) invoke;
  115 + if (collections != null && collections.size() > 0) {
  116 + String[] strings = (String[]) collections.toArray();
  117 + addParameter(filedName, strings);
  118 + return;
  119 + }
  120 + }
  121 +
  122 + addParameter(filedName, invoke);
  123 + }
  124 + } catch (IllegalAccessException e) {
  125 + e.printStackTrace();
  126 + } catch (InvocationTargetException e) {
  127 + e.printStackTrace();
  128 + }
  129 + }
  130 +}
cloud/user_search/src/main/java/com/sincere/userSearch/controller/UserController.java 0 → 100644
@@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
  1 +package com.sincere.userSearch.controller;
  2 +
  3 +import com.sincere.userSearch.service.UserService;
  4 +import com.sincere.userSearch.vo.BaseVo;
  5 +import com.sincere.userSearch.vo.UserInfo;
  6 +import com.sincere.userSearch.vo.rep.ZnxwRepVo;
  7 +import com.sincere.userSearch.vo.req.ZnxwReqVo;
  8 +import io.swagger.annotations.Api;
  9 +import io.swagger.annotations.ApiOperation;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.web.bind.annotation.*;
  12 +
  13 +@RestController
  14 +@RequestMapping("/user")
  15 +@Api(value = "用户中心")
  16 +public class UserController {
  17 +
  18 + @Autowired
  19 + UserService userService ;
  20 +
  21 + /**
  22 + * 获取钉钉angenId的接口 EM_QYHApply
  23 + */
  24 + @ApiOperation("获取智能校卫agentid")
  25 + @RequestMapping(value = "getZNXWWebApp" , method = RequestMethod.POST)
  26 + public BaseVo<ZnxwRepVo> getZNXWWebApp(@RequestBody ZnxwReqVo znxwReqVo , UserInfo userInfo){
  27 + BaseVo<ZnxwRepVo> result = new BaseVo<>() ;
  28 + ZnxwRepVo data = userService.selectAgentId(znxwReqVo) ;
  29 + result.setData(data);
  30 + return result ;
  31 + }
  32 +
  33 +
  34 + public void getUserRole(){
  35 +
  36 + }
  37 +
  38 + /**
  39 + * 用户类型 0-班主任; 1-任课老师; 2-学生; 3-家长; 10-学校管理员;
  40 + * @param userId
  41 + */
  42 + @ApiOperation("根据userId 获取用户信息")
  43 + @RequestMapping(value = "getUserInfo" , method = RequestMethod.POST)
  44 + public void getUserInfo(UserInfo userId){
  45 +
  46 + }
  47 +
  48 + public void getUserId(){
  49 +
  50 + }
  51 +}
cloud/user_search/src/main/java/com/sincere/userSearch/mapper/QyhApplyMapper.java 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +package com.sincere.userSearch.mapper;
  2 +
  3 +import com.sincere.userSearch.vo.rep.ZnxwRepVo;
  4 +import com.sincere.userSearch.vo.req.ZnxwReqVo;
  5 +
  6 +public interface QyhApplyMapper {
  7 +
  8 + ZnxwRepVo selectAgentId(ZnxwReqVo znxwReqVo);
  9 +}
cloud/user_search/src/main/java/com/sincere/userSearch/mapper/UserMapper.java 0 → 100644
@@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
  1 +package com.sincere.userSearch.mapper;
  2 +
  3 +public interface UserMapper {
  4 +}
cloud/user_search/src/main/java/com/sincere/userSearch/service/UserService.java 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +package com.sincere.userSearch.service;
  2 +
  3 +import com.sincere.userSearch.vo.rep.ZnxwRepVo;
  4 +import com.sincere.userSearch.vo.req.ZnxwReqVo;
  5 +
  6 +public interface UserService {
  7 +
  8 + ZnxwRepVo selectAgentId(ZnxwReqVo znxwReqVo);
  9 +
  10 +}
cloud/user_search/src/main/java/com/sincere/userSearch/service/impl/UserServiceImpl.java 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +package com.sincere.userSearch.service.impl;
  2 +
  3 +import com.sincere.userSearch.mapper.QyhApplyMapper;
  4 +import com.sincere.userSearch.service.UserService;
  5 +import com.sincere.userSearch.vo.rep.ZnxwRepVo;
  6 +import com.sincere.userSearch.vo.req.ZnxwReqVo;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Service;
  9 +
  10 +@Service
  11 +public class UserServiceImpl implements UserService {
  12 +
  13 + @Autowired
  14 + QyhApplyMapper qyhApplyMapper ;
  15 +
  16 + @Override
  17 + public ZnxwRepVo selectAgentId(ZnxwReqVo znxwReqVo) {
  18 + return qyhApplyMapper.selectAgentId(znxwReqVo);
  19 + }
  20 +}
cloud/user_search/src/main/java/com/sincere/userSearch/vo/BaseVo.java 0 → 100644
@@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
  1 +package com.sincere.userSearch.vo;
  2 +
  3 +public class BaseVo<T> {
  4 +
  5 + private String message ;
  6 + private boolean status ;
  7 + private T data ;
  8 +
  9 + public String getMessage() {
  10 + return message;
  11 + }
  12 +
  13 + public void setMessage(String message) {
  14 + this.message = message;
  15 + }
  16 +
  17 + public boolean isStatus() {
  18 + return status;
  19 + }
  20 +
  21 + public void setStatus(boolean status) {
  22 + this.status = status;
  23 + }
  24 +
  25 + public T getData() {
  26 + return data;
  27 + }
  28 +
  29 + public void setData(T data) {
  30 + this.data = data;
  31 + }
  32 +
  33 + public BaseVo() {
  34 + this.status = true ;
  35 + }
  36 +}
cloud/user_search/src/main/java/com/sincere/userSearch/vo/UserInfo.java 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +package com.sincere.userSearch.vo;
  2 +
  3 +public class UserInfo {
  4 +
  5 + private String userId ;
  6 +
  7 + public String getUserId() {
  8 + return userId;
  9 + }
  10 +
  11 + public void setUserId(String userId) {
  12 + this.userId = userId;
  13 + }
  14 +}
cloud/user_search/src/main/java/com/sincere/userSearch/vo/rep/ZnxwRepVo.java 0 → 100644
@@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
  1 +package com.sincere.userSearch.vo.rep;
  2 +
  3 +public class ZnxwRepVo {
  4 +
  5 + private String agentId ;
  6 + private String schoolName ;
  7 +
  8 + public String getAgentId() {
  9 + return agentId;
  10 + }
  11 +
  12 + public void setAgentId(String agentId) {
  13 + this.agentId = agentId;
  14 + }
  15 +
  16 + public String getSchoolName() {
  17 + return schoolName;
  18 + }
  19 +
  20 + public void setSchoolName(String schoolName) {
  21 + this.schoolName = schoolName;
  22 + }
  23 +}
cloud/user_search/src/main/java/com/sincere/userSearch/vo/req/ZnxwReqVo.java 0 → 100644
@@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
  1 +package com.sincere.userSearch.vo.req;
  2 +
  3 +public class ZnxwReqVo {
  4 +
  5 + private int schoolId ;
  6 + private int type ;
  7 +
  8 + public int getSchoolId() {
  9 + return schoolId;
  10 + }
  11 +
  12 + public void setSchoolId(int schoolId) {
  13 + this.schoolId = schoolId;
  14 + }
  15 +
  16 + public int getType() {
  17 + return type;
  18 + }
  19 +
  20 + public void setType(int type) {
  21 + this.type = type;
  22 + }
  23 +}
cloud/user_search/src/main/resources/application.yaml 0 → 100644
@@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
  1 +server:
  2 + port: 9004
  3 +
  4 +spring:
  5 + application:
  6 + name: user_search
  7 + datasource:
  8 + username: szjxtuser
  9 + password: RQminVCJota3H1u8bBYH
  10 + url: jdbc:sqlserver://116.62.155.137:33419;database=SmartCampus
  11 + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
  12 +##mybatis
  13 +mybatis:
  14 + mapper-locations: classpath:mapper/*.xml
  15 + type-aliases-package: com.sincere.quartz.mapper
  16 + check-config-location: true
  17 +ribbon:
  18 + ReadTimeout: 50000
  19 + ConnectTimeout: 5000
  20 +eureka:
  21 + instance:
  22 + hostname: localhost
  23 + lease-expiration-duration-in-seconds: 60
  24 + lease-renewal-interval-in-seconds: 10
  25 + client:
  26 + service-url:
  27 + defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
  28 +
cloud/user_search/src/main/resources/logback.xml 0 → 100644
@@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<configuration debug="true">
  3 +     <!-- 项目名称 -->
  4 +     <property name="PROJECT_NAME" value="user_search" />
  5 +
  6 +     <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
  7 + <property name="LOG_HOME" value="C://log"/>
  8 +
  9 +     <!-- 控制台输出 -->
  10 +     <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
  11 +         <!--<withJansi>true</withJansi>-->
  12 +         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  13 +             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
  14 +             <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] %highlight([%-5level] %logger{50} - %msg%n)</pattern>
  15 +             <charset>UTF-8</charset>
  16 +         </encoder>
  17 +     </appender>
  18 +
  19 +     <!-- 按照每天生成日志文件 -->
  20 +     <appender name="SYSTEM_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  21 +         <!-- 过滤器,只打印ERROR级别的日志 -->
  22 +         <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
  23 +             <!--日志文件输出的文件名-->
  24 +             <FileNamePattern>${LOG_HOME}/${PROJECT_NAME}/%d{yyyy-MM-dd}.%i.log</FileNamePattern>
  25 +             <!--日志文件保留天数-->
  26 +             <MaxHistory>30</MaxHistory>
  27 +             <!--日志文件最大的大小-->
  28 +             <MaxFileSize>100MB</MaxFileSize>
  29 +         </rollingPolicy>
  30 +
  31 +         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
  32 +             <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
  33 +             <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%thread] [%-5level] %logger{50} - %msg%n</pattern>
  34 +             <charset>UTF-8</charset>
  35 +         </encoder>
  36 +     </appender>
  37 +     <logger name="system_error" additivity="true">
  38 +        <appender-ref ref="SYSTEM_FILE"/>
  39 +    </logger>
  40 +
  41 +    <!-- 设置Spring&Hibernate日志输出级别 -->
  42 +    <logger name="org.springframework" level="WARN" />
  43 +    <logger name="org.mybatis" level="WARN" />
  44 +    <logger name="com.ibatis" level="DEBUG" />
  45 +    <logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" />
  46 +    <logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" />
  47 +    <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" />
  48 +
  49 +
  50 +    <logger name="java.sql.Connection" level="DEBUG" />
  51 +    <logger name="java.sql.Statement" level="DEBUG" />
  52 +    <logger name="java.sql.PreparedStatement" level="DEBUG" />
  53 +    <logger name="com.sincere.smartSearch.mapper" level="DEBUG" />
  54 +    <!-- 开发环境下的日志配置 -->
  55 +    <root level="INFO">
  56 +        <appender-ref ref="CONSOLE" />
  57 +        <appender-ref ref="SYSTEM_FILE" />
  58 +    </root>
  59 +
  60 +</configuration>
cloud/user_search/src/main/resources/mapper/QyhApplyMapper.xml 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.sincere.userSearch.mapper.QyhApplyMapper">
  4 +
  5 + <resultMap id="ZnxwMap" type="com.sincere.userSearch.vo.rep.ZnxwRepVo">
  6 + <result column="AgentId" property="agentId" />
  7 + <result column="school_name" property="schoolName" />
  8 + </resultMap>
  9 + <select id="selectAgentId" parameterType="com.sincere.userSearch.vo.req.ZnxwReqVo" resultMap="ZnxwMap">
  10 + SELECT EM_QYHApply.AgentId , SZ_School.school_name FROM EM_QYHApply join SZ_School on EM_QYHApply.SchoolId = SZ_School.school_id
  11 + where EM_QYHApply.SchoolId = #{schoolId} and EM_QYHApply.Type = #{type} and EM_QYHApply.ApplyName = '智能校卫'
  12 + </select>
  13 +
  14 +</mapper>
cloud/user_search/src/main/resources/mapper/UserMapper.xml 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.sincere.userSearch.mapper.UserMapper">
  4 +
  5 + <resultMap id="ZnxwMap" type="com.sincere.userSearch.vo.rep.ZnxwRepVo">
  6 + <result column="AgentId" property="agentId" />
  7 + <result column="school_name" property="schoolName" />
  8 + </resultMap>
  9 + <select id="selectAgentId" parameterType="com.sincere.userSearch.vo.req.ZnxwReqVo" resultMap="ZnxwMap">
  10 + SELECT EM_QYHApply.AgentId , SZ_School.school_name FROM EM_QYHApply join SZ_School on EM_QYHApply.SchoolId = SZ_School.school_id
  11 + where EM_QYHApply.SchoolId = #{schoolId} and EM_QYHApply.Type = #{type} and EM_QYHApply.ApplyName = '智能校卫'
  12 + </select>
  13 +
  14 +</mapper>