admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/CustomerServiceController.java
@@ -1,157 +1,157 @@
package com.yeshi.fanli.controller.client.v1;
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.multipart.MultipartFile;
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();
      }
   }
}
package com.yeshi.fanli.controller.client.v1;
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.multipart.MultipartFile;
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();
      }
   }
}