package com.xinelu.manage.controller.wechattemplate;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.dto.wechattemplate.WechatTemplateDTO;
import com.xinelu.manage.dto.wechattemplate.WechatTemplateTaskDTO;
import com.xinelu.manage.service.wechattemplate.IWechatTemplateService;
import com.xinelu.manage.vo.wechattemplate.WechatTemplateTaskVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信模板信息Controller
 *
 * @author xinelu
 * @date 2024-02-27
 */
@Api(tags = "微信库控制器")
@RestController
@RequestMapping("/manage/template")
public class WechatTemplateController extends BaseController {
    @Resource
    private IWechatTemplateService wechatTemplateService;

    /**
     * 查询微信模板信息列表
     */
    @ApiOperation("查询微信模板信息列表")
    @GetMapping("/list")
    public TableDataInfo list(WechatTemplateDTO wechatTemplateDto) {
        startPage();
        List<WechatTemplateTaskVO> list = wechatTemplateService.selectWechatTemplateList(wechatTemplateDto);
	    return getDataTable(list);
    }

    /**
     * 导出微信模板信息列表
     */
    @ApiOperation("导出微信模板信息列表")
    @PreAuthorize("@ss.hasPermi('manage:template:export')")
    @Log(title = "微信模板信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WechatTemplateDTO wechatTemplateDto) {
        List<WechatTemplateTaskVO> voList = wechatTemplateService.selectWechatTemplateList(wechatTemplateDto);
        ExcelUtil<WechatTemplateTaskVO> util = new ExcelUtil<WechatTemplateTaskVO>(WechatTemplateTaskVO.class);
        util.exportExcel(response, voList, "微信模板信息数据");
    }

    /**
     * 获取微信模板信息详细信息
     */
    @ApiOperation("获取微信模板信息详细信息")
    @PreAuthorize("@ss.hasPermi('manage:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(wechatTemplateService.selectWechatTemplateDtoById(id));
    }

    /**
     * 新增微信模板信息
     */
    @ApiOperation("新增微信模板信息")
    @PreAuthorize("@ss.hasPermi('manage:template:add')")
    @Log(title = "微信模板信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WechatTemplateTaskDTO wechatTemplateTaskDTO) {
        return toAjax(wechatTemplateService.insertWechatTemplate(wechatTemplateTaskDTO));
    }

    /**
     * 修改微信模板信息
     */
    @ApiOperation("修改微信模板信息")
    @PreAuthorize("@ss.hasPermi('manage:template:edit')")
    @Log(title = "微信模板信息", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody WechatTemplateTaskDTO wechatTemplateTaskDTO) {
        return toAjax(wechatTemplateService.updateWechatTemplate(wechatTemplateTaskDTO));
    }

    /**
     * 删除微信模板信息
     */
    @ApiOperation("删除微信模板信息")
    @PreAuthorize("@ss.hasPermi('manage:template:remove')")
    @Log(title = "微信模板信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wechatTemplateService.deleteWechatTemplateByIds(ids));
    }
}
