username@email.com
2023-03-08 f7a2d28869cc31c7dbe057a1d80dd40536d97fed
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using DTO;
using IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
using zhengcaioa.IService;
using zhengcaioa.Models;
 
namespace zhengcaioa.Controllers.Expert
{
    public class ZhuanjiahuidaController : Controller
    {
        private readonly ILogger<ZhuanjiahuidaController> _logger;
        private readonly ILZhuanjiahuidumService _lZhuanjiahuidumService;
        private readonly ILiaotianService _liaotianService;
        //private readonly IConfiguration _configuration;
        private readonly IPltPageService _pltPageService;
 
 
 
        public ZhuanjiahuidaController(ILogger<ZhuanjiahuidaController> logger, ILZhuanjiahuidumService lZhuanjiahuidumService, ILiaotianService liaotianService
              , IPltPageService pltPageService)
        {
            _logger = logger;
            _lZhuanjiahuidumService = lZhuanjiahuidumService;
            _liaotianService = liaotianService;
            _pltPageService = pltPageService;
        }
        [CheckLogin]
        public IActionResult Index()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            ActionEntity actionEntity = new ActionEntity();
            actionEntity.OpenType = 0;
            actionEntity.ActionUrl = "";
            actionEntity.ActionFun = "Search";
            actionEntity.PageIco = "fa fa-search";
            actionEntity.ActionName = "查询";
            actionlist.Add(actionEntity);
            //ActionEntity actionEntity1 = new ActionEntity();
            //actionEntity1.OpenType = 0;
            //actionEntity1.ActionUrl = "";
            //actionEntity1.ActionFun = "Add";
            //actionEntity1.PageIco = "fa fa-plus";
            //actionEntity1.ActionName = "新增";
            //actionlist.Add(actionEntity1);
            ViewData["ActionInfo"] = actionlist;
 
            var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/Zhuanjiahuida/Index");
            var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList();
            ViewData["ActionInfo2"] = pageEntities2;
 
            ViewBag.shifou = _liaotianService.GetSYScode("system", "shifou").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            return View();
        }
 
        [CheckLogin]
        public IActionResult GetList(LZhuanjiahuidumDTOSearch search)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return new JsonResult(_lZhuanjiahuidumService.SearchByPaging(search));
        }
 
 
        #region 编辑
        [CheckLogin]
        public ActionResult Edit(string id = null)
        {
 
 
 
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
 
            LZhuanjiahuidumDTO dto = new LZhuanjiahuidumDTO();
            if (!String.IsNullOrEmpty(id))
            {
                dto = _lZhuanjiahuidumService.Get(id);
 
            }
     
 
 
 
 
            ViewData.Model = dto;
            return View();
        }
 
 
 
 
 
 
 
 
 
 
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        [HttpPost]
        [CheckLogin]
        public IActionResult Save(LZhuanjiahuidumDTO data)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            data.RecStatus = "A";
            if (String.IsNullOrEmpty(data.Id))
            {
                data.Creater = curentuser.Id;
                data.Createtime = DateTime.Now;
            }
            else
            {
                data.HuidaStatus = "A";
            }
            data.Modifier = curentuser.Id;
            data.Modifytime = DateTime.Now;
 
            ResultEntity resultEntity = _lZhuanjiahuidumService.save(data);
 
            return new JsonResult(resultEntity);
        }
        #endregion
 
        /// <summary>
        /// 删除主信息
        /// </summary>
        /// <param name="info">实体</param>
        /// <returns></returns>
        /// 
        [CheckLogin]
        public IActionResult Nullify(string Id = "")
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            return new JsonResult(_lZhuanjiahuidumService.ModifyStatus(Id, curentuser.Id));
        }
 
 
 
        //提问
        public IActionResult Wenti([FromBody]LZhuanjiahuidumDTO data)
        {
            ReturnMsg<LZhuanjiahuidumDTO> returnMsg = new ReturnMsg<LZhuanjiahuidumDTO>();
            returnMsg.code = 2;
            try
            {
                var headers = Request.Headers;
                if (headers != null)
                {
                    //string SecurityKey = _configuration.GetSection("SecurityKey").Value;
                    var keyId = headers["Authorization"].FirstOrDefault();
                    if (string.IsNullOrEmpty(keyId))
                    {
                        returnMsg.code = 2;
                        returnMsg.error = "没有获取到token";
                        returnMsg.count = 0;
 
                        return new JsonResult(returnMsg);
                    }
 
 
                    JwtSecurityToken jwt = null;
                    var handler = new JwtSecurityTokenHandler();
                    var key1 = keyId.Replace("Bearer", "").Trim();
                    jwt = handler.ReadJwtToken(key1);
                    System.Security.Claims.Claim sss = jwt.Claims.Where(x => x.Type == "id").FirstOrDefault();
                    data.Userid = sss.Value;
 
                }
 
               var lZhuanjiahuidumDTOs = _lZhuanjiahuidumService.GetList(data.Userid, data.Question);
 
                if(lZhuanjiahuidumDTOs!=null&& lZhuanjiahuidumDTOs.Count > 0)
                {
                    returnMsg.code = 3;
                    returnMsg.error = "这个问题已经提问过了";
                    returnMsg.count = 0;
 
                    return new JsonResult(returnMsg);
                }
 
                data.RecStatus = "A";
                if (String.IsNullOrEmpty(data.Id))
                {
                    data.Creater = "1";
                    data.Createtime = DateTime.Now;
                }
                data.Modifier = "1"; ;
                data.Modifytime = DateTime.Now;
 
                ResultEntity resultEntity = _lZhuanjiahuidumService.save(data);
                if (resultEntity.Result)
                {
                    returnMsg.code = 1;
                }
            }
            catch (Exception ex)
            {
                returnMsg.code = 2;
                returnMsg.error = "没有获取到token";
                returnMsg.count = 0;
                
            }
 
           
 
            return new JsonResult(returnMsg);
        }
 
 
 
 
        //提问
        public IActionResult Huida()
        {
            ReturnMsg<List<LZhuanjiahuidumDTO>> returnMsg = new ReturnMsg<List<LZhuanjiahuidumDTO>> ();
            returnMsg.code = 2;
            try
            {
                string userid = "";
                var headers = Request.Headers;
                if (headers != null)
                {
                    //string SecurityKey = _configuration.GetSection("SecurityKey").Value;
                    var keyId = headers["Authorization"].FirstOrDefault();
                    if (string.IsNullOrEmpty(keyId))
                    {
                        returnMsg.code = 2;
                        returnMsg.error = "没有获取到token";
                        returnMsg.count = 0;
 
                        return new JsonResult(returnMsg);
                    }
 
 
                    JwtSecurityToken jwt = null;
                    var handler = new JwtSecurityTokenHandler();
                    var key1 = keyId.Replace("Bearer", "").Trim();
                    jwt = handler.ReadJwtToken(key1);
                    System.Security.Claims.Claim sss = jwt.Claims.Where(x => x.Type == "id").FirstOrDefault();
                    userid = sss.Value;
 
                }
                LZhuanjiahuidumDTOSearch searchEntity = new LZhuanjiahuidumDTOSearch();
                searchEntity.Userid = userid;
                //searchEntity.HuidaStatus = "A";
                searchEntity.page = 1;
                searchEntity.rows = 1000;
 
                ResultDataEntity<LZhuanjiahuidumDTO> resultDataEntity = _lZhuanjiahuidumService.SearchByPaging(searchEntity);
                returnMsg.code = 1;
                returnMsg.returnObj = resultDataEntity.DataList;
                returnMsg.count = resultDataEntity.DataList.Count;
 
 
            }
            catch (Exception ex)
            {
                returnMsg.code = 2;
                returnMsg.error = "没有获取到token";
                returnMsg.count = 0;
 
            }
           
 
             
 
            
 
            return new JsonResult(returnMsg);
        }
 
    
 
}
 
 
 
 
 
}