|
|
|
@ -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<ClockingInVo.ClockingInInfo> 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<Long> 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<ClockingInVo.ClockRecord> clockRecordList = clockingInDao.queryMembersOfClock(params.getProjectId(),userOfMemberId,params.getRoleId()); |
|
|
|
ProMember member = memberDao.queryMemberOfRole(userOfMemberId, params.getRoleId()); |
|
|
|
if (CollectionUtil.isEmpty(params.getMemberIdList())) { |
|
|
|
List<ClockingInVo.ClockRecord> 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<ClockingInVo.ClockRecord> clockRecordList = clockingInDao.queryMemberByIdList(params.getMemberIdList(),params.getRoleId()); |
|
|
|
List<ClockingInVo.ClockRecord> 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<ClockingInVo.ClockingInInfo> 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<PoiUtil.PoiUtilCell> 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<String> dateList = getDateList(params.getStartTime(), params.getEndTime()); |
|
|
|
//查询需要的成员的记录
|
|
|
|
List<ClockingInVo.ClockMember> clockMembers = clockingInDao.queryMemberClockingIn(params.getMemberIdList(), params.getRoleId(), params.getStartTime(), params.getEndTime()); |
|
|
|
|
|
|
|
//生成导入数据
|
|
|
|
List<List<PoiUtil.PoiUtilCell>> 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<List<PoiUtil.PoiUtilCell>> createCell(List<String> dateList, List<ClockingInVo.ClockMember> clockMembers) { |
|
|
|
//整体数据
|
|
|
|
List<List<PoiUtil.PoiUtilCell>> 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<ClockingInVo.NotClockingIn> notList = notClocking(dateList, clockMember); |
|
|
|
//实际出勤天数row
|
|
|
|
List<PoiUtil.PoiUtilCell> 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<PoiUtil.PoiUtilCell> 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<PoiUtil.PoiUtilCell> 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<PoiUtil.PoiUtilCell> getOneRow(String value,String times) { |
|
|
|
List<PoiUtil.PoiUtilCell> 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<ClockingInVo.NotClockingIn> notClocking(List<String> dateList, ClockingInVo.ClockMember clockMember) { |
|
|
|
List<ClockingInVo.NotClockingIn> notList = new ArrayList<>(); |
|
|
|
Map<String, ClockingInVo.RecordMember> 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<String> getDateList(Long startTime, Long endTime) { |
|
|
|
List<String> 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> 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; |
|
|
|
} |
|
|
|
} |
|
|
|
|