Browse Source

Merge branch 'master' of http://git.cc-lotus.info/customer/service

zs 8 months ago
parent
commit
0022ad179e

+ 3 - 6
src/main/java/com/free/config/ApplicationStartup.java

@@ -1,25 +1,22 @@
 package com.free.config;
 
-import java.util.Map;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.event.EventListener;
 import org.springframework.stereotype.Component;
 
-import com.free.service.system.AdminService;
+import com.free.service.InitDataService;
 
 /**项目启动后执行函数 */
 @Component
 public class ApplicationStartup {
   @Autowired
-  AdminService adminService;
+  InitDataService service;
 
   @EventListener(ApplicationReadyEvent.class)
   public void onApplicationReady() {
     System.out.println("Spring Boot application started.");
     // 执行需要的逻辑
-    // Map admin = adminService.getMap(null);
-    // System.out.println(admin);
+    service.init();
   }
 }

+ 2 - 1
src/main/java/com/free/controller/ChatRecordController.java

@@ -9,7 +9,6 @@ import javax.validation.Valid;
 
 import com.free.annotation.PassToken;
 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;
@@ -142,6 +141,8 @@ public class ChatRecordController {
       List list = service.list(qw);
       returnList = service.getUserAndCustomerName(list);
     }
+    // 查询当前用户未读数量
+    returnList = service.getUserNotReadNum(returnList);
     map.put("data", returnList);
 
     return ResponseFormat.success(map);

+ 1 - 32
src/main/java/com/free/controller/system/MenusController.java

@@ -114,39 +114,8 @@ public class MenusController {
     List<Map> list = mapper.readValue(str, javaType);
     // 整理数据
     menusMapper.truncate();
-    this.toInsertMenusData(list, null);
+    service.toInsertMenusData(list, null);
     return ResponseFormat.success(list);
   }
 
-  private void toInsertMenusData(List<Map> list, String parent_id) {
-    ObjectMapper mapper = new ObjectMapper();
-    for (int i = 0; i < list.size(); i++) {
-      Map m = list.get(i);
-      // 获取children,然后把map里的children删了,要不影响之后转换成Menus
-      List<Map> children = (List<Map>) m.get("children");
-      m.remove("children");
-      // 获取排序,没有顺序就填充
-      Integer on = (Integer) m.get("order_num");
-      Long order_num = null;
-      if (null == on) {
-        order_num = i + 1L;
-      } else {
-        order_num = Long.valueOf(on);
-      }
-      // 如果有parent_id,说明是子目录,需要加上
-      m.put("parent_id", parent_id);
-      // 转船成menus对象
-      Menus menuData = mapper.convertValue(m, Menus.class);
-      menuData.setOrder_num(order_num);
-      // 创建数据,并获得当前id
-      this.service.save(menuData);
-      if (null == children) {
-        continue;
-      }
-      // 处理children,获取parent_id
-      String children_parent_id = menuData.getId();
-      toInsertMenusData(children, children_parent_id);
-    }
-  }
-
 }

+ 50 - 26
src/main/java/com/free/service/ChatRecordService.java

@@ -1,12 +1,13 @@
 package com.free.service;
 
-import com.free.entity.TransferApply;
 import com.free.entity.system.Customer;
 import com.free.service.system.CustomerService;
+import com.free.utils.JwtUtil;
 import com.free.utils.Utils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.free.entity.ChatRecord;
 import com.free.mapper.ChatRecordMapper;
@@ -18,33 +19,56 @@ import java.util.Map;
 @Service
 public class ChatRecordService extends ServiceImpl<ChatRecordMapper, ChatRecord> {
 
-    @Autowired
-    private CustomerService customerService;
-
-    /**
-     * 将列表中的客服id和用户io的数据取出来
-     *
-     * @param list
-     * @return
-     */
-    public List<Map> getUserAndCustomerName(List<ChatRecord> list) {
-        List<Map> returnData = new ArrayList<>();
-        for (ChatRecord i : list) {
-            Map map = Utils.objectToMap(i);
-            String customer_id = i.getCustomer_id();
-            if (null != customer_id) {
-                Customer cData = customerService.getById(customer_id);
-                if (null != cData) {
-                    map.put("customer_name", cData.getNick_name());
-                }
-            }
-            // TODO:查询用户名称
-            map.put("user_name", "还没有呢");
-
-            returnData.add(map);
+  @Autowired
+  private CustomerService customerService;
 
+  /** 对话记录未读标识 */
+  public static final String chatRecordNotReadSign = "0";
+
+  /**
+   * 查询当前用户查出的列表中的未读数量
+   * @param list
+   * @return
+   */
+  public List<Map> getUserNotReadNum(List<Map> list) {
+    Map userInfo = JwtUtil.getDetails(null);
+    String user_id = (String) userInfo.get("id");
+    for (Map map : list) {
+      String apply_id = (String) map.get("apply_id");
+      QueryWrapper qw = new QueryWrapper<>();
+      qw.eq("apply_id", apply_id);
+      qw.eq("is_read", chatRecordNotReadSign);
+      qw.ne("speaker", user_id);
+      Long num = this.count(qw);
+      map.put("notRead", num);
+    }
+    return list;
+  }
+
+  /**
+   * 将列表中的客服id和用户io的数据取出来
+   *
+   * @param list
+   * @return
+   */
+  public List<Map> getUserAndCustomerName(List<ChatRecord> list) {
+    List<Map> returnData = new ArrayList<>();
+    for (ChatRecord i : list) {
+      Map map = Utils.objectToMap(i);
+      String customer_id = i.getCustomer_id();
+      if (null != customer_id) {
+        Customer cData = customerService.getById(customer_id);
+        if (null != cData) {
+          map.put("customer_name", cData.getNick_name());
         }
-        return returnData;
+      }
+      // TODO:查询用户名称
+      map.put("user_name", "还没有呢");
+
+      returnData.add(map);
+
     }
+    return returnData;
+  }
 
 }

+ 133 - 0
src/main/java/com/free/service/InitDataService.java

@@ -0,0 +1,133 @@
+package com.free.service;
+
+import java.util.List;
+import java.util.Map;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.type.CollectionType;
+import com.free.entity.system.Admin;
+import com.free.service.system.AdminService;
+import com.free.service.system.DictDataService;
+import com.free.service.system.DictTypeService;
+import com.free.service.system.MenusService;
+import com.free.service.system.RoleService;
+import com.free.utils.BcryptUtil;
+import com.free.utils.Utils;
+
+@Service
+public class InitDataService {
+  @Autowired
+  AdminService adminService;
+  @Autowired
+  MenusService menusService;
+  @Autowired
+  RoleService roleService;
+  @Autowired
+  DictTypeService dictTypeService;
+  @Autowired
+  DictDataService dictDataService;
+  @Autowired
+  QuestionService questionService;
+
+  public void init() {
+    admin();
+    menus();
+    role();
+    dictType();
+    dictData();
+    question();
+
+  }
+
+  public void admin() {
+    QueryWrapper qw = new QueryWrapper<>();
+    qw.eq("account", "sadmin");
+    qw.eq("is_super", "0");
+    Long num = adminService.count(qw);
+    if (num > 0) {
+      return;
+    }
+    Admin admin = new Admin();
+    admin.setAccount("sadmin");
+    admin.setIs_super("0");
+    admin.setNick_name("超级管理员");
+    String pwd = "1qaz2wsx";
+    String cpwd = BcryptUtil.encryptPassword(pwd);
+    admin.setPassword(cpwd);
+    adminService.save(admin);
+
+  }
+
+  public void menus() {
+    // 先查询有没有数据
+    Long num = menusService.count();
+    if (num > 0) {
+      return;
+    }
+    List<Map> list = readFile("menus");
+    menusService.initData(list);
+  }
+
+  public void role() {
+    // 先查询有没有数据
+    Long num = roleService.count();
+    if (num > 0) {
+      return;
+    }
+    List<Map> list = readFile("role");
+    roleService.initData(list);
+  }
+
+  public void dictType() {
+    // 先查询有没有数据
+    Long num = dictTypeService.count();
+    if (num > 0) {
+      return;
+    }
+    List<Map> list = readFile("dictType");
+    dictTypeService.initData(list);
+  }
+
+  public void dictData() {
+    // 先查询有没有数据
+    Long num = dictDataService.count();
+    if (num > 0) {
+      return;
+    }
+    List<Map> list = readFile("dictData");
+    dictDataService.initData(list);
+  }
+
+  public void question() {
+    // 先查询有没有数据
+    Long num = questionService.count();
+    if (num > 0) {
+      return;
+    }
+    List<Map> list = readFile("question");
+    questionService.initData(list);
+  }
+
+  public List<Map> readFile(String name) {
+    String filePath = "db/" + name + ".json";
+    ObjectMapper mapper = new ObjectMapper();
+    String str = Utils.readJsonFile(filePath);
+    CollectionType javaType = mapper.getTypeFactory().constructCollectionType(List.class, Map.class);
+    try {
+      List<Map> list = mapper.readValue(str, javaType);
+      return list;
+    } catch (JsonMappingException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    } catch (JsonProcessingException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    }
+    return null;
+  }
+}

+ 39 - 1
src/main/java/com/free/service/system/MenusService.java

@@ -8,6 +8,7 @@ import java.util.stream.Collectors;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.free.entity.system.Menus;
 import com.free.mapper.system.MenusMapper;
 import com.free.utils.Utils;
@@ -15,6 +16,43 @@ import com.free.utils.Utils;
 @Service
 public class MenusService extends ServiceImpl<MenusMapper, Menus> {
 
+  public void initData(List<Map> list) {
+    // 清空表
+    this.baseMapper.truncate();
+    this.toInsertMenusData(list, null);
+  }
+
+  public void toInsertMenusData(List<Map> list, String parent_id) {
+    ObjectMapper mapper = new ObjectMapper();
+    for (int i = 0; i < list.size(); i++) {
+      Map m = list.get(i);
+      // 获取children,然后把map里的children删了,要不影响之后转换成Menus
+      List<Map> children = (List<Map>) m.get("children");
+      m.remove("children");
+      // 获取排序,没有顺序就填充
+      Integer on = (Integer) m.get("order_num");
+      Long order_num = null;
+      if (null == on) {
+        order_num = i + 1L;
+      } else {
+        order_num = Long.valueOf(on);
+      }
+      // 如果有parent_id,说明是子目录,需要加上
+      m.put("parent_id", parent_id);
+      // 转船成menus对象
+      Menus menuData = mapper.convertValue(m, Menus.class);
+      menuData.setOrder_num(order_num);
+      // 创建数据,并获得当前id
+      this.save(menuData);
+      if (null == children) {
+        continue;
+      }
+      // 处理children,获取parent_id
+      String children_parent_id = menuData.getId();
+      toInsertMenusData(children, children_parent_id);
+    }
+  }
+
   /**
    * 递归查询所有菜单
    * 
@@ -88,7 +126,7 @@ public class MenusService extends ServiceImpl<MenusMapper, Menus> {
       // 找children
       for (Map<String, Object> am : allList) {
         String parent_id = (String) am.get("parent_id");
-        if (null!= parent_id && parent_id.equals(id)) {
+        if (null != parent_id && parent_id.equals(id)) {
           // 为子目录,放入children中
           am.put("parent_name", name);
           children.add(am);