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);
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|