package com.zhongzheng.controller.activity;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.modules.activity.bo.ActivityGradeAddBo;
import com.zhongzheng.modules.activity.bo.ActivityGradeEditBo;
import com.zhongzheng.modules.activity.bo.ActivityGradeQueryBo;
import com.zhongzheng.modules.activity.service.IActivityGradeService;
import com.zhongzheng.modules.activity.vo.ActivityGradeVo;
import lombok.RequiredArgsConstructor;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 等级积分Controller
 * 
 * @author change
 * @date 2021-05-19
 */
@Api(value = "等级控制器", tags = {"等级管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/grade")
public class ActivityGradeController extends BaseController {

    private final IActivityGradeService iActivityGradeService;

    /**
     * 查询等级积分列表
     */
    @ApiOperation("查询等级管理列表")
    @PreAuthorize("@ss.hasPermi('system:grade:list')")
    @GetMapping("/list")
    public TableDataInfo<ActivityGradeVo> list(ActivityGradeQueryBo bo) {
        startPage();
        TableDataInfo<ActivityGradeVo> list = iActivityGradeService.queryList(bo);
        return list;
    }

    /**
     * 导出等级积分列表
     */
/*    @ApiOperation("导出等级积分列表")
    @PreAuthorize("@ss.hasPermi('system:grade:export')")
    @Log(title = "等级积分", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ActivityGradeVo> export(ActivityGradeQueryBo bo) {
        List<ActivityGradeVo> list = iActivityGradeService.queryList(bo);
        ExcelUtil<ActivityGradeVo> util = new ExcelUtil<ActivityGradeVo>(ActivityGradeVo.class);
        return util.exportExcel(list, "等级积分");
    }*/

    /**
     * 获取等级积分详细信息
     */
    @ApiOperation("获取等级管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:grade:query')")
    @GetMapping("/{id}")
    public AjaxResult<ActivityGradeVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iActivityGradeService.queryById(id));
    }

    /**
     * 新增等级积分
     */
    @ApiOperation("新增等级积分")
    @PreAuthorize("@ss.hasPermi('system:grade:add')")
    @Log(title = "等级积分", businessType = BusinessType.INSERT)
    @PostMapping("/addGrade")
    public AjaxResult<Void> add(@RequestBody ActivityGradeAddBo bo) {
        return toAjax(iActivityGradeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改等级积分
     */
    @ApiOperation("修改等级积分")
    @PreAuthorize("@ss.hasPermi('system:grade:edit')")
    @Log(title = "等级积分", businessType = BusinessType.UPDATE)
    @PostMapping("/editGrade")
    public AjaxResult<Void> edit(@RequestBody ActivityGradeEditBo bo) {
        return toAjax(iActivityGradeService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除等级积分
     */
  /*  @ApiOperation("删除等级积分")
    @PreAuthorize("@ss.hasPermi('system:grade:remove')")
    @Log(title = "等级积分" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iActivityGradeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
