wks 1 год назад
Родитель
Сommit
41607a2c45

+ 1 - 1
src/main/java/com/ydtech/modules/admin/controller/SysQyWeChatController.java

@@ -77,7 +77,7 @@ public class SysQyWeChatController {
 
     @ApiOperation(value = "查询微信客服链接")
     @PostMapping(value = "/find/wechatCustomer")
-    public HttpResult<String> findWechatPictureByUserId() throws WxErrorException {
+    public HttpResult<String> findWechatCustomerLink() throws WxErrorException {
         String userId = BaseController.getUser().getId();
         SysUser user = sysUserService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, userId));
         String link = sysWechatCustomerBusinessService.getWeChatCustomer(user);

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

@@ -67,12 +67,13 @@ public interface SysWechatCustomerService extends BaseIService<SysWechatCustomer
         }
     }
 
-    default void isDutyCustomerId(String customerId) {
+    default void isDutyCustomerId(Long customerId) {
         List<SysWechatCustomer> list = lambdaQuery().eq(SysWechatCustomer::getDutyCustomerId, customerId).list();
         if (!list.isEmpty()) {
             throw new SystemException("此客服还在值班客服中配置,请删除后重试");
         }
     }
 
+    void getCacheCustomerId(SysWechatCustomer sysWechatCustomer);
 
 }

+ 8 - 18
src/main/java/com/ydtech/modules/admin/service/impl/SysWechatCustomerBusinessServiceImpl.java

@@ -57,8 +57,6 @@ 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);
@@ -160,6 +158,7 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
     @Override
     public void deleteWechatCustomer(String customerId) throws WxErrorException {
         SysWechatCustomer sysWechatCustomer = sysWechatCustomerService.getByIdExist(customerId, "客服不存在");
+        sysWechatCustomerService.isDutyCustomerId(sysWechatCustomer.getId());
         WxCpKfAccountDel wxCpKfAccountDel = new WxCpKfAccountDel();
         wxCpKfAccountDel.setOpenKfid(sysWechatCustomer.getOpenKfId());
         WxCpBaseResp wxCpBaseResp;
@@ -172,8 +171,10 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
 
     @Override
     public void updateWechatCustomer(String customerId, SysWechatCustomerAddVo sysWechatCustomerAddVo) throws WxErrorException {
-        sysWechatCustomerService.isNicknameRepeat(sysWechatCustomerAddVo.getNickname());
         SysWechatCustomer sysWechatCustomer = sysWechatCustomerService.getByIdExist(customerId, "客服不存在");
+        if(!sysWechatCustomer.getNickname().equals(sysWechatCustomerAddVo.getNickname())){
+            sysWechatCustomerService.isNicknameRepeat(sysWechatCustomerAddVo.getNickname());
+        }
         WxCpKfAccountUpd wxCpKfAccountUpd = new WxCpKfAccountUpd();
         wxCpKfAccountUpd.setOpenKfid(sysWechatCustomer.getOpenKfId());
         boolean isAvatarSame = StringUtils.hasLength(sysWechatCustomer.getAvatar()) && !sysWechatCustomer.getAvatar()
@@ -234,25 +235,15 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
                     .last("limit 1")
                     .one();
             if (ObjectUtils.isEmpty(sysWechatCustomerRecording)) {
-                String s = redisTemplate.opsForValue().get("sys:wechat:customer");
-                String s1 = Optional.ofNullable(s)
-                        .orElse("0");
-                sysWechatCustomer = sysWechatCustomerService.lambdaQuery()
-                        .gt(StringUtils.hasLength(s1), SysWechatCustomer::getId, s1)
-                        .orderByAsc(SysWechatCustomer::getId)
-                        .last("limit 1")
-                        .one();
-                if (ObjectUtils.isEmpty(sysWechatCustomer)) {
-                    sysWechatCustomer = sysWechatCustomerService.lambdaQuery()
-                            .orderByAsc(SysWechatCustomer::getId)
-                            .last("limit 1")
-                            .one();
-                }
+                sysWechatCustomerService.getCacheCustomerId(sysWechatCustomer);
             } else {
                 // 使用上一次的客服
                 sysWechatCustomer = sysWechatCustomerService.lambdaQuery()
                         .eq(SysWechatCustomer::getId, sysWechatCustomerRecording.getCustomerId())
                         .one();
+                if (ObjectUtils.isEmpty(sysWechatCustomer)) {
+                    sysWechatCustomerService.getCacheCustomerId(sysWechatCustomer);
+                }
             }
             SysWechatCustomerRecording customerRecording = new SysWechatCustomerRecording();
             customerRecording.setCustomerId(sysWechatCustomer.getId());
@@ -281,5 +272,4 @@ public class SysWechatCustomerBusinessServiceImpl implements SysWechatCustomerBu
         return accountLink.getUrl();
     }
 
-
 }

+ 26 - 2
src/main/java/com/ydtech/modules/admin/service/impl/SysWechatCustomerServiceImpl.java

@@ -15,8 +15,11 @@ import com.ydtech.modules.admin.service.SysWechatCustomerDutyService;
 import com.ydtech.modules.admin.service.SysWechatCustomerService;
 import com.ydtech.utils.DateTimeUtil;
 import lombok.RequiredArgsConstructor;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
 
 import java.util.List;
 import java.util.Optional;
@@ -34,6 +37,8 @@ public class SysWechatCustomerServiceImpl extends ServiceImpl<SysWechatCustomerM
 
     private final SysWechatCustomerDutyService sysWechatCustomerDutyService;
 
+    private final StringRedisTemplate redisTemplate;
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void deleteAllInfo(String customerId) {
@@ -56,6 +61,8 @@ public class SysWechatCustomerServiceImpl extends ServiceImpl<SysWechatCustomerM
         sysWechatCustomerDutyRulesVo.setCustomerId(String.valueOf(customer.getId()));
         if (customer.getDutyCustomerId() > 0) {
             sysWechatCustomerDutyRulesVo.setDutyCustomerId(String.valueOf(customer.getDutyCustomerId()));
+        }else {
+            sysWechatCustomerDutyRulesVo.setDutyCustomerId(null);
         }
         List<SysWechatCustomerDutyRulesVo.DutyDateTime> collect = sysWechatCustomerDuties.stream()
                 .map(sysWechatCustomerDuty -> {
@@ -96,8 +103,25 @@ public class SysWechatCustomerServiceImpl extends ServiceImpl<SysWechatCustomerM
         sysWechatCustomerDutyService.saveBatch(collect);
     }
 
-
-
+    @Override
+    public void getCacheCustomerId(SysWechatCustomer sysWechatCustomer) {
+        String customerCache = redisTemplate.opsForValue().get("sys:wechat:customer");
+        String s1 = Optional.ofNullable(customerCache)
+                .orElse("0");
+        sysWechatCustomer = lambdaQuery()
+                .gt(StringUtils.hasLength(s1), SysWechatCustomer::getId, s1)
+                .orderByAsc(SysWechatCustomer::getId)
+                .last("limit 1")
+                .one();
+
+        if (ObjectUtils.isEmpty(sysWechatCustomer)) {
+            sysWechatCustomer = lambdaQuery()
+                    .orderByAsc(SysWechatCustomer::getId)
+                    .last("limit 1")
+                    .one();
+        }
+        redisTemplate.opsForValue().set("sys:wechat:customer", String.valueOf(sysWechatCustomer.getId()));
+    }
 }