|
@@ -0,0 +1,410 @@
|
|
|
+package com.jpsoft.smart.modules.mobile.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.smart.modules.base.entity.*;
|
|
|
+import com.jpsoft.smart.modules.base.service.*;
|
|
|
+import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.smart.modules.common.utils.DES3;
|
|
|
+import com.jpsoft.smart.modules.common.utils.JwtUtil;
|
|
|
+import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.smart.modules.sys.entity.User;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.sf.jsqlparser.expression.LongValue;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import springfox.documentation.annotations.ApiIgnore;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 墨鱼_mo
|
|
|
+ * @date 2020-4-3 9:33
|
|
|
+ * <p>
|
|
|
+ * 手机端健康公示
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/mobile/healthShowApi")
|
|
|
+public class HealthShowApiController {
|
|
|
+
|
|
|
+ @Value("${jwt.secret}")
|
|
|
+ private String jwtSecret;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceFilterLogService personDeviceFilterLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceLogService personDeviceLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyDeviceRelationService companyDeviceRelationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CheckNumCompanyService checkNumCompanyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TotalCheckCompanyService totalCheckCompanyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonCompanyService personCompanyService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "数字数据")
|
|
|
+ @RequestMapping(value = "numData", method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "query", dataType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> numData(String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ List<CompanyInfo> list = new ArrayList<>();
|
|
|
+ HashMap<String, Object> mapData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(subject);
|
|
|
+ if (companyInfo == null) {
|
|
|
+ PersonInfo personInfo = personInfoService.get(new Long(subject));
|
|
|
+ if (personInfo == null) {
|
|
|
+ throw new Exception("参数异常");
|
|
|
+ }
|
|
|
+ if (personInfo.getPopedom().contains("3")) {
|
|
|
+ List<PersonCompany> personCompanyList = personCompanyService.findByPersonId(personInfo.getId());
|
|
|
+ if (personCompanyList.size() > 0) {
|
|
|
+ for (PersonCompany personCompany : personCompanyList) {
|
|
|
+ CompanyInfo companyInfo1 = companyInfoService.get(personCompany.getCompanyId());
|
|
|
+ if (companyInfo1 != null) {
|
|
|
+ list.add(companyInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (list.size() > 0) {
|
|
|
+
|
|
|
+
|
|
|
+ List<String> deviceNoList = new ArrayList<>();
|
|
|
+ for (CompanyInfo companyInfo1 : list) {
|
|
|
+ List<DeviceInfo> deviceInfoList = companyDeviceRelationService.findDeviceByCompanyId(companyInfo1.getId());
|
|
|
+ for (DeviceInfo deviceInfo : deviceInfoList) {
|
|
|
+ if (!deviceNoList.contains(deviceInfo.getDeviceNo())) {
|
|
|
+ deviceNoList.add(deviceInfo.getDeviceNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer personNum = Math.toIntExact(personInfoService.countByCompanyList(list));
|
|
|
+ Integer checkedPersonNum = personDeviceFilterLogService.getDayCheckedPersonNumByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, null);
|
|
|
+ Integer checkedVisitorNum = personDeviceLogService.getDayCheckedVistorNumByDeviceNoList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), deviceNoList);
|
|
|
+ Integer num = checkNumCompanyService.getDayCheckNumByCompanyList(DateUtil.format(new Date(), "yyyy-MM-dd"), list);
|
|
|
+ Integer totalNum = totalCheckCompanyService.getTotalCheckNum(list);
|
|
|
+ Integer dayCheckNum = num == null ? 0 : num;
|
|
|
+ Integer totalCheckNum = totalNum == null ? dayCheckNum : totalNum + dayCheckNum;
|
|
|
+
|
|
|
+ Integer num2 = personDeviceFilterLogService.getDayAbnormalNumByCompanyList(DateUtil.beginOfDay(new Date()), new Date(), list);
|
|
|
+ Integer totalNum2 = totalCheckCompanyService.getTotalAbnormalNumByCompanyList(list);
|
|
|
+ Integer dayAbnormalNum = num2 == null ? 0 : num2;
|
|
|
+ Integer totalAbnormalNum = totalNum2 == null ? 0 : totalNum2 + dayAbnormalNum;
|
|
|
+
|
|
|
+ Integer normalDaysNum = totalCheckCompanyService.findMinNormalDayByCompanyList(list);
|
|
|
+ Integer normalDays = normalDaysNum == null ? 0 : normalDaysNum;
|
|
|
+
|
|
|
+
|
|
|
+ mapData.put("checkedPersonNum", checkedPersonNum);
|
|
|
+ mapData.put("personNum", personNum);
|
|
|
+ mapData.put("checkedVisitorNum", checkedVisitorNum);
|
|
|
+ mapData.put("totalCheckNum", totalCheckNum);
|
|
|
+ mapData.put("dayAbnormalNum", dayAbnormalNum);
|
|
|
+ mapData.put("totalAbnormalNum", totalAbnormalNum);
|
|
|
+ mapData.put("normalDays", normalDays);
|
|
|
+
|
|
|
+ }
|
|
|
+ msgResult.setMessage("查询成功");
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(mapData);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "图片数据")
|
|
|
+ @RequestMapping(value = "picData", method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "query", dataType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "type", value = "员工/访客(person/visitor)", required = true, paramType = "form", dataType = "String"),
|
|
|
+
|
|
|
+ })
|
|
|
+ public MessageResult<Map> picData(
|
|
|
+ @RequestParam(value = "type", defaultValue = "all") String type,
|
|
|
+ @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "12") int pageSize,
|
|
|
+ String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ List<CompanyInfo> list = new ArrayList<>();
|
|
|
+ HashMap<String, Object> mapData = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(subject);
|
|
|
+
|
|
|
+ if (companyInfo == null) {
|
|
|
+ PersonInfo personInfo = personInfoService.get(new Long(subject));
|
|
|
+ if (personInfo == null) {
|
|
|
+ throw new Exception("参数异常");
|
|
|
+ }
|
|
|
+ if (personInfo.getPopedom().contains("3")) {
|
|
|
+ List<PersonCompany> personCompanyList = personCompanyService.findByPersonId(personInfo.getId());
|
|
|
+ if (personCompanyList.size() > 0) {
|
|
|
+ for (PersonCompany personCompany : personCompanyList) {
|
|
|
+ CompanyInfo companyInfo1 = companyInfoService.get(personCompany.getCompanyId());
|
|
|
+ if (companyInfo1 != null) {
|
|
|
+ list.add(companyInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (list.size() > 0) {
|
|
|
+
|
|
|
+
|
|
|
+ List<String> deviceNoList = new ArrayList<>();
|
|
|
+ for (CompanyInfo companyInfo1 : list) {
|
|
|
+ List<DeviceInfo> deviceInfoList = companyDeviceRelationService.findDeviceByCompanyId(companyInfo1.getId());
|
|
|
+ for (DeviceInfo deviceInfo : deviceInfoList) {
|
|
|
+ if (!deviceNoList.contains(deviceInfo.getDeviceNo())) {
|
|
|
+ deviceNoList.add(deviceInfo.getDeviceNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<PersonDeviceLog> personDeviceLogList = new Page<>();
|
|
|
+ if ("all".equals(type)) {
|
|
|
+ personDeviceLogList = personDeviceLogService.findAllPersonLogByCompanyListAndDeviceNoList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, deviceNoList, pageIndex, pageSize);
|
|
|
+ } else if ("person".equals(type)) {
|
|
|
+ personDeviceLogList = personDeviceLogService.findLastPersonLogByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, pageIndex, pageSize);
|
|
|
+ } else if ("visitor".equals(type)) {
|
|
|
+ personDeviceLogList = personDeviceLogService.findVisitorLogByDeviceNoList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), deviceNoList, pageIndex, pageSize);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(personDeviceLogList));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ msgResult.setData(mapData);
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setMessage("查询成功");
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "学校数字数据")
|
|
|
+ @RequestMapping(value = "numDataForSchool", method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "query", dataType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<Map> numDataForSchool(String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(subject);
|
|
|
+ if (companyInfo == null) {
|
|
|
+ throw new Exception("学校不存在");
|
|
|
+ }
|
|
|
+ List<CompanyInfo> list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
|
|
|
+ List<String> deviceNoList = new ArrayList<>();
|
|
|
+ for (CompanyInfo companyInfo1 : list) {
|
|
|
+ List<DeviceInfo> deviceInfoList = companyDeviceRelationService.findDeviceByCompanyId(companyInfo1.getId());
|
|
|
+ for (DeviceInfo deviceInfo : deviceInfoList) {
|
|
|
+ if (!deviceNoList.contains(deviceInfo.getDeviceNo())) {
|
|
|
+ deviceNoList.add(deviceInfo.getDeviceNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //应测教职工数
|
|
|
+ Integer teacherNum = Math.toIntExact(personInfoService.countByCompanyListAndPopedom("teacher", list));
|
|
|
+ //应测学生数
|
|
|
+ Integer studentNum = Math.toIntExact(personInfoService.countByCompanyListAndPopedom("student", list));
|
|
|
+ //已测教职工数
|
|
|
+ Integer checkedTeacherNum = personDeviceFilterLogService.getDayCheckedPersonNumByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, "2");
|
|
|
+ Integer checkedTeacherAndStudentNum = personDeviceFilterLogService.getDayCheckedPersonNumByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, "1");
|
|
|
+
|
|
|
+ //已测学生数
|
|
|
+ Integer checkedStudentNum = checkedTeacherAndStudentNum - checkedTeacherNum;
|
|
|
+
|
|
|
+ Integer num = checkNumCompanyService.getDayCheckNumByCompanyList(DateUtil.format(new Date(), "yyyy-MM-dd"), list);
|
|
|
+ Integer totalNum = totalCheckCompanyService.getTotalCheckNum(list);
|
|
|
+ Integer dayCheckNum = num == null ? 0 : num;
|
|
|
+ Integer totalCheckNum = totalNum == null ? dayCheckNum : totalNum + dayCheckNum;
|
|
|
+
|
|
|
+ Integer num2 = personDeviceFilterLogService.getDayAbnormalNumByCompanyList(DateUtil.beginOfDay(new Date()), new Date(), list);
|
|
|
+ Integer totalNum2 = totalCheckCompanyService.getTotalAbnormalNumByCompanyList(list);
|
|
|
+
|
|
|
+ //当日异常
|
|
|
+ Integer dayAbnormalNum = num2 == null ? 0 : num2;
|
|
|
+
|
|
|
+ //总异常
|
|
|
+ Integer totalAbnormalNum = totalNum2 == null ? 0 : totalNum2 + dayAbnormalNum;
|
|
|
+
|
|
|
+ Integer normalDaysNum = totalCheckCompanyService.findMinNormalDayByCompanyList(list);
|
|
|
+ //连续无异常天数
|
|
|
+ Integer normalDays = normalDaysNum == null ? 0 : normalDaysNum;
|
|
|
+
|
|
|
+ HashMap<String, Object> mapData = new HashMap<>();
|
|
|
+ mapData.put("teacherNum", teacherNum);
|
|
|
+ mapData.put("studentNum", studentNum);
|
|
|
+ mapData.put("checkedTeacherNum", checkedTeacherNum);
|
|
|
+ mapData.put("checkedStudentNum", checkedStudentNum);
|
|
|
+ mapData.put("dayAbnormalNum", dayAbnormalNum);
|
|
|
+ mapData.put("totalAbnormalNum", totalAbnormalNum);
|
|
|
+ mapData.put("normalDays", normalDays);
|
|
|
+ msgResult.setMessage("查询成功");
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(mapData);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "学校图片数据")
|
|
|
+ @RequestMapping(value = "picDataForSchool", method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "token", value = "令牌", paramType = "query", dataType = "form"),
|
|
|
+ @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form"),
|
|
|
+ @ApiImplicitParam(name = "type", value = "老师/学生(teacher/student)", required = true, paramType = "form", dataType = "String"),
|
|
|
+
|
|
|
+ })
|
|
|
+ public MessageResult<Map> picDataForSchool(
|
|
|
+ @RequestParam(value = "type", defaultValue = "all") String type,
|
|
|
+ @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "12") int pageSize,
|
|
|
+ String token, @RequestAttribute String subject) {
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(subject);
|
|
|
+ if (companyInfo == null) {
|
|
|
+ throw new Exception("公司不存在");
|
|
|
+ }
|
|
|
+ List<CompanyInfo> list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%", null);
|
|
|
+ List<String> deviceNoList = new ArrayList<>();
|
|
|
+ for (CompanyInfo companyInfo1 : list) {
|
|
|
+ List<DeviceInfo> deviceInfoList = companyDeviceRelationService.findDeviceByCompanyId(companyInfo1.getId());
|
|
|
+ for (DeviceInfo deviceInfo : deviceInfoList) {
|
|
|
+ if (!deviceNoList.contains(deviceInfo.getDeviceNo())) {
|
|
|
+ deviceNoList.add(deviceInfo.getDeviceNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<PersonDeviceLog> personDeviceLogList = new Page<>();
|
|
|
+ if ("all".equals(type)) {
|
|
|
+ personDeviceLogList = personDeviceLogService.findLastPersonLogByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, pageIndex, pageSize);
|
|
|
+ } else if ("teacher".equals(type)) {
|
|
|
+ personDeviceLogList = personDeviceLogService.findLastTeacherLogByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, pageIndex, pageSize);
|
|
|
+ } else if ("student".equals(type)) {
|
|
|
+ personDeviceLogList = personDeviceLogService.findLastStudentLogByCompanyList(DateUtil.beginOfDay(new Date()), DateUtil.endOfDay(new Date()), list, pageIndex, pageSize);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ msgResult.setMessage("查询成功");
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(personDeviceLogList));
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/getCompanyToken")
|
|
|
+ @ApiOperation(value = "根据公司id获取token")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "companyInfoId", paramType = "query", required = true, value = "公司id")
|
|
|
+ })
|
|
|
+ public MessageResult<String> getCompanyToken(String companyInfoId, @ApiIgnore HttpSession session) {
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(companyInfoId);
|
|
|
+
|
|
|
+ DES3 des3 = new DES3();
|
|
|
+
|
|
|
+
|
|
|
+ if (companyInfo != null) {
|
|
|
+
|
|
|
+ //生成token
|
|
|
+ String token = JwtUtil.createToken(jwtSecret, companyInfoId, DateTime.now().plusHours(6).toDate());
|
|
|
+
|
|
|
+ session.setAttribute("companyToken", token);
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setData(token);
|
|
|
+ } else {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage("公司不存在!");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception ex) {
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|