package com.chinaweal.aiccs.aiccs.fraudreg.controller;


import com.chinaweal.aiccs.aiccs.fraudreg.entity.FraudBatchBaseinfo;
import com.chinaweal.aiccs.aiccs.fraudreg.service.FraudBatchBaseinfoService;
import com.chinaweal.aiccs.common.base.controller.BaseController;
import com.chinaweal.youfool.framework.springboot.mybatis.plus.page.PageRequestDto;
import com.chinaweal.youfool.framework.springboot.rest.RestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 批量撤销登记关联主体表 前端控制器
 * </p>
 *
 * @author sh
 * @since 2023-03-14
 */
@RestController
@RequestMapping("/fraudBatchBaseinfo")
public class FraudBatchBaseinfoController extends BaseController {

    @Autowired
    private FraudBatchBaseinfoService fraudBatchBaseinfoService;

    @PostMapping("/page")
    public RestResult<?> page(@RequestBody PageRequestDto pageRequestDto) {
        return RestResult.ok(fraudBatchBaseinfoService.queryByPage(pageRequestDto));
    }

    @PostMapping("/remove")
    public RestResult<?> remove( String ids, String reasons) {
        fraudBatchBaseinfoService.remove(ids, reasons);
        return RestResult.ok();
    }

    @PostMapping("/add")
    public RestResult<?> add(@RequestBody FraudBatchBaseinfo fraudBatchBaseinfo) {
        return fraudBatchBaseinfoService.add(fraudBatchBaseinfo);
    }

    @RequestMapping(value = "exportExcel")
    public void exportExcel(@RequestBody PageRequestDto pageRequestDto, HttpServletResponse response) throws IOException {
        ServletOutputStream outputStream=null;
        try {
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String("主体名单.xls".getBytes(), "UTF-8"));
            response.setContentType("application/msexcel;charset=UTF-8");
            outputStream = response.getOutputStream();
            fraudBatchBaseinfoService.exportExcel(pageRequestDto, outputStream);
        } catch (IOException e) {
            outputStream.close();
            e.printStackTrace();
        } finally {
            outputStream.close();
        }
    }

}

