package com.yijia.market.controller;

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.yijia.common.annotation.Log;
import com.yijia.common.core.controller.BaseController;
import com.yijia.common.core.domain.AjaxResult;
import com.yijia.common.enums.BusinessType;
import com.yijia.market.domain.MarkertPlan;
import com.yijia.market.service.IMarkertPlanService;
import com.yijia.common.utils.poi.ExcelUtil;
import com.yijia.common.core.page.TableDataInfo;

/**
 * 营销方案Controller
 * 
 * @author yijia
 * @date 2020-12-22
 */
@RestController
@RequestMapping("/market/plan")
public class MarkertPlanController extends BaseController
{
    @Autowired
    private IMarkertPlanService markertPlanService;

    /**
     * 查询营销方案列表
     */
    @PreAuthorize("@ss.hasPermi('market:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(MarkertPlan markertPlan)
    {
        startPage();
        List<MarkertPlan> list = markertPlanService.selectMarkertPlanList(markertPlan);
        return getDataTable(list);
    }

    /**
     * 导出营销方案列表
     */
    @PreAuthorize("@ss.hasPermi('market:plan:export')")
    @Log(title = "营销方案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MarkertPlan markertPlan)
    {
        List<MarkertPlan> list = markertPlanService.selectMarkertPlanList(markertPlan);
        ExcelUtil<MarkertPlan> util = new ExcelUtil<MarkertPlan>(MarkertPlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 获取营销方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(markertPlanService.selectMarkertPlanById(id));
    }

    /**
     * 新增营销方案
     */
    @PreAuthorize("@ss.hasPermi('market:plan:add')")
    @Log(title = "营销方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MarkertPlan markertPlan)
    {
        return toAjax(markertPlanService.insertMarkertPlan(markertPlan));
    }

    /**
     * 修改营销方案
     */
    @PreAuthorize("@ss.hasPermi('market:plan:edit')")
    @Log(title = "营销方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MarkertPlan markertPlan)
    {
        return toAjax(markertPlanService.updateMarkertPlan(markertPlan));
    }

    /**
     * 删除营销方案
     */
    @PreAuthorize("@ss.hasPermi('market:plan:remove')")
    @Log(title = "营销方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(markertPlanService.deleteMarkertPlanByIds(ids));
    }
}
