| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- package com.linkwechat.controller;
- import cn.hutool.core.collection.CollectionUtil;
- import cn.hutool.core.collection.ListUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.linkwechat.common.constant.Constants;
- 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.utils.SnowFlakeUtil;
- import com.linkwechat.common.utils.StringUtils;
- import com.linkwechat.domain.*;
- import com.linkwechat.domain.customer.WeMakeCustomerTag;
- import com.linkwechat.domain.customer.vo.WeCustomerAddGroupVo;
- import com.linkwechat.domain.customer.vo.WeCustomerPortraitVo;
- import com.linkwechat.service.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.Iterator;
- import java.util.List;
- /**
- * @description: 客户画像相关controller
- * @author: HaoN
- * @create: 2021-03-03 15:10
- **/
- @RestController
- @RequestMapping("/portrait")
- public class WeCustomerPortraitController extends BaseController{
- @Autowired
- private IWeCustomerService weCustomerService;
- @Autowired
- private IWeTagService iWeTagService;
- @Autowired
- private IWeTagGroupService iWeTagGroupService;
- @Autowired
- private IWeGroupService iWeGroupService;
- @Autowired
- private IWeCustomerTrajectoryService iWeCustomerTrajectoryService;
- @Autowired
- private IWeMomentsService iWeMomentsService;
- @Autowired
- private IWeSysFieldTemplateService iWeSysFieldTemplateService;
- /**
- * 根据客户id和当前企业员工id获取客户详细信息
- * @param externalUserid
- * @param userId
- * @return
- */
- @GetMapping(value = "/findWeCustomerInfo")
- public AjaxResult<WeCustomerPortraitVo> findWeCustomerInfo(String externalUserid, String userId) throws Exception {
- return AjaxResult.success(
- weCustomerService.findCustomerByOperUseridAndCustomerId(externalUserid,userId)
- );
- }
- /**
- * 客户画像资料更新
- * @param weCustomerPortrait
- * @return
- */
- @PostMapping(value = "/updateWeCustomerInfo")
- public AjaxResult updateWeCustomerInfo(@RequestBody WeCustomerPortraitVo weCustomerPortrait){
- weCustomerService.updateWeCustomerPortrait(weCustomerPortrait);
- return AjaxResult.success();
- }
- /**
- * 获取当前系统所有可用标签
- * @param userId 员工id
- * @return
- */
- @GetMapping(value = "/findAllTags")
- public AjaxResult findAllTags(Integer groupTagType,String userId){
- if(groupTagType.equals(new Integer(1))){//企业标签
- return AjaxResult.success(
- iWeTagGroupService.selectWeTagGroupList(
- WeTagGroup.builder()
- .groupTagType(1)
- .build()
- )
- );
- }
- return AjaxResult.success(
- iWeTagService.list(
- new LambdaQueryWrapper<WeTag>()
- .eq(WeTag::getDelFlag,new Integer(0))
- .eq(WeTag::getOwner,userId)
- )
- );
- }
- /**
- * 客户画像个人标签库新增
- * @param weTagGroup
- * @return
- */
- @PostMapping("/addOrUpdatePersonTags")
- public AjaxResult addOrUpdatePersonTags(@RequestBody WeTagGroup weTagGroup){
- List<WeTag> weTags = weTagGroup.getWeTags();
- if(CollectionUtil.isNotEmpty(weTags)){
- weTags.stream().forEach(k->{
- k.setId(SnowFlakeUtil.nextId());
- k.setTagId(k.getId().toString());
- k.setGroupId(weTagGroup.getGroupId());
- k.setTagType(new Integer(3));
- });
- iWeTagService.saveOrUpdateBatch(weTags);
- }
- return AjaxResult.success();
- }
- /**
- * 个人标签删除
- * @param ids
- * @return
- */
- @DeleteMapping("/deletePersonTag/{ids}")
- public AjaxResult deletePersonTag(@PathVariable String[] ids){
- iWeTagService.removeByIds(CollectionUtil.newArrayList(ids));
- return AjaxResult.success();
- }
- /**
- * 更新客户画像标签
- * @param weMakeCustomerTag
- * @return
- */
- @PostMapping(value = "/updateWeCustomerPorTraitTag")
- public AjaxResult updateWeCustomerPorTraitTag(@RequestBody WeMakeCustomerTag weMakeCustomerTag){
- weCustomerService.makeLabel(weMakeCustomerTag);
- return AjaxResult.success();
- }
- /**
- * 查看客户添加的员工
- * @param externalUserid
- * @return
- */
- @GetMapping(value = "/findAddaddEmployes/{externalUserid}")
- public AjaxResult findaddEmployes(@PathVariable String externalUserid){
- return AjaxResult.success(
- weCustomerService.findWeUserByCustomerId(externalUserid)
- );
- }
- /**
- * 获取用户添加的群
- * @param externalUserid
- * @param userId
- * @return
- */
- @GetMapping(value = "/findAddGroupNum")
- public AjaxResult<WeCustomerAddGroupVo> findAddGroupNum(String externalUserid, String userId){
- return AjaxResult.success(
- iWeGroupService.findWeGroupByCustomer(userId,externalUserid)
- );
- }
- /**
- * 获取轨迹信息
- * @param trajectoryType
- * @return
- */
- @GetMapping(value = "/findTrajectory")
- public TableDataInfo findTrajectory(String userId, String externalUserid, Integer trajectoryType){
- startPage();
- LambdaQueryWrapper<WeCustomerTrajectory> ne = new LambdaQueryWrapper<WeCustomerTrajectory>()
- .eq(WeCustomerTrajectory::getWeUserId,userId)
- .eq(WeCustomerTrajectory::getExternalUseridOrChatid,externalUserid)
- .orderByDesc(WeCustomerTrajectory::getCreateTime);
- if(trajectoryType != null){
- ne.eq(WeCustomerTrajectory::getTrajectoryType, trajectoryType);
- }
- return getDataTable(
- iWeCustomerTrajectoryService.list(ne)
- );
- }
- /**
- *编辑跟进动态
- * @param trajectory
- * @return
- */
- @PostMapping(value = "/addOrEditWaitHandle")
- public AjaxResult addOrEditWaitHandle(@RequestBody WeCustomerTrackRecord trajectory){
- weCustomerService.addOrEditWaitHandle(trajectory);
- return AjaxResult.success();
- }
- /**
- * 个人朋友圈互动数据同步
- * @param userId
- * @return
- */
- @GetMapping("/synchMomentsInteracte/{userId}")
- public AjaxResult synchMomentsInteracte(@PathVariable String userId){
- iWeMomentsService.synchMomentsInteracte(CollectionUtil.newArrayList(userId));
- return AjaxResult.success(WeConstans.SYNCH_TIP);
- }
- /**
- * 获取指定客户拥有的表单字段以及填充的值
- * @param weUserId
- * @param externalUserId
- * @return
- */
- @GetMapping("/findSysFieldTemplate")
- public AjaxResult<List<WeSysFieldTemplate>> findSysFieldTemplate(String weUserId, String externalUserId){
- List<WeSysFieldTemplate> weSysFieldTemplates = iWeSysFieldTemplateService.findLists(new WeSysFieldTemplate());
- for (Iterator iter = weSysFieldTemplates.iterator(); iter.hasNext();) {
- WeSysFieldTemplate weSysFieldTemplate = (WeSysFieldTemplate) iter.next();
- if(StringUtils.isNotEmpty(weSysFieldTemplate.getVisualTagIds())){
- WeCustomer weCustomer = weCustomerService.getOne(new LambdaQueryWrapper<WeCustomer>()
- .eq(WeCustomer::getExternalUserid, externalUserId)
- .eq(WeCustomer::getAddUserId, weUserId));
- if(null != weCustomer && StringUtils.isNotEmpty(weCustomer.getTagIds())){
- if(!ListUtil.toList(weCustomer
- .getTagIds().split(",")).contains(weSysFieldTemplate.getVisualTagIds())){
- iter.remove();
- };
- }
- }
- }
- return AjaxResult.success(
- weSysFieldTemplates
- );
- }
- }
|