package com.gkhy.assess.system.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.gkhy.assess.common.api.CommonPage;
import com.gkhy.assess.common.enums.DeleteFlagEnum;
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;
/**
*
* 系统专家信息表 服务实现类
*
*
* @author kzy
* @since 2023-11-27 16:33:33
*/
@Service
public class SysExpertInfoServiceImpl extends ServiceImpl implements SysExpertInfoService {
@Override
public CommonPage exportInfoList(SysExpertInfo expertInfo) {
PageUtil.startPage();
List 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()+"身份证号码已经存在");
}
expertInfo.setUpdateBy(ShiroUtils.getSysUser().getUsername());
boolean b=updateById(expertInfo);
if(!b){
throw new ApiException("修改专家信息失败");
}
return 1;
}
@Override
public int delExpertInfo(Long expertId) {
SysExpertInfo expertInfo = new SysExpertInfo();
expertInfo.setId(expertId);
expertInfo.setDelFlag(DeleteFlagEnum.DELETED.getCode());
expertInfo.setUpdateBy(ShiroUtils.getSysUser().getUsername());
boolean b= updateById(expertInfo);
if(!b){
throw new ApiException("删除专家信息失败");
}
return 1;
}
@Override
public int delExpertInfoBatch(Long[] expertIds) {
return baseMapper.deleteBatchByIds(expertIds);
}
@Override
public SysExpertInfo exportInfoDetail(Long expertId) {
return baseMapper.getExpertInfoById(expertId);
}
public SysExpertInfo checkExpertInfoDataScope(Long expertId) {
if(expertId==null){
throw new ApiException("专家id为空!");
}
SysExpertInfo expertInfo = baseMapper.getExpertInfoById(expertId);
if (ObjectUtil.isNull(expertInfo))
{
throw new ApiException("专家数据不存在!");
}
return expertInfo;
}
@Override
public boolean changeApprove(SysExpertInfo expertInfo) {
checkExpertInfoDataScope(expertInfo.getId());
SysExpertInfo se=new SysExpertInfo().setId(expertInfo.getId()).setState(expertInfo.getState());
se.setUpdateBy(ShiroUtils.getSysUser().getUsername());
return updateById(se);
}
public boolean checkIdCardUnique(SysExpertInfo expertInfo){
Long expertId = expertInfo.getId()==null? -1L : expertInfo.getId();
SysExpertInfo info = baseMapper.checkIdcardUnique(expertInfo.getIdCard());
if (info!=null && info.getId().longValue() != expertId.longValue())
{
return false;
}
return true;
}
}