126 lines
4.5 KiB
Plaintext
126 lines
4.5 KiB
Plaintext
<%@ page language="java" contentType="text/html; charset=utf-8" %>
|
||
<%@ page import="weaver.general.*,java.util.*,java.math.*" %>
|
||
<%@ page import="weaver.conn.RecordSet" %>
|
||
<%@ page import="java.time.LocalDate" %>
|
||
<%@ page import="java.time.temporal.ChronoUnit" %>
|
||
<%@ page import="java.text.DecimalFormat" %>
|
||
<%@ page import="java.time.format.DateTimeFormatter" %>
|
||
<%@ page import="java.time.Period" %>
|
||
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
|
||
<jsp:useBean id="rst" class="weaver.conn.RecordSet" scope="page" />
|
||
<%
|
||
int sum = 0;
|
||
|
||
String sss = "";
|
||
|
||
String companystartdate = request.getParameter("companystartdate");
|
||
String id = request.getParameter("userid");
|
||
|
||
//参加工作日期
|
||
String cjgzrq = request.getParameter("cjgzrq");
|
||
//扣减社会工龄
|
||
String kjshgl = request.getParameter("kjshgl");
|
||
|
||
// 首次参加工作日期 自定义字段
|
||
String cjgzrq_fieldid = rs.getPropValue("wuyuan_hrminfo","cjgzrq_fieldid");
|
||
// 扣减社会工龄 自定义字段id
|
||
String kjshgl_fieldid = rs.getPropValue("wuyuan_hrminfo","kjshgl_fieldid");
|
||
|
||
//司龄
|
||
String companyworkyear = "0";
|
||
if(companystartdate != null && !"".equals(companystartdate)){
|
||
int company_year = Integer.parseInt(companystartdate.substring(0,4));
|
||
int company_month = Integer.parseInt(companystartdate.substring(5,7));
|
||
int company_day = Integer.parseInt(companystartdate.substring(8,10));
|
||
companyworkyear = calculateCompanyAge(company_year,company_month,company_day);
|
||
sss += "update hrmresource set companyworkyear='"+companyworkyear+"' where id="+ id;
|
||
}
|
||
//参加工作日期
|
||
// String cjgzrq = Util.null2String(getFieldValue(cjgzrq_fieldid,id));
|
||
//扣减社会工龄
|
||
// String kjshgl = Util.null2o(getFieldValue(kjshgl_fieldid,id));
|
||
String age = calculateAge(cjgzrq);
|
||
if(cjgzrq != null && !"".equals(cjgzrq)){
|
||
sss += "update hrmresource set workstartdate='"+cjgzrq+"' where id="+ id;
|
||
if(Float.valueOf(kjshgl) > 0){
|
||
String endAge = String.valueOf(new BigDecimal(age).subtract(new BigDecimal(kjshgl)));
|
||
sss += "update hrmresource set workyear='"+endAge+"' where id="+id;
|
||
}else{
|
||
sss += "update hrmresource set workyear='"+age+"' where id="+id;
|
||
}
|
||
}
|
||
|
||
sum++;
|
||
|
||
|
||
%>
|
||
|
||
<%!
|
||
|
||
public String getFieldValue(String type,String userid){
|
||
String result = "";
|
||
RecordSet rs = new RecordSet();
|
||
rs.executeQuery("select "+type+" from cus_fielddata where scope='HrmCustomFieldByInfoType' and scopeid='3' and id=?",userid);
|
||
if(rs.next()){
|
||
result = Util.null2String(rs.getString(type));
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* 根据 日期 计算年龄
|
||
* @param birthdate
|
||
* @return
|
||
*/
|
||
public String calculateAge(String birthdate) {
|
||
String result = "0";
|
||
try {
|
||
// 解析日期
|
||
LocalDate startDate = LocalDate.parse(birthdate);
|
||
LocalDate endDate = LocalDate.now();
|
||
// 计算工龄(月份)
|
||
long monthsBetween = ChronoUnit.MONTHS.between(startDate, endDate);
|
||
// 将月份转换为年并格式化为2位小数
|
||
double years = (double) monthsBetween / 12;
|
||
DecimalFormat df = new DecimalFormat("0.00"); // 设置格式为2位小数
|
||
result = df.format(years);
|
||
}catch (Exception e){
|
||
e.printStackTrace();
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public String calculateCompanyAge(int year,int month,int day){
|
||
String result = "";
|
||
// 假设入职日期是2020年1月1日
|
||
LocalDate hireDate = LocalDate.of(year, month, day);
|
||
|
||
// 获取当前日期
|
||
LocalDate currentDate = LocalDate.now();
|
||
|
||
// 计算司龄(总月份数除以12)
|
||
double monthsBetween = Math.abs(Period.between(hireDate, currentDate).getMonths()) + 12 * Math.abs(Period.between(hireDate, currentDate).getYears());
|
||
double serviceYears = monthsBetween / 12.0; // 注意这里已经是总月份数除以12的结果,可以直接格式化输出
|
||
|
||
// 使用DecimalFormat格式化输出,保留两位小数
|
||
DecimalFormat df = new DecimalFormat("#.##"); // 注意这里的格式化符号使用的是英文的点号和井号,而不是中文的井号和井号。
|
||
result = df.format(serviceYears);
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
%>
|
||
|
||
<HEAD>
|
||
</HEAD>
|
||
<BODY>
|
||
|
||
<h1>Congratulation Mode 666666 !</h1>
|
||
|
||
<h1> sss <%=sss%> </h1>
|
||
|
||
<h1> sum <%=sum%> </h1>
|
||
|
||
</BODY>
|