WeCustomerPortraitController.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package com.linkwechat.controller;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import cn.hutool.core.collection.ListUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.linkwechat.common.constant.Constants;
  6. import com.linkwechat.common.constant.WeConstans;
  7. import com.linkwechat.common.core.controller.BaseController;
  8. import com.linkwechat.common.core.domain.AjaxResult;
  9. import com.linkwechat.common.core.page.TableDataInfo;
  10. import com.linkwechat.common.utils.SnowFlakeUtil;
  11. import com.linkwechat.common.utils.StringUtils;
  12. import com.linkwechat.domain.*;
  13. import com.linkwechat.domain.customer.WeMakeCustomerTag;
  14. import com.linkwechat.domain.customer.vo.WeCustomerAddGroupVo;
  15. import com.linkwechat.domain.customer.vo.WeCustomerPortraitVo;
  16. import com.linkwechat.service.*;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import java.util.Iterator;
  20. import java.util.List;
  21. /**
  22. * @description: 客户画像相关controller
  23. * @author: HaoN
  24. * @create: 2021-03-03 15:10
  25. **/
  26. @RestController
  27. @RequestMapping("/portrait")
  28. public class WeCustomerPortraitController extends BaseController{
  29. @Autowired
  30. private IWeCustomerService weCustomerService;
  31. @Autowired
  32. private IWeTagService iWeTagService;
  33. @Autowired
  34. private IWeTagGroupService iWeTagGroupService;
  35. @Autowired
  36. private IWeGroupService iWeGroupService;
  37. @Autowired
  38. private IWeCustomerTrajectoryService iWeCustomerTrajectoryService;
  39. @Autowired
  40. private IWeMomentsService iWeMomentsService;
  41. @Autowired
  42. private IWeSysFieldTemplateService iWeSysFieldTemplateService;
  43. /**
  44. * 根据客户id和当前企业员工id获取客户详细信息
  45. * @param externalUserid
  46. * @param userId
  47. * @return
  48. */
  49. @GetMapping(value = "/findWeCustomerInfo")
  50. public AjaxResult<WeCustomerPortraitVo> findWeCustomerInfo(String externalUserid, String userId) throws Exception {
  51. return AjaxResult.success(
  52. weCustomerService.findCustomerByOperUseridAndCustomerId(externalUserid,userId)
  53. );
  54. }
  55. /**
  56. * 客户画像资料更新
  57. * @param weCustomerPortrait
  58. * @return
  59. */
  60. @PostMapping(value = "/updateWeCustomerInfo")
  61. public AjaxResult updateWeCustomerInfo(@RequestBody WeCustomerPortraitVo weCustomerPortrait){
  62. weCustomerService.updateWeCustomerPortrait(weCustomerPortrait);
  63. return AjaxResult.success();
  64. }
  65. /**
  66. * 获取当前系统所有可用标签
  67. * @param userId 员工id
  68. * @return
  69. */
  70. @GetMapping(value = "/findAllTags")
  71. public AjaxResult findAllTags(Integer groupTagType,String userId){
  72. if(groupTagType.equals(new Integer(1))){//企业标签
  73. return AjaxResult.success(
  74. iWeTagGroupService.selectWeTagGroupList(
  75. WeTagGroup.builder()
  76. .groupTagType(1)
  77. .build()
  78. )
  79. );
  80. }
  81. return AjaxResult.success(
  82. iWeTagService.list(
  83. new LambdaQueryWrapper<WeTag>()
  84. .eq(WeTag::getDelFlag,new Integer(0))
  85. .eq(WeTag::getOwner,userId)
  86. )
  87. );
  88. }
  89. /**
  90. * 客户画像个人标签库新增
  91. * @param weTagGroup
  92. * @return
  93. */
  94. @PostMapping("/addOrUpdatePersonTags")
  95. public AjaxResult addOrUpdatePersonTags(@RequestBody WeTagGroup weTagGroup){
  96. List<WeTag> weTags = weTagGroup.getWeTags();
  97. if(CollectionUtil.isNotEmpty(weTags)){
  98. weTags.stream().forEach(k->{
  99. k.setId(SnowFlakeUtil.nextId());
  100. k.setTagId(k.getId().toString());
  101. k.setGroupId(weTagGroup.getGroupId());
  102. k.setTagType(new Integer(3));
  103. });
  104. iWeTagService.saveOrUpdateBatch(weTags);
  105. }
  106. return AjaxResult.success();
  107. }
  108. /**
  109. * 个人标签删除
  110. * @param ids
  111. * @return
  112. */
  113. @DeleteMapping("/deletePersonTag/{ids}")
  114. public AjaxResult deletePersonTag(@PathVariable String[] ids){
  115. iWeTagService.removeByIds(CollectionUtil.newArrayList(ids));
  116. return AjaxResult.success();
  117. }
  118. /**
  119. * 更新客户画像标签
  120. * @param weMakeCustomerTag
  121. * @return
  122. */
  123. @PostMapping(value = "/updateWeCustomerPorTraitTag")
  124. public AjaxResult updateWeCustomerPorTraitTag(@RequestBody WeMakeCustomerTag weMakeCustomerTag){
  125. weCustomerService.makeLabel(weMakeCustomerTag);
  126. return AjaxResult.success();
  127. }
  128. /**
  129. * 查看客户添加的员工
  130. * @param externalUserid
  131. * @return
  132. */
  133. @GetMapping(value = "/findAddaddEmployes/{externalUserid}")
  134. public AjaxResult findaddEmployes(@PathVariable String externalUserid){
  135. return AjaxResult.success(
  136. weCustomerService.findWeUserByCustomerId(externalUserid)
  137. );
  138. }
  139. /**
  140. * 获取用户添加的群
  141. * @param externalUserid
  142. * @param userId
  143. * @return
  144. */
  145. @GetMapping(value = "/findAddGroupNum")
  146. public AjaxResult<WeCustomerAddGroupVo> findAddGroupNum(String externalUserid, String userId){
  147. return AjaxResult.success(
  148. iWeGroupService.findWeGroupByCustomer(userId,externalUserid)
  149. );
  150. }
  151. /**
  152. * 获取轨迹信息
  153. * @param trajectoryType
  154. * @return
  155. */
  156. @GetMapping(value = "/findTrajectory")
  157. public TableDataInfo findTrajectory(String userId, String externalUserid, Integer trajectoryType){
  158. startPage();
  159. LambdaQueryWrapper<WeCustomerTrajectory> ne = new LambdaQueryWrapper<WeCustomerTrajectory>()
  160. .eq(WeCustomerTrajectory::getWeUserId,userId)
  161. .eq(WeCustomerTrajectory::getExternalUseridOrChatid,externalUserid)
  162. .orderByDesc(WeCustomerTrajectory::getCreateTime);
  163. if(trajectoryType != null){
  164. ne.eq(WeCustomerTrajectory::getTrajectoryType, trajectoryType);
  165. }
  166. return getDataTable(
  167. iWeCustomerTrajectoryService.list(ne)
  168. );
  169. }
  170. /**
  171. *编辑跟进动态
  172. * @param trajectory
  173. * @return
  174. */
  175. @PostMapping(value = "/addOrEditWaitHandle")
  176. public AjaxResult addOrEditWaitHandle(@RequestBody WeCustomerTrackRecord trajectory){
  177. weCustomerService.addOrEditWaitHandle(trajectory);
  178. return AjaxResult.success();
  179. }
  180. /**
  181. * 个人朋友圈互动数据同步
  182. * @param userId
  183. * @return
  184. */
  185. @GetMapping("/synchMomentsInteracte/{userId}")
  186. public AjaxResult synchMomentsInteracte(@PathVariable String userId){
  187. iWeMomentsService.synchMomentsInteracte(CollectionUtil.newArrayList(userId));
  188. return AjaxResult.success(WeConstans.SYNCH_TIP);
  189. }
  190. /**
  191. * 获取指定客户拥有的表单字段以及填充的值
  192. * @param weUserId
  193. * @param externalUserId
  194. * @return
  195. */
  196. @GetMapping("/findSysFieldTemplate")
  197. public AjaxResult<List<WeSysFieldTemplate>> findSysFieldTemplate(String weUserId, String externalUserId){
  198. List<WeSysFieldTemplate> weSysFieldTemplates = iWeSysFieldTemplateService.findLists(new WeSysFieldTemplate());
  199. for (Iterator iter = weSysFieldTemplates.iterator(); iter.hasNext();) {
  200. WeSysFieldTemplate weSysFieldTemplate = (WeSysFieldTemplate) iter.next();
  201. if(StringUtils.isNotEmpty(weSysFieldTemplate.getVisualTagIds())){
  202. WeCustomer weCustomer = weCustomerService.getOne(new LambdaQueryWrapper<WeCustomer>()
  203. .eq(WeCustomer::getExternalUserid, externalUserId)
  204. .eq(WeCustomer::getAddUserId, weUserId));
  205. if(null != weCustomer && StringUtils.isNotEmpty(weCustomer.getTagIds())){
  206. if(!ListUtil.toList(weCustomer
  207. .getTagIds().split(",")).contains(weSysFieldTemplate.getVisualTagIds())){
  208. iter.remove();
  209. };
  210. }
  211. }
  212. }
  213. return AjaxResult.success(
  214. weSysFieldTemplates
  215. );
  216. }
  217. }