| | |
| | | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | |
| | | */ |
| | | @Service |
| | | public class MdcEquipmentPunchServiceImpl extends ServiceImpl<MdcEquipmentPunchMapper, MdcEquipmentPunch> implements IMdcEquipmentPunchService { |
| | | |
| | | @Resource |
| | | private MdcEquipmentPunchMapper mdcEquipmentPunchMapper; |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } |