package com.xinelu.manage.controller.subscribemessagerecord;

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.domain.subscribemessagerecord.SubscribeMessageRecord;
import com.xinelu.manage.service.subscribemessagerecord.ISubscribeMessageRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微信小程序订阅消息记录Controller
 *
 * @author xinelu
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/manage/sendRecord")
public class SubscribeMessageRecordController extends BaseController {
    @Resource
    private ISubscribeMessageRecordService subscribeMessageRecordService;

    /**
     * 查询微信小程序订阅消息记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sendRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubscribeMessageRecord subscribeMessageRecord) {
        startPage();
        List<SubscribeMessageRecord> list = subscribeMessageRecordService.selectSubscribeMessageRecordList(subscribeMessageRecord);
        return getDataTable(list);
    }

    /**
     * 导出微信小程序订阅消息记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:sendRecord:export')")
    @Log(title = "微信小程序订阅消息记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubscribeMessageRecord subscribeMessageRecord) {
        List<SubscribeMessageRecord> list = subscribeMessageRecordService.selectSubscribeMessageRecordList(subscribeMessageRecord);
        ExcelUtil<SubscribeMessageRecord> util = new ExcelUtil<>(SubscribeMessageRecord.class);
        util.exportExcel(response, list, "微信小程序订阅消息记录数据");
    }

    /**
     * 获取微信小程序订阅消息记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:sendRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(subscribeMessageRecordService.selectSubscribeMessageRecordById(id));
    }

    /**
     * 新增微信小程序订阅消息记录
     */
    @PreAuthorize("@ss.hasPermi('manage:sendRecord:add')")
    @Log(title = "微信小程序订阅消息记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubscribeMessageRecord subscribeMessageRecord) {
        return toAjax(subscribeMessageRecordService.insertSubscribeMessageRecord(subscribeMessageRecord));
    }

    /**
     * 修改微信小程序订阅消息记录
     */
    @PreAuthorize("@ss.hasPermi('manage:sendRecord:edit')")
    @Log(title = "微信小程序订阅消息记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubscribeMessageRecord subscribeMessageRecord) {
        return toAjax(subscribeMessageRecordService.updateSubscribeMessageRecord(subscribeMessageRecord));
    }

    /**
     * 删除微信小程序订阅消息记录
     */
    @PreAuthorize("@ss.hasPermi('manage:sendRecord:remove')")
    @Log(title = "微信小程序订阅消息记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(subscribeMessageRecordService.deleteSubscribeMessageRecordByIds(ids));
    }
}
