zhao
2021-07-19 8347f2fbddbd25369359dcb2da1233ac48a19fdc
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using HH.MData;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
 
namespace HW.DAL.Common {
    public class CommonDAL : BaseDAL {
        MongoDBHelper dbHelper = null;
 
        #region 新增一个集合到mongo数据库
        /// <summary>
        /// 新增一个集合到mongo数据库
        /// </summary>
        /// <typeparam name="T">实体类</typeparam>
        /// <param name="lstEntity">实体类集合数据</param>
        /// <param name="CollectionName">对象名称</param>
        /// <returns></returns>
        public bool AddList<T>(List<T> lstEntity, string collectionName) {
            try {
                dbHelper = new MongoDBHelper();
                bool result = dbHelper.Insert<T>(lstEntity, collectionName);
                return result;
            }
            catch (Exception ex) {
                HanHe.Service.Log.Info("mongo error", ex.Message);
                return false;
            }
        }
        #endregion
 
        #region 根据物料编码删除
        /// <summary>
        /// 根据物料编码删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="code">物料编码</param>
        /// <param name="collectionName">集合名称</param>
        /// <returns></returns>
        public bool RemoveDataByCode<T>(string code, string collectionName) {
            dbHelper = new MongoDBHelper();
            IMongoQuery query = Query.EQ("S_60_C1", code);
            bool result = dbHelper.Remove<T>(query, collectionName);
            return result;
        }
        #endregion
 
        #region 根据物料编码删除
        /// <summary>
        /// 根据物料编码删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="code">物料编码</param>
        /// <param name="collectionName">集合名称</param>
        /// <returns></returns>
        public bool RemoveDataByCodeHc<T>(string code, string collectionName)
        {
            dbHelper = new MongoDBHelper();
            IMongoQuery query = Query.EQ("CN_S_ITEM_CODE", code);
            bool result = dbHelper.Remove<T>(query, collectionName);
            return result;
        }
        #endregion
 
        #region 判断记录是否存在
        /// <summary>
        /// 判断记录是否存在
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="code">物料编码</param>
        /// <param name="collectionName">集合名称</param>
        /// <returns></returns>
        public bool IsExistsMongo<T>(string code, string collectionName) {
            dbHelper = new MongoDBHelper();
            IMongoQuery query = Query.EQ("S_60_C1", code);
            long count = dbHelper.FindCount<T>(query, collectionName);
            if (count > 0) return true;
            return false;
        }
        #endregion
 
 
            #region 判断记录是否存在
        /// <summary>
        /// 判断记录是否存在
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="code">物料编码</param>
        /// <param name="collectionName">集合名称</param>
        /// <returns></returns>
        public bool IsExistsMongoHc<T>(string code, string collectionName)
        {
            dbHelper = new MongoDBHelper();
            IMongoQuery query = Query.EQ("CN_S_ITEM_CODE", code);
            long count = dbHelper.FindCount<T>(query, collectionName);
            if (count > 0) return true;
            return false;
        }
        #endregion
 
        #region 新增一条实体记录到MONGO数据库
        /// <summary>
        /// 新增一条实体记录到MONGO数据库
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="entity">实体数据</param>
        /// <param name="collectionName">对象名称</param>
        /// <returns></returns>
        public bool Add<T>(T entity, string collectionName) {
            dbHelper = new MongoDBHelper();
            bool result = dbHelper.Insert(entity, collectionName);
            return result;
        }
        #endregion
    }
}