Ver código fonte

update 客服处理

wks 1 ano atrás
pai
commit
eff58d0448

+ 0 - 3
src/main/java/com/ydtech/modules/admin/model/po/SysWechatCustomerRecording.java

@@ -20,19 +20,16 @@ public class SysWechatCustomerRecording implements Serializable {
      */
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
-
     /**
      * 客服id
      */
     @TableField(value = "customer_id")
     private Long customerId;
-
     /**
      * 用户id
      */
     @TableField(value = "user_id")
     private String userId;
-
     /**
      * 创建时间
      */

+ 3 - 0
src/main/java/com/ydtech/modules/admin/model/vo/wechat/SysWechatCustomerDutyRulesVo.java

@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
+import javax.validation.constraints.NotBlank;
 import java.io.Serializable;
 import java.util.List;
 
@@ -28,9 +29,11 @@ public class SysWechatCustomerDutyRulesVo implements Serializable {
 
         private static final long serialVersionUID = -633472086045531848L;
 
+        @NotBlank(message = "值班开始时间不能为空")
         @ApiModelProperty("值班时间")
         private String startTime;
 
+        @NotBlank(message = "值班结束时间不能为空")
         @ApiModelProperty("结束时间")
         private String endTime;
 

+ 25 - 2
src/main/java/com/ydtech/modules/admin/service/SysWechatCustomerService.java

@@ -1,12 +1,15 @@
 package com.ydtech.modules.admin.service;
 
 import com.github.pagehelper.PageInfo;
+import com.ydtech.exception.SystemException;
 import com.ydtech.extension.BaseIService;
 import com.ydtech.modules.admin.model.po.SysWechatCustomer;
 import com.ydtech.modules.admin.model.vo.wechat.SysWechatCustomerDutyRulesVo;
 import com.ydtech.modules.admin.model.vo.wechat.SysWechatCustomerQueryVo;
 import com.ydtech.modules.admin.model.vo.wechat.SysWechatCustomerVo;
 
+import java.util.List;
+
 /**
  * @author Administrator
  * @description 针对表【sys_wechat_customer(微信客服)】的数据库操作Service
@@ -45,11 +48,31 @@ public interface SysWechatCustomerService extends BaseIService<SysWechatCustomer
 
     /**
      * 通过用户id 获取微信客服
-     * @param userId  用户id
+     *
+     * @param userId 用户id
      * @return 微信客服
      */
-    default SysWechatCustomer getByUserId(String userId){
+    default SysWechatCustomer getByUserId(String userId) {
         return lambdaQuery().eq(SysWechatCustomer::getUserId, userId).one();
     }
 
+    /**
+     * 昵称是否存在
+     * @param nickname
+     */
+    default void isNicknameRepeat(String nickname) {
+        List<SysWechatCustomer> list = lambdaQuery().eq(SysWechatCustomer::getNickname, nickname).list();
+        if (!list.isEmpty()) {
+            throw new SystemException("客服昵称已存在");
+        }
+    }
+
+    default void isDutyCustomerId(String customerId) {
+        List<SysWechatCustomer> list = lambdaQuery().eq(SysWechatCustomer::getDutyCustomerId, customerId).list();
+        if (!list.isEmpty()) {
+            throw new SystemException("此客服还在值班客服中配置,请删除后重试");
+        }
+    }
+
+
 }

+ 29 - 35
src/main/java/com/ydtech/modules/admin/service/impl/SysWechatCustomerBusinessServiceImpl.java

@@ -26,6 +26,7 @@ import me.chanjar.weixin.cp.bean.WxCpBaseResp;
 import me.chanjar.weixin.cp.bean.WxCpDepart;
 import me.chanjar.weixin.cp.bean.WxCpUser;
 import me.chanjar.weixin.cp.bean.kf.*;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
@@ -56,6 +57,8 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
 
     private final SysWechatCustomerRecordingService sysWechatCustomerRecordingService;
 
+    private final StringRedisTemplate redisTemplate;
+
     @Override
     public List<SysWechatCustomerDeptVo> getDeptByDeptId() throws WxErrorException {
         List<WxCpDepart> list = wxCpDepartmentService.list(null);
@@ -75,9 +78,7 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
     @Override
     public List<SysWeComUserVo> getUser(String deptId) throws WxErrorException {
         List<WxCpUser> wxCpUsers = wxCpUserService.listSimpleByDepartment(Long.valueOf(deptId), true, 0);
-        return wxCpUsers.stream()
-                .map(x -> new SysWeComUserVo(x.getUserId(), x.getName()))
-                .collect(Collectors.toList());
+        return wxCpUsers.stream().map(x -> new SysWeComUserVo(x.getUserId(), x.getName())).collect(Collectors.toList());
     }
 
     @Override
@@ -110,8 +111,7 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
             });
         }
 
-        return new BasePageResult<>(sysWechatCustomerQuery.getPageNum(), sysWechatCustomerQuery.getPageSize(), sysWechatCustomerVoPageInfo.getTotal(),
-                sysWechatCustomerVoPageInfo.getPages(), sysWechatCustomerVoPageInfo.getList());
+        return new BasePageResult<>(sysWechatCustomerQuery.getPageNum(), sysWechatCustomerQuery.getPageSize(), sysWechatCustomerVoPageInfo.getTotal(), sysWechatCustomerVoPageInfo.getPages(), sysWechatCustomerVoPageInfo.getList());
     }
 
 
@@ -125,26 +125,25 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
 
     @Override
     public void addWechatCustomer(SysWechatCustomerAddVo sysWechatCustomerAddVo) throws WxErrorException {
-
+        sysWechatCustomerService.isNicknameRepeat(sysWechatCustomerAddVo.getNickname());
         WxCpKfAccountAdd wxCpKfAccountAdd = new WxCpKfAccountAdd();
         wxCpKfAccountAdd.setName(sysWechatCustomerAddVo.getNickname());
-        wxCpKfAccountAdd.setMediaId("");
         // 头像
-        InsUploadFiles insUploadFiles = insUploadFilesService.getById(sysWechatCustomerAddVo.getAvatar());
-        Optional.ofNullable(insUploadFiles)
-                .map(InsUploadFiles::getFilePath)
-                .ifPresent(filePath -> {
-                    File file = new File(filePath);
-                    // 上传素材
-                    WxMediaUploadResult image;
-                    try {
-                        image = wxCpMediaService.upload("image", file);
-                    } catch (WxErrorException e) {
-                        throw new SystemException("图片上传失败");
-                    }
-                    String mediaId = image.getMediaId();
-                    wxCpKfAccountAdd.setMediaId(mediaId);
-                });
+        if (StringUtils.hasLength(sysWechatCustomerAddVo.getAvatar())) {
+            InsUploadFiles insUploadFiles = insUploadFilesService.getById(sysWechatCustomerAddVo.getAvatar());
+            Optional.ofNullable(insUploadFiles).map(InsUploadFiles::getFilePath).ifPresent(filePath -> {
+                File file = new File(filePath);
+                // 上传素材
+                WxMediaUploadResult image;
+                try {
+                    image = wxCpMediaService.upload("image", file);
+                } catch (WxErrorException e) {
+                    throw new SystemException("图片上传失败");
+                }
+                String mediaId = image.getMediaId();
+                wxCpKfAccountAdd.setMediaId(mediaId);
+            });
+        }
         // 添加
         WxCpKfAccountAddResp wxCpKfAccountAddResp = wxCpKfService.addAccount(wxCpKfAccountAdd);
         SysWechatCustomer sysWechatCustomer = new SysWechatCustomer(sysWechatCustomerAddVo);
@@ -173,6 +172,7 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
 
     @Override
     public void updateWechatCustomer(String customerId, SysWechatCustomerAddVo sysWechatCustomerAddVo) throws WxErrorException {
+        sysWechatCustomerService.isNicknameRepeat(sysWechatCustomerAddVo.getNickname());
         SysWechatCustomer sysWechatCustomer = sysWechatCustomerService.getByIdExist(customerId, "客服不存在");
         WxCpKfAccountUpd wxCpKfAccountUpd = new WxCpKfAccountUpd();
         wxCpKfAccountUpd.setOpenKfid(sysWechatCustomer.getOpenKfId());
@@ -222,8 +222,9 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
     public String getWeChatCustomer(SysUser user) throws WxErrorException {
         SysWechatCustomer sysWechatCustomer = sysWechatCustomerService.getByUserId(user.getLeaderId());
         List<SysWechatCustomer> sysWechatCustomerList = sysWechatCustomerService.list();
-        List<Long> sysWechatCustomerIdList = sysWechatCustomerList.stream().map(SysWechatCustomer::getId).collect(Collectors.toList());
-
+        List<Long> sysWechatCustomerIdList = sysWechatCustomerList.stream()
+                .map(SysWechatCustomer::getId)
+                .collect(Collectors.toList());
         if (ObjectUtils.isEmpty(sysWechatCustomer)) {
             // 获取最近一次的客服记录
             SysWechatCustomerRecording sysWechatCustomerRecording = sysWechatCustomerRecordingService.lambdaQuery()
@@ -233,17 +234,11 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
                     .last("limit 1")
                     .one();
             if (ObjectUtils.isEmpty(sysWechatCustomerRecording)) {
-                // 没有客服记录使用最近的一条
-                sysWechatCustomerRecording = sysWechatCustomerRecordingService.lambdaQuery()
-                        .in(!sysWechatCustomerIdList.isEmpty(), SysWechatCustomerRecording::getCustomerId, sysWechatCustomerIdList)
-                        .orderByDesc(SysWechatCustomerRecording::getCreateTime)
-                        .last("limit 1")
-                        .one();
-                Long i = Optional.ofNullable(sysWechatCustomerRecording)
-                        .map(SysWechatCustomerRecording::getCustomerId)
-                        .orElse(0L);
+                String s = redisTemplate.opsForValue().get("sys:wechat:customer");
+                String s1 = Optional.ofNullable(s)
+                        .orElse("0");
                 sysWechatCustomer = sysWechatCustomerService.lambdaQuery()
-                        .gt(i > 0, SysWechatCustomer::getId, i)
+                        .gt(StringUtils.hasLength(s1), SysWechatCustomer::getId, s1)
                         .orderByAsc(SysWechatCustomer::getId)
                         .last("limit 1")
                         .one();
@@ -259,7 +254,6 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
                         .eq(SysWechatCustomer::getId, sysWechatCustomerRecording.getCustomerId())
                         .one();
             }
-
             SysWechatCustomerRecording customerRecording = new SysWechatCustomerRecording();
             customerRecording.setCustomerId(sysWechatCustomer.getId());
             customerRecording.setUserId(user.getId());

+ 13 - 0
src/main/java/com/ydtech/modules/admin/service/impl/SysWechatCustomerServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.ydtech.exception.SystemException;
 import com.ydtech.modules.admin.dao.SysWechatCustomerMapper;
 import com.ydtech.modules.admin.model.po.SysWechatCustomer;
 import com.ydtech.modules.admin.model.po.SysWechatCustomerDuty;
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 /**
@@ -72,6 +74,16 @@ public class SysWechatCustomerServiceImpl extends ServiceImpl<SysWechatCustomerM
     public void saveOrUpdateCustomerDutyRules(SysWechatCustomerDutyRulesVo sysWechatCustomerDutyRules) {
         SysWechatCustomer customer = getByIdExist(sysWechatCustomerDutyRules.getCustomerId(), "客服不存在");
         SysWechatCustomer dutyCustomer = getByIdExist(sysWechatCustomerDutyRules.getDutyCustomerId(), "值班客服不存在");
+
+        Optional.ofNullable(sysWechatCustomerDutyRules.getDutyDateTimeList())
+                        .ifPresent(sysWechatCustomerDutyRulesList -> {
+                            sysWechatCustomerDutyRulesList.forEach(sysWechatCustomerDutyRule -> {
+                                if (DateTimeUtil.timeComparison(sysWechatCustomerDutyRule.getStartTime(), sysWechatCustomerDutyRule.getEndTime())) {
+                                    throw new SystemException("结束时间必须晚于开始时间");
+                                }
+                            });
+                        });
+
         customer.setDutyCustomerId(dutyCustomer.getId());
         updateById(customer);
         // 清楚再删除
@@ -85,6 +97,7 @@ public class SysWechatCustomerServiceImpl extends ServiceImpl<SysWechatCustomerM
     }
 
 
+
 }
 
 

+ 13 - 0
src/main/java/com/ydtech/utils/DateTimeUtil.java

@@ -535,4 +535,17 @@ public class DateTimeUtil {
         return datePart + " – " + timeRange;
     }
 
+    /**
+     * 时间比较
+     * @param date1 yyyy-MM-dd HH:mm:ss
+     * @param date2 yyyy-MM-dd HH:mm:ss
+     * @return
+     */
+    public static boolean timeComparison(String date1, String date2) {
+        LocalDateTime dateTime1 = DateTimeUtil.parseLocalDateTime(date1, DateTimeUtil.DATETIME_PATTERN);
+        LocalDateTime dateTime2 = DateTimeUtil.parseLocalDateTime(date2, DateTimeUtil.DATETIME_PATTERN);
+        return dateTime1.isAfter(dateTime2);
+    }
+
+
 }

+ 1 - 0
src/main/resources/mapper/modules/admin/SysWechatCustomerMapper.xml

@@ -38,6 +38,7 @@
         <if test="nickname != null and nickname != ''">
             where c.nickname = #{nickname}
         </if>
+        order by c.id
     </select>
 
 </mapper>