|
@@ -0,0 +1,163 @@
|
|
|
+package com.jpsoft.smart.modules.mobile.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonDeviceLog;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonDeviceLogService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
+import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.format.annotation.DateTimeFormat;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/mobile/personDeviceLogApi")
|
|
|
+public class PersonDeviceLogApiController {
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceLogService personDeviceLogService;
|
|
|
+
|
|
|
+ @PostMapping("queryTemperatureRecordListByEnt")
|
|
|
+ @ApiOperation(value="企业管理员查看温度记录(需要传令牌)")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="queryDate",value = "查询日期",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
|
|
|
+ @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<List> queryTemperatureRecordListByEnt(
|
|
|
+ @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate,
|
|
|
+ String token,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+ List<Map> recordList = new ArrayList<>();
|
|
|
+
|
|
|
+ MessageResult<List> messageResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ PersonInfo admin = personInfoService.get(Long.valueOf(subject));
|
|
|
+
|
|
|
+ Map<String, Object> personSearchParam = new HashMap<>();
|
|
|
+ personSearchParam.put("companyId",admin.getCompanyId());
|
|
|
+
|
|
|
+ List<Sort> sortList1 = new ArrayList<>();
|
|
|
+ sortList1.add(new Sort("id_","asc"));
|
|
|
+
|
|
|
+ Page<PersonInfo> personList = personInfoService.pageSearch(personSearchParam,pageIndex,pageSize,true,sortList1);
|
|
|
+
|
|
|
+ DateTime startTime = new DateTime(queryDate);
|
|
|
+
|
|
|
+ for (PersonInfo person : personList) {
|
|
|
+ Map<String, Object> recordMap = new HashMap<>();
|
|
|
+
|
|
|
+ recordMap.put("name", person.getName());
|
|
|
+ recordMap.put("faceImageUrl", person.getFaceImageUrl());
|
|
|
+
|
|
|
+ Map<String, Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ searchParams.put("personId", person.getId());
|
|
|
+ searchParams.put("beginTime", startTime.toDate());
|
|
|
+ searchParams.put("endTime", startTime.plusDays(1).toDate());
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("record_time", "asc"));
|
|
|
+
|
|
|
+ Page<PersonDeviceLog> page = personDeviceLogService.simplePageSearch(searchParams, 1, 100, false, sortList);
|
|
|
+
|
|
|
+ Map<Integer, List> hourMap = new TreeMap<>();
|
|
|
+
|
|
|
+ //收集每个人每小时的测量温度
|
|
|
+ for (PersonDeviceLog personDeviceLog : page) {
|
|
|
+ DateTime recordTime = new DateTime(personDeviceLog.getRecordTime());
|
|
|
+
|
|
|
+ int hour = recordTime.getHourOfDay();
|
|
|
+
|
|
|
+ if (hourMap.containsKey(hour)) {
|
|
|
+ hourMap.get(hour).add(personDeviceLog);
|
|
|
+ } else {
|
|
|
+ List<PersonDeviceLog> logList = new ArrayList<>();
|
|
|
+ logList.add(personDeviceLog);
|
|
|
+ hourMap.put(hour, logList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //每个小时取一条温度数据小于37的即可,如果没有则取最低的
|
|
|
+ BigDecimal stdLower = new BigDecimal(36);
|
|
|
+ BigDecimal stdUpper = new BigDecimal(37);
|
|
|
+
|
|
|
+ Map<Integer, PersonDeviceLog> hourFilterMap = new TreeMap<>();
|
|
|
+
|
|
|
+ for (Integer hour : hourMap.keySet()) {
|
|
|
+ List<PersonDeviceLog> logList = hourMap.get(hour);
|
|
|
+
|
|
|
+ List<PersonDeviceLog> filterList = logList.stream()
|
|
|
+ //查询是否有36度至37度
|
|
|
+ .filter((log) -> {
|
|
|
+ if (log.getTemperature().compareTo(stdLower) >= 0
|
|
|
+ && log.getTemperature().compareTo(stdUpper) <= 0) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ //体温由低到高排列
|
|
|
+ .sorted(Comparator.comparing(PersonDeviceLog::getTemperature)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (filterList.size() > 0) {
|
|
|
+ hourFilterMap.put(hour, filterList.get(0));
|
|
|
+ } else {
|
|
|
+ //如果不存在,则取最低的一条
|
|
|
+ Optional<PersonDeviceLog> optional = logList.stream()
|
|
|
+ .sorted(Comparator.comparing(PersonDeviceLog::getTemperature)).findFirst();
|
|
|
+
|
|
|
+ if (optional.isPresent()) {
|
|
|
+ hourFilterMap.put(hour, optional.get());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
|
+
|
|
|
+ List<Map> personDeviceLogs = hourFilterMap.keySet().stream()
|
|
|
+ .map((key) -> hourFilterMap.get(key))
|
|
|
+ .sorted(Comparator.comparing(PersonDeviceLog::getRecordTime))
|
|
|
+ .map((log)->{
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("temperature",log.getTemperature());
|
|
|
+ map.put("recordTime",sdf.format(log.getRecordTime()));
|
|
|
+
|
|
|
+ return map;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ recordMap.put("list", personDeviceLogs);
|
|
|
+
|
|
|
+ recordList.add(recordMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ messageResult.setResult(true);
|
|
|
+ messageResult.setData(recordList);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ messageResult.setResult(false);
|
|
|
+ messageResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return messageResult;
|
|
|
+ }
|
|
|
+}
|