杜洪波
2024-08-30 d2e9aa27200ffe582c48cf1c2bd0c98cdc7256e5
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.product.lucene.controller;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.lucene.config.CmnConst;
import com.product.lucene.config.SystemCode;
import com.product.lucene.service.SearchTermService;
import com.product.module.sys.version.ApiVersion;
import com.product.util.BaseUtil;
import com.product.util.ResultInfo;
 
 
@RequestMapping("/api/search-term")
@RestController
public class SearchTermController extends AbstractBaseController{
 
    @Autowired
    SearchTermService searchTermService;
    
    /**
     *     获取检索词条(常用词条和历史记录)
     * @param request
     */
    @RequestMapping("/list/{version}")
    @ApiVersion(1)
    public String listSearchTerm(HttpServletRequest request) {
        try {
            searchTermService.listSearchTerm();
            return ResultInfo.success(searchTermService.listSearchTerm());
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(SystemCode.LIST_SEARCH_CENTENT_FAIL.getValue(), SystemCode.LIST_SEARCH_CENTENT_FAIL.getText());
        }
    }
    
    /**
     *     新增检索词条(常用词条)
     * @param request
     */
    @RequestMapping("/add/{version}")
    @ApiVersion(1)
    public String addSearchTerm(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT);
            return OK_Add(searchTermService.addSearchTerm(fse.getString(CmnConst.SEARCH_CONTENT), fse.getString(CmnConst.CONTENT_TYPE)));
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(SystemCode.ADD_SEARCH_CENTENT_FAIL.getValue(), SystemCode.ADD_SEARCH_CENTENT_FAIL.getText());
        }
    }
    
    /**
     *     删除检索词条(常用词条和历史记录)
     * @param request
     */
    @RequestMapping("/delete/{version}")
    @ApiVersion(1)
    public String deleteSearchTerm(HttpServletRequest request) {
        try {
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_SYS_DOCUMENT_SEARCH_CONTENT);
            searchTermService.deleteSearchTerm(fse.getUUID());
            boolean succ = searchTermService.deleteSearchTerm(fse.getUUID());
            if (succ) {
                return OK();
            }
            throw new BaseException(SystemCode.DELETE_SEARCH_CENTENT_FAIL.getValue(), SystemCode.DELETE_SEARCH_CENTENT_FAIL.getText());
        } catch (BaseException e) {
            e.printStackTrace();
            return this.error(e.getCode(), e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.error(SystemCode.DELETE_SEARCH_CENTENT_FAIL.getValue(), SystemCode.DELETE_SEARCH_CENTENT_FAIL.getText());
        }
    }
}