using DTO;
|
using IServices;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Logging;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Net.Http;
|
using System.Net.Http.Headers;
|
using System.Threading.Tasks;
|
using System.Transactions;
|
using zhengcaioa.IService;
|
using zhengcaioa.Models;
|
|
|
namespace zhengcaioa.Controllers.ExpertTest
|
{
|
public class ExpertTestTopicController : Controller
|
{
|
private readonly ILogger<ExpertTestTopicController> _logger;
|
private readonly ILiaotianService _liaotianService;
|
private readonly IExpertTestTopicService _expertTestTopicService;
|
private readonly IAreaService _areaService;
|
private readonly IConfiguration _configuration;
|
private readonly IPltPageService _pltPageService;
|
private readonly IHttpClientFactory _clientFactory;
|
|
|
public ExpertTestTopicController(ILogger<ExpertTestTopicController> logger, ILiaotianService liaotianService, IExpertTestTopicService expertTestTopicService
|
, IAreaService areaService
|
, IConfiguration configuration
|
, IPltPageService pltPageService
|
, IHttpClientFactory clientFactory)
|
{
|
_logger = logger;
|
_liaotianService = liaotianService;
|
_expertTestTopicService = expertTestTopicService;
|
_areaService = areaService;
|
_configuration = configuration;
|
_pltPageService = pltPageService;
|
_clientFactory = clientFactory;
|
|
}
|
|
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);
|
|
|
ActionEntity actionEntity2 = new ActionEntity();
|
actionEntity2.OpenType = 0;
|
actionEntity2.ActionUrl = "";
|
actionEntity2.ActionFun = "Print";
|
actionEntity2.PageIco = "fa fa-print";
|
actionEntity2.ActionName = "打印";
|
actionlist.Add(actionEntity2);
|
|
|
ViewData["ActionInfo"] = actionlist;
|
|
|
|
|
ViewBag.topictype = _liaotianService.GetSYScode("expert_test_topic", "topictype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
|
ViewBag.zhishitype = _liaotianService.GetSYScode("expert_test_topic", "zhishitype").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.zhongdian = _liaotianService.GetSYScode("system", "shifou").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.jiexi_status = _liaotianService.GetSYScode("expert_test_topic", "jiexi_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.shenpi_status = _liaotianService.GetSYScode("expert_test_topic", "shenpi_status").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
|
ViewBag.Area = _areaService.GetList().Where(x => x.ParentId == "0 ").Select(x => new { code = x.CodeId, label = x.Name }).ToList();
|
|
|
return View();
|
|
}
|
|
public IActionResult GetList(ExpertTestTopicDTOSearch search)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
//search.Creater = curentuser.Id;
|
//JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
|
return new JsonResult(_expertTestTopicService.SearchByPaging(search));
|
}
|
|
public IActionResult Edit(string id = null, string Topictype = "", string Zhishitype = "", string Area = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
var expertTestTopicanwserDTOs = new List<ExpertTestTopicanwserDTO>();
|
|
ExpertTestTopicDTO dto = new ExpertTestTopicDTO();
|
if (!String.IsNullOrEmpty(id))
|
{
|
dto = _expertTestTopicService.Get(id);
|
expertTestTopicanwserDTOs = _expertTestTopicService.GetListanwser(id);
|
if (expertTestTopicanwserDTOs.Count == 0)
|
{
|
expertTestTopicanwserDTOs.Add(new ExpertTestTopicanwserDTO());
|
}
|
|
dto.expertTestTopicanwserDTOs = expertTestTopicanwserDTOs;
|
}
|
else
|
{
|
expertTestTopicanwserDTOs.Add(new ExpertTestTopicanwserDTO());
|
dto.expertTestTopicanwserDTOs = expertTestTopicanwserDTOs;
|
dto.Topictype = Topictype;
|
dto.Zhishitype = Zhishitype;
|
dto.Area = Area;
|
}
|
|
|
|
|
|
ViewBag.topictype = _liaotianService.GetSYScode("expert_test_topic", "topictype");
|
|
ViewBag.zhishitype = _liaotianService.GetSYScode("expert_test_topic", "zhishitype");
|
ViewBag.zhongdian = _liaotianService.GetSYScode("system", "shifou").OrderByDescending(x=>x.Sort).ToList();
|
ViewBag.jiexi_status = _liaotianService.GetSYScode("expert_test_topic", "jiexi_status");
|
ViewBag.shenpi_status = _liaotianService.GetSYScode("expert_test_topic", "shenpi_status");
|
ViewBag.Area = _areaService.GetList().Where(x => x.ParentId == "0 ").ToList();
|
|
|
|
List<PageEntity> pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/ExpertTestTopic/Index");
|
|
ViewData["pageEntities"] = pageEntities;
|
|
ViewData.Model = dto;
|
return View();
|
}
|
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
///
|
[HttpPost]
|
public async Task<IActionResult> SaveAsync(ExpertTestTopicDTO data)
|
{
|
|
ResultEntity resultEntity = new ResultEntity();
|
|
if (!string.IsNullOrEmpty(data.Id))
|
{
|
|
string api_domain = _configuration.GetSection("Elasticsearchurl").Value;
|
string url = $"{api_domain}/liaotian/person/" + data.Id;
|
//string requestJson = "{\"id\": \"" + Id + "\",\"question\": \"" + data.Question + "\",\"anwser\": \"" + data.Anwser + "\"}";
|
try
|
{
|
string result = string.Empty;
|
Uri postUrl = new Uri(url);
|
|
|
|
|
var httpClient = _clientFactory.CreateClient();
|
httpClient.Timeout = new TimeSpan(0, 0, 60);
|
var Result = await httpClient.DeleteAsync(postUrl);
|
result = Result.Content.ReadAsStringAsync().Result;
|
|
Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(result);
|
|
if (jobject["error"] == null && jobject["_shards"]["successful"].ToString() == "1")
|
{
|
resultEntity.Result = true;
|
}
|
else
|
{
|
resultEntity.Result = false;
|
}
|
|
}
|
catch (Exception e)
|
{
|
resultEntity.Result = false;
|
throw e;
|
|
|
}
|
}
|
|
using (TransactionScope scope = new TransactionScope())
|
{
|
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;
|
data.ShenpiStatus = "D";
|
data.JiexiStatus = "D";
|
}
|
else
|
{
|
var ddd = _expertTestTopicService.Get(data.Id);
|
|
data.ShenpiStatus = "D";
|
data.JiexiStatus = ddd.JiexiStatus;
|
}
|
data.Modifier = curentuser.Id;
|
data.Modifytime = DateTime.Now;
|
|
resultEntity = _expertTestTopicService.save(data);
|
scope.Complete();
|
}
|
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
/// <summary>
|
/// 审核
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
[HttpPost]
|
[CheckLogin]
|
public async Task<string> ShenheAsync(String Id)
|
{
|
ResultEntity resultEntity = new ResultEntity();
|
resultEntity.Result = false;
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
|
|
|
var data = _expertTestTopicService.Get(Id);
|
var datadtls = _expertTestTopicService.GetListanwser(Id);
|
|
data.ShenpiStatus = "A";
|
data.Modifier = curentuser.Id;
|
data.Modifytime = DateTime.Now;
|
resultEntity = _expertTestTopicService.shenpi(data);
|
|
string api_domain = _configuration.GetSection("Elasticsearchurl").Value;
|
string url = $"{api_domain}/liaotian/person/" + data.Id;
|
LiaotianElasticsearchDTO liaotianElasticsearchDTO = new LiaotianElasticsearchDTO();
|
liaotianElasticsearchDTO.id = data.Id;
|
liaotianElasticsearchDTO.question = data.Topic;
|
liaotianElasticsearchDTO.anwser = data.Topic+" </br> ";
|
foreach(var datadtl in datadtls)
|
{
|
if (datadtl.Shifouzhengqu == "A")
|
{
|
liaotianElasticsearchDTO.anwser += "<font color=\"#FF0000\">"+datadtl.Anwserno + " " + datadtl.Anwser + "</font> </br> ";
|
}
|
else
|
{
|
liaotianElasticsearchDTO.anwser += datadtl.Anwserno + " " + datadtl.Anwser + " </br> ";
|
}
|
|
}
|
|
|
|
string requestJson = JsonConvert.SerializeObject(liaotianElasticsearchDTO); ;// "{\"id\": \"" + liaotianDTO.Id + "\",\"question\": \"" + liaotianDTO.Question.Replace("\n", "")+ "\",\"anwser\": \"" + liaotianDTO.Anwser.Replace("\n", "") + "\"}";
|
|
try
|
{
|
string result = string.Empty;
|
Uri postUrl = new Uri(url);
|
|
using (HttpContent httpContent = new StringContent(requestJson))
|
{
|
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
|
var httpClient = _clientFactory.CreateClient();
|
httpClient.Timeout = new TimeSpan(0, 0, 60);
|
var Result = await httpClient.PutAsync(postUrl, httpContent);
|
result = Result.Content.ReadAsStringAsync().Result;
|
|
|
|
}
|
|
Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(result);
|
|
if (jobject["error"] == null && jobject["_shards"]["successful"].ToString() == "1")
|
{
|
resultEntity.Result = true;
|
}
|
else
|
{
|
resultEntity.Result = false;
|
}
|
|
}
|
catch (Exception e)
|
{
|
resultEntity.Result = false;
|
throw e;
|
|
|
}
|
|
|
|
|
|
return JsonConvert.SerializeObject(resultEntity);
|
}
|
|
|
/// <summary>
|
/// 提交并审核
|
/// </summary>
|
/// <param name="data">岗位实体类对象</param>
|
/// <returns></returns>
|
[HttpPost]
|
[CheckLogin]
|
public async Task<string> TijiaobingshenheAsync(ExpertTestTopicDTO data)
|
{
|
|
ResultEntity resultEntity = new ResultEntity();
|
using (TransactionScope scope = new TransactionScope())
|
{
|
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;
|
data.ShenpiStatus = "A";
|
data.JiexiStatus = "D";
|
}
|
else
|
{
|
var ddd = _expertTestTopicService.Get(data.Id);
|
|
data.ShenpiStatus = "A";
|
data.JiexiStatus = ddd.JiexiStatus;
|
}
|
data.Modifier = curentuser.Id;
|
data.Modifytime = DateTime.Now;
|
|
resultEntity = _expertTestTopicService.save(data);
|
scope.Complete();
|
}
|
|
data = _expertTestTopicService.Get(data.Id);
|
var datadtls = _expertTestTopicService.GetListanwser(data.Id);
|
string api_domain = _configuration.GetSection("Elasticsearchurl").Value;
|
string url = $"{api_domain}/liaotian/person/" + data.Id;
|
LiaotianElasticsearchDTO liaotianElasticsearchDTO = new LiaotianElasticsearchDTO();
|
liaotianElasticsearchDTO.id = data.Id;
|
liaotianElasticsearchDTO.question = data.Topic;
|
liaotianElasticsearchDTO.anwser = data.Topic + " </br> ";
|
foreach (var datadtl in datadtls)
|
{
|
if (datadtl.Shifouzhengqu == "A")
|
{
|
liaotianElasticsearchDTO.anwser += "<font color=\"#FF0000\">" + datadtl.Anwserno + " " + datadtl.Anwser + "</font> </br>";
|
}
|
else
|
{
|
liaotianElasticsearchDTO.anwser += datadtl.Anwserno + " " + datadtl.Anwser + " </br> ";
|
}
|
|
}
|
|
|
|
string requestJson = JsonConvert.SerializeObject(liaotianElasticsearchDTO); ;// "{\"id\": \"" + liaotianDTO.Id + "\",\"question\": \"" + liaotianDTO.Question.Replace("\n", "")+ "\",\"anwser\": \"" + liaotianDTO.Anwser.Replace("\n", "") + "\"}";
|
|
try
|
{
|
string result = string.Empty;
|
Uri postUrl = new Uri(url);
|
|
using (HttpContent httpContent = new StringContent(requestJson))
|
{
|
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
|
var httpClient = _clientFactory.CreateClient();
|
httpClient.Timeout = new TimeSpan(0, 0, 60);
|
var Result = await httpClient.PutAsync(postUrl, httpContent);
|
result = Result.Content.ReadAsStringAsync().Result;
|
|
|
|
}
|
|
Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(result);
|
|
if (jobject["error"] == null && jobject["_shards"]["successful"].ToString() == "1")
|
{
|
resultEntity.Result = true;
|
}
|
else
|
{
|
resultEntity.Result = false;
|
}
|
|
}
|
catch (Exception e)
|
{
|
resultEntity.Result = false;
|
throw e;
|
|
|
}
|
|
|
|
|
return JsonConvert.SerializeObject(resultEntity);
|
}
|
|
|
|
|
/// <summary>
|
/// 删除主信息
|
/// </summary>
|
/// <param name="info">实体</param>
|
/// <returns></returns>
|
///
|
public async Task<IActionResult> NullifyAsync(string Id = "")
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
|
ResultEntity resultEntity = _expertTestTopicService.ModifyStatus(Id, curentuser.Id);
|
|
string api_domain = _configuration.GetSection("Elasticsearchurl").Value;
|
string url = $"{api_domain}/liaotian/person/" + Id;
|
//string requestJson = "{\"id\": \"" + Id + "\",\"question\": \"" + data.Question + "\",\"anwser\": \"" + data.Anwser + "\"}";
|
try
|
{
|
string result = string.Empty;
|
Uri postUrl = new Uri(url);
|
|
|
|
|
var httpClient = _clientFactory.CreateClient();
|
httpClient.Timeout = new TimeSpan(0, 0, 60);
|
var Result = await httpClient.DeleteAsync(postUrl);
|
result = Result.Content.ReadAsStringAsync().Result;
|
|
Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(result);
|
|
if (jobject["error"] == null && jobject["_shards"]["successful"].ToString() == "1")
|
{
|
resultEntity.Result = true;
|
}
|
else
|
{
|
resultEntity.Result = false;
|
}
|
|
}
|
catch (Exception e)
|
{
|
resultEntity.Result = false;
|
throw e;
|
|
|
}
|
|
return new JsonResult(resultEntity);
|
}
|
|
|
|
|
public IActionResult print(ExpertTestTopicDTOSearch search)
|
{
|
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
|
ViewData["curentuser"] = curentuser;
|
search.page = 1;
|
search.rows = 10000;
|
ViewBag.listExpertTestTopicDTO = _expertTestTopicService.SearchByPaging(search).DataList;
|
|
|
|
return View();
|
}
|
}
|
}
|