package cn.com.countrygarden.bi.main.controller.ck;

import cn.com.countrygarden.bi.main.controller.BaseController;
import cn.com.countrygarden.bi.main.core.Result;
import cn.com.countrygarden.bi.main.dto.ck.CkPublicBenefitsZationVo;
import cn.com.countrygarden.bi.main.model.ck.CkPublicBenefitsZation;
import cn.com.countrygarden.bi.main.service.ck.CkPublicBenefitsZationService;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * <p>
 *   公共收益初始化数据表模块接口
 * </p>
 *
 * @author 吕伟峰
 * @date 2021-05-07
 * @version V1.0
 */
@RestController("CkPublicBenefitsZationController")
@RequestMapping("/api/ckPublicZation")
public class CkPublicBenefitsZationController extends BaseController {
    @Autowired
    private CkPublicBenefitsZationService ckPublicBenefitsZationService;


    @GetMapping(value = "/list", produces = "application/json;charset=utf-8")
    public Result list(CkPublicBenefitsZation ckPublicBenefitsZation,
                       @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                       HttpServletRequest request) {
        return ckPublicBenefitsZationService.queryPageList(ckPublicBenefitsZation,size,page,getAccessToken(request));
    }

    @GetMapping(value = "/listChcki", produces = "application/json;charset=utf-8")
    public Result listChcki(CkPublicBenefitsZation ckPublicBenefitsZation,
                       HttpServletRequest request) {
        return ckPublicBenefitsZationService.listChcki(ckPublicBenefitsZation,getAccessToken(request));
    }

    @PostMapping(value = "/addZation")
    public Result addZation(CkPublicBenefitsZation ckPublicBenefitsZation, HttpServletRequest request) throws ParseException {
        return ckPublicBenefitsZationService.addZation(ckPublicBenefitsZation,getAccessToken(request));
    }

    @PostMapping(value = "/editZation")
    public Result editZation(CkPublicBenefitsZation ckPublicBenefitsZation, HttpServletRequest request) throws ParseException {
        return ckPublicBenefitsZationService.editZation(ckPublicBenefitsZation,getAccessToken(request));
    }


    @GetMapping(value = "/one", produces = "application/json;charset=utf-8")
    public Result one(CkPublicBenefitsZation ckPublicBenefits,
                       HttpServletRequest request) {
        return ckPublicBenefitsZationService.one(ckPublicBenefits,getAccessToken(request));
    }

    @GetMapping(value = "/oneExhibition", produces = "application/json;charset=utf-8")
    public Result oneExhibition(CkPublicBenefitsZation ckPublicBenefits,
                      HttpServletRequest request) {
        return ckPublicBenefitsZationService.oneExhibition(ckPublicBenefits,getAccessToken(request));
    }

    @GetMapping(value = "/oneZationAd", produces = "application/json;charset=utf-8")
    public Result oneZationAd(CkPublicBenefitsZation ckPublicBenefits,
                      HttpServletRequest request) {
        return ckPublicBenefitsZationService.oneZationAd(ckPublicBenefits,getAccessToken(request));
    }
    @PostMapping(value = "/addOrEdit")
    public Result addOrEdit(CkPublicBenefitsZation ckPublicBenefits,
                            HttpServletRequest request) throws ParseException {
        return ckPublicBenefitsZationService.addOrEdit(ckPublicBenefits, getAccessToken(request));
    }

    //导出
    @GetMapping(value = "/exportEntered", produces = "multipart/form-data")
    public void exportEntered(CkPublicBenefitsZation ckPublicBenefits){
       List<CkPublicBenefitsZationVo> zationVoList=ckPublicBenefitsZationService.listExport(ckPublicBenefits,getAccessToken());

        ExportParams params = new ExportParams("公共收益期初值", "公共收益期初值", ExcelType.XSSF);
        XSSFWorkbook workbook = (XSSFWorkbook) ExcelExportUtil.exportExcel(params, CkPublicBenefitsZationVo.class, zationVoList);

        downloadExcelData(workbook, "公共收益期初值");
    }

}