package com.engine.htxc.tycgsq.web;

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;

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

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810027
 * @version: 1.0
 * @CreateDate: 2022-08-24 17:02
 * @Description:
 * @ModifyLog:
 **/
public class GetRequestTypeAjax {

    @GET
    @Path("/getRequestTypeAjax")
    @Produces({MediaType.TEXT_PLAIN})
    public String getRequestTypeAjax(@Context HttpServletRequest request, @Context HttpServletResponse response){
        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        HashMap<String, Object> map = new HashMap<>();
        String szbm = Util.null2String( request.getParameter( "szbm" ) );//所在部门
        String ngr = Util.null2String( request.getParameter( "ngr" ) );//拟稿人
        JSONObject json = new JSONObject();

        String sblb = "" ;
//	String sql =" select sblb as id from ( "+
//                "   select sblb from uf_zysxsyfw where " +
//                "   (to_char(ngr) is null and to_char(ngbm) is null) or"+
//                "   (to_char(ngr) is null and to_char(ngbm) ='"+szbm+"') or"+
//                "   (to_char(ngr) ='"+ngr+"' and to_char(ngbm) is null " +
//                " ) group by sblb order by sblb) ";

        String sql =" select sblb as id\n" +
                "  from (select sblb\n" +
                "          from uf_zysxsyfw \n" +
                "         where ( to_char(ngr) is null and to_char(ngbm) is null )\n" +
                "            or ( to_char(ngr) is null and instr(','||to_char(ngbm)||',',',"+szbm+",') > 0 )\n" +
                "            or ( to_char(ngbm) is null and instr(','||to_char(ngr)||',',',"+ngr+",') > 0 )\n" +
                "         group by sblb\n" +
                "         order by sblb" +
                " ) \n " ;

        rs.executeQuery(sql);
        bb.writeLog(sql);
        while (rs.next()) {
            String id = Util.null2String( rs.getString( "id" ) );//申请类别
            sblb += sblb ==""? id : ","+id ;//自由节点
        }

//        json.put( "sblb", sblb );
        map.put("data",sblb);
        map.put("code",200);
        map.put("msg","SUCCESS");
        bb.writeLog( "getRequestType_Ajax=================json:" + JSONObject.toJSONString(map) );
//        out.print( json.toJSONString() );
        return JSONObject.toJSONString(map);
    }
}
