@ -10,13 +10,20 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper ;
import org.apache.commons.beanutils.PropertyUtils ;
import org.apache.commons.io.IOUtils ;
import org.apache.commons.lang3.StringUtils ;
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.system.query.QueryGenerator ;
import org.jeecg.common.system.vo.LoginUser ;
import org.jeecg.common.util.DateUtils2 ;
import org.jeecg.common.util.ExcelStyleUtil ;
import org.jeecg.common.util.oConvertUtils ;
import org.jeecg.modules.clockInproject.entity.ClockInProject ;
import org.jeecg.modules.clockInproject.service.IClockInProjectService ;
@ -25,6 +32,7 @@ import org.jeecg.modules.clockinauth.service.IClockinAuthService;
import org.jeecg.modules.clockinlog.entity.ClockinLog ;
import org.jeecg.modules.clockinlog.mapper.ClockinLogMapper ;
import org.jeecg.modules.clockinlog.ressp.ClockInLogExportResp ;
import org.jeecg.modules.clockinlog.ressp.ClockInLogExportResp2 ;
import org.jeecg.modules.clockinlog.ressp.ClockInLogResp ;
import org.jeecg.modules.clockinlog.service.IClockinLogService ;
@ -35,12 +43,15 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.clockinteamlog.entity.ClockinTeamLog ;
import org.jeecg.modules.clockinteamlog.service.IClockinTeamLogService ;
import org.jeecgframework.poi.excel.ExcelExportUtil ;
import org.jeecgframework.poi.excel.ExcelImportUtil ;
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.view.JeecgEntityExcelView ;
import org.jeecg.common.system.base.controller.JeecgController ;
import org.jeecgframework.poi.excel.view.JeecgMapExcelView ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.web.bind.annotation.* ;
@ -185,7 +196,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
@RequestMapping ( value = "/exportXls2" )
public ModelAndView exportXls3 ( HttpServletRequest request , ClockinLog clockinLog ) {
return this . exportXls2 ( request , ClockInLogExportResp . class , "打卡" ) ;
return this . exportXls3 ( request , ClockInLogExportResp2 . class , "打卡" ) ;
}
/ / @RequestMapping ( value = "/exportXls2" )
@ -193,15 +204,21 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
/ / Step . 1 组装查询条件
Map < String , String [ ] > parameterMap = request . getParameterMap ( ) ;
String [ ] clockStartTimes = parameterMap . get ( "clockStartTime" ) ;
String [ ] userIds = parameterMap . get ( "userId" ) ;
/ / QueryWrapper < ClockinLog > queryWrapper = QueryGenerator . initQueryWrapper ( object , request . getParameterMap ( ) ) ;
LoginUser sysUser = ( LoginUser ) SecurityUtils . getSubject ( ) . getPrincipal ( ) ;
List < ClockinTeamLog > clockinTeamLogs = clockinTeamLogService . lambdaQuery ( )
. eq ( ClockinTeamLog : : getDelFlag , 0 )
/ / . eq ( ClockinTeamLog : : getStatus , 1 )
. list ( ) ;
LambdaQueryChainWrapper < ClockinTeamLog > queryChainWrapper = clockinTeamLogService . lambdaQuery ( )
. eq ( ClockinTeamLog : : getDelFlag , 0 ) ;
/ / List < ClockinTeamLog > 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 < ClockinTeamLog > clockinTeamLogs = queryChainWrapper . list ( ) ;
/ / int day = Integer . parseInt ( DateUtils2 . getNowMonthMaxDay ( ) ) ;
@ -229,6 +246,9 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
. eq ( ClockInProject : : getTeamId , clockinTeamLog . getTeamId ( ) )
. one ( ) ;
if ( clockInProject = = null ) {
continue ;
}
ClockinAuth clockinAuth = clockinAuthService . lambdaQuery ( )
. eq ( ClockinAuth : : getDelFlag , 0 )
. eq ( ClockinAuth : : getUserId , clockinTeamLog . getUserId ( ) )
@ -236,13 +256,20 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
if ( clockinAuth = = null ) {
continue ;
}
List < ClockInLogExportResp2 > clockInLogExportResp2s = new ArrayList < > ( ) ;
ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp ( ) ;
clockInLogExportResp . setName ( clockinAuth . getName ( ) ) ;
clockInLogExportResp . setDate ( nowYearMonth ) ;
for ( int n = 1 ; n < = day ; n + + ) {
ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp ( ) ;
clockInLogExportResp . setName ( clockinAuth . getName ( ) ) ;
clockInLogExportResp . setDate ( nowYearMonth ) ;
clockInLogExportResp . setDay ( n + "" ) ;
yearMonthDay = nowYearMonth + "-" + n ;
ClockInLogExportResp2 clockInLogExportResp2 = new ClockInLogExportResp2 ( ) ;
clockInLogExportResp2 . setDay ( n + "" ) ;
yearMonthDay = nowYearMonth + "-" + n ;
if ( n < 10 ) {
yearMonthDay = nowYearMonth + "-0" + n ;
}
List < ClockInLogResp > clockInLogExpeort = clockinLogMapper . getClockInLogExpeort ( yearMonthDay , clockInProject . getId ( ) , clockinTeamLog . getUserId ( ) ) ;
String clockInTime = "" ;
for ( ClockInLogResp clockInLogResp : clockInLogExpeort ) {
@ -253,10 +280,12 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
clockInTime = clockInTime + "\n" + clockInLogResp . getClockStartTime ( ) ;
/ / strings . add ( clockInLogResp . getClockStartTime ( ) ) ;
}
clockInLogExportResp . setClockInTime ( clockInTime ) ;
exportList . add ( clockInLogExportResp ) ;
}
clockInLogExportResp2 . setClockInTime ( clockInTime ) ;
clockInLogExportResp2s . add ( clockInLogExportResp2 ) ;
}
clockInLogExportResp . setClockInLogExportResp2s ( clockInLogExportResp2s ) ;
exportList . add ( clockInLogExportResp ) ;
}
@ -276,14 +305,107 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
mv . addObject ( NormalExcelConstants . CLASS , clazz ) ;
/ / 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 , exportList ) ;
return mv ;
}
private String getId ( ClockinLog item ) {
protected ModelAndView exportXls3 ( HttpServletRequest request , Class < ClockInLogExportResp2 > clazz , String title ) {
/ / Step . 1 组装查询条件
Map < String , String [ ] > parameterMap = request . getParameterMap ( ) ;
String [ ] clockStartTimes = parameterMap . get ( "clockStartTime" ) ;
String [ ] userIds = parameterMap . get ( "userId" ) ;
LoginUser sysUser = ( LoginUser ) SecurityUtils . getSubject ( ) . getPrincipal ( ) ;
LambdaQueryChainWrapper < ClockinTeamLog > queryChainWrapper = clockinTeamLogService . lambdaQuery ( )
. eq ( ClockinTeamLog : : getDelFlag , 0 ) ;
if ( userIds ! = null & & userIds . length ! = 0 & & StringUtils . isNotBlank ( userIds [ 0 ] ) ) {
queryChainWrapper . eq ( ClockinTeamLog : : getUserId , userIds [ 0 ] ) ;
}
List < ClockinTeamLog > clockinTeamLogs = queryChainWrapper . list ( ) ;
/ / 确定导出月份
String nowYearMonth = DateUtils2 . getNowYearMonth ( ) ;
if ( clockStartTimes ! = null & & clockStartTimes . length ! = 0 & & StringUtils . isNotBlank ( clockStartTimes [ 0 ] ) ) {
nowYearMonth = clockStartTimes [ 0 ] ;
}
YearMonth yearMonth = YearMonth . parse ( nowYearMonth ) ;
int daysInMonth = yearMonth . lengthOfMonth ( ) ; / / 当前月份的天数
/ / Step . 2 获取导出数据
List < Map < String , Object > > exportList = new ArrayList < > ( ) ;
for ( ClockinTeamLog clockinTeamLog : clockinTeamLogs ) {
ClockInProject clockInProject = clockInProjectService . lambdaQuery ( )
. eq ( ClockInProject : : getDelFlag , 0 )
. eq ( ClockInProject : : getTeamId , clockinTeamLog . getTeamId ( ) )
. one ( ) ;
ClockinAuth clockinAuth = clockinAuthService . lambdaQuery ( )
. eq ( ClockinAuth : : getDelFlag , 0 )
. eq ( ClockinAuth : : getUserId , clockinTeamLog . getUserId ( ) )
. one ( ) ;
if ( clockinAuth = = null ) {
continue ;
}
/ / 初始化记录 , 包含 “ 姓名 ” 和每日打卡记录
Map < String , Object > 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 ) ;
List < ClockInLogResp > clockInLogs = clockinLogMapper . getClockInLogExpeort (
yearMonthDay , clockInProject . getId ( ) , clockinTeamLog . getUserId ( )
) ;
/ / 拼接打卡时间或标记 “ 缺卡 ”
StringBuilder clockInTime = new StringBuilder ( ) ;
for ( ClockInLogResp log : clockInLogs ) {
if ( StringUtils . isBlank ( log . getTime ( ) ) ) {
log . setClockStartTime ( "缺卡" ) ;
}
if ( clockInTime . length ( ) > 0 ) {
clockInTime . append ( "\n" ) ;
}
clockInTime . append ( log . getClockStartTime ( ) ) ;
}
record . put ( day + "号" , clockInTime . length ( ) > 0 ? clockInTime . toString ( ) : "缺卡" ) ;
}
exportList . add ( record ) ;
}
/ / Step . 3 动态表头生成
List < String > 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 ( ) ) ;
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 ) ;
return mv ;
}
private String getId ( ClockinLog item ) {
try {
return PropertyUtils . getProperty ( item , "id" ) . toString ( ) ;
} catch ( Exception e ) {
@ -304,4 +426,5 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
return super . importExcel ( request , response , ClockinLog . class ) ;
}
}