12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019 |
- package com.caimei365.commodity.service.impl;
- import com.aliyun.oss.OSS;
- import com.aliyun.oss.OSSClientBuilder;
- import com.caimei365.commodity.components.PriceUtilService;
- import com.caimei365.commodity.mapper.*;
- import com.caimei365.commodity.model.ResponseJson;
- import com.caimei365.commodity.model.po.*;
- 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.text.ParseException;
- import java.text.SimpleDateFormat;
- 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;
- @Value("${spring.cloud.config.profile}")
- private String active;
- private String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
- private String accessKeyId = "LTAI4GBL3o4YkWnbKYgf2Xia";
- private String accessKeySecret = "dBjAXqbYiEPP6Ukuk2ZsXQeET7FVkK";
- private String bucketName = "caimei-oss";
- /**
- * 获取分类列表
- *
- * @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);
- // 商品资料id
- Integer archiveId = pageMapper.getArchiveIdById(product.getProductId());
- product.setArchiveId(null != archiveId ? archiveId : 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未收藏,未收藏过该商品用户是null
- 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;
- }
- /**
- * 商品资料列表
- * @param keyword 搜索关键词
- * @param productType 商品属性:1产品,2仪器
- * @param pageNum 页码
- * @param pageSize 每页数量
- * @return
- */
- @Override
- public ResponseJson<PaginationVo<ArchiveVo>> getProductArchive(String keyword, Integer productType, Integer pageNum, Integer pageSize) {
- PageHelper.startPage(pageNum, pageSize);
- List<ArchiveVo> archiveList = pageMapper.getProductArchiveList(keyword, productType);
- archiveList.forEach(archive->{
- if (null != archive.getProductId()) {
- String imageURL = ImageUtils.getImageURL("product", archive.getProductImage(), 0, domain);
- archive.setProductImage(imageURL);
- }
- });
- PaginationVo<ArchiveVo> pageData = new PaginationVo<>(archiveList);
- return ResponseJson.success(pageData);
- }
- /**
- * 商品资料内容
- * @param archiveId 商品资料id
- * @param userId 用户id
- * @return
- */
- @Override
- public ResponseJson<ArchiveDetailVo> getArchiveDetail(Integer archiveId, Integer userId) {
- ArchivePo archive = pageMapper.getArchiveByArchiveId(archiveId);
- if (null == archive) {
- return ResponseJson.error("商品资料不存在", null);
- }
- // 判断该用户是否拥有访问该资料的权限
- int permission = checkArchivePermission(archive, userId);
- List<ArchiveContentVo> imageArchiveList = pageMapper.getImageArchiveList(archiveId);
- List<ArchiveContentVo> videoArchiveList = pageMapper.getVideoArchiveList(archiveId);
- List<ArchiveContentVo> fileArchiveList = pageMapper.getFileArchiveList(archiveId);
- if (imageArchiveList.size() == 0 && videoArchiveList.size() == 0 && fileArchiveList.size() == 0) {
- // 没有文件的时候,用户可查看资料
- permission = 0;
- }
- int finalPermission = permission;
- imageArchiveList.forEach(imageArchive->{
- List<String> imageList = pageMapper.getArchiveImageList(imageArchive.getArchiveContentId());
- if (0 == finalPermission) {
- imageArchive.setImageList(imageList);
- }
- imageArchive.setImageNum(imageList.size());
- });
- videoArchiveList.forEach(videoArchive->{
- ArchiveFilePo archiveFile = pageMapper.getArchiveFile(videoArchive.getArchiveContentId());
- if (0 == finalPermission) {
- String fileUrl = generateFileUrl(archiveFile);
- videoArchive.setFileUrl(fileUrl);
- }
- });
- fileArchiveList.forEach(fileArchive->{
- ArchiveFilePo archiveFile = pageMapper.getArchiveFile(fileArchive.getArchiveContentId());
- fileArchive.setFileName(archiveFile.getFileName());
- if (0 == finalPermission) {
- String fileUrl = generateFileUrl(archiveFile);
- fileArchive.setFileUrl(fileUrl);
- }
- });
- ArchiveDetailVo archiveDetail = new ArchiveDetailVo();
- archiveDetail.setImageArchiveList(imageArchiveList);
- archiveDetail.setVideoArchiveList(videoArchiveList);
- archiveDetail.setFileArchiveList(fileArchiveList);
- archiveDetail.setPermission(permission);
- archiveDetail.setProductImage(archive.getProductImage());
- archiveDetail.setProductName(archive.getProductName());
- archiveDetail.setProductType(archive.getProductType());
- archiveDetail.setShopName(archive.getShopName());
- return ResponseJson.success(archiveDetail);
- }
- private Integer checkArchivePermission(ArchivePo archive, Integer userId) {
- //资料等级:1一类资料,2二类资料,3三类资料
- Integer archiveLevel = archive.getArchiveLevel();
- //商品分类:1医美,2生美
- Integer productClassify = archive.getProductClassify();
- // 根据用户Id查询用户身份
- Integer identity = priceMapper.getIdentityByUserId(userId);
- // 1生美机构,2医美机构
- Integer clubType = pageMapper.getClubTypeByUserId(userId);
- // permission:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
- int permission;
- if (null == identity) {
- // 未登录
- permission = 1;
- } else if (1 == identity) {
- //协销可查看所有资料
- permission = 0;
- } else if (4 == identity) {
- // 普通机构
- if (archiveLevel > 1) {
- // 二级资料,普通机构
- permission = 2 == productClassify ? 2 : 3;
- } else {
- permission = 0;
- }
- } else if (2 == identity) {
- // 会员机构
- if (2 == archiveLevel && 1 == productClassify && (0 == clubType || 2 == clubType)) {
- // 二级医美资料,生美会员机构
- permission = 3;
- } else if (3 == archiveLevel) {
- // 查询用户对该资料的抵扣记录
- Integer historyId = pageMapper.findBeansHistoryByArchiveId(userId, archive.getArchiveId());
- if (1 == productClassify && (0 == clubType || 2 == clubType)) {
- // 三级医美资料,生美会员机构
- permission = 3;
- } else if (null == historyId){
- permission = 4;
- } else {
- permission = 0;
- }
- } else {
- permission = 0;
- }
- } else{
- permission = 5;
- }
- return permission;
- }
- public String generateFileUrl(ArchiveFilePo archiveFile) {
- OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
- String ossName = archiveFile.getOssName();
- // 设置URL过期时间为1个小时
- Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000);
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- Date dateOne = format.parse("2021-06-01 00:00:00");
- Date dateTwo = format.parse("2021-09-17 18:00:00");
- if (archiveFile.getUploadTime() != null && archiveFile.getUploadTime().compareTo(dateOne) > 0 && archiveFile.getUploadTime().compareTo(dateTwo) < 0) {
- ossName = active + "/" + ossName;
- } else if (archiveFile.getUploadTime() != null && archiveFile.getUploadTime().compareTo(dateTwo)>0){
- ossName = active + "/archiveFile/" + ossName;
- }
- } catch (ParseException e) {
- log.info("格式化时间错误", e);
- }
- String url = ossClient.generatePresignedUrl(bucketName, ossName, expiration).toString();
- ossClient.shutdown();
- return url;
- }
- }
|