dcs 1 月之前
父節點
當前提交
4aded90025

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

@@ -44,13 +44,32 @@ public class CustomerController {
         return Response.ok();
     }
 
+    @ApiOperation("删除客服")
+    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
+    public Response delete(@PathVariable long id) {
+        customerService.delete(id);
+        return Response.ok();
+    }
+
     @ApiOperation("指定用户为客服")
     @RequestMapping(value = "", method = RequestMethod.PUT)
     public Response update(@RequestBody Customer customer) {
+        Customer c = customerService.getOrganizationId(customer.getOrganizationId(), customer.getUserId());
+        if(c != null){
+            return Response.fail(20000, "组织下已经指定过客服了");
+        }
         customerService.update(customer);
         return Response.ok();
     }
 
+    @ApiOperation("更新名称或头像")
+    @RequestMapping(value = "/update", method = RequestMethod.PUT)
+    public Response updateInfo(@RequestBody Customer customer) {
+        customerService.updateInfo(customer);
+        return Response.ok();
+    }
+
+
     @ApiOperation("详情")
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public Response get(@PathVariable long id) {

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

@@ -23,4 +23,6 @@ public interface CustomerDao {
 
     Customer get(long id);
 
+    List<Customer> getOrganizationId(long organizationId, long userId);
+
 }

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

@@ -36,6 +36,8 @@ public class Customer {
 
     private String userPortrait;
 
+    private int isDelete;
+
     public long getId() {
         return id;
     }
@@ -99,4 +101,12 @@ public class Customer {
     public void setUserPortrait(String userPortrait) {
         this.userPortrait = userPortrait;
     }
+
+    public int getIsDelete() {
+        return isDelete;
+    }
+
+    public void setIsDelete(int isDelete) {
+        this.isDelete = isDelete;
+    }
 }

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

@@ -6,6 +6,7 @@ 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.apache.commons.codec.digest.DigestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -75,4 +76,42 @@ public class CustomerService {
     public Customer get(long id) {
         return customerDao.get(id);
     }
+
+    public int delete(long id) {
+        return customerDao.delete(id);
+    }
+
+    public String getToken(String userId) {
+        JSONObject js = new JSONObject();
+        long timestamp = System.currentTimeMillis() + 30000;
+        String yei = "50abd47112ebe8c5a73f4694c96a49ce";
+        String sign = DigestUtils.md5Hex(userId + timestamp + yei);
+
+        js.put("userId", userId);
+        js.put("timestamp", timestamp);
+        js.put("sign", sign);
+        String s = WeChatUtil.httpPost("https://www.waywish.com/im/user/token/get", js, null);
+        if (StringUtil.notBlank(s)) {
+            String token = JSONObject.parseObject(s).getJSONObject("data").getString("token");
+            return token;
+        }
+        return null;
+    }
+
+    public Customer getOrganizationId(long organizationId, long userId) {
+        return customerDao.getOrganizationId(organizationId, userId);
+    }
+
+    @Transactional
+    public int updateInfo(Customer customer) {
+        Customer c = customerDao.get(customer.getId());
+        String token = getToken(c.getCustomerId());
+        JSONObject js = new JSONObject();
+        js.put("nickname", customer.getNickName());
+        js.put("avatarUrl", customer.getAvatarUrl());
+        String str = WeChatUtil.httpPost("https://www.waywish.com/im/user/update", js, token);
+        log.info("updateCustomerChatUser=" + str);
+        return customerDao.update(customer);
+    }
+
 }

+ 16 - 3
virgo.core/src/main/resources/mapper/CustomerMapper.xml

@@ -13,6 +13,9 @@
         <result column="userPortrait" property="userPortrait"/>
     </resultMap>
 
+    <select id="getOrganizationId" resultMap="result">
+        select * from customer where organizationId = #{organizationId} and userId = #{userId}
+    </select>
 
     <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
@@ -20,7 +23,7 @@
 
     <select id="get" resultMap="result">
         <include refid="query"/>
-        where a.id = #{id}
+        where a.id = #{id} and isDelete != 1
     </select>
 
     <select id="getList" resultMap="result">
@@ -28,6 +31,7 @@
         <where>
             <if test="organizationId!=0">and a.organizationId=#{organizationId}</if>
             <if test="userId!=0">and a.userId=#{userId}</if>
+            and isDelete != 1
         </where>
     </select>
 
@@ -36,11 +40,18 @@
     </insert>
 
     <delete id="delete">
-        DELETE FROM customer WHERE id = #{id}
+        UPDATE customer SET isDelete = 1 WHERE id = #{id}
     </delete>
 
     <update id="update" parameterType="com.bosshand.virgo.core.model.Customer">
-        UPDATE customer SET userId = #{userId} WHERE id = #{id}
+        UPDATE customer
+        <trim prefix="set" suffixOverrides=",">
+            <if test="nickName!=null">nickName=#{nickName},</if>
+            <if test="avatarUrl!=null">avatarUrl=#{avatarUrl},</if>
+            <if test="organizationId!=0">organizationId=#{organizationId},</if>
+            <if test="userId!=0">userId=#{userId},</if>
+        </trim>
+        WHERE id = #{id}
     </update>
 
     <select id="getTotalCount" parameterType="com.bosshand.virgo.core.model.Customer" resultType="Integer">
@@ -49,6 +60,7 @@
             <if test="customerId!=null">and customerId=#{customerId}</if>
             <if test="organizationId!=0">and organizationId=#{organizationId}</if>
             <if test="userId!=0">and userId=#{userId}</if>
+            and isDelete != 1
         </where>
     </select>
 
@@ -58,6 +70,7 @@
             <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>
+            and a.isDelete != 1
         </where>
         limit #{currIndex} , #{pageSize}
     </select>