parent
127138669c
commit
848f228a57
@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.dusttype;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dusttype.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dusttype.DustTypeDO;
|
||||
import cn.iocoder.yudao.module.system.service.dusttype.DustTypeService;
|
||||
|
||||
@Tag(name = "管理后台 - 粉尘种类")
|
||||
@RestController
|
||||
@RequestMapping("/system/dust-type")
|
||||
@Validated
|
||||
public class DustTypeController {
|
||||
|
||||
@Resource
|
||||
private DustTypeService dustTypeService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建粉尘种类")
|
||||
@PreAuthorize("@ss.hasPermission('system:dust-type:create')")
|
||||
public CommonResult<String> createDustType(@Valid @RequestBody DustTypeSaveReqVO createReqVO) {
|
||||
return success(dustTypeService.createDustType(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新粉尘种类")
|
||||
@PreAuthorize("@ss.hasPermission('system:dust-type:update')")
|
||||
public CommonResult<Boolean> updateDustType(@Valid @RequestBody DustTypeSaveReqVO updateReqVO) {
|
||||
dustTypeService.updateDustType(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除粉尘种类")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:dust-type:delete')")
|
||||
public CommonResult<Boolean> deleteDustType(@RequestParam("id") String id) {
|
||||
dustTypeService.deleteDustType(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得粉尘种类")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:dust-type:query')")
|
||||
public CommonResult<DustTypeRespVO> getDustType(@RequestParam("id") String id) {
|
||||
DustTypeDO dustType = dustTypeService.getDustType(id);
|
||||
return success(BeanUtils.toBean(dustType, DustTypeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得粉尘种类列表")
|
||||
@PreAuthorize("@ss.hasPermission('system:dust-type:query')")
|
||||
public CommonResult<List<DustTypeRespVO>> getDustTypeList(@Valid DustTypeListReqVO listReqVO) {
|
||||
List<DustTypeDO> list = dustTypeService.getDustTypeList(listReqVO);
|
||||
return success(BeanUtils.toBean(list, DustTypeRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出粉尘种类 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:dust-type:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDustTypeExcel(@Valid DustTypeListReqVO listReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<DustTypeDO> list = dustTypeService.getDustTypeList(listReqVO);
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "粉尘种类.xls", "数据", DustTypeRespVO.class,
|
||||
BeanUtils.toBean(list, DustTypeRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.dusttype.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 粉尘种类列表 Request VO")
|
||||
@Data
|
||||
public class DustTypeListReqVO {
|
||||
|
||||
@Schema(description = "名称", example = "李四")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "父级", example = "20841")
|
||||
private String parentId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.dusttype.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import cn.idev.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 粉尘种类 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class DustTypeRespVO {
|
||||
|
||||
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A")
|
||||
@ExcelProperty("编码")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@ExcelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "父级", example = "20841")
|
||||
@ExcelProperty("父级")
|
||||
private String parentId;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
@Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("排序")
|
||||
private Integer sort;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.dusttype.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 粉尘种类新增/修改 Request VO")
|
||||
@Data
|
||||
public class DustTypeSaveReqVO {
|
||||
|
||||
@Schema(description = "编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
|
||||
@NotEmpty(message = "名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "父级", example = "20841")
|
||||
private String parentId;
|
||||
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.dusttype;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 粉尘种类 DO
|
||||
*
|
||||
* @author 超级管理员
|
||||
*/
|
||||
@TableName("hazard_dust_type")
|
||||
@KeySequence("hazard_dust_type_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DustTypeDO extends BaseDO {
|
||||
|
||||
public static final String PARENT_ID_ROOT = "0";
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@TableId(type = IdType.INPUT)
|
||||
private String id;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 父级
|
||||
*/
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.dusttype;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dusttype.DustTypeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dusttype.vo.*;
|
||||
|
||||
/**
|
||||
* 粉尘种类 Mapper
|
||||
*
|
||||
* @author 超级管理员
|
||||
*/
|
||||
@Mapper
|
||||
public interface DustTypeMapper extends BaseMapperX<DustTypeDO> {
|
||||
|
||||
default List<DustTypeDO> selectList(DustTypeListReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<DustTypeDO>()
|
||||
.likeIfPresent(DustTypeDO::getName, reqVO.getName())
|
||||
.eqIfPresent(DustTypeDO::getParentId, reqVO.getParentId())
|
||||
.betweenIfPresent(DustTypeDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByAsc(DustTypeDO::getSort));
|
||||
}
|
||||
|
||||
default DustTypeDO selectByParentIdAndName(String parentId, String name) {
|
||||
return selectOne(DustTypeDO::getParentId, parentId, DustTypeDO::getName, name);
|
||||
}
|
||||
|
||||
default Long selectCountByParentId(String parentId) {
|
||||
return selectCount(DustTypeDO::getParentId, parentId);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.iocoder.yudao.module.system.service.dusttype;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dusttype.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dusttype.DustTypeDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 粉尘种类 Service 接口
|
||||
*
|
||||
* @author 超级管理员
|
||||
*/
|
||||
public interface DustTypeService {
|
||||
|
||||
/**
|
||||
* 创建粉尘种类
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
String createDustType(@Valid DustTypeSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新粉尘种类
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateDustType(@Valid DustTypeSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除粉尘种类
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteDustType(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 获得粉尘种类
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 粉尘种类
|
||||
*/
|
||||
DustTypeDO getDustType(String id);
|
||||
|
||||
/**
|
||||
* 获得粉尘种类列表
|
||||
*
|
||||
* @param listReqVO 查询条件
|
||||
* @return 粉尘种类列表
|
||||
*/
|
||||
List<DustTypeDO> getDustTypeList(DustTypeListReqVO listReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,141 @@
|
||||
package cn.iocoder.yudao.module.system.service.dusttype;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dusttype.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dusttype.DustTypeDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dusttype.DustTypeMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 粉尘种类 Service 实现类
|
||||
*
|
||||
* @author 超级管理员
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class DustTypeServiceImpl implements DustTypeService {
|
||||
|
||||
@Resource
|
||||
private DustTypeMapper dustTypeMapper;
|
||||
|
||||
@Override
|
||||
public String createDustType(DustTypeSaveReqVO createReqVO) {
|
||||
// 校验父级的有效性
|
||||
validateParentDustType(null, createReqVO.getParentId());
|
||||
// 校验名称的唯一性
|
||||
validateDustTypeNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
|
||||
|
||||
// 插入
|
||||
DustTypeDO dustType = BeanUtils.toBean(createReqVO, DustTypeDO.class);
|
||||
dustTypeMapper.insert(dustType);
|
||||
|
||||
// 返回
|
||||
return dustType.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDustType(DustTypeSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateDustTypeExists(updateReqVO.getId());
|
||||
// 校验父级的有效性
|
||||
validateParentDustType(updateReqVO.getId(), updateReqVO.getParentId());
|
||||
// 校验名称的唯一性
|
||||
validateDustTypeNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
|
||||
|
||||
// 更新
|
||||
DustTypeDO updateObj = BeanUtils.toBean(updateReqVO, DustTypeDO.class);
|
||||
dustTypeMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDustType(String id) {
|
||||
// 校验存在
|
||||
validateDustTypeExists(id);
|
||||
// 校验是否有子粉尘种类
|
||||
if (dustTypeMapper.selectCountByParentId(id) > 0) {
|
||||
throw exception(DUST_TYPE_EXITS_CHILDREN);
|
||||
}
|
||||
// 删除
|
||||
dustTypeMapper.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
private void validateDustTypeExists(String id) {
|
||||
if (dustTypeMapper.selectById(id) == null) {
|
||||
throw exception(DUST_TYPE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateParentDustType(String id, String parentId) {
|
||||
if (parentId == null || DustTypeDO.PARENT_ID_ROOT.equals(parentId)) {
|
||||
return;
|
||||
}
|
||||
// 1. 不能设置自己为父粉尘种类
|
||||
if (Objects.equals(id, parentId)) {
|
||||
throw exception(DUST_TYPE_PARENT_ERROR);
|
||||
}
|
||||
// 2. 父粉尘种类不存在
|
||||
DustTypeDO parentDustType = dustTypeMapper.selectById(parentId);
|
||||
if (parentDustType == null) {
|
||||
throw exception(DUST_TYPE_PARENT_NOT_EXITS);
|
||||
}
|
||||
// 3. 递归校验父粉尘种类,如果父粉尘种类是自己的子粉尘种类,则报错,避免形成环路
|
||||
if (id == null) { // id 为空,说明新增,不需要考虑环路
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) {
|
||||
// 3.1 校验环路
|
||||
parentId = parentDustType.getParentId();
|
||||
if (Objects.equals(id, parentId)) {
|
||||
throw exception(DUST_TYPE_PARENT_IS_CHILD);
|
||||
}
|
||||
// 3.2 继续递归下一级父粉尘种类
|
||||
if (parentId == null || DustTypeDO.PARENT_ID_ROOT.equals(parentId)) {
|
||||
break;
|
||||
}
|
||||
parentDustType = dustTypeMapper.selectById(parentId);
|
||||
if (parentDustType == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDustTypeNameUnique(String id, String parentId, String name) {
|
||||
DustTypeDO dustType = dustTypeMapper.selectByParentIdAndName(parentId, name);
|
||||
if (dustType == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的粉尘种类
|
||||
if (id == null) {
|
||||
throw exception(DUST_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
if (!Objects.equals(dustType.getId(), id)) {
|
||||
throw exception(DUST_TYPE_NAME_DUPLICATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DustTypeDO getDustType(String id) {
|
||||
return dustTypeMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DustTypeDO> getDustTypeList(DustTypeListReqVO listReqVO) {
|
||||
return dustTypeMapper.selectList(listReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue