|
|
@@ -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());
|