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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CY.IDAL;
using System.Data.SqlClient;
using System.Data;
using CY.Model;
 
namespace CY.SQLDAL
{
    public class Integrity_ComplainanInfoDAL : IIntegrity_ComplainanInfoDAL
    {
        private Database _dataBase = null;
 
        public Integrity_ComplainanInfoDAL()
        {
            _dataBase = new Database();
        }
 
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool InserModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Integrity_ComplainanInfo trueModel = model as Model.Integrity_ComplainanInfo;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter orderIdPar = null;
            if (trueModel.OrderId.HasValue)
            {
                orderIdPar = new SqlParameter("@OrderId", trueModel.OrderId);
            }
            else
            {
                orderIdPar = new SqlParameter("@OrderId", DBNull.Value);
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@RespondentId",trueModel.RespondentId),
                    new SqlParameter("@ComplainantId",trueModel.ComplainantId),
                    new SqlParameter("@OrderCode",trueModel.OrderCode),
                    new SqlParameter("@ComplaintsReason",trueModel.ComplaintsReason),
                    new SqlParameter("@ComplaintsStatusId",trueModel.ComplaintsStatusId),
                    new SqlParameter("@ComplaintsTypeId",trueModel.ComplaintsTypeId),
                    new SqlParameter("@ComplaintsTime",trueModel.ComplaintsTime),
                    new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime),
                    orderIdPar
            };
            try
            {
                _dataBase.Query("sp_Integrity_ComplainanInfo_Insert", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Integrity_ComplainanInfo trueModel = model as Model.Integrity_ComplainanInfo;
            if (trueModel == null)
            {
                return false;
            }
            SqlParameter auditTimePar = null;
            if (trueModel.AuditTime.HasValue)
            {
                auditTimePar = new SqlParameter("@AuditTime", trueModel.AuditTime.Value);
            }
            else
            {
                auditTimePar = new SqlParameter("@AuditTime", DBNull.Value);
            }
            SqlParameter handleTimePar = null;
            if (trueModel.HandleTime.HasValue)
            {
                handleTimePar = new SqlParameter("@HandleTime", trueModel.HandleTime.Value);
            }
            else
            {
                handleTimePar = new SqlParameter("@HandleTime", DBNull.Value);
            }
            SqlParameter canclTimePar = null;
            if (trueModel.CanclTime.HasValue)
            {
                canclTimePar = new SqlParameter("@CanclTime", trueModel.CanclTime.Value);
            }
            else
            {
                canclTimePar = new SqlParameter("@CanclTime", DBNull.Value);
            }
            SqlParameter reciveTimePar = null;
            if (trueModel.ReciveTime.HasValue)
            {
                reciveTimePar = new SqlParameter("@ReciveTime", trueModel.ReciveTime.Value);
            }
            else
            {
                reciveTimePar = new SqlParameter("@ReciveTime", DBNull.Value);
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {   new SqlParameter("@Keyid",trueModel.Keyid),
                    new SqlParameter("@ComplaintsStatusId",trueModel.ComplaintsStatusId),
                    new SqlParameter("@ProcessingResults",trueModel.ProcessingResults),
                    new SqlParameter("@HandlePeople",trueModel.HandlePeople),
                    new SqlParameter("@AuditPeople",trueModel.AuditPeople),
                    new SqlParameter("@RecivePeople",trueModel.RecivePeople),
                    auditTimePar,
                    handleTimePar,
                    canclTimePar,
                    reciveTimePar,
                    new SqlParameter("@LastUpdateTime",trueModel.LastUpdateTime)
            };
            try
            {
                _dataBase.Query("sp_Integrity_ComplainanInfo_Update", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteModel(Infrastructure.Domain.IAggregateRoot model)
        {
            Model.Integrity_ComplainanInfo trueModel = model as Model.Integrity_ComplainanInfo;
            if (trueModel == null)
            {
                return false;
            }
            IList<SqlParameter> sqlParms = new List<SqlParameter>()
            {
                new SqlParameter("@Keyid",trueModel.Keyid)
            };
            try
            {
                _dataBase.Query("sp_Integrity_ComplainanInfo_DeleteRow", CommandType.StoredProcedure, sqlParms.ToArray<SqlParameter>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
 
        public IEnumerable<Model.Integrity_ComplainanInfo> SelectModelPageByFirm(int complaintsTypeId, string respondentName, string orderCode, int complaintsStatusId, Guid memberId, Infrastructure.Query.Pagination pagination)
        {
            string selectTarget = @" t.* ";
            string fromSouce = @" ( 
                                SELECT a.*,b.Name AS RespondentName,c.Name AS ComplaintsStatus,d.Name as ComplaintsTypeName
                                FROM Integrity_ComplainanInfo a INNER JOIN dbo.EC_MemberBasic b
                                ON a.RespondentId=b.MemberId INNER JOIN Sys_Dictionary c ON a.ComplaintsStatusId=c.MeanValue AND c.DicType='投诉状态'
                                INNER JOIN Sys_Dictionary d ON a.ComplaintsTypeId=d.MeanValue AND d.DicType='投诉类型'
                                where a.ComplainantId='" + memberId.ToString() + "' ";
 
            if (complaintsTypeId != -1)
            {
                fromSouce += " and a.complaintsTypeId='" + complaintsTypeId + "'";
            }
            if (!string.IsNullOrEmpty(respondentName))
            {
                fromSouce += " and b.Name like '%" + respondentName + "%'";
            }
            if (!string.IsNullOrEmpty(orderCode))
            {
                fromSouce += " and a.orderCode like '%" + orderCode + "%'";
            }
 
            if (complaintsStatusId != -1)
            {
                fromSouce += " and a.complaintsStatusId=" + complaintsStatusId;
            }
            fromSouce += " ) as t";
            return _dataBase.SelectModelPage<Integrity_ComplainanInfo>(pagination, selectTarget, fromSouce, "t.LastUpdateTime desc ", "LastUpdateTime desc ");
        }
 
        public IEnumerable<Model.Integrity_ComplainanInfo> SelectModelPageBysys(int complaintsTypeId, string respondentName, string orderCode, int complaintsStatusId, Infrastructure.Query.Pagination pagination)
        {
            string selectTarget = @" t.* ";
            string fromSouce = @" ( 
                                SELECT a.*,b.Name AS RespondentName,c.Name AS ComplaintsStatus,d.Name as ComplaintsTypeName,e.Name as ComplainantName
                                FROM Integrity_ComplainanInfo a INNER JOIN dbo.EC_MemberBasic b
                                ON a.RespondentId=b.MemberId 
                                INNER JOIN dbo.EC_MemberBasic e
                                ON a.ComplainantId=e.MemberId 
                                INNER JOIN Sys_Dictionary c ON a.ComplaintsStatusId=c.MeanValue AND c.DicType='投诉状态'
                                INNER JOIN Sys_Dictionary d ON a.ComplaintsTypeId=d.MeanValue AND d.DicType='投诉类型'
                                where 1=1 ";
 
            if (complaintsTypeId != -1)
            {
                fromSouce += " and a.complaintsTypeId='" + complaintsTypeId + "'";
            }
            if (!string.IsNullOrEmpty(respondentName))
            {
                fromSouce += " and b.Name like '%" + respondentName + "%'";
            }
            if (!string.IsNullOrEmpty(orderCode))
            {
                fromSouce += " and a.orderCode like '%" + orderCode + "%'";
            }
 
            if (complaintsStatusId != -1)
            {
                fromSouce += " and a.complaintsStatusId=" + complaintsStatusId;
            }
            fromSouce += " ) as t";
            return _dataBase.SelectModelPage<Integrity_ComplainanInfo>(pagination, selectTarget, fromSouce, "t.LastUpdateTime desc ", "LastUpdateTime desc ");
        }
 
        /// <summary>
        /// 根据keyId获取投诉实体
        /// </summary>
        /// <param name="keyId"></param>
        /// <returns></returns>
        public Integrity_ComplainanInfo GetModel(int keyId)
        {
            string selectTarget = " a.*,b.Name AS RespondentName,c.Name AS ComplaintsStatus,d.Name as ComplaintsTypeName,e.Name as ComplainantName ";
            string fromSouce = @" Integrity_ComplainanInfo a INNER JOIN dbo.EC_MemberBasic b
                                ON a.RespondentId=b.MemberId
                                INNER JOIN dbo.EC_MemberBasic e
                                ON a.ComplainantId=e.MemberId  
                                INNER JOIN Sys_Dictionary c ON a.ComplaintsStatusId=c.MeanValue AND c.DicType='投诉状态'
                                INNER JOIN Sys_Dictionary d ON a.ComplaintsTypeId=d.MeanValue AND d.DicType='投诉类型' ";
            string condition = string.Empty;
            condition = " a.KeyId=" + keyId;
            IList<Integrity_ComplainanInfo> result = _dataBase.SelectModel<Integrity_ComplainanInfo>(selectTarget, fromSouce, condition);
            return null == result || result.Count == 0 ? null : result[0];
        }
    }
}