package com.engine.htsc.general.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.htsc.general.model.GeneralLinkReq;
import com.engine.htsc.general.service.GeneralPaymentLinkService;
import com.engine.htsc.general.service.impl.GeneralPaymentLinkServiceImpl;
import com.engine.htsc.general.service.impl.ItGeneralPaymentLinkServiceImpl;
import com.weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GeneralPaymentLinkController {

    GeneralPaymentLinkService getService(String unumber) {
        if("zbitfk".equals(unumber)) {
            //总部it付款
            return new ItGeneralPaymentLinkServiceImpl();
        }else {
            //总部通用付款
            return new GeneralPaymentLinkServiceImpl();
        }
    }

    @POST
    @Path("/getGeneralSpl")
    @Produces({MediaType.TEXT_PLAIN})
    @Consumes({MediaType.APPLICATION_JSON})
    public String getGeneralSpl(GeneralLinkReq generalLinkReq){
        String unnumber = Util.null2String(generalLinkReq.getUnnumber());
        String unnumbercode = Util.null2String(generalLinkReq.getUnnumbercode());
        JSONArray jsonArray = generalLinkReq.getValue();
        if(jsonArray==null||jsonArray.size()<=0||"".equals(jsonArray)){
            return  JAVATools.Apiretrun("400","参数为空");
        }
        JAVATools.writelog("获取审批链入参: unnumber:"+unnumber+" unnumbercode:"+unnumbercode+" value:"+jsonArray.toJSONString());
        List<Map<String,String>> req = (List<Map<String,String>>) JSONArray.parse(String.valueOf(jsonArray));
        HashMap<String,Object> reqMap = new HashMap();
        reqMap.put("unnumber", unnumber);
        reqMap.put("unnumbercode",unnumbercode);
        reqMap.put("reqMapList",req);
        Map resultMap = this.getService(unnumber).getGeneralSpl(reqMap);
        JSONObject res = (JSONObject) JSONObject.toJSON(resultMap);
        return JAVATools.Apiretrun("200", res);
    }
}
