Commit 23e6e116 by 阳浪

门户搜素接口

parent 42156309
......@@ -78,18 +78,70 @@ public class DictionaryController {
}
/**
* 新增数据字典
* 新增搜索数据字典
*
* @param searchName
* @return
*/
@ApiOperation(value = "数据字典", notes = "新增一个字典数据", response = Response.class)
@ApiOperation(value = "新增搜索数据字典", notes = "新增一个搜索的字典数据", response = Response.class)
@GetMapping("/insertBySearchName")
public boolean insertBySearchName(@RequestParam("searchName") String searchName) {
return dictionaryService.insertBySearchName(searchName);
}
/**
* 我的搜索历史记录
*
* @return
*/
@ApiOperation(value = "我的搜索历史记录", notes = "查询所有我的搜索历史记录", response = Response.class)
@GetMapping(value = "/home/searchListByMe")
public Response<List<Dictionary>> searchListByMe() {
try {
List<com.yizhi.system.application.domain.Dictionary> result = dictionaryService.searchListByMe();
return Response.ok(result);
} catch (Exception e) {
LOG.error("", e);
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
/**
* 删除我的搜索历史记录
*
* @return
*/
@ApiOperation(value = "删除我的搜索历史记录", notes = "删除所有我的搜索历史记录", response = Response.class)
@GetMapping(value = "/home/searchDeleteByMe")
public Response<String> searchDeleteByMe() {
try {
dictionaryService.searchDeleteByMe();
return Response.ok();
} catch (Exception e) {
LOG.error("", e);
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
/**
* 大家都在搜索历史记录
*
* @return
*/
@ApiOperation(value = "大家都在搜索历史记录", notes = "查询所有大家都在搜索历史记录", response = Response.class)
@GetMapping(value = "/home/searchListByAll")
public Response<List<Dictionary>> searchListByAll() {
try {
List<com.yizhi.system.application.domain.Dictionary> result = dictionaryService.searchListByAll();
return Response.ok(result);
} catch (Exception e) {
LOG.error("", e);
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
/**
* 删除单个数据字典
*
* @param id
......
......@@ -89,4 +89,10 @@ public interface DictionaryService extends IService<Dictionary> {
boolean checkCode(String code);
boolean insertBySearchName(String searchName);
List<Dictionary> searchListByMe();
List<Dictionary> searchListByAll();
Boolean searchDeleteByMe();
}
......@@ -3,6 +3,8 @@ package com.yizhi.system.application.service.impl;
import java.util.*;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.enums.SqlLike;
import com.google.common.collect.Lists;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.system.application.domain.Dictionary;
......@@ -35,8 +37,6 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
@Autowired
private IdGenerator idGenerator;
@Autowired
private DictionaryMapper dictionaryMapper;
@Override
......@@ -45,7 +45,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
dictExample.setCode(dictionary.getCode());
dictExample.setEnabled(Boolean.TRUE);
int num = dictionaryMapper.selectCount(new EntityWrapper<Dictionary>(dictExample));
int num = baseMapper.selectCount(new EntityWrapper<Dictionary>(dictExample));
if (num > 0) {
throw new RuntimeException("Code has alredy existed! -- code: " + dictionary.getCode());
}
......@@ -63,7 +63,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
Dictionary dictForParent = new Dictionary();
dictForParent.setId(dictionary.getParentId());
dictForParent.setEnabled(Boolean.TRUE);
Dictionary parent = dictionaryMapper.selectOne(dictForParent);
Dictionary parent = baseMapper.selectOne(dictForParent);
dictionary.setLayer(parent.getLayer() + 1);
if (parent.getParentId() == 0) { // 若父对象的parentId为0,则父为root
......@@ -80,11 +80,11 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
layerDict.setRootId(dictionary.getRootId());
layerDict.setEnabled(Boolean.TRUE);
int layerCount = dictionaryMapper.selectCount(new EntityWrapper<Dictionary>(layerDict));
int layerCount = baseMapper.selectCount(new EntityWrapper<Dictionary>(layerDict));
dictionary.setSort(layerCount + 1);
}
return dictionaryMapper.insert(dictionary) == 1;
return baseMapper.insert(dictionary) == 1;
}
@Override
......@@ -93,7 +93,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
dictExample.setCode(code);
dictExample.setEnabled(Boolean.TRUE);
return dictionaryMapper.selectOne(dictExample);
return baseMapper.selectOne(dictExample);
}
@Override
......@@ -101,7 +101,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
Dictionary dictionary = new Dictionary();
dictionary.setRootId(new Long(0));
dictionary.setEnabled(Boolean.TRUE);
return dictionaryMapper.selectList(new EntityWrapper<Dictionary>(dictionary));
return baseMapper.selectList(new EntityWrapper<Dictionary>(dictionary));
}
@Override
......@@ -128,7 +128,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
@Override
public List<Dictionary> listChildren(long id, Boolean includeParent, Integer layer) {
String idsStr = dictionaryMapper.getDictChildList(id, includeParent, layer, true);
String idsStr = baseMapper.getDictChildList(id, includeParent, layer, true);
if (StringUtils.isNotEmpty(idsStr)) {
String[] ids = idsStr.split(",");
List<Long> idList = new ArrayList<Long>();
......@@ -148,7 +148,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
// 待删除id
StringBuilder idsToDeleteSb = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
idsToDeleteSb.append("," + dictionaryMapper.getDictChildList(ids[i], true, null, true));
idsToDeleteSb.append("," + baseMapper.getDictChildList(ids[i], true, null, true));
idsToDeleteSb.append("," +ids[i]);
}
String[] idsToDeleteStr = idsToDeleteSb.toString().split(",");
......@@ -199,9 +199,9 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
try {
if(ObjectUtils.isNotEmpty(searchName)) {
Dictionary Dictionary = findByCode("all_search_list");
if (Dictionary != null) {
List<Dictionary> DictionaryList = listChildren(Dictionary.getId(), false, 1);
Dictionary search = findByCode("all_search_list");
if (search != null) {
List<Dictionary> DictionaryList = listChildren(search.getId(), false, 1);
Optional<Dictionary> optional =null;
if(DictionaryList==null){
DictionaryList = Lists.newArrayList();
......@@ -229,7 +229,7 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
dictionarySub = new Dictionary();
BeanUtil.copyProperties(dictionary,dictionarySub);
dictionarySub.setParentId(dictionary.getId());
dictionarySub.setCnName(searchName+"_"+ContextHolder.get().getAccountId());
dictionarySub.setCnName(searchName);
dictionarySub.setCode(key);
dictionarySub.setEnName(key);
insertDetail(dictionarySub);
......@@ -250,14 +250,14 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
dictionary.setCreateTime(today);
dictionary.setSystemFlag(1);
dictionary.setSort(DictionaryList.size());
dictionary.setParentId(Dictionary.getId());
dictionary.setParentId(search.getId());
insertDetail(dictionary);
Dictionary dictionarySub = new Dictionary();
BeanUtil.copyProperties(dictionary,dictionarySub);
dictionarySub.setParentId(dictionary.getId());
dictionarySub.setCode(key);
dictionarySub.setCnName(searchName+"_"+ContextHolder.get().getAccountId());
dictionarySub.setCnName(searchName);
dictionarySub.setEnName(key);
insertDetail(dictionarySub);
......@@ -271,5 +271,39 @@ public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Diction
return true;
}
@Override
public List<Dictionary> searchListByMe(){
Dictionary dictionary = new Dictionary();
dictionary.setEnabled(Boolean.TRUE);
EntityWrapper<Dictionary> ew = new EntityWrapper<>(dictionary);
ew.like("code","search_list",SqlLike.DEFAULT);
ew.like("code",ContextHolder.get().getAccountId()+"",SqlLike.DEFAULT);
return this.selectList(ew);
}
@Override
public List<Dictionary> searchListByAll(){
Dictionary search = findByCode("all_search_list");
if(search==null){
return Lists.newArrayList();
}
Dictionary dictionary = new Dictionary();
dictionary.setEnabled(Boolean.TRUE);
dictionary.setLayer(1);
dictionary.setParentId(search.getId());
EntityWrapper<Dictionary> ew = new EntityWrapper<>(dictionary);
return this.selectList(ew);
}
@Override
public Boolean searchDeleteByMe(){
List<Dictionary> dictionaries = searchListByMe();
if(CollectionUtil.isNotEmpty(dictionaries)){
dictionaries.stream().forEach(d->{
d.setEnabled(Boolean.FALSE);
updateById(d);
});
}
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment