package com.dhcc.finance.main.controller;

import com.dhcc.finance.main.model.ChroAccountExportParam;
import com.dhcc.finance.main.model.FileUploadRequest;

import java.text.ParseException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dhcc.common.model.CurrencyMeta;
import com.dhcc.common.model.response.RestfulResponse;
import com.dhcc.finance.constant.MsConfigConsts;
import com.dhcc.finance.main.service.FinancialStatementsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
/**
 * 功能描述：财务报表
 * @author dml
 * @date 2019年7月28日 下午3:40:59
 * @修改日志：
 */
@RestController
@RequestMapping(value = MsConfigConsts.MS_API_PREFIX + FinancialStatemenController.API_PREFIX, 
  	          produces = {MediaType.APPLICATION_JSON_UTF8_VALUE }, consumes = { MediaType.APPLICATION_JSON_UTF8_VALUE })
@Api(value = "财务报表controller", tags = { "财务报表" })
public class FinancialStatemenController {
	// 财务对外接口接口地址前缀
	public static final String API_PREFIX = "/financial_statemen";
	
	@Autowired
	FinancialStatementsService financialStatementsService;
	
	/**
	 * 功能描述：初始化报表数据
	 * @param reportDate
	 * @param searchType
	 * @param param
	 * @param reportType
	 * @return RestfulResponse<Object,CurrencyMeta>
	 * @author dml
	 * @date 2019年11月14日 上午9:28:59
	 * @修改日志：
	 */
	@ApiOperation(value = "初始化资产负债表", notes = "初始化资产负债表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE ,consumes = MediaType.ALL_VALUE)
	@ApiImplicitParams({
		@ApiImplicitParam(name = "reportDate", value = "查询时间", required = false, dataType = "String", paramType="query"),
		@ApiImplicitParam(name = "searchType", value = "查询类型", required = false, dataType = "String", paramType="query"),
		@ApiImplicitParam(name = "param", value = "参数值", required = false, dataType = "String", paramType="query"),
		@ApiImplicitParam(name = "reportType", value = "类型", required = false, dataType = "String", paramType="query"),
    }) 
	@RequestMapping(value = "/insertInitBalanceSheet", method = RequestMethod.POST,consumes = MediaType.ALL_VALUE)
	RestfulResponse<Object, CurrencyMeta> createVoucherInfo(String reportDate,String searchType,String param,
			String reportType){
		return financialStatementsService.insertInitBalanceSheet(reportDate,searchType, param, reportType);
	}
	/**
	 * 功能描述：初始化/查询加权信息
	 * @param endDate
	 * @param beginDate
	 * @param isInit
	 * @return RestfulResponse<Object,CurrencyMeta>
	 * @author dml
	 * @date 2020年1月7日 上午9:50:08
	 * @修改日志：
	 */
	@ApiOperation(value = "初始化/查询加权详情", notes = "初始化/查询加权详情", produces = MediaType.APPLICATION_JSON_UTF8_VALUE ,consumes = MediaType.ALL_VALUE)
	@ApiImplicitParams({
		@ApiImplicitParam(name = "endDate", value = "截止时间", required = false, dataType = "String", paramType="query"),
		@ApiImplicitParam(name = "beginDate", value = "开始时间", required = false, dataType = "String", paramType="query"),
		@ApiImplicitParam(name = "isInit", value = "是否初始化", required = false, dataType = "Boolean", paramType="query"),
    }) 
	@RequestMapping(value = "/initJqDetail", method = RequestMethod.POST,consumes = MediaType.ALL_VALUE)
	RestfulResponse<Object, CurrencyMeta> initJqDetail(String endDate,String beginDate,Boolean isInit){
		return financialStatementsService.initJqDetail(endDate,beginDate, isInit);
	}


	/**
	 * @param reportDate
	 * @return com.dhcc.common.model.response.RestfulResponse<java.lang.String,com.dhcc.common.model.CurrencyMeta>
	 * @description: 校验报表数据
	 * @author lxj
	 * @date 2020-07-20 19:24
	 * @modify
	 */
	@ApiOperation(value = "校验报表数据", notes = "", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.ALL_VALUE)
	@RequestMapping(value = { "/checkReport" }, method = RequestMethod.GET, consumes = MediaType.ALL_VALUE)
	public RestfulResponse<String, CurrencyMeta> checkReport(String reportDate){
		return financialStatementsService.checkReport(reportDate);
	}

	/*
	 * Title: exportExcelInfo
	 * Description: 导出资产负债表或利润表数据
	 * @param param
	 * @param reportDate
	 * @param reportType
	 * @param searchType
	 * @return org.springframework.http.ResponseEntity<org.springframework.core.io.FileSystemResource>
	 * @Author jiangyoushun
	 * @Date 2020/7/14 11:36
	 * @修改日志:
	 **/
	@ApiOperation(value = "导出数据", notes = "导出数据", produces = MediaType.APPLICATION_JSON_UTF8_VALUE ,consumes = MediaType.ALL_VALUE)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "reportDate", value = "查询时间", required = false, dataType = "String", paramType="query"),
			@ApiImplicitParam(name = "searchType", value = "查询类型", required = false, dataType = "String", paramType="query"),
			@ApiImplicitParam(name = "param", value = "参数值", required = false, dataType = "String", paramType="query"),
			@ApiImplicitParam(name = "reportType", value = "类型", required = false, dataType = "String", paramType="query"),
	})
	@RequestMapping(value = "/exportExcelInfo", method = RequestMethod.POST,consumes = MediaType.ALL_VALUE)
	public ResponseEntity<FileSystemResource> exportExcelInfo(String param,String reportDate, String reportType,String searchType) {
		return financialStatementsService.exportExcelInfo(param,reportDate, reportType, searchType);
	}

	/*
	 * Title: importExcelInfo
	 * Description: 导入资产负债表或利润表数据
	 * @param fileUploadRequest
	 * @param param
	 * @param reportDate
	 * @param reportType
	 * @param searchType
	 * @return com.dhcc.common.model.response.RestfulResponse<java.lang.Object,com.dhcc.common.model.CurrencyMeta>
	 * @Author jiangyoushun
	 * @Date 2020/7/14 11:37
	 * @修改日志:
	 **/
	@ApiOperation(value = "导入数据", notes = "导入数据", produces = MediaType.APPLICATION_JSON_UTF8_VALUE ,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "reportDate", value = "查询时间", required = false, dataType = "String", paramType="query"),
			@ApiImplicitParam(name = "searchType", value = "查询类型", required = false, dataType = "String", paramType="query"),
			@ApiImplicitParam(name = "param", value = "参数值", required = false, dataType = "String", paramType="query"),
			@ApiImplicitParam(name = "reportType", value = "类型", required = false, dataType = "String", paramType="query"),
	})
	@RequestMapping(value = "/importExcelInfo", method = RequestMethod.POST,consumes =  MediaType.MULTIPART_FORM_DATA_VALUE)
	public RestfulResponse<Object, CurrencyMeta> importExcelInfo(FileUploadRequest fileUploadRequest, String param,String reportDate, String reportType,String searchType) {
		return financialStatementsService.importExcelInfo(fileUploadRequest, param,reportDate, reportType, searchType);
	}
	
	@ApiOperation(value = "序时账数据导出excel", notes = "", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @RequestMapping(value = "/exportChroAccountInfo", method = RequestMethod.POST)
    public ResponseEntity<FileSystemResource> exportChroAccountInfo(
    		@RequestBody ChroAccountExportParam chroAccountExportParam) throws ParseException {
        return financialStatementsService.exportChroAccountInfo(chroAccountExportParam);
    }
}
