kongzy
2024-01-29 983bdb5b89932b38d08a11ad1eed6ea89d1597e1
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.gkhy.assess.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gkhy.assess.common.enums.DeleteFlagEnum;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.system.domain.AssEstimateSchedule;
import com.gkhy.assess.system.mapper.AssEstimateScheduleMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.assess.system.service.AssEstimateScheduleService;
import com.gkhy.assess.system.service.AssProjectService;
import com.gkhy.assess.system.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * <p>
 * 评价日程安排表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-12-12 10:46:54
 */
@Service
public class AssEstimateScheduleServiceImpl extends ServiceImpl<AssEstimateScheduleMapper, AssEstimateSchedule> implements AssEstimateScheduleService {
    @Autowired
    private AssProjectService projectService;
    @Override
    public List<AssEstimateSchedule> getByProjectId(Long projectId) {
        projectService.checkUserAllowed(projectId);
        return baseMapper.getEstimateScheduleByProjectId(projectId);
    }
 
 
    @Override
    public int addSchedule(AssEstimateSchedule estimateSchedule) {
        projectService.checkUserAllowed(estimateSchedule.getProjectId());
        if(!checkNameUnique(estimateSchedule)){
            throw new ApiException("项目下已存在该日程安排");
        }
        estimateSchedule.setCreateBy(ShiroUtils.getSysUser().getUsername());
        return baseMapper.insert(estimateSchedule);
    }
 
    public boolean checkNameUnique(AssEstimateSchedule estimateSchedule) {
        LambdaQueryWrapper<AssEstimateSchedule> lambdaQueryWrapper = Wrappers.<AssEstimateSchedule>lambdaQuery()
                .eq(AssEstimateSchedule::getName, estimateSchedule.getName())
                .eq(AssEstimateSchedule::getDelFlag, DeleteFlagEnum.UN_DELETE)
                .eq(AssEstimateSchedule::getProjectId, estimateSchedule.getProjectId());
        if(estimateSchedule.getId()!=null){
            lambdaQueryWrapper.ne(AssEstimateSchedule::getId,estimateSchedule.getId());
        }
        long contractCount= count(lambdaQueryWrapper);
        if(contractCount>0){
            return false;
        }
        return true;
    }
 
    @Override
    public int editSchedule(AssEstimateSchedule estimateSchedule) {
        projectService.checkUserAllowed(estimateSchedule.getProjectId());
        if(!checkNameUnique(estimateSchedule)){
            throw new ApiException("项目下已存在该日程安排");
        }
        estimateSchedule.setUpdateBy(ShiroUtils.getSysUser().getUsername());
        return baseMapper.updateById(estimateSchedule);
    }
}