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.Dimension;
import com.younike.system.service.IDimensionService;
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/dimension")
public class AdminDimensionController extends BaseController {
    @Autowired
    private IDimensionService dimensionService;

    /**
     * 查询评价维度列表
     */
    @ApiOperation("查询评价维度列表")
    @PreAuthorize("@ss.hasPermi('system:dimension:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dimension dimension) {
        startPage();
        List<Dimension> list = dimensionService.selectDimensionList(dimension);
        return getDataTable(list);
    }

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

    /**
     * 获取评价维度详细信息
     */
    @ApiOperation("获取评价维度详细信息")
    @PreAuthorize("@ss.hasPermi('system:dimension:query')")
    @GetMapping(value = "/{dimensionId}")
    public AjaxResult getInfo(@PathVariable("dimensionId") Long dimensionId) {
        return AjaxResult.success(dimensionService.selectDimensionByDimensionId(dimensionId));
    }

    /**
     * 新增评价维度
     */
    @ApiOperation("新增评价维度")
    @PreAuthorize("@ss.hasPermi('system:dimension:add')")
    @Log(title = "评价维度", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dimension dimension) {
        return toAjax(dimensionService.insertDimension(dimension));
    }

    /**
     * 修改评价维度
     */
    @ApiOperation("修改评价维度")
    @PreAuthorize("@ss.hasPermi('system:dimension:edit')")
    @Log(title = "评价维度", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dimension dimension) {
        return toAjax(dimensionService.updateDimension(dimension));
    }

    /**
     * 删除评价维度
     */
    @ApiOperation("删除评价维度")
    @PreAuthorize("@ss.hasPermi('system:dimension:remove')")
    @Log(title = "评价维度", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dimensionIds}")
    public AjaxResult remove(@PathVariable Long[] dimensionIds) {
        return toAjax(dimensionService.deleteDimensionByDimensionIds(dimensionIds));
    }
}
