bug修复

This commit is contained in:
guoshengxiong 2025-08-21 17:51:23 +08:00
parent e6ae6c94e0
commit 933f6ebb41
16 changed files with 582 additions and 162 deletions

View File

@ -83,5 +83,11 @@ public class WorkerAttendanceVo {
private String mockTime;
private String enterpriseId;
private String enterpriseName;
/**
* 人员id
*/
@ApiModelProperty(value = "人员id")
private java.lang.Long workerId;
}

View File

@ -73,7 +73,7 @@ public class SafetyHatDataDailyStatisticsServiceImpl extends ServiceImpl<SafetyH
WorkerInfo workerInfo = workerInfoService.queryById(workerId);
String projectSn = workerInfo.getProjectSn();
Map<String, Long> devSn2WorkerMap = safetyHatDevService.list(new LambdaQueryWrapper<SafetyHatDev>()
.eq(SafetyHatDev::getProjectSn, projectSn)).stream().collect(Collectors.toMap(SafetyHatDev::getDevSn, SafetyHatDev::getWorkerInfoId, (o1, o2) -> o1));
.eq(SafetyHatDev::getProjectSn, projectSn)).stream().filter(d -> Objects.nonNull(d.getDevSn()) && Objects.nonNull(d.getWorkerInfoId())).collect(Collectors.toMap(SafetyHatDev::getDevSn, SafetyHatDev::getWorkerInfoId, (o1, o2) -> o1));
//实时计算
ArrayList<SafetyHatDataDailyStatisticsVo> vos = new ArrayList<>();
List<SafetyHatFence> fences = safetyHatFenceService.list(new LambdaQueryWrapper<SafetyHatFence>().eq(SafetyHatFence::getProjectSn, projectSn));

View File

@ -22,13 +22,16 @@ import com.zhgd.xmgl.async.AsyncAttendance;
import com.zhgd.xmgl.base.entity.vo.echarts.ChartDataVo;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.service.IProjectService;
import com.zhgd.xmgl.modules.worker.entity.EnterpriseInfo;
import com.zhgd.xmgl.modules.worker.entity.WorkerAttendance;
import com.zhgd.xmgl.modules.worker.entity.WorkerDailyAttendanceStatisticsV2;
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import com.zhgd.xmgl.modules.worker.entity.bo.ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo;
import com.zhgd.xmgl.modules.worker.entity.dto.WorkerDailyAttendanceStatisticsV2Dto;
import com.zhgd.xmgl.modules.worker.entity.vo.*;
import com.zhgd.xmgl.modules.worker.service.IWorkerAttendanceService;
import com.zhgd.xmgl.modules.worker.service.IWorkerDailyAttendanceStatisticsV2Service;
import com.zhgd.xmgl.modules.worker.service.impl.EnterpriseInfoServiceImpl;
import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl;
import com.zhgd.xmgl.security.util.SecurityUtils;
import com.zhgd.xmgl.util.EasyPoiUtil;
@ -43,6 +46,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.core.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
@ -76,6 +80,9 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
@Lazy
@Autowired
IProjectService projectService;
@Autowired
@Lazy
EnterpriseInfoServiceImpl enterpriseInfoService;
@Lazy
@Autowired
private IWorkerDailyAttendanceStatisticsV2Service workerDailyAttendanceStatisticsV2Service;
@ -250,6 +257,15 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
vo.setDailyDayMap(dailyDayMap);
vo.setDailyAttendanceMap(dailyAttendanceMap);
vo.setPersonSn(workerInfo.getPersonSn());
vo.setWorkerId(workerInfo.getId());
vo.setWorkerTypeName(workerInfo.getTypeName());
vo.setPhoneNumber(workerInfo.getPhoneNumber());
vo.setIdCard(workerInfo.getIdCard());
vo.setSex(workerInfo.getSex());
vo.setEnterDate(workerInfo.getEnterDate());
vo.setProjectSn(workerInfo.getProjectSn());
vo.setPayRollBankName(workerInfo.getPayRollBankName());
vo.setPayRollBankNumber(workerInfo.getPayRollBankNumber());
vos.add(vo);
}
IPage<StatisticsListVo> p = new Page<>();
@ -553,7 +569,7 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
vo.setPersonType(workerInfo.getPersonType());
vo.setEnterpriseName(workerInfo.getEnterpriseName());
vo.setWorkerName(workerInfo.getWorkerName());
vo.setDeptName(workerInfo.getDepartmentName());
vo.setDeptName(Objects.equals(workerInfo.getPersonType(), 1) ? workerInfo.getTeamName() : workerInfo.getDepartmentName());
vo.setProjectSn(workerInfo.getProjectSn());
vo.setPersonSn(workerInfo.getPersonSn());
vo.setAttendanceDate(DateUtil.parseDate(attendanceDate));
@ -571,14 +587,10 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
}
List<WorkerAttendance> attendances = personSn2AttendancesMap.get(workerInfo.getPersonSn());
if (Objects.equals(vo.getIsAttendance(), 1) && CollUtil.isNotEmpty(attendances)) {
String firstInTime = attendances.stream().filter(w -> Objects.equals(w.getPassType(), 1)).min(Comparator.comparing(WorkerAttendance::getCreateTime)).map(WorkerAttendance::getCreateTime).orElse(null);
String endOutTime = attendances.stream().filter(w -> Objects.equals(w.getPassType(), 2)).max(Comparator.comparing(WorkerAttendance::getCreateTime)).map(WorkerAttendance::getCreateTime).orElse(null);
vo.setFirstInTime(firstInTime);
vo.setEndOutTime(endOutTime);
String firstTimeAm = attendances.stream().filter(w -> DateUtil.compare(DateUtil.parseDateTime(w.getCreateTime()), DateUtil.parseDateTime(attendanceDate + " 12:00:00")) < 0).min(Comparator.comparing(WorkerAttendance::getCreateTime)).map(WorkerAttendance::getCreateTime).orElse(null);
vo.setFirstTimeAm(firstTimeAm);
String endTimePm = attendances.stream().filter(w -> DateUtil.compare(DateUtil.parseDateTime(w.getCreateTime()), DateUtil.parseDateTime(attendanceDate + " 12:00:00")) >= 0).max(Comparator.comparing(WorkerAttendance::getCreateTime)).map(WorkerAttendance::getCreateTime).orElse(null);
vo.setEndTimePm(endTimePm);
vo.setFirstInTime(Optional.ofNullable(getFirstInTime(attendances)).map(WorkerAttendance::getCreateTime).orElse(null));
vo.setEndOutTime(Optional.ofNullable(getEndOutTime(attendances)).map(WorkerAttendance::getCreateTime).orElse(null));
vo.setFirstTimeAm(Optional.ofNullable(getFirstTimeAm(attendances)).map(WorkerAttendance::getCreateTime).orElse(null));
vo.setEndTimePm(Optional.ofNullable(getEndTimePm(attendances)).map(WorkerAttendance::getCreateTime).orElse(null));
vo.setAttendanceList(attendances);
}
vo.setWorkerId(workerInfo.getId());
@ -592,6 +604,50 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
return p;
}
/**
* 下午打卡(未次)
*
* @param attendances
* @return
*/
@Nullable
private WorkerAttendance getEndTimePm(List<WorkerAttendance> attendances) {
return attendances.stream().filter(w -> DateUtil.compare(DateUtil.parseDateTime(w.getCreateTime()), DateUtil.parseDateTime(w.getCreateTime().substring(0, 10) + " 12:00:00")) >= 0)
.max(Comparator.comparing(WorkerAttendance::getCreateTime)).orElse(null);
}
/**
* 上午打卡(首次)
*
* @param attendances
* @return
*/
@Nullable
private WorkerAttendance getFirstTimeAm(List<WorkerAttendance> attendances) {
return attendances.stream().filter(w -> DateUtil.compare(DateUtil.parseDateTime(w.getCreateTime()), DateUtil.parseDateTime(w.getCreateTime().substring(0, 10) + " 12:00:00")) < 0)
.min(Comparator.comparing(WorkerAttendance::getCreateTime)).orElse(null);
}
/**
* 获取出场打卡(末次)
*
* @param attendances
* @return
*/
private WorkerAttendance getEndOutTime(List<WorkerAttendance> attendances) {
return attendances.stream().filter(w -> Objects.equals(w.getPassType(), 2)).max(Comparator.comparing(WorkerAttendance::getCreateTime)).orElse(null);
}
/**
* 获取进场打卡(首次)
*
* @param attendances
* @return
*/
private WorkerAttendance getFirstInTime(List<WorkerAttendance> attendances) {
return attendances.stream().filter(w -> Objects.equals(w.getPassType(), 1)).min(Comparator.comparing(WorkerAttendance::getCreateTime)).orElse(null);
}
@ApiOperation(value = "统计考勤日报", notes = "统计考勤日报", httpMethod = "POST")
@ApiImplicitParams({
@ApiImplicitParam(name = "projectSn", value = "项目sn", paramType = "body", required = true, dataType = "String"),
@ -774,141 +830,372 @@ public class WorkerDailyAttendanceStatisticsV2Controller {
@ApiImplicitParam(name = "startDate", value = "开始日期yyyy-MM-dd", paramType = "body", required = true, dataType = "String"),
@ApiImplicitParam(name = "endDate", value = "结束日期yyyy-MM-dd", paramType = "body", required = true, dataType = "String"),
@ApiImplicitParam(name = "groupByType", value = "1.按项目;2.按参建单位;3.按班组/部门;4.按人员", paramType = "body", required = true, dataType = "String"),
@ApiImplicitParam(name = "downloadType", value = "1上下午打卡2进出场打卡", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "effectiveHour", value = "有效工时", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "downloadType", value = "1每日明细上下午打卡2进出场打卡3每日工时4每日明细", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "hourValBegin", value = "大于有效工时", paramType = "body", required = false, dataType = "String"),
@ApiImplicitParam(name = "enterpriseId", value = "单位id", paramType = "body", required = false, dataType = "String"),
})
@PostMapping(value = "/exportWorkerDailyAttendancesStaticsByMonthXls")
public void exportWorkerDailyAttendancesStaticsByMonthXls(HttpServletResponse response, @RequestBody HashMap<String, Object> param) {
// String templateUrl = null;
// try {
// String projectSn = MapUtils.getString(param, "projectSn");
// String startDate = MapUtils.getString(param, "startDate");
// String endDate = MapUtils.getString(param, "endDate");
// Integer downloadType = MapUtils.getInteger(param, "downloadType");
// Integer groupByType = MapUtils.getInteger(param, "groupByType");
// List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR);
// Map<Integer, Map<String, Object>> root = new HashMap<>();
// if (Objects.equals(groupByType, 3)) {
// //按班组/部门
// if (Objects.equals(downloadType, 1)) {
// //考勤月报-按班组-每日出入(打卡记录明细).xlsx
// param.put("startTime", startDate);
// param.put("endTime", endDate);
// param.put("pageSize", -1);
// List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
// Map<String, List<StatisticsListVo>> deptNameMap = voList.stream().collect(Collectors.groupingBy(StatisticsListVo::getDeptName));
// Map<String, Object> sheetMap = new HashMap<>();
// List<Map<String, Object>> listMap = new ArrayList<>();
// for (Map.Entry<String, List<StatisticsListVo>> entry : deptNameMap.entrySet()) {
// int j = 0;
// for (StatisticsListVo vo : entry.getValue()) {
// Map<String, Object> map = new HashMap<>();
// map.put("firstInTimeYes", StrUtil.isNotBlank(vo.getFirstInTime()) ? "" : "×");
// map.put("firstInTime", vo.getFirstInTime());
// map.put("endOutTimeYes", StrUtil.isNotBlank(vo.getEndOutTime()) ? "" : "×");
// map.put("endOutTime", vo.getEndOutTime());
// map.put("firstTimeAmYes", StrUtil.isNotBlank(vo.getFirstTimeAm()) ? "" : "×");
// map.put("firstTimeAm", vo.getFirstTimeAm());
// map.put("endTimePmYes", StrUtil.isNotBlank(vo.getEndTimePm()) ? "" : "×");
// map.put("endTimePm", vo.getEndTimePm());
// map.put("personType", vo.getPersonType());
// map.put("enterpriseName", vo.getEnterpriseName());
// map.put("workerName", vo.getWorkerName());
// map.put("deptName", vo.getDeptName());
// map.put("projectSn", vo.getProjectSn());
// map.put("personSn", vo.getPersonSn());
// map.put("attendanceDate", vo.getAttendanceDate());
// map.put("hourVal", vo.getHourVal());
// map.put("dayVal", vo.getDayVal());
// map.put("isAttendance", vo.getIsAttendance());
// map.put("overtimeHourVal", vo.getOvertimeHourVal());
// map.put("overtimeDayVal", vo.getOvertimeDayVal());
// map.put("inserviceType", vo.getInserviceType());
// AtomicInteger i = new AtomicInteger(1);
// map.put("attendanceList", Objects.nonNull(vo.getAttendanceList()) ? vo.getAttendanceList().stream().map(a -> {
// return i.getAndIncrement() + ".(" + (Objects.equals(a.getPassType(), 1) ? "进场" : "出场") + a.getCreateTime() + ")";
// }).collect(Collectors.joining("\n")) : "");
// map.put("workerTypeName", vo.getWorkerTypeName());
// map.put("phoneNumber", vo.getPhoneNumber());
// map.put("idCard", vo.getIdCard());
// map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
// map.put("enterDate", vo.getEnterDate());
// listMap.add(map);
// }
// }
// sheetMap.put("date", DateUtil.formatDate(dateTime));
// sheetMap.put("listMap", listMap);
// root.put(j++, sheetMap);
// }
// }
//
// param.put("pageNo", 1);
// param.put("pageSize", -1);
// int j = 0;
// String tempSheetName;
// if (Objects.equals(downloadType, 1)) {
// tempSheetName = "考勤日报-出勤导出模版(上午下午).xlsx";
// } else {
// tempSheetName = "考勤日报-出勤导出模版(进场出场).xlsx";
// }
// for (DateTime dateTime : dateTimes) {
// param.put("attendanceDate", DateUtil.formatDate(dateTime));
// List<WorkerDailyAttendancesByDateVo> records = doGetWorkerDailyAttendancePageByDateVoIPage(param).getRecords();
// Map<String, Object> sheetMap = new HashMap<>();
// List<Map<String, Object>> listMap = new ArrayList<>();
// for (WorkerDailyAttendancesByDateVo vo : records) {
// Map<String, Object> map = new HashMap<>();
// map.put("firstInTimeYes", StrUtil.isNotBlank(vo.getFirstInTime()) ? "" : "×");
// map.put("firstInTime", vo.getFirstInTime());
// map.put("endOutTimeYes", StrUtil.isNotBlank(vo.getEndOutTime()) ? "" : "×");
// map.put("endOutTime", vo.getEndOutTime());
// map.put("firstTimeAmYes", StrUtil.isNotBlank(vo.getFirstTimeAm()) ? "" : "×");
// map.put("firstTimeAm", vo.getFirstTimeAm());
// map.put("endTimePmYes", StrUtil.isNotBlank(vo.getEndTimePm()) ? "" : "×");
// map.put("endTimePm", vo.getEndTimePm());
// map.put("personType", vo.getPersonType());
// map.put("enterpriseName", vo.getEnterpriseName());
// map.put("workerName", vo.getWorkerName());
// map.put("deptName", vo.getDeptName());
// map.put("projectSn", vo.getProjectSn());
// map.put("personSn", vo.getPersonSn());
// map.put("attendanceDate", vo.getAttendanceDate());
// map.put("hourVal", vo.getHourVal());
// map.put("dayVal", vo.getDayVal());
// map.put("isAttendance", vo.getIsAttendance());
// map.put("overtimeHourVal", vo.getOvertimeHourVal());
// map.put("overtimeDayVal", vo.getOvertimeDayVal());
// map.put("inserviceType", vo.getInserviceType());
// AtomicInteger i = new AtomicInteger(1);
// map.put("attendanceList", Objects.nonNull(vo.getAttendanceList()) ? vo.getAttendanceList().stream().map(a -> {
// return i.getAndIncrement() + ".(" + (Objects.equals(a.getPassType(), 1) ? "进场" : "出场") + a.getCreateTime() + ")";
// }).collect(Collectors.joining("\n")) : "");
// map.put("workerTypeName", vo.getWorkerTypeName());
// map.put("phoneNumber", vo.getPhoneNumber());
// map.put("idCard", vo.getIdCard());
// map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
// map.put("enterDate", vo.getEnterDate());
// listMap.add(map);
// }
// sheetMap.put("date", DateUtil.formatDate(dateTime));
// sheetMap.put("listMap", listMap);
// root.put(j++, sheetMap);
// }
// templateUrl = Fileutils.getExportTemplateFile("excel/" + tempSheetName).getAbsolutePath();
// String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
// EasyPoiUtil.cloneSheetMultipleTimes(templateUrl, outputTemplateFilePath, "1", dateTimes.size() - 1);
// TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
// params.setSheetName(dateTimes.stream().map(DateUtil::formatDate).collect(Collectors.toList()).toArray(new String[]{}));
// Workbook workbook = ExcelExportUtil.exportExcel(root, params);
// //设置下拉
// ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
// } catch (IOException e) {
// log.error("", e);
// throw new OpenAlertException("系统错误");
// } finally {
// if (templateUrl != null) {
// FileUtil.deleteFile(templateUrl);
// }
// }
String templateUrl = null;
try {
String projectSn = MapUtils.getString(param, "projectSn");
Project project = projectService.getOne(new LambdaQueryWrapper<Project>()
.eq(Project::getProjectSn, projectSn));
String startDate = MapUtils.getString(param, "startDate");
String endDate = MapUtils.getString(param, "endDate");
Integer downloadType = MapUtils.getInteger(param, "downloadType");
Integer groupByType = MapUtils.getInteger(param, "groupByType");
List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parseDate(startDate), DateUtil.parseDate(endDate), DateField.DAY_OF_YEAR);
Map<Integer, Map<String, Object>> root = new HashMap<>();
int sheetIndex = 0;
List<String> sheetNames = new ArrayList<>();
String tempSheetName;
if (Objects.equals(groupByType, 3)) {
//按班组/部门
tempSheetName = "考勤月报-按班组.xlsx";
//考勤月报-按班组.xlsx
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, List<StatisticsListVo>> deptNameMap = voList.stream().collect(Collectors.groupingBy(StatisticsListVo::getDeptName));
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
BigDecimal totalAttendanceDay = BigDecimal.ZERO;
BigDecimal totalHour = BigDecimal.ZERO;
for (Map.Entry<String, List<StatisticsListVo>> entry : deptNameMap.entrySet()) {
Map<String, Object> sheetMap = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
List<StatisticsListVo> vos = entry.getValue();
int index = 0;
for (StatisticsListVo vo : vos) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", vo.getPersonType());
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
sheetMap.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
sheetMap.put("delete" + (z + 1), false);
String value;
if (Objects.equals(downloadType, 1) || Objects.equals(downloadType, 2)) {
value = getExcelAmPmAttendanceByDate(personSn2Date2AttendancesMap, vo, dateTime, downloadType);
} else if (Objects.equals(downloadType, 3)) {
//每日工时
value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("");
} else {
//每日明细
value = Optional.ofNullable(vo.getDailyAttendanceMap().get(DateUtil.formatDate(dateTime))).map(integer -> Objects.equals(integer, 1) ? "" : "×").orElse("x");
}
map.put("attendanceByDate" + (z + 1), value);
}
for (int i = dateTimes.size(); i < 31; i++) {
sheetMap.put("delete" + (i + 1), true);
}
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
totalAttendanceDay = NumberUtil.add(vo.getTotalAttendanceDay(), totalAttendanceDay);
totalHour = NumberUtil.add(vo.getTotalHour(), totalHour);
listMap.add(map);
}
sheetMap.put("listMap", listMap);
sheetMap.put("projectName", project.getProjectName());
StatisticsListVo vo = CollUtil.getFirst(vos);
sheetMap.put("title", StrUtil.format("项目名称:{} 参建单位名称:{} {}名称:{} 总人数:{} 时间:({} - {}",
project.getProjectName(), vo.getEnterpriseName(), vo.getPersonType() == 1 ? "班组" : "部门", vo.getDeptName(), vos.size(), startDate, endDate));
sheetMap.put("totalAttendanceDay", totalAttendanceDay);
sheetMap.put("totalHour", totalHour);
root.put(sheetIndex++, sheetMap);
sheetNames.add(entry.getKey());
}
templateUrl = Fileutils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
EasyPoiUtil.cloneSheetMultipleTimes(templateUrl, outputTemplateFilePath, "1", sheetNames.size() - 1);
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(sheetNames.toArray(new String[]{}));
Workbook workbook = ExcelExportUtil.exportExcel(root, params);
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
} else if (Objects.equals(groupByType, 2)) {
//按参建单位
tempSheetName = "考勤月报-按单位-出勤人数与考勤报表.xlsx";
//导出sheet1上海振南出勤人数
List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo> list = workerDailyAttendanceStatisticsV2Service.countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(param);
Map<String, List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo>> date2Map = list.stream().collect(Collectors.groupingBy(ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo::getDate));
Map<String, Object> sheetMap1 = new HashMap<>();
List<Map<String, Object>> colList = new ArrayList<Map<String, Object>>();
List<Map<String, Object>> listMap1 = new ArrayList<>();
Integer totalGlNum = 0;
Integer totalSgNum = 0;
Map<String, Integer> deptKeyMap = new HashMap<>();
for (Map.Entry<String, List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo>> entry : date2Map.entrySet()) {
int index = 0;
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("date", entry.getKey());
Integer glNum = 0;
Integer sgNum = 0;
for (ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo bo : entry.getValue()) {
Map<String, Object> e = new HashMap<>();
e.put("name", bo.getDeptName() + (bo.getPersonType() == 2 ? "(部门)" : "(班组)"));
e.put("glName", "管理人数");
e.put("sgName", "施工人数");
String glKey = "gl" + bo.getDeptName();
String sgKey = "sg" + bo.getDeptName();
e.put("glNum", "t." + glKey);
e.put("sgNum", "t." + sgKey);
e.put("glTotalNum", glKey);
e.put("sgTotalNum", sgKey);
colList.add(e);
if (Objects.equals(bo.getPersonType(), 1)) {
sgNum = bo.getWorkerNum() + sgNum;
} else {
glNum = bo.getWorkerNum() + glNum;
}
Integer glKeyVal = Objects.equals(bo.getPersonType(), 1) ? 0 : bo.getWorkerNum();
Integer sgKeyVal = Objects.equals(bo.getPersonType(), 2) ? 0 : bo.getWorkerNum();
map.put(glKey, glKeyVal);
map.put(sgKey, sgKeyVal);
deptKeyMap.merge(glKey, glKeyVal, (o, n) -> o + n);
deptKeyMap.merge(sgKey, sgKeyVal, (o, n) -> o + n);
}
map.put("glNum", glNum);
map.put("sgNum", sgNum);
map.put("totalNum", glNum + sgNum);
listMap1.add(map);
totalGlNum += glNum;
totalSgNum += sgNum;
}
sheetMap1.putAll(deptKeyMap);
sheetMap1.put("listMap", listMap1);
sheetMap1.put("totalGlNum", totalGlNum);
sheetMap1.put("totalSgNum", totalSgNum);
sheetMap1.put("totalNum", totalGlNum + totalSgNum);
sheetMap1.put("projectName", project.getProjectName());
String enterpriseId = MapUtils.getString(param, "enterpriseId");
sheetMap1.put("hourValBegin", MapUtils.getInteger(param, "hourValBegin"));
EnterpriseInfo enterpriseInfo = enterpriseInfoService.getById(enterpriseId);
String enterpriseName = enterpriseInfo.getEnterpriseName();
sheetMap1.put("enterpriseName", enterpriseName);
sheetMap1.put("colList", colList);
root.put(0, sheetMap1);
sheetNames.add(enterpriseName + "出勤人数");
//导出sheet2上海振南考勤报表
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Object> sheetMap2 = new HashMap<>();
int index = 0;
List<Map<String, Object>> listMap2 = new ArrayList<>();
for (StatisticsListVo vo : voList) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", vo.getPersonType());
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
sheetMap2.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
sheetMap2.put("delete" + (z + 1), false);
//每日工时
String value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("");
map.put("attendanceByDate" + (z + 1), value);
}
for (int i = dateTimes.size(); i < 31; i++) {
sheetMap2.put("delete" + (i + 1), true);
}
listMap2.add(map);
}
sheetMap2.put("listMap", listMap2);
sheetMap2.put("projectName", project.getProjectName());
sheetMap2.put("title", StrUtil.format("项目名称:{} 参建单位名称:{} 班组名称:全部 总人数:{} 时间:({} - {}",
project.getProjectName(), enterpriseName, voList.size(), startDate, endDate));
sheetMap2.put("enterpriseName", enterpriseName);
root.put(1, sheetMap2);
sheetNames.add(enterpriseName + "考勤报表");
templateUrl = Fileutils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(sheetNames.toArray(new String[]{}));
Workbook workbook = ExcelExportUtil.exportExcel(root, params);
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
} else if (Objects.equals(groupByType, 4)) {
//按人员
tempSheetName = "单个人员考勤出入明细报表.xlsx";
List<StatisticsListVo> voList = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
for (StatisticsListVo vo : voList) {
Map<String, Object> sheetMap = new HashMap<>();
sheetMap.put("startDate", startDate);
sheetMap.put("endDate", endDate);
List<Map<String, Object>> listMap = new ArrayList<>();
for (int z = 0; z < dateTimes.size(); z++) {
Map<String, Object> map = new HashMap<>();
DateTime date = dateTimes.get(z);
map.put("date", DateUtil.formatDate(date));
map.put("week", DateUtil.dayOfWeekEnum(date).toChinese());
map.put("detail", Optional.ofNullable(personSn2Date2AttendancesMap.get(vo.getPersonSn())).map(m -> m.get(DateUtil.formatDate(date)))
.map(attendances -> attendances.stream().sorted(Comparator.comparing(WorkerAttendance::getCreateTime))
.map(att -> DateUtil.format(DateUtil.parseDateTime(att.getCreateTime()), "HH:mm") + (att.getPassType() == 1 ? "入场" : "出场")).collect(Collectors.joining("\n"))).orElse(""));
listMap.add(map);
}
root.put(sheetIndex++, sheetMap);
sheetMap.put("projectName", project.getProjectName());
sheetMap.put("personType", vo.getPersonType() == 1 ? "班组" : "部门");
sheetMap.put("enterpriseName", vo.getEnterpriseName());
sheetMap.put("workerName", vo.getWorkerName());
sheetMap.put("deptName", vo.getDeptName());
sheetMap.put("workerTypeName", vo.getWorkerTypeName());
sheetMap.put("totalAttendanceDay", vo.getTotalAttendanceDay());
sheetNames.add(vo.getWorkerName());
}
templateUrl = Fileutils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
EasyPoiUtil.cloneSheetMultipleTimes(templateUrl, outputTemplateFilePath, "1", sheetNames.size() - 1);
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(sheetNames.toArray(new String[]{}));
Workbook workbook = ExcelExportUtil.exportExcel(root, params);
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
} else if (Objects.equals(groupByType, 1)) {
//按项目
tempSheetName = "考勤月报-按项目.xlsx";
param.put("startTime", startDate);
param.put("endTime", endDate);
param.put("pageSize", -1);
List<StatisticsListVo> vos = this.doCountDailyAttendanceByDateRange(param).getRecords();
Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap = workerAttendanceService.list(new LambdaQueryWrapper<WorkerAttendance>()
.eq(WorkerAttendance::getProjectSn, projectSn)
.ge(WorkerAttendance::getCreateTime, startDate)
.le(WorkerAttendance::getCreateTime, DateUtil.formatDateTime(DateUtil.endOfDay(DateUtil.parseDate(endDate))))
.select(WorkerAttendance::getPersonSn, WorkerAttendance::getCreateTime, WorkerAttendance::getPassType))
.stream().filter(w -> Objects.nonNull(w.getPersonSn())).collect(Collectors.groupingBy(WorkerAttendance::getPersonSn,
Collectors.groupingBy(o -> DateUtil.formatDate(DateUtil.parseDate(o.getCreateTime())),
Collectors.toList())));
BigDecimal totalAttendanceDay = BigDecimal.ZERO;
BigDecimal totalHour = BigDecimal.ZERO;
Map<String, Object> sheetMap = new HashMap<>();
List<Map<String, Object>> listMap = new ArrayList<>();
int index = 0;
for (StatisticsListVo vo : vos) {
Map<String, Object> map = new HashMap<>();
map.put("no", ++index);
map.put("personType", vo.getPersonType());
map.put("enterpriseName", vo.getEnterpriseName());
map.put("workerName", vo.getWorkerName());
map.put("deptName", vo.getDeptName());
map.put("projectSn", vo.getProjectSn());
map.put("personSn", vo.getPersonSn());
map.put("workerTypeName", vo.getWorkerTypeName());
map.put("phoneNumber", vo.getPhoneNumber());
map.put("idCard", vo.getIdCard());
map.put("sex", Objects.equals(vo.getSex(), 1) ? "" : "");
map.put("enterDate", vo.getEnterDate());
for (int z = 0; z < dateTimes.size(); z++) {
DateTime dateTime = dateTimes.get(z);
sheetMap.put("date" + (z + 1), DateUtil.format(dateTime, "M/d"));
sheetMap.put("delete" + (z + 1), false);
String value;
if (Objects.equals(downloadType, 1) || Objects.equals(downloadType, 2)) {
value = getExcelAmPmAttendanceByDate(personSn2Date2AttendancesMap, vo, dateTime, downloadType);
} else if (Objects.equals(downloadType, 3)) {
//每日工时
value = Optional.ofNullable(vo.getDailyHourMap().get(DateUtil.formatDate(dateTime))).map(decimal -> decimal.toString()).orElse("");
} else {
//每日明细
value = Optional.ofNullable(vo.getDailyAttendanceMap().get(DateUtil.formatDate(dateTime))).map(integer -> Objects.equals(integer, 1) ? "" : "×").orElse("x");
}
map.put("attendanceByDate" + (z + 1), value);
}
for (int i = dateTimes.size(); i < 31; i++) {
sheetMap.put("delete" + (i + 1), true);
}
map.put("totalHour", vo.getTotalHour());
map.put("totalAttendanceDay", vo.getTotalAttendanceDay());
totalAttendanceDay = NumberUtil.add(vo.getTotalAttendanceDay(), totalAttendanceDay);
totalHour = NumberUtil.add(vo.getTotalHour(), totalHour);
listMap.add(map);
}
sheetMap.put("listMap", listMap);
sheetMap.put("totalAttendanceDay", totalAttendanceDay);
sheetMap.put("totalWorkerNum", vos.size());
sheetMap.put("totalHour", totalHour);
sheetMap.put("startDate", startDate);
sheetMap.put("endDate", endDate);
sheetMap.put("projectName", project.getProjectName());
root.put(0, sheetMap);
sheetNames.add(project.getProjectName());
templateUrl = Fileutils.getExportTemplateFile("excel/workerDailyAttendanceStatisticsV2/" + tempSheetName).getAbsolutePath();
String outputTemplateFilePath = PathUtil.getBasePath() + "/temp/" + IdUtil.randomUUID() + ".xlsx";
TemplateExportParams params = new TemplateExportParams(outputTemplateFilePath, true);
params.setSheetName(sheetNames.toArray(new String[]{}));
Workbook workbook = ExcelExportUtil.exportExcel(root, params);
ExcelUtils.downLoadExcel(tempSheetName, response, workbook);
}
} catch (IOException e) {
log.error("", e);
throw new OpenAlertException("系统错误");
} finally {
if (templateUrl != null) {
FileUtil.deleteFile(templateUrl);
}
}
}
/**
* 获取一天上下午/进出场打卡格式
* 07:19入场;
* 17:39出场
*
* @param personSn2Date2AttendancesMap
* @param vo
* @param dateTime
* @param downloadType 1上下午打卡2进出场打卡
* @return
*/
private String getExcelAmPmAttendanceByDate(Map<String, Map<String, List<WorkerAttendance>>> personSn2Date2AttendancesMap, StatisticsListVo vo, DateTime dateTime, Integer downloadType) {
String attendanceByDate = "";
Optional<List<WorkerAttendance>> workerAttendances = Optional.ofNullable(personSn2Date2AttendancesMap.get(vo.getPersonSn())).map(m -> m.get(DateUtil.formatDate(dateTime)));
WorkerAttendance first = workerAttendances.map(attendances -> downloadType == 1 ? getFirstTimeAm(attendances) : getFirstInTime(attendances)).orElse(null);
if (first != null) {
attendanceByDate = DateUtil.format(DateUtil.parseDateTime(first.getCreateTime()), "HH:mm") + (first.getPassType() == 1 ? "入场" : "出场");
}
WorkerAttendance end = workerAttendances.map(attendances -> downloadType == 1 ? getEndTimePm(attendances) : getEndOutTime(attendances)).orElse(null);
if (end != null) {
if (StrUtil.isNotBlank(attendanceByDate)) {
attendanceByDate += "\n";
}
attendanceByDate += DateUtil.format(DateUtil.parseDateTime(end.getCreateTime()), "HH:mm") + (end.getPassType() == 1 ? "入场" : "出场");
}
return attendanceByDate;
}
}

View File

@ -0,0 +1,26 @@
package com.zhgd.xmgl.modules.worker.entity.bo;
import lombok.Data;
@Data
public class ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo {
/**
* 人员类型 1劳务人员 2管理人员
*/
private java.lang.Integer personType;
/**
* 日期
*/
private java.lang.String date;
/**
* 班组/部门
*/
private java.lang.String deptName;
/**
* 人数
*/
private java.lang.Integer workerNum;
}

View File

@ -64,4 +64,50 @@ public class StatisticsListVo {
*/
@ApiModelProperty(value = "人员sn")
private java.lang.String personSn;
/**
* 劳务人员Id
*/
@ApiModelProperty(value = "劳务人员Id")
private java.lang.Long workerId;
/**
* 工种名称
*/
@ApiModelProperty(value = "工种名称")
private String workerTypeName;
/**
* 手机号
*/
@ApiModelProperty(value = "手机号")
private java.lang.String phoneNumber;
/**
* 身份证号
*/
@ApiModelProperty(value = "身份证号")
private java.lang.String idCard;
/**
* 性别
*/
@ApiModelProperty(value = "性别1男2女")
private java.lang.Integer sex;
/**
* 进场日期
*/
@ApiModelProperty(value = "进场日期")
private java.lang.String enterDate;
/**
* 项目sn
*/
@ApiModelProperty(value = "项目sn")
private java.lang.String projectSn;
/**
* 工人工资卡银行开户行名称
*/
@ApiModelProperty(value = "工人工资卡银行开户行名称")
private java.lang.String payRollBankName;
/**
* 工人银行卡号
*/
@ApiModelProperty(value = "工人银行卡号")
private java.lang.String payRollBankNumber;
}

View File

@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhgd.xmgl.modules.worker.entity.WorkerDailyAttendanceStatisticsV2;
import com.zhgd.xmgl.modules.worker.entity.bo.CountWorkerDailyAttendanceStatisticsV2ByDateBo;
import com.zhgd.xmgl.modules.worker.entity.bo.ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo;
import com.zhgd.xmgl.modules.worker.entity.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -79,4 +80,6 @@ public interface WorkerDailyAttendanceStatisticsV2Mapper extends BaseMapper<Work
List<CountByEnterpriseVo> countNumByEnterprise(HashMap<String, Object> param);
List<CountNumByWorkerTypeVo> countNumByWorkerType(HashMap<String, Object> param);
List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo> countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(HashMap<String, Object> param);
}

View File

@ -55,6 +55,7 @@
,ei.id as enterprise_id
,if(c.id is not null,c.id,d.id) as department_team_id
,if(c.team_name is not null,c.team_name,d.department_name) as department_team_name
,b.id as worker_id
from worker_attendance a
LEFT JOIN worker_info b ON a.person_sn = b.person_sn
LEFT JOIN team_info c ON b.team_id = c.id

View File

@ -49,7 +49,7 @@
resultType="com.zhgd.xmgl.modules.worker.entity.vo.CountWorkerDailyAttendanceStatisticsV2Vo">
select
t.*
,ifnull(round(t.total_in_service_num/t.total_attendance_num*100,2),0) as attendance_rate_avg
,ifnull(round(t.total_attendance_num/t.total_in_service_num*100,2),0) as attendance_rate_avg
from (
select
count(*) as total_in_service_num
@ -57,11 +57,11 @@
,ifnull(sum(t.hour_val),0) as hour_val_total
from worker_daily_attendance_statistics_v2 t
JOIN worker_info a on t.person_sn=a.person_sn
JOIN team_info b ON a.team_id = b.id and a.person_type = 1
JOIN department_info c ON a.department_id = c.id and a.person_type = 2
JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
LEFT JOIN team_info b ON a.team_id = b.id and a.person_type = 1
LEFT JOIN department_info c ON a.department_id = c.id and a.person_type = 2
LEFT JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
JOIN enterprise_info en ON en.id = a.enterprise_id
INNER JOIN project_enterprise pe ON a.id = pe.enterprise_id and pe.project_sn=t.project_sn
INNER JOIN project_enterprise pe ON en.id = pe.enterprise_id and pe.project_sn=t.project_sn
where t.project_sn=#{projectSn}
<if test="personSn != null and personSn != ''">
and a.person_sn = #{personSn}
@ -97,7 +97,7 @@
resultType="com.zhgd.xmgl.modules.worker.entity.bo.CountWorkerDailyAttendanceStatisticsV2ByDateBo">
select
t.*
,ifnull(round(t.total_in_service_num/t.total_attendance_num*100,2),0) as attendance_rate_avg
,ifnull(round(t.total_attendance_num/t.total_in_service_num*100,2),0) as attendance_rate_avg
from (
select
<if test="startMonth != null and startMonth != ''">
@ -110,11 +110,11 @@
,ifnull(sum(t.is_attendance),0) as total_attendance_num
from worker_daily_attendance_statistics_v2 t
JOIN worker_info a on t.person_sn=a.person_sn
JOIN team_info b ON a.team_id = b.id and a.person_type = 1
JOIN department_info c ON a.department_id = c.id and a.person_type = 2
JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
LEFT JOIN team_info b ON a.team_id = b.id and a.person_type = 1
LEFT JOIN department_info c ON a.department_id = c.id and a.person_type = 2
LEFT JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
JOIN enterprise_info en ON en.id = a.enterprise_id
INNER JOIN project_enterprise pe ON a.id = pe.enterprise_id and pe.project_sn=t.project_sn
INNER JOIN project_enterprise pe ON en.id = pe.enterprise_id and pe.project_sn=t.project_sn
where t.project_sn=#{projectSn}
<if test="enterpriseTypeId != null and enterpriseTypeId != ''">
and pe.enterprise_type_id = #{enterpriseTypeId}
@ -152,11 +152,11 @@
,ifnull(sum(t.day_val),0) as day_val_total
from worker_daily_attendance_statistics_v2 t
JOIN worker_info a on t.person_sn=a.person_sn
JOIN team_info b ON a.team_id = b.id and a.person_type = 1
JOIN department_info c ON a.department_id = c.id and a.person_type = 2
JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
LEFT JOIN team_info b ON a.team_id = b.id and a.person_type = 1
LEFT JOIN department_info c ON a.department_id = c.id and a.person_type = 2
LEFT JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
JOIN enterprise_info en ON en.id = a.enterprise_id
INNER JOIN project_enterprise pe ON a.id = pe.enterprise_id and pe.project_sn=t.project_sn
INNER JOIN project_enterprise pe ON en.id = pe.enterprise_id and pe.project_sn=t.project_sn
where t.project_sn=#{projectSn}
<if test="enterpriseTypeId != null and enterpriseTypeId != ''">
and pe.enterprise_type_id = #{enterpriseTypeId}
@ -195,11 +195,11 @@
,ifnull(sum(t.is_attendance),0) as worker_count
from worker_daily_attendance_statistics_v2 t
JOIN worker_info a on t.person_sn=a.person_sn
JOIN team_info b ON a.team_id = b.id and a.person_type = 1
JOIN department_info c ON a.department_id = c.id and a.person_type = 2
JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
LEFT JOIN team_info b ON a.team_id = b.id and a.person_type = 1
LEFT JOIN department_info c ON a.department_id = c.id and a.person_type = 2
LEFT JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
JOIN enterprise_info en ON en.id = a.enterprise_id
JOIN project_enterprise pe ON a.id = pe.enterprise_id and pe.project_sn=t.project_sn
JOIN project_enterprise pe ON en.id = pe.enterprise_id and pe.project_sn=t.project_sn
where t.project_sn=#{projectSn}
<if test="personType != null and personType != ''">
and a.person_type = #{personType}
@ -239,4 +239,30 @@
</if>
group by wt.id) t
</select>
<select id="countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo"
resultType="com.zhgd.xmgl.modules.worker.entity.bo.ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo">
select
if(a.person_type=1,b.team_name,c.department_name) dept_name
,a.person_type
,t.attendance_date date
,count(*) as worker_num
from worker_daily_attendance_statistics_v2 t
JOIN worker_info a on t.person_sn=a.person_sn
LEFT JOIN team_info b ON a.team_id = b.id and a.person_type = 1
LEFT JOIN department_info c ON a.department_id = c.id and a.person_type = 2
LEFT JOIN worker_type wt ON b.worker_type_id = wt.id and a.person_type = 1
LEFT JOIN enterprise_info en ON en.id = a.enterprise_id
where a.project_sn=#{projectSn} and a.person_type in (1,2)
<if test="hourValBegin != null and hourValBegin != ''">
and t.hour_val >= #{hourValBegin}
</if>
<if test="startDate != null and startDate != ''">
and t.attendance_date >= #{startDate}
</if>
<if test="endDate != null and endDate != ''">
and t.attendance_date <![CDATA[<=]]> concat(#{endDate},' 23:59:59')
</if>
group by t.attendance_date,if(a.person_type=1,b.team_name,c.department_name)
</select>
</mapper>

View File

@ -7,6 +7,7 @@ import com.zhgd.xmgl.base.entity.vo.echarts.ChartDataVo;
import com.zhgd.xmgl.modules.worker.entity.WorkerAttendanceRuleV2;
import com.zhgd.xmgl.modules.worker.entity.WorkerDailyAttendanceStatisticsV2;
import com.zhgd.xmgl.modules.worker.entity.bo.CalAttendanceBo;
import com.zhgd.xmgl.modules.worker.entity.bo.ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo;
import com.zhgd.xmgl.modules.worker.entity.dto.WorkerDailyAttendanceStatisticsV2Dto;
import com.zhgd.xmgl.modules.worker.entity.vo.*;
@ -101,4 +102,12 @@ public interface IWorkerDailyAttendanceStatisticsV2Service extends IService<Work
List<CountByEnterpriseVo> countNumByEnterprise(HashMap<String, Object> param);
List<CountNumByWorkerTypeVo> countNumByWorkerType(HashMap<String, Object> param);
/**
* 获取导出的
*
* @param param
* @return
*/
List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo> countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(HashMap<String, Object> param);
}

View File

@ -19,6 +19,7 @@ import com.zhgd.xmgl.modules.project.service.IProjectEnterpriseService;
import com.zhgd.xmgl.modules.worker.entity.*;
import com.zhgd.xmgl.modules.worker.entity.bo.CalAttendanceBo;
import com.zhgd.xmgl.modules.worker.entity.bo.CountWorkerDailyAttendanceStatisticsV2ByDateBo;
import com.zhgd.xmgl.modules.worker.entity.bo.ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo;
import com.zhgd.xmgl.modules.worker.entity.bo.Hour2dayJsonBo;
import com.zhgd.xmgl.modules.worker.entity.dto.WorkerDailyAttendanceStatisticsV2Dto;
import com.zhgd.xmgl.modules.worker.entity.vo.*;
@ -450,7 +451,12 @@ public class WorkerDailyAttendanceStatisticsV2ServiceImpl extends ServiceImpl<Wo
for (DateTime dateTime : range) {
for (WorkerInfo worker : workerInfos) {
WorkerAttendanceRuleV2 ruleV2 = Optional.ofNullable(worker.getAttendanceGroupV2Id()).map(groupToRuleMap::get).orElse(null);
this.calAndSaveStatistics(worker.getProjectSn(), worker.getPersonSn(), worker.getInserviceType(), dateTime, ruleV2, attendances, allAttendances);
Integer inserviceType = worker.getInserviceType();
if (DateUtil.compare(StrUtil.isNotBlank(worker.getEnterDate()) ? DateUtil.parseDate(worker.getEnterDate()) : worker.getAddTime(), dateTime) > 0) {
//没入场不在职
inserviceType = 2;
}
this.calAndSaveStatistics(worker.getProjectSn(), worker.getPersonSn(), inserviceType, dateTime, ruleV2, attendances, allAttendances);
}
}
}
@ -588,4 +594,9 @@ public class WorkerDailyAttendanceStatisticsV2ServiceImpl extends ServiceImpl<Wo
return baseMapper.countNumByWorkerType(param);
}
@Override
public List<ExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo> countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(HashMap<String, Object> param) {
return baseMapper.countExportWorkerDailyAttendancesStaticsByDepartmentTeamXlsBo(param);
}
}

View File

@ -18,6 +18,7 @@ import cn.hutool.poi.excel.ExcelWriter;
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.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -617,6 +618,10 @@ public class WorkerInfoServiceImpl extends ServiceImpl<WorkerInfoMapper, WorkerI
if (Objects.equals(oldWorkerInfo.getInserviceType(), WorkerInfInserviceTypeoEnum.OUT.getCode()) && Objects.equals(workerInfo.getInserviceType(), 1)) {
workerInfo.setSafeScore(oldWorkerInfo.getExitSafeScore());
}
workerInfoService.update(null, new LambdaUpdateWrapper<WorkerInfo>()
.set(WorkerInfo::getAttendanceGroupV2Id, workerInfo.getAttendanceGroupV2Id())
.eq(WorkerInfo::getId, workerInfo.getId())
);
workerInfoMapper.updateById(workerInfo);
systemUserService.updateRealNameFromWorker(workerInfo.getId(), workerInfo.getWorkerName());
boolean hikvisionConfig = projectUfaceConfigService.isHikvisionConfig(workerInfo.getProjectSn());