ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

计算员工的年假天数

2022-07-10 16:35:38  阅读:185  来源: 互联网

标签:&& isDate String double valueOf 员工 dataService 计算 天数


1.通过在职位天数和职位等级,得出年总天数

1.jsp

                <tr>
                    <th scope="col" width="1%">Formula</th>
                    <th scope="col" width="1%">Service Year</th>
                    <th width="12%">JobGrade</th>
                    <th scope="col" width="10%">Period From</th>
                    <th scope="col" width="10%">Periond To</th>
                    <th scope="col" width="8%">Entitlement</th>
                    <th scope="col" width="8%">Acutual</th>
                    <th scope="col" width="25%">Taken</th>
                    <th scope="col" width="25%"></th>
                </tr>
                <%
                    for (int i = 0; i < jobgrades.size(); i++) {
                        Map map = (Map) jobgrades.get(i);
                        String nyear1 = StringHelper.null2String(map.get("nyear"));
                        String bdate = StringHelper.null2String(map.get("bdate"));               //职级开始日期
                        String edate = StringHelper.null2String(map.get("edate"));               //职级结束日期
                        String serviceyear = StringHelper.null2String(map.get("serviceyear"));   //已在职年数
                        String jobgrade1 = StringHelper.null2String(map.get("jobgrade"));        //职级

                        if (StringHelper.isNotEmpty(quitdate)){
                            if ((isDate(quitdate)>=isDate(bdate)) && (isDate(quitdate)<=isDate(edate))){
                                edate=quitdate;
                            }
                        }

                        String zhijidays = zhijidays(serviceyear, jobgrade1);
                        String value = dataService.getValue(zhijidays);

                        int nyear = Integer.valueOf(nyear1);
                        int yeardays = 365;
                        if (nyear % 4 == 0 && nyear % 100 != 0 || nyear % 400 == 0) {
                            yeardays = 366;
                        }
                        double Acutual = 0;
                        Acutual =((addDays(edate) - addDays(bdate) + 1) / yeardays) * Integer.valueOf(value);

                %>
                <tr>
                    <td scope="row"><%=nyear%>
                    </td>
                    <td scope="row"><%=serviceyear%>
                    </td>
                    <td scope="row"><%=jobgrade1%>
                    </td>
                    <td scope="row"><%=bdate%>
                    </td>
                    <td scope="row"><%=edate%>
                    </td>
                    <td scope="row"><%=value%>
                    </td>
                    <td scope="row"><%=math(Acutual)%>
                    </td>
                    <td scope="row">
                        <%
                            if (i==jobgrades.size()-1){
                        %>
                        <%=math(TakenSum)%>
                        <%}%>
                    </td>
                    <td scope="row"></td>
                </tr>
                <%
                        if (StringHelper.isNotEmpty(quitdate)){
                            if ((isDate(quitdate)>=isDate(bdate)) && (isDate(quitdate)<=isDate(edate))){
                                break;
                            }
                        }
                    } %>

2.获取对应职级的年假天数

/**
     * 获取对应职级的年假天数
     */
    public String zhijidays(String service, String job) {
        Integer intservice = Integer.valueOf(service);
        String dayssql = "";
        if (intservice <= 1) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=0 " +
                    " and field001='" + name(job) + "'";
        } else if (intservice > 1 && intservice <= 3) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=1 " +
                    " and field001='" + name(job) + "'";
        } else if (intservice > 3 && intservice <= 10) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=3 " +
                    " and field001='" + name(job) + "'";
        } else if (intservice > 10) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=10 " +
                    " and field001='" + name(job) + "'";
        }
        return dayssql;
    }

3.职级名称与id相互转化

 /**
     * 职级名称与id相互转化
     */
    public String name(String name) {
//        DataService dataService = (DataService) BaseContext.getBean(request, "dataService");
//        String sql="SELECT id,objdesc FROM selectitem WHERE typeid = '2c923daf73e3322e0173e863c72f083e'";
//        List values = dataService.getValues(sql);
//        for (int i=0;i<values.size();i++){
//            Map map = (Map) values.get(i);
//            String ids = StringHelper.null2String(map.get("id"));
//            String objdesc = StringHelper.null2String(map.get("objdesc"));
//            System.out.println(ids+"==============================="+objdesc);
//        }
        if (name.equals("1")) {
            return "2c923daf73e3322e0173e87e327c0861";
        } else if (name.equals("2")) {
            return "2c923daf73e3322e0173e87e327c0862";
        } else if (name.equals("3")) {
            return "2c923daf73e3322e0173e87e327c0863";
        } else if (name.equals("4")) {
            return "2c923daf73e3322e0173e87e327c0864";
        } else if (name.equals("5")) {
            return "2c923daf73e3322e0173e87e327c0865";
        } else if (name.equals("6")) {
            return "2c923daf73e3322e0173e87e327c0866";
        } else if (name.equals("7")) {
            return "2c923daf73e3322e0173e87e327c0867";
        } else if (name.equals("8")) {
            return "2c923daf73e3322e0173e87e327c0868";
        } else if (name.equals("9")) {
            return "2c923daf73e3322e0173e87e327c0869";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0861")) {
            return "1";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0862")) {
            return "2";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0863")) {
            return "3";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0864")) {
            return "4";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0865")) {
            return "5";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0866")) {
            return "6";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0867")) {
            return "7";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0868")) {
            return "8";
        } else {
            return "9";
        }
    }

4.获取一年中每个职级对应的年假数

/**
     * 获取一年中每个职级对应的年假数
     */
    public double everyzhiji(String nyear1,String bdate,String edate,String value){
        int nyear = Integer.valueOf(nyear1);
        int yeardays = 365;
        if (nyear % 4 == 0 && nyear % 100 != 0 || nyear % 400 == 0) {
            yeardays = 366;
        }
        double Acutual = ((addDays(edate) - addDays(bdate)+1) / yeardays) * Integer.valueOf(value);
        return Acutual;
    }

5.获取对应日期的天数

/**
     * 获取对应日期的天数
     * @param date
     * @return
     */
    private double addDays(String date) {
        Date date1 = null;
        try {
            date1 = new SimpleDateFormat("yyyy-MM-dd").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdf1 = new SimpleDateFormat("MM");
        SimpleDateFormat sdf2 = new SimpleDateFormat("dd");
        double year = Double.valueOf(sdf0.format(date1)); //年
        double month = Double.valueOf(sdf1.format(date1)); //月
        double days = Double.valueOf(sdf2.format(date1)); //日

        //定义数组,这里2月的天数取28,假设是平年。
        int[] Day = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        //如果是闰年,那么2月应该有29天。
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            Day[1] = 29;
        }
        double sum = 0;
        for (int i = 0; i < month - 1; i++) {
            sum += Day[i];
        }
        return sum + days;
    }

 

最后整一个jsp

<%@page import="com.velcro.license.LicenseCenter" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="/vbase/init.jsp" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.velcro.base.DataService" %>
<%@ page import="com.velcro.workflow.workflow.service.WorkflowbaseService" %>
<%@ page import="com.velcro.workflow.workflow.model.Workflowbase" %>
<%@ page import="com.velcro.base.util.StringHelper" %>
<%@ page import="com.velcro.humres.base.service.HumresService" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="com.velcro.kernel.humres.base.service.IHumresService" %>
<%@ page import="com.velcro.kernel.base.IDataService" %>
<%@ page import="java.text.ParseException" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="com.sun.tools.jdi.ReferenceTypeImpl" %>
<%@ page import="com.velcro.workflow.pipe.service.ExtendJspService" %>
<%@ page import="com.velcro.workflow.AbstractWorkflowService" %>

<%
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar today = Calendar.getInstance();
    //String Year= String.valueOf(today.get(Calendar.YEAR));
    //String lastYear=String.valueOf(today.get(Calendar.YEAR)-1);
    //  String lastYear=sdf.format();

    DataService dataService = (DataService) BaseContext.getBean(request, "dataService");
    String selectDate = StringHelper.null2String(request.getParameter("selectDate"));
    String lidate = StringHelper.null2String(request.getParameter("lidate"));
    String action = StringHelper.null2String(request.getParameter("lidateaction"));
    System.out.println("action"+action);
    IHumresService humresService = (IHumresService) BaseContext.getBean(request, "humresService");
    String humresid = StringHelper.null2String(request.getParameter("humresid"));
    if (humresid.equals("")) {
        humresid = currentuser.getId();
    }

    if (StringHelper.isNotEmpty(lidate)){
        String quitdateNum=dataService.getValue("select count(*) from quitdate where humresid='"+humresid+"'");
        if (quitdateNum.equals("0")){
            dataService.executeSql("insert into quitdate(id,humresid,date) values(replace(uuid(),'-',''),'"+humresid+"','"+lidate+"')");
        }else {
            dataService.executeSql("update quitdate set date='"+lidate+"' where humresid='"+humresid+"'");
        }
    }

    if (StringHelper.isEmpty(lidate) && action.equals("qc")){
        dataService.executeSql("delete from quitdate where humresid='"+humresid+"'");
    }
//    String quitdate=dataService.getValue("select count(*) from quitdate where humresid='"+humresid+"'");

    String quitdate=dataService.getValue("select date from quitdate where humresid='"+humresid+"'");
    System.out.println("quitdate"+quitdate);

    IHumres humres = (IHumres) humresService.getHumresById(humresid);
    String humresname = humres.getObjname();


    if (selectDate.equals("")) {
        selectDate = sdf.format(today.getTime());
    }
    //Integer.parseInt(selectDate.subString(0,4))-1;
    String year = String.valueOf(Integer.parseInt(selectDate.substring(0, 4)));
    String yeah = selectDate.substring(0, 4);
    String lastyear = String.valueOf(Integer.parseInt(selectDate.substring(0, 4)) - 1);
    String beforlastyear = String.valueOf(Integer.parseInt(selectDate.substring(0, 4)) - 2);
    System.out.println("year====" + year + "beforlastyear===" + beforlastyear + "====lastyear=====" + lastyear);

%>
<html>
<head>
    <script src="/vjs/base/InputMsg.js" type="text/javascript"></script>
    <script src="/vjs/base/DataHelper.js" type="text/javascript"></script>
    <script src="/vjs/functions.js" type="text/javascript"></script>
    <script src="/js/browser.js" type="text/javascript"></script>
    <script src="/vjs/selectitemjs.js" type="text/javascript"></script>
    <script language="JScript.Encode" src="/vjs/rtxint.js"></script>
    <script language="JScript.Encode" src="/vjs/browinfo.js"></script>
    <script src="/public/vendor/layer/layer.min.js"></script>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script language="JScript.Encode" src="/vjs/rtxint.js"></script>
    <link rel="stylesheet" type="text/css" href="/vcss/report/tables.css">
    <script src="/vjs/base/Validator.js" type="text/javascript"></script>
    <!-- JQuery -->
    <script type="text/javascript" src="/vjs/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/vjs/jquery/jquery.migrate.min.js"></script>
    <!-- JQuery EasyUI -->
    <script type="text/javascript" src="/vjs/jquery-easyui/jquery.easyui.min.js"></script>
    <!--<script type="text/javascript" src="/vjs/init/portalLoader.js"></script>-->
</head>
<body>

<form name="VelcroForm" id="VelcroForm" aciton="">
    <div class="bBac" style="margin-left:3%;">
        <tr>
            <button id="button_wb-search" class="btn btn-primary ladda-button" onclick="onSubmit()" type="button">
                <span class="ladda-label">搜索</span></button>
            <button id="button_wb-search1" class="btn btn-primary ladda-button" onclick="daying()" type="button" target="_blank">
                <span class="ladda-label">打印</span></button>
            <%
                if (currentuser.getId().equals("5a91c68456c08fad0156c4aba61e0056") || currentuser.getId().equals("402881e70be6d209010be75668750014")){

            %>
            <button id="button_wb-search1" class="btn btn-primary ladda-button" onclick="NewFile()" type="button" target="_blank">
                <span class="ladda-label">编辑离职日期</span></button>
            <%}%>
        </tr>
    </div>
    <div style="margin-left:5%;margin-right: 5%;">
        <center>
            <div class="sTab">
                <%--WdatePicker({ dateFmt: 'yyyy', minDate: '1900', maxDate: '2099' })--%>
                <tr>
                    <%--<th>查询时间:</th>--%>
                    <%--<td><input size="5" type="text"--%>
                    <%--onclick="WdatePicker({ dateFmt: 'yyyy', minDate: '1900', maxDate: '2099' })"--%>
                    <%--placeholder="<%=selectDate%>" id="selectDate" name="selectDate" value="<%=year%>"/></td>--%>
                    <th>查询时间:</th>
                    <td>
                        <select id="selectDate" name="selectDate">
                            <option></option>
                            <!-- 是 -->
                            <%
                                String selectitemListSql = "SELECT s.id AS id,s.objname AS nameid,l.labelname AS names FROM selectitem s LEFT JOIN label l ON " +
                                        " s.objname = l.id WHERE s.typeid='8ae8e83a58dcc91a0158ddb5760d0391' AND l.labelname>2019 and s.pid IS NULL ORDER BY names";
                                List selectitemList = dataService.getValues(selectitemListSql);
                                String yearsid = "";
                                String newyearsid = "";
                                for (int n = 0; n < selectitemList.size(); n++) {
                                    Map selectMap = (Map) selectitemList.get(n);
                                    String names = (String) selectMap.get("names");
                                    if (!names.equals("2020")){
                            %>
                            <option <%if (names.equals(year)) { %>
                                    selected
                                    <%
                                            newyearsid = (String) selectMap.get("id");
                                            int h = n - 1;
                                            String lastid = "";
                                            if (n != 0) {
                                                lastid = (String) ((Map) (selectitemList.get(h))).get("id");
                                            }
                                            yearsid = lastid;
                                        } %>
                                    value="<%=names%>">
                                <%=names%>
                            </option>
                            <%
                                    }
                                }
                            %>
                        </select>
                    </td>
                    <th>人员姓名:</th>
                    <td class="input-group">
                        <input id="humresid" name="humresid" type="hidden" value="<%=humresid%>">
                        <input class="form-control" id="humresid_span"
                               onkeyup="InputMsg.get('/ServiceAction/com.velcro.humres.base.servlet.InputMsgAction?action=getHumres&amp;filter=humres','humresid','humresid_span',false)"
                               type="text" value="<%=humresname%>">
                        <button class="icoR iRSin btn btn-primary"
                                onclick="javascript:getnewrefobj('humresid','humresid_span','402881e70bc70ed1010bc75e0361000f','','/vhumres/base/humresview.jsp?id=','0');"
                                type="button" style="right: 33px;">
                        </button>
                    </td>
                </tr>
                <div style="margin-left:80%;">
                    <img src="/vcss/images/logo1.png" width="75%">
                </div>
            </div>

            <table id="eTab" cellspacing="0" style="table-layout:fixed;">
                <tr>
                    <th scope="col" rowspan="3" width="4%">Staff No.</th>
                    <th scope="col" rowspan="3" width="13%">Staff Name</th>
                    <th scope="col" rowspan="3" width="15%">DOJ</th>
                    <th scope="col" colspan="11">Leaves taken in <%=year%>
                    </th>
                    <th scope="col" rowspan="3" width="5%">remarks</th>

                </tr>
                <tr>
                    <th scope="col" colspan="2" width="30%">Leave Date</th>
                    <th scope="col" colspan="5" width="46%">Annual Leave</th>
                    <th scope="col" rowspan="2" width="6%">Sick Leave</th>
                    <th scope="col" rowspan="2" width="6%">Wedding Leave</th>
                    <th scope="col" rowspan="2" width="6%">Nopay Leave</th>
                    <th scope="col" rowspan="2" width="6%">Others</th>
                </tr>
                <tr>

                    <th width="20%">From</th>
                    <th width="20%">To</th>
                    <th scope="col" width="10%"><%=lastyear%> Balance</th>
                    <th scope="col" width="10%"><%=year%> Entitlement</th>
                    <th scope="col" width="10%"><%=year%> Actual Entitlement</th>
                    <th scope="col" width="10%"><%=year%>  Taken</th>
                    <th scope="col" width="10%"><%=year%>Actual Balance</th>
                </tr>
                <%
                    String jobgradeSql = "select * from humreslevellist where field001='" + humresid + "' and nyear='" + yeah + "' order by bdate";
                    List jobgrades = dataService.getValues(jobgradeSql);
                    double sum = 0;
                    double days = 0;
                    String Entitlements = "";
                    for (int i = 0; i < jobgrades.size(); i++) {
                        Map map = (Map) jobgrades.get(i);
                        String nyear1 = StringHelper.null2String(map.get("nyear"));
                        String bdate = StringHelper.null2String(map.get("bdate"));               //职级开始日期
                        String edate = StringHelper.null2String(map.get("edate"));               //职级结束日期
                        String serviceyear = StringHelper.null2String(map.get("serviceyear"));   //已在职年数
                        String jobgrade1 = StringHelper.null2String(map.get("jobgrade"));        //职级
                        String zhijidays = zhijidays(serviceyear, jobgrade1);
                        String value = dataService.getValue(zhijidays);

                        if (StringHelper.isNotEmpty(quitdate)){
                            if ((isDate(quitdate)>=isDate(bdate)) && (isDate(quitdate)<=isDate(edate))){
                                edate=quitdate;
                            }
                        }

                        double Acutual = everyzhiji(nyear1,bdate,edate,value);  //职级对应的年假数
                        sum += math(Acutual);    //计算一年实际获取年假总和

                        if (StringHelper.isNotEmpty(quitdate)){
                            if ((isDate(quitdate)>=isDate(bdate)) && (isDate(quitdate)<=isDate(edate))){
                                break;
                            }
                        }
//                        double entitlement = Double.valueOf(value);            //每类职级对应的年假数
//                        if (days != entitlement) {
//                            if (i == 0) {
//                                Entitlements += "" + (int) entitlement + "";
//                            } else {
//                                Entitlements += "/" + (int) entitlement;
//                            }
//                            days = entitlement;
//                        }

                    }

                    /**
                     * 上一年员工年假剩余天数
                     */
                    String lastyears = "";
                    if (!yearsid.equals("")) {
                        lastyears = dataService.getValue("SELECT surplustime FROM uft9c2x01609814704081 "+
                                " WHERE id=(SELECT MAX(id) FROM uft9c2x01609814704081 WHERE years='" +
                                yearsid + "' AND humresid='" + humresid + "' AND yearstype='a')");
                    }
                    if (lastyears.equals("")) {
                        lastyears = "0";
                    }

                    String lastyearb = "";
                    if (!yearsid.equals("")) {
                        lastyearb = dataService.getValue("select surplustime from uft9c2x01609814704081 where years='" +
                                yearsid + "' and humresid='" + humresid + "' and yearstype='b'");
                    }
                    if (lastyearb.equals("")) {
                        lastyearb = "0";
                    }
                %>
                <tr>
                    <td scope="row"><%=humres.getExttextfield0()%>
                    </td>
                    <td scope="row"><%=humres.getObjname()%>
                    </td>
                    <td scope="row"><%=humres.getExtdatefield0()%>
                    </td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    </td>
                    <td scope="row"><%=lastyears%>
                    </td>
                    <td scope="row"><%=math(sum)%>
                    </td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                </tr>
                <%

                    String selectSql = "select * from ufe2u6z01347003295281 where field001='" + humresid + "' " +
                            "and field005 >= '" + yeah + "-03-01' and field005 < '" + (Integer.valueOf(yeah) + 1) +
                            "-03-01' and requestid IN (SELECT id FROM workflowbase WHERE isdelete=0) order by field005";
                    List values = dataService.getValues(selectSql);

                    String selectSqllast = "select * from ufe2u6z01347003295281 where field001='" + humresid + "' " +
                            "and field005 >= '" + yeah + "-01-01' and field005 < '" + yeah + "-03-01' "+
                            " and requestid IN (SELECT id FROM workflowbase WHERE isdelete=0) order by field005";
                    List lastjia = dataService.getValues(selectSqllast);
                    //List lastdateid = new ArrayList();

                    double TakenSum = 0;
                    double SickLeaveSum = 0;
                    double WeddingLeaveSum = 0;
                    double NopayLeaveSum = 0;
                    double OthersSum = 0;
                    double takens = 0;
                    double takenb = 0;
                    if (!lastyears.equals("")) {
                        takens = Double.valueOf(lastyears);
                    }
                    if (!lastyearb.equals("")) {
                        takenb = Double.valueOf(lastyearb);
                    }
                    double ActualEntitlement = sum+ takens;
                    double ActualBalance = sum + takens;

                    double sumds = 0;
                    sumds = sum + takens;
                    double oneyear=0;
                    //ActualEntitlement = math(ActualEntitlement);
                    //ActualBalance = math(ActualBalance);
                    if (math(takenb)<0){
                        String selectSqllastyear = "select * from ufe2u6z01347003295281 where field001='" + humresid + "' " +
                                "and field005 >= '" + (Integer.valueOf(yeah) - 1) + "-01-01' and field005 <= '" + (Integer.valueOf(yeah) - 1) + "-12-31' "+
                                " and requestid IN (SELECT id FROM workflowbase WHERE isdelete=0) order by field005 desc";
                        List lastjiayear = dataService.getValues(selectSqllastyear);
                        for (int i = 0; i < lastjiayear.size(); i++) {
                            Map map = (Map) lastjiayear.get(i);
                            String field005 = StringHelper.null2String(map.get("field005"));  //请假开始日期
                            String field007 = StringHelper.null2String(map.get("field007"));  //请假结束日期
                            String field013 = StringHelper.null2String(map.get("field013"));  //请假天数
                            String field003 = StringHelper.null2String(map.get("field003"));  //请假类别
                            String requestid = StringHelper.null2String(map.get("requestid"));
                            String field021 = StringHelper.null2String(map.get("field021"));

                            String Taken = "0";
                            String SickLeave = "";
                            String WeddingLeave = "";
                            String NopayLeave = "";
                            String Others = "";
                            if (field003.equals("ff80808133a4ca6e0133a4df1a230047")) {
                                if ((-math(takenb))>=math(Double.valueOf(field013))){
                                    takenb=(-takenb)-Double.valueOf(field013);
                                    Taken = field013;
                                }else if ((-math(takenb))>0 && (-math(takenb))<math(Double.valueOf(field013))){
                                    Taken = (-math(takenb))+"";
                                    takenb=0;
                                }
                                ActualBalance = ActualEntitlement - Double.valueOf(Taken);
                                if (ActualBalance < 0) {
                                    ActualBalance = 0;
                                    Taken = math(ActualEntitlement) +"";
                                }
                                TakenSum += math(Double.valueOf(Taken));
                            }

                            if (field003.equals("ff80808133a4ca6e0133a4df1a230045")) {
                                SickLeave = field013;
                                SickLeaveSum += Double.valueOf(SickLeave);
                                SickLeaveSum = math(SickLeaveSum);
                            } else if (field003.equals("ff80808133a4ca6e0133a4df1a230049")) {
                                WeddingLeave = field013;
                                WeddingLeaveSum += Double.valueOf(WeddingLeave);
                                WeddingLeaveSum = math(WeddingLeaveSum);
                            } else if (field003.equals("ff80808133a4ca6e0133a4df1a23004c")) {
                                Others = field013;
                                OthersSum += Double.valueOf(Others);
                                OthersSum = math(OthersSum);
                            } else if (!field003.equals("ff80808133a4ca6e0133a4df1a230047")) {
                                NopayLeave = field013;
                                NopayLeaveSum += Double.valueOf(NopayLeave);
                            }

                %>
                <tr>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row">
                        <%
                            if (currentuser.getId().equals("5a91c68456c08fad0156c4aba61e0056")){

                        %>
                        <a href="/ServiceAction/com.velcro.workflow.workflow.servlet.WfViewAction?workflowid=<%=requestid%>" target="_blank">编辑</a>
                        <%}%>
                    </td>
                    <td scope="row"><%=field005%>
                    </td>
                    <td scope="row"><%=field007%>
                    </td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"><%=math(ActualEntitlement)%>
                    </td>
                    <td scope="row"><%=Taken%>
                    </td>
                    <td scope="row"><%=math(ActualBalance)%>
                    </td>
                    <td scope="row"><%=SickLeave%>
                    </td>
                    <td scope="row"><%=WeddingLeave%>
                    </td>
                    <td scope="row"><%=NopayLeave%>
                    </td>
                    <td scope="row"><%=Others%>
                    <td scope="row"><%=field021%>
                    </td>
                </tr>
                <%
                            ActualEntitlement = ActualBalance;
                            if (takenb==0){
                                break;
                            }
                        }
                    }
                    for (int i = 0; i < lastjia.size(); i++) {
                        Map map = (Map) lastjia.get(i);
                        String field005 = StringHelper.null2String(map.get("field005"));  //请假开始日期
                        String field007 = StringHelper.null2String(map.get("field007"));  //请假结束日期
                        String field013 = StringHelper.null2String(map.get("field013"));  //请假天数
                        String field003 = StringHelper.null2String(map.get("field003"));  //请假类别
                        String requestid = StringHelper.null2String(map.get("requestid"));
                        String field021 = StringHelper.null2String(map.get("field021"));
                        String id = StringHelper.null2String(map.get("id"));

                        String Taken = "0";
                        String SickLeave = "";
                        String WeddingLeave = "";
                        String NopayLeave = "";
                        String Others = "";

                        if (field003.equals("ff80808133a4ca6e0133a4df1a230047")) {
                            if (math(takenb)>=math(Double.valueOf(field013))){
                                takenb=takenb-Double.valueOf(field013);
                                Taken = "0";
                            }else if (math(takenb)>0 && math(takenb)<math(Double.valueOf(field013))){
                                Taken = math(Double.valueOf(field013)-takenb)+"";
                                takenb=0;
                            }/*else if (math(takenb)<0){
                                ActualEntitlement=ActualEntitlement+math(takenb);
                                ActualBalance=ActualBalance+math(takenb);
                                takenb=0;
                            }*/else {
                                Taken = field013;
                                takenb=0;
                            }
                            if (isDate(field005) >=isDate(yeah+"-01-01") && isDate(field005) <=isDate(yeah+"-12-31")){
                                oneyear+= Double.valueOf(Taken);
                            }
                            ActualBalance = ActualEntitlement - Double.valueOf(Taken);
                            if (ActualBalance < 0) {
                                ActualBalance = 0;
                                Taken = math(ActualEntitlement) +"";
                            }
                            TakenSum += math(Double.valueOf(Taken));
                        }

                        if (field003.equals("ff80808133a4ca6e0133a4df1a230045")) {
                            SickLeave = field013;
                            SickLeaveSum += Double.valueOf(SickLeave);
                            SickLeaveSum = math(SickLeaveSum);
                        } else if (field003.equals("ff80808133a4ca6e0133a4df1a230049")) {
                            WeddingLeave = field013;
                            WeddingLeaveSum += Double.valueOf(WeddingLeave);
                            WeddingLeaveSum = math(WeddingLeaveSum);
                        } else if (field003.equals("ff80808133a4ca6e0133a4df1a23004c")) {
                            Others = field013;
                            OthersSum += Double.valueOf(Others);
                            OthersSum = math(OthersSum);
                        } else if (!field003.equals("ff80808133a4ca6e0133a4df1a230047")) {
                            NopayLeave = field013;
                            NopayLeaveSum += Double.valueOf(NopayLeave);
                        }
                %>
                <tr>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row">
                        <%
                            if (currentuser.getId().equals("5a91c68456c08fad0156c4aba61e0056")){

                        %>
                        <a href="/ServiceAction/com.velcro.workflow.workflow.servlet.WfViewAction?workflowid=<%=requestid%>" target="_blank">编辑</a>
                        <%}%>
                    </td>
                    <td scope="row"><%=field005%>
                    </td>
                    <td scope="row"><%=field007%>
                    </td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"><%=math(ActualEntitlement)%>
                    </td>
                    <td scope="row"><%=Taken%>
                    </td>
                    <td scope="row"><%=math(ActualBalance)%>
                    </td>
                    <td scope="row"><%=SickLeave%>
                    </td>
                    <td scope="row"><%=WeddingLeave%>
                    </td>
                    <td scope="row"><%=NopayLeave%>
                    </td>
                    <td scope="row"><%=Others%>
                    <td scope="row"><%=field021%>
                    </td>
                </tr>
                <%
                        ActualEntitlement = ActualBalance;
                    } %>
                <%
                    for (int i = 0; i < values.size(); i++) {
                        Map map = (Map) values.get(i);
                        String field005 = StringHelper.null2String(map.get("field005"));  //请假开始日期
                        String field007 = StringHelper.null2String(map.get("field007"));  //请假结束日期
                        String field013 = StringHelper.null2String(map.get("field013"));  //请假天数
                        String field003 = StringHelper.null2String(map.get("field003"));  //请假类别
                        String requestid = StringHelper.null2String(map.get("requestid"));
                        String field021 = StringHelper.null2String(map.get("field021"));
                        String id = StringHelper.null2String(map.get("id"));

                        String Taken = "0";
                        String SickLeave = "";
                        String WeddingLeave = "";
                        String NopayLeave = "";
                        String Others = "";

//                        if (takens>0){
                        if (field003.equals("ff80808133a4ca6e0133a4df1a230047")) {
                            Taken = field013;
                            if (isDate(field005) >=isDate(yeah+"-01-01") && isDate(field005) <=isDate(yeah+"-12-31")){
                                oneyear+= Double.valueOf(Taken);
                            }
                            ActualBalance = ActualEntitlement - Double.valueOf(Taken);
                            if (ActualBalance < 0) {
                                ActualBalance = 0;
                                Taken = math(ActualEntitlement) +"";
                            }
                            TakenSum += math(Double.valueOf(Taken));
                        }

//                        }

                        if (field003.equals("ff80808133a4ca6e0133a4df1a230045")) {
                            SickLeave = field013;
                            SickLeaveSum += Double.valueOf(SickLeave);
                            SickLeaveSum = math(SickLeaveSum);
                        } else if (field003.equals("ff80808133a4ca6e0133a4df1a230049")) {
                            WeddingLeave = field013;
                            WeddingLeaveSum += Double.valueOf(WeddingLeave);
                            WeddingLeaveSum = math(WeddingLeaveSum);
                        } else if (field003.equals("ff80808133a4ca6e0133a4df1a23004c")) {
                            Others = field013;
                            OthersSum += Double.valueOf(Others);
                            OthersSum = math(OthersSum);
                        } else if (!field003.equals("ff80808133a4ca6e0133a4df1a230047")) {
                            NopayLeave = field013;
                            NopayLeaveSum += Double.valueOf(NopayLeave);
                        }

                %>
                <tr>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row">
                        <%
                            if (currentuser.getId().equals("5a91c68456c08fad0156c4aba61e0056")){

                        %>
                        <a href="/ServiceAction/com.velcro.workflow.workflow.servlet.WfViewAction?workflowid=<%=requestid%>" target="_blank">编辑</a>
                        <%}%>
                    </td>
                    <td scope="row"><%=field005%>
                    </td>
                    <td scope="row"><%=field007%>
                    </td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"><%=math(ActualEntitlement)%>
                    </td>
                    <td scope="row"><%=Taken%>
                    </td>
                    <td scope="row"><%=math(ActualBalance)%>
                    </td>
                    <td scope="row"><%=SickLeave%>
                    </td>
                    <td scope="row"><%=WeddingLeave%>
                    </td>
                    <td scope="row"><%=NopayLeave%>
                    </td>
                    <td scope="row"><%=Others%>
                    <td scope="row"><%=field021%>
                    </td>
                </tr>
                <%
                        ActualEntitlement = ActualBalance;
                    } %>
                <tr>
                    <td scope="row"></td>
                    <td scope="row">Total:</td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"><%=math(TakenSum)%>
                    </td>
                    <td scope="row"><%=math(ActualBalance)%>
                    </td>
                    <td scope="row"><%=SickLeaveSum%>
                    </td>
                    <td scope="row"><%=WeddingLeaveSum%>
                    </td>
                    <td scope="row"><%=NopayLeaveSum%>
                    </td>
                    <td scope="row"><%=OthersSum%>
                    </td>
                    <td scope="row"></td>
                </tr>
                <%
                    if (isDate(yeah+"-01-01")>=isDate("2020-01-01")){
                        List intyear = dataService.getValues("select * from uft9c2x01609814704081 where yearstype='b' and years='"+newyearsid+"' "+
                                " and humresid='"+humresid+"'");
                        if (intyear.isEmpty()){
                            dataService.executeSql("insert into uft9c2x01609814704081(id,requestid,nodeid,humresid,years,surplustime,yearstype)"+
                                    " values (replace(uuid(),'-',''),'2c923daf7838c1610178a6211ca0295d','2c923daf76b7d9e30176d079a1c01309',"+
                                    "'"+humresid+"','"+newyearsid+"','"+math(sumds-oneyear)+"','b')");
                        }else {
                            dataService.executeSql("update uft9c2x01609814704081 set surplustime='"+math(sumds-oneyear)+"' "+
                                    " where yearstype='b' and years='"+newyearsid+"' and humresid='"+humresid+"'");
                        }
                    }
//                    dataService.executeSql("update uft9c2x01609814704081 set surplustime='"+math(sum-oneyear)+"' "+
//                            " where requestid='2c923daf7838c1610178a6211ca0295d' and humresid='"+humresid+"'");
//                    dataService.executeSql("insert into uft9c2x01609814704081(id,requestid,nodeid,humresid,years,surplustime,yearstype)"+
//                            " values (replace(uuid(),'-',''),'2c923daf7838c1610178a6211ca0295d','2c923daf76b7d9e30176d079a1c01309',"+
//                            "'"+humresid+"','8ae8e83a58dcc91a0158ddb654c703a9','"+math(sum-oneyear)+"','b')");

                %>
            </table>
            <table id="eTab" cellspacing="0">
                <tr>
                    <th scope="col" width="1%">Formula</th>
                    <th scope="col" width="1%">Service Year</th>
                    <th width="12%">JobGrade</th>
                    <th scope="col" width="10%">Period From</th>
                    <th scope="col" width="10%">Periond To</th>
                    <th scope="col" width="8%">Entitlement</th>
                    <th scope="col" width="8%">Acutual</th>
                    <th scope="col" width="25%">Taken</th>
                    <th scope="col" width="25%"></th>
                </tr>
                <%
                    for (int i = 0; i < jobgrades.size(); i++) {
                        Map map = (Map) jobgrades.get(i);
                        String nyear1 = StringHelper.null2String(map.get("nyear"));
                        String bdate = StringHelper.null2String(map.get("bdate"));               //职级开始日期
                        String edate = StringHelper.null2String(map.get("edate"));               //职级结束日期
                        String serviceyear = StringHelper.null2String(map.get("serviceyear"));   //已在职年数
                        String jobgrade1 = StringHelper.null2String(map.get("jobgrade"));        //职级

                        if (StringHelper.isNotEmpty(quitdate)){
                            if ((isDate(quitdate)>=isDate(bdate)) && (isDate(quitdate)<=isDate(edate))){
                                edate=quitdate;
                            }
                        }

                        String zhijidays = zhijidays(serviceyear, jobgrade1);
                        String value = dataService.getValue(zhijidays);

                        int nyear = Integer.valueOf(nyear1);
                        int yeardays = 365;
                        if (nyear % 4 == 0 && nyear % 100 != 0 || nyear % 400 == 0) {
                            yeardays = 366;
                        }
                        double Acutual = 0;
                        Acutual =((addDays(edate) - addDays(bdate) + 1) / yeardays) * Integer.valueOf(value);

                %>
                <tr>
                    <td scope="row"><%=nyear%>
                    </td>
                    <td scope="row"><%=serviceyear%>
                    </td>
                    <td scope="row"><%=jobgrade1%>
                    </td>
                    <td scope="row"><%=bdate%>
                    </td>
                    <td scope="row"><%=edate%>
                    </td>
                    <td scope="row"><%=value%>
                    </td>
                    <td scope="row"><%=math(Acutual)%>
                    </td>
                    <td scope="row">
                        <%
                            if (i==jobgrades.size()-1){
                        %>
                        <%=math(TakenSum)%>
                        <%}%>
                    </td>
                    <td scope="row"></td>
                </tr>
                <%
                        if (StringHelper.isNotEmpty(quitdate)){
                            if ((isDate(quitdate)>=isDate(bdate)) && (isDate(quitdate)<=isDate(edate))){
                                break;
                            }
                        }
                    } %>
                <tr>
                    <td scope="row">剩余假期</td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"></td>
                    <td scope="row"><%=math(ActualBalance)%>
                    </td>
                    <td scope="row">
                    </td>
                    <td scope="row">
                    </td>
                </tr>
            </table>
        </center>
    </div>
</form>
<div style="display: none">
    <div id="openwin" title="编辑离职日期" style="overflow: hidden;">
        <script src="/vjs/base/Validator.js" type="text/javascript"></script>
        <form name="dates" id="dates" aciton="">
            <div class="vTab">
                <table>
                    <tr>
                        <th>离职日期</th><!-- 联系人 -->
                        <%--<td><input type="text" id="lidate" name="lidate" />--%>
                        <td>
                            <input name="lidate" id="lidate" type="hidden" value="<%=quitdate%>">
                            <input name="lidatespan" id="lidatespan" style="width: 295px;" readonly="readonly" onchange="changeDate('lidate')" type="text" value="<%=quitdate%>">
                            <button class="icoR iRDat" id="button_lidate" onclick="javascript:getdate(event,'lidate','lidatespan','0');" type="button"></button>
                            <input name="form_need_check" disabled="disabled" id="form_need_check_lidatespan" required="false" type="hidden" value="lidatespan" requiredfield="false" datatype="date('yyyy-MM-dd')">
                            <input name="lidateaction" id="lidateaction" type="hidden" value="qc">
                            <input name="selectDate" id="selectDate" type="hidden" value="<%=selectDate%>">
                            <input name="humresid" id="humresid" type="hidden" value="<%=humresid%>">
                        </td>
                    </tr>
                </table>
            </div>
            <div style="float: right;" class="bBac">
                <div class="fMid">
                    <button class="btn" accessKey="S" onclick="onconfirm()"><%=labelService.getLabelName(locale,"402881eb0bcbfd19010bcc6e71870022") %></button>
                </div>
            </div>
        </form>
    </div></div>
</body>
</html>
<%!
    /**
     * 向上取一位小数
     *
     */
    public double math(double t) {
        BigDecimal bigDecimal2 = new BigDecimal(t).setScale(2, BigDecimal.ROUND_HALF_UP);//向上取小数点后两位数
        t = bigDecimal2.doubleValue();
        BigDecimal bigDecimal1 = new BigDecimal(t).setScale(1, BigDecimal.ROUND_HALF_UP);
        t = bigDecimal1.doubleValue();
        return t;
    }

    /**
     * 获取时间值,用于进行时间比较
     */
    public long isDate(String Date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(Date);
        long time = parse.getTime();
        return time;
    }

    /**
     * 获取对应职级的年假天数
     */
    public String zhijidays(String service, String job) {
        Integer intservice = Integer.valueOf(service);
        String dayssql = "";
        if (intservice <= 1) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=0 " +
                    " and field001='" + name(job) + "'";
        } else if (intservice > 1 && intservice <= 3) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=1 " +
                    " and field001='" + name(job) + "'";
        } else if (intservice > 3 && intservice <= 10) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=3 " +
                    " and field001='" + name(job) + "'";
        } else if (intservice > 10) {
            dayssql = "select field003 from ufa0p7g41597332545253 where " +
                    " requestid='402880e978492dea017849f7f7690009' and field004=10 " +
                    " and field001='" + name(job) + "'";
        }
        return dayssql;
    }

    /**
     * 获取对应日期的天数
     * @param date
     * @return
     */
    private double addDays(String date) {
        Date date1 = null;
        try {
            date1 = new SimpleDateFormat("yyyy-MM-dd").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy");
        SimpleDateFormat sdf1 = new SimpleDateFormat("MM");
        SimpleDateFormat sdf2 = new SimpleDateFormat("dd");
        double year = Double.valueOf(sdf0.format(date1)); //年
        double month = Double.valueOf(sdf1.format(date1)); //月
        double days = Double.valueOf(sdf2.format(date1)); //日

        //定义数组,这里2月的天数取28,假设是平年。
        int[] Day = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        //如果是闰年,那么2月应该有29天。
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            Day[1] = 29;
        }
        double sum = 0;
        for (int i = 0; i < month - 1; i++) {
            sum += Day[i];
        }
        return sum + days;
    }

    /**
     * 职级名称与id相互转化
     */
    public String name(String name) {
//        DataService dataService = (DataService) BaseContext.getBean(request, "dataService");
//        String sql="SELECT id,objdesc FROM selectitem WHERE typeid = '2c923daf73e3322e0173e863c72f083e'";
//        List values = dataService.getValues(sql);
//        for (int i=0;i<values.size();i++){
//            Map map = (Map) values.get(i);
//            String ids = StringHelper.null2String(map.get("id"));
//            String objdesc = StringHelper.null2String(map.get("objdesc"));
//            System.out.println(ids+"==============================="+objdesc);
//        }
        if (name.equals("1")) {
            return "2c923daf73e3322e0173e87e327c0861";
        } else if (name.equals("2")) {
            return "2c923daf73e3322e0173e87e327c0862";
        } else if (name.equals("3")) {
            return "2c923daf73e3322e0173e87e327c0863";
        } else if (name.equals("4")) {
            return "2c923daf73e3322e0173e87e327c0864";
        } else if (name.equals("5")) {
            return "2c923daf73e3322e0173e87e327c0865";
        } else if (name.equals("6")) {
            return "2c923daf73e3322e0173e87e327c0866";
        } else if (name.equals("7")) {
            return "2c923daf73e3322e0173e87e327c0867";
        } else if (name.equals("8")) {
            return "2c923daf73e3322e0173e87e327c0868";
        } else if (name.equals("9")) {
            return "2c923daf73e3322e0173e87e327c0869";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0861")) {
            return "1";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0862")) {
            return "2";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0863")) {
            return "3";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0864")) {
            return "4";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0865")) {
            return "5";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0866")) {
            return "6";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0867")) {
            return "7";
        } else if (name.equals("2c923daf73e3322e0173e87e327c0868")) {
            return "8";
        } else {
            return "9";
        }
    }

    /**
     * 获取一年中每个职级对应的年假数
     */
    public double everyzhiji(String nyear1,String bdate,String edate,String value){
        int nyear = Integer.valueOf(nyear1);
        int yeardays = 365;
        if (nyear % 4 == 0 && nyear % 100 != 0 || nyear % 400 == 0) {
            yeardays = 366;
        }
        double Acutual = ((addDays(edate) - addDays(bdate)+1) / yeardays) * Integer.valueOf(value);
        return Acutual;
    }


%>
<script>
    function onSubmit() {
        document.VelcroForm.submit();
    }

    function daying() {
        a=$("#selectDate option:selected").val();
        b=$("#humresid").val();
        c = $('#VelcroForm').serialize();
        window.location.href="/vworkflow/workflow/fhumresannualleave.jsp?"+c
    }

    //显示新建文件提示页
    function NewFile() {
        $('#openwin').dialog({
            modal : true,
            width : "400",
            height : "130"
        });
        $('#openwin').dialog("open");
        date('yyyy-MM-dd')
    };
    //新建文件确认
    function onconfirm() {
        $('#openwin').dialog("close");
        //var fileName = document.getElementById("lidate").value; //文件名
        document.dates.submit();
        //window.location.href="/vworkflow/workflow/fhumresannualleave.jsp?"+c
        //alert("fileName:" + fileName);
    };

</script>

 

标签:&&,isDate,String,double,valueOf,员工,dataService,计算,天数
来源: https://www.cnblogs.com/jk200/p/16463378.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有