Przeglądaj źródła

设备同步 图片同步 删除设备图片等功能

xiao547607 5 lat temu
rodzic
commit
926a315f4b

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonInfoDAO.java

@@ -41,4 +41,6 @@ public interface PersonInfoDAO {
     PersonInfo findByIdCardAndCompanyId(String idCard,String companyId);
 
 	List<PersonInfo> notGuestList();
+
+	int resetOpenId(Long personId);
 }

+ 9 - 0
common/src/main/java/com/jpsoft/smart/modules/base/entity/PersonInfo.java

@@ -167,4 +167,13 @@ public class PersonInfo {
 
     @ApiModelProperty(value="单位性质")
     private String companyType;
+
+    @ApiModelProperty(value="健康照路径")
+    private String healthErtificateUrl;
+
+    @ApiModelProperty(value="是否同步")
+    private Boolean isSync;
+
+    @ApiModelProperty(value = "性别")
+    private String sex;
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonInfoService.java

@@ -40,4 +40,6 @@ public interface PersonInfoService {
     PersonInfo addPersonForCompany(PersonInfo personInfo, String deviceNo);
 
 	List<PersonInfo> notGuestList();
+
+	int resetOpenId(Long personId);
 }

+ 5 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonInfoServiceImpl.java

@@ -179,4 +179,9 @@ public class PersonInfoServiceImpl implements PersonInfoService {
 	public List<PersonInfo> notGuestList() {
 		return personInfoDAO.notGuestList();
 	}
+
+	@Override
+	public int resetOpenId(Long personId) {
+		return personInfoDAO.resetOpenId(personId);
+	}
 }

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

@@ -31,6 +31,9 @@
         <result property="popedom" column="popedom_"/>
         <result property="wechatNoticeEnabled" column="wechat_notice_enabled"/>
         <result property="allowViewLocal" column="allow_view_local"/>
+        <result property="healthErtificateUrl" column="health_ertificate_url"/>
+        <result property="isSync" column="is_sync"/>
+        <result property="sex" column="sex_"/>
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.smart.modules.base.entity.PersonInfo">
         <selectKey resultType="long" keyColumn="id_" keyProperty="id">
@@ -41,7 +44,7 @@
 	    (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,popedom_,wechat_notice_enabled,allow_view_local)
+	    create_by,create_time,update_by,update_time,popedom_,wechat_notice_enabled,allow_view_local,health_ertificate_url,is_sync,sex_)
 		values
 		(
             #{companyId,jdbcType=VARCHAR}
@@ -69,6 +72,9 @@
             ,#{popedom,jdbcType= VARCHAR }
             ,#{wechatNoticeEnabled,jdbcType= NUMERIC }
             ,#{allowViewLocal,jdbcType= NUMERIC }
+            ,#{healthErtificateUrl,jdbcType=VARCHAR}
+            ,#{isSync,jdbcType= NUMERIC }
+            ,#{sex,jdbcType=VARCHAR}
 		)
 	]]>
     </insert>
@@ -153,6 +159,15 @@
             <if test="allowViewLocal!=null">
                 allow_view_local=#{allowViewLocal,jdbcType= VARCHAR },
             </if>
+            <if test="healthErtificateUrl!=null">
+                health_ertificate_url=#{healthErtificateUrl,jdbcType=VARCHAR},
+            </if>
+            <if test="isSync!=null">
+                is_sync=#{isSync,jdbcType=NUMERIC},
+            </if>
+            <if test="sex!=null">
+                sex_=#{sex,jdbcType=VARCHAR},
+            </if>
         </set>
         where id_=#{id}
     </update>
@@ -373,14 +388,14 @@
             and id_card = #{idCard}
             and company_id = #{companyId}
                 ]]>
-
-
-</select>
+    </select>
     <select id="notGuestList" resultMap="PersonInfoMap">
         <![CDATA[
         select * from base_person_info where del_flag = 0
                 and guest_enabled is not true
         ]]>
-
-</select>
+    </select>
+    <update id="resetOpenId" parameterType="long">
+        update base_person_info set open_id=null where id_=#{0} limit 1
+    </update>
 </mapper>

+ 47 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -3,14 +3,17 @@ package com.jpsoft.smart.modules.base.controller;
 import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation;
 import com.jpsoft.smart.modules.base.service.CompanyDeviceRelationService;
+import com.jpsoft.smart.modules.common.utils.HttpUtil;
 import com.jpsoft.smart.modules.common.utils.PojoUtils;
 import com.jpsoft.smart.modules.common.dto.Sort;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
+import com.jpsoft.smart.modules.sys.entity.SysLog;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
+import com.jpsoft.smart.modules.sys.service.SysLogService;
 import com.jpsoft.smart.modules.sys.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -24,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.util.*;
 
@@ -48,6 +52,9 @@ public class DeviceInfoController {
     @Autowired
     private CompanyDeviceRelationService companyDeviceRelationService;
 
+    @Autowired
+    private SysLogService sysLogService;
+
 
 
     @ApiOperation(value="添加设备")
@@ -569,4 +576,44 @@ public class DeviceInfoController {
         return msgResult;
     }
 
+    @ResponseBody
+    @ApiOperation(value="远程重启")
+    @PostMapping("reboot")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "deviceId",value = "设备编号", required = true,paramType = "query")
+    })
+    public MessageResult<String> reboot(String deviceId, @RequestAttribute String subject, HttpServletRequest request){
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        SysLog sysLog = new SysLog();
+        sysLog.setPointcut("远程重启设备");
+        sysLog.setUserId(subject);
+        sysLog.setData(deviceId);
+        sysLog.setCreateTime(new Date());
+        sysLog.setRemoteIp(HttpUtil.getIpAddress(request));
+
+        try {
+            boolean result = lapiService.reBoot(deviceId);
+
+            msgResult.setResult(result);
+
+            if (msgResult.isResult()){
+                msgResult.setMessage("远程重启成功!");
+            }
+            else{
+                msgResult.setMessage("远程重启失败!");
+            }
+
+            sysLog.setRemark(msgResult.getMessage());
+        }
+        catch (Exception ex){
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        sysLogService.insert(sysLog);
+
+        return msgResult;
+    }
+
 }

+ 184 - 73
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -34,6 +34,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
@@ -75,9 +76,6 @@ public class PersonDeviceRelationController {
 
     @Autowired
     private CompanyInfoService companyInfoService;
-
-
-
     
     @ApiOperation(value="添加设备和人员绑定")
     @Transactional(rollbackFor = Exception.class)
@@ -87,6 +85,10 @@ public class PersonDeviceRelationController {
 
         try {
             int affectCount = 0;
+            Boolean isWrite = true;
+            if(personDeviceRelation.getIsWrite() != null){
+                isWrite = personDeviceRelation.getIsWrite();
+            }
 
             PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(personDeviceRelation.getDeviceId(), personDeviceRelation.getPersonId());
 
@@ -102,26 +104,28 @@ public class PersonDeviceRelationController {
 
 
             if (affectCount > 0) {
-                //往设备库传输人脸信息
-                PersonInfo personInfo = personInfoService.get(personDeviceRelation.getPersonId());
-                //如果人员照片不为空
-                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())){
-                    DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
-                    if(!deviceInfo.getIsOnline()){
-                        throw new Exception("无法绑定,设备不在线!" );
-                    }
-                    List<LapiResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
-                    for (int i = 0; i < lapiResults.size(); i++) {
-                        LapiResult lapiMsgResult = lapiResults.get(i);
-                        if (lapiMsgResult.isSuccess()) {
-                            msgResult.setResult(true);
-                        }else{
-                            throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                if(isWrite) {
+                    //往设备库传输人脸信息
+                    PersonInfo personInfo = personInfoService.get(personDeviceRelation.getPersonId());
+                    //如果人员照片不为空
+                    if (StringUtils.isNotEmpty(personInfo.getFaceImageUrl())) {
+                        DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
+                        if (!deviceInfo.getIsOnline()) {
+                            throw new Exception("无法绑定,设备不在线!");
                         }
+                        List<LapiResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(), personDeviceRelation.getDeviceId());
+                        for (int i = 0; i < lapiResults.size(); i++) {
+                            LapiResult lapiMsgResult = lapiResults.get(i);
+                            if (lapiMsgResult.isSuccess()) {
+                                msgResult.setResult(true);
+                            } else {
+                                throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                            }
+                        }
+                    } else {
+                        //throw new Exception("添加失败:人员没有上传照片" );
+                        //没有照片 可以只进行数据绑定 不进行设备操作
                     }
-                }else{
-                    //throw new Exception("添加失败:人员没有上传照片" );
-                    //没有照片 可以只进行数据绑定 不进行设备操作
                 }
                 msgResult.setResult(true);
                 msgResult.setData(personDeviceRelation);
@@ -145,9 +149,12 @@ public class PersonDeviceRelationController {
     @PostMapping("batchBindDevice")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "personId",value = "人员ID", required = true,paramType = "query"),
-            @ApiImplicitParam(name = "devices",value = "设备ID(多个设备)", required = true, paramType = "query")
+            @ApiImplicitParam(name = "devices",value = "设备ID(多个设备)", required = true, paramType = "query"),
+            @ApiImplicitParam(name = "isWrite",value = "是否需要上传照片到设备", required = true, paramType = "query")
     })
-    public MessageResult<Integer> batchBindDevice(Long personId,String devices,@RequestAttribute String subject){
+    public MessageResult<Integer> batchBindDevice(Long personId,String devices,
+      @RequestParam(value = "isWrite", defaultValue = "true")Boolean isWrite,
+      @RequestAttribute String subject){
         MessageResult<Integer> msgResult = new MessageResult<>();
         int affectCount = 0;
 
@@ -172,68 +179,87 @@ public class PersonDeviceRelationController {
                        item.setIsBound(false);//绑定设备默认false
 
                        affectCount += personDeviceRelationService.insert(item);
+                   }else{
+                       String personName = "";
+                       PersonInfo personInfo = item.getPersonInfo();
+                       if (personInfo != null) {
+                           personName = personInfo.getName();
+                       }
+                       HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
+                       HSSFCell cell1 = row.createCell(0);
+                       cell1.setCellValue(personName);
+                       HSSFCell cell2 = row.createCell(1);
+                       cell2.setCellValue(item.getDeviceInfo().getAliasName());
+                       HSSFCell cell3 = row.createCell(2);
+                       cell3.setCellValue("添加失败:");
+                       HSSFCell cell4 = row.createCell(3);
+                       cell4.setCellValue("已绑定该设备");
                    }
                }
             }
 
             if (affectCount > 0) {
-                //往设备库传输人脸信息
-                //批量操作
-                int addCount = 0;
-                //往设备库传输人脸信息
-                PersonInfo personInfo = personInfoService.get(personId);
-                //如果人员照片不为空
-                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())) {
-                    List<LapiResult> lapiResults = lapiService.addPerson(personId);
-                    for (int i = 0; i < lapiResults.size(); i++) {
-                        LapiResult lapiResult = lapiResults.get(i);
-                        if (lapiResult.isSuccess()) {
-                            msgResult.setResult(true);
-                        } else {
-                            String personName = "";
-                            if (personInfo != null) {
-                                personName = personInfo.getName();
+                if (isWrite) {
+                    //往设备库传输人脸信息
+                    //批量操作
+                    int addCount = 0;
+                    //往设备库传输人脸信息
+                    PersonInfo personInfo = personInfoService.get(personId);
+                    //如果人员照片不为空
+                    if (StringUtils.isNotEmpty(personInfo.getFaceImageUrl())) {
+                        List<LapiResult> lapiResults = lapiService.addPerson(personId);
+                        for (int i = 0; i < lapiResults.size(); i++) {
+                            LapiResult lapiResult = lapiResults.get(i);
+                            if (lapiResult.isSuccess()) {
+                                msgResult.setResult(true);
+                            } else {
+                                String personName = "";
+                                if (personInfo != null) {
+                                    personName = personInfo.getName();
+                                }
+                                Map resultMap = (Map) lapiResult.getData();
+                                HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
+                                HSSFCell cell1 = row.createCell(0);
+                                cell1.setCellValue(personName);
+                                HSSFCell cell2 = row.createCell(1);
+                                cell2.setCellValue(resultMap.get("deviceAliasName").toString());
+                                HSSFCell cell3 = row.createCell(2);
+                                cell3.setCellValue("添加失败:");
+                                HSSFCell cell4 = row.createCell(3);
+                                cell4.setCellValue(lapiResult.getMsg());
+
+                                //删除绑定关系
+                                PersonDeviceRelation personDeviceRelation = personDeviceRelationService.findByDeviceIdAndPersonId(resultMap.get("deviceId").toString(), personId);
+                                personDeviceRelation.setDelFlag(true);
+                                personDeviceRelation.setUpdateBy(subject);
+                                personDeviceRelation.setUpdateTime(new Date());
+                                personDeviceRelation.setIsBound(false);
+
+                                personDeviceRelationService.update(personDeviceRelation);
+                                addCount++;
                             }
-                            Map resultMap = (Map) lapiResult.getData();
-                            HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
-                            HSSFCell cell1 = row.createCell(0);
-                            cell1.setCellValue(personName);
-                            HSSFCell cell2 = row.createCell(1);
-                            cell2.setCellValue(resultMap.get("deviceAliasName").toString());
-                            HSSFCell cell3 = row.createCell(2);
-                            cell3.setCellValue("添加失败:");
-                            HSSFCell cell4 = row.createCell(3);
-                            cell4.setCellValue(lapiResult.getMsg());
-
-                            //删除绑定关系
-                            PersonDeviceRelation personDeviceRelation = personDeviceRelationService.findByDeviceIdAndPersonId(resultMap.get("deviceId").toString(), personId);
-                            personDeviceRelation.setDelFlag(true);
-                            personDeviceRelation.setUpdateBy(subject);
-                            personDeviceRelation.setUpdateTime(new Date());
-                            personDeviceRelation.setIsBound(false);
-
-                            personDeviceRelationService.update(personDeviceRelation);
-                            addCount++;
                         }
                     }
-                }
 //
-                if(addCount > 0){
-                    //异常数量大于0,表示有部分数据同步失败
-                    msgResult.setResult(false);
-                    //保存失败信息
-                    ByteArrayOutputStream output = new ByteArrayOutputStream();
-                    workbook.write(output);
-                    byte[] buffer = output.toByteArray();
-                    ByteArrayInputStream input = new ByteArrayInputStream(buffer);
-                    String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
-                    msgResult.setMessage(downloadUrl);
-                }else {
-                    //异常数量为0,表示全部同步成功
+                    if (addCount > 0) {
+                        //异常数量大于0,表示有部分数据同步失败
+                        msgResult.setResult(false);
+                        //保存失败信息
+                        ByteArrayOutputStream output = new ByteArrayOutputStream();
+                        workbook.write(output);
+                        byte[] buffer = output.toByteArray();
+                        ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+                        String downloadUrl = OSSUtil.upload(ossConfig, "import", "error.xls", input);
+                        msgResult.setMessage(downloadUrl);
+                    } else {
+                        //异常数量为0,表示全部同步成功
+                        msgResult.setResult(true);
+                        msgResult.setData(affectCount);
+                    }
+                } else {
                     msgResult.setResult(true);
                     msgResult.setData(affectCount);
                 }
-
             } else {
                 msgResult.setResult(false);
                 msgResult.setMessage("人员与0个设备绑定成功!");
@@ -1075,4 +1101,89 @@ public class PersonDeviceRelationController {
         return bl;
     }
 
+    @ApiOperation(value="更新单个用户图片存在状态")
+    @RequestMapping(value = "updatePersonIsWrite",method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "personId",value = "姓名", required = false, paramType = "form",dataType = "String"),
+    })
+    public MessageResult<Boolean> updatePersonIsWrite(
+            @RequestParam(value="personId",defaultValue="") Long personId,
+            @RequestAttribute String subject){
+
+        //当前用户ID
+        User user = userService.get(subject);
+
+        CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
+
+        MessageResult<Boolean> msgResult = new MessageResult<>();
+        msgResult.setData(true);
+        msgResult.setResult(true);
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<PersonDeviceRelation> pdrList = personDeviceRelationService.findByPersonId(personId);
+        for(PersonDeviceRelation pdr : pdrList){
+            DeviceInfo  di = pdr.getDeviceInfo();
+            //这里查询人员信息实际是在xml中调用personInfoDAO。get方法,注意不要加del_flag=0,否则无法查询到已删除用户
+            PersonInfo personInfo = pdr.getPersonInfo();
+            String faceDbId = "";
+            Boolean isWrite = false;
+            try {
+                //查找人脸ID
+                faceDbId = lapiService.getFaceDbId(di,personInfo.getCompanyName());
+                //查询人员是否成功写入设备
+                isWrite = lapiService.isPersonImageExist(personInfo,di,faceDbId);
+
+            }catch (Exception e){
+                isWrite = false;
+            }
+            //更新状态
+            pdr.setIsBound(isWrite);
+            pdr.setUpdateBy(subject);
+            pdr.setUpdateTime(new Date());
+            personDeviceRelationService.update(pdr);
+        }
+
+        msgResult.setResult(true);
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="单用户和设备数据同步")
+    @PostMapping("devicesPersonSync")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "personId", value = "人员ID", required = false, paramType = "form", dataType = "String"),
+            @ApiImplicitParam(name = "deviceIds", value = "设备ID", required = false, paramType = "form", dataType = "String"),
+    })
+    public MessageResult<Boolean> devicesPersonSync(
+            @RequestParam(value="personId",defaultValue="") String personId,
+            @RequestParam(value="deviceIds",defaultValue="") String deviceIds
+    ){
+        MessageResult<Boolean> msgResult = new MessageResult<>();
+        msgResult.setData(true);
+        msgResult.setResult(true);
+        try {
+            PersonInfo personInfo = personInfoService.get(Long.valueOf(personId));
+            if (personInfo==null){
+                throw new Exception("人员信息不存在!");
+            }
+
+            List<LapiResult> msgResultList = lapiService.addPersonForDeviceIds(personInfo.getId(),deviceIds);
+            for (int i = 0; i < msgResultList.size(); i++) {
+                LapiResult lapiResult = msgResultList.get(i);
+                if (!lapiResult.isSuccess()) {
+                    throw  new Exception(lapiResult.getMsg());
+                }
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
 }

+ 188 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -15,8 +15,10 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
 import com.jpsoft.smart.modules.lapi.service.ILapiService;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import com.jpsoft.smart.modules.lapi.vo.LapiResult;
+import com.jpsoft.smart.modules.sys.entity.SysLog;
 import com.jpsoft.smart.modules.sys.entity.User;
 import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
+import com.jpsoft.smart.modules.sys.service.SysLogService;
 import com.jpsoft.smart.modules.sys.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -29,6 +31,7 @@ import org.apache.poi.ss.usermodel.Workbook;
 import org.joda.time.DateTime;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -76,6 +79,11 @@ public class PersonInfoController {
     private PunchLocationService punchLocationService;
     @Autowired
     private PunchRecordService punchRecordService;
+    @Autowired
+    private SysLogService sysLogService;
+
+    @Autowired
+    RabbitTemplate rabbitTemplate;
 
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
@@ -655,6 +663,77 @@ public class PersonInfoController {
         return msgResult;
     }
 
+    @ApiOperation(value = "自动同步开启关闭")
+    @PostMapping("enabledSync")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "人员编号", required = false, paramType = "form", dataType = "String")
+    })
+    public MessageResult<PersonInfo> enabledSync(@RequestParam(value = "id", defaultValue = "") Long id, @RequestAttribute String subject) {
+        MessageResult<PersonInfo> msgResult = new MessageResult<>();
+
+        try {
+            PersonInfo personInfo = personInfoService.get(id);
+
+            if (personInfo.getIsSync()) {
+                personInfo.setIsSync(false);
+            } else {
+                personInfo.setIsSync(true);
+            }
+            personInfo.setUpdateBy(subject);
+            personInfo.setUpdateTime(new Date());
+
+            int affectCount = personInfoService.update(personInfo);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(personInfo);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库保存失败");
+            }
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value = "批量开启自动同步")
+    @PostMapping("enabledSyncList")
+    public MessageResult<PersonInfo> enabledSyncList(@RequestBody List<String> ids, @RequestAttribute String subject) {
+        MessageResult<PersonInfo> msgResult = new MessageResult<>();
+
+        try {
+            int affectCount = 0;
+            for (String id : ids) {
+                PersonInfo personInfo = personInfoService.get(Long.valueOf(id));
+                personInfo.setIsSync(true);
+                personInfo.setUpdateBy(subject);
+                personInfo.setUpdateTime(new Date());
+                personInfoService.update(personInfo);
+
+                affectCount++;
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库保存失败");
+            }
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
     @ApiOperation(value="人脸批量授权")
     @PostMapping("enabledFaceList")
     public MessageResult<PersonInfo> enabledFaceList(@RequestBody List<String> ids,@RequestAttribute String subject){
@@ -1418,5 +1497,114 @@ public class PersonInfoController {
         return messageResult;
     }
 
+    @ApiOperation(value = "清除微信openId")
+    @PostMapping("unbindWechat")
+    public MessageResult<String> unbindWechat(@RequestBody Long id, @RequestAttribute String subject) {
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        try {
+            PersonInfo personInfo = personInfoService.get(id);
+            int affectCount = personInfoService.resetOpenId(id);
+
+            if (affectCount > 0) {
+                SysLog sysLog = new SysLog();
+                sysLog.setUserId(id+"");
+                sysLog.setPointcut("清空微信openId");
+                sysLog.setRemark("清空:" + personInfo.getName() + "(" + id + ")的openId:" + personInfo.getOpenId());
+                sysLog.setCreateTime(new Date());
+                sysLogService.insert(sysLog);
+
+                msgResult.setResult(true);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("更新失败");
+            }
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value = "批量删除用户所有设备上的照片")
+    @PostMapping("batchClearFaceImg")
+    public MessageResult<String> batchClearFaceImg(@RequestBody List<Long> idList) {
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        try {
+            for (Long personId : idList) {
+                rabbitTemplate.convertAndSend("schoolRemoveImageExchange", "schoolRemoveImage", personId);
+            }
+
+            msgResult.setResult(true);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value = "删除用户所有设备上的照片")
+    @PostMapping("clearFaceImg")
+    public MessageResult<Boolean> clearFaceImg(@RequestBody Long id, @RequestAttribute String subject) {
+        MessageResult<Boolean> msgResult = new MessageResult<>();
+        msgResult.setResult(true);
+
+        Boolean isSuccess = true;
+        try {
+            //List<LapiMsgResult> result = lapiService.deletePerson(id);
+            PersonInfo personInfo = personInfoService.get(id);
+            if(personInfo == null){
+                return msgResult;
+            }
+            HSSFWorkbook workbook = new HSSFWorkbook();
+            HSSFSheet sheet = workbook.createSheet();
+            if(!deleteDevicePerson(personInfo, sheet)){
+                ByteArrayOutputStream output = new ByteArrayOutputStream();
+                workbook.write(output);
+                byte[] buffer = output.toByteArray();
+                ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+                String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
+
+                msgResult.setData(false);
+                msgResult.setMessage(downloadUrl);
+            }
+
+            //更新图片状态
+            List<PersonDeviceRelation> pdrList = personDeviceRelationService.findByPersonId(id);
+            for(PersonDeviceRelation pdr : pdrList) {
+                DeviceInfo di = pdr.getDeviceInfo();
+                PersonInfo pi = pdr.getPersonInfo();
+                String faceDbId = "";
+                Boolean isWrite = false;
+                try {
+                    //查找人脸ID
+                    faceDbId = lapiService.getFaceDbId(di, pi.getCompanyName());
+                    //查询人员是否成功写入设备
+                    isWrite = lapiService.isPersonImageExist(pi, di, faceDbId);
+
+                } catch (Exception e) {
+                    isWrite = false;
+                }
+                //更新状态
+                pdr.setIsBound(isWrite);
+                pdr.setUpdateBy(subject);
+                pdr.setUpdateTime(new Date());
+                personDeviceRelationService.update(pdr);
+            }
+        } catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
 
+        return msgResult;
+    }
 }