kongzy
2023-12-08 ca5445257b1fdeceddf3fcc2dea18c442023aeb7
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
package com.gkhy.assess.system.service.impl;
 
import com.gkhy.assess.common.api.CommonPage;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.common.utils.PageUtil;
import com.gkhy.assess.system.domain.SysAgency;
import com.gkhy.assess.system.domain.SysExpertInfo;
import com.gkhy.assess.system.domain.SysUser;
import com.gkhy.assess.system.mapper.SysExpertInfoMapper;
import com.gkhy.assess.system.service.SysExpertInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.assess.system.utils.ShiroUtils;
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 CommonPage exportInfoList(SysExpertInfo expertInfo) {
        PageUtil.startPage();
        List<SysExpertInfo> agencyList=baseMapper.expertInfoList(expertInfo);
        return CommonPage.restPage(agencyList);
    }
 
    @Override
    public int addExpertInfo(SysExpertInfo expertInfo) {
        if(!checkIdCardUnique(new SysExpertInfo().setIdCard(expertInfo.getIdCard()))){
            throw new ApiException(expertInfo.getIdCard()+"身份证号码已经存在");
        }
        expertInfo.setCreateBy(ShiroUtils.getSysUser().getUsername());
        boolean b=save(expertInfo);
        if(!b){
            throw new ApiException("新增专家信息失败");
        }
        return 1;
    }
 
    @Override
    public int modExpertInfo(SysExpertInfo expertInfo) {
        if(!checkIdCardUnique(expertInfo)){
            throw new ApiException(expertInfo.getIdCard()+"身份证号码已经存在");
        }
        boolean b=updateById(expertInfo);
        if(!b){
            throw new ApiException("修改专家信息失败");
        }
        return 1;
    }
 
    @Override
    public int delExpertInfo(Long expertId) {
        SysExpertInfo expertInfo = new SysExpertInfo();
        expertInfo.setExpertId(expertId);
        expertInfo.setDelFlag(1);
        boolean b= updateById(expertInfo);
        if(!b){
            throw new ApiException("删除专家信息失败");
        }
        return 1;
    }
 
    @Override
    public int delExpertInfoBatch(Long[] expertIds) {
        return baseMapper.deleteBatchByIds(expertIds);
    }
 
    public boolean checkIdCardUnique(SysExpertInfo expertInfo){
        Long expertId = expertInfo.getExpertId()==null? -1L : expertInfo.getExpertId();
        SysExpertInfo info = baseMapper.checkIdcardUnique(expertInfo.getIdCard());
        if (info!=null && info.getExpertId().longValue() != expertId.longValue())
        {
            return false;
        }
        return true;
    }
}