Преглед изворни кода

Merge remote-tracking branch 'origin/V1' into V1

yanliming пре 5 година
родитељ
комит
3bf1603545

+ 122 - 132
common/src/main/java/com/jpsoft/smart/modules/base/entity/PersonInfo.java

@@ -4,6 +4,7 @@ import java.io.Serializable;
 import java.util.Date;
 import java.text.SimpleDateFormat;
 import java.math.BigDecimal;
+
 import org.springframework.format.annotation.DateTimeFormat;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
@@ -11,143 +12,132 @@ import io.swagger.annotations.ApiModel;
 import lombok.Data;
 
 /**
-  描述:base_person_info的实体类
+ * 描述:base_person_info的实体类
  */
 @Data
 @ApiModel(value = "base_person_info的实体类")
 public class PersonInfo {
-	/**
-	 *编号
-	 */
-	@ApiModelProperty(value = "编号")
-	private Long id;
-	/**
-	 *企业编号
-	 */
-        @ApiModelProperty(value = "企业编号")
-	private String companyId;
-	/**
-	 *企业名称
-	 */
-	@ApiModelProperty(value = "企业名称")
-	private String companyName;
-	/**
-	 *姓名
-	 */
-        @ApiModelProperty(value = "姓名")
-	private String name;
-	/**
-	 *手机号
-	 */
-	@ApiModelProperty(value = "手机号")
-	private String phone;
-	/**
-	 *身份证号
-	 */
-	@ApiModelProperty(value = "身份证号")
-	private String idCard;
-	/**
-	 *微信openId
-	 */
-	@ApiModelProperty(value = "微信openId")
-	private String openId;
-	/**
-	 *人脸
-	 */
-        @ApiModelProperty(value = "人脸")
-	private Boolean faceEnabled;
-	/**
-	 *刷卡
-	 */
-        @ApiModelProperty(value = "刷卡")
-	private Boolean cardEnabled;
-	/**
-	 *手机
-	 */
-        @ApiModelProperty(value = "手机")
-	private Boolean appEnabled;
-	/**
-	 *密码
-	 */
-        @ApiModelProperty(value = "密码")
-	private Boolean passwordEnabled;
-	/**
-	 *访客
-	 */
-        @ApiModelProperty(value = "访客")
-	private Boolean guestEnabled;
-	/**
-	 *位置1
-	 */
-        @ApiModelProperty(value = "位置1")
-	private String position1;
-	/**
-	 *位置2
-	 */
-        @ApiModelProperty(value = "位置2")
-	private String position2;
-	/**
-	 *位置3
-	 */
-        @ApiModelProperty(value = "位置3")
-	private String position3;
-	/**
-	 *位置4
-	 */
-        @ApiModelProperty(value = "位置4")
-	private String position4;
-	/**
-	 *位置5
-	 */
-        @ApiModelProperty(value = "位置5")
-	private String position5;
-	/**
-	 *是否删除
-	 */
-        @ApiModelProperty(value = "是否删除")
-	private Boolean delFlag;
-	/**
-	 *创建人
-	 */
-        @ApiModelProperty(value = "创建人")
-	private String createBy;
-	/**
-	 *创建时间
-	 */
-    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
-	    @ApiModelProperty(value = "创建时间")
-	private Date createTime;
-	/**
-	 *更新人
-	 */
-        @ApiModelProperty(value = "更新人")
-	private String updateBy;
-	/**
-	 *更新时间
-	 */
-    	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
-	    @ApiModelProperty(value = "更新时间")
-	private Date updateTime;
-	/**
-	 *设置企业名称
-	 */
-	public String getCompanyName() {
-		return companyName;
-	}
+    /**
+     * 编号
+     */
+    @ApiModelProperty(value = "编号")
+    private Long id;
+    /**
+     * 企业编号
+     */
+    @ApiModelProperty(value = "企业编号")
+    private String companyId;
+    /**
+     * 企业名称
+     */
+    @ApiModelProperty(value = "企业名称")
+    private String companyName;
+    /**
+     * 姓名
+     */
+    @ApiModelProperty(value = "姓名")
+    private String name;
+    /**
+     * 手机号
+     */
+    @ApiModelProperty(value = "手机号")
+    private String phone;
+    /**
+     * 身份证号
+     */
+    @ApiModelProperty(value = "身份证号")
+    private String idCard;
+    /**
+     * 微信openId
+     */
+    @ApiModelProperty(value = "微信openId")
+    private String openId;
+    /**
+     * 人脸
+     */
+    @ApiModelProperty(value = "人脸")
+    private Boolean faceEnabled;
+
+    @ApiModelProperty(value = "是否已将人脸信息传给终端")
+    private Boolean faceBound;
+
+    /**
+     * 刷卡
+     */
+    @ApiModelProperty(value = "刷卡")
+    private Boolean cardEnabled;
+    /**
+     * 手机
+     */
+    @ApiModelProperty(value = "手机")
+    private Boolean appEnabled;
+    /**
+     * 密码
+     */
+    @ApiModelProperty(value = "密码")
+    private Boolean passwordEnabled;
+    /**
+     * 访客
+     */
+    @ApiModelProperty(value = "访客")
+    private Boolean guestEnabled;
+    /**
+     * 位置1
+     */
+    @ApiModelProperty(value = "位置1")
+    private String position1;
+    /**
+     * 位置2
+     */
+    @ApiModelProperty(value = "位置2")
+    private String position2;
+    /**
+     * 位置3
+     */
+    @ApiModelProperty(value = "位置3")
+    private String position3;
+    /**
+     * 位置4
+     */
+    @ApiModelProperty(value = "位置4")
+    private String position4;
+    /**
+     * 位置5
+     */
+    @ApiModelProperty(value = "位置5")
+    private String position5;
+    /**
+     * 是否删除
+     */
+    @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+    /**
+     * 创建人
+     */
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+    /**
+     * 创建时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
 
-	public void setCompanyName(String companyName) {
-		this.companyName = companyName;
-	}
+    /**
+     * 更新人
+     */
+    @ApiModelProperty(value = "更新人")
+    private String updateBy;
+    /**
+     * 更新时间
+     */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
 
-	@ApiModelProperty(value = "人脸相片地址")
-	private String faceImageUrl;
-	public String getFaceImageUrl() {
-		return faceImageUrl;
-	}
+    @ApiModelProperty(value = "人脸相片地址")
+    private String faceImageUrl;
 
-	public void setFaceImageUrl(String faceImageUrl) {
-		this.faceImageUrl = faceImageUrl;
-	}
 }

+ 1 - 1
common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java

@@ -14,5 +14,5 @@ public interface DeviceInfoService {
 	int delete(String id);
 	List<DeviceInfo> list();
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
-	int updateByDeviceNo(String deviceNo,String ip);
+	void updateByDeviceNo(String deviceNo, String ip);
 }

+ 10 - 3
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java

@@ -2,8 +2,9 @@ package com.jpsoft.smart.modules.base.service.impl;
 
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
 import javax.annotation.Resource;
+
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 import com.jpsoft.smart.modules.base.dao.DeviceInfoDAO;
@@ -13,6 +14,7 @@ import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.github.pagehelper.PageHelper;
 
+@Slf4j
 @Transactional
 @Component(value="deviceInfoService")
 public class DeviceInfoServiceImpl implements DeviceInfoService {
@@ -69,9 +71,14 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 	}
 
 	@Override
-	public int updateByDeviceNo(String deviceNo, String ip) {
+	public void updateByDeviceNo(String deviceNo, String ip) {
 		DeviceInfo deviceInfo= deviceInfoDAO.findByDeviceNo(deviceNo);
+		String oldIp = deviceInfo.getIpAddress();
+		if (deviceInfo.getIsAutoUpdate() && !deviceInfo.getIpAddress().equals(ip)){
+			deviceInfo.setIpAddress(ip);
+			deviceInfoDAO.update(deviceInfo);
+			log.warn(deviceNo+"的ip由原来的:"+oldIp+"自动更新为:"+ip);
+		}
 
-		return 0;
 	}
 }

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/common/utils/LApiUtil.java

@@ -83,6 +83,7 @@ public class LApiUtil {
         if (dataJson.getInteger("StatusCode") == 14){
             throw new Exception("重复订阅");
         }
+
         return dataJson.getJSONObject("Data");
     }
 

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -43,4 +43,6 @@ public interface ILapiService {
      * @return
      */
      String getFaceDbId(DeviceInfo deviceInfo, String companyName) throws Exception;
+
+     
 }

+ 5 - 2
common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java

@@ -135,19 +135,22 @@ public class LapiServiceImpl implements ILapiService {
                 String faceDbId = getFaceDbId(deviceInfo,companyInfo.getName());
                 JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress()+":"+deviceInfo.getPort()+LApiConstant.ADDPERSON+faceDbId+"/People",map);
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
+                JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") ==0 && dataJson.getInteger("StatusCode") == 0){
                     LapiMsgResult lapiMsgResult = new LapiMsgResult();
                     lapiMsgResult.setPersonName(personInfo.getName());
-                    lapiMsgResult.setMsg(true);
+                    lapiMsgResult.setSuccess(true);
                     lapiMsgResult.setAliasName(deviceInfo.getAliasName());
                     lapiMsgResults.add(lapiMsgResult);
                 }
+
             }catch (Exception e){
 
                 log.error(e.getMessage());
                 LapiMsgResult lapiMsgResult = new LapiMsgResult();
                 lapiMsgResult.setPersonName(personInfo.getName());
-                lapiMsgResult.setMsg(false);
+                lapiMsgResult.setSuccess(false);
+                lapiMsgResult.setMsg(e.getMessage());
                 lapiMsgResult.setAliasName(deviceInfo.getAliasName());
                 lapiMsgResults.add(lapiMsgResult);
 

+ 3 - 1
common/src/main/java/com/jpsoft/smart/modules/lapi/vo/LapiMsgResult.java

@@ -13,5 +13,7 @@ public class LapiMsgResult {
 
     private String aliasName;
 
-    private boolean msg;
+    private String msg;
+
+    private boolean success;
 }

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

@@ -12,6 +12,7 @@
         <result property="idCard" column="id_card"/>
         <result property="openId" column="open_id"/>
         <result property="faceEnabled" column="face_enabled"/>
+        <result property="faceBound" column="face_bound"/>
         <result property="cardEnabled" column="card_enabled"/>
         <result property="appEnabled" column="app_enabled"/>
         <result property="passwordEnabled" column="password_enabled"/>
@@ -36,7 +37,7 @@
         -->
         <![CDATA[
 		insert into base_person_info
-	    (company_id,name_,phone_,id_card,open_id,face_enabled,card_enabled,
+	    (company_id,name_,phone_,id_card,open_id,face_enabled,face_bound,card_enabled,
 	    app_enabled,password_enabled,guest_enabled,position1_,position2_,
 	    position3_,position4_,position5_,face_image_url,del_flag,create_by,create_time,update_by,update_time)
 		values
@@ -47,6 +48,7 @@
             ,#{idCard,jdbcType=VARCHAR}
             ,#{openId,jdbcType= VARCHAR }
             ,#{faceEnabled,jdbcType= NUMERIC }
+            ,#{faceBound,jdbcType= NUMERIC }
             ,#{cardEnabled,jdbcType= NUMERIC }
             ,#{appEnabled,jdbcType= NUMERIC }
             ,#{passwordEnabled,jdbcType= NUMERIC }
@@ -89,6 +91,9 @@
             <if test="faceEnabled!=null">
                 face_enabled=#{faceEnabled,jdbcType= NUMERIC },
             </if>
+            <if test="faceBound!=null">
+                face_bound=#{faceBound,jdbcType= NUMERIC },
+            </if>
             <if test="cardEnabled!=null">
                 card_enabled=#{cardEnabled,jdbcType= NUMERIC },
             </if>
@@ -139,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
@@ -159,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}
@@ -191,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>

+ 1 - 1
lapi/src/main/java/com/jpsoft/smart/lapi/handler/HeartReportHandler.java

@@ -33,7 +33,7 @@ public class HeartReportHandler extends SimpleChannelInboundHandler<HeartReportI
         log.warn(deviceNo);
         log.warn("ip =="+ip);
 
-     //   deviceInfoService.updateByDeviceNo(deviceNo,ip);
+        deviceInfoService.updateByDeviceNo(deviceNo,ip);
 
 
 

+ 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");
+
 	}
 }

+ 57 - 3
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -661,7 +661,27 @@ public class PersonInfoController {
 
     @ApiOperation(value="导出人员")
     @PostMapping("exportXls")
-    public MessageResult<String> exportXls(@RequestBody List<String> ids){
+    @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 = "companyId",value = "企业id", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "position1",value = "一级位置", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "position2",value = "二级位置", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "position3",value = "三级位置", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "position4",value = "四级位置", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "position5",value = "五级位置", required = false, paramType = "form",dataType = "String")
+    })
+    public MessageResult<String> exportXls(@RequestParam(value="name",defaultValue="") String name,
+                                           @RequestParam(value="idCard",defaultValue="") String idCard,
+                                           @RequestParam(value="phone",defaultValue="") String phone,
+                                           @RequestParam(value="companyId",defaultValue="") String companyId,
+                                           @RequestParam(value="position1",defaultValue="") String position1,
+                                           @RequestParam(value="position2",defaultValue="") String position2,
+                                           @RequestParam(value="position3",defaultValue="") String position3,
+                                           @RequestParam(value="position4",defaultValue="") String position4,
+                                           @RequestParam(value="position5",defaultValue="") String position5,
+                                           @RequestAttribute String subject){
         MessageResult<String> msgResult = new MessageResult<>();
 
         try {
@@ -695,9 +715,43 @@ public class PersonInfoController {
             cellTitle12.setCellValue("手机开关");
             HSSFCell cellTitle13 = rowTitle.createCell(12);
             cellTitle13.setCellValue("访客开关");
+
             //表内容
-            for(int i=0; i<ids.size(); i++){
-                PersonInfo personInfo = personInfoService.get(Long.getLong(ids.get(i)));
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.id_","asc"));
+            Map<String,Object> searchParams = new HashMap<>();
+            if (StringUtils.isNotEmpty(name)) {
+                searchParams.put("name","%" + name + "%");
+            }
+            if (StringUtils.isNotEmpty(idCard)) {
+                searchParams.put("idCard","%" + idCard + "%");
+            }
+            if (StringUtils.isNotEmpty(phone)) {
+                searchParams.put("phone","%" + phone + "%");
+            }
+            if (StringUtils.isNotEmpty(companyId)) {
+                searchParams.put("companyId",companyId);
+            }
+            if (StringUtils.isNotEmpty(position1)) {
+                searchParams.put("position1",position1);
+            }
+            if (StringUtils.isNotEmpty(position2)) {
+                searchParams.put("position2",position2);
+            }
+            if (StringUtils.isNotEmpty(position3)) {
+                searchParams.put("position3",position3);
+            }
+            if (StringUtils.isNotEmpty(position4)) {
+                searchParams.put("position4",position4);
+            }
+            if (StringUtils.isNotEmpty(position5)) {
+                searchParams.put("position5",position5);
+            }
+
+            Page<PersonInfo> page = personInfoService.pageSearch(searchParams,1,10000,false,sortList);
+
+            for(int i=0; i<page.size(); i++){
+                PersonInfo personInfo = page.get(i);
 
                 HSSFRow rowContent = sheet.createRow(0);
                 HSSFCell cellContent1 = rowContent.createCell(0);

+ 215 - 64
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonInfoApiController.java

@@ -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());
         }

+ 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