package com.matrix.system.shopXcx.api.action;
|
|
import com.matrix.core.pojo.AjaxResult;
|
import com.matrix.core.tools.StringUtils;
|
import com.matrix.system.common.interceptor.HostInterceptor;
|
import com.matrix.system.shopXcx.bean.ShopProductAttribute;
|
import com.matrix.system.shopXcx.dao.ShopProductAttributeDao;
|
import org.apache.ibatis.annotations.Param;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* @description 属性频道表
|
* @author pengliang
|
* @date 2019-06-05 19:00
|
*/
|
|
|
@Controller
|
@RequestMapping(value="/wxapi/ProductAttribute")
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
public class WxProductAttributeAction {
|
|
@Autowired
|
private ShopProductAttributeDao shopProductAttributeDao;
|
|
@RequestMapping("/getByCode/{attrCode}")
|
@ResponseBody
|
public AjaxResult getProductAttributeByCode(@PathVariable("attrCode") String attrCode){
|
|
if(!StringUtils.isNotBlank(attrCode)){
|
return new AjaxResult(AjaxResult.STATUS_FAIL,"属性编码不能为空");
|
}
|
|
|
|
ShopProductAttribute bean = shopProductAttributeDao.selectByCode(attrCode, HostInterceptor.getCompanyId());
|
if(null == bean){
|
return new AjaxResult(AjaxResult.STATUS_FAIL,"未找到属性信息");
|
}
|
List<ShopProductAttribute> list = shopProductAttributeDao.selectByParentId(bean.getAttrId());
|
// 存储子集
|
List<ShopProductAttribute> shopProductAttributeList = new ArrayList<ShopProductAttribute>();
|
// 遍历子集
|
for(ShopProductAttribute shopProductAttribute : list){
|
// 查询子集并储存
|
shopProductAttributeList = shopProductAttributeDao.selectByParentId(shopProductAttribute.getAttrId());
|
shopProductAttribute.setShopProductAttributeList(shopProductAttributeList);
|
}
|
|
return new AjaxResult(AjaxResult.STATUS_SUCCESS,list,list.size());
|
}
|
}
|