package org.jeecg.modules.mdc.service.impl;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.jeecg.modules.mdc.entity.MdcEquipmentPunch;
|
import org.jeecg.modules.mdc.entity.MdcEquipmentPunchRate;
|
import org.jeecg.modules.mdc.mapper.MdcEquipmentPunchMapper;
|
import org.jeecg.modules.mdc.mapper.MdcEquipmentPunchRateMapper;
|
import org.jeecg.modules.mdc.service.IMdcEquipmentPunchRateService;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.List;
|
import java.util.UUID;
|
|
/**
|
* @Description: mdc_equipment_punch
|
* @Author: jeecg-boot
|
* @Date: 2025-06-09
|
* @Version: V1.0
|
*/
|
@Service
|
public class MdcEquipmentPunchRateServiceImpl extends ServiceImpl<MdcEquipmentPunchRateMapper, MdcEquipmentPunchRate> implements IMdcEquipmentPunchRateService {
|
@Resource
|
private MdcEquipmentPunchRateMapper mdcEquipmentPunchRateMapper;
|
|
@Resource
|
private MdcEquipmentPunchMapper mdcEquipmentPunchMapper;
|
@Override
|
public void savePunchRates(String targetDate, List<MdcEquipmentPunch> punchRecords) {
|
|
int morningIn = mdcEquipmentPunchMapper.countMorningShiftIn(targetDate);
|
int eveningIn = mdcEquipmentPunchMapper.countEveningShiftIn(targetDate);
|
int morningOut = mdcEquipmentPunchMapper.countMorningShiftOut(targetDate);
|
int eveningOut = mdcEquipmentPunchMapper.countEveningShiftOut(targetDate);
|
for (MdcEquipmentPunch punch : punchRecords) {
|
MdcEquipmentPunchRate rate = new MdcEquipmentPunchRate();
|
|
rate.setId(UUID.randomUUID().toString()); // 生成唯一ID
|
rate.setEquipmentId(punch.getEquipmentId());
|
rate.setTheDate(targetDate);
|
rate.setShiftSchedule(punch.getShiftSchedule());
|
|
|
|
|
// 设置设备数量
|
rate.setMornShiftInNum(morningIn);
|
rate.setMornShiftOutNum(eveningIn);
|
rate.setEvenShiftInNum(morningOut);
|
rate.setEvenShiftOutNum(eveningOut);
|
|
|
|
// 获取总设备数
|
int totalDevices = mdcEquipmentPunchMapper.getTotalDeviceCount();
|
if (totalDevices == 0) return;
|
|
|
rate.setDeviceCountNum(totalDevices);
|
|
// 计算打卡率(保留两位小数)
|
rate.setMornShiftInRate(calculateRate(morningIn, totalDevices));
|
rate.setMornShiftOutRate(calculateRate(eveningIn, totalDevices));
|
rate.setEvenShiftInRate(calculateRate(morningOut, totalDevices));
|
rate.setEvenShiftOutRate(calculateRate(eveningOut, totalDevices));
|
|
this.save(rate);
|
}
|
}
|
private BigDecimal calculateRate(int actual, int total) {
|
if (total == 0) return BigDecimal.ZERO;
|
return new BigDecimal(actual)
|
.divide(new BigDecimal(total), 4, RoundingMode.DOWN)
|
.multiply(BigDecimal.valueOf(100))
|
.setScale(2, RoundingMode.DOWN); // 保留两位小数,不进行四舍五入
|
}
|
|
}
|