Просмотр исходного кода

增加通过父类目id获取子类目信息

wangyc 7 лет назад
Родитель
Сommit
0738f0918c

+ 14 - 0
src/main/java/com/uas/platform/b2c/prod/product/kind/controller/KindController.java

@@ -1,10 +1,12 @@
 package com.uas.platform.b2c.prod.product.kind.controller;
 
 import com.uas.platform.b2c.prod.product.kind.model.Kind;
+import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
 import com.uas.platform.b2c.prod.product.kind.model.KindProperty;
 import com.uas.platform.b2c.prod.product.kind.service.KindService;
 import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
+import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.wordnik.swagger.annotations.ApiOperation;
 import com.wordnik.swagger.annotations.ApiParam;
@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.servlet.ModelAndView;
@@ -222,4 +225,15 @@ public class KindController {
 	public ModelAndView downloadKindProperties(@PathVariable("kindid") Long kindId) {
 		return kindService.downloadKindProperties(kindId);
 	}
+
+	/**
+	 * 通过父类目id获取类目信息
+	 * @param parentId 父类目id
+	 * @return
+	 */
+	@RequestMapping(value = "/parentid", method = RequestMethod.GET)
+	public ResultMap getKindsByLevelAndParentId(@RequestParam(value = "parentid", defaultValue = "0") Long parentId) {
+		List<KindInfo> kindInfos = kindService.findByParentId(parentId);
+		return ResultMap.success(kindInfos);
+	}
 }

+ 8 - 2
src/main/java/com/uas/platform/b2c/prod/product/kind/service/KindService.java

@@ -6,11 +6,10 @@ import com.uas.platform.b2c.prod.product.kind.model.Kind;
 import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
 import com.uas.platform.b2c.prod.product.kind.model.KindProperty;
 import com.uas.platform.b2c.prod.product.property.model.Property;
-import org.springframework.web.servlet.ModelAndView;
-
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.springframework.web.servlet.ModelAndView;
 
 public interface KindService {
 	/**
@@ -348,4 +347,11 @@ public interface KindService {
 	 * @return kindids
 	 */
 	public Set<Long> findByEnUU(Long enUU);
+
+	/**
+	 * 通过父类目id获取类目信息
+	 * @param parentId 父类目id
+	 * @return
+	 */
+	List<KindInfo> findByParentId(Long parentId);
 }

+ 16 - 0
src/main/java/com/uas/platform/b2c/prod/product/kind/service/impl/KindServiceImpl.java

@@ -1354,4 +1354,20 @@ public class KindServiceImpl implements KindService {
 	public Set<Long> findByEnUU(Long enUU) {
 		return pcbDao.findByEnUU(enUU);
 	}
+
+	@Override
+	public List<KindInfo> findByParentId(Long parentId) {
+		List<KindInfo> kindInfos = new ArrayList<>();
+		if (parentId == 0L) {
+			kindInfos = kindInfoDao.findByParentid(parentId);
+		} else {
+			KindInfo parentKind = kindInfoDao.findOne(parentId);
+			if (parentKind == null || parentKind.getIsLeaf().equals(0)) {
+				throw new IllegalOperatorException("此类目不存在或无下级类目");
+			} else {
+				kindInfos = kindInfoDao.findByParentid(parentId);
+			}
+		}
+		return kindInfos;
+	}
 }