package com.engine.htsc.fundbusinesspay.web;

import com.engine.common.util.ServiceUtil;
import com.engine.htsc.fundbusinesspay.service.FundBusinessService;
import com.engine.htsc.fundbusinesspay.service.impl.FundBusinessServiceImpl;
import com.engine.htsc.fundbusinesspay.utils.FundBizUtil;
import com.engine.htsc.trip.util.AjaxResult;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Map;

public class FundBusinessPayAction {

	public FundBusinessService getService() {
		return ServiceUtil.getService(FundBusinessServiceImpl.class);
	}

	/**
	 * 付款明细预算科目带出会计明细会计科目
	 *
	 * @param budgetCode 预算code
	 * @return aja
	 */
	@GET
	@Path("/getKjBrowser")
	@Produces(MediaType.APPLICATION_JSON)
	public AjaxResult<String> getBrowserValue(@QueryParam("budgetCode") String budgetCode) {
		try {
			String browserValue = this.getService().getKjBrowserValue(budgetCode);
			return AjaxResult.ok(browserValue);
		} catch (Exception e) {
			return AjaxResult.error(e.getMessage());
		}

	}

	/**
	 * 资金业务付款生成流程编号
	 *
	 * @return 字符串
	 */
	@POST
	@Path("/createRequestMark")
	@Produces(MediaType.APPLICATION_JSON)
	public AjaxResult<String> createFundBusinessPayRequestMark() {
		try {
			FundBizUtil fbu = new FundBizUtil();
			String fundBusinessPayRequestMark = fbu.createFundBusinessPayRequestMark();
			return AjaxResult.ok(fundBusinessPayRequestMark);
		} catch (Exception e) {
			return AjaxResult.error(e.getMessage());
		}

	}

	/**
	 * 付款日期范围
	 *
	 * @return 拟稿日期 +5个工作日
	 */
	@GET
	@Path("/getPayDateRange")
	@Produces(MediaType.APPLICATION_JSON)
	public AjaxResult<Map<String, String>> getPaymentDateRange(@QueryParam("startDate") String startDate) {
		try {
			Map<String, String> dateRange = this.getService().getPaymentDateRange(startDate);
			return AjaxResult.ok(dateRange);
		} catch (Exception e) {
			return AjaxResult.error(e.getMessage());
		}

	}
}
