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.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810027
 * @version: 1.0
 * @CreateDate: 2022-08-24 16:07
 * @Description:采购相关接口
 * @ModifyLog:
 **/
public class GetWorkflowShqAjax {
    @GET
    @Path("/getWorkflowShqAjax")
    @Produces({MediaType.TEXT_PLAIN})
    public String getWorkflowShqAjax(@Context HttpServletRequest request, @Context HttpServletResponse response){
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        BaseBean bb = new BaseBean();
        HashMap<String, Object> map = new HashMap<String, Object>();
        int formid = Math.abs(Util.getIntValue( request.getParameter( "formid" ) ));//请求ID
        int requestid = Util.getIntValue( request.getParameter( "requestid" ) );
        JSONObject json = new JSONObject();
        String tablename = "formtable_main_".concat( formid+"");
        rs.executeQuery( " select id from " + tablename + " where requestid ='" + requestid + "'" );
        rs.next();
        String mainid = Util.null2String( rs.getString( "id" ) );//mainid
        rs1.executeQuery( " select bmfzr from " + tablename + "_dt2 where mainid ='" + mainid + "'" );

        List<String> list1 = new ArrayList<>();
        List<String> list2= new ArrayList<>();

        while (rs1.next()) {
            String bmfzr = Util.null2String( rs1.getString( "bmfzr" ) );//部门负责人
            if(!"".equals(bmfzr) && bmfzr !=null){
                list1.add(bmfzr);
            }
        }

        rs.executeQuery("select operatorids from workflow_freenode where requestid = '"+requestid+"'");
        while (rs.next()){
            String operatorids = Util.null2String(rs.getString("operatorids"));
            if(!"".equals(operatorids) && operatorids !=null){
                list2.add(operatorids);
            }
        }
        int count = 0;
        if (list2.containsAll(list1)){
            count = 1;
        }
//        json.put("count",count);
        map.put("code",200);
        map.put("msg","SUCCESS");
        map.put("data",count);
        bb.writeLog( "getworkflow_shq_Ajax=================json:" + JSONObject.toJSONString(map));
//        out.print( json.toJSONString() );
        return JSONObject.toJSONString(map);
    }
}
