From 7c24ebe3d982c56c985590d5e95be8d233cc6ece Mon Sep 17 00:00:00 2001 From: selfrelease Date: Wed, 29 Jul 2026 12:36:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=86=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=90=88=E5=90=8C=E6=95=B0=E6=8D=AE=20+=20batchRenew=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E6=97=A7=E5=90=88=E5=90=8CendDate=20+=20addContract?= =?UTF-8?q?=E9=98=B2=E9=87=8D=E5=A4=8D=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/services/contract.service.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/backend/src/services/contract.service.ts b/backend/src/services/contract.service.ts index 7e3ee8a..d14102f 100644 --- a/backend/src/services/contract.service.ts +++ b/backend/src/services/contract.service.ts @@ -653,6 +653,15 @@ export async function batchRenew(orgId: string, userId: string, contractIds: str const newEndDate = new Date(newStartDate) newEndDate.setFullYear(newEndDate.getFullYear() + years) + // 将旧合同 endDate 截止到续签开始日前一天,避免重叠 + const oldEndDate = new Date(newStartDate) + oldEndDate.setDate(oldEndDate.getDate() - 1) + + await prisma.laborContract.update({ + where: { id: contract.id }, + data: { endDate: oldEndDate }, + }) + await prisma.laborContract.create({ data: { orgId, @@ -682,6 +691,19 @@ export async function addContract(orgId: string, userId: string, data: any) { throw { code: 'NOT_FOUND', message: '员工不存在' } } + // 检查是否存在日期完全相同的合同,防止重复提交 + const duplicate = await prisma.laborContract.findFirst({ + where: { + employeeId: data.employeeId, + orgId, + startDate: new Date(data.startDate), + ...(data.endDate ? { endDate: new Date(data.endDate) } : { endDate: null }), + }, + }) + if (duplicate) { + throw { code: 'DUPLICATE', message: '该员工已存在相同日期的合同,请勿重复添加' } + } + const contractMonths = data.endDate ? Math.ceil(daysBetween(new Date(data.endDate), new Date(data.startDate)) / 30.44) : data.contractYears * 12