fix: 鱼类字典功能优化
This commit is contained in:
parent
5986658c68
commit
f4dacb2efc
@ -3,10 +3,12 @@ package com.yfd.platform.qgc_base.controller;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yfd.platform.annotation.Log;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.qgc_base.domain.SdFishDictoryB;
|
||||
import com.yfd.platform.qgc_base.domain.SdEngInfoBHOperateRequest;
|
||||
import com.yfd.platform.qgc_base.service.ISdFishDictoryBService;
|
||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -29,14 +31,13 @@ public class SdFishDictoryBController {
|
||||
@Resource
|
||||
private ISdFishDictoryBService sdFishDictoryBService;
|
||||
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@PostMapping("/queryPageList")
|
||||
@Operation(summary = "分页查询鱼类字典列表(支持动态过滤和排序)")
|
||||
public ResponseResult queryPageList(@RequestBody DataSourceRequest request) {
|
||||
Page<SdFishDictoryB> page = DataSourceRequestUtil.executeQuery(
|
||||
request,
|
||||
SdFishDictoryB.class,
|
||||
sdFishDictoryBService
|
||||
);
|
||||
Page<SdFishDictoryB> page = sdFishDictoryBService.queryPageList(request);
|
||||
return ResponseResult.successData(page);
|
||||
}
|
||||
|
||||
@ -56,7 +57,8 @@ public class SdFishDictoryBController {
|
||||
public ResponseResult listByName(@RequestParam(required = false) String name) {
|
||||
return ResponseResult.successData(sdFishDictoryBService.list(
|
||||
new LambdaQueryWrapper<SdFishDictoryB>()
|
||||
.eq(StrUtil.isNotBlank(name), SdFishDictoryB::getName, name).select(SdFishDictoryB::getId, SdFishDictoryB::getName, SdFishDictoryB::getAlias)
|
||||
.eq(StrUtil.isNotBlank(name), SdFishDictoryB::getName, name)
|
||||
.select(SdFishDictoryB::getId, SdFishDictoryB::getName, SdFishDictoryB::getAlias)
|
||||
));
|
||||
}
|
||||
|
||||
@ -69,24 +71,31 @@ public class SdFishDictoryBController {
|
||||
@Log(module = "鱼类字典管理", value = "新增鱼类字典")
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增鱼类字典")
|
||||
public ResponseResult add(@RequestBody SdFishDictoryB fishDictoryB) {
|
||||
boolean result = sdFishDictoryBService.add(fishDictoryB);
|
||||
public ResponseResult add(@RequestBody SdEngInfoBHOperateRequest request) {
|
||||
SdFishDictoryB entity = request == null || request.getEngInfo() == null ? null
|
||||
: objectMapper.convertValue(request.getEngInfo(), SdFishDictoryB.class);
|
||||
boolean result = sdFishDictoryBService.add(entity, request == null ? null : request.getSource());
|
||||
return result ? ResponseResult.success("新增成功") : ResponseResult.error("新增失败");
|
||||
}
|
||||
|
||||
@Log(module = "鱼类字典管理", value = "修改鱼类字典")
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "修改鱼类字典")
|
||||
public ResponseResult update(@RequestBody SdFishDictoryB fishDictoryB) {
|
||||
boolean result = sdFishDictoryBService.updateById(fishDictoryB);
|
||||
public ResponseResult update(@RequestBody SdEngInfoBHOperateRequest request) {
|
||||
SdFishDictoryB entity = request == null || request.getEngInfo() == null ? null
|
||||
: objectMapper.convertValue(request.getEngInfo(), SdFishDictoryB.class);
|
||||
boolean result = sdFishDictoryBService.update(entity, request == null ? null : request.getSource());
|
||||
return result ? ResponseResult.success("修改成功") : ResponseResult.error("修改失败");
|
||||
}
|
||||
|
||||
@Log(module = "鱼类字典管理", value = "删除鱼类字典")
|
||||
@PostMapping("/delete")
|
||||
@Operation(summary = "删除鱼类字典")
|
||||
public ResponseResult delete(@RequestParam String id) {
|
||||
boolean result = sdFishDictoryBService.deleteById(id);
|
||||
public ResponseResult delete(@RequestBody SdEngInfoBHOperateRequest request) {
|
||||
boolean result = sdFishDictoryBService.delete(
|
||||
request == null ? null : request.getIds(),
|
||||
request == null ? null : request.getSource()
|
||||
);
|
||||
return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败");
|
||||
}
|
||||
|
||||
|
||||
@ -116,6 +116,7 @@ public class SdArtsgBH implements Serializable {
|
||||
*/
|
||||
private String rvcd;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
private String rvnm;
|
||||
|
||||
@ -165,6 +166,7 @@ public class SdArtsgBH implements Serializable {
|
||||
*/
|
||||
private Integer bldsttCode;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String bldsttCodeName;
|
||||
|
||||
/**
|
||||
|
||||
@ -198,7 +198,7 @@ public class SdDwBH implements Serializable {
|
||||
/**
|
||||
* 叠梁门层数高度
|
||||
*/
|
||||
private BigDecimal dcshg;
|
||||
private String dcshg;
|
||||
|
||||
/**
|
||||
* 叠梁门单层取水口个数
|
||||
|
||||
@ -85,6 +85,9 @@ public class SdFishDictoryB implements Serializable {
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 成鱼大小:单位:cm
|
||||
*/
|
||||
@ -95,16 +98,25 @@ public class SdFishDictoryB implements Serializable {
|
||||
*/
|
||||
private Integer rare;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String rareName;
|
||||
|
||||
/**
|
||||
* 物种来源:1=本土物种 2=外来物种
|
||||
*/
|
||||
private Integer specOrigin;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String specOriginName;
|
||||
|
||||
/**
|
||||
* 保护类型:1=濒危 2=极危 3=近危 4=易危 5=重点保护 6=无危 7=国家二级 8=市二级保护
|
||||
*/
|
||||
private Integer ptype;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String ptypeName;
|
||||
|
||||
/**
|
||||
* 所属流域
|
||||
*/
|
||||
@ -165,21 +177,33 @@ public class SdFishDictoryB implements Serializable {
|
||||
*/
|
||||
private String wqtq;
|
||||
|
||||
// @TableField(exist = false)
|
||||
// private String wqtqName;
|
||||
|
||||
/**
|
||||
* 主要生活环境 1=流水生境 2=静缓流生境 3=洞穴生境
|
||||
*/
|
||||
private Integer habitat;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String habitatName;
|
||||
|
||||
/**
|
||||
* 种群现状 1=优势种 2=常见种 3=少见种 4=记录种
|
||||
*/
|
||||
private Integer situation;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String situationName;
|
||||
|
||||
/**
|
||||
* 资源类型 1=保护鱼类 2=特有鱼类 3=重要经济鱼类 4=濒危状况
|
||||
*/
|
||||
private Integer resourceType;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String resourceTypeName;
|
||||
|
||||
/**
|
||||
* 形态描述
|
||||
*/
|
||||
|
||||
@ -2,19 +2,22 @@ package com.yfd.platform.qgc_base.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.qgc_base.domain.SdFishDictoryB;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ISdFishDictoryBService extends IService<SdFishDictoryB> {
|
||||
|
||||
Page<SdFishDictoryB> queryPageList(DataSourceRequest request);
|
||||
|
||||
Page<SdFishDictoryB> selectPage(String name, String code, Integer type, Integer rare, Page<SdFishDictoryB> page);
|
||||
|
||||
boolean add(SdFishDictoryB fishDictoryB);
|
||||
boolean add(SdFishDictoryB entity, String source);
|
||||
|
||||
boolean updateById(SdFishDictoryB fishDictoryB);
|
||||
boolean update(SdFishDictoryB entity, String source);
|
||||
|
||||
boolean deleteById(String id);
|
||||
boolean delete(List<String> ids, String source);
|
||||
|
||||
SdFishDictoryB getById(String id);
|
||||
|
||||
|
||||
@ -2,20 +2,124 @@ package com.yfd.platform.qgc_base.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.qgc_base.domain.SdFishDictoryB;
|
||||
import com.yfd.platform.qgc_base.mapper.SdFishDictoryBMapper;
|
||||
import com.yfd.platform.qgc_base.service.IMsOperationLogService;
|
||||
import com.yfd.platform.qgc_base.service.ISdFishDictoryBService;
|
||||
import com.yfd.platform.utils.CodeToNameMetadataBo;
|
||||
import com.yfd.platform.utils.DataSourceRequestUtil;
|
||||
import com.yfd.platform.utils.DictCodeToNameConverter;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 鱼类字典 Service 实现类
|
||||
*/
|
||||
@Service
|
||||
public class SdFishDictoryBServiceImpl extends ServiceImpl<SdFishDictoryBMapper, SdFishDictoryB> implements ISdFishDictoryBService {
|
||||
|
||||
private static final String TABLE_NAME = "SD_FISHDICTORY_B";
|
||||
|
||||
@Resource
|
||||
private IMsOperationLogService msOperationLogService;
|
||||
|
||||
|
||||
@Resource
|
||||
private DictCodeToNameConverter dictCodeToNameConverter;
|
||||
|
||||
/**
|
||||
* 代码转名称元数据配置列表(静态初始化)
|
||||
* <p>
|
||||
* 每个模块的 ServiceImpl 中可按需定义自己的 codeToNameMetadataBoList,
|
||||
* 在查询方法返回前调用 dictCodeToNameConverter.convertCodeToName(voList, codeToNameMetadataBoList)
|
||||
* 即可自动将 code 字段转为对应的 name 字段。
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* 使用示例:
|
||||
* // 在查询方法末尾调用:
|
||||
* dictCodeToNameConverter.convertCodeToName(voList, CODE_TO_NAME_META_LIST);
|
||||
* </pre>
|
||||
*/
|
||||
private static final List<CodeToNameMetadataBo> CODE_TO_NAME_META_LIST = new ArrayList<>();
|
||||
|
||||
static {
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("specOrigin").modifyProperty("specOriginName").dictType("STATIC").dictSource("SPEC_ORIGIN").build());
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("rare").modifyProperty("rareName").dictType("STATIC").dictSource("TY_SF").build());
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("ptype").modifyProperty("ptypeName").dictType("STATIC").dictSource("PTYPE").build());
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("habitat").modifyProperty("habitatName").dictType("STATIC").dictSource("HABITAT").build());
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("situation").modifyProperty("situationName").dictType("STATIC").dictSource("SITUATION").build());
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("resourceType").modifyProperty("resourceTypeName").dictType("STATIC").dictSource("RESOURCE_TYPE").build());
|
||||
// CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("wqtq").modifyProperty("wqtqName").dictType("STATIC").dictSource("WWQTG").build());
|
||||
CODE_TO_NAME_META_LIST.add(CodeToNameMetadataBo.builder().codeProperty("type").modifyProperty("typeName").dictType("STATIC").dictSource("WATER_TYPE").build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SdFishDictoryB> queryPageList(DataSourceRequest request) {
|
||||
Page<SdFishDictoryB> sdFishDictoryBPage = DataSourceRequestUtil.executeQuery(request, SdFishDictoryB.class, this);
|
||||
dictCodeToNameConverter.convertCodeToName(sdFishDictoryBPage, CODE_TO_NAME_META_LIST);
|
||||
return sdFishDictoryBPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean add(SdFishDictoryB entity, String source) {
|
||||
boolean result = this.save(entity);
|
||||
if (result) {
|
||||
msOperationLogService.recordAddDetailLog(TABLE_NAME, entity, source);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean update(SdFishDictoryB entity, String source) {
|
||||
SdFishDictoryB before = this.getById(entity.getId());
|
||||
boolean result = this.updateById(entity);
|
||||
if (result && before != null) {
|
||||
msOperationLogService.recordModifyDetailLog(TABLE_NAME, before, entity, source);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean delete(List<String> ids, String source) {
|
||||
if (ids == null || ids.isEmpty()) return false;
|
||||
int count = 0;
|
||||
for (String id : ids) {
|
||||
SdFishDictoryB entity = getById(id);
|
||||
LambdaUpdateWrapper<SdFishDictoryB> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.eq(SdFishDictoryB::getId, id);
|
||||
wrapper.set(SdFishDictoryB::getIsDeleted, 1);
|
||||
wrapper.set(SdFishDictoryB::getDeleteUser, SecurityUtils.getCurrentUsername());
|
||||
wrapper.set(SdFishDictoryB::getDeleteTime, new Date());
|
||||
if (this.update(wrapper)) {
|
||||
msOperationLogService.recordDeleteDetailLog(TABLE_NAME, entity, source);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdFishDictoryB getById(String id) {
|
||||
LambdaQueryWrapper<SdFishDictoryB> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SdFishDictoryB::getId, id)
|
||||
.eq(SdFishDictoryB::getIsDeleted, 0);
|
||||
return getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SdFishDictoryB> selectPage(String name, String code, Integer type, Integer rare, Page<SdFishDictoryB> page) {
|
||||
LambdaQueryWrapper<SdFishDictoryB> wrapper = new LambdaQueryWrapper<>();
|
||||
@ -38,35 +142,6 @@ public class SdFishDictoryBServiceImpl extends ServiceImpl<SdFishDictoryBMapper,
|
||||
return page(page, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(SdFishDictoryB fishDictoryB) {
|
||||
fishDictoryB.setIsDeleted(0);
|
||||
return save(fishDictoryB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateById(SdFishDictoryB fishDictoryB) {
|
||||
return updateById(fishDictoryB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteById(String id) {
|
||||
SdFishDictoryB entity = getById(id);
|
||||
if (entity != null) {
|
||||
entity.setIsDeleted(1);
|
||||
return updateById(entity);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdFishDictoryB getById(String id) {
|
||||
LambdaQueryWrapper<SdFishDictoryB> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SdFishDictoryB::getId, id)
|
||||
.eq(SdFishDictoryB::getIsDeleted, 0);
|
||||
return getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SdFishDictoryB> findSimilarFish(String name, Integer limit) {
|
||||
if (!StringUtils.hasText(name)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user