Commit f87060a079a6c8b9cdef6d934c7fec48ad715a85

Authored by guzijian
1 parent dd1aa88f

feat: 新增顶班

ruoyi-admin/src/main/java/com/ruoyi/common/RuleSchedulingProperties.java
@@ -65,4 +65,14 @@ public interface RuleSchedulingProperties { @@ -65,4 +65,14 @@ public interface RuleSchedulingProperties {
65 */ 65 */
66 Integer FREE_FLAG = 0; 66 Integer FREE_FLAG = 0;
67 67
  68 + /**
  69 + * 顶班 当前规则
  70 + */
  71 + Integer NOW_RULE = 1;
  72 +
  73 + /**
  74 + * 顶班 其他规则
  75 + */
  76 + Integer OTHER_RULE = 2;
  77 +
68 } 78 }
ruoyi-admin/src/main/java/com/ruoyi/controller/AttendanceController.java
@@ -137,4 +137,18 @@ public class AttendanceController extends BaseController { @@ -137,4 +137,18 @@ public class AttendanceController extends BaseController {
137 } 137 }
138 138
139 139
  140 + @ApiOperation("用户顶班")
  141 + @PutMapping("/update/people/attendance")
  142 + @Log(title = "用户顶班", businessType = BusinessType.UPDATE)
  143 + public Result<?> updateSchedulingByUser( @RequestBody @Validated UpdatePeopleAttendanceRequestVo vo){
  144 + attendanceService.updateSchedulingByUser(vo);
  145 + return Result.OK("顶班成功");
  146 + }
  147 +
  148 + @ApiOperation("获取当日休息的用户")
  149 + @GetMapping("/getToday/freeUser")
  150 + public Result<?> getTodayFreeUser(@RequestParam("date") String date){
  151 + return Result.OK(attendanceService.getTodayFreeUser(date));
  152 + }
  153 +
140 } 154 }
ruoyi-admin/src/main/java/com/ruoyi/pojo/request/ReportErrorRequestVo.java
1 package com.ruoyi.pojo.request; 1 package com.ruoyi.pojo.request;
2 2
3 -import com.fasterxml.jackson.annotation.JsonFormat;  
4 import io.swagger.annotations.ApiModel; 3 import io.swagger.annotations.ApiModel;
5 import io.swagger.annotations.ApiModelProperty; 4 import io.swagger.annotations.ApiModelProperty;
6 import lombok.Data; 5 import lombok.Data;
7 -import org.springframework.format.annotation.DateTimeFormat;  
8 -  
9 -import java.util.Date;  
10 -import java.util.List;  
11 6
12 /** 7 /**
13 * 异常报表请求 8 * 异常报表请求
@@ -28,10 +23,15 @@ public class ReportErrorRequestVo { @@ -28,10 +23,15 @@ public class ReportErrorRequestVo {
28 @ApiModelProperty("错误类型") 23 @ApiModelProperty("错误类型")
29 private Integer exType; 24 private Integer exType;
30 /** 25 /**
31 - * 错误类型 26 + * 车队|部门
  27 + */
  28 + @ApiModelProperty("车队|部门")
  29 + private String fleetName;
  30 + /**
  31 + * 线路
32 */ 32 */
33 - @ApiModelProperty("场地名称")  
34 - private String siteName; 33 + @ApiModelProperty("线路")
  34 + private String lineName;
35 /** 35 /**
36 * 指定日期 36 * 指定日期
37 */ 37 */
ruoyi-admin/src/main/java/com/ruoyi/pojo/vo/UpdatePeopleAttendanceRequestVo.java 0 → 100644
  1 +package com.ruoyi.pojo.vo;
  2 +
  3 +
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.constraints.NotBlank;
  7 +import javax.validation.constraints.NotNull;
  8 +
  9 +/**
  10 + * 修改用户的顶班
  11 + * @author 20412
  12 + */
  13 +@Data
  14 +public class UpdatePeopleAttendanceRequestVo {
  15 + @NotBlank
  16 + private String jobCode;
  17 + @NotBlank
  18 + private String otherJobCode;
  19 + @NotBlank
  20 + private String date;
  21 + private Integer ruleId;
  22 + @NotNull
  23 + private Integer type;
  24 +}
ruoyi-admin/src/main/java/com/ruoyi/service/AttendanceService.java
@@ -62,4 +62,15 @@ public interface AttendanceService { @@ -62,4 +62,15 @@ public interface AttendanceService {
62 */ 62 */
63 List<TableMonthResponseVo> getTableMonth(PeopleRequestVo vo); 63 List<TableMonthResponseVo> getTableMonth(PeopleRequestVo vo);
64 64
  65 + /**
  66 + * 顶班
  67 + * @param vo
  68 + */
  69 + void updateSchedulingByUser(UpdatePeopleAttendanceRequestVo vo);
  70 +
  71 + /**
  72 + * 获取当日休息的人员信息
  73 + * @return
  74 + */
  75 + List<PeopleResponseVo> getTodayFreeUser(String date);
65 } 76 }
ruoyi-admin/src/main/java/com/ruoyi/service/RuleAttendanceMainService.java
@@ -9,6 +9,7 @@ import com.ruoyi.pojo.vo.PeopleResponseVo; @@ -9,6 +9,7 @@ import com.ruoyi.pojo.vo.PeopleResponseVo;
9 import com.ruoyi.pojo.vo.UpdateAttendanceVo; 9 import com.ruoyi.pojo.vo.UpdateAttendanceVo;
10 import org.apache.ibatis.annotations.Param; 10 import org.apache.ibatis.annotations.Param;
11 11
  12 +import java.time.LocalDate;
12 import java.util.List; 13 import java.util.List;
13 14
14 /** 15 /**
@@ -45,4 +46,6 @@ public interface RuleAttendanceMainService extends IService&lt;RuleAttendanceMain&gt; @@ -45,4 +46,6 @@ public interface RuleAttendanceMainService extends IService&lt;RuleAttendanceMain&gt;
45 * @return 46 * @return
46 */ 47 */
47 List<RuleAttendanceMain> queryNowMonthDate(PeopleRequestVo vo, List<String> jobCodes); 48 List<RuleAttendanceMain> queryNowMonthDate(PeopleRequestVo vo, List<String> jobCodes);
  49 +
  50 +
48 } 51 }
ruoyi-admin/src/main/java/com/ruoyi/service/impl/AttendanceServiceImpl.java
@@ -209,6 +209,82 @@ public class AttendanceServiceImpl implements AttendanceService { @@ -209,6 +209,82 @@ public class AttendanceServiceImpl implements AttendanceService {
209 return handleTableMonthResponseVo(vo.getDate(), helpList, mainList); 209 return handleTableMonthResponseVo(vo.getDate(), helpList, mainList);
210 } 210 }
211 211
  212 + @Override
  213 + @Transactional(rollbackFor = Exception.class)
  214 + public void updateSchedulingByUser(UpdatePeopleAttendanceRequestVo vo) {
  215 + if (NOW_RULE.equals(vo.getType())) {
  216 + ruleCopyToOtherUser(vo);
  217 + } else if (OTHER_RULE.equals(vo.getType())) {
  218 + handleOtherRule(vo);
  219 + }
  220 + }
  221 +
  222 + @Override
  223 + public List<PeopleResponseVo> getTodayFreeUser(String date) {
  224 + LocalDate localDate = LocalDate.parse(date);
  225 + QueryWrapper<RuleAttendanceMain> qw = new QueryWrapper<>();
  226 + qw.lambda()
  227 + .eq(RuleAttendanceMain::getSchedulingDate, localDate)
  228 + .eq(RuleAttendanceMain::getWorkFlag, FREE_FLAG);
  229 + List<RuleAttendanceMain> mainList = attendanceMainService.list(qw);
  230 + List<PeopleResponseVo> peopleList = mainTransformPeopleResponseVo(mainList);
  231 + return peopleList;
  232 + }
  233 +
  234 + private List<PeopleResponseVo> mainTransformPeopleResponseVo(List<RuleAttendanceMain> mainList) {
  235 + List<PeopleResponseVo> vos = new ArrayList<>(mainList.size());
  236 + for (RuleAttendanceMain main : mainList) {
  237 + PeopleResponseVo vo = new PeopleResponseVo();
  238 + BeanUtils.copyProperties(main, vo);
  239 + vos.add(vo);
  240 + }
  241 + return vos;
  242 + }
  243 +
  244 + private void handleOtherRule(UpdatePeopleAttendanceRequestVo vo) {
  245 + RuleAttendanceMain main = getRuleAttendanceMain(vo.getJobCode(), vo);
  246 + RuleAttendanceMain otherMain = getRuleAttendanceMain(vo.getOtherJobCode(), vo);
  247 + RuleScheduling ruleScheduling = ruleSchedulingService.selectRuleSchedulingById(vo.getRuleId().longValue());
  248 + // 更新休息
  249 + BeanUtils.copyProperties(otherMain, main, "id", "name", "posts", "fleetName", "ruleDictName", "jobCode");
  250 + attendanceMainService.updateById(main);
  251 +
  252 + // 更新顶班人员规则
  253 + handleOtherMain(ruleScheduling, otherMain, vo.getDate());
  254 + attendanceMainService.updateById(otherMain);
  255 + }
  256 +
  257 + private void handleOtherMain(RuleScheduling ruleScheduling, RuleAttendanceMain otherMain, String date) {
  258 + RuleSchedulingDto dto = new RuleSchedulingDto();
  259 + BeanUtils.copyProperties(ruleScheduling, dto);
  260 +
  261 + BeanUtils.copyProperties(dto, otherMain);
  262 + RuleNumSettingServiceImpl.handleSegmentationByDate(LocalDate.parse(date), otherMain, dto);
  263 + otherMain.setWorkFlag(dto.getId() == 0 ? FREE_FLAG : WORK_FLAG);
  264 + }
  265 +
  266 + private void ruleCopyToOtherUser(UpdatePeopleAttendanceRequestVo vo) {
  267 + RuleAttendanceMain main = getRuleAttendanceMain(vo.getJobCode(), vo);
  268 +
  269 + RuleAttendanceMain otherMain = getRuleAttendanceMain(vo.getOtherJobCode(), vo);
  270 + RuleAttendanceMain backMain = new RuleAttendanceMain();
  271 + BeanUtils.copyProperties(otherMain, backMain);
  272 +
  273 + BeanUtils.copyProperties(main, otherMain, "id", "name", "posts", "fleetName", "ruleDictName", "jobCode");
  274 + attendanceMainService.updateById(otherMain);
  275 + // 更新休息
  276 + BeanUtils.copyProperties(backMain, main, "id", "name", "posts", "fleetName", "ruleDictName", "jobCode");
  277 + attendanceMainService.updateById(main);
  278 + }
  279 +
  280 + private RuleAttendanceMain getRuleAttendanceMain(String vo, UpdatePeopleAttendanceRequestVo vo1) {
  281 + QueryWrapper<RuleAttendanceMain> qw = new QueryWrapper<>();
  282 + qw.lambda().eq(RuleAttendanceMain::getJobCode, vo)
  283 + .eq(RuleAttendanceMain::getSchedulingDate, vo1.getDate());
  284 + RuleAttendanceMain main = attendanceMainService.getOne(qw);
  285 + return main;
  286 + }
  287 +
212 private List<TableMonthResponseVo> handleTableMonthResponseVo(@NotBlank String date, List<RuleAttendanceMainHelp> helpList, List<RuleAttendanceMain> mainList) { 288 private List<TableMonthResponseVo> handleTableMonthResponseVo(@NotBlank String date, List<RuleAttendanceMainHelp> helpList, List<RuleAttendanceMain> mainList) {
213 Map<String, List<RuleAttendanceMain>> mainMap = transformMapByRuleAttendanceMain(mainList); 289 Map<String, List<RuleAttendanceMain>> mainMap = transformMapByRuleAttendanceMain(mainList);
214 List<TableMonthResponseVo> vos = new ArrayList<>(10); 290 List<TableMonthResponseVo> vos = new ArrayList<>(10);
@@ -237,7 +313,7 @@ public class AttendanceServiceImpl implements AttendanceService { @@ -237,7 +313,7 @@ public class AttendanceServiceImpl implements AttendanceService {
237 int month = Integer.parseInt(split[1]); 313 int month = Integer.parseInt(split[1]);
238 List<LocalDate> dateList = ConstDateUtil.getAllDatesOfTheMonth(year, month); 314 List<LocalDate> dateList = ConstDateUtil.getAllDatesOfTheMonth(year, month);
239 if (vos.size() != dateList.size()) { 315 if (vos.size() != dateList.size()) {
240 - int diff = dateList.size() - vos.size(); 316 + int diff = DateUtils.differentDaysByMillisecond(Date.from(dateList.get(0).atStartOfDay(ZoneId.systemDefault()).toInstant()), vos.get(0).getSchedulingDate());
241 if (diff > 0) { 317 if (diff > 0) {
242 for (int i = 0; i < diff; i++) { 318 for (int i = 0; i < diff; i++) {
243 TableMonthResponseVo.WorkItemVo itemVo = new TableMonthResponseVo.WorkItemVo(); 319 TableMonthResponseVo.WorkItemVo itemVo = new TableMonthResponseVo.WorkItemVo();
ruoyi-admin/src/main/java/com/ruoyi/service/impl/RuleNumSettingServiceImpl.java
@@ -159,7 +159,7 @@ public class RuleNumSettingServiceImpl extends ServiceImpl&lt;RuleNumSettingMapper, @@ -159,7 +159,7 @@ public class RuleNumSettingServiceImpl extends ServiceImpl&lt;RuleNumSettingMapper,
159 mainList.add(main); 159 mainList.add(main);
160 } 160 }
161 161
162 - private void handleSegmentationByDate(LocalDate date, RuleAttendanceMain main, RuleSchedulingDto dto) { 162 + public static void handleSegmentationByDate(LocalDate date, RuleAttendanceMain main, RuleSchedulingDto dto) {
163 main.setFirstWorkSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getFirstWorkSignInTime()))); 163 main.setFirstWorkSignInTime(ConstDateUtil.dateAddition(date.toString(), ConstDateUtil.formatDate("HH:mm:ss", main.getFirstWorkSignInTime())));
164 // 不存在分段 164 // 不存在分段
165 if (NO_SEGMENTATION.equals(dto.getSecondFlag())) { 165 if (NO_SEGMENTATION.equals(dto.getSecondFlag())) {
@@ -243,7 +243,12 @@ public class RuleNumSettingServiceImpl extends ServiceImpl&lt;RuleNumSettingMapper, @@ -243,7 +243,12 @@ public class RuleNumSettingServiceImpl extends ServiceImpl&lt;RuleNumSettingMapper,
243 return ruleSchedulingDtoList.get(daysDifference % length); 243 return ruleSchedulingDtoList.get(daysDifference % length);
244 } 244 }
245 245
246 - private static RuleSchedulingDto getFreeRuleSchedulingDto(Date startDate) { 246 + /**
  247 + * 获取休息rule
  248 + * @param startDate
  249 + * @return
  250 + */
  251 + public static RuleSchedulingDto getFreeRuleSchedulingDto(Date startDate) {
247 RuleSchedulingDto dto = new RuleSchedulingDto(); 252 RuleSchedulingDto dto = new RuleSchedulingDto();
248 dto.setId(0L); 253 dto.setId(0L);
249 dto.setRuleName("休息"); 254 dto.setRuleName("休息");
@@ -259,7 +264,7 @@ public class RuleNumSettingServiceImpl extends ServiceImpl&lt;RuleNumSettingMapper, @@ -259,7 +264,7 @@ public class RuleNumSettingServiceImpl extends ServiceImpl&lt;RuleNumSettingMapper,
259 } 264 }
260 265
261 266
262 - private Date handleTimeTomorrowByRule(LocalDate date, Date time) { 267 + private static Date handleTimeTomorrowByRule(LocalDate date, Date time) {
263 // 隔天日期需要加1 268 // 隔天日期需要加1
264 return ConstDateUtil.dateAddition(date.plusDays(1).toString(), ConstDateUtil.formatDate("HH:mm:ss", time)); 269 return ConstDateUtil.dateAddition(date.plusDays(1).toString(), ConstDateUtil.formatDate("HH:mm:ss", time));
265 } 270 }
ruoyi-admin/src/main/java/com/ruoyi/utils/ConstDateUtil.java
1 package com.ruoyi.utils; 1 package com.ruoyi.utils;
2 2
  3 +import java.text.ParseException;
3 import java.text.SimpleDateFormat; 4 import java.text.SimpleDateFormat;
4 import java.time.*; 5 import java.time.*;
5 import java.time.format.DateTimeFormatter; 6 import java.time.format.DateTimeFormatter;
@@ -14,6 +15,15 @@ public class ConstDateUtil { @@ -14,6 +15,15 @@ public class ConstDateUtil {
14 return simpleDateFormat.format(new Date()); 15 return simpleDateFormat.format(new Date());
15 } 16 }
16 17
  18 + public static Date parseDate(String date){
  19 + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  20 + try {
  21 + return simpleDateFormat.parse(date);
  22 + } catch (ParseException e) {
  23 + throw new RuntimeException(e);
  24 + }
  25 + }
  26 +
17 public static String formatDate(String pattern,Date date){ 27 public static String formatDate(String pattern,Date date){
18 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); 28 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
19 return simpleDateFormat.format(date); 29 return simpleDateFormat.format(date);
ruoyi-admin/src/main/resources/mapper/eexception/EquipmentExceptionMapper.xml
@@ -96,7 +96,8 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot; @@ -96,7 +96,8 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
96 join equipment on equipment.device_id = equipment_exception.device_id 96 join equipment on equipment.device_id = equipment_exception.device_id
97 <where> 97 <where>
98 equipment_exception.`status` != 1 98 equipment_exception.`status` != 1
99 - <if test="siteName != null and siteName != ''"> and equipment.site_name = #{siteName}</if> 99 + <if test="fleetName != null and fleetName != ''"> and equipment_exception.fleet_name like concat(#{fleetName},'%')</if>
  100 + <if test="lineName != null and lineName != ''"> and equipment_exception.line_name like concat(#{lineName},'%')</if>
100 <if test="jobCode != null and jobCode != ''"> and driver.job_code = #{jobCode}</if> 101 <if test="jobCode != null and jobCode != ''"> and driver.job_code = #{jobCode}</if>
101 <if test="exType != null "> and ex_type = #{exType}</if> 102 <if test="exType != null "> and ex_type = #{exType}</if>
102 <if test="id != null "> and equipment_exception.id #{id}</if> 103 <if test="id != null "> and equipment_exception.id #{id}</if>