|
@@ -22,8 +22,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.free.config.CustomizationException;
|
|
import com.free.config.CustomizationException;
|
|
import com.free.config.ExceptionEnum;
|
|
import com.free.config.ExceptionEnum;
|
|
import com.free.config.ResponseFormat;
|
|
import com.free.config.ResponseFormat;
|
|
|
|
+import com.free.dto.ChatRecordCreateDTO;
|
|
import com.free.entity.ChatRecord;
|
|
import com.free.entity.ChatRecord;
|
|
|
|
+import com.free.entity.TransferApply;
|
|
|
|
+import com.free.mq.MqService;
|
|
import com.free.service.ChatRecordService;
|
|
import com.free.service.ChatRecordService;
|
|
|
|
+import com.free.service.TransferApplyService;
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -34,22 +38,55 @@ import io.swagger.annotations.ApiOperation;
|
|
public class ChatRecordController {
|
|
public class ChatRecordController {
|
|
@Autowired
|
|
@Autowired
|
|
private ChatRecordService service;
|
|
private ChatRecordService service;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TransferApplyService transferApplyService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private MqService mqService;
|
|
|
|
|
|
/** 创建数据 */
|
|
/** 创建数据 */
|
|
@ApiOperation("创建数据")
|
|
@ApiOperation("创建数据")
|
|
@PostMapping("")
|
|
@PostMapping("")
|
|
- public Object save(@RequestBody @Valid ChatRecord data) {
|
|
|
|
|
|
+ public Object save(@RequestBody @Valid ChatRecordCreateDTO body) {
|
|
|
|
+ // 创建对话记录前,检查 转人工申请状态 及 发言人 是否在 转人工申请中;
|
|
|
|
+ TransferApply apply = transferApplyService.getById(body.getApply_id());
|
|
|
|
+ if (null == apply) {
|
|
|
|
+ throw new CustomizationException(ExceptionEnum.APPLY_NOT_FOUNT);
|
|
|
|
+ }
|
|
|
|
+ String is_agree = apply.getIs_agree();
|
|
|
|
+ if (!TransferApplyController.TransferApplyAgree.equals(is_agree)) {
|
|
|
|
+ // 抛出异常,当前申请未受理
|
|
|
|
+ throw new CustomizationException(ExceptionEnum.CHAT_APPLY_NOT_AGREE);
|
|
|
|
+ }
|
|
|
|
+ int is_close = apply.getIs_close();
|
|
|
|
+ if (TransferApplyController.TransferApplyClose == is_close) {
|
|
|
|
+ // 抛出异常,当前申请已结束
|
|
|
|
+ throw new CustomizationException(ExceptionEnum.CHAT_APPLY_IS_CLOSE);
|
|
|
|
+ }
|
|
|
|
+ Long customer_id = apply.getCustomer_id();
|
|
|
|
+ Long user_id = apply.getUser_id();
|
|
|
|
+ Long speaker = body.getSpeaker();
|
|
|
|
+ if (customer_id != speaker && user_id != speaker) {
|
|
|
|
+ // 抛出异常,发言人既不是该申请的客服人员,也不是用户
|
|
|
|
+ throw new CustomizationException(ExceptionEnum.CHAT_SPEAKER_NOT_IN_APPLY);
|
|
|
|
+ }
|
|
|
|
+ ChatRecord data = new ChatRecord();
|
|
|
|
+ data.setApply_id(body.getApply_id());
|
|
|
|
+ data.setSpeaker(body.getSpeaker());
|
|
|
|
+ data.setContent(body.getContent());
|
|
this.service.save(data);
|
|
this.service.save(data);
|
|
QueryWrapper qw = new QueryWrapper<>();
|
|
QueryWrapper qw = new QueryWrapper<>();
|
|
qw.eq("id", data.getId());
|
|
qw.eq("id", data.getId());
|
|
Map returnData = this.service.getMap(qw);
|
|
Map returnData = this.service.getMap(qw);
|
|
|
|
+ // TODO:发送mq消息,往chat.${apply_id}中发,客服和用户都会订阅这个
|
|
|
|
+ mqService.sendChatToApply(returnData);
|
|
return ResponseFormat.success(returnData);
|
|
return ResponseFormat.success(returnData);
|
|
// return ResponseFormat.success();
|
|
// return ResponseFormat.success();
|
|
}
|
|
}
|
|
|
|
|
|
- /** 修改数据 */
|
|
|
|
|
|
+ /** 修改数据, 转人工对话不修改 */
|
|
@ApiOperation("修改数据")
|
|
@ApiOperation("修改数据")
|
|
- @PostMapping("/{id}")
|
|
|
|
|
|
+ // @PostMapping("/{id}")
|
|
public Object update(@PathVariable long id, @RequestBody ChatRecord data) {
|
|
public Object update(@PathVariable long id, @RequestBody ChatRecord data) {
|
|
QueryWrapper qw = new QueryWrapper<>();
|
|
QueryWrapper qw = new QueryWrapper<>();
|
|
qw.eq("id", id);
|
|
qw.eq("id", id);
|
|
@@ -106,9 +143,9 @@ public class ChatRecordController {
|
|
return ResponseFormat.success(newData);
|
|
return ResponseFormat.success(newData);
|
|
}
|
|
}
|
|
|
|
|
|
- /** 根据id删除数据 */
|
|
|
|
|
|
+ /** 根据id删除数据 , 无删除 */
|
|
@ApiOperation("删除数据")
|
|
@ApiOperation("删除数据")
|
|
- @DeleteMapping("/{id}")
|
|
|
|
|
|
+ // @DeleteMapping("/{id}")
|
|
public Object delete(@PathVariable long id) {
|
|
public Object delete(@PathVariable long id) {
|
|
QueryWrapper qw = new QueryWrapper<>();
|
|
QueryWrapper qw = new QueryWrapper<>();
|
|
qw.eq("id", id);
|
|
qw.eq("id", id);
|