123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- package com.caimei365.user.service.impl;
- import com.caimei365.user.mapper.RoosInformationMapper;
- import com.caimei365.user.model.ResponseJson;
- import com.caimei365.user.model.dto.RoosInformationDto;
- import com.caimei365.user.model.vo.CmShopPopUpVo;
- import com.caimei365.user.model.vo.cmShopAdvertisingImage;
- import com.caimei365.user.service.RoosInformationService;
- import com.caimei365.user.utils.AppletsLinkUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- import org.springframework.web.context.request.RequestAttributes;
- import org.springframework.web.context.request.RequestContextHolder;
- import org.springframework.web.context.request.ServletRequestAttributes;
- import javax.servlet.http.HttpServletRequest;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.List;
- /**
- * Description
- *
- * @author : Charles
- * @date : 2022/12/9
- */
- @Slf4j
- @Service
- public class RoosInformationServiceImpl implements RoosInformationService {
- @Autowired private RoosInformationMapper roosInformationMapper;
- /**
- * 查看用户是否有过弹框,游客当天是否有过弹框
- *
- * @param IP
- * @return
- */
- @Override
- public Boolean boolIsClick(String IP, Integer shopId, Integer productId, Integer infoId, String keyword) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- String format = simpleDateFormat.format(new Date());
- List<Integer> list = roosInformationMapper.selIsClick(IP, format, shopId, productId, infoId, keyword);
- log.info("list==="+list);
- boolean isClick = false;
- // 判断是否点击过取消、或者填写过信息
- if (null != list && list.size() > 0) {
- if (list.stream().allMatch(i -> i == 0)) {
- isClick = true;
- }
- } else {
- isClick = true;
- }
- log.info("shopId==="+shopId+"===productId==="+productId+"===infoId==="+infoId+"===keyword==="+keyword);
- // 供应商不存在或者处于不统计状态 不显示弹框
- Integer shopStatus = roosInformationMapper.getShopStatus(shopId, productId, infoId, keyword);
- List<Integer> shopProductIds = roosInformationMapper.getShopProductIds(shopId);
- log.info("shopStatus===="+shopStatus);
- // 网站底部的每个商品的弹窗,只在浏览了该商品相关的文章详情,商品详情和搜索列表后才显示,而不是该供应商的任意一个商品都显示
- if (null != shopStatus && 0 != shopStatus) {
- isClick = false;
- }
- if (null == shopStatus) {
- isClick = false;
- }
- // 若一个供应商只添加了一个商品,则游客在浏览该供应商主页时,就显示该商品的底部弹窗
- if (null != shopId) {
- if (null != list && list.size() > 0 && list.stream().allMatch(i -> i == 0)
- && null != shopStatus && 0 == shopStatus && null != shopProductIds && shopProductIds.size() == 1) {
- isClick = true;
- } else {
- isClick = false;
- }
- }
- return isClick;
- }
- /**
- * 供应商弹框信息
- *
- * @param shopId
- * @param productId
- * @param infoId
- * @param keyword
- * @return
- */
- @Override
- public ResponseJson<CmShopPopUpVo> getPopUpInfo(Integer shopId, Integer productId, Integer infoId, String keyword) {
- log.info("shopId==="+shopId+"===productId==="+productId+"===infoId==="+infoId+"===keyword==="+keyword);
- CmShopPopUpVo shopPop = new CmShopPopUpVo();
- if (null != shopId) {
- List<Integer> shopProductIds = roosInformationMapper.getShopProductIds(shopId);
- if (null != shopProductIds && shopProductIds.size() == 1) {
- shopPop = roosInformationMapper.getProductPop(shopId);
- }
- } else {
- shopPop = roosInformationMapper.getShopPop(productId, infoId, keyword);
- }
- if (null == shopPop) {
- return ResponseJson.error(-1, "信息异常", null);
- }
- log.info("shopPop====="+shopPop);
- return ResponseJson.success(shopPop);
- }
- /**
- * 插入填写咨询人基本信息
- *
- * @param roosInformationDto
- */
- @Override
- public ResponseJson<String> insRoosInformation(RoosInformationDto roosInformationDto) {
- // 设置创建时间
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String format = simpleDateFormat.format(new Date());
- roosInformationDto.setCreateTime(format);
- roosInformationMapper.insRoosInformation(roosInformationDto);
- return ResponseJson.success("咨询信息插入成功");
- }
- /**
- * 查看访问者是否浏览过供应商相关页面 供应商广告图
- *
- * @param userId
- * @param IP
- * @return
- */
- @Override
- public ResponseJson<List<cmShopAdvertisingImage>> selectVisitRoos(Integer userId , String IP) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- String format = simpleDateFormat.format(new Date());
- // 供应商集合
- List<Integer> shopIds = new ArrayList<>();
- // 该用户是否访问过相关供应商相关页面
- List<Integer> shopIdList = roosInformationMapper.getShopId();
- for (Integer shopId : shopIdList) {
- List<Integer> behavior = null;
- // 是否访问过商品
- List<Integer> shopProductId = roosInformationMapper.getShopProductId(shopId);
- for (Integer productId : shopProductId) {
- behavior = roosInformationMapper.getBehavior(userId.toString(), IP, format, 6, productId.toString());
- if (behavior != null && behavior.size() > 0) {
- if (!shopIds.contains(shopId)) {
- shopIds.add(shopId);
- }
- }
- }
- // 是否访问过供应商相关文章
- List<Integer> shopInfoId = roosInformationMapper.getShopInfoId(shopId);
- for (Integer infoId : shopInfoId) {
- behavior = roosInformationMapper.getBehavior(userId.toString(), IP, format, 11, infoId.toString());
- if (behavior != null && behavior.size() > 0) {
- if (!shopIds.contains(shopId)) {
- shopIds.add(shopId);
- }
- }
- }
- // 是否搜索过供应商相关搜索词
- List<String> shopKeyword = roosInformationMapper.getShopKeyword(shopId);
- for (String keyword: shopKeyword) {
- behavior = roosInformationMapper.getBehavior(userId.toString(), IP, format, 8, keyword);
- if (behavior != null && behavior.size() > 0) {
- if (!shopIds.contains(shopId)) {
- shopIds.add(shopId);
- }
- }
- }
- }
- // 返回数供应商广告图据
- List<cmShopAdvertisingImage> shopAdvert = roosInformationMapper.getShopAdvert(shopIdList);
- for (cmShopAdvertisingImage advert : shopAdvert) {
- advert.setLinkType(AppletsLinkUtil.getLinkType(advert.getJumpLink()));
- advert.setLinkParam(AppletsLinkUtil.getLinkParam(advert.getLinkType(), advert.getJumpLink()));
- }
- return ResponseJson.success(shopAdvert);
- }
- /**
- * 获取用户访问IP
- * @return
- */
- @Override
- public String obtainIp() {
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
- ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
- HttpServletRequest request = servletRequestAttributes.getRequest();
- // ip
- String unknown = "unknown";
- String ip = "";
- ip = request.getHeader("x-forwarded-for");
- if (org.apache.commons.lang.StringUtils.isBlank(ip)) {
- ip = request.getHeader("X-Real-IP");
- }
- if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
- ip = request.getHeader("Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
- ip = request.getHeader("WL-Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
- ip = request.getRemoteAddr();
- }
- log.info("获取访问人ip==========="+ip);
- return ip;
- }
- }
|