Browse Source

sz 设备人员管理,测温统计添加查询条件

xiao547607 5 years ago
parent
commit
53fbfb5d1a

+ 51 - 3
common/src/main/resources/mapper/base/PersonDeviceRelation.xml

@@ -107,18 +107,66 @@ id_,device_id,person_id,del_flag,create_by,create_time,update_by,update_time		fr
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="PersonDeviceRelationMap">
 		<![CDATA[
-			select * from base_person_device_relation a
+			select a.* from base_person_device_relation a
 			LEFT JOIN base_device_info b ON a.device_id = b.id_
+			LEFT JOIN base_person_info c ON a.person_id = c.id_
+			LEFT JOIN base_company_info d ON c.company_id = d.id_
 		]]>
 		<where>
 			and a.del_flag = false
 			and b.del_flag = false
+			and c.del_flag = false
+			and d.del_flag = false
 			<if test="searchParams.deviceId != null">
-			and a.device_id = #{searchParams.deviceId}
-		</if>
+				and a.device_id = #{searchParams.deviceId}
+			</if>
 			<if test="searchParams.personId != null">
 				and a.person_id = #{searchParams.personId}
 			</if>
+			<if test="searchParams.companyId != null">
+				and c.company_id = #{searchParams.companyId}
+			</if>
+			<if test="searchParams.companyCode != null">
+				and d.code_ like #{searchParams.companyCode}
+			</if>
+			<if test="searchParams.name != null">
+				and c.name_ like #{searchParams.name}
+			</if>
+			<if test="searchParams.nameList != null">
+				<foreach item="name" collection="searchParams.nameList" open="and (" separator="or" close=")">
+					c.name_ like #{name}
+				</foreach>
+			</if>
+			<if test="searchParams.idCard != null">
+				and c.id_card like #{searchParams.idCard}
+			</if>
+			<if test="searchParams.phone != null">
+				and c.phone_ like #{searchParams.phone}
+			</if>
+			<if test="searchParams.position1 != null">
+				and c.position1_ like #{searchParams.position1}
+			</if>
+			<if test="searchParams.position2 != null">
+				and c.position2_ like #{searchParams.position2}
+			</if>
+			<if test="searchParams.position3 != null">
+				and c.position3_ like #{searchParams.position3}
+			</if>
+			<if test="searchParams.position4 != null">
+				and c.position4_ like #{searchParams.position4}
+			</if>
+			<if test="searchParams.position5 != null">
+				and c.position5_ like #{searchParams.position5}
+			</if>
+			<if test="searchParams.faceBound != null">
+				and c.face_bound = #{searchParams.faceBound}
+			</if>
+			<if test="'1'.toString() == searchParams.isUploadPhoto and null != searchParams.isUploadPhoto">
+				and c.face_image_url is not null
+			</if>
+			<if test="'0'.toString() == searchParams.isUploadPhoto and null != searchParams.isUploadPhoto">
+				and c.face_image_url is null
+			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
 	        a.${sort.name} ${sort.order}

+ 2 - 2
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceLogController.java

@@ -68,7 +68,7 @@ public class PersonDeviceLogController {
     @RequestMapping(value = "pageList", method = RequestMethod.POST)
     @ApiImplicitParams({
             @ApiImplicitParam(name = "companyId", value = "所属单位编号", paramType = "query"),
-            @ApiImplicitParam(name = "subordinate", value = "会否保护下级单位", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "subordinate", value = "是否查询下级单位", required = false, paramType = "query", dataType = "String"),
             @ApiImplicitParam(name = "deviceNo", value = "设备编号", paramType = "query"),
             @ApiImplicitParam(name = "aliasName", value = "设备别名", paramType = "query"),
             @ApiImplicitParam(name = "personName", value = "人员姓名", paramType = "query"),
@@ -197,7 +197,7 @@ public class PersonDeviceLogController {
     @PostMapping("exportXls")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "companyId", value = "所属单位编号", paramType = "query"),
-            @ApiImplicitParam(name = "subordinate", value = "会否保护下级单位", required = false, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "subordinate", value = "是否查询下级单位", required = false, paramType = "query", dataType = "String"),
             @ApiImplicitParam(name = "deviceNo", value = "设备编号", paramType = "query"),
             @ApiImplicitParam(name = "aliasName", value = "设备别名", paramType = "query"),
             @ApiImplicitParam(name = "personName", value = "人员姓名", paramType = "query"),

+ 288 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -4,8 +4,11 @@ import com.alipay.api.domain.Person;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.util.StringUtil;
 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.PersonInfo;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.base.service.DeviceInfoService;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.utils.OSSUtil;
@@ -41,6 +44,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/personDeviceRelation")
@@ -69,6 +73,10 @@ public class PersonDeviceRelationController {
     @Autowired
     private PersonInfoService personInfoService;
 
+    @Autowired
+    private CompanyInfoService companyInfoService;
+
+
 
     
     @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;
+    }
 
 }

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

@@ -435,7 +435,7 @@ public class PersonInfoController {
             @ApiImplicitParam(name = "phone",value = "手机号", required = false, paramType = "form",dataType = "String"),
             @ApiImplicitParam(name = "companyCode",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 = "subordinate",value = "是否查询下级单位", required = false, paramType = "form",dataType = "String"),
             @ApiImplicitParam(name = "derviceName",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"),
@@ -976,8 +976,8 @@ public class PersonInfoController {
             @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 = "companyCode",value = "企业编码", required = false, paramType = "form",dataType = "String"),
-            @ApiImplicitParam(name = "subordinate",value = "会否保护下级单位", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "parentId",value = "企业编号", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "subordinate",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"),
@@ -1313,4 +1313,6 @@ public class PersonInfoController {
 
         return bl;
     }
+
+
 }

+ 23 - 5
web/src/main/java/com/jpsoft/smart/modules/base/controller/ReportController.java

@@ -48,9 +48,15 @@ public class ReportController {
     @ApiOperation(value = "获取每个单位的人数和打卡人数")
     @PostMapping("getCompanyRecordReport")
     @ApiImplicitParams({
+            @ApiImplicitParam(name = "parentId",value = "上级单位ID", required = false, paramType = "form",dataType = "String"),
+            @ApiImplicitParam(name = "subordinate",value = "是否查询下级单位", required = false, paramType = "form",dataType = "String"),
             @ApiImplicitParam(name = "timeRanges",value = "时间范围", paramType = "query")
     })
-    public MessageResult<Map> getCompanyRecordReport(@RequestParam(value="timeRanges",defaultValue = "") String timeRanges,@RequestAttribute String subject) {
+    public MessageResult<Map> getCompanyRecordReport(
+            @RequestParam(value="parentId",defaultValue="")  String parentId,
+            @RequestParam(value="subordinate",defaultValue="false")  Boolean subordinate,
+            @RequestParam(value="timeRanges",defaultValue = "") String timeRanges,
+            @RequestAttribute String subject) {
 
         MessageResult<Map> msgResult = new MessageResult<>();
         HashMap<String, Object> map = new HashMap<>();
@@ -59,11 +65,23 @@ public class ReportController {
             List<CompanyInfo> list = new ArrayList<>();
 
             //系统管理者和非系统管理者公司列表
-            if (userService.hasRole(subject, "SYSADMIN")) {
-                list = companyInfoService.list();
+            if(StringUtil.isNotEmpty(parentId)){
+                CompanyInfo companyInfo = companyInfoService.get(parentId);
+                String code = "";
+                if (subordinate) {
+                    code = companyInfo.getCode() + "%";
+                } else {
+                    code = companyInfo.getCode();
+                }
+                list = companyInfoService.findByCompanyCode(code, null);
+
             }else {
-                CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
-                list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
+                if (userService.hasRole(subject, "SYSADMIN")) {
+                    list = companyInfoService.list();
+                } else {
+                    CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
+                    list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
+                }
             }
 
             //查询时间