zhangfeng
2023-07-26 dd59c95e87ba585c4e3e2f059e218853784402e5
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.gk.hotwork.Service.ServiceImpl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.InspectionExpert;
import com.gk.hotwork.Domain.SafetyInspectionElementA;
import com.gk.hotwork.Domain.UserInfo;
import com.gk.hotwork.Mapper.InspectionExpertGroupMapper;
import com.gk.hotwork.Mapper.InspectionExpertMapper;
import com.gk.hotwork.Mapper.SafetyInspectionElementAMapper;
import com.gk.hotwork.Service.InspectionExpertService;
import com.gk.hotwork.Service.SafetyInspectionElementAService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/7/19
 * @time: 17:30
 */
@Service
public class InspectionExpertServiceImpl extends ServiceImpl<InspectionExpertMapper, InspectionExpert> implements InspectionExpertService {
 
    @Autowired
    private InspectionExpertMapper inspectionExpertMapper;
 
 
    @Override
    public void setLeader(InspectionExpert inspectionExpert, UserInfo user) {
        requireVertify(inspectionExpert);
        inspectionExpertMapper.updateById(inspectionExpert);
    }
 
    /**
     * 根据专家组id获取专家成员
     * @param expertGroupId
     * @return
     */
    public List<InspectionExpert> getByGroupId(Long expertGroupId){
        List<InspectionExpert> list = inspectionExpertMapper.selectList(new LambdaQueryWrapper<InspectionExpert>().eq(InspectionExpert::getExpertGropId, expertGroupId));
        return list;
    }
 
    /**
     * 根据检查清单id获取专家成员
     * @param selfInspectionId
     * @return
     */
    public List<InspectionExpert> getBySelfInspectionId(Long selfInspectionId){
        List<InspectionExpert> list = inspectionExpertMapper.selectList(new LambdaQueryWrapper<InspectionExpert>()
                .eq(InspectionExpert::getSelfInspectionId, selfInspectionId));
        return list;
    }
 
    public List<InspectionExpert> getLeaderList(Long expertGroupId){
        List<InspectionExpert> list = inspectionExpertMapper
                .selectList(new LambdaQueryWrapper<InspectionExpert>()
                        .eq(InspectionExpert::getExpertGropId, expertGroupId)
                        .eq(InspectionExpert::getIsLeader,true));
        return list;
 
    }
 
    private void requireVertify(InspectionExpert inspectionExpert) {
        if(inspectionExpert.getId() == null){
            throw new BusinessException("专家主键不可为空");
        }
        if(inspectionExpert.getIsLeader() == null){
            throw new BusinessException("专家成员类型不可为空");
        }
        if(inspectionExpert.getExpertGropId() == null){
            throw new BusinessException("专家组id不可为空");
        }
        List<InspectionExpert> leaderList = this.getLeaderList(inspectionExpert.getExpertGropId());
        if(leaderList.size() > 0){
            InspectionExpert expert = leaderList.get(0);
            if(expert.getId().equals(inspectionExpert.getId())){
                if(expert.getIsLeader() == true){
                    throw new BusinessException("该专家成员已是组长");
                }
            }else {
                throw new BusinessException("该专家组已有组长");
            }
 
 
        }
    }
}