dcs 1 месяц назад
Родитель
Сommit
b5ab9c3bdb

+ 60 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/controller/CustomerController.java

@@ -0,0 +1,60 @@
+package com.bosshand.virgo.core.controller;
+
+import com.bosshand.virgo.core.model.Customer;
+import com.bosshand.virgo.core.response.Response;
+import com.bosshand.virgo.core.service.CustomerService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping({"customer"})
+@Api(tags = {"客服管理"})
+public class CustomerController {
+
+    @Autowired
+    CustomerService customerService;
+
+    @ApiOperation("获取")
+    @RequestMapping(value = "/list", method = RequestMethod.POST)
+    public Response list(@RequestBody Customer customer) {
+        return Response.ok(customerService.getList(customer));
+    }
+
+    @ApiOperation("分页获取")
+    @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
+    public Response list(@RequestBody Customer customer, @PathVariable int currPage, @PathVariable int pageSize) {
+        int totalCount = customerService.getTotalCount(customer);
+        List<Customer> dataList = customerService.getLimit(customer, currPage, pageSize);
+        Map<String, Object> result = new HashMap<>();
+        result.put("dataList", dataList);
+        result.put("totalCount", totalCount);
+        return Response.ok(result);
+    }
+
+    @ApiOperation("新增客服")
+    @RequestMapping(value = "", method = RequestMethod.POST)
+    public Response insert(@RequestBody Customer customer) {
+        customerService.insert(customer);
+        return Response.ok();
+    }
+
+    @ApiOperation("指定用户为客服")
+    @RequestMapping(value = "", method = RequestMethod.PUT)
+    public Response update(@RequestBody Customer customer) {
+        customerService.update(customer);
+        return Response.ok();
+    }
+
+    @ApiOperation("详情")
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public Response get(@PathVariable long id) {
+        return Response.ok(customerService.get(id));
+    }
+
+}

+ 26 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/dao/CustomerDao.java

@@ -0,0 +1,26 @@
+package com.bosshand.virgo.core.dao;
+
+import com.bosshand.virgo.core.model.Customer;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface CustomerDao {
+
+    int insert(Customer customer);
+
+    int update(Customer customer);
+
+    int getTotalCount(Customer customer);
+
+    List<Customer> getLimit(@Param("p") Customer p, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
+
+    List<Customer> getList(Customer customer);
+
+    int delete(long id);
+
+    Customer get(long id);
+
+}

+ 102 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/model/Customer.java

@@ -0,0 +1,102 @@
+package com.bosshand.virgo.core.model;
+
+/**
+ * 客服
+ */
+public class Customer {
+
+    private long id;
+
+    /**
+     * 客服id
+     */
+    private String customerId;
+
+    /**
+     * 客服昵称
+     */
+    private String nickName;
+
+    /**
+     * 客服头像
+     */
+    private String avatarUrl;
+
+    /**
+     * 组织id
+     */
+    private long organizationId;
+
+    /**
+     * 绑定用户id
+     */
+    private long userId;
+
+    private String userName;
+
+    private String userPortrait;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getCustomerId() {
+        return customerId;
+    }
+
+    public void setCustomerId(String customerId) {
+        this.customerId = customerId;
+    }
+
+    public String getNickName() {
+        return nickName;
+    }
+
+    public void setNickName(String nickName) {
+        this.nickName = nickName;
+    }
+
+    public String getAvatarUrl() {
+        return avatarUrl;
+    }
+
+    public void setAvatarUrl(String avatarUrl) {
+        this.avatarUrl = avatarUrl;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(long userId) {
+        this.userId = userId;
+    }
+
+    public String getUserName() {
+        return userName;
+    }
+
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+
+    public String getUserPortrait() {
+        return userPortrait;
+    }
+
+    public void setUserPortrait(String userPortrait) {
+        this.userPortrait = userPortrait;
+    }
+}

+ 78 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/service/CustomerService.java

@@ -0,0 +1,78 @@
+package com.bosshand.virgo.core.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.bosshand.virgo.core.dao.CustomerDao;
+import com.bosshand.virgo.core.model.Customer;
+import com.bosshand.virgo.core.utils.CodeCache;
+import com.bosshand.virgo.core.utils.StringUtil;
+import com.bosshand.virgo.core.utils.WeChatUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+@Service
+public class CustomerService {
+
+    static Logger log = LoggerFactory.getLogger(CustomerService.class);
+
+    @Autowired
+    CustomerDao customerDao;
+
+    public int getTotalCount(Customer customer) {
+        return customerDao.getTotalCount(customer);
+    }
+
+    public List<Customer> getLimit(Customer customer, int currPage, int pageSize) {
+        int currIndex = (currPage - 1) * pageSize;
+        return customerDao.getLimit(customer, currIndex, pageSize);
+    }
+
+    @Transactional
+    public void insert(Customer customer) {
+        if (StringUtil.blank(customer.getAvatarUrl())) {
+            customer.setAvatarUrl(CodeCache.DefaultPortrait);
+        }
+        customer.setCustomerId(getNo());
+        customerDao.insert(customer);
+        String url = "http://git.waywish.com:9120/user/register";
+        JSONObject js = new JSONObject();
+        js.put("userId", customer.getCustomerId());
+        js.put("nickname", customer.getNickName());
+        js.put("avatarUrl", customer.getAvatarUrl());
+        String str = WeChatUtil.httpPost(url, js, null);
+        log.info("addCustomerChatUser=" + str);
+    }
+
+    /**
+     * 指定用户为客服
+     */
+    public int update(Customer customer) {
+        return customerDao.update(customer);
+    }
+
+    public List<Customer> getList(Customer customer) {
+        return customerDao.getList(customer);
+    }
+
+    public String getNo() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        String newDate = sdf.format(new Date());
+        String result = "";
+        Random random = new Random();
+        for (int i = 0; i < 3; i++) {
+            result += random.nextInt(10);
+        }
+        return newDate + result;
+    }
+
+    public Customer get(long id) {
+        return customerDao.get(id);
+    }
+}

+ 65 - 0
virgo.core/src/main/resources/mapper/CustomerMapper.xml

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.bosshand.virgo.core.dao.CustomerDao">
+
+    <resultMap type="com.bosshand.virgo.core.model.Customer" id="result">
+        <id column="id" property="id"/>
+        <result column="customerId" property="customerId"/>
+        <result column="nickName" property="nickName"/>
+        <result column="avatarUrl" property="avatarUrl"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="userId" property="userId"/>
+        <result column="userName" property="userName"/>
+        <result column="userPortrait" property="userPortrait"/>
+    </resultMap>
+
+
+    <sql id="query">
+        select a.*, b.name as userName, b.portrait as userPortrait from customer a left join mgr_user b on a.userId = b.id
+    </sql>
+
+    <select id="get" resultMap="result">
+        <include refid="query"/>
+        where a.id = #{id}
+    </select>
+
+    <select id="getList" resultMap="result">
+        <include refid="query"/>
+        <where>
+            <if test="organizationId!=0">and a.organizationId=#{organizationId}</if>
+            <if test="userId!=0">and a.userId=#{userId}</if>
+        </where>
+    </select>
+
+    <insert id="insert" parameterType="com.bosshand.virgo.core.model.Customer" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO customer(customerId, nickName, avatarUrl, organizationId, userId) VALUES (#{customerId}, #{nickName}, #{avatarUrl}, #{organizationId}, #{userId})
+    </insert>
+
+    <delete id="delete">
+        DELETE FROM customer WHERE id = #{id}
+    </delete>
+
+    <update id="update" parameterType="com.bosshand.virgo.core.model.Customer">
+        UPDATE customer SET userId = #{userId} WHERE id = #{id}
+    </update>
+
+    <select id="getTotalCount" parameterType="com.bosshand.virgo.core.model.Customer" resultType="Integer">
+        SELECT count(*) FROM customer
+        <where>
+            <if test="customerId!=null">and customerId=#{customerId}</if>
+            <if test="organizationId!=0">and organizationId=#{organizationId}</if>
+            <if test="userId!=0">and userId=#{userId}</if>
+        </where>
+    </select>
+
+    <select id="getLimit" resultMap="result">
+        <include refid="query"/>
+        <where>
+            <if test="p.customerId!=null">and a.customerId=#{p.customerId}</if>
+            <if test="p.organizationId!=0">and a.organizationId=#{p.organizationId}</if>
+            <if test="p.userId!=0">and a.userId=#{p.userId}</if>
+        </where>
+        limit #{currIndex} , #{pageSize}
+    </select>
+
+</mapper>