添加新增,编辑搜索数据的接口
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package org.jeecg.common.constant.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PhysicalErrCodeEnum {
|
||||
|
||||
SEARCH_DATA_ADD_DUPLICATE(10001, "数据已存在"),
|
||||
SYSTEM_ERR(10000, "系统内部错误,请联系管理员!")
|
||||
;
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
|
||||
PhysicalErrCodeEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ 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.exception.JeecgBootException;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.modules.database.entity.SearchResult;
|
||||
import org.jeecg.modules.database.service.IComponentSearchService;
|
||||
@@ -88,7 +88,12 @@ public class ComponentSearchController {
|
||||
result.setUpdateTime(currentDate);
|
||||
result.setCreateBy(userByName.getId());
|
||||
result.setUpdateBy(userByName.getId());
|
||||
componentSearchService.save(result);
|
||||
try {
|
||||
componentSearchService.saveComponentSearch(result);
|
||||
}catch (JeecgBootException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
|
||||
return Result.OK("保存成功!");
|
||||
}
|
||||
|
||||
@@ -107,7 +112,12 @@ public class ComponentSearchController {
|
||||
SysUser userByName = userService.getUserByName(username);
|
||||
searchResult.setUpdateBy(userByName.getId());
|
||||
searchResult.setUpdateTime(new Date());
|
||||
componentSearchService.updateById(searchResult);
|
||||
try {
|
||||
componentSearchService.saveComponentSearch(searchResult);
|
||||
}catch (JeecgBootException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ 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);
|
||||
|
||||
boolean saveComponentSearch(SearchResult searchResult);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@ package org.jeecg.modules.database.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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 jodd.util.StringUtil;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.constant.enums.PhysicalErrCodeEnum;
|
||||
import org.jeecg.common.exception.JeecgBootException;
|
||||
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;
|
||||
@@ -18,9 +17,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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 {
|
||||
@@ -28,14 +25,11 @@ public class ComponentSearchServiceImpl extends ServiceImpl<ComponentSearchMappe
|
||||
|
||||
@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);
|
||||
LambdaQueryWrapper<SearchResult> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SearchResult::getDataType, type);
|
||||
queryWrapper.likeRight(SearchResult::getContent, content);
|
||||
Page<SearchResult> page = new Page<>(pageNo, pageSize);
|
||||
IPage<SearchResult> pageList = this.page(page, queryWrapper);
|
||||
return pageList;
|
||||
return this.page(page, queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,4 +99,15 @@ public class ComponentSearchServiceImpl extends ServiceImpl<ComponentSearchMappe
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveComponentSearch(SearchResult searchResult) {
|
||||
LambdaQueryWrapper<SearchResult> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SearchResult::getDataType, searchResult.getDataType());
|
||||
queryWrapper.eq(SearchResult::getContent, searchResult.getContent());
|
||||
if (this.count(queryWrapper) > 0)
|
||||
throw new JeecgBootException("数据已存在!",PhysicalErrCodeEnum.SEARCH_DATA_ADD_DUPLICATE.getCode());
|
||||
|
||||
return this.saveOrUpdate(searchResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user