schangxiang@126.com
2025-09-29 682eba0aaf922e69dfafe05fb6c1bbdbf3a0e04a
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
using iWareCommon.Utils;
using iWareLog.ORM;
using iWareLog.Report.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace iWareLog.Report.Service
{
    public class InOutService
    {
        private static object Lock = new object();
 
        private static InOutService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>单例实体</returns>
        public static InOutService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new InOutService();
                    }
                }
            }
            return Instance;
        }
 
 
 
        /// <summary>
        /// 根据出入库类型,物料类型查询
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public List<InOutHelper> GetMaterial(DateTime start, DateTime end, int type)
        {
            using (DbModelLog context = new DbModelLog())
            {
                try
                {
                    string sql = @"select count(B.typename)quantity,B.typename materialcode from  InOutStorageDetail A left join WGQ_WB19011_CORE.[dbo].[BASEMaterialView] B on A.materialid=B.id
                                    where A.type=@p0 and A.updatetime>=@p1 and A.updatetime<@p2 group by B.typename";
                    List<InOutHelper> data = context.Database.SqlQuery<InOutHelper>(sql, type, start, end).ToList();
                    return data;
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("InOutService", "GetInMaterial", ex.ToString());
                    return null;
                }
            }
        }
 
 
        /// <summary>
        /// 查询出入库明细及物料信息(联查 InOutStorageDetail 和 BASEMaterialView)
        /// </summary>
        /// <returns>返回包含型材编码、船号、分段号、业务标识、库位、时间等信息的列表</returns>
        public List<InOutStorageDetailResultForMes> GetInOutStorageDetailListForMes()
        {
            using (DbModelLog context = new DbModelLog())
            {
                try
                {
                    string sql = @"
                SELECT 
                    A.id AS Id,
                    B.code AS Code,
                    B.issueprojectno AS IssueProjectNo,
                    B.serialno AS SerialNo,
                    A.type AS BusinessFlag,
                    A.toplacecode AS PlaceCode,
                    A.createtime AS Timestamp,
                    A.createtime AS OccurrenceTime
                FROM 
                    InOutStorageDetail A
                INNER JOIN 
                    WGQ_WB19011_CORE.[dbo].[BASEMaterialView] B
                    ON A.materialid = B.id And A.isSendToMes=1 ";
 
                    // 执行 SQL 查询,并映射到自定义类 InOutStorageDetailResult
                    var data = context.Database.SqlQuery<InOutStorageDetailResultForMes>(sql).ToList();
 
                    return data;
                }
                catch (Exception ex)
                {
                    // 记录异常日志(和你原有方法保持一致)
                    LogTextHelper.WriteLine("InOutService", "GetInOutStorageDetailList", ex.ToString());
                    return null; // 或者返回 new List<InOutStorageDetailResult>(),根据你的业务需求
                }
            }
        }
 
    }
}