package com.zhongzheng.controller.activity;

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

import com.zhongzheng.modules.activity.bo.ActivityConfigurationAddBo;
import com.zhongzheng.modules.activity.bo.ActivityConfigurationEditBo;
import com.zhongzheng.modules.activity.bo.ActivityConfigurationQueryBo;
import com.zhongzheng.modules.activity.service.IActivityConfigurationService;
import com.zhongzheng.modules.activity.vo.ActivityConfigurationVo;
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;

import javax.validation.constraints.NotNull;

/**
 * 活动配置Controller
 * 
 * @author change
 * @date 2021-05-17
 */
@Api(value = "活动配置控制器", tags = {"活动配置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/configuration")
public class ActivityConfigurationController extends BaseController {

    private final IActivityConfigurationService iActivityConfigurationService;

    /**
     * 查询活动配置列表
     */
    @ApiOperation("查询活动配置列表")
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo<ActivityConfigurationVo> list(ActivityConfigurationQueryBo bo) {
        startPage();
        TableDataInfo<ActivityConfigurationVo> list = iActivityConfigurationService.queryList(bo);
        return list;
    }

    /**
     * 导出活动配置列表
     */
 /* @ApiOperation("导出活动配置列表")
    @PreAuthorize("@ss.hasPermi('system:configuration:export')")
    @Log(title = "活动配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ActivityConfigurationVo> export(ActivityConfigurationQueryBo bo) {
        List<ActivityConfigurationVo> list = iActivityConfigurationService.queryList(bo);
        ExcelUtil<ActivityConfigurationVo> util = new ExcelUtil<ActivityConfigurationVo>(ActivityConfigurationVo.class);
        return util.exportExcel(list, "活动配置");
    }*/

    /**
     * 获取活动配置详细信息
     */
    @ApiOperation("获取活动配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping("/{id}")
    public AjaxResult<ActivityConfigurationVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iActivityConfigurationService.queryById(id));
    }

    /**
     * 新增活动配置
     */
    @ApiOperation("新增活动配置")
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "活动配置", businessType = BusinessType.INSERT)
    @PostMapping("addConfig")
    public AjaxResult<Void> add(@RequestBody ActivityConfigurationAddBo bo) {
        return toAjax(iActivityConfigurationService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改活动配置
     */
    @ApiOperation("修改活动配置")
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "活动配置", businessType = BusinessType.UPDATE)
    @PostMapping("editConfig")
    public AjaxResult<Void> edit(@RequestBody ActivityConfigurationEditBo bo) {
        return toAjax(iActivityConfigurationService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除活动配置
     */
    @ApiOperation("删除活动配置")
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "活动配置" , businessType = BusinessType.DELETE)
    @PostMapping("/deleteConfig")
    public AjaxResult<Void> remove(@RequestBody Long[] ids) {
        return toAjax(iActivityConfigurationService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
