新增器件搜索相关接口,搜索,新增,分页列表,更新
This commit is contained in:
10
README.md
10
README.md
@@ -4,6 +4,16 @@
|
||||
|
||||
# 前端打包命令
|
||||
pnpm run build
|
||||
|
||||
|
||||
# 后端发布
|
||||
## 测试环境
|
||||
docker compose pull
|
||||
docker compose up -d
|
||||
|
||||
# 数据库地址
|
||||
47.102.126.67:23306
|
||||
root urwTocIA1f395t
|
||||
# minio bucket 权限配置
|
||||
|
||||
```json
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
|
||||
DROP TABLE IF EXISTS `component_search`;
|
||||
CREATE TABLE `component_search` (
|
||||
`id` varchar(36) CHARACTER SET utf8mb4 NOT NULL,
|
||||
`create_by` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '创建人',
|
||||
`create_time` datetime DEFAULT NULL COMMENT '创建日期',
|
||||
`update_by` varchar(50) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '更新人',
|
||||
`update_time` datetime DEFAULT NULL COMMENT '更新日期',
|
||||
`data_type` varchar(32) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '数据类型',
|
||||
`content` varchar(200) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '搜索内容',
|
||||
`extent_info` varchar(648) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '拓展字段',
|
||||
-- 索引
|
||||
UNIQUE INDEX idx_unique_column2 (content),
|
||||
INDEX idx_combined (data_type, content),
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.jeecg.common.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SearchRequest implements Serializable {
|
||||
private String id;
|
||||
private int type;
|
||||
private String content;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.jeecg.modules.database.constant;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ComponentSearchType {
|
||||
|
||||
MODEL_NUMBER(1, "样品型号"),
|
||||
MODEL_NAME(2, "样品名称"),
|
||||
MODEL_TYPE(3, "样品类型"),
|
||||
MODEL_BATCH_NO(4, "样品批次");
|
||||
|
||||
|
||||
int code;
|
||||
String name;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package org.jeecg.modules.database.controller;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.api.vo.SearchRequest;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.modules.database.entity.SearchResult;
|
||||
import org.jeecg.modules.database.service.IComponentSearchService;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@Tag(name = "样品元器件模糊预搜索API")
|
||||
@RestController
|
||||
@RequestMapping("/database/componentSearch")
|
||||
@Slf4j
|
||||
public class ComponentSearchController {
|
||||
@Autowired
|
||||
private IComponentSearchService componentSearchService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
/**
|
||||
* 默认查询器件类型的分页列表
|
||||
* @param type
|
||||
* @param content
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "器件查询 - 分页查询API")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<SearchResult>> queryPageList(@RequestParam(name = "type", defaultValue = "3") Integer type,@RequestParam(name = "content", defaultValue = "") String content,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
|
||||
) {
|
||||
Result<IPage<SearchResult>> result = new Result<>();
|
||||
IPage<SearchResult> pageList = componentSearchService.queryPageList(type, content, pageNo, pageSize);
|
||||
result.setSuccess(true);
|
||||
result.setResult(pageList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索接口
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @param type
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "器件查询 - 分页查询API")
|
||||
@GetMapping(value = "/search")
|
||||
public Result<List<SearchResult>> search(@RequestParam(name = "type", defaultValue = "") Integer type,@RequestParam(name = "content", defaultValue = "") String content) {
|
||||
Result<List<SearchResult>> result = new Result<>();
|
||||
result.setSuccess(true);
|
||||
result.setResult(componentSearchService.search(type, content));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@AutoLog(value = "器件搜索数据-添加")
|
||||
@Operation(summary = "器件搜索数据-添加")
|
||||
// @RequiresPermissions("database:document_favorites:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody SearchRequest searchRequest, HttpServletRequest request) {
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser userByName = userService.getUserByName(username);
|
||||
SearchResult result = new SearchResult();
|
||||
result.setContent(searchRequest.getContent());
|
||||
result.setDataType(searchRequest.getType());
|
||||
Date currentDate = new Date();
|
||||
result.setCreateTime(currentDate);
|
||||
result.setUpdateTime(currentDate);
|
||||
result.setCreateBy(userByName.getId());
|
||||
result.setUpdateBy(userByName.getId());
|
||||
componentSearchService.save(result);
|
||||
return Result.OK("保存成功!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param searchResult
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "器件搜索数据-编辑")
|
||||
@Operation(summary = "器件搜索数据-编辑")
|
||||
// @RequiresPermissions("database:document_favorites:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody SearchResult searchResult, HttpServletRequest request) {
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser userByName = userService.getUserByName(username);
|
||||
searchResult.setUpdateBy(userByName.getId());
|
||||
searchResult.setUpdateTime(new Date());
|
||||
componentSearchService.updateById(searchResult);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "器件搜索数据-通过id删除")
|
||||
@Operation(summary = "器件搜索数据-通过id删除")
|
||||
// @RequiresPermissions("database:document_favorites:delete")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name = "id") String id) {
|
||||
componentSearchService.removeById(id);
|
||||
return Result.OK("删除!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package org.jeecg.modules.database.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode
|
||||
@Schema(description = "系统预搜索的信息模型")
|
||||
@TableName("component_search")
|
||||
public class SearchResult implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private String id;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
@Schema(description = "创建日期")
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@Schema(description = "更新人")
|
||||
private String updateBy;
|
||||
/**
|
||||
* 更新日期
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
||||
@Schema(description = "更新日期")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 搜索的数据类型,参考枚举 @ComponentSearchType
|
||||
*/
|
||||
@Schema(description = "数据类型")
|
||||
private int dataType;
|
||||
/**
|
||||
* 搜索的内容
|
||||
*/
|
||||
@Schema(description = "搜索内容")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 用来作为拓展字段
|
||||
*/
|
||||
@Schema(description = "扩展信息")
|
||||
private String extentInfo;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.jeecg.modules.database.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.jeecg.modules.database.entity.SearchResult;
|
||||
|
||||
public interface ComponentSearchMapper extends BaseMapper<SearchResult> {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?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="org.jeecg.modules.database.mapper.ComponentSearchMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.jeecg.modules.database.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.modules.database.entity.Experiment;
|
||||
import org.jeecg.modules.database.entity.SearchResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IComponentSearchService extends IService<SearchResult> {
|
||||
|
||||
IPage<SearchResult> queryPageList(Integer type, String content, Integer pageNo, Integer pageSize);
|
||||
List<SearchResult> search(Integer type, String content);
|
||||
|
||||
|
||||
void saveDataAfterSaveExperiment(Experiment experiment);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.jeecg.modules.database.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.modules.database.constant.ComponentSearchType;
|
||||
import org.jeecg.modules.database.entity.DocumentFavorites;
|
||||
import org.jeecg.modules.database.entity.Experiment;
|
||||
import org.jeecg.modules.database.entity.SearchResult;
|
||||
import org.jeecg.modules.database.mapper.ComponentSearchMapper;
|
||||
import org.jeecg.modules.database.service.IComponentSearchService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ComponentSearchServiceImpl extends ServiceImpl<ComponentSearchMapper, SearchResult> implements IComponentSearchService {
|
||||
@Override
|
||||
public IPage<SearchResult> queryPageList(Integer type, String content, Integer pageNo, Integer pageSize) {
|
||||
SearchResult searchResult = new SearchResult();
|
||||
Map requestMap = new HashMap();
|
||||
requestMap.put("dataType", type);
|
||||
requestMap.put("content", content);
|
||||
QueryWrapper<SearchResult> queryWrapper = QueryGenerator.initQueryWrapper(searchResult,requestMap);
|
||||
Page<SearchResult> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SearchResult> pageList = this.page(page, queryWrapper);
|
||||
return pageList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SearchResult> search(Integer type, String content) {
|
||||
SearchResult searchResult = new SearchResult();
|
||||
Map requestMap = new HashMap();
|
||||
requestMap.put("dataType", type);
|
||||
requestMap.put("content", content);
|
||||
QueryWrapper<SearchResult> queryWrapper = QueryGenerator.initQueryWrapper(searchResult,requestMap);
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDataAfterSaveExperiment(Experiment experiment) {
|
||||
// 批量更新样品型号,样品名称,样品批次
|
||||
if (CollUtil.isNotEmpty(experiment.getSampleInfoList())) {
|
||||
experiment.getSampleInfoList().forEach(sampleInfo -> {
|
||||
SearchResult modelNumberRecord = new SearchResult();
|
||||
modelNumberRecord.setDataType(ComponentSearchType.MODEL_NUMBER.getCode());
|
||||
modelNumberRecord.setContent(sampleInfo.getSampleModel());
|
||||
try {
|
||||
saveOrUpdate(modelNumberRecord);
|
||||
}catch (Exception e) {
|
||||
log.warn("样品型号搜索数据更新失败,错误信息: " + e.getMessage());
|
||||
}
|
||||
|
||||
SearchResult modelNameRecord = new SearchResult();
|
||||
modelNameRecord.setDataType(ComponentSearchType.MODEL_NAME.getCode());
|
||||
modelNameRecord.setContent(sampleInfo.getSampleName());
|
||||
try {
|
||||
updateById(modelNameRecord);
|
||||
}catch (Exception e) {
|
||||
log.warn("样品名称搜索数据更新失败,错误信息: " + e.getMessage());
|
||||
}
|
||||
|
||||
SearchResult modelBatchNoRecord = new SearchResult();
|
||||
modelBatchNoRecord.setDataType(ComponentSearchType.MODEL_BATCH_NO.getCode());
|
||||
modelBatchNoRecord.setContent(sampleInfo.getModelBatch());
|
||||
try {
|
||||
updateById(modelBatchNoRecord);
|
||||
}catch (Exception e) {
|
||||
log.warn("样品批次搜索数据更新失败,错误信息: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user