feat(product): 平台属性管理

This commit is contained in:
bunny 2024-04-03 16:52:25 +08:00
parent 69fa0ab77d
commit 916dcab6f0
3 changed files with 74 additions and 4 deletions

View File

@ -1,9 +1,16 @@
package com.atguigu.ssyx.product.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.Attr;
import com.atguigu.ssyx.product.service.AttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
@ -13,9 +20,55 @@ import org.springframework.web.bind.annotation.RestController;
* @author bunny
* @since 2024-04-03
*/
@Api(value = "Attr管理", tags = "平台属性管理")
@RestController
@RequestMapping("/product/attr")
@RequestMapping(value = "/admin/product/attr")
public class AttrController {
@Autowired
private AttrService attrService;
@ApiOperation(value = "获取列表")
@GetMapping("{attrGroupId}")
public Result<List<Attr>> index(
@ApiParam(name = "attrGroupId", value = "分组id", required = true)
@PathVariable Long attrGroupId) {
List<Attr> attrList = attrService.findByAttrGroupId(attrGroupId);
return Result.success(attrList);
}
@ApiOperation(value = "获取")
@GetMapping("get/{id}")
public Result<Attr> get(@PathVariable Long id) {
Attr attr = attrService.getById(id);
return Result.success(attr);
}
@ApiOperation(value = "新增")
@PostMapping("save")
public Result<Attr> save(@RequestBody Attr attr) {
attrService.save(attr);
return Result.success();
}
@ApiOperation(value = "修改")
@PutMapping("update")
public Result<Attr> updateById(@RequestBody Attr attr) {
attrService.updateById(attr);
return Result.success();
}
@ApiOperation(value = "删除")
@DeleteMapping("remove/{id}")
public Result<Attr> remove(@PathVariable Long id) {
attrService.removeById(id);
return Result.success();
}
@ApiOperation(value = "根据id列表删除")
@DeleteMapping("batchRemove")
public Result<Attr> batchRemove(@RequestBody List<Long> ids) {
attrService.removeByIds(ids);
return Result.success();
}
}

View File

@ -3,6 +3,8 @@ package com.atguigu.ssyx.product.service;
import com.atguigu.ssyx.model.product.Attr;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* <p>
* 商品属性 服务类
@ -13,4 +15,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface AttrService extends IService<Attr> {
/**
* 获取列表
*/
List<Attr> findByAttrGroupId(Long attrGroupId);
}

View File

@ -3,9 +3,12 @@ package com.atguigu.ssyx.product.service.impl;
import com.atguigu.ssyx.model.product.Attr;
import com.atguigu.ssyx.product.mapper.AttrMapper;
import com.atguigu.ssyx.product.service.AttrService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 商品属性 服务实现类
@ -16,5 +19,13 @@ import org.springframework.stereotype.Service;
*/
@Service
public class AttrServiceImpl extends ServiceImpl<AttrMapper, Attr> implements AttrService {
/**
* 获取列表
*/
@Override
public List<Attr> findByAttrGroupId(Long attrGroupId) {
LambdaQueryWrapper<Attr> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Attr::getAttrGroupId, attrGroupId);
return baseMapper.selectList(wrapper);
}
}