Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
55439fe475
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
@ -14,7 +13,6 @@ import java.util.*;
|
|||||||
import cn.iocoder.yudao.module.home.controller.admin.calendar.vo.*;
|
import cn.iocoder.yudao.module.home.controller.admin.calendar.vo.*;
|
||||||
import cn.iocoder.yudao.module.home.dal.dataobject.calendar.CalendarDO;
|
import cn.iocoder.yudao.module.home.dal.dataobject.calendar.CalendarDO;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
|
||||||
import cn.iocoder.yudao.module.home.dal.mysql.calendar.CalendarMapper;
|
import cn.iocoder.yudao.module.home.dal.mysql.calendar.CalendarMapper;
|
||||||
@ -152,146 +150,105 @@ public class CalendarServiceImpl implements CalendarService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal getWorkDay(CalendarPageReqVO workDayVO) {
|
public BigDecimal getWorkDay(CalendarPageReqVO workDayVO) {
|
||||||
// 储存判断后扣除天数
|
|
||||||
float day = 0.0f;
|
|
||||||
int sWorkHour = 0;
|
|
||||||
int eWorkHour = 0;
|
|
||||||
// 储存返回天数
|
|
||||||
BigDecimal result = null;
|
|
||||||
// 获取开始结束时间
|
// 获取开始结束时间
|
||||||
Integer sHour = workDayVO.getSHour();
|
Integer sHour = workDayVO.getSHour();
|
||||||
Integer eHour = workDayVO.getEHour();
|
Integer eHour = workDayVO.getEHour();
|
||||||
System.out.println("sHour: " + sHour);
|
|
||||||
System.out.println("eHour: " + eHour);
|
|
||||||
// 判断开始结束时间
|
// 判断开始结束时间
|
||||||
if (sHour == null || eHour == null) {
|
if (sHour == null || eHour == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取开始日期结束日期传递的isWorkDay参数
|
// 获取开始日期结束日期传递的isWorkDay参数
|
||||||
String sDay = workDayVO.getDate()[0];
|
String sDay = workDayVO.getDate()[0];
|
||||||
String eDay = workDayVO.getDate()[1];
|
String eDay = workDayVO.getDate()[1];
|
||||||
System.out.println("sDay: " + sDay);
|
|
||||||
System.out.println("eDay: " + eDay);
|
|
||||||
Integer isWork = workDayVO.getIsWorkday();
|
Integer isWork = workDayVO.getIsWorkday();
|
||||||
// 设置开始时间vo判断开始天数是否为工作日
|
|
||||||
CalendarPageReqVO sWorkDayVO = new CalendarPageReqVO();
|
// 创建工作日请求VO
|
||||||
sWorkDayVO.setDate(new String[]{sDay, sDay});
|
CalendarPageReqVO sWorkDayVO = createCalendarPageReqVO(sDay,sDay,isWork,null);
|
||||||
sWorkDayVO.setIsWorkday(isWork);
|
CalendarPageReqVO eWorkDayVO = createCalendarPageReqVO(eDay,eDay,isWork,null);
|
||||||
// 设置结束时间vo判断结束天数是否为工作日
|
|
||||||
CalendarPageReqVO eWorkDayVO = new CalendarPageReqVO();
|
|
||||||
eWorkDayVO.setDate(new String[]{eDay, eDay});
|
|
||||||
eWorkDayVO.setIsWorkday(isWork);
|
|
||||||
System.out.println("workDayVO: " + workDayVO);
|
|
||||||
// 获取开始结束工作日天数,获取时间段内工作日天数
|
// 获取开始结束工作日天数,获取时间段内工作日天数
|
||||||
Long sTotal = calendarMapper.selectPage(sWorkDayVO).getTotal();
|
Long sTotal = calendarMapper.selectPage(sWorkDayVO).getTotal();
|
||||||
Long eTotal = calendarMapper.selectPage(eWorkDayVO).getTotal();
|
Long eTotal = calendarMapper.selectPage(eWorkDayVO).getTotal();
|
||||||
Long total = calendarMapper.selectPage(workDayVO).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
|
@Override
|
||||||
public BigDecimal getWorkDayAi(CalendarAiVO workDayAiVO) {
|
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 formatterYMDHMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
DateTimeFormatter formatterYMD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
DateTimeFormatter formatterYMD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
// 使用 formatter 解析字符串为 LocalDateTime
|
// 使用 formatter 解析字符串为 LocalDateTime
|
||||||
LocalDateTime sDateTime = LocalDateTime.parse(workDayAiVO.getStartTime(), formatterYMDHMS);
|
LocalDateTime sDateTime = LocalDateTime.parse(workDayAiVO.getStartTime(), formatterYMDHMS);
|
||||||
LocalDateTime eDateTime = LocalDateTime.parse(workDayAiVO.getEndTime(), formatterYMDHMS);
|
LocalDateTime eDateTime = LocalDateTime.parse(workDayAiVO.getEndTime(), formatterYMDHMS);
|
||||||
|
|
||||||
System.out.println("sDateTime: " + sDateTime);
|
// 获取开始结束小时数
|
||||||
System.out.println("eDateTime: " + eDateTime);
|
|
||||||
// 获取开始结束时间
|
|
||||||
Integer sHour = sDateTime.getHour();
|
Integer sHour = sDateTime.getHour();
|
||||||
Integer eHour = eDateTime.getHour();
|
Integer eHour = eDateTime.getHour();
|
||||||
System.out.println("sHour: " + sHour);
|
|
||||||
System.out.println("eHour: " + eHour);
|
// 获取开始日期结束日期
|
||||||
// 获取开始日期结束日期传递的isWorkDay参数
|
|
||||||
String sDay = sDateTime.format(formatterYMD);
|
String sDay = sDateTime.format(formatterYMD);
|
||||||
String eDay = eDateTime.format(formatterYMD);
|
String eDay = eDateTime.format(formatterYMD);
|
||||||
System.out.println("sDay: " + sDay);
|
|
||||||
System.out.println("eDay: " + eDay);
|
// 创建工作日请求VO
|
||||||
// 设置开始时间vo判断开始天数是否为工作日
|
CalendarPageReqVO sWorkDayVO = createCalendarPageReqVO(sDay,sDay,1,null);
|
||||||
CalendarPageReqVO sWorkDayVO = new CalendarPageReqVO();
|
CalendarPageReqVO eWorkDayVO = createCalendarPageReqVO(eDay,eDay,1,null);
|
||||||
sWorkDayVO.setDate(new String[]{sDay, sDay});
|
CalendarPageReqVO workDayVO = createCalendarPageReqVO(sDay,eDay,1,1);
|
||||||
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);
|
|
||||||
System.out.println("workDayVO: " + workDayVO);
|
|
||||||
// 获取开始结束工作日天数,获取时间段内工作日天数
|
// 获取开始结束工作日天数,获取时间段内工作日天数
|
||||||
Long sTotal = calendarMapper.selectPage(sWorkDayVO).getTotal();
|
Long sTotal = calendarMapper.selectPage(sWorkDayVO).getTotal();
|
||||||
Long eTotal = calendarMapper.selectPage(eWorkDayVO).getTotal();
|
Long eTotal = calendarMapper.selectPage(eWorkDayVO).getTotal();
|
||||||
Long total = calendarMapper.selectPage(workDayVO).getTotal();
|
Long total = calendarMapper.selectPage(workDayVO).getTotal();
|
||||||
// 判断总过天数不为0时才判断否则直接返回
|
|
||||||
if (total >= 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) {
|
if (sTotal > 0) {
|
||||||
|
day += getSDay(sHour);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断结束天为工作日时
|
||||||
|
if (eTotal > 0) {
|
||||||
|
day += getEDay(eHour);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 小时数相等时
|
||||||
|
if (sTotal > 0&&eTotal > 0&&sHour.equals(eHour)) {
|
||||||
|
day = 1;
|
||||||
|
}
|
||||||
|
// 计算总工作日期,需要减去的对应天数
|
||||||
|
return BigDecimal.valueOf(total)
|
||||||
|
.subtract(BigDecimal.valueOf(day))
|
||||||
|
.setScale(1, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取开始扣除天数
|
||||||
|
private float getSDay(Integer sHour) {
|
||||||
|
int sWorkHour = 0;
|
||||||
|
float day = 0.0f;
|
||||||
|
|
||||||
// 开始日期的时间判断
|
// 开始日期的时间判断
|
||||||
if (sHour < 8 ) {
|
if (sHour < 8 ) {
|
||||||
day += 0f;
|
day += 0f;
|
||||||
@ -302,9 +259,21 @@ public class CalendarServiceImpl implements CalendarService {
|
|||||||
} else {
|
} else {
|
||||||
day += 1f;
|
day += 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算开始时间
|
||||||
|
if (sWorkHour != 0&&sWorkHour <= 4) {
|
||||||
|
day += 0.5F;
|
||||||
|
} else {
|
||||||
|
day += 0F;
|
||||||
}
|
}
|
||||||
// 判断结束天为工作日时才判断
|
return day;
|
||||||
if (eTotal > 0) {
|
}
|
||||||
|
|
||||||
|
// 获取结束扣除天数
|
||||||
|
private float getEDay(Integer eHour) {
|
||||||
|
int eWorkHour = 0;
|
||||||
|
float day = 0.0f;
|
||||||
|
|
||||||
// 结束日期的时间判断
|
// 结束日期的时间判断
|
||||||
if (eHour <= 8 ) {
|
if (eHour <= 8 ) {
|
||||||
day += 1f;
|
day += 1f;
|
||||||
@ -315,30 +284,13 @@ public class CalendarServiceImpl implements CalendarService {
|
|||||||
} else {
|
} else {
|
||||||
day += 0f;
|
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) {
|
if (eWorkHour != 0 && eWorkHour <= 4) {
|
||||||
day += 0.5F;
|
day += 0.5F;
|
||||||
} else if (eWorkHour > 5) {
|
} else if (eWorkHour > 4) {
|
||||||
day += 0F;
|
day += 0F;
|
||||||
}
|
}
|
||||||
// 小时数相等时
|
return day;
|
||||||
if (sHour.equals(eHour)) {
|
|
||||||
day = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 计算总工作日期,需要减去的对应天数
|
|
||||||
result = BigDecimal.valueOf(total)
|
|
||||||
.subtract(BigDecimal.valueOf(day))
|
|
||||||
.setScale(1, RoundingMode.HALF_UP);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user