111
啊鑫
2025-07-17 93473e2792e5d23a168e575f17190a5e51ad7c9f
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
using System.Data;
using MES.Service.DB;
using MES.Service.Dto.service;
using MES.Service.Modes;
using MES.Service.util;
using SqlSugar;
using DbType = System.Data.DbType;
 
namespace MES.Service.service.QC;
 
public class MesLaboratoryService : Repository<MesLaboratory>
{
    //OQCDto
    public bool SaveLaboratory(OQCDto dto)
    {
        //1.根据BillNo查询视图VLaboratory,用dto的OrderNo,使用.First()只返回一个对象
        var vLaboratory = Context.Queryable<VLaboratory>()
            .Where(x => x.BillNo == dto.OrderNo)
            .First();
 
        //2.将查询出来的VLaboratory转换为MesLaboratory
        var mesLaboratory = new MesLaboratory
        {
            BillNo = vLaboratory.BillNo,
            LineNo = vLaboratory.LineNo,
            ItemId = vLaboratory.ItemId,
            ItemNo = vLaboratory.ItemNo,
            ItemName = vLaboratory.ItemName,
            ItemModel = vLaboratory.ItemModel,
            DepartmentId = vLaboratory.DepartmentId,
            DepartmentCode = vLaboratory.DepartmentCode,
            SaleOrderNoc = vLaboratory.SaleOrderNoc,
            CreateBy = dto.CreateUser,
            CreateTime = DateTime.Now
        };
 
        //3.插入到数据库中
        return Context.Insertable(mesLaboratory)
            .IgnoreColumns(ignoreNullColumn: true)
            .ExecuteCommand() > 0;
    }
 
    public new object InsertReturnIdentity(MesLaboratory data)
    {
        return base.InsertReturnIdentity(data);
    }
 
    public (List<MesLaboratory> item, int TotalCount) GetPage(
        XJPageResult queryObj)
    {
        if (queryObj == null)
            throw new ArgumentNullException(nameof(queryObj));
 
        var db = Db;
        var totalCount = 0;
 
        if (!decimal.TryParse(queryObj.id, out var id))
            id = 0;
 
        var pageList = db
            .Queryable<MesLaboratory, SysUser, SysUser>((a, b, c) =>
                new JoinQueryInfos(JoinType.Left, a.CreateBy == b.Fcode,
                    JoinType.Left, a.InspectionBy == c.Fcode
                ))
            .WhereIF(id > 0, (a, b, c) => a.Id == id)
            .Select((a, b, c) => new MesLaboratory()
            {
                CreateUser = b.Fname,
                InspectionUser = c.Fname,
                DepartmentId = a.DepartmentId,
            }, true)
            .OrderByDescending(a => a.Id)
            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
 
        return (pageList, totalCount);
    }
 
    /// <summary>
    /// 录入检验结果
    /// </summary>
    /// <param name="data">实验室检测数据</param>
    /// <returns></returns>
    public bool UpdateInspectionResult(MesLaboratory data)
    {
        return Context.Updateable<MesLaboratory>()
            .SetColumnsIF(!string.IsNullOrEmpty(data.InspectionResult),
                x => x.InspectionResult == data.InspectionResult)
            .SetColumnsIF(!string.IsNullOrEmpty(data.InspectionBy),
                x => x.InspectionBy == data.InspectionBy)
            .SetColumns(x => x.InspectionTime == DateTime.Now)
            .Where(x => x.Id == data.Id)
            .ExecuteCommand() > 0;
    }
}