ChannelController.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.cyksj.web.controller.channel;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.cyksj.common.constant.Constant;
  6. import com.cyksj.common.exception.BusinessRuntimeException;
  7. import com.cyksj.common.util.Jsons;
  8. import com.cyksj.dto.Result;
  9. import com.cyksj.enums.GatewayResponse;
  10. import com.cyksj.mapper.channel.ChannelPopularizeMapper;
  11. import com.cyksj.mapper.channel.ChannelPopularizeVisitMapper;
  12. import com.cyksj.mapper.channel.MoviesVisitRecordMapper;
  13. import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
  14. import com.cyksj.mapper.sys.SysConfigMapper;
  15. import com.cyksj.model.entity.ChannelPopularizeVisit;
  16. import com.cyksj.model.entity.MoviesVisitRecord;
  17. import com.cyksj.model.entity.SysConfig;
  18. import com.cyksj.model.manage.dto.ChannelBaiDuDiscountDto;
  19. import com.cyksj.model.views.ChannelPopularizeFrontView;
  20. import com.cyksj.model.views.CouponTfPopularizeView;
  21. import com.cyksj.service.corp.CorpCustomerAcquistionService;
  22. import com.cyksj.web.util.StpUserUtil;
  23. import com.ejlchina.searcher.BeanSearcher;
  24. import com.ejlchina.searcher.param.Operator;
  25. import com.ejlchina.searcher.util.MapBuilder;
  26. import com.ejlchina.searcher.util.MapUtils;
  27. import lombok.RequiredArgsConstructor;
  28. import lombok.extern.slf4j.Slf4j;
  29. import org.springframework.web.bind.annotation.*;
  30. import javax.servlet.http.HttpServletResponse;
  31. import java.util.List;
  32. /**
  33. * @author chan
  34. * @date 2022/12/13 2:36 PM
  35. */
  36. @RequestMapping("/applets/channel")
  37. @RestController
  38. @RequiredArgsConstructor
  39. @Slf4j
  40. public class ChannelController {
  41. private final HttpServletResponse response;
  42. private final ChannelPopularizeVisitMapper channelPopularizeVisitMapper;
  43. private final ChannelPopularizeMapper popularizeMapper;
  44. private final MoviesVisitRecordMapper moviesVisitRecordMapper;
  45. private final BeanSearcher beanSearcher;
  46. private final CouponSkuMapper couponSkuMapper;
  47. private final CorpCustomerAcquistionService corpCustomerAcquistionService;
  48. private final SysConfigMapper sysConfigMapper;
  49. @GetMapping("/get/{id}")
  50. public Result<ChannelPopularizeFrontView> getById(@PathVariable Long id) {
  51. ChannelPopularizeFrontView channelPopularize = beanSearcher.searchFirst(ChannelPopularizeFrontView.class, MapUtils.builder()
  52. .put("id", String.format("id = %s", id))
  53. .build());
  54. if (channelPopularize == null) {
  55. throw BusinessRuntimeException.getInstance("该链接不存在!");
  56. }
  57. if (StrUtil.isNotBlank(channelPopularize.getCouponIds())) {
  58. try {
  59. List<Long> couponIds = Jsons.parseList(channelPopularize.getCouponIds(), Long.class);
  60. Long userId = StpUserUtil.getUserIdAfterLogin();
  61. MapBuilder builder = MapUtils.builder().field(CouponTfPopularizeView::getCouponId, couponIds).op(Operator.InList);
  62. if (userId != null) {
  63. builder.put("user_id", String.format("and cu.user_id = %s", userId));
  64. }
  65. List<CouponTfPopularizeView> couponTfPopularizeViews = beanSearcher.searchAll(CouponTfPopularizeView.class, builder.build());
  66. couponTfPopularizeViews.forEach(data -> {
  67. String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
  68. data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
  69. });
  70. channelPopularize.setCoupons(couponTfPopularizeViews);
  71. } catch (Exception e) {
  72. System.out.println(e.getMessage());
  73. }
  74. }
  75. String channelName = channelPopularize.getChannelName();
  76. if (channelName.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(0)) || channelName.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(1))) {
  77. String key;
  78. if (channelName.contains(Constant.NO_SIGN_CHANNEL_NAMES.get(0))) {
  79. key = Constant.CHANNEL_BAIDU_DISCOUNT_KEY;
  80. } else {
  81. key = Constant.CHANNEL_DY_DISCOUNT_KEY;
  82. }
  83. SysConfig baiduConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  84. .eq(SysConfig::getSysKey, key).last("limit 1"));
  85. if (baiduConfig != null) {
  86. String sysValue = baiduConfig.getSysValue();
  87. if (StrUtil.isNotBlank(sysValue)) {
  88. try {
  89. ChannelBaiDuDiscountDto baiDuDiscountDto = Jsons.parseObject(sysValue, ChannelBaiDuDiscountDto.class);
  90. if (baiDuDiscountDto != null && CollUtil.isNotEmpty(baiDuDiscountDto.getPopularizeIds()) && baiDuDiscountDto.getPopularizeIds().contains(id)) {
  91. channelPopularize.setIsSign(true);
  92. channelPopularize.setDiscount(baiDuDiscountDto.getDiscount());
  93. }
  94. } catch (Exception e) {
  95. }
  96. }
  97. }
  98. }
  99. ChannelPopularizeVisit channelPopularizeVisit = new ChannelPopularizeVisit();
  100. channelPopularizeVisit.setPopularizeId(id);
  101. channelPopularizeVisitMapper.insert(channelPopularizeVisit);
  102. return GatewayResponse.SUCCESS.newBuilder().toResult(channelPopularize);
  103. }
  104. /**
  105. * 记录银河电影浏览量
  106. */
  107. @PostMapping("/movies/record/")
  108. public Result<String> moviesVisitRecord() {
  109. MoviesVisitRecord moviesVisitRecord = new MoviesVisitRecord();
  110. moviesVisitRecord.setType(MoviesVisitRecord.Type.movies);
  111. moviesVisitRecordMapper.insert(moviesVisitRecord);
  112. return GatewayResponse.SUCCESS.newBuilder().toResult();
  113. }
  114. /**
  115. * 橙子建站带参跳转获客链接
  116. */
  117. @GetMapping("/customerAcquistion")
  118. public void customerAcquistion(String projectid, String clickid, String callback, Long linkId) throws Exception {
  119. log.info("橙子建站带参跳转获客链接 projectid:{} clickid:{},callback:{}", projectid, clickid, callback);
  120. if (StrUtil.equals(projectid, "__PROJECT_ID__") && StrUtil.equals(clickid, "__CLICKID__") && linkId != null && linkId == 5) {
  121. response.sendRedirect("https://www.chengzijianzhan.com/tetris/page/7321557902601240626/");
  122. return;
  123. }
  124. String key = corpCustomerAcquistionService.saveClickid(projectid, clickid, callback, linkId);
  125. String url = corpCustomerAcquistionService.getUrlByLinkId(linkId);
  126. String redirect = url + "?customer_channel=" + "customer_" + key;
  127. log.info("橙子建站带参跳转获客链接 跳转路径:{}", redirect);
  128. response.sendRedirect(redirect);
  129. }
  130. /**
  131. * 动态客服 链接
  132. * acLinkId 获客链接id
  133. */
  134. @GetMapping("/customerAcquistion/{acLinkId}")
  135. public void getCustomerAcquistionById(@PathVariable Long acLinkId) throws Exception {
  136. log.info("动态客服获客链接跳转 acLinkId:{}", acLinkId);
  137. String url = corpCustomerAcquistionService.getActiveCustomerAcquistionById(acLinkId);
  138. String redirect = url + "?customer_channel=" + "customer_" + acLinkId;
  139. log.info("动态客服获客链接 跳转路径:{}", redirect);
  140. response.sendRedirect(redirect);
  141. }
  142. }