From e853dd2fecef3a0c446d161248d0498a5a081e66 Mon Sep 17 00:00:00 2001
From: xwt <2740516069@qq.com>
Date: 星期三, 17 十二月 2025 18:49:49 +0800
Subject: [PATCH] SJ,XJ,RKJ优化修改
---
StandardInterface/MES.Service/service/QC/RKJService.cs | 691 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 652 insertions(+), 39 deletions(-)
diff --git a/StandardInterface/MES.Service/service/QC/RKJService.cs b/StandardInterface/MES.Service/service/QC/RKJService.cs
index 06e7a22..1639a80 100644
--- a/StandardInterface/MES.Service/service/QC/RKJService.cs
+++ b/StandardInterface/MES.Service/service/QC/RKJService.cs
@@ -1,10 +1,14 @@
锘縰sing MES.Service.DB;
using MES.Service.Dto.service;
using MES.Service.Modes;
+using MES.Service.Modes.QcIssueResult;
+using MES.Service.service.QcIssueResult;
using MES.Service.util;
using SqlSugar;
using System.Linq;
using System.Data;
+using System.Net;
+using System.Web;
namespace MES.Service.service.QC;
@@ -287,7 +291,8 @@
a.FcheckLevel,
a.FacLevel,
a.QsCode,
- a.QsName
+ a.QsName,
+ a.Forder
}).Select((a, b) => new QsItemOqcItem
{
ProjName = a.ProjName,
@@ -304,13 +309,11 @@
FacLevel = a.FacLevel,
QsCode = a.QsCode,
QsName = a.QsName,
+ Forder = a.Forder,
isCheck = SqlFunc.AggregateCount(b.Id),
- Result = a.IsPass == 1 &&
- a.LevelNum == SqlFunc.AggregateCount(b.Id) ? "鍚堟牸"
- : a.IsPass == 0 &&
- a.LevelNum == SqlFunc.AggregateCount(b.Id) ? "涓嶅悎鏍�"
- : "鏈畬鎴�"
- }).OrderBy("result desc").ToList();
+ Result = SqlFunc.AggregateCount(b.Id) == 0 ? "鏈畬鎴�" :
+ a.IsPass == 1 ? "鍚堟牸" : "涓嶅悎鏍�"
+ }).OrderBy("FORDER").ToList();
}
public dynamic save(RKJDto rkjDto)
@@ -363,10 +366,16 @@
if (!string.IsNullOrEmpty(rkjDto.RbillNo))
xj.RbillNo = rkjDto.RbillNo;
- // 纭繚Quantity瀛楁琚纭缃�
+ // 纭繚宸ュ崟鏁伴噺瀛楁琚纭缃紙QUANTITY锛�
if (xj.Quantity == null && rkjDto.quantity != null)
{
xj.Quantity = rkjDto.quantity;
+ }
+
+ // 纭繚閫佹鏁伴噺瀛楁琚纭缃紙SJQTY锛�
+ if (xj.Sjqty == null && rkjDto.sjqty != null)
+ {
+ xj.Sjqty = rkjDto.sjqty;
}
// 纭繚鎻愪氦鐘舵�佽姝g‘璁剧疆锛堥粯璁や负鏈彁浜わ級
@@ -433,7 +442,7 @@
detail.Pid = s.Id;
detail.Gid = rkjDto.gid;
detail.Fstand = "鈭�";
- detail.FcheckResu = "1";
+ detail.FcheckResu = "OK";
detail.UpdateBy = rkjDto.userNo;
detail.count = (int?)s.LevelNum;
SetQSItemDetail(detail);
@@ -558,12 +567,12 @@
var qsItemOqcReq =
db.Queryable<QsItemOqcReq>().Single(s => s.Id == gid);
- var mesInvItemIns = db.Queryable<MesInvItemIns>()
- .Single(s => s.BillNo == qsItemOqcReq.BillNo);
+ //var mesInvItemIns = db.Queryable<MesInvItemIns>()
+ // .Single(s => s.BillNo == qsItemOqcReq.BillNo);
var mesSchemeResult = db.Queryable<Womdaa>()
- .Single(s => s.Daa001 == mesInvItemIns.CbillNo);
-
+ //.Single(s => s.Daa001 == mesInvItemIns.CbillNo);
+ .Single(s => s.Daa001 == qsItemOqcReq.BillNo);
var entity = new MesQaItemsDetect02();
// entity.ItemNo = mesSchemeResult.BoardItem;
// entity.BoardItem = mesSchemeResult.BoardItem;
@@ -590,13 +599,13 @@
entity.CreateBy = createBy;
entity.FcheckBy = createBy;
- return SqlSugarHelper.UseTransactionWithOracle(db => db
- .Insertable(entity)
- .ExecuteCommand());
+ // 璺宠繃MES_QA_ITEMS_DETECT_02琛ㄧ殑鎻掑叆鎿嶄綔
+ // 涓嶅啀鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥璁板綍
+ return 0;
}
- public List<QsItemOqcReq> getPage(XJPageResult queryObj)
+ public (List<QsItemOqcReq>, int) getPage(XJPageResult queryObj)
{
var db = SqlSugarHelper.GetInstance();
@@ -607,24 +616,58 @@
if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
lineNo = _baseService.getUserLineNo(queryObj.createUser);
- return db
- .Queryable<QsItemOqcReq, Womdaa, MesItems>((a, da, b) =>
+ var totalCount = 0;
+
+ var data = db
+ .Queryable<QsItemOqcReq, Womdaa, MesItems, MesLine>((a, da, b, m) =>
new JoinQueryInfos(
JoinType.Left, da.Daa001 == a.BillNo,
- JoinType.Left, a.ItemId == b.Id
+ JoinType.Left, a.ItemId == b.Id,
+ JoinType.Left, da.Daa015 == m.LineNo
))
.WhereIF(lineNo != null && lineNo.Length > 0,
- (a, da, b) => lineNo.Contains(da.Daa015))
+ (a, da, b, m) => lineNo.Contains(da.Daa015))
+ // 娣诲姞QC绛涢�夋潯浠讹細杞﹂棿鍜岀嚎浣�
+ .WhereIF(!string.IsNullOrEmpty(queryObj.departmentId),
+ (a, da, b, m) => m.DepotId.ToString() == queryObj.departmentId)
+ .WhereIF(!string.IsNullOrEmpty(queryObj.lineId),
+ (a, da, b, m) => m.LineNo == queryObj.lineId)
.WhereIF(
StringUtil.IsNotNullOrEmpty(queryObj.result) &&
"鏈畬鎴�".Equals(queryObj.result),
- (a, da, b) => a.FcheckResu == null || a.FcheckResu == "")
+ (a, da, b, m) => a.FcheckResu == null || a.FcheckResu == "")
.WhereIF(
StringUtil.IsNotNullOrEmpty(queryObj.result) &&
!"鏈畬鎴�".Equals(queryObj.result),
- (a, da, b) => a.FcheckResu != null && a.FcheckResu != "")
- .WhereIF(id > 0, (a, da, b) => a.Id == id)
- .Select((a, da, b) => new QsItemOqcReq
+ (a, da, b, m) => a.FcheckResu != null && a.FcheckResu != "")
+ .WhereIF(id > 0, (a, da, b, m) => a.Id == id)
+ // 娣诲姞fsubmit瀛楁杩囨护閫昏緫 - 鍙湁鍦ㄦ槑纭寚瀹歠submit鍙傛暟鏃舵墠杩囨护锛屼笖娌℃湁浼犻�抜d鏃舵墠杩囨护
+ .WhereIF(
+ id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1",
+ (a, da, b, m) => a.Fsubmit == 1)
+ .WhereIF(
+ id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "0",
+ (a, da, b, m) => a.Fsubmit == 0 || a.Fsubmit == null)
+ // 娣诲姞鎼滅储鏉′欢 - 鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+ .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "billNo", // 宸ュ崟
+ (a, da, b, m) => a.BillNo.Contains(queryObj.SearchValue))
+ .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "releaseNo", // 妫�楠屽崟鍙�
+ (a, da, b, m) => a.ReleaseNo.Contains(queryObj.SearchValue))
+ .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "daa015", // 浜х嚎
+ (a, da, b, m) => da.Daa015.Contains(queryObj.SearchValue))
+ .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "itemNo", // 鐗╂枡缂栫爜
+ (a, da, b, m) => a.ItemNo.Contains(queryObj.SearchValue))
+ .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "itemName", // 鐗╂枡鍚嶇О
+ (a, da, b, m) => b.ItemName.Contains(queryObj.SearchValue))
+ // 涓轰簡鍏煎鏃х増鏈紝濡傛灉娌℃湁浼犻�� searchField锛屼娇鐢ㄥ師鏉ョ殑鏌ヨ閫昏緫
+ .WhereIF(string.IsNullOrEmpty(queryObj.searchField) && !string.IsNullOrEmpty(queryObj.SearchValue),
+ (a, da, b, m) =>
+ a.ItemNo.Contains(queryObj.SearchValue) ||
+ b.ItemName.Contains(queryObj.SearchValue) ||
+ a.BillNo.Contains(queryObj.SearchValue) ||
+ a.ReleaseNo.Contains(queryObj.SearchValue) ||
+ da.Daa015.Contains(queryObj.SearchValue))
+ .Select((a, da, b, m) => new QsItemOqcReq
{
Id = a.Id,
ReleaseNo = a.ReleaseNo,
@@ -641,13 +684,47 @@
Remarks = a.Remarks,
WorkShop = a.WorkShop,
DepartmentId = a.DepartmentId,
+ Fsubmit = a.Fsubmit, // 娣诲姞fsubmit瀛楁鍒拌繑鍥炵粨鏋�
+ Blyy = a.Blyy, // 娣诲姞涓嶈壇鍘熷洜瀛楁
+ Pszt = a.Pszt, // 娣诲姞璇勫鐘舵�佸瓧娈�
+ Sscj = a.Sscj, // 娣诲姞鎵�灞炶溅闂村瓧娈�
+ FngDesc = a.FngDesc, // 娣诲姞涓嶈壇鎻忚堪瀛楁
// 浠庡叧鑱旇〃鑾峰彇鐨勫瓧娈�
ItemName = b.ItemName,
ItemModel = b.ItemModel,
Daa015 = da.Daa015,
- Quantity = a.Quantity
+ Quantity = a.Quantity, // 宸ュ崟鏁伴噺
+ Sjqty = a.Sjqty // 閫佹鏁伴噺
}).OrderBy(a => a.CreateDate, OrderByType.Desc)
- .ToPageList(queryObj.PageIndex, queryObj.Limit);
+ .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+
+ // 淇妫�楠岀粨鏋滐細濡傛灉鏄剧ず涓衡�滃悎鏍尖�濅絾娌℃湁妫�楠岄」鐩紝鍒欐敼涓虹┖锛堝緟妫�楠岋級
+ if (data.Count > 0)
+ {
+ var ids = data.Select(d => d.Id).ToList();
+
+ // 鎵归噺鏌ヨ妫�楠岄」鐩暟閲�
+ var itemCounts = db.Queryable<QsItemOqcItem>()
+ .Where(item => ids.Contains(item.Pid.Value))
+ .GroupBy(item => item.Pid)
+ .Select(g => new { Pid = g.Pid, Count = SqlFunc.AggregateCount(g.Id) })
+ .ToList();
+
+ // 淇姣忔潯璁板綍鐨勬楠岀粨鏋�
+ foreach (var item in data)
+ {
+ var itemCount = itemCounts.FirstOrDefault(ic => ic.Pid == item.Id);
+ var hasItems = itemCount != null && itemCount.Count > 0;
+
+ // 濡傛灉娌℃湁妫�楠岄」鐩紝鍒欏皢妫�楠岀粨鏋滄竻绌猴紙鏄剧ず涓哄緟妫�楠岋級
+ if (!hasItems)
+ {
+ item.FcheckResu = null;
+ }
+ }
+ }
+
+ return (data, totalCount);
}
//鍒犻櫎涓昏〃骞朵笖杩炵骇鍒犻櫎瀛愯〃鍜屽瓩琛�
@@ -678,8 +755,36 @@
var rkjDto = new RKJDto();
var db = SqlSugarHelper.GetInstance();
- var qsItemOqcItem =
- db.Queryable<QsItemOqcItem>().Single(s => s.Id == id);
+
+ // 浣跨敤JOIN鏌ヨ鑾峰彇瀛愯〃鏁版嵁鍜屼富琛ㄧ殑ItemNo瀛楁
+ var qsItemOqcItem = db
+ .Queryable<QsItemOqcItem, QsItemOqcReq>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id))
+ .Where((a, b) => a.Id == id)
+ .Select((a, b) => new QsItemOqcItem
+ {
+ Id = a.Id,
+ Pid = a.Pid,
+ ProjName = a.ProjName,
+ ItemMod = a.ItemMod,
+ InspectionMethod = a.InspectionMethod,
+ UsingInstruments = a.UsingInstruments,
+ LevelNum = a.LevelNum,
+ MaxValue = a.MaxValue,
+ StandardValue = a.StandardValue,
+ MinValue = a.MinValue,
+ Notes = a.Notes,
+ FcheckLevel = a.FcheckLevel,
+ FacLevel = a.FacLevel,
+ QsCode = a.QsCode,
+ QsName = a.QsName,
+ Picture = a.Picture,
+ Picturename = a.Picturename,
+ IsPass = a.IsPass,
+ Remarks = a.Remarks,
+ FreQty = a.FreQty,
+ // 娣诲姞涓昏〃鐨処temNo瀛楁
+ ItemNo = b.ItemNo
+ }).Single();
if (qsItemOqcItem.IsPass == 0)
qsItemOqcItem.Result = "涓嶅悎鏍�";
@@ -692,6 +797,35 @@
qsItemOqcItem.imageData =
Convert.ToBase64String(qsItemOqcItem.Picture);
+ // 浠� QS_ITEM_IPI_IMAGE 琛ㄤ腑鑾峰彇鍥剧墖鍒楄〃锛堝叆搴撴 QS_TYPE=3锛�
+ var imageRecords = db.Queryable<QsItemIpiImage>()
+ .Where(s => s.Fid == id && s.QsType == 3 && s.ImageData != null)
+ .ToList();
+
+ if (imageRecords.Count > 0)
+ {
+ qsItemOqcItem.imageList = new List<ImageInfo>();
+ foreach (var img in imageRecords)
+ {
+ if (img.ImageData != null && img.ImageData.Length > 0)
+ {
+ qsItemOqcItem.imageList.Add(new ImageInfo
+ {
+ Id = img.Id ?? 0,
+ FileName = img.Picturename,
+ Base64Data = Convert.ToBase64String(img.ImageData),
+ CreateDate = img.CreateDate,
+ CreateBy = img.CreateBy
+ });
+ }
+ }
+ // 淇濇寔鍚戝悗鍏煎
+ if (qsItemOqcItem.imageList.Count > 0 && string.IsNullOrEmpty(qsItemOqcItem.imageData))
+ {
+ qsItemOqcItem.imageData = qsItemOqcItem.imageList[0].Base64Data;
+ }
+ }
+
//鑾峰彇涓嶅悎鏍兼暟
var count = db.Queryable<QsItemOqcItemDetail>()
.Where(s => s.Fstand == "脳" && s.Pid == id).Count();
@@ -699,7 +833,6 @@
qsItemOqcItem.Unqualified = count;
rkjDto.ItemXj01 = qsItemOqcItem;
-
rkjDto.ItemXj02s = db.Queryable<QsItemOqcItemDetail>()
.Where(s => s.Pid == id)
@@ -792,7 +925,7 @@
detail.Pid = s.Id;
detail.Gid = rkjDto.gid;
detail.Fstand = "鈭�";
- detail.FcheckResu = "1";
+ detail.FcheckResu = "OK";
detail.UpdateBy = rkjDto.userNo;
detail.count = (int?)s.LevelNum;
SetQSItemDetail(detail);
@@ -807,17 +940,123 @@
/// <param name="id">妫�楠屽崟ID</param>
/// <param name="userNo">鎻愪氦鐢ㄦ埛</param>
/// <returns>鏇存柊缁撴灉</returns>
- public int SubmitInspection(decimal id, string userNo)
+ public bool SubmitInspection(decimal id, string userNo)
{
- return SqlSugarHelper.UseTransactionWithOracle(db =>
+ try
{
- return db.Updateable<QsItemOqcReq>()
- .SetColumns(it => it.Fsubmit == 1) // 璁剧疆鎻愪氦鐘舵�佷负1锛堝凡鎻愪氦锛�
- .SetColumns(it => it.FcheckBy == userNo) // 璁剧疆妫�楠屼汉
- .SetColumns(it => it.FcheckDate == DateTime.Now) // 璁剧疆妫�楠屾椂闂�
+ var db = SqlSugarHelper.GetInstance();
+
+ // 鍏堣幏鍙栨楠屽崟璇︾粏淇℃伅锛堢敤浜庨拤閽夋帹閫佸垽鏂級
+ var inspectionData = db.Queryable<QsItemOqcReq>()
.Where(it => it.Id == id)
- .ExecuteCommand();
- });
+ .First();
+
+ if (inspectionData == null)
+ {
+ throw new Exception("妫�楠屽崟涓嶅瓨鍦�");
+ }
+
+ // 瀹氫箟杈撳嚭鍙傛暟
+ var outputResult = new SugarParameter("PO_RESULT", null,
+ System.Data.DbType.Int32, ParameterDirection.Output,
+ 4000);
+
+ var outputMessage = new SugarParameter("PO_MSG", null,
+ System.Data.DbType.String,
+ ParameterDirection.Output, 4000);
+
+ // 瀹氫箟杈撳叆鍙傛暟
+ var parameters = new List<SugarParameter>
+ {
+ new("P_ID", id, System.Data.DbType.Decimal, ParameterDirection.Input),
+ new("P_USER", userNo, System.Data.DbType.String, ParameterDirection.Input),
+ outputResult,
+ outputMessage
+ };
+
+ // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼
+ db.Ado.ExecuteCommand(
+ "BEGIN PRC_RKJ_UPDATE_SH(:P_ID, :P_USER, :PO_RESULT, :PO_MSG); END;",
+ parameters.ToArray());
+
+ // 鑾峰彇杈撳嚭鍙傛暟鐨勫��
+ var resultValue = outputResult.Value?.ToString();
+ var messageValue = outputMessage.Value?.ToString();
+
+ // 濡傛灉杩斿洖缁撴灉涓嶄负0锛岃〃绀哄け璐�
+ if ("1".Equals(resultValue))
+ {
+ throw new Exception(messageValue ?? "鎻愪氦澶辫触");
+ }
+
+ // 瀛樺偍杩囩▼鎵ц鎴愬姛鍚庯紝澶勭悊閽夐拤鎺ㄩ�侀�昏緫
+ // 妫�鏌ラ拤閽夋帹閫佹潯浠讹細PSZT涓哄緟鍒わ紝涓斾笉鑹師鍥犮�佷笉鑹弿杩般�佹墍灞炶溅闂翠笉涓虹┖
+ bool shouldPushToDingTalk = inspectionData.Pszt == "寰呭垽" &&
+ !string.IsNullOrEmpty(inspectionData.Blyy) &&
+ !string.IsNullOrEmpty(inspectionData.FngDesc) &&
+ !string.IsNullOrEmpty(inspectionData.Sscj);
+
+ // 濡傛灉婊¤冻鎺ㄩ�佹潯浠讹紝鍒欐帹閫佸埌閽夐拤
+ if (shouldPushToDingTalk)
+ {
+ try
+ {
+ // 鏋勫缓閽夐拤鎺ㄩ�佹暟鎹�
+ var dingTalkData = new GetQcIssueResultDetail
+ {
+ FbatchQty = inspectionData.Quantity?.ToString(), // 閫佹鏁伴噺
+ ItemName = inspectionData.ItemName,
+ ItemNo = inspectionData.ItemNo,
+ SuppName = "鐢熶骇鍏ュ簱", // 鍥哄畾鍊�
+ AppicationReason = inspectionData.FngDesc, // 涓嶈壇鎻忚堪
+ BadReason = inspectionData.Blyy, // 涓嶈壇鍘熷洜
+ remark = inspectionData.Remarks,
+ ReleaseNo = inspectionData.ReleaseNo,
+ StaffNo = userNo,
+ IqcStatus = inspectionData.Pszt, // 璇勫鐘舵��
+ Department = inspectionData.Sscj, // 浣跨敤鎵�灞炶溅闂翠綔涓洪儴闂�
+ WorkShop = inspectionData.Sscj, // 鎵�灞炶溅闂�
+ EMERGENCY = "0" // 鍥哄畾鍊间负0
+ };
+
+ // 璋冪敤閽夐拤鎺ㄩ�佹湇鍔�
+ var qcIssueResultManager = new QcIssueResultManager();
+ string dingTalkResult = qcIssueResultManager.GetProcessNo(dingTalkData, "RKJ");
+
+ // 瑙f瀽閽夐拤杩斿洖缁撴灉锛岃幏鍙栨祦绋嬪疄渚婭D
+ if (dingTalkResult.Contains("閽夐拤宸ヤ綔娴佸疄渚嬪惎鍔ㄦ垚鍔�"))
+ {
+ // 鎻愬彇instanceId
+ int startIndex = dingTalkResult.IndexOf("\"InstanceId\":\"") + 14;
+ int endIndex = dingTalkResult.IndexOf("\"", startIndex);
+ if (startIndex > 13 && endIndex > startIndex)
+ {
+ string instanceId = dingTalkResult.Substring(startIndex, endIndex - startIndex);
+
+ // 淇濆瓨閽夐拤娴佺▼淇℃伅
+ qcIssueResultManager.SaveProcessNo(
+ inspectionData.ReleaseNo,
+ instanceId,
+ userNo,
+ inspectionData.Sscj,
+ inspectionData.Pszt
+ );
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // 閽夐拤鎺ㄩ�佸け璐ヤ笉褰卞搷妫�楠屾彁浜わ紝鍙褰曟棩蹇�
+ Console.WriteLine($"閽夐拤鎺ㄩ�佸け璐�: {ex.Message}");
+ }
+ }
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ throw new Exception(ex.Message);
+ }
}
/// <summary>
@@ -851,4 +1090,378 @@
return (result, message);
}
+
+ /// <summary>
+ /// 鑾峰彇闄勪欢淇℃伅
+ /// </summary>
+ /// <param name="ItemNo">鐗╂枡缂栫爜</param>
+ /// <param name="projName">椤圭洰鍚嶇О锛堢敤浜庤繃婊わ級</param>
+ /// <returns>闄勪欢鍒楄〃</returns>
+ public List<QamftpDto> GetAttachments(string ItemNo, string projName = null)
+ {
+ var db = SqlSugarHelper.GetInstance();
+ try
+ {
+ var query = db.Queryable<MesQamftp>()
+ .Where(x => x.ItemNo == ItemNo)
+ .Where(x => x.Ftype == "鍏ュ簱妫�"); // 娣诲姞FTYPE = '鍏ュ簱妫�'鐨勯檺鍒�
+
+ // 濡傛灉浼犲叆浜唒rojName锛屽垯鎸塅version杩囨护
+ if (!string.IsNullOrEmpty(projName))
+ {
+ query = query.Where(x => x.Fversion == projName);
+ }
+
+ return query
+ .OrderBy(x => x.Fdate, OrderByType.Desc)
+ .Select(x => new QamftpDto
+ {
+ Id = x.Id,
+ itemNo = x.ItemNo,
+ Ftype = x.Ftype,
+ Fattach = x.Fattach,
+ Fversion = x.Fversion,
+ Fdate = x.Fdate,
+ CreateBy = x.CreateBy,
+ CreateDate = x.CreateDate,
+ Company = x.Company,
+ Factory = x.Factory,
+ F_type = x.F_type,
+ LastupdateBy = x.LastupdateBy,
+ LastupdateDate = x.LastupdateDate,
+ ItemId = x.ItemId
+ }).ToList();
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"鏌ヨ闄勪欢淇℃伅澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 浠嶧TP鏈嶅姟鍣ㄨ幏鍙栨枃浠�
+ /// </summary>
+ /// <param name="itemNo">鐗╂枡缂栫爜</param>
+ /// <param name="fileName">鏂囦欢鍚�</param>
+ /// <param name="projName">椤圭洰鍚嶇О</param>
+ /// <returns>鏂囦欢瀛楄妭鏁扮粍</returns>
+ public byte[] GetFtpFile(string itemNo, string fileName, string projName = null)
+ {
+ // 鍙傛暟楠岃瘉
+ if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName))
+ {
+ throw new ArgumentException("鍙傛暟涓嶈兘涓虹┖: itemNo, fileName");
+ }
+
+ string ftpUser = "hm_ftp";
+ string ftpPwd = "dell_123";
+ string ftpServer = "ftp://192.168.1.100"; // 榛樿FTP鏈嶅姟鍣ㄥ湴鍧�
+
+ // 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧�
+ string normalizedServer = NormalizeFtpServer(ftpServer);
+
+ // 鏋勫缓FTP鏂囦欢璺緞 - RKJ浣跨敤FQC鏂囦欢澶癸紝濡傛灉鏈塸rojName鍒欎娇鐢╬rojName浣滀负璺緞鐨勬渶鍚庝竴娈�
+ string ftpPath;
+ if (!string.IsNullOrEmpty(projName))
+ {
+ ftpPath = $"{normalizedServer}/FQC/{itemNo}/{projName}/{fileName}";
+ }
+ else
+ {
+ ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}";
+ }
+
+ try
+ {
+ var request = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(ftpPath);
+ request.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
+ request.Credentials = new System.Net.NetworkCredential(ftpUser, ftpPwd);
+ request.UseBinary = true;
+ request.UsePassive = false;
+ request.Timeout = 30000; // 30绉掕秴鏃�
+ request.ReadWriteTimeout = 30000;
+
+ using (var response = (System.Net.FtpWebResponse)request.GetResponse())
+ using (var ftpStream = response.GetResponseStream())
+ using (var ms = new System.IO.MemoryStream())
+ {
+ if (ftpStream == null)
+ {
+ throw new Exception("FTP鍝嶅簲娴佷负绌�");
+ }
+
+ ftpStream.CopyTo(ms);
+ var fileBytes = ms.ToArray();
+
+ if (fileBytes.Length == 0)
+ {
+ return null; // 鏂囦欢涓虹┖鎴栦笉瀛樺湪
+ }
+
+ return fileBytes;
+ }
+ }
+ catch (System.Net.WebException ex)
+ {
+ if (ex.Response is System.Net.FtpWebResponse ftpResponse)
+ {
+ switch (ftpResponse.StatusCode)
+ {
+ case System.Net.FtpStatusCode.ActionNotTakenFileUnavailable:
+ return null; // 鏂囦欢涓嶅瓨鍦�
+ case System.Net.FtpStatusCode.NotLoggedIn:
+ throw new Exception("FTP璁よ瘉澶辫触锛岃妫�鏌ョ敤鎴峰悕鍜屽瘑鐮�");
+ case System.Net.FtpStatusCode.ActionNotTakenFilenameNotAllowed:
+ throw new Exception("鏂囦欢鍚嶄笉琚厑璁告垨璺緞鏃犳晥");
+ default:
+ throw new Exception($"FTP閿欒 ({ftpResponse.StatusCode}): {ftpResponse.StatusDescription}");
+ }
+ }
+
+ // 澶勭悊瓒呮椂鍜岀綉缁滈敊璇�
+ if (ex.Status == System.Net.WebExceptionStatus.Timeout)
+ {
+ throw new Exception("FTP杩炴帴瓒呮椂锛岃绋嶅悗閲嶈瘯");
+ }
+
+ throw new Exception($"FTP杩炴帴澶辫触: {ex.Message}");
+ }
+ catch (Exception ex)
+ {
+ throw new Exception($"鑾峰彇FTP鏂囦欢澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鑾峰彇鏂囦欢鍐呭绫诲瀷
+ /// </summary>
+ /// <param name="fileName">鏂囦欢鍚�</param>
+ /// <returns>鍐呭绫诲瀷</returns>
+ public string GetContentType(string fileName)
+ {
+ if (string.IsNullOrEmpty(fileName))
+ return "application/octet-stream";
+
+ var extension = System.IO.Path.GetExtension(fileName).ToLowerInvariant();
+ return extension switch
+ {
+ ".pdf" => "application/pdf",
+ ".jpg" or ".jpeg" => "image/jpeg",
+ ".png" => "image/png",
+ ".gif" => "image/gif",
+ ".bmp" => "image/bmp",
+ ".txt" => "text/plain",
+ ".doc" => "application/msword",
+ ".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
+ ".xls" => "application/vnd.ms-excel",
+ ".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
+ ".ppt" => "application/vnd.ms-powerpoint",
+ ".pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
+ _ => "application/octet-stream"
+ };
+ }
+
+ /// <summary>
+ /// 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧�
+ /// </summary>
+ /// <param name="ftpServer">FTP鏈嶅姟鍣ㄥ湴鍧�</param>
+ /// <returns>鏍囧噯鍖栧悗鐨勫湴鍧�</returns>
+ private string NormalizeFtpServer(string ftpServer)
+ {
+ if (string.IsNullOrEmpty(ftpServer))
+ throw new ArgumentException("FTP鏈嶅姟鍣ㄥ湴鍧�涓嶈兘涓虹┖");
+
+ // 绉婚櫎鍙兘鐨勫崗璁墠缂�
+ var normalized = ftpServer.Trim();
+ if (normalized.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase))
+ {
+ normalized = normalized.Substring(6);
+ }
+ else if (normalized.StartsWith("ftps://", StringComparison.OrdinalIgnoreCase))
+ {
+ normalized = normalized.Substring(7);
+ }
+
+ // 纭繚浠tp://寮�澶�
+ if (!normalized.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase))
+ {
+ normalized = "ftp://" + normalized;
+ }
+
+ return normalized;
+ }
+
+ /// <summary>
+ /// 淇濆瓨涓嬫媺妗嗗瓧娈碉紙涓嶈壇鍘熷洜銆佽瘎瀹$姸鎬併�佹墍灞炶溅闂达級
+ /// </summary>
+ /// <param name="dto">鍖呭惈瀛楁鏁版嵁鐨凞TO</param>
+ /// <returns>鏇存柊缁撴灉</returns>
+ public int SaveDropdownFields(RKJDto dto)
+ {
+ return SqlSugarHelper.UseTransactionWithOracle(db =>
+ {
+ return db.Updateable<QsItemOqcReq>()
+ .SetColumns(it => it.Blyy == dto.BLYY)
+ .SetColumns(it => it.Pszt == dto.PSZT)
+ .SetColumns(it => it.Sscj == dto.SSCJ)
+ .Where(it => it.ReleaseNo == dto.releaseNo)
+ .ExecuteCommand();
+ });
+ }
+
+ /// <summary>
+ /// 淇濆瓨涓嶈壇鎻忚堪
+ /// </summary>
+ /// <param name="gid">妫�楠屽崟ID</param>
+ /// <param name="fngDesc">涓嶈壇鎻忚堪</param>
+ /// <returns>鏇存柊缁撴灉</returns>
+ public int SaveFngDesc(decimal gid, string fngDesc)
+ {
+ return SqlSugarHelper.UseTransactionWithOracle(db =>
+ {
+ return db.Updateable<QsItemOqcReq>()
+ .SetColumns(it => it.FngDesc == fngDesc)
+ .Where(it => it.Id == gid)
+ .ExecuteCommand();
+ });
+ }
+
+ /// <summary>
+ /// 涓婁紶鍥剧墖鍒� QS_ITEM_IPI_IMAGE 琛紙鍏ュ簱妫� QS_TYPE=3锛屾敮鎸佸鍥剧墖锛�
+ /// </summary>
+ /// <param name="id">妫�楠岄」鐩甀D (FID)</param>
+ /// <param name="imageBytes">鍥剧墖瀛楄妭鏁扮粍</param>
+ /// <param name="fileName">鍘熷鏂囦欢鍚�</param>
+ /// <param name="createBy">鍒涘缓浜�</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public (int status, string message) UploadImageToPicture(decimal id, byte[] imageBytes, string fileName, string createBy)
+ {
+ try
+ {
+ if (imageBytes == null || imageBytes.Length == 0)
+ {
+ return (1, "鍥剧墖鏁版嵁涓虹┖");
+ }
+
+ if (string.IsNullOrEmpty(fileName))
+ {
+ return (1, "鏂囦欢鍚嶄负绌�");
+ }
+
+ // 楠岃瘉鍥剧墖鏍煎紡
+ var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" };
+ var extension = System.IO.Path.GetExtension(fileName).ToLower();
+ if (!allowedExtensions.Contains(extension))
+ {
+ return (1, "涓嶆敮鎸佺殑鍥剧墖鏍煎紡锛屼粎鏀寔锛歫pg, jpeg, png, gif, bmp, webp");
+ }
+
+ // 楠岃瘉鍥剧墖澶у皬锛堥檺鍒朵负5MB锛�
+ if (imageBytes.Length > 5 * 1024 * 1024)
+ {
+ return (1, "鍥剧墖澶у皬涓嶈兘瓒呰繃5MB");
+ }
+
+ // 鐢熸垚鏃堕棿鎴虫枃浠跺悕锛屾牸寮忥細1746945271304.jpg
+ var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
+ var timestampFileName = $"{timestamp}{extension}";
+
+ var result = SqlSugarHelper.UseTransactionWithOracle(db =>
+ {
+ // 妫�鏌ユ楠岄」鐩槸鍚﹀瓨鍦紝骞惰幏鍙栨楠屽崟ID鍜屾楠岄」鐩悕绉�
+ var oqcItem = db.Queryable<QsItemOqcItem>()
+ .Where(s => s.Id == id)
+ .Select(s => new { s.Id, s.Pid, s.ProjName })
+ .First();
+
+ if (oqcItem == null)
+ {
+ throw new Exception("妫�楠岄」鐩笉瀛樺湪");
+ }
+
+ // 姣忔閮藉垱寤烘柊鐨勫浘鐗囪褰曪紝鏀寔澶氬浘鐗囦笂浼�
+ var newImage = new QsItemIpiImage
+ {
+ Fid = id, // 妫�楠岄」鐩甀D (QS_ITEM_OQC_ITEM.ID)
+ Gid = oqcItem.Pid, // 妫�楠屽崟ID (QS_ITEM_OQC_REQ.ID)
+ QsType = 3, // 鍏ュ簱妫�绫诲瀷
+ ImageData = imageBytes,
+ Picturename = timestampFileName,
+ JyName = oqcItem.ProjName, // 妫�楠岄」鐩悕绉�
+ CreateDate = DateTime.Now,
+ CreateBy = createBy
+ };
+ return db.Insertable(newImage).ExecuteCommand();
+ });
+
+ if (result > 0)
+ {
+ return (0, "鍥剧墖淇濆瓨鎴愬姛");
+ }
+ else
+ {
+ return (1, "鍥剧墖淇濆瓨澶辫触");
+ }
+ }
+ catch (Exception ex)
+ {
+ return (1, $"鍥剧墖淇濆瓨澶辫触锛歿ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鍒犻櫎妫�楠岄」鐩殑鍥剧墖锛堜粠 QS_ITEM_IPI_IMAGE 琛ㄤ腑鍒犻櫎锛屽叆搴撴 QS_TYPE=3锛�
+ /// </summary>
+ /// <param name="id">妫�楠岄」鐩甀D (FID)锛屽綋imageId涓虹┖鏃跺垹闄よ妫�楠岄」鐩殑鎵�鏈夊浘鐗�</param>
+ /// <param name="imageId">鍥剧墖ID锛岀敤浜庡垹闄ゅ崟寮犲浘鐗囷紙鍙�夛級</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public (int status, string message) DeleteImageFromPicture(decimal id, decimal? imageId = null)
+ {
+ try
+ {
+ var result = SqlSugarHelper.UseTransactionWithOracle(db =>
+ {
+ // 妫�鏌ユ楠岄」鐩槸鍚﹀瓨鍦�
+ var exists = db.Queryable<QsItemOqcItem>()
+ .Where(s => s.Id == id)
+ .Any();
+
+ if (!exists)
+ {
+ throw new Exception("妫�楠岄」鐩笉瀛樺湪");
+ }
+
+ int deleteResult;
+ if (imageId.HasValue && imageId.Value > 0)
+ {
+ // 鍒犻櫎鍗曞紶鍥剧墖
+ deleteResult = db.Deleteable<QsItemIpiImage>()
+ .Where(s => s.Id == imageId.Value && s.Fid == id && s.QsType == 3)
+ .ExecuteCommand();
+ }
+ else
+ {
+ // 鍒犻櫎璇ユ楠岄」鐩殑鎵�鏈夊浘鐗�
+ deleteResult = db.Deleteable<QsItemIpiImage>()
+ .Where(s => s.Fid == id && s.QsType == 3)
+ .ExecuteCommand();
+ }
+
+ return deleteResult;
+ });
+
+ if (result > 0)
+ {
+ return (0, "鍥剧墖鍒犻櫎鎴愬姛");
+ }
+ else
+ {
+ return (0, "娌℃湁鎵惧埌瑕佸垹闄ょ殑鍥剧墖");
+ }
+ }
+ catch (Exception ex)
+ {
+ return (1, $"鍥剧墖鍒犻櫎澶辫触锛歿ex.Message}");
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3