|
@@ -0,0 +1,164 @@
|
|
|
+package com.caimei365.commodity.service.impl;
|
|
|
+
|
|
|
+import com.caimei365.commodity.mapper.ProductMapper;
|
|
|
+import com.caimei365.commodity.model.ResponseJson;
|
|
|
+import com.caimei365.commodity.model.vo.*;
|
|
|
+import com.caimei365.commodity.service.ProductService;
|
|
|
+import com.caimei365.commodity.utils.AppletsLinkUtil;
|
|
|
+import com.caimei365.commodity.utils.ImageUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2021/4/12
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ProductServiceImpl implements ProductService {
|
|
|
+ @Value("${caimei.wwwDomain}")
|
|
|
+ private String domain;
|
|
|
+ @Resource
|
|
|
+ private ProductMapper productMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分类列表
|
|
|
+ *
|
|
|
+ * @param typeSort 分类类型:1产品,2仪器
|
|
|
+ * @param source 请求来源:www,crm
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<BigTypeVo>> getClassify(String typeSort, String source) {
|
|
|
+ List<BigTypeVo> bigTypeList = productMapper.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 = productMapper.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 = productMapper.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
|
|
|
+ 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 = productMapper.getPageTypeSort(pageId);
|
|
|
+ List<HotSearchVo> hotSearchList = productMapper.getHotSearchByPageId(pageId, source);
|
|
|
+ List<PageFloorVo> floorList = productMapper.getFloorByPageId(pageId, source);
|
|
|
+ for (PageFloorVo floor : floorList) {
|
|
|
+ FloorContentVo floorContent = productMapper.getFloorContentById(floor.getId());
|
|
|
+ setFloorLinkType(floorContent);
|
|
|
+ floor.setFloorContent(floorContent);
|
|
|
+ List<FloorImageVo> floorImageList = productMapper.getFloorImageById(floor.getId(), source);
|
|
|
+ setFloorImageProduct(userId, floorImageList);
|
|
|
+ floor.setFloorImageList(floorImageList);
|
|
|
+ }
|
|
|
+ map.put("typeSort", typeSort);
|
|
|
+ map.put("hotSearchList", hotSearchList);
|
|
|
+ map.put("floorList", floorList);
|
|
|
+ return ResponseJson.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置跳转参数
|
|
|
+ * @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()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置楼层相关图片的商品信息
|
|
|
+ */
|
|
|
+ private void setFloorImageProduct(Integer userId, List<FloorImageVo> floorImageList) {
|
|
|
+ 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 = homePageDao.findProduct(image.getProductId());
|
|
|
+// if (product != null) {
|
|
|
+// image.setName(product.getName());
|
|
|
+// image.setImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
|
|
|
+// // 设置价格等级
|
|
|
+// product.setPrice1Grade(ProductUtils.getPriceGrade(product.getPrice1()));
|
|
|
+// image.setListType(1);
|
|
|
+// repeatPurchaseService.setProductPrice(product, userId);
|
|
|
+// image.setProduct(product);
|
|
|
+// if (userId != null) {
|
|
|
+// UserVo user = loginDao.findUser(userId);
|
|
|
+// if (user != null) {
|
|
|
+// product.setUserIdentity(user.getUserIdentity());
|
|
|
+// if (4 == user.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();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ image.setListType(2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|