|
|
@@ -1,19 +1,30 @@
|
|
|
package com.fs.qw.controller;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.domain.model.LoginUser;
|
|
|
+import com.fs.common.utils.ServletUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.course.config.CourseConfig;
|
|
|
+import com.fs.framework.web.service.TokenService;
|
|
|
+import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.qw.domain.QwContactWay;
|
|
|
+import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.param.*;
|
|
|
import com.fs.qw.service.IQwContactWayService;
|
|
|
import com.fs.qw.service.IQwExternalContactInfoService;
|
|
|
import com.fs.qw.service.IQwGroupChatUserService;
|
|
|
import com.fs.qw.service.IQwTagService;
|
|
|
+import com.fs.qw.service.IQwUserService;
|
|
|
import com.fs.course.service.IFsUserCompanyBindService;
|
|
|
import com.fs.course.vo.UserWatchLogListVo;
|
|
|
import com.fs.qw.vo.QwExternalContactUnionIdExportVO;
|
|
|
@@ -41,6 +52,7 @@ import com.fs.qw.domain.QwExternalContact;
|
|
|
import com.fs.qw.service.IQwExternalContactService;
|
|
|
import com.fs.common.utils.poi.ExcelUtil;
|
|
|
import com.fs.common.core.page.TableDataInfo;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
|
|
|
/**
|
|
|
* 企业微信客户Controller
|
|
|
@@ -67,6 +79,18 @@ public class QwExternalContactController extends BaseController
|
|
|
@Autowired
|
|
|
private IFsUserCompanyBindService fsUserCompanyBindService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwUserService qwUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TokenService tokenService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
QwExternalContactController(IQwExternalContactService qwExternalContactService,IQwTagService iQwTagService){
|
|
|
this.qwExternalContactService=qwExternalContactService;
|
|
|
this.iQwTagService=iQwTagService;
|
|
|
@@ -80,10 +104,16 @@ public class QwExternalContactController extends BaseController
|
|
|
@GetMapping("/list")
|
|
|
public TableDataInfo list(QwExternalContactParam qwExternalContact)
|
|
|
{
|
|
|
- if (qwExternalContact.getFsUserId() == null
|
|
|
- && qwExternalContact.getExtId() == null
|
|
|
- && qwExternalContact.getId() == null
|
|
|
- && StringUtils.isEmpty(qwExternalContact.getExternalUserId())) {
|
|
|
+ boolean hasBasicQuery = qwExternalContact.getFsUserId() != null
|
|
|
+ || qwExternalContact.getExtId() != null
|
|
|
+ || qwExternalContact.getId() != null
|
|
|
+ || StringUtils.isNotEmpty(qwExternalContact.getExternalUserId());
|
|
|
+ boolean hasAddSalesQuery = qwExternalContact.getAddSalesCount() != null
|
|
|
+ && hasAddSalesCountScope(qwExternalContact);
|
|
|
+ if (!hasBasicQuery && !hasAddSalesQuery) {
|
|
|
+ return getDataTable(new ArrayList<>());
|
|
|
+ }
|
|
|
+ if (qwExternalContact.getAddSalesCount() != null && !hasAddSalesCountScope(qwExternalContact)) {
|
|
|
return getDataTable(new ArrayList<>());
|
|
|
}
|
|
|
|
|
|
@@ -132,6 +162,58 @@ public class QwExternalContactController extends BaseController
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加销售数筛选 - 公司下拉
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('qw:externalContact:list')")
|
|
|
+ @GetMapping("/companyOptions")
|
|
|
+ public R companyOptions() {
|
|
|
+ Long deptId = resolveDeptIdForCompanyScope();
|
|
|
+ List<OptionsVO> list = companyService.selectAllCompanyList(deptId);
|
|
|
+ return R.ok().put("data", list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加销售数筛选 - 销售下拉(企微昵称 qwUserName)
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('qw:externalContact:list')")
|
|
|
+ @GetMapping("/salesOptions")
|
|
|
+ public R salesOptions(@RequestParam(required = false) Long companyId) {
|
|
|
+ if (companyId == null) {
|
|
|
+ return R.ok().put("data", new ArrayList<>());
|
|
|
+ }
|
|
|
+ QwUser query = new QwUser();
|
|
|
+ query.setCompanyId(companyId);
|
|
|
+ List<Map<String, String>> options = qwUserService.selectQwUserList(query).stream()
|
|
|
+ .map(QwUser::getQwUserName)
|
|
|
+ .filter(StringUtils::isNotEmpty)
|
|
|
+ .distinct()
|
|
|
+ .sorted()
|
|
|
+ .map(name -> {
|
|
|
+ Map<String, String> option = new HashMap<>(2);
|
|
|
+ option.put("dictLabel", name);
|
|
|
+ option.put("dictValue", name);
|
|
|
+ return option;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return R.ok().put("data", options);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long resolveDeptIdForCompanyScope() {
|
|
|
+ LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig courseConfig = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
+ if (!loginUser.isAdmin() && courseConfig.getDept() != null && courseConfig.getDept()) {
|
|
|
+ return loginUser.getDeptId();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean hasAddSalesCountScope(QwExternalContactParam param) {
|
|
|
+ return param.getCompanyId() != null
|
|
|
+ || StringUtils.isNotEmpty(param.getQwUserName());
|
|
|
+ }
|
|
|
+
|
|
|
public String getContactWayNameStream(String configStr, List<QwContactWay> wayList) {
|
|
|
if (configStr == null || wayList == null || wayList.isEmpty()) {
|
|
|
return null;
|