buhuazhen
2 天以前 93723438fd269d2f602439eabca127ed4054818a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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<StaffSchedulingMapper, StaffScheduling>
        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<StaffSchedulingDto> listPage(SearchSchedulingVo vo) {
        Page<StaffScheduling> page = new Page<>(vo.getCurrent(), vo.getSize());
 
        return staffSchedulingMapper.listPage(page, vo);
    }
}