From 2599726e37d161a4688d8c59dd9d59ad5e373902 Mon Sep 17 00:00:00 2001 From: dxfeng Date: Mon, 18 Aug 2025 17:49:53 +0800 Subject: [PATCH] Initial commit --- .gitignore | 19 ++ secondev-chapanda-feishu.gradle | 6 + .../controller/EmployeePanelController.java | 41 ++++ .../OutEmployeePanelController.java | 41 ++++ .../entity/po/EmployeeAttendInfoPo.java | 26 +++ .../feishu/mapper/EmployeePanelMapper.java | 25 +++ .../feishu/service/EmployeePanelService.java | 22 +++ .../impl/EmployeePanelServiceImpl.java | 114 +++++++++++ .../resources/mapper/EmployeePanelMapper.xml | 186 ++++++++++++++++++ 9 files changed, 480 insertions(+) create mode 100644 .gitignore create mode 100644 secondev-chapanda-feishu.gradle create mode 100644 src/main/java/com/weaver/seconddev/feishu/controller/EmployeePanelController.java create mode 100644 src/main/java/com/weaver/seconddev/feishu/controller/OutEmployeePanelController.java create mode 100644 src/main/java/com/weaver/seconddev/feishu/entity/po/EmployeeAttendInfoPo.java create mode 100644 src/main/java/com/weaver/seconddev/feishu/mapper/EmployeePanelMapper.java create mode 100644 src/main/java/com/weaver/seconddev/feishu/service/EmployeePanelService.java create mode 100644 src/main/java/com/weaver/seconddev/feishu/service/impl/EmployeePanelServiceImpl.java create mode 100644 src/main/resources/mapper/EmployeePanelMapper.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..31e631b --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +.iml +/out/ +/.idea/ + + +HELP.md +target/ + +### IntelliJ IDEA ### +.idea + + +/src/test +/src/rebel.xml +/src/META-INF +### IntelliJ IDEA ### + +/log +/build/ diff --git a/secondev-chapanda-feishu.gradle b/secondev-chapanda-feishu.gradle new file mode 100644 index 0000000..6b10660 --- /dev/null +++ b/secondev-chapanda-feishu.gradle @@ -0,0 +1,6 @@ +description = "子模块demo项目" + +dependencies { + // 子项目私有依赖添加 + implementation project(':secondev-chapanda-portal') +} \ No newline at end of file diff --git a/src/main/java/com/weaver/seconddev/feishu/controller/EmployeePanelController.java b/src/main/java/com/weaver/seconddev/feishu/controller/EmployeePanelController.java new file mode 100644 index 0000000..f3067f1 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/feishu/controller/EmployeePanelController.java @@ -0,0 +1,41 @@ +package com.weaver.seconddev.feishu.controller; + +import com.weaver.common.authority.annotation.WeaPermission; +import com.weaver.seconddev.feishu.service.EmployeePanelService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/07/15 + * @version: 1.0 + */ +@Slf4j +@RestController +@RequestMapping("/api/secondev/panel/employee") +@WeaPermission(publicPermission = true) +public class EmployeePanelController { + + @Autowired + EmployeePanelService employeePanelService; + + @GetMapping("/getAttendInfo") + public Object getAttendInfo(@RequestParam("beginDate") String beginDate, + @RequestParam("endDate") String endDate, + @RequestParam("jobNum") String jobNum) { + log.error("beginDate:{},endDate:{},jobNum:{}", beginDate, endDate, jobNum); + Map params = new HashMap<>(); + params.put("beginDate", beginDate); + params.put("endDate", endDate); + params.put("jobNum", jobNum); + return employeePanelService.getAttendInfo(params); + } + +} diff --git a/src/main/java/com/weaver/seconddev/feishu/controller/OutEmployeePanelController.java b/src/main/java/com/weaver/seconddev/feishu/controller/OutEmployeePanelController.java new file mode 100644 index 0000000..f1d626d --- /dev/null +++ b/src/main/java/com/weaver/seconddev/feishu/controller/OutEmployeePanelController.java @@ -0,0 +1,41 @@ +package com.weaver.seconddev.feishu.controller; + +import com.weaver.common.authority.annotation.WeaPermission; +import com.weaver.seconddev.feishu.service.EmployeePanelService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/07/15 + * @version: 1.0 + */ +@Slf4j +@RestController +@RequestMapping("/sapi/secondev/panel/employee") +@WeaPermission(publicPermission = true) +public class OutEmployeePanelController { + + @Autowired + EmployeePanelService employeePanelService; + + @GetMapping("/getAttendInfo") + public Object getAttendInfo(@RequestParam("beginDate") String beginDate, + @RequestParam("endDate") String endDate, + @RequestParam("jobNum") String jobNum) { + log.error("beginDate:{},endDate:{},jobNum:{}", beginDate, endDate, jobNum); + Map params = new HashMap<>(); + params.put("beginDate", beginDate); + params.put("endDate", endDate); + params.put("jobNum", jobNum); + return employeePanelService.getAttendInfo(params); + } + +} diff --git a/src/main/java/com/weaver/seconddev/feishu/entity/po/EmployeeAttendInfoPo.java b/src/main/java/com/weaver/seconddev/feishu/entity/po/EmployeeAttendInfoPo.java new file mode 100644 index 0000000..2710411 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/feishu/entity/po/EmployeeAttendInfoPo.java @@ -0,0 +1,26 @@ +package com.weaver.seconddev.feishu.entity.po; + +import lombok.Data; + +/** + * @author:dxfeng + * @createTime: 2025/07/15 + * @version: 1.0 + */ +@Data +public class EmployeeAttendInfoPo { + + /** + * 工号 + */ + private String workCode; + + /** + * 应出勤天数 + */ + private String expectedAttendance; + /** + * 实际出勤 + */ + private String actualAttendance; +} diff --git a/src/main/java/com/weaver/seconddev/feishu/mapper/EmployeePanelMapper.java b/src/main/java/com/weaver/seconddev/feishu/mapper/EmployeePanelMapper.java new file mode 100644 index 0000000..a717122 --- /dev/null +++ b/src/main/java/com/weaver/seconddev/feishu/mapper/EmployeePanelMapper.java @@ -0,0 +1,25 @@ +package com.weaver.seconddev.feishu.mapper; + +import com.weaver.seconddev.portal.entity.param.BaseParam; +import org.apache.ibatis.annotations.MapKey; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/07/15 + * @version: 1.0 + */ +@Mapper +public interface EmployeePanelMapper { + + @MapKey("employee") + Map> statsWorkTimeLength(@Param("param") BaseParam param, @Param(value = "empIds") List empIds, @Param(value = "beginDate") Date beginDate, @Param(value = "endDate") Date endDate, + @Param(value = "tenantKey") String tenantKey, @Param("extraAbsenteeism") boolean extraAbsenteeism, @Param("hasDetailExtend") boolean hasDetailExtend); + +} diff --git a/src/main/java/com/weaver/seconddev/feishu/service/EmployeePanelService.java b/src/main/java/com/weaver/seconddev/feishu/service/EmployeePanelService.java new file mode 100644 index 0000000..4982eab --- /dev/null +++ b/src/main/java/com/weaver/seconddev/feishu/service/EmployeePanelService.java @@ -0,0 +1,22 @@ +package com.weaver.seconddev.feishu.service; + +import com.weaver.common.base.entity.result.WeaResult; +import com.weaver.seconddev.feishu.entity.po.EmployeeAttendInfoPo; + +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/07/15 + * @version: 1.0 + */ +public interface EmployeePanelService { + + /** + * 获取考勤信息 + * + * @param params + * @return + */ + WeaResult getAttendInfo(Map params); +} diff --git a/src/main/java/com/weaver/seconddev/feishu/service/impl/EmployeePanelServiceImpl.java b/src/main/java/com/weaver/seconddev/feishu/service/impl/EmployeePanelServiceImpl.java new file mode 100644 index 0000000..5dfc56f --- /dev/null +++ b/src/main/java/com/weaver/seconddev/feishu/service/impl/EmployeePanelServiceImpl.java @@ -0,0 +1,114 @@ +package com.weaver.seconddev.feishu.service.impl; + +import com.weaver.common.base.entity.result.WeaResult; +import com.weaver.common.hr.util.Util; +import com.weaver.seconddev.feishu.entity.po.EmployeeAttendInfoPo; +import com.weaver.seconddev.feishu.mapper.EmployeePanelMapper; +import com.weaver.seconddev.feishu.service.EmployeePanelService; +import com.weaver.seconddev.portal.entity.param.BaseParam; +import com.weaver.workflow.common.cfg.org.service.UserService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @author:dxfeng + * @createTime: 2025/07/15 + * @version: 1.0 + */ +@Slf4j +@Service +public class EmployeePanelServiceImpl implements EmployeePanelService { + + @Autowired + EmployeePanelMapper employeePanelMapper; + + @Autowired + UserService userService; + + @Override + public WeaResult getAttendInfo(Map params) { + String jobNum = Util.null2String(params.get("jobNum")); + String beginDateStr = Util.null2String(params.get("beginDate")); + String endDateStr = Util.null2String(params.get("endDate")); + BaseParam baseParam = new BaseParam(); + + List userIdsByJobNum = userService.getUserIdsByJobNum(jobNum, baseParam.getTenantKey()); + if (CollectionUtils.isEmpty(userIdsByJobNum)) { + return WeaResult.fail("未匹配到人员", true); + } + Long employeeId = userIdsByJobNum.get(0); + // + List empIds = new ArrayList<>(); + empIds.add(employeeId); + + Date beginDate = parseDate(beginDateStr); + Date endDate = parseDate(endDateStr); + + Map> mapMap = employeePanelMapper.statsWorkTimeLength(baseParam, empIds, beginDate, endDate, baseParam.getTenantKey(), false, false); + Map map = mapMap.get(BigDecimal.valueOf(employeeId)); + log.error("map===>{}", map); + + EmployeeAttendInfoPo employeeAttendInfoPo = new EmployeeAttendInfoPo(); + employeeAttendInfoPo.setExpectedAttendance(formatNumber(map.get("period_length_day").toString())); + employeeAttendInfoPo.setActualAttendance(formatNumber(map.get("work_length_day").toString())); + return WeaResult.success(employeeAttendInfoPo); + } + + + /** + * 日期类型转换 + * + * @param dateStr + * @return + */ + private Date parseDate(String dateStr) { + if (dateStr == null) { + return null; + } + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + // 将字符串解析为LocalDate + LocalDate localDate = LocalDate.parse(dateStr, formatter); + + // 将LocalDate转换为java.util.Date + return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + } + + + /** + * 格式化数字 + * + * @param numberStr + * @return + */ + public static String formatNumber(String numberStr) { + if (numberStr == null || numberStr.isEmpty()) { + return numberStr; + } + + BigDecimal bd = new BigDecimal(numberStr); + // 向上取整,最多保留两位小数 + bd = bd.setScale(2, RoundingMode.HALF_UP); + String formatted = bd.stripTrailingZeros().toPlainString(); + + // 如果结果为整数,则去掉小数点 + if (formatted.contains(".") && formatted.substring(formatted.indexOf('.') + 1).matches("0+")) { + return formatted.substring(0, formatted.indexOf('.')); + } + + return formatted; + } +} diff --git a/src/main/resources/mapper/EmployeePanelMapper.xml b/src/main/resources/mapper/EmployeePanelMapper.xml new file mode 100644 index 0000000..f68de81 --- /dev/null +++ b/src/main/resources/mapper/EmployeePanelMapper.xml @@ -0,0 +1,186 @@ + + + + + + SUM(CASE DAY_TYPE WHEN 'WORK' THEN + CASE WHEN FINAL_SIGN_IN_STATUS='SIGN_IN_ABSENCE' THEN + ABSENCE_LENGTH_MSEC-IFNULL(abs.ABSENTEEISM_LENGTH_MESC,0)-IFNULL(EARLY_OUT_LENGTH_MESC,0) - + IFNULL(SERIOUS_EARLY_LENGTH_MESC, 0) + WHEN SIGN_IN_RECORD IS NOT NULL THEN + CASE FINAL_SIGN_OUT_STATUS WHEN 'SIGN_OUT_ABSENCE' THEN + ABSENCE_LENGTH_MSEC-IFNULL(abs.ABSENTEEISM_LENGTH_MESC,0)-IFNULL(LATE_LENGTH_MESC,0) + -IFNULL(SERIOUS_LATE_LENGTH_MESC,0) ELSE 0 END + ELSE 0 END + ELSE 0 END)*1.00/3600000 AS lost_length_hour + + + + SUM(CASE DAY_TYPE WHEN 'WORK' THEN + CASE WHEN FINAL_SIGN_IN_STATUS='SIGN_IN_ABSENCE' THEN + ABSENCE_LENGTH_DAY-IFNULL(abs.ABSENTEEISM_LENGTH_DAY,0)-IFNULL(EARLY_OUT_LENGTH_DAY,0)-IFNULL(SERIOUS_EARLY_LENGTH_DAY,0) + WHEN SIGN_IN_RECORD IS NOT NULL THEN + CASE FINAL_SIGN_OUT_STATUS WHEN 'SIGN_OUT_ABSENCE' THEN + ABSENCE_LENGTH_DAY-IFNULL(abs.ABSENTEEISM_LENGTH_DAY,0)-IFNULL(LATE_LENGTH_DAY,0)-IFNULL(SERIOUS_LATE_LENGTH_DAY,0) + ELSE 0 END + ELSE 0 END + ELSE 0 END) AS lost_length_day + + + + SUM(CASE DAY_TYPE WHEN 'WORK' THEN + CASE WHEN FINAL_SIGN_IN_STATUS='SIGN_IN_ABSENCE' THEN + ABSENCE_LENGTH_MSEC-IFNULL(AAD.ABSENTEEISM_LENGTH_MESC,0)-IFNULL(EARLY_OUT_LENGTH_MESC,0) - + IFNULL(SERIOUS_EARLY_LENGTH_MESC, 0) + WHEN SIGN_IN_RECORD IS NOT NULL THEN + CASE FINAL_SIGN_OUT_STATUS WHEN 'SIGN_OUT_ABSENCE' THEN + ABSENCE_LENGTH_MSEC-IFNULL(AAD.ABSENTEEISM_LENGTH_MESC,0)-IFNULL(LATE_LENGTH_MESC,0) + -IFNULL(SERIOUS_LATE_LENGTH_MESC,0) ELSE 0 END + ELSE 0 END + ELSE 0 END)*1.00/3600000 AS lost_length_hour + + + + sum(case when month_late_length_mesc = 1 then 1 else 0 end) AS month_late_in_count, + sum(case when month_late_length_mesc = 1 then AAD.LATE_LENGTH_MESC else 0 end)*1.00/3600000 AS + month_late_in_hour, + sum(case when month_late_length_mesc = 1 then AAD.LATE_LENGTH_DAY else 0 end) AS month_late_in_day, + sum(case when month_late_length_mesc = 2 then 1 else 0 end) AS month_late_out_count, + sum(case when month_late_length_mesc = 2 then AAD.LATE_LENGTH_MESC else 0 end)*1.00/3600000 AS + month_late_out_hour, + sum(case when month_late_length_mesc = 2 then AAD.LATE_LENGTH_DAY else 0 end) AS month_late_out_day, + sum(case when month_early_length_mesc = 1 then 1 else 0 end) AS month_early_in_count, + sum(case when month_early_length_mesc = 1 then AAD.EARLY_OUT_LENGTH_MESC else 0 end)*1.00/3600000 AS + month_early_in_hour, + sum(case when month_early_length_mesc = 1 then AAD.EARLY_OUT_LENGTH_DAY else 0 end) AS month_early_in_day, + sum(case when month_early_length_mesc = 2 then 1 else 0 end) AS month_early_out_count, + sum(case when month_early_length_mesc = 2 then AAD.EARLY_OUT_LENGTH_MESC else 0 end)*1.00/3600000 AS + month_early_out_hour, + sum(case when month_early_length_mesc = 2 then AAD.EARLY_OUT_LENGTH_DAY else 0 end) AS month_early_out_day + + + + SUM(CASE DAY_TYPE WHEN 'WORK' THEN + CASE WHEN FINAL_SIGN_IN_STATUS='SIGN_IN_ABSENCE' THEN + ABSENCE_LENGTH_DAY-IFNULL(AAD.ABSENTEEISM_LENGTH_DAY,0)-IFNULL(EARLY_OUT_LENGTH_DAY,0)-IFNULL(SERIOUS_EARLY_LENGTH_DAY,0) + WHEN SIGN_IN_RECORD IS NOT NULL THEN + CASE FINAL_SIGN_OUT_STATUS WHEN 'SIGN_OUT_ABSENCE' THEN + ABSENCE_LENGTH_DAY-IFNULL(AAD.ABSENTEEISM_LENGTH_DAY,0)-IFNULL(LATE_LENGTH_DAY,0)-IFNULL(SERIOUS_LATE_LENGTH_DAY,0) + ELSE 0 END + ELSE 0 END + ELSE 0 END) AS lost_length_day + + + + +