package com.zhongzheng.controller.activity;

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

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.modules.activity.vo.ActivityTaskVo;
import com.zhongzheng.modules.activity.bo.ActivityTaskQueryBo;
import com.zhongzheng.modules.activity.bo.ActivityTaskAddBo;
import com.zhongzheng.modules.activity.bo.ActivityTaskEditBo;
import com.zhongzheng.modules.activity.service.IActivityTaskService;
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("/activity/task")
public class ActivityTaskController extends BaseController {

    private final IActivityTaskService iActivityTaskService;

    /**
     * 查询任务存储列表
     */
    @ApiOperation("查询任务存储列表")
    @PreAuthorize("@ss.hasPermi('activity:task:list')")
    @GetMapping("/list")
    public TableDataInfo<ActivityTaskVo> list(ActivityTaskQueryBo bo) {
        startPage();
        List<ActivityTaskVo> list = iActivityTaskService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出任务存储列表
     */
  /*  @ApiOperation("导出任务存储列表")
    @PreAuthorize("@ss.hasPermi('modules.activity:task:export')")
    @Log(title = "任务存储", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ActivityTaskVo> export(ActivityTaskQueryBo bo) {
        List<ActivityTaskVo> list = iActivityTaskService.queryList(bo);
        ExcelUtil<ActivityTaskVo> util = new ExcelUtil<ActivityTaskVo>(ActivityTaskVo.class);
        return util.exportExcel(list, "任务存储");
    }*/

    /**
     * 获取任务存储详细信息
     */
    @ApiOperation("获取任务存储详细信息")
    @PreAuthorize("@ss.hasPermi('modules.activity:task:query')")
    @GetMapping("/{id}")
    public AjaxResult<ActivityTaskVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iActivityTaskService.queryById(id));
    }

    /**
     * 新增任务存储
     */
    @ApiOperation("新增任务存储")
    @PreAuthorize("@ss.hasPermi('modules.activity:task:add')")
    @Log(title = "任务存储", businessType = BusinessType.INSERT)
    @PostMapping("/addTask")
    public AjaxResult<Void> add(@RequestBody ActivityTaskAddBo bo) {
        return toAjax(iActivityTaskService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改任务存储
     */
    @ApiOperation("修改任务存储")
    @PreAuthorize("@ss.hasPermi('modules.activity:task:edit')")
    @Log(title = "任务存储", businessType = BusinessType.UPDATE)
    @PostMapping("/editTask")
    public AjaxResult<Void> edit(@RequestBody ActivityTaskEditBo bo) {
        return toAjax(iActivityTaskService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除任务存储
     */
/*    @ApiOperation("删除任务存储")
    @PreAuthorize("@ss.hasPermi('modules.activity:task:remove')")
    @Log(title = "任务存储" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iActivityTaskService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }*/
}
