package com.younike.admin;

import java.util.List;
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.younike.common.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.CateDimension;
import com.younike.system.service.ICateDimensionService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 分类维度Controller
 * 
 * @author elev
 * @date 2022-01-04
 */
@Api("分类维度接口")
@RestController
@RequestMapping("/admin/cateDimension")
public class AdminCateDimensionController extends BaseController {
    @Autowired
    private ICateDimensionService cateDimensionService;

    /**
     * 查询分类维度列表
     */
    @ApiOperation("查询分类维度列表")
    @PreAuthorize("@ss.hasPermi('system:dimension:list')")
    @GetMapping("/list")
    public TableDataInfo list(CateDimension cateDimension) {
        startPage();
        List<CateDimension> list = cateDimensionService.selectCateDimensionList(cateDimension);
        return getDataTable(list);
    }

    /**
     * 导出分类维度列表
     */
    @ApiOperation("导出分类维度列表")
    @PreAuthorize("@ss.hasPermi('system:dimension:export')")
    @Log(title = "分类维度", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CateDimension cateDimension) {
        List<CateDimension> list = cateDimensionService.selectCateDimensionList(cateDimension);
        ExcelUtil<CateDimension> util = new ExcelUtil<CateDimension>(CateDimension.class);
        return util.exportExcel(list, "分类维度数据");
    }

    /**
     * 获取分类维度详细信息
     */
    @ApiOperation("获取分类维度详细信息")
    @PreAuthorize("@ss.hasPermi('system:dimension:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cateDimensionService.selectCateDimensionById(id));
    }

    /**
     * 新增分类维度
     */
    @ApiOperation("新增分类维度")
    @PreAuthorize("@ss.hasPermi('system:dimension:add')")
    @Log(title = "分类维度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CateDimension cateDimension) {
        return toAjax(cateDimensionService.insertCateDimension(cateDimension));
    }

    /**
     * 修改分类维度
     */
    @ApiOperation("修改分类维度")
    @PreAuthorize("@ss.hasPermi('system:dimension:edit')")
    @Log(title = "分类维度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CateDimension cateDimension) {
        return toAjax(cateDimensionService.updateCateDimension(cateDimension));
    }

    /**
     * 删除分类维度
     */
    @ApiOperation("删除分类维度")
    @PreAuthorize("@ss.hasPermi('system:dimension:remove')")
    @Log(title = "分类维度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cateDimensionService.deleteCateDimensionByIds(ids));
    }
}
