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 >= #{start} and err.create_time < #{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; }