<%@ page import="java.net.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="weaver.hrm.resource.ResourceComInfo" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%
    String billid = request.getParameter("billid");
    out.print("请求的billid:"+billid+"</br>");
    RecordSet rs = new RecordSet();
    BaseBean bb = new BaseBean();
    ResourceComInfo resourceComInfo = null;
    try{
        resourceComInfo = new ResourceComInfo();

        if(StringUtils.isNotBlank(billid)){
            String ywlx = ""; //0:政保类、1:商业类
            String proname = "";
            String sql =" select ywlx,proname from uf_threebatches where id="+billid+" ";
            rs.executeQuery(sql);
            if(rs.next()){
                ywlx = Util.null2String(rs.getString("ywlx"));
                proname = Util.null2String(rs.getString("proname"));
            }
            String citycom = "";
            if("0".equals(ywlx)){

                // 政保类 50w以上的
                sql =" select id,citycom,modedatacreater from uf_threebatches where id="+billid+" and proamout > 50 and sfcj = 1 ";
                rs.executeQuery(sql);
                if(rs.next()){
                    citycom = Util.null2String(rs.getString("citycom"));
                }

                if(StringUtils.isNotBlank(citycom)){
                    Set<String> userSet = new HashSet<String>();
                    String lastname = "";
                    sql = " select resourceid from hrmrolemembers where roleid = 29570 and resourcetype=1 and resourceid in(select id from hrmresource where subcompanyid1 in("+citycom+"))" ;
                    rs.executeQuery(sql);
                    out.print("查找角色:三个一批项目经理[29570]中的人员的分部为表单[立项市公司]的:"+sql+"</br>");
                    while (rs.next()){
                        String resourceid = Util.null2String(rs.getString("resourceid"));
                        userSet.add(resourceid);

                        lastname += resourceComInfo.getLastname(resourceid)+",";

                    }
                    if(userSet.size() > 0){
                        String context = "请及时维护"+proname+"的落地情况";
                        String title = "三个一批项目提醒";
                        out.print("建模ID:"+billid+" ,项目:"+proname+" ,政保类项目 ,项目金额 > 50 ,提醒标题:"+title+" ,提醒内容:"+context+" ,提醒人:"+lastname+"("+userSet.toString()+")</br>");
                    }
                }

                // 政保类 100w以上的
                int count = 0 ;
                sql =" select id,citycom,modedatacreater from uf_threebatches where id="+billid+" and proamout > 100 and sfcj = 1 ";
                rs.executeQuery(sql);
                if(rs.next()){
                    count++;
                }
                if(count > 0){
                    Set<String> userSet = new HashSet<String>();
                    String lastname = "";
                    sql =   " select resourceid \n" +
                            " from hrmrolemembers " +
                            " where roleid = 29570 " +
                            " and resourcetype=1 \n" +
                            " and resourceid in(\n" +
                            "    select id from hrmresource where departmentid in(\n" +
                            "        select t.id \n" +
                            "        from hrmdepartment t\n" +
                            "        inner join hrmsubcompany k on k.id = t.subcompanyid1\n" +
                            "        where k.subcompanycode='33000000'\n" +
                            "        and nvl(t.canceled,0)=0\n" +
                            "    )\n" +
                            " ) " ;
                    out.print("查找角色:三个一批项目经理[29570]中的人员的分部为总部的:"+sql+"</br>");
                    rs.executeQuery(sql);
                    while (rs.next()){
                        String resourceid = Util.null2String(rs.getString("resourceid"));
                        userSet.add(resourceid);

                        lastname += resourceComInfo.getLastname(resourceid)+",";
                    }

                    if(userSet.size() > 0){
                        String context = "请及时维护"+proname+"的落地情况";
                        String title = "三个一批项目提醒";
                        out.print("建模ID:"+billid+" ,项目:"+proname+" ,政保类项目 ,项目金额 > 100 ,提醒标题:"+title+" ,提醒内容:"+context+" ,提醒人:"+lastname+"("+userSet.toString()+")</br>");
                    }
                }

            }else if("1".equals(ywlx)){
                // 商业类 100w以上的
                sql =" select id,citycom,modedatacreater from uf_threebatches where id="+billid+" and proamout > 100 and sfcj = 1 ";
                rs.executeQuery(sql);
                if(rs.next()){
                    citycom = Util.null2String(rs.getString("citycom"));
                }
                if(StringUtils.isNotBlank(citycom)){
                    Set<String> userSet = new HashSet<String>();

                    String lastname = "";

                    sql = " select resourceid from hrmrolemembers where roleid = 29570 and resourcetype=1 and resourceid in(select id from hrmresource where subcompanyid1 in("+citycom+"))" ;
                    out.print("查找角色:三个一批项目经理[29570]中的人员的分部为表单[立项市公司]的:"+sql+"</br>");
                    rs.executeQuery(sql);
                    while (rs.next()){
                        String resourceid = Util.null2String(rs.getString("resourceid"));
                        userSet.add(resourceid);

                        lastname += resourceComInfo.getLastname(resourceid)+",";
                    }

                    if(userSet.size() > 0){
                        String context = "请及时维护"+proname+"的落地情况";
                        String title = "三个一批项目提醒";
                        out.print("建模ID:"+billid+" ,项目:"+proname+" ,商业类项目 ,项目金额 > 100 ,提醒标题:"+title+" ,提醒内容:"+context+" ,提醒人:"+lastname+"("+userSet.toString()+")</br>");
                    }
                }

                int count = 0 ;
                sql =" select id,citycom,modedatacreater from uf_threebatches where id="+billid+" and proamout > 150 and sfcj = 1 ";
                rs.executeQuery(sql);
                if(rs.next()){
                    count++;
                }
                if(count > 0){
                    String lastname = "";
                    Set<String> userSet = new HashSet<String>();
                    sql =   " select resourceid \n" +
                            " from hrmrolemembers " +
                            " where roleid = 29570 " +
                            " and resourcetype=1 \n" +
                            " and resourceid in(\n" +
                            "    select id from hrmresource where departmentid in(\n" +
                            "        select t.id \n" +
                            "        from hrmdepartment t\n" +
                            "        inner join hrmsubcompany k on k.id = t.subcompanyid1\n" +
                            "        where k.subcompanycode='33000000'\n" +
                            "        and nvl(t.canceled,0)=0\n" +
                            "    )\n" +
                            " ) " ;

                    out.print("查找角色:三个一批项目经理[29570]中的人员的分部为总部的:"+sql+"</br>");
                    rs.executeQuery(sql);
                    while (rs.next()){
                        String resourceid = Util.null2String(rs.getString("resourceid"));
                        userSet.add(resourceid);

                        lastname += resourceComInfo.getLastname(resourceid)+",";
                    }
                    if(userSet.size() > 0){
                        String context = "请及时维护"+proname+"的落地情况";
                        String title = "三个一批项目提醒";
                        out.print("建模ID:"+billid+" ,项目:"+proname+" ,商业类项目 ,项目金额 > 150 ,提醒标题:"+title+" ,提醒内容:"+context+" ,提醒人:"+lastname+"("+userSet.toString()+")</br>");
                    }
                }
            }
        }else{
            out.print("请求的billid为空</br>");
        }
    }catch (Exception e){
        bb.writeLog("e:"+e+"</br>");
    }
%>
