Ver Fonte

报表-平均工时

guarantee-lsq há 2 semanas atrás
pai
commit
775d9a843c

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

@@ -383,4 +383,6 @@ public class RepairApplicationFormDTO extends BaseDTO implements Serializable {
      * 转派历史
      */
     private String repairTransferList;
+
+    private String yearMonth; // 输入年月  yyyy-MM
 }

+ 7 - 0
platform-dao/src/main/java/com/platform/dao/mapper/repair/RepairApplicationFormMapper.java

@@ -76,4 +76,11 @@ public interface RepairApplicationFormMapper extends MyMapper<RepairApplicationF
     List<RepairApplicationFormVO> selectWorkHourDetail(RepairApplicationFormDTO dto);
 
     String selectMaxNo(RepairApplicationFormDTO dto);
+
+    /**
+     * 按月统计每个设备的平均维修工时
+     * @param dto
+     * @return
+     */
+    List<RepairWorkHourReportVO> statisticsWorkHourByMonth(RepairApplicationFormDTO dto);
 }

+ 35 - 0
platform-dao/src/main/resources/mapper/repair/RepairApplicationFormMapper.xml

@@ -286,4 +286,39 @@
             </if>
         </where>
     </select>
+
+    <!-- 维修工时统计:按月度统计所有设备的单次平均维修工时 -->
+    <select id="statisticsWorkHourByMonth" parameterType="com.platform.dao.dto.repair.RepairApplicationFormDTO"
+            resultType="com.platform.dao.vo.report.RepairWorkHourReportVO">
+        select application.sb_id as sbId,
+        sb.no as sbNo,
+        sb.name as sbName,
+        sbType.name as sbTypeName,
+        count(1) as num,
+        IFNULL(sum(application.repair_minutes), 0) as totalRepairHours,
+        IFNULL(avg(application.repair_minutes), 0) as avgRepairHours,
+        IFNULL(sum(application.deal_minutes), 0) as totalDealHours
+        from t_repair_application_form application
+        left join t_sb_info sb on application.sb_id = sb.id
+        left join t_sb_type sbType on sb.type_id = sbType.id
+        <where>
+            application.repair_end_time is not null
+            and application.sb_id is not null and application.sb_id != ''
+            <if test="sbId != null and sbId != ''">
+                and application.sb_id = #{sbId}
+            </if>
+            <if test="keyword != null and keyword != ''">
+                and (sb.name like concat('%',#{keyword},'%') or sb.no like concat('%',#{keyword},'%'))
+            </if>
+            <if test="searchRepairStartTime != null">
+                and application.repair_start_time <![CDATA[ >= ]]> #{searchRepairStartTime}
+            </if>
+            <if test="searchRepairEndTime != null">
+                and application.repair_start_time <![CDATA[ <= ]]> #{searchRepairEndTime}
+            </if>
+        </where>
+        group by application.sb_id
+        having totalRepairHours > 0
+        order by totalRepairHours desc
+    </select>
 </mapper>

+ 54 - 0
platform-rest/src/main/java/com/platform/rest/controller/report/RepairReportController.java

@@ -521,4 +521,58 @@ public class RepairReportController {
         ExcelUtil.exportResponseDict(response, ExportRepairApplicationFormVO.class,
                 BeanConverterUtil.copyListProperties(list, ExportRepairApplicationFormVO.class), "维修工时统计-明细");
     }
+
+    /**
+     * 维修工时统计:按月度统计所有设备的单次平均维修工时
+     * @param dto      查询条件(设备名称/编号模糊、维修开始时间范围)
+     * @param pageNum  页码
+     * @param pageSize 每页条数
+     * @return R
+     */
+    @GetMapping("/workhour/month")
+    @SysLog("维修工时统计-按月度")
+    public R<AbstractPageResultBean<RepairWorkHourReportVO>> statisticsWorkHourByMonth(RepairApplicationFormDTO dto,
+                                                                                    @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
+        return new R<>(repairApplicationFormService.statisticsWorkHourByMonth(dto, pageNum, pageSize));
+    }
+
+    /**
+     * 维修工时统计明细:按月度统计所有设备的单次平均维修工时
+     * @param dto 查询条件(维修人主维修人精确匹配、设备、维修开始时间范围)
+     * @return R
+     */
+    @GetMapping("/workhour/month/detail")
+    @SysLog("月度统计维修工时统计-明细")
+    public R<List<RepairApplicationFormVO>> getWorkHourMonthDetail(RepairApplicationFormDTO dto) {
+        return new R<>(repairApplicationFormService.getWorkHourDetailByMonth(dto));
+    }
+
+    /**
+     * 维修工时统计明细导出:某维修人或某设备已完成维修的报修单列表
+     *
+     * @param dto 查询条件(维修人主维修人精确匹配、设备、维修开始时间范围)
+     */
+    @GetMapping("/workhour/month/export/detail")
+    @SysLog("维修工时统计-明细导出")
+    public void exportWorkHourMonthDetail(HttpServletResponse response, RepairApplicationFormDTO dto) {
+        List<RepairApplicationFormVO> list = repairApplicationFormService.getWorkHourDetailByMonth(dto);
+        ExcelUtil.exportResponseDict(response, ExportRepairApplicationFormVO.class,
+                BeanConverterUtil.copyListProperties(list, ExportRepairApplicationFormVO.class), "设备维修明细导出");
+    }
+
+    /**
+     * 维修工时统计导出:按设备
+     *
+     * @param dto 查询条件(设备名称/编号模糊、维修开始时间范围)
+     */
+    @GetMapping("/workhour/export/month")
+    @SysLog("维修工时统计-按月度导出")
+    public void exportWorkHourMonth(HttpServletResponse response, RepairApplicationFormDTO dto) {
+        List<RepairWorkHourReportVO> list = repairApplicationFormService.statisticsWorkHourByMonth(dto, 1, Integer.MAX_VALUE)
+                .getRows();
+        String[] arr = dto.getYearMonth().split("-");
+        String title = arr[0] + "年" + arr[1] + "月" + "-平均工时数据导出";
+        ExcelUtil.exportResponseDict(response, ExportRepairWorkHourSbVO.class,
+                BeanConverterUtil.copyListProperties(list, ExportRepairWorkHourSbVO.class), title);
+    }
 }

+ 17 - 0
platform-service/src/main/java/com/platform/service/repair/RepairApplicationFormService.java

@@ -197,4 +197,21 @@ public interface RepairApplicationFormService extends IBaseService<RepairApplica
      * @param id
      */
     void endRepair(String id);
+
+    /**
+     * 维修工时统计:按月统计每个月的平均维修工时
+     * @param model    查询条件(设备名称/编号模糊、维修开始时间范围)
+     * @param pageNum  页码
+     * @param pageSize 每页条数
+     * @return 分页统计结果
+     */
+    MyVOPage<RepairWorkHourReportVO> statisticsWorkHourByMonth(RepairApplicationFormDTO model, int pageNum, int pageSize);
+
+    /**
+     * 维修工时统计明细:某维修人或某设备已完成维修的报修单列表
+     *
+     * @param model 查询条件(维修人主维修人精确匹配、设备、维修开始时间范围)
+     * @return 报修单列表
+     */
+    List<RepairApplicationFormVO> getWorkHourDetailByMonth(RepairApplicationFormDTO model);
 }

+ 36 - 4
platform-service/src/main/java/com/platform/service/repair/impl/RepairApplicationFormServiceImpl.java

@@ -62,10 +62,7 @@ import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -2129,4 +2126,39 @@ public class RepairApplicationFormServiceImpl
         form.setAssistantStatus(RepairAssistantStatusEnum.end.getValue());
         mapper.updateByPrimaryKeySelective(form);
     }
+
+    @Override
+    public MyVOPage<RepairWorkHourReportVO> statisticsWorkHourByMonth(RepairApplicationFormDTO model, int pageNum, int pageSize) {
+        if(StringUtils.isBlank(model.getYearMonth())){
+            throw new DeniedException("统计的月份不可为空");
+        }
+        setStartAndEndTime(model); // 设置月度时间范围
+        PageHelper.startPage(pageNum, pageSize);
+        return new MyVOPage<>(mapper.statisticsWorkHourByMonth(model));
+    }
+
+    @Override
+    public List<RepairApplicationFormVO> getWorkHourDetailByMonth(RepairApplicationFormDTO model) {
+        setStartAndEndTime(model);
+        return mapper.selectWorkHourDetail(model);
+    }
+
+    private void setStartAndEndTime(RepairApplicationFormDTO model){
+        String[] arr = model.getYearMonth().split("-");
+        int year = Integer.parseInt(arr[0]);
+        int month = Integer.parseInt(arr[1]);
+        LocalDateTime startTime = LocalDateTime.of(year,month,1,0,0,0);
+        int endDay = 30;
+        if (month == 2){
+            endDay = 28;
+            if (year%4 == 0){
+                endDay = 29;
+            }
+        }else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
+            endDay = 31;
+        }
+        LocalDateTime endTime = LocalDateTime.of(year,month,endDay,23,59,59);
+        model.setSearchRepairEndTime(endTime);
+        model.setSearchRepairStartTime(startTime);
+    }
 }