zhengqiang 5 anni fa
parent
commit
a0db1b8265

+ 15 - 0
common/src/main/java/com/jpsoft/smart/modules/common/utils/PojoUtils.java

@@ -66,4 +66,19 @@ public class PojoUtils {
 
         return pageMap;
     }
+
+    public static <T> Page<T> convertPage(Page page, Class<T> destinationClass){
+        Page newPage = new Page();
+
+        newPage.setPageNum(page.getPageNum());
+        newPage.setPageSize(page.getPageSize());
+        newPage.setPages(page.getPages());
+        newPage.setTotal(page.getTotal());
+
+        for (Object obj: page) {
+            newPage.add(map(obj,destinationClass));
+        }
+
+        return newPage;
+    }
 }

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

@@ -192,7 +192,7 @@
     </select>
     <select id="findByNameAndPhone" resultMap="PersonInfoMap">
         select * from  base_person_info
-        where name_=#{name} and phone_=#{phone} limit 1
+        where name_=#{name} and phone_=#{phone} and del_flag=0 limit 1
     </select>
     <select id="findByOpenId" resultMap="PersonInfoMap">
         select * from  base_person_info

+ 63 - 4
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonInfoApiController.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.formula.functions.T;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 @RestController
@@ -126,7 +128,7 @@ public class PersonInfoApiController {
 
                 messageResult = SMSUtil.send(personInfo.getPhone(), "SMS_49390047", verifyCodeJSON.toString());
 
-                //设置当前用户的验证码,60秒后过期
+                //设置当前用户的验证码,1分钟内有效
                 valueOperations.set(key, verifyCode, 60000, TimeUnit.SECONDS);
             }
 
@@ -166,17 +168,70 @@ public class PersonInfoApiController {
         return messageResult;
     }
 
+    @PostMapping("validateCode")
+    @ApiOperation(value="验证短信验证码")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="personId",value = "人员编号",required = true,paramType = "form"),
+            @ApiImplicitParam(name="verifyCode",value = "验证码",required = true,paramType = "form")
+    })
+    public MessageResult<String> validateCode(Long personId,String verifyCode){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            String smsKey = "SMS_" + personId;
+
+            String  beforeVerifyCode = (String)valueOperations.get(smsKey);
+
+            if(StringUtils.isEmpty(beforeVerifyCode)) {
+                throw new Exception("验证码已过期!");
+            }
+
+            if (!beforeVerifyCode.equals(verifyCode)){
+                throw new Exception("验证码错误!");
+            }
+
+            String tokenKey = "token_" + personId;
+            String tokenValue = UUID.randomUUID().toString();
+
+            //token有效时间30分钟
+            valueOperations.set(tokenKey,tokenValue,30, TimeUnit.MINUTES);
+
+            messageResult.setData(tokenValue);
+            messageResult.setResult(true);
+            messageResult.setCode(200);
+        }
+        catch (Exception ex){
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
     @PostMapping("save")
     @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="faceImageUrl",value = "照片地址",required = true,paramType = "form"),
+            @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form")
     })
-    public MessageResult<String> save(Long personId,String openId,String faceImageUrl){
-        MessageResult<String> messageResult = new MessageResult<>();
+    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){
@@ -190,6 +245,10 @@ public class PersonInfoApiController {
 
             personInfoService.update(personInfo);
 
+            //todo 同步终端
+
+
+            messageResult.setData(personInfo);
             messageResult.setResult(true);
             messageResult.setCode(200);
         } catch (Exception e) {