package com.engine.htxc.tycgsq.web;

import com.alibaba.fastjson.JSONArray;
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:28
 * @Description:采购相关接口
 * @ModifyLog:
 **/
public class GetNbshryAjax {
    @GET
    @Path("/getNbshryAjax")
    @Produces({MediaType.TEXT_PLAIN})
    public String getNbshryAjax(@Context HttpServletRequest request, @Context HttpServletResponse response){
        HashMap<String, Object> map = new HashMap<>();
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        String szbm = Util.null2String( request.getParameter( "szbm" ) );//所在部门
        //String ngr = Util.null2String( request.getParameter( "ngr" ) );//拟稿人
        //String sblb = Util.null2String( request.getParameter( "sblb" ) );//申报类别

        JSONArray arr = new JSONArray();
        JSONObject data = new JSONObject();

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

        String value = "";

        String sql ="select * from uf_lcgwry where jg = "+szbm+"  and xzlc = 'zbzysx'";
        rs.executeQuery(sql);
        RecordSet hrRs = new RecordSet();
        bb.writeLog(sql);
        while (rs.next()) {
            String ry = Util.null2String( rs.getString( "ry" ) );//人员
            value += value ==""? ry : ","+ry ;
            String hrSql = "select * from hrmresource where id = " + ry;
            hrRs.executeQuery(hrSql);
            hrRs.next();
            String name = Util.null2String( hrRs.getString( "LASTNAME" ) ) ;
            JSONObject json = new JSONObject();
            json.put( "id", ry );
            json.put( "name", name );
            arr.add(json);
        }
        data.put("value",value);
        data.put("specialobj",arr);
        map.put("code",200);
        map.put("msg","SUCCESS");
        map.put("data",data);

        bb.writeLog( "getRequestType_Ajax=================json:" + JSONObject.toJSONString(map) );
//        out.print( data.toJSONString() );
        return JSONObject.toJSONString(map) ;
    }
}
