|
@@ -1,7 +1,8 @@
|
|
|
package com.fs.company.controller.qw;
|
|
package com.fs.company.controller.qw;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.http.HttpUtil;
|
|
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.fs.common.annotation.Log;
|
|
import com.fs.common.annotation.Log;
|
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
@@ -14,6 +15,7 @@ import com.fs.common.enums.BusinessType;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.exception.user.UserPasswordNotMatchException;
|
|
import com.fs.common.exception.user.UserPasswordNotMatchException;
|
|
|
import com.fs.common.utils.MessageUtils;
|
|
import com.fs.common.utils.MessageUtils;
|
|
|
|
|
+import com.fs.common.utils.SecurityUtils;
|
|
|
import com.fs.common.utils.ServletUtils;
|
|
import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
import com.fs.company.domain.Company;
|
|
import com.fs.company.domain.Company;
|
|
@@ -27,8 +29,6 @@ import com.fs.framework.manager.AsyncManager;
|
|
|
import com.fs.framework.manager.factory.AsyncFactory;
|
|
import com.fs.framework.manager.factory.AsyncFactory;
|
|
|
import com.fs.framework.security.LoginUser;
|
|
import com.fs.framework.security.LoginUser;
|
|
|
import com.fs.framework.service.TokenService;
|
|
import com.fs.framework.service.TokenService;
|
|
|
-import com.fs.qw.domain.QwCompany;
|
|
|
|
|
-import com.fs.qw.domain.QwExternalContact;
|
|
|
|
|
import com.fs.qw.domain.QwUser;
|
|
import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
import com.fs.qw.mapper.QwCompanyMapper;
|
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
import com.fs.qw.mapper.QwExternalContactMapper;
|
|
@@ -40,17 +40,13 @@ import com.fs.qw.vo.QwOptionsVO;
|
|
|
import com.fs.qw.vo.QwUserVO;
|
|
import com.fs.qw.vo.QwUserVO;
|
|
|
import com.fs.qw.vo.UpdateSendTypeVo;
|
|
import com.fs.qw.vo.UpdateSendTypeVo;
|
|
|
import com.fs.qwApi.config.OpenQwConfig;
|
|
import com.fs.qwApi.config.OpenQwConfig;
|
|
|
-import com.fs.qwApi.domain.QwExternalContactAllListResult;
|
|
|
|
|
-import com.fs.qwApi.domain.inner.ExternalContact;
|
|
|
|
|
-import com.fs.qwApi.domain.inner.ExternalContactInfo;
|
|
|
|
|
-import com.fs.qwApi.domain.inner.FollowInfo;
|
|
|
|
|
-import com.fs.qwApi.param.QwExternalListParam;
|
|
|
|
|
-import com.fs.qwApi.service.QwApiService;
|
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.fs.voice.utils.StringUtil;
|
|
import com.fs.voice.utils.StringUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -59,6 +55,7 @@ import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -68,11 +65,11 @@ import java.util.stream.Collectors;
|
|
|
* @author fs
|
|
* @author fs
|
|
|
* @date 2024-06-20
|
|
* @date 2024-06-20
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/qw/user")
|
|
@RequestMapping("/qw/user")
|
|
|
public class QwUserController extends BaseController
|
|
public class QwUserController extends BaseController
|
|
|
{
|
|
{
|
|
|
- private static final org.slf4j.Logger logger = LoggerFactory.getLogger(QwUserController.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IQwUserService qwUserService;
|
|
private IQwUserService qwUserService;
|
|
@@ -101,15 +98,16 @@ public class QwUserController extends BaseController
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CompanyUserMapper companyUserMapper;
|
|
private CompanyUserMapper companyUserMapper;
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private QwApiService qwApiService;
|
|
|
|
|
-
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private AuthenticationManager authenticationManager;
|
|
private AuthenticationManager authenticationManager;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CompanyDeptServiceImpl companyDeptService;
|
|
private CompanyDeptServiceImpl companyDeptService;
|
|
|
|
|
|
|
|
|
|
+ /** HTTP调用超时时间(秒) */
|
|
|
|
|
+ @Value("${qw.api.timeout:120}")
|
|
|
|
|
+ private int apiTimeout;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询企微员工列表
|
|
* 查询企微员工列表
|
|
|
*/
|
|
*/
|
|
@@ -856,88 +854,36 @@ public class QwUserController extends BaseController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public R syncMyQwExternalContact(QwUser qwUser,String getNextCursor ) {
|
|
public R syncMyQwExternalContact(QwUser qwUser,String getNextCursor ) {
|
|
|
-
|
|
|
|
|
- String qwUserId = qwUser.getQwUserId();
|
|
|
|
|
- String corpId = qwUser.getCorpId();
|
|
|
|
|
- Long companyId = qwUser.getCompanyId();
|
|
|
|
|
-
|
|
|
|
|
- QwExternalListParam param = new QwExternalListParam();
|
|
|
|
|
- param.setLimit(100);
|
|
|
|
|
- param.setUserid_list(Arrays.asList(qwUserId));
|
|
|
|
|
- param.setCursor(getNextCursor);
|
|
|
|
|
- QwCompany qwCompany = qwCompanyMapper.selectQwCompanyByCorpId(corpId);
|
|
|
|
|
- QwExternalContactAllListResult list = qwApiService.getAllExternalcontactList(param, corpId,qwCompany);
|
|
|
|
|
-
|
|
|
|
|
- logger.info("批量获取客户详情" + list);
|
|
|
|
|
-
|
|
|
|
|
- if (list.getErrcode() == 0) {
|
|
|
|
|
- List<ExternalContactInfo> externalContactList = list.getExternal_contact_list();
|
|
|
|
|
- for (ExternalContactInfo externalContactInfo : externalContactList) {
|
|
|
|
|
-
|
|
|
|
|
- ExternalContact externalContact = externalContactInfo.getExternal_contact();
|
|
|
|
|
- FollowInfo followInfo = externalContactInfo.getFollow_info();
|
|
|
|
|
- QwExternalContact qwExternalContact = qwExternalContactMapper.selectQwExternalContactUserIdAndExternalIdAndCompanyId(externalContact.getExternal_userid(), qwUserId, corpId);
|
|
|
|
|
- logger.info("客户详情" + qwExternalContact);
|
|
|
|
|
-
|
|
|
|
|
- if (qwExternalContact == null) {
|
|
|
|
|
- qwExternalContact = new QwExternalContact();
|
|
|
|
|
- qwExternalContact.setUserId(qwUserId); // 设置属于用户ID
|
|
|
|
|
- qwExternalContact.setExternalUserId(externalContact.getExternal_userid()); // 设置外部联系人ID
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- qwExternalContact.setCorpId(corpId); // 设置企业ID
|
|
|
|
|
- qwExternalContact.setCompanyId(companyId); // 设置公司ID
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- // 设置公共属性
|
|
|
|
|
- qwExternalContact.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
|
|
- qwExternalContact.setQwUserId(qwUser.getId());
|
|
|
|
|
- qwExternalContact.setName(externalContact.getName()); // 设置名称
|
|
|
|
|
- qwExternalContact.setAvatar(externalContact.getAvatar()); // 设置头像
|
|
|
|
|
- qwExternalContact.setType(externalContact.getType()); // 设置外部联系人类型(1微信用户,2企业微信用户)
|
|
|
|
|
- qwExternalContact.setGender(externalContact.getGender()); // 设置性别 (0-未知, 1-男性, 2-女性)
|
|
|
|
|
- qwExternalContact.setDescription(followInfo.getDescription()); // 设置描述信息
|
|
|
|
|
- qwExternalContact.setRemark(followInfo.getRemark());
|
|
|
|
|
-
|
|
|
|
|
-// if (followInfo.getTag_id() != null && !followInfo.getTag_id().isEmpty()) {
|
|
|
|
|
- qwExternalContact.setTagIds(JSON.toJSONString(followInfo.getTag_id())); // 设置标签ID
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// if (followInfo.getRemark_mobiles() != null && !followInfo.getRemark_mobiles().isEmpty()) {
|
|
|
|
|
- qwExternalContact.setRemarkMobiles(JSON.toJSONString(followInfo.getRemark_mobiles())); // 设置备注电话号码
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- qwExternalContact.setState(followInfo.getState());
|
|
|
|
|
-
|
|
|
|
|
- if (followInfo.getState() != null && !followInfo.getState().isEmpty()) {
|
|
|
|
|
- String s = "way:" + corpId + ":";
|
|
|
|
|
- if (followInfo.getState().contains(s)) {
|
|
|
|
|
- String wayId = followInfo.getState().substring(followInfo.getState().indexOf(s) + s.length());
|
|
|
|
|
- qwExternalContact.setWayId(Long.parseLong(wayId));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- qwExternalContact.setRemarkCorpName(followInfo.getRemark_corp_name()); // 设置备注企业名称
|
|
|
|
|
- qwExternalContact.setAddWay(followInfo.getAdd_way()); // 设置来源
|
|
|
|
|
- qwExternalContact.setOperUserid(followInfo.getOper_userid()); // 设置oper用户ID
|
|
|
|
|
-
|
|
|
|
|
- // 根据是否存在记录进行更新或插入
|
|
|
|
|
- if (qwExternalContact.getId() != null) {
|
|
|
|
|
- qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
|
|
|
|
|
- } else {
|
|
|
|
|
- qwExternalContactMapper.insertQwExternalContact(qwExternalContact);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 从当前登录用户获取租户ID
|
|
|
|
|
+ Long tenantId = SecurityUtils.getTenantId();
|
|
|
|
|
+ String encodedQwUser;
|
|
|
|
|
+ try {
|
|
|
|
|
+ encodedQwUser = java.net.URLEncoder.encode(JSON.toJSONString(qwUser), "UTF-8");
|
|
|
|
|
+ } catch (java.io.UnsupportedEncodingException e) {
|
|
|
|
|
+ encodedQwUser = JSON.toJSONString(qwUser);
|
|
|
|
|
+ }
|
|
|
|
|
+ String url = OpenQwConfig.api + "/qw/externalContact/syncExternalContact?tenantId=" + tenantId
|
|
|
|
|
+ + "&qwUser=" + encodedQwUser;
|
|
|
|
|
+ if (getNextCursor != null && !getNextCursor.isEmpty()) {
|
|
|
|
|
+ url += "&cursor=" + getNextCursor;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ HttpResponse response = HttpRequest.post(url)
|
|
|
|
|
+ .timeout(apiTimeout * 1000)
|
|
|
|
|
+ .execute();
|
|
|
|
|
+ if (response.getStatus() == 200) {
|
|
|
|
|
+ return JSON.parseObject(response.body(), R.class);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("同步外部联系人失败,HTTP状态码: {}", response.getStatus());
|
|
|
|
|
+ return R.error("同步外部联系人失败,服务返回状态码: " + response.getStatus());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- }else {
|
|
|
|
|
- return R.error("同步失败:"+list.getErrmsg());
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("同步外部联系人异常, url={}", url, e);
|
|
|
|
|
+ if (e.getCause() instanceof SocketTimeoutException) {
|
|
|
|
|
+ return R.error("同步外部联系人超时,请稍后重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ return R.error("同步外部联系人失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if (!StringUtil.strIsNullOrEmpty(list.getNext_cursor())){
|
|
|
|
|
- syncMyQwExternalContact(qwUser,list.getNext_cursor());
|
|
|
|
|
- }
|
|
|
|
|
- return R.ok();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// /**
|
|
// /**
|