354798ggg
2023-05-31 c7584948cb01407c9db17dc082acc91bed11a97e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.product.lucene.service;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.product.core.config.CoreConst;
import com.product.core.dao.BaseDao;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.lucene.config.CmnConst;
import com.product.lucene.config.SystemCode;
import com.product.util.BaseUtil;
 
import cn.hutool.json.JSONObject;
 
@Component
public class SearchTermService extends AbstractBaseService{
 
    
    @Autowired
    BaseDao baseDao;
    
    /**
     *     获取所有搜索词条
     * @return
     */
    public JSONObject listSearchTerm() {
        JSONObject jsonReturn = new JSONObject();
        jsonReturn.set(CmnConst.SEARCH_KEYWORD, BaseUtil.dataTableEntityToJson(baseDao.listTable(CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT, "created_by=? AND content_type=0", new Object[] {SpringMVCContextHolder.getCurrentUserId()})));
        jsonReturn.set(CmnConst.SEARCH_HISTORY, BaseUtil.dataTableEntityToJson(baseDao.listTable(CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT, "created_by=? AND content_type=1", new Object[] {SpringMVCContextHolder.getCurrentUserId()})));
        return jsonReturn;
    }
    
    /**
     *     新增常用搜索词条
     * @param searchContent
     * @param contentType
     * @return
     */
    public String addSearchTerm(String searchContent, String contentType) {
        
        //查询数据是否存在
        FieldSetEntity fseExist = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT,
                "created_by=? AND search_content=? AND content_type=?", new Object[] {SpringMVCContextHolder.getCurrentUserId(), searchContent, contentType}, false);
        
        if ("0".equals(contentType) && fseExist!=null) {
            throw new BaseException(SystemCode.ADD_SEARCH_CONTENT_EXIST.getValue(), SystemCode.ADD_SEARCH_CONTENT_EXIST.getText());
        }
        //新增
        FieldSetEntity fseAddInfo = new FieldSetEntity();
        fseAddInfo.setTableName(CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT);
        if (fseExist!=null) {
            fseAddInfo.setValue(CoreConst.UUID, fseExist.getUUID());
        }
        fseAddInfo.setValue(CmnConst.SEARCH_CONTENT, searchContent);
        fseAddInfo.setValue(CmnConst.CONTENT_TYPE, contentType);
        BaseUtil.createCreatorAndCreationTime(fseAddInfo);
        baseDao.saveFieldSetEntity(fseAddInfo);
        return  fseAddInfo.getUUID();
    }
    
    /**
     *     删除单个搜索词条
     * @param uuid
     * @return
     */
    public boolean deleteSearchTerm(String uuid) {
        return baseDao.delete(CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT, "uuid=?", new Object[] {uuid});
    }
}