|
|
|
@ -26,73 +26,103 @@ import jakarta.validation.Valid;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参数管理
|
|
|
|
|
* 参数管理相关的控制器类,主要负责处理商品参数(属性)相关的增删改查操作,并且在各个操作方法上添加了权限控制,
|
|
|
|
|
* 确保只有具备相应权限的用户才能执行对应的操作。
|
|
|
|
|
*
|
|
|
|
|
* @author lgh
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/admin/attribute")
|
|
|
|
|
public class AttributeController {
|
|
|
|
|
|
|
|
|
|
// 注入ProdPropService,用于与商品属性相关的业务逻辑处理,例如查询、保存、更新、删除商品属性及其相关值等操作。
|
|
|
|
|
@Autowired
|
|
|
|
|
private ProdPropService prodPropService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* 分页获取商品属性信息的方法,根据传入的查询条件(ProdProp对象)和分页参数(PageParam对象),
|
|
|
|
|
* 从数据库中分页查询符合条件的商品属性信息,并返回给前端。
|
|
|
|
|
* 同时,通过@PreAuthorize注解进行权限控制,只有具备"admin:attribute:page"权限的用户才能访问此方法。
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/page")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:page')")
|
|
|
|
|
public ServerResponseEntity<IPage<ProdProp>> page(ProdProp prodProp,PageParam<ProdProp> page){
|
|
|
|
|
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
|
|
|
|
|
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
IPage<ProdProp> prodPropPage = prodPropService.pagePropAndValue(prodProp,page);
|
|
|
|
|
return ServerResponseEntity.success(prodPropPage);
|
|
|
|
|
}
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:page')")
|
|
|
|
|
public ServerResponseEntity<IPage<ProdProp>> page(ProdProp prodProp, PageParam<ProdProp> page) {
|
|
|
|
|
// 设置商品属性的规则为属性类型(这里假设ProdPropRule.ATTRIBUTE表示属性类型),用于后续业务逻辑中区分不同类型的商品属性规则。
|
|
|
|
|
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
|
|
|
|
|
// 设置商品属性所属的店铺ID,通过SecurityUtils工具类获取当前登录用户所属的店铺ID,确保查询的是当前店铺下的商品属性信息。
|
|
|
|
|
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
// 调用ProdPropService的pagePropAndValue方法,传入设置好的商品属性对象和分页参数,获取分页后的商品属性信息结果集。
|
|
|
|
|
IPage<ProdProp> prodPropPage = prodPropService.pagePropAndValue(prodProp, page);
|
|
|
|
|
// 将查询到的分页商品属性信息封装在成功的响应实体中返回给前端。
|
|
|
|
|
return ServerResponseEntity.success(prodPropPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/info/{id}")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:info')")
|
|
|
|
|
public ServerResponseEntity<ProdProp> info(@PathVariable("id") Long id){
|
|
|
|
|
ProdProp prodProp = prodPropService.getById(id);
|
|
|
|
|
return ServerResponseEntity.success(prodProp);
|
|
|
|
|
}
|
|
|
|
|
* 根据商品属性ID获取商品属性详细信息的方法,通过传入的商品属性ID,从数据库中查询对应的商品属性信息并返回给前端。
|
|
|
|
|
* 同样通过@PreAuthorize注解进行权限控制,只有具备"admin:attribute:info"权限的用户才能访问此方法。
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/info/{id}")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:info')")
|
|
|
|
|
public ServerResponseEntity<ProdProp> info(@PathVariable("id") Long id) {
|
|
|
|
|
// 调用ProdPropService的getById方法,根据传入的商品属性ID从数据库中获取对应的商品属性对象。
|
|
|
|
|
ProdProp prodProp = prodPropService.getById(id);
|
|
|
|
|
// 将获取到的商品属性对象封装在成功的响应实体中返回给前端。
|
|
|
|
|
return ServerResponseEntity.success(prodProp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:save')")
|
|
|
|
|
public ServerResponseEntity<Void> save(@Valid ProdProp prodProp){
|
|
|
|
|
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
|
|
|
|
|
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
prodPropService.saveProdPropAndValues(prodProp);
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 保存商品属性信息的方法,接收一个经过验证(通过@Valid注解)的商品属性对象(ProdProp),
|
|
|
|
|
* 在保存前设置相关属性(如属性规则、店铺ID等),然后调用服务层方法将商品属性及其相关值保存到数据库中,
|
|
|
|
|
* 最后返回成功的响应结果给前端。通过@PreAuthorize注解进行权限控制,只有具备"admin:attribute:save"权限的用户才能访问此方法。
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:save')")
|
|
|
|
|
public ServerResponseEntity<Void> save(@Valid ProdProp prodProp) {
|
|
|
|
|
// 设置商品属性的规则为属性类型(这里假设ProdPropRule.ATTRIBUTE表示属性类型),用于后续业务逻辑中区分不同类型的商品属性规则。
|
|
|
|
|
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
|
|
|
|
|
// 设置商品属性所属的店铺ID,通过SecurityUtils工具类获取当前登录用户所属的店铺ID,确保保存的是当前店铺下的商品属性信息。
|
|
|
|
|
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
// 调用ProdPropService的saveProdPropAndValues方法,将设置好的商品属性对象及其相关值保存到数据库中。
|
|
|
|
|
prodPropService.saveProdPropAndValues(prodProp);
|
|
|
|
|
// 返回表示操作成功的响应实体,由于这里只是执行保存操作,无需返回具体数据,所以返回的是Void类型的成功响应。
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:update')")
|
|
|
|
|
public ServerResponseEntity<Void> update(@Valid ProdProp prodProp){
|
|
|
|
|
ProdProp dbProdProp = prodPropService.getById(prodProp.getPropId());
|
|
|
|
|
if (!Objects.equals(dbProdProp.getShopId(), SecurityUtils.getSysUser().getShopId())) {
|
|
|
|
|
throw new YamiShopBindException("没有权限获取该商品规格信息");
|
|
|
|
|
}
|
|
|
|
|
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
|
|
|
|
|
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
prodPropService.updateProdPropAndValues(prodProp);
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 修改商品属性信息的方法,接收一个经过验证(通过@Valid注解)的商品属性对象(ProdProp),
|
|
|
|
|
* 首先根据传入的商品属性对象中的ID查询数据库中已有的商品属性信息,判断当前登录用户是否有修改该商品属性的权限(通过店铺ID对比),
|
|
|
|
|
* 若有权限则设置相关属性(如属性规则、店铺ID等),再调用服务层方法更新商品属性及其相关值到数据库中,
|
|
|
|
|
* 最后返回成功的响应结果给前端。通过@PreAuthorize注解进行权限控制,只有具备"admin:attribute:update"权限的用户才能访问此方法。
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:update')")
|
|
|
|
|
public ServerResponseEntity<Void> update(@Valid ProdProp prodProp) {
|
|
|
|
|
// 根据传入的商品属性对象中的ID,调用ProdPropService的getById方法从数据库中获取对应的商品属性对象,用于后续权限判断等操作。
|
|
|
|
|
ProdProp dbProdProp = prodPropService.getById(prodProp.getPropId());
|
|
|
|
|
// 判断数据库中查询到的商品属性所属的店铺ID与当前登录用户所属的店铺ID是否一致,若不一致则说明当前用户没有权限修改该商品属性信息,抛出相应异常。
|
|
|
|
|
if (!Objects.equals(dbProdProp.getShopId(), SecurityUtils.getSysUser().getShopId())) {
|
|
|
|
|
throw new YamiShopBindException("没有权限获取该商品规格信息");
|
|
|
|
|
}
|
|
|
|
|
// 设置商品属性的规则为属性类型(这里假设ProdPropRule.ATTRIBUTE表示属性类型),用于后续业务逻辑中区分不同类型的商品属性规则。
|
|
|
|
|
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
|
|
|
|
|
// 设置商品属性所属的店铺ID,通过SecurityUtils工具类获取当前登录用户所属的店铺ID,确保更新的是当前店铺下的商品属性信息。
|
|
|
|
|
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
// 调用ProdPropService的updateProdPropAndValues方法,将设置好的商品属性对象及其相关值更新到数据库中。
|
|
|
|
|
prodPropService.updateProdPropAndValues(prodProp);
|
|
|
|
|
// 返回表示操作成功的响应实体,由于这里只是执行更新操作,无需返回具体数据,所以返回的是Void类型的成功响应。
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:delete')")
|
|
|
|
|
public ServerResponseEntity<Void> delete(@PathVariable Long id){
|
|
|
|
|
prodPropService.deleteProdPropAndValues(id,ProdPropRule.ATTRIBUTE.value(),SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 删除商品属性信息的方法,根据传入的商品属性ID,调用服务层方法删除对应的商品属性及其相关值信息,
|
|
|
|
|
* 最后返回成功的响应结果给前端。通过@PreAuthorize注解进行权限控制,只有具备"admin:attribute:delete"权限的用户才能访问此方法。
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
|
@PreAuthorize("@pms.hasPermission('admin:attribute:delete')")
|
|
|
|
|
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
|
|
|
|
|
// 调用ProdPropService的deleteProdPropAndValues方法,传入商品属性ID、属性规则(这里指定为属性类型)以及当前登录用户所属的店铺ID,执行删除操作。
|
|
|
|
|
prodPropService.deleteProdPropAndValues(id, ProdPropRule.ATTRIBUTE.value(), SecurityUtils.getSysUser().getShopId());
|
|
|
|
|
// 返回表示操作成功的响应实体,由于这里只是执行删除操作,无需返回具体数据,所以返回的是Void类型的成功响应。
|
|
|
|
|
return ServerResponseEntity.success();
|
|
|
|
|
}
|
|
|
|
|
}
|