# `FUN_GET_CALCPLAN_DATE_END` (function)

> 几台Id，传入时间加时间,得出来结束时间


- **Type:** FUNCTION
- **Returns:** `datetime`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_tDate` | `datetime` |
| 2 | IN | `p_dDayHour` | `decimal(18,6)` |
| 3 | IN | `p_sMachineId` | `varchar(50)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTION `FUN_GET_CALCPLAN_DATE_END`'`._

## Narrative

**Business context:** Production-planning shift-aware end-time calculator. Given the start datetime, total task minutes, and a machine id, returns the forecast end datetime taking into account the machine's shift schedule, weekend off-days (`sWkDayId` = 1 weekends, 3 Saturday only, 4 Sunday only), and the configured break windows (morning/lunch/afternoon/evening). Header comment is `几台Id，传入时间加时间,得出来结束时间` ("machine id + start + minutes → end").

**What it does:** loads the machine's `elemachine` shift configuration (`sOffWork`, `sWorkType`, `sShiftsWork`, six break-window pairs, `sWkDayId`, `dWeek`). Computes how many full shifts the workload spans (`p_dDayHour DIV (dWeek*60)`) and the leftover minutes. Walks one day at a time, skipping weekend days as configured, then forwards the date by the unsuspended-shift count and the remaining minutes via [`FUN_GET_DATE_BC_ADDTIME`](FUN_GET_DATE_BC_ADDTIME.md). For each scheduled break window (`FUN_GET_DATE_UKT_ADD` per window) it pushes the end-time forward by the break length if the job spans it. Finally normalizes back onto a shift boundary via [`FUN_GET_DATE_BC_STARTDATE`](FUN_GET_DATE_BC_STARTDATE.md).

**Invocation:** referenced in the source file under `script/标版/30100101/schedule/settime算休息时间/`. Status: appears orphaned in the live DB — no other routine, form-master sSqlStr, gdsmodule hook, or Java caller references it. Body also references `p_tStartDate`, `sBrId`, `sSuId` which are not declared as parameters — verify before invoking.
