package com.engine.htsc.zgsqs.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.htsc.zgsqs.ZgsqsActionApi;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.zgsqs.service.ZgsqsService;
import com.engine.htsc.zgsqs.service.impl.ZgsqsServiceImpl;
import org.apache.commons.lang.StringUtils;
import weaver.general.BaseBean;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.GlobatTools.RequestJSsonUtil;
import weaver.wechat.util.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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;

/**
 * @ClassName ZgsqsAction
 * @Author K1810015
 * @Date 2022/2/15 13:36
 * Version 1.0
 */
public class ZgsqsAction  {


    private ZgsqsService zgsqsService()
    {
        return ServiceUtil.getService(ZgsqsServiceImpl.class);
    }

    @POST
    @Path("/getLeadRange")
    @Produces({MediaType.APPLICATION_JSON})
    public String getLeadRange(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        JSONObject json=new JSONObject();
        JAVATools.SetCmdwritelog("----UnionSealApplicationAction-----");
        try{
            Map<String,String> value = zgsqsService().getLeadRange(ParamUtil.request2Map(request));

        if(value==null || value.size()<=0){
            return JAVATools.Apiretrun("400","请检查参数");
        }
            json.put("dscbh", Utils.null2String(value.get("dscbh")));
            json.put("ldmc", Utils.null2String(value.get("ldmc")));



            //new JSONObject(value);
           return JAVATools.Apiretrun("200",json);
        }catch (Exception e) {
            //   e.printStackTrace();
            return JAVATools.Apiretrun("400","请检查参数");
        }



    }


    @POST
    @Path("/getldeadwftouserids")
    @Produces({MediaType.APPLICATION_JSON})
    public String getldeadwftouserids(@Context HttpServletRequest request, @Context HttpServletResponse response){


        boolean flag=false;
        JAVATools.SetCmdwritelog("----UnionSealApplicationAction-----");
        try{
            flag = zgsqsService().getleadflowstatus(ParamUtil.request2Map(request));
        }catch (Exception e) {
            //   e.printStackTrace();
            return JAVATools.Apiretrun("400","请检查参数");
        }
        return JAVATools.Apiretrun("200",flag);

    }

    @POST
    @Path("/getDoneWorkcodeOperator")
    @Produces({MediaType.APPLICATION_JSON})
    public String getDoneWorkcodeOperator(@Context HttpServletRequest request, @Context HttpServletResponse response){

        String operator = null;
        JAVATools.SetCmdwritelog("----UnionSealApplicationAction-----");
        try{
            operator = zgsqsService().getOperator(ParamUtil.request2Map(request));
        }catch (Exception e) {
           // e.printStackTrace();
            return JAVATools.Apiretrun("400","请检查参数");
        }
         return JAVATools.Apiretrun("200",operator);

    }

    @POST
    @Path("/getdeptrange")
    @Produces({MediaType.APPLICATION_JSON})
    public String getdeptrange(@Context HttpServletRequest request, @Context HttpServletResponse response){

        boolean flag=false;
        JAVATools.SetCmdwritelog("----UnionSealApplicationAction-----");
        try{

            JSONObject json = RequestJSsonUtil.getRequestJsonObject(request);
            if(json==null || json.size()<=0){
                return JAVATools.Apiretrun("400","请检查参数");
            }
            String bmid=Utils.null2String(json.get("bmid"));
            String jgid=Utils.null2String(json.get("jgid"));
            if(StringUtils.isBlank(bmid) || StringUtils.isBlank(jgid)){
                return JAVATools.Apiretrun("400","请检查参数");
            }
            Map map=new HashMap(2);
            map.put("bmid",bmid);
            map.put("jgid",jgid);
            JSONObject jsonObject= zgsqsService().getdeptrange(map);
            if(jsonObject==null){
                return JAVATools.Apiretrun("400","请检查参数");
            }
            return JAVATools.Apiretrun("200",jsonObject);
        }catch (Exception e) {
            //   e.printStackTrace();
            return JAVATools.Apiretrun("400","请检查参数");
        }
       // return JAVATools.Apiretrun("200",flag);

    }


}
