package com.engine.htsc.generaltrip.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.branch.approvalChain.model.BranchLinkReq;
import com.engine.htsc.generaltrip.model.GeneralTripReq;
import com.engine.htsc.generaltrip.service.GeneralTripLinkService;
import com.engine.htsc.generaltrip.service.impl.GeneralTripLinkServiceImpl;
import com.weaver.general.Util;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GeneralTripLinkController {

    GeneralTripLinkService getService() {
        return ServiceUtil.getService(GeneralTripLinkServiceImpl.class);
    }

    @POST
    @Path("/getGeneralTripSpl")
    @Produces({MediaType.TEXT_PLAIN})
    @Consumes({MediaType.APPLICATION_JSON})
    public String getGeneralTripSpl(GeneralTripReq generalTripReq){
        String unnumber = Util.null2String(generalTripReq.getUnnumber());
        String unnumbercode = Util.null2String(generalTripReq.getUnnumbercode());
        JSONArray jsonArray = generalTripReq.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);
        JSONObject res = this.getService().getGeneralTripSplDetail(reqMap);
        return JAVATools.Apiretrun("200", res);
    }

}
