package com.engine.htsc.yfkfyqr.web;

import com.alibaba.fastjson.JSONObject;
import com.api.htsc.browser.HtscBrowserAction;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.yfkfyqr.service.NewYfkByOldTsSrevice;
import com.engine.htsc.yfkfyqr.service.impl.NewYfkTsSreviceImpl;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.workflow.logging.Logger;
import weaver.workflow.logging.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

public class YfkfyqrAvtion {
    Logger logger = LoggerFactory.getLogger(YfkfyqrAvtion.class);

    private NewYfkByOldTsSrevice getService() {
        return ServiceUtil.getService(NewYfkTsSreviceImpl.class);
    }

    /**
     * type:assign---指定、all---所有已归档的托收业务流程
     * 所需配置：
     */
    @POST
    @Path("/createyfkbyoldts")
    @Produces({MediaType.APPLICATION_JSON})
    public String createYfkByOldTs(@Context HttpServletRequest request,
                                   @Context HttpServletResponse response) {
        new BaseBean().writeLog("==================check in Action===================");
        Map<String, Object> result;
        Map<String, Object> paramsMap = new HashMap<>();
        String type = Util.null2String(request.getParameter("type"));
        paramsMap.put("type", type);
        if (!"all".equals(type)) {
            paramsMap.put("requestids", request.getParameter("requestids"));
        }
        new BaseBean().writeLog("传给service的接口是：" + paramsMap);
        result = getService().createTfkByOldTS(paramsMap);
        return JSONObject.toJSONString(result);
    }


    /**
     * 收款单位/开票方：取付款流程-支付信息-收款单位&关联已办结预付款确认流程中票据信息销方名称（匹配去重时，需要考虑特殊符号“括号”格式的兼容）；
     * 预付款金额：取付款流程-支付信息-收款单位对应合计金额汇总；
     * 已核销金额：取关联已办结预付款确认流程中票据信息-销方名称对应价税合计金额/开票金额汇总；
     * 待核销金额：预付款金额-已核销金额；
     *
     * @param request
     * @return
     */
    @GET
    @Path("/viewDetail")
    @Produces({MediaType.APPLICATION_JSON})
    public String viewDetail(@Context HttpServletRequest request) {
        Logger logger = LoggerFactory.getLogger(this.getClass());
        String requestid = request.getParameter("requestid");
        logger.info("进入详情查询接口，接收到的原付款流程requestid是：" + requestid);
        return JSONObject.toJSONString(getService().viewDetailService(requestid));

    }

    /**
     * 预付款建模页面点击触发手动触发预付款
     */
    @POST
    @Path("/manualPrepayments")
    @Produces({MediaType.APPLICATION_JSON})
    public String manualPrepayments(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        logger.info("================进入手动触发预付款方法======================");
        String yfkTableName = new PropBean().getPropName("yfkTableName");
        String requestIds = Util.null2String(request.getParameter("requestIds"));
        Map<String, Object> params = new HashMap<>();
        params.put("requestIds", requestIds);
        params.put("yfkTableName", yfkTableName);
        logger.info("即将传递的参数是：" + JSONObject.toJSONString(params));
        Map<String, Object> result = getService().manualPrepayments(params);
        return JSONObject.toJSONString(result);
    }
}
