admin
2019-04-16 c987318c7cf02e51fe6c9c98e75bfcc47058841b
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.yeshi.fanli.controller.client;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.yeshi.fanli.entity.AppInfo;
import com.yeshi.fanli.entity.DeviceInfo;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.customerservice.CustomerServiceCommonQuestion;
import com.yeshi.fanli.entity.customerservice.CustomerServiceHistory;
import com.yeshi.fanli.exception.user.UserComplaintException;
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceCommonQuestionService;
import com.yeshi.fanli.service.inter.customerservice.CustomerServiceHistoryService;
import com.yeshi.fanli.service.inter.user.UserComplaintService;
import com.yeshi.fanli.util.StringUtil;
 
import net.sf.json.JSONObject;
 
/**
 * 客服api接口
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("api/v1/customerservice")
public class CustomerServiceController {
 
    @Resource
    private CustomerServiceCommonQuestionService customerServiceCommonQuestionService;
 
    @Resource
    private CustomerServiceHistoryService customerServiceHistoryService;
 
    @Resource
    private UserComplaintService userComplaintService;
 
    /**
     * 预设标题的关键字列表
     * 
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getkeys", method = RequestMethod.POST)
    public void getKeys(AcceptData acceptData, PrintWriter out) {
        List<String> keys = customerServiceCommonQuestionService.listKeysCache();
        JSONObject data = new JSONObject();
        data.put("keys", keys);
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 根据关键字获取答案
     * 
     * @param acceptData
     * @param key
     *            -关键字
     * @param out
     */
    @RequestMapping(value = "getanswer", method = RequestMethod.POST)
    public void getGoodsInfo(AcceptData acceptData, String key, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(key)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传问题"));
            return;
        }
 
        if (key.length() > 512) {
            out.print(JsonUtil.loadFalseResult(2, "问题过长,请精简问题"));
            return;
        }
 
        Gson gson = new Gson();
 
        CustomerServiceHistory history = new CustomerServiceHistory();
        AppInfo appInfo = new AppInfo();
        appInfo.setChannel(acceptData.getChannel());
        appInfo.setPackages(acceptData.getPackages());
        appInfo.setVersion(acceptData.getVersion());
 
        history.setAppInfo(appInfo);
        history.setAppInfoStr(gson.toJson(appInfo));
        history.setContent(key);
        history.setCreateTime(new Date());
        history.setDevice(acceptData.getDevice());
        DeviceInfo deviceInfo = new DeviceInfo();
        deviceInfo.setDevice(acceptData.getDevice());
        deviceInfo.setDeviceType(acceptData.getDeviceType());
        deviceInfo.setNetwork(acceptData.getNetwork());
        deviceInfo.setOsVersion(acceptData.getOsVersion());
        deviceInfo.setPlatform(acceptData.getPlatform());
 
        history.setDeviceInfo(deviceInfo);
        history.setDeviceInfoStr(gson.toJson(deviceInfo));
        history.setPlatform(acceptData.getPlatform());
        history.setUpdateTime(new Date());
 
        // 保存问题历史记录
        customerServiceHistoryService.addHistory(history);
 
        // 搜索问题答案
        CustomerServiceCommonQuestion answer = customerServiceCommonQuestionService.searchByKeyCache(key);
        if (answer == null) {
            answer = new CustomerServiceCommonQuestion();
            answer.setKey("");
            answer.setContentType(CustomerServiceCommonQuestion.TYPE_TEXT);
            answer.setContent("客服机器人不明白您的问题,请输入你问题的准确关键词或转人工客服解决,谢谢!#^.^#");
 
            // out.print(JsonUtil.loadFalseResult(-1, "无答案"));
            // return;
        }
        out.print(JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(answer)));
    }
 
    /**
     * 用户吐槽记录添加
     * 
     * @param fileList
     * @param uid
     * @param content
     * @param out
     */
    @RequestMapping(value = "complaint")
    public void complaint(AcceptData acceptData, MultipartFile[] fileList, String content, Long uid,
            HttpServletRequest request, PrintWriter out) {
        try {
            List<MultipartFile> files = new ArrayList<>();
            if (fileList != null)
                for (MultipartFile mf : fileList) {
                    files.add(mf);
                }
            userComplaintService.addUserComplaint(files, uid, content);
            out.print(JsonUtil.loadTrueResult("保存成功"));
        } catch (UserComplaintException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            e.printStackTrace();
        } catch (IOException e) {
            out.print(JsonUtil.loadFalseResult("图片上传失败失败"));
            e.printStackTrace();
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("保存失败"));
            e.printStackTrace();
        }
    }
}