lrf 8 months ago
parent
commit
39fd8a9f24

+ 1 - 0
src/main/java/com/free/config/ExceptionEnum.java

@@ -17,6 +17,7 @@ public enum ExceptionEnum {
   CHAT_APPLY_IS_CLOSE("40010", "转人工申请已结束"),
   CHAT_SPEAKER_NOT_IN_APPLY("40011", "当前用户无法发言"),
   ACCPET_USER_TYPE_FAULT("40012", "当前用户不是客服人员,无法受理转人工申请"),
+  UID_EXIST("40013","其他系统标识已存在"),
   ACCOUNT_IS_EXIST("4011", "账号已存在"),
   ACCOUNT_NOT_FOUND("4012", "未找到账号信息"),
   PASSWORD_ERROR("4013", "密码错误"),

+ 5 - 0
src/main/java/com/free/controller/CustomizationExcep.java

@@ -0,0 +1,5 @@
+package com.free.controller;
+
+public class CustomizationExcep {
+
+}

+ 157 - 0
src/main/java/com/free/controller/UserController.java

@@ -0,0 +1,157 @@
+package com.free.controller;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.validation.Valid;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.free.annotation.PassToken;
+import com.free.config.CustomizationException;
+import com.free.config.ExceptionEnum;
+import com.free.config.ResponseFormat;
+import com.free.dto.UserGetInfoDTO;
+import com.free.entity.User;
+import com.free.service.UserService;
+import com.free.utils.JwtUtil;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+@RestController
+@RequestMapping("/user")
+@Api(tags = "使用用户")
+public class UserController {
+  @Autowired
+  private UserService service;
+  @PassToken
+  @ApiOperation("用户进入智能客服获取信息")
+  @PostMapping("/getInfo")
+  public Object getInfo(@RequestBody UserGetInfoDTO body) {
+    QueryWrapper qw = new QueryWrapper<>();
+    qw.eq("uid", body.getUid());
+    Map user = service.getMap(qw);
+    if (null == user) {
+      // 用户首次登录,需要获取用户信息
+      User newUser = new User();
+      newUser.setUid(body.getUid());
+      // TODO:获取用户信息并填充,缺字段再补
+      newUser.setName("游客");
+      service.save(newUser);
+      // 再将新创建的用户赋值回user中,后面统一处理
+      QueryWrapper nqw = new QueryWrapper<>();
+      nqw.eq("id", newUser.getId());
+      user = service.getMap(nqw);
+    }
+    // 将用户转换成token
+    String code = JwtUtil.sign(user);
+    return ResponseFormat.success(code);
+  }
+
+  /** 创建数据 */
+  @ApiOperation("创建数据")
+  @PostMapping("")
+  public Object save(@RequestBody @Valid User data) {
+    QueryWrapper oqw = new QueryWrapper<>();
+    oqw.eq("uid", data.getUid());
+    Long num = service.count(oqw);
+    if(num>0) {
+      throw new CustomizationException(ExceptionEnum.UID_EXIST);
+    }
+    this.service.save(data);
+    QueryWrapper qw = new QueryWrapper<>();
+    qw.eq("id", data.getId());
+    Map returnData = this.service.getMap(qw);
+    return ResponseFormat.success(returnData);
+    // return ResponseFormat.success();
+  }
+
+  @ApiOperation("修改数据")
+  @PostMapping("/{id}")
+  public Object update(@PathVariable String id, @RequestBody User data) {
+    QueryWrapper qw = new QueryWrapper<>();
+    qw.eq("id", id);
+    Long num = this.service.count(qw);
+    if (num <= 0) {
+      throw new CustomizationException(ExceptionEnum.NOT_FOUND);
+    }
+    // 需要清掉uid修改,不允许修改,要改就删了再加
+    data.setUid(null);
+    data.setId(id);
+    this.service.updateById(data);
+    Object newData = this.service.getById(id);
+    return ResponseFormat.success(newData);
+  }
+
+  @ApiOperation("查询数据列表")
+  @SuppressWarnings({ "unchecked" })
+  @GetMapping()
+  public Object list(@RequestParam Map<String, Object> allParams) {
+    Long skip = null, limit = null;
+    Map map = new HashMap();
+    QueryWrapper qw = new QueryWrapper<>();
+    qw.select("id", "title", "platform", "is_use");
+    /** 参数处理处理 */
+    for (String key : allParams.keySet()) {
+      Object value = allParams.get(key);
+      if (key.equals("skip")) {
+        skip = Long.valueOf(String.valueOf(value));
+      } else if (key.equals("limit")) {
+        limit = Long.valueOf(String.valueOf(value));
+      } else {
+        if (key.equals("title") || key.equals("platform")) {
+          qw.like(key, value);
+        } else {
+          // 其他为查询条件
+          qw.eq(key, value);
+        }
+      }
+    }
+    /** 分页处理 */
+    if (null != skip && null != limit) {
+      IPage page = new Page<>(skip, limit);
+      IPage pageResult = service.page(page, qw);
+      List data = pageResult.getRecords();
+      long total = pageResult.getTotal();
+      map.put("data", data);
+      map.put("total", total);
+    } else {
+      List list = service.list(qw);
+      map.put("data", list);
+    }
+    return ResponseFormat.success(map);
+  }
+
+  @ApiOperation("查询数据")
+  @GetMapping("/{id}")
+  public Object fetch(@PathVariable String id) {
+    Object newData = service.getById(id);
+    return ResponseFormat.success(newData);
+  }
+
+  @ApiOperation("删除数据")
+  @DeleteMapping("/{id}")
+  public Object delete(@PathVariable String id) {
+    QueryWrapper qw = new QueryWrapper<>();
+    qw.eq("id", id);
+    Long num = service.count(qw);
+    if (num <= 0) {
+      throw new CustomizationException(ExceptionEnum.NOT_FOUND);
+    }
+    service.removeById(id);
+    return ResponseFormat.success();
+  }
+}

+ 11 - 0
src/main/java/com/free/dto/UserGetInfoDTO.java

@@ -0,0 +1,11 @@
+package com.free.dto;
+
+import javax.validation.constraints.NotBlank;
+
+import lombok.Data;
+
+@Data
+public class UserGetInfoDTO {
+  @NotBlank(message = "缺少用户标识")
+  private String uid;
+}

+ 29 - 0
src/main/java/com/free/entity/User.java

@@ -0,0 +1,29 @@
+package com.free.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.free.utils.BaseEntity;
+import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
+import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Table(name = "user")
+@TableName(value = "user")
+@ApiModel("转人工服务")
+public class User extends BaseEntity{
+  @Column(comment = "用户名称")
+  @TableField(value = "name")
+  @ApiModelProperty("用户名称")
+  private String name;
+
+  @Column(comment = "其他系统标识")
+  @TableField(value = "uid")
+  @ApiModelProperty("其他系统标识")
+  private String uid;
+}

+ 11 - 0
src/main/java/com/free/mapper/UserMapper.java

@@ -0,0 +1,11 @@
+package com.free.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.free.entity.User;
+
+@Mapper
+public interface UserMapper extends BaseMapper<User> {
+
+}

+ 36 - 23
src/main/java/com/free/schedule/ClearTransferApply.java

@@ -28,6 +28,7 @@ public class ClearTransferApply {
   private ChatRecordService chatRecordService;
   /** 自动关闭时间: 10分钟 */
   private Long limit = 10L;
+
   // 每2分整执行一次
   @Scheduled(cron = "0 0/2 * * * ? ")
   public void schedule() {
@@ -37,28 +38,40 @@ public class ClearTransferApply {
     log.info("当前执行任务的线程号ID===>{}", Thread.currentThread().getId()); // 日志输出
     log.info("当前执行任务时间===>{}", nowTimeStr); // 日志输出
     // 查询受理但是没有结束的转人工申请
-    // QueryWrapper applyQw = new QueryWrapper<>();
-    // applyQw.eq("is_agree", TransferApplyController.TransferApplyAgree);
-    // applyQw.eq("is_close", TransferApplyController.TransferApplyNotClose);
-    // List<TransferApply> agreeNotCloseApplyList = transferApplyService.list(applyQw);
-    // // 查询这些没结束的转人工申请, 最后一次发言时间
-    // for (TransferApply i : agreeNotCloseApplyList) {
-    //   QueryWrapper chatRecordQw = new QueryWrapper<>();
-    //   chatRecordQw.eq("apply_id", i.getId());
-    //   chatRecordQw.orderByDesc("time");
-    //   ChatRecord chatRecord = chatRecordService.getOne(chatRecordQw);
-    //   LocalDateTime chat_time = chatRecord.getTime();
-    //   chat_time.plusMinutes(limit);
-    //   // 判断, 最后的发言时间 + 自动关闭时间的10分钟 是否在当前时间之前:
-    //   // 在当前时间之前: 不处理,未超时
-    //   // 不在当前时间之前: 超过自动关闭的时间,直接关闭
-    //   boolean isBefore = nowTime.isBefore(chat_time);
-    //   if (!isBefore) {
-    //     TransferApply closeData = new TransferApply();
-    //     closeData.setId(i.getId());
-    //     closeData.setIs_close(TransferApplyController.TransferApplyClose);
-    //     transferApplyService.updateById(closeData);
-    //   }
-    // }
+    QueryWrapper applyQw = new QueryWrapper<>();
+    applyQw.eq("is_agree", TransferApplyController.TransferApplyAgree);
+    applyQw.eq("is_close", TransferApplyController.TransferApplyNotClose);
+    List<TransferApply> agreeNotCloseApplyList = transferApplyService.list(applyQw);
+    // 查询这些没结束的转人工申请, 最后一次发言时间
+    for (TransferApply i : agreeNotCloseApplyList) {
+      QueryWrapper chatRecordQw = new QueryWrapper<>();
+      chatRecordQw.eq("apply_id", i.getId());
+      chatRecordQw.orderByDesc("time");
+      chatRecordQw.last("limit 1");
+      ChatRecord chatRecord = chatRecordService.getOne(chatRecordQw);
+      boolean isBefore = true;
+      if (null != chatRecord) {
+        // 有聊天记录,就根据最后一次发言时间判断
+        LocalDateTime chat_time = chatRecord.getTime();
+        chat_time.plusMinutes(limit);
+        isBefore = nowTime.isBefore(chat_time);
+        
+      } else {
+        // 没有聊天记录,用申请时间判断,10分钟不说话就给关了
+        LocalDateTime apply_time = i.getApply_time();
+        apply_time.plusMinutes(limit);
+        isBefore = nowTime.isBefore(apply_time);
+      }
+      // 判断, 最后的发言时间 + 自动关闭时间的10分钟 是否在当前时间之前:
+      // 在当前时间之前: 不处理,未超时
+      // 不在当前时间之前: 超过自动关闭的时间,直接关闭
+      if (!isBefore) {
+        TransferApply closeData = new TransferApply();
+        closeData.setId(i.getId());
+        closeData.setIs_close(TransferApplyController.TransferApplyClose);
+        transferApplyService.updateById(closeData);
+      }
+
+    }
   }
 }

+ 12 - 0
src/main/java/com/free/service/UserService.java

@@ -0,0 +1,12 @@
+package com.free.service;
+
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.free.entity.User;
+import com.free.mapper.UserMapper;
+
+@Service
+public class UserService extends ServiceImpl<UserMapper, User> {
+
+}