|
@@ -1,18 +1,29 @@
|
|
package com.txz.mall.service.impl;
|
|
package com.txz.mall.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.txz.mall.constants.Constants;
|
|
import com.txz.mall.core.AbstractService;
|
|
import com.txz.mall.core.AbstractService;
|
|
import com.txz.mall.core.ServiceException;
|
|
import com.txz.mall.core.ServiceException;
|
|
import com.txz.mall.dao.StoreProductMapper;
|
|
import com.txz.mall.dao.StoreProductMapper;
|
|
|
|
+import com.txz.mall.model.ProductAttr;
|
|
|
|
+import com.txz.mall.model.ProductAttrValue;
|
|
import com.txz.mall.model.StoreProduct;
|
|
import com.txz.mall.model.StoreProduct;
|
|
|
|
+import com.txz.mall.service.ProductAttrService;
|
|
|
|
+import com.txz.mall.service.ProductAttrValueService;
|
|
import com.txz.mall.service.StoreProductService;
|
|
import com.txz.mall.service.StoreProductService;
|
|
import com.txz.mall.util.EasyExcelUtil;
|
|
import com.txz.mall.util.EasyExcelUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+import vo.AttrValueVO;
|
|
|
|
+import vo.StoreProductInfoVO;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -20,6 +31,7 @@ import java.io.OutputStream;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -31,6 +43,11 @@ import java.util.List;
|
|
public class StoreProductServiceImpl extends AbstractService<StoreProduct> implements StoreProductService {
|
|
public class StoreProductServiceImpl extends AbstractService<StoreProduct> implements StoreProductService {
|
|
@Resource
|
|
@Resource
|
|
private StoreProductMapper storeProductMapper;
|
|
private StoreProductMapper storeProductMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductAttrService attrService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductAttrValueService attrValueService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void importFile(MultipartFile file) {
|
|
public void importFile(MultipartFile file) {
|
|
@@ -68,4 +85,76 @@ public class StoreProductServiceImpl extends AbstractService<StoreProduct> imple
|
|
throw new ServiceException("模板下载失败, 请联系管理员");
|
|
throw new ServiceException("模板下载失败, 请联系管理员");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public StoreProductInfoVO getInfo(Integer id) {
|
|
|
|
+ StoreProduct storeProduct = findById(id);
|
|
|
|
+ if (ObjectUtil.isNull(storeProduct)) {
|
|
|
|
+ throw new ServiceException("未找到对应商品信息");
|
|
|
|
+ }
|
|
|
|
+ StoreProductInfoVO storeProductResponse = new StoreProductInfoVO();
|
|
|
|
+ BeanUtils.copyProperties(storeProduct, storeProductResponse);
|
|
|
|
+
|
|
|
|
+ // 设置商品所参与的活动
|
|
|
|
+ List<String> activityList = getProductActivityList(storeProduct.getActivity());
|
|
|
|
+ storeProductResponse.setActivity(activityList);
|
|
|
|
+
|
|
|
|
+ List<ProductAttr> attrList = attrService.getListByProductIdAndType(storeProduct.getId(), Constants.PRODUCT_TYPE_NORMAL);
|
|
|
|
+ storeProductResponse.setAttr(attrList);
|
|
|
|
+
|
|
|
|
+ List<ProductAttrValue> attrValueList = attrValueService.getListByProductIdAndType(storeProduct.getId(), Constants.PRODUCT_TYPE_NORMAL);
|
|
|
|
+ List<AttrValueVO> valueResponseList = attrValueList.stream().map(e -> {
|
|
|
|
+ AttrValueVO valueResponse = new AttrValueVO();
|
|
|
|
+ BeanUtils.copyProperties(e, valueResponse);
|
|
|
|
+ return valueResponse;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ storeProductResponse.setAttrValue(valueResponseList);
|
|
|
|
+
|
|
|
|
+// StoreProductDescription sd = storeProductDescriptionService.getByProductIdAndType(storeProduct.getId(), Constants.PRODUCT_TYPE_NORMAL);
|
|
|
|
+// if (ObjectUtil.isNotNull(sd)) {
|
|
|
|
+// storeProductResponse.setContent(ObjectUtil.isNull(sd.getDescription()) ? "" : sd.getDescription());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// // 获取已关联的优惠券
|
|
|
|
+// List<StoreProductCoupon> storeProductCoupons = storeProductCouponService.getListByProductId(storeProduct.getId());
|
|
|
|
+// if (CollUtil.isNotEmpty(storeProductCoupons)) {
|
|
|
|
+// List<Integer> ids = storeProductCoupons.stream().map(StoreProductCoupon::getIssueCouponId).collect(Collectors.toList());
|
|
|
|
+// storeProductResponse.setCouponIds(ids);
|
|
|
|
+// }
|
|
|
|
+ return storeProductResponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 商品活动字符列表
|
|
|
|
+ *
|
|
|
|
+ * @param activityStr 商品活动字符串
|
|
|
|
+ * @return 商品活动字符列表
|
|
|
|
+ */
|
|
|
|
+ private List<String> getProductActivityList(String activityStr) {
|
|
|
|
+ List<String> activityList = CollUtil.newArrayList();
|
|
|
|
+ if ("0, 1, 2, 3".equals(activityStr)) {
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_NORMAL_STR);
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_SECKILL_STR);
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_BARGAIN_STR);
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_PINGTUAN_STR);
|
|
|
|
+ return activityList;
|
|
|
|
+ }
|
|
|
|
+ String[] split = activityStr.split(",");
|
|
|
|
+ for (String s : split) {
|
|
|
|
+ Integer integer = Integer.valueOf(s);
|
|
|
|
+ if (integer.equals(Constants.PRODUCT_TYPE_NORMAL)) {
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_NORMAL_STR);
|
|
|
|
+ }
|
|
|
|
+ if (integer.equals(Constants.PRODUCT_TYPE_SECKILL)) {
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_SECKILL_STR);
|
|
|
|
+ }
|
|
|
|
+ if (integer.equals(Constants.PRODUCT_TYPE_BARGAIN)) {
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_BARGAIN_STR);
|
|
|
|
+ }
|
|
|
|
+ if (integer.equals(Constants.PRODUCT_TYPE_PINGTUAN)) {
|
|
|
|
+ activityList.add(Constants.PRODUCT_TYPE_PINGTUAN_STR);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return activityList;
|
|
|
|
+ }
|
|
}
|
|
}
|