package com.crm.manager.controller;

import com.crm.manager.dto.export.CustomEmailSubscribeRecordExportDto;
import com.crm.manager.service.CustomEmailSubscribeRecordService;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.entity.custom.email.subscribe.record.CustomEmailSubscribeRecordSearchEntity;
import com.crm.rely.backend.core.pojo.view.CustomEmailSubscribeRecordView;
import com.crm.rely.backend.exception.ServiceException;
import com.crm.rely.backend.util.ExportUtil;
import com.crm.rely.backend.util.FileProcessUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 邮件订阅记录
 *
 * @author gao
 * @date 2025/7/21 14:35
 */
@RestController
@RequestMapping("/custom/email/subscribe/record")
public class CustomEmailSubscribeRecordController {

    @Autowired
    private CustomEmailSubscribeRecordService customEmailSubscribeRecordService;


    /**
     * 列表
     *
     * @param entity: page
     * @return ResultWithPagerDto<CustomEmailSubscribeRecordDto>
     */
    @PostMapping("/search/list")
    public ResultWithPagerDto<CustomEmailSubscribeRecordView> pageList(@RequestBody CustomEmailSubscribeRecordSearchEntity entity) throws ServiceException {

        return customEmailSubscribeRecordService.searchPageList(entity);
    }

    /**
     * 导出
     *
     * @param response:
     * @return void
     */
    @RequestMapping("/export")
    public void export(CustomEmailSubscribeRecordSearchEntity entity, HttpServletResponse response) throws Exception {
        List<CustomEmailSubscribeRecordExportDto> exportDtos = customEmailSubscribeRecordService.export(entity);
        ExportUtil.transferToResponse(FileProcessUtil.genExportFileName("EMAIL_SUBSCRIBE_RECORD"), exportDtos, CustomEmailSubscribeRecordExportDto.class, response);
    }

}
