|
@@ -0,0 +1,112 @@
|
|
|
+package com.caimei365.commodity.service.impl;
|
|
|
+
|
|
|
+import com.caimei365.commodity.mapper.ProductTypeMapper;
|
|
|
+import com.caimei365.commodity.model.ResponseJson;
|
|
|
+import com.caimei365.commodity.model.vo.BigTypeVo;
|
|
|
+import com.caimei365.commodity.model.vo.SmallTypeVo;
|
|
|
+import com.caimei365.commodity.model.vo.TinyTypeVo;
|
|
|
+import com.caimei365.commodity.service.ProductTypeService;
|
|
|
+import com.caimei365.commodity.utils.ImageUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Charles
|
|
|
+ * @date : 2021/4/22
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ProductTypeServiceImpl implements ProductTypeService {
|
|
|
+ @Value("${caimei.wwwDomain}")
|
|
|
+ private String domain;
|
|
|
+ @Resource
|
|
|
+ private ProductTypeMapper productTypeMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据商品属性获取一级分类下拉
|
|
|
+ *
|
|
|
+ * @param typeSort 分类类型,1产品,2仪器
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<BigTypeVo>> getBigTypeSelect(Integer typeSort) {
|
|
|
+ List<BigTypeVo> bigTypeList = productTypeMapper.getBigTypeList(typeSort,"www");
|
|
|
+ return ResponseJson.success(bigTypeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取二级分类下拉列表
|
|
|
+ *
|
|
|
+ * @param bigTypeId 一级分类Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<SmallTypeVo>> getSmallTypeSelect(Integer bigTypeId) {
|
|
|
+ List<SmallTypeVo> smallTypeList = productTypeMapper.getSmallTypeList(bigTypeId, "www");
|
|
|
+ return ResponseJson.success(smallTypeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取三级分类下拉列表
|
|
|
+ *
|
|
|
+ * @param smallTypeId 二级分类Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<List<TinyTypeVo>> getTinyTypeSelect(Integer smallTypeId) {
|
|
|
+ List<TinyTypeVo> tinyTypeList = productTypeMapper.getTinyTypeList(smallTypeId, "www");
|
|
|
+ return ResponseJson.success(tinyTypeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据Id获取分类(小程序)
|
|
|
+ *
|
|
|
+ * @param typeId 分类Id
|
|
|
+ * @param idType typeId类型:1:bigType,2:smallType,3:tinyType
|
|
|
+ * @param source 请求来源:www,crm
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<BigTypeVo> getTypeById(Integer typeId, Integer idType, String source) {
|
|
|
+ if (typeId == null || typeId == 0) {
|
|
|
+ return ResponseJson.error("请输入分类Id", null);
|
|
|
+ }
|
|
|
+ if (idType == null || idType == 0) {
|
|
|
+ return ResponseJson.error("请输入分类Id类型", null);
|
|
|
+ }
|
|
|
+ Integer bigTypeId = 0;
|
|
|
+ if (idType == 1) {
|
|
|
+ bigTypeId = typeId;
|
|
|
+ } else if (idType == 2 ) {
|
|
|
+ bigTypeId = productTypeMapper.getBigTypeIdBySmallTypeId(typeId);
|
|
|
+ } else if (idType == 3 ) {
|
|
|
+ bigTypeId = productTypeMapper.getBigTypeIdByTinyTypeId(typeId);
|
|
|
+ }
|
|
|
+ BigTypeVo bigType = productTypeMapper.getBigTypeBId(bigTypeId);
|
|
|
+ bigType.setIsChecked(false);
|
|
|
+ String caiMeiImage = ImageUtils.getImageURL("caiMeiImage", null, 0, domain);
|
|
|
+ bigType.setWwwIcon(org.apache.commons.lang.StringUtils.isEmpty(bigType.getWwwIcon())?caiMeiImage:bigType.getWwwIcon());
|
|
|
+ bigType.setCrmIcon(org.apache.commons.lang.StringUtils.isEmpty(bigType.getCrmIcon())?caiMeiImage:bigType.getCrmIcon());
|
|
|
+ List<SmallTypeVo> smallTypeList = productTypeMapper.getSmallTypeList(bigType.getBigTypeId(), source);
|
|
|
+ if (!CollectionUtils.isEmpty(smallTypeList)) {
|
|
|
+ smallTypeList.forEach(smallType -> {
|
|
|
+ smallType.setWwwIcon(org.apache.commons.lang.StringUtils.isEmpty(smallType.getWwwIcon())?caiMeiImage:smallType.getWwwIcon());
|
|
|
+ smallType.setCrmIcon(org.apache.commons.lang.StringUtils.isEmpty(smallType.getCrmIcon())?caiMeiImage:smallType.getCrmIcon());
|
|
|
+ List<TinyTypeVo> tinyTypeList = productTypeMapper.getTinyTypeList(smallType.getSmallTypeId(), source);
|
|
|
+ if (!CollectionUtils.isEmpty(tinyTypeList)) {
|
|
|
+ tinyTypeList.forEach(tinyType -> {
|
|
|
+ tinyType.setWwwIcon(org.apache.commons.lang.StringUtils.isEmpty(tinyType.getWwwIcon())?caiMeiImage:tinyType.getWwwIcon());
|
|
|
+ tinyType.setCrmIcon(org.apache.commons.lang.StringUtils.isEmpty(tinyType.getCrmIcon())?caiMeiImage:tinyType.getCrmIcon());
|
|
|
+ });
|
|
|
+ smallType.setTinyTypeList(tinyTypeList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ bigType.setSmallTypeList(smallTypeList);
|
|
|
+ }
|
|
|
+ return ResponseJson.success(bigType);
|
|
|
+ }
|
|
|
+}
|