package com.cl.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.cl.common.constant.DelFlagConstant;
|
import com.cl.common.context.BaseContext;
|
import com.cl.common.exception.institution.InstitutionException;
|
import com.cl.mapper.InstitutionMapper;
|
import com.cl.pojo.dto.AddInstitutionDTO;
|
import com.cl.pojo.dto.EditInstitutionDTO;
|
import com.cl.pojo.entity.Institution;
|
import com.cl.pojo.vo.InstitutionVO;
|
import com.cl.service.InstitutionService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
@Service
|
public class InstitutionServiceImpl extends ServiceImpl<InstitutionMapper, Institution> implements InstitutionService {
|
@Autowired
|
private InstitutionMapper institutionMapper;
|
@Override
|
public void add(AddInstitutionDTO addDTO) {
|
Institution institution = new Institution();
|
BeanUtils.copyProperties(addDTO, institution);
|
institution.setCreateBy(BaseContext.getCurrentUser().getId());
|
institution.setCreateTime(LocalDateTime.now());
|
boolean save = this.save(institution);
|
if (!save) {
|
throw new InstitutionException("机构新增保存失败");
|
}
|
}
|
|
@Override
|
public IPage<InstitutionVO> pageList(IPage<Institution> page, Integer county, String name) {
|
return institutionMapper.pageList(page,county,name);
|
}
|
|
@Override
|
public InstitutionVO read(Integer id) {
|
LambdaQueryWrapper<Institution> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(Institution::getId, id);
|
queryWrapper.eq(Institution::getDelFlag, DelFlagConstant.UNDELETE);
|
Institution institution = institutionMapper.selectOne(queryWrapper);
|
if (institution == null) {
|
throw new InstitutionException("机构id不存在");
|
}
|
InstitutionVO institutionVO = new InstitutionVO();
|
BeanUtils.copyProperties(institution, institutionVO);
|
return institutionVO;
|
}
|
|
@Override
|
public void edit(EditInstitutionDTO editDTO) {
|
LambdaQueryWrapper<Institution> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(Institution::getId, editDTO.getId());
|
queryWrapper.eq(Institution::getDelFlag, DelFlagConstant.UNDELETE);
|
Institution institution = institutionMapper.selectOne(queryWrapper);
|
if (institution == null) {
|
throw new InstitutionException("机构id不存在");
|
}
|
institution.setCounty(editDTO.getCounty());
|
institution.setType(editDTO.getType());
|
institution.setName(editDTO.getName());
|
institution.setAddress(editDTO.getAddress());
|
institution.setPhone(editDTO.getPhone());
|
institution.setUpdateBy(BaseContext.getCurrentUser().getId());
|
institution.setUpdateTime(LocalDateTime.now());
|
int i = institutionMapper.updateById(institution);
|
if (i != 1) {
|
throw new InstitutionException("机构信息更新失败");
|
}
|
}
|
|
@Override
|
public void delete(Integer id) {
|
LambdaQueryWrapper<Institution> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.eq(Institution::getId, id);
|
queryWrapper.eq(Institution::getDelFlag, DelFlagConstant.UNDELETE);
|
Institution institution = institutionMapper.selectOne(queryWrapper);
|
if (institution == null) {
|
throw new InstitutionException("机构id不存在");
|
}
|
institution.setDelFlag(DelFlagConstant.DELETE);
|
institution.setUpdateBy(BaseContext.getCurrentUser().getId());
|
institution.setUpdateTime(LocalDateTime.now());
|
int i = institutionMapper.updateById(institution);
|
if (i != 1) {
|
throw new InstitutionException("删除机构信息失败");
|
}
|
}
|
|
@Override
|
public List<InstitutionVO> getAll(Integer county) {
|
return institutionMapper.getAll(county);
|
}
|
|
|
}
|