|
@@ -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;
|
|
|
+ }
|
|
|
}
|