|
|
@@ -9,14 +9,25 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.common.util.SmsUtil;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
+import com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkMapper;
|
|
|
+import com.cyksj.mapper.corp.CorpFollowActiveCodeMapper;
|
|
|
import com.cyksj.mapper.manage.cms.CmsUserMapper;
|
|
|
import com.cyksj.mapper.sys.SysConfigChangeRecordMapper;
|
|
|
-import com.cyksj.model.dto.YhServiceChangeDto;
|
|
|
-import com.cyksj.model.dto.YhServiceDto;
|
|
|
+import com.cyksj.model.dto.*;
|
|
|
import com.cyksj.model.entity.CmsUser;
|
|
|
+import com.cyksj.model.entity.CorpCustomerAcquisitionLink;
|
|
|
+import com.cyksj.model.entity.CorpFollowActiveCode;
|
|
|
import com.cyksj.model.entity.SysConfigChangeRecord;
|
|
|
+import com.cyksj.model.request.corp.link.Range;
|
|
|
+import com.cyksj.model.request.corp.link.WxCpLinkAddResp;
|
|
|
+import com.cyksj.model.request.corp.link.WxCpLinkUpd;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
+import com.cyksj.service.corp.CorpFollowDynamicConfigService;
|
|
|
+import com.cyksj.service.corp.WxCorpOps;
|
|
|
import com.cyksj.service.sys.SysConfigChangeRecordService;
|
|
|
+import com.cyksj.service.sys.SysCorpServiceRelateService;
|
|
|
+import com.cyksj.xxljob.XxlJobInfo;
|
|
|
+import com.cyksj.xxljob.XxlJobUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -25,6 +36,8 @@ import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -43,12 +56,23 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
+ private final CorpFollowActiveCodeMapper corpFollowActiveCodeMapper;
|
|
|
+
|
|
|
+ private final CorpFollowDynamicConfigService corpFollowDynamicConfigService;
|
|
|
+
|
|
|
+ private final SysCorpServiceRelateService sysCorpServiceRelateService;
|
|
|
+
|
|
|
+ private final CorpCustomerAcquisitionLinkMapper corpCustomerAcquisitionLinkMapper;
|
|
|
+
|
|
|
+ private final WxCorpOps corpOps;
|
|
|
+
|
|
|
@Override
|
|
|
- public Boolean changeRecord(Long adminId, String sysKey, String sysValue, String updateValue) throws Exception {
|
|
|
+ public SysServiceChangeDto changeRecord(Long adminId, String sysKey, String sysValue, String updateValue) throws Exception {
|
|
|
CmsUser cmsUser = cmsUserMapper.selectById(adminId);
|
|
|
if (cmsUser == null) {
|
|
|
throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_TOKEN_VALID);
|
|
|
}
|
|
|
+ SysServiceChangeDto sysServiceChangeDto = new SysServiceChangeDto();
|
|
|
//保存客服系统配置key前后更新数据
|
|
|
if (Constant.serviceKeys.contains(sysKey)) {
|
|
|
if (!StrUtil.equals(sysValue, updateValue)) {
|
|
|
@@ -57,6 +81,8 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
|
|
|
sysConfigChangeRecord.setPreValue(sysValue);
|
|
|
sysConfigChangeRecord.setBackValue(updateValue);
|
|
|
sysConfigChangeRecord.setOperator(cmsUser.getNickname());
|
|
|
+
|
|
|
+ List<Integer> updateFollowIndxList = new ArrayList<>();
|
|
|
if (Constant.serviceKeys.get(0).equals(sysKey)) {
|
|
|
//变更记录
|
|
|
List<YhServiceDto> before = Jsons.parseList(sysValue, YhServiceDto.class);
|
|
|
@@ -106,12 +132,28 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
|
|
|
SmsUtil.sendLuoKey2Msg(Constant.DUTY_SERVICE_CHANGE_NOTIFY_PHONE, String.format(Constant.DUTY_SERVICE_CHANGE_MSG, weekdayMsgNotifySb));
|
|
|
}
|
|
|
}
|
|
|
+ sysServiceChangeDto.setChangeCsImg(true);
|
|
|
+ } else {
|
|
|
+ List<YhServiceNameDto> before = Jsons.parseList(sysValue, YhServiceNameDto.class);
|
|
|
+ Map<Integer, List<YhServiceNameDto>> afterIndxMap = Jsons.parseList(updateValue, YhServiceNameDto.class).stream().collect(Collectors.groupingBy(YhServiceNameDto::getIndx));
|
|
|
+ before.forEach(e1 -> {
|
|
|
+ List<YhServiceNameDto> serviceNameDtos = afterIndxMap.get(e1.getIndx());
|
|
|
+ if (CollUtil.isNotEmpty(serviceNameDtos)) {
|
|
|
+ YhServiceNameDto e2 = serviceNameDtos.get(0);
|
|
|
+ if (e1.getIndx() == e2.getIndx() && !StrUtil.equals(e1.getFollowId(), e2.getFollowId())) {
|
|
|
+ updateFollowIndxList.add(e1.getIndx());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (CollUtil.isNotEmpty(updateFollowIndxList)) {
|
|
|
+ sysServiceChangeDto.setChangeCsName(true);
|
|
|
+ sysServiceChangeDto.setUpdateFollowIndxs(updateFollowIndxList);
|
|
|
+ }
|
|
|
}
|
|
|
this.save(sysConfigChangeRecord);
|
|
|
- return true;
|
|
|
}
|
|
|
}
|
|
|
- return false;
|
|
|
+ return sysServiceChangeDto;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -152,4 +194,56 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateCorpFollowLinkConfig(List<Integer> updateFollowIndx) throws Exception {
|
|
|
+ List<CorpFollowActiveCode> corpFollowActiveCodes = corpFollowActiveCodeMapper.selectActiveCodeByFollowIndx(updateFollowIndx);
|
|
|
+ Map<Integer, List<CorpFollowServiceDto>> corpYhFollowService = sysCorpServiceRelateService.getCorpYhFollowService();
|
|
|
+ //去更新活码对应客服 成员id
|
|
|
+ corpFollowActiveCodes.forEach(data -> {
|
|
|
+ try {
|
|
|
+ List<Integer> upUserIndxList = Jsons.parseList(data.getFollowStr(), Integer.class);
|
|
|
+ List<String> up_followStrList = sysCorpServiceRelateService.getFollowIdsByRelateIds(upUserIndxList, corpYhFollowService);
|
|
|
+ String code_str = corpFollowDynamicConfigService.createCorpFollowActiveCode(up_followStrList, upUserIndxList, Constant.AC_CODE_KEY + data.getId(), data.getIsDuty());
|
|
|
+ data.setCodeStr(code_str);
|
|
|
+ Set<String> keys = redisService.keys(RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getNameFormat(data.getId(), "*"));
|
|
|
+ redisService.del(keys.toArray(String[]::new));
|
|
|
+ corpFollowActiveCodeMapper.updateById(data);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //去更新获客链接 成员id
|
|
|
+ List<CorpCustomerAcquisitionLink> acquisitionLinks = corpCustomerAcquisitionLinkMapper.selectActiveCodeByFollowIndx(updateFollowIndx);
|
|
|
+ AtomicBoolean isDutyTask = new AtomicBoolean(false);
|
|
|
+ acquisitionLinks.forEach(link -> {
|
|
|
+ try {
|
|
|
+ WxCpLinkUpd wxCpLinkUpd = new WxCpLinkUpd();
|
|
|
+ wxCpLinkUpd.setLinkName(link.getLinkName());
|
|
|
+ wxCpLinkUpd.setLinkId(link.getLinkId());
|
|
|
+ wxCpLinkUpd.setSkipVerify(link.getSkipVerify());
|
|
|
+ Range range = new Range();
|
|
|
+ //值班客服
|
|
|
+ String userList;
|
|
|
+ if (link.getIsDuty()) {
|
|
|
+ userList = link.getChooseDutyUsers();
|
|
|
+ } else {
|
|
|
+ userList = link.getUserList();
|
|
|
+ }
|
|
|
+ List<String> followIds = sysCorpServiceRelateService.getFollowIdsByRelateIds(Jsons.parseList(userList, Integer.class), corpYhFollowService);
|
|
|
+ range.setUserList(followIds);
|
|
|
+ wxCpLinkUpd.setRange(range);
|
|
|
+ WxCpLinkAddResp wxCpLinkAddResp = corpOps.customerAcquisitionUpdateLink(null, wxCpLinkUpd);
|
|
|
+
|
|
|
+ corpCustomerAcquisitionLinkMapper.updateById(link);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (isDutyTask.get()) {
|
|
|
+ //立即执行客服值班定时任务
|
|
|
+ XxlJobUtil.executeMarkDynamicRuleTagJob(XxlJobInfo.getExecuteTaskInstance(Constant.CORP_LINK_JOB_ID, StrUtil.EMPTY).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|