@ -1,22 +1,31 @@
package org.jeecg.modules.clockinlog.controller ;
import java.util.Arrays ;
import java.util.List ;
import java.util.Map ;
import java.time.YearMonth ;
import java.util.* ;
import java.util.stream.Collectors ;
import java.io.IOException ;
import java.io.UnsupportedEncodingException ;
import java.net.URLDecoder ;
import javax.annotation.Resource ;
import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import org.apache.commons.beanutils.PropertyUtils ;
import org.apache.commons.lang3.StringUtils ;
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.oConvertUtils ;
import org.jeecg.modules.clockInproject.entity.ClockInProject ;
import org.jeecg.modules.clockInproject.service.IClockInProjectService ;
import org.jeecg.modules.clockinauth.entity.ClockinAuth ;
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.ClockInLogResp ;
import org.jeecg.modules.clockinlog.service.IClockinLogService ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
@ -24,6 +33,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import lombok.extern.slf4j.Slf4j ;
import org.jeecg.modules.clockinteamlog.entity.ClockinTeamLog ;
import org.jeecg.modules.clockinteamlog.service.IClockinTeamLogService ;
import org.jeecgframework.poi.excel.ExcelImportUtil ;
import org.jeecgframework.poi.excel.def.NormalExcelConstants ;
import org.jeecgframework.poi.excel.entity.ExportParams ;
@ -40,8 +51,9 @@ import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api ;
import io.swagger.annotations.ApiOperation ;
import org.jeecg.common.aspect.annotation.AutoLog ;
import reactor.core.publisher.Flux ;
/ * *
/ * *
* @Description : clockin_log
* @Author : jeecg - boot
* @Date : 2024 - 10 - 24
@ -56,6 +68,14 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
private IClockinLogService clockinLogService ;
@Value ( "${jeecg.path.upload}" )
private String upLoadPath ;
@Resource
private ClockinLogMapper clockinLogMapper ;
@Resource
private IClockinTeamLogService clockinTeamLogService ;
@Resource
private IClockinAuthService clockinAuthService ;
@Resource
private IClockInProjectService clockInProjectService ;
/ * *
* 分页列表查询
*
@ -77,7 +97,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
IPage < ClockinLog > pageList = clockinLogService . page ( page , queryWrapper ) ;
return Result . OK ( pageList ) ;
}
/ * *
* 添加
*
@ -91,7 +111,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
clockinLogService . save ( clockinLog ) ;
return Result . OK ( "添加成功!" ) ;
}
/ * *
* 编辑
*
@ -105,7 +125,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
clockinLogService . updateById ( clockinLog ) ;
return Result . OK ( "编辑成功!" ) ;
}
/ * *
* 通过id删除
*
@ -119,7 +139,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
clockinLogService . removeById ( id ) ;
return Result . OK ( "删除成功!" ) ;
}
/ * *
* 批量删除
*
@ -133,7 +153,7 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
this . clockinLogService . removeByIds ( Arrays . asList ( ids . split ( "," ) ) ) ;
return Result . OK ( "批量删除成功!" ) ;
}
/ * *
* 通过id查询
*
@ -159,27 +179,95 @@ public class ClockinLogController extends JeecgController<ClockinLog, IClockinLo
* /
@RequestMapping ( value = "/exportXls" )
public ModelAndView exportXls ( HttpServletRequest request , ClockinLog clockinLog ) {
return thi s. exportXls ( request , clockinLog , ClockinLog . class , "clockin_log" ) ;
return super . exportXls ( request , clockinLog , ClockinLog . class , "clockin_log" ) ;
}
protected ModelAndView exportXls ( HttpServletRequest request , ClockinLog object , Class < ClockinLog > clazz , String title ) {
@RequestMapping ( value = "/exportXls2" )
public ModelAndView exportXls3 ( HttpServletRequest request , ClockinLog clockinLog ) {
return this . exportXls2 ( request , ClockInLogExportResp . class , "打卡" ) ;
}
/ / @RequestMapping ( value = "/exportXls2" )
protected ModelAndView exportXls2 ( HttpServletRequest request , Class < ClockInLogExportResp > clazz , String title ) {
/ / Step . 1 组装查询条件
QueryWrapper < ClockinLog > queryWrapper = QueryGenerator . initQueryWrapper ( object , request . getParameterMap ( ) ) ;
Map < String , String [ ] > parameterMap = request . getParameterMap ( ) ;
String [ ] clockStartTimes = parameterMap . get ( "clockStartTime" ) ;
/ / 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 ( ) ;
/ / int day = Integer . parseInt ( DateUtils2 . getNowMonthMaxDay ( ) ) ;
String nowYearMonth = clockStartTimes [ 0 ] ;
if ( StringUtils . isBlank ( clockStartTimes [ 0 ] ) ) {
nowYearMonth = DateUtils2 . getNowYearMonth ( ) ;
}
YearMonth yearMonth = YearMonth . parse ( nowYearMonth ) ;
int day = yearMonth . lengthOfMonth ( ) ;
String yearMonthDay = "" ;
/ / Step . 2 获取导出数据
List < ClockinLog > pageList = service . list ( queryWrapper ) ;
List < ClockinLog > exportList = null ;
/ / List < ClockinLog > pageList = service . list ( queryWrapper ) ;
/ / List < ClockinLog > exportList = null ;
List < Map < String , Object > > list = new ArrayList < > ( ) ;
List < String > strings = null ;
List < ClockInLogExportResp > 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 ;
}
for ( int n = 1 ; n < = day ; n + + ) {
ClockInLogExportResp clockInLogExportResp = new ClockInLogExportResp ( ) ;
clockInLogExportResp . setName ( clockinAuth . getName ( ) ) ;
clockInLogExportResp . setDate ( nowYearMonth ) ;
clockInLogExportResp . setDay ( n + "" ) ;
yearMonthDay = nowYearMonth + "-" + n ;
List < ClockInLogResp > clockInLogExpeort = clockinLogMapper . getClockInLogExpeort ( yearMonthDay , clockInProject . getId ( ) , clockinTeamLog . getUserId ( ) ) ;
String clockInTime = "" ;
for ( ClockInLogResp clockInLogResp : clockInLogExpeort ) {
if ( StringUtils . isBlank ( clockInLogResp . getTime ( ) ) ) {
clockInLogResp . setClockStartTime ( "缺卡" ) ;
}
clockInTime = clockInTime + "\n" + clockInLogResp . getClockStartTime ( ) ;
/ / strings . add ( clockInLogResp . getClockStartTime ( ) ) ;
}
clockInLogExportResp . setClockInTime ( clockInTime ) ;
exportList . add ( clockInLogExportResp ) ;
}
/ / 过滤选中数据
String selections = request . getParameter ( "selections" ) ;
if ( oConvertUtils . isNotEmpty ( selections ) ) {
List < String > selectionList = Arrays . asList ( selections . split ( "," ) ) ;
exportList = pageList . stream ( ) . filter ( item - > selectionList . contains ( getId ( item ) ) ) . collect ( Collectors . toList ( ) ) ;
} else {
exportList = pageList ;
}
/ / 过滤选中数据
/ / String selections = request . getParameter ( "selections" ) ;
/ / if ( oConvertUtils . isNotEmpty ( selections ) ) {
/ / List < String > 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无效 , 前端会重更新设置一下