username@email.com
2025-04-21 d594c576eb6cd7073e880cd09fe581fb2ac5504b
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
using AutoMapper;
using DTO;
using IServices;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zhengcaioa.Models;
 
namespace Services
{
    public class FiAccountRecordService: IFiAccountRecordService
    {
        private readonly zhengcaioaContext _context;
        private readonly IMapper _mapper;
        public FiAccountRecordService(zhengcaioaContext context, IMapper mapper)
        {
            _context = context;
            _mapper = mapper;
        }
 
        public ResultEntity save(FiAccountRecordDTO dto)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                var fiAccountRecord = _mapper.Map<FiAccountRecord>(dto);
                if (String.IsNullOrEmpty(fiAccountRecord.Id))
                {
                    fiAccountRecord.Id = Guid.NewGuid().ToString();
                    dto.Id = fiAccountRecord.Id;
 
                    _context.FiAccountRecords.Add(fiAccountRecord);
                }
                else
                {
                    var updatepltRole = _context.FiAccountRecords.Find(fiAccountRecord.Id);
                    updatepltRole.SubjectId = fiAccountRecord.SubjectId;
                    updatepltRole.AccountId = fiAccountRecord.AccountId;
                    updatepltRole.RecordTypeId = fiAccountRecord.RecordTypeId;
                    updatepltRole.Department = fiAccountRecord.Department;
                    updatepltRole.Money = fiAccountRecord.Money;
                    updatepltRole.PaymentUnit = fiAccountRecord.PaymentUnit;
 
 
                    updatepltRole.OperationalMatters = fiAccountRecord.OperationalMatters;
                    updatepltRole.Remark = fiAccountRecord.Remark;
                    updatepltRole.QiyongStatus = fiAccountRecord.QiyongStatus;
 
 
 
                    updatepltRole.RecStatus = fiAccountRecord.RecStatus;
                    // updatepltRole.Creater = pltRole.Creater;
                    //updatepltRole.Createtime = pltRole.Createtime;
                    updatepltRole.Modifier = fiAccountRecord.Modifier;
                    updatepltRole.Modifytime = fiAccountRecord.Modifytime;
 
                }
 
                _context.SaveChanges();
                resultEntity.ReturnID = fiAccountRecord.Id;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
 
            }
            return resultEntity;
        }
 
        public FiAccountRecordDTO Get(string id)
        {
            var entity = _context.FiAccountRecords.Find(id);
 
            if (entity.RecStatus != "A")
            {
                entity = new FiAccountRecord();
            }
            var FiAccountRecordDTO = _mapper.Map<FiAccountRecordDTO>(entity);
            return FiAccountRecordDTO;
        }
 
        public ResultDataEntity<FiAccountRecordDTO> SearchByPaging(FiAccountRecordDTOSearch searchEntity)
        {
            ResultDataEntity<FiAccountRecordDTO> data = new ResultDataEntity<FiAccountRecordDTO>();
 
            var listCode = (from a in _context.SysCodeDtls
                            join b in _context.SysCodes
                            on a.CodeId equals b.Id
                            where a.RecStatus == "A"
                                          && b.RecStatus == "A"
                            select new CodeDataEntity()
                            {
                                CodeId = b.Id,
                                CodeTable = b.CodeTable,
                                CodeField = b.CodeField,
                                CodeSn = a.CodeSn,
                                Comments = a.Comments,
                                Contents = a.Contents,
                                RecStatus = a.RecStatus,
                                Sort = a.Sort
                            }
                     );
 
            DateTime XdTimestart = DateTime.Now;
            DateTime XdTimeend = DateTime.Now;
            if (!string.IsNullOrWhiteSpace(searchEntity.Createtime))
            {
                string[] XdTimes = searchEntity.Createtime.Split("|");
                DateTime.TryParse(XdTimes[0], out XdTimestart);
                DateTime.TryParse(XdTimes[1], out XdTimeend);
                XdTimeend = XdTimeend.AddDays(1);
            }
            var query = (from a in _context.FiAccountRecords//.Where(x => x.RecStatus == "A")
                         join z in _context.FiAccounts on a.AccountId equals z.Id
 
                         join b in listCode.Where(x => x.CodeTable == "fi_account" && x.CodeField == "accounttype")
                        on z.Accounttype equals b.CodeSn
                        into bsss
                         from bbb in bsss.DefaultIfEmpty()
 
 
                         join c in listCode.Where(x => x.CodeTable == "fi_account_record" && x.CodeField == "RecordTypeId")
                        on a.RecordTypeId equals c.CodeSn
                          into csss
                         from ccc in csss.DefaultIfEmpty()
 
 
                         join f in _context.FiSubjects on a.SubjectId equals f.Id
                           into fsss
                         from fff in fsss.DefaultIfEmpty()
 
 
                         join y in _context.PltUsers on a.Creater equals y.Id
                           into ysss
                         from yyy in ysss.DefaultIfEmpty()
 
                         where a.RecStatus == "A"
                           && (string.IsNullOrWhiteSpace(searchEntity.Createtime) || (a.Createtime >= XdTimestart && a.Createtime <= XdTimeend))
                         && (string.IsNullOrWhiteSpace(searchEntity.Accounttype) || z.Accounttype == searchEntity.Accounttype.Trim())
                          && (string.IsNullOrWhiteSpace(searchEntity.AccountId) || a.AccountId == searchEntity.AccountId.Trim())
                            && (string.IsNullOrWhiteSpace(searchEntity.SubjectId) || a.SubjectId == searchEntity.SubjectId.Trim())
 
                               && (string.IsNullOrWhiteSpace(searchEntity.OperationalMatters) || a.OperationalMatters.Contains(searchEntity.OperationalMatters.Trim()))
                                  && (string.IsNullOrWhiteSpace(searchEntity.PaymentUnit) || a.PaymentUnit.Contains(searchEntity.PaymentUnit.Trim()))
                                     && (string.IsNullOrWhiteSpace(searchEntity.CreaterName) || yyy.UserName.Contains(searchEntity.CreaterName.Trim()))
                                        && (string.IsNullOrWhiteSpace(searchEntity.RecordTypeId) || a.RecordTypeId == searchEntity.RecordTypeId.Trim())
                                           && (string.IsNullOrWhiteSpace(searchEntity.RecordTypeId) || a.RecordTypeId == searchEntity.RecordTypeId.Trim())
                                             && (string.IsNullOrWhiteSpace(searchEntity.Remark) || a.Remark.Contains(searchEntity.Remark.Trim()))
                                                && (string.IsNullOrWhiteSpace(searchEntity.Creater) || (a.Creater != "ZCUserCentre" && a.Creater != "shop"))
 
                         select new FiAccountRecordDTO
                         {
                             Id = a.Id,
                             SubjectId = a.SubjectId,
                             SubjectName = fff.Subjectname,
                             AccountId = a.AccountId,
                             AccountName = z.Accountname,
 
                             Accounttype = z.Accounttype,
                             AccounttypeName = bbb.Comments,
                             RecordTypeId = a.RecordTypeId,
                             RecordTypeName = ccc.Comments,
                             Department = a.Department,
                             Money = a.Money,
                             PaymentUnit = a.PaymentUnit,
                             OperationalMatters = a.OperationalMatters,
                             Remark = a.Remark,
                             CreatetimeName = a.Createtime.ToString("yyyy-MM-dd HH:mm:ss"),
 
                             Creater = a.Creater,
                             CreaterName = yyy.UserName,
                             Createtime = a.Createtime,
                             Modifier = a.Modifier,
                             Modifytime = a.Modifytime,
                             QiyongStatus = a.QiyongStatus,
                             RecStatus = a.RecStatus,
                             Balance = z.Balance??0,
                             AccountMoney = a.AccountMoney??0,
                           
                         }).OrderByDescending(x => x.Modifytime).ToList();
 
 
 
 
 
 
 
            //if (searchEntity.totalrows == 0)
                searchEntity.totalrows = query.Count();
            data.Heji1 = Math.Round(query.Sum(x => x.Money) ?? 0, 2);
            var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
            data.DangyeHeji1 = Math.Round(lianlist.Sum(x => x.Money) ?? 0, 2);
            data.LoadData(searchEntity, lianlist);
            return data;
        }
 
        public ResultEntity ModifyStatus(string id, string userid)
        {
 
            ResultEntity result = new ResultEntity();
            result.Result = true;
 
            var model = _context.FiAccountRecords.Find(id);
            if (model != null)
            {
                model.RecStatus = "D";
                model.Modifier = userid;
                model.Modifytime = DateTime.Now;
                _context.SaveChanges();
            }
 
            return result;
        }
 
 
        /// <summary>
        /// 获取所有有效角色
        /// </summary>
        /// <returns></returns>
        public List<FiAccountRecordDTO> GetList(string OperationalMatters = null, string Remark = null)
        {
 
 
            var listPosition = _context.FiAccountRecords.Where(r => r.RecStatus == "A" ).ToList();
 
            if (!string.IsNullOrEmpty(OperationalMatters)&& !string.IsNullOrEmpty(Remark))
            {
                listPosition = listPosition.Where(x => x.OperationalMatters == OperationalMatters || x.Remark == Remark).ToList();
            }
           
            var list = _mapper.Map<List<FiAccountRecordDTO>>(listPosition);
            return list;
        }
    }
}