|
|
@@ -8,17 +8,21 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
+import com.cyksj.config.corp.YHLXWxCorpConfig;
|
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeMapper;
|
|
|
import com.cyksj.mapper.corp.CorpFollowDutyRelateMapper;
|
|
|
+import com.cyksj.mapper.corp.CorpFollowServiceRelateMapper;
|
|
|
+import com.cyksj.mapper.corp.CorpTagMapper;
|
|
|
import com.cyksj.model.dto.YhServiceDto;
|
|
|
-import com.cyksj.model.entity.CmsUser;
|
|
|
-import com.cyksj.model.entity.CorpFollow;
|
|
|
-import com.cyksj.model.entity.CorpFollowActiveCode;
|
|
|
-import com.cyksj.model.entity.CorpFollowDutyRelate;
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.request.corp.Attachments;
|
|
|
import com.cyksj.service.corp.CorpFollowDynamicConfigService;
|
|
|
import com.cyksj.service.corp.CorpFollowService;
|
|
|
+import com.cyksj.service.corp.CorpService;
|
|
|
+import com.cyksj.service.corp.WxCorpOps;
|
|
|
import com.cyksj.service.mange.cms.CmsUserManager;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -44,6 +48,16 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
|
|
|
private final CorpFollowDutyRelateMapper corpFollowDutyRelateMapper;
|
|
|
|
|
|
+ private final CorpFollowServiceRelateMapper corpFollowServiceRelateMapper;
|
|
|
+
|
|
|
+ private final WxCorpOps wxCorpOps;
|
|
|
+
|
|
|
+ private final CorpTagMapper corpTagMapper;
|
|
|
+
|
|
|
+ private final CorpService corpService;
|
|
|
+
|
|
|
+ private final YHLXWxCorpConfig yhlxWxCorpConfig;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Throwable.class)
|
|
|
public void postActiveCode(Long adminId, CorpFollowActiveCode activeCode) throws Exception {
|
|
|
@@ -52,16 +66,29 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
activeCode.setOperator(cmsUser.getNickname());
|
|
|
}
|
|
|
Boolean isDuty = Optional.ofNullable(activeCode.getIsDuty()).orElse(false);
|
|
|
- String followStr = activeCode.getFollowStr();
|
|
|
- if (StrUtil.isEmpty(followStr)) {
|
|
|
+ List<CorpFollow> followList = activeCode.getFollowList();
|
|
|
+ if (CollUtil.isEmpty(followList)) {
|
|
|
throw BusinessRuntimeException.getInstance("请选择对应客服");
|
|
|
}
|
|
|
- List<CorpFollow> corpFollows = Jsons.parseList(followStr, CorpFollow.class);
|
|
|
- List<String> followIds = corpFollows.stream().map(CorpFollow::getUserid).collect(Collectors.toList());
|
|
|
+ activeCode.setFollowStr(Jsons.toJson(followList));
|
|
|
+ List<String> followIds = followList.stream().map(CorpFollow::getUserid).collect(Collectors.toList());
|
|
|
activeCode.setMarkTag(activeCode.getMarkTag().trim());
|
|
|
+ String text = activeCode.getText();
|
|
|
+ if (StrUtil.isNotBlank(text) && text.length() > 4000) {
|
|
|
+ throw BusinessRuntimeException.getInstance("欢迎语内容过长");
|
|
|
+ }
|
|
|
+ //附件
|
|
|
+ List<Attachments> attachments = activeCode.getAttachments();
|
|
|
+ if (CollUtil.isNotEmpty(attachments)) {
|
|
|
+ activeCode.setAttachmentsStr(Jsons.toJson(attachments));
|
|
|
+ }
|
|
|
//是否值班
|
|
|
String codeStr;
|
|
|
- corpFollowActiveCodeMapper.insert(activeCode);
|
|
|
+ try {
|
|
|
+ corpFollowActiveCodeMapper.insert(activeCode);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ throw BusinessRuntimeException.getInstance("存在相同的标记标签");
|
|
|
+ }
|
|
|
if (!isDuty) {
|
|
|
//生成一个活码 一个客服或多个客服
|
|
|
codeStr = corpFollowDynamicConfigService.createCorpFollowActiveCode(followIds, Constant.AC_CODE_KEY + activeCode.getId(), true);
|
|
|
@@ -83,14 +110,11 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
throw BusinessRuntimeException.getInstance("对应的数据已不存在");
|
|
|
}
|
|
|
String db_followStr = dbActiveCode.getFollowStr();
|
|
|
- String up_followStr = activeCode.getFollowStr();
|
|
|
- if (StrUtil.isEmpty(up_followStr)) {
|
|
|
- throw BusinessRuntimeException.getInstance("请选择对应客服");
|
|
|
- }
|
|
|
- List<CorpFollow> up_corpFollows = Jsons.parseList(up_followStr, CorpFollow.class);
|
|
|
+ List<CorpFollow> up_corpFollows = activeCode.getFollowList();
|
|
|
if (CollUtil.isEmpty(up_corpFollows)) {
|
|
|
throw BusinessRuntimeException.getInstance("请选择对应客服");
|
|
|
}
|
|
|
+ activeCode.setFollowStr(Jsons.toJson(up_corpFollows));
|
|
|
if (StrUtil.isEmpty(activeCode.getMarkTag())) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入标签");
|
|
|
}
|
|
|
@@ -121,13 +145,17 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
if (!dbActiveCode.getMarkTag().equals(activeCode.getMarkTag())) {
|
|
|
isUpdateAcCode = true;
|
|
|
}
|
|
|
+ activeCode.setAttachmentsStr(dbActiveCode.getAttachmentsStr());
|
|
|
+ if (CollUtil.isEmpty(activeCode.getAttachments())) {
|
|
|
+ activeCode.setAttachmentsStr(null);
|
|
|
+ }
|
|
|
|
|
|
//重新构建活码配置
|
|
|
if (isReCreateAcCode) {
|
|
|
String code_str = corpFollowDynamicConfigService.createCorpFollowActiveCode(followIds, Constant.AC_CODE_KEY + activeCode.getId(), up_isDuty);
|
|
|
activeCode.setCodeStr(code_str);
|
|
|
} else if (isUpdateAcCode) {
|
|
|
- corpFollowDynamicConfigService.updateCorpFollowActiveCode(activeCode.getCodeStr(), Constant.AC_CODE_KEY + activeCode.getId());
|
|
|
+ corpFollowDynamicConfigService.updateCorpFollowActiveCode(dbActiveCode.getMarkTag(), activeCode.getMarkTag());
|
|
|
}
|
|
|
if (activeCode.getCouponId() == null) {
|
|
|
activeCode.setCouponId(0l);
|
|
|
@@ -136,11 +164,19 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteActiveCodeById(Long id) {
|
|
|
- corpFollowActiveCodeMapper.update(null, Wrappers.lambdaUpdate(CorpFollowActiveCode.class)
|
|
|
- .eq(CorpFollowActiveCode::getId, id)
|
|
|
- .set(CorpFollowActiveCode::getDeleted, false)
|
|
|
- .eq(CorpFollowActiveCode::getDeleted, true));
|
|
|
+ public void deleteActiveCodeById(Long id) throws Exception {
|
|
|
+ CorpFollowActiveCode corpFollowActiveCode = corpFollowActiveCodeMapper.selectById(id);
|
|
|
+ if (corpFollowActiveCode == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ corpFollowActiveCode.setDeleted(false);
|
|
|
+ corpFollowActiveCodeMapper.updateById(corpFollowActiveCode);
|
|
|
+
|
|
|
+ CorpTag corpTag = corpTagMapper.selectOne(Wrappers.lambdaQuery(CorpTag.class)
|
|
|
+ .eq(CorpTag::getName, corpFollowActiveCode.getMarkTag()).last("limit 1"));
|
|
|
+ if (corpTag != null) {
|
|
|
+ wxCorpOps.delCorpTag(new String[]{corpTag.getTagId()}, null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -148,6 +184,7 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
if (StrUtil.isEmpty(config)) {
|
|
|
return;
|
|
|
}
|
|
|
+ corpFollowDutyRelateMapper.delete(null);
|
|
|
List<YhServiceDto> yhServiceDtos = Jsons.parseList(config, YhServiceDto.class);
|
|
|
yhServiceDtos.forEach(data -> {
|
|
|
DateTime stTime = DateUtil.parse(data.getStartTime(), "HH:mm");
|
|
|
@@ -157,20 +194,21 @@ public class CorpFollowServiceImpl implements CorpFollowService {
|
|
|
List<YhServiceDto.CustomerServiceDto> select = data.getSelect();
|
|
|
select.forEach(cs -> {
|
|
|
String name = cs.getName();
|
|
|
- CorpFollowDutyRelate relate = Optional.ofNullable(corpFollowDutyRelateMapper.selectOne(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
|
|
|
- .eq(CorpFollowDutyRelate::getServiceName, name).last("limit 1"))).orElse(new CorpFollowDutyRelate());
|
|
|
- relate.setServiceName(name);
|
|
|
- relate.setSt(st);
|
|
|
- relate.setEt(et);
|
|
|
- Integer index = cs.getIndex();
|
|
|
- relate.setIndex(index);
|
|
|
- //1工作日,2.周六,3周末
|
|
|
- Integer type = index <= 2 ? 1 : index <= 4 ? 2 : 3;
|
|
|
- relate.setType(type);
|
|
|
- if (relate.getId() == null) {
|
|
|
+ CorpFollowDutyRelate relate = new CorpFollowDutyRelate();
|
|
|
+ CorpFollowServiceRelate corpFollowServiceRelate = corpFollowServiceRelateMapper.selectOne(Wrappers.lambdaQuery(CorpFollowServiceRelate.class)
|
|
|
+ .eq(CorpFollowServiceRelate::getServiceName, name).last("limit 1"));
|
|
|
+ if (corpFollowServiceRelate != null) {
|
|
|
+ relate.setFollowId(corpFollowServiceRelate.getFollowId());
|
|
|
+ relate.setFollowName(corpFollowServiceRelate.getFollowName());
|
|
|
+ relate.setServiceName(name);
|
|
|
+ relate.setSt(st);
|
|
|
+ relate.setEt(et);
|
|
|
+ Integer index = data.getIndex();
|
|
|
+ relate.setIndexTag(index);
|
|
|
+ //1工作日,2.周六,3周末
|
|
|
+ Integer type = index <= 2 ? 1 : index <= 4 ? 2 : 3;
|
|
|
+ relate.setType(type);
|
|
|
corpFollowDutyRelateMapper.insert(relate);
|
|
|
- } else {
|
|
|
- corpFollowDutyRelateMapper.updateById(relate);
|
|
|
}
|
|
|
});
|
|
|
});
|