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 { //OQCDto public bool SaveLaboratory(OQCDto dto) { //1.根据BillNo查询视图VLaboratory,用dto的OrderNo,使用.First()只返回一个对象 var vLaboratory = Context.Queryable() .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 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((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); } /// /// 录入检验结果 /// /// 实验室检测数据 /// public bool UpdateInspectionResult(MesLaboratory data) { return Context.Updateable() .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; } }