|
@@ -4,8 +4,11 @@ import com.alipay.api.domain.Person;
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.Page;
|
|
import com.github.pagehelper.util.StringUtil;
|
|
import com.github.pagehelper.util.StringUtil;
|
|
import com.jpsoft.smart.config.OSSConfig;
|
|
import com.jpsoft.smart.config.OSSConfig;
|
|
|
|
+import com.jpsoft.smart.modules.base.dto.PersonInfoDTO;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
import com.jpsoft.smart.modules.base.entity.DeviceInfo;
|
|
import com.jpsoft.smart.modules.base.entity.DeviceInfo;
|
|
import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
|
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
|
|
import com.jpsoft.smart.modules.base.service.DeviceInfoService;
|
|
import com.jpsoft.smart.modules.base.service.DeviceInfoService;
|
|
import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
@@ -41,6 +44,7 @@ import java.io.ByteArrayInputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/personDeviceRelation")
|
|
@RequestMapping("/personDeviceRelation")
|
|
@@ -69,6 +73,10 @@ public class PersonDeviceRelationController {
|
|
@Autowired
|
|
@Autowired
|
|
private PersonInfoService personInfoService;
|
|
private PersonInfoService personInfoService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value="添加设备和人员绑定")
|
|
@ApiOperation(value="添加设备和人员绑定")
|
|
@@ -786,7 +794,287 @@ public class PersonDeviceRelationController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation(value="设备人员列表")
|
|
|
|
+ @RequestMapping(value = "devicePersonList",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 = "parentId",value = "上级企业ID", required = false, paramType = "form",dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "subordinate",value = "是否查询下级单位", required = false, paramType = "form",dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "derviceId",value = "设备编号", 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"),
|
|
|
|
+ @ApiImplicitParam(name = "faceBound",value = "是否同步", required = false, paramType = "form",dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "isUploadPhoto",value = "是否上传照片", required = false, paramType = "form",dataType = "String")
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<Map> devicePersonList(
|
|
|
|
+ @RequestParam(value="name",defaultValue="") String name,
|
|
|
|
+ @RequestParam(value="idCard",defaultValue="") String idCard,
|
|
|
|
+ @RequestParam(value="phone",defaultValue="") String phone,
|
|
|
|
+ @RequestParam(value="companyCode",defaultValue="") String companyCode,
|
|
|
|
+ @RequestParam(value="parentId",defaultValue="") String parentId,
|
|
|
|
+ @RequestParam(value="subordinate",defaultValue="false") Boolean subordinate,
|
|
|
|
+ @RequestParam(value="deviceId",defaultValue="") String deviceId,
|
|
|
|
+ @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,
|
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
|
+ @RequestParam(value="faceBound",defaultValue="") Integer faceBound,
|
|
|
|
+ @RequestParam(value="isUploadPhoto",defaultValue="") String isUploadPhoto,
|
|
|
|
+ @RequestAttribute String subject){
|
|
|
|
+
|
|
|
|
+ //当前用户ID
|
|
|
|
+ User user = userService.get(subject);
|
|
|
|
+
|
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
|
|
|
|
+
|
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
|
+ String[] names = name.split(",");
|
|
|
|
+ List nameList = new ArrayList();
|
|
|
|
+ for (String n : names) {
|
|
|
|
+ nameList.add("%"+ n +"%");
|
|
|
|
+ }
|
|
|
|
+ searchParams.put("nameList", nameList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(idCard)) {
|
|
|
|
+ searchParams.put("idCard","%" + idCard + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(phone)) {
|
|
|
|
+ searchParams.put("phone","%" + phone + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(companyCode)){
|
|
|
|
+ if (!userService.hasRole(subject,"SYSADMIN")) {
|
|
|
|
+ searchParams.put("companyCode", companyInfo.getCode() + "%");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(subordinate){
|
|
|
|
+ searchParams.put("companyCode", companyCode + "%");
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ searchParams.put("companyCode", companyCode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(parentId)){
|
|
|
|
+ CompanyInfo parentCompanyInfo = companyInfoService.get(parentId);
|
|
|
|
+
|
|
|
|
+ String parentCode = parentCompanyInfo.getCode();
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(parentCode)){
|
|
|
|
+ if (!userService.hasRole(subject,"SYSADMIN")) {
|
|
|
|
+ searchParams.put("companyCode", parentCode + "%");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(subordinate){
|
|
|
|
+ searchParams.put("companyCode", parentCode + "%");
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ searchParams.put("companyCode", parentCode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 + "%");
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ if(faceBound != null){
|
|
|
|
+ searchParams.put("faceBound",faceBound);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(isUploadPhoto)){
|
|
|
|
+ searchParams.put("isUploadPhoto", isUploadPhoto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(deviceId)){
|
|
|
|
+ searchParams.put("deviceId", deviceId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
|
+ sortList.add(new Sort("person_id","asc"));
|
|
|
|
+
|
|
|
|
+ Page<PersonDeviceRelation> page = personDeviceRelationService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
+
|
|
|
|
+// Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
+// Page<PersonInfoDTO> pageDTO = PojoUtils.convertPage(page, PersonInfoDTO.class);
|
|
|
|
+//
|
|
|
|
+// for(PersonInfoDTO dto : pageDTO.getResult()){
|
|
|
|
+// List<DeviceInfo> deviceNameList = personDeviceRelationService.findDeviceByPersonId(dto.getId());
|
|
|
|
+//
|
|
|
|
+// String deviceName = deviceNameList.stream()
|
|
|
|
+// .map((device)->device.getAliasName())
|
|
|
|
+// .collect(Collectors.joining(","));
|
|
|
|
+//
|
|
|
|
+// dto.setDeviceName(deviceName);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="用户和单设备数据同步")
|
|
|
|
+ @PostMapping("devicePersonSync")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "personId", value = "人员ID", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "deviceId", value = "设备ID", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<Boolean> devicePersonSync(
|
|
|
|
+ @RequestParam(value="personId",defaultValue="") String personId,
|
|
|
|
+ @RequestParam(value="deviceId",defaultValue="") String deviceId
|
|
|
|
+ ){
|
|
|
|
+ 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(),deviceId);
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="用户和单设备数据同步")
|
|
|
|
+ @PostMapping("devicePersonsSync")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "personIds", value = "人员ID", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "deviceId", value = "设备ID", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<Boolean> devicePersonsSync(
|
|
|
|
+ @RequestParam(value="personIds",defaultValue="") List<String> personIds,
|
|
|
|
+ @RequestParam(value="deviceId",defaultValue="") String deviceId
|
|
|
|
+ ){
|
|
|
|
+ MessageResult<Boolean> msgResult = new MessageResult<>();
|
|
|
|
+ msgResult.setData(true);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
+ HSSFSheet sheet = workbook.createSheet();
|
|
|
|
+
|
|
|
|
+ for(String personId : personIds){
|
|
|
|
+ PersonInfo personInfo = personInfoService.get(Long.valueOf(personId));
|
|
|
|
+
|
|
|
|
+ if (personInfo==null){
|
|
|
|
+ throw new Exception("人员信息不存在!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!addPersonForDeviceIds(personInfo,deviceId, sheet)){
|
|
|
|
+ msgResult.setData(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!msgResult.getData()){
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="添加设备人员图片")
|
|
|
|
+ private Boolean addPersonForDeviceIds(PersonInfo personInfo,String deviceId, HSSFSheet sheet){
|
|
|
|
+ boolean bl = true;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ List<LapiResult> msgResultList = lapiService.addPersonForDeviceIds(personInfo.getId(),deviceId);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < msgResultList.size(); i++) {
|
|
|
|
+ LapiResult lapiResult = msgResultList.get(i);
|
|
|
|
+ if (!lapiResult.isSuccess()) {
|
|
|
|
+ Map resultMap = (Map)lapiResult.getData();
|
|
|
|
+ HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
|
+ HSSFCell cell1 = row.createCell(0);
|
|
|
|
+ cell1.setCellValue(personInfo.getName());
|
|
|
|
+ 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());
|
|
|
|
+
|
|
|
|
+ bl = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }catch(Exception ex) {
|
|
|
|
+ logger.error(ex.getMessage(), ex);
|
|
|
|
+ bl = false;
|
|
|
|
+
|
|
|
|
+ HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
|
+
|
|
|
|
+ HSSFCell cell1 = row.createCell(0);
|
|
|
|
+ cell1.setCellValue(personInfo.getName());
|
|
|
|
+
|
|
|
|
+ HSSFCell cell2 = row.createCell(1);
|
|
|
|
+ cell2.setCellValue("");
|
|
|
|
+
|
|
|
|
+ HSSFCell cell3 = row.createCell(2);
|
|
|
|
+ cell3.setCellValue("");
|
|
|
|
+
|
|
|
|
+ HSSFCell cell4 = row.createCell(3);
|
|
|
|
+ cell4.setCellValue(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return bl;
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|