diff --git a/src/main/java/com/ccsens/defaultwbs/api/ClockingInController.java b/src/main/java/com/ccsens/defaultwbs/api/ClockingInController.java index 684fd12..51b3fc2 100644 --- a/src/main/java/com/ccsens/defaultwbs/api/ClockingInController.java +++ b/src/main/java/com/ccsens/defaultwbs/api/ClockingInController.java @@ -67,4 +67,12 @@ public class ClockingInController { ClockingInVo.ExcelUrl excelUrl = clockingInService.exportRecord(params.getParam(), params.getUserId()); return JsonResponse.newInstance().ok(excelUrl); } + + @MustLogin + @ApiOperation(value = "导出考勤excel", notes = "") + @RequestMapping(value = "/export1", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public JsonResponse export1(@ApiParam @Validated @RequestBody QueryDto params) throws Exception{ + ClockingInVo.ExcelUrl excelUrl = clockingInService.exportRecord1(params.getParam(), params.getUserId()); + return JsonResponse.newInstance().ok(excelUrl); + } } diff --git a/src/main/java/com/ccsens/defaultwbs/bean/vo/ClockingInVo.java b/src/main/java/com/ccsens/defaultwbs/bean/vo/ClockingInVo.java index fbd296b..1566148 100644 --- a/src/main/java/com/ccsens/defaultwbs/bean/vo/ClockingInVo.java +++ b/src/main/java/com/ccsens/defaultwbs/bean/vo/ClockingInVo.java @@ -1,12 +1,18 @@ package com.ccsens.defaultwbs.bean.vo; +import cn.hutool.core.collection.CollectionUtil; import com.fasterxml.jackson.annotation.JsonIgnore; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import javafx.print.Collation; import lombok.Data; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Data public class ClockingInVo { @@ -68,4 +74,48 @@ public class ClockingInVo { @ApiModelProperty("上次检查人名字") private String lastCheckerName; } + + + @Data + public static class ClockMember{ + private Long id; + private String name; + private Map recordMemberMap; + private List recordMemberList; + + public Map getRecordMemberMap() { + Map map = new HashMap<>(); + if(CollectionUtil.isNotEmpty(recordMemberList)){ + recordMemberList.forEach(recordMember -> { + if(recordMember.getMorning() != 0){ + map.put(new SimpleDateFormat("yyyy-MM-dd").format(recordMember.getMorning()),recordMember); + }else if(recordMember.night != 0){ + map.put(new SimpleDateFormat("yyyy-MM-dd").format(recordMember.getMorning()),recordMember); + } + }); + } + return map; + } + } + + @Data + public static class RecordMember{ + private Long recordId; + private Long morning; + private Long night; + } + + @Data + public static class NotClockingIn{ + private String time; + private String type; + + public NotClockingIn(String time, String type) { + this.time = time; + this.type = type; + } + + public NotClockingIn() { + } + } } diff --git a/src/main/java/com/ccsens/defaultwbs/bean/vo/RoleVo.java b/src/main/java/com/ccsens/defaultwbs/bean/vo/RoleVo.java index 38b1110..d7dda7e 100644 --- a/src/main/java/com/ccsens/defaultwbs/bean/vo/RoleVo.java +++ b/src/main/java/com/ccsens/defaultwbs/bean/vo/RoleVo.java @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; +import java.util.Map; /** * @author 逗 @@ -34,4 +35,18 @@ public class RoleVo { @ApiModelProperty("排序") private Long sequence; } + + @Data + @ApiModel("查找需要的成员信息") + public static class QueryMember{ + @ApiModelProperty("成员id") + private Long id; + @ApiModelProperty("名字") + private String name; + @ApiModelProperty("用户id") + private Long userId; + @ApiModelProperty("是不是我(0-否,1-是)") + private Byte isMine = 0; + } + } diff --git a/src/main/java/com/ccsens/defaultwbs/persist/dao/ProClockingInDao.java b/src/main/java/com/ccsens/defaultwbs/persist/dao/ProClockingInDao.java index 5d919c0..6830d11 100644 --- a/src/main/java/com/ccsens/defaultwbs/persist/dao/ProClockingInDao.java +++ b/src/main/java/com/ccsens/defaultwbs/persist/dao/ProClockingInDao.java @@ -3,6 +3,7 @@ package com.ccsens.defaultwbs.persist.dao; import com.ccsens.defaultwbs.bean.po.ProClockingIn; import com.ccsens.defaultwbs.bean.vo.ClockingInVo; import com.ccsens.defaultwbs.bean.vo.DeliverVo; +import com.ccsens.defaultwbs.bean.vo.RoleVo; import com.ccsens.defaultwbs.persist.mapper.ProClockingInMapper; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -54,5 +55,11 @@ public interface ProClockingInDao extends ProClockingInMapper { */ List queryMemberByIdList(@Param("memberIdList") List memberIdList,@Param("roleId") Long roleId); - + /** + * 根据角色id查询成员信息,成员id为空则查询全部 + * @param memberIdList 成员id列表 + * @param roleId 角色id + * @return 返回成员信息 + */ + List queryMemberClockingIn(@Param("memberIdList")List memberIdList, @Param("roleId")Long roleId, @Param("startTime")Long startTime, @Param("endTime")Long endTime); } diff --git a/src/main/java/com/ccsens/defaultwbs/service/ClockingInService.java b/src/main/java/com/ccsens/defaultwbs/service/ClockingInService.java index a026fb4..3344a2d 100644 --- a/src/main/java/com/ccsens/defaultwbs/service/ClockingInService.java +++ b/src/main/java/com/ccsens/defaultwbs/service/ClockingInService.java @@ -5,15 +5,16 @@ import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.ObjectUtil; import com.ccsens.common.bean.po.ProMember; +import com.ccsens.common.bean.po.SysHolidays; +import com.ccsens.common.bean.po.SysHolidaysExample; import com.ccsens.common.persist.dao.ProMemberDao; +import com.ccsens.common.persist.mapper.SysHolidaysMapper; import com.ccsens.common.service.IPowerService; import com.ccsens.common.util.CommonCodeError; import com.ccsens.defaultwbs.bean.dto.ClockingInDto; import com.ccsens.defaultwbs.bean.po.ProClockingIn; - import com.ccsens.defaultwbs.bean.vo.ClockingInVo; import com.ccsens.defaultwbs.persist.dao.ProClockingInDao; - import com.ccsens.defaultwbs.util.DefaultCodeError; import com.ccsens.util.PoiUtil; import com.ccsens.util.PropUtil; @@ -21,15 +22,14 @@ import com.ccsens.util.exception.BaseException; import lombok.extern.slf4j.Slf4j; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.ResourceLoader; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -37,7 +37,7 @@ import java.util.stream.Collectors; @Slf4j @Service -@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class) +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class ClockingInService implements IClockingInService { @Resource @@ -48,6 +48,8 @@ public class ClockingInService implements IClockingInService { private Snowflake snowflake; @Resource private IPowerService powerService; + @Resource + private SysHolidaysMapper holidaysMapper; @Override public List queryClockingIn(ClockingInDto.QueryClockingIn params, Long userId) { @@ -57,14 +59,14 @@ public class ClockingInService implements IClockingInService { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date startTimeParam = new Date(params.getStartTime()); Date endTimeParam = new Date(params.getEndTime()); - long dayDifference = DateUtil.betweenDay(startTimeParam, endTimeParam, false)+1; + long dayDifference = DateUtil.betweenDay(startTimeParam, endTimeParam, false) + 1; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(startTimeParam); ClockingInVo.ClockingInInfo start = new ClockingInVo.ClockingInInfo(); start.setDateTime(format.format(startTimeParam)); list.add(start); for (long i = 1; i < dayDifference; i++) { - calendar.add(Calendar.DATE,1); + calendar.add(Calendar.DATE, 1); Date time = calendar.getTime(); ClockingInVo.ClockingInInfo clockingInInfo = new ClockingInVo.ClockingInInfo(); clockingInInfo.setDateTime(format.format(time)); @@ -76,13 +78,12 @@ public class ClockingInService implements IClockingInService { //添加成员信息 //1.查询全部 - List memberIdList = new ArrayList<>(); Long userOfMemberId = memberDao.findUserOfMemberId(params.getProjectId(), userId); memberIdList.add(userOfMemberId); - ProMember member = memberDao.queryMemberOfRole(userOfMemberId,params.getRoleId()); - if (CollectionUtil.isEmpty(params.getMemberIdList())){ - List clockRecordList = clockingInDao.queryMembersOfClock(params.getProjectId(),userOfMemberId,params.getRoleId()); + ProMember member = memberDao.queryMemberOfRole(userOfMemberId, params.getRoleId()); + if (CollectionUtil.isEmpty(params.getMemberIdList())) { + List clockRecordList = clockingInDao.queryMembersOfClock(params.getProjectId(), userOfMemberId, params.getRoleId()); memberIdList.addAll(clockRecordList.stream().map(ClockingInVo.ClockRecord::getMemberId).collect(Collectors.toList())); for (ClockingInVo.ClockingInInfo clockingInInfo : list) { if (ObjectUtil.isNotNull(member)) { @@ -92,7 +93,7 @@ public class ClockingInService implements IClockingInService { clockRecord.setMemberUserId(member.getUserId()); clockingInInfo.getRecordList().add(clockRecord); if (member.getUserId().equals(clockRecord.getMemberUserId())) { - clockRecord.setIsMine((byte)1); + clockRecord.setIsMine((byte) 1); } } for (ClockingInVo.ClockRecord record : clockRecordList) { @@ -103,15 +104,15 @@ public class ClockingInService implements IClockingInService { clockingInInfo.getRecordList().add(otherClockRecord); if (ObjectUtil.isNotNull(member)) { if (member.getUserId().equals(otherClockRecord.getMemberUserId())) { - record.setIsMine((byte)1); + record.setIsMine((byte) 1); } } } } - }else { + } else { //2.筛选成员 - List clockRecordList = clockingInDao.queryMemberByIdList(params.getMemberIdList(),params.getRoleId()); + List clockRecordList = clockingInDao.queryMemberByIdList(params.getMemberIdList(), params.getRoleId()); if (CollectionUtil.isNotEmpty(clockRecordList)) { memberIdList.addAll(clockRecordList.stream().map(ClockingInVo.ClockRecord::getMemberId).collect(Collectors.toList())); for (ClockingInVo.ClockingInInfo clockingInInfo : list) { @@ -121,7 +122,7 @@ public class ClockingInService implements IClockingInService { filterRecord.setMemberName(clockRecord.getMemberName()); filterRecord.setMemberUserId(clockRecord.getMemberUserId()); if (filterRecord.getMemberUserId().equals(userId)) { - filterRecord.setIsMine((byte)1); + filterRecord.setIsMine((byte) 1); } clockingInInfo.getRecordList().add(filterRecord); } @@ -148,7 +149,7 @@ public class ClockingInService implements IClockingInService { clockRecord.setMorningStatus(record.getMorningStatus()); clockRecord.setNight(record.getNight()); clockRecord.setNightStatus(record.getNightStatus()); - if(ObjectUtil.isNotNull(member)) { + if (ObjectUtil.isNotNull(member)) { if (record.getCheckerId().equals(member.getId())) { clockRecord.setIsChecker((byte) 1); } @@ -180,39 +181,39 @@ public class ClockingInService implements IClockingInService { public void punchTheClock(ClockingInDto.PunchTheClock params, Long userId) { //判断选择打卡的成员和当前用户是否匹配 ProMember proMember = memberDao.selectByPrimaryKey(params.getMemberId()); - if(ObjectUtil.isNull(proMember) || !proMember.getUserId().equals(userId)){ + if (ObjectUtil.isNull(proMember) || !proMember.getUserId().equals(userId)) { throw new BaseException(CommonCodeError.MEMBER_NOT_MINE); } //验证打卡日期是否是今天 DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String format = df.format(new Date()); - log.info("获取今天的日期:{}",format); - if(!format.equalsIgnoreCase(df.format(new Date(params.getDateTime())))){ + log.info("获取今天的日期:{}", format); + if (!format.equalsIgnoreCase(df.format(new Date(params.getDateTime())))) { throw new BaseException(CommonCodeError.DATE_ERROR); } //判断是否有打卡记录 - ProClockingIn proClockingIn = clockingInDao.queryHaveData(params.getMemberId(),System.currentTimeMillis()); - if(ObjectUtil.isNotNull(proClockingIn)){ + ProClockingIn proClockingIn = clockingInDao.queryHaveData(params.getMemberId(), System.currentTimeMillis()); + if (ObjectUtil.isNotNull(proClockingIn)) { //如果有记录则查找记录并修改 - if(params.getClockType() == 0 && proClockingIn.getMorningStatus() == 0){ + if (params.getClockType() == 0 && proClockingIn.getMorningStatus() == 0) { proClockingIn.setMorning(System.currentTimeMillis()); proClockingIn.setMorningStatus((byte) 1); - }else if(params.getClockType() == 1 && proClockingIn.getNightStatus() == 0){ + } else if (params.getClockType() == 1 && proClockingIn.getNightStatus() == 0) { proClockingIn.setNight(System.currentTimeMillis()); proClockingIn.setNightStatus((byte) 1); } proClockingIn.setCheckerId(params.getCheckerId()); clockingInDao.updateByPrimaryKeySelective(proClockingIn); - }else { + } else { //如果没有记录,则添加一条新的记录 ProClockingIn newClockingIn = new ProClockingIn(); newClockingIn.setId(snowflake.nextId()); newClockingIn.setMemberId(params.getMemberId()); newClockingIn.setCheckerId(params.getCheckerId()); - if(params.getClockType() == 0){ + if (params.getClockType() == 0) { newClockingIn.setMorning(System.currentTimeMillis()); newClockingIn.setMorningStatus((byte) 1); - }else if(params.getClockType() == 1){ + } else if (params.getClockType() == 1) { newClockingIn.setNight(System.currentTimeMillis()); newClockingIn.setNightStatus((byte) 1); } @@ -224,7 +225,7 @@ public class ClockingInService implements IClockingInService { @Override public void auditRecord(ClockingInDto.Audit params, Long userId) { ProClockingIn record = clockingInDao.selectByPrimaryKey(params.getId()); - log.info("查找打卡记录:{}",record); + log.info("查找打卡记录:{}", record); Long userOfMemberId = memberDao.findUserOfMemberId(params.getProjectId(), userId); if (!record.getCheckerId().equals(userOfMemberId)) { throw new BaseException(CommonCodeError.NO_POWER); @@ -235,40 +236,40 @@ public class ClockingInService implements IClockingInService { proClockingIn.setId(params.getId()); if (ObjectUtil.isNotNull(params.getMorning())) { proClockingIn.setMorning(params.getMorning()); - proClockingIn.setMorningStatus((byte)1); + proClockingIn.setMorningStatus((byte) 1); } if (ObjectUtil.isNotNull(params.getNight())) { proClockingIn.setNight(params.getNight()); - proClockingIn.setNightStatus((byte)1); + proClockingIn.setNightStatus((byte) 1); } clockingInDao.updateByPrimaryKeySelective(proClockingIn); - log.info("修改打卡记录:{}",proClockingIn); + log.info("修改打卡记录:{}", proClockingIn); } //驳回 if (1 == params.getType()) { ProClockingIn proClockingIn = new ProClockingIn(); proClockingIn.setId(params.getId()); if (ObjectUtil.isNotNull(params.getMorning())) { - proClockingIn.setMorningStatus((byte)2); + proClockingIn.setMorningStatus((byte) 2); } if (ObjectUtil.isNotNull(params.getNight())) { - proClockingIn.setNightStatus((byte)2); + proClockingIn.setNightStatus((byte) 2); } clockingInDao.updateByPrimaryKeySelective(proClockingIn); - log.info("驳回打卡记录:{}",proClockingIn); + log.info("驳回打卡记录:{}", proClockingIn); } //审核通过 if (2 == params.getType()) { ProClockingIn proClockingIn = new ProClockingIn(); proClockingIn.setId(params.getId()); if (ObjectUtil.isNotNull(params.getMorning())) { - proClockingIn.setMorningStatus((byte)3); + proClockingIn.setMorningStatus((byte) 3); } if (ObjectUtil.isNotNull(params.getNight())) { - proClockingIn.setNightStatus((byte)3); + proClockingIn.setNightStatus((byte) 3); } clockingInDao.updateByPrimaryKeySelective(proClockingIn); - log.info("审核通过打卡记录:{}",proClockingIn); + log.info("审核通过打卡记录:{}", proClockingIn); } } @@ -278,12 +279,12 @@ public class ClockingInService implements IClockingInService { //查询当前用户所属的memberId Long userOfMemberId = memberDao.findUserOfMemberId(params.getProjectId(), userId); //判断打卡记录id是否为空 - if(ObjectUtil.isNotNull(params.getId())){ + if (ObjectUtil.isNotNull(params.getId())) { //不为空 查询打卡记录 ProClockingIn record = clockingInDao.selectByPrimaryKey(params.getId()); - log.info("查找打卡记录:{}",record); + log.info("查找打卡记录:{}", record); //如果是空返回错误信息 - if(ObjectUtil.isNull(record)){ + if (ObjectUtil.isNull(record)) { throw new BaseException(DefaultCodeError.NOT_CLOCKING_IN); } //判断当前用户是否是检查人 @@ -293,17 +294,17 @@ public class ClockingInService implements IClockingInService { //需要操作的记录 proClockingIn = new ProClockingIn(); proClockingIn.setId(params.getId()); - }else { + } else { //当前用户是否是项目经理 Integer power = powerService.queryUserPower(params.getProjectId(), userId); //根据memberId查询上一条打卡记录的检查人 ClockingInVo.LastChecker lastChecker = clockingInDao.queryLastChecker(params.getMemberId()); - if(power < 1){ + if (power < 1) { //不是项目经理,且不是上一条信息的检查人,提示错误信息 - if(ObjectUtil.isNull(lastChecker)){ + if (ObjectUtil.isNull(lastChecker)) { throw new BaseException(CommonCodeError.NO_POWER); } - if(!lastChecker.getLastCheckerId().equals(userOfMemberId)){ + if (!lastChecker.getLastCheckerId().equals(userOfMemberId)) { throw new BaseException(CommonCodeError.NO_POWER); } } @@ -319,33 +320,33 @@ public class ClockingInService implements IClockingInService { if (0 == params.getType()) { if (ObjectUtil.isNotNull(params.getMorning())) { proClockingIn.setMorning(params.getMorning()); - proClockingIn.setMorningStatus((byte)1); + proClockingIn.setMorningStatus((byte) 1); } if (ObjectUtil.isNotNull(params.getNight())) { proClockingIn.setNight(params.getNight()); - proClockingIn.setNightStatus((byte)1); + proClockingIn.setNightStatus((byte) 1); } - log.info("修改打卡记录:{}",proClockingIn); + log.info("修改打卡记录:{}", proClockingIn); } //驳回 if (1 == params.getType()) { if (ObjectUtil.isNotNull(params.getMorning())) { - proClockingIn.setMorningStatus((byte)2); + proClockingIn.setMorningStatus((byte) 2); } if (ObjectUtil.isNotNull(params.getNight())) { - proClockingIn.setNightStatus((byte)2); + proClockingIn.setNightStatus((byte) 2); } - log.info("驳回打卡记录:{}",proClockingIn); + log.info("驳回打卡记录:{}", proClockingIn); } //审核通过 if (2 == params.getType()) { if (ObjectUtil.isNotNull(params.getMorning())) { - proClockingIn.setMorningStatus((byte)3); + proClockingIn.setMorningStatus((byte) 3); } if (ObjectUtil.isNotNull(params.getNight())) { - proClockingIn.setNightStatus((byte)3); + proClockingIn.setNightStatus((byte) 3); } - log.info("审核通过打卡记录:{}",proClockingIn); + log.info("审核通过打卡记录:{}", proClockingIn); } clockingInDao.updateByPrimaryKeySelective(proClockingIn); @@ -356,7 +357,7 @@ public class ClockingInService implements IClockingInService { public ClockingInVo.ExcelUrl exportRecord(ClockingInDto.QueryClockingIn params, Long userId) throws IOException { log.info("开始调用查询考勤方法"); List clockingInInfos = queryClockingIn(params, userId); - log.info("调用查询考勤方法结束{}",clockingInInfos); + log.info("调用查询考勤方法结束{}", clockingInInfos); Workbook workbook = new XSSFWorkbook(); //空白格 PoiUtil.PoiUtilCell blank = new PoiUtil.PoiUtilCell(); @@ -407,43 +408,202 @@ public class ClockingInService implements IClockingInService { for (int i = 0; i < clockingInInfo.getRecordList().size(); i++) { List poiUtilCells = list.get(i + 2); PoiUtil.PoiUtilCell morning = new PoiUtil.PoiUtilCell(); - if (ObjectUtil.isNull(clockingInInfo.getRecordList().get(i).getMorning()) || 0 == clockingInInfo.getRecordList().get(i).getMorning()){ + if (ObjectUtil.isNull(clockingInInfo.getRecordList().get(i).getMorning()) || 0 == clockingInInfo.getRecordList().get(i).getMorning()) { morning.setValue("未打卡"); - }else if (2 == clockingInInfo.getRecordList().get(i).getMorningStatus()){ + } else if (2 == clockingInInfo.getRecordList().get(i).getMorningStatus()) { morning.setValue("已驳回"); - }else { + } else { morning.setValue(format.format(new Date(clockingInInfo.getRecordList().get(i).getMorning()))); } poiUtilCells.add(morning); PoiUtil.PoiUtilCell night = new PoiUtil.PoiUtilCell(); - if (ObjectUtil.isNull(clockingInInfo.getRecordList().get(i).getNight()) || 0 == clockingInInfo.getRecordList().get(i).getNight()){ + if (ObjectUtil.isNull(clockingInInfo.getRecordList().get(i).getNight()) || 0 == clockingInInfo.getRecordList().get(i).getNight()) { night.setValue("未打卡"); - }else if (2 == clockingInInfo.getRecordList().get(i).getNightStatus()){ + } else if (2 == clockingInInfo.getRecordList().get(i).getNightStatus()) { night.setValue("已驳回"); - }else { + } else { night.setValue(format.format(new Date(clockingInInfo.getRecordList().get(i).getNight()))); } poiUtilCells.add(night); } } + //写入数据 + Workbook wbs = PoiUtil.exportWB("Sheet1", list, workbook); + + return excelReport(wbs); + } + + @Override + public ClockingInVo.ExcelUrl exportRecord1(ClockingInDto.QueryClockingIn params, Long userId) throws Exception { + //根据时间生成日期列表(工作日) + List dateList = getDateList(params.getStartTime(), params.getEndTime()); + //查询需要的成员的记录 + List clockMembers = clockingInDao.queryMemberClockingIn(params.getMemberIdList(), params.getRoleId(), params.getStartTime(), params.getEndTime()); + //生成导入数据 + List> list = createCell(dateList, clockMembers); + + //获取模板 + ResourceLoader resourceLoader = new DefaultResourceLoader(); + InputStream is = resourceLoader.getResource("classpath:templates/ClcokingIn.xlsx").getInputStream(); + Workbook workbook = new XSSFWorkbook(is); + //写入数据 + Workbook wbs = PoiUtil.exportWB("考勤统计", list, workbook); + + return excelReport(wbs); + } - //导出操作 + private ClockingInVo.ExcelUrl excelReport(Workbook wbs) throws IOException { + //生成导出文件 String fileName = DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; String path = PropUtil.path + fileName; File tmpFile = new File(path); if (!tmpFile.getParentFile().exists()) { tmpFile.getParentFile().mkdirs(); } - - Workbook wbs = PoiUtil.exportWB("Sheet1", list, workbook); + //将workBook写入文件 OutputStream stream = new FileOutputStream(tmpFile); wbs.write(stream); stream.close(); + //返回文件路径 ClockingInVo.ExcelUrl excelUrl = new ClockingInVo.ExcelUrl(); String url = PropUtil.imgDomain+fileName; excelUrl.setUrl(url); return excelUrl; } + + private List> createCell(List dateList, List clockMembers) { + //整体数据 + List> list = new ArrayList<>(); + //第一行(标题) + list.add(new ArrayList<>()); + //第二三行(表头) + list.add(new ArrayList<>()); + list.add(new ArrayList<>()); + //序号 + int a = 1; + //判断成员不为空 + if (CollectionUtil.isNotEmpty(clockMembers)) { + // 循环成员 + for (ClockingInVo.ClockMember clockMember : clockMembers) { + //计算工作日未打卡的记录 + List notList = notClocking(dateList, clockMember); + //实际出勤天数row + List clockingInTimes = new ArrayList<>(); + //序号 + clockingInTimes.add(new PoiUtil.PoiUtilCell(a + "", 1, 4 + (notList.size() == 0 ? 1 : notList.size()))); + //成员名 + clockingInTimes.add(new PoiUtil.PoiUtilCell(clockMember.getName(), 1, 4 + (notList.size() == 0 ? 1 : notList.size()))); + clockingInTimes.add(new PoiUtil.PoiUtilCell("实际考勤天数")); + clockingInTimes.add(new PoiUtil.PoiUtilCell(clockMember.getRecordMemberList().size() + "")); + list.add(clockingInTimes); + + //请假天数row + list.add(getOneRow("请假天数",0 + "")); + //加班天数row + list.add(getOneRow("加班天数",0 + " ")); + //出差天数row + list.add(getOneRow("出差天数",0 + "")); + + //未打卡次数及时间 + if(CollectionUtil.isEmpty(notList)){ + List notClocking = new ArrayList<>(); + notClocking.add(new PoiUtil.PoiUtilCell()); + notClocking.add(new PoiUtil.PoiUtilCell()); + notClocking.add(new PoiUtil.PoiUtilCell("未打卡次数及时间")); + notClocking.add(new PoiUtil.PoiUtilCell(0 + "次")); + list.add(notClocking); + }else { + for (int i = 0; i < notList.size(); i++) { + ClockingInVo.NotClockingIn notClockingIn = notList.get(i); + List notClocking = new ArrayList<>(); + notClocking.add(new PoiUtil.PoiUtilCell()); + notClocking.add(new PoiUtil.PoiUtilCell()); + if(i == 0){ + notClocking.add(new PoiUtil.PoiUtilCell("未打卡次数及时间", 1, notList.size())); + notClocking.add(new PoiUtil.PoiUtilCell(notList.size() + "次", 1, notList.size())); + }else { + notClocking.add(new PoiUtil.PoiUtilCell()); + notClocking.add(new PoiUtil.PoiUtilCell()); + } + notClocking.add(new PoiUtil.PoiUtilCell(notClockingIn.getTime())); + notClocking.add(new PoiUtil.PoiUtilCell(notClockingIn.getType())); + list.add(notClocking); + } + } + + } + } + + return list; + } + + private List getOneRow(String value,String times) { + List row = new ArrayList<>(); + row.add(new PoiUtil.PoiUtilCell()); + row.add(new PoiUtil.PoiUtilCell()); + row.add(new PoiUtil.PoiUtilCell(value)); + row.add(new PoiUtil.PoiUtilCell(times)); + return row; + } + + private List notClocking(List dateList, ClockingInVo.ClockMember clockMember) { + List notList = new ArrayList<>(); + Map recordMemberMap = clockMember.getRecordMemberMap(); + if (CollectionUtil.isNotEmpty(dateList)) { + //循环计算未打卡的记录 + dateList.forEach(day -> { + ClockingInVo.RecordMember recordMember = recordMemberMap.get(day); + if (recordMember == null) { + //工作日未打卡,将记录存入数组 + ClockingInVo.NotClockingIn notMorning = new ClockingInVo.NotClockingIn(day, "早"); + ClockingInVo.NotClockingIn notNight = new ClockingInVo.NotClockingIn(day, "晚"); + notList.add(notMorning); + notList.add(notNight); + } else { + if (recordMember.getMorning() == null || recordMember.getMorning() == 0) { + ClockingInVo.NotClockingIn notMorning = new ClockingInVo.NotClockingIn(day, "早"); + notList.add(notMorning); + } + if (recordMember.getMorning() == null || recordMember.getMorning() == 0) { + ClockingInVo.NotClockingIn notNight = new ClockingInVo.NotClockingIn(day, "晚"); + notList.add(notNight); + } + } + }); + } + return notList; + } + + private List getDateList(Long startTime, Long endTime) { + List dateList = new ArrayList<>(); + DateFormat df = new SimpleDateFormat("MM-dd"); + String isHoliday = ""; + String overDay = ""; + //获取假日调休信息 + SysHolidaysExample holidaysExample = new SysHolidaysExample(); + holidaysExample.createCriteria().andYearEqualTo(new SimpleDateFormat("yyyy").format(new Date())); + List sysHolidays = holidaysMapper.selectByExample(holidaysExample); + if (CollectionUtil.isNotEmpty(sysHolidays)) { + isHoliday = sysHolidays.get(0).getHoliday(); + overDay = sysHolidays.get(0).getWorkday(); + } + + Calendar min = Calendar.getInstance(); + Calendar max = Calendar.getInstance(); + min.setTime(new Date(startTime)); + max.setTime(new Date(endTime)); + max.add(Calendar.DATE, 1); + while (max.after(min)) { + int i = min.get(Calendar.DAY_OF_WEEK); + //是调休 || (不是周末 && 不是节假日) + if (overDay.contains(df.format(min.getTime())) || ((i != 1 && i != 7) && !isHoliday.contains(df.format(min.getTime())))) { + dateList.add(new SimpleDateFormat("yyyy-MM-dd").format(min.getTime())); + } + min.add(Calendar.DATE, 1); + } + + return dateList; + } } diff --git a/src/main/java/com/ccsens/defaultwbs/service/IClockingInService.java b/src/main/java/com/ccsens/defaultwbs/service/IClockingInService.java index 16e3cfd..7c92ee9 100644 --- a/src/main/java/com/ccsens/defaultwbs/service/IClockingInService.java +++ b/src/main/java/com/ccsens/defaultwbs/service/IClockingInService.java @@ -41,5 +41,7 @@ public interface IClockingInService { */ ClockingInVo.ExcelUrl exportRecord(ClockingInDto.QueryClockingIn params, Long userId) throws IOException; + ClockingInVo.ExcelUrl exportRecord1(ClockingInDto.QueryClockingIn params, Long userId) throws Exception; + void auditRecord1(ClockingInDto.Audit param, Long userId); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c3b11fb..2fb38e5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: test - include: common, util-test + active: dev + include: common, util-dev diff --git a/src/main/resources/druid-dev.yml b/src/main/resources/druid-dev.yml index c823ae7..0e658fd 100644 --- a/src/main/resources/druid-dev.yml +++ b/src/main/resources/druid-dev.yml @@ -28,8 +28,8 @@ spring: testOnReturn: false testWhileIdle: true timeBetweenEvictionRunsMillis: 60000 -# url: jdbc:mysql://49.233.89.188:3306/defaultwbs?useUnicode=true&characterEncoding=UTF-8 - url: jdbc:mysql://www.tall.wiki/defaultwbs?useUnicode=true&characterEncoding=UTF-8 + url: jdbc:mysql://49.233.89.188:3306/defaultwbs?useUnicode=true&characterEncoding=UTF-8 +# url: jdbc:mysql://www.tall.wiki/defaultwbs?useUnicode=true&characterEncoding=UTF-8 # url: jdbc:mysql://127.0.0.1/mt?useUnicode=true&characterEncoding=UTF-8 username: root validationQuery: SELECT 1 FROM DUAL diff --git a/src/main/resources/mapper_dao/ProClockingInDao.xml b/src/main/resources/mapper_dao/ProClockingInDao.xml index 9ecd5a4..e58902b 100644 --- a/src/main/resources/mapper_dao/ProClockingInDao.xml +++ b/src/main/resources/mapper_dao/ProClockingInDao.xml @@ -105,4 +105,53 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mbg.xml b/src/main/resources/mbg.xml index 5eb50a2..4c76971 100644 --- a/src/main/resources/mbg.xml +++ b/src/main/resources/mbg.xml @@ -78,9 +78,10 @@ -
-
-
+ + + +