<%@ page import="weaver.general.*" %>
<%@page import="weaver.conn.RecordSet"%>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>

<%

    List<Map<String,String>> dataList = new ArrayList<Map<String,String>>();

    RecordSet rs = new RecordSet();
    int days = 30 ;
    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd" ) ;
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy" ) ;

    Map<String,String> dataMap = null;
    for(int i=0;i<days;i++)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, i);
        String currentDay = sdf.format(calendar.getTime()) ;
        out.println("currentDay:"+currentDay+"</br>");

        String currentYear = sdf2.format(calendar.getTime()) ;
        out.println("currentYear:"+currentYear+"</br>");

        String sql =" select k.* from (" +
                    "	select h.id,h.lastname,h.sex,h.companystartdate,h.departmentid,h.subcompanyid1,d.departmentname,s.subcompanyname," +
                    "   datediff(year,h.companystartdate,convert(varchar(50), getdate(), 23)) as rzzn," +
                    "	right(companystartdate,5) startday " +
                    "   from hrmresource h " +
                    "   inner join HrmDepartment d on d.id = h.departmentid " +
                    "   inner join HrmSubCompany s on s.id = h.subcompanyid1 " +
                    "   where right(companystartdate,5) = '"+currentDay+"' " +
                    "   and h.status in(0,1,2,3) " +
                    "   and (h.belongto is null or  h.belongto = -1 )  " +
                    "	and h.companystartdate is not null " +
                    " ) k where k.rzzn > 0 " +
                    " order by k.startday desc " ;


        // out.println("updateAnniversaryWishes-sql:"+sql);

        rs.executeQuery(sql);
        while (rs.next()){
            String userid = Util.null2String(rs.getString("id"));
            String lastname = Util.null2String(rs.getString("lastname"));
            int rzzn = Util.getIntValue(Util.null2String(rs.getString("rzzn")),0);
            String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
            String departmentid = Util.null2String(rs.getString("departmentid"));
            String companystartdate = Util.null2String(rs.getString("companystartdate"));
            String rzyr = Util.null2String(rs.getString("startday"));

            String zfy = getZfy(lastname,rzzn);

            dataMap = new HashMap<String, String>();
            dataMap.put("ry",userid);
            dataMap.put("xm",lastname);
            dataMap.put("zfy",zfy);
            dataMap.put("bm",departmentid);
            dataMap.put("rzrq",companystartdate);
            dataMap.put("rzyr",rzyr);
            dataMap.put("fb",subcompanyid1);
            dataMap.put("nf",currentYear);
            dataMap.put("rzzn",rzzn+"");
            dataList.add(dataMap);
        }
    }
    out.println("updateAnniversaryWishes-dataList1:"+dataList.size()+"</br>");

    for(int i=0;i<days;i++)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_YEAR, 0-i);
        String currentDay = sdf.format(calendar.getTime()) ;
        out.println("currentDay:"+currentDay+"</br>");

        String currentYear = sdf2.format(calendar.getTime()) ;
        out.println("currentYear:"+currentYear+"</br>");

        String sql ="   select k.* from (" +
                "	select h.id,h.lastname,h.sex,h.companystartdate,h.departmentid,h.subcompanyid1,d.departmentname,s.subcompanyname," +
                "   datediff(year,h.companystartdate,convert(varchar(50), getdate(), 23)) as rzzn," +
                "	right(companystartdate,5) startday " +
                "   from hrmresource h " +
                "   inner join HrmDepartment d on d.id = h.departmentid " +
                "   inner join HrmSubCompany s on s.id = h.subcompanyid1 " +
                "   where right(companystartdate,5) = '"+currentDay+"' " +
                "   and h.status in(0,1,2,3) " +
                "   and (h.belongto is null or  h.belongto = -1 )  " +
                "	and h.companystartdate is not null " +
                " ) k where k.rzzn > 0 " +
                " order by k.startday desc " ;


        // out.println("updateAnniversaryWishes-sql:"+sql);

        rs.executeQuery(sql);
        while (rs.next()){
            String userid = Util.null2String(rs.getString("id"));
            String lastname = Util.null2String(rs.getString("lastname"));
            int rzzn = Util.getIntValue(Util.null2String(rs.getString("rzzn")),0);
            String subcompanyid1 = Util.null2String(rs.getString("subcompanyid1"));
            String departmentid = Util.null2String(rs.getString("departmentid"));
            String companystartdate = Util.null2String(rs.getString("companystartdate"));
            String rzyr = Util.null2String(rs.getString("startday"));
            String zfy = getZfy(lastname,rzzn);

            dataMap = new HashMap<String, String>();
            dataMap.put("ry",userid);
            dataMap.put("xm",lastname);
            dataMap.put("zfy",zfy);
            dataMap.put("bm",departmentid);
            dataMap.put("rzrq",companystartdate);
            dataMap.put("rzyr",rzyr);
            dataMap.put("fb",subcompanyid1);
            dataMap.put("nf",currentYear);
            dataMap.put("rzzn",rzzn+"");
            dataList.add(dataMap);
        }
    }

    out.println("updateAnniversaryWishes-dataList2:"+dataList.size()+"</br>");

%>


<%!

    public String getZfy(String lastname,int rzzn){
        String rzzzdx = "" ;

        String zfy =" <div style=\"width: 500px;text-align: left;font-size: 14px !important;\">\n" +
                "    <p class=\"p1\"  style=\"color: #202e7f;font-size: 18px;font-weight: 600;\">亲爱的<span class=\"s1\">"+lastname+"</span>：</p>\n" +
                "    <p class=\"p2\" >&nbsp;</p>\n" +
                "    <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">衷心祝贺您与铭沣同行<span class=\"s1\">"+rzzzdx+"</span>周年快乐！</p>\n" +
                "    <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">感谢您将自己的青春年华和工作热情奉献给了铭沣！</p>\n" +
                "    <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">感谢您辛勤的付出与不懈的跟随与守候，期待我们一起度过下一个周年！</p>\n" +
                "    <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">今天的您是否忙碌在工作岗位上而忽略了这个重要的日子......</p>\n" +
                "    <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">但公司记得您每一份付出和努力！</p>\n" +
                "    <p class=\"p3\" style=\"color: #202e7f;line-height: 30px;\">感谢您的一路相伴，未来我们继续同行!</p>\n" +
                "    <p class=\"p2\">&nbsp;</p>\n" +
                "    <p class=\"p2\">&nbsp;</p>\n" +
                "    <p class=\"p4\" style=\"float: right;color: #202e7f;font-size: 18px;font-weight: 600;\">&nbsp;MATFRON</p>\n" +
                " </div> ";
        return zfy;
    }

%>



