package com.isu.gaswellwatch.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.isu.gaswellwatch.config.SnowflakeConfig; import com.isu.gaswellwatch.service.DepartmentService; import com.isu.gaswellwatch.dao.DepartmentDao; import com.isu.gaswellwatch.dto.*; import com.isu.gaswellwatch.entity.Department; import com.isu.gaswellwatch.exception.BusinessException; import com.isu.gaswellwatch.utils.ConverterUtil; import com.isu.gaswellwatch.vo.DepartmentVO; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service("departmentService") @Transactional(rollbackFor = Exception.class) public class DepartmentServiceImpl extends ServiceImpl implements DepartmentService { @Resource private SnowflakeConfig snowflakeConfig; @Resource private DepartmentDao companyDao; @Override public Page page(Integer currentPage, Integer pageSize, String name, String code){ Page page = companyDao.page(new Page<>(currentPage, pageSize),name,code); return ConverterUtil.convertPage(page, DepartmentVO.class); } @Override public void add(DepartmentDTO companyDTO){ //查重 List list = list(new LambdaQueryWrapper().eq(Department::getName, companyDTO.getName())); if(CollectionUtil.isNotEmpty(list)) { throw new BusinessException("已有相同名称,请重新输入"); } Long companyId = snowflakeConfig.snowflakeId(); save(Department.builder().id(companyId).name(companyDTO.getName()).description(companyDTO.getDescription()).code(companyDTO.getCode()).build()); } @Override public void edit(DepartmentEditDTO departmentEditDTO){ List list = list(new LambdaQueryWrapper().eq(Department::getName, departmentEditDTO.getName()).ne(Department::getId, departmentEditDTO.getId())); if(CollectionUtil.isNotEmpty(list)) { throw new BusinessException("部门名称已存在,请重新输入"); } updateById(ConverterUtil.convert(departmentEditDTO, Department.class)); } @Override public void delete(Long id){ //TODO 如果部门绑定了气井 不能删除 //删除 removeById(id); } }