diff --git a/common/src/main/java/com/ccsens/common/api/TaskController.java b/common/src/main/java/com/ccsens/common/api/TaskController.java index bbfb2501..d23ef86f 100644 --- a/common/src/main/java/com/ccsens/common/api/TaskController.java +++ b/common/src/main/java/com/ccsens/common/api/TaskController.java @@ -85,6 +85,12 @@ // return JsonResponse.newInstance().ok(); // } // -// +// @MustLogin +// @ApiOperation(value = "导出考勤excel", notes = "") +// @RequestMapping(value = "/export", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) +// public JsonResponse export(@ApiParam @Validated @RequestBody QueryDto params) throws Exception{ +// clockingInService.exportRecord(params.getParam(), params.getUserId()); +// return JsonResponse.newInstance().ok(); +// } // //} diff --git a/common/src/main/java/com/ccsens/common/bean/dto/CShareDto.java b/common/src/main/java/com/ccsens/common/bean/dto/CShareDto.java index 15edbd59..5f670e79 100644 --- a/common/src/main/java/com/ccsens/common/bean/dto/CShareDto.java +++ b/common/src/main/java/com/ccsens/common/bean/dto/CShareDto.java @@ -30,11 +30,22 @@ public class CShareDto { @Data @ApiModel("点击分享链接") public static class ClickShareUrl { - @NotBlank(message = "链接信息错误") - @ApiModelProperty("链接id") - private String shareId; +// @NotBlank(message = "链接信息错误") +// @ApiModelProperty("链接id") +// private String shareId; @NotBlank(message = "code信息错误") @ApiModelProperty("加密code") private String code; } + + @Data + @ApiModel("点击分享链接") + public static class QueryMemberByShare { + @NotNull(message = "请选择项目") + @ApiModelProperty("项目id") + private Long projectId; + @NotNull(message = "code错误") + @ApiModelProperty("加密code") + private String code; + } } diff --git a/common/src/main/java/com/ccsens/common/persist/dao/ProClockingInDao.java b/common/src/main/java/com/ccsens/common/persist/dao/ProClockingInDao.java index 4870c3b2..7a31a27c 100644 --- a/common/src/main/java/com/ccsens/common/persist/dao/ProClockingInDao.java +++ b/common/src/main/java/com/ccsens/common/persist/dao/ProClockingInDao.java @@ -1,5 +1,6 @@ package com.ccsens.common.persist.dao; +import com.ccsens.common.bean.po.ProClockingIn; import com.ccsens.common.bean.vo.CClockingInVo; import com.ccsens.common.persist.mapper.ProClockingInMapper; import org.apache.ibatis.annotations.Param; @@ -19,4 +20,12 @@ public interface ProClockingInDao extends ProClockingInMapper { * @return 打卡记录列表 */ List queryByMemberId(@Param("memberIdList") List memberIdList); + + /** + * 查询该成员今天是否有打卡记录 + * @param memberId 成员id + * @param currentTimeMillis 当前时间时间戳 + * @return 打卡记录 + */ + ProClockingIn queryHaveData(@Param("memberId") Long memberId,@Param("time") long currentTimeMillis); } diff --git a/common/src/main/java/com/ccsens/common/service/ClockingInService.java b/common/src/main/java/com/ccsens/common/service/ClockingInService.java index 176a0390..09acce52 100644 --- a/common/src/main/java/com/ccsens/common/service/ClockingInService.java +++ b/common/src/main/java/com/ccsens/common/service/ClockingInService.java @@ -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 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 clockingInInfos = queryClockingIn(params, userId); log.info("调用查询考勤方法结束{}",clockingInInfos); + Workbook workbook = new XSSFWorkbook(); + //空白格 + PoiUtil.PoiUtilCell blank = new PoiUtil.PoiUtilCell(); + //excel + List> list = new ArrayList<>(); + //第一行list + List firstCells = new ArrayList<>(); + //第二行list + List 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 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 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; } } diff --git a/common/src/main/java/com/ccsens/common/service/IClockingInService.java b/common/src/main/java/com/ccsens/common/service/IClockingInService.java index b5aa4efd..96fead20 100644 --- a/common/src/main/java/com/ccsens/common/service/IClockingInService.java +++ b/common/src/main/java/com/ccsens/common/service/IClockingInService.java @@ -3,6 +3,7 @@ package com.ccsens.common.service; import com.ccsens.common.bean.dto.CClockingInDto; import com.ccsens.common.bean.vo.CClockingInVo; +import java.io.IOException; import java.util.List; /** @@ -38,5 +39,5 @@ public interface IClockingInService { * @param userId 当前用户userId * @return excel的路径 */ - CClockingInVo.ExcelUrl exportRecord(CClockingInDto.QueryClockingIn params,Long userId); + CClockingInVo.ExcelUrl exportRecord(CClockingInDto.QueryClockingIn params,Long userId) throws IOException; } diff --git a/common/src/main/java/com/ccsens/common/service/IShareService.java b/common/src/main/java/com/ccsens/common/service/IShareService.java index 24c96bc0..edf73bde 100644 --- a/common/src/main/java/com/ccsens/common/service/IShareService.java +++ b/common/src/main/java/com/ccsens/common/service/IShareService.java @@ -23,4 +23,12 @@ public interface IShareService { * @return 项目和角色id */ CShareVo.ClickShareInfo clickShareUrl(CShareDto.ClickShareUrl param,Long userId,String userName,String phone); + + /** + * 查询通过分享链接加入的成员 + * @param param 参数 + * @param userId 用户id + * @return 成员列表 + */ + CShareVo.ClickShareInfo queryMemberByShare(CShareDto.QueryMemberByShare param,Long userId); } diff --git a/common/src/main/java/com/ccsens/common/service/ShareService.java b/common/src/main/java/com/ccsens/common/service/ShareService.java index a641c45c..3de17fd9 100644 --- a/common/src/main/java/com/ccsens/common/service/ShareService.java +++ b/common/src/main/java/com/ccsens/common/service/ShareService.java @@ -138,4 +138,11 @@ public class ShareService implements IShareService{ shareMemberDao.insertSelective(proShareMember); return clickShareInfo; } + + + @Override + public CShareVo.ClickShareInfo queryMemberByShare(CShareDto.QueryMemberByShare param, Long userId) { + + return null; + } } diff --git a/common/src/main/resources/mapper_dao/ProClockingInDao.xml b/common/src/main/resources/mapper_dao/ProClockingInDao.xml index 88bcfd23..b250896f 100644 --- a/common/src/main/resources/mapper_dao/ProClockingInDao.xml +++ b/common/src/main/resources/mapper_dao/ProClockingInDao.xml @@ -25,4 +25,26 @@ + + \ No newline at end of file diff --git a/util/src/main/java/com/ccsens/util/PoiUtil.java b/util/src/main/java/com/ccsens/util/PoiUtil.java index 0bd7c4cd..3730ab67 100644 --- a/util/src/main/java/com/ccsens/util/PoiUtil.java +++ b/util/src/main/java/com/ccsens/util/PoiUtil.java @@ -636,33 +636,65 @@ public class PoiUtil { // workbook.write(stream); // stream.close(); - - + //第一行 + PoiUtilCell blank = new PoiUtilCell(); PoiUtilCell poiUtilCell = new PoiUtilCell(); - poiUtilCell.setValue("111222333"); - poiUtilCell.setColspan(2); - poiUtilCell.setRowspan(1); - + poiUtilCell.setValue("空白"); + poiUtilCell.setColspan(1); + poiUtilCell.setRowspan(2); PoiUtilCell poiUtilCell1 = new PoiUtilCell(); - poiUtilCell1.setValue("1112222"); + poiUtilCell1.setValue("2021.8.31"); + poiUtilCell1.setColspan(2); + poiUtilCell1.setRowspan(1); PoiUtilCell poiUtilCell3 = new PoiUtilCell(); - poiUtilCell3.setValue("123"); - - PoiUtilCell poiUtilCell2 = new PoiUtilCell(); - poiUtilCell2.setValue(""); + poiUtilCell3.setValue("2021.9.1"); + poiUtilCell3.setColspan(2); + poiUtilCell3.setRowspan(1); + //第二行 + PoiUtilCell poiUtilCellTwo1 = new PoiUtilCell(); + poiUtilCellTwo1.setValue(""); + poiUtilCellTwo1.setValue(""); + PoiUtilCell poiUtilCellTwo2 = new PoiUtilCell(); + poiUtilCellTwo2.setValue("早"); + PoiUtilCell poiUtilCellTwo3 = new PoiUtilCell(); + poiUtilCellTwo3.setValue("晚"); + PoiUtilCell poiUtilCellTwo4 = new PoiUtilCell(); + poiUtilCellTwo2.setValue("早"); + PoiUtilCell poiUtilCellTwo5 = new PoiUtilCell(); + poiUtilCellTwo3.setValue("晚"); //poiUtilCell2.setFunction("SUM(A1:C1)"); + //第三行 + PoiUtilCell poiUtilCellThree1 = new PoiUtilCell(); + poiUtilCellThree1.setValue("张三"); + PoiUtilCell poiUtilCellThree2 = new PoiUtilCell(); + poiUtilCellThree2.setValue("10:43"); + PoiUtilCell poiUtilCellThree3 = new PoiUtilCell(); + poiUtilCellThree3.setValue("20:00"); List cells = new ArrayList<>(); cells.add(poiUtilCell); cells.add(poiUtilCell1); - cells.add(poiUtilCell1); + cells.add(blank); cells.add(poiUtilCell3); + cells.add(blank); - cells.add(poiUtilCell2); List cells2 = new ArrayList<>(); + cells2.add(poiUtilCellTwo1); + cells2.add(poiUtilCellTwo2); + cells2.add(poiUtilCellTwo3); + cells2.add(poiUtilCellTwo4); + cells2.add(poiUtilCellTwo5); + + List cells3 = new ArrayList<>(); + cells3.add(poiUtilCellThree1); + cells3.add(poiUtilCellThree2); + cells3.add(poiUtilCellThree3); + List> list = new ArrayList<>(); list.add(cells); + list.add(cells2); + list.add(cells3);