package cn.ezhizao.project.business.collection.controller;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.collection.domain.BizCollection;
import cn.ezhizao.project.business.collection.domain.BizCollectionDetail;
import cn.ezhizao.project.business.collection.domain.vo.ReqStatisticsVo;
import cn.ezhizao.project.business.collection.domain.vo.ResStatisticsVo;
import cn.ezhizao.project.business.collection.service.IBizCollectionDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;

import static cn.ezhizao.common.utils.PageUtils.custStartPage;

@RestController
@Api(tags = "收款管理，收款明细表")
@RequestMapping(value = "/business/collectionDetail")
public class BizCollectionDetailController extends BaseController {
    @Resource
    IBizCollectionDetailService collectionDetailService;


    @ApiOperation(value = "带条件List 分页查询", notes = "带条件List 分页查询")
    @PreAuthorize("@ss.hasPermi('business:collectionDetail:list')")
    @RequestMapping ("/DetailList")
    @ResponseBody
    public TableDataInfo getDetailList(@RequestBody BizCollectionDetail collectionDetail) throws NoSuchFieldException, IllegalAccessException {
        setTenantId(collectionDetail);
        custStartPage((Integer) collectionDetail.getParams().get("pageNum"),(Integer)collectionDetail.getParams().get("pageSize"));
        startOrderBy();
        List<BizCollectionDetail> list = collectionDetailService.getDetailList(collectionDetail);
        return getDataTable(list);
    }

    @ApiOperation("导出收款明细")
//    @PreAuthorize("@ss.hasPermi('business:salary:export')")
    @Log(title = "导出收款明细报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody BizCollectionDetail collectionDetail, HttpServletResponse response) throws NoSuchFieldException, IllegalAccessException {
        response.setHeader("Content-Disposition","attachment;filename="+"a.xlsx");
        List<BizCollectionDetail> list = collectionDetailService.getDetailList(collectionDetail);
        ExcelUtil<BizCollectionDetail> util = new ExcelUtil<BizCollectionDetail>(BizCollectionDetail.class);
        util.exportExcel(response, list, "收款明细");
    }
}
