pom.xml
@@ -39,6 +39,7 @@ <tomcat.version>9.0.102</tomcat.version> <minio.version>8.4.3</minio.version> <okhttp.version>4.9.0</okhttp.version> <hutool.version>5.8.18</hutool.version> <logback.version>1.2.13</logback.version> <spring-security.version>5.7.12</spring-security.version> <spring-framework.version>5.3.39</spring-framework.version> @@ -314,6 +315,13 @@ <version>${getui-sdk.version}</version> <scope>compile</scope> </dependency> <!--hutoolå·¥å ·å --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version> </dependency> </dependencies> src/main/java/com/ruoyi/ScheduleTask.java
@@ -55,4 +55,6 @@ .eq(SysNotice::getStatus,"1") .lt(SysNotice::getCreateTime, LocalDateTime.now())); } } src/main/java/com/ruoyi/staff/controller/PersonalShiftController.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,98 @@ package com.ruoyi.staff.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.write.style.HorizontalCellStyleStrategy; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.framework.web.domain.R; import com.ruoyi.staff.dto.PerformanceShiftAddDto; import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig; import com.ruoyi.staff.pojo.PersonalShift; import com.ruoyi.staff.service.PersonalAttendanceLocationConfigService; import com.ruoyi.staff.service.PersonalShiftService; import com.ruoyi.staff.utils.StyleMonthUtils; import com.ruoyi.staff.utils.StyleYearUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import java.util.Collection; import java.util.List; import java.util.Map; /** * <p> * å端æ§å¶å¨ * </p> * * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå ¬å¸ * @since 2026-03-05 03:52:19 */ @RestController @RequestMapping("/personalShift") @Api(tags = "人åæç") public class PersonalShiftController { @Autowired private PersonalShiftService personalShiftService; @ApiOperation("人åæç") @PostMapping("/add") public R add(@RequestBody PerformanceShiftAddDto performanceShiftAddDto){ return R.ok(personalShiftService.performanceShiftAdd(performanceShiftAddDto)); } @ApiOperation(value = "æä»½å页æ¥è¯¢") @GetMapping("page") public R performanceShiftPage(Integer size, Integer current, String time, String userName, Integer sysDeptId) { return R.ok(personalShiftService.performanceShiftPage(new Page<>(current, size), time, userName, sysDeptId)); } @ApiOperation(value = "年份å页æ¥è¯¢") @GetMapping("pageYear") public R performanceShiftPageYear(Integer size, Integer current, String time, String userName, Integer sysDeptId) { return R.ok(personalShiftService.performanceShiftPageYear(new Page<>(current, size), time, userName, sysDeptId)); } @ApiOperation(value = "çæ¬¡ç¶æä¿®æ¹") @PostMapping("update") public R performanceShiftUpdate(@RequestBody PersonalShift personalShift) { personalShiftService.performanceShiftUpdate(personalShift); return R.ok(); } @ApiOperation(value = "导åº") @GetMapping("export") public void exportToExcel(@NotNull(message = "æ¶é´ä¸è½ä¸ºç©ºï¼") String time, String userName, Integer sysDeptId, Boolean isMonth, HttpServletResponse response) throws Exception { Map<Object, Object> data; response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); response.setHeader("requestType","excel"); response.setHeader("Access-Control-Expose-Headers", "requestType"); if (!isMonth) { data = personalShiftService.exportToYearExcel(time, userName, sysDeptId); // 设置åå æ ¼æ ·å¼ HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleYearUtils.getHeadStyle(), StyleYearUtils.getContentStyle()); // ä¿åå°ç¬¬ä¸ä¸ªsheetä¸ EasyExcel.write(response.getOutputStream()) .head((List<List<String>>) data.get("header")) .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // èªéåºå宽 .registerWriteHandler(horizontalCellStyleStrategy) .sheet("年度") .doWrite((Collection<?>) data.get("data")); } else { data = personalShiftService.exportToMonthExcel(time, userName, sysDeptId); // 设置åå æ ¼æ ·å¼ HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleMonthUtils.getHeadStyle(), StyleMonthUtils.getContentStyle()); EasyExcel.write(response.getOutputStream()) .head((List<List<String>>) data.get("header")) .registerWriteHandler(horizontalCellStyleStrategy) .sheet("æåº¦") .doWrite((Collection<?>) data.get("data")); } } } src/main/java/com/ruoyi/staff/dto/PerformanceShiftAddDto.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,33 @@ package com.ruoyi.staff.dto; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Data public class PerformanceShiftAddDto { @NotNull(message = "è¯·éæ©çæ¬¡") @ApiModelProperty("çæ¬¡") private Integer personalAttendanceLocationConfigId; @NotNull(message = "è¯·éæ©åå·¥") @ApiModelProperty("åå·¥id") private String staffOnJobId; @NotNull(message = "è¯·éæ©å¨æ¬¡") @ApiModelProperty("å¼å§å¨æ¬¡") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime startWeek; @NotNull(message = "è¯·éæ©å¨æ¬¡") @ApiModelProperty("ç»æå¨æ¬¡") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime endWeek; } src/main/java/com/ruoyi/staff/dto/PerformanceShiftMapDto.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,26 @@ package com.ruoyi.staff.dto; import lombok.Data; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Data public class PerformanceShiftMapDto { private String name; private String shiftTime; private String userId; private String department; private Map<String, Object> monthlyAttendance = new HashMap<>(); private List<Map<String, Object>> list = new ArrayList<>(); private List<Map<Object, Object>> headerList = new ArrayList<>(); } src/main/java/com/ruoyi/staff/dto/PersonalAttendanceRecordsDto.java
@@ -40,4 +40,7 @@ @JsonFormat(pattern = "HH:mm") @DateTimeFormat(pattern = "HH:mm") private LocalTime endAt; //çæ¬¡ private String shift; } src/main/java/com/ruoyi/staff/mapper/PersonalShiftMapper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,34 @@ package com.ruoyi.staff.mapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.config.MyBaseMapper; import com.ruoyi.staff.dto.PerformanceShiftMapDto; import com.ruoyi.staff.pojo.PersonalShift; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; /** * <p> * Mapper æ¥å£ * </p> * * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå ¬å¸ * @since 2026-03-05 03:52:19 */ @Mapper public interface PersonalShiftMapper extends BaseMapper<PersonalShift> { IPage<PerformanceShiftMapDto> performanceShiftPage(Page<Object> page, @Param("time") String time, @Param("userName") String userName, @Param("sysDeptId") Integer sysDeptId); IPage<Map<String, Object>> performanceShiftYear(Page<Object> page, @Param("time") String time, @Param("userName") String userName, @Param("sysDeptId") Integer sysDeptId); List<Map<String, Object>> performanceShiftYearList(@Param("time") String time, @Param("userName") String userName, @Param("sysDeptId") Integer sysDeptId); List<PerformanceShiftMapDto> performanceShiftList(@Param("time") String time, @Param("userName") String userName, @Param("sysDeptId") Integer sysDeptId); } src/main/java/com/ruoyi/staff/pojo/PersonalAttendanceLocationConfig.java
@@ -57,4 +57,7 @@ @JsonFormat(pattern = "HH:mm") @DateTimeFormat(pattern = "HH:mm") private LocalTime endAt; @ApiModelProperty("çæ¬¡") private String shift; } src/main/java/com/ruoyi/staff/pojo/PersonalShift.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,59 @@ package com.ruoyi.staff.pojo; import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import java.time.LocalDateTime; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; import org.springframework.format.annotation.DateTimeFormat; /** * <p> * * </p> * * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå ¬å¸ * @since 2026-03-05 03:52:19 */ @Getter @Setter @TableName("personal_shift") @ApiModel(value = "PersonalShift对象", description = "") public class PersonalShift implements Serializable { private static final long serialVersionUID = 1L; @TableId(value = "id", type = IdType.AUTO) private Long id; @ApiModelProperty("çæ¬¡(æå¡è§åid)") private Integer personalAttendanceLocationConfigId; @ApiModelProperty("åå·¥å¨èid") private Long staffOnJobId; @ApiModelProperty("å½å ¥æ¶é´") @TableField(fill = FieldFill.INSERT) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime createTime; @ApiModelProperty("æ´æ°æ¶é´") @TableField(fill = FieldFill.INSERT_UPDATE) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime updateTime; @ApiModelProperty("æçæ¥æ") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime workTime; } src/main/java/com/ruoyi/staff/service/PersonalShiftService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,32 @@ package com.ruoyi.staff.service; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.staff.dto.PerformanceShiftAddDto; import com.ruoyi.staff.pojo.PersonalShift; import com.baomidou.mybatisplus.extension.service.IService; import java.util.Map; /** * <p> * æå¡ç±» * </p> * * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå ¬å¸ * @since 2026-03-05 03:52:19 */ public interface PersonalShiftService extends IService<PersonalShift> { int performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto); Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, Integer sysDeptId); void performanceShiftUpdate(PersonalShift performanceShift); IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, Integer sysDeptId); Map<Object, Object> exportToYearExcel(String time, String userName, Integer sysDeptId) throws Exception; Map<Object, Object> exportToMonthExcel(String time, String userName, Integer sysDeptId); } src/main/java/com/ruoyi/staff/service/impl/PersonalAttendanceRecordsServiceImpl.java
@@ -1,5 +1,6 @@ package com.ruoyi.staff.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -14,10 +15,12 @@ import com.ruoyi.staff.dto.PersonalAttendanceRecordsDto; import com.ruoyi.staff.dto.StaffOnJobDto; import com.ruoyi.staff.mapper.PersonalAttendanceLocationConfigMapper; import com.ruoyi.staff.mapper.PersonalShiftMapper; import com.ruoyi.staff.mapper.StaffOnJobMapper; import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig; import com.ruoyi.staff.pojo.PersonalAttendanceRecords; import com.ruoyi.staff.mapper.PersonalAttendanceRecordsMapper; import com.ruoyi.staff.pojo.PersonalShift; import com.ruoyi.staff.pojo.StaffOnJob; import com.ruoyi.staff.service.PersonalAttendanceRecordsService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -63,6 +66,9 @@ @Autowired private SysDeptMapper sysDeptMapper; @Autowired private PersonalShiftMapper personalShiftMapper; @Override public int add(PersonalAttendanceRecordsDto personalAttendanceRecordsDto) { // å½åæ¶é´ @@ -76,20 +82,24 @@ if (staffOnJob == null) { throw new BaseException("å½åç¨æ·æ²¡æå¯¹åºçå工信æ¯"); } /*夿æå¡ä½ç½®æ¯å¦å¨è§åèå´å */ List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(Wrappers.<PersonalAttendanceLocationConfig>lambdaQuery() .eq(PersonalAttendanceLocationConfig::getSysDeptId, staffOnJob.getSysDeptId()) .orderByDesc(PersonalAttendanceLocationConfig::getId)); if (personalAttendanceLocationConfigs == null || personalAttendanceLocationConfigs.isEmpty()) { throw new BaseException("å½åé¨é¨æ²¡æè®¾ç½®æå¡è§å"); //夿夿åå·¥å½å¤©æ¯å¦ææçæ°æ® List<PersonalShift> personalShifts = personalShiftMapper.selectList(Wrappers.<PersonalShift>lambdaQuery() .eq(PersonalShift::getStaffOnJobId, staffOnJob.getId()) .eq(PersonalShift::getWorkTime, currentDate.atStartOfDay()) .isNotNull(PersonalShift::getPersonalAttendanceLocationConfigId)); if (CollectionUtil.isEmpty(personalShifts)){ throw new BaseException("å½åç¨æ·å½å¤©æ²¡ææçæ°æ®"); } /*夿æå¡ä½ç½®æ¯å¦å¨è§åèå´å */ PersonalShift personalShift = personalShifts.get(0); PersonalAttendanceLocationConfig locationConfig = personalAttendanceLocationConfigMapper.selectById(personalShift.getPersonalAttendanceLocationConfigId()); Double punchLongitude = personalAttendanceRecordsDto.getLongitude(); //æå¡çç»åº¦ Double punchLatitude = personalAttendanceRecordsDto.getLatitude(); // æå¡ç纬度 if (punchLongitude == null || punchLatitude == null) { throw new BaseException("æå¡å¤±è´¥ï¼æªè·åå°æ¨çä½ç½®ä¿¡æ¯ï¼è¯·å¼å¯å®ä½æé"); } //è®¡ç®æå¡ä½ç½®ä¸èå¤ç¹çè·ç¦» PersonalAttendanceLocationConfig locationConfig = personalAttendanceLocationConfigs.get(0);//è·åææ°ç䏿¡æ°æ® double allowedRadius = locationConfig.getRadius(); // å 许çèå´ï¼ç±³ï¼ double actualDistance = LocationUtils.calculateDistance( punchLatitude, punchLongitude, // åå·¥æå¡çç»çº¬åº¦ @@ -231,12 +241,15 @@ SysDept dept = sysDeptMapper.selectDeptById(staffOnJob.getSysDeptId()); resultDto.setDeptName(dept != null ? dept.getDeptName() : null); //è·å该å工对åºçæå¡è§å List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(Wrappers.<PersonalAttendanceLocationConfig>lambdaQuery() .eq(PersonalAttendanceLocationConfig::getSysDeptId, staffOnJob.getSysDeptId()) .orderByDesc(PersonalAttendanceLocationConfig::getId)); if (personalAttendanceLocationConfigs.size()>0){ resultDto.setStartAt(personalAttendanceLocationConfigs.get(0).getStartAt()); resultDto.setEndAt(personalAttendanceLocationConfigs.get(0).getEndAt()); List<PersonalShift> personalShifts = personalShiftMapper.selectList(Wrappers.<PersonalShift>lambdaQuery() .eq(PersonalShift::getStaffOnJobId, staffOnJob.getId()) .eq(PersonalShift::getWorkTime, currentDate.atStartOfDay()) .isNotNull(PersonalShift::getPersonalAttendanceLocationConfigId)); if (CollectionUtil.isNotEmpty(personalShifts)){ PersonalAttendanceLocationConfig personalAttendanceLocationConfig = personalAttendanceLocationConfigMapper.selectById(personalShifts.get(0).getPersonalAttendanceLocationConfigId()); resultDto.setStartAt(personalAttendanceLocationConfig.getStartAt()); resultDto.setEndAt(personalAttendanceLocationConfig.getEndAt()); resultDto.setShift(personalAttendanceLocationConfig.getShift()); } return resultDto; } src/main/java/com/ruoyi/staff/service/impl/PersonalShiftServiceImpl.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,488 @@ package com.ruoyi.staff.service.impl; import cn.hutool.core.date.DateTime; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.project.system.domain.SysDictData; import com.ruoyi.staff.dto.PerformanceShiftAddDto; import com.ruoyi.staff.dto.PerformanceShiftMapDto; import com.ruoyi.staff.mapper.PersonalAttendanceLocationConfigMapper; import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig; import com.ruoyi.staff.pojo.PersonalShift; import com.ruoyi.staff.mapper.PersonalShiftMapper; import com.ruoyi.staff.service.PersonalAttendanceLocationConfigService; import com.ruoyi.staff.service.PersonalShiftService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.staff.utils.JackSonUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import cn.hutool.core.date.DateUtil; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.YearMonth; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.temporal.TemporalAdjusters; import java.util.*; /** * <p> * æå¡å®ç°ç±» * </p> * * @author è¯å¯¼è½¯ä»¶ï¼æ±èï¼æéå ¬å¸ * @since 2026-03-05 03:52:19 */ @Service @Transactional(rollbackFor = Exception.class) public class PersonalShiftServiceImpl extends ServiceImpl<PersonalShiftMapper, PersonalShift> implements PersonalShiftService { @Autowired private PersonalAttendanceLocationConfigMapper personalAttendanceLocationConfigMapper; @Override public int performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { List<PersonalShift> list = new ArrayList<>(); LocalDateTime startWeek = performanceShiftAddDto.getStartWeek();//å¼å§æ¥æ LocalDateTime endWeek = performanceShiftAddDto.getEndWeek();//ç»ææ¥æ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter); String[] splitUserId = performanceShiftAddDto.getStaffOnJobId().split(","); for (String userId : splitUserId) { //夿æ¯å¦è·¨æ boolean isMonth = startWeek.getMonthValue() != endWeek.getMonthValue(); if (isMonth){ //å¦æè·¨æ,å两个æé½å¤æä¸ä¸çæ°æ®åºæ¯åªä¸ªæä»½çæ°æ®æ²¡æ boolean exists1 = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery() .eq(PersonalShift::getWorkTime, startWeek) .eq(PersonalShift::getStaffOnJobId, userId)); boolean exists2 = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery() .eq(PersonalShift::getWorkTime, endWeek) .eq(PersonalShift::getStaffOnJobId, userId)); if (!exists1 && !exists2){ //两个æé½ä¸å卿°æ® list = saveMonth(performanceShiftAddDto.getStartWeek(), userId, list); list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list); }else if (!exists1 && exists2){ //å¼å§çæä»½ä¸å卿°æ® list = saveMonth(performanceShiftAddDto.getStartWeek(), userId, list); }else if (exists1 && !exists2){ //ç»æçæä»½ä¸å卿°æ® list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list); } }else { //ä¸è·¨æ boolean exists = baseMapper.exists(Wrappers.<PersonalShift>lambdaQuery() .in(PersonalShift::getWorkTime, formattedDateTime) .eq(PersonalShift::getStaffOnJobId, userId)); // 妿ä¸å卿·»å æ°æ® if (!exists) { list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list); } } } if (!list.isEmpty()) { saveBatch(list); list.clear(); } // 忬¡æ´æ° List<LocalDateTime> datesBetween = getLocalDateTimesBetween(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek()); for (LocalDateTime date : datesBetween) { for (String s : splitUserId) { PersonalShift personalShift = new PersonalShift(); personalShift.setPersonalAttendanceLocationConfigId(performanceShiftAddDto.getPersonalAttendanceLocationConfigId()); personalShift.setStaffOnJobId(Long.valueOf(s)); personalShift.setWorkTime(date); String formatterDateTime = date.format(formatter); baseMapper.update(new PersonalShift(), Wrappers.<PersonalShift>lambdaUpdate() .set(PersonalShift::getPersonalAttendanceLocationConfigId, performanceShiftAddDto.getPersonalAttendanceLocationConfigId()) .eq(PersonalShift::getStaffOnJobId, s) .eq(PersonalShift::getWorkTime, formatterDateTime)); } } return 0; } @Override public Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, Integer sysDeptId) { IPage<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftPage(page, time, userName, sysDeptId); //æ¥è¯¢ææç次(æå¡è§å) List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null); mapIPage.getRecords().forEach(i -> { String[] shiftTimes = i.getShiftTime().split(";"); double totalAttendance = 0;//æ»åºå¤å¤©æ° List<Map<String, Object>> map = new ArrayList<>(); // å岿¥æ for (String shiftTime : shiftTimes) { i.setShiftTime(null); Map<String, Object> hashMap = new HashMap<>(); String[] shiftTimeAndShift = shiftTime.split("ï¼"); //æçè¯¦ç»æ°æ® hashMap.put("id", shiftTimeAndShift[2]); hashMap.put("shift", shiftTimeAndShift[1]); hashMap.put("time", shiftTimeAndShift[0]); map.add(hashMap); i.setList(map); //æ±æ»çåçæ¬¡ç»è®¡æ°æ® for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { if (!i.getMonthlyAttendance().containsKey(personalAttendanceLocationConfig.getShift())){ i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), 0); } if (personalAttendanceLocationConfig.getShift().equals(shiftTimeAndShift[1])) { BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(personalAttendanceLocationConfig.getShift()).toString()); i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), bigDecimal.add(new BigDecimal("1"))); } } //ç»è®¡æ»åºå¤å¤©æ°(æ©/ä¸/æ/å¤)é½ç®åºå¤,å ¶ä½é½æ¯ä¼æ¯ if (shiftTimeAndShift[1].contains("æ©") || shiftTimeAndShift[1].contains("ä¸") || shiftTimeAndShift[1].contains("æ") || shiftTimeAndShift[1].contains("å¤")) { i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1); } } }); // è·åheaderæ¶é´ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // å°å符串æ¶é´è½¬æ¢ä¸º LocalDateTime ç±»åæ¶é´ LocalDateTime localDateTime = LocalDateTime.parse(time, formatters); LocalDate firstDayOfMonth = localDateTime.toLocalDate().withDayOfMonth(1); LocalDate lastDayOfMonth = localDateTime.toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); List<Object> list1 = new ArrayList<>(); for (LocalDateTime dateTime : localDateTimesBetween) { Map<Object, Object> hashMap = new HashMap<>(); DateTime parse = DateUtil.parse(dateTime.format(formatter)); hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))); hashMap.put("headerTime", getWeek(dateTime.format(formatters))); list1.add(hashMap); } Map<String, Object> resultMap = new HashMap<>(); resultMap.put("page", mapIPage); resultMap.put("headerList", list1); return resultMap; } @Override public void performanceShiftUpdate(PersonalShift personalShift) { baseMapper.update(new PersonalShift(), Wrappers.<PersonalShift>lambdaUpdate() .eq(PersonalShift::getId, personalShift.getId()) .set(PersonalShift::getPersonalAttendanceLocationConfigId, personalShift.getPersonalAttendanceLocationConfigId())); } @Override public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, Integer sysDeptId) { IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, sysDeptId); //æ¥è¯¢ææç次(æå¡è§å) List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null); mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), personalAttendanceLocationConfigs)); return mapYearIPage; } @Override public Map<Object, Object> exportToYearExcel(String time, String userName, Integer sysDeptId) throws Exception { Map<Object, Object> map = new HashMap<>(); //æ¥è¯¢ææç次(æå¡è§å) List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null); DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // å°å符串æ¶é´è½¬æ¢ä¸º LocalDateTime ç±»åæ¶é´ LocalDateTime localDateTime = LocalDateTime.parse(time, formatters); map.put("header", getYearHeader(localDateTime.getYear() + " å¹´", personalAttendanceLocationConfigs)); List<Map<String, Object>> mapYearList = baseMapper.performanceShiftYearList(time, userName, sysDeptId); annualAttendanceProcessing(mapYearList, personalAttendanceLocationConfigs); List<List<Object>> lists = dataRequiredForProcessingIntoExcel(mapYearList, personalAttendanceLocationConfigs); map.put("data", lists); return map; } @Override public Map<Object, Object> exportToMonthExcel(String time, String userName, Integer sysDeptId) { //æ¥è¯¢ææç次(æå¡è§å) List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null); List<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftList(time, userName, sysDeptId); mapIPage.forEach(i -> { String[] shiftTimes = i.getShiftTime().split(";"); double totalAttendance = 0; List<Map<String, Object>> map = new ArrayList<>(); // å岿¥æ for (String shiftTime : shiftTimes) { Map<String, Object> hashMap = new HashMap<>(); String[] shiftTimeAndShift = shiftTime.split("ï¼"); for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { if (!i.getMonthlyAttendance().containsKey(personalAttendanceLocationConfig.getShift())) { i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), 0); } if (personalAttendanceLocationConfig.getShift().equals(shiftTimeAndShift[1])) { BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(personalAttendanceLocationConfig.getShift()).toString()); i.getMonthlyAttendance().put(personalAttendanceLocationConfig.getShift(), bigDecimal.add(new BigDecimal("1"))); } } //ç»è®¡æ»åºå¤å¤©æ°(æ©/ä¸/æ/å¤)é½ç®åºå¤,å ¶ä½é½æ¯ä¼æ¯ if (shiftTimeAndShift[1].contains("æ©") || shiftTimeAndShift[1].contains("ä¸") || shiftTimeAndShift[1].contains("æ") || shiftTimeAndShift[1].contains("å¤")) { i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1); } hashMap.put("id", shiftTimeAndShift[2]); hashMap.put("shift", shiftTimeAndShift[1]); hashMap.put("time", shiftTimeAndShift[0]); map.add(hashMap); } i.setList(map); i.setShiftTime(null); }); Map<Object, Object> map = new HashMap<>(); DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // å°å符串æ¶é´è½¬æ¢ä¸º LocalDateTime ç±»åæ¶é´ LocalDateTime localDateTime = LocalDateTime.parse(time, formatters); map.put("header", getMonthHeader(localDateTime)); List<List<Object>> lists = dataRequiredForProcessingIntoExcelMonth(mapIPage, personalAttendanceLocationConfigs); map.put("data", lists); return map; } // å¹´å页ä¸å¯¼åºå ±åä½¿ç¨ public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList,List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) { for (Map<String, Object> map : mapYearList) { Map<String, Object> resultMap = new LinkedHashMap<>(); Map<String, Object> hashMapYear = new LinkedHashMap<>(); double totalYearAttendance = 0; // ä¸å¹´12个æ for (int i = 1; i < 13; i++) { Map<String, Object> hashMapMonth = new LinkedHashMap<>(); double totalMonthAttendance = 0; for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { // åå§åèµå¼ if (!hashMapYear.containsKey(personalAttendanceLocationConfig.getShift())){ hashMapYear.put(personalAttendanceLocationConfig.getShift(), 0); } // æ if (!ObjectUtils.isEmpty(map.get("month_str"))) { String charArray = map.get("month_str").toString(); int count = countOccurrences(charArray, i + "ï¼" + personalAttendanceLocationConfig.getShift()); hashMapMonth.put(personalAttendanceLocationConfig.getShift(), count); hashMapYear.put(personalAttendanceLocationConfig.getShift(), new BigDecimal(hashMapYear.get(personalAttendanceLocationConfig.getShift()).toString()).add(new BigDecimal(count))); // æ©ï¼ä¸ï¼å¤ï¼å·® if (personalAttendanceLocationConfig.getShift().contains("æ©") || personalAttendanceLocationConfig.getShift().contains("ä¸") || personalAttendanceLocationConfig.getShift().contains("æ") || personalAttendanceLocationConfig.getShift().contains("å¤")) { totalMonthAttendance += count; totalYearAttendance += count; } } // ç©ºæ°æ® else { map.put("work_time", i); hashMapMonth.put(personalAttendanceLocationConfig.getShift(), 0); } } hashMapMonth.put("totalMonthAttendance", totalMonthAttendance); hashMapYear.put("totalYearAttendance", totalYearAttendance); resultMap.put(i + "", hashMapMonth); } map.remove("month_str"); map.remove("year_str"); map.put("year", hashMapYear); map.put("month", resultMap); } return mapYearList; } public static int countOccurrences(String str, String target) { int count = 0; int index = 0; while ((index = str.indexOf(target, index)) != -1) { count++; index += target.length(); } return count; } public List<List<Object>> dataRequiredForProcessingIntoExcel(List<Map<String, Object>> list, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) throws Exception { List<List<Object>> data = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { List<Object> excelRowList = new ArrayList<>(); excelRowList.add(i + 1); excelRowList.add(list.get(i).get("account")); excelRowList.add(list.get(i).get("name")); Map<String, Object> year = JackSonUtil.unmarshal(JackSonUtil.marshal(list.get(i).get("year")), Map.class); excelRowList.add(year.get("totalYearAttendance")); personalAttendanceLocationConfigs.forEach(j -> { excelRowList.add(year.get(j.getShift())); }); Map<String, Map<String, Object>> month = JackSonUtil.unmarshal(JackSonUtil.marshal(list.get(i).get("month")), Map.class); for (int j = 1; j < 13; j++) { Object totalMonthAttendance = month.get(j + "").get("totalMonthAttendance"); excelRowList.add(totalMonthAttendance); for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { excelRowList.add(month.get(j + "").get(personalAttendanceLocationConfig.getShift())); } } data.add(excelRowList); } return data; } private List<PersonalShift> saveMonth (LocalDateTime week,String userId,List<PersonalShift> list){ LocalDate firstDayOfMonth = week.toLocalDate().withDayOfMonth(1); LocalDate lastDayOfMonth = week.toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); localDateTimesBetween.forEach(i -> { PersonalShift personalShift = new PersonalShift(); personalShift.setStaffOnJobId(Long.valueOf(userId)); personalShift.setWorkTime(i); list.add(personalShift); if (list.size() >= 1000) { saveBatch(list); list.clear(); } }); return list; } // è·å两个localDateTimeçæ¯ä¸å¤© public static List<LocalDateTime> getLocalDateTimesBetween(LocalDateTime start, LocalDateTime end) { List<LocalDateTime> localDateTimes = new ArrayList<>(); LocalDate currentDate = start.toLocalDate(); LocalDateTime currentLocalDateTime = start; while (!currentDate.isAfter(end.toLocalDate())) { localDateTimes.add(currentLocalDateTime); currentLocalDateTime = currentLocalDateTime.plusDays(1); currentDate = currentDate.plusDays(1); } return localDateTimes; } public static String getWeek(String dayStr) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = sdf.parse(dayStr); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); int day = calendar.get(Calendar.DAY_OF_MONTH); return day + " " + getWeekDay(dayOfWeek); } catch (Exception e) { e.printStackTrace(); } return null; } public static String getWeekDay(int dayOfWeek) { switch (dayOfWeek) { case Calendar.MONDAY: return "å¨ä¸"; case Calendar.TUESDAY: return "å¨äº"; case Calendar.WEDNESDAY: return "å¨ä¸"; case Calendar.THURSDAY: return "å¨å"; case Calendar.FRIDAY: return "å¨äº"; case Calendar.SATURDAY: return "å¨å "; case Calendar.SUNDAY: return "卿¥"; default: return "æªç¥"; } } /** * è¿å表头 * <p> * å¤å±List代表è¡å å± List代表å ç¸åçåæ°æ®ä¼è¢«ä¸»å¨åå¹¶ * æé åå表头 * * @return List<List < String>> */ private static List<List<String>> getYearHeader(String year, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) { List<List<String>> line = new ArrayList<>(); line.add(Arrays.asList("è夿±æ»", "åºå·", "åºå·")); line.add(Arrays.asList("è夿±æ»", "å·¥å·", "å·¥å·")); line.add(Arrays.asList("è夿±æ»", "å§å", "å§å")); line.add(Arrays.asList("åºå¤è¯¦æ ", year, "åºå¤")); // å¹´ header for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { line.add(Arrays.asList("è夿±æ»", year, personalAttendanceLocationConfig.getShift())); } // æheader for (int i = 1; i < 13; i++) { line.add(Arrays.asList("åºå¤è¯¦æ ", i + " æ", "åºå¤")); for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { line.add(Arrays.asList("åºå¤è¯¦æ ", i + " æ", personalAttendanceLocationConfig.getShift())); } } return line; } private static List<List<String>> getMonthHeader(LocalDateTime localDateTimeYear) { String year = localDateTimeYear.getYear() + " 年人åçæ¬¡"; List<List<String>> line = new ArrayList<>(); line.add(Arrays.asList(year, "åºå·", "åºå·", "åºå·")); line.add(Arrays.asList(year, "å§å", "å§å", "å§å")); line.add(Arrays.asList(year, "é¨é¨", "é¨é¨", "é¨é¨")); line.add(Arrays.asList(year, localDateTimeYear.getYear() + "", localDateTimeYear.getYear() + "", "åºå¤")); line.add(Arrays.asList(year, localDateTimeYear.getYear() + "", localDateTimeYear.getYear() + "","ä¼")); line.add(Arrays.asList(year, "å¹´", "å¹´", "请å")); line.add(Arrays.asList(year, localDateTimeYear.getMonthValue() + "", localDateTimeYear.getMonthValue() + "", "æ©")); line.add(Arrays.asList(year, "æ", "æ", "ä¸")); line.add(Arrays.asList(year, "", "", "å¤")); line.add(Arrays.asList(year, "卿¬¡", "ææ", "åºå·®")); LocalDate firstDayOfMonth = localDateTimeYear.toLocalDate().withDayOfMonth(1); LocalDate lastDayOfMonth = localDateTimeYear.toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); List<LocalDateTime> timeList = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); timeList.forEach(i -> { int dayOfYear = i.getDayOfMonth(); Date from = Date.from(i.atZone(ZoneId.systemDefault()).toInstant()); String weekDay = getWeekDay(i.getDayOfWeek().getValue()); line.add(Arrays.asList(year, DateUtil.weekOfYear(DateUtil.offsetDay(from, 1)) + "", weekDay, dayOfYear + "")); }); return line; } public List<List<Object>> dataRequiredForProcessingIntoExcelMonth(List<PerformanceShiftMapDto> list, List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs) { List<List<Object>> data = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { List<Object> excelRowList = new ArrayList<>(); excelRowList.add(i + 1); excelRowList.add(list.get(i).getName()); excelRowList.add(list.get(i).getDepartment()); excelRowList.add(list.get(i).getMonthlyAttendance().get("totalAttendance")); excelRowList.add(list.get(i).getMonthlyAttendance().get("%ä¼%")); // ä¼ excelRowList.add(list.get(i).getMonthlyAttendance().get("%å%")); // å excelRowList.add(list.get(i).getMonthlyAttendance().get("%æ©%")); // æ© excelRowList.add(list.get(i).getMonthlyAttendance().get("%ä¸%")); // ä¸ excelRowList.add(list.get(i).getMonthlyAttendance().get("%å¤%")); // å¤ excelRowList.add(list.get(i).getMonthlyAttendance().get("%å·®%")); // å·® for (Map<String, Object> o : list.get(i).getList()) { String enumLabel = ""; for (PersonalAttendanceLocationConfig personalAttendanceLocationConfig : personalAttendanceLocationConfigs) { if (personalAttendanceLocationConfig.getShift().equals(o.get("shift"))) { enumLabel = personalAttendanceLocationConfig.getShift(); } } excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel); } data.add(excelRowList); } return data; } } src/main/java/com/ruoyi/staff/task/PersonalAttendanceRecordsTask.java
@@ -1,9 +1,17 @@ package com.ruoyi.staff.task; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.staff.dto.PerformanceShiftAddDto; import com.ruoyi.staff.mapper.PersonalAttendanceLocationConfigMapper; import com.ruoyi.staff.mapper.PersonalShiftMapper; import com.ruoyi.staff.mapper.StaffOnJobMapper; import com.ruoyi.staff.pojo.PersonalAttendanceLocationConfig; import com.ruoyi.staff.pojo.PersonalAttendanceRecords; import com.ruoyi.staff.pojo.StaffOnJob; import com.ruoyi.staff.service.PersonalAttendanceRecordsService; import com.ruoyi.staff.mapper.PersonalAttendanceRecordsMapper; import com.ruoyi.staff.service.PersonalShiftService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -12,7 +20,14 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; import java.time.temporal.TemporalAdjusters; import java.time.temporal.WeekFields; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; /** * 个人èå¤è®°å½å®æ¶ä»»å¡ @@ -29,6 +44,15 @@ @Autowired private PersonalAttendanceRecordsService personalAttendanceRecordsService; @Autowired private PersonalAttendanceLocationConfigMapper personalAttendanceLocationConfigMapper; @Autowired private StaffOnJobMapper staffOnJobMapper; @Autowired private PersonalShiftService personalShiftService; /** * æ¯å¤©åæ¨çææ¨æ¥ç缺å¤è®°å½ @@ -73,4 +97,50 @@ log.error("çææ¨æ¥ç¼ºå¤è®°å½ä»»å¡æ§è¡å¤±è´¥ï¼{}", e.getMessage(), e); } } } /** * 宿¶ä»»å¡,æ¯ä¸ªæ1å·ç00:00:00ç»ä¸ä¸ä¸ªææç * ç»æ¯ä¸ªäººé½è¿è¡æç(é»è®¤æ©ç) */ @Scheduled(cron = "0 10 0 1 * ?") private void timerCreateSchedule() { log.info("å¼å§ç»æ¯ä¸ªäººè¿è¡æç,é»è®¤æ©ç======start"); PerformanceShiftAddDto performanceShiftAddDto = new PerformanceShiftAddDto(); //æ¥è¯¢ææç次(æå¡è§å) List<PersonalAttendanceLocationConfig> personalAttendanceLocationConfigs = personalAttendanceLocationConfigMapper.selectList(null); if (CollectionUtil.isEmpty(personalAttendanceLocationConfigs)){ return; } performanceShiftAddDto.setPersonalAttendanceLocationConfigId(personalAttendanceLocationConfigs.get(0).getId()); //å¨è人å List<StaffOnJob> staffOnJobs = staffOnJobMapper.selectList(Wrappers.<StaffOnJob>lambdaQuery().eq(StaffOnJob::getStaffState, 1)); if (CollectionUtil.isEmpty(staffOnJobs)){ return; } String userIds = staffOnJobs.stream().map(user -> user.getId().toString()).distinct().collect(Collectors.joining(",")); performanceShiftAddDto.setStaffOnJobId(userIds); //卿¬¡--å½æææ // è·åå½åæ¥æ LocalDate today = LocalDate.now(ZoneId.of(ZoneId.SHORT_IDS.get("CTT"))).plusMonths(1); // è·åæ¬æç第ä¸å¤©åæåä¸å¤© LocalDate firstDayOfMonth = today.with(TemporalAdjusters.firstDayOfMonth()); LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth()); // è·åå¨å段信æ¯ï¼æ ¹æ®åºåè®¾ç½®ï¼ WeekFields weekFields = WeekFields.of(Locale.getDefault()); // è·åæ¬æç¬¬ä¸å¤©çå¨ä¸ LocalDate startOfWeek = firstDayOfMonth.with(TemporalAdjusters.previousOrSame(weekFields.getFirstDayOfWeek())); // éåæ¬æææå¤©æ°ï¼æ¾åºæ¯å¨ç第ä¸å¤©åæåä¸å¤© LocalDate endOfWeek; while (startOfWeek.isBefore(firstDayOfMonth.plusMonths(1))) { endOfWeek = startOfWeek.plusDays(6); LocalDateTime startDateTime = LocalDateTime.of(startOfWeek, LocalTime.MIDNIGHT); LocalDateTime endDateTime = LocalDateTime.of(endOfWeek, LocalTime.MIDNIGHT); log.info("Week starts on {} and ends on {}", startDateTime, endDateTime); performanceShiftAddDto.setStartWeek(startDateTime); performanceShiftAddDto.setEndWeek(endDateTime); personalShiftService.performanceShiftAdd(performanceShiftAddDto); startOfWeek = startOfWeek.plusWeeks(1); } log.info("æçç»æ======end"); } } src/main/java/com/ruoyi/staff/utils/JackSonUtil.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,133 @@ package com.ruoyi.staff.utils; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.stereotype.Component; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * JSONè§£æå¤ç * * @author zss */ @Component public class JackSonUtil { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); private static final ObjectWriter OBJECT_WRITER = OBJECT_MAPPER.writerWithDefaultPrettyPrinter(); public static void marshal(File file, Object value) throws Exception { try { OBJECT_WRITER.writeValue(file, value); } catch (JsonGenerationException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } public static void marshal(OutputStream os, Object value) throws Exception { try { OBJECT_WRITER.writeValue(os, value); } catch (JsonGenerationException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } public static String marshal(Object value) throws Exception { try { return OBJECT_WRITER.writeValueAsString(value); } catch (JsonGenerationException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } public static byte[] marshalBytes(Object value) throws Exception { try { return OBJECT_WRITER.writeValueAsBytes(value); } catch (JsonGenerationException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } public static <T> T unmarshal(File file, Class<T> valueType) throws Exception { try { return OBJECT_MAPPER.readValue(file, valueType); } catch (JsonParseException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } public static <T> T unmarshal(InputStream is, Class<T> valueType) throws Exception { try { return OBJECT_MAPPER.readValue(is, valueType); } catch (JsonParseException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } /** * å符串转对象 * @param str * @param valueType * @return * @param <T> * @throws Exception */ public static <T> T unmarshal(String str, Class<T> valueType) throws Exception { try { OBJECT_MAPPER.registerModule(new JavaTimeModule()); return OBJECT_MAPPER.readValue(str, valueType); } catch (JsonParseException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } public static <T> T unmarshal(byte[] bytes, Class<T> valueType) throws Exception { try { if (bytes == null) { bytes = new byte[0]; } return OBJECT_MAPPER.readValue(bytes, 0, bytes.length, valueType); } catch (JsonParseException e) { throw new Exception(e); } catch (JsonMappingException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } } } src/main/java/com/ruoyi/staff/utils/StyleMonthUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,86 @@ package com.ruoyi.staff.utils; import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteFont; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; public class StyleMonthUtils { /** * æ 颿 ·å¼ * @return */ public static WriteCellStyle getHeadStyle(){ // 头ççç¥ WriteCellStyle headWriteCellStyle = new WriteCellStyle(); // èæ¯é¢è² // headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex()); // headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); // åä½ WriteFont headWriteFont = new WriteFont(); headWriteFont.setFontName("ç线");//设置åä½åå headWriteFont.setFontHeightInPoints((short)9);//设置åä½å¤§å° headWriteFont.setBold(true);//åä½å ç² headWriteFont.setColor((short) 0); headWriteCellStyle.setWriteFont(headWriteFont); //卿 ·å¼ç¨åºç¨è®¾ç½®çåä½; // æ ·å¼ headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置åºè¾¹æ¡; headWriteCellStyle.setBottomBorderColor((short) 0);//设置åºè¾¹æ¡é¢è²; headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边æ¡; headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边æ¡é¢è²; headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置å³è¾¹æ¡; headWriteCellStyle.setRightBorderColor((short) 0);//设置å³è¾¹æ¡é¢è²; headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边æ¡; headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边æ¡é¢è²; headWriteCellStyle.setWrapped(false); //设置èªå¨æ¢è¡; headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对é½çæ ·å¼ä¸ºå± ä¸å¯¹é½; headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置åç´å¯¹é½çæ ·å¼ä¸ºå± ä¸å¯¹é½; headWriteCellStyle.setShrinkToFit(true);//è®¾ç½®ææ¬æ¶ç¼©è³åé return headWriteCellStyle; } /** * å å®¹æ ·å¼ * @return */ public static WriteCellStyle getContentStyle(){ // å 容ççç¥ WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); // è¿ééè¦æå® FillPatternType 为FillPatternType.SOLID_FOREGROUND ä¸ç¶æ æ³æ¾ç¤ºèæ¯é¢è².头é»è®¤äº FillPatternTypeæä»¥å¯ä»¥ä¸æå® // contentWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex()); contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); // 设置åä½ WriteFont contentWriteFont = new WriteFont(); contentWriteFont.setFontHeightInPoints((short) 10);//设置åä½å¤§å° contentWriteFont.setFontName("ç线"); //设置åä½åå contentWriteCellStyle.setWriteFont(contentWriteFont);//卿 ·å¼ç¨åºç¨è®¾ç½®çåä½; //è®¾ç½®æ ·å¼; contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置åºè¾¹æ¡; contentWriteCellStyle.setBottomBorderColor((short) 0);//设置åºè¾¹æ¡é¢è²; contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边æ¡; contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边æ¡é¢è²; contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置å³è¾¹æ¡; contentWriteCellStyle.setRightBorderColor((short) 0);//设置å³è¾¹æ¡é¢è²; contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边æ¡; contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边æ¡é¢è²; contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// æ°´å¹³å± ä¸ contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// åç´å± ä¸ contentWriteCellStyle.setWrapped(false); //设置èªå¨æ¢è¡; // contentWriteCellStyle.setShrinkToFit(true);//è®¾ç½®ææ¬æ¶ç¼©è³åé return contentWriteCellStyle; } } src/main/java/com/ruoyi/staff/utils/StyleYearUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,89 @@ package com.ruoyi.staff.utils; import com.alibaba.excel.write.metadata.style.WriteCellStyle; import com.alibaba.excel.write.metadata.style.WriteFont; import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.VerticalAlignment; public class StyleYearUtils { /** * æ 颿 ·å¼ * * @return */ public static WriteCellStyle getHeadStyle() { // 头ççç¥ WriteCellStyle headWriteCellStyle = new WriteCellStyle(); // èæ¯é¢è² // headWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex()); headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); // åä½ WriteFont headWriteFont = new WriteFont(); headWriteFont.setFontName("仿å®");//设置åä½åå headWriteFont.setFontHeightInPoints((short) 9);//设置åä½å¤§å° headWriteFont.setBold(true);//åä½å ç² headWriteFont.setColor((short) 1); headWriteCellStyle.setWriteFont(headWriteFont); //卿 ·å¼ç¨åºç¨è®¾ç½®çåä½; // æ ·å¼ headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置åºè¾¹æ¡; headWriteCellStyle.setBottomBorderColor((short) 1);//设置åºè¾¹æ¡é¢è²; headWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边æ¡; headWriteCellStyle.setLeftBorderColor((short) 1);//设置左边æ¡é¢è²; headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置å³è¾¹æ¡; headWriteCellStyle.setRightBorderColor((short) 1);//设置å³è¾¹æ¡é¢è²; headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边æ¡; headWriteCellStyle.setTopBorderColor((short) 1); //设置顶边æ¡é¢è²; headWriteCellStyle.setWrapped(false); //设置èªå¨æ¢è¡; headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对é½çæ ·å¼ä¸ºå± ä¸å¯¹é½; headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置åç´å¯¹é½çæ ·å¼ä¸ºå± ä¸å¯¹é½; headWriteCellStyle.setShrinkToFit(true);//è®¾ç½®ææ¬æ¶ç¼©è³åé return headWriteCellStyle; } /** * å å®¹æ ·å¼ * * @return */ public static WriteCellStyle getContentStyle() { // å 容ççç¥ WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); // è¿ééè¦æå® FillPatternType 为FillPatternType.SOLID_FOREGROUND ä¸ç¶æ æ³æ¾ç¤ºèæ¯é¢è².头é»è®¤äº FillPatternTypeæä»¥å¯ä»¥ä¸æå® // contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND); // 设置åä½ WriteFont contentWriteFont = new WriteFont(); contentWriteFont.setFontHeightInPoints((short) 9);//设置åä½å¤§å° contentWriteFont.setFontName("仿å®"); //设置åä½åå contentWriteCellStyle.setWriteFont(contentWriteFont);//卿 ·å¼ç¨åºç¨è®¾ç½®çåä½; //è®¾ç½®æ ·å¼; contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置åºè¾¹æ¡; contentWriteCellStyle.setBottomBorderColor((short) 0);//设置åºè¾¹æ¡é¢è²; contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //设置左边æ¡; contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边æ¡é¢è²; contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置å³è¾¹æ¡; contentWriteCellStyle.setRightBorderColor((short) 0);//设置å³è¾¹æ¡é¢è²; contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边æ¡; contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边æ¡é¢è²; contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// æ°´å¹³å± ä¸ contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// åç´å± ä¸ contentWriteCellStyle.setWrapped(false); //设置èªå¨æ¢è¡; // contentWriteCellStyle.setShrinkToFit(true);//è®¾ç½®ææ¬æ¶ç¼©è³åé return contentWriteCellStyle; } } src/main/resources/mapper/staff/PersonalShiftMapper.xml
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,106 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ruoyi.staff.mapper.PersonalShiftMapper"> <!-- éç¨æ¥è¯¢æ å°ç»æ --> <resultMap id="BaseResultMap" type="com.ruoyi.staff.pojo.PersonalShift"> <id column="id" property="id" /> <result column="personal_attendance_location_config_id" property="personalAttendanceLocationConfigId" /> <result column="staff_on_job_id" property="staffOnJobId" /> <result column="create_time" property="createTime" /> <result column="update_time" property="updateTime" /> <result column="work_time" property="workTime" /> </resultMap> <select id="performanceShiftPage" resultType="com.ruoyi.staff.dto.PerformanceShiftMapDto"> SELECT u.staff_name name, GROUP_CONCAT(s.work_time, 'ï¼', IFNULL(palc.shift, ''), 'ï¼', s.id order by s.work_time SEPARATOR ';') AS shift_time, u.id user_id FROM personal_shift s LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id <where> <if test="sysDeptId != null and sysDeptId != ''"> and u.sys_dept_id = #{sysDeptId} </if> <if test="time != null and time != ''"> and DATE_FORMAT(s.work_time, '%Y-%m') = DATE_FORMAT(#{time}, '%Y-%m' ) </if> <if test="userName != null and userName != ''"> and u.staff_name like concat('%', #{userName}, '%') </if> </where> GROUP BY u.id order by s.create_time </select> <select id="performanceShiftYear" resultType="java.util.Map"> SELECT u.staff_name name, u.id user_id, u.staff_no account, DATE_FORMAT(s.work_time, '%c') work_time, GROUP_CONCAT(DATE_FORMAT(s.work_time, '%c'), 'ï¼', IFNULL(palc.shift, '') order by s.work_time SEPARATOR ';') month_str FROM personal_shift s LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id <where> <if test="time != null and time != ''"> and DATE_FORMAT(s.work_time, '%Y') = DATE_FORMAT(#{time}, '%Y' ) </if> <if test="userName != null and userName != ''"> and u.staff_name like concat('%', #{userName}, '%') </if> <if test="sysDeptId != null and sysDeptId != ''"> and u.sys_dept_id = #{sysDeptId} </if> </where> GROUP BY u.id order by s.create_time </select> <select id="performanceShiftYearList" resultType="java.util.Map"> SELECT u.staff_name name, s.staff_on_job_id user_id, u.staff_no account, DATE_FORMAT(s.work_time, '%c') work_time, GROUP_CONCAT(DATE_FORMAT(s.work_time, '%c'), 'ï¼', IFNULL(palc.shift, '') order by s.work_time SEPARATOR ';') month_str FROM personal_shift s LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id <where> <if test="time != null and time != ''"> and DATE_FORMAT(s.work_time, '%Y') = DATE_FORMAT(#{time}, '%Y' ) </if> <if test="userName != null and userName != ''"> and u.staff_name like concat('%', #{userName}, '%') </if> <if test="sysDeptId != null and sysDeptId != ''"> and u.sys_dept_id = #{sysDeptId} </if> </where> GROUP BY u.id order by s.create_time </select> <select id="performanceShiftList" resultType="com.ruoyi.staff.dto.PerformanceShiftMapDto"> SELECT u.staff_name name, GROUP_CONCAT(s.work_time, 'ï¼', IFNULL(palc.shift, ''), 'ï¼', s.id order by s.work_time SEPARATOR ';') AS shift_time, u.id user_id FROM personal_shift s LEFT JOIN staff_on_job u ON u.id = s.staff_on_job_id LEFT JOIN personal_attendance_location_config palc ON palc.id = s.personal_attendance_location_config_id <where> <if test="time != null and time != ''"> and DATE_FORMAT(s.work_time, '%Y-%m') = DATE_FORMAT(#{time}, '%Y-%m' ) </if> <if test="userName != null and userName != ''"> and u.staff_name like concat('%', #{userName}, '%') </if> <if test="sysDeptId != null and sysDeptId != ''"> and u.sys_dept_id = #{sysDeptId} </if> </where> GROUP BY u.id order by s.create_time </select> </mapper>