Kaynağa Gözat

移动端联调添加人员、查询人员列表。

tomatozq 5 yıl önce
ebeveyn
işleme
6a9e72654a

+ 11 - 6
common/src/main/resources/mapper/base/PersonInfo.xml

@@ -144,8 +144,10 @@
     </update>
     <select id="get" parameterType="long" resultMap="PersonInfoMap">
         select
-        *
-        from base_person_info where id_=#{0} and del_flag = 0
+        a.*,b.name_ as company_name
+        from base_person_info a
+        left join base_company_info b on a.company_id = b.id_
+        where a.id_=#{0} and a.del_flag = 0 limit 1
     </select>
     <select id="exist" parameterType="long" resultType="int">
         select count(*) from base_person_info where id_=#{0}  and del_flag = 0
@@ -164,7 +166,7 @@
                 and a.ID_ like #{searchParams.id}
             </if>
             <if test="searchParams.companyId != null">
-                and a.company_id like #{searchParams.companyId}
+                and a.company_id = #{searchParams.companyId}
             </if>
             <if test="searchParams.name != null">
                 and a.name_ like #{searchParams.name}
@@ -196,11 +198,14 @@
         </foreach>
     </select>
     <select id="findByNameAndPhone" resultMap="PersonInfoMap">
-        select * from  base_person_info
+        select * from base_person_info
         where name_=#{name} and phone_=#{phone} and del_flag=0 limit 1
     </select>
     <select id="findByOpenId" resultMap="PersonInfoMap">
-        select * from  base_person_info
-        where open_id=#{openId} limit 1
+        select
+        a.*,b.name_ as company_name
+        from base_person_info a
+        left join base_company_info b on a.company_id = b.id_
+        where a.open_id=#{openId} and a.del_flag = 0 limit 1
     </select>
 </mapper>

+ 5 - 1
web/src/main/java/com/jpsoft/smart/config/WebMvcConfig.java

@@ -59,6 +59,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
 				.excludePathPatterns("/base/employeeInfo/mobile/**")
 				.excludePathPatterns("/base/companyInfo/list")
 				.excludePathPatterns("/wechat/**")
-				.excludePathPatterns("/mobile/**");
+				.excludePathPatterns("/mobile/personInfoApi/findByNameAndPhone")
+				.excludePathPatterns("/mobile/personInfoApi/getVerifyCode")
+				.excludePathPatterns("/mobile/personInfoApi/validateCode")
+				.excludePathPatterns("/mobile/personInfoApi/findByOpenId");
+
 	}
 }

+ 136 - 44
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonInfoApiController.java

@@ -1,14 +1,21 @@
 package com.jpsoft.smart.modules.mobile.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.Page;
 import com.jpsoft.smart.config.OSSConfig;
 import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
+import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
+import com.jpsoft.smart.modules.common.utils.PojoUtils;
 import com.jpsoft.smart.modules.common.utils.SMSUtil;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
+import com.jpsoft.smart.modules.sys.entity.User;
+import com.jpsoft.smart.modules.sys.service.UserService;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.security.Keys;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
@@ -17,20 +24,22 @@ import org.apache.poi.ss.formula.functions.T;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.security.Key;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
 @RestController
 @RequestMapping("/mobile/personInfoApi")
 public class PersonInfoApiController {
+    @Value("${jwt.secret}")
+    private String jwtSecret;
+
     private Logger logger = LoggerFactory.getLogger(getClass());
 
     @Autowired
@@ -45,8 +54,11 @@ public class PersonInfoApiController {
     @Autowired
     private ValueOperations<String, Object> valueOperations;
 
+    @Autowired
+    private UserService userService;
+
     @PostMapping("findByNameAndPhone")
-    @ApiOperation(value="通过姓名和手机号查询人员")
+    @ApiOperation(value="通过姓名和手机号查询人员(公开接口)")
     @ApiImplicitParams({
             @ApiImplicitParam(name="name",value = "姓名",required = true,paramType = "form"),
             @ApiImplicitParam(name = "phone",value = "电话号码", required = true,paramType="form")
@@ -78,7 +90,7 @@ public class PersonInfoApiController {
     }
 
     @PostMapping("findByOpenId")
-    @ApiOperation(value="通过openId查询人员")
+    @ApiOperation(value="通过openId查询人员(公开接口)")
     @ApiImplicitParams({
             @ApiImplicitParam(name="openId",value = "微信openId",required = true,paramType = "form")
     })
@@ -111,7 +123,7 @@ public class PersonInfoApiController {
     }
 
     @PostMapping("getVerifyCode")
-    @ApiOperation(value="获取短信验证码")
+    @ApiOperation(value="获取短信验证码(公开接口)")
     @ApiImplicitParams({
             @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form")
     })
@@ -152,7 +164,7 @@ public class PersonInfoApiController {
     }
 
     @PostMapping("validateCode")
-    @ApiOperation(value="验证短信验证码")
+    @ApiOperation(value="验证短信验证码(公开接口)")
     @ApiImplicitParams({
             @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
             @ApiImplicitParam(name="verifyCode",value = "验证码",required = true,paramType = "form")
@@ -188,41 +200,35 @@ public class PersonInfoApiController {
     }
 
     private String createToken(Long personId) {
-        String key = "token_" + personId;
-        String token = UUID.randomUUID().toString();
-
         //token有效时间2小时
-        valueOperations.set(key,token,30, TimeUnit.MINUTES);
+        byte[] privateKey = Base64.getDecoder().decode(jwtSecret);
 
-        return token;
+        Date now = new Date();
+        long expiration = now.getTime() + 3600 * 6000; //6个小时后,该客户端的token过期
+
+        Key key = Keys.hmacShaKeyFor(privateKey);
+
+        String token = Jwts.builder()
+                .setSubject(personId + "")
+                .signWith(key)
+                .setExpiration(new Date(expiration))
+                .compact();
+
+        return "Bearer " + token;
     }
 
     @PostMapping("upload")
     @ApiOperation(value="人员照片上传")
     @ApiImplicitParams({
-            @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
-            @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
             @ApiImplicitParam(name="photoName",value = "照片名称",required = true,paramType = "form"),
-            @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file")
+            @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file"),
+            @ApiImplicitParam(name="token",value = "令牌",required = false,paramType = "query")
     })
     public MessageResult<String> upload(
-            Long personId,String token,
-            String photoName, MultipartFile photoFile){
+            String photoName, MultipartFile photoFile,String token){
         MessageResult<String> messageResult = new MessageResult<>();
 
         try {
-            String tokenKey = "token_" + personId;
-
-            String  beforeToken = (String)valueOperations.get(tokenKey);
-
-            if(StringUtils.isEmpty(beforeToken)) {
-                throw new Exception("操作已超时!");
-            }
-
-            if (!beforeToken.equals(token)){
-                throw new Exception("无效请求!");
-            }
-
             String retFileUrl = OSSUtil.upload(ossConfig,"/person",photoName,photoFile.getInputStream());
 
             messageResult.setResult(true);
@@ -239,29 +245,17 @@ public class PersonInfoApiController {
     }
 
     @PostMapping("save")
-    @ApiOperation(value="保存人员信息")
+    @ApiOperation(value="保存人员信息并将照片上传到终端")
     @ApiImplicitParams({
             @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
             @ApiImplicitParam(name="openId",value = "微信openId",required = true,paramType = "form"),
             @ApiImplicitParam(name="faceImageUrl",value = "照片地址",required = true,paramType = "form"),
-            @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form")
+            @ApiImplicitParam(name="token",value = "令牌",required = false,paramType = "query")
     })
     public MessageResult<PersonInfo> save(Long personId,String openId,String faceImageUrl,String token){
         MessageResult<PersonInfo> messageResult = new MessageResult<>();
 
         try {
-            String tokenKey = "token_" + personId;
-
-            String  beforeToken = (String)valueOperations.get(tokenKey);
-
-            if(StringUtils.isEmpty(beforeToken)) {
-                throw new Exception("操作已超时!");
-            }
-
-            if (!beforeToken.equals(token)){
-                throw new Exception("无效请求!");
-            }
-
             PersonInfo personInfo = personInfoService.get(personId);
 
             if (personInfo==null){
@@ -318,5 +312,103 @@ public class PersonInfoApiController {
         return messageResult;
     }
 
+    @ApiOperation(value="人员列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "name",value = "姓名", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "idCard",value = "身份证", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "phone",value = "手机号", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name="token",value = "令牌",paramType = "query",dataType = "form"),
+            @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
+    })
+    public MessageResult<Map> pageList(
+            @RequestParam(value="name",defaultValue="") String name,
+            @RequestParam(value="idCard",defaultValue="") String idCard,
+            @RequestParam(value="phone",defaultValue="") String phone,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            String token,
+            @RequestAttribute String subject){
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        try {
+            User user = userService.get(subject);
+
+            if (user==null){
+                throw new Exception("当前用户不是管理员!");
+            }
+
+            Map<String, Object> searchParams = new HashMap<>();
+
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.create_time", "asc"));
+
+            if (StringUtils.isNotEmpty(name)) {
+                searchParams.put("name", "%" + name + "%");
+            }
+            if (StringUtils.isNotEmpty(idCard)) {
+                searchParams.put("idCard", "%" + idCard + "%");
+            }
+            if (StringUtils.isNotEmpty(phone)) {
+                searchParams.put("phone", "%" + phone + "%");
+            }
+
+            searchParams.put("companyId", user.getCompanyId());
+
+            Page<PersonInfo> page = personInfoService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
+
+            msgResult.setResult(true);
+            msgResult.setData(PojoUtils.pageWrapper(page));
+        }
+        catch (Exception e) {
+            logger.error(e.getMessage(),e);
+            msgResult.setResult(false);
+            msgResult.setMessage(e.getMessage());
+        }
+
+
+
+        return msgResult;
+    }
+
+    @PostMapping("add")
+    @ApiOperation(value="添加人员信息")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="name",value = "姓名",required = true,paramType = "form"),
+            @ApiImplicitParam(name="phone",value = "电话",required = true,paramType = "form"),
+            @ApiImplicitParam(name="token",value = "令牌",paramType = "form"),
+            @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
+    })
+    public MessageResult<PersonInfo> add(String name,String phone,String token,@RequestAttribute String subject){
+        MessageResult<PersonInfo> messageResult = new MessageResult<>();
+
+        try {
+            User user = userService.get(subject);
+
+            if (user==null){
+                throw new Exception("当前用户不是管理员!");
+            }
+
+            PersonInfo personInfo = new PersonInfo();
+            personInfo.setName(name);
+            personInfo.setPhone(phone);
+            personInfo.setFaceEnabled(true);
+            personInfo.setCompanyId(user.getCompanyId());
+            personInfo.setDelFlag(false);
+            personInfo.setCreateBy(user.getId());
+            personInfo.setCreateTime(new Date());
+
+            personInfoService.insert(personInfo);
+
+            messageResult.setData(personInfo);
+            messageResult.setResult(true);
+            messageResult.setCode(200);
+        } catch (Exception e) {
+            logger.error(e.getMessage(),e);
+            messageResult.setResult(false);
+            messageResult.setMessage(e.getMessage());
+        }
 
+        return messageResult;
+    }
 }

+ 3 - 3
web/src/main/resources/application-dev.yml

@@ -5,9 +5,9 @@ server:
 
 spring:
   datasource:
-    url: jdbc:log4jdbc:mysql://192.168.33.20:3306/smart-community?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
-    username: smart
-    password: smart
+    url: jdbc:log4jdbc:mysql://127.0.0.1:3306/smart-community?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    username: root
+    password: root
   devtools:
     add-properties: false
     restart:

+ 1 - 1
web/src/main/resources/application.yml

@@ -61,7 +61,7 @@ spring:
     # Redis数据库索引(默认为0)
     database: 1
     # Redis服务器地址
-    host: 192.168.33.21
+    host: 127.0.0.1
     #host: 127.0.0.1
     # Redis服务器连接端口
     port: 6379