|
@@ -1,12 +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;
|
|
@@ -15,23 +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.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
+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
|
|
@@ -40,11 +48,17 @@ public class PersonInfoApiController {
|
|
|
@Autowired
|
|
|
private PersonInfoService personInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILapiService lapiService;
|
|
|
+
|
|
|
@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")
|
|
@@ -56,7 +70,7 @@ public class PersonInfoApiController {
|
|
|
PersonInfo personInfo = personInfoService.findByNameAndPhone(name, phone);
|
|
|
|
|
|
if (personInfo==null){
|
|
|
- throw new Exception("当前用户信息未登记,请先联系单位管理员!");
|
|
|
+ throw new Exception("您的信息暂未登记,请先联系管理人员!");
|
|
|
}
|
|
|
|
|
|
if (personInfo.getFaceEnabled()==null || !personInfo.getFaceEnabled()){
|
|
@@ -76,12 +90,12 @@ public class PersonInfoApiController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("findByOpenId")
|
|
|
- @ApiOperation(value="通过openId查询人员")
|
|
|
+ @ApiOperation(value="通过openId查询人员(公开接口)")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name="openId",value = "微信openId",required = true,paramType = "form")
|
|
|
})
|
|
|
- public MessageResult<PersonInfo> findByOpenId(String openId){
|
|
|
- MessageResult<PersonInfo> messageResult = new MessageResult<>();
|
|
|
+ public MessageResult<Map> findByOpenId(String openId){
|
|
|
+ MessageResult<Map> messageResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
PersonInfo personInfo = personInfoService.findByOpenId(openId);
|
|
@@ -90,7 +104,13 @@ public class PersonInfoApiController {
|
|
|
throw new Exception("当前用户不存在!");
|
|
|
}
|
|
|
|
|
|
- messageResult.setData(personInfo);
|
|
|
+ Map<String,Object> dataMap = new HashMap<String, Object>();
|
|
|
+ String token = createToken(personInfo.getId());
|
|
|
+
|
|
|
+ dataMap.put("person",personInfo);
|
|
|
+ dataMap.put("token", token);
|
|
|
+
|
|
|
+ messageResult.setData(dataMap);
|
|
|
messageResult.setResult(true);
|
|
|
messageResult.setCode(200);
|
|
|
}
|
|
@@ -103,7 +123,7 @@ public class PersonInfoApiController {
|
|
|
}
|
|
|
|
|
|
@PostMapping("getVerifyCode")
|
|
|
- @ApiOperation(value="获取短信验证码")
|
|
|
+ @ApiOperation(value="获取短信验证码(公开接口)")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form")
|
|
|
})
|
|
@@ -128,8 +148,8 @@ public class PersonInfoApiController {
|
|
|
|
|
|
messageResult = SMSUtil.send(personInfo.getPhone(), "SMS_49390047", verifyCodeJSON.toString());
|
|
|
|
|
|
- //设置当前用户的验证码,1分钟内有效
|
|
|
- valueOperations.set(key, verifyCode, 60000, TimeUnit.SECONDS);
|
|
|
+ //设置当前用户的验证码,5分钟内有效
|
|
|
+ valueOperations.set(key, verifyCode, 5, TimeUnit.MINUTES);
|
|
|
}
|
|
|
|
|
|
messageResult.setResult(true);
|
|
@@ -143,33 +163,8 @@ public class PersonInfoApiController {
|
|
|
return messageResult;
|
|
|
}
|
|
|
|
|
|
- @PostMapping("upload")
|
|
|
- @ApiOperation(value="人员照片上传")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name="photoName",value = "照片名称",required = true,paramType = "form"),
|
|
|
- @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file")
|
|
|
- })
|
|
|
- public MessageResult<String> upload(String photoName, MultipartFile photoFile){
|
|
|
- MessageResult<String> messageResult = new MessageResult<>();
|
|
|
-
|
|
|
- try {
|
|
|
- String retFileUrl = OSSUtil.upload(ossConfig,"/person",photoName,photoFile.getInputStream());
|
|
|
-
|
|
|
- messageResult.setResult(true);
|
|
|
- messageResult.setData(retFileUrl);
|
|
|
- messageResult.setCode(200);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error(e.getMessage(),e);
|
|
|
-
|
|
|
- messageResult.setResult(false);
|
|
|
- messageResult.setMessage(e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- return messageResult;
|
|
|
- }
|
|
|
-
|
|
|
@PostMapping("validateCode")
|
|
|
- @ApiOperation(value="验证短信验证码")
|
|
|
+ @ApiOperation(value="验证短信验证码(公开接口)")
|
|
|
@ApiImplicitParams({
|
|
|
@ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
|
|
|
@ApiImplicitParam(name="verifyCode",value = "验证码",required = true,paramType = "form")
|
|
@@ -190,13 +185,9 @@ public class PersonInfoApiController {
|
|
|
throw new Exception("验证码错误!");
|
|
|
}
|
|
|
|
|
|
- String tokenKey = "token_" + personId;
|
|
|
- String tokenValue = UUID.randomUUID().toString();
|
|
|
-
|
|
|
- //token有效时间30分钟
|
|
|
- valueOperations.set(tokenKey,tokenValue,30, TimeUnit.MINUTES);
|
|
|
+ String token = createToken(personId);
|
|
|
|
|
|
- messageResult.setData(tokenValue);
|
|
|
+ messageResult.setData(token);
|
|
|
messageResult.setResult(true);
|
|
|
messageResult.setCode(200);
|
|
|
}
|
|
@@ -208,52 +199,212 @@ public class PersonInfoApiController {
|
|
|
return messageResult;
|
|
|
}
|
|
|
|
|
|
+ private String createToken(Long personId) {
|
|
|
+ //token有效时间2小时
|
|
|
+ byte[] privateKey = Base64.getDecoder().decode(jwtSecret);
|
|
|
+
|
|
|
+ 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="photoName",value = "照片名称",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file"),
|
|
|
+ @ApiImplicitParam(name="token",value = "令牌",required = false,paramType = "query")
|
|
|
+ })
|
|
|
+ public MessageResult<String> upload(
|
|
|
+ String photoName, MultipartFile photoFile,String token){
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String retFileUrl = OSSUtil.upload(ossConfig,"/person",photoName,photoFile.getInputStream());
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setData(retFileUrl);
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
@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);
|
|
|
+ PersonInfo personInfo = personInfoService.get(personId);
|
|
|
|
|
|
- if(StringUtils.isEmpty(beforeToken)) {
|
|
|
- throw new Exception("操作已超时!");
|
|
|
+ if (personInfo==null){
|
|
|
+ throw new Exception("人员信息不存在!");
|
|
|
}
|
|
|
|
|
|
- if (!beforeToken.equals(token)){
|
|
|
- throw new Exception("无效请求!");
|
|
|
- }
|
|
|
+ //todo 同步终端
|
|
|
+ List<LapiMsgResult> msgResultList = lapiService.addPerson(personId);
|
|
|
|
|
|
- PersonInfo personInfo = personInfoService.get(personId);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
- if (personInfo==null){
|
|
|
- throw new Exception("人员信息不存在!");
|
|
|
+ boolean success = true;
|
|
|
+
|
|
|
+ for(int i=0;i<msgResultList.size();i++) {
|
|
|
+ LapiMsgResult lapiMsgResult = msgResultList.get(i);
|
|
|
+
|
|
|
+ if (lapiMsgResult.isSuccess()){
|
|
|
+ sb.append(lapiMsgResult.getAliasName() + "绑定人脸信息成功!");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sb.append(lapiMsgResult.getAliasName() + "绑定人脸信息失败!" + lapiMsgResult.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i!=msgResultList.size()-1){
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sb.append("。");
|
|
|
+ }
|
|
|
+
|
|
|
+ success &= lapiMsgResult.isSuccess();
|
|
|
}
|
|
|
|
|
|
personInfo.setOpenId(openId);
|
|
|
personInfo.setFaceImageUrl(faceImageUrl);
|
|
|
+ personInfo.setFaceBound(success);
|
|
|
|
|
|
personInfo.setUpdateTime(new Date());
|
|
|
|
|
|
personInfoService.update(personInfo);
|
|
|
|
|
|
- //todo 同步终端
|
|
|
+ messageResult.setData(personInfo);
|
|
|
+ messageResult.setResult(success);
|
|
|
+ messageResult.setMessage(sb.toString());
|
|
|
|
|
|
+ messageResult.setCode(200);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error(e.getMessage(),e);
|
|
|
+
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
}
|