设备类型维护,表单开发中增加设备类型下拉所需的接口增加、修改
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package com.lideeyunji.service.system.controller;
|
||||
|
||||
import com.lideeyunji.service.system.controller.vo.dept.dept.DeptRespVO;
|
||||
import com.lideeyunji.service.system.controller.vo.dept.dept.DeptSimpleRespVO;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxListReqVO;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxRespVO;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxSaveReqVO;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxSimpleRespVO;
|
||||
import com.lideeyunji.service.system.entity.SblxDO;
|
||||
import com.lideeyunji.service.system.service.ISblxService;
|
||||
import com.lideeyunji.tool.framework.common.pojo.CommonResult;
|
||||
import com.lideeyunji.tool.framework.common.util.object.BeanUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static com.lideeyunji.tool.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - 设备类型")
|
||||
@RestController
|
||||
@RequestMapping("/system/sblx")
|
||||
@Validated
|
||||
public class SblxController {
|
||||
|
||||
@Resource
|
||||
private ISblxService sblxService;
|
||||
|
||||
@PostMapping("create")
|
||||
@Operation(tags = "设备类型管理",summary = "创建设备类型")
|
||||
@PreAuthorize("@ss.hasPermission('system:sblx:create')")
|
||||
public CommonResult<Long> createSblx(@Valid @RequestBody SblxSaveReqVO createReqVO) {
|
||||
Long deptId = sblxService.createSblx(createReqVO);
|
||||
return success(deptId);
|
||||
}
|
||||
|
||||
@PutMapping("update")
|
||||
@Operation(tags = "设备类型管理",summary = "更新设备类型")
|
||||
@PreAuthorize("@ss.hasPermission('system:sblx:update')")
|
||||
public CommonResult<Boolean> updateSblx(@Valid @RequestBody SblxSaveReqVO updateReqVO) {
|
||||
sblxService.updateSblx(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("delete")
|
||||
@Operation(tags = "设备类型管理",summary = "删除设备类型")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:sblx:delete')")
|
||||
public CommonResult<Boolean> deleteSblx(@RequestParam("id") Long id) {
|
||||
sblxService.deleteSblx(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(tags = "设备类型管理",summary = "获取设备类型列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:sblx:query')")
|
||||
public CommonResult<List<SblxRespVO>> getSblxList(SblxListReqVO reqVO) {
|
||||
List<SblxDO> list = sblxService.getSblxList(reqVO);
|
||||
return success(BeanUtils.toBean(list, SblxRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/list-all-simple", "/simple-list"})
|
||||
@Operation(tags = "设备类型管理",summary = "获取设备类型精简信息列表", description = "主要用于前端的下拉选项")
|
||||
public CommonResult<List<SblxSimpleRespVO>> getSimpleDeptList() {
|
||||
List<SblxDO> list = sblxService.getSblxList(
|
||||
new SblxListReqVO());
|
||||
return success(BeanUtils.toBean(list, SblxSimpleRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(tags = "设备类型管理",summary = "获得设备类型信息")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:sblx:query')")
|
||||
public CommonResult<DeptRespVO> getDept(@RequestParam("id") Long id) {
|
||||
SblxDO sblx = sblxService.getSblx(id);
|
||||
return success(BeanUtils.toBean(sblx, DeptRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.lideeyunji.service.system.controller.vo.sblx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 设备类型列表 Request VO")
|
||||
@Data
|
||||
public class SblxListReqVO {
|
||||
|
||||
@Schema(description = "设备类型名称,模糊匹配" )
|
||||
private String industryName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.lideeyunji.service.system.controller.vo.sblx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 设备类型信息 Response VO")
|
||||
@Data
|
||||
public class SblxRespVO {
|
||||
|
||||
@Schema(description = "设备类型编号", example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "设备类型名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String industryName;
|
||||
|
||||
@Schema(description = "设备类型编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String industryCode;
|
||||
|
||||
@Schema(description = "父设备类型 ID", example = "1024")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.lideeyunji.service.system.controller.vo.sblx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Schema(description = "管理后台 - 设备类型创建/修改 Request VO")
|
||||
@Data
|
||||
public class SblxSaveReqVO {
|
||||
|
||||
@Schema(description = "设备类型id", example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "设备类型名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "设备类型名称不能为空")
|
||||
@Size(max = 30, message = "设备类型名称长度不能超过 30 个字符")
|
||||
private String industryName;
|
||||
|
||||
@Schema(description = "设备类型编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "设备类型编码不能为空")
|
||||
@Size(max = 30, message = "设备类型编码长度不能超过 30 个字符")
|
||||
private String industryCode;
|
||||
|
||||
@Schema(description = "父设备类型 ID", example = "1024")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "显示顺序不能为空", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
@NotNull(message = "显示顺序不能为空")
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.lideeyunji.service.system.controller.vo.sblx;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Schema(description = "管理后台 - 设备类型精简信息 Response VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SblxSimpleRespVO {
|
||||
|
||||
@Schema(description = "设备类型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "设备类型名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String industryName;
|
||||
|
||||
@Schema(description = "父设备类型 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long parentId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.lideeyunji.service.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.lideeyunji.tool.framework.common.enums.CommonStatusEnum;
|
||||
import com.lideeyunji.tool.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.lideeyunji.tool.framework.tenant.core.db.TenantBaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 设备类型表
|
||||
*
|
||||
*/
|
||||
@TableName("dev_sblx")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SblxDO extends BaseDO {
|
||||
|
||||
public static final Long PARENT_ID_ROOT = 0L;
|
||||
|
||||
/**
|
||||
* 设备类型ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 设备类型名称
|
||||
*/
|
||||
private String industryName;
|
||||
|
||||
/**
|
||||
* 设备类型编码
|
||||
*/
|
||||
private String industryCode;
|
||||
|
||||
/**
|
||||
* 父设备类型ID
|
||||
*
|
||||
* 关联 {@link #id}
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lideeyunji.service.system.mapper;
|
||||
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxListReqVO;
|
||||
import com.lideeyunji.service.system.entity.SblxDO;
|
||||
import com.lideeyunji.tool.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.lideeyunji.tool.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SblxMapper extends BaseMapperX<SblxDO> {
|
||||
|
||||
default List<SblxDO> selectList(SblxListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<SblxDO>()
|
||||
.likeIfPresent(SblxDO::getIndustryName, reqVO.getIndustryName()));
|
||||
}
|
||||
|
||||
default SblxDO selectByParentIdAndName(Long parentId, String name) {
|
||||
return selectOne(SblxDO::getParentId, parentId, SblxDO::getIndustryName, name);
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(Long parentId) {
|
||||
return selectCount(SblxDO::getParentId, parentId);
|
||||
}
|
||||
|
||||
default List<SblxDO> selectListByParentId(Collection<Long> parentIds) {
|
||||
return selectList(SblxDO::getParentId, parentIds);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.lideeyunji.service.system.service;
|
||||
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxListReqVO;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxSaveReqVO;
|
||||
import com.lideeyunji.service.system.entity.SblxDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备类型 Service 接口
|
||||
*
|
||||
*/
|
||||
public interface ISblxService {
|
||||
|
||||
/**
|
||||
* 创建设备类型
|
||||
*
|
||||
* @param createReqVO 设备类型信息
|
||||
* @return id
|
||||
*/
|
||||
Long createSblx(SblxSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新设备类型信息
|
||||
*
|
||||
* @param updateReqVO 设备类型信息
|
||||
*/
|
||||
void updateSblx(SblxSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除设备类型信息
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteSblx(Long id);
|
||||
|
||||
/**
|
||||
* 获得设备类型信息
|
||||
*
|
||||
* @param id
|
||||
* @return 设备类型信息
|
||||
*/
|
||||
SblxDO getSblx(Long id);
|
||||
|
||||
/**
|
||||
* 筛选设备类型列表
|
||||
*
|
||||
* @param reqVO 筛选条件请求 VO
|
||||
* @return 设备类型信息列表
|
||||
*/
|
||||
List<SblxDO> getSblxList(SblxListReqVO reqVO);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.lideeyunji.service.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxListReqVO;
|
||||
import com.lideeyunji.service.system.controller.vo.sblx.SblxSaveReqVO;
|
||||
import com.lideeyunji.service.system.entity.SblxDO;
|
||||
import com.lideeyunji.service.system.mapper.SblxMapper;
|
||||
import com.lideeyunji.service.system.service.ISblxService;
|
||||
import com.lideeyunji.tool.framework.common.util.object.BeanUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.lideeyunji.service.system.constant.ErrorCodeConstants.*;
|
||||
import static com.lideeyunji.tool.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 设备类型 Service 实现类
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class SblxServiceImpl implements ISblxService {
|
||||
|
||||
@Resource
|
||||
private SblxMapper sblxMapper;
|
||||
|
||||
@Override
|
||||
public Long createSblx(SblxSaveReqVO createReqVO) {
|
||||
if (createReqVO.getParentId() == null) {
|
||||
createReqVO.setParentId(SblxDO.PARENT_ID_ROOT);
|
||||
}
|
||||
// 校验父部门的有效性
|
||||
validateParentDept(null, createReqVO.getParentId());
|
||||
// 校验部门名的唯一性
|
||||
validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getIndustryName());
|
||||
|
||||
// 插入
|
||||
SblxDO sblx = BeanUtils.toBean(createReqVO, SblxDO.class);
|
||||
sblxMapper.insert(sblx);
|
||||
return sblx.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSblx(SblxSaveReqVO updateReqVO) {
|
||||
if (updateReqVO.getParentId() == null) {
|
||||
updateReqVO.setParentId(SblxDO.PARENT_ID_ROOT);
|
||||
}
|
||||
// 校验自己存在
|
||||
validateDeptExists(updateReqVO.getId());
|
||||
// 校验父部门的有效性
|
||||
validateParentDept(updateReqVO.getId(), updateReqVO.getParentId());
|
||||
// 校验部门名的唯一性
|
||||
validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getIndustryName());
|
||||
|
||||
// 更新
|
||||
SblxDO updateObj = BeanUtils.toBean(updateReqVO, SblxDO.class);
|
||||
sblxMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSblx(Long id) {
|
||||
// 校验是否存在
|
||||
validateDeptExists(id);
|
||||
// 校验是否有子部门
|
||||
if (sblxMapper.selectCountByParentId(id) > 0) {
|
||||
throw exception(SBLX_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除部门
|
||||
sblxMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateDeptExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
SblxDO sblx = sblxMapper.selectById(id);
|
||||
if (sblx == null) {
|
||||
throw exception(SBLX_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateParentDept(Long id, Long parentId) {
|
||||
if (parentId == null || SblxDO.PARENT_ID_ROOT.equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 1. 不能设置自己为父部门
|
||||
if (Objects.equals(id, parentId)) {
|
||||
throw exception(SBLX_PARENT_ERROR);
|
||||
}
|
||||
// 2. 父部门不存在
|
||||
SblxDO parentSblx = sblxMapper.selectById(parentId);
|
||||
if (parentSblx == null) {
|
||||
throw exception(SBLX_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 3. 递归校验父部门,如果父部门是自己的子部门,则报错,避免形成环路
|
||||
if (id == null) { // id 为空,说明新增,不需要考虑环路
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) {
|
||||
// 3.1 校验环路
|
||||
parentId = parentSblx.getParentId();
|
||||
if (Objects.equals(id, parentId)) {
|
||||
throw exception(SBLX_PARENT_IS_CHILD);
|
||||
}
|
||||
// 3.2 继续递归下一级父部门
|
||||
if (parentId == null || SblxDO.PARENT_ID_ROOT.equals(parentId)) {
|
||||
break;
|
||||
}
|
||||
parentSblx = sblxMapper.selectById(parentId);
|
||||
if (parentSblx == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateDeptNameUnique(Long id, Long parentId, String name) {
|
||||
SblxDO sblx = sblxMapper.selectByParentIdAndName(parentId, name);
|
||||
if (sblx == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的部门
|
||||
if (id == null) {
|
||||
throw exception(SBLX_NAME_DUPLICATE);
|
||||
}
|
||||
if (ObjectUtil.notEqual(sblx.getId(), id)) {
|
||||
throw exception(SBLX_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SblxDO getSblx(Long id) {
|
||||
return sblxMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SblxDO> getSblxList(SblxListReqVO reqVO) {
|
||||
List<SblxDO> list = sblxMapper.selectList(reqVO);
|
||||
list.sort(Comparator.comparing(SblxDO::getSort));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user