From 443a9510ba9c032d83139048f73201706a1d9c45 Mon Sep 17 00:00:00 2001 From: value <z1292839451@163.com> Date: 星期五, 10 五月 2024 22:19:33 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java | 5 inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsUnPassServiceImpl.java | 2 performance-server/src/main/java/com/yuanchu/mom/mapper/PerformanceShiftMapper.java | 4 performance-server/src/main/java/com/yuanchu/mom/controller/AuxiliaryWorkingHoursController.java | 64 ++++++ performance-server/src/main/java/com/yuanchu/mom/mapper/AuxiliaryWorkingHoursMapper.java | 19 + performance-server/src/main/java/com/yuanchu/mom/service/impl/AuxiliaryWorkingHoursServiceImpl.java | 51 +++++ performance-server/src/main/java/com/yuanchu/mom/pojo/AuxiliaryWorkingHours.java | 73 +++++++ performance-server/src/main/java/com/yuanchu/mom/utils/StyleUtils.java | 83 ++++++++ pom.xml | 8 performance-server/src/main/resources/mapper/AuxiliaryWorkingHoursMapper.xml | 38 +++ performance-server/src/main/java/com/yuanchu/mom/service/AuxiliaryWorkingHoursService.java | 22 ++ performance-server/src/main/resources/mapper/PerformanceShiftMapper.xml | 42 ++++ performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java | 139 ++++++++++++- inspect-server/src/main/resources/mapper/InsUnPassMapper.xml | 8 performance-server/src/main/java/com/yuanchu/mom/service/PerformanceShiftService.java | 5 performance-server/src/main/java/com/yuanchu/mom/controller/PerformanceShiftController.java | 36 +++ 16 files changed, 576 insertions(+), 23 deletions(-) diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsUnPassServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsUnPassServiceImpl.java index 4350315..19bf21e 100644 --- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsUnPassServiceImpl.java +++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsUnPassServiceImpl.java @@ -30,8 +30,6 @@ public Map<String, Object> pageInsUnPass(Page page, UnPassPageDto unPassPageDto) { Map<String, Object> map = new HashMap<>(); map.put("head", PrintChina.printChina(UnPassPageDto.class)); - Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("pageInsUnPass"); - if (map1.get("look") == 1) unPassPageDto.setCreateUser(map1.get("userId")); map.put("body", insUnPassMapper.pageInsUnPass(page, QueryWrappers.queryWrappers(unPassPageDto))); return map; } diff --git a/inspect-server/src/main/resources/mapper/InsUnPassMapper.xml b/inspect-server/src/main/resources/mapper/InsUnPassMapper.xml index 79658de..88c5d45 100644 --- a/inspect-server/src/main/resources/mapper/InsUnPassMapper.xml +++ b/inspect-server/src/main/resources/mapper/InsUnPassMapper.xml @@ -19,14 +19,6 @@ <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/> </resultMap> <select id="pageInsUnPass" resultType="com.yuanchu.mom.dto.UnPassPageDto"> --- select * --- from ( --- select --- iu.*,io.entrust_code,u.name write_user_name --- from ins_un_pass iu --- left join ins_order io on io.id = iu.ins_order_id --- left join user u on u.id = iu.create_user --- ) a select * from ins_un_pass iu </select> diff --git a/performance-server/src/main/java/com/yuanchu/mom/controller/AuxiliaryWorkingHoursController.java b/performance-server/src/main/java/com/yuanchu/mom/controller/AuxiliaryWorkingHoursController.java new file mode 100644 index 0000000..cb0f98f --- /dev/null +++ b/performance-server/src/main/java/com/yuanchu/mom/controller/AuxiliaryWorkingHoursController.java @@ -0,0 +1,64 @@ +package com.yuanchu.mom.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yuanchu.mom.annotation.ValueClassify; +import com.yuanchu.mom.pojo.AuxiliaryWorkingHours; +import com.yuanchu.mom.service.AuxiliaryWorkingHoursService; +import com.yuanchu.mom.utils.JackSonUtil; +import com.yuanchu.mom.vo.Result; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.apache.ibatis.annotations.Param; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * <p> + * 杈呭姪宸ユ椂 鍓嶇鎺у埗鍣� + * </p> + * + * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 + * @since 2024-05-09 06:58:31 + */ +@Api(tags = "缁╂晥绠$悊-杈呭姪宸ユ椂璁剧疆") +@AllArgsConstructor +@RestController +@RequestMapping("/auxiliaryWorkingHours") +public class AuxiliaryWorkingHoursController { + @Resource + private AuxiliaryWorkingHoursService auxiliaryWorkingHoursService; + + @ApiOperation(value="鏌ヨ杈呭姪宸ユ椂") + @PostMapping("/selectAuxiliaryWorkingHours") + public Result selectAuxiliaryWorkingHours(@RequestBody Map<String, Object> data) throws Exception { + Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class); + AuxiliaryWorkingHours entity = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), AuxiliaryWorkingHours.class); + return Result.success(auxiliaryWorkingHoursService.selectAuxiliaryWorkingHours(page,entity)); + } + @ValueClassify("宸ユ椂绠$悊") + @ApiOperation(value="鍒犻櫎杈呭姪宸ユ椂") + @PostMapping("/deleteAuxiliaryWorkingHours") + public Result deleteAuxiliaryWorkingHours(Integer id){ + return Result.success(auxiliaryWorkingHoursService.deleteAuxiliaryWorkingHours(id)); + } + @ValueClassify("宸ユ椂绠$悊") + @ApiOperation(value="淇敼杈呭姪宸ユ椂") + @PostMapping("/upAuxiliaryWorkingHours") + public Result upAuxiliaryWorkingHours(@RequestBody AuxiliaryWorkingHours auxiliaryWorkingHours){ + return Result.success(auxiliaryWorkingHoursService.upAuxiliaryWorkingHours(auxiliaryWorkingHours)); + } + @ValueClassify("宸ユ椂绠$悊") + @ApiOperation(value="鏂板杈呭姪宸ユ椂") + @PostMapping("/insertAuxiliaryWorkingHours") + public Result insertAuxiliaryWorkingHours(@RequestBody AuxiliaryWorkingHours auxiliaryWorkingHours){ + return Result.success(auxiliaryWorkingHoursService.insertAuxiliaryWorkingHours(auxiliaryWorkingHours)); + } + + +} diff --git a/performance-server/src/main/java/com/yuanchu/mom/controller/PerformanceShiftController.java b/performance-server/src/main/java/com/yuanchu/mom/controller/PerformanceShiftController.java index 65b368a..45a48c6 100644 --- a/performance-server/src/main/java/com/yuanchu/mom/controller/PerformanceShiftController.java +++ b/performance-server/src/main/java/com/yuanchu/mom/controller/PerformanceShiftController.java @@ -1,14 +1,24 @@ package com.yuanchu.mom.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.yuanchu.mom.dto.PerformanceShiftAddDto; import com.yuanchu.mom.pojo.PerformanceShift; import com.yuanchu.mom.service.PerformanceShiftService; +import com.yuanchu.mom.utils.StyleUtils; import com.yuanchu.mom.vo.Result; 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; /** @@ -34,10 +44,16 @@ return Result.success(); } - @ApiOperation(value = "缁╂晥绠$悊-鐝-鍒嗛〉鏌ヨ") + @ApiOperation(value = "缁╂晥绠$悊-鐝-鏈堜唤鍒嗛〉鏌ヨ") @PostMapping("page") public Result<?> performanceShiftPage(Integer size, Integer current, String time, String userName, String laboratory) { return Result.success(performanceShiftService.performanceShiftPage(new Page<>(current, size), time, userName, laboratory)); + } + + @ApiOperation(value = "缁╂晥绠$悊-鐝-骞翠唤鍒嗛〉鏌ヨ") + @PostMapping("pageYear") + public Result<?> performanceShiftPageYear(Integer size, Integer current, String time, String userName, String laboratory) { + return Result.success(performanceShiftService.performanceShiftPageYear(new Page<>(current, size), time, userName, laboratory)); } @ApiOperation(value = "缁╂晥绠$悊-鐝-鐝鐘舵�佷慨鏀�") @@ -46,4 +62,22 @@ performanceShiftService.performanceShiftUpdate(performanceShift); return Result.success(); } + + @ApiOperation(value = "缁╂晥绠$悊-鐝-瀵煎嚭") + @GetMapping("update") + public void exportToExcel(@NotNull(message = "鏃堕棿涓嶈兘涓虹┖锛�") String time, String userName, String laboratory, HttpServletResponse response) throws Exception { + Map<Object, Object> data = performanceShiftService.exportToExcel(time, userName, laboratory); + // 璁剧疆鍗曞厓鏍兼牱寮� + HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(StyleUtils.getHeadStyle(), StyleUtils.getContentStyle()); + // 淇濆瓨鍒扮涓�涓猻heet涓� + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setHeader("requestType","excel"); + response.setHeader("Access-Control-Expose-Headers", "requestType"); + EasyExcel.write(response.getOutputStream()) + .head((List<List<String>>) data.get("header")) + .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 鑷�傚簲鍒楀 + .registerWriteHandler(horizontalCellStyleStrategy) + .sheet("妯℃澘") + .doWrite((Collection<?>) data.get("data")); + } } diff --git a/performance-server/src/main/java/com/yuanchu/mom/mapper/AuxiliaryWorkingHoursMapper.java b/performance-server/src/main/java/com/yuanchu/mom/mapper/AuxiliaryWorkingHoursMapper.java new file mode 100644 index 0000000..cfc2223 --- /dev/null +++ b/performance-server/src/main/java/com/yuanchu/mom/mapper/AuxiliaryWorkingHoursMapper.java @@ -0,0 +1,19 @@ +package com.yuanchu.mom.mapper; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yuanchu.mom.pojo.AuxiliaryWorkingHours; + +/** + * <p> + * 杈呭姪宸ユ椂 Mapper 鎺ュ彛 + * </p> + * + * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 + * @since 2024-05-09 06:58:31 + */ +public interface AuxiliaryWorkingHoursMapper extends BaseMapper<AuxiliaryWorkingHours> { + IPage<AuxiliaryWorkingHours> selectAuxiliaryWorkingHours(Page page, QueryWrapper<AuxiliaryWorkingHours> ew); +} diff --git a/performance-server/src/main/java/com/yuanchu/mom/mapper/PerformanceShiftMapper.java b/performance-server/src/main/java/com/yuanchu/mom/mapper/PerformanceShiftMapper.java index f9ef663..2623b39 100644 --- a/performance-server/src/main/java/com/yuanchu/mom/mapper/PerformanceShiftMapper.java +++ b/performance-server/src/main/java/com/yuanchu/mom/mapper/PerformanceShiftMapper.java @@ -30,4 +30,8 @@ List<Map<String, Object>> performanceShiftYearPage(@Param("time") String time, @Param("userName") String userName, @Param("laboratory") String laboratory); + + IPage<Map<String, Object>> performanceShiftYear(Page<Object> page, String time, String userName, String laboratory); + + List<Map<String, Object>> performanceShiftYearList(String time, String userName, String laboratory); } diff --git a/performance-server/src/main/java/com/yuanchu/mom/pojo/AuxiliaryWorkingHours.java b/performance-server/src/main/java/com/yuanchu/mom/pojo/AuxiliaryWorkingHours.java new file mode 100644 index 0000000..570c382 --- /dev/null +++ b/performance-server/src/main/java/com/yuanchu/mom/pojo/AuxiliaryWorkingHours.java @@ -0,0 +1,73 @@ +package com.yuanchu.mom.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.yuanchu.mom.annotation.ValueTableShow; +import com.yuanchu.mom.common.OrderBy; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import jdk.nashorn.internal.ir.annotations.Ignore; +import lombok.Getter; +import lombok.Setter; + +/** + * <p> + * 杈呭姪宸ユ椂 + * </p> + * + * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 + * @since 2024-05-09 06:58:31 + */ +@Getter +@Setter +@TableName("auxiliary_working_hours") +@ApiModel(value = "AuxiliaryWorkingHours瀵硅薄", description = "杈呭姪宸ユ椂") +public class AuxiliaryWorkingHours extends OrderBy implements Serializable { + @ApiModelProperty("涓婚敭ID") + @TableId(type = IdType.AUTO) + private Integer id; + @ValueTableShow(2) + @ApiModelProperty("缂栧彿") + private String number; + @ValueTableShow(3) + @ApiModelProperty("杈呭姪椤圭洰鍚嶇О") + private String auxiliaryProject; + @ValueTableShow(5) + @ApiModelProperty("鏍稿噯宸ユ椂") + private Float approvedWorkingHour; + @ValueTableShow(7) + @ApiModelProperty("澶囨敞") + private String remarks; + + @ApiModelProperty("鍒涘缓浜篿d") + @TableField(fill = FieldFill.INSERT) + private Integer createUser; + + @ApiModelProperty("淇敼浜篿d") + @TableField(fill = FieldFill.INSERT_UPDATE) + private Integer updateUser; + + @ApiModelProperty("鍒涘缓鏃堕棿") + @TableField(fill = FieldFill.INSERT) + private LocalDateTime createTime; + + @ApiModelProperty("淇敼鏃堕棿") + @TableField(fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + @ValueTableShow(6) + @ApiModelProperty("閮ㄩ棬") + private String department; + @ValueTableShow(3) + @ApiModelProperty("瀹為獙瀹�") + private String laboratory; + @ValueTableShow(4) + @ApiModelProperty("鍗曚綅") + private String unit; +} diff --git a/performance-server/src/main/java/com/yuanchu/mom/service/AuxiliaryWorkingHoursService.java b/performance-server/src/main/java/com/yuanchu/mom/service/AuxiliaryWorkingHoursService.java new file mode 100644 index 0000000..6b0d199 --- /dev/null +++ b/performance-server/src/main/java/com/yuanchu/mom/service/AuxiliaryWorkingHoursService.java @@ -0,0 +1,22 @@ +package com.yuanchu.mom.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yuanchu.mom.pojo.AuxiliaryWorkingHours; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.Map; + +/** + * <p> + * 杈呭姪宸ユ椂 鏈嶅姟绫� + * </p> + * + * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 + * @since 2024-05-09 06:58:31 + */ +public interface AuxiliaryWorkingHoursService extends IService<AuxiliaryWorkingHours> { + Map<String, Object> selectAuxiliaryWorkingHours(Page page, AuxiliaryWorkingHours auxiliaryWorkingHours); + int deleteAuxiliaryWorkingHours(Integer id); + int upAuxiliaryWorkingHours(AuxiliaryWorkingHours auxiliaryWorkingHours); + int insertAuxiliaryWorkingHours(AuxiliaryWorkingHours auxiliaryWorkingHours); +} diff --git a/performance-server/src/main/java/com/yuanchu/mom/service/PerformanceShiftService.java b/performance-server/src/main/java/com/yuanchu/mom/service/PerformanceShiftService.java index 67ad72a..e671f1a 100644 --- a/performance-server/src/main/java/com/yuanchu/mom/service/PerformanceShiftService.java +++ b/performance-server/src/main/java/com/yuanchu/mom/service/PerformanceShiftService.java @@ -1,5 +1,6 @@ package com.yuanchu.mom.service; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.yuanchu.mom.dto.PerformanceShiftAddDto; @@ -22,4 +23,8 @@ Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory); void performanceShiftUpdate(PerformanceShift performanceShift); + + IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, String laboratory); + + Map<Object, Object> exportToExcel(String time, String userName, String laboratory) throws Exception; } diff --git a/performance-server/src/main/java/com/yuanchu/mom/service/impl/AuxiliaryWorkingHoursServiceImpl.java b/performance-server/src/main/java/com/yuanchu/mom/service/impl/AuxiliaryWorkingHoursServiceImpl.java new file mode 100644 index 0000000..8049fab --- /dev/null +++ b/performance-server/src/main/java/com/yuanchu/mom/service/impl/AuxiliaryWorkingHoursServiceImpl.java @@ -0,0 +1,51 @@ +package com.yuanchu.mom.service.impl; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.yuanchu.mom.common.PrintChina; +import com.yuanchu.mom.pojo.AuxiliaryWorkingHours; +import com.yuanchu.mom.mapper.AuxiliaryWorkingHoursMapper; +import com.yuanchu.mom.service.AuxiliaryWorkingHoursService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.yuanchu.mom.utils.QueryWrappers; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +/** + * <p> + * 杈呭姪宸ユ椂 鏈嶅姟瀹炵幇绫� + * </p> + * + * @author 姹熻嫃榈烽洀缃戠粶绉戞妧鏈夐檺鍏徃 + * @since 2024-05-09 06:58:31 + */ +@Service +public class AuxiliaryWorkingHoursServiceImpl extends ServiceImpl<AuxiliaryWorkingHoursMapper, AuxiliaryWorkingHours> implements AuxiliaryWorkingHoursService { + + @Resource + private AuxiliaryWorkingHoursMapper auxiliaryWorkingHoursMapper; + @Override + public Map<String, Object> selectAuxiliaryWorkingHours(Page page, AuxiliaryWorkingHours auxiliaryWorkingHours) { + Map<String, Object> map = new HashMap<>(); + map.put("head", PrintChina.printChina(AuxiliaryWorkingHours.class)); + map.put("body", auxiliaryWorkingHoursMapper.selectAuxiliaryWorkingHours(page, QueryWrappers.queryWrappers(auxiliaryWorkingHours))); + return map; + } + + @Override + public int deleteAuxiliaryWorkingHours(Integer id) { + return auxiliaryWorkingHoursMapper.deleteById(id); + } + + @Override + public int upAuxiliaryWorkingHours(AuxiliaryWorkingHours auxiliaryWorkingHours) { + return auxiliaryWorkingHoursMapper.updateById(auxiliaryWorkingHours); + } + + @Override + public int insertAuxiliaryWorkingHours(AuxiliaryWorkingHours auxiliaryWorkingHours) { + return auxiliaryWorkingHoursMapper.insert(auxiliaryWorkingHours); + } +} diff --git a/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java b/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java index fd33f86..dde83c3 100644 --- a/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java +++ b/performance-server/src/main/java/com/yuanchu/mom/service/impl/PerformanceShiftServiceImpl.java @@ -3,6 +3,7 @@ import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -13,6 +14,7 @@ import com.yuanchu.mom.pojo.PerformanceShift; import com.yuanchu.mom.service.EnumService; import com.yuanchu.mom.service.PerformanceShiftService; +import com.yuanchu.mom.utils.JackSonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -171,16 +173,106 @@ .set(PerformanceShift::getShift, performanceShift.getShift())); } -// public static void main(String[] args) { -// String dateStr = "2023-09-15 12:30:45"; -// LocalDateTime localDateTime = convertToLocalDateTime(dateStr); -// System.out.println(localDateTime); -// } -// -// public static LocalDateTime convertToLocalDateTime(String dateStr) { -// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); -// return LocalDateTime.parse(dateStr, formatter); -// } + @Override + public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, String laboratory) { + IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, laboratory); + List<Enums> shiftType = enumService.selectEnumByCategory("鐝绫诲瀷"); + mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), shiftType)); + return mapYearIPage; + } + + // 骞村垎椤典笌瀵煎嚭鍏卞悓浣跨敤 + public List<Map<String, Object>> annualAttendanceProcessing(List<Map<String, Object>> mapYearList, List<Enums> shiftType){ + for (Map<String, Object> map : mapYearList) { + Map<String, Object> resultMap = new LinkedHashMap<>(); + Map<String, Object> hashMapYear = new LinkedHashMap<>(); + int totalYearAttendance = 0; + // 涓�骞�12涓湀 + for (int i = 1; i < 13; i++) { + Map<String, Object> hashMapMonth = new LinkedHashMap<>(); + int totalMonthAttendance = 0; + for (Enums enums : shiftType) { + if (!hashMapYear.containsKey(enums.getLabel())) { + hashMapYear.put(enums.getLabel(), 0); + } + // 鏈� + if (ObjectUtils.isNotEmpty(map.get("month_str")) && map.get("work_time").equals(i)) { + String charArray = map.get("month_str").toString(); + int count = countOccurrences(charArray, i + "锛�" + enums.getValue()); + hashMapMonth.put(enums.getLabel(), count); + hashMapYear.put(enums.getLabel(), Integer.parseInt(hashMapYear.get(enums.getLabel()).toString()) + count ); + if (enums.getValue().equals("0") || enums.getValue().equals("1") || enums.getValue().equals("2")) { + totalMonthAttendance += count; + totalYearAttendance += count; + } + } + // 绌烘暟鎹� + else { + map.put("work_time", i); + hashMapMonth.put(enums.getLabel(), 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<Enums> enums) 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")); + enums.forEach(j -> { + excelRowList.add(year.get(j.getLabel())); + }); + 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 (Enums anEnum : enums) { + excelRowList.add(month.get(j + "").get(anEnum.getLabel())); + } + } + data.add(excelRowList); + } + return data; + } + + @Override + public Map<Object, Object> exportToExcel(String time, String userName, String laboratory) throws Exception { + Map<Object, Object> map = new HashMap<>(); + List<Enums> shiftType = enumService.selectEnumByCategory("鐝绫诲瀷"); + DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + // 灏嗗瓧绗︿覆鏃堕棿杞崲涓� LocalDateTime 绫诲瀷鏃堕棿 + LocalDateTime localDateTime = LocalDateTime.parse(time, formatters); + map.put("header", getHeader(localDateTime.getYear() + " 骞�", shiftType)); + List<Map<String, Object>> mapYearList = baseMapper.performanceShiftYearList(time, userName, laboratory); + annualAttendanceProcessing(mapYearList, shiftType); + List<List<Object>> lists = dataRequiredForProcessingIntoExcel(mapYearList, shiftType); + map.put("data", lists); + return map; + } // 鑾峰彇涓や釜localDateTime鐨勬瘡涓�澶� public static List<LocalDateTime> getLocalDateTimesBetween(LocalDateTime start, LocalDateTime end) { @@ -230,4 +322,31 @@ return "鏈煡"; } } + + /** + * 杩斿洖琛ㄥご + * + * 澶栧眰List浠h〃琛屽唴灞� List浠h〃鍒� 鐩稿悓鐨勫垪鏁版嵁浼氳涓诲姩鍚堝苟 + * 鏋勯�犲弻鍒楄〃澶� + * @return List<List<String>> + */ + private static List<List<String>> getHeader(String month, List<Enums> enums){ + List<List<String>> line = new ArrayList<>(); + line.add(Arrays.asList("鑰冨嫟姹囨��", "搴忓彿", "搴忓彿")); + line.add(Arrays.asList("鑰冨嫟姹囨��", "宸ュ彿", "宸ュ彿")); + line.add(Arrays.asList("鑰冨嫟姹囨��", "濮撳悕", "濮撳悕")); + line.add(Arrays.asList("鍑哄嫟璇︽儏", month, "鍑哄嫟")); + // 骞� header + for (Enums anEnum : enums) { + line.add(Arrays.asList("鑰冨嫟姹囨��", month, anEnum.getLabel())); + } + // 鏈坔eader + for (int i = 1; i < 13; i++) { + line.add(Arrays.asList("鍑哄嫟璇︽儏", i + " 鏈�", "鍑哄嫟")); + for (Enums anEnum : enums) { + line.add(Arrays.asList("鍑哄嫟璇︽儏", i + " 鏈�", anEnum.getLabel())); + } + } + return line; + } } diff --git a/performance-server/src/main/java/com/yuanchu/mom/utils/StyleUtils.java b/performance-server/src/main/java/com/yuanchu/mom/utils/StyleUtils.java new file mode 100644 index 0000000..dc8a300 --- /dev/null +++ b/performance-server/src/main/java/com/yuanchu/mom/utils/StyleUtils.java @@ -0,0 +1,83 @@ +package com.yuanchu.mom.utils; + +import com.alibaba.excel.write.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.metadata.style.WriteFont; +import org.apache.poi.ss.usermodel.*; + +public class StyleUtils { + /** + * 鏍囬鏍峰紡 + * @return + */ + public static WriteCellStyle getHeadStyle(){ + // 澶寸殑绛栫暐 + WriteCellStyle headWriteCellStyle = new WriteCellStyle(); + // 鑳屾櫙棰滆壊 + headWriteCellStyle.setFillForegroundColor(IndexedColors.LIME.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 涓篎illPatternType.SOLID_FOREGROUND 涓嶇劧鏃犳硶鏄剧ず鑳屾櫙棰滆壊.澶撮粯璁や簡 FillPatternType鎵�浠ュ彲浠ヤ笉鎸囧畾 + contentWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.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) 1);//璁剧疆搴曡竟妗嗛鑹�; + contentWriteCellStyle.setBorderLeft(BorderStyle.THIN); //璁剧疆宸﹁竟妗�; + contentWriteCellStyle.setLeftBorderColor((short) 1);//璁剧疆宸﹁竟妗嗛鑹�; + contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//璁剧疆鍙宠竟妗�; + contentWriteCellStyle.setRightBorderColor((short) 1);//璁剧疆鍙宠竟妗嗛鑹�; + contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//璁剧疆椤惰竟妗�; + contentWriteCellStyle.setTopBorderColor((short) 1); ///璁剧疆椤惰竟妗嗛鑹�; + + contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 姘村钩灞呬腑 + contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 鍨傜洿灞呬腑 + contentWriteCellStyle.setWrapped(false); //璁剧疆鑷姩鎹㈣; + +// contentWriteCellStyle.setShrinkToFit(true);//璁剧疆鏂囨湰鏀剁缉鑷冲悎閫� + + return contentWriteCellStyle; + } +} diff --git a/performance-server/src/main/resources/mapper/AuxiliaryWorkingHoursMapper.xml b/performance-server/src/main/resources/mapper/AuxiliaryWorkingHoursMapper.xml new file mode 100644 index 0000000..7977187 --- /dev/null +++ b/performance-server/src/main/resources/mapper/AuxiliaryWorkingHoursMapper.xml @@ -0,0 +1,38 @@ +<?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.yuanchu.mom.mapper.AuxiliaryWorkingHoursMapper"> + + <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 --> + <resultMap id="BaseResultMap" type="com.yuanchu.mom.pojo.AuxiliaryWorkingHours"> + <id column="id" property="id" /> + <result column="number" property="number"/> + <result column="AuxiliaryProject" property="auxiliaryProject" /> + <result column="approved_working_hour" property="approvedWorkingHour" /> + <result column="remarks" property="remarks" /> + <result column="create_user" property="createUser" /> + <result column="update_user" property="updateUser" /> + <result column="create_time" property="createTime" /> + <result column="update_time" property="updateTime" /> + <result column="department" property="department" /> + <result column="laboratory" property="laboratory" /> + <result column="unit" property="unit"/> + </resultMap> + <select id="selectAuxiliaryWorkingHours" resultType="com.yuanchu.mom.pojo.AuxiliaryWorkingHours"> + select data.* + from ( + select + awh.id, + awh.number, + awh.auxiliary_project, + awh.laboratory, + awh.unit, + awh.approved_working_hour, + awh.department, + awh.remarks + FROM auxiliary_working_hours awh + ) data + <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''"> + ${ew.customSqlSegment} + </if> + </select> +</mapper> diff --git a/performance-server/src/main/resources/mapper/PerformanceShiftMapper.xml b/performance-server/src/main/resources/mapper/PerformanceShiftMapper.xml index 29c9d73..0b702be 100644 --- a/performance-server/src/main/resources/mapper/PerformanceShiftMapper.xml +++ b/performance-server/src/main/resources/mapper/PerformanceShiftMapper.xml @@ -43,4 +43,46 @@ <if test="laboratory != null and laboratory != ''"> </if> </select> + + <select id="performanceShiftYear" resultType="java.util.Map"> + SELECT if(u.department is not null and u.department != '', CONCAT(u.name, '锛�', u.department, '锛�'), u.name) name, + s.user_id, u.account, + DATE_FORMAT(s.work_time, '%c') work_time, + GROUP_CONCAT(DATE_FORMAT(s.work_time, '%c'), '锛�', s.shift order by s.work_time SEPARATOR ';') month_str + FROM performance_shift s + LEFT JOIN user u on u.id = s.user_id + where s.shift is not NULL + and s.shift != '' + <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.name like concat('%', #{userName}, '%') + </if> + <if test="laboratory != null and laboratory != ''"> + </if> + GROUP BY u.id + order by s.work_time + </select> + + <select id="performanceShiftYearList" resultType="map"> + SELECT if(u.department is not null and u.department != '', CONCAT(u.name, '锛�', u.department, '锛�'), u.name) name, + s.user_id, u.account, + DATE_FORMAT(s.work_time, '%c') work_time, + GROUP_CONCAT(DATE_FORMAT(s.work_time, '%c'), '锛�', s.shift order by s.work_time SEPARATOR ';') month_str + FROM performance_shift s + LEFT JOIN user u on u.id = s.user_id + where s.shift is not NULL + and s.shift != '' + <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.name like concat('%', #{userName}, '%') + </if> + <if test="laboratory != null and laboratory != ''"> + </if> + GROUP BY u.id + order by s.work_time + </select> </mapper> diff --git a/pom.xml b/pom.xml index e129ed5..766c9d9 100644 --- a/pom.xml +++ b/pom.xml @@ -37,12 +37,20 @@ <feign-okhttp.version>11.0</feign-okhttp.version> <shiro.version>1.5.3</shiro.version> <freemwork.version>2.3.32</freemwork.version> + <easyexcel.version>3.3.2</easyexcel.version> <!--鎻愪氦鍓�--> <!-- 鎵撳寘鍚庡鍑虹殑璺緞 --> <package.path>${project.build.directory}/BLOG</package.path> </properties> <dependencies> + <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel --> + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>easyexcel</artifactId> + <version>${easyexcel.version}</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> diff --git a/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java b/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java index a34819b..05a3381 100644 --- a/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java +++ b/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java @@ -6,8 +6,9 @@ @SpringBootTest class SystemRunApplicationTest { - @Test - void contextLoads() { + void contextLoads() throws Exception { + } + } -- Gitblit v1.9.3