WebPortalController.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. using DocumentFormat.OpenXml.Spreadsheet;
  2. using Hotline.Application.Bulletin;
  3. using Hotline.Application.Orders;
  4. using Hotline.Article;
  5. using Hotline.Caching.Interfaces;
  6. using Hotline.KnowledgeBase;
  7. using Hotline.Orders;
  8. using Hotline.Push.Notifies;
  9. using Hotline.Repository.SqlSugar.Extensions;
  10. using Hotline.Settings;
  11. using Hotline.Settings.Hotspots;
  12. using Hotline.Share.Dtos;
  13. using Hotline.Share.Dtos.DataSharing.PusherHotlineDto;
  14. using Hotline.Share.Dtos.Order;
  15. using Hotline.Share.Dtos.Schedulings;
  16. using Hotline.Share.Dtos.WebPortal;
  17. using Hotline.Share.Enums.Order;
  18. using Hotline.Share.Enums.Push;
  19. using Hotline.WebPortal;
  20. using MapsterMapper;
  21. using MathNet.Numerics;
  22. using MediatR;
  23. using Microsoft.AspNetCore.Authorization;
  24. using Microsoft.AspNetCore.Mvc;
  25. using SqlSugar;
  26. using XF.Domain.Authentications;
  27. using XF.Domain.Cache;
  28. using XF.Domain.Filters;
  29. using XF.Domain.Repository;
  30. namespace Hotline.Api.Controllers
  31. {
  32. public class WebPortalController : BaseController
  33. {
  34. private readonly IMapper _mapper;
  35. private readonly IMediator _mediator;
  36. private readonly IRepository<Bulletin> _bulletinRepository;
  37. private readonly IRepository<WebUserRegister> _webUserRegisterRepository;
  38. private readonly IRepository<WebUserAuth> _webUserAuthRepository;
  39. private readonly IRepository<WebFlowAccept> _webFlowAcceptRepository;
  40. private readonly ITypedCache<WriteLettersSendSmsDto> _writeLettersSendSms;
  41. private readonly IRepository<Hotspot> _hotspotRepository;
  42. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  43. private readonly IRepository<OrderPublish> _orderPublishRepository;
  44. private readonly IOrderRepository _orderRepository;
  45. private readonly IRepository<OrderVisit> _orderVisitRepository;
  46. private readonly IOrderApplication _orderApplication;
  47. private readonly ISessionContext _sessionContext;
  48. private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
  49. private readonly IBulletinApplication _bulletinApplication;
  50. private readonly IRepository<OldPublicData> _oldPublicDataRepository;
  51. private readonly IRepository<KnowledgeRelationType> _knowledgeRelationTypeRepository;
  52. private readonly IRepository<KnowledgeType> _knowledgeTypeRepository;
  53. private readonly IRepository<Knowledge> _knowledgeRepository;
  54. private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
  55. public WebPortalController(IMapper mapper,
  56. IMediator mediator,
  57. IRepository<Bulletin> bulletinRepository,
  58. IRepository<WebUserRegister> webUserRegisterRepository,
  59. IRepository<WebUserAuth> webUserAuthRepository,
  60. IRepository<WebFlowAccept> webFlowAcceptRepository,
  61. ITypedCache<WriteLettersSendSmsDto> writeLettersSendSms,
  62. IRepository<Hotspot> hotspotRepository,
  63. ISystemSettingCacheManager systemSettingCacheManager,
  64. IRepository<OrderPublish> orderPublishRepository,
  65. IOrderRepository orderRepository,
  66. IRepository<OrderVisit> orderVisitRepository,
  67. IOrderApplication orderApplication,
  68. ISessionContext sessionContext,
  69. IRepository<OrderVisitDetail> orderVisitDetailRepository,
  70. IBulletinApplication bulletinApplication,
  71. IRepository<OldPublicData> oldPublicDataRepository,
  72. IRepository<KnowledgeRelationType> knowledgeRelationTypeRepository,
  73. IRepository<KnowledgeType> knowledgeTypeRepository,
  74. IRepository<Knowledge> knowledgeRepository,
  75. ISystemDicDataCacheManager systemDicDataCacheManager
  76. )
  77. {
  78. _mapper = mapper;
  79. _mediator = mediator;
  80. _bulletinRepository = bulletinRepository;
  81. _webUserRegisterRepository = webUserRegisterRepository;
  82. _webUserAuthRepository = webUserAuthRepository;
  83. _webFlowAcceptRepository = webFlowAcceptRepository;
  84. _writeLettersSendSms = writeLettersSendSms;
  85. _hotspotRepository = hotspotRepository;
  86. _systemSettingCacheManager = systemSettingCacheManager;
  87. _orderPublishRepository = orderPublishRepository;
  88. _orderRepository = orderRepository;
  89. _orderVisitRepository = orderVisitRepository;
  90. _orderApplication = orderApplication;
  91. _sessionContext = sessionContext;
  92. _orderVisitDetailRepository = orderVisitDetailRepository;
  93. _bulletinApplication = bulletinApplication;
  94. _oldPublicDataRepository = oldPublicDataRepository;
  95. _knowledgeRelationTypeRepository = knowledgeRelationTypeRepository;
  96. _knowledgeTypeRepository = knowledgeTypeRepository;
  97. _knowledgeRepository = knowledgeRepository;
  98. _systemDicDataCacheManager = systemDicDataCacheManager;
  99. }
  100. #region 通知
  101. /// <summary>
  102. /// 获取列表
  103. /// </summary>
  104. /// <returns></returns>
  105. [AllowAnonymous]
  106. [HttpPost("getarticlelist")]
  107. public async Task<OpenResponse> GetArticleList([FromBody] QueryArticleListDto dto)
  108. {
  109. RefAsync<int> total = 0;
  110. var items = await _bulletinRepository.Queryable()
  111. .Where(p => p.LoseEfficacyTime >= DateTime.Now)
  112. .Where(p => p.IsArrive == true)
  113. .Where(p => SqlFunc.JsonListObjectAny(p.PushRanges, "Key", "2"))
  114. .Where(p => p.BulletinTypeId == dto.NoticeType)
  115. .WhereIF(!string.IsNullOrEmpty(dto.Condition), p => p.Title.Contains(dto.Condition))
  116. .OrderByDescending(p => p.CreationTime)
  117. .Select(it => new
  118. {
  119. Page = SqlFunc.RowNumber($"{it.CreationTime} desc "),// SqlFunc.MappingColumn(default(int), " row_number() over( order by 'NoticeCreateDate' ) "),
  120. NoticeID = it.Id,
  121. NoticeContent = it.Content,
  122. NoticeTypeName = it.BulletinTypeName,
  123. NoticeTitle = it.Title,
  124. NoticeBMName = it.SourceOrgName,
  125. NoticeCreateDate = it.CreationTime,
  126. VideoUrl = "",
  127. WNLT_FullCode = ""
  128. })
  129. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  130. //计算总页数
  131. int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / dto.PageSize));
  132. ArticleListDataDto dataDto = new()
  133. {
  134. PageCount = nPageCount,
  135. data = _mapper.Map<IReadOnlyList<ArticleListDto>>(items)
  136. };
  137. return OpenResponse.Ok(WebPortalDeResponse<ArticleListDataDto>.Success(dataDto));
  138. }
  139. /// <summary>
  140. /// 获取通知公告前几条数据
  141. /// </summary>
  142. /// <param name="dto"></param>
  143. /// <returns></returns>
  144. [AllowAnonymous]
  145. [HttpPost("getarticlelistbynum")]
  146. public async Task<OpenResponse> GetArticleListByNum([FromBody] ArticleIdByNumDto dto)
  147. {
  148. var items = await _bulletinRepository.Queryable()
  149. .Where(p => p.LoseEfficacyTime >= DateTime.Now)
  150. .Where(p => p.IsArrive == true)
  151. .Where(p => SqlFunc.JsonListObjectAny(p.PushRanges, "Key", "2"))
  152. // .Where(p => p.BulletinTypeId == dto.BulletinTypeId)
  153. .WhereIF(!string.IsNullOrEmpty(dto.BulletinTypeId), p => p.BulletinTypeId == dto.BulletinTypeId)
  154. .WhereIF(!string.IsNullOrEmpty(dto.CheckChar), p => p.Content.Contains(dto.CheckChar))
  155. .WhereIF(!string.IsNullOrEmpty(dto.BulletinDisplayLocation), p => SqlFunc.JsonListObjectAny(p.DisplayLocation, "Key", dto.BulletinDisplayLocation))
  156. .OrderByDescending(p => p.CreationTime)
  157. .Select(it => new
  158. {
  159. DataID = it.Id,
  160. it.Title,
  161. CreateDate = it.CreationTime,
  162. it.Content,
  163. it.BulletinTypeName
  164. })
  165. .Take(dto.Num)
  166. .ToListAsync();
  167. var data = _mapper.Map<IReadOnlyList<DataListTopDto>>(items);
  168. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<DataListTopDto>>.Success(data, "成功"));
  169. }
  170. /// <summary>
  171. /// 获取详情,修改阅读次数
  172. /// </summary>
  173. /// <param name="dto"></param>
  174. /// <returns></returns>
  175. [AllowAnonymous]
  176. [HttpPost("getarticledetails")]
  177. public async Task<OpenResponse> GetArticleDetails([FromBody] ArticleIdDto dto)
  178. {
  179. var data = await _bulletinRepository.GetAsync(p => p.Id == dto.Id, HttpContext.RequestAborted);
  180. ArticleDetailsDto detailsDto = null;
  181. if (data != null)
  182. {
  183. data.ReadedNum = data.ReadedNum++;
  184. await _bulletinRepository.UpdateAsync(data, HttpContext.RequestAborted);
  185. detailsDto = new()
  186. {
  187. NoticeID = data.Id,
  188. NoticeTypeName = data.BulletinTypeName,
  189. NoticeTitle = data.Title,
  190. NoticeBMName = data.SourceOrgName,
  191. NoticeCreateDate = data.CreationTime,
  192. NoticeRCount = data.ReadedNum,
  193. WNED_VideoUrl = "",
  194. NoticeContent = data.Content
  195. };
  196. if (data != null && !string.IsNullOrEmpty(data.Content))
  197. data.Content = _bulletinApplication.GetSiteUrls(data.Content);
  198. }
  199. else
  200. detailsDto = new();
  201. List<ArticleDetailsDto> dataDto = new() { detailsDto };
  202. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<ArticleDetailsDto>>.Success(dataDto));
  203. }
  204. /// <summary>
  205. /// 上一条和下一条
  206. /// </summary>
  207. /// <param name="dto"></param>
  208. /// <returns></returns>
  209. [AllowAnonymous]
  210. [HttpPost("getpreviousandnext")]
  211. public async Task<OpenResponse> GetPreviousAndNext([FromBody] ArticlePreviousAndNextDto dto)
  212. {
  213. var sugar = _bulletinRepository.Queryable()
  214. .Where(p => p.LoseEfficacyTime >= DateTime.Now)
  215. .Where(p => p.IsArrive == true)
  216. .Where(p => SqlFunc.JsonListObjectAny(p.PushRanges, "Key", "2"))
  217. ;
  218. if (dto.FullSearch == "1")//全文搜索
  219. {
  220. sugar.Where(p => p.BulletinTypeId == "1" || p.BulletinTypeId == "5" || p.BulletinTypeId == "6" || p.BulletinTypeId == "7" || p.BulletinTypeId == "3" || p.BulletinTypeId == "4")
  221. .WhereIF(!string.IsNullOrEmpty(dto.Condition), p => p.Content.Contains(dto.Condition) || p.Title.Contains(dto.Condition));
  222. }
  223. else//指定分类
  224. {
  225. sugar.WhereIF(!string.IsNullOrEmpty(dto.Condition), p => p.Title.Contains(dto.Condition))
  226. .Where(p => p.BulletinTypeId == dto.NoticeTypeId);
  227. }
  228. var list = await sugar.OrderByDescending(p => p.CreationTime)
  229. .Select(it => new
  230. {
  231. Page = SqlFunc.RowNumber($"{it.CreationTime} desc "),// SqlFunc.MappingColumn(default(int), " row_number() over( order by 'NoticeCreateDate' ) "),
  232. NoticeID = it.Id,
  233. NoticeTitle = it.Title,
  234. NoticeCreateDate = it.CreationTime
  235. })
  236. .ToListAsync();
  237. //数据为空返回空数据
  238. if (list == null || list.Count == 0)
  239. return OpenResponse.Ok(WebPortalDeResponse<List<ArticlePreviousAndNextDataDto>>.Success(null));
  240. else
  241. {
  242. var temp = list.Find(p => p.NoticeID == dto.ID);
  243. if (temp != null)
  244. {
  245. List<ArticlePreviousAndNextDataDto> returnDto = new();
  246. //上一条
  247. var pTemp = list.Find(p => p.Page == temp.Page - 1);
  248. if (pTemp != null)
  249. returnDto.Add(new()
  250. {
  251. NoticeID = pTemp.NoticeID,
  252. NoticeTitle = pTemp.NoticeTitle,
  253. pntype = "p"
  254. });
  255. //下一条
  256. var nTemp = list.Find(p => p.Page == temp.Page + 1);
  257. if (nTemp != null)
  258. returnDto.Add(new()
  259. {
  260. NoticeID = nTemp.NoticeID,
  261. NoticeTitle = nTemp.NoticeTitle,
  262. pntype = "n"
  263. });
  264. return OpenResponse.Ok(WebPortalDeResponse<List<ArticlePreviousAndNextDataDto>>.Success(returnDto));
  265. }
  266. else
  267. return OpenResponse.Ok(WebPortalDeResponse<List<ArticlePreviousAndNextDataDto>>.Success(null));
  268. }
  269. }
  270. /// <summary>
  271. /// 全文检索
  272. /// </summary>
  273. /// <param name="dto"></param>
  274. /// <returns></returns>
  275. [AllowAnonymous]
  276. [HttpPost("getfulltextsearchlist")]
  277. public async Task<OpenResponse> GetFullTextSearchList([FromBody] QueryArticleListDto dto)
  278. {
  279. if (string.IsNullOrEmpty(dto.Condition))
  280. return OpenResponse.Ok(WebPortalDeResponse<FullTextSearchListDataDto>.Success(null));
  281. RefAsync<int> total = 0;
  282. var items = await _bulletinRepository.Queryable()
  283. .Where(p => p.LoseEfficacyTime >= DateTime.Now)
  284. .Where(p => p.IsArrive == true)
  285. .Where(p => SqlFunc.JsonListObjectAny(p.PushRanges, "Key", "2"))
  286. .Where(p => p.BulletinTypeId == "1" || p.BulletinTypeId == "5" || p.BulletinTypeId == "6" || p.BulletinTypeId == "7" || p.BulletinTypeId == "3" || p.BulletinTypeId == "4")
  287. .WhereIF(!string.IsNullOrEmpty(dto.Condition), p => p.Title.Contains(dto.Condition))
  288. .OrderByDescending(p => p.CreationTime)
  289. .Select(it => new
  290. {
  291. Page = SqlFunc.RowNumber($"{it.CreationTime} desc "),
  292. NoticeID = it.Id,
  293. Content = it.Content,
  294. NoticeTypeID = it.BulletinTypeId,
  295. NoticeTypeName = it.BulletinTypeName,
  296. NoticeTitle = it.Title,
  297. NoticeBMName = it.SourceOrgName,
  298. NoticeCreateDate = it.CreationTime,
  299. TypeCode = "",
  300. })
  301. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  302. //计算总页数
  303. int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / dto.PageSize));
  304. FullTextSearchListDataDto dataDto = new()
  305. {
  306. PageCount = nPageCount,
  307. data = _mapper.Map<IReadOnlyList<FullTextSearchListDto>>(items)
  308. };
  309. return OpenResponse.Ok(WebPortalDeResponse<FullTextSearchListDataDto>.Success(dataDto));
  310. }
  311. #endregion
  312. #region 用户
  313. /// <summary>
  314. /// 添加统一认证用户数据
  315. /// </summary>
  316. /// <param name="dto"></param>
  317. /// <returns></returns>
  318. [AllowAnonymous]
  319. [HttpPost("adduserauth")]
  320. public async Task<OpenResponse> AddUserAuth([FromBody] UserModelDto dto)
  321. {
  322. bool bResult = false;
  323. // 唯一记录ID
  324. string id = dto.id;
  325. // 注册用户ID
  326. string webUserID = "";
  327. // 统一认证用户注册ID
  328. string wUAID = "";
  329. //查询是否有注册用户
  330. var dataUser = await _webUserAuthRepository.GetAsync(p => p.DataId == id, HttpContext.RequestAborted);
  331. if (dataUser != null)
  332. {
  333. webUserID = dataUser.WebUserID;
  334. wUAID = dataUser.Id;
  335. }
  336. //没有注册用户添加数据
  337. if (string.IsNullOrEmpty(webUserID))
  338. {
  339. var userRegister = _mapper.Map<WebUserRegister>(dto);
  340. userRegister.RegDate = DateTime.Now;
  341. userRegister.LastDate = DateTime.Now;
  342. webUserID = await _webUserRegisterRepository.AddAsync(userRegister, HttpContext.RequestAborted);
  343. }
  344. //统一认证数据
  345. var userAuth = _mapper.Map<WebUserAuth>(dto);
  346. if (!string.IsNullOrEmpty(wUAID))
  347. {
  348. //修改数据
  349. userAuth.Id = wUAID;
  350. await _webUserAuthRepository.UpdateAsync(userAuth, HttpContext.RequestAborted);
  351. bResult = true;
  352. }
  353. else
  354. {
  355. //新增数据
  356. userAuth.WebGUID = Guid.NewGuid().ToString();
  357. userAuth.WebUserID = webUserID;
  358. var addId = await _webUserAuthRepository.AddAsync(userAuth, HttpContext.RequestAborted);
  359. if (!string.IsNullOrEmpty(addId))
  360. bResult = true;
  361. }
  362. //判断是否成功
  363. if (bResult)
  364. return OpenResponse.Ok(WebPortalDeResponse<string>.Success(webUserID));
  365. else
  366. return OpenResponse.Ok(WebPortalDeResponse<string>.Failed());
  367. }
  368. /// <summary>
  369. /// 用户中心用户写信数据
  370. /// </summary>
  371. /// <param name="dto"></param>
  372. /// <returns></returns>
  373. [HttpPost("getorderbyuserlist")]
  374. [AllowAnonymous]
  375. public async Task<OpenResponse> GetOrderByUserList([FromBody] QueryOrderListByUserDto dto)
  376. {
  377. var dataUser = await _webUserAuthRepository.GetAsync(p => p.DataId == dto.UserId, HttpContext.RequestAborted);
  378. if (dataUser != null)
  379. {
  380. RefAsync<int> total = 0;
  381. var items = await _webFlowAcceptRepository.Queryable()
  382. .LeftJoin<Hotline.Orders.Order>((o, or) => o.OrderId == or.Id)
  383. .Where(o => o.WebUserID == dataUser.WebUserID)
  384. //重新构建数据
  385. .Select((o, or) => new
  386. {
  387. FlowID = o.OrderId,
  388. FlowCode = o.Code,
  389. FlowPwd = o.Pwd,
  390. FlowTitle = o.Title,
  391. FlowFromName = or.SourceChannel,
  392. FlowPurTypeName = o.PurTypeName,
  393. ConTypeName = or.HotspotName,
  394. FlowAddDate = o.CreationTime,
  395. RSFlagName = or.Status < EOrderStatus.Filed ? "办理中" : "办理完成",
  396. WebUserID = o.WebUserID
  397. })
  398. //将结果合并成一个表
  399. .MergeTable()
  400. .Where(p => p.WebUserID == dataUser.WebUserID)
  401. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  402. //计算总页数
  403. int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / dto.PageSize));
  404. OrderListReturnDto returnDto = new()
  405. {
  406. PageNum = dto.PageIndex,
  407. PageCount = nPageCount,
  408. Data = _mapper.Map<IReadOnlyList<OrderListDto>>(items)
  409. };
  410. return OpenResponse.Ok(WebPortalDeResponse<OrderListReturnDto>.Success(returnDto, "成功"));
  411. }
  412. return OpenResponse.Ok(WebPortalDeResponse<OrderListReturnDto>.Success(new OrderListReturnDto(), "成功"));
  413. }
  414. #endregion
  415. #region 短信、基础设置
  416. /// <summary>
  417. /// 短信验证码发送
  418. /// </summary>
  419. /// <param name="dto"></param>
  420. /// <returns></returns>
  421. [AllowAnonymous]
  422. [HttpPost("writeletterssendsms")]
  423. public async Task<OpenResponse> WriteLettersSendSms([FromBody] WebPortalSendSmsModelDto dto)
  424. {
  425. string keyToken = "SmsUserWriteKey_" + dto.TelNum + "_" + DateTime.Now.ToString("yyyyMMdd");
  426. var data = await _writeLettersSendSms.GetAsync(keyToken, HttpContext.RequestAborted);
  427. if (data != null)//已经发过短信
  428. {
  429. //是否可以继续发送短信(10次)
  430. if (data.SendCount > 10)
  431. //短信发送超过10条
  432. return OpenResponse.Ok(WebPortalDeResponse<string>.Success("-2"));
  433. // 验证是否在两分钟之内
  434. TimeSpan duration = DateTime.Now - data.AddTime; // 计算时间差
  435. if ((int)duration.TotalSeconds < 120)
  436. // 距离上次发送时间不足两分钟
  437. return OpenResponse.Ok(WebPortalDeResponse<string>.Success("-4"));
  438. //修改缓存信息
  439. data.SendCount++;
  440. data.SmsCode = dto.SmsCode;
  441. data.AddTime = DateTime.Now;
  442. }
  443. else
  444. {
  445. //没有发过短信,直接写入数据
  446. data = new WriteLettersSendSmsDto
  447. {
  448. AddTime = DateTime.Now,
  449. SmsCode = dto.SmsCode,
  450. MobileNum = dto.TelNum,
  451. SendCount = 1
  452. };
  453. }
  454. //这里发送短信 宜宾12345市民服务热线网站验证码{0},用于写信时验证联系电话。验证码有效期10分钟。
  455. var messageDto = new Share.Dtos.Push.MessageDto
  456. {
  457. PushBusiness = EPushBusiness.MsgCode,
  458. ExternalId = "",
  459. OrderId = "",
  460. PushPlatform = EPushPlatform.Web,
  461. Remark = "",
  462. Name = dto.TelNum,
  463. TemplateCode = "1008",
  464. Params = new List<string>() { dto.SmsCode },
  465. TelNumber = dto.TelNum,
  466. };
  467. await _mediator.Publish(new PushMessageNotify(messageDto), HttpContext.RequestAborted);
  468. //修改缓存
  469. await _writeLettersSendSms.SetAsync(keyToken, data, TimeSpan.FromDays(1), HttpContext.RequestAborted);
  470. return OpenResponse.Ok(WebPortalDeResponse<string>.Success("1"));
  471. }
  472. /// <summary>
  473. /// 验证短信验证码是否正确 正确返回1,错误返回-1
  474. /// </summary>
  475. /// <param name="dto"></param>
  476. /// <returns></returns>
  477. [AllowAnonymous]
  478. [HttpPost("checksmscode")]
  479. public async Task<OpenResponse> CheckSmsCode([FromBody] WebPortalSendSmsModelDto dto)
  480. {
  481. string keyToken = "SmsUserWriteKey_" + dto.TelNum + "_" + DateTime.Now.ToString("yyyyMMdd");
  482. var data = await _writeLettersSendSms.GetAsync(keyToken, HttpContext.RequestAborted);
  483. //检测是否存在
  484. if (data != null)
  485. return OpenResponse.Ok(WebPortalDeResponse<string>.Success(data.SmsCode));
  486. //不存在
  487. return OpenResponse.Ok(WebPortalDeResponse<string>.Success("-1"));
  488. }
  489. /// <summary>
  490. /// 获取热点分类的树形
  491. /// </summary>
  492. /// <returns></returns>
  493. [AllowAnonymous]
  494. [HttpPost("gethotspottreelist")]
  495. public async Task<OpenResponse> GetHotspotTreeList()
  496. {
  497. var data = await _hotspotRepository.Queryable().ToTreeAsync(it => it.Children, it => it.ParentId, null);
  498. return OpenResponse.Ok(WebPortalDeResponse<List<Hotspot>>.Success(data));
  499. }
  500. /// <summary>
  501. /// 系统主题颜色
  502. /// </summary>
  503. /// <returns></returns>
  504. [AllowAnonymous]
  505. [HttpPost("getsystemsettingstheme")]
  506. public async Task<OpenResponse> GetSystemSettingsTheme()
  507. {
  508. var WebSystemSettingsTheme = bool.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.WebSystemSettingsTheme).SettingValue[0]);
  509. if (WebSystemSettingsTheme == false)
  510. return OpenResponse.Ok(WebPortalDeResponse<string>.Success(""));
  511. else
  512. return OpenResponse.Ok(WebPortalDeResponse<string>.Success("class=gray2"));
  513. }
  514. #endregion
  515. #region 办件
  516. /// <summary>
  517. /// 获取信件前6条数据
  518. /// </summary>
  519. /// <param name="dto"></param>
  520. /// <returns></returns>
  521. [HttpPost("getorderlistbynum")]
  522. [AllowAnonymous]
  523. public async Task<OpenResponse> GetOrderListByNum([FromBody] QueryOrderListByNumDto dto)
  524. {
  525. var queryNew = _orderRepository.Queryable()
  526. .LeftJoin<OrderPublish>((p, op) => p.Id == op.OrderId)
  527. .Where(p => p.IsPublicity == true)
  528. .OrderByDescending((p, op) => p.CreationTime)
  529. .Select((p, op) => new DataListTopDto
  530. {
  531. DataID = p.Id,
  532. Title = p.Title,
  533. CreateDate = op.CreationTime
  534. });
  535. var queryold = _oldPublicDataRepository.Queryable()
  536. .OrderByDescending(p => p.PubDate)
  537. .Select(p => new DataListTopDto
  538. {
  539. DataID = p.OrderId,
  540. Title = p.Title,
  541. CreateDate = p.CreationTime
  542. });
  543. var items = await _orderRepository.UnionAll(queryNew, queryold)
  544. .OrderByDescending(p => p.CreateDate)
  545. .Take(dto.Num)
  546. .ToListAsync();
  547. var data = _mapper.Map<IReadOnlyList<DataListTopDto>>(items);
  548. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<DataListTopDto>>.Success(data, "成功"));
  549. }
  550. /// <summary>
  551. /// 办件摘编列表数据
  552. /// </summary>
  553. /// <param name="dto"></param>
  554. /// <returns></returns>
  555. [HttpPost("getorderlist")]
  556. [AllowAnonymous]
  557. public async Task<OpenResponse> GetOrderList([FromBody] QueryOrderListDto dto)
  558. {
  559. RefAsync<int> total = 0;
  560. var queryNew = _orderPublishRepository.Queryable()
  561. .Includes(d => d.Order)
  562. .Where(d => d.PublishState == true && d.Order.Id != null)
  563. .WhereIF(!string.IsNullOrEmpty(dto.FlowCode), d => d.Order.No == dto.FlowCode)
  564. .WhereIF(!string.IsNullOrEmpty(dto.FlowName), d => d.Order.Title.Contains(dto.FlowName))
  565. .WhereIF(!string.IsNullOrEmpty(dto.FlowSType), d => d.Order.AcceptTypeCode == dto.FlowSType)
  566. .WhereIF(!string.IsNullOrEmpty(dto.FlowRType), d => d.Order.HotspotId == dto.FlowRType)
  567. .WhereIF(!string.IsNullOrEmpty(dto.FlowSDate), d => d.Order.StartTime >= DateTime.Parse(DateTime.Parse(dto.FlowSDate).ToString("yyyy-MM-dd 00:00:00")))//dto.FlowSDate
  568. .WhereIF(!string.IsNullOrEmpty(dto.FlowEDate), d => d.Order.StartTime <= DateTime.Parse(DateTime.Parse(dto.FlowEDate).ToString("yyyy-MM-dd 00:00:00")))// dto.FlowEDate
  569. .WhereIF(!string.IsNullOrEmpty(dto.FlowFrom), d => d.Order.FromName.Contains(dto.FlowFrom))
  570. .OrderByDescending(p => p.CreationTime)
  571. .Select(p => new OrderListDto
  572. {
  573. FlowID = p.OrderId,
  574. FlowCode = p.No,
  575. FlowPwd = p.Order.Password,
  576. FlowTitle = p.Order.Title,
  577. FlowFromName = p.Order.SourceChannel,
  578. FlowPurTypeName = p.Order.AcceptType,
  579. ConTypeName = p.Order.HotspotName,
  580. FlowAddDate = p.Order.CreationTime,
  581. RSFlagName = p.Order.Status >= EOrderStatus.Filed ? "办理完成" : "办理中",
  582. PubDate = p.CreationTime
  583. });
  584. var queryold = _oldPublicDataRepository.Queryable()
  585. .WhereIF(!string.IsNullOrEmpty(dto.FlowCode), d => d.OrderNo == dto.FlowCode)
  586. .WhereIF(!string.IsNullOrEmpty(dto.FlowName), d => d.Title.Contains(dto.FlowName))
  587. .WhereIF(!string.IsNullOrEmpty(dto.FlowSType), d => d.AcceptTypeCode == dto.FlowSType)
  588. .WhereIF(!string.IsNullOrEmpty(dto.FlowSDate), d => d.PubDate >= DateTime.Parse(DateTime.Parse(dto.FlowSDate).ToString("yyyy-MM-dd 00:00:00")))//dto.FlowSDate
  589. .WhereIF(!string.IsNullOrEmpty(dto.FlowEDate), d => d.PubDate <= DateTime.Parse(DateTime.Parse(dto.FlowEDate).ToString("yyyy-MM-dd 00:00:00")))// dto.FlowEDate
  590. .WhereIF(!string.IsNullOrEmpty(dto.FlowFrom), d => d.FromName.Contains(dto.FlowFrom))
  591. .OrderByDescending(p => p.PubDate)
  592. .Select(p => new OrderListDto
  593. {
  594. FlowID = p.OrderId,
  595. FlowCode = p.OrderNo,
  596. FlowPwd = p.OrderPwd,
  597. FlowTitle = p.Title,
  598. FlowFromName = p.SourceChannel,
  599. FlowPurTypeName = p.AcceptType,
  600. ConTypeName = p.HotspotName,
  601. FlowAddDate = p.AcceptTime,
  602. RSFlagName = p.State == "1" ? "办理完成" : "办理中",
  603. PubDate = p.PubDate
  604. });
  605. var items = await _orderRepository.UnionAll(queryNew, queryold)
  606. .OrderByDescending(p => p.PubDate)
  607. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  608. //计算总页数
  609. int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / dto.PageSize));
  610. OrderListReturnDto returnDto = new()
  611. {
  612. PageNum = dto.PageIndex,
  613. PageCount = nPageCount,
  614. Data = _mapper.Map<IReadOnlyList<OrderListDto>>(items)
  615. };
  616. return OpenResponse.Ok(WebPortalDeResponse<OrderListReturnDto>.Success(returnDto, "成功"));
  617. }
  618. /// <summary>
  619. /// 查询工单发布后公开的数据
  620. /// </summary>
  621. /// <param name="dto"></param>
  622. /// <returns></returns>
  623. [HttpPost("get_order_list_publish_all")]
  624. [AllowAnonymous]
  625. public async Task<OpenResponse> GetOrderByListAllOpen([FromBody] QueryOrderListDto dto)
  626. {
  627. var queryNew = _orderRepository.Queryable()
  628. .LeftJoin<OrderPublish>((p, op) => p.Id == op.OrderId)
  629. .Where(p => p.IsPublicity == true)
  630. .WhereIF(!string.IsNullOrEmpty(dto.FlowCode), (p, op) => p.No == dto.FlowCode)
  631. .WhereIF(!string.IsNullOrEmpty(dto.FlowName), (p, op) => p.Title.Contains(dto.FlowName))
  632. .WhereIF(!string.IsNullOrEmpty(dto.FlowSType), (p, op) => p.AcceptTypeCode == dto.FlowSType)
  633. .WhereIF(!string.IsNullOrEmpty(dto.FlowRType), (p, op) => p.HotspotId == dto.FlowRType)
  634. .WhereIF(!string.IsNullOrEmpty(dto.FlowSDate), (p, op) => p.StartTime >= DateTime.Parse(DateTime.Parse(dto.FlowSDate).ToString("yyyy-MM-dd 00:00:00")))//dto.FlowSDate
  635. .WhereIF(!string.IsNullOrEmpty(dto.FlowEDate), (p, op) => p.StartTime <= DateTime.Parse(DateTime.Parse(dto.FlowEDate).ToString("yyyy-MM-dd 00:00:00")))// dto.FlowEDate
  636. .WhereIF(!string.IsNullOrEmpty(dto.FlowFrom), (p, op) => p.FromName.Contains(dto.FlowFrom))
  637. .OrderByDescending((p, op) => p.CreationTime)
  638. .Select((p, op) => new OrderListDto
  639. {
  640. FlowID = p.Id,
  641. FlowCode = p.No,
  642. FlowPwd = p.Password,
  643. FlowTitle = p.Title,
  644. FlowFromName = p.SourceChannel,
  645. FlowPurTypeName = p.AcceptType,
  646. ConTypeName = p.HotspotName,
  647. FlowAddDate = p.CreationTime,
  648. PubDate = op.CreationTime,
  649. RSFlagName = p.Status >= EOrderStatus.Filed ? "办理完成" : "办理中"
  650. });
  651. var queryold = _oldPublicDataRepository.Queryable()
  652. .WhereIF(!string.IsNullOrEmpty(dto.FlowCode), p => p.OrderNo == dto.FlowCode)
  653. .WhereIF(!string.IsNullOrEmpty(dto.FlowName), p => p.Title.Contains(dto.FlowName))
  654. .WhereIF(!string.IsNullOrEmpty(dto.FlowSType), p => p.AcceptTypeCode == dto.FlowSType)
  655. .WhereIF(!string.IsNullOrEmpty(dto.FlowRType), p => p.HotspotId == dto.FlowRType)
  656. .WhereIF(!string.IsNullOrEmpty(dto.FlowSDate), p => p.AcceptTime >= DateTime.Parse(DateTime.Parse(dto.FlowSDate).ToString("yyyy-MM-dd 00:00:00")))//dto.FlowSDate
  657. .WhereIF(!string.IsNullOrEmpty(dto.FlowEDate), p => p.AcceptTime <= DateTime.Parse(DateTime.Parse(dto.FlowEDate).ToString("yyyy-MM-dd 00:00:00")))// dto.FlowEDate
  658. .WhereIF(!string.IsNullOrEmpty(dto.FlowFrom), p => p.FromName.Contains(dto.FlowFrom))
  659. .OrderByDescending(p => p.PubDate)
  660. .Select(p => new OrderListDto
  661. {
  662. FlowID = p.OrderId,
  663. FlowCode = p.OrderNo,
  664. FlowPwd = p.OrderPwd,
  665. FlowTitle = p.Title,
  666. FlowFromName = p.SourceChannelCode,
  667. FlowPurTypeName = p.AcceptTypeCode,
  668. ConTypeName = p.HotspotName,
  669. FlowAddDate = p.CreationTime,
  670. PubDate = p.CreationTime,
  671. RSFlagName = p.State == "1" ? "办理完成" : "办理中"
  672. });
  673. var (total, items) = await _orderRepository.UnionAll(queryNew, queryold)
  674. .OrderByDescending(p => p.PubDate)
  675. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  676. //计算总页数
  677. int nPageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / dto.PageSize));
  678. OrderListReturnDto returnDto = new()
  679. {
  680. PageNum = dto.PageIndex,
  681. PageCount = nPageCount,
  682. Data = _mapper.Map<IReadOnlyList<OrderListDto>>(items)
  683. };
  684. return OpenResponse.Ok(WebPortalDeResponse<OrderListReturnDto>.Success(returnDto, "成功"));
  685. }
  686. /// <summary>
  687. /// 办件摘编详情
  688. /// </summary>
  689. /// <param name="dto"></param>
  690. /// <returns></returns>
  691. [AllowAnonymous]
  692. [HttpPost("getorderdetailbyid")]
  693. public async Task<OpenResponse> GetOrderDetailById([FromBody] ArticleIdDto dto)
  694. {
  695. var data = await _orderRepository.GetAsync(p => p.Id == dto.Id, HttpContext.RequestAborted);
  696. var orderDetail = _mapper.Map<OrderDetail>(data);
  697. if (data != null)
  698. {
  699. //如果是省工单或者是省政民互动的工单,市民不能进行评价
  700. if (data.IsProvince == true || data.SourceChannelCode == "ZMHD")
  701. orderDetail.IsProvinceOrder = "1";
  702. else
  703. orderDetail.IsProvinceOrder = "0";
  704. //获取发布的数据
  705. var orderPublish = await _orderPublishRepository.GetAsync(p => p.OrderId == data.Id, HttpContext.RequestAborted);
  706. if (orderPublish != null)
  707. {
  708. orderDetail.PubFlag = "1";
  709. orderDetail.FlowTitle = orderPublish.ArrangeTitle;
  710. orderDetail.FlowContent = orderPublish.ArrangeContent;
  711. orderDetail.FlowResult = orderPublish.ArrangeOpinion;
  712. if (orderPublish.PublishState)
  713. orderDetail.FlowPubFlagName = "公开";
  714. }
  715. //能否进行评价
  716. var orderVisit = await _orderVisitRepository.GetAsync(p => p.OrderId == data.Id && p.VisitState != EVisitState.None, HttpContext.RequestAborted);
  717. if (orderVisit == null)
  718. orderDetail.VisitType = "0";
  719. else
  720. {
  721. orderDetail.VisitType = orderVisit.VisitState switch
  722. {
  723. EVisitState.WaitForVisit => "1",
  724. EVisitState.Visited => "2",
  725. EVisitState.Visiting or EVisitState.NoSatisfiedWaitForVisit or EVisitState.None => "0",
  726. _ => "0",
  727. };
  728. }
  729. }
  730. List<OrderDetail> dataDto = new() { orderDetail };
  731. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<OrderDetail>>.Success(dataDto));
  732. }
  733. /// <summary>
  734. /// 根据编号和密码查询信件ID
  735. /// </summary>
  736. /// <param name="dto"></param>
  737. /// <returns></returns>
  738. [AllowAnonymous]
  739. [HttpPost("getorderid")]
  740. public async Task<OpenResponse> GetOrderId([FromBody] GetOrderCodePwd dto)
  741. {
  742. var data = await _orderRepository.GetAsync(p => p.No == dto.OrderNo && p.Password == dto.Pwd, HttpContext.RequestAborted);//&& p.Status > EOrderStatus.Published
  743. return OpenResponse.Ok(WebPortalDeResponse<string>.Success(data?.Id));
  744. }
  745. /// <summary>
  746. /// 办件摘编详情
  747. /// </summary>
  748. /// <param name="dto"></param>
  749. /// <returns></returns>
  750. [AllowAnonymous]
  751. [HttpPost("getorderdetailbyno")]
  752. public async Task<OpenResponse> GetOrderDetailByNo([FromBody] GetOrderCodePwd dto)
  753. {
  754. var data = await _orderRepository.GetAsync(p => p.No == dto.OrderNo && p.Password == dto.Pwd, HttpContext.RequestAborted);
  755. if (data != null)
  756. {
  757. var orderDetail = _mapper.Map<OrderDetail>(data);
  758. if (data != null)
  759. {
  760. //如果是省工单或者是省政民互动的工单,市民不能进行评价
  761. if (data.IsProvince == true || data.SourceChannelCode == "ZMHD")
  762. orderDetail.IsProvinceOrder = "1";
  763. else
  764. orderDetail.IsProvinceOrder = "0";
  765. //获取发布的数据
  766. var orderPublish = await _orderPublishRepository.GetAsync(p => p.OrderId == data.Id, HttpContext.RequestAborted);
  767. if (orderPublish != null)
  768. {
  769. orderDetail.PubFlag = "1";
  770. orderDetail.FlowTitle = orderPublish.ArrangeTitle;
  771. orderDetail.FlowContent = orderPublish.ArrangeContent;
  772. orderDetail.FlowResult = orderPublish.ArrangeOpinion;
  773. if (orderPublish.PublishState)
  774. orderDetail.FlowPubFlagName = "公开";
  775. }
  776. //能否进行评价
  777. var orderVisit = await _orderVisitRepository.GetAsync(p => p.OrderId == data.Id && p.VisitState != EVisitState.None, HttpContext.RequestAborted);
  778. if (orderVisit == null)
  779. orderDetail.VisitType = "0";
  780. else
  781. {
  782. orderDetail.VisitType = orderVisit.VisitState switch
  783. {
  784. EVisitState.WaitForVisit => "1",
  785. EVisitState.Visited => "2",
  786. EVisitState.Visiting or EVisitState.NoSatisfiedWaitForVisit or EVisitState.None => "0",
  787. _ => "0",
  788. };
  789. }
  790. }
  791. List<OrderDetail> dataDto = new() { orderDetail };
  792. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<OrderDetail>>.Success(dataDto));
  793. }
  794. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<string>>.Failed(code: "0", description: "查询失败"));
  795. }
  796. /// <summary>
  797. /// 写信接口
  798. /// </summary>
  799. /// <param name="dto"></param>
  800. /// <returns></returns>
  801. [AllowAnonymous]
  802. [HttpPost("orderacceptance")]
  803. public async Task<OpenResponse> OrderAcceptance([FromBody] WebFlowAccept dto)
  804. {
  805. //电话号码去空格
  806. if (!string.IsNullOrEmpty(dto.Mobile))
  807. dto.Mobile = dto.Mobile.Trim();
  808. var data = _mapper.Map<Hotline.Share.Dtos.Order.AddOrderDto>(dto);
  809. if (string.IsNullOrEmpty(data.SourceChannelCode))
  810. {
  811. data.SourceChannel = "因特网";
  812. data.SourceChannelCode = "YTW";
  813. }
  814. data.Source = ESource.WebPortal;
  815. if (!string.IsNullOrEmpty(data.LicenceNo))
  816. {
  817. data.LicenceTypeCode = "10";
  818. data.LicenceType = "中华人民共和国居民身份证";
  819. }
  820. data.ExternalId = Guid.NewGuid().ToString();
  821. data.IdentityType = EIdentityType.Citizen;
  822. data.Transpond = false;
  823. data.IsEnforcementOrder = false;
  824. var result = await _orderApplication.ReceiveOrderFromExternalAsync(data, HttpContext.RequestAborted);
  825. OrderAcceptanceReturnDto returnDto = new();
  826. if (result != null)
  827. {
  828. returnDto.PWD = result.Password;
  829. returnDto.Code = result.No;
  830. returnDto.State = "1";
  831. dto.Pwd = result.Password;
  832. dto.Code = result.No;
  833. dto.OrderId = result.Id;
  834. await _webFlowAcceptRepository.AddAsync(dto, HttpContext.RequestAborted);
  835. }
  836. else
  837. returnDto.State = "0";
  838. return OpenResponse.Ok(WebPortalDeResponse<OrderAcceptanceReturnDto>.Success(returnDto));
  839. }
  840. /// <summary>
  841. /// 受理类型和热点统计
  842. /// </summary>
  843. /// <returns></returns>
  844. [AllowAnonymous]
  845. [HttpPost("getchartdata")]
  846. public async Task<OpenResponse> GetChartData()
  847. {
  848. var startDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  849. var endDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  850. //数据查询
  851. var listType = await _orderRepository.Queryable()
  852. .Where(p => p.CreationTime >= startDate && p.CreationTime <= endDate && p.Status > EOrderStatus.WaitForAccept)
  853. .Select(it => new
  854. {
  855. it.AcceptType,
  856. it.AcceptTypeCode
  857. })
  858. .MergeTable()//将查询出来的结果合并成一个新表
  859. .GroupBy(it => new { it.AcceptType, it.AcceptTypeCode })//对新表进行分组
  860. .Select(it => new
  861. {
  862. name = it.AcceptType,
  863. value = SqlFunc.AggregateCount(it.AcceptTypeCode)
  864. })
  865. .ToListAsync();
  866. var listHot = await _orderRepository.Queryable()
  867. .Where(it => it.CreationTime >= startDate && it.CreationTime <= endDate && it.Status > EOrderStatus.WaitForAccept)
  868. .Select(it => new
  869. {
  870. HotspotId = it.HotspotId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("2")),
  871. })
  872. .MergeTable()
  873. .Where(it => it.HotspotId != "18")
  874. .GroupBy(it => it.HotspotId)//对新表进行分组
  875. .Select(it => new
  876. {
  877. HotspotId = it.HotspotId,
  878. num = SqlFunc.AggregateCount(it.HotspotId)
  879. })
  880. .OrderByDescending(it => it.num)
  881. .Take(5)
  882. .MergeTable()
  883. .LeftJoin<Hotspot>((it, h) => it.HotspotId == h.Id)
  884. .Select((it, h) => new
  885. {
  886. typeName = h.HotSpotName,
  887. num = it.num
  888. }).ToListAsync();
  889. ////数据查询-查询总数前5的数据
  890. //var listHot = await _orderRepository.Queryable()
  891. // .Where(p => p.StartTime >= startDate && p.StartTime <= endDate && p.Status > EOrderStatus.WaitForAccept)
  892. // .Select(it => new
  893. // {
  894. // it.HotspotId,
  895. // it.HotspotName
  896. // })
  897. // .MergeTable()//将查询出来的结果合并成一个新表
  898. // .GroupBy(it => new { it.HotspotId, it.HotspotName })//对新表进行分组
  899. // .Select(it => new
  900. // {
  901. // typeName = it.HotspotName,
  902. // num = SqlFunc.AggregateCount(it.HotspotId)
  903. // })
  904. // .OrderByDescending(it => it.num)
  905. // .Take(5)
  906. // .ToListAsync();
  907. GetChartDataDto dataDto = new()
  908. {
  909. formCount = _mapper.Map<IReadOnlyList<OrderFormCount>>(listType),
  910. hotCount = _mapper.Map<IReadOnlyList<OrderHotCount>>(listHot)
  911. };
  912. return OpenResponse.Ok(WebPortalDeResponse<GetChartDataDto>.Success(dataDto));
  913. }
  914. /// <summary>
  915. /// 获取统计数据
  916. /// </summary>
  917. /// <returns></returns>
  918. [AllowAnonymous]
  919. [HttpPost("getstatist")]
  920. public async Task<OpenResponse> GetStatist()
  921. {
  922. var startDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  923. var endDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  924. //GetStatistDto getStatistDto = new()
  925. //{
  926. // AllCount = await _orderRepository.Queryable().Where(p => p.Status > EOrderStatus.WaitForAccept).CountAsync(),
  927. // AllTrandCount = await _orderRepository.Queryable().Where(p => p.Status >= EOrderStatus.Filed).CountAsync(),
  928. // DayCount = await _orderRepository.Queryable().Where(p => p.StartTime >= startDate && p.StartTime <= endDate && p.Status > EOrderStatus.WaitForAccept).CountAsync(),
  929. // DayTrandCount = await _orderRepository.Queryable().Where(p => p.ActualHandleTime >= startDate && p.ActualHandleTime <= endDate && p.Status >= EOrderStatus.Filed).CountAsync()
  930. //};
  931. var getStatistDto = await _orderRepository.Queryable()
  932. .Select(p => new GetStatistDto
  933. {
  934. AllCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.Status > EOrderStatus.WaitForAccept, 1, 0)) + 7079457,
  935. AllTrandCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.Status >= EOrderStatus.Filed, 1, 0)) + 7079214,
  936. DayCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.CreationTime >= startDate && p.CreationTime <= endDate && p.Status > EOrderStatus.WaitForAccept, 1, 0)),
  937. DayTrandCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.CreationTime >= startDate && p.CreationTime <= endDate && p.FiledTime >= startDate && p.FiledTime <= endDate && p.Status >= EOrderStatus.Filed, 1, 0)),
  938. })
  939. .FirstAsync();
  940. return OpenResponse.Ok(WebPortalDeResponse<GetStatistDto>.Success(getStatistDto));
  941. }
  942. #endregion
  943. #region 评价
  944. /// <summary>
  945. /// 获取待评价部门信息
  946. /// </summary>
  947. /// <param name="dto"></param>
  948. /// <returns></returns>
  949. [AllowAnonymous]
  950. [HttpPost("getwaitvisitdata")]
  951. public async Task<OpenResponse> GetWaitVisitData([FromBody] ArticleIdDto dto)
  952. {
  953. var dataOrder = await _orderVisitRepository.GetAsync(p => p.OrderId == dto.Id && p.VisitState != EVisitState.None, HttpContext.RequestAborted);
  954. if (dataOrder == null)
  955. return OpenResponse.Ok(WebPortalDeResponse<List<WaitVisitListDataDto>>.Failed("工单不能评价!"));
  956. if (dataOrder.VisitState != EVisitState.WaitForVisit)
  957. return OpenResponse.Ok(WebPortalDeResponse<List<WaitVisitListDataDto>>.Failed("工单已经评价!"));
  958. var data = await _orderVisitDetailRepository.Queryable()
  959. .Where(p => p.VisitId == dataOrder.Id && p.VisitTarget == EVisitTarget.Org)
  960. .ToListAsync();
  961. var listDat = _mapper.Map<List<WaitVisitListDataDto>>(data);
  962. return OpenResponse.Ok(WebPortalDeResponse<List<WaitVisitListDataDto>>.Success(listDat));
  963. }
  964. /// <summary>
  965. /// 评价内容
  966. /// </summary>
  967. /// <param name="dto"></param>
  968. /// <returns></returns>
  969. [AllowAnonymous]
  970. [HttpPost("receivevisitdata")]
  971. public async Task<OpenResponse> ReceiveVisitData([FromBody] OrderVisitListDataDto dto)
  972. {
  973. if (dto == null || dto.VistListDtos == null || dto.VistListDtos.Count == 0)
  974. return OpenResponse.Ok(WebPortalDeResponse<string>.Failed("评价数据不能为空!"));
  975. var dataOrder = await _orderVisitRepository.GetAsync(p => p.OrderId == dto.OrderId && p.VisitState != EVisitState.None, HttpContext.RequestAborted);
  976. if (dataOrder == null)
  977. return OpenResponse.Ok(WebPortalDeResponse<string>.Failed("工单已经评价!"));
  978. //组装数据
  979. OrderVisitWebDto visitWebDto = new()
  980. {
  981. VisitType = Hotline.Share.Enums.Order.EVisitType.WebVisit,
  982. VisitTime = DateTime.Now
  983. };
  984. List<OrderVisitDetailWebDto> orderVisitDetails = new();
  985. #region 部门评价
  986. //部门评价
  987. //遍历数据
  988. foreach (var item in dto.VistListDtos)
  989. {
  990. Hotline.Share.Dtos.Kv kv = item.SatisfactionCode switch
  991. {
  992. "5" => new Hotline.Share.Dtos.Kv { Key = "5", Value = "非常满意" },
  993. "4" => new Hotline.Share.Dtos.Kv { Key = "4", Value = "满意" },
  994. "2" => new Hotline.Share.Dtos.Kv { Key = "2", Value = "不满意" },
  995. _ => new Hotline.Share.Dtos.Kv { Key = "7", Value = "不做评价" },
  996. };
  997. //组装回访数据
  998. visitWebDto.Id = item.VisitId;
  999. OrderVisitDetailWebDto detailDto = new()
  1000. {
  1001. Id = item.Id,
  1002. VisitTarget = Hotline.Share.Enums.Order.EVisitTarget.Org,
  1003. OrgProcessingResults = kv,
  1004. OrgNoSatisfiedReason = new List<Hotline.Share.Dtos.Kv>(),
  1005. OrgHandledAttitude = kv,
  1006. VisitContent = item.VisitContent
  1007. };
  1008. orderVisitDetails.Add(detailDto);
  1009. }
  1010. #endregion
  1011. visitWebDto.OrderVisitDetailDto = orderVisitDetails;
  1012. //推送数据
  1013. await _orderApplication.OrderVisitWeb(visitWebDto, HttpContext.RequestAborted);
  1014. return OpenResponse.Ok(WebPortalDeResponse<string>.Success("1"));
  1015. }
  1016. #endregion
  1017. /// <summary>
  1018. /// 获取知识库分类
  1019. /// </summary>
  1020. /// <returns></returns>
  1021. [HttpPost("getknowledgetype")]
  1022. [AllowAnonymous]
  1023. public async Task<OpenResponse> GetKnowledgeType()
  1024. {
  1025. //查询知识分类
  1026. var item = await _knowledgeTypeRepository.Queryable()
  1027. .Where(p => p.ParentId == null || p.ParentId == "")
  1028. .Select(p => new
  1029. {
  1030. SDICT_ID = p.Id,
  1031. SDICT_Name = p.Name
  1032. })
  1033. .ToListAsync();
  1034. //查询知识标签
  1035. var list = _systemDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.KnowledgeBaseTags).Select(p => new
  1036. {
  1037. SDICT_Name = p.DicDataName,
  1038. SDICT_ID = p.DicDataName
  1039. }).ToList();
  1040. var rsp = new
  1041. {
  1042. KnowledgeType = item,
  1043. KnowledgeBaseTags = item,
  1044. };
  1045. return OpenResponse.Ok(WebPortalDeResponse<object>.Success(rsp));
  1046. }
  1047. /// <summary>
  1048. /// 知识库查询
  1049. /// </summary>
  1050. /// <param name="dto"></param>
  1051. /// <returns></returns>
  1052. [HttpPost("getknowledgelist")]
  1053. [AllowAnonymous]
  1054. public async Task<OpenResponse> GetKnowledgeList([FromBody] QueryKnowledgeList dto)
  1055. {
  1056. var typeSpliceName = string.Empty;
  1057. if (!string.IsNullOrEmpty(dto.KnowledgeTypeId))
  1058. {
  1059. var type = await _knowledgeTypeRepository.GetAsync(x => x.Id == dto.KnowledgeTypeId);
  1060. typeSpliceName = type?.SpliceName;
  1061. }
  1062. var typeSpliceNameTags = string.Empty;
  1063. if (!string.IsNullOrEmpty(dto.KnowledgeBaseTags))
  1064. {
  1065. var type = await _knowledgeTypeRepository.GetAsync(x => x.Name == dto.KnowledgeBaseTags);
  1066. typeSpliceNameTags = type?.SpliceName;
  1067. }
  1068. var (total, items) = await _knowledgeRepository.Queryable()
  1069. .WhereIF(!string.IsNullOrEmpty(dto.Title), p => p.Title.Contains(dto.Title))
  1070. .WhereIF(!string.IsNullOrEmpty(typeSpliceNameTags), p => p.KnowledgeType.Any(t => t.KnowledgeTypeSpliceName.EndsWith(typeSpliceNameTags)))
  1071. .WhereIF(!string.IsNullOrEmpty(typeSpliceName), x => x.KnowledgeType.Any(t => t.KnowledgeTypeSpliceName.EndsWith(typeSpliceName)))
  1072. .OrderByDescending(p => p.CreationTime)
  1073. .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
  1074. var data = new PagedDto<KnowledgeInfoDto>(total, _mapper.Map<IReadOnlyList<KnowledgeInfoDto>>(items));
  1075. return OpenResponse.Ok(WebPortalDeResponse<PagedDto<KnowledgeInfoDto>>.Success(data));
  1076. }
  1077. /// <summary>
  1078. /// 获取知识库详情
  1079. /// </summary>
  1080. /// <param name="dto"></param>
  1081. /// <returns></returns>
  1082. [HttpPost("getknowledgeinfo")]
  1083. [AllowAnonymous]
  1084. public async Task<OpenResponse> GetKnowledgeInfo([FromBody] QueryKnowledgeInfo dto)
  1085. {
  1086. var data = await _knowledgeRepository.GetAsync(p => p.Id == dto.Id, HttpContext.RequestAborted);
  1087. KnowledgeInfoDto detailsDto = null;
  1088. if (data != null)
  1089. {
  1090. detailsDto = _mapper.Map<KnowledgeInfoDto>(data);
  1091. if (detailsDto != null && !string.IsNullOrEmpty(detailsDto.Content))
  1092. data.Content = _bulletinApplication.GetSiteUrls(data.Content);
  1093. }
  1094. else
  1095. {
  1096. detailsDto = new();
  1097. }
  1098. List<KnowledgeInfoDto> dataDto = [detailsDto];
  1099. return OpenResponse.Ok(WebPortalDeResponse<IReadOnlyList<KnowledgeInfoDto>>.Success(dataDto));
  1100. }
  1101. }
  1102. }