|
|
@ -12,14 +12,23 @@ import com.ccsens.common.bean.vo.CClockingInVo; |
|
|
|
import com.ccsens.common.persist.dao.ProClockingInDao; |
|
|
|
import com.ccsens.common.persist.dao.ProMemberDao; |
|
|
|
import com.ccsens.common.util.CommonCodeError; |
|
|
|
import com.ccsens.util.PoiUtil; |
|
|
|
import com.ccsens.util.PropUtil; |
|
|
|
import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
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.text.DateFormat; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
@ -101,6 +110,7 @@ public class ClockingInService implements IClockingInService { |
|
|
|
CClockingInVo.ClockRecord filterRecord = new CClockingInVo.ClockRecord(); |
|
|
|
filterRecord.setMemberId(clockRecord.getMemberId()); |
|
|
|
filterRecord.setMemberName(clockRecord.getMemberName()); |
|
|
|
filterRecord.setMemberUserId(clockRecord.getMemberUserId()); |
|
|
|
if (filterRecord.getMemberUserId().equals(userId)) { |
|
|
|
filterRecord.setIsMine((byte)1); |
|
|
|
} |
|
|
@ -113,7 +123,7 @@ public class ClockingInService implements IClockingInService { |
|
|
|
List<CClockingInVo.ClockRecord> clockRecords = clockingInDao.queryByMemberId(memberIdList); |
|
|
|
for (CClockingInVo.ClockingInInfo clockingInInfo2 : list) { |
|
|
|
for (CClockingInVo.ClockRecord record : clockRecords) { |
|
|
|
if (format.format(new Date(record.getMorning())).equals(clockingInInfo2.getDateTime())) { |
|
|
|
if (format.format(new Date(record.getMorning())).equals(clockingInInfo2.getDateTime()) || format.format(new Date(record.getNight())).equals(clockingInInfo2.getDateTime())) { |
|
|
|
for (CClockingInVo.ClockRecord clockRecord : clockingInInfo2.getRecordList()) { |
|
|
|
if (clockRecord.getMemberId().equals(record.getMemberId())) { |
|
|
|
|
|
|
@ -152,9 +162,10 @@ public class ClockingInService implements IClockingInService { |
|
|
|
throw new BaseException(CommonCodeError.DATE_ERROR); |
|
|
|
} |
|
|
|
//判断是否有打卡记录
|
|
|
|
if(ObjectUtil.isNotNull(params.getId())){ |
|
|
|
ProClockingIn proClockingIn = clockingInDao.queryHaveData(params.getMemberId(),System.currentTimeMillis()); |
|
|
|
if(ObjectUtil.isNotNull(proClockingIn)){ |
|
|
|
//如果有记录则查找记录并修改
|
|
|
|
ProClockingIn proClockingIn = clockingInDao.selectByPrimaryKey(params.getId()); |
|
|
|
// ProClockingIn proClockingIn = clockingInDao.selectByPrimaryKey(params.getId());
|
|
|
|
if(params.getClockType() == 0 && proClockingIn.getMorningStatus() == 0){ |
|
|
|
proClockingIn.setMorning(System.currentTimeMillis()); |
|
|
|
proClockingIn.setMorningStatus((byte) 1); |
|
|
@ -166,18 +177,18 @@ public class ClockingInService implements IClockingInService { |
|
|
|
clockingInDao.updateByPrimaryKeySelective(proClockingIn); |
|
|
|
}else { |
|
|
|
//如果没有记录,则添加一条新的记录
|
|
|
|
ProClockingIn proClockingIn = new ProClockingIn(); |
|
|
|
proClockingIn.setId(snowflake.nextId()); |
|
|
|
proClockingIn.setMemberId(params.getMemberId()); |
|
|
|
proClockingIn.setCheckerId(params.getCheckerId()); |
|
|
|
ProClockingIn newClockingIn = new ProClockingIn(); |
|
|
|
newClockingIn.setId(snowflake.nextId()); |
|
|
|
newClockingIn.setMemberId(params.getMemberId()); |
|
|
|
newClockingIn.setCheckerId(params.getCheckerId()); |
|
|
|
if(params.getClockType() == 0){ |
|
|
|
proClockingIn.setMorning(System.currentTimeMillis()); |
|
|
|
proClockingIn.setMorningStatus((byte) 1); |
|
|
|
newClockingIn.setMorning(System.currentTimeMillis()); |
|
|
|
newClockingIn.setMorningStatus((byte) 1); |
|
|
|
}else if(params.getClockType() == 1){ |
|
|
|
proClockingIn.setNight(System.currentTimeMillis()); |
|
|
|
proClockingIn.setNightStatus((byte) 1); |
|
|
|
newClockingIn.setNight(System.currentTimeMillis()); |
|
|
|
newClockingIn.setNightStatus((byte) 1); |
|
|
|
} |
|
|
|
clockingInDao.insertSelective(proClockingIn); |
|
|
|
clockingInDao.insertSelective(newClockingIn); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@ -216,12 +227,92 @@ public class ClockingInService implements IClockingInService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CClockingInVo.ExcelUrl exportRecord(CClockingInDto.QueryClockingIn params, Long userId) { |
|
|
|
public CClockingInVo.ExcelUrl exportRecord(CClockingInDto.QueryClockingIn params, Long userId) throws IOException { |
|
|
|
log.info("开始调用查询考勤方法"); |
|
|
|
List<CClockingInVo.ClockingInInfo> clockingInInfos = queryClockingIn(params, userId); |
|
|
|
log.info("调用查询考勤方法结束{}",clockingInInfos); |
|
|
|
Workbook workbook = new XSSFWorkbook(); |
|
|
|
//空白格
|
|
|
|
PoiUtil.PoiUtilCell blank = new PoiUtil.PoiUtilCell(); |
|
|
|
//excel
|
|
|
|
List<List<PoiUtil.PoiUtilCell>> list = new ArrayList<>(); |
|
|
|
//第一行list
|
|
|
|
List<PoiUtil.PoiUtilCell> firstCells = new ArrayList<>(); |
|
|
|
//第二行list
|
|
|
|
List<PoiUtil.PoiUtilCell> secondCells = new ArrayList<>(); |
|
|
|
//第一行开始
|
|
|
|
PoiUtil.PoiUtilCell poiUtilCell = new PoiUtil.PoiUtilCell(); |
|
|
|
poiUtilCell.setValue(""); |
|
|
|
poiUtilCell.setColspan(1); |
|
|
|
poiUtilCell.setRowspan(2); |
|
|
|
firstCells.add(poiUtilCell); |
|
|
|
//第二行开始
|
|
|
|
secondCells.add(blank); |
|
|
|
for (CClockingInVo.ClockingInInfo clockingInInfo : clockingInInfos) { |
|
|
|
PoiUtil.PoiUtilCell cellOne = new PoiUtil.PoiUtilCell(); |
|
|
|
cellOne.setValue(clockingInInfo.getDateTime()); |
|
|
|
cellOne.setColspan(2); |
|
|
|
cellOne.setRowspan(1); |
|
|
|
firstCells.add(cellOne); |
|
|
|
firstCells.add(blank); |
|
|
|
PoiUtil.PoiUtilCell cellTwo = new PoiUtil.PoiUtilCell(); |
|
|
|
cellTwo.setValue("早"); |
|
|
|
secondCells.add(cellTwo); |
|
|
|
PoiUtil.PoiUtilCell cellTwo2 = new PoiUtil.PoiUtilCell(); |
|
|
|
cellTwo2.setValue("晚"); |
|
|
|
secondCells.add(cellTwo2); |
|
|
|
} |
|
|
|
list.add(firstCells); |
|
|
|
list.add(secondCells); |
|
|
|
for (CClockingInVo.ClockingInInfo clockingInInfo : clockingInInfos) { |
|
|
|
//添加考勤信息
|
|
|
|
for (CClockingInVo.ClockRecord clockRecord : clockingInInfo.getRecordList()) { |
|
|
|
List<PoiUtil.PoiUtilCell> memberCells = new ArrayList<>(); |
|
|
|
PoiUtil.PoiUtilCell cell = new PoiUtil.PoiUtilCell(); |
|
|
|
cell.setValue(clockRecord.getMemberName()); |
|
|
|
memberCells.add(cell); |
|
|
|
list.add(memberCells); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); |
|
|
|
for (CClockingInVo.ClockingInInfo clockingInInfo : clockingInInfos) { |
|
|
|
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()){ |
|
|
|
morning.setValue("未打卡"); |
|
|
|
}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()){ |
|
|
|
night.setValue("未打卡"); |
|
|
|
}else{ |
|
|
|
night.setValue(format.format(new Date(clockingInInfo.getRecordList().get(i).getNight()))); |
|
|
|
} |
|
|
|
poiUtilCells.add(night); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
//导出操作
|
|
|
|
String fileName = cn.hutool.core.date.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); |
|
|
|
OutputStream stream = new FileOutputStream(tmpFile); |
|
|
|
wbs.write(stream); |
|
|
|
stream.close(); |
|
|
|
CClockingInVo.ExcelUrl excelUrl = new CClockingInVo.ExcelUrl(); |
|
|
|
String url = PropUtil.imgDomain+fileName; |
|
|
|
excelUrl.setUrl(url); |
|
|
|
return excelUrl; |
|
|
|
} |
|
|
|
} |
|
|
|