package com.ruoyi.staff.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.staff.dto.SaveStaffSchedulingDto; import com.ruoyi.staff.dto.StaffSchedulingDto; import com.ruoyi.staff.mapper.StaffSchedulingMapper; import com.ruoyi.staff.pojo.StaffScheduling; import com.ruoyi.staff.service.StaffSchedulingService; import com.ruoyi.staff.vo.SearchSchedulingVo; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.time.Duration; /** * @author buhuazhen * @description 针对表【staff_scheduling】的数据库操作Service实现 * @createDate 2025-09-03 14:50:34 */ @Service @RequiredArgsConstructor public class StaffSchedulingServiceImpl extends ServiceImpl implements StaffSchedulingService { private final StaffSchedulingMapper staffSchedulingMapper; @Lazy @Resource private StaffSchedulingService staffSchedulingService; @Override public void saveStaffScheduling(SaveStaffSchedulingDto saveStaffSchedulingDto) { StaffScheduling staffScheduling = new StaffScheduling(); BeanUtils.copyProperties(saveStaffSchedulingDto, staffScheduling); // 开始计算时间 Duration duration = Duration.between(staffScheduling.getWorkStartTime(), staffScheduling.getWorkEndTime()); long hours = duration.toHours(); // 0.5 double minutes = (duration.toMinutes() % 60) / 60.0; // minutes = minutes < 0.5 ? 0 : 0.5; 公司一般以0.5为标准计算 staffScheduling.setWorkHours(BigDecimal.valueOf(hours + minutes)); staffSchedulingService.saveOrUpdate(staffScheduling); } @Override public IPage listPage(SearchSchedulingVo vo) { Page page = new Page<>(vo.getCurrent(), vo.getSize()); return staffSchedulingMapper.listPage(page, vo); } }