From 4dd33cbe7be8c0e552962b64d9f323a9cc04db45 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期五, 13 六月 2025 10:54:35 +0800 Subject: [PATCH] 设备打卡率定时任务。设备打卡率列表接口 --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentPunchServiceImpl.java | 63 +++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 1 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentPunchServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentPunchServiceImpl.java index b0733d8..31517e7 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentPunchServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentPunchServiceImpl.java @@ -3,6 +3,7 @@ import cn.hutool.core.date.DatePattern; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -19,6 +20,10 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -30,7 +35,8 @@ */ @Service public class MdcEquipmentPunchServiceImpl extends ServiceImpl<MdcEquipmentPunchMapper, MdcEquipmentPunch> implements IMdcEquipmentPunchService { - + @Resource + private MdcEquipmentPunchMapper mdcEquipmentPunchMapper; @Resource private IMdcEquipmentService mdcEquipmentService; @@ -235,4 +241,59 @@ this.saveOrUpdateBatch(list); } + + @Override + public void fillPunchRates(List<MdcEquipmentPunch> punchList) { + + // 鑾峰彇鏄ㄥぉ鏃ユ湡 + LocalDate yesterday = LocalDate.now().minusDays(1); + String yesterdayStr = yesterday.format(DateTimeFormatter.ofPattern(DatePattern.PURE_DATE_PATTERN)); // 鏍煎紡鍖栦负 "yyyy-MM-dd" + + + // 鑾峰彇鎬昏澶囨暟 + int totalDevices = mdcEquipmentPunchMapper.getTotalDeviceCount(); + if (totalDevices == 0) return; + + // 缁熻鍚勭被鍨嬫墦鍗′汉鏁� + int morningIn = mdcEquipmentPunchMapper.countMorningShiftIn(yesterdayStr); + int eveningIn = mdcEquipmentPunchMapper.countEveningShiftIn(yesterdayStr); + int morningOut = mdcEquipmentPunchMapper.countMorningShiftOut(yesterdayStr); + int eveningOut = mdcEquipmentPunchMapper.countEveningShiftOut(yesterdayStr); + + + // 璁剧疆鎵撳崱鐜囧埌姣忎釜 DTO + for (MdcEquipmentPunch dto : punchList) { + dto.setMorningShiftInRate(calculateRate(morningIn, totalDevices)); + dto.setEveningShiftInRate(calculateRate(eveningIn, totalDevices)); + dto.setMorningShiftOutRate(calculateRate(morningOut, totalDevices)); + dto.setEveningShiftOutRate(calculateRate(eveningOut, totalDevices)); + + // 璁剧疆鎵撳崱璁惧鏁伴噺瀛楁 + dto.setMorningShiftInDeviceNum(morningIn); + dto.setMorningShiftOutDeviceNum(morningOut); + dto.setEveningShiftInDeviceNum(eveningIn); + dto.setEveningShiftOutDeviceNum(eveningOut); + dto.setDeviceCountNum(totalDevices); + } + } + + // 璁$畻鐧惧垎姣斿苟淇濈暀涓や綅灏忔暟 + private BigDecimal calculateRate(int actual, int total) { + if (total == 0) return BigDecimal.ZERO; + return new BigDecimal(actual) + .divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)) + .setScale(2, RoundingMode.HALF_UP); // 淇濈暀涓や綅灏忔暟 + } + + @Override + public List<MdcEquipmentPunch> getYesterdayRecords(String targetDate) { + // 鏋勯�犳煡璇㈡潯浠讹細record_date = targetDate.toString() + QueryWrapper<MdcEquipmentPunch> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("record_date", targetDate); + + // 鎵ц鏌ヨ骞惰繑鍥炵粨鏋� + return baseMapper.selectList(queryWrapper); + } + } -- Gitblit v1.9.3