From d84d8515ada523c06140bec02f3f89e53eebca14 Mon Sep 17 00:00:00 2001
From: Houjie <714924425@qq.com>
Date: 星期五, 11 七月 2025 14:58:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java |  279 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 278 insertions(+), 1 deletions(-)

diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java
index 00f3bf7..c2e132f 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java
@@ -1,14 +1,291 @@
 package org.jeecg.modules.eam.controller;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.parser.Feature;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.common.util.TranslateDictTextUtils;
+import org.jeecg.modules.eam.constant.*;
+import org.jeecg.modules.eam.entity.EamEquipment;
+import org.jeecg.modules.eam.entity.EamInspectionOrder;
+import org.jeecg.modules.eam.entity.EamRepairOrder;
+import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrder;
+import org.jeecg.modules.eam.service.*;
+import org.jeecg.modules.eam.vo.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.util.*;
+
 @Slf4j
-@Api(tags="璁惧绠$悊-棣栭〉鐪嬫澘鎺ュ彛")
+@Api(tags = "璁惧绠$悊-棣栭〉鐪嬫澘鎺ュ彛")
 @RestController
 @RequestMapping("/eam/dashboard")
 public class EamDashboardController {
+    @Autowired
+    private IEamEquipmentService eamEquipmentService;
+    @Autowired
+    private IEamReportRepairService reportRepairService;
+    @Autowired
+    private IEamInspectionOrderService inspectionOrderService;
+    @Autowired
+    private IEamWeekMaintenanceOrderService weekMaintenanceOrderService;
+    @Resource
+    private ObjectMapper objectMapper;
+    @Resource
+    private TranslateDictTextUtils translateDictTextUtils;
+    @Autowired
+    private IEamRepairOrderService repairOrderService;
 
+
+    @ApiOperation(value = "鐪嬫澘鎺ュ彛-缁翠繚鐘舵�佺粺璁�", notes = "鐪嬫澘鎺ュ彛-缁翠繚鐘舵�佺粺璁�")
+    @GetMapping(value = "/equipmentStatusStatistics")
+    public Result<?> equipmentStatusStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
+        List<EamEquipment> list = eamEquipmentService.queryByProductionId(productionId);
+        //鍒濆鍖栬繑鍥�
+        Map<String, EquipmentStatusStatistics> statisticsMap = new HashMap<>();
+        statisticsMap.put(EquipmentMaintenanceStatus.NORMAL.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.NORMAL.name(), "姝e父"));
+        statisticsMap.put(EquipmentMaintenanceStatus.UNDER_INSPECTION.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.UNDER_INSPECTION.name(), "鐐规"));
+        statisticsMap.put(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name(), "淇濆吇"));
+        statisticsMap.put(EquipmentRepairStatus.UNDER_REPAIR.name(), new EquipmentStatusStatistics(EquipmentRepairStatus.UNDER_REPAIR.name(), "缁翠慨"));
+
+        for (EamEquipment entity : list) {
+            if (EquipmentMaintenanceStatus.NORMAL.name().equals(entity.getMaintenanceStatus()) && EquipmentMaintenanceStatus.NORMAL.name().equals(entity.getRepairStatus())) {
+                //姝e父鐘舵��
+                statisticsMap.get(EquipmentMaintenanceStatus.NORMAL.name()).increase();
+            } else if (!EquipmentMaintenanceStatus.NORMAL.name().equals(entity.getRepairStatus())) {
+                //缁翠慨鐘舵��
+                statisticsMap.get(EquipmentRepairStatus.UNDER_REPAIR.name()).increase();
+            } else if (EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name().equals(entity.getMaintenanceStatus()) || EquipmentMaintenanceStatus.WAIT_CONFIRM.name().equals(entity.getMaintenanceStatus())) {
+                //淇濆吇鐘舵��
+                statisticsMap.get(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name()).increase();
+            } else {
+                statisticsMap.get(EquipmentMaintenanceStatus.UNDER_INSPECTION.name()).increase();
+            }
+        }
+        List<EquipmentStatusStatistics> resultList = new ArrayList<>(statisticsMap.values());
+        return Result.ok(resultList);
+    }
+
+    @ApiOperation(value = "鐪嬫澘鎺ュ彛-缁翠慨缁熻", notes = "鐪嬫澘鎺ュ彛-缁翠慨缁熻")
+    @GetMapping(value = "/equipmentRepairStatistics")
+    public Result<?> equipmentRepairStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
+        //缁熻缁撴潫鏃ユ湡
+        LocalDate today = LocalDate.now();
+        LocalDate localDate = today.minusMonths(5);
+        //缁熻寮�濮嬫棩鏈�
+        LocalDate firstOfMonth = DateUtils.getFirstOfMonth(localDate);
+
+        //鍒濆鍖栬繑鍥炲��
+        Map<String, EquipmentRepairStatistics> statisticsMap = new HashMap<>();
+        List<String> monthsBetween = DateUtils.getMonthsBetween(firstOfMonth, today);
+        monthsBetween.forEach(month -> {
+            statisticsMap.put(month, new EquipmentRepairStatistics(month));
+        });
+
+        List<EquipmentRepairStatistics> list = reportRepairService.equipmentRepairStatistics(productionId, firstOfMonth, today);
+        for (EquipmentRepairStatistics statistics : list) {
+            if (statisticsMap.containsKey(statistics.getMonthStr())) {
+                statisticsMap.put(statistics.getMonthStr(), statistics);
+            }
+        }
+        List<EquipmentRepairStatistics> resultList = new ArrayList<>(statisticsMap.values());
+        //鎺掑簭
+        resultList.sort(Comparator.comparing(EquipmentRepairStatistics::getMonthStr));
+        return Result.ok(resultList);
+    }
+
+    @ApiOperation(value = "鐪嬫澘鎺ュ彛-鐐规缁熻", notes = "鐪嬫澘鎺ュ彛-鐐规缁熻")
+    @GetMapping(value = "/equipmentInspectionStatistics")
+    public Result<?> equipmentInspectionStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
+        //缁熻缁撴潫鏃ユ湡
+        LocalDate today = LocalDate.now();
+        LocalDate localDate = today.minusMonths(5);
+        //缁熻寮�濮嬫棩鏈�
+        LocalDate firstOfMonth = DateUtils.getFirstOfMonth(localDate);
+
+        //鍒濆鍖栬繑鍥炲��
+        Map<String, EquipmentInspectionStatistics> statisticsMap = new HashMap<>();
+        List<String> monthsBetween = DateUtils.getMonthsBetween(firstOfMonth, today);
+        monthsBetween.forEach(month -> {
+            statisticsMap.put(month, new EquipmentInspectionStatistics(month));
+        });
+
+        List<EquipmentInspectionStatistics> list = inspectionOrderService.equipmentInspectionStatistics(productionId, firstOfMonth, today);
+        for (EquipmentInspectionStatistics statistics : list) {
+            if (statisticsMap.containsKey(statistics.getMonthStr())) {
+                statisticsMap.put(statistics.getMonthStr(), statistics);
+            }
+        }
+        List<EquipmentInspectionStatistics> resultList = new ArrayList<>(statisticsMap.values());
+        //鎺掑簭
+        resultList.sort(Comparator.comparing(EquipmentInspectionStatistics::getMonthStr));
+        return Result.ok(resultList);
+    }
+
+    @ApiOperation(value = "鐪嬫澘鎺ュ彛-鍛ㄤ繚缁熻", notes = "鐪嬫澘鎺ュ彛-鍛ㄤ繚缁熻")
+    @GetMapping(value = "/equipmentMaintenanceStatistics")
+    public Result<?> equipmentMaintenanceStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
+        //缁熻缁撴潫鏃ユ湡
+        LocalDate today = LocalDate.now();
+        LocalDate localDate = today.minusMonths(5);
+        //缁熻寮�濮嬫棩鏈�
+        LocalDate firstOfMonth = DateUtils.getFirstOfMonth(localDate);
+
+        //鍒濆鍖栬繑鍥炲��
+        Map<String, EquipmentMaintenanceStatistics> statisticsMap = new HashMap<>();
+        List<String> monthsBetween = DateUtils.getMonthsBetween(firstOfMonth, today);
+        monthsBetween.forEach(month -> {
+            statisticsMap.put(month, new EquipmentMaintenanceStatistics(month));
+        });
+
+        List<EquipmentMaintenanceStatistics> list = weekMaintenanceOrderService.equipmentMaintenanceStatistics(productionId, firstOfMonth, today);
+        for (EquipmentMaintenanceStatistics statistics : list) {
+            if (statisticsMap.containsKey(statistics.getMonthStr())) {
+                statisticsMap.put(statistics.getMonthStr(), statistics);
+            }
+        }
+        List<EquipmentMaintenanceStatistics> resultList = new ArrayList<>(statisticsMap.values());
+        //鎺掑簭
+        resultList.sort(Comparator.comparing(EquipmentMaintenanceStatistics::getMonthStr));
+        return Result.ok(resultList);
+    }
+
+    @ApiOperation(value = "缁翠慨鐪嬫澘-缁翠慨鐘舵�佺粺璁�", notes = "缁翠慨鐪嬫澘-缁翠慨鐘舵�佺粺璁�")
+    @GetMapping(value = "/repairStatusStatistics")
+    public Result<?> repairStatusStatistics() {
+        EquipmentRepairStatusStatistics statistics = reportRepairService.repairStatusStatistics();
+        return Result.OK(statistics);
+    }
+
+    @ApiOperation(value = "缁翠慨鐪嬫澘-缁翠慨鍒楄〃", notes = "缁翠慨鐪嬫澘-缁翠慨鍒楄〃")
+    @GetMapping(value = "/repairList")
+    public Result<?> repairList() {
+        List<EquipmentRepairListVO> list = reportRepairService.repairList();
+        if (CollectionUtil.isEmpty(list)) {
+            return Result.ok(Collections.emptyList());
+        }
+        List<JSONObject> items = new ArrayList<>();
+        try {
+            for (EquipmentRepairListVO vo : list) {
+                String json = objectMapper.writeValueAsString(vo);
+                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
+                translateDictTextUtils.translateField("reportOperator", vo.getReportOperator(), item, "sys_user,realname,username");
+                translateDictTextUtils.translateField("repairOperator", vo.getRepairOperator(), item, "sys_user,realname,username");
+                translateDictTextUtils.translateField("reportStatus", vo.getReportStatus(), item, "report_repair_status");
+                translateDictTextUtils.translateField("orgId", vo.getOrgId(), item, "mdc_production,production_name,id");
+                items.add(item);
+            }
+            return Result.OK(items);
+        } catch (Exception e) {
+            return Result.error("鏁版嵁杞瘧澶辫触锛�");
+        }
+    }
+
+    @ApiOperation(value = "缁翠慨鐪嬫澘-缁翠慨宸ユ帓鍚�", notes = "缁翠慨鐪嬫澘-缁翠慨宸ユ帓鍚�")
+    @GetMapping(value = "/repairmanRanking")
+    public Result<?> repairmanRanking() {
+        LocalDate today = LocalDate.now();
+        LocalDate end = today.plusDays(1);
+        LocalDate start = today.minusDays(30);
+        //鍙彇鍓�7鍚�
+        List<RepairmanRankingVO> list = repairOrderService.repairmanRanking(start.toString(), end.toString());
+        if (CollectionUtil.isEmpty(list)) {
+            return Result.ok(Collections.emptyList());
+        }
+        if (list.size() > 7) {
+            list = list.subList(0, 7);
+        }
+        List<JSONObject> items = new ArrayList<>();
+        try {
+            for (RepairmanRankingVO vo : list) {
+                String json = objectMapper.writeValueAsString(vo);
+                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
+                translateDictTextUtils.translateField("repairer", vo.getRepairer(), item, "sys_user,realname,username");
+                items.add(item);
+            }
+            return Result.OK(items);
+        } catch (Exception e) {
+            return Result.error("鏁版嵁杞瘧澶辫触锛�");
+        }
+    }
+
+    @ApiOperation(value = "缁翠慨鐪嬫澘-鏁呴殰绫诲瀷缁熻", notes = "缁翠慨鐪嬫澘-鏁呴殰绫诲瀷缁熻")
+    @GetMapping(value = "/faultTypeStatistics")
+    public Result<?> faultTypeStatistics() {
+        //缁熻浠婂勾鏉ユ晠闅滃垎绫绘儏鍐�
+        LocalDate today = LocalDate.now();
+        LocalDate end = today.plusDays(1);
+        //浠婂勾绗竴澶�
+        LocalDate start = today.withDayOfYear(1);
+        // 缁熻涓暟
+        List<FaultTypeStatisticsVO> list = reportRepairService.faultTypeStatistics(start.toString(), end.toString());
+        if (CollectionUtil.isEmpty(list)) {
+            return Result.ok(Collections.emptyList());
+        }
+        List<JSONObject> items = new ArrayList<>();
+        try {
+            for (FaultTypeStatisticsVO vo : list) {
+                String json = objectMapper.writeValueAsString(vo);
+                JSONObject item = JSONObject.parseObject(json, Feature.OrderedField);
+                translateDictTextUtils.translateField("faultType", vo.getFaultType(), item, "fault_reason_category");
+                if (item.get("faultType" + CommonConstant.DICT_TEXT_SUFFIX) != null) {
+                    items.add(item);
+                }
+            }
+            return Result.OK(items);
+        } catch (Exception e) {
+            return Result.error("鏁版嵁杞瘧澶辫触锛�");
+        }
+    }
+
+    @ApiOperation(value = "H5棣栭〉-寰呮墽琛屽伐鍗曟暟閲忕粺璁�", notes = "H5棣栭〉-寰呮墽琛屽伐鍗曟暟閲忕粺璁�")
+    @GetMapping(value = "/pendingExecOrderCountBySelf")
+    public Result<?> pendingExecOrderCountBySelf() {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        String post = user.getPost();
+        Map<String, Integer> countMap = CollectionUtil.newHashMap();
+        if (BusinessCodeConst.PCR0001.equals(post)) {
+            //鏄搷浣滃伐锛屾煡璇㈠緟鐐规宸ュ崟銆佸緟鍛ㄤ繚宸ュ崟
+            List<EamInspectionOrder> unExecInspectionOrderList = inspectionOrderService.list(new LambdaQueryWrapper<EamInspectionOrder>()
+                    .eq(EamInspectionOrder::getOperator, user.getUsername())
+                    .eq(EamInspectionOrder::getInspectionStatus, InspectionStatus.UNDER_INSPECTION.name())
+                    .eq(EamInspectionOrder::getDelFlag, CommonConstant.DEL_FLAG_0));
+            List<EamWeekMaintenanceOrder> unExecMaintenanceOrderList = weekMaintenanceOrderService.list(new LambdaQueryWrapper<EamWeekMaintenanceOrder>()
+                    .eq(EamWeekMaintenanceOrder::getOperator, user.getUsername())
+                    .eq(EamWeekMaintenanceOrder::getMaintenanceStatus, WeekMaintenanceStatusEnum.UNDER_MAINTENANCE.name())
+                    .eq(EamWeekMaintenanceOrder::getDelFlag, CommonConstant.DEL_FLAG_0));
+            countMap.put("unExecInspectionOrderCount", unExecInspectionOrderList.size());
+            countMap.put("unExecMaintenanceOrderCount", unExecMaintenanceOrderList.size());
+            countMap.put("unExecRepairOrderCount", 0);
+        } else if (BusinessCodeConst.PCR0002.equals(post)) {
+            //鏄淮淇伐锛屾煡璇㈠緟缁翠慨宸ュ崟
+            List<EamRepairOrder> unExecRepairOrderList = repairOrderService.list(new LambdaQueryWrapper<EamRepairOrder>()
+                    .eq(EamRepairOrder::getRepairer, user.getUsername())
+                    .eq(EamRepairOrder::getRepairStatus, EquipmentRepairStatus.UNDER_REPAIR.name())
+                    .eq(EamRepairOrder::getDelFlag, CommonConstant.DEL_FLAG_0));
+            countMap.put("unExecInspectionOrderCount", 0);
+            countMap.put("unExecMaintenanceOrderCount", 0);
+            countMap.put("unExecRepairOrderCount", unExecRepairOrderList.size());
+        } else {
+            countMap.put("unExecInspectionOrderCount", 0);
+            countMap.put("unExecMaintenanceOrderCount", 0);
+            countMap.put("unExecRepairOrderCount", 0);
+        }
+        return Result.OK(countMap);
+    }
 }

--
Gitblit v1.9.3