| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- package com.linkwechat.controller;
- import cn.hutool.core.collection.ListUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.linkwechat.common.annotation.Log;
- import com.linkwechat.common.annotation.PhoneEncryptMethod;
- import com.linkwechat.common.constant.Constants;
- import com.linkwechat.common.constant.SynchRecordConstants;
- import com.linkwechat.common.constant.WeConstans;
- import com.linkwechat.common.core.controller.BaseController;
- import com.linkwechat.common.core.domain.AjaxResult;
- import com.linkwechat.common.core.page.TableDataInfo;
- import com.linkwechat.common.core.page.TableSupport;
- import com.linkwechat.common.enums.BusinessType;
- import com.linkwechat.common.exception.CustomException;
- import com.linkwechat.common.utils.ServletUtils;
- import com.linkwechat.common.utils.poi.LwExcelUtil;
- import com.linkwechat.domain.WeCustomer;
- import com.linkwechat.domain.WeCustomerSeas;
- import com.linkwechat.domain.customer.WeBacthMakeCustomerTag;
- import com.linkwechat.domain.customer.WeMakeCustomerTag;
- import com.linkwechat.domain.customer.query.WeCustomersQuery;
- import com.linkwechat.domain.customer.query.WeOnTheJobCustomerQuery;
- import com.linkwechat.domain.customer.vo.WeCustomerDetailInfoVo;
- import com.linkwechat.domain.customer.vo.WeCustomersVo;
- import com.linkwechat.service.IWeCustomerService;
- import com.linkwechat.service.IWeSynchRecordService;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Optional;
- import java.util.Set;
- import java.util.stream.Collectors;
- /**
- * 企业微信客户Controller
- *
- * @author ruoyi
- * @date 2020-09-13
- */
- @Slf4j
- @RestController
- @RequestMapping("/customer")
- public class WeCustomerController extends BaseController {
- @Autowired
- private IWeCustomerService weCustomerService;
- @Autowired
- private IWeSynchRecordService iWeSynchRecordService;
- /**
- * 查询企业微信客户列表(分页),索引优化客户列表,未使用默认分页
- */
- @GetMapping("/findWeCustomerList")
- public TableDataInfo findWeCustomerList(WeCustomersQuery weCustomersQuery)
- {
- weCustomersQuery.setDelFlag(null == weCustomersQuery.getDelFlag() ? Constants.COMMON_STATE : weCustomersQuery.getDelFlag());
- List<WeCustomersVo> list = weCustomerService.findWeCustomerList(weCustomersQuery, TableSupport.buildPageRequest());
- TableDataInfo dataTable = getDataTable(list);
- //设置总条数
- dataTable.setTotal(
- weCustomerService.countWeCustomerList(weCustomersQuery)
- );
- dataTable.setLastSyncTime(
- iWeSynchRecordService.findUpdateLatestTime(SynchRecordConstants.SYNCH_CUSTOMER)
- );//最近同步时间
- dataTable.setNoRepeatCustomerTotal(
- weCustomerService.noRepeatCountCustomer(weCustomersQuery)
- );//去重客户数
- return dataTable;
- }
- /**
- * 导出企业客户
- */
- @GetMapping("/exprotWeCustomerList")
- public void exprotWeCustomerList(WeCustomersQuery weCustomersQuery)
- {
- weCustomersQuery.setDelFlag(null == weCustomersQuery.getDelFlag() ? Constants.COMMON_STATE : weCustomersQuery.getDelFlag());
- List<WeCustomersVo> list = weCustomerService.findWeCustomerList(weCustomersQuery, null);
- LwExcelUtil.exprotForWeb(
- ServletUtils.getResponse(), WeCustomersVo .class, list,"企业客户"
- );
- }
- /**
- * 移动应用客户列表(分页)
- * @param weCustomersQuery
- * @return
- */
- @GetMapping("/findWeCustomerListByApp")
- public TableDataInfo<List<WeCustomersVo>> findWeCustomerListByApp(WeCustomersQuery weCustomersQuery){
- return weCustomerService.findWeCustomerListByApp(
- weCustomersQuery,TableSupport.buildPageRequest()
- );
- }
- /**
- * 查询企业微信客户列表(不分页)
- */
- @GetMapping("/findAllWeCustomerList")
- public AjaxResult findAllWeCustomerList(WeCustomersQuery weCustomersQuery)
- {
- weCustomersQuery.setDelFlag(null == weCustomersQuery.getDelFlag() ? Constants.COMMON_STATE : weCustomersQuery.getDelFlag());
- return AjaxResult.success(
- weCustomerService.findWeCustomerList(weCustomersQuery,null)
- );
- }
- /**
- * 客户同步接口
- * @return
- */
- @Log(title = "企业微信客户同步接口", businessType = BusinessType.DELETE)
- @GetMapping("/synchWeCustomer")
- public AjaxResult synchWeCustomer() {
- try {
- weCustomerService.synchWeCustomer();
- }catch (CustomException e){
- log.error("客户同步失败:ex:{}",e.getMessage(),e);
- return AjaxResult.error(e.getMessage());
- }
- return AjaxResult.success(WeConstans.SYNCH_TIP);
- }
- /**
- * 客户打标签
- * @param weMakeCustomerTag
- * @return
- */
- @Log(title = "客户打标签", businessType = BusinessType.UPDATE)
- @PostMapping("/makeLabel")
- public AjaxResult makeLabel(@RequestBody WeMakeCustomerTag weMakeCustomerTag){
- weCustomerService.makeLabel(weMakeCustomerTag);
- return AjaxResult.success();
- }
- /**
- * 在职继承
- * @param weOnTheJobCustomerQuery
- * @return
- */
- @Log(title="在职继承",businessType = BusinessType.UPDATE)
- @PostMapping("/jobExtends")
- public AjaxResult jobExtends(@RequestBody WeOnTheJobCustomerQuery weOnTheJobCustomerQuery){
- try {
- weCustomerService.allocateOnTheJobCustomer(
- weOnTheJobCustomerQuery
- );
- }catch (Exception e){
- e.printStackTrace();
- return AjaxResult.error(e.getMessage());
- }
- return AjaxResult.success();
- }
- /**********************************************************************************
- **************************************客户详情*************************************
- *********************************************************************************/
- /**
- * 客户详情基础(基础信息+社交关系)
- * @param externalUserid
- * @param userId
- * @param
- * @return
- */
- @GetMapping("/findWeCustomerBaseInfo")
- public AjaxResult<WeCustomerDetailInfoVo> findWeCustomerBaseInfo(String externalUserid, String userId, @RequestParam(defaultValue = "0") Integer delFlag){
- return AjaxResult.success(
- weCustomerService.findWeCustomerDetail(externalUserid,userId,null)
- );
- }
- /**
- * 客户画像汇总
- * @param externalUserid
- * @return
- */
- @GetMapping("/findWeCustomerInfoSummary")
- public AjaxResult<WeCustomerDetailInfoVo> findWeCustomerInfoSummary(String externalUserid,@RequestParam(defaultValue = "0") Integer delFlag){
- return AjaxResult.success(
- weCustomerService.findWeCustomerInfoSummary(externalUserid,null,null)
- );
- }
- /**
- * 单个跟进人客户
- * @param externalUserid
- * @param weUserId
- * @return
- */
- @GetMapping("/findWeCustomerInfoByUserId")
- public AjaxResult findWeCustomerInfoByUserId(String externalUserid,String weUserId,@RequestParam(defaultValue = "0") Integer delFlag){
- return AjaxResult.success(
- weCustomerService.findWeCustomerInfoByUserId(externalUserid,weUserId,null)
- );
- }
- // /**
- // * 跟进记录
- // * @param externalUserid
- // * @param userId
- // * @return
- // */
- // @GetMapping("/followUpRecord")
- // public TableDataInfo followUpRecord(String externalUserid,String userId){
- //
- // startPage();
- //
- // return getDataTable( iWeCustomerTrackRecordService.list(new LambdaQueryWrapper<WeCustomerTrackRecord>()
- // .eq(WeCustomerTrackRecord::getExternalUserid,externalUserid)
- // .eq(WeCustomerTrackRecord::getWeUserId,userId)));
- // }
- // /**
- // * 客户轨迹
- // * @param externalUserid
- // * @param weUserId
- // * @param trajectoryType 轨迹类型:1:信息动态;2:社交动态;3:活动规则;4:待办动态
- // * @return
- // */
- // @GetMapping("/findTrajectory")
- // public AjaxResult<WeCustomerTrajectory> findTrajectory(String externalUserid,String weUserId,Integer trajectoryType){
- //
- // List<WeCustomerTrajectory> weCustomerTrajectories = iWeCustomerTrajectoryService
- // .list(new LambdaQueryWrapper<WeCustomerTrajectory>()
- // .eq(StringUtils.isNotEmpty(externalUserid),WeCustomerTrajectory::getExternalUseridOrChatid, externalUserid)
- // .eq(StringUtils.isNotEmpty(weUserId),WeCustomerTrajectory::getWeUserId, weUserId)
- // .eq(trajectoryType !=null,WeCustomerTrajectory::getTrajectoryType,trajectoryType)
- // );
- //
- // return AjaxResult.success(weCustomerTrajectories);
- // }
- @ApiOperation(value = "通过条件校验客户数据", httpMethod = "POST")
- @PostMapping("/checkByCondition")
- public AjaxResult checkByCondition(@RequestBody WeCustomersQuery query){
- log.info("checkByCondition 接口入参:query:{}", JSONObject.toJSONString(query));
- List<WeCustomer> customerList = weCustomerService.getCustomerListByCondition(query);
- Set<String> externalUserIdSet = Optional.ofNullable(customerList).orElseGet(ArrayList::new)
- .stream().map(WeCustomer::getExternalUserid).collect(Collectors.toSet());
- Set<String> userNum = Optional.ofNullable(customerList).orElseGet(ArrayList::new)
- .stream().map(WeCustomer::getAddUserId).collect(Collectors.toSet());
- JSONObject result = new JSONObject();
- result.put("customerNum",externalUserIdSet.size());
- result.put("userNum",userNum.size());
- return AjaxResult.success(result);
- }
- /**
- * 批量添加或删除客户标签
- * @param makeCustomerTags
- * @return
- */
- @Log(title = "批量添加或删除客户标签", businessType = BusinessType.UPDATE)
- @PostMapping("/batchMakeLabel")
- public AjaxResult batchMakeLabel(@RequestBody WeBacthMakeCustomerTag makeCustomerTags){
- weCustomerService.batchMakeLabel(makeCustomerTags);
- return AjaxResult.success();
- }
- }
|