username@email.com
2024-07-24 294494e5559dcc92670dd9800caf976853aff876
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
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 AdmGoodsRecordService: IAdmGoodsRecordService
    {
        private readonly zhengcaioaContext _context;
        private readonly IMapper _mapper;
        public AdmGoodsRecordService(zhengcaioaContext context, IMapper mapper)
        {
            _context = context;
            _mapper = mapper;
        }
 
        public ResultEntity save(AdmGoodsRecordDTO dto)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                var AdmGoodsRecord = _mapper.Map<AdmGoodsRecord>(dto);
                if (String.IsNullOrEmpty(AdmGoodsRecord.Id))
                {
                    AdmGoodsRecord.Id = Guid.NewGuid().ToString();
                    dto.Id = AdmGoodsRecord.Id;
 
                    _context.AdmGoodsRecords.Add(AdmGoodsRecord);
                }
                else
                {
                    var updatepltRole = _context.AdmGoodsRecords.Find(AdmGoodsRecord.Id);
                    updatepltRole.GoodsId = AdmGoodsRecord.GoodsId;
                    updatepltRole.RecordTypeId = AdmGoodsRecord.RecordTypeId;
                    updatepltRole.GoodsNum = AdmGoodsRecord.GoodsNum;
                    updatepltRole.GoodsLeft = AdmGoodsRecord.GoodsLeft;
 
 
 
                    updatepltRole.OperationalMatters = AdmGoodsRecord.OperationalMatters;
                    updatepltRole.Remark = AdmGoodsRecord.Remark;
                   
 
 
                    updatepltRole.RecStatus = AdmGoodsRecord.RecStatus;
                    // updatepltRole.Creater = pltRole.Creater;
                    //updatepltRole.Createtime = pltRole.Createtime;
                    updatepltRole.Modifier = AdmGoodsRecord.Modifier;
                    updatepltRole.Modifytime = AdmGoodsRecord.Modifytime;
 
                }
 
                _context.SaveChanges();
                resultEntity.ReturnID = AdmGoodsRecord.Id;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
 
            }
            return resultEntity;
        }
 
        public AdmGoodsRecordDTO Get(string id)
        {
            var entity = _context.AdmGoodsRecords.Find(id);
 
            if (entity.RecStatus != "A")
            {
                entity = new AdmGoodsRecord();
            }
            var AdmGoodsRecordDTO = _mapper.Map<AdmGoodsRecordDTO>(entity);
            return AdmGoodsRecordDTO;
        }
 
        public ResultDataEntity<AdmGoodsRecordDTO> SearchByPaging(AdmGoodsRecordDTOSearch searchEntity)
        {
            ResultDataEntity<AdmGoodsRecordDTO> data = new ResultDataEntity<AdmGoodsRecordDTO>();
 
            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.AdmGoodsRecords//.Where(x => x.RecStatus == "A")
                         join z in _context.AdmGoodsManages on a.GoodsId equals z.Id
 
                        
                         join c in listCode.Where(x => x.CodeTable == "adm_goods_record" && x.CodeField == "RecordTypeId")
                        on a.RecordTypeId equals c.CodeSn
                         
 
 
                         
                         where a.RecStatus == "A"
                           && (string.IsNullOrWhiteSpace(searchEntity.Createtime) || (a.Createtime >= XdTimestart && a.Createtime <= XdTimeend))
                       
 
                               && (string.IsNullOrWhiteSpace(searchEntity.OperationalMatters) || a.OperationalMatters.Contains(searchEntity.OperationalMatters.Trim()))
                                
                                        && (string.IsNullOrWhiteSpace(searchEntity.RecordTypeId) || a.RecordTypeId == searchEntity.RecordTypeId.Trim())
                                             && (string.IsNullOrWhiteSpace(searchEntity.GoodsId) || a.GoodsId == searchEntity.GoodsId.Trim())
 
                         select new AdmGoodsRecordDTO
                         {
                             Id = a.Id,
                            
 
                           
                             RecordTypeId = a.RecordTypeId,
                             RecordTypeName = c.Comments,
                             GoodsId = a.GoodsId,
                             GoodsName = z.GoodsName,
                            
                             OperationalMatters = a.OperationalMatters,
                             Remark = a.Remark,
                             CreatetimeName = a.Createtime.ToString("yyyy-MM-dd HH:mm:ss"),
 
                             Creater = a.Creater,
                             Createtime = a.Createtime,
                             Modifier = a.Modifier,
                             Modifytime = a.Modifytime,
                            
                             RecStatus = a.RecStatus,
                             GoodsNum = a.GoodsNum ?? 0,
                             GoodsLeft = a.GoodsLeft ?? 0,
 
                         }).OrderByDescending(x => x.Createtime).ToList();
 
 
 
 
 
 
 
            //if (searchEntity.totalrows == 0)
            searchEntity.totalrows = query.Count();
            var rolelist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
 
            data.LoadData(searchEntity, rolelist);
            return data;
        }
 
        public ResultEntity ModifyStatus(string id, string userid)
        {
 
            ResultEntity result = new ResultEntity();
            result.Result = true;
 
            var model = _context.AdmGoodsRecords.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<AdmGoodsRecordDTO> GetList()
        {
 
 
            var listPosition = _context.AdmGoodsRecords.Where(r => r.RecStatus == "A").ToList();
 
            var list = _mapper.Map<List<AdmGoodsRecordDTO>>(listPosition);
            return list;
        }
    }
}