ResourceController.cs 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. using OASystem.API.OAMethodLib;
  2. using OASystem.Domain.Dtos.Resource;
  3. using System.Collections.Generic;
  4. namespace OASystem.API.Controllers
  5. {
  6. /// <summary>
  7. /// 资料相关
  8. /// </summary>
  9. //[Authorize]
  10. [Route("api/[controller]/[action]")]
  11. public class ResourceController : ControllerBase
  12. {
  13. private readonly IMapper _mapper;
  14. private readonly IConfiguration _config;
  15. private readonly CarDataRepository _carDataRep;
  16. private readonly LocalGuideDataRepository _localGuideDataRep;
  17. private readonly ThreeCodeRepository _ThreeCodeRep;
  18. private readonly HotelDataRepository _hotelDataRep;
  19. private readonly ResItemInfoRepository _resItemInfoRep;
  20. private readonly SetDataRepository _setDataRepository;
  21. private readonly CountryFeeRepository _countryFeeRep;
  22. private readonly SetDataTypeRepository _setDataTypeRep;
  23. private readonly AirTicketAgentRepository _airTicketAgentRep;
  24. public ResourceController(IMapper mapper, IConfiguration config, CarDataRepository carDataRep,
  25. LocalGuideDataRepository localGuideDataRep, ThreeCodeRepository threeCodeRep,
  26. HotelDataRepository hotelDataRep, ResItemInfoRepository resItemInfoRep, SetDataRepository setDataRepository,
  27. CountryFeeRepository countryFeeRep, SetDataTypeRepository setDataTypeRep, AirTicketAgentRepository airTicketAgentRep)
  28. {
  29. _mapper = mapper;
  30. _config = config;
  31. _carDataRep = carDataRep;
  32. _localGuideDataRep = localGuideDataRep;
  33. _ThreeCodeRep = threeCodeRep;
  34. _hotelDataRep = hotelDataRep;
  35. _resItemInfoRep = resItemInfoRep;
  36. _setDataRepository = setDataRepository;
  37. _countryFeeRep = countryFeeRep;
  38. _setDataTypeRep = setDataTypeRep;
  39. _airTicketAgentRep = airTicketAgentRep;
  40. }
  41. #region 车公司资料板块
  42. /// <summary>
  43. /// 车公司信息查询
  44. /// </summary>
  45. /// <returns></returns>
  46. [HttpPost]
  47. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  48. public async Task<IActionResult> QueryCarData(QueryCarDataDto dto)
  49. {
  50. try
  51. {
  52. Result LocalGuide = await _carDataRep.QueryCarData(dto);
  53. if (LocalGuide.Code == 0)
  54. {
  55. return Ok(JsonView(true, "查询成功", LocalGuide.Data));
  56. }
  57. else
  58. {
  59. return Ok(JsonView(false, LocalGuide.Msg));
  60. }
  61. }
  62. catch (Exception)
  63. {
  64. return Ok(JsonView(false, "程序错误!"));
  65. throw;
  66. }
  67. }
  68. /// <summary>
  69. /// 车公司资料下拉框数据
  70. /// </summary>
  71. /// <returns></returns>
  72. [HttpPost]
  73. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  74. public async Task<IActionResult> QueryCarSelect()
  75. {
  76. try
  77. {
  78. var CarData = _carDataRep.QueryDto<Res_CarData, CarDataSelectView>().ToList();
  79. if (CarData.Count == 0)
  80. {
  81. return Ok(JsonView(false, "暂无数据!"));
  82. }
  83. CarData.Add(new CarDataSelectView { Id = 0, UnitArea = "全部" });
  84. CarData = CarData.Where((x, i) => CarData.FindIndex(z => z.UnitArea == x.UnitArea) == i).ToList();
  85. CarData = CarData.OrderBy(x => x.Id).ToList();
  86. List<CarDataSelectView> data = new List<CarDataSelectView>();
  87. foreach (CarDataSelectView car in CarData)
  88. {
  89. if (!string.IsNullOrWhiteSpace(car.UnitArea))
  90. {
  91. data.Add(car);
  92. }
  93. }
  94. return Ok(JsonView(true, "查询成功", data));
  95. }
  96. catch (Exception)
  97. {
  98. return Ok(JsonView(false, "程序错误!"));
  99. throw;
  100. }
  101. }
  102. /// <summary>
  103. /// 车公司信息添加
  104. /// </summary>
  105. /// <returns></returns>
  106. [HttpPost]
  107. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  108. public async Task<IActionResult> AddCarData(AddCarDataDto dto)
  109. {
  110. try
  111. {
  112. if (dto.UnitArea == "")
  113. {
  114. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  115. }
  116. if (dto.UnitName == "")
  117. {
  118. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  119. }
  120. if (dto.Contact == "")
  121. {
  122. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  123. }
  124. if (dto.ContactTel == "")
  125. {
  126. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  127. }
  128. var carDada = _carDataRep.QueryDto<Res_CarData, CarDataView>(a => a.UnitArea == dto.UnitArea && a.UnitName == dto.UnitName && a.Contact == dto.Contact && a.ContactTel == dto.ContactTel).ToList();
  129. if (carDada.Count != 0)
  130. {
  131. return Ok(JsonView(false, "该信息已存在,请勿重复添加!"));
  132. }
  133. Res_CarData _CarData = _mapper.Map<Res_CarData>(dto);
  134. int id = await _carDataRep.AddAsyncReturnId(_CarData);
  135. if (id == 0)
  136. {
  137. return Ok(JsonView(false, "添加失败!"));
  138. }
  139. return Ok(JsonView(true, "添加成功", new { Id = id }));
  140. }
  141. catch (Exception ex)
  142. {
  143. return Ok(JsonView(false, "程序错误!"));
  144. throw;
  145. }
  146. }
  147. /// <summary>
  148. /// 车公司信息修改
  149. /// </summary>
  150. /// <returns></returns>
  151. [HttpPost]
  152. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  153. public async Task<IActionResult> UpCarData(UpCarDataDto dto)
  154. {
  155. try
  156. {
  157. if (dto.UnitArea == "")
  158. {
  159. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  160. }
  161. if (dto.UnitName == "")
  162. {
  163. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  164. }
  165. if (dto.Contact == "")
  166. {
  167. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  168. }
  169. if (dto.ContactTel == "")
  170. {
  171. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  172. }
  173. bool res = await _carDataRep.UpdateAsync(a => a.Id == dto.Id, a => new Res_CarData
  174. {
  175. UnitArea = dto.UnitArea,
  176. UnitName = dto.UnitName,
  177. Address = dto.Address,
  178. Contact = dto.Contact,
  179. ContactTel = dto.ContactTel,
  180. ContactEmail = dto.ContactEmail,
  181. ContactFax = dto.ContactFax,
  182. CarDes = dto.CarDes,
  183. CarPicPaths = dto.CarPicPaths,
  184. OtherInfo = dto.OtherInfo,
  185. Score = dto.Score,
  186. QualificationScore = dto.QualificationScore,
  187. CarAgeScore = dto.CarAgeScore,
  188. CleanImgScore = dto.CleanImgScore,
  189. SmellScore = dto.SmellScore,
  190. WaterPaperScore = dto.WaterPaperScore,
  191. HardwareScore = dto.HardwareScore,
  192. TimeScore = dto.TimeScore,
  193. SafetyScore = dto.SafetyScore,
  194. DrivingAgeScore = dto.DrivingAgeScore,
  195. Remark = dto.Remark,
  196. });
  197. if (!res) { return Ok(JsonView(false, "修改失败!")); }
  198. return Ok(JsonView(true, "修改成功"));
  199. }
  200. catch (Exception ex)
  201. {
  202. return Ok(JsonView(false, "程序错误!"));
  203. throw;
  204. }
  205. }
  206. /// <summary>
  207. /// 车公司信息删除
  208. /// </summary>
  209. /// <returns></returns>
  210. [HttpPost]
  211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  212. public async Task<IActionResult> DelCarData(DelCarDataDto dto)
  213. {
  214. try
  215. {
  216. bool res = await _carDataRep.SoftDeleteByIdAsync<Res_CarData>(dto.Id.ToString(), dto.DeleteUserId);
  217. if (!res) { return Ok(JsonView(false, "删除失败!")); }
  218. return Ok(JsonView(true, "删除成功"));
  219. }
  220. catch (Exception ex)
  221. {
  222. return Ok(JsonView(false, "程序错误!"));
  223. throw;
  224. }
  225. }
  226. #endregion
  227. #region 导游地接资料板块
  228. /// <summary>
  229. /// 导游地接资料查询
  230. /// </summary>
  231. /// <param name="dto"></param>
  232. /// <returns></returns>
  233. [HttpPost]
  234. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  235. public async Task<IActionResult> QueryLocalGuide(QueryLocalGuide dto)
  236. {
  237. try
  238. {
  239. Result LocalGuide = await _localGuideDataRep.QueryLocalGuide(dto);
  240. if (LocalGuide.Code == 0)
  241. {
  242. return Ok(JsonView(true, "查询成功", LocalGuide.Data));
  243. }
  244. else
  245. {
  246. return Ok(JsonView(false, LocalGuide.Msg));
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. return Ok(JsonView(false, "程序错误!"));
  252. throw;
  253. }
  254. }
  255. /// <summary>
  256. /// 导游地接资料下拉框数据
  257. /// </summary>
  258. /// <returns></returns>
  259. [HttpPost]
  260. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  261. public async Task<IActionResult> QueryLocalGuideSelect()
  262. {
  263. try
  264. {
  265. var LocalGuide = _carDataRep.QueryDto<Res_LocalGuideData, QueryLocalGuideSelectView>().ToList();
  266. if (LocalGuide.Count == 0)
  267. {
  268. return Ok(JsonView(false, "暂无数据!"));
  269. }
  270. LocalGuide.Add(new QueryLocalGuideSelectView { Id = 0, UnitArea = "全部" });
  271. LocalGuide = LocalGuide.Where((x, i) => LocalGuide.FindIndex(z => z.UnitArea == x.UnitArea && z.UnitArea != "") == i).ToList();
  272. LocalGuide = LocalGuide.OrderBy(x => x.Id).ToList();
  273. List<QueryLocalGuideSelectView> data = new List<QueryLocalGuideSelectView>();
  274. foreach (QueryLocalGuideSelectView Local in LocalGuide)
  275. {
  276. if (!string.IsNullOrWhiteSpace(Local.UnitArea))
  277. {
  278. data.Add(Local);
  279. }
  280. }
  281. return Ok(JsonView(true, "查询成功", data));
  282. }
  283. catch (Exception)
  284. {
  285. return Ok(JsonView(false, "程序错误!"));
  286. throw;
  287. }
  288. }
  289. /// <summary>
  290. /// 导游地接信息操作(Status:1.新增,2.修改)
  291. /// </summary>
  292. /// <returns></returns>
  293. [HttpPost]
  294. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  295. public async Task<IActionResult> OperationLocalGuide(LocalGuideOperationDto dto)
  296. {
  297. try
  298. {
  299. if (dto.UnitArea == "")
  300. {
  301. return Ok(JsonView(false, "请检查单位区域是否填写!"));
  302. }
  303. if (dto.UnitName == "")
  304. {
  305. return Ok(JsonView(false, "请检查单位名称是否填写!"));
  306. }
  307. if (dto.Contact == "")
  308. {
  309. return Ok(JsonView(false, "请检查单位联系人是否填写!"));
  310. }
  311. if (dto.ContactTel == "")
  312. {
  313. return Ok(JsonView(false, "请检查联系方式是否填写正确!"));
  314. }
  315. Result result = await _localGuideDataRep.LocalGuideOperation(dto);
  316. if (result.Code != 0)
  317. {
  318. return Ok(JsonView(false, result.Msg));
  319. }
  320. return Ok(JsonView(true, result.Msg));
  321. }
  322. catch (Exception ex)
  323. {
  324. return Ok(JsonView(false, "程序错误!"));
  325. throw;
  326. }
  327. }
  328. /// <summary>
  329. /// 导游地接信息操作(删除)
  330. /// </summary>
  331. /// <returns></returns>
  332. [HttpPost]
  333. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  334. public async Task<IActionResult> DelLocalGuide(LocalGuideDelDto dto)
  335. {
  336. try
  337. {
  338. var res = await _localGuideDataRep.SoftDeleteByIdAsync<Res_LocalGuideData>(dto.Id.ToString(), dto.DeleteUserId);
  339. if (!res)
  340. {
  341. return Ok(JsonView(false, "删除失败"));
  342. }
  343. return Ok(JsonView(true, "删除成功!"));
  344. }
  345. catch (Exception ex)
  346. {
  347. return Ok(JsonView(false, "程序错误!"));
  348. throw;
  349. }
  350. }
  351. #endregion
  352. #region 机场三字码信息
  353. /// <summary>
  354. /// 机场三字码查询
  355. /// </summary>
  356. /// <param name="dto"></param>
  357. /// <returns></returns>
  358. [HttpPost]
  359. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  360. public async Task<IActionResult> QueryThreeCode(QueryThreeCodeDto dto)
  361. {
  362. try
  363. {
  364. Result LocalGuide = await _ThreeCodeRep.QueryThreeCode(dto);
  365. if (LocalGuide.Code == 0)
  366. {
  367. return Ok(JsonView(true, "查询成功", LocalGuide.Data));
  368. }
  369. else
  370. {
  371. return Ok(JsonView(false, LocalGuide.Msg));
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. return Ok(JsonView(false, "程序错误!"));
  377. throw;
  378. }
  379. }
  380. /// <summary>
  381. /// 机场三字码数据城市下拉框数据
  382. /// </summary>
  383. /// <returns></returns>
  384. [HttpPost]
  385. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  386. public async Task<IActionResult> QueryThreeCodeSelect()
  387. {
  388. try
  389. {
  390. var ThreeCode = _carDataRep.QueryDto<Res_ThreeCode, ThreeCodeSelectView>().ToList();
  391. if (ThreeCode.Count == 0)
  392. {
  393. return Ok(JsonView(false, "暂无数据!"));
  394. }
  395. ThreeCode.Add(new ThreeCodeSelectView { Id = 0, City = "全部" });
  396. ThreeCode = ThreeCode.Where((x, i) => ThreeCode.FindIndex(z => z.City == x.City && z.City != "") == i).ToList();
  397. ThreeCode = ThreeCode.OrderBy(x => x.Id).ToList();
  398. List<ThreeCodeSelectView> data = new List<ThreeCodeSelectView>();
  399. foreach (ThreeCodeSelectView _ThreeCode in ThreeCode)
  400. {
  401. if (!string.IsNullOrWhiteSpace(_ThreeCode.City))
  402. {
  403. data.Add(_ThreeCode);
  404. }
  405. }
  406. return Ok(JsonView(true, "查询成功", data));
  407. }
  408. catch (Exception)
  409. {
  410. return Ok(JsonView(false, "程序错误!"));
  411. throw;
  412. }
  413. }
  414. /// <summary>
  415. /// 机场三字码资料操作(Status:1.新增,2.修改)
  416. /// </summary>
  417. /// <param name="dto"></param>
  418. /// <returns></returns>
  419. [HttpPost]
  420. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  421. public async Task<IActionResult> OperationThreeCode(ThreeCodeOperationDto dto)
  422. {
  423. try
  424. {
  425. if (dto.Three == "")
  426. {
  427. return Ok(JsonView(false, "请检查三字码是否填写!"));
  428. }
  429. if (dto.Country == "")
  430. {
  431. return Ok(JsonView(false, "请检查国家是否填写!"));
  432. }
  433. if (dto.City == "")
  434. {
  435. return Ok(JsonView(false, "请检查城市是否填写正确!"));
  436. }
  437. if (dto.AirPort == "")
  438. {
  439. return Ok(JsonView(false, "请检查机场是否填写正确!"));
  440. }
  441. Result result = await _ThreeCodeRep.ThreeCodeOperation(dto);
  442. if (result.Code != 0)
  443. {
  444. return Ok(JsonView(false, result.Msg));
  445. }
  446. return Ok(JsonView(true, result.Msg));
  447. }
  448. catch (Exception ex)
  449. {
  450. return Ok(JsonView(false, "程序错误!"));
  451. throw;
  452. }
  453. }
  454. /// <summary>
  455. /// 机场三字码资料操作(删除)
  456. /// </summary>
  457. /// <returns></returns>
  458. [HttpPost]
  459. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  460. public async Task<IActionResult> DelThreeCode(ThreeCodeDelDto dto)
  461. {
  462. try
  463. {
  464. var res = await _ThreeCodeRep.SoftDeleteByIdAsync<Res_ThreeCode>(dto.Id.ToString(), dto.DeleteUserId);
  465. if (!res)
  466. {
  467. return Ok(JsonView(false, "删除失败"));
  468. }
  469. return Ok(JsonView(true, "删除成功!"));
  470. }
  471. catch (Exception ex)
  472. {
  473. return Ok(JsonView(false, "程序错误!"));
  474. throw;
  475. }
  476. }
  477. #endregion
  478. #region 代理出票合作方资料
  479. /// <summary>
  480. /// 代理出票合作方资料
  481. /// </summary>
  482. /// <param name="dto"></param>
  483. /// <returns></returns>
  484. [HttpPost]
  485. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  486. public async Task<IActionResult> QueryAirTicketAgent(DtoBase dto)
  487. {
  488. try
  489. {
  490. List<Res_AirTicketAgent> res_AirTicketAgents = _airTicketAgentRep.Query<Res_AirTicketAgent>(a => a.IsDel == 0).ToList();
  491. if (res_AirTicketAgents.Count != 0)
  492. {
  493. res_AirTicketAgents = res_AirTicketAgents.OrderByDescending(a => a.CreateTime).ToList();
  494. if (dto.PageSize == 0 && dto.PageIndex == 0)
  495. {
  496. return Ok(JsonView(true, "查询成功!", res_AirTicketAgents));
  497. }
  498. else
  499. {
  500. int count = res_AirTicketAgents.Count;
  501. float totalPage = (float)count / dto.PageSize;//总页数
  502. if (totalPage == 0) totalPage = 1;
  503. else totalPage = (int)Math.Ceiling((double)totalPage);
  504. List<Res_AirTicketAgent> _AirTicketAgent = new List<Res_AirTicketAgent>();
  505. for (int i = 0; i < dto.PageSize; i++)
  506. {
  507. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  508. if (RowIndex < res_AirTicketAgents.Count)
  509. {
  510. _AirTicketAgent.Add(res_AirTicketAgents[RowIndex]);
  511. }
  512. else
  513. {
  514. break;
  515. }
  516. }
  517. return Ok(JsonView(true, "查询成功!",new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = _AirTicketAgent }));
  518. }
  519. }
  520. else
  521. {
  522. return Ok(JsonView(false, "暂无数据!"));
  523. }
  524. }
  525. catch (Exception ex)
  526. {
  527. return Ok(JsonView(false, "程序错误!"));
  528. throw;
  529. }
  530. }
  531. /// <summary>
  532. /// 代理出票合作方资料操作(Status:1.新增,2.修改)
  533. /// </summary>
  534. /// <param name="dto"></param>
  535. /// <returns></returns>
  536. [HttpPost]
  537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  538. public async Task<IActionResult> OpAirTicketAgent(OpAirTicketAgentDto dto)
  539. {
  540. try
  541. {
  542. if (dto.Account == "")
  543. {
  544. return Ok(JsonView(false, "请检查代理商账户是否填写!"));
  545. }
  546. if (dto.Bank == "")
  547. {
  548. return Ok(JsonView(false, "请检查代理商银行是否填写!"));
  549. }
  550. if (dto.Name == "")
  551. {
  552. return Ok(JsonView(false, "请检查代理商名称是否填写正确!"));
  553. }
  554. Result result = await _airTicketAgentRep.OpAirTicketAgent(dto);
  555. if (result.Code != 0)
  556. {
  557. return Ok(JsonView(false, result.Msg));
  558. }
  559. return Ok(JsonView(true, result.Msg));
  560. }
  561. catch (Exception ex)
  562. {
  563. return Ok(JsonView(false, "程序错误!"));
  564. throw;
  565. }
  566. }
  567. /// <summary>
  568. /// 代理出票合作方资料操作(删除)
  569. /// </summary>
  570. /// <returns></returns>
  571. [HttpPost]
  572. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  573. public async Task<IActionResult> DelAirTicketAgent(DelBaseDto dto)
  574. {
  575. try
  576. {
  577. var res = await _airTicketAgentRep.SoftDeleteByIdAsync<Res_AirTicketAgent>(dto.Id.ToString(), dto.DeleteUserId);
  578. if (!res)
  579. {
  580. return Ok(JsonView(false, "删除失败"));
  581. }
  582. return Ok(JsonView(true, "删除成功!"));
  583. }
  584. catch (Exception ex)
  585. {
  586. return Ok(JsonView(false, "程序错误!"));
  587. throw;
  588. }
  589. }
  590. #endregion
  591. #region 酒店资料数据
  592. /// <summary>
  593. /// 酒店信息查询
  594. /// </summary>
  595. /// <param name="dto"></param>
  596. /// <returns></returns>
  597. [HttpPost]
  598. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  599. public async Task<IActionResult> QueryHotelData(QueryHotelDataDto dto)
  600. {
  601. try
  602. {
  603. Result hotelData = await _hotelDataRep.QueryHotelData(dto);
  604. if (hotelData.Code == 0)
  605. {
  606. return Ok(JsonView(true, "查询成功", hotelData.Data));
  607. }
  608. else
  609. {
  610. return Ok(JsonView(false, hotelData.Msg));
  611. }
  612. }
  613. catch (Exception ex)
  614. {
  615. return Ok(JsonView(false, "程序错误!"));
  616. throw;
  617. }
  618. }
  619. /// <summary>
  620. /// 酒店资料下拉框数据
  621. /// </summary>
  622. /// <returns></returns>
  623. [HttpPost]
  624. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  625. public async Task<IActionResult> QueryHotelDataSelect()
  626. {
  627. try
  628. {
  629. var HotelData = _carDataRep.QueryDto<Res_HotelData, QueryHotelDataSelect>().ToList();
  630. if (HotelData.Count == 0)
  631. {
  632. return Ok(JsonView(false, "暂无数据!"));
  633. }
  634. HotelData.Add(new QueryHotelDataSelect { Id = 0, City = "全部" });
  635. HotelData = HotelData.Where((x, i) => HotelData.FindIndex(z => z.City == x.City && z.City != "") == i).ToList();
  636. HotelData = HotelData.OrderBy(x => x.Id).ToList();
  637. List<QueryHotelDataSelect> data = new List<QueryHotelDataSelect>();
  638. foreach (QueryHotelDataSelect Hotel in HotelData)
  639. {
  640. if (!string.IsNullOrWhiteSpace(Hotel.City))
  641. {
  642. data.Add(Hotel);
  643. }
  644. }
  645. return Ok(JsonView(true, "查询成功", data));
  646. }
  647. catch (Exception)
  648. {
  649. return Ok(JsonView(false, "程序错误!"));
  650. throw;
  651. }
  652. }
  653. /// <summary>
  654. /// 酒店资料操作(Status:1.新增,2.修改)
  655. /// </summary>
  656. /// <param name="dto"></param>
  657. /// <returns></returns>
  658. [HttpPost]
  659. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  660. public async Task<IActionResult> OperationHotelData(OperationHotelDto dto)
  661. {
  662. try
  663. {
  664. if (dto.City == "")
  665. {
  666. return Ok(JsonView(false, "请检查酒店所在城市是否填写!"));
  667. }
  668. if (dto.Name == "")
  669. {
  670. return Ok(JsonView(false, "请检查酒店名称是否填写!"));
  671. }
  672. if (dto.Address == "")
  673. {
  674. return Ok(JsonView(false, "请检查酒店地址是否填写正确!"));
  675. }
  676. if (dto.Tel == "")
  677. {
  678. return Ok(JsonView(false, "请检查酒店联系方式是否填写正确!"));
  679. }
  680. Result result = await _hotelDataRep.OperationHotelData(dto);
  681. if (result.Code != 0)
  682. {
  683. return Ok(JsonView(false, result.Msg));
  684. }
  685. return Ok(JsonView(true, result.Msg));
  686. }
  687. catch (Exception ex)
  688. {
  689. return Ok(JsonView(false, "程序错误!"));
  690. throw;
  691. }
  692. }
  693. /// <summary>
  694. /// 酒店资料操作(删除)
  695. /// </summary>
  696. /// <returns></returns>
  697. [HttpPost]
  698. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  699. public async Task<IActionResult> DelHotelData(DelHotelDataDto dto)
  700. {
  701. try
  702. {
  703. var res = await _hotelDataRep.SoftDeleteByIdAsync<Res_HotelData>(dto.Id.ToString(), dto.DeleteUserId);
  704. if (!res)
  705. {
  706. return Ok(JsonView(false, "删除失败"));
  707. }
  708. return Ok(JsonView(true, "删除成功!"));
  709. }
  710. catch (Exception ex)
  711. {
  712. return Ok(JsonView(false, "程序错误!"));
  713. throw;
  714. }
  715. }
  716. #endregion
  717. #region 签证费用资料
  718. /// <summary>
  719. /// 签证费用资料查询
  720. /// </summary>
  721. /// <param name="dto"></param>
  722. /// <returns></returns>
  723. [HttpPost]
  724. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  725. public async Task<IActionResult> QueryCountryFeeCost(DtoBase dto)
  726. {
  727. try
  728. {
  729. if (dto.PortType == 1)
  730. {
  731. var CountryFee = _countryFeeRep.QueryDto<Res_CountryFeeCost, CountryFeeCostView>().ToList();
  732. if (CountryFee.Count == 0)
  733. {
  734. return Ok(JsonView(false, "暂无数据!"));
  735. }
  736. CountryFee = CountryFee.OrderByDescending(s => s.CreateTime).ToList();
  737. return Ok(JsonView(true, "查询成功", CountryFee));
  738. }
  739. else if (dto.PortType == 2)
  740. {
  741. var CountryFee = _countryFeeRep.QueryDto<Res_CountryFeeCost, CountryFeeCostView>().ToList();
  742. if (CountryFee.Count == 0)
  743. {
  744. return Ok(JsonView(false, "暂无数据!"));
  745. }
  746. CountryFee = CountryFee.OrderByDescending(s => s.CreateTime).ToList();
  747. return Ok(JsonView(true, "查询成功", CountryFee));
  748. }
  749. else
  750. {
  751. return Ok(JsonView(false, "请传入PortType参数!1:Web,2:Android,3:IOS"));
  752. }
  753. }
  754. catch (Exception ex)
  755. {
  756. return Ok(JsonView(false, "程序错误!"));
  757. throw;
  758. }
  759. }
  760. /// <summary>
  761. /// 签证费用资料操作(Status:1.新增,2.修改)
  762. /// </summary>
  763. /// <param name="dto"></param>
  764. /// <returns></returns>
  765. [HttpPost]
  766. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  767. public async Task<IActionResult> OperationCountryFeeCost(OperationCountryFeeCostDto dto)
  768. {
  769. try
  770. {
  771. if (dto.VisaContinent == "")
  772. {
  773. return Ok(JsonView(false, "请检查州名是否填写!"));
  774. }
  775. if (dto.VisaCountry == "")
  776. {
  777. return Ok(JsonView(false, "请检查国家名是否填写!"));
  778. }
  779. if (dto.VisaTime == "1")
  780. {
  781. return Ok(JsonView(false, "请检一般签证时间是否填写正确!"));
  782. }
  783. if (dto.UrgentTime == "1")
  784. {
  785. return Ok(JsonView(false, "请检加急时间是否填写正确!"));
  786. }
  787. if (dto.VisaPrice == 0)
  788. {
  789. return Ok(JsonView(false, "请检查签证费用是否填写正确,小数点后可1到2位!"));
  790. }
  791. if (dto.VisaPrice == 1)
  792. {
  793. return Ok(JsonView(false, "请检查签证加急费用是否填写正确,小数点后可1到2位!"));
  794. }
  795. Result result = await _countryFeeRep.OperationCountryFeeCost(dto);
  796. if (result.Code != 0)
  797. {
  798. return Ok(JsonView(false, result.Msg));
  799. }
  800. return Ok(JsonView(true, result.Msg));
  801. }
  802. catch (Exception ex)
  803. {
  804. return Ok(JsonView(false, "程序错误!"));
  805. throw;
  806. }
  807. }
  808. /// <summary>
  809. /// 签证费用资料操作(删除)
  810. /// </summary>
  811. /// <returns></returns>
  812. [HttpPost]
  813. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  814. public async Task<IActionResult> DelCountryFeeCost(DelCountryFeeCostDto dto)
  815. {
  816. try
  817. {
  818. var res = await _countryFeeRep.SoftDeleteByIdAsync<Res_CountryFeeCost>(dto.Id.ToString(), dto.DeleteUserId);
  819. if (!res)
  820. {
  821. return Ok(JsonView(false, "删除失败"));
  822. }
  823. return Ok(JsonView(true, "删除成功!"));
  824. }
  825. catch (Exception ex)
  826. {
  827. return Ok(JsonView(false, "程序错误!"));
  828. throw;
  829. }
  830. }
  831. #endregion
  832. #region 物料信息、供应商维护
  833. #region 供应商
  834. /// <summary>
  835. /// 物料供应商查询
  836. /// </summary>
  837. /// <param name="paras">Json序列化</param>
  838. /// <returns></returns>
  839. [HttpPost]
  840. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  841. public async Task<IActionResult> PostSearchItemVendor(JsonDtoBase _jsonDto)
  842. {
  843. if (string.IsNullOrEmpty(_jsonDto.Paras))
  844. {
  845. return Ok(JsonView(false, "参数为空"));
  846. }
  847. Search_ResItemVendorDto _ItemVendorDto = System.Text.Json.JsonSerializer.Deserialize<Search_ResItemVendorDto>(_jsonDto.Paras);
  848. if (_ItemVendorDto != null)
  849. {
  850. if (_ItemVendorDto.SearchType == 2) //获取列表
  851. {
  852. Res_ItemVendorListView rstList = _resItemInfoRep.GetVendorList(_ItemVendorDto);
  853. return Ok(rstList);
  854. }
  855. else
  856. {
  857. Res_ItemVendorView rstInfo = _resItemInfoRep.getVendorInfo(_ItemVendorDto);
  858. return Ok(rstInfo);
  859. }
  860. }
  861. else
  862. {
  863. return Ok(JsonView(false, "参数反序列化失败"));
  864. }
  865. return Ok(JsonView(false));
  866. }
  867. /// <summary>
  868. /// 创建/编辑/删除供应商信息
  869. /// </summary>
  870. /// <param name="_dto"></param>
  871. /// <returns></returns>
  872. [HttpPost]
  873. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  874. public async Task<IActionResult> PostEditItemVendor(Edit_ResItemVendorDto _dto)
  875. {
  876. bool rst = false;
  877. if (_dto.EditType >= 0)
  878. {
  879. if (string.IsNullOrEmpty(_dto.VendorFullName))
  880. {
  881. return Ok(JsonView(false, "全称未填写"));
  882. }
  883. if (string.IsNullOrEmpty(_dto.VendorLinker))
  884. {
  885. return Ok(JsonView(false, "联系人未填写"));
  886. }
  887. if (string.IsNullOrEmpty(_dto.VendorMobile))
  888. {
  889. return Ok(JsonView(false, "联系人手机号未填写"));
  890. }
  891. if (string.IsNullOrEmpty(_dto.BusRange))
  892. {
  893. return Ok(JsonView(false, "经营范围未选择"));
  894. }
  895. if (_dto.EditType == 0)
  896. {
  897. var checkEmpty = _resItemInfoRep.Query<Res_ItemVendor>(s => s.FullName == _dto.VendorFullName).First();
  898. if (checkEmpty != null)
  899. {
  900. return Ok(JsonView(false, "已存在同名供应商"));
  901. }
  902. rst = await _resItemInfoRep.addVendorInfo(_dto);
  903. }
  904. else if (_dto.EditType == 1)
  905. {
  906. if (_dto.VendorId > 0)
  907. {
  908. Res_ItemVendor _entity = _mapper.Map<Res_ItemVendor>(_dto);
  909. rst = await _resItemInfoRep.updVendorInfo(_entity);
  910. }
  911. else
  912. {
  913. return Ok(JsonView(false, "供应商不存在"));
  914. }
  915. }
  916. }
  917. else
  918. {
  919. if (_dto.VendorId < 1 || _dto.SysUserId < 1)
  920. {
  921. return Ok(JsonView(false, "用户Id或供应商Id不存在"));
  922. }
  923. Res_ItemVendor _entity = _mapper.Map<Res_ItemVendor>(_dto);
  924. rst = await _resItemInfoRep.delVendorInfo(_entity);
  925. }
  926. return Ok(JsonView(rst));
  927. }
  928. #endregion
  929. #region 物料信息
  930. /// <summary>
  931. /// 物料信息查询
  932. /// </summary>
  933. /// <param name="paras">Json序列化</param>
  934. /// <returns></returns>
  935. [HttpPost]
  936. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  937. public async Task<IActionResult> PostSearchItemInfo(string paras)
  938. {
  939. if (string.IsNullOrEmpty(paras))
  940. {
  941. return Ok(JsonView(false, "参数为空"));
  942. }
  943. Search_ItemInfoDto _ItemInfoDto = System.Text.Json.JsonSerializer.Deserialize<Search_ItemInfoDto>(paras);
  944. if (_ItemInfoDto != null)
  945. {
  946. if (_ItemInfoDto.SearchType == 2) //获取列表
  947. {
  948. Res_ItemInfoListView rstList = _resItemInfoRep.GetItemList(_ItemInfoDto);
  949. return Ok(rstList);
  950. }
  951. else
  952. {
  953. Res_ItemInfoView rstInfo = _resItemInfoRep.getItemInfo(_ItemInfoDto);
  954. return Ok(rstInfo);
  955. }
  956. }
  957. else
  958. {
  959. return Ok(JsonView(false, "参数反序列化失败"));
  960. }
  961. return Ok(JsonView(false));
  962. }
  963. /// <summary>
  964. /// 创建/编辑/删除物料信息
  965. /// </summary>
  966. ///
  967. /// <returns></returns>
  968. [HttpPost]
  969. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  970. public async Task<IActionResult> PostEditItemInfo(Edit_ResItemInfoDto _dto)
  971. {
  972. bool rst = false;
  973. if (_dto.EditType >= 0)
  974. {
  975. if (_dto.VendorId < 1)
  976. {
  977. return Ok(JsonView(false, "未选择供应商"));
  978. }
  979. if (string.IsNullOrEmpty(_dto.ItemName))
  980. {
  981. return Ok(JsonView(false, "物料名称为空"));
  982. }
  983. if (_dto.ItemTypeId < 1)
  984. {
  985. return Ok(JsonView(false, "未选择物料类型"));
  986. }
  987. if (_dto.SysUserId < 1)
  988. {
  989. return Ok(JsonView(false, "当前操作用户Id为空"));
  990. }
  991. if (_dto.CurrRate <= 0)
  992. {
  993. return Ok(JsonView(false, "物料录入价格不能小于等于0"));
  994. }
  995. if (_dto.EditType == 0)
  996. {
  997. //判断物料名称、类型、供应商全部重复
  998. var checkEmpty = _resItemInfoRep.Query<Res_ItemDetailInfo>(s => s.ItemName == _dto.ItemName && s.ItemTypeId == _dto.ItemTypeId && s.VendorId == _dto.VendorId).First();
  999. if (checkEmpty != null)
  1000. {
  1001. return Ok(JsonView(false, "已存在重复物料信息"));
  1002. }
  1003. Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
  1004. DateTime dtNow = DateTime.Now;
  1005. _entity.CreateUserId = _dto.SysUserId;
  1006. _entity.IsDel = 0;
  1007. _entity.MaxRate = _dto.CurrRate;
  1008. _entity.MaxDt = dtNow;
  1009. _entity.CurrRate = _dto.CurrRate;
  1010. _entity.CurrDt = dtNow;
  1011. _entity.MinRate = _dto.CurrRate;
  1012. _entity.MinDt = dtNow;
  1013. rst = await _resItemInfoRep.AddAsync<Res_ItemDetailInfo>(_entity) > 0;
  1014. }
  1015. else if (_dto.EditType == 1)
  1016. {
  1017. if (_dto.ItemId > 0)
  1018. {
  1019. Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
  1020. _entity.Id = _dto.ItemId;
  1021. rst = await _resItemInfoRep.updItemInfo(_entity);
  1022. }
  1023. else
  1024. {
  1025. return Ok(JsonView(false, "供应商不存在"));
  1026. }
  1027. }
  1028. }
  1029. else
  1030. {
  1031. if (_dto.ItemId < 1 || _dto.SysUserId < 1)
  1032. {
  1033. return Ok(JsonView(false, "用户Id或物料信息Id不存在"));
  1034. }
  1035. Res_ItemDetailInfo _entity = _mapper.Map<Res_ItemDetailInfo>(_dto);
  1036. rst = await _resItemInfoRep.delItemInfo(_entity);
  1037. }
  1038. return Ok(JsonView(rst));
  1039. }
  1040. #endregion
  1041. #region 物料类型获取
  1042. #endregion
  1043. #endregion
  1044. #region 备忘录
  1045. /// <summary>
  1046. /// 备忘录查询
  1047. /// </summary>
  1048. /// <param name="paras">Json序列化</param>
  1049. /// <returns></returns>
  1050. [HttpPost]
  1051. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1052. public async Task<IActionResult> PostSearchMemo(JsonDtoBase _jsonDto)
  1053. {
  1054. if (string.IsNullOrEmpty(_jsonDto.Paras))
  1055. {
  1056. return Ok(JsonView(false, "参数为空"));
  1057. }
  1058. Search_ResMemoDto _memoDto = JsonConvert.DeserializeObject<Search_ResMemoDto>(_jsonDto.Paras);
  1059. if (_memoDto != null)
  1060. {
  1061. if (_memoDto.SearchType == 2)
  1062. {
  1063. //获取列表
  1064. string sqlWhere = string.Format(" Where IsDel=0 ");
  1065. #region SqlWhere
  1066. if (!string.IsNullOrEmpty(_memoDto.Abstracts))
  1067. {
  1068. sqlWhere += string.Format(@" And m.Abstracts Like '%{0}%' ", _memoDto.Abstracts);
  1069. }
  1070. if (!string.IsNullOrEmpty(_memoDto.Title))
  1071. {
  1072. sqlWhere += string.Format(@" And m.Title Like '%{0}%' ", _memoDto.Title);
  1073. }
  1074. if (_memoDto.ReadLevel > 0)
  1075. {
  1076. sqlWhere += string.Format(@" And m.ReadLevel = {0} ", _memoDto.ReadLevel);
  1077. }
  1078. #endregion
  1079. int currPIndex = (((_memoDto.PageIndex > 0) ? (_memoDto.PageIndex - 1) : 0) * _memoDto.PageSize) + 1;
  1080. int currPSize = (((_memoDto.PageIndex > 0) ? (_memoDto.PageIndex - 1) : 0) + 1) * _memoDto.PageSize;
  1081. string sql = string.Format(@" Select * From(Select ROW_NUMBER() Over(order By m.Id desc) as RowNumber,
  1082. m.Id as MemoId,d.DepName as DepartmentName,m.ReadLevel,m.Title,m.Abstracts,
  1083. m.LastedEditDt,m.LastedEditorId
  1084. From Res_Memo as m With(Nolock) Inner Join Sys_Users as u With(Nolock) On m.CreateUserId=u.Id
  1085. Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id {2}
  1086. ) as tb Where tb.RowNumber Between {0} And {1} ", currPIndex, currPSize, sqlWhere);
  1087. Res_MemoListView rst = new Res_MemoListView();
  1088. rst.CurrPageIndex = currPIndex;
  1089. rst.CurrPageSize = currPSize;
  1090. List<Res_MemoView> dataSource = _carDataRep._sqlSugar.SqlQueryable<Res_MemoView>(sql).ToList();
  1091. Dictionary<int, string> userDic = new Dictionary<int, string>();
  1092. foreach (var item in dataSource)
  1093. {
  1094. if (userDic.ContainsKey(item.LastedEditorId))
  1095. {
  1096. item.LastedEditor = userDic[item.LastedEditorId];
  1097. }
  1098. else
  1099. {
  1100. Sys_Users _sysUser = _carDataRep.Query<Sys_Users>(s => s.Id == item.LastedEditorId).First();
  1101. userDic[item.LastedEditorId] = _sysUser.CnName;
  1102. item.LastedEditor = _sysUser.CnName;
  1103. }
  1104. }
  1105. rst.DataList = new List<Res_MemoView>(dataSource);
  1106. if (rst.DataList.Count > 0)
  1107. {
  1108. string sqlCount = string.Format(@" Select Id From Res_Memo as m With(Nolock) {0} ", sqlWhere);
  1109. int dataCount = _carDataRep._sqlSugar.SqlQueryable<Res_MemoInfo>(sqlCount).Count();
  1110. rst.DataCount = dataCount;
  1111. }
  1112. return Ok(JsonView(rst));
  1113. }
  1114. else
  1115. {
  1116. //获取对象
  1117. string sqlSingle = string.Format(@" Select
  1118. m.Id as MemoId,d.DepName as DepartmentName,m.ReadLevel,m.Title,m.Abstracts,
  1119. m.LastedEditDt,m.LastedEditor,m.MDFilePath
  1120. From Res_Memo as m With(Nolock) Inner Join Sys_Users as u With(Nolock) On m.CreateUserId=u.Id
  1121. Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _memoDto.MemoId);
  1122. Res_MemoView _result = _carDataRep._sqlSugar.SqlQueryable<Res_MemoView>(sqlSingle).First();
  1123. if (_result != null)
  1124. {
  1125. Sys_Users _sysUser = _carDataRep.Query<Sys_Users>(s => s.Id == _result.LastedEditorId).First();
  1126. _result.LastedEditor = _sysUser.CnName;
  1127. _result.MarkDownContent = new IOOperatorHelper().Read(_result.MDFilePath);
  1128. return Ok(JsonView(_result));
  1129. }
  1130. }
  1131. }
  1132. else
  1133. {
  1134. return Ok(JsonView(false, "参数反序列化失败"));
  1135. }
  1136. return Ok(JsonView(false));
  1137. }
  1138. /// <summary>
  1139. /// 创建/编辑/删除备忘录信息
  1140. /// </summary>
  1141. /// <param name="_dto"></param>
  1142. /// <returns></returns>
  1143. [HttpPost]
  1144. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1145. public async Task<IActionResult> PostEditMemo(Edit_ResMemoDto _dto)
  1146. {
  1147. bool rst = false;
  1148. if (_dto.SysUserId < 1)
  1149. {
  1150. return Ok(JsonView(false, "操作人失效"));
  1151. }
  1152. Sys_Users _sysUser = _resItemInfoRep.Query<Sys_Users>(s => s.Id == _dto.SysUserId).First();
  1153. if (_sysUser == null)
  1154. {
  1155. return Ok(JsonView(false, "操作人失效02"));
  1156. }
  1157. if (_dto.EditType >= 0)
  1158. {
  1159. if (_dto.ReadLevel < 1)
  1160. {
  1161. return Ok(JsonView(false, "未知的阅读等级"));
  1162. }
  1163. if (string.IsNullOrEmpty(_dto.Title.Trim()))
  1164. {
  1165. return Ok(JsonView(false, "标题不能为空"));
  1166. }
  1167. if (string.IsNullOrEmpty(_dto.Content.Trim()))
  1168. {
  1169. return Ok(JsonView(false, "正文内容不能为空"));
  1170. }
  1171. //新增备忘录
  1172. DateTime dtNow = DateTime.Now;
  1173. string dir = AppSettingsHelper.Get("MemoCurrPath");
  1174. string fileName = dtNow.ToString("yyyyMMddHHmmss") + _dto.Title + ".md";
  1175. string content = JsonConvert.SerializeObject(_dto.Content);
  1176. if (_dto.EditType == 0)//新增
  1177. {
  1178. string savePath = new IOOperatorHelper().Write_CoverFile(content, dir, fileName);
  1179. if (savePath.Length > 0)
  1180. {
  1181. Res_MemoInfo _insert = new Res_MemoInfo();
  1182. _insert.Abstracts = _dto.Abstracts;
  1183. _insert.Title = _dto.Title;
  1184. _insert.DepartmentId = _sysUser.DepId;
  1185. _insert.CreateUserId = _sysUser.Id;
  1186. _insert.LastedEditDt = dtNow;
  1187. _insert.LastedEditor = _sysUser.Id;
  1188. _insert.MDFilePath = savePath;
  1189. _insert.ReadLevel = _dto.ReadLevel;
  1190. _insert.Title = _dto.Title;
  1191. int result = await _resItemInfoRep.AddAsync(_insert);
  1192. return Ok(JsonView(result > 0));
  1193. }
  1194. else
  1195. {
  1196. return Ok(JsonView(false, "路径保存失败"));
  1197. }
  1198. }
  1199. else//修改
  1200. {
  1201. if (_dto.MemoId < 1)
  1202. {
  1203. return Ok(JsonView(false, "MemoId不存在"));
  1204. }
  1205. Res_MemoInfo _source = _resItemInfoRep.Query<Res_MemoInfo>(s => s.Id == _dto.MemoId).First();
  1206. if (_source == null)
  1207. {
  1208. return Ok(JsonView(false, "MemoInfo不存在"));
  1209. }
  1210. //修改
  1211. string sourcePath = _source.MDFilePath;
  1212. string recycDir = AppSettingsHelper.Get("MemoRecycleBinPath");
  1213. new IOOperatorHelper().MoveFile(sourcePath, recycDir);
  1214. string savePath = new IOOperatorHelper().Write_CoverFile(content, dir, fileName);
  1215. if (savePath.Length > 0)
  1216. {
  1217. var result = await _resItemInfoRep._sqlSugar.Updateable<Res_MemoInfo>()
  1218. .SetColumns(it => it.LastedEditDt == DateTime.Now)
  1219. .SetColumns(it => it.LastedEditor == _sysUser.Id)
  1220. .SetColumns(it => it.Abstracts == _dto.Abstracts)
  1221. .SetColumns(it => it.MDFilePath == savePath)
  1222. .SetColumns(it => it.ReadLevel == _dto.ReadLevel)
  1223. .SetColumns(it => it.Title == _dto.Title)
  1224. .Where(s => s.Id == _source.Id)
  1225. .ExecuteCommandAsync();
  1226. return Ok(JsonView(result > 0));
  1227. }
  1228. }
  1229. }
  1230. else
  1231. {
  1232. //删除
  1233. if (_dto.MemoId < 1)
  1234. {
  1235. return Ok(JsonView(false, "MemoId不存在"));
  1236. }
  1237. Res_MemoInfo _source = _resItemInfoRep.Query<Res_MemoInfo>(s => s.Id == _dto.MemoId).First();
  1238. if (_source == null)
  1239. {
  1240. return Ok(JsonView(false, "MemoInfo不存在"));
  1241. }
  1242. //修改
  1243. string sourcePath = _source.MDFilePath;
  1244. string recycDir = AppSettingsHelper.Get("MemoRecycleBinPath");
  1245. new IOOperatorHelper().MoveFile(sourcePath, recycDir);
  1246. var result = await _resItemInfoRep._sqlSugar.Updateable<Res_MemoInfo>()
  1247. .SetColumns(it => it.IsDel == 1)
  1248. .SetColumns(it => it.DeleteUserId == _sysUser.Id)
  1249. .SetColumns(it => it.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1250. .Where(s => s.Id == _source.Id)
  1251. .ExecuteCommandAsync();
  1252. return Ok(JsonView(result > 0));
  1253. }
  1254. return Ok(JsonView(rst));
  1255. }
  1256. #endregion
  1257. }
  1258. }