|
|
@@ -2,6 +2,7 @@ package com.ruoyi.zhushi.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.ruoyi.common.core.domain.PageQuery; |
|
|
@@ -11,7 +12,9 @@ import com.ruoyi.common.core.page.TableDataInfo; |
|
|
|
import com.ruoyi.common.helper.LoginHelper; |
|
|
|
import com.ruoyi.zhushi.entity.*; |
|
|
|
import com.ruoyi.zhushi.mapper.DkRecordMapper; |
|
|
|
import com.ruoyi.zhushi.mapper.NjBalanceManageDetailMapper; |
|
|
|
import com.ruoyi.zhushi.service.DkRecordService; |
|
|
|
import com.ruoyi.zhushi.service.NjBalanceManageDetailService; |
|
|
|
import com.ruoyi.zhushi.util.CalendarGenerator; |
|
|
|
import com.ruoyi.zhushi.util.Constans; |
|
|
|
import com.ruoyi.zhushi.util.TimeUtils; |
|
|
@@ -40,6 +43,11 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
@Autowired |
|
|
|
private DkRecordMapper dkMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private NjBalanceManageDetailMapper njBalanceManageDetailMapper; |
|
|
|
@Autowired |
|
|
|
private NjBalanceManageDetailService njBalanceManageDetailService; |
|
|
|
|
|
|
|
public String getTime() { |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
Date currentDate = new Date(); |
|
|
@@ -141,14 +149,6 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
return ; |
|
|
|
} |
|
|
|
|
|
|
|
// 如果传了 strDay,再校验日期 |
|
|
|
if (StringUtils.isNotBlank(dkCheckInRecordDTO.getStrDay())) { |
|
|
|
LocalDate inputDay = LocalDate.parse(dkCheckInRecordDTO.getStrDay()); // e.g. "2025-07-10" |
|
|
|
if (inputDay.isAfter(now)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 查询出所有人员 |
|
|
|
List<JSONObject> jsonObjects = dkMapper.queryAllUsers(dkCheckInRecordDTO.getAttendanceGroupIds()); |
|
|
|
if(jsonObjects==null||jsonObjects.size() == 0){ |
|
|
@@ -166,15 +166,6 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
|
|
|
|
try { |
|
|
|
InputStream inputStream = null; |
|
|
|
Workbook workbook; |
|
|
|
// 定义迟到人数 |
|
|
|
int latePersonCount = 0; |
|
|
|
// 定义早退人数 |
|
|
|
int earlyPersonCount = 0; |
|
|
|
// 定义迟到次数 |
|
|
|
int lateCount = 0; |
|
|
|
// 定义早退次数 |
|
|
|
int earlyCount = 0; |
|
|
|
// 加载模板文件 |
|
|
|
if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){ |
|
|
|
ClassPathResource resource = new ClassPathResource("template/template-guonei.xlsx"); |
|
|
@@ -184,8 +175,16 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
ClassPathResource resource = new ClassPathResource("template/template-riben.xlsx"); |
|
|
|
inputStream = resource.getInputStream(); |
|
|
|
} |
|
|
|
workbook = WorkbookFactory.create(inputStream); |
|
|
|
|
|
|
|
// 定义迟到人数 |
|
|
|
int latePersonCount = 0; |
|
|
|
// 定义早退人数 |
|
|
|
int earlyPersonCount = 0; |
|
|
|
// 定义迟到次数 |
|
|
|
int lateCount = 0; |
|
|
|
// 定义早退次数 |
|
|
|
int earlyCount = 0; |
|
|
|
Workbook workbook = WorkbookFactory.create(inputStream); |
|
|
|
// 遍历所有人员 |
|
|
|
for (int i = 0; i <= dkCheckInRecordDTOS.size(); i++){ |
|
|
|
int newSheetIndex = workbook.getNumberOfSheets(); |
|
|
@@ -226,7 +225,7 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
if (attendanceData.getDayRecords().size() == 0){ |
|
|
|
return; |
|
|
|
} |
|
|
|
fillTemplate(newSheet, attendanceData); |
|
|
|
fillTemplate(newSheet, attendanceData,dkCheckInRecordDTO.getStrMonth(),dk); |
|
|
|
} |
|
|
|
// 日本模版 |
|
|
|
if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){ |
|
|
@@ -236,7 +235,7 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
/* if (attendanceData.getDayRecords().size() == 0){ |
|
|
|
break; |
|
|
|
}*/ |
|
|
|
fillTemplateRiBen(newSheet, attendanceData); |
|
|
|
fillTemplateRiBen(newSheet, attendanceData,dkCheckInRecordDTO.getStrMonth(),dk); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -287,23 +286,10 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
//根据userId获取打卡配置信息 |
|
|
|
DkAttendanceGroup dkAttendanceGroup = dkMapper.queryConfigByUserId(dkCheckInRecordDTO.getSysUserId()); |
|
|
|
|
|
|
|
/* // 是否允许迟到 |
|
|
|
Boolean allowLate = dkAttendanceGroup.getAllowLate(); |
|
|
|
// 允许迟到的时长 |
|
|
|
Integer lateRange = dkAttendanceGroup.getLateRange(); |
|
|
|
// 是否允许早退 |
|
|
|
Boolean allowEarly = dkAttendanceGroup.getAllowEarly(); |
|
|
|
// 允许早退的时长 |
|
|
|
Integer earlyRange = dkAttendanceGroup.getEarlyRange();*/ |
|
|
|
|
|
|
|
|
|
|
|
// 定义集合,用于存储每天打卡记录 |
|
|
|
List<DayRecord> dayRecords = new ArrayList<>(); |
|
|
|
// 根据用户的ID查询该用户所有的打卡记录 |
|
|
|
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null); |
|
|
|
//打过卡的 |
|
|
|
//queryWrapper.ne( DkCheckInRecord::getCheckInStatus, 0); |
|
|
|
//queryWrapper.orderByAsc(DkCheckInRecord::getCheckInTime); |
|
|
|
List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper); |
|
|
|
if (dkCheckInRecordDTOS == null && dkCheckInRecordDTOS.isEmpty()){ |
|
|
|
return data; |
|
|
@@ -410,7 +396,6 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 判断是否为法定节假日加班 |
|
|
|
dayRecords.add(dayRecord); |
|
|
|
} |
|
|
|
|
|
|
@@ -423,25 +408,24 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
private void fillTemplate(Sheet sheet, EmployeeAttendance data) { |
|
|
|
private void fillTemplate(Sheet sheet, EmployeeAttendance data,String date,DkCheckInRecordDTO dk) { |
|
|
|
// 1.填充标题区域 |
|
|
|
setCellValue(sheet, 6, 6, data.getUserName()); |
|
|
|
setCellValue(sheet, 6, 10, data.getEmployeeName()); |
|
|
|
setCellValue(sheet, 3, 1, data.getDateTime()); |
|
|
|
setCellValue(sheet, 6, 6, dk.getSysUserName()); |
|
|
|
setCellValue(sheet, 6, 10, dk.getNickName()); |
|
|
|
setCellValue(sheet, 3, 1, date); |
|
|
|
|
|
|
|
//2.考勤数据区域 |
|
|
|
//2.1 生成全部的日期和星期 并设置颜色 |
|
|
|
int year = LocalDate.now().getYear(); |
|
|
|
int month = LocalDate.now().getMonthValue(); |
|
|
|
int njCount =0; |
|
|
|
int rowIndex = 10; |
|
|
|
Map<Integer, List<CalendarGenerator.DayInfo>> calendar = CalendarGenerator.generateYearCalendar(year); |
|
|
|
List<CalendarGenerator.DayInfo> dayInfos = calendar.get(month); |
|
|
|
List<CalendarGenerator.DayInfo> dayInfos = CalendarGenerator.getMonthDays(date,"cn"); |
|
|
|
for (int i = 0; i < dayInfos.size(); i++) { |
|
|
|
rowIndex = i + 10; |
|
|
|
//初始化天数 |
|
|
|
setCellValue(sheet, rowIndex, 1, dayInfos.get(i).getDay()); |
|
|
|
setCellValue(sheet, rowIndex, 1, dayInfos.get(i).getDayNumber()); |
|
|
|
//初始化星期 |
|
|
|
String weekName = dayInfos.get(i).getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINESE).replace("星期",""); |
|
|
|
String weekName = dayInfos.get(i).getDayOfWeek(); |
|
|
|
|
|
|
|
setCellValue(sheet, rowIndex, 2, weekName); |
|
|
|
// 星期六和星期日背景颜色设置 |
|
|
|
if ("六".equals(weekName) || "日".equals(weekName)) { |
|
|
@@ -459,6 +443,43 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
|
|
|
cell.setCellStyle(style); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查询当前用户 这个月的年假 审批通过记录 |
|
|
|
QueryWrapper<NjBalanceManageDetail> njWrapper = new QueryWrapper<>(); |
|
|
|
njWrapper.eq("user_id", dk.getSysUserId()); |
|
|
|
njWrapper.eq("status","2"); |
|
|
|
njWrapper.apply("YEAR(create_time) = {0}", Integer.parseInt(date.substring(0,4))); |
|
|
|
njWrapper.apply("MONTH(create_time) = {0}",Integer.parseInt(date.substring(5))); |
|
|
|
List<NjBalanceManageDetail> njList = njBalanceManageDetailMapper.selectList(njWrapper); |
|
|
|
|
|
|
|
boolean isLeave = false; |
|
|
|
if (njList != null && !njList.isEmpty()) { |
|
|
|
for (NjBalanceManageDetail detail : njList) { |
|
|
|
String applyDates = detail.getApplyDates(); |
|
|
|
if (applyDates != null && !applyDates.isEmpty()) { |
|
|
|
// 按逗号分割日期字符串 |
|
|
|
String[] dateArray = applyDates.split(","); |
|
|
|
for (String dateStr : dateArray) { |
|
|
|
//这一天是否申请了年假 |
|
|
|
if (dayInfos.get(i).getDate().equals(dateStr.trim())) { |
|
|
|
isLeave = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (isLeave) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isLeave) { |
|
|
|
DayRecord record = new DayRecord(); |
|
|
|
record.setNj("●"); |
|
|
|
fillTemplateCell(sheet, rowIndex, record); |
|
|
|
njCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
//2.2 考勤数据赋值 |
|
|
|
for (DayRecord record : data.getDayRecords()) { |
|
|
@@ -473,6 +494,7 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
setCellValue(sheet, 41, 6, data.getExceptionCount()); |
|
|
|
setCellValue(sheet, 41, 7, formatOvertime(data.getWorkOverTime()==null?0:data.getWorkOverTime().doubleValue())); |
|
|
|
setCellValue(sheet, 41, 8, formatOvertime(data.getRestOverTime()==null?0:data.getRestOverTime().doubleValue())); |
|
|
|
setCellValue(sheet, 41, 10, njCount); |
|
|
|
} |
|
|
|
|
|
|
|
private void fillTemplateCell(Sheet sheet, int rowIndex, DayRecord record) { |
|
|
@@ -483,7 +505,7 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
setCellValue(sheet, rowIndex, 7, record.getGongzuori()); |
|
|
|
setCellValue(sheet, rowIndex, 8, record.getXiuxiri()); |
|
|
|
setCellValue(sheet, rowIndex, 9, record.getFadingjiari()); |
|
|
|
setCellValue(sheet, rowIndex, 10, record.getXiuxi()); |
|
|
|
setCellValue(sheet, rowIndex, 10, record.getNj()); |
|
|
|
setCellValue(sheet, rowIndex, 11, record.getQingjia()); |
|
|
|
setCellValue(sheet, rowIndex, 12, record.getRemark()); |
|
|
|
} |
|
|
@@ -545,26 +567,24 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
return data; |
|
|
|
} |
|
|
|
//日本excel 整体信息赋值 |
|
|
|
private void fillTemplateRiBen(Sheet sheet, EmployeeAttendance data) { |
|
|
|
private void fillTemplateRiBen(Sheet sheet, EmployeeAttendance data,String date,DkCheckInRecordDTO dk) { |
|
|
|
// 1.填充标题区域 |
|
|
|
setCellValue(sheet, 3, 1, data.getDateTime()); |
|
|
|
setCellValue(sheet, 6, 6, data.getUserName()); |
|
|
|
setCellValue(sheet, 6, 8, data.getEmployeeName()); |
|
|
|
setCellValue(sheet, 3, 1, date); |
|
|
|
setCellValue(sheet, 6, 6, dk.getSysUserName()); |
|
|
|
setCellValue(sheet, 6, 8, dk.getNickName()); |
|
|
|
|
|
|
|
// |
|
|
|
// 要生成的年份 |
|
|
|
int year = LocalDate.now().getYear(); |
|
|
|
int month = LocalDate.now().getMonthValue(); |
|
|
|
int rowIndex = 10; |
|
|
|
Map<Integer, List<CalendarGenerator.DayInfo>> calendar = CalendarGenerator.generateYearCalendar(year); |
|
|
|
List<CalendarGenerator.DayInfo> dayInfos = calendar.get(month); |
|
|
|
List<CalendarGenerator.DayInfo> dayInfos = CalendarGenerator.getMonthDays(date,"jp"); |
|
|
|
for (int i = 0; i < dayInfos.size(); i++) { |
|
|
|
rowIndex = i + 10; |
|
|
|
//初始化天数 |
|
|
|
setCellValue(sheet, rowIndex, 1, dayInfos.get(i).getDay()); |
|
|
|
setCellValue(sheet, rowIndex, 1, dayInfos.get(i).getDayNumber()); |
|
|
|
//初始化星期 日本的星期名 |
|
|
|
int week = dayInfos.get(i).getDayOfWeek().getValue(); |
|
|
|
String weekName = getJpWeekName(week); |
|
|
|
String weekName = dayInfos.get(i).getDayOfWeek(); |
|
|
|
setCellValue(sheet, rowIndex, 2, weekName); |
|
|
|
// 日本的星期六和星期日背景颜色设置 |
|
|
|
if ("土".equals(weekName) || "日".equals(weekName)) { |
|
|
@@ -631,26 +651,6 @@ public class DkRecordServiceImpl implements DkRecordService { |
|
|
|
return half; |
|
|
|
|
|
|
|
} |
|
|
|
//查询日本星期名字 |
|
|
|
private String getJpWeekName(int week) { |
|
|
|
String WeekName = ""; |
|
|
|
if(week == Constans.EXPORT_ZHOUYI){ |
|
|
|
WeekName = "月"; |
|
|
|
}else if(week == Constans.EXPORT_ZHOUER){ |
|
|
|
WeekName = "火"; |
|
|
|
}else if(week == Constans.EXPORT_ZHOUSAN){ |
|
|
|
WeekName = "水"; |
|
|
|
}else if(week == Constans.EXPORT_ZHOUSI){ |
|
|
|
WeekName = "木"; |
|
|
|
}else if(week == Constans.EXPORT_ZHOUWU){ |
|
|
|
WeekName = "金"; |
|
|
|
} else if(week == Constans.EXPORT_ZHOULIU){ |
|
|
|
WeekName = "土"; |
|
|
|
}else if(week == Constans.EXPORT_ZHOURI){ |
|
|
|
WeekName = "日"; |
|
|
|
} |
|
|
|
return WeekName; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算加班时间,返回格式为 HH:mm:ss。如果加班时间为0则返回空字符串。 |