123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855 |
- package com.caimei365.commodity.service.impl;
- import com.caimei365.commodity.components.PriceUtilService;
- import com.caimei365.commodity.mapper.*;
- import com.caimei365.commodity.model.ResponseJson;
- import com.caimei365.commodity.model.po.ProductDetailInfoPo;
- import com.caimei365.commodity.model.po.ProductImagePo;
- import com.caimei365.commodity.model.po.ProductParameterPo;
- import com.caimei365.commodity.model.search.ProductListVo;
- import com.caimei365.commodity.model.vo.*;
- import com.caimei365.commodity.service.PageService;
- import com.caimei365.commodity.utils.AppletsLinkUtil;
- import com.caimei365.commodity.utils.ImageUtils;
- import com.caimei365.commodity.utils.MathUtil;
- import com.github.pagehelper.PageHelper;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.cache.annotation.Cacheable;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import javax.annotation.Resource;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * Description
- *
- * @author : Charles
- * @date : 2021/4/12
- */
- @Slf4j
- @Service
- public class PageServiceImpl implements PageService {
- @Value("${caimei.wwwDomain}")
- private String domain;
- @Resource
- private UserLikeMapper likeMapper;
- @Resource
- private PageMapper pageMapper;
- @Resource
- private ShopMapper shopMapper;
- @Resource
- private PriceMapper priceMapper;
- @Resource
- private PriceUtilService priceUtilService;
- @Resource
- private ProductTypeMapper productTypeMapper;
- @Resource
- private PageService pageService;
- @Resource
- private CouponMapper couponMapper;
- /**
- * 获取分类列表
- *
- * @param typeSort 分类类型:1产品,2仪器,0全部
- * @param source 请求来源:www,crm
- */
- @Override
- @Cacheable(value = "getCommodityClassify", key = "#typeSort +'-'+ #source", unless = "#result == null")
- public ResponseJson<List<BigTypeVo>> getClassify(Integer typeSort, String source) {
- List<BigTypeVo> bigTypeList = productTypeMapper.getBigTypeList(typeSort, source);
- bigTypeList.forEach(bigType -> {
- String caiMeiImage = ImageUtils.getImageURL("caiMeiImage", null, 0, domain);
- bigType.setWwwIcon(StringUtils.isEmpty(bigType.getWwwIcon()) ? caiMeiImage : bigType.getWwwIcon());
- bigType.setCrmIcon(StringUtils.isEmpty(bigType.getCrmIcon()) ? caiMeiImage : bigType.getCrmIcon());
- List<SmallTypeVo> smallTypeList = productTypeMapper.getSmallTypeList(bigType.getBigTypeId(), source);
- if (!CollectionUtils.isEmpty(smallTypeList)) {
- smallTypeList.forEach(smallType -> {
- smallType.setWwwIcon(StringUtils.isEmpty(smallType.getWwwIcon()) ? caiMeiImage : smallType.getWwwIcon());
- smallType.setCrmIcon(StringUtils.isEmpty(smallType.getCrmIcon()) ? caiMeiImage : smallType.getCrmIcon());
- List<TinyTypeVo> tinyTypeList = productTypeMapper.getTinyTypeList(smallType.getSmallTypeId(), source);
- if (!CollectionUtils.isEmpty(tinyTypeList)) {
- tinyTypeList.forEach(tinyType -> {
- tinyType.setWwwIcon(StringUtils.isEmpty(tinyType.getWwwIcon()) ? caiMeiImage : tinyType.getWwwIcon());
- tinyType.setCrmIcon(StringUtils.isEmpty(tinyType.getCrmIcon()) ? caiMeiImage : tinyType.getCrmIcon());
- });
- smallType.setTinyTypeList(tinyTypeList);
- }
- });
- bigType.setSmallTypeList(smallTypeList);
- }
- });
- return ResponseJson.success(bigTypeList);
- }
- /**
- * 产品/仪器页面数据
- *
- * @param pageId 页面信息id
- * @param userId 用户id
- * @param source 来源:1网站,2小程序
- */
- @Override
- @Cacheable(value = "insCommodityData", key = "#pageId+'-'+#userId+'-'+#source", unless = "#result == null")
- public ResponseJson<Map<String, Object>> getClassifyData(Integer pageId, Integer userId, Integer source) {
- source = source == null ? 1 : source;
- Map<String, Object> map = new HashMap<>(3);
- Integer typeSort = pageMapper.getPageTypeSort(pageId);
- List<HotSearchVo> hotSearchList = pageMapper.getHotSearchByPageId(pageId, source);
- List<PageFloorVo> floorList = pageMapper.getFloorByPageId(pageId, source);
- for (PageFloorVo floor : floorList) {
- FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(floor.getId());
- setFloorLinkType(floorContent);
- floor.setFloorContent(floorContent);
- List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(floor.getId(), source);
- setFloorImageProduct(userId, floorImageList, source);
- floor.setFloorImageList(floorImageList);
- }
- map.put("typeSort", typeSort);
- map.put("hotSearchList", hotSearchList);
- map.put("floorList", floorList);
- return ResponseJson.success(map);
- }
- /**
- * 首页楼层数据
- *
- * @param userId 用户id
- * @param source 来源:1网站,2小程序
- */
- @Cacheable(value = "getHomeCommodityData", key = "#userId +'-'+ #source", unless = "#result == null")
- @Override
- public ResponseJson<Map<String, Object>> getHomeData(Integer userId, Integer source) {
- Map<String, Object> map = new HashMap<>(2);
- //楼层管理
- source = source == null ? 1 : source;
- List<PageFloorVo> homePageFloor = pageMapper.getHomePageFloor(source);
- Iterator<PageFloorVo> floorIterator = homePageFloor.iterator();
- while (floorIterator.hasNext()) {
- PageFloorVo floor = floorIterator.next();
- FloorContentVo floorContent = pageMapper.getFloorContentById(floor.getId());
- setFloorLinkType(floorContent);
- floor.setFloorContent(floorContent);
- List<FloorImageVo> floorImageList = pageMapper.getFloorImageById(floor.getId(), source);
- if (floorImageList == null || floorImageList.size() == 0) {
- floorIterator.remove();
- continue;
- }
- setFloorImageProduct(userId, floorImageList, source);
- floor.setFloorImageList(floorImageList);
- }
- map.put("homePageFloor", homePageFloor);
- // 优质供应商
- ShopFloorVo supplierImage = pageMapper.getSupplierFloorImage();
- List<ShopImageVo> supplierList = pageMapper.getSupplierImage(source);
- supplierList.forEach(supplier -> {
- Integer linkType = AppletsLinkUtil.getLinkType(supplier.getLink());
- supplier.setLinkType(linkType);
- supplier.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, supplier.getLink()));
- });
- if (supplierImage != null) {
- supplierImage.setQualitySupplierList(supplierList);
- if (StringUtils.isNotBlank(supplierImage.getWwwLink())) {
- Integer linkType = AppletsLinkUtil.getLinkType(supplierImage.getWwwLink());
- supplierImage.setLinkType(linkType);
- supplierImage.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, supplierImage.getWwwLink()));
- }
- }
- map.put("supplierImage", supplierImage);
- return ResponseJson.success(map);
- }
- /**
- * 首页基础数据(小程序)
- *
- * @param source 来源 : 1 网站 ; 2 小程序
- */
- @Override
- public ResponseJson<Map<String, Object>> getHomeInit(Integer source) {
- Map<String, Object> map = new HashMap<>(4);
- // 搜索热门关键字
- List<String> searchHotWord = pageMapper.getSearchKeyword();
- if (!CollectionUtils.isEmpty(searchHotWord) && searchHotWord.size() > 8) {
- searchHotWord.parallelStream()
- .filter(str -> !StringUtils.isEmpty(str)).limit(8)
- .collect(Collectors.toList());
- }
- map.put("searchHotWord", searchHotWord);
- // 头部菜单
- List<TopMenuVo> menuList = pageMapper.getTopMenus(source);
- menuList.forEach(item -> {
- String link = item.getLink();
- if (StringUtils.isNotBlank(link)) {
- if (source == 1) {
- if (link.contains("?")) {
- link = link + "&name=" + item.getName();
- } else {
- link = link + "?name=" + item.getName();
- }
- }
- item.setLinkType(AppletsLinkUtil.getLinkType(link));
- item.setLinkParam(AppletsLinkUtil.getLinkParam(item.getLinkType(), link));
- item.setLink(link);
- }
- });
- map.put("topMenuList", menuList);
- // 底部帮助页
- List<BaseLinkVo> helpPages = pageMapper.getHelpPageTypes();
- helpPages.forEach(item -> {
- List<BaseLinkVo> pageList = pageMapper.getHelpPagesByType(item.getId());
- item.setLinkList(pageList);
- });
- map.put("helpPages", helpPages);
- // 友情链接
- List<BaseLinkVo> friendLinks = pageMapper.getFriendLinks();
- map.put("friendLinks", friendLinks);
- //是否显示领取优惠券入口
- List<CouponVo> couponList = couponMapper.findCouponList(null);
- if (couponList != null && couponList.size() > 0) {
- //展示
- map.put("couponEntry", 1);
- } else {
- //隐藏
- map.put("couponEntry", 2);
- }
- return ResponseJson.success(map);
- }
- /**
- * 活动专题楼层数据(美博会)
- *
- * @param pageId 页面id
- * @param userId 用户id
- * @param source 来源 : 1 网站 ; 2 小程序
- */
- @Cacheable(value = "getPageFloorData", key = "#userId +'-'+ #pageId +'-'+ #source", unless = "#result == null")
- @Override
- public ResponseJson<Map<String, Object>> getPageData(Integer pageId, Integer userId, Integer source) {
- if (pageId == null) {
- return ResponseJson.error("参数异常: 页面id不能为空!", null);
- }
- source = source == null ? 1 : source;
- // 页面数据
- CmPageVo page = pageMapper.findCmPageById(pageId);
- //轮播图设置链接类型
- if (StringUtils.isNotBlank(page.getHeadLink())) {
- Integer linkType = AppletsLinkUtil.getLinkType(page.getHeadLink());
- page.setLinkType(linkType);
- page.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, page.getHeadLink()));
- }
- List<PageFloorVo> floorList = pageMapper.getFloorByPageId(pageId, source);
- ListIterator<PageFloorVo> iterator = floorList.listIterator();
- while (iterator.hasNext()) {
- PageFloorVo floor = iterator.next();
- FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(floor.getId());
- if (null == floorContent) {
- iterator.remove();
- } else {
- setFloorLinkType(floorContent);
- List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(floor.getId(), source);
- setFloorImageProduct(userId, floorImageList, source);
- floor.setFloorImageList(floorImageList);
- String templateTypeStr = floorContent.getTemplateType();
- if (StringUtils.isNotEmpty(templateTypeStr)) {
- int templateType = Integer.parseInt(floorContent.getTemplateType());
- // 日期切换模板处理
- if (templateType == 1 || templateType == 2 || (templateType >= 7 && templateType <= 10)) {
- floorContent.setTemplateClassify(1);
- } else if (templateType >= 3 && templateType <= 6) {
- floorContent.setTemplateClassify(2);
- } else if (templateType >= 11 && templateType <= 21) {
- floorContent.setTemplateClassify(3);
- } else if (templateType >= 22 && templateType <= 25) {
- floorContent.setTemplateClassify(1);
- List<FloorImageVo> floorImageList1 = new ArrayList<>();
- List<FloorImageVo> floorImageList2 = new ArrayList<>();
- List<FloorImageVo> floorImageList3 = new ArrayList<>();
- floorImageList.forEach(image -> {
- // 根据展示日期排序分割进3个列表中
- if (1 == image.getDisplaySort()) {
- floorImageList1.add(image);
- } else if (2 == image.getDisplaySort()) {
- floorImageList2.add(image);
- } else if (3 == image.getDisplaySort()) {
- floorImageList3.add(image);
- }
- });
- floor.setFloorImageList(floorImageList1);
- floor.setFloorImageList2(floorImageList2);
- floor.setFloorImageList3(floorImageList3);
- } else if (templateType >= 26 && templateType <= 29) {
- floorContent.setTemplateClassify(4);
- }
- }
- floor.setFloorContent(floorContent);
- }
- }
- Map<String, Object> map = new HashMap<>(2);
- map.put("page", page);
- map.put("floorList", floorList);
- return ResponseJson.success(map);
- }
- /**
- * 楼层详情
- *
- * @param floorId 楼层id
- * @param userId 用户id
- * @param source 来源 : 1 网站 ; 2 小程序
- */
- @Override
- public ResponseJson<Map<String, Object>> getPageFloorData(Integer floorId, Integer userId, Integer source) {
- if (floorId == null) {
- return ResponseJson.error("参数异常: 页面id不能为空!", null);
- }
- FloorContentVo floorContent = pageMapper.getFloorContentById(floorId);
- setFloorLinkType(floorContent);
- List<FloorImageVo> floorImageList = pageMapper.getFloorImageById(floorId, source);
- setFloorImageProduct(userId, floorImageList, source);
- Map<String, Object> map = new HashMap<>(2);
- map.put("floorContent", floorContent);
- map.put("floorImageList", floorImageList);
- return ResponseJson.success(map);
- }
- /**
- * 分页详情楼层详情
- *
- * @param centreId 分页详情楼层id
- * @param userId 用户id
- * @param source 来源 : 1 网站 ; 2 小程序
- */
- @Override
- public ResponseJson<Map<String, Object>> getPageCentreData(Integer centreId, Integer userId, Integer source) {
- if (centreId == null) {
- return ResponseJson.error("参数异常: 分页详情楼层id不能为空!", null);
- }
- FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(centreId);
- setFloorLinkType(floorContent);
- String templateTypeStr = floorContent.getTemplateType();
- if (StringUtils.isNotEmpty(templateTypeStr)) {
- int templateType = Integer.parseInt(floorContent.getTemplateType());
- // 日期切换模板处理
- if (templateType == 1 || templateType == 2 || (templateType >= 7 && templateType <= 10)) {
- floorContent.setTemplateClassify(1);
- } else if (templateType >= 3 && templateType <= 6) {
- floorContent.setTemplateClassify(2);
- } else if (templateType >= 11 && templateType <= 21) {
- floorContent.setTemplateClassify(3);
- } else if (templateType >= 22 && templateType <= 25) {
- floorContent.setTemplateClassify(1);
- } else if (templateType >= 26 && templateType <= 29) {
- floorContent.setTemplateClassify(4);
- }
- }
- List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(centreId, source);
- setFloorImageProduct(userId, floorImageList, source);
- Map<String, Object> map = new HashMap<>(2);
- map.put("floorContent", floorContent);
- map.put("floorImageList", floorImageList);
- return ResponseJson.success(map);
- }
- /**
- * 商品详情页
- *
- * @param productId 商品Id
- * @param userId 用户Id
- */
- @Override
- public ResponseJson<ProductDetailVo> getProductDetails(Integer productId, Integer userId) {
- ProductDetailVo product = pageMapper.getProductDetails(productId);
- if (product == null) {
- //商品不存在
- product = new ProductDetailVo();
- product.setValidFlag(0);
- }
- boolean validFlag = 2 != product.getProductCategory() && 2 == product.getValidFlag() && (product.getStock() == null || product.getStock() == 0);
- if (validFlag) {
- //已上架但库存为0的正常商品,设置为已售罄商品
- product.setValidFlag(4);
- }
- String[] split = null;
- // 品牌名称
- String brandName = shopMapper.getBrandNameById(product.getBrandId());
- product.setBrandName(brandName);
- //商品标签
- if (product.getTags() != null) {
- String tags = product.getTags().replace(" ", ",").replace("、", ",").replace(",", ",");
- if (tags.contains(",")) {
- List<String> list = new ArrayList<String>();
- for (String s : tags.split(",")) {
- if (s != null && !"".equals(s)) {
- list.add(s);
- }
- }
- split = list.toArray(new String[list.size()]);
- }
- }
- product.setTagsList(split);
- // 主图
- product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
- // 商品图片
- List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
- for (ProductImagePo image : imageList) {
- String imageURL = ImageUtils.getImageURL("product", image.getImage(), 0, domain);
- image.setImage(imageURL);
- }
- product.setImageList(imageList);
- // 商品详情
- ProductDetailInfoPo productDetail = shopMapper.getProductDetailInfo(productId);
- product.setProductDetail(productDetail);
- // 相关参数
- List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
- product.setParametersList(parametersList);
- // 分类名称
- String typeName = shopMapper.getTypeName(product.getBigTypeId(), product.getSmallTypeId(), product.getTinyTypeId());
- product.setTypeName(typeName);
- List<String> list = StringUtils.isNotEmpty(typeName) ? Arrays.asList(typeName.split("-")) : new ArrayList<>();
- product.setBigTypeName(list.size() > 0 ? list.get(0) : null);
- product.setSmallTypeName(list.size() > 1 ? list.get(1) : null);
- product.setTinyTypeName(list.size() > 2 ? list.get(2) : null);
- //价格等级
- product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
- // 商品云上美博会活动状态
- Integer pcBeautyStatus = shopMapper.getPcBeautyStatusById(product.getProductId());
- Integer appletsBeautyStatus = shopMapper.getAppletsBeautyStatusById(product.getProductId());
- product.setPcActType(null != pcBeautyStatus ? 1 : 0);
- product.setAppletsActType(null != appletsBeautyStatus ? 1 : 0);
- //供应商信息
- ShopVo shop = shopMapper.getProductShopById(product.getShopId());
- if (null != shop) {
- Integer normalNum = shopMapper.getProductNumById(product.getShopId());
- shop.setNormalNum(null == normalNum ? 0 : normalNum);
- if (shop.getBusinessScope() != null && shop.getBusinessScope().contains("/")) {
- String[] businessScopeArray = shop.getBusinessScope().split("/");
- shop.setBusinessScopeArray(businessScopeArray);
- }
- shop.setLogo(ImageUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
- shop.setBusinessLicense(ImageUtils.getImageURL("shopLogo", shop.getBusinessLicense(), 0, domain));
- product.setShop(shop);
- }
- // 商品可见度:3:所有人可见,2:普通机构可见,1:会员机构可见
- Integer visibility = product.getVisibility();
- if (null != userId && userId > 0) {
- // 用户身份:0个人,1协销,2会员机构,3供应商,4普通机构
- Integer identity = shopMapper.getUserIdentityById(userId);
- // 协销 | 会员机构 | 综合供应商
- boolean pass1 = null != identity && (identity == 1 || identity == 2);
- // 普通机构
- boolean pass2 = null != identity && (identity == 4 && (visibility == 2 || visibility == 3));
- // 游客
- boolean pass3 = visibility == 3;
- if (!(pass1 || pass2 || pass3)) {
- return ResponseJson.success(1, "没有权限查看该商品", new ProductDetailVo());
- }
- } else if (2 == visibility || 1 == visibility) {
- return ResponseJson.success(1, "没有权限查看该商品,userId为空", new ProductDetailVo());
- }
- // 商品不处于已删除/待审核/审核未通过的状态
- if (0 != product.getValidFlag()) {
- // 数据库获取基本价格信息
- PriceVo price = priceMapper.getDetailPrice(productId);
- // 根据用户id设置详细价格
- priceUtilService.setPriceByUserId(price, userId);
- // 设置价格
- product.setActStatus(price.getActStatus());
- product.setPrice(price.getPrice());
- product.setOriginalPrice(price.getOriginalPrice());
- product.setNormalPrice(price.getNormalPrice());
- product.setLadderPriceFlag(price.getLadderPriceFlag());
- product.setPromotions(price.getPromotions());
- product.setMinBuyNumber(price.getMinBuyNumber());
- product.setUserIdentity(price.getUserIdentity());
- product.setRepurchaseFlag(price.getRepurchaseFlag());
- product.setMaxBuyNumber(price.getMaxBuyNumber());
- // 设置阶梯价格详情
- if (1 == price.getLadderPriceFlag()) {
- List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(product.getProductId());
- TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
- if (!CollectionUtils.isEmpty(ladderPrices)) {
- priceUtilService.setLadderPriceList(ladderPrices, tax);
- }
- product.setLadderPriceList(ladderPrices);
- }
- //查询商品收藏情况,1未收藏,0未收藏
- Integer like = likeMapper.findLike(userId, productId);
- product.setUserLike(like);
- }
- return ResponseJson.success(product);
- }
- /**
- * 再次购买商品列表
- *
- * @param userId 用户Id
- * @param pageNum
- * @param pageSize
- */
- @Override
- public ResponseJson<PaginationVo<ProductItemVo>> getBuyAgainProducts(Integer userId, int pageNum, int pageSize) {
- if (null == userId) {
- return ResponseJson.error("参数错误:用户Id不能为空!", null);
- }
- PageHelper.startPage(pageNum, pageSize);
- List<ProductItemVo> productList = pageMapper.getBuyAgainProducts(userId);
- productList.forEach(product -> {
- double price = product.getPrice() != null ? product.getPrice() : 0d;
- double costPrice = product.getCostPrice() != null ? product.getCostPrice() : 0d;
- double discountPrice = product.getDiscountPrice() != null ? product.getDiscountPrice() : 0d;
- Integer costFlag = product.getCostCheckFlag();
- // 成本大于等于复购价 或 复购价大于机构价
- boolean state = (costFlag == 1 && MathUtil.compare(costPrice, discountPrice) >= 0) || MathUtil.compare(discountPrice, price) > 0;
- product.setRepurchasePriceState(state);
- // 设置商品主图及价格
- priceUtilService.setProductDetails(userId, product);
- //优惠券标识
- Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), 2);
- product.setCouponsLogo(couponsLogo);
- });
- PaginationVo<ProductItemVo> pageData = new PaginationVo<>(productList);
- return ResponseJson.success(pageData);
- }
- /**
- * 项目仪器详情页
- *
- * @param equipmentId 项目仪器Id
- */
- @Override
- public ResponseJson<EquipmentVo> getEquipmentDetails(Integer equipmentId) {
- if (equipmentId == null) {
- return ResponseJson.error("参数异常:项目仪器Id不能为空!", null);
- }
- //仪器详情
- EquipmentVo equipment = pageMapper.getEquipmentById(equipmentId);
- if (null != equipment) {
- Map<String, List<EquipmentParameterVo>> pageContentMap = new HashMap<>();
- List<EquipmentParameterVo> firstFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 1);
- List<EquipmentParameterVo> secondFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 2);
- List<EquipmentParameterVo> underSecondFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 4);
- List<EquipmentParameterVo> pcDetailList = pageMapper.getEquipmentParametersByType(equipmentId, 3);
- List<EquipmentParameterVo> crmDetailList = pageMapper.getEquipmentParametersByType(equipmentId, 5);
- pageContentMap.put("firstFloorList", firstFloorList);
- pageContentMap.put("secondFloorList", secondFloorList);
- pageContentMap.put("underSecondFloorList", underSecondFloorList);
- pageContentMap.put("pcDetailList", pcDetailList);
- pageContentMap.put("crmDetailList", crmDetailList);
- equipment.setPageContentMap(pageContentMap);
- } else {
- return ResponseJson.error("该仪器不存在", null);
- }
- List<PageFloorVo> floorList = pageMapper.getFloorByPageId(equipmentId, 1);
- if (floorList.size() > 0) {
- List<PageFloorVo> tempList = new ArrayList<>();
- floorList.forEach(floor -> {
- List<ImageLinkVo> imageLinks = pageMapper.getImageLinkByFloorId(floor.getId());
- //设置链接类型及参数
- if (StringUtils.isNotEmpty(floor.getLink())) {
- floor.setLinkType(AppletsLinkUtil.getLinkType(floor.getLink()));
- floor.setLinkParam(AppletsLinkUtil.getLinkParam(floor.getLinkType(), floor.getLink()));
- }
- if (imageLinks.size() > 0) {
- imageLinks.forEach(img -> {
- img.setImage(ImageUtils.getImageURL("actType", img.getImage(), 0, domain));
- //设置链接类型及参数
- if (StringUtils.isNotEmpty(img.getLink())) {
- img.setLinkType(AppletsLinkUtil.getLinkType(img.getLink()));
- img.setLinkParam(AppletsLinkUtil.getLinkParam(img.getLinkType(), img.getLink()));
- }
- });
- floor.setFloorData(imageLinks);
- } else {
- tempList.add(floor);
- }
- });
- if (tempList.size() > 0) {
- floorList.removeAll(tempList);
- }
- }
- equipment.setFloorList(floorList);
- return ResponseJson.success(equipment);
- }
- /**
- * 商品详情页-图片
- *
- * @param productId 商品Id
- */
- @Override
- public ResponseJson<List<String>> getProductDetailImages(Integer productId) {
- if (productId == null) {
- return ResponseJson.error("参数错误:商品Id不能为空!", null);
- }
- List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
- List<String> newList = new ArrayList<>();
- if (imageList.size() > 0) {
- // 设置老图片路径
- imageList.forEach(image -> {
- newList.add(ImageUtils.getImageURL("product", image.getImage(), 0, domain));
- });
- }
- return ResponseJson.success(newList);
- }
- /**
- * 商品详情页-相关参数
- *
- * @param productId 商品Id
- */
- @Override
- public ResponseJson<List<ProductParameterPo>> getProductParameters(Integer productId) {
- if (productId == null) {
- return ResponseJson.error("参数错误:商品Id不能为空!", null);
- }
- List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
- return ResponseJson.success(parametersList);
- }
- /**
- * 商品详情页-相关推荐
- *
- * @param productId 商品Id
- * @param recommendType 相关推荐类型: 0自动选择, 1手动推荐
- * @param userId 用户Id
- */
- @Override
- public ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId) {
- if (null == productId) {
- return ResponseJson.error("商品Id不能为空!", null);
- }
- // 根据用户Id查询用户身份
- Integer identity = 0;
- if (null != userId && userId > 0) {
- identity = priceMapper.getIdentityByUserId(userId);
- if (null == identity) {
- identity = 0;
- }
- }
- List<ProductListVo> list = null;
- //相关推荐类型 0自动选择(默认); 1手动推荐
- if (null == recommendType || 1 != recommendType) {
- list = pageMapper.getAutoProductRecommends(productId);
- } else {
- list = pageMapper.getProductRecommendsById(productId);
- }
- if (null != list && list.size() > 0) {
- // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
- // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
- // boolean passFlag = identity ==1 || identity == 2 || product.getVisibility()==3 || (identity == 4 && product.getVisibility()==2);
- try {
- Integer finalIdentity = identity;
- list.removeIf(product -> (null == product || null == product.getVisibility() || !(finalIdentity == 1 || finalIdentity == 2 || product.getVisibility() == 3 || (finalIdentity == 4 && product.getVisibility() == 2))));
- list.forEach(product -> {
- // 设置 图片路径
- product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
- });
- } catch (Exception e) {
- log.error("相关推荐", e);
- }
- }
- return ResponseJson.success(list);
- }
- /**
- * 商品维修(链接分享数据)
- *
- * @param code 维修code
- */
- @Override
- public ResponseJson<ProductRepairVo> getProductRepair(String code) {
- if (StringUtils.isEmpty(code)) {
- return ResponseJson.error("维修code不能为空!", null);
- }
- ProductRepairVo repair = null;
- // 仪器维修表ID
- Integer maintenanceId = pageMapper.getMaintenanceIdByCode(code);
- if (null != maintenanceId) {
- // 维修详情
- repair = pageMapper.getMaintenanceById(maintenanceId);
- }
- if (null == repair) {
- return ResponseJson.error("无效的链接!", null);
- }
- List<String> imageList = new ArrayList<>();
- if (StringUtils.isNotEmpty(repair.getInstrumentImage1())) {
- imageList.add(repair.getInstrumentImage1());
- }
- if (StringUtils.isNotEmpty(repair.getInstrumentImage2())) {
- imageList.add(repair.getInstrumentImage2());
- }
- if (StringUtils.isNotEmpty(repair.getInstrumentImage3())) {
- imageList.add(repair.getInstrumentImage3());
- }
- if (StringUtils.isNotEmpty(repair.getInstrumentImage4())) {
- imageList.add(repair.getInstrumentImage4());
- }
- if (StringUtils.isNotEmpty(repair.getInstrumentImage5())) {
- imageList.add(repair.getInstrumentImage5());
- }
- String[] images = imageList.toArray(new String[imageList.size()]);
- repair.setInstrumentArr(images);
- String viewerType = repair.getViewerType();
- if ("1".equals(viewerType)) {
- // 用户可评价展示详细信息
- repair.setCanEvaluation(true);
- repair.setOnlyBaseInfo(false);
- } else if ("3".equals(viewerType)) {
- // 供应商不可评价展示详细信息
- repair.setCanEvaluation(false);
- repair.setOnlyBaseInfo(false);
- } else {
- // 供应商不可评价展示基础信息
- ProductRepairVo repairTemp = new ProductRepairVo();
- repairTemp.setCanEvaluation(false);
- repairTemp.setOnlyBaseInfo(true);
- repairTemp.setViewerType("2");
- repairTemp.setUserAddress(repair.getUserAddress());
- repairTemp.setInstrumentName(repair.getInstrumentName());
- repairTemp.setManufacturer(repair.getManufacturer());
- repairTemp.setInstrumentBrand(repair.getInstrumentBrand());
- repairTemp.setProblemDescription(repair.getProblemDescription());
- return ResponseJson.success(repairTemp);
- }
- return ResponseJson.success(repair);
- }
- /**
- * 设置跳转参数
- *
- * @param floorContent FloorContentVo
- */
- private void setFloorLinkType(FloorContentVo floorContent) {
- if (floorContent != null) {
- if (StringUtils.isNotBlank(floorContent.getAdsLink1())) {
- Integer linkType1 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink1());
- floorContent.setLinkType1(linkType1);
- floorContent.setLinkParam1(AppletsLinkUtil.getLinkParam(linkType1, floorContent.getAdsLink1()));
- }
- if (StringUtils.isNotBlank(floorContent.getAdsLink2())) {
- Integer linkType2 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink2());
- floorContent.setLinkType2(linkType2);
- floorContent.setLinkParam2(AppletsLinkUtil.getLinkParam(linkType2, floorContent.getAdsLink2()));
- }
- if (StringUtils.isNotBlank(floorContent.getAdsLink3())) {
- Integer linkType3 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink3());
- floorContent.setLinkType3(linkType3);
- floorContent.setLinkParam3(AppletsLinkUtil.getLinkParam(linkType3, floorContent.getAdsLink3()));
- }
- if (StringUtils.isNotBlank(floorContent.getAdsLink4())) {
- Integer linkType4 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink4());
- floorContent.setLinkType4(linkType4);
- floorContent.setLinkParam4(AppletsLinkUtil.getLinkParam(linkType4, floorContent.getAdsLink4()));
- }
- if (StringUtils.isNotBlank(floorContent.getAdsLink5())) {
- Integer linkType3 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink3());
- floorContent.setLinkType3(linkType3);
- floorContent.setLinkParam3(AppletsLinkUtil.getLinkParam(linkType3, floorContent.getAdsLink3()));
- }
- }
- }
- /**
- * 设置楼层相关图片的商品信息
- */
- private void setFloorImageProduct(Integer userId, List<FloorImageVo> floorImageList, Integer source) {
- Iterator<FloorImageVo> iterator = floorImageList.iterator();
- while (iterator.hasNext()) {
- FloorImageVo image = iterator.next();
- Integer linkType = AppletsLinkUtil.getLinkType(image.getLink());
- Map<String, Object> linkParam = AppletsLinkUtil.getLinkParam(linkType, image.getLink());
- image.setLinkType(linkType);
- image.setLinkParam(linkParam);
- if (image.getProductId() != null) {
- // 获取商品及价格
- ProductItemVo product = pageMapper.getProductItemById(image.getProductId());
- if (product != null) {
- // 商品价格
- priceUtilService.setProductDetails(userId, product);
- // 设置商品主图
- image.setListType(1);
- image.setName(product.getName());
- image.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
- image.setProduct(product);
- if (userId != null) {
- if (product.getUserIdentity() > 0) {
- if (4 == product.getUserIdentity() && "1".equals(product.getVisibility())) {
- iterator.remove();
- }
- } else {
- if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
- iterator.remove();
- }
- }
- } else {
- if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
- iterator.remove();
- }
- }
- //优惠券标识
- Boolean couponsLogo = setCouponsLogo(userId, image.getProductId(), source);
- product.setCouponsLogo(couponsLogo);
- } else {
- iterator.remove();
- }
- } else {
- image.setListType(2);
- }
- }
- }
- /**
- * 优惠券标识是否显示
- *
- * @param userId 机构用户id
- * @param productId 商品id
- * @param source 来源 : 1 网站 ; 2 小程序
- * @return
- */
- @Override
- public Boolean setCouponsLogo(Integer userId, Integer productId, Integer source) {
- boolean couponsLogo = false;
- ProductDetailVo product = pageMapper.getProductDetails(productId);
- List<CouponVo> couponList = pageMapper.findAllCoupon(userId);
- if (couponList != null && couponList.size() > 0) {
- for (CouponVo coupon : couponList) {
- if (coupon.getCouponType() == 4 || coupon.getCouponType() == 2) {
- //用户券与用户专享券
- couponsLogo = true;
- break;
- }
- if (coupon.getCouponType() == 0) {
- if (coupon.getProductType() == 1) {
- //活动券-全商城商品
- couponsLogo = true;
- break;
- } else {
- //活动券-指定商品
- List<Integer> productIds = pageMapper.findAllProductId(coupon.getCouponId(), source);
- if (productIds.contains(productId)) {
- couponsLogo = true;
- break;
- }
- }
- }
- if (coupon.getCouponType() == 3 && product.getShopId().equals(coupon.getShopId())) {
- //店铺券
- couponsLogo = true;
- break;
- }
- if (coupon.getCouponType() == 1 && coupon.getCategoryType().equals(product.getCommodityType())) {
- //品类券
- couponsLogo = true;
- break;
- }
- }
- }
- return couponsLogo;
- }
- }
|