From 6a2485176b0f42dc74394ad0985cad8e60d5cc6a Mon Sep 17 00:00:00 2001 From: backuppc Date: Tue, 2 Dec 2025 08:30:06 +0900 Subject: [PATCH] =?UTF-8?q?=EC=97=85=EB=AC=B4=EC=9D=BC=EC=A7=80=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8=20=EC=84=A0=ED=83=9D=20?= =?UTF-8?q?=EC=8B=9C=20=EC=9D=B4=EC=A0=84=20=EA=B8=B0=EB=A1=9D=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=20=EA=B8=B0=EB=B3=B8=EA=B0=92=20=EC=9E=90=EB=8F=99=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - MachineBridge에 Jobreport_GetLastByProject API 추가 (pidx 또는 projectName 기반 마지막 업무일지 조회) - WebSocket 서버에 JOBREPORT_GET_LAST_BY_PROJECT 핸들러 추가 - communication.ts에 getLastJobReportByProject 메서드 추가 - JobreportEditModal에서 프로젝트 선택 시 자동으로 이전 기록의 요청부서, 패키지, 업무형태, 공정, 상태 값을 기본값으로 설정 - 윈폼(fJobReport_Add.cs)의 동일한 로직을 웹앱에 구현 --- .../MachineBridge/MachineBridge.Jobreport.cs | 74 +++++++++++++++++++ Project/Web/MachineBridge/WebSocketServer.cs | 10 +++ Project/frontend/src/communication.ts | 9 +++ .../jobreport/JobreportEditModal.tsx | 72 ++++++++++++++++-- Project/frontend/src/types.ts | 1 + 5 files changed, 160 insertions(+), 6 deletions(-) diff --git a/Project/Web/MachineBridge/MachineBridge.Jobreport.cs b/Project/Web/MachineBridge/MachineBridge.Jobreport.cs index 8f7f1d7..e96ab2f 100644 --- a/Project/Web/MachineBridge/MachineBridge.Jobreport.cs +++ b/Project/Web/MachineBridge/MachineBridge.Jobreport.cs @@ -432,6 +432,80 @@ namespace Project.Web } } + /// + /// 특정 프로젝트의 마지막 업무일지 조회 (프로젝트 선택 시 기본값 설정용) + /// + public string Jobreport_GetLastByProject(int pidx, string projectName) + { + try + { + var currentUserId = info.Login.no; + var sql = ""; + + if (pidx > 0) + { + // pidx로 조회 + sql = @"SELECT TOP 1 requestpart, package, type, jobgrp, process, status + FROM JobReport WITH (nolock) + WHERE gcode = @gcode AND uid = @uid AND ISNULL(pidx, -1) = @pidx + ORDER BY pdate DESC, idx DESC"; + } + else if (!string.IsNullOrEmpty(projectName)) + { + // projectName으로 조회 + sql = @"SELECT TOP 1 requestpart, package, type, jobgrp, process, status + FROM JobReport WITH (nolock) + WHERE gcode = @gcode AND uid = @uid AND ISNULL(projectName, '') LIKE @projectName + ORDER BY pdate DESC, idx DESC"; + } + else + { + return JsonConvert.SerializeObject(new { Success = false, Message = "프로젝트 정보가 없습니다." }); + } + + var cs = Properties.Settings.Default.gwcs; + using (var cn = new SqlConnection(cs)) + using (var cmd = new SqlCommand(sql, cn)) + { + cmd.Parameters.AddWithValue("@gcode", info.Login.gcode); + cmd.Parameters.AddWithValue("@uid", currentUserId); + if (pidx > 0) + { + cmd.Parameters.AddWithValue("@pidx", pidx); + } + else + { + cmd.Parameters.AddWithValue("@projectName", projectName); + } + + using (var da = new SqlDataAdapter(cmd)) + { + var dt = new DataTable(); + da.Fill(dt); + + if (dt.Rows.Count > 0) + { + var row = dt.Rows[0]; + var data = new Dictionary(); + foreach (DataColumn col in dt.Columns) + { + data[col.ColumnName] = row[col] == DBNull.Value ? null : row[col]; + } + return JsonConvert.SerializeObject(new { Success = true, Data = data }); + } + else + { + return JsonConvert.SerializeObject(new { Success = false, Message = "이전 기록이 없습니다." }); + } + } + } + } + catch (Exception ex) + { + return JsonConvert.SerializeObject(new { Success = false, Message = ex.Message }); + } + } + #endregion } } diff --git a/Project/Web/MachineBridge/WebSocketServer.cs b/Project/Web/MachineBridge/WebSocketServer.cs index a423892..25038a0 100644 --- a/Project/Web/MachineBridge/WebSocketServer.cs +++ b/Project/Web/MachineBridge/WebSocketServer.cs @@ -696,6 +696,16 @@ namespace Project.Web } break; + case "JOBREPORT_GET_LAST_BY_PROJECT": + { + int pidx = json.pidx ?? -1; + string projectName = json.projectName ?? ""; + string result = _bridge.Jobreport_GetLastByProject(pidx, projectName); + var response = new { type = "JOBREPORT_LAST_BY_PROJECT", data = JsonConvert.DeserializeObject(result) }; + await Send(socket, JsonConvert.SerializeObject(response)); + } + break; + case "JOBREPORT_GET_JOBTYPES": { string process = json.process ?? ""; diff --git a/Project/frontend/src/communication.ts b/Project/frontend/src/communication.ts index 01b4ccd..905ed64 100644 --- a/Project/frontend/src/communication.ts +++ b/Project/frontend/src/communication.ts @@ -788,6 +788,15 @@ class CommunicationLayer { } } + public async getLastJobReportByProject(pidx: number, projectName: string): Promise> { + if (isWebView && machine) { + const result = await machine.Jobreport_GetLastByProject(pidx, projectName); + return JSON.parse(result); + } else { + return this.wsRequest>('JOBREPORT_GET_LAST_BY_PROJECT', 'JOBREPORT_LAST_BY_PROJECT', { pidx, projectName }); + } + } + public async getJobReportTypeList(sd: string, ed: string, uid: string = ''): Promise> { if (isWebView && machine) { const result = await machine.Jobreport_GetTypeList(sd, ed, uid); diff --git a/Project/frontend/src/components/jobreport/JobreportEditModal.tsx b/Project/frontend/src/components/jobreport/JobreportEditModal.tsx index 7ac1db7..633abef 100644 --- a/Project/frontend/src/components/jobreport/JobreportEditModal.tsx +++ b/Project/frontend/src/components/jobreport/JobreportEditModal.tsx @@ -75,6 +75,8 @@ export function JobreportEditModal({ const [processList, setProcessList] = useState([]); const [statusList, setStatusList] = useState([]); const [loadingCodes, setLoadingCodes] = useState(false); + // 프로젝트 변경 추적 (이전 기록 불러오기 여부 판단) + const [previousProjectIdx, setPreviousProjectIdx] = useState(null); // ESC 키로 닫기 useEffect(() => { @@ -515,12 +517,70 @@ export function JobreportEditModal({ setShowProjectSearch(false)} - onSelect={(project) => { - onFormChange({ - ...formData, - projectName: project.name, - pidx: project.idx > 0 ? project.idx : -1, - }); + onSelect={async (project) => { + // 프로젝트가 변경된 경우에만 이전 기록 불러오기 + if (previousProjectIdx !== project.idx) { + try { + // 해당 프로젝트의 마지막 업무일지 조회 + const lastReport = await comms.getLastJobReportByProject(project.idx, project.name); + if (lastReport.Success && lastReport.Data) { + // 이전 기록의 값들을 기본값으로 설정 + const updatedFormData = { + ...formData, + projectName: project.name, + pidx: project.idx > 0 ? project.idx : -1 + }; + + // 이전 기록에서 값 가져오기 (null이 아닌 경우에만) + if (lastReport.Data.requestpart) { + updatedFormData.requestpart = lastReport.Data.requestpart; + } + if (lastReport.Data.package) { + updatedFormData.package = lastReport.Data.package; + } + if (lastReport.Data.type) { + updatedFormData.type = lastReport.Data.type; + } + if (lastReport.Data.jobgrp) { + updatedFormData.jobgrp = lastReport.Data.jobgrp; + } + if (lastReport.Data.process) { + updatedFormData.process = lastReport.Data.process; + } + if (lastReport.Data.status) { + updatedFormData.status = lastReport.Data.status; + } + + onFormChange(updatedFormData); + setPreviousProjectIdx(project.idx); + } else { + // 이전 기록이 없어도 프로젝트는 설정 + onFormChange({ + ...formData, + projectName: project.name, + pidx: project.idx > 0 ? project.idx : -1 + }); + setPreviousProjectIdx(project.idx); + } + } catch (error) { + console.error('이전 기록 불러오기 오류:', error); + // 오류가 나도 프로젝트는 설정 + onFormChange({ + ...formData, + projectName: project.name, + pidx: project.idx > 0 ? project.idx : -1 + }); + setPreviousProjectIdx(project.idx); + } + } else { + // 동일한 프로젝트면 그냥 설정만 + onFormChange({ + ...formData, + projectName: project.name, + pidx: project.idx > 0 ? project.idx : -1 + }); + } + setShowProjectSearch(false); }} initialSearchKey={formData.projectName} /> diff --git a/Project/frontend/src/types.ts b/Project/frontend/src/types.ts index 794e7ea..69e09d0 100644 --- a/Project/frontend/src/types.ts +++ b/Project/frontend/src/types.ts @@ -362,6 +362,7 @@ export interface MachineBridgeInterface { Jobreport_Edit(idx: number, pdate: string, projectName: string, pidx: number, requestpart: string, package_: string, type: string, process: string, status: string, description: string, hrs: number, ot: number, jobgrp: string, tag: string, otStart: string, otEnd: string): Promise; Jobreport_Delete(id: number): Promise; Jobreport_GetPermission(targetUserId: string): Promise; + Jobreport_GetLastByProject(pidx: number, projectName: string): Promise; Jobreport_GetJobTypes(process: string): Promise; // App Info API