package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dto.PlatformProductDto;
import com.ym.mec.biz.service.PlatformProductService;
import com.ym.mec.common.controller.BaseController;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author hgw
 * Created by 2021-12-03
 */
@RequestMapping("/platformProduct")
@Api(tags = "平台产品管理")
@RestController
public class PlatformProductController extends BaseController {

    @Autowired
    private PlatformProductService platformProductService;

    @ApiOperation("分页查询")
    @GetMapping(value = "/queryPage")
    @PreAuthorize("@pcs.hasPermissions('platformProduct/queryPage')")
    public Object queryPage(String search, Integer page, Integer rows) {
        return succeed(platformProductService.queryPage(search, page, rows));
    }

    @ApiOperation("修改平台产品")
    @PostMapping(value = "/update")
    @PreAuthorize("@pcs.hasPermissions('platformProduct/update')")
    public Object updateProduct(@Valid @RequestBody PlatformProductDto dto) {
        platformProductService.updateProduct(dto);
        return succeed();
    }

    @ApiOperation("添加平台产品")
    @PostMapping(value = "/add")
    @PreAuthorize("@pcs.hasPermissions('platformProduct/add')")
    public Object addProduct(@Valid @RequestBody PlatformProductDto dto) {
        platformProductService.addProduct(dto);
        return succeed();
    }

    @ApiOperation("删除平台产品")
    @GetMapping(value = "/delete/{id}")
    @PreAuthorize("@pcs.hasPermissions('platformProduct/delete')")
    public Object deleteProduct(@ApiParam(value = "平台产品ID", required = true) @PathVariable("id") Integer id) {
        platformProductService.deleteProduct(id);
        return succeed();
    }

}
