package com.yunyan.web.controller.business;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.yunyan.common.annotation.Log;
import com.yunyan.common.core.controller.BaseController;
import com.yunyan.common.core.domain.AjaxResult;
import com.yunyan.common.enums.BusinessType;
import com.yunyan.business.domain.FillTemplate;
import com.yunyan.business.service.IFillTemplateService;
import com.yunyan.common.utils.poi.ExcelUtil;
import com.yunyan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.yunyan.common.core.domain.AjaxResultVo;
import com.yunyan.common.utils.SecurityUtils;
import java.util.Date;

/**
 * 模板管理Controller
 *
 * @author yunyan
 * @date 2023-07-27
 */
@Api(tags = "3.0.1模板管理")
@RestController
@RequestMapping("/business/template")
public class FillTemplateController extends BaseController
{
    @Autowired
    private IFillTemplateService fillTemplateService;

    /**
     * 查询模板管理列表
     */
    @ApiOperation(value="查询模板管理列表", notes="查询模板管理列表")
    @PreAuthorize("@ss.hasPermi('business:template:list')")
    @GetMapping("/list")
    public TableDataInfo<FillTemplate> list(FillTemplate fillTemplate)
    {
        startPage();
        List<FillTemplate> list = fillTemplateService.selectFillTemplateList(fillTemplate);
        return getDataTable(list);
    }

    /**
     * 导出模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:template:export')")
    @Log(title = "模板管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FillTemplate fillTemplate)
    {
        List<FillTemplate> list = fillTemplateService.selectFillTemplateList(fillTemplate);
        ExcelUtil<FillTemplate> util = new ExcelUtil<FillTemplate>(FillTemplate.class);
        util.exportExcel(response, list, "模板管理数据");
    }

    /**
     * 获取模板管理详细信息
     */
    @ApiOperation(value="获取模板管理详细信息", notes="获取模板管理详细信息")
    @PreAuthorize("@ss.hasPermi('business:template:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResultVo getInfo(@PathVariable("id") Long id)
    {
        return AjaxResultVo.success(fillTemplateService.getById(id));
    }

    /**
     * 新增模板管理
     */
    @ApiOperation(value="新增模板管理", notes="新增模板管理")
    @PreAuthorize("@ss.hasPermi('business:template:add')")
    @Log(title = "模板管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FillTemplate dto)
    {
        return toAjax(fillTemplateService.save(dto));
    }

    /**
     * 修改模板管理
     */
    @ApiOperation(value="修改模板管理", notes="修改模板管理")
    @PreAuthorize("@ss.hasPermi('business:template:edit')")
    @Log(title = "模板管理", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FillTemplate dto)
    {
        return toAjax(fillTemplateService.updateById(dto));
    }

    /**
     * 删除模板管理
     */
    @ApiOperation(value="删除模板管理", notes="删除模板管理")
    @PreAuthorize("@ss.hasPermi('business:template:remove')")
    @Log(title = "模板管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fillTemplateService.removeByIds(Arrays.asList(ids)));
    }

}
