zoujiajian 1 год назад
Родитель
Сommit
fb9a602a93

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

@@ -25,5 +25,7 @@ public class SysCorpFollowRelate extends BaseEntity{
 
 	private String img;
 
+	private String toFollowId;
+
 	private Boolean deleted;
 }

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

@@ -34,6 +34,11 @@ public class SysCorpFollowReq {
 	 */
 	private String followId;
 
+	/**
+	 * 转接客服
+	 */
+	private String toFollowId;
+
 	private Integer status;
 
 	private String img;

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

@@ -60,6 +60,11 @@ public class SysCorpFollowView {
 	@DbIgnore
 	private Boolean isOpen = false;
 
+	/**
+	 * 转接客服
+	 */
+	private String toFollowId;
+
 	public String getShowName() {
 		StringBuilder sb = new StringBuilder();
 		sb.append(name).append("(").append(followName).append(")");

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/corp/impl/WxCorpOpsImpl.java

@@ -962,7 +962,7 @@ public class WxCorpOpsImpl implements WxCorpOps {
 		JSONObject request = new JSONObject();
 		request.putOpt("open_kfid", openKfId);
 		request.putOpt("external_userid", externalUserId);
-		//待接入池排队中
+		//由人工接待
 		request.putOpt("service_state", 3);
 		request.putOpt("servicer_userid", userid);
 		HttpResponse<String> res =

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/kf/CorpKfService.java

@@ -29,4 +29,6 @@ public interface CorpKfService {
 	List<CorpKfDutyServicersStatusView> getDutyFollowByOpenKfId(long cmsUserId, String openKfId) throws Exception;
 
 	String getUrl(String openKfId, String scene) throws Exception;
+
+	void transCustomer(String followId, String toFollowId) throws Exception;
 }

+ 49 - 8
netflix-service/src/main/java/com/cyksj/service/corp/kf/impl/CorpKfServiceImpl.java

@@ -9,14 +9,8 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.mapper.corp.CorpFollowMapper;
-import com.cyksj.mapper.corp.kf.CorpKfAccountFollowDutyStatusMapper;
-import com.cyksj.mapper.corp.kf.CorpKfAccountFollowMapper;
-import com.cyksj.mapper.corp.kf.CorpKfAccountMapper;
-import com.cyksj.mapper.corp.kf.CorpKfAccountSessionConfigMapper;
-import com.cyksj.model.entity.CorpFollow;
-import com.cyksj.model.entity.CorpKfAccount;
-import com.cyksj.model.entity.CorpKfAccountFollow;
-import com.cyksj.model.entity.CorpKfAccountSessionConfig;
+import com.cyksj.mapper.corp.kf.*;
+import com.cyksj.model.entity.*;
 import com.cyksj.model.kf.*;
 import com.cyksj.model.request.corp.kf.CorpKfDutyReq;
 import com.cyksj.model.views.CorpKfDutyServicersStatusView;
@@ -58,6 +52,8 @@ public class CorpKfServiceImpl implements CorpKfService {
 
 	private final CorpFollowMapper corpFollowMapper;
 
+	private final CorpKfServicerSessionRecordMapper corpKfServicerSessionRecordMapper;
+
 	@Override
 	public void addKfAccount(CorpKfAccount corpKfAccount) throws Exception {
 		WxCpKfAccountAdd wxCpKfAccountAdd = new WxCpKfAccountAdd();
@@ -259,4 +255,49 @@ public class CorpKfServiceImpl implements CorpKfService {
 	public String getUrl(String openKfId, String scene) throws Exception {
 		return wxCorpOps.getUrl(openKfId, scene);
 	}
+
+	/**
+	 * 转接客服
+	 */
+	@Override
+	public void transCustomer(String followId, String toFollowId) throws Exception {
+		List<CorpKfAccountFollow> corpKfAccountFollows = corpKfAccountFollowMapper.selectList(Wrappers.lambdaQuery(CorpKfAccountFollow.class)
+				.apply(" and JSON_CONTAINS(user_id_list,'\"%s\"')", followId));
+		List<String> openKfIds = new ArrayList<>();
+		for (CorpKfAccountFollow corpKfAccountFollow : corpKfAccountFollows) {
+			String userIdList = corpKfAccountFollow.getUserIdList();
+			List<String> followIds = Jsons.parseList(userIdList, String.class);
+			followIds.remove(followIds);
+			followIds.add(toFollowId);
+			corpKfAccountFollowMapper.updateById(corpKfAccountFollow);
+			if (!openKfIds.contains(corpKfAccountFollow.getOpenKfId())) {
+				openKfIds.add(corpKfAccountFollow.getOpenKfId());
+			}
+		}
+		List<CorpKfServicerSessionRecord> corpKfServicerSessionRecords = corpKfServicerSessionRecordMapper.selectList(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
+				.eq(CorpKfServicerSessionRecord::getServiceState, 0));
+
+		String corpId = yhlxWxCorpConfig.getCorpId();
+		//添加对应客服
+		for (String openKfId : openKfIds) {
+			CorpKfServicerResp corpKfServicerResp = wxCorpOps.getKfServicerList(yhlxWxCorpConfig.getCorpId(), openKfId);
+			List<CorpKfServicerResp.CorpKfServicer> servicerList = corpKfServicerResp.getServicerList();
+			Set<String> dutyFollowIds = new HashSet<>();
+			for (CorpKfServicerResp.CorpKfServicer corpKfServicer : servicerList) {
+				String userid = corpKfServicer.getUserid();
+				if (userid != null) {
+					dutyFollowIds.add(userid);
+				}
+			}
+			if (!dutyFollowIds.isEmpty()) {
+				dutyFollowIds.remove(followId);
+				dutyFollowIds.add(toFollowId);
+				wxCorpOps.addCorpKfServicer(openKfId, dutyFollowIds);
+			}
+		}
+		for (CorpKfServicerSessionRecord corpKfServicerSessionRecord : corpKfServicerSessionRecords) {
+			//调用微信客服接口 变更会话状态
+			wxCorpOps.transCorpKfSessionToServicer(corpId, corpKfServicerSessionRecord.getOpenKfId(), toFollowId, corpKfServicerSessionRecord.getExternalUserid());
+		}
+	}
 }

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

@@ -4,12 +4,15 @@ import cn.hutool.core.collection.CollUtil;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.SysCorpFollowRelateMapper;
 import com.cyksj.mapper.corp.CorpUserFollowRelationMapper;
+import com.cyksj.model.entity.SysCorpFollowRelate;
 import com.cyksj.model.request.sys.SysCorpFollowReq;
 import com.cyksj.model.views.SysCorpFollowView;
 import com.cyksj.model.views.SysCorpMasterFollowView;
 import com.cyksj.service.corp.CorpService;
 import com.cyksj.service.corp.WxCorpOps;
+import com.cyksj.service.corp.kf.CorpKfService;
 import com.cyksj.service.sys.SysCorpFollowService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.util.MapUtils;
@@ -50,6 +53,10 @@ public class SysCorpFollowController {
 
 	private final YHLXWxCorpConfig corpConfig;
 
+	private final CorpKfService corpKfService;
+
+	private final SysCorpFollowRelateMapper sysCorpFollowRelateMapper;
+
 	/**
 	 * 新增客服
 	 */
@@ -115,4 +122,18 @@ public class SysCorpFollowController {
 		corpId = Optional.ofNullable(corpId).orElse(yhlxWxCorpConfig.getCorpId());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(corpService.dataInitByCorpId(corpId));
 	}
+
+	/**
+	 * 转接客户
+	 */
+	@PostMapping("/tans/customer")
+	public Result<String> transCustomer(@RequestBody SysCorpFollowReq req) throws Exception {
+		String toFollowId = req.getToFollowId();
+		Long sid = req.getSid();
+		SysCorpFollowRelate sysCorpFollowRelate = sysCorpFollowRelateMapper.selectById(sid);
+		corpKfService.transCustomer(sysCorpFollowRelate.getFollowId(), toFollowId);
+		sysCorpFollowRelate.setToFollowId(toFollowId);
+		sysCorpFollowRelateMapper.updateById(sysCorpFollowRelate);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }