package cn.superdesk.uniorder.controller._statistics;


import cn.superdesk.uniorder.common.enums.login.SysLoginTypeEnum;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.JwtUtil;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dto.param.accounting.statistics.ReceivableStatisticsPageQueryParam;
import cn.superdesk.uniorder.dto.vo._statistics.ReceivableStatisticsPageVo;
import cn.superdesk.uniorder.dto.vo._statistics.payable.PayableStatisticsPageVo;
import cn.superdesk.uniorder.dubbo.consumer.statistics.ReceivableStatisticsDubboService;
import cn.superdesk.uniorder.interceptor.logger.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;


/**
 * @Description: Java类作用描述
 * @Author: qzy
 * @CreateDate: 2021/12/2 下午3:49
 * @UpdateUser: qzy
 * @UpdateDate: 2021/12/2 下午3:49
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Api(value = "应付报表", tags = {"应付报表"})
@Slf4j
@RestController
@RequestMapping("/statistics/payable")
public class PayableStatisticsController extends BaseController {


	@Autowired
	private ReceivableStatisticsDubboService receivableStatisticsDubboService;



	@ApiOperation(value = "应付报表", notes = "应付报表")
	@PostMapping("/getPayableStatisticsPageVoList")
	@ResponseBody
	public R<List<PayableStatisticsPageVo>> getReceivableStatisticsPageVoList(ReceivableStatisticsPageQueryParam queryParam) {


		String token = getToken();

		LoginSysUser loginSysUser = JwtUtil.getLoginSysUser(token);

		if (loginSysUser.getOutLogin().compareTo(SysLoginTypeEnum.福利商城_侨城汇.getKey()) != 0) {
			//return ResponseResultOuterUtils.createErrorResult("500", "商户端专用");
		}


		R<List<PayableStatisticsPageVo>> response = new R<>();

		try {

			response = receivableStatisticsDubboService.getPayableStatisticsPageVoList(queryParam);


		} catch (Exception e) {

			response.setCode(String.valueOf(e.hashCode()));
			response.setSuccess(false);
			response.setMessage(e.getMessage());

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}

		return response;
	}

	/**
	 * @throws IOException
	 */
	@ResponseExcel
	@ApiOperation(value = "导出应付汇总报表", tags = "导出应付汇总报表")
	@RequestMapping(value = "/getPayableStatisExcel", method = RequestMethod.POST)
	public R<String> getPayableStatisExcel(ReceivableStatisticsPageQueryParam queryParam) throws IOException {


//		getScoreOrderReconciliationNotYet additionalInfoGetScoreOrderReconciliationNotYet 已修
		return new R<String>(receivableStatisticsDubboService.getPayableStatisExcel(queryParam,getToken()));


	}
}
