schangxiang@126.com
2025-09-23 ea04aef49691444ed8ac1e7e7b94feabcbb5326f
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 iWareCommon.Utils;
using iWareDataCore.BASE.Entity;
using iWareDataCore.ORM;
using iWareDataCore.Properties;
using iWareDataCore.Report.PlaceMaterial.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace iWareDataCore.Report.PlaceMaterial.Service
{
    public class PlaceMaterialViewService
    {
        private static object Lock = new object();
 
        private static PlaceMaterialViewService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>单例实体</returns>
        public static PlaceMaterialViewService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new PlaceMaterialViewService();
                    }
                }
            }
            return Instance;
        }
 
 
 
        /// <summary>
        /// 查询数量按物料类型分组,
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public List<PlaceMaterialHelper> GetMaterialByType()
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
                    string sql = "SELECT materialcode,typename,COUNT(id) as quantity FROM BASEPlaceMaterialView  group by materialcode, typename";
                    List<PlaceMaterialHelper> data = context.Database.SqlQuery<PlaceMaterialHelper>(sql).ToList();
                    return data;
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("PlaceMaterialViewService", "GetMaterialByType", ex.ToString());
                    return null;
                }
            }
        }
 
        
 
        /// <summary>
        /// 获取各种状态的库位
        /// </summary>
        /// <returns></returns>
        public List<PlaceMaterialHelper> GetPlaceStatusNum(out string msg) 
        {
            msg = "";
            List<PlaceMaterialHelper> psnlst = new List<PlaceMaterialHelper>();
            try
            {
                using (DbModelCore mcore = new DbModelCore())
                {
                    string sql = @"select A.EmptyPlace,B.FullPlace,C.LockPlace from 
                              (select 1 as id,COUNT(id) as EmptyPlace from BASEPlace where typeid=4 and status=0 )A left join
                              (select 1 as id,COUNT(id) as FullPlace from BASEPlace where typeid=4 and status=2)B on A.id=B.id left join
                              (select 1 as id,COUNT(id) as LockPlace from BASEPlace where typeid=4 and islock=1)C on A.id=C.id";
                    psnlst = mcore.Database.SqlQuery<PlaceMaterialHelper>(sql).ToList();
                }
                return psnlst;
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "GetPlaceStatusNum", ex.Message);
                return psnlst;
            }
        }
    }
}