zoujiajian 2 лет назад
Родитель
Сommit
feabc6bd16

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpCustomerAcquisitionLinkMapper.java

@@ -2,8 +2,11 @@ package com.cyksj.mapper.corp;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.CorpCustomerAcquisitionLink;
+import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
+import java.util.List;
+
 /**
  * @author chan
  * @date 2023/11/28 14:21
@@ -12,4 +15,6 @@ public interface CorpCustomerAcquisitionLinkMapper extends BaseMapper<CorpCustom
 
     @Select("select cl.* from corp_customer_acquisition_link cl, corp_customer_acquisition_link_popularize clp where cl.id = clp.customer_acquistion_link_id and clp.id = #{linkId}")
     CorpCustomerAcquisitionLink getByLinkPopularizeId(Long linkId);
+
+	List<CorpCustomerAcquisitionLink> selectActiveCodeByFollowIndx(@Param("list") List<Integer> updateFollowIndx);
 }

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpFollowActiveCodeMapper.java

@@ -2,6 +2,9 @@ package com.cyksj.mapper.corp;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.CorpFollowActiveCode;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 项目名: yhlxj
@@ -10,4 +13,6 @@ import com.cyksj.model.entity.CorpFollowActiveCode;
  * 创建时间:2023/10/9 16:27
  */
 public interface CorpFollowActiveCodeMapper extends BaseMapper<CorpFollowActiveCode> {
+
+	List<CorpFollowActiveCode> selectActiveCodeByFollowIndx(@Param("list") List<Integer> indx);
 }

+ 24 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/YhServiceNameDto.java

@@ -0,0 +1,24 @@
+package com.cyksj.model.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: YhServiceNameDto
+ * 创建者: JavaZou
+ * 创建时间:2024/1/11 15:45
+ */
+@Getter
+@Setter
+public class YhServiceNameDto {
+	private String name;
+
+	private String img;
+
+	private Integer indx;
+
+	private String url;
+
+	private String followId;
+}

+ 14 - 0
netflix-dao/src/main/resources/mapper/CorpCustomerAcquisitionLinkMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkMapper">
+
+    <select id="selectActiveCodeByFollowIndx" resultType="com.cyksj.model.entity.CorpCustomerAcquisitionLink">
+        select *
+        from corp_customer_acquisition_link
+        where user_list != '[]'
+        <foreach collection="list" item="item" separator="OR">
+            JSON_CONTAINS(user_list, '[#{item}]')
+        </foreach>
+    </select>
+</mapper>

+ 15 - 0
netflix-dao/src/main/resources/mapper/CorpFollowActiveCodeMapper.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.cyksj.mapper.corp.CorpFollowActiveCodeMapper">
+
+    <select id="selectActiveCodeByFollowIndx" resultType="com.cyksj.model.entity.CorpFollowActiveCode">
+        select *
+        from corp_follow_active_code
+        where deleted is true
+        and follow_str != ''
+        <foreach collection="list" item="item" separator="OR">
+            JSON_CONTAINS(follow_str, '[#{item}]')
+        </foreach>
+    </select>
+</mapper>

+ 90 - 3
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigChangeRecordServiceImpl.java

@@ -9,22 +9,34 @@ 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.YhServiceNameDto;
 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;
 
 import java.time.DayOfWeek;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -43,6 +55,16 @@ 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 {
 		CmsUser cmsUser = cmsUserMapper.selectById(adminId);
@@ -57,6 +79,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,8 +130,23 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
 							SmsUtil.sendLuoKey2Msg(Constant.DUTY_SERVICE_CHANGE_NOTIFY_PHONE, String.format(Constant.DUTY_SERVICE_CHANGE_MSG, weekdayMsgNotifySb));
 						}
 					}
+				} 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());
+							}
+						}
+					});
 				}
 				this.save(sysConfigChangeRecord);
+				if (CollUtil.isNotEmpty(updateFollowIndxList)) {
+					updateCorpFollowLinkConfig(updateFollowIndxList);
+				}
 				return true;
 			}
 		}
@@ -152,4 +191,52 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
 		}
 		return null;
 	}
+
+	public void updateCorpFollowLinkConfig(List<Integer> updateFollowIndx) throws Exception {
+		List<CorpFollowActiveCode> corpFollowActiveCodes = corpFollowActiveCodeMapper.selectActiveCodeByFollowIndx(updateFollowIndx);
+		//去更新活码对应客服 成员id
+		corpFollowActiveCodes.forEach(data -> {
+			try {
+				List<Integer> upUserIndxList = Jsons.parseList(data.getFollowStr(), Integer.class);
+				List<String> up_followStrList = sysCorpServiceRelateService.getFollowIdsByRelateIds(Jsons.parseList(data.getFollowStr(), Integer.class));
+				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 {
+				if (!link.getIsDuty()) {
+					WxCpLinkUpd wxCpLinkUpd = new WxCpLinkUpd();
+					wxCpLinkUpd.setLinkName(link.getLinkName());
+					wxCpLinkUpd.setLinkId(link.getLinkId());
+					wxCpLinkUpd.setSkipVerify(link.getSkipVerify());
+					Range range = new Range();
+					//值班客服
+					String userList = link.getUserList();
+
+					List<String> followIds = sysCorpServiceRelateService.getFollowIdsByRelateIds(Jsons.parseList(userList, Integer.class));
+					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());
+		}
+	}
 }