WeCustomerController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. package com.linkwechat.controller;
  2. import cn.hutool.core.collection.ListUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.linkwechat.common.annotation.Log;
  5. import com.linkwechat.common.annotation.PhoneEncryptMethod;
  6. import com.linkwechat.common.constant.Constants;
  7. import com.linkwechat.common.constant.SynchRecordConstants;
  8. import com.linkwechat.common.constant.WeConstans;
  9. import com.linkwechat.common.core.controller.BaseController;
  10. import com.linkwechat.common.core.domain.AjaxResult;
  11. import com.linkwechat.common.core.page.TableDataInfo;
  12. import com.linkwechat.common.core.page.TableSupport;
  13. import com.linkwechat.common.enums.BusinessType;
  14. import com.linkwechat.common.exception.CustomException;
  15. import com.linkwechat.common.utils.ServletUtils;
  16. import com.linkwechat.common.utils.poi.LwExcelUtil;
  17. import com.linkwechat.domain.WeCustomer;
  18. import com.linkwechat.domain.WeCustomerSeas;
  19. import com.linkwechat.domain.customer.WeBacthMakeCustomerTag;
  20. import com.linkwechat.domain.customer.WeMakeCustomerTag;
  21. import com.linkwechat.domain.customer.query.WeCustomersQuery;
  22. import com.linkwechat.domain.customer.query.WeOnTheJobCustomerQuery;
  23. import com.linkwechat.domain.customer.vo.WeCustomerDetailInfoVo;
  24. import com.linkwechat.domain.customer.vo.WeCustomersVo;
  25. import com.linkwechat.service.IWeCustomerService;
  26. import com.linkwechat.service.IWeSynchRecordService;
  27. import io.swagger.annotations.ApiOperation;
  28. import lombok.extern.slf4j.Slf4j;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.web.bind.annotation.*;
  31. import java.util.ArrayList;
  32. import java.util.List;
  33. import java.util.Optional;
  34. import java.util.Set;
  35. import java.util.stream.Collectors;
  36. /**
  37. * 企业微信客户Controller
  38. *
  39. * @author ruoyi
  40. * @date 2020-09-13
  41. */
  42. @Slf4j
  43. @RestController
  44. @RequestMapping("/customer")
  45. public class WeCustomerController extends BaseController {
  46. @Autowired
  47. private IWeCustomerService weCustomerService;
  48. @Autowired
  49. private IWeSynchRecordService iWeSynchRecordService;
  50. /**
  51. * 查询企业微信客户列表(分页),索引优化客户列表,未使用默认分页
  52. */
  53. @GetMapping("/findWeCustomerList")
  54. public TableDataInfo findWeCustomerList(WeCustomersQuery weCustomersQuery)
  55. {
  56. weCustomersQuery.setDelFlag(null == weCustomersQuery.getDelFlag() ? Constants.COMMON_STATE : weCustomersQuery.getDelFlag());
  57. List<WeCustomersVo> list = weCustomerService.findWeCustomerList(weCustomersQuery, TableSupport.buildPageRequest());
  58. TableDataInfo dataTable = getDataTable(list);
  59. //设置总条数
  60. dataTable.setTotal(
  61. weCustomerService.countWeCustomerList(weCustomersQuery)
  62. );
  63. dataTable.setLastSyncTime(
  64. iWeSynchRecordService.findUpdateLatestTime(SynchRecordConstants.SYNCH_CUSTOMER)
  65. );//最近同步时间
  66. dataTable.setNoRepeatCustomerTotal(
  67. weCustomerService.noRepeatCountCustomer(weCustomersQuery)
  68. );//去重客户数
  69. return dataTable;
  70. }
  71. /**
  72. * 导出企业客户
  73. */
  74. @GetMapping("/exprotWeCustomerList")
  75. public void exprotWeCustomerList(WeCustomersQuery weCustomersQuery)
  76. {
  77. weCustomersQuery.setDelFlag(null == weCustomersQuery.getDelFlag() ? Constants.COMMON_STATE : weCustomersQuery.getDelFlag());
  78. List<WeCustomersVo> list = weCustomerService.findWeCustomerList(weCustomersQuery, null);
  79. LwExcelUtil.exprotForWeb(
  80. ServletUtils.getResponse(), WeCustomersVo .class, list,"企业客户"
  81. );
  82. }
  83. /**
  84. * 移动应用客户列表(分页)
  85. * @param weCustomersQuery
  86. * @return
  87. */
  88. @GetMapping("/findWeCustomerListByApp")
  89. public TableDataInfo<List<WeCustomersVo>> findWeCustomerListByApp(WeCustomersQuery weCustomersQuery){
  90. return weCustomerService.findWeCustomerListByApp(
  91. weCustomersQuery,TableSupport.buildPageRequest()
  92. );
  93. }
  94. /**
  95. * 查询企业微信客户列表(不分页)
  96. */
  97. @GetMapping("/findAllWeCustomerList")
  98. public AjaxResult findAllWeCustomerList(WeCustomersQuery weCustomersQuery)
  99. {
  100. weCustomersQuery.setDelFlag(null == weCustomersQuery.getDelFlag() ? Constants.COMMON_STATE : weCustomersQuery.getDelFlag());
  101. return AjaxResult.success(
  102. weCustomerService.findWeCustomerList(weCustomersQuery,null)
  103. );
  104. }
  105. /**
  106. * 客户同步接口
  107. * @return
  108. */
  109. @Log(title = "企业微信客户同步接口", businessType = BusinessType.DELETE)
  110. @GetMapping("/synchWeCustomer")
  111. public AjaxResult synchWeCustomer() {
  112. try {
  113. weCustomerService.synchWeCustomer();
  114. }catch (CustomException e){
  115. log.error("客户同步失败:ex:{}",e.getMessage(),e);
  116. return AjaxResult.error(e.getMessage());
  117. }
  118. return AjaxResult.success(WeConstans.SYNCH_TIP);
  119. }
  120. /**
  121. * 客户打标签
  122. * @param weMakeCustomerTag
  123. * @return
  124. */
  125. @Log(title = "客户打标签", businessType = BusinessType.UPDATE)
  126. @PostMapping("/makeLabel")
  127. public AjaxResult makeLabel(@RequestBody WeMakeCustomerTag weMakeCustomerTag){
  128. weCustomerService.makeLabel(weMakeCustomerTag);
  129. return AjaxResult.success();
  130. }
  131. /**
  132. * 在职继承
  133. * @param weOnTheJobCustomerQuery
  134. * @return
  135. */
  136. @Log(title="在职继承",businessType = BusinessType.UPDATE)
  137. @PostMapping("/jobExtends")
  138. public AjaxResult jobExtends(@RequestBody WeOnTheJobCustomerQuery weOnTheJobCustomerQuery){
  139. try {
  140. weCustomerService.allocateOnTheJobCustomer(
  141. weOnTheJobCustomerQuery
  142. );
  143. }catch (Exception e){
  144. e.printStackTrace();
  145. return AjaxResult.error(e.getMessage());
  146. }
  147. return AjaxResult.success();
  148. }
  149. /**********************************************************************************
  150. **************************************客户详情*************************************
  151. *********************************************************************************/
  152. /**
  153. * 客户详情基础(基础信息+社交关系)
  154. * @param externalUserid
  155. * @param userId
  156. * @param
  157. * @return
  158. */
  159. @GetMapping("/findWeCustomerBaseInfo")
  160. public AjaxResult<WeCustomerDetailInfoVo> findWeCustomerBaseInfo(String externalUserid, String userId, @RequestParam(defaultValue = "0") Integer delFlag){
  161. return AjaxResult.success(
  162. weCustomerService.findWeCustomerDetail(externalUserid,userId,null)
  163. );
  164. }
  165. /**
  166. * 客户画像汇总
  167. * @param externalUserid
  168. * @return
  169. */
  170. @GetMapping("/findWeCustomerInfoSummary")
  171. public AjaxResult<WeCustomerDetailInfoVo> findWeCustomerInfoSummary(String externalUserid,@RequestParam(defaultValue = "0") Integer delFlag){
  172. return AjaxResult.success(
  173. weCustomerService.findWeCustomerInfoSummary(externalUserid,null,null)
  174. );
  175. }
  176. /**
  177. * 单个跟进人客户
  178. * @param externalUserid
  179. * @param weUserId
  180. * @return
  181. */
  182. @GetMapping("/findWeCustomerInfoByUserId")
  183. public AjaxResult findWeCustomerInfoByUserId(String externalUserid,String weUserId,@RequestParam(defaultValue = "0") Integer delFlag){
  184. return AjaxResult.success(
  185. weCustomerService.findWeCustomerInfoByUserId(externalUserid,weUserId,null)
  186. );
  187. }
  188. // /**
  189. // * 跟进记录
  190. // * @param externalUserid
  191. // * @param userId
  192. // * @return
  193. // */
  194. // @GetMapping("/followUpRecord")
  195. // public TableDataInfo followUpRecord(String externalUserid,String userId){
  196. //
  197. // startPage();
  198. //
  199. // return getDataTable( iWeCustomerTrackRecordService.list(new LambdaQueryWrapper<WeCustomerTrackRecord>()
  200. // .eq(WeCustomerTrackRecord::getExternalUserid,externalUserid)
  201. // .eq(WeCustomerTrackRecord::getWeUserId,userId)));
  202. // }
  203. // /**
  204. // * 客户轨迹
  205. // * @param externalUserid
  206. // * @param weUserId
  207. // * @param trajectoryType 轨迹类型:1:信息动态;2:社交动态;3:活动规则;4:待办动态
  208. // * @return
  209. // */
  210. // @GetMapping("/findTrajectory")
  211. // public AjaxResult<WeCustomerTrajectory> findTrajectory(String externalUserid,String weUserId,Integer trajectoryType){
  212. //
  213. // List<WeCustomerTrajectory> weCustomerTrajectories = iWeCustomerTrajectoryService
  214. // .list(new LambdaQueryWrapper<WeCustomerTrajectory>()
  215. // .eq(StringUtils.isNotEmpty(externalUserid),WeCustomerTrajectory::getExternalUseridOrChatid, externalUserid)
  216. // .eq(StringUtils.isNotEmpty(weUserId),WeCustomerTrajectory::getWeUserId, weUserId)
  217. // .eq(trajectoryType !=null,WeCustomerTrajectory::getTrajectoryType,trajectoryType)
  218. // );
  219. //
  220. // return AjaxResult.success(weCustomerTrajectories);
  221. // }
  222. @ApiOperation(value = "通过条件校验客户数据", httpMethod = "POST")
  223. @PostMapping("/checkByCondition")
  224. public AjaxResult checkByCondition(@RequestBody WeCustomersQuery query){
  225. log.info("checkByCondition 接口入参:query:{}", JSONObject.toJSONString(query));
  226. List<WeCustomer> customerList = weCustomerService.getCustomerListByCondition(query);
  227. Set<String> externalUserIdSet = Optional.ofNullable(customerList).orElseGet(ArrayList::new)
  228. .stream().map(WeCustomer::getExternalUserid).collect(Collectors.toSet());
  229. Set<String> userNum = Optional.ofNullable(customerList).orElseGet(ArrayList::new)
  230. .stream().map(WeCustomer::getAddUserId).collect(Collectors.toSet());
  231. JSONObject result = new JSONObject();
  232. result.put("customerNum",externalUserIdSet.size());
  233. result.put("userNum",userNum.size());
  234. return AjaxResult.success(result);
  235. }
  236. /**
  237. * 批量添加或删除客户标签
  238. * @param makeCustomerTags
  239. * @return
  240. */
  241. @Log(title = "批量添加或删除客户标签", businessType = BusinessType.UPDATE)
  242. @PostMapping("/batchMakeLabel")
  243. public AjaxResult batchMakeLabel(@RequestBody WeBacthMakeCustomerTag makeCustomerTags){
  244. weCustomerService.batchMakeLabel(makeCustomerTags);
  245. return AjaxResult.success();
  246. }
  247. }