package com.miaxis.pc.controller.product;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.product.domain.ProductTypeInfo;
import com.miaxis.product.service.IProductTypeInfoService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【品类管理】Controller
 *
 * @author miaxis
 * @date 2021-03-11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/pc/product/info")
@Api(tags={"【pc-品类管理】"})
public class ProductTypeInfoController extends BaseController{

    private final IProductTypeInfoService productTypeInfoService;

    /**
     * 查询品类列表
     */
    @PreAuthorize("@ss.hasPermi('product:info:list')")
    @GetMapping("/list")
    @ApiOperation("查询品类列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<ProductTypeInfo> list(@ModelAttribute ProductTypeInfo productTypeInfo){
        startPage();
        List<ProductTypeInfo> list = productTypeInfoService.selectProductTypeInfoList(productTypeInfo);
        return toResponsePageInfo(list);
    }


    /**
     * 获取品类详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:info:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取品类详细信息")
    public Response<ProductTypeInfo> getInfo(
            @ApiParam(name = "id", value = "品类参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(productTypeInfoService.getById(id));
    }

    /**
     * 新增品类
     */
    @PreAuthorize("@ss.hasPermi('product:info:add')")
    @Log(title = "品类", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增品类")
    public Response<Integer> add(@RequestBody ProductTypeInfo productTypeInfo){
        return toResponse(productTypeInfoService.save(productTypeInfo) ? 1 : 0);
    }

    /**
     * 修改品类
     */
    @PreAuthorize("@ss.hasPermi('product:info:edit')")
    @Log(title = "品类", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改品类")
    public Response<Integer> edit(@RequestBody ProductTypeInfo productTypeInfo){
        return toResponse(productTypeInfoService.updateById(productTypeInfo) ? 1 : 0);
    }

    /**
     * 删除品类
     */
    @PreAuthorize("@ss.hasPermi('product:info:remove')")
    @Log(title = "品类", businessType = BusinessTypeEnum.UPDATE)
	@PutMapping("/{ids}")
    @ApiOperation("删除品类")
    public  Response<Integer> remove(
            @ApiParam(name = "ids", value = "品类ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return productTypeInfoService.removeProductByIds(ids);
    }
}
