zhangherong
2025-05-06 665ffec07abac9fa14e7613fe1c73922a537ff77
art: 设备管理-看板接口-维修统计接口
已重命名1个文件
已添加1个文件
已修改6个文件
252 ■■■■■ 文件已修改
lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/EamReportRepairMapper.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/EamReportRepairMapper.xml 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamReportRepairService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/vo/EquipmentRepairStatistics.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/vo/EquipmentStatusStatistics.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java
@@ -6,11 +6,10 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.time.format.DateTimeFormatter;
import java.util.*;
import org.jeecg.common.constant.SymbolConstant;
import org.springframework.util.StringUtils;
@@ -783,4 +782,91 @@
    public static Date localDateToDate(LocalDate localDate) {
        return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    }
    /**
     * èŽ·å–æœ¬æœˆç¬¬ä¸€å¤©
     *
     * @return
     */
    public static LocalDate getFirstOfMonth() {
        LocalDate localDate = LocalDate.now();
        return localDate.withDayOfMonth(1);
    }
    /**
     * èŽ·å–æœ¬æœˆç¬¬ä¸€å¤©
     *
     * @return
     */
    public static LocalDate getFirstOfMonth(LocalDate localDate) {
        return localDate.withDayOfMonth(1);
    }
    /**
     * èŽ·å–ä¸¤ä¸ªæœˆä»½ä¸­é—´çš„æ‰€æœ‰æœˆä»½ï¼ŒåŒ…å«å¼€å§‹å’Œç»“æŸæœˆä»½
     *
     * @param startMonth
     * @param endMonth
     * @return
     */
    public static List<String> getMonthsBetween(String startMonth, String endMonth) {
        List<String> months = new ArrayList<>();
        // å®šä¹‰æ—¥æœŸæ ¼å¼
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        // è§£æžèµ·å§‹å’Œç»“束月份
        YearMonth start = YearMonth.parse(startMonth, formatter);
        YearMonth end = YearMonth.parse(endMonth, formatter);
        // ç¡®ä¿start <= end å¦‚果不是 åˆ™è¿›è¡Œäº¤æ¢
        if (start.isAfter(end)) {
            YearMonth temp = start;
            start = end;
            end = temp;
        }
        // å¾ªçŽ¯æ·»åŠ æœˆä»½
        YearMonth current = start;
        while (!current.isAfter(end)) {
            months.add(current.format(formatter));
            current = current.plusMonths(1);
        }
        return months;
    }
    /**
     * èŽ·å–ä¸¤ä¸ªæœˆä»½ä¸­é—´çš„æ‰€æœ‰æœˆä»½ï¼ŒåŒ…å«å¼€å§‹å’Œç»“æŸæœˆä»½
     *
     * @param startMonth
     * @param endMonth
     * @return
     */
    public static List<String> getMonthsBetween(LocalDate startMonth, LocalDate endMonth) {
        List<String> months = new ArrayList<>();
        // å®šä¹‰æ—¥æœŸæ ¼å¼
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        // è§£æžèµ·å§‹å’Œç»“束月份
        YearMonth start = YearMonth.of(startMonth.getYear(), startMonth.getMonth());
        YearMonth end = YearMonth.of(endMonth.getYear(), endMonth.getMonth());
        // ç¡®ä¿start <= end å¦‚果不是 åˆ™è¿›è¡Œäº¤æ¢
        if (start.isAfter(end)) {
            YearMonth temp = start;
            start = end;
            end = temp;
        }
        // å¾ªçŽ¯æ·»åŠ æœˆä»½
        YearMonth current = start;
        while (!current.isAfter(end)) {
            months.add(current.format(formatter));
            current = current.plusMonths(1);
        }
        return months;
    }
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamDashboardController.java
@@ -4,21 +4,22 @@
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus;
import org.jeecg.modules.eam.constant.EquipmentRepairStatus;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.eam.service.IEamEquipmentService;
import org.jeecg.modules.eam.vo.EquipmentMaintenanceStatistics;
import org.jeecg.modules.eam.service.IEamReportRepairService;
import org.jeecg.modules.eam.vo.EquipmentRepairStatistics;
import org.jeecg.modules.eam.vo.EquipmentStatusStatistics;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import java.util.*;
@Slf4j
@Api(tags="设备管理-首页看板接口")
@@ -27,17 +28,19 @@
public class EamDashboardController {
    @Autowired
    private IEamEquipmentService eamEquipmentService;
    @Autowired
    private IEamReportRepairService reportRepairService;
    @ApiOperation(value="看板接口-维保状态统计", notes="看板接口-维保状态统计")
    @GetMapping(value = "/equipmentStatusStatistics")
    public Result<?> equipmentStatusStatistics(@RequestParam(required = false, value = "productionId") String productionId) {
        List<EamEquipment> list = eamEquipmentService.queryByProductionId(productionId);
        //初始化返回
        Map<String, EquipmentMaintenanceStatistics> statisticsMap = new HashMap<>();
        statisticsMap.put(EquipmentMaintenanceStatus.NORMAL.name(), new EquipmentMaintenanceStatistics(EquipmentMaintenanceStatus.NORMAL.name(), "正常"));
        statisticsMap.put(EquipmentMaintenanceStatus.UNDER_INSPECTION.name(), new EquipmentMaintenanceStatistics(EquipmentMaintenanceStatus.UNDER_INSPECTION.name(), "点检"));
        statisticsMap.put(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name(), new EquipmentMaintenanceStatistics(EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name(), "保养"));
        statisticsMap.put(EquipmentRepairStatus.UNDER_REPAIR.name(), new EquipmentMaintenanceStatistics(EquipmentRepairStatus.UNDER_REPAIR.name(), "ç»´ä¿®"));
        Map<String, EquipmentStatusStatistics> statisticsMap = new HashMap<>();
        statisticsMap.put(EquipmentMaintenanceStatus.NORMAL.name(), new EquipmentStatusStatistics(EquipmentMaintenanceStatus.NORMAL.name(), "正常"));
        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())) {
@@ -53,7 +56,35 @@
                statisticsMap.get(EquipmentMaintenanceStatus.UNDER_INSPECTION.name()).increase();
            }
        }
        List<EquipmentMaintenanceStatistics> resultList = new ArrayList<>(statisticsMap.values());
        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);
    }
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/EamReportRepairMapper.java
@@ -1,11 +1,12 @@
package org.jeecg.modules.eam.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.eam.entity.EamReportRepair;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.vo.EquipmentRepairStatistics;
import java.util.List;
@@ -25,4 +26,13 @@
     * @return
     */
    IPage<EamReportRepair> pageList(Page<EamReportRepair> page, @Param("eamReportRepair") EamReportRepairQuery eamReportRepairQuery, @Param("userId") String userId, @Param("equipmentIds") List<String> equipmentIds);
    /**
     * ç»Ÿè®¡ç»´ä¿®
     * @param productionIds ä½¿ç”¨è½¦é—´ ids
     * @param start ç»Ÿè®¡å¼€å§‹æ—¥æœŸ
     * @param end ç»Ÿè®¡ç»“束日期
     * @return
     */
    List<EquipmentRepairStatistics> equipmentRepairStatistics(@Param("productionIds") List<String> productionIds, @Param("start") String start, @Param("end") String end);
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/EamReportRepairMapper.xml
@@ -48,4 +48,23 @@
        </where>
        ORDER BY t1.create_time DESC
    </select>
    <select id="equipmentRepairStatistics" resultType="org.jeecg.modules.eam.vo.EquipmentRepairStatistics">
        select FORMAT(err.create_time, 'yyyy-MM') as monthStr,
               COUNT(1) as reportNumber,
               SUM(CASE WHEN err.report_status = 'COMPLETE' THEN 1 ELSE 0 END) as repairedNumber
        from eam_report_repair err
        inner join eam_equipment e
        on err.equipment_id = e.id
        where err.report_status != 'ABOLISH' and err.del_flag = 0 and e.del_flag = 0
        <if test="productionIds != null">
            AND e.org_id IN
            <foreach collection="productionIds" item="productionId" index="index" open="(" close=")" separator=",">
                #{productionId}
            </foreach>
        </if>
        and err.create_time &gt;= #{start}
        and err.create_time &lt; #{end}
        group by FORMAT(err.create_time, 'yyyy-MM')
    </select>
</mapper>
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamReportRepairService.java
@@ -7,7 +7,9 @@
import org.jeecg.modules.eam.entity.EamReportRepair;
import org.jeecg.modules.eam.entity.EamWeekMaintenanceOrderDetail;
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.vo.EquipmentRepairStatistics;
import java.time.LocalDate;
import java.util.List;
/**
@@ -54,4 +56,12 @@
     */
    boolean edit(EamReportRepair eamReportRepair);
    /**
     * æŸ¥è¯¢æŠ¥ä¿®åˆ—表
     * @param productionId
     * @param firstOfMonth
     * @param today
     * @return
     */
    List<EquipmentRepairStatistics> equipmentRepairStatistics(String productionId, LocalDate firstOfMonth, LocalDate today);
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamReportRepairServiceImpl.java
@@ -1,5 +1,7 @@
package org.jeecg.modules.eam.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -16,11 +18,15 @@
import org.jeecg.modules.eam.request.EamReportRepairQuery;
import org.jeecg.modules.eam.service.IEamEquipmentExtendService;
import org.jeecg.modules.eam.service.IEamReportRepairService;
import org.jeecg.modules.eam.vo.EquipmentRepairStatistics;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.*;
/**
@@ -33,6 +39,8 @@
    @Resource
    private IEamEquipmentExtendService eamEquipmentExtendService;
    @Autowired
    private IMdcProductionService mdcProductionService;
    /**
     * åˆ†é¡µåˆ—表
@@ -148,4 +156,25 @@
        this.baseMapper.updateById(eamReportRepair);
        return true;
    }
    @Override
    public List<EquipmentRepairStatistics> equipmentRepairStatistics(String productionId, LocalDate firstOfMonth, LocalDate today) {
        if (StringUtils.isNotBlank(productionId)) {
            //车间编码不为空
            List<String> productIds = mdcProductionService.recursionChildren(productionId);
            if (CollectionUtil.isEmpty(productIds)) {
                return Collections.emptyList();
            }
            List<EquipmentRepairStatistics> list = this.baseMapper.equipmentRepairStatistics(productIds, firstOfMonth.toString(), today.plusDays(1).toString());
            if (CollectionUtil.isEmpty(list)) {
                return Collections.emptyList();
            }
            return list;
        }
        List<EquipmentRepairStatistics> list = this.baseMapper.equipmentRepairStatistics(null, firstOfMonth.toString(), today.plusDays(1).toString());
        if (CollectionUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list;
    }
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/vo/EquipmentRepairStatistics.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,29 @@
package org.jeecg.modules.eam.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class EquipmentRepairStatistics implements Serializable {
    /**
     * æœˆä»½
     */
    private String monthStr;
    /**
     * æŠ¥ä¿®æ•°
     */
    private Integer reportNumber;
    /**
     * ç»´ä¿®æ•°
     */
    private Integer repairedNumber;
    public EquipmentRepairStatistics(){}
    public EquipmentRepairStatistics(String monthStr){
        this.monthStr = monthStr;
        this.reportNumber = 0;
        this.repairedNumber = 0;
    }
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/vo/EquipmentStatusStatistics.java
ÎļþÃû´Ó lxzn-module-eam/src/main/java/org/jeecg/modules/eam/vo/EquipmentMaintenanceStatistics.java ÐÞ¸Ä
@@ -8,7 +8,7 @@
 * è®¾å¤‡ç»´ä¿çŠ¶æ€ç»Ÿè®¡
 */
@Data
public class EquipmentMaintenanceStatistics implements Serializable {
public class EquipmentStatusStatistics implements Serializable {
    /**
     * çŠ¶æ€
     */
@@ -23,9 +23,9 @@
     */
    private String statusText;
    public EquipmentMaintenanceStatistics() {}
    public EquipmentStatusStatistics() {}
    public EquipmentMaintenanceStatistics(String status, String statusText) {
    public EquipmentStatusStatistics(String status, String statusText) {
        this.status = status;
        this.statusText = statusText;
    }