RoosInformationServiceImpl.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package com.caimei365.user.service.impl;
  2. import com.caimei365.user.mapper.RoosInformationMapper;
  3. import com.caimei365.user.model.ResponseJson;
  4. import com.caimei365.user.model.dto.RoosInformationDto;
  5. import com.caimei365.user.model.vo.CmShopPopUpVo;
  6. import com.caimei365.user.model.vo.cmShopAdvertisingImage;
  7. import com.caimei365.user.service.RoosInformationService;
  8. import com.caimei365.user.utils.AppletsLinkUtil;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.util.ObjectUtils;
  13. import org.springframework.web.context.request.RequestAttributes;
  14. import org.springframework.web.context.request.RequestContextHolder;
  15. import org.springframework.web.context.request.ServletRequestAttributes;
  16. import javax.servlet.http.HttpServletRequest;
  17. import java.text.SimpleDateFormat;
  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.Date;
  21. import java.util.List;
  22. /**
  23. * Description
  24. *
  25. * @author : Charles
  26. * @date : 2022/12/9
  27. */
  28. @Slf4j
  29. @Service
  30. public class RoosInformationServiceImpl implements RoosInformationService {
  31. @Autowired private RoosInformationMapper roosInformationMapper;
  32. /**
  33. * 查看用户是否有过弹框,游客当天是否有过弹框
  34. *
  35. * @param IP
  36. * @return
  37. */
  38. @Override
  39. public Boolean boolIsClick(String IP, Integer shopId, Integer productId, Integer infoId, String keyword) {
  40. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  41. String format = simpleDateFormat.format(new Date());
  42. List<Integer> list = roosInformationMapper.selIsClick(IP, format, shopId, productId, infoId, keyword);
  43. log.info("list==="+list);
  44. boolean isClick = false;
  45. // 判断是否点击过取消、或者填写过信息
  46. if (null != list && list.size() > 0) {
  47. if (list.stream().allMatch(i -> i == 0)) {
  48. isClick = true;
  49. }
  50. } else {
  51. isClick = true;
  52. }
  53. log.info("shopId==="+shopId+"===productId==="+productId+"===infoId==="+infoId+"===keyword==="+keyword);
  54. // 供应商不存在或者处于不统计状态 不显示弹框
  55. Integer shopStatus = roosInformationMapper.getShopStatus(shopId, productId, infoId, keyword);
  56. List<Integer> shopProductIds = roosInformationMapper.getShopProductIds(shopId);
  57. log.info("shopStatus===="+shopStatus);
  58. // 网站底部的每个商品的弹窗,只在浏览了该商品相关的文章详情,商品详情和搜索列表后才显示,而不是该供应商的任意一个商品都显示
  59. if (null != shopStatus && 0 != shopStatus) {
  60. isClick = false;
  61. }
  62. if (null == shopStatus) {
  63. isClick = false;
  64. }
  65. // 若一个供应商只添加了一个商品,则游客在浏览该供应商主页时,就显示该商品的底部弹窗
  66. if (null != shopId) {
  67. if (null != list && list.size() > 0 && list.stream().allMatch(i -> i == 0)
  68. && null != shopStatus && 0 == shopStatus && null != shopProductIds && shopProductIds.size() == 1) {
  69. isClick = true;
  70. } else {
  71. isClick = false;
  72. }
  73. }
  74. return isClick;
  75. }
  76. /**
  77. * 供应商弹框信息
  78. *
  79. * @param shopId
  80. * @param productId
  81. * @param infoId
  82. * @param keyword
  83. * @return
  84. */
  85. @Override
  86. public ResponseJson<CmShopPopUpVo> getPopUpInfo(Integer shopId, Integer productId, Integer infoId, String keyword) {
  87. log.info("shopId==="+shopId+"===productId==="+productId+"===infoId==="+infoId+"===keyword==="+keyword);
  88. CmShopPopUpVo shopPop = new CmShopPopUpVo();
  89. if (null != shopId) {
  90. List<Integer> shopProductIds = roosInformationMapper.getShopProductIds(shopId);
  91. if (null != shopProductIds && shopProductIds.size() == 1) {
  92. shopPop = roosInformationMapper.getProductPop(shopId);
  93. }
  94. } else {
  95. shopPop = roosInformationMapper.getShopPop(productId, infoId, keyword);
  96. }
  97. if (null == shopPop) {
  98. return ResponseJson.error(-1, "信息异常", null);
  99. }
  100. log.info("shopPop====="+shopPop);
  101. return ResponseJson.success(shopPop);
  102. }
  103. /**
  104. * 插入填写咨询人基本信息
  105. *
  106. * @param roosInformationDto
  107. */
  108. @Override
  109. public ResponseJson<String> insRoosInformation(RoosInformationDto roosInformationDto) {
  110. // 设置创建时间
  111. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  112. String format = simpleDateFormat.format(new Date());
  113. roosInformationDto.setCreateTime(format);
  114. roosInformationMapper.insRoosInformation(roosInformationDto);
  115. return ResponseJson.success("咨询信息插入成功");
  116. }
  117. /**
  118. * 查看访问者是否浏览过供应商相关页面 供应商广告图
  119. *
  120. * @param userId
  121. * @param IP
  122. * @return
  123. */
  124. @Override
  125. public ResponseJson<List<cmShopAdvertisingImage>> selectVisitRoos(Integer userId , String IP) {
  126. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  127. String format = simpleDateFormat.format(new Date());
  128. // 供应商集合
  129. List<Integer> shopIds = new ArrayList<>();
  130. // 该用户是否访问过相关供应商相关页面
  131. List<Integer> shopIdList = roosInformationMapper.getShopId();
  132. for (Integer shopId : shopIdList) {
  133. List<Integer> behavior = null;
  134. // 是否访问过商品
  135. List<Integer> shopProductId = roosInformationMapper.getShopProductId(shopId);
  136. for (Integer productId : shopProductId) {
  137. behavior = roosInformationMapper.getBehavior(userId.toString(), IP, format, 6, productId.toString());
  138. if (behavior != null && behavior.size() > 0) {
  139. if (!shopIds.contains(shopId)) {
  140. shopIds.add(shopId);
  141. }
  142. }
  143. }
  144. // 是否访问过供应商相关文章
  145. List<Integer> shopInfoId = roosInformationMapper.getShopInfoId(shopId);
  146. for (Integer infoId : shopInfoId) {
  147. behavior = roosInformationMapper.getBehavior(userId.toString(), IP, format, 11, infoId.toString());
  148. if (behavior != null && behavior.size() > 0) {
  149. if (!shopIds.contains(shopId)) {
  150. shopIds.add(shopId);
  151. }
  152. }
  153. }
  154. // 是否搜索过供应商相关搜索词
  155. List<String> shopKeyword = roosInformationMapper.getShopKeyword(shopId);
  156. for (String keyword: shopKeyword) {
  157. behavior = roosInformationMapper.getBehavior(userId.toString(), IP, format, 8, keyword);
  158. if (behavior != null && behavior.size() > 0) {
  159. if (!shopIds.contains(shopId)) {
  160. shopIds.add(shopId);
  161. }
  162. }
  163. }
  164. }
  165. // 返回数供应商广告图据
  166. List<cmShopAdvertisingImage> shopAdvert = roosInformationMapper.getShopAdvert(shopIdList);
  167. for (cmShopAdvertisingImage advert : shopAdvert) {
  168. advert.setLinkType(AppletsLinkUtil.getLinkType(advert.getJumpLink()));
  169. advert.setLinkParam(AppletsLinkUtil.getLinkParam(advert.getLinkType(), advert.getJumpLink()));
  170. }
  171. return ResponseJson.success(shopAdvert);
  172. }
  173. /**
  174. * 获取用户访问IP
  175. * @return
  176. */
  177. @Override
  178. public String obtainIp() {
  179. RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
  180. ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
  181. HttpServletRequest request = servletRequestAttributes.getRequest();
  182. // ip
  183. String unknown = "unknown";
  184. String ip = "";
  185. ip = request.getHeader("x-forwarded-for");
  186. if (org.apache.commons.lang.StringUtils.isBlank(ip)) {
  187. ip = request.getHeader("X-Real-IP");
  188. }
  189. if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
  190. ip = request.getHeader("Proxy-Client-IP");
  191. }
  192. if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
  193. ip = request.getHeader("WL-Proxy-Client-IP");
  194. }
  195. if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
  196. ip = request.getRemoteAddr();
  197. }
  198. log.info("获取访问人ip==========="+ip);
  199. return ip;
  200. }
  201. }