package com.yiqi.admin.controller.core;

import com.yiqi.common.annotation.Log;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.core.page.TableDataInfo;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.core.domain.GoodsBrand;
import com.yiqi.core.service.IGoodsBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品品牌管理Controller
 *
 * @author ruoyi
 * @date 2023-08-21
 */
@Api(tags = "管理后台 - 商品品牌管理")
@RestController
@RequestMapping(UrlConstants.managerApi + "/core/brand")
public class GoodsBrandController extends BaseController {
    @Autowired
    private IGoodsBrandService goodsBrandService;

    /**
     * 查询商品品牌管理列表
     */
//    @PreAuthorize("@ss.hasPermi('goods:brand:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询商品品牌管理列表")
    public TableDataInfo list(GoodsBrand goodsBrand) {
        startPage();
        List<GoodsBrand> list = goodsBrandService.selectGoodsBrandList(goodsBrand);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌管理列表
     */
    @PreAuthorize("@ss.hasPermi('goods:brand:export')")
    @Log(title = "商品品牌管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出商品品牌管理列表")
    public void export(HttpServletResponse response, GoodsBrand goodsBrand) {
        List<GoodsBrand> list = goodsBrandService.selectGoodsBrandList(goodsBrand);
        ExcelUtil<GoodsBrand> util = new ExcelUtil<GoodsBrand>(GoodsBrand.class);
        util.exportExcel(response, list, "商品品牌管理数据");
    }

    /**
     * 获取商品品牌管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:brand:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取商品品牌管理详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodsBrandService.selectGoodsBrandById(id));
    }

    /**
     * 新增商品品牌管理
     */
    @PreAuthorize("@ss.hasPermi('goods:brand:add')")
    @Log(title = "商品品牌管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增商品品牌管理")
    public AjaxResult add(@RequestBody GoodsBrand goodsBrand) {
        goodsBrand.setCreateById(getUserId());
        goodsBrand.setCreateBy(getUsername());
        return toAjax(goodsBrandService.insertGoodsBrand(goodsBrand));
    }

    /**
     * 修改商品品牌管理
     */
    @PreAuthorize("@ss.hasPermi('goods:brand:edit')")
    @Log(title = "商品品牌管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改商品品牌管理")
    public AjaxResult edit(@RequestBody GoodsBrand goodsBrand) {
        goodsBrand.setUpdateById(getUserId());
        goodsBrand.setUpdateBy(getUsername());
        return toAjax(goodsBrandService.updateGoodsBrand(goodsBrand));
    }

    /**
     * 删除商品品牌管理
     */
    @PreAuthorize("@ss.hasPermi('goods:brand:remove')")
    @Log(title = "商品品牌管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除商品品牌管理")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodsBrandService.deleteGoodsBrandByIds(ids));
    }


    /**
     * 修改商品品牌管理状态
     */
    @PreAuthorize("@ss.hasPermi('goods:brand:edit')")
    @Log(title = "商品管理", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateStatus")
    @ApiOperation(value = "修改商品品牌管理状态")
    public AjaxResult updateBrandStatus(@RequestBody GoodsBrand brand) {
        return toAjax(goodsBrandService.updateBrandStatus(brand));
    }
}
