ResourceController.cs 51 KB

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