getWorkDayAi接口更新
This commit is contained in:
parent
acc53401ac
commit
36d27e6cba
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.home.service.calendar;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import liquibase.pro.packaged.I;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -152,12 +153,6 @@ public class CalendarServiceImpl implements CalendarService {
|
||||
|
||||
@Override
|
||||
public BigDecimal getWorkDay(CalendarPageReqVO workDayVO) {
|
||||
// 储存判断后扣除天数
|
||||
float day = 0.0f;
|
||||
int sWorkHour = 0;
|
||||
int eWorkHour = 0;
|
||||
// 储存返回天数
|
||||
BigDecimal result = null;
|
||||
// 获取开始结束时间
|
||||
Integer sHour = workDayVO.getSHour();
|
||||
Integer eHour = workDayVO.getEHour();
|
||||
@ -165,167 +160,140 @@ public class CalendarServiceImpl implements CalendarService {
|
||||
if (sHour == null || eHour == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取开始日期结束日期传递的isWorkDay参数
|
||||
String sDay = workDayVO.getDate()[0];
|
||||
String eDay = workDayVO.getDate()[1];
|
||||
Integer isWork = workDayVO.getIsWorkday();
|
||||
// 设置开始时间vo判断开始天数是否为工作日
|
||||
CalendarPageReqVO sWorkDayVO = new CalendarPageReqVO();
|
||||
sWorkDayVO.setDate(new String[]{sDay, sDay});
|
||||
sWorkDayVO.setIsWorkday(isWork);
|
||||
// 设置结束时间vo判断结束天数是否为工作日
|
||||
CalendarPageReqVO eWorkDayVO = new CalendarPageReqVO();
|
||||
eWorkDayVO.setDate(new String[]{eDay, eDay});
|
||||
eWorkDayVO.setIsWorkday(isWork);
|
||||
|
||||
// 创建工作日请求VO
|
||||
CalendarPageReqVO sWorkDayVO = createCalendarPageReqVO(sDay,sDay,isWork,null);
|
||||
CalendarPageReqVO eWorkDayVO = createCalendarPageReqVO(eDay,eDay,isWork,null);
|
||||
|
||||
// 获取开始结束工作日天数,获取时间段内工作日天数
|
||||
Long sTotal = calendarMapper.selectPage(sWorkDayVO).getTotal();
|
||||
Long eTotal = calendarMapper.selectPage(eWorkDayVO).getTotal();
|
||||
Long total = calendarMapper.selectPage(workDayVO).getTotal();
|
||||
// 判断总过天数不为0时才判断否则直接返回
|
||||
if (total >= 1) {
|
||||
// 判断开始天为工作日时才判断
|
||||
if (sTotal > 0) {
|
||||
// 开始日期的时间判断
|
||||
if (sHour < 8 ) {
|
||||
day += 0f;
|
||||
} else if (sHour <= 12) {
|
||||
sWorkHour = 16 - sHour;
|
||||
} else if (sHour < 17 ) {
|
||||
sWorkHour = 17 - sHour;
|
||||
} else {
|
||||
day += 1f;
|
||||
}
|
||||
}
|
||||
// 判断结束天为工作日时才判断
|
||||
if (eTotal > 0) {
|
||||
// 结束日期的时间判断
|
||||
if (eHour <= 8 ) {
|
||||
day += 1f;
|
||||
} else if (eHour <= 12) {
|
||||
eWorkHour = eHour - 8;
|
||||
}else if (eHour <= 17 ) {
|
||||
eWorkHour = eHour - 9;
|
||||
} else {
|
||||
day += 0f;
|
||||
}
|
||||
}
|
||||
// 计算开始时间
|
||||
if (sWorkHour == 1) {
|
||||
day += 1F;
|
||||
} else if (sWorkHour >= 2&&sWorkHour <= 4) {
|
||||
day += 0.5F;
|
||||
} else if (sWorkHour > 4) {
|
||||
day += 0F;
|
||||
}
|
||||
// 计算结束时间
|
||||
if (eWorkHour != 0 && eWorkHour <= 5) {
|
||||
day += 0.5F;
|
||||
} else if (eWorkHour > 5) {
|
||||
day += 0F;
|
||||
}
|
||||
// 小时数相等时
|
||||
if (sHour.equals(eHour)) {
|
||||
day = 1;
|
||||
}
|
||||
}
|
||||
// 计算总工作日期,需要减去的对应天数
|
||||
result = BigDecimal.valueOf(total)
|
||||
.subtract(BigDecimal.valueOf(day))
|
||||
.setScale(1, RoundingMode.HALF_UP);
|
||||
return result;
|
||||
|
||||
return workDayCount( total, sTotal, eTotal, sHour, eHour);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getWorkDayAi(CalendarAiVO workDayAiVO) {
|
||||
// 储存判断后扣除天数
|
||||
float day = 0.0f;
|
||||
int sWorkHour = 0;
|
||||
int eWorkHour = 0;
|
||||
// 储存返回天数
|
||||
BigDecimal result = null;
|
||||
|
||||
DateTimeFormatter formatterYMDHMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
DateTimeFormatter formatterYMD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
// 使用 formatter 解析字符串为 LocalDateTime
|
||||
LocalDateTime sDateTime = LocalDateTime.parse(workDayAiVO.getStartTime(), formatterYMDHMS);
|
||||
LocalDateTime eDateTime = LocalDateTime.parse(workDayAiVO.getEndTime(), formatterYMDHMS);
|
||||
// 获取开始结束时间
|
||||
|
||||
// 获取开始结束小时数
|
||||
Integer sHour = sDateTime.getHour();
|
||||
Integer eHour = eDateTime.getHour();
|
||||
// 获取开始日期结束日期传递的isWorkDay参数
|
||||
|
||||
// 获取开始日期结束日期
|
||||
String sDay = sDateTime.format(formatterYMD);
|
||||
String eDay = eDateTime.format(formatterYMD);
|
||||
// 设置开始时间vo判断开始天数是否为工作日
|
||||
CalendarPageReqVO sWorkDayVO = new CalendarPageReqVO();
|
||||
sWorkDayVO.setDate(new String[]{sDay, sDay});
|
||||
sWorkDayVO.setIsWorkday(1);
|
||||
// 设置结束时间vo判断结束天数是否为工作日
|
||||
CalendarPageReqVO eWorkDayVO = new CalendarPageReqVO();
|
||||
eWorkDayVO.setDate(new String[]{eDay, eDay});
|
||||
eWorkDayVO.setIsWorkday(1);
|
||||
// 时间段vo
|
||||
CalendarPageReqVO workDayVO = new CalendarPageReqVO();
|
||||
workDayVO.setDate(new String[]{sDay, eDay});
|
||||
workDayVO.setIsWorkday(1);
|
||||
workDayVO.setPageSize(1);
|
||||
|
||||
// 创建工作日请求VO
|
||||
CalendarPageReqVO sWorkDayVO = createCalendarPageReqVO(sDay,sDay,1,null);
|
||||
CalendarPageReqVO eWorkDayVO = createCalendarPageReqVO(eDay,eDay,1,null);
|
||||
CalendarPageReqVO workDayVO = createCalendarPageReqVO(sDay,eDay,1,1);
|
||||
|
||||
// 获取开始结束工作日天数,获取时间段内工作日天数
|
||||
Long sTotal = calendarMapper.selectPage(sWorkDayVO).getTotal();
|
||||
Long eTotal = calendarMapper.selectPage(eWorkDayVO).getTotal();
|
||||
Long total = calendarMapper.selectPage(workDayVO).getTotal();
|
||||
// 判断总过天数不为0时才判断否则直接返回
|
||||
if (total >= 1) {
|
||||
// 判断开始天为工作日时才判断
|
||||
if (sTotal > 0) {
|
||||
// 开始日期的时间判断
|
||||
if (sHour < 8 ) {
|
||||
day += 0f;
|
||||
} else if (sHour <= 12) {
|
||||
sWorkHour = 16 - sHour;
|
||||
} else if (sHour < 17 ) {
|
||||
sWorkHour = 17 - sHour;
|
||||
} else {
|
||||
day += 1f;
|
||||
}
|
||||
}
|
||||
// 判断结束天为工作日时才判断
|
||||
if (eTotal > 0) {
|
||||
// 结束日期的时间判断
|
||||
if (eHour <= 8 ) {
|
||||
day += 1f;
|
||||
} else if (eHour <= 12) {
|
||||
eWorkHour = eHour - 8;
|
||||
}else if (eHour <= 17 ) {
|
||||
eWorkHour = eHour - 9;
|
||||
} else {
|
||||
day += 0f;
|
||||
}
|
||||
}
|
||||
// 计算开始时间
|
||||
if (sWorkHour == 1) {
|
||||
day += 1F;
|
||||
} else if (sWorkHour >= 2&&sWorkHour <= 4) {
|
||||
day += 0.5F;
|
||||
} else if (sWorkHour > 4) {
|
||||
day += 0F;
|
||||
}
|
||||
// 计算结束时间
|
||||
if (eWorkHour != 0 && eWorkHour <= 5) {
|
||||
day += 0.5F;
|
||||
} else if (eWorkHour > 5) {
|
||||
day += 0F;
|
||||
}
|
||||
// 小时数相等时
|
||||
if (sHour.equals(eHour)) {
|
||||
day = 1;
|
||||
}
|
||||
|
||||
return workDayCount( total, sTotal, eTotal,sHour, eHour);
|
||||
}
|
||||
|
||||
// 创建CalendarPageReqVO的辅助方法
|
||||
private CalendarPageReqVO createCalendarPageReqVO(String sDay, String eDay, Integer isWork, Integer size) {
|
||||
CalendarPageReqVO vo = new CalendarPageReqVO();
|
||||
|
||||
vo.setDate(new String[]{sDay, eDay});
|
||||
vo.setIsWorkday(isWork);
|
||||
vo.setPageSize(size != null ? size : 10);
|
||||
return vo;
|
||||
}
|
||||
|
||||
// 计算天数并返回
|
||||
private BigDecimal workDayCount( Long total, Long sTotal, Long eTotal, Integer sHour, Integer eHour) {
|
||||
float day = 0.0f;
|
||||
|
||||
// 判断总过天数不为0时才判断
|
||||
if (total == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
// 判断开始天为工作日时
|
||||
if (sTotal > 0) {
|
||||
day += getSDay(sHour);
|
||||
}
|
||||
|
||||
// 判断结束天为工作日时
|
||||
if (eTotal > 0) {
|
||||
day += getEDay(eHour);
|
||||
}
|
||||
|
||||
// 小时数相等时
|
||||
if (sTotal > 0&&eTotal > 0&&sHour.equals(eHour)) {
|
||||
day = 1;
|
||||
}
|
||||
// 计算总工作日期,需要减去的对应天数
|
||||
result = BigDecimal.valueOf(total)
|
||||
return BigDecimal.valueOf(total)
|
||||
.subtract(BigDecimal.valueOf(day))
|
||||
.setScale(1, RoundingMode.HALF_UP);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获取开始扣除天数
|
||||
private float getSDay(Integer sHour) {
|
||||
int sWorkHour = 0;
|
||||
float day = 0.0f;
|
||||
|
||||
// 开始日期的时间判断
|
||||
if (sHour < 8 ) {
|
||||
day += 0f;
|
||||
} else if (sHour <= 12) {
|
||||
sWorkHour = 16 - sHour;
|
||||
} else if (sHour < 17 ) {
|
||||
sWorkHour = 17 - sHour;
|
||||
} else {
|
||||
day += 1f;
|
||||
}
|
||||
|
||||
// 计算开始时间
|
||||
if (sWorkHour != 0&&sWorkHour <= 4) {
|
||||
day += 0.5F;
|
||||
} else {
|
||||
day += 0F;
|
||||
}
|
||||
return day;
|
||||
}
|
||||
|
||||
// 获取结束扣除天数
|
||||
private float getEDay(Integer eHour) {
|
||||
int eWorkHour = 0;
|
||||
float day = 0.0f;
|
||||
|
||||
// 结束日期的时间判断
|
||||
if (eHour <= 8 ) {
|
||||
day += 1f;
|
||||
} else if (eHour <= 12) {
|
||||
eWorkHour = eHour - 8;
|
||||
}else if (eHour <= 17 ) {
|
||||
eWorkHour = eHour - 9;
|
||||
} else {
|
||||
day += 0f;
|
||||
}
|
||||
|
||||
// 计算结束时间
|
||||
if (eWorkHour != 0 && eWorkHour <= 4) {
|
||||
day += 0.5F;
|
||||
} else if (eWorkHour > 4) {
|
||||
day += 0F;
|
||||
}
|
||||
return day;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user