|
|
@@ -7,6 +7,8 @@ import com.jjt.biz.domain.SensorConfig;
|
|
|
import com.jjt.biz.service.*;
|
|
|
import com.jjt.common.core.controller.BaseController;
|
|
|
import com.jjt.common.core.page.TableDataInfo;
|
|
|
+import com.jjt.common.utils.SecurityUtils;
|
|
|
+import com.jjt.common.utils.StringUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
@@ -16,10 +18,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 可视化首页
|
|
|
@@ -34,8 +34,6 @@ public class IndexController extends BaseController {
|
|
|
@Resource
|
|
|
private IHouseConfigService houseConfigService;
|
|
|
@Resource
|
|
|
- private IDeviceConfigService deviceConfigService;
|
|
|
- @Resource
|
|
|
private IDeviceChannelsService channelsService;
|
|
|
@Resource
|
|
|
private IFlowsRecordService flowsRecordService;
|
|
|
@@ -57,15 +55,15 @@ public class IndexController extends BaseController {
|
|
|
} else {
|
|
|
xx.put("alarm", -1);
|
|
|
}
|
|
|
+ xx.put("smoke", true);
|
|
|
+ xx.put("exhaust", true);
|
|
|
SensorConfig sensorConfig = sensorConfigService.findByHouseId(house.getHouseId());
|
|
|
- String[] tmp = sensorConfig.getRemark().split(",");
|
|
|
- if (tmp.length == 2) {
|
|
|
- xx.put("smoke", !"true".equals(tmp[0]));
|
|
|
- xx.put("exhaust", !"true".equals(tmp[1]));
|
|
|
-
|
|
|
- } else {
|
|
|
- xx.put("smoke", true);
|
|
|
- xx.put("exhaust", true);
|
|
|
+ if (StringUtils.isNotEmpty(sensorConfig.getRemark())) {
|
|
|
+ String[] tmp = sensorConfig.getRemark().split(",");
|
|
|
+ if (tmp.length == 2) {
|
|
|
+ xx.put("smoke", !"true".equals(tmp[0]));
|
|
|
+ xx.put("exhaust", !"true".equals(tmp[1]));
|
|
|
+ }
|
|
|
}
|
|
|
xx.put("channel", channelsService.findByHouseId(house.getHouseId()));
|
|
|
house.setParams(xx);
|
|
|
@@ -77,52 +75,14 @@ public class IndexController extends BaseController {
|
|
|
@GetMapping("/events")
|
|
|
public Map<String, Object> event() {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- Map<String, Object> curr = new HashMap<>();
|
|
|
- curr.put("0", 0);
|
|
|
- curr.put("189", 1);
|
|
|
- curr.put("191", 2);
|
|
|
- curr.put("195", 3);
|
|
|
- curr.put("201", 4);
|
|
|
- result.put("curr", curr);
|
|
|
- Map<String, Object> month = new HashMap<>();
|
|
|
- month.put("0", 0);
|
|
|
- month.put("189", 45);
|
|
|
- month.put("191", 12);
|
|
|
- month.put("195", 22);
|
|
|
- month.put("201", 55);
|
|
|
- result.put("month", month);
|
|
|
- List<Map<String, Object>> trade = new ArrayList<>();
|
|
|
- // 模拟数据:从1号到今天的事件统计
|
|
|
- int today = LocalDate.now().getDayOfMonth();
|
|
|
- // 获取今天是几号
|
|
|
- for (int i = 1; i <= today; i++) {
|
|
|
- Map<String, Object> dayData = new HashMap<>();
|
|
|
- dayData.put("date", "2025-10-" + String.format("%02d", i));
|
|
|
- dayData.put("value", (int) (Math.random() * 100));
|
|
|
- // 随机事件数
|
|
|
- trade.add(dayData);
|
|
|
- }
|
|
|
- result.put("trade", trade);
|
|
|
- List<Map<String, Object>> flow = new ArrayList<>();
|
|
|
- for (int i = 1; i <= today; i++) {
|
|
|
- Map<String, Object> dayData = new HashMap<>();
|
|
|
- dayData.put("date", "2025-10-" + String.format("%02d", i));
|
|
|
-
|
|
|
- int total = (int) (Math.random() * 100) + 50;
|
|
|
- // 总量(闭单量+未闭单量)
|
|
|
- int closed = (int) (Math.random() * total);
|
|
|
- // 闭单量
|
|
|
- int unclosed = total - closed;
|
|
|
- // 未闭单量
|
|
|
-
|
|
|
- dayData.put("total", total);
|
|
|
- dayData.put("closed", closed);
|
|
|
- dayData.put("unclosed", unclosed);
|
|
|
-
|
|
|
- // 随机流程数
|
|
|
- flow.add(dayData);
|
|
|
- }
|
|
|
- result.put("flow", flow);
|
|
|
+ //1.查询当天的事件统计
|
|
|
+ FlowsRecord flowsRecord = new FlowsRecord();
|
|
|
+ // 设置为当月第一天的0点
|
|
|
+ LocalDate today = LocalDate.now().withDayOfMonth(1);
|
|
|
+ flowsRecord.setCreateTime(java.util.Date.from(today.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant()));
|
|
|
+ flowsRecord.getParams().put("deptId", SecurityUtils.getDeptId());
|
|
|
+ List<FlowsRecord> list = flowsRecordService.selectFlowsRecordList(flowsRecord);
|
|
|
+ eventCalc(result, list);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -130,36 +90,92 @@ public class IndexController extends BaseController {
|
|
|
@GetMapping("/events/{houseId}")
|
|
|
public Map<String, Object> eventByHouse(@PathVariable("houseId") Long houseId) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
+ HouseConfig house = houseConfigService.selectHouseConfigByHouseId(houseId);
|
|
|
+ FlowsRecord flowsRecord = new FlowsRecord();
|
|
|
+ LocalDate today = LocalDate.now().withDayOfMonth(1);
|
|
|
+ flowsRecord.setCreateTime(java.util.Date.from(today.atStartOfDay(java.time.ZoneId.systemDefault()).toInstant()));
|
|
|
+ flowsRecord.setHouse(house.getHouseName());
|
|
|
+ List<FlowsRecord> list = flowsRecordService.selectFlowsRecordList(flowsRecord);
|
|
|
+ eventCalc(result, list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void eventCalc(Map<String, Object> result, List<FlowsRecord> list) {
|
|
|
Map<String, Object> curr = new HashMap<>();
|
|
|
+ // 按updateBy分组统计数量
|
|
|
+ Map<String, Integer> monthCountMap = new HashMap<>();
|
|
|
+
|
|
|
+ list.forEach(record -> {
|
|
|
+ String updateBy = record.getUpdateBy();
|
|
|
+ monthCountMap.put(updateBy, monthCountMap.getOrDefault(updateBy, 0) + 1);
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Integer> dayCountMap = new HashMap<>();
|
|
|
+ // 过滤出当天的记录并进行统计
|
|
|
+ list.stream()
|
|
|
+ .filter(record -> {
|
|
|
+ LocalDate recordDate = record.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
|
|
+ return recordDate.equals(LocalDate.now());
|
|
|
+ })
|
|
|
+ .forEach(record -> {
|
|
|
+ String updateBy = record.getUpdateBy();
|
|
|
+ dayCountMap.put(updateBy, dayCountMap.getOrDefault(updateBy, 0) + 1);
|
|
|
+ });
|
|
|
+
|
|
|
+ //先全部初始化为0,避免前端出现NAN
|
|
|
curr.put("0", 0);
|
|
|
curr.put("189", 0);
|
|
|
- curr.put("191", 2);
|
|
|
+ curr.put("191", 0);
|
|
|
curr.put("195", 0);
|
|
|
curr.put("201", 0);
|
|
|
+ curr.putAll(dayCountMap);
|
|
|
result.put("curr", curr);
|
|
|
- // 模拟数据:从1号到今天的事件统计
|
|
|
- int today = LocalDate.now().getDayOfMonth();
|
|
|
+ Map<String, Object> month = new HashMap<>();
|
|
|
+ month.put("0", 0);
|
|
|
+ month.put("189", 0);
|
|
|
+ month.put("191", 0);
|
|
|
+ month.put("195", 0);
|
|
|
+ month.put("201", 0);
|
|
|
+ month.putAll(monthCountMap);
|
|
|
+
|
|
|
+ result.put("month", month);
|
|
|
+ List<Map<String, Object>> trade = new ArrayList<>();
|
|
|
+
|
|
|
List<Map<String, Object>> flow = new ArrayList<>();
|
|
|
- for (int i = 1; i <= today; i++) {
|
|
|
+ // 按日期分组统计数量
|
|
|
+ Map<String, Long> dateCountMap = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(record -> {
|
|
|
+ LocalDate recordDate = record.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
|
|
+ return recordDate.toString(); // 格式: YYYY-MM-DD
|
|
|
+ }, TreeMap::new, Collectors.counting()));
|
|
|
+ Map<String, Long> dateOnCountMap = list.stream()
|
|
|
+ .filter(record -> "进行中".equals(record.getStatus()))
|
|
|
+ .collect(Collectors.groupingBy(record -> {
|
|
|
+ LocalDate recordDate = record.getCreateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
|
|
+ return recordDate.toString(); // 格式: YYYY-MM-DD
|
|
|
+ }, TreeMap::new, Collectors.counting()));
|
|
|
+ dateCountMap.forEach((date, count) -> {
|
|
|
Map<String, Object> dayData = new HashMap<>();
|
|
|
- dayData.put("date", "2025-10-" + String.format("%02d", i));
|
|
|
-
|
|
|
- int total = (int) (Math.random() * 100) + 50;
|
|
|
- // 总量(闭单量+未闭单量)
|
|
|
- int closed = (int) (Math.random() * total);
|
|
|
- // 闭单量
|
|
|
- int unclosed = total - closed;
|
|
|
- // 未闭单量
|
|
|
-
|
|
|
- dayData.put("total", total);
|
|
|
- dayData.put("closed", closed);
|
|
|
- dayData.put("unclosed", unclosed);
|
|
|
-
|
|
|
- // 随机流程数
|
|
|
- flow.add(dayData);
|
|
|
- }
|
|
|
+ Map<String, Object> dayOnData = new HashMap<>();
|
|
|
+ dayData.put("date", date);
|
|
|
+ dayData.put("value", count);
|
|
|
+ dayOnData.put("date", date);
|
|
|
+ dayOnData.put("total", count);
|
|
|
+ long unclosed = 0;
|
|
|
+ if (dateOnCountMap.get(date) != null) {
|
|
|
+ unclosed = dateOnCountMap.get(date);
|
|
|
+ }
|
|
|
+ long closed = count - unclosed;
|
|
|
+ dayOnData.put("unclosed", unclosed);
|
|
|
+ dayOnData.put("closed", closed);
|
|
|
+ trade.add(dayData);
|
|
|
+ flow.add(dayOnData);
|
|
|
+ });
|
|
|
+
|
|
|
+ result.put("trade", trade);
|
|
|
result.put("flow", flow);
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
@ApiOperation("根据流程ID查询流程列表")
|
|
|
@@ -168,18 +184,23 @@ public class IndexController extends BaseController {
|
|
|
startPage();
|
|
|
FlowsRecord flowsRecord = new FlowsRecord();
|
|
|
flowsRecord.setUpdateBy(flowId + "");
|
|
|
+ flowsRecord.setCreateTime(java.util.Date.from(java.time.LocalDate.now().atStartOfDay(java.time.ZoneId.systemDefault()).toInstant()));
|
|
|
+ flowsRecord.getParams().put("deptId", SecurityUtils.getDeptId());
|
|
|
List<FlowsRecord> list = flowsRecordService.selectFlowsRecordList(flowsRecord);
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("根据流程ID和仓库ID查询流程列表")
|
|
|
@GetMapping("/flows/{flowId}/{houseId}")
|
|
|
- public List<FlowsRecord> flowsHouseList(@PathVariable("flowId") String flowId, @PathVariable("houseId") Long houseId) {
|
|
|
+ public TableDataInfo flowsHouseList(@PathVariable("flowId") String flowId, @PathVariable("houseId") Long
|
|
|
+ houseId) {
|
|
|
+ startPage();
|
|
|
FlowsRecord flowsRecord = new FlowsRecord();
|
|
|
flowsRecord.setUpdateBy(flowId + "");
|
|
|
HouseConfig houseConfig = houseConfigService.selectHouseConfigByHouseId(houseId);
|
|
|
flowsRecord.setHouse(houseConfig.getHouseName());
|
|
|
- return flowsRecordService.selectFlowsRecordList(flowsRecord);
|
|
|
+ List<FlowsRecord> list = flowsRecordService.selectFlowsRecordList(flowsRecord);
|
|
|
+ return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
@ApiOperation("根据仓库ID查询设备列表")
|
|
|
@@ -187,38 +208,4 @@ public class IndexController extends BaseController {
|
|
|
public List<DeviceChannels> device(@PathVariable("houseId") Long houseId) {
|
|
|
return channelsService.findByHouseId(houseId);
|
|
|
}
|
|
|
-
|
|
|
- @ApiOperation("根据仓库ID查询事件统计")
|
|
|
- @GetMapping("/event/{houseId}")
|
|
|
- public Map<String, Object> flow(@PathVariable("houseId") Long houseId) {
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- Map<String, Object> curr = new HashMap<>();
|
|
|
- curr.put("0", 0);
|
|
|
- curr.put("189", 1);
|
|
|
- curr.put("191", 2);
|
|
|
- curr.put("195", 3);
|
|
|
- curr.put("201", 4);
|
|
|
- result.put("curr", curr);
|
|
|
- int today = LocalDate.now().getDayOfMonth();
|
|
|
- List<Map<String, Object>> flow = new ArrayList<>();
|
|
|
- for (int i = 1; i <= today; i++) {
|
|
|
- Map<String, Object> dayData = new HashMap<>();
|
|
|
- dayData.put("date", "2025-10-" + String.format("%02d", i));
|
|
|
- int total = (int) (Math.random() * 100) + 50;
|
|
|
- // 总量(闭单量+未闭单量)
|
|
|
- int closed = (int) (Math.random() * total);
|
|
|
- // 闭单量
|
|
|
- int unclosed = total - closed;
|
|
|
- // 未闭单量
|
|
|
-
|
|
|
- dayData.put("total", total);
|
|
|
- dayData.put("closed", closed);
|
|
|
- dayData.put("unclosed", unclosed);
|
|
|
-
|
|
|
- // 随机流程数
|
|
|
- flow.add(dayData);
|
|
|
- }
|
|
|
- result.put("flow", flow);
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|