13 changed files with 544 additions and 0 deletions
@ -0,0 +1,60 @@ |
|||||
|
// CompanyController.java
|
||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.*; |
||||
|
import cn.iocoder.yudao.module.system.convert.unit.CompanyConvert; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.unit.CompanyDO; |
||||
|
import cn.iocoder.yudao.module.system.service.unit.Company.CompanyService; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import jakarta.validation.Valid; |
||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
||||
|
|
||||
|
@Tag(name = "管理后台 - 集团管理") |
||||
|
@RestController |
||||
|
@RequestMapping("/system/Company") |
||||
|
@Validated |
||||
|
public class CompanyController { |
||||
|
|
||||
|
@Resource |
||||
|
private CompanyService companyService; |
||||
|
|
||||
|
@GetMapping("/page") |
||||
|
@Operation(summary = "获得集团分页列表") |
||||
|
public CommonResult<PageResult<CompanyRespVO>> getCompanyPage(@Valid CompanyPageReqVO reqVO) { |
||||
|
PageResult<CompanyDO> pageResult = companyService.getCompanyPage(reqVO); |
||||
|
return success(CompanyConvert.INSTANCE.convertPage(pageResult)); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("/get") |
||||
|
@Operation(summary = "获得集团详情") |
||||
|
public CommonResult<CompanyRespVO> getCompany(@RequestParam("id") Long id) { |
||||
|
CompanyDO Company = companyService.getCompany(id); |
||||
|
return success(CompanyConvert.INSTANCE.convert(Company)); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("/create") |
||||
|
@Operation(summary = "创建集团") |
||||
|
public CommonResult<Long> createCompany(@Valid @RequestBody CompanyCreateReqVO reqVO) { |
||||
|
return success(companyService.createCompany(CompanyConvert.INSTANCE.convert(reqVO))); |
||||
|
} |
||||
|
|
||||
|
@PutMapping("/update") |
||||
|
@Operation(summary = "修改集团") |
||||
|
public CommonResult<Boolean> updateCompany(@Valid @RequestBody CompanyUpdateReqVO reqVO) { |
||||
|
companyService.updateCompany(CompanyConvert.INSTANCE.convert(reqVO)); |
||||
|
return success(true); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping("/delete") |
||||
|
@Operation(summary = "删除集团") |
||||
|
public CommonResult<Boolean> deleteCompany(@RequestParam("id") Long id) { |
||||
|
companyService.deleteCompany(id); |
||||
|
return success(true); |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 集团基础VO") |
||||
|
@Data |
||||
|
public class CompanyBaseVO { |
||||
|
|
||||
|
@Schema(description = "集团序号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001") |
||||
|
|
||||
|
private Long id; |
||||
|
|
||||
|
@Schema(description = "集团名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试集团") |
||||
|
|
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "集团简称", requiredMode = Schema.RequiredMode.REQUIRED, example = "测试") |
||||
|
|
||||
|
private String shortName; // 修改了字段名,因为short是Java关键字
|
||||
|
|
||||
|
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
||||
|
private Integer status; |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 集团创建请求VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class CompanyCreateReqVO extends CompanyBaseVO { |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 集团分页请求VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class CompanyPageReqVO extends PageParam { |
||||
|
|
||||
|
@Schema(description = "集团名称", example = "测试") |
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "状态", example = "1") |
||||
|
private Integer status; |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 集团响应VO") |
||||
|
@Data |
||||
|
public class CompanyRespVO { |
||||
|
|
||||
|
@Schema(description = "集团编号", example = "1") |
||||
|
private Long id; |
||||
|
|
||||
|
@Schema(description = "集团名称", example = "测试集团") |
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "集团简称", example = "测试") |
||||
|
private String shortName; |
||||
|
|
||||
|
@Schema(description = "状态", example = "1") |
||||
|
private Integer status; |
||||
|
|
||||
|
@Schema(description = "创建时间") |
||||
|
private Date createTime; |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo; |
||||
|
|
||||
|
import jakarta.validation.constraints.NotEmpty; |
||||
|
import jakarta.validation.constraints.NotNull; |
||||
|
import jakarta.validation.constraints.Size; |
||||
|
|
||||
|
public class CompanySaveReqVO { |
||||
|
// 集团编号,用于更新时指定集团
|
||||
|
private Long id; |
||||
|
// 集团名称
|
||||
|
@NotEmpty(message = "集团名称不能为空") |
||||
|
@Size(max = 100, message = "集团名称长度不能超过100个字符") |
||||
|
private String name; |
||||
|
|
||||
|
// 集团简称
|
||||
|
@NotEmpty(message = "集团简称不能为空") |
||||
|
@Size(max = 50, message = "集团简称长度不能超过50个字符") |
||||
|
private String shortName; |
||||
|
|
||||
|
// 集团状态
|
||||
|
@NotNull(message = "集团状态不能为空") |
||||
|
private Integer status; |
||||
|
|
||||
|
// Getter 和 Setter 方法
|
||||
|
public Long getId() { |
||||
|
return id; |
||||
|
} |
||||
|
|
||||
|
public void setId(Long id) { |
||||
|
this.id = id; |
||||
|
} |
||||
|
|
||||
|
public String getName() { |
||||
|
return name; |
||||
|
} |
||||
|
|
||||
|
public void setName(String name) { |
||||
|
this.name = name; |
||||
|
} |
||||
|
|
||||
|
public String getShortName() { |
||||
|
return shortName; |
||||
|
} |
||||
|
|
||||
|
public void setShortName(String shortName) { |
||||
|
this.shortName = shortName; |
||||
|
} |
||||
|
|
||||
|
public Integer getStatus() { |
||||
|
return status; |
||||
|
} |
||||
|
|
||||
|
public void setStatus(Integer status) { |
||||
|
this.status = status; |
||||
|
} |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
|
||||
|
@Schema(description = "管理后台 - 集团更新请求VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class CompanyUpdateReqVO extends CompanyBaseVO { |
||||
|
|
||||
|
@Schema(description = "集团编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
||||
|
private Long id; |
||||
|
} |
@ -0,0 +1,36 @@ |
|||||
|
package cn.iocoder.yudao.module.system.convert.unit; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanyCreateReqVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanyRespVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanySaveReqVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanyUpdateReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.unit.CompanyDO; |
||||
|
import jakarta.validation.Valid; |
||||
|
import org.mapstruct.Mapper; |
||||
|
import org.mapstruct.factory.Mappers; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface CompanyConvert { |
||||
|
|
||||
|
CompanyConvert INSTANCE = Mappers.getMapper(CompanyConvert.class); |
||||
|
|
||||
|
// ========== VO 转 DO ==========
|
||||
|
@Valid |
||||
|
CompanySaveReqVO convert(CompanyCreateReqVO bean); |
||||
|
@Valid |
||||
|
CompanySaveReqVO convert(CompanyUpdateReqVO bean); |
||||
|
|
||||
|
// ========== DO 转 VO ==========
|
||||
|
CompanyRespVO convert(CompanyDO bean); |
||||
|
List<CompanyRespVO> convertList(List<CompanyDO> list); |
||||
|
PageResult<CompanyRespVO> convertPage(PageResult<CompanyDO> page); |
||||
|
|
||||
|
// ========== 自定义转换 ==========
|
||||
|
default CompanyRespVO convertWithExtra(CompanyDO Company, Object extraInfo) { |
||||
|
CompanyRespVO vo = convert(Company); |
||||
|
return vo; |
||||
|
} |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
package cn.iocoder.yudao.module.system.dal.dataobject.unit; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.*; |
||||
|
|
||||
|
/** |
||||
|
* 集团 DO |
||||
|
*/ |
||||
|
@TableName("Company") // 根据您的需求指定表名
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@Builder |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class CompanyDO extends BaseDO { |
||||
|
|
||||
|
/** |
||||
|
* 集团序号 |
||||
|
*/ |
||||
|
@TableId |
||||
|
private Long id; |
||||
|
|
||||
|
/** |
||||
|
|
||||
|
/** |
||||
|
* 集团名称 |
||||
|
*/ |
||||
|
private String name; |
||||
|
|
||||
|
/** |
||||
|
* 集团简称 |
||||
|
*/ |
||||
|
private String shortName; |
||||
|
|
||||
|
/** |
||||
|
* 帐号状态 |
||||
|
* 枚举 {@link CommonStatusEnum} |
||||
|
*/ |
||||
|
private Integer status; |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
// UnitMapper.java
|
||||
|
package cn.iocoder.yudao.module.system.dal.mysql.unit; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanyPageReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.unit.CompanyDO; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface CompanyMapper extends BaseMapperX<CompanyDO> { |
||||
|
|
||||
|
default PageResult<CompanyDO> selectPage(CompanyPageReqVO reqVO) { |
||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<CompanyDO>() |
||||
|
.likeIfPresent(CompanyDO::getName, reqVO.getName()) |
||||
|
.eqIfPresent(CompanyDO::getStatus, reqVO.getStatus()) |
||||
|
.orderByDesc(CompanyDO::getId)); |
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
package cn.iocoder.yudao.module.system.service.unit.Company; |
||||
|
|
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanyPageReqVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanySaveReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.unit.CompanyDO; |
||||
|
|
||||
|
import jakarta.validation.Valid; |
||||
|
import java.util.Collection; |
||||
|
import java.util.List; |
||||
|
public interface CompanyService { |
||||
|
/** |
||||
|
* 创建集团 |
||||
|
* |
||||
|
* @param createReqVO 集团信息 |
||||
|
* @return 集团编号 |
||||
|
*/ |
||||
|
Long createCompany(@Valid CompanySaveReqVO createReqVO); |
||||
|
|
||||
|
/** |
||||
|
* 修改集团 |
||||
|
* |
||||
|
* @param updateReqVO 集团信息 |
||||
|
*/ |
||||
|
void updateCompany(@Valid CompanySaveReqVO updateReqVO); |
||||
|
|
||||
|
/** |
||||
|
* 删除集团 |
||||
|
* |
||||
|
* @param id 集团编号 |
||||
|
*/ |
||||
|
void deleteCompany(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 获得集团分页列表 |
||||
|
* |
||||
|
* @param reqVO 分页条件 |
||||
|
* @return 分页列表 |
||||
|
*/ |
||||
|
PageResult<CompanyDO> getCompanyPage(CompanyPageReqVO reqVO); |
||||
|
|
||||
|
/** |
||||
|
* 通过集团 ID 查询集团 |
||||
|
* |
||||
|
* @param id 集团ID |
||||
|
* @return 集团对象信息 |
||||
|
*/ |
||||
|
CompanyDO getCompany(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 获得集团列表 |
||||
|
* |
||||
|
* @param ids 集团编号数组 |
||||
|
* @return 集团列表 |
||||
|
*/ |
||||
|
List<CompanyDO> getCompanyList(Collection<Long> ids); |
||||
|
|
||||
|
/** |
||||
|
* 校验集团们是否有效。如下情况,视为无效: |
||||
|
* 1. 集团编号不存在 |
||||
|
* 2. 集团被禁用 |
||||
|
* |
||||
|
* @param ids 集团编号数组 |
||||
|
*/ |
||||
|
void validateCompanyList(Collection<Long> ids); |
||||
|
|
||||
|
/** |
||||
|
* 修改集团状态 |
||||
|
* |
||||
|
* @param id 集团编号 |
||||
|
* @param status 状态 |
||||
|
*/ |
||||
|
void updateCompanyStatus(Long id, Integer status); |
||||
|
|
||||
|
/** |
||||
|
* 获得指定状态的集团们 |
||||
|
* |
||||
|
* @param status 状态 |
||||
|
* @return 集团们 |
||||
|
*/ |
||||
|
List<CompanyDO> getCompanyListByStatus(Integer status); |
||||
|
} |
@ -0,0 +1,149 @@ |
|||||
|
// CompanyServiceImpl.java
|
||||
|
package cn.iocoder.yudao.module.system.service.unit.Company; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
||||
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanyPageReqVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.unit.Company.vo.CompanySaveReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.unit.CompanyDO; |
||||
|
import cn.iocoder.yudao.module.system.dal.mysql.unit.CompanyMapper; |
||||
|
import cn.iocoder.yudao.module.system.enums.ErrorCodeConstants; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import java.util.Collection; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
||||
|
|
||||
|
/** |
||||
|
* 集团 Service 实现类 |
||||
|
*/ |
||||
|
@Service |
||||
|
@Validated |
||||
|
public class CompanyServiceImpl implements CompanyService { |
||||
|
|
||||
|
@Resource |
||||
|
private CompanyMapper companyMapper; |
||||
|
|
||||
|
@Override |
||||
|
public Long createCompany(CompanySaveReqVO createReqVO) { |
||||
|
// 校验集团名称唯一性
|
||||
|
validateCompanyNameUnique(createReqVO.getName(), null); |
||||
|
|
||||
|
// 插入
|
||||
|
CompanyDO Company = new CompanyDO(); |
||||
|
|
||||
|
Company.setName(createReqVO.getName()); |
||||
|
Company.setShortName(createReqVO.getShortName()); |
||||
|
Company.setStatus(createReqVO.getStatus()); |
||||
|
companyMapper.insert(Company); |
||||
|
return Company.getId(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateCompany(CompanySaveReqVO updateReqVO) { |
||||
|
// 校验存在
|
||||
|
validateCompanyExists(updateReqVO.getId()); |
||||
|
// 校验集团名称唯一性
|
||||
|
validateCompanyNameUnique(updateReqVO.getName(), updateReqVO.getId()); |
||||
|
|
||||
|
// 更新
|
||||
|
CompanyDO updateObj = new CompanyDO(); |
||||
|
updateObj.setId(updateReqVO.getId()); |
||||
|
updateObj.setName(updateReqVO.getName()); |
||||
|
updateObj.setShortName(updateReqVO.getShortName()); |
||||
|
updateObj.setStatus(updateReqVO.getStatus()); |
||||
|
companyMapper.updateById(updateObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deleteCompany(Long id) { |
||||
|
// 校验存在
|
||||
|
validateCompanyExists(id); |
||||
|
// 删除
|
||||
|
companyMapper.deleteById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PageResult<CompanyDO> getCompanyPage(CompanyPageReqVO reqVO) { |
||||
|
return companyMapper.selectPage(reqVO); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public CompanyDO getCompany(Long id) { |
||||
|
return companyMapper.selectById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<CompanyDO> getCompanyList(Collection<Long> ids) { |
||||
|
if (CollUtil.isEmpty(ids)) { |
||||
|
return List.of(); |
||||
|
} |
||||
|
return companyMapper.selectBatchIds(ids); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void validateCompanyList(Collection<Long> ids) { |
||||
|
if (CollUtil.isEmpty(ids)) { |
||||
|
return; |
||||
|
} |
||||
|
// 获得集团信息
|
||||
|
Map<Long, CompanyDO> CompanyMap = CollectionUtils.convertMap(getCompanyList(ids), CompanyDO::getId); |
||||
|
// 校验
|
||||
|
ids.forEach(id -> { |
||||
|
CompanyDO Company = CompanyMap.get(id); |
||||
|
if (Company == null) { |
||||
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.Company_NOT_EXISTS); |
||||
|
} |
||||
|
if (CommonStatusEnum.DISABLE.getStatus().equals(Company.getStatus())) { |
||||
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.Company_DISABLED); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateCompanyStatus(Long id, Integer status) { |
||||
|
// 校验存在
|
||||
|
validateCompanyExists(id); |
||||
|
|
||||
|
// 更新状态
|
||||
|
CompanyDO updateObj = new CompanyDO(); |
||||
|
updateObj.setId(id); |
||||
|
updateObj.setStatus(status); |
||||
|
companyMapper.updateById(updateObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<CompanyDO> getCompanyListByStatus(Integer status) { |
||||
|
return companyMapper.selectList(new LambdaQueryWrapperX<CompanyDO>() |
||||
|
.eq(CompanyDO::getStatus, status)); |
||||
|
} |
||||
|
|
||||
|
private void validateCompanyExists(Long id) { |
||||
|
if (companyMapper.selectById(id) == null) { |
||||
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.Company_NOT_EXISTS); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void validateCompanyNameUnique(String name, Long id) { |
||||
|
CompanyDO Company = companyMapper.selectOne(new LambdaQueryWrapperX<CompanyDO>() |
||||
|
.eq(CompanyDO::getName, name)); |
||||
|
if (Company == null) { |
||||
|
return; |
||||
|
} |
||||
|
// 如果 id 为空,说明是新增,直接报错
|
||||
|
if (id == null) { |
||||
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.Company_NAME_DUPLICATE); |
||||
|
} |
||||
|
// 如果 id 不为空,但是 id 不匹配,说明有其他集团使用该名称
|
||||
|
if (!Company.getId().equals(id)) { |
||||
|
throw ServiceExceptionUtil.exception(ErrorCodeConstants.Company_NAME_DUPLICATE); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue