heheng
2024-12-10 0ee9cf0938174798af956fc6ae301ef149fd8b6a
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package com.gkhy.system.service.impl;
 
 
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.common.enums.DeleteFlagEnum;
import com.gkhy.common.exception.ServiceException;
import com.gkhy.common.utils.SecurityUtils;
import com.gkhy.common.utils.StringUtils;
import com.gkhy.system.domain.SysExpertInfo;
import com.gkhy.system.domain.vo.request.ExpertBatchChangeReq;
import com.gkhy.system.domain.vo.request.SysExpertInfoRoundReq;
import com.gkhy.system.domain.vo.request.SysExpertSearchReqDto;
import com.gkhy.system.domain.vo.response.ProjectExpertSectionResp;
import com.gkhy.system.domain.vo.response.SysExpertSearchRep;
import com.gkhy.system.mapper.SysExpertInfoMapper;
import com.gkhy.system.service.SysExpertInfoService;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * <p>
 * 系统专家信息表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2023-11-27 16:33:33
 */
@Service
public class SysExpertInfoServiceImpl extends ServiceImpl<SysExpertInfoMapper, SysExpertInfo> implements SysExpertInfoService {
 
    @Override
    public List<SysExpertInfo> exportInfoList(SysExpertInfo expertInfo) {
        //
 
        return baseMapper.expertInfoListV2(expertInfo);
    }
 
    @Override
    public int addExpertInfo(SysExpertInfo expertInfo) {
        if(!checkIdCardUnique(expertInfo)){
            throw new ServiceException("该业务处室申请数据已存在");
        }
        if(StringUtils.isEmpty(expertInfo.getPersonalOpinionKey()) && StringUtils.isEmpty(expertInfo.getRecommendUnitOpinionKey())){
            throw new ServiceException("专家本人意见和推荐单位意见不能同时为空");
        }
        expertInfo.setCreateBy(expertInfo.getName());
        boolean b=save(expertInfo);
        if(!b){
            throw new ServiceException("新增专家信息失败");
        }
        return 1;
    }
 
    @Override
    public int modExpertInfo(SysExpertInfo expertInfo) {
        if(!checkIdCardUnique(expertInfo)){
            throw new ServiceException("该业务处室专业领域申请数据已存在");
        }
        checkHavePer(expertInfo.getId());
        expertInfo.setUpdateBy(SecurityUtils.getUsername());
        boolean b=updateById(expertInfo);
        if(!b){
            throw new ServiceException("修改专家信息失败");
        }
        return 1;
    }
 
    @Override
    public int delExpertInfo(Long expertId) {
        checkHavePer(expertId);
 
        SysExpertInfo expertInfo = new SysExpertInfo();
        expertInfo.setId(expertId);
        expertInfo.setDelFlag(DeleteFlagEnum.DELETED.getCode().intValue());
        expertInfo.setUpdateBy(SecurityUtils.getUsername());
        boolean b= updateById(expertInfo);
        if(!b){
            throw new ServiceException("删除专家信息失败");
        }
        return 1;
    }
 
    @Override
    public int delExpertInfoBatch(Long[] expertIds) {
        return baseMapper.deleteBatchByIds(expertIds);
    }
 
    @Override
    public SysExpertInfo exportInfoDetail(Long expertId) {
        return baseMapper.getExpertInfoById(expertId);
    }
 
   private void checkHavePer(Long expertId){
       SysExpertInfo sysExpertInfo = checkExpertInfoDataScope(expertId);
       if (!SecurityUtils.isAdmin(SecurityUtils.getUserId()) && !sysExpertInfo.getDeptId().toString().equals(SecurityUtils.getDeptId().toString()))
       {
           throw new ServiceException("没有权限操作该专家信息!");
       }
   }
 
 
    public SysExpertInfo checkExpertInfoDataScope(Long expertId) {
        if(expertId==null){
            throw new ServiceException("专家id为空!");
        }
        SysExpertInfo expertInfo = baseMapper.getExpertInfoById(expertId);
        if (ObjectUtil.isNull(expertInfo))
        {
            throw new ServiceException("专家数据不存在!");
        }
        return expertInfo;
    }
 
    @Override
    public boolean changeApprove(SysExpertInfo expertInfo) {
        checkExpertInfoDataScope(expertInfo.getId());
        //SysExpertInfo se=new SysExpertInfo().setId(expertInfo.getId()).setState(expertInfo.getState());
        expertInfo.setUpdateBy(SecurityUtils.getUsername());
//        se.setUpdateBy(SecurityUtils.getUsername());
        return updateById(expertInfo);
    }
 
    @Override
    public SysExpertSearchRep queryApprove(SysExpertSearchReqDto expertInfo) {
        SysExpertSearchRep sysExpertSearchRep = baseMapper.queryApprove(expertInfo);
        if (null == sysExpertSearchRep){
            throw new ServiceException("申请记录不存!");
        }
        return sysExpertSearchRep;
    }
 
    @Override
    public List<ProjectExpertSectionResp> getExpertRound(SysExpertInfoRoundReq req) {
       // req.setDeptId(SecurityUtils.getDeptId());
        return baseMapper.getExpertRound(req);
    }
 
    @Override
    public void batchChangeEmploymentDate(ExpertBatchChangeReq req) {
        if (!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            throw new ServiceException("无权操作!");
        }
 
        baseMapper.update(null, Wrappers.<SysExpertInfo>lambdaUpdate()
                .set(SysExpertInfo::getUpdateBy,SecurityUtils.getUsername())
                .set(SysExpertInfo::getEmploymentDateStart,req.getEmploymentDateStart())
                .set(SysExpertInfo::getEmploymentDateEnd,req.getEmploymentDateEnd())
                .in(SysExpertInfo::getId,req.getId()));
 
    }
 
    public boolean checkIdCardUnique(SysExpertInfo expertInfo){
        Long expertId = expertInfo.getId()==null? -1L : expertInfo.getId();
        SysExpertInfo info = baseMapper.checkIdCardDomainUnique(expertInfo.getPhone(),expertInfo.getIdCard(),expertInfo.getDomain());
        if (info!=null && info.getId().longValue() != expertId.longValue())
        {
            return false;
        }
        return true;
    }
}