935090232@qq.com
2021-03-19 81a3369395a7cccceb7cd36f5238cc6fe2aa88e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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());
    }
}