package com.yiqi.admin.controller.core;

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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.domain.R;
import com.yiqi.common.enums.DeleteStatus;
import com.yiqi.common.enums.StatusType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.core.domain.ClothBrand;
import com.yiqi.core.service.IClothBrandService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 衣服品牌Controller
 *
 * @author ruoyi
 * @date 2023-10-16
 */
@Api(tags = "管理后台 - 衣服品牌")
@RestController
@RequestMapping(UrlConstants.managerApi + "/cloth/brand")
public class ClothBrandController extends BaseController {
    @Autowired
    private IClothBrandService clothBrandService;

    @ApiOperation("获取所有品牌")
    @GetMapping(value = "all")
    public R<List<ClothBrand>> all() throws Exception{
        return R.ok(clothBrandService.list(new QueryWrapper<ClothBrand>().lambda()
                .eq(ClothBrand::getDelFlag, DeleteStatus.OK.getCode())
                .eq(ClothBrand::getStatus, StatusType.OK.getCode())));
    }

    /**
     * 查询衣服品牌列表
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询衣服品牌列表")
    public TableDataInfo list(ClothBrand clothBrand) {
        startPage();
        List<ClothBrand> list = clothBrandService.selectClothBrandList(clothBrand);
        return getDataTable(list);
    }

    /**
     * 导出衣服品牌列表
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:export')")
    @Log(title = "衣服品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出衣服品牌列表")
    public void export(HttpServletResponse response, ClothBrand clothBrand) {
        List<ClothBrand> list = clothBrandService.selectClothBrandList(clothBrand);
        ExcelUtil<ClothBrand> util = new ExcelUtil<ClothBrand>(ClothBrand. class);
        util.exportExcel(response, list, "衣服品牌数据");
    }

    /**
     * 获取衣服品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取衣服品牌详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(clothBrandService.selectClothBrandById(id));
    }

    /**
     * 新增衣服品牌
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:add')")
    @Log(title = "衣服品牌", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增衣服品牌")
    public AjaxResult add(@RequestBody ClothBrand clothBrand) {
        clothBrand.setCreateById(getUserId());
        clothBrand.setCreateBy(getUsername());
        return toAjax(clothBrandService.insertClothBrand(clothBrand));
    }

    /**
     * 修改衣服品牌
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:edit')")
    @Log(title = "衣服品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改衣服品牌")
    public AjaxResult edit(@RequestBody ClothBrand clothBrand) {
        clothBrand.setUpdateById(getUserId());
        clothBrand.setUpdateBy(getUsername());
        return toAjax(clothBrandService.updateClothBrand(clothBrand));
    }

    /**
     * 删除衣服品牌
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:remove')")
    @Log(title = "衣服品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除衣服品牌")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(clothBrandService.deleteClothBrandByIds(ids));
    }

    /**
     * 修改衣服品牌状态
     */
    @PreAuthorize("@ss.hasPermi('cloth:brand:edit')")
    @Log(title = "衣服品牌", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateStatus")
    @ApiOperation(value = "修改衣服品牌状态")
    public AjaxResult updateClothBrandStatus(@RequestBody ClothBrand clothBrand) {
        return toAjax(clothBrandService.updateClothBrandStatus(clothBrand));
    }
}
