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:17
 * @Description: 采购相关接口
 * @ModifyLog:
 **/
public class GetSyfwSblxAjax {

    @GET
    @Path("/getSyfwSblxAjax")
    @Produces({MediaType.TEXT_PLAIN})
    public String getSyfwSblxAjax(@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" ) );//拟稿人
        String sblb = Util.null2String( request.getParameter( "sblb" ) );//申报类别
        JSONObject json = new JSONObject();

        //szbm = szbm.replace("'","','");
        //ngr = ngr.replace("'","','");

        String sblx = "";

        String sql =" select sblx as id from uf_zysxsyfw where sblb='"+sblb+"' " +
                " and ((to_char(ngr) is null and to_char(ngbm) is null) " +
                " or (instr(','||ngbm||',','"+szbm+"')>0 ) "+
                " or (instr(','||ngr||',','"+ngr+"')>0 ) ) ";
        rs.executeQuery(sql);
        bb.writeLog(sql);
        while (rs.next()) {
            String id = Util.null2String( rs.getString( "id" ) );//申请类别
            sblx += sblx ==""? id : ","+id ;//自由节点
        }

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