南骏 池
2025-06-02 1be2fc056943ba8b9e62328430e15beee03e8a9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using MES.Service.Models;
using Microsoft.IdentityModel.Tokens;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
using SqlSugar;
using System.Data;
using System.Data.SqlClient;
using static Azure.Core.HttpHeader;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
namespace NewPdaSqlServer.service.QC;
 
public class IpqcService : RepositoryNoEntity
{
    public (List<VIpqcSj> item, int TotalCount) getPageSj(XJPageResult queryObj)
    {
        var parsedGuid = Guid.Empty;
        if (!queryObj.id.IsNullOrEmpty())
        {
            var isValid = Guid.TryParse(queryObj.id, out parsedGuid);
            if (!isValid)
                throw new ApplicationException("GUID转换错误");
        }
 
 
        var totalCount = 0;
 
        var pageList = Db.Queryable<VIpqcSj>()
            .WhereIF(!string.IsNullOrWhiteSpace(queryObj.keyword), a =>
                a.ItemNo.Contains(queryObj.keyword) ||
                a.ItemName.Contains(queryObj.keyword) ||
                a.Daa001.Contains(queryObj.keyword) ||
                a.ReleaseNo.Contains(queryObj.keyword) ||
                a.DepartmentName.Contains(queryObj.keyword )||
                a.XtName.Contains(queryObj.keyword) 
            )
            .WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                a => a.Guid == parsedGuid.ToString() )
            .Where(a => (a.FSubmit ?? 0) == 0)
            .OrderByDescending(a => a.CreateDate)
            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
 
        return (pageList, totalCount);
    }
 
    public List<MesQaItemsDetectDetail5> GetItems(string? releaseNo,
        string? id)
    {
        var parsedGuid = Guid.Empty;
 
        if (id != null)
        {
            var isValid = Guid.TryParse(id, out parsedGuid);
            if (!isValid)
                throw new ApplicationException("GUID转换错误");
        }
 
        var Ybsl_In = Db.Queryable<MesQaItemsDetectDetail5>()
            .Where(a => a.ParentGuid == parsedGuid)
            .Count();
 
        return Db.Queryable<MesQaItemsDetectDetail5, MesQaItemsDetectDetail12>(
                (a, b) =>
                    new JoinQueryInfos(JoinType.Left, a.Guid == b.ParentGuid))
            .Where((a, b) => a.ReleaseNo == releaseNo)
            .WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                (a, b) => a.Guid == parsedGuid)
            .GroupBy((a, b) => new
            {
                a.Guid,
                a.ParentGuid,
                a.ReleaseNo,
                a.FacLevel,
                a.FcheckItem,
                a.FcheckTool,
                a.FdownAllow,
                a.FcheckLevel,
                a.Fstand,
                a.FupAllow,
                a.SampleSizeNo,
                a.FspecRequ,
                a.FreQty,
                a.CheckQyt,
                a.FcheckResu,
                a.Order,
                a.Ybsl,
                a.ISRZXX,
                a.IPQCRZXX,
                a.IPQCRZXXDate,
                a.IPQCRZXXNum,
                a.IPQCpscs,
                a.FcheckType,
            }).Select((a, b) => new MesQaItemsDetectDetail5
            {
                Guid = a.Guid,
                ParentGuid = a.ParentGuid,
                ReleaseNo = a.ReleaseNo,
                CheckQyt = a.CheckQyt,
                FacLevel = a.FacLevel,
                FcheckItem = a.FcheckItem,
                FcheckTool = a.FcheckTool,
                FdownAllow = a.FdownAllow,
                FcheckLevel = a.FcheckLevel,
                Fstand = a.Fstand,
                FupAllow = a.FupAllow,
                SampleSizeNo = a.SampleSizeNo,
                FspecRequ = a.FspecRequ,
                FreQty = a.FreQty,
                Factory = "1000",
                Company = "1000",
                FenterQty = SqlFunc.AggregateCount(b.Guid),
                FcheckResu = a.FcheckResu,
                Order = a.Order,
                Ybsl = a.Ybsl,
                YbslIn = Ybsl_In,
                ISRZXX = a.ISRZXX,
                IPQCRZXX = a.IPQCRZXX,
                IPQCRZXXDate = a.IPQCRZXXDate.ToString(),
                IPQCRZXXNum = a.IPQCRZXXNum,
                IPQCpscs = a.IPQCpscs,
                FcheckType =a.FcheckType,
            }).OrderBy(a => a.Order)
            .ToList();
    }
 
 
    public (List<VIpqcXj> item, int TotalCount) getPageXj(XJPageResult queryObj)
    {
        var parsedGuid = Guid.Empty;
        if (!queryObj.id.IsNullOrEmpty())
        {
            var isValid = Guid.TryParse(queryObj.id, out parsedGuid);
            if (!isValid)
                throw new ApplicationException("GUID转换错误");
        }
 
 
        var totalCount = 0;
 
        var pageList = Db.Queryable<VIpqcXj>()
            .WhereIF(!string.IsNullOrWhiteSpace(queryObj.keyword), a =>
                a.ItemNo.Contains(queryObj.keyword) ||
                a.ItemName.Contains(queryObj.keyword) ||
                a.Daa001.Contains(queryObj.keyword) ||
                a.ReleaseNo.Contains(queryObj.keyword) ||
                a.DepartmentName.Contains(queryObj.keyword) ||
                a.xtName.Contains(queryObj.keyword)
            )
            .WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                a => a.Guid == parsedGuid.ToString())
            .Where(a => (a.FSubmit ?? 0) == 0)
            .OrderByDescending(a => a.CreateDate)
            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
 
        return (pageList, totalCount);
    }
 
 
    //更新不合格描述
    public int updateIpqcRzxx(LLJDto dto)
    {
        if (dto == null) throw new ArgumentNullException(nameof(dto), "参数对象不能为 null");
 
        // 参数校验(根据存储过程新增参数)
        if (string.IsNullOrEmpty(dto.pid?.ToString()))
            throw new ArgumentException("项目明细id存在问题,请联系管理员!", nameof(dto.pid));
 
        var withOracle = Db.Updateable<MesQaItemsDetectDetail5>()
                .SetColumns(s => s.IPQCRZXX == dto.inRzxxValue)
                .Where(s => s.Guid.ToString() == dto.pid)
                .ExecuteCommand();
 
        return withOracle;
    }
 
 
    public dynamic CreateByWomdaa(dynamic query)
    {
        if (query == null) throw new ArgumentNullException(nameof(query));
 
        if (string.IsNullOrEmpty(query.userAccount?.ToString()))
            throw new ArgumentException("用户账号不能为空", nameof(query.userAccount));
 
        if (string.IsNullOrEmpty(query.inOrderGuid1?.ToString()))
            throw new ArgumentException("检验单GUID不能为空", nameof(query.inOrderGuid1));
 
            if (string.IsNullOrEmpty(query.DAA001?.ToString()))
                throw new ArgumentException("工单号不能为空", nameof(query.inOrderGuid1));
 
            var _strMsg = "";
        var _status = -1;
 
        using (var conn = new SqlConnection(DbHelperSQL.strConn))
        using (var cmd = new SqlCommand("ipqc_createByWomdaa", conn))
        {
            try
            {
                conn.Open();
                cmd.CommandType = CommandType.StoredProcedure;
 
                SqlParameter[] parameters = 
                {
                    new("@po_outMsg", SqlDbType.NVarChar, 150) { Direction = ParameterDirection.Output },
                    new("@po_outStatus", SqlDbType.Int) { Direction = ParameterDirection.Output },
                    new("@pi_user", SqlDbType.NVarChar, 150) { Value = query.userAccount },
                    new("@pi_OrderGuid1", SqlDbType.UniqueIdentifier) { Value = Guid.Parse(query.inOrderGuid1.ToString()) },
                    new("@pi_DAA001", SqlDbType.NVarChar, 150) { Value = query.DAA001.ToString() },
                    new("@pi_inP1", SqlDbType.NVarChar, 20) { Value = query.pi_inP1 ?? DBNull.Value },
                    new("@pi_inP2", SqlDbType.NVarChar, 20) { Value = query.pi_inP2 ?? DBNull.Value }
                };
 
                cmd.Parameters.AddRange(parameters);
                cmd.ExecuteNonQuery();
 
                _strMsg = parameters[0].Value?.ToString() ?? "";
                _status = Convert.ToInt32(parameters[1].Value ?? -1);
 
                if (_status <= 0) throw new Exception(_strMsg);
 
                return new 
                {
                    message = _strMsg,
                    status = _status
                };
            }
            catch (Exception ex)
            {
                throw new Exception($"检验单更新失败:{ex.Message}");
            }
        }
    }
 
    public int UpdateTableConfig(string selectedWater, string selectedFlow, string tableData, string mxguid)
    {
        var sqlParams = new List<SugarParameter> {
            new("@selectedWater", selectedWater),
            new("@selectedFlow", selectedFlow),
            new("@tableData", tableData),
            new("@mxguid", mxguid)
        };
 
        var sql = @"UPDATE MES_QA_ITEMS_DETECT_DETAIL5 
                    SET ipqc_zrxn_sel1 = @selectedWater,
                        ipqc_zrxn_sel2 = @selectedFlow,
                        ipqc_zrxn_table = @tableData 
                    WHERE guid = @mxguid";
 
        return Db.Ado.ExecuteCommand(sql, sqlParams);
    }
 
    public dynamic GetTableConfig(string mxguid)
    {
        var sqlParams = new List<SugarParameter> {
            new("@mxguid", mxguid)
        };
 
        var sql = @"SELECT ipqc_zrxn_sel1,ipqc_zrxn_sel2,ipqc_zrxn_table 
                    FROM MES_QA_ITEMS_DETECT_DETAIL5 
                    WHERE guid = @mxguid";
 
        var result = Db.Ado.SqlQuery<dynamic>(sql, sqlParams).FirstOrDefault();
        
        if (result == null)
            throw new Exception("配置信息查询结果为空");
 
        return result;
    }
 
    public List<dynamic> GetRzxxList(string mxguid)
    {
        var sqlParams = new List<SugarParameter> {
            new("@mxguid", mxguid)
        };
 
        var sql = @"SELECT a.s_type, a.defect_name 
                    FROM [dbo].[MES_DEFECT_CODE] a 
                    WHERE a.s_type = '认证信息' 
                    AND a.pid = ( 
                        SELECT TOP 1 b.guid 
                        FROM [dbo].[MES_DEFECT_CODE] b 
                        INNER JOIN [dbo].[MES_QA_ITEMS_DETECT_DETAIL5] d 
                            ON b.defect_name = d.fcheck_item 
                        WHERE d.guid = @mxguid 
                        ORDER BY b.guid 
                    )";
 
        var result = Db.Ado.SqlQuery<dynamic>(sql, sqlParams);
        
        if (result == null || result.Count == 0)
            throw new Exception("未找到相关认证信息");
 
        return result;
    }
 
    public int UpdateScDate(string scDateValue, string mxguid)
    {
        var sqlParams = new List<SugarParameter> {
            new("@scDateValue", scDateValue),
            new("@mxguid", mxguid)
        };
 
        var sql = @"UPDATE MES_QA_ITEMS_DETECT_DETAIL5 
                    SET ipqc_rzxx_date = @scDateValue 
                    WHERE guid = @mxguid";
 
        return Db.Ado.ExecuteCommand(sql, sqlParams);
    }
 
    public int UpdateRzxxNum(string ipqcrzxxNum, string mxguid)
    {
        var sqlParams = new List<SugarParameter> {
            new("@ipqcrzxxNum", ipqcrzxxNum),
            new("@mxguid", mxguid)
        };
 
        var sql = @"UPDATE MES_QA_ITEMS_DETECT_DETAIL5 
                    SET ipqc_rzxx_num = @ipqcrzxxNum 
                    WHERE guid = @mxguid";
 
        return Db.Ado.ExecuteCommand(sql, sqlParams);
    }
 
    public int UpdateCpscs(string ipqCpscs, string mxguid)
    {
        var sqlParams = new List<SugarParameter> {
            new("@ipqCpscs", ipqCpscs),
            new("@mxguid", mxguid)
        };
 
        var sql = @"UPDATE MES_QA_ITEMS_DETECT_DETAIL5 
                    SET ipqc_pscs = @ipqCpscs 
                    WHERE guid = @mxguid";
 
        return Db.Ado.ExecuteCommand(sql, sqlParams);
    }
}