From 3fd76e37d9dd0f95dfbd2621966e3c48efa35580 Mon Sep 17 00:00:00 2001 From: ieaii <1069385070@qq.com> Date: Sun, 5 Jan 2025 23:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=B8=80=E4=B8=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-hanhai-vue/src/views/xcx/ClockinLogList.vue | 42 ++++- .../controller/ClockinLogController.java | 194 ++++++++++++++++----- pom.xml | 2 +- 3 files changed, 188 insertions(+), 50 deletions(-) diff --git a/admin-hanhai-vue/src/views/xcx/ClockinLogList.vue b/admin-hanhai-vue/src/views/xcx/ClockinLogList.vue index 8cde1fa..3cd74ae 100644 --- a/admin-hanhai-vue/src/views/xcx/ClockinLogList.vue +++ b/admin-hanhai-vue/src/views/xcx/ClockinLogList.vue @@ -14,6 +14,11 @@ + + + + + @@ -22,7 +27,7 @@
- 导出 + 导出 @@ -110,6 +115,7 @@ import { JeecgListMixin } from '@/mixins/JeecgListMixin' import ClockinLogModal from './modules/ClockinLogModal' import {filterMultiDictText} from '@/components/dict/JDictSelectUtil' + import {downFile} from "@api/manage"; export default { name: 'ClockinLogList', @@ -209,7 +215,39 @@ fieldList.push({type:'string',value:'lat',text:'纬度',dictCode:''}) fieldList.push({type:'int',value:'delFlag',text:'是否删除',dictCode:'is_delete'}) this.superFieldList = fieldList - } + }, + handleExportXls2(fileName){ + if(!fileName || typeof fileName != "string"){ + fileName = "导出文件" + } + let param = this.getQueryParams(); + if(this.selectedRowKeys && this.selectedRowKeys.length>0){ + param['selections'] = this.selectedRowKeys.join(",") + } + console.log("导出参数",param) + this.loading = true; + downFile(this.url.exportXlsUrl,param).then((data)=>{ + if (!data) { + this.$message.warning("文件下载失败") + return + } + if (typeof window.navigator.msSaveBlob !== 'undefined') { + window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xls') + }else{ + let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'})) + let link = document.createElement('a') + link.style.display = 'none' + link.href = url + link.setAttribute('download', fileName+'.xls') + document.body.appendChild(link) + link.click() + document.body.removeChild(link); //下载完成移除元素 + window.URL.revokeObjectURL(url); //释放掉blob对象 + } + }).finally(() => { + this.loading = false; + }); + }, } } diff --git a/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java b/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java index 9fc291a..53562fa 100644 --- a/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java +++ b/jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/modules/clockinlog/controller/ClockinLogController.java @@ -16,12 +16,14 @@ import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapp import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.DateUtils2; @@ -51,6 +53,7 @@ import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.enmus.ExcelType; +import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.base.controller.JeecgController; import org.jeecgframework.poi.excel.view.JeecgMapExcelView; @@ -207,6 +210,7 @@ public class ClockinLogController extends JeecgController parameterMap = request.getParameterMap(); String[] clockStartTimes = parameterMap.get("clockStartTime"); String[] userIds = parameterMap.get("userId"); + String[] projectIds = parameterMap.get("projectId"); // QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap()); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); @@ -221,6 +225,27 @@ public class ClockinLogController extends JeecgController clockinTeamLogs = queryChainWrapper.list(); + if(projectIds!=null && projectIds.length!=0 && StringUtils.isNotBlank(projectIds[0])){ + ClockInProject clockInProject = clockInProjectService.lambdaQuery() + .eq(ClockInProject::getDelFlag, 0) + .eq(ClockInProject::getId,projectIds[0]) + .one(); + if(clockInProject == null){ + throw new JeecgBootException("项目错误"); + } + try { + clockinTeamLogs = clockinTeamLogService.lambdaQuery() + .eq(ClockinTeamLog::getDelFlag, 0) + .eq(ClockinTeamLog::getTeamId, clockInProject.getTeamId()) + .list(); +// clockinTeamLogs.add(clockinTeamLog); + }catch (Exception e){ + throw new JeecgBootException("该项目可能存在两个团队绑定,请检查项目管理"); + } + + + } + // int day = Integer.parseInt(DateUtils2.getNowMonthMaxDay()); @@ -235,7 +260,6 @@ public class ClockinLogController extends JeecgController pageList = service.list(queryWrapper); // List exportList = null; @@ -314,6 +338,7 @@ public class ClockinLogController extends JeecgController clazz, String title) { + protected ModelAndView exportXls3(HttpServletRequest request, Class clazz, String title) { // Step.1 组装查询条件 Map parameterMap = request.getParameterMap(); String[] clockStartTimes = parameterMap.get("clockStartTime"); String[] userIds = parameterMap.get("userId"); + String[] projectIds = parameterMap.get("projectId"); +// QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(object, request.getParameterMap()); LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); LambdaQueryChainWrapper queryChainWrapper = clockinTeamLogService.lambdaQuery() .eq(ClockinTeamLog::getDelFlag, 0); - if (userIds != null && userIds.length != 0 && StringUtils.isNotBlank(userIds[0])) { - queryChainWrapper.eq(ClockinTeamLog::getUserId, userIds[0]); +// List clockinTeamLogs = clockinTeamLogService.lambdaQuery() +// .eq(ClockinTeamLog::getDelFlag, 0) +// .list(); + + if(userIds!=null && userIds.length!=0 && StringUtils.isNotBlank(userIds[0])){ + queryChainWrapper.eq(ClockinTeamLog::getUserId,userIds[0]); } List clockinTeamLogs = queryChainWrapper.list(); + if(projectIds!=null && projectIds.length!=0 && StringUtils.isNotBlank(projectIds[0])){ + ClockInProject clockInProject = clockInProjectService.lambdaQuery() + .eq(ClockInProject::getDelFlag, 0) + .eq(ClockInProject::getId,projectIds[0]) + .one(); + if(clockInProject == null){ + throw new JeecgBootException("项目错误"); + } + try { + clockinTeamLogs = clockinTeamLogService.lambdaQuery() + .eq(ClockinTeamLog::getDelFlag, 0) + .eq(ClockinTeamLog::getTeamId, clockInProject.getTeamId()) + .list(); +// clockinTeamLogs.add(clockinTeamLog); + }catch (Exception e){ + throw new JeecgBootException("该项目可能存在两个团队绑定,请检查项目管理"); + } + + + } + + + List> maps = new ArrayList<>(); + Map map = new HashMap<>(); + List entity = new ArrayList(); + ExcelExportEntity excelExportEntity = new ExcelExportEntity("姓名", "name"); + excelExportEntity.setNeedMerge(true); + + ExcelExportEntity excelExportEntity1 = new ExcelExportEntity("性别", "sex"); + excelExportEntity1.setNeedMerge(true); + + ExcelExportEntity excelExportEntity2 = new ExcelExportEntity("数据", "list"); + excelExportEntity2.setNeedMerge(true); - // 确定导出月份 + entity.add(excelExportEntity); + entity.add(excelExportEntity1); + entity.add(excelExportEntity2); + +// int day = Integer.parseInt(DateUtils2.getNowMonthMaxDay()); String nowYearMonth = DateUtils2.getNowYearMonth(); - if (clockStartTimes != null && clockStartTimes.length != 0 && StringUtils.isNotBlank(clockStartTimes[0])) { + + if(clockStartTimes!=null && clockStartTimes.length!=0 && StringUtils.isNotBlank(clockStartTimes[0])){ nowYearMonth = clockStartTimes[0]; } YearMonth yearMonth = YearMonth.parse(nowYearMonth); - int daysInMonth = yearMonth.lengthOfMonth(); // 当前月份的天数 + int day = yearMonth.lengthOfMonth(); + + + String yearMonthDay = ""; // Step.2 获取导出数据 - List> exportList = new ArrayList<>(); - for (ClockinTeamLog clockinTeamLog : clockinTeamLogs) { +// List pageList = service.list(queryWrapper); +// List exportList = null; + List> list = new ArrayList<>(); + List strings = null; + List exportList = new ArrayList<>(); + for (ClockinTeamLog clockinTeamLog:clockinTeamLogs){ ClockInProject clockInProject = clockInProjectService.lambdaQuery() .eq(ClockInProject::getDelFlag, 0) .eq(ClockInProject::getTeamId, clockinTeamLog.getTeamId()) .one(); + if(clockInProject == null){ + continue; + } ClockinAuth clockinAuth = clockinAuthService.lambdaQuery() .eq(ClockinAuth::getDelFlag, 0) .eq(ClockinAuth::getUserId, clockinTeamLog.getUserId()) .one(); - if (clockinAuth == null) { + if(clockinAuth == null){ continue; } + List clockInLogExportResp2s = new ArrayList<>(); + ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp(); + clockInLogExportResp.setName(clockinAuth.getName()); + clockInLogExportResp.setDate(nowYearMonth); + map.put("name",clockinAuth.getName()); + map.put("sex",nowYearMonth); + List> maps1 = new ArrayList<>(); + for (int n= 1;n<=day;n++){ + ClockInLogExportResp2 clockInLogExportResp2 = new ClockInLogExportResp2(); + + + clockInLogExportResp2.setDay(n+""); + yearMonthDay = nowYearMonth+"-"+n; + if(n < 10){ + yearMonthDay = nowYearMonth+"-0"+n; + } - // 初始化记录,包含“姓名”和每日打卡记录 - Map record = new LinkedHashMap<>(); - record.put("name", clockinAuth.getName()); - record.put("date", nowYearMonth); - - for (int day = 1; day <= daysInMonth; day++) { - String yearMonthDay = nowYearMonth + "-" + (day < 10 ? "0" + day : day); Date date = DateUtils2.getDate(yearMonthDay + " 23:59:59"); LocalDateTime localDateTime = DateUtils2.dateToDateTime(date); Integer type = 0; if(DayOfWeek.SATURDAY.equals(localDateTime.getDayOfWeek()) || DayOfWeek.SUNDAY.equals(localDateTime.getDayOfWeek())){ type = 1; } - List clockInLogs = clockinLogMapper.getClockInLogExpeort( - yearMonthDay, clockInProject.getId(), clockinTeamLog.getUserId(),type - ); - - // 拼接打卡时间或标记“缺卡” - StringBuilder clockInTime = new StringBuilder(); - for (ClockInLogResp log : clockInLogs) { - if (StringUtils.isBlank(log.getTime())) { - log.setClockStartTime("缺卡"); - } - if (clockInTime.length() > 0) { - clockInTime.append("\n"); + + List clockInLogExpeort = clockinLogMapper.getClockInLogExpeort(yearMonthDay, clockInProject.getId(), clockinTeamLog.getUserId(),type); + String clockInTime = ""; + for (ClockInLogResp clockInLogResp:clockInLogExpeort) { + + if(StringUtils.isBlank(clockInLogResp.getTime())){ + clockInLogResp.setClockStartTime("缺卡"); } - clockInTime.append(log.getClockStartTime()); + clockInTime = clockInTime+"\n"+clockInLogResp.getClockStartTime(); +// strings.add(clockInLogResp.getClockStartTime()); } - record.put(day + "号", clockInTime.length() > 0 ? clockInTime.toString() : "缺卡"); + Map map1 = new HashMap<>(); + map1.put(n+"",clockInTime); + maps1.add(map1); + clockInLogExportResp2.setClockInTime(clockInTime); + clockInLogExportResp2s.add(clockInLogExportResp2); + } - exportList.add(record); + map.put("list",maps1); + maps.add(map); + clockInLogExportResp.setClockInLogExportResp2s(clockInLogExportResp2s); + exportList.add(clockInLogExportResp); } - // Step.3 动态表头生成 - List headers = new ArrayList<>(); - headers.add("姓名"); - headers.add("日期"); - for (int i = 1; i <= daysInMonth; i++) { - headers.add(i + "号"); - } - // Step.4 AutoPoi 导出Excel - ModelAndView mv = new ModelAndView(new JeecgMapExcelView()); + // 过滤选中数据 +// String selections = request.getParameter("selections"); +// if (oConvertUtils.isNotEmpty(selections)) { +// List selectionList = Arrays.asList(selections.split(",")); +// exportList = pageList.stream().filter(item -> selectionList.contains(getId(item))).collect(Collectors.toList()); +// } else { +// exportList = pageList; +// } + + // Step.3 AutoPoi 导出Excel + ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); + //此处设置的filename无效 ,前端会重更新设置一下 + mv.addObject(NormalExcelConstants.FILE_NAME, title); -// mv.addObject(NormalExcelConstants.CLASS, clazz); - ExportParams exportParams = new ExportParams( - title + "报表", "导出人:" + sysUser.getRealname(), title); -// exportParams.setExclusions(headers.toArray(new String[0])); // 设置表头排除无用列 - mv.addObject(NormalExcelConstants.PARAMS, exportParams); - mv.addObject(NormalExcelConstants.MAP_LIST, exportList); + mv.addObject(NormalExcelConstants.CLASS, entity.getClass()); + //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- + ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title); + +// exportParams.setType(ExcelType.XSSF); + exportParams.setImageBasePath(upLoadPath); + + //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- + mv.addObject(NormalExcelConstants.PARAMS,exportParams); + mv.addObject(NormalExcelConstants.DATA_LIST, maps); return mv; } diff --git a/pom.xml b/pom.xml index 1b16994..46c4fca 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ 3.11.0 3.1.0 1.3.8 - 1.4.0 + 1.4.11 8.0.3 1.3.4 1.6.1