xiongchao 3 years ago
parent
commit
a9a8dbf81f

+ 78 - 5
platform-common/src/main/java/com/platform/common/util/DateUtils.java

@@ -6,9 +6,11 @@ import lombok.extern.slf4j.Slf4j;
 import java.text.SimpleDateFormat;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
 import java.time.temporal.Temporal;
 import java.time.temporal.TemporalAdjusters;
 import java.time.temporal.TemporalUnit;
+import java.time.temporal.WeekFields;
 import java.util.*;
 
 
@@ -143,6 +145,51 @@ public class DateUtils {
         return lastDay ;
     }
 
+    /**
+     * 获取某年,某周的第一天
+     *
+     * @param year
+     * @param week
+     * @return
+     */
+    public static LocalDateTime getFirstDayOfWeek(int year, int week) {
+        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
+        LocalDateTime ldt = LocalDateTime.now()
+                .withYear(year)
+                .with(weekFields.weekOfYear(), week)
+                .with(weekFields.dayOfWeek(), 1).withHour(0).withMinute(0).withSecond(0);
+        return ldt;
+    }
+
+    /**
+     * 获取某年,某周的最后一天
+     *
+     * @param year
+     * @param week
+     * @return
+     */
+    public static LocalDateTime getLastDayOfWeek(int year, int week) {
+        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
+        LocalDateTime ldt = LocalDateTime.now()
+                .withYear(year)
+                .with(weekFields.weekOfYear(), week)
+                .with(weekFields.dayOfWeek(), 7).withHour(23).withMinute(59).withSecond(59);
+        return ldt;
+    }
+
+    /**
+     * 获取某年,最后一周的最后一天
+     *
+     * @param year
+     * @return
+     */
+    public static LocalDateTime getLastDayOfWeekOfYear(int year) {
+        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
+        LocalDateTime lastDayOfYear = DateUtils.getLastDayOfThisYear(year);
+        Integer lastWeek = lastDayOfYear.get(weekFields.weekOfYear());
+        return getLastDayOfWeek(year, lastWeek);
+    }
+
     /**
      * 是否是闰年
      *
@@ -334,9 +381,9 @@ public class DateUtils {
     }
 
     public static void main(String[] args) {
-        List<Map<String, LocalDateTime>>  monthStartAndEndList = getMonthStartAndEndByYear(2021,10);
+        List<Map<String, LocalDateTime>>  monthStartAndEndList = getWeekStartAndEndByYear(2021);
         for(Map<String, LocalDateTime> map: monthStartAndEndList){
-            System.out.println(map.get("searchStartTimeMonth").toString() + " : " +  map.get("searchEndTimeMonth").toString());
+            System.out.println(map.get("searchStartTimeWeek").toString() + " : " +  map.get("searchEndTimeWeek").toString());
         }
     }
     /**
@@ -350,7 +397,7 @@ public class DateUtils {
     }
 
     /**
-     * 制定年份,月份之前的每个月的开始时间和结束时间
+     * 指定年份,一直到指定月份的每个月的开始时间和结束时间
      *
      * @param year
      * @param month
@@ -358,9 +405,7 @@ public class DateUtils {
      */
     public static List<Map<String, LocalDateTime>> getMonthStartAndEndByYear(int year, int month) {
         List<Map<String, LocalDateTime>> monthStartAndEndList = new ArrayList<Map<String,LocalDateTime>>();
-        LocalDateTime now = LocalDateTime.now();
         // 每年的 一月一号,零时零分零秒
-        LocalDateTime startDay =  now.withYear(year).with(TemporalAdjusters.firstDayOfYear()).withHour(0).withMinute(0).withSecond(0);
         for(int i = 1;i<month;i++){
             Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
             LocalDateTime searchStartTimeMonth = getFirstDayOfMonth(i);
@@ -372,5 +417,33 @@ public class DateUtils {
         return  monthStartAndEndList;
     }
 
+    /**
+     * 指定年份,每周的开始时间和结束时间
+     *
+     * @param year
+     * @return
+     */
+    public static List<Map<String, LocalDateTime>> getWeekStartAndEndByYear(int year) {
+        List<Map<String, LocalDateTime>> weekStartAndEndList = new ArrayList<Map<String,LocalDateTime>>();
+        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY,1);
+        LocalDate now = LocalDate.now();
+        LocalDateTime firstDayOfYear = DateUtils.getFirstDayOfThisYear(year);
+        LocalDateTime lastDayOfYear = DateUtils.getLastDayOfThisYear(year);
+        //获取第一周和最后一周
+        Integer firstWeek = firstDayOfYear.get(weekFields.weekOfYear());
+        Integer lastWeek = lastDayOfYear.get(weekFields.weekOfYear());
+        // 每年的 一月一号,零时零分零秒
+        for(int i = firstWeek;i<lastWeek;i++){
+            Map<String, LocalDateTime> dateTimeMap = new HashMap<String, LocalDateTime>();
+            LocalDateTime searchStartTimeWeek = getFirstDayOfWeek(year, i);
+            LocalDateTime searchEndTimeWeek = getLastDayOfWeek(year, i);
+            dateTimeMap.put("searchStartTimeWeek", searchStartTimeWeek);
+            dateTimeMap.put("searchEndTimeWeek",searchEndTimeWeek);
+            weekStartAndEndList.add(dateTimeMap);
+        }
+        return  weekStartAndEndList;
+    }
+
+
 }
 

+ 5 - 0
platform-dao/src/main/java/com/platform/dao/dto/repair/RepairApplicationFormDTO.java

@@ -153,6 +153,11 @@ public class RepairApplicationFormDTO extends BaseDTO implements Serializable {
      * 设备停机修复时间:报修类型:1:计划性维修,2非计划性维修,3其他
      */
     private Integer category;
+    /**
+     * 查询列表:报修类型:1:计划性维修,2非计划性维修,3其他,
+     */
+    @Transient
+    private List<Integer> categoryList;
     /**
      * 维修耗时:0否,1是
      */

+ 32 - 0
platform-dao/src/main/java/com/platform/dao/vo/report/CheckJobReportWeekHoursVO.java

@@ -0,0 +1,32 @@
+package com.platform.dao.vo.report;
+
+import com.platform.office.annotation.Excel;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * @author cyz
+ */
+@Data
+@Accessors(chain = true)
+public class CheckJobReportWeekHoursVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 周
+     */
+    @Excel(name = "周", orderNum = "1")
+    private String week;
+    /**
+     * 保养标准工时(小时)
+     */
+    @Excel(name = "保养标准工时", orderNum = "2")
+    private Double totalHours;
+    /**
+     * 可用工时
+     */
+    @Excel(name = "可用工时", orderNum = "3")
+    private Double useHours;
+
+}

+ 26 - 1
platform-rest/src/main/java/com/platform/rest/controller/report/CheckJobReportController.java

@@ -11,6 +11,7 @@ import com.platform.dao.util.ExcelUtil;
 import com.platform.dao.vo.export.check.ExportCheckJobVO;
 import com.platform.dao.vo.query.check.CheckJobVO;
 import com.platform.dao.vo.report.CheckJobReportVO;
+import com.platform.dao.vo.report.CheckJobReportWeekHoursVO;
 import com.platform.dao.vo.report.RepairReport24VO;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.check.CheckJobService;
@@ -55,9 +56,33 @@ public class CheckJobReportController {
      */
     @GetMapping("/export")
     @SysLog("保养任务每月统计报表导出")
-    @PreAuthorize("@pms.hasPermission('repair-application-forms-export')")
     public void export(HttpServletResponse response, CheckJobDTO dto, @RequestParam(defaultValue = "2021") Integer year) {
         List<CheckJobReportVO> list = checkJobService.getMonthReport(dto, year);
         ExcelUtil.exportResponseDict(response, CheckJobReportVO.class, list, year + "年-保养任务统计报表");
     }
+
+    /**
+     * 保养任务每月统计报表导出
+     * @param dto 查询条件
+     * @param year 查询年份
+     * @return R
+     */
+    @SysLog("保养任务周工作负荷统计报表")
+    @GetMapping("week")
+    public R getWeekReportByYear(CheckJobDTO dto, @RequestParam(defaultValue = "2021") Integer year){
+        return new R(checkJobService.getWeekReport(dto, year));
+    }
+
+    /**
+     * 保养任务每月统计报表导出
+     * @param dto 查询条件
+     * @param year 查询年份
+     * @return R
+     */
+    @GetMapping("/week/export")
+    @SysLog("保养任务周工作负荷统计报表")
+    public void exportWeekReportByYear(HttpServletResponse response, CheckJobDTO dto, @RequestParam(defaultValue = "2021") Integer year) {
+        List<CheckJobReportWeekHoursVO> list = checkJobService.getWeekReport(dto, year);
+        ExcelUtil.exportResponseDict(response, CheckJobReportWeekHoursVO.class, list, year + "年-保养任务每周工作负荷统计报表");
+    }
 }

+ 3 - 0
platform-service/src/main/java/com/platform/service/check/CheckJobService.java

@@ -6,6 +6,7 @@ import com.platform.dao.entity.check.CheckJob;
 import com.platform.dao.vo.query.check.CheckJobScreenVO;
 import com.platform.dao.vo.query.check.CheckJobVO;
 import com.platform.dao.vo.report.CheckJobReportVO;
+import com.platform.dao.vo.report.CheckJobReportWeekHoursVO;
 import com.platform.dao.vo.tuicalendar.TuiCalendar;
 import com.platform.service.base.IBaseService;
 
@@ -120,4 +121,6 @@ public interface CheckJobService extends IBaseService<CheckJob, CheckJobDTO> {
     int countTask(String sbId, String userId, Integer type, Integer searchType);
     int countSbUserTask(String sbId, String userId, Integer type);
     List<CheckJobReportVO> getMonthReport(CheckJobDTO checkJobDTO, Integer month);
+
+    List<CheckJobReportWeekHoursVO> getWeekReport(CheckJobDTO checkJobDTO, Integer month);
 }

+ 52 - 7
platform-service/src/main/java/com/platform/service/check/impl/CheckJobServiceImpl.java

@@ -24,7 +24,9 @@ import com.platform.dao.vo.SysUserVO;
 import com.platform.dao.vo.query.check.*;
 import com.platform.dao.vo.repair.RepairApplicationFormVO;
 import com.platform.dao.vo.report.CheckJobReportVO;
+import com.platform.dao.vo.report.CheckJobReportWeekHoursVO;
 import com.platform.dao.vo.report.RepairReport24VO;
+import com.platform.dao.vo.report.RepairReportMttr;
 import com.platform.dao.vo.sb.SbInfoVO;
 import com.platform.dao.vo.tuicalendar.TuiCalendar;
 import com.platform.dao.vo.tuicalendar.TuiCalendarUtil;
@@ -1173,17 +1175,16 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
 
         // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
         int month = localDate.getMonthValue() + 1;
+        if(searchYear<year){
+            month = 12;
+            year = searchYear;
+        }
         List<Map<String, LocalDateTime>> monthStartAndEndList = DateUtils.getMonthStartAndEndByYear(year, month);
         LocalDateTime searchStartTime = null;
         LocalDateTime searchEndTime = null;
         // 当前年份只统计到当前月,历史年份统计全年
-        if(year == searchYear){
-            searchStartTime = DateUtils.getFirstDayOfThisYear(year);
-            searchEndTime = DateUtils.getLastDayOfMonth(month);
-        }else{
-            searchStartTime = DateUtils.getFirstDayOfThisYear(searchYear);
-            searchEndTime = DateUtils.getLastDayOfThisYear(searchYear);
-        }
+        searchStartTime = DateUtils.getFirstDayOfThisYear(year);
+        searchEndTime = DateUtils.getLastDayOfMonth(month);
 
         // 总数
         Weekend<CheckJob> weekend = new Weekend<>(CheckJob.class);
@@ -1221,4 +1222,48 @@ public class CheckJobServiceImpl extends BaseServiceImpl<CheckJobMapper, CheckJo
         }
         return result;
     }
+
+    @Override
+    public List<CheckJobReportWeekHoursVO> getWeekReport(CheckJobDTO checkJobDTO, Integer searchYear) {
+        List<Map<String, LocalDateTime>> monthStartAndEndList = DateUtils.getWeekStartAndEndByYear(searchYear);
+        LocalDateTime searchStartTime = null;
+        LocalDateTime searchEndTime = null;
+        // 统计全年,全年不一定是1号到最后一号,有可能是上一年的某一天使这年的第一周的第一天
+        searchStartTime = DateUtils.getFirstDayOfWeek(searchYear, 1);
+        searchEndTime = DateUtils.getLastDayOfWeekOfYear(searchYear);
+
+        // 总数
+        Weekend<CheckJob> weekend = new Weekend<>(CheckJob.class);
+        WeekendCriteria<CheckJob, Object> weekendCriteria = weekend.weekendCriteria();
+        weekendCriteria.andBetween(CheckJob::getStartTime, searchStartTime, searchEndTime);
+        checkJobDTO.setSearchStartTime(searchStartTime);
+        checkJobDTO.setSearchEndTime(searchEndTime);
+        checkJobDTO.setType(CheckStandardTypeEnum.POLLING.getValue());
+        List<CheckJobVO> list = mapper.selectList(checkJobDTO);
+        List<CheckJobReportWeekHoursVO> result = new ArrayList<CheckJobReportWeekHoursVO>();
+        int i = 1;
+        for(Map<String, LocalDateTime> map: monthStartAndEndList){
+            CheckJobReportWeekHoursVO vo = new CheckJobReportWeekHoursVO();
+            vo.setWeek((i++) + "周");
+            double totalHours = 0;
+            for(CheckJobVO checkJob: list){
+                System.out.println("checkJob.getStandardHours(): " + checkJob.getStandardHours());
+                if(checkJob.getStartTime().isAfter(map.get("searchStartTimeWeek").toLocalDate()) && checkJob.getStartTime().isBefore(map.get("searchEndTimeWeek").toLocalDate())){
+                    String standardHours = checkJob.getStandardHours();
+                    if(StringUtils.isBlank(checkJob.getStandardHours())){
+                        continue;
+                    }else{
+                        totalHours = totalHours + Double.valueOf(standardHours);
+                        System.out.println("totalHours: " + totalHours);
+                    }
+                }
+            }
+            vo.setTotalHours(totalHours);
+            result.add(vo);
+        }
+        for(CheckJobReportWeekHoursVO r: result){
+            System.out.println(r.toString());
+        }
+        return result;
+    }
 }

+ 14 - 16
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -698,17 +698,17 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
 
         // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
         int month = localDate.getMonthValue() + 1;
+        if(searchYear<year){
+            month = 12;
+            year = searchYear;
+        }
         List<Map<String, LocalDateTime>> monthStartAndEndList = DateUtils.getMonthStartAndEndByYear(year, month);
         LocalDateTime searchStartTime = null;
         LocalDateTime searchEndTime = null;
         // 当前年份只统计到当前月,历史年份统计全年
-        if(year == searchYear){
-            searchStartTime = DateUtils.getFirstDayOfThisYear(year);
-            searchEndTime = DateUtils.getLastDayOfMonth(month);
-        }else{
-            searchStartTime = DateUtils.getFirstDayOfThisYear(searchYear);
-            searchEndTime = DateUtils.getLastDayOfThisYear(searchYear);
-        }
+        searchStartTime = DateUtils.getFirstDayOfThisYear(year);
+        searchEndTime = DateUtils.getLastDayOfMonth(month);
+
         // 选择非计划性的订单
         if(type == 1){
             repairApplicationFormDTO.setCategory(RepairApplicationFormCategoryEnum.PLAN_NOT.getValue());
@@ -756,8 +756,6 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
      *
      * @param repairApplicationFormDTO
      * @param searchYear 查询年份
-     * @param type  1:大于24的非计划性维修
-     *              2:所有类型维修,不限维修时间,包括计划性和非计划性,单不包括其他(如:布线等完善性维修)
      * @return
      */
     @Override
@@ -767,17 +765,17 @@ public class RepairApplicationFormServiceImpl extends BaseServiceImpl<RepairAppl
 
         // 如2021-10-15号码,则month=10,需要计算到11月份,需要加1
         int month = localDate.getMonthValue() + 1;
+        if(searchYear<year){
+            month = 12;
+            year = searchYear;
+        }
         List<Map<String, LocalDateTime>> monthStartAndEndList = DateUtils.getMonthStartAndEndByYear(year, month);
         LocalDateTime searchStartTime = null;
         LocalDateTime searchEndTime = null;
         // 当前年份只统计到当前月,历史年份统计全年
-        if(year == searchYear){
-            searchStartTime = DateUtils.getFirstDayOfThisYear(year);
-            searchEndTime = DateUtils.getLastDayOfMonth(month);
-        }else{
-            searchStartTime = DateUtils.getFirstDayOfThisYear(searchYear);
-            searchEndTime = DateUtils.getLastDayOfThisYear(searchYear);
-        }
+        searchStartTime = DateUtils.getFirstDayOfThisYear(year);
+        searchEndTime = DateUtils.getLastDayOfMonth(month);
+
         // 选择非计划性的订单
         List<Integer> categoryList = new ArrayList<Integer>();
         categoryList.add(RepairApplicationFormCategoryEnum.PLAN_NOT.getValue());