Commit 45629ec6 authored by fangxinjiang's avatar fangxinjiang

合同续签劳务派遣起止日期与合同起止日期一致性校验+批量派遣年限>2-fxj

parent 27a9e17a
package com.yifu.cloud.plus.v1.csp.utils;
import com.yifu.cloud.plus.v1.yifu.insurances.util.LocalDateUtil;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
/**
* @Author fxj
* @Date 2026/2/24
* @Description
* @Version 1.0
*/
@Service
public class ContractTermCalculator {
/**
* 合同期限计算结果
*/
public static class ContractTerm {
private final int years;
private final int months;
public ContractTerm(int years, int months) {
this.years = years;
this.months = months;
}
public int getYears() { return years; }
public int getMonths() { return months; }
}
/**
* 计算合同期限(年数和月数)
* @param startDate 合同开始日期
* @param endDate 合同截止日期
* @return ContractTerm 包含年数和月数
*/
public static ContractTerm calculateTerm(String startDate, String endDate) {
// 验证日期
if (startDate == null || endDate == null) {
throw new IllegalArgumentException("开始日期和截止日期不能为空");
}
// 计算相差的年数
int years = 0;
int months = (int) LocalDateUtil.betweenMonth(startDate, endDate);
// 处理月份进位
if (months >= 12) {
years = (months / 12);
months = months % 12;
}
return new ContractTerm(years, months);
}
/**
* 解析日期字符串(支持yyyy-MM-dd和yyyy年MM月dd日格式)
*/
private static LocalDate parseDate(String dateStr) {
if (dateStr == null || dateStr.trim().isEmpty()) {
throw new IllegalArgumentException("日期不能为空");
}
dateStr = dateStr.trim();
try {
// 处理 yyyy-MM-dd 格式
if (dateStr.contains("-")) {
String[] parts = dateStr.split("-");
if (parts.length == 3) {
return LocalDate.of(
Integer.parseInt(parts[0]),
Integer.parseInt(parts[1]),
Integer.parseInt(parts[2])
);
}
}
// 处理 yyyy年MM月dd日 格式
if (dateStr.contains("年")) {
String yearPart = dateStr.substring(0, dateStr.indexOf("年"));
String monthPart = dateStr.substring(dateStr.indexOf("年") + 1, dateStr.indexOf("月"));
String dayPart = dateStr.substring(dateStr.indexOf("月") + 1, dateStr.indexOf("日"));
return LocalDate.of(
Integer.parseInt(yearPart),
Integer.parseInt(monthPart),
Integer.parseInt(dayPart)
);
}
throw new IllegalArgumentException("不支持的日期格式: " + dateStr);
} catch (Exception e) {
throw new IllegalArgumentException("日期解析失败: " + dateStr, e);
}
}
/**
* 测试方法
*/
public static void main(String[] args) {
System.out.println("=== 合同期限计算测试 ===");
// 测试示例1:2026年2月3日到2027年2月2日(正好一年)
testCase("2026-02-03", "2027-02-02", "正好一年");
// 测试示例2:2026年2月3日到2027年2月3日(一年零一天,应算一年一个月)
testCase("2026-02-03", "2027-02-03", "一年零一天");
// 测试示例3:2026年2月3日到2027年2月28日(一年零25天,应算一年一个月)
testCase("2026-02-03", "2027-02-28", "一年零25天");
// 测试示例3:2026年2月3日到2027年3月3日(应算一年2个月)
testCase("2026-02-03", "2027-03-02", "一年1月零1天");
// 测试示例4:2026年2月3日到2027年3月1日(一年零26天,应算一年一个月)
testCase("2026-02-03", "2027-03-03", "跨月一天");
// 测试示例5:2026年2月3日到2028年2月2日(正好两年)
testCase("2026-02-03", "2028-03-04", "正好两年");
// 测试示例6:2026年2月3日到2028年3月1日(两年多,应算两年一个月)
testCase("2026-02-03", "2028-03-01", "两年多一天");
// 测试示例7:2026年1月31日到2026年2月28日(一个月差几天)
testCase("2026-01-31", "2026-02-28", "跨月边界");
}
private static void testCase(String start, String end, String description) {
try {
ContractTerm term = calculateTerm(start, end);
LocalDate startDate = parseDate(start);
LocalDate endDate = parseDate(end);
System.out.printf("开始:%-12s | 截止:%-12s | 结果:(%d年%d个月)%n",
start, end, term.getYears(), term.getMonths());
} catch (Exception e) {
System.out.println("错误:" + e.getMessage());
}
}
}
...@@ -675,7 +675,7 @@ ...@@ -675,7 +675,7 @@
FROM t_dispatch_info_pre a FROM t_dispatch_info_pre a
left join view_contract b on a.EMP_IDCARD = b.EMP_IDCARD and a.DEPT_NO = b.DEPT_NO left join view_contract b on a.EMP_IDCARD = b.EMP_IDCARD and a.DEPT_NO = b.DEPT_NO
LEFT JOIN (select t.DEPART_NAME,t.LOWER_LIMIT,t.UPPER_LIMIT from sys_base_set_info t where t.BASE_TYPE = '0' and t.STATUS = 0 and t.DELETE_FLAG = '0' and LEFT JOIN (select t.DEPART_NAME,t.LOWER_LIMIT,t.UPPER_LIMIT from sys_base_set_info t where t.BASE_TYPE = '0' and t.STATUS = 0 and t.DELETE_FLAG = '0' and
DATE_FORMAT(t.APPLY_START_DATE,'%Y%m%d') <![CDATA[ <= ]]> DATE_FORMAT(CURDATE(),'%Y%m%d') and DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[ <= ]]> IFNULL(t.APPLY_END_DATE,DATE_FORMAT(CURDATE(),'%Y%m%d')) DATE_FORMAT(t.APPLY_START_DATE,'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(CURDATE(),'%Y-%m-%d') and DATE_FORMAT(CURDATE(),'%Y-%m-%d') <![CDATA[ <= ]]> IFNULL(t.APPLY_END_DATE,DATE_FORMAT(CURDATE(),'%Y-%m-%d'))
) c on c.DEPART_NAME = a.SOCIAL_HOUSEHOLD_NAME ) c on c.DEPART_NAME = a.SOCIAL_HOUSEHOLD_NAME
<where> <where>
a.DELETE_FLAG = '0' and a.IS_REFUSE ='1' a.DELETE_FLAG = '0' and a.IS_REFUSE ='1'
...@@ -761,7 +761,7 @@ ...@@ -761,7 +761,7 @@
if(#{type} = '1',concat('自动化手动-',a.customer_username),concat('自动化自动-',a.customer_username)) preName if(#{type} = '1',concat('自动化手动-',a.customer_username),concat('自动化自动-',a.customer_username)) preName
FROM t_dispatch_info_pre a FROM t_dispatch_info_pre a
LEFT JOIN (select t.DEPART_NAME,t.LOWER_LIMIT,t.UPPER_LIMIT from sys_base_set_info t where t.BASE_TYPE = '1' and t.STATUS = 0 and t.DELETE_FLAG = '0' and LEFT JOIN (select t.DEPART_NAME,t.LOWER_LIMIT,t.UPPER_LIMIT from sys_base_set_info t where t.BASE_TYPE = '1' and t.STATUS = 0 and t.DELETE_FLAG = '0' and
DATE_FORMAT(t.APPLY_START_DATE,'%Y%m%d') <![CDATA[ <= ]]> DATE_FORMAT(CURDATE(),'%Y%m%d') and DATE_FORMAT(CURDATE(),'%Y%m%d') <![CDATA[ <= ]]> IFNULL(t.APPLY_END_DATE,DATE_FORMAT(CURDATE(),'%Y%m%d')) DATE_FORMAT(t.APPLY_START_DATE,'%Y-%m-%d') <![CDATA[ <= ]]> DATE_FORMAT(CURDATE(),'%Y-%m-%d') and DATE_FORMAT(CURDATE(),'%Y-%m-%d') <![CDATA[ <= ]]> IFNULL(t.APPLY_END_DATE,DATE_FORMAT(CURDATE(),'%Y-%m-%d'))
) c on c.DEPART_NAME = a.PROVIDENT_HOUSEHOLD_NAME ) c on c.DEPART_NAME = a.PROVIDENT_HOUSEHOLD_NAME
,(select @i:=0) as itable ,(select @i:=0) as itable
<where> <where>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment