Commit f58b666fdd69ae05926294326134753c4e450caa

Authored by guzijian
1 parent 253d1832

feat: 按照时间段导出日期

Bsth-admin/src/main/java/com/ruoyi/common/ReportProperties.java
... ... @@ -4,4 +4,5 @@ public interface ReportProperties {
4 4 Integer NOW = 0;
5 5 Integer DAY = 1;
6 6 Integer MONTH = 2;
  7 + Integer TIME_PERIOD = 3;
7 8 }
... ...
Bsth-admin/src/main/java/com/ruoyi/driver/mapper/DriverSchedulingMapper.java
... ... @@ -2,6 +2,7 @@ package com.ruoyi.driver.mapper;
2 2  
3 3 import com.ruoyi.domain.DriverScheduling;
4 4 import com.ruoyi.driver.domain.Driver;
  5 +import com.ruoyi.pojo.response.ExportReportViewResponseVo;
5 6 import org.apache.ibatis.annotations.Param;
6 7 import org.apache.ibatis.annotations.Select;
7 8  
... ... @@ -29,5 +30,6 @@ public interface DriverSchedulingMapper {
29 30 @Select("select count(*) from equipment")
30 31 Integer queryNumberByDevice();
31 32  
32   - void updateDriverInfo(@Param("driver") Driver driver,@Param("date")String date);
  33 +
  34 + List<DriverScheduling> queryByMonth(@Param("startDate") String startDate,@Param("endDate") String endDate);
33 35 }
... ...
Bsth-admin/src/main/java/com/ruoyi/pojo/request/ReportViewRequestVo.java
... ... @@ -49,4 +49,10 @@ public class ReportViewRequestVo {
49 49 @ApiModelProperty("查询各个阶段超时的人员 0 全部 1 第一次打卡 2 第二卡打卡 3 第三次打卡 4 第四次打卡")
50 50 Integer stage;
51 51  
  52 + @ApiModelProperty("开始时间")
  53 + String startDate;
  54 +
  55 + @ApiModelProperty("结束时间")
  56 + String endDate;
  57 +
52 58 }
... ...
Bsth-admin/src/main/java/com/ruoyi/pojo/response/ExportReportViewResponseVo.java
... ... @@ -4,11 +4,13 @@ import com.alibaba.excel.annotation.ExcelProperty;
4 4 import com.alibaba.excel.annotation.write.style.ColumnWidth;
5 5 import com.alibaba.excel.annotation.write.style.HeadFontStyle;
6 6 import com.alibaba.excel.annotation.write.style.HeadRowHeight;
  7 +import com.fasterxml.jackson.annotation.JsonFormat;
7 8 import com.ruoyi.common.utils.bean.BeanUtils;
8 9 import com.ruoyi.domain.DriverScheduling;
9 10 import io.swagger.annotations.ApiModel;
10 11 import io.swagger.annotations.ApiModelProperty;
11 12 import lombok.Data;
  13 +import org.springframework.format.annotation.DateTimeFormat;
12 14  
13 15 import java.math.BigDecimal;
14 16 import java.util.Date;
... ... @@ -157,6 +159,8 @@ public class ExportReportViewResponseVo {
157 159 @ApiModelProperty("排班日期")
158 160 @ExcelProperty(value = "排班日期")
159 161 @ColumnWidth(20)
  162 + @DateTimeFormat(pattern = "yyyy-MM-dd")
  163 + @JsonFormat(pattern = "yyyy-MM-dd")
160 164 private Date scheduleDate;
161 165  
162 166 public ExportReportViewResponseVo(List<DriverScheduling> driverScheduling) {
... ...
Bsth-admin/src/main/java/com/ruoyi/service/ReportService.java
... ... @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
4 4 import com.ruoyi.common.global.Result;
5 5 import com.ruoyi.common.global.ResultCode;
6 6 import com.ruoyi.common.utils.SecurityUtils;
  7 +import com.ruoyi.common.utils.StringUtils;
7 8 import com.ruoyi.driver.mapper.DriverMapper;
8 9 import com.ruoyi.driver.mapper.DriverSchedulingMapper;
9 10 import com.ruoyi.eexception.mapper.EquipmentExceptionMapper;
... ... @@ -27,7 +28,11 @@ import javax.validation.constraints.NotBlank;
27 28 import java.time.LocalDate;
28 29 import java.time.YearMonth;
29 30 import java.time.format.DateTimeFormatter;
  31 +import java.time.temporal.ChronoUnit;
30 32 import java.util.*;
  33 +import java.util.concurrent.ExecutorService;
  34 +import java.util.concurrent.Executors;
  35 +import java.util.concurrent.TimeUnit;
31 36 import java.util.regex.Matcher;
32 37 import java.util.regex.Pattern;
33 38 import java.util.stream.Collectors;
... ... @@ -35,8 +40,7 @@ import java.util.stream.Collectors;
35 40 import static com.ruoyi.common.ApiProperties.PERSONNEL_API_KEY;
36 41 import static com.ruoyi.common.ConstDriverProperties.BC_TYPE_OUT;
37 42 import static com.ruoyi.common.ConstSignInConstSignInProperties.*;
38   -import static com.ruoyi.common.ReportProperties.DAY;
39   -import static com.ruoyi.common.ReportProperties.MONTH;
  43 +import static com.ruoyi.common.ReportProperties.*;
40 44  
41 45 /**
42 46 * @author 20412
... ... @@ -101,9 +105,74 @@ public class ReportService {
101 105 else if (requestVo.getExportFlag().equals(MONTH)) {
102 106 return getMonthReportTableResponseVo(requestVo);
103 107 }
  108 + // 处理导出任意时间段 后台追加限制条件 366 天为最长导出时间
  109 + else if (requestVo.getExportFlag().equals(TIME_PERIOD)) {
  110 + return getTimePeriodReportTableResponseVo(requestVo);
  111 + }
104 112 return null;
105 113 }
106 114  
  115 + private List<ExportReportViewResponseVo> getTimePeriodReportTableResponseVo(ReportViewRequestVo requestVo) {
  116 + String startDate = requestVo.getStartDate();
  117 + String endDate = requestVo.getEndDate();
  118 + LocalDate startLocalDate = LocalDate.parse(startDate);
  119 + LocalDate endLocalDate = LocalDate.parse(endDate);
  120 +
  121 + long days = ChronoUnit.DAYS.between(startLocalDate, endLocalDate);
  122 + long timePeriod = 366;
  123 + if (days > timePeriod) {
  124 + throw new RuntimeException("时间段不能超过" + timePeriod + "天");
  125 + }
  126 + List<ExportReportViewResponseVo> voList = new ArrayList<>();
  127 + // 分段查询
  128 + spiteQueryResult(startLocalDate, endLocalDate, voList);
  129 +
  130 + return voList;
  131 + }
  132 +
  133 + private void spiteQueryResult(LocalDate startLocalDate, LocalDate endLocalDate, List<ExportReportViewResponseVo> voList) {
  134 + // 1 时间按月分段
  135 + String split = "p";
  136 + List<String> localDates = splitByMonth(startLocalDate, endLocalDate, split);
  137 + // 2 按月创建多线程
  138 + ExecutorService pool = Executors.newFixedThreadPool(localDates.size());
  139 + // 3
  140 + for (String date : localDates) {
  141 + pool.execute(new Runnable() {
  142 + @Override
  143 + public void run() {
  144 + String[] dateSplit = date.split(split);
  145 + List<DriverScheduling> vos = schedulingMapper.queryByMonth(dateSplit[0], dateSplit[1]);
  146 + Map<String, List<DriverScheduling>> resultMap = new HashMap<>();
  147 + handlerResultMap(resultMap, vos);
  148 + handleResultList(voList, resultMap);
  149 + }
  150 + });
  151 + }
  152 + pool.shutdown();
  153 + try {
  154 + // 等待所有任务执行完毕或超时
  155 + pool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
  156 + } catch (InterruptedException e) {
  157 + throw new RuntimeException("导出失败,请尝试刷新页面重新导出或者联系管理员");
  158 + }
  159 + }
  160 +
  161 + private static List<String> splitByMonth(LocalDate startDate, LocalDate endDate, String split) {
  162 + List<String> dates = new ArrayList<>();
  163 + LocalDate currentMonthStart = startDate;
  164 + LocalDate currentMonthEnd;
  165 + while (currentMonthStart.isBefore(endDate) || currentMonthStart.isEqual(endDate)) {
  166 + currentMonthEnd = currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth());
  167 + if (currentMonthEnd.isAfter(endDate)) {
  168 + currentMonthEnd = endDate;
  169 + }
  170 + dates.add(currentMonthStart + split + currentMonthEnd);
  171 + currentMonthStart = currentMonthEnd.plusDays(1);
  172 + }
  173 + return dates;
  174 + }
  175 +
107 176 private List<ExportReportViewResponseVo> getDayReportTableResponseVo(String date) {
108 177 List<DriverScheduling> schedulingList = schedulingMapper.queryToDay(date, null, null, null);
109 178 Map<String, List<DriverScheduling>> resultMap = new HashMap<>(800);
... ... @@ -131,6 +200,17 @@ public class ReportService {
131 200 }
132 201 }
133 202  
  203 + private void handlerResultMap(Map<String, List<DriverScheduling>> resultMap, List<DriverScheduling> schedulingList) {
  204 + for (DriverScheduling item : schedulingList) {
  205 + String key = item.getScheduleDate() + item.getJobCode();
  206 + if (Objects.isNull(resultMap.get(key))) {
  207 + resultMap.put(key, new ArrayList<>(Arrays.asList(item)));
  208 + } else {
  209 + resultMap.get(key).add(item);
  210 + }
  211 + }
  212 + }
  213 +
134 214 private List<ExportReportViewResponseVo> getMonthReportTableResponseVo(ReportViewRequestVo requestVo) {
135 215 List<ExportReportViewResponseVo> responseVos = new ArrayList<>(10000);
136 216 List<String> days = getNowMonthAllDay(requestVo.getDate());
... ...
Bsth-admin/src/main/resources/mapper/driver_scheduling/DriverSchedulingMapper.xml
... ... @@ -70,4 +70,9 @@
70 70 </if>
71 71  
72 72 </select>
  73 + <select id="queryByMonth" resultType="com.ruoyi.domain.DriverScheduling" resultMap="Scheduling">
  74 + select scheduling.*,driver.fleet_name fleetName from
  75 + scheduling left join driver on driver.job_code = scheduling.job_code
  76 + where schedule_date &gt;= #{startDate} and schedule_date &lt;= #{endDate}
  77 + </select>
73 78 </mapper>
74 79 \ No newline at end of file
... ...