Bladeren bron

Merge branch 'sys_corp_follow_func' into pre

zoujiajian 2 jaren geleden
bovenliggende
commit
9c61adc508
19 gewijzigde bestanden met toevoegingen van 560 en 56 verwijderingen
  1. 19 0
      netflix-common/src/main/java/com/cyksj/common/util/StringUtil.java
  2. 13 0
      netflix-dao/src/main/java/com/cyksj/mapper/SysCorpFollowMapper.java
  3. 13 0
      netflix-dao/src/main/java/com/cyksj/mapper/SysCorpFollowRelateMapper.java
  4. 2 0
      netflix-dao/src/main/java/com/cyksj/model/entity/CorpCustomerAcquisitionLinkExtraCustomer.java
  5. 18 0
      netflix-dao/src/main/java/com/cyksj/model/entity/SysCorpFollow.java
  6. 29 0
      netflix-dao/src/main/java/com/cyksj/model/entity/SysCorpFollowRelate.java
  7. 40 0
      netflix-dao/src/main/java/com/cyksj/model/request/sys/SysCorpFollowReq.java
  8. 61 0
      netflix-dao/src/main/java/com/cyksj/model/views/SysCorpFollowView.java
  9. 68 0
      netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java
  10. 18 0
      netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java
  11. 2 0
      netflix-service/src/main/java/com/cyksj/service/corp/msg/CorpEventActionService.java
  12. 17 0
      netflix-service/src/main/java/com/cyksj/service/sys/SysCorpFollowService.java
  13. 0 10
      netflix-service/src/main/java/com/cyksj/service/sys/SysCorpServiceRelateService.java
  14. 2 3
      netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigChangeRecordServiceImpl.java
  15. 21 1
      netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigServiceImpl.java
  16. 135 0
      netflix-service/src/main/java/com/cyksj/service/sys/impl/SysCorpFollowServiceImpl.java
  17. 6 41
      netflix-service/src/main/java/com/cyksj/service/sys/impl/SysCorpServiceRelateServiceImpl.java
  18. 10 1
      netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/CorpCustomerAcquistionLinkController.java
  19. 86 0
      netflix-web/src/main/java/com/cyksj/web/controller/sys/SysCorpFollowController.java

+ 19 - 0
netflix-common/src/main/java/com/cyksj/common/util/StringUtil.java

@@ -571,4 +571,23 @@ public final class StringUtil {
 		}
 		return StrUtil.EMPTY;
 	}
+
+	public static <T> List<List<T>> averageAssign(List<T> source, int n) {
+		List<List<T>> result = new ArrayList<List<T>>();
+		int remainder = source.size() % n;  //(先计算出余数)
+		int number = source.size() / n;  //然后是商
+		int offset = 0;//偏移量
+		for (int i = 0; i < n; i++) {
+			List<T> value = null;
+			if (remainder > 0) {
+				value = source.subList(i * number + offset, (i + 1) * number + offset + 1);
+				remainder--;
+				offset++;
+			} else {
+				value = source.subList(i * number + offset, (i + 1) * number + offset);
+			}
+			result.add(value);
+		}
+		return result;
+	}
 }

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/SysCorpFollowMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.SysCorpFollow;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:53
+ */
+public interface SysCorpFollowMapper extends BaseMapper<SysCorpFollow> {
+}

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/SysCorpFollowRelateMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.SysCorpFollowRelate;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowRelateMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:54
+ */
+public interface SysCorpFollowRelateMapper extends BaseMapper<SysCorpFollowRelate> {
+}

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpCustomerAcquisitionLinkExtraCustomer.java

@@ -20,6 +20,8 @@ public class CorpCustomerAcquisitionLinkExtraCustomer extends BaseEntity{
 	@NotNull
 	private Integer serviceId;
 
+	private String followId;
+
 	/**
 	 * 值班日期
 	 */

+ 18 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/SysCorpFollow.java

@@ -0,0 +1,18 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollow
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:51
+ */
+@Getter
+@Setter
+public class SysCorpFollow extends BaseEntity{
+	private String name;
+
+	private Boolean deleted;
+}

+ 29 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/SysCorpFollowRelate.java

@@ -0,0 +1,29 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowRelate
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:52
+ */
+@Getter
+@Setter
+public class SysCorpFollowRelate extends BaseEntity{
+	private Long mid;
+
+	private String name;
+
+	private String followId;
+
+	private Integer status;
+
+	private String img;
+
+	/**
+	 * 激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业
+	 */
+	private Boolean deleted;
+}

+ 40 - 0
netflix-dao/src/main/java/com/cyksj/model/request/sys/SysCorpFollowReq.java

@@ -0,0 +1,40 @@
+package com.cyksj.model.request.sys;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowReq
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:55
+ */
+@Getter
+@Setter
+public class SysCorpFollowReq {
+	private Long mid;
+
+	/**
+	 * 客服名
+	 */
+	private String name;
+
+	/**
+	 * 子账号id
+	 */
+	private Long sid;
+
+	/**
+	 * 企业客服名
+	 */
+	private String followName;
+
+	/**
+	 * 企业客服id
+	 */
+	private String followId;
+
+	private Integer status;
+
+	private String img;
+}

+ 61 - 0
netflix-dao/src/main/java/com/cyksj/model/views/SysCorpFollowView.java

@@ -0,0 +1,61 @@
+package com.cyksj.model.views;
+
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.DbIgnore;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowView
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 12:02
+ */
+@Getter
+@Setter
+@SearchBean(tables = "sys_corp_follow sf",
+		where = "sf.deleted is true",
+		orderBy = "sf.update_time desc")
+public class SysCorpFollowView {
+	@DbField("sf.id")
+	private Long mid;
+
+	@DbField("sf.name")
+	private String name;
+
+	@DbIgnore
+	List<SysCorpFollowRelateView> subList;
+
+
+	@Getter
+	@Setter
+	@SearchBean(tables = "sys_corp_follow_relate sfr",
+			where = "sfr.deleted is true"
+			, orderBy = "sfr.update_time desc")
+	public class SysCorpFollowRelateView {
+
+		@DbField("sfr.id")
+		private Long sid;
+
+		@DbField("sfr.mid")
+		private Long mid;
+
+		@DbField("sfr.name")
+		private String followName;
+
+		@DbField("sfr.follow_id")
+		private String followId;
+
+		@DbField("sfr.img")
+		private String img;
+
+		/**
+		 * 激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业
+		 */
+		@DbField("sfr.status")
+		private Integer status;
+	}
+}

+ 68 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -137,6 +137,8 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 
 	private final CorpCustomerAcquistionCallbackMapper corpCustomerAcquistionCallbackMapper;
 
+	private final CorpFollowMapper corpFollowMapper;
+
 	private static final String DEFAULT_MSG = "您好,欢迎加入银河录像局";
 
 	/**
@@ -593,6 +595,30 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		return null;
 	}
 
+	@Override
+	public CorpXmlOutMessage creatOrUpdateFollowUser(CorpXmlMessage message) throws Exception {
+		//corpId
+		String corpId = message.getToUserName();
+		//成员id
+		String userId = message.getUserId();
+
+		Long wxCorpId = WeChatCorpFactory.getCorpConfigStrategy(corpId).getId();
+		CorpFollow corpFollow = corpFollowMapper.selectOne(Wrappers.lambdaQuery(CorpFollow.class).eq(CorpFollow::getWxCorpId, wxCorpId).eq(CorpFollow::getUserid, userId));
+		CorpUserInfo userInfo = wxCorpOps.getFollowUser(corpId, userId);
+		if (corpFollow == null) {
+			corpFollow = new CorpFollow();
+			BeanUtil.copyProperties(userInfo, corpFollow);
+			corpFollow.setWxCorpId(wxCorpId);
+			corpFollowMapper.insert(corpFollow);
+			//同步客户列表
+			getCorpUserInfo(corpId, corpFollow.getUserid());
+		} else {
+			BeanUtil.copyProperties(userInfo, corpFollow);
+			corpFollowMapper.updateById(corpFollow);
+		}
+		return null;
+	}
+
 	/**
 	 * 修改客户成员关系,客户标签
 	 */
@@ -1227,4 +1253,46 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 		}
 		return corpWelcomeTemplate;
 	}
+
+	public void getCorpUserInfo(String corpId, String userId) {
+		THREAD_POOL.execute(() -> {
+			List<String> externalList = null;
+			try {
+				externalList = wxCorpOps.listExternalContacts(corpId, userId);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			if (externalList.size() > 1000) {
+				List<List<String>> lists = StringUtil.averageAssign(externalList, 5);
+				for (List<String> list : lists) {
+					THREAD_POOL.execute(() -> {
+						for (String externalUserid : list) {
+							try {
+								log.info("同步客户数据 corpId:{},externalUserid:{}", corpId, externalUserid);
+								//尝试添加客户
+								CorpXmlMessage message = new CorpXmlMessage();
+								message.setToUserName(corpId);
+								message.setExternalUserId(externalUserid);
+								addExternalContact(message, null);
+							} catch (Exception e) {
+								e.printStackTrace();
+							}
+						}
+					});
+				}
+			} else {
+				for (String externalUserid : externalList) {
+					try {
+						//尝试添加客户
+						CorpXmlMessage message = new CorpXmlMessage();
+						message.setToUserName(corpId);
+						message.setExternalUserId(externalUserid);
+						addExternalContact(message, null);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			}
+		});
+	}
 }

+ 18 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -190,6 +190,24 @@ public class CorpServiceImpl implements CorpService {
 					}
 				})
 				.end()
+				//新增成员
+				.rule().async(false).changeType("create_user")
+				.handler(new CorpMessageHandler() {
+					@Override
+					public CorpXmlOutMessage handle(CorpXmlMessage message, Map<String, Object> context, CorpService corpService) throws Exception {
+						return corpEventActionService.creatOrUpdateFollowUser(message);
+					}
+				})
+				.end()
+				//成员更新事件
+				.rule().async(false).changeType("update_user")
+				.handler(new CorpMessageHandler() {
+					@Override
+					public CorpXmlOutMessage handle(CorpXmlMessage message, Map<String, Object> context, CorpService corpService) throws Exception {
+						return corpEventActionService.creatOrUpdateFollowUser(message);
+					}
+				})
+				.end()
 		;
 
 	}

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/msg/CorpEventActionService.java

@@ -33,4 +33,6 @@ public interface CorpEventActionService {
     CorpXmlOutMessage msgAuditApproved(CorpXmlMessage message, Map<String, Object> context);
 
 	CorpXmlOutMessage customerStartChat(CorpXmlMessage message, Map<String, Object> context);
+
+	CorpXmlOutMessage creatOrUpdateFollowUser(CorpXmlMessage message) throws Exception;
 }

+ 17 - 0
netflix-service/src/main/java/com/cyksj/service/sys/SysCorpFollowService.java

@@ -0,0 +1,17 @@
+package com.cyksj.service.sys;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.cyksj.model.entity.SysCorpFollow;
+import com.cyksj.model.request.sys.SysCorpFollowReq;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowService
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:58
+ */
+public interface SysCorpFollowService extends IService<SysCorpFollow> {
+	void saveOrUpdateFollow(SysCorpFollowReq req) throws Exception;
+
+	void delBySid(Long sid) throws Exception;
+}

+ 0 - 10
netflix-service/src/main/java/com/cyksj/service/sys/SysCorpServiceRelateService.java

@@ -1,9 +1,6 @@
 package com.cyksj.service.sys;
 
-import com.cyksj.model.dto.CorpFollowServiceDto;
-
 import java.util.List;
-import java.util.Map;
 
 /**
  * 项目名: yhlxj2
@@ -14,11 +11,4 @@ import java.util.Map;
 public interface SysCorpServiceRelateService {
 
 	List<String> getFollowIdsByRelateIds(List<Integer> indxIds) throws Exception;
-
-	List<String> getFollowIdsByRelateIds(List<Integer> indxIds, Map<Integer, List<CorpFollowServiceDto>> corpYhFollowService) throws Exception;
-
-	/**
-	 * 获取客服对照关系
-	 */
-	Map<Integer, List<CorpFollowServiceDto>> getCorpYhFollowService() throws Exception;
 }

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

@@ -198,12 +198,11 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
 	@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);
+				List<String> up_followStrList = sysCorpServiceRelateService.getFollowIdsByRelateIds(upUserIndxList);
 				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(), "*"));
@@ -233,7 +232,7 @@ public class SysConfigChangeRecordServiceImpl extends ServiceImpl<SysConfigChang
 				} else {
 					userList = link.getUserList();
 				}
-				List<String> followIds = sysCorpServiceRelateService.getFollowIdsByRelateIds(Jsons.parseList(userList, Integer.class), corpYhFollowService);
+				List<String> followIds = sysCorpServiceRelateService.getFollowIdsByRelateIds(Jsons.parseList(userList, Integer.class));
 				range.setUserList(followIds);
 				wxCpLinkUpd.setRange(range);
 				WxCpLinkAddResp wxCpLinkAddResp = corpOps.customerAcquisitionUpdateLink(null, wxCpLinkUpd);

+ 21 - 1
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigServiceImpl.java

@@ -8,12 +8,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.service.CropDutyServiceDateService;
 import com.cyksj.common.util.Jsons;
+import com.cyksj.mapper.corp.CorpFollowMapper;
 import com.cyksj.mapper.sys.SysConfigMapper;
 import com.cyksj.model.dto.DefaultShopConfig;
 import com.cyksj.model.dto.YhServiceDto;
+import com.cyksj.model.entity.CorpFollow;
 import com.cyksj.model.entity.ShopConfig;
 import com.cyksj.model.entity.SysConfig;
 import com.cyksj.service.sys.SysConfigService;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -29,7 +32,9 @@ import java.util.stream.Collectors;
  */
 @Slf4j
 @Service
+@RequiredArgsConstructor
 public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper,SysConfig> implements SysConfigService {
+	private final CorpFollowMapper corpFollowMapper;
 
 	@Override
 	public String getDefaultShopConfigByType(String type) {
@@ -65,11 +70,26 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper,SysConfig>
 		SysConfig sysConfig = this.getOne(Wrappers.lambdaQuery(SysConfig.class)
 				.eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
 				.last("limit 1"));
-
+		//过滤被禁用的规格
+		Map<String, List<CorpFollow>> followMap = corpFollowMapper.selectList(Wrappers.lambdaQuery(CorpFollow.class)
+				.ne(CorpFollow::getStatus, 1)).stream().collect(Collectors.groupingBy(CorpFollow::getUserid));
 		List<YhServiceDto> yhServiceDtos = null;
 
 		if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
 			yhServiceDtos = Jsons.parseList(sysConfig.getSysValue(), YhServiceDto.class);
+			yhServiceDtos.stream().forEach(s -> {
+				List<YhServiceDto.CustomerServiceDto> finalSelect = s.getSelect().stream().filter(select -> {
+					List<CorpFollow> corpFollows = followMap.get(select);
+					if (CollUtil.isNotEmpty(corpFollows)) {
+						CorpFollow corpFollow = corpFollows.get(0);
+						if (corpFollow.getStatus() != 1) {
+							return false;
+						}
+					}
+					return true;
+				}).collect(Collectors.toList());
+				s.setSelect(finalSelect);
+			});
 		}
 
 		final List<YhServiceDto> dtoCs = yhServiceDtos;

+ 135 - 0
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysCorpFollowServiceImpl.java

@@ -0,0 +1,135 @@
+package com.cyksj.service.sys.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.common.constant.Constant;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.Jsons;
+import com.cyksj.mapper.SysCorpFollowMapper;
+import com.cyksj.mapper.SysCorpFollowRelateMapper;
+import com.cyksj.mapper.sys.SysConfigMapper;
+import com.cyksj.model.dto.YhServiceDto;
+import com.cyksj.model.entity.SysConfig;
+import com.cyksj.model.entity.SysCorpFollow;
+import com.cyksj.model.entity.SysCorpFollowRelate;
+import com.cyksj.model.request.sys.SysCorpFollowReq;
+import com.cyksj.service.sys.SysConfigChangeRecordService;
+import com.cyksj.service.sys.SysCorpFollowService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:58
+ */
+@Service
+@RequiredArgsConstructor
+public class SysCorpFollowServiceImpl extends ServiceImpl<SysCorpFollowMapper, SysCorpFollow> implements SysCorpFollowService {
+	private final SysCorpFollowRelateMapper sysCorpFollowRelateMapper;
+
+	private final SysConfigMapper sysConfigMapper;
+
+	private final SysConfigChangeRecordService sysConfigChangeRecordService;
+
+	@Override
+	@Transactional(rollbackFor = Throwable.class)
+	public void saveOrUpdateFollow(SysCorpFollowReq req) throws Exception {
+		SysCorpFollow sysCorpFollow = new SysCorpFollow();
+		sysCorpFollow.setId(req.getMid());
+		sysCorpFollow.setName(req.getName());
+		this.saveOrUpdate(sysCorpFollow);
+
+		SysCorpFollowRelate sysCorpFollowRelate = new SysCorpFollowRelate();
+		sysCorpFollowRelate.setId(req.getSid());
+		sysCorpFollowRelate.setMid(sysCorpFollow.getId());
+		sysCorpFollowRelate.setFollowId(req.getFollowId());
+		sysCorpFollowRelate.setName(req.getFollowName());
+		sysCorpFollowRelate.setImg(req.getImg());
+		sysCorpFollowRelate.setStatus(req.getStatus());
+		if (sysCorpFollowRelate.getId() == null) {
+			sysCorpFollowRelateMapper.insert(sysCorpFollowRelate);
+		} else {
+			SysCorpFollowRelate db = sysCorpFollowRelateMapper.selectById(sysCorpFollowRelate.getId());
+			//更新获客。活码 企业客服
+			updateCorpFollowRelateConfig(sysCorpFollowRelate, db);
+			//更新客服图片
+			updateCorpFollowImg(sysCorpFollowRelate, req.getName());
+			sysCorpFollowRelateMapper.updateById(sysCorpFollowRelate);
+		}
+	}
+
+	@Override
+	public void delBySid(Long sid) throws Exception {
+		SysCorpFollowRelate sysCorpFollowRelate = sysCorpFollowRelateMapper.selectById(sid);
+		if (sysCorpFollowRelate == null || !sysCorpFollowRelate.getDeleted()) {
+			return;
+		}
+		//是否已被选择
+		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
+				.eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
+				.last("limit 1"));
+		List<YhServiceDto> yhServiceDtos = Jsons.parseList(sysConfig.getSysValue(), YhServiceDto.class);
+
+		yhServiceDtos.stream().forEach(s -> {
+			List<YhServiceDto.CustomerServiceDto> select = s.getSelect();
+			select.forEach(e -> {
+				String followId = e.getFollowId();
+				if (StrUtil.equals(followId, sysCorpFollowRelate.getFollowId())) {
+					throw BusinessRuntimeException.getInstance("请先移除对应值班客服");
+				}
+			});
+		});
+		sysCorpFollowRelate.setDeleted(false);
+		sysCorpFollowRelateMapper.updateById(sysCorpFollowRelate);
+	}
+
+	public void updateCorpFollowRelateConfig(SysCorpFollowRelate sysCorpFollowRelate, SysCorpFollowRelate db) {
+		Long sid = sysCorpFollowRelate.getId();
+		if (!StrUtil.equals(db.getFollowId(), sysCorpFollowRelate.getFollowId())) {
+			//更新活码,获客
+			try {
+				sysConfigChangeRecordService.updateCorpFollowLinkConfig(List.of(Integer.parseInt(sid.toString())));
+			} catch (Exception e) {
+			}
+
+		}
+	}
+
+	/**
+	 * 更新企业值班客服信息
+	 */
+	private void updateCorpFollowImg(SysCorpFollowRelate sysCorpFollowRelate, String mName) throws Exception {
+		int sid = sysCorpFollowRelate.getId().intValue();
+		//更新活码,获客
+		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
+				.eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
+				.last("limit 1"));
+
+		List<YhServiceDto> yhServiceDtos = Jsons.parseList(sysConfig.getSysValue(), YhServiceDto.class);
+		AtomicBoolean isFlag = new AtomicBoolean(false);
+		yhServiceDtos.forEach(ys -> {
+			ys.getSelect().forEach(select -> {
+				if (select.getIndex().intValue() == sid) {
+					select.setFollowId(sysCorpFollowRelate.getFollowId());
+					select.setImg(sysCorpFollowRelate.getImg());
+					StringBuilder showName = new StringBuilder();
+					showName.append(mName).append("(").append(sysCorpFollowRelate.getName()).append(")");
+					select.setName(showName.toString());
+					if (!isFlag.get()) {
+						isFlag.set(true);
+					}
+				}
+			});
+		});
+		if (isFlag.get()) {
+			sysConfigMapper.updateById(sysConfig);
+		}
+	}
+}

+ 6 - 41
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysCorpServiceRelateServiceImpl.java

@@ -1,21 +1,14 @@
 package com.cyksj.service.sys.impl;
 
-import cn.hutool.core.collection.CollUtil;
-import cn.hutool.core.util.StrUtil;
 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.mapper.SysCorpFollowRelateMapper;
 import com.cyksj.mapper.sys.SysConfigMapper;
-import com.cyksj.model.dto.CorpFollowServiceDto;
-import com.cyksj.model.entity.SysConfig;
+import com.cyksj.model.entity.SysCorpFollowRelate;
 import com.cyksj.service.sys.SysCorpServiceRelateService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -29,41 +22,13 @@ import java.util.stream.Collectors;
 public class SysCorpServiceRelateServiceImpl implements SysCorpServiceRelateService {
 	private final SysConfigMapper sysConfigMapper;
 
+	private final SysCorpFollowRelateMapper sysCorpFollowRelateMapper;
+
 
 	@Override
 	public List<String> getFollowIdsByRelateIds(List<Integer> indxIds) throws Exception {
 		//值班客服
-		Map<Integer, List<CorpFollowServiceDto>> corpYhFollowService = this.getCorpYhFollowService();
-		return getFollowIdsByIndxs(indxIds, corpYhFollowService);
-	}
-
-	@Override
-	public List<String> getFollowIdsByRelateIds(List<Integer> indxIds, Map<Integer, List<CorpFollowServiceDto>> corpYhFollowService) throws Exception {
-		return getFollowIdsByIndxs(indxIds, corpYhFollowService);
-	}
-
-
-	@Override
-	public Map<Integer, List<CorpFollowServiceDto>> getCorpYhFollowService() throws Exception {
-		SysConfig config = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
-				.eq(SysConfig::getSysKey, Constant.serviceKeys.get(1)).last("limit 1"));
-		if (config == null || StrUtil.isEmpty(config.getSysValue())) {
-			throw BusinessRuntimeException.getInstance("未配置对应系统值班客服");
-		}
-		String sysValue = config.getSysValue();
-		List<CorpFollowServiceDto> corpFollowServiceDtos = Jsons.parseList(sysValue, CorpFollowServiceDto.class);
-		return corpFollowServiceDtos.stream().collect(Collectors.groupingBy(CorpFollowServiceDto::getIndx));
-	}
-
-	private List<String> getFollowIdsByIndxs(List<Integer> indxIds, Map<Integer, List<CorpFollowServiceDto>> corpYhFollowService) {
-		List<String> followIds = new ArrayList<>();
-		indxIds.forEach(indx -> {
-			List<CorpFollowServiceDto> corpFollowServiceDtos = corpYhFollowService.get(indx);
-			if (CollUtil.isEmpty(corpFollowServiceDtos)) {
-				throw BusinessRuntimeException.getInstance("存在被删除的值班客服");
-			}
-			followIds.add(corpFollowServiceDtos.get(0).getFollowId());
-		});
-		return followIds;
+		return sysCorpFollowRelateMapper.selectList(Wrappers.lambdaQuery(SysCorpFollowRelate.class)
+				.in(SysCorpFollowRelate::getId, indxIds)).stream().map(SysCorpFollowRelate::getFollowId).collect(Collectors.toList());
 	}
 }

+ 10 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/CorpCustomerAcquistionLinkController.java

@@ -6,6 +6,7 @@ import com.cyksj.common.constant.Constant;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.SysCorpFollowRelateMapper;
 import com.cyksj.mapper.corp.CorpCustomerAcquisitionLinkExtraCustomerMapper;
 import com.cyksj.mapper.corp.CorpFollowMapper;
 import com.cyksj.mapper.corp.CorpTagMapper;
@@ -54,6 +55,8 @@ public class CorpCustomerAcquistionLinkController {
 
     private final CorpCustomerAcquisitionLinkExtraCustomerMapper corpCustomerAcquisitionLinkExtraCustomerMapper;
 
+    private final SysCorpFollowRelateMapper sysCorpFollowRelateMapper;
+
     /**
      * 新增获客助手链接
      */
@@ -135,7 +138,10 @@ public class CorpCustomerAcquistionLinkController {
      */
     @PostMapping("/add/extra/service")
     public Result<String> addExtraService(@RequestBody @Validated CorpCustomerAcquisitionLinkExtraCustomer extraCustomer) throws Exception {
-	    corpCustomerAcquisitionLinkExtraCustomerMapper.insert(extraCustomer);
+        Integer serviceId = extraCustomer.getServiceId();
+        SysCorpFollowRelate sysCorpFollowRelate = sysCorpFollowRelateMapper.selectById(serviceId);
+        extraCustomer.setFollowId(sysCorpFollowRelate.getFollowId());
+        corpCustomerAcquisitionLinkExtraCustomerMapper.insert(extraCustomer);
         corpCustomerAcquisitionLinkService.handleCorpLinkSchedulerJob();
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
@@ -145,6 +151,9 @@ public class CorpCustomerAcquistionLinkController {
      */
     @PutMapping("/update/extra/service")
     public Result<String> updateExtraService(@RequestBody @Validated CorpCustomerAcquisitionLinkExtraCustomer extraCustomer) throws Exception {
+        Integer serviceId = extraCustomer.getServiceId();
+        SysCorpFollowRelate sysCorpFollowRelate = sysCorpFollowRelateMapper.selectById(serviceId);
+        extraCustomer.setFollowId(sysCorpFollowRelate.getFollowId());
 	    corpCustomerAcquisitionLinkExtraCustomerMapper.updateById(extraCustomer);
         corpCustomerAcquisitionLinkService.handleCorpLinkSchedulerJob();
         return GatewayResponse.SUCCESS.newBuilder().toResult();

+ 86 - 0
netflix-web/src/main/java/com/cyksj/web/controller/sys/SysCorpFollowController.java

@@ -0,0 +1,86 @@
+package com.cyksj.web.controller.sys;
+
+import com.cyksj.config.corp.YHLXWxCorpConfig;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.model.request.sys.SysCorpFollowReq;
+import com.cyksj.model.views.SysCorpFollowView;
+import com.cyksj.service.corp.CorpService;
+import com.cyksj.service.sys.SysCorpFollowService;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: SysCorpFollowController
+ * 创建者: JavaZou
+ * 创建时间:2024/6/12 11:54
+ * 系统客服配置
+ */
+@Slf4j
+@RequestMapping("/sys/corp/follow")
+@RestController
+@RequiredArgsConstructor
+public class SysCorpFollowController {
+	private final SysCorpFollowService sysCorpFollowService;
+
+	private final BeanSearcher beanSearcher;
+
+	private final YHLXWxCorpConfig yhlxWxCorpConfig;
+
+	private final CorpService corpService;
+
+	/**
+	 * 新增客服
+	 */
+	@PostMapping("/post")
+	public Result<String> post(@RequestBody SysCorpFollowReq req) throws Exception {
+		sysCorpFollowService.saveOrUpdateFollow(req);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 删除客服
+	 */
+	@DeleteMapping("/del/{sid}")
+	public Result<String> delBySId(@PathVariable Long sid) throws Exception {
+		sysCorpFollowService.delBySid(sid);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 修改客服
+	 */
+	@PutMapping("/put")
+	public Result<String> update(@RequestBody SysCorpFollowReq req) throws Exception {
+		sysCorpFollowService.saveOrUpdateFollow(req);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 客服列表
+	 */
+	@GetMapping("/get")
+	public Result<List<SysCorpFollowView>> get() {
+		List<SysCorpFollowView> sysCorpFollowViews = beanSearcher.searchAll(SysCorpFollowView.class, MapUtils.builder().build());
+		sysCorpFollowViews.forEach(e->{
+			e.setSubList(beanSearcher.searchAll(SysCorpFollowView.SysCorpFollowRelateView.class, MapUtils.builder().field(SysCorpFollowView.SysCorpFollowRelateView::getMid, e.getMid()).build()));
+		});
+		return GatewayResponse.SUCCESS.newBuilder().toResult(sysCorpFollowViews);
+	}
+
+	/**
+	 * 同步企业客服
+	 */
+	@GetMapping("/dataInit")
+	public Result<String> dataInitByCorpId(String corpId) throws Exception {
+		corpId = Optional.ofNullable(corpId).orElse(yhlxWxCorpConfig.getCorpId());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(corpService.dataInitByCorpId(corpId));
+	}
+}