farm模块-二级字典抽取
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.twodict;
|
||||
|
||||
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.farm.controller.admin.twodict.vo.TwoDictPageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictRespVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictTreeRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.twodict.TwoDictDO;
|
||||
import cn.iocoder.yudao.module.farm.service.twodict.TwoDictService;
|
||||
|
||||
@Tag(name = "管理后台 - 二级字典")
|
||||
@RestController
|
||||
@RequestMapping("/farm/two-dict")
|
||||
@Validated
|
||||
public class TwoDictController {
|
||||
|
||||
@Resource
|
||||
private TwoDictService twoDictService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建二级字典")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:create')")
|
||||
public CommonResult<Long> createTwoDict(@Valid @RequestBody TwoDictSaveReqVO createReqVO) {
|
||||
return success(twoDictService.createTwoDict(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新二级字典")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:update')")
|
||||
public CommonResult<Boolean> updateTwoDict(@Valid @RequestBody TwoDictSaveReqVO updateReqVO) {
|
||||
twoDictService.updateTwoDict(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除二级字典")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:delete')")
|
||||
public CommonResult<Boolean> deleteTwoDict(@RequestParam("id") Long id) {
|
||||
twoDictService.deleteTwoDict(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除二级字典")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:delete')")
|
||||
public CommonResult<Boolean> deleteTwoDictList(@RequestParam("ids") List<Long> ids) {
|
||||
twoDictService.deleteTwoDictListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得二级字典")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
||||
public CommonResult<TwoDictRespVO> getTwoDict(@RequestParam("id") Long id) {
|
||||
TwoDictDO twoDict = twoDictService.getTwoDict(id);
|
||||
return success(BeanUtils.toBean(twoDict, TwoDictRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得二级字典分页")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
||||
public CommonResult<PageResult<TwoDictRespVO>> getTwoDictPage(@Valid TwoDictPageReqVO pageReqVO) {
|
||||
PageResult<TwoDictDO> pageResult = twoDictService.getTwoDictPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, TwoDictRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出二级字典 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportTwoDictExcel(@Valid TwoDictPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<TwoDictDO> list = twoDictService.getTwoDictPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "二级字典.xls", "数据", TwoDictRespVO.class,
|
||||
BeanUtils.toBean(list, TwoDictRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/tree")
|
||||
@Operation(summary = "获得二级字典树形结构")
|
||||
@PreAuthorize("@ss.hasPermission('farm:two-dict:query')")
|
||||
public CommonResult<List<TwoDictTreeRespVO>> getTwoDictTree() {
|
||||
List<TwoDictTreeRespVO> tree = twoDictService.getTwoDictTree();
|
||||
return success(tree);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.twodict.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 二级字典分页 Request VO")
|
||||
@Data
|
||||
public class TwoDictPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "主键ID", example = "31986")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父级id", example = "29268")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "启用状态", example = "1")
|
||||
private Boolean status;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "租户ID", example = "4364")
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.twodict.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 TwoDictRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31986")
|
||||
@ExcelProperty("主键ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父级id", example = "29268")
|
||||
@ExcelProperty("父级id")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "名称", example = "王五")
|
||||
@ExcelProperty("名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("启用状态")
|
||||
private Boolean status;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "租户ID", example = "4364")
|
||||
@ExcelProperty("租户ID")
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.twodict.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 TwoDictSaveReqVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31986")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父级id", example = "29268")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "启用状态不能为空")
|
||||
private Boolean status;
|
||||
|
||||
@Schema(description = "租户ID", example = "4364")
|
||||
private String tenantId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.module.farm.controller.admin.twodict.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 二级字典树形结构 Response VO")
|
||||
@Data
|
||||
public class TwoDictTreeRespVO {
|
||||
|
||||
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "31986")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "父级id", example = "29268")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "名称", example = "王五")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "启用状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Boolean status;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "租户ID", example = "4364")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "子节点列表")
|
||||
private List<TwoDictTreeRespVO> children;
|
||||
|
||||
@Schema(description = "是否为叶子节点", example = "true")
|
||||
private Boolean leaf;
|
||||
|
||||
@Schema(description = "层级", example = "1")
|
||||
private Integer level;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.module.farm.dal.dataobject.twodict;
|
||||
|
||||
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("farm_two_dict")
|
||||
@KeySequence("farm_two_dict_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TwoDictDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 父级id
|
||||
*/
|
||||
private Long parentId;
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 启用状态
|
||||
*/
|
||||
private Boolean status;
|
||||
|
||||
private String tenantId;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public interface FarmingTypeMaintenanceMapper extends BaseMapperX<FarmingTypeMai
|
||||
);
|
||||
}
|
||||
|
||||
List<FarmingTypeMaintenanceDO> listForFarmingType(@Param("req") FarmingTypeMaintenanceSaveReqVO reqVO );
|
||||
List<FarmingTypeMaintenanceDO> listForFarmingType();
|
||||
|
||||
Boolean update(@Param("req") FarmingTypeMaintenanceDO reqVO);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cn.iocoder.yudao.module.farm.dal.mysql.twodict;
|
||||
|
||||
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.farm.dal.dataobject.twodict.TwoDictDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.*;
|
||||
|
||||
/**
|
||||
* 二级字典 Mapper
|
||||
*
|
||||
* @author 万懋超级管理
|
||||
*/
|
||||
@Mapper
|
||||
public interface TwoDictMapper extends BaseMapperX<TwoDictDO> {
|
||||
|
||||
default PageResult<TwoDictDO> selectPage(TwoDictPageReqVO pageReqVO) {
|
||||
return selectPage(pageReqVO, new LambdaQueryWrapperX<TwoDictDO>()
|
||||
.eqIfPresent(TwoDictDO::getId, pageReqVO.getId())
|
||||
.eqIfPresent(TwoDictDO::getParentId, pageReqVO.getParentId())
|
||||
.likeIfPresent(TwoDictDO::getName, pageReqVO.getName())
|
||||
.eqIfPresent(TwoDictDO::getStatus, pageReqVO.getStatus())
|
||||
.eqIfPresent(TwoDictDO::getTenantId, pageReqVO.getTenantId())
|
||||
.betweenIfPresent(TwoDictDO::getCreateTime, pageReqVO.getCreateTime())
|
||||
.orderByDesc(TwoDictDO::getId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有二级字典数据
|
||||
*
|
||||
* @return 所有二级字典数据
|
||||
*/
|
||||
default List<TwoDictDO> selectAll(long tenantId) {
|
||||
return selectList(new LambdaQueryWrapperX<TwoDictDO>()
|
||||
.eqIfPresent(TwoDictDO::getTenantId, tenantId)
|
||||
.orderByAsc(TwoDictDO::getParentId)
|
||||
.orderByAsc(TwoDictDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,6 +111,10 @@ public interface ErrorCodeConstants {
|
||||
// ========== 网格 1_050_033_000 ==========
|
||||
ErrorCode GRID_INFO_NOT_EXISTS = new ErrorCode(1_050_033_000, "网格不存在");
|
||||
|
||||
// ========== 设备报警 1_050_033_000 ==========
|
||||
// ========== 设备报警 1_050_034_000 ==========
|
||||
ErrorCode DEVICE_ALARM_NOT_EXISTS = new ErrorCode(1_050_034_000, "设备报警不存在");
|
||||
|
||||
// ========== 设备报警 1_050_035_000 ==========
|
||||
ErrorCode TWO_DICT_NOT_EXISTS = new ErrorCode(1_050_035_000, "字典不存在");
|
||||
|
||||
}
|
||||
@@ -89,10 +89,7 @@ public class FarmingTypeMaintenanceServiceImpl implements FarmingTypeMaintenance
|
||||
|
||||
@Override
|
||||
public List<FarmingTypeMaintenanceDO> getFarmingTypeList() {
|
||||
FarmingTypeMaintenanceSaveReqVO reqVO = new FarmingTypeMaintenanceSaveReqVO();
|
||||
reqVO.setDeleted(CommonConstants.NO_CODE);
|
||||
|
||||
return farmingTypeMaintenanceMapper.listForFarmingType(reqVO);
|
||||
return farmingTypeMaintenanceMapper.listForFarmingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package cn.iocoder.yudao.module.farm.service.twodict;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.*;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.twodict.TwoDictDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 二级字典 Service 接口
|
||||
*
|
||||
* @author 万懋超级管理
|
||||
*/
|
||||
public interface TwoDictService {
|
||||
|
||||
/**
|
||||
* 创建二级字典
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createTwoDict(@Valid TwoDictSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新二级字典
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateTwoDict(@Valid TwoDictSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除二级字典
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteTwoDict(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除二级字典
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteTwoDictListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得二级字典
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 二级字典
|
||||
*/
|
||||
TwoDictDO getTwoDict(Long id);
|
||||
|
||||
/**
|
||||
* 获得二级字典分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 二级字典分页
|
||||
*/
|
||||
PageResult<TwoDictDO> getTwoDictPage(TwoDictPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得二级字典树形结构
|
||||
*
|
||||
* @return 二级字典树形结构
|
||||
*/
|
||||
List<TwoDictTreeRespVO> getTwoDictTree();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package cn.iocoder.yudao.module.farm.service.twodict;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictPageReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictSaveReqVO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictTreeRespVO;
|
||||
import cn.iocoder.yudao.module.farm.dal.dataobject.twodict.TwoDictDO;
|
||||
import cn.iocoder.yudao.module.farm.dal.mysql.twodict.TwoDictMapper;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
import static cn.iocoder.yudao.module.farm.enums.ErrorCodeConstants.TWO_DICT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 二级字典 Service 实现类
|
||||
*
|
||||
* @author 万懋超级管理
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class TwoDictServiceImpl implements TwoDictService {
|
||||
|
||||
@Resource
|
||||
private TwoDictMapper twoDictMapper;
|
||||
|
||||
@Override
|
||||
public Long createTwoDict(TwoDictSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
TwoDictDO twoDict = BeanUtils.toBean(createReqVO, TwoDictDO.class);
|
||||
twoDictMapper.insert(twoDict);
|
||||
|
||||
// 返回
|
||||
return twoDict.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTwoDict(TwoDictSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTwoDictExists(updateReqVO.getId());
|
||||
// 更新
|
||||
TwoDictDO updateObj = BeanUtils.toBean(updateReqVO, TwoDictDO.class);
|
||||
twoDictMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTwoDict(Long id) {
|
||||
// 校验存在
|
||||
validateTwoDictExists(id);
|
||||
// 删除
|
||||
twoDictMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTwoDictListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
twoDictMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateTwoDictExists(Long id) {
|
||||
if (twoDictMapper.selectById(id) == null) {
|
||||
throw exception(TWO_DICT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TwoDictDO getTwoDict(Long id) {
|
||||
return twoDictMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<TwoDictDO> getTwoDictPage(TwoDictPageReqVO pageReqVO) {
|
||||
pageReqVO.setTenantId(getLoginUser().getTenantId().toString());
|
||||
return twoDictMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TwoDictTreeRespVO> getTwoDictTree() {
|
||||
// 获取当前用户租户ID
|
||||
Long tenantId = getLoginUser().getTenantId();
|
||||
// 获取所有数据(临时移除租户ID过滤进行测试)
|
||||
List<TwoDictDO> allDicts = twoDictMapper.selectAll(tenantId);
|
||||
// 如果上面查询为空,尝试不传租户ID查询所有数据
|
||||
if (allDicts == null || allDicts.isEmpty()) {
|
||||
allDicts = twoDictMapper.selectList(new LambdaQueryWrapperX<TwoDictDO>()
|
||||
.orderByAsc(TwoDictDO::getParentId)
|
||||
.orderByAsc(TwoDictDO::getId));
|
||||
}
|
||||
// 构建树形结构 - 注意:数据库中的根节点parentId是null,不是0
|
||||
List<TwoDictTreeRespVO> result = buildTree(allDicts, null, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建树形结构
|
||||
*
|
||||
* @param allDicts 所有字典数据
|
||||
* @param parentId 父级ID
|
||||
* @param level 当前层级
|
||||
* @return 树形结构
|
||||
*/
|
||||
private List<TwoDictTreeRespVO> buildTree(List<TwoDictDO> allDicts, Long parentId, int level) {
|
||||
List<TwoDictTreeRespVO> treeList = new ArrayList<>();
|
||||
for (TwoDictDO dict : allDicts) {
|
||||
if (Objects.equals(dict.getParentId(), parentId)) {
|
||||
TwoDictTreeRespVO treeNode = BeanUtils.toBean(dict, TwoDictTreeRespVO.class);
|
||||
treeNode.setLevel(level);
|
||||
// 递归构建子节点
|
||||
List<TwoDictTreeRespVO> children = buildTree(allDicts, dict.getId(), level + 1);
|
||||
treeNode.setChildren(children);
|
||||
treeNode.setLeaf(children.isEmpty());
|
||||
treeList.add(treeNode);
|
||||
}
|
||||
}
|
||||
return treeList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,6 +67,7 @@
|
||||
AND field3_code = #{field3Code}
|
||||
</if>
|
||||
</where>
|
||||
LIMIT 1
|
||||
</sql>
|
||||
|
||||
<select id="selectDictByOne"
|
||||
|
||||
@@ -30,22 +30,9 @@
|
||||
parameterType="cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance.vo.FarmingTypeMaintenanceSaveReqVO"
|
||||
resultType="cn.iocoder.yudao.module.farm.dal.dataobject.farmingtypemaintenance.FarmingTypeMaintenanceDO">
|
||||
|
||||
SELECT <include refid="all_fields"/> FROM farm_farming_type_maintenance t
|
||||
<where>
|
||||
<if test="req.id != null and req.id != ''">
|
||||
AND t.id = #{req.id}
|
||||
</if>
|
||||
<if test="req.farmingCode != null and req.farmingCode != ''">
|
||||
AND t.farming_code = #{req.farmingCode}
|
||||
</if>
|
||||
<if test="req.farmingName != null and req.farmingName != ''">
|
||||
AND t.farming_name LIKE CONCAT('%', #{req.farmingName}, '%')
|
||||
</if>
|
||||
<if test="req.useStatus != null">
|
||||
AND t.use_status = #{req.useStatus}
|
||||
</if>
|
||||
AND t.deleted = 0
|
||||
</where>
|
||||
SELECT <include refid="all_fields"/> FROM farm_farming_type_maintenance
|
||||
WHERE deleted = 0
|
||||
AND use_status = 0
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.farm.dal.mysql.twodict.TwoDictMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user