【商城项目19】剩下的API编写

【商城项目19】剩下的API编写

1.新增属性

特点:1.用到了org.springframework.beans.BeanUtils;

BeanUtils.copyProperties(attr,attrEntity);

2.用到了vo模型:把接受的json数据变成一个打自定义对象。

image-20200612151141833

http://localhost:11000/product/attr/save

{
  "attrGroupId": 0, 
  "attrName": "像素",
  "attrType": 0, 
  "catelogId": 0, 
  "enable": 0, 
  "icon": "string", 
  "searchType": 0,
  "showDesc": 0,
  "valueSelect": "string", 
  "valueType": 0
}
{
    "msg": "success",
    "code": 0
}
@RequestMapping("/save")
//@RequiresPermissions("product:attr:save")
public R save(@RequestBody AttrVo attr) throws InvocationTargetException, IllegalAccessException {
    System.out.println(attr.getAttrName());
    attrService.saveAttr(attr);

    return R.ok();
}
    @Override
    public void saveAttr(AttrVo attr) throws InvocationTargetException, IllegalAccessException {
        AttrEntity attrEntity = new AttrEntity();
//        attrEntity.setAttrName(attr.getAttrName());
        BeanUtils.copyProperties(attr,attrEntity);
        //1、保存基本数据
        this.save(attrEntity);
        System.out.println(attrEntity.getAttrName());
        //2、保存关联关系
            AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
            relationEntity.setAttrGroupId(attr.getAttrGroupId());
            relationEntity.setAttrId(attrEntity.getAttrId());
            relationDao.insert(relationEntity);
    }
2.属性分组模糊查询

特点:用wrapper封装查询条件,使用.eq like .or

http://localhost:11000/mailproducts/attrgroup/list/170?key=不

get

{
    "msg": "success",
    "code": 0,
    "page": {
        "totalCount": 1,
        "pageSize": 10,
        "totalPage": 1,
        "currPage": 1,
        "list": [
            {
                "attrGroupId": 1,
                "attrGroupName": "不知道",
                "sort": 1,
                "descript": "七大服务",
                "icon": "群文档",
                "catelogId": 170,
                "catelogPath": null
            }
        ]
    }
}
    @RequestMapping("/list/{catelogId}")
    //@RequiresPermissions("product:attrgroup:list")
    public R list(@RequestParam Map<String, Object> params,
                  @PathVariable("catelogId") Long catelogId){
//        PageUtils page = attrGroupService.queryPage(params);

        PageUtils page = attrGroupService.queryPage(params,catelogId);

        return R.ok().put("page", page);
    }
  @Override
    public PageUtils queryPage(Map<String, Object> params, Long catelogId) {
        String key = (String) params.get("key");
        //select * from pms_attr_group where catelog_id=? and (attr_group_id=key or attr_group_name like %key%)
        QueryWrapper<AttrGroupEntity> wrapper = new QueryWrapper<AttrGroupEntity>();
        if(!StringUtils.isEmpty(key)){
            wrapper.and((obj)->{
                obj.eq("attr_group_id",key).or().like("attr_group_name",key);
            });
        }

        if( catelogId == 0){
            IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),
                    wrapper);
            return new PageUtils(page);
        }else {
            wrapper.eq("catelog_id",catelogId);
            IPage<AttrGroupEntity> page = this.page(new Query<AttrGroupEntity>().getPage(params),
                    wrapper);
            return new PageUtils(page);
        }
    }

3.获取某个分类的属性

http://localhost:11000/product/attr/base/listforspu/1 get

{
    "msg": "success",
    "code": 0,
    "data": [
        {
            "id": 1,
            "spuId": 1,
            "attrId": 2,
            "attrName": "尺寸",
            "attrValue": null,
            "attrSort": null,
            "quickShow": null
        },
        {
            "id": 2,
            "spuId": 1,
            "attrId": 1,
            "attrName": "像素",
            "attrValue": null,
            "attrSort": null,
            "quickShow": null
        }
    ]
}
@GetMapping("/base/listforspu/{spuId}")
public R baseAttrlistforspu(@PathVariable("spuId") Long spuId){

    List<ProductAttrValueEntity> entities = productAttrValueService.baseAttrlistforspu(spuId);

    return R.ok().put("data",entities);
}
    @Override
    public List<ProductAttrValueEntity> baseAttrlistforspu(Long spuId) {
        List<ProductAttrValueEntity> entities = this.baseMapper.selectList(new QueryWrapper<ProductAttrValueEntity>().eq("spu_id", spuId));
        return entities;
    }
4.回显属性

http://localhost:11000/product/attr/info/1 get

 @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		//AttrEntity attr = attrService.getById(attrId);
        AttrRespVo respVo = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", respVo);
    }
@Override
    public AttrRespVo getAttrInfo(Long attrId) {
        AttrRespVo respVo = new AttrRespVo();
        AttrEntity attrEntity = this.getById(attrId);
        BeanUtils.copyProperties(attrEntity,respVo);



            //1、设置分组信息
            AttrAttrgroupRelationEntity attrgroupRelation = relationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrId));
            if(attrgroupRelation!=null){
                respVo.setAttrGroupId(attrgroupRelation.getAttrGroupId());
                AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrgroupRelation.getAttrGroupId());
                if(attrGroupEntity!=null){
                    respVo.setGroupName(attrGroupEntity.getAttrGroupName());
                }
            }


        //2、设置分类信息
        Long catelogId = attrEntity.getCatelogId();
        Long[] catelogPath = categoryService.findCatelogPath(catelogId);
        respVo.setCatelogPath(catelogPath);

        CategoryEntity categoryEntity = categoryDao.selectById(catelogId);
        if(categoryEntity!=null){
            respVo.setCatelogName(categoryEntity.getName());
        }


        return respVo;
    }
{
    "msg": "success",
    "code": 0,
    "attr": {
        "attrId": 1,
        "attrName": "像素",
        "searchType": 0,
        "valueType": null,
        "icon": "string",
        "valueSelect": "string",
        "attrType": 1,
        "enable": 1,
        "catelogId": 170,
        "showDesc": 0,
        "attrGroupId": 1,
        "catelogName": "影视",
        "groupName": "不知道",
        "catelogPath": [
            1,
            23,
            170
        ]
    }
}
5.属性修改后保存

http://localhost:11000/product/attr/update post

{
  "attrId": 1,
  "attrGroupId": 0,
  "attrName": "属性名",
  "attrType": 0, 
  "catelogId": 1,
  "enable": 0, 
  "icon": "string", 
  "searchType": 0,
  "showDesc": 0, 
  "valueSelect": "string", 
  "valueType": 0 
}
  @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }
AttrEntity attrEntity = new AttrEntity();
        BeanUtils.copyProperties(attr,attrEntity);
        this.updateById(attrEntity);

        if(attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()){
            //1、修改分组关联
            AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();

            relationEntity.setAttrGroupId(attr.getAttrGroupId());
            relationEntity.setAttrId(attr.getAttrId());

            Integer count = relationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attr.getAttrId()));
            if(count>0){

                relationDao.update(relationEntity,new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id",attr.getAttrId()));

            }else{
                relationDao.insert(relationEntity);
            }
        }

6.属性区分销售属性还是分类属性

ProductConstant:

package com.ufo.common.constant;

import lombok.Data;

public class ProductConstant {


    public enum  AttrEnum{
        ATTR_TYPE_BASE(1,"基本属性"),ATTR_TYPE_SALE(0,"销售属性");
        private int code;
        private String msg;

        AttrEnum(int code,String msg){
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }
}

   @GetMapping("/{attrType}//list/{catelogId}")
    public R baseAttrList(@RequestParam Map<String, Object> params,
                          @PathVariable("catelogId") Long catelogId,
                          @PathVariable("attrType")String type){

        PageUtils page = attrService.queryBaseAttrPage(params,catelogId,type);
        return R.ok().put("page", page);
    }

实现类:查询

 @Override
    public PageUtils queryBaseAttrPage(Map<String, Object> params, Long catelogId, String type) {
        QueryWrapper<AttrEntity> queryWrapper = new QueryWrapper<AttrEntity>();

        if(catelogId != 0){
            queryWrapper.eq("catelog_id",catelogId).eq("attr_type","base".equalsIgnoreCase(type)?1:0);
        }

        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            //attr_id  attr_name
            queryWrapper.and((wrapper)->{
                wrapper.eq("attr_id",key).or().like("attr_name",key);
            });
        }

        IPage<AttrEntity> page = this.page(
                new Query<AttrEntity>().getPage(params),
                queryWrapper
        );

        PageUtils pageUtils = new PageUtils(page);
        List<AttrEntity> records = page.getRecords();
        List<AttrRespVo> respVos = records.stream().map((attrEntity) -> {
            AttrRespVo attrRespVo = new AttrRespVo();
            BeanUtils.copyProperties(attrEntity, attrRespVo);

            //1、设置分类和分组的名字
            if("base".equalsIgnoreCase(type)){
                AttrAttrgroupRelationEntity attrId = relationDao.selectOne(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attrEntity.getAttrId()));
                if (attrId != null && attrId.getAttrGroupId()!=null) {
                    AttrGroupEntity attrGroupEntity = attrGroupDao.selectById(attrId.getAttrGroupId());
                    attrRespVo.setGroupName(attrGroupEntity.getAttrGroupName());
                }

            }


            CategoryEntity categoryEntity = categoryDao.selectById(attrEntity.getCatelogId());
            if (categoryEntity != null) {
                attrRespVo.setCatelogName(categoryEntity.getName());
            }
            return attrRespVo;
        }).collect(Collectors.toList());

        pageUtils.setList(respVos);
        return pageUtils;
    }

实现类:更新

 @Transactional
    @Override
    public void updateAttr(AttrVo attr) {
        AttrEntity attrEntity = new AttrEntity();
        BeanUtils.copyProperties(attr,attrEntity);
        this.updateById(attrEntity);
        if(attrEntity.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode()) {
            //1、修改分组关联
            AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();

            relationEntity.setAttrGroupId(attr.getAttrGroupId());
            relationEntity.setAttrId(attr.getAttrId());

            Integer count = relationDao.selectCount(new QueryWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attr.getAttrId()));
            if (count > 0) {

                relationDao.update(relationEntity, new UpdateWrapper<AttrAttrgroupRelationEntity>().eq("attr_id", attr.getAttrId()));

            } else {
                relationDao.insert(relationEntity);
            }
        }


    }

新增:

   @Override
    public void saveAttr(AttrVo attr) throws InvocationTargetException, IllegalAccessException {
        AttrEntity attrEntity = new AttrEntity();
//        attrEntity.setAttrName(attr.getAttrName());
        BeanUtils.copyProperties(attr,attrEntity);
        //1、保存基本数据
        this.save(attrEntity);
        //2、保存关联关系
        if(attr.getAttrType() == ProductConstant.AttrEnum.ATTR_TYPE_BASE.getCode() && attr.getAttrGroupId()!=null){
            AttrAttrgroupRelationEntity relationEntity = new AttrAttrgroupRelationEntity();
            relationEntity.setAttrGroupId(attr.getAttrGroupId());
            relationEntity.setAttrId(attrEntity.getAttrId());
            relationDao.insert(relationEntity);
        }
7…

查询一个品牌有哪些分类GET
http://localhost:11000/product/categorybrandrelation/catelog/list?brandId=1
@RequestParam(“brandId”)Long brandId

给品牌新增分类:
http://localhost:11000/product/categorybrandrelation/save
{“brandId”:2,“catelogId”:5}
@RequestBody CategoryBrandRelationEntity categoryBrandRelation

image-20200612163956574

在Eclipse上针对API级别19(Android 4.4 KitKat)进行开发,你需要确保以下几个步骤: 1. **安装必要的插件**: Eclipse的标准版本可能不包含Android开发工具。你需要先下载并安装Eclipse的adt bundle,它包含了Android Development Tools (ADT),包括支持API 19的SDK。 2. **配置SDK环境**: 安装完成后,在Eclipse的Window -> Preferences -> Android中,确保SDK Manager已正确配置。找到API Level 19(KitKat)并勾选安装,如果尚未安装。此外,还需要选择合适的Build Target(构建目标),通常设置为API 19。 3. **新建项目**: 使用Eclipse菜单File -> New -> Android Project,然后选择Empty Activity或其他模板。在新项目窗口中,指定项目的最低API级别为API 19。 4. **兼容库**: API 19可能有一些新的特性,为了兼容旧设备,你可以在build.gradle(如果使用Gradle构建)或AndroidManifest.xml中设置兼容库(minSdkVersion和targetSdkVersion)。比如: ```xml <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" /> ``` 5. **代码编写**: 开始编写你的Java或Kotlin代码,注意使用API 19特有的功能时,需要检查该功能是否在你指定的最小API级别之上可用。例如,对于API 19的新特性,如Action Barsherlock(如果你在使用)或新的UI组件,记得只在需要的地方引入和使用它们。 6. **调试运行**: 在模拟器或真机上,设置正确的设备目标(Emulator -> AVD Manager),然后在Eclipse中右键点击项目 -> Run As -> Android Application,确保应用程序能在API 19环境中正常运行和调试。 7. **测试适配性**: 要确认你的应用在不同设备上工作良好,尤其是那些较旧的API 19设备,因为某些硬件加速可能会有所不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值