|
@@ -0,0 +1,160 @@
|
|
|
+package com.jpsoft.smart.modules.base.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.github.pagehelper.util.StringUtil;
|
|
|
+import com.jpsoft.smart.modules.base.dto.CompanyRecordReportDTO;
|
|
|
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonCompany;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonDeviceFilterLog;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonCompanyService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonDeviceFilterLogService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
+import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.smart.modules.sys.entity.User;
|
|
|
+import com.jpsoft.smart.modules.sys.service.UserService;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 墨鱼_mo
|
|
|
+ * @date 2020-4-7 8:53
|
|
|
+ */
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RequestMapping("/report")
|
|
|
+@RestController
|
|
|
+public class ReportController {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceFilterLogService personDeviceFilterLogService;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取每个单位的人数和打卡人数")
|
|
|
+ @PostMapping("getCompanyRecordReport")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "timeRanges",value = "时间范围", paramType = "query")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> getCompanyRecordReport(@RequestParam(value="timeRanges") String timeRanges,@RequestAttribute String subject) {
|
|
|
+
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ try {
|
|
|
+ User user = userService.get(subject);
|
|
|
+ List<CompanyInfo> list = new ArrayList<>();
|
|
|
+
|
|
|
+ //系统管理者和非系统管理者公司列表
|
|
|
+ if (userService.hasRole(subject, "SYSADMIN")) {
|
|
|
+ list = companyInfoService.list();
|
|
|
+ }else {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
|
|
|
+ list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询时间
|
|
|
+ Date beginTime = DateUtil.beginOfDay(new Date());
|
|
|
+ Date endTime = DateUtil.endOfDay(new Date());
|
|
|
+ if(StringUtil.isNotEmpty(timeRanges)){
|
|
|
+ String[] timeRangeArray = timeRanges.split(",");
|
|
|
+ if(timeRangeArray.length==1){
|
|
|
+ beginTime = DateUtil.parse(timeRangeArray[0]);
|
|
|
+ }
|
|
|
+ else if(timeRangeArray.length==2){
|
|
|
+ beginTime = DateUtil.parse(timeRangeArray[0]);
|
|
|
+ endTime = DateUtil.parse(timeRangeArray[1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //结果集
|
|
|
+ List<CompanyRecordReportDTO> companyRecordReportDTOS = new ArrayList<>();
|
|
|
+ //所有公司人员总数初始化
|
|
|
+ Integer totalPersonNum = 0;
|
|
|
+ //所有公司已测人数初始化
|
|
|
+ Integer checkTotalPersonNum = 0;
|
|
|
+ if (list.size()>0){
|
|
|
+ for (CompanyInfo companyInfo : list){
|
|
|
+ // List<CompanyInfo> companyInfoList = new ArrayList<>();
|
|
|
+ //对象封装成集合方便后续使用
|
|
|
+ // companyInfoList.add(companyInfo);
|
|
|
+ //结果集对象初始化
|
|
|
+ CompanyRecordReportDTO companyRecordReportDTO = new CompanyRecordReportDTO();
|
|
|
+ //查询公司的所有未删除对象
|
|
|
+ List<PersonInfo> personInfoList = personInfoService.findByCompanyId(companyInfo.getId());
|
|
|
+
|
|
|
+ //总人数
|
|
|
+ totalPersonNum = totalPersonNum+ personInfoList.size();
|
|
|
+
|
|
|
+ //过滤记录表中时间区间内的非重复数据
|
|
|
+ List<PersonDeviceFilterLog> personDeviceFilterLogs = personDeviceFilterLogService.getDayCheckedPersonByCompanyList(beginTime,endTime,companyInfo);
|
|
|
+ //总已测人数
|
|
|
+ checkTotalPersonNum = checkTotalPersonNum + personDeviceFilterLogs.size();
|
|
|
+
|
|
|
+ //查询出已测温对象
|
|
|
+ List<PersonInfo> checkPersonList = new ArrayList<>();
|
|
|
+ if (personDeviceFilterLogs.size()>0){
|
|
|
+ for (PersonDeviceFilterLog personDeviceFilterLog : personDeviceFilterLogs){
|
|
|
+ PersonInfo personInfo = personInfoService.get(personDeviceFilterLog.getPersonId().longValue());
|
|
|
+ if (personInfo != null){
|
|
|
+ checkPersonList.add(personInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询出未测温对象
|
|
|
+ personInfoList.removeAll(checkPersonList);
|
|
|
+ //未测试人员姓名集合初始化
|
|
|
+ String name = "";
|
|
|
+ if (personInfoList.size()>0){
|
|
|
+ for (PersonInfo personInfo : personInfoList){
|
|
|
+ name = name +","+ personInfo.getName();
|
|
|
+
|
|
|
+ }
|
|
|
+ name = name.substring(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Integer checkPersonTotal = personDeviceFilterLogService.getDayCheckedPersonNumByCompanyList(beginTime,endTime,companyInfoList,null);
|
|
|
+ companyRecordReportDTO.setCompanyName(companyInfo.getName());
|
|
|
+ companyRecordReportDTO.setPersonTotal(personInfoList.size());
|
|
|
+ companyRecordReportDTO.setCheckPersonTotal(personDeviceFilterLogs.size());
|
|
|
+ companyRecordReportDTO.setUnCheckPersonName(name);
|
|
|
+ companyRecordReportDTOS.add(companyRecordReportDTO);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("list",companyRecordReportDTOS);
|
|
|
+ map.put("totalPersonNum",totalPersonNum);
|
|
|
+ map.put("checkTotalPersonNum",checkTotalPersonNum);
|
|
|
+
|
|
|
+ msgResult.setData(map);
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("获取成功");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ msgResult.setData(map);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+}
|