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