SystemController.cs 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038
  1. using Aspose.Cells;
  2. using EyeSoft.Messanging;
  3. using Microsoft.EntityFrameworkCore.Metadata;
  4. using Microsoft.Extensions.Configuration.UserSecrets;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.Entities.Groups;
  9. using Org.BouncyCastle.Asn1.Cmp;
  10. using System.Collections;
  11. using static OASystem.API.OAMethodLib.GeneralMethod;
  12. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  13. using static QRCoder.PayloadGenerator;
  14. using static Quartz.Logging.OperationName;
  15. using static OASystem.API.OAMethodLib.JWTHelper;
  16. using System.Runtime.Intrinsics.Arm;
  17. using OASystem.Domain.Dtos.Statistics;
  18. using OASystem.Domain.AesEncryption;
  19. namespace OASystem.API.Controllers
  20. {
  21. /// <summary>
  22. /// 系统设置
  23. /// </summary>
  24. //[Authorize]
  25. [Route("api/[controller]/[action]")]
  26. public class SystemController : ControllerBase
  27. {
  28. private readonly CompanyRepository _syscomRep;
  29. private readonly DepartmentRepository _sysDepRep;
  30. private readonly UsersRepository _userRep;
  31. private readonly IMapper _mapper;
  32. private readonly SqlSugarClient _sqlSugar;
  33. private readonly MessageRepository _messageRep;
  34. private readonly SetDataRepository _setDataRepository;
  35. private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
  36. private readonly CompanyRepository _CompanyRepository;
  37. private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
  38. private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
  39. private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
  40. private readonly JobPostRepository _jobRep;
  41. private readonly SetDataTypeRepository _setDataTypeRep;
  42. private readonly UserAuthorityRepository _UserAuthorityRepository;
  43. private readonly List<int> _operationTypeList = new List<int>() { 1, 2, 3, 4, 5 }; //操作通知所属类型
  44. private readonly List<int> _taskTypeList = new List<int>() { 6 };//任务通知 TaskNotification
  45. public SystemController(
  46. CompanyRepository syscom,
  47. DepartmentRepository sysDepRep,
  48. UsersRepository userRep,
  49. IMapper mapper,
  50. SqlSugarClient sqlSugar,
  51. SetDataRepository setDataRepository,
  52. CompanyRepository companyRepository,
  53. SystemMenuPermissionRepository systemMenuPermissionRepository,
  54. PageFunctionPermissionRepository pageFunctionPermissionRepository,
  55. SystemMenuAndFunctionRepository systemMenuAndFunctionRepository,
  56. JobPostAuthorityRepository jobPostAuthorityRepository,
  57. JobPostRepository jobRep,
  58. UserAuthorityRepository userAuthorityRepository,
  59. MessageRepository messageRep,
  60. SetDataTypeRepository setDataTypeRep
  61. )
  62. {
  63. _syscomRep = syscom;
  64. _sysDepRep = sysDepRep;
  65. _messageRep = messageRep;
  66. _userRep = userRep;
  67. _mapper = mapper;
  68. _sqlSugar = sqlSugar;
  69. _setDataRepository = setDataRepository;
  70. _CompanyRepository = companyRepository;
  71. _SystemMenuPermissionRepository = systemMenuPermissionRepository;
  72. _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
  73. _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
  74. _JobPostAuthorityRepository = jobPostAuthorityRepository;
  75. _UserAuthorityRepository = userAuthorityRepository;
  76. _jobRep = jobRep;
  77. _setDataTypeRep = setDataTypeRep;
  78. }
  79. #region 消息
  80. /// <summary>
  81. /// 获取消息列表-整合版
  82. /// </summary>
  83. /// <param name="dto"></param>
  84. /// <returns></returns>
  85. [HttpPost]
  86. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  87. public async Task<IActionResult> PsotMsgPageList(MsgDto dto)
  88. {
  89. var msgData = await _messageRep.GetMsgList(dto);
  90. if (msgData.Code != 0)
  91. {
  92. return Ok(JsonView(false, msgData.Msg));
  93. }
  94. return Ok(JsonView(msgData.Data));
  95. }
  96. #region 消息列表 - 分开
  97. /// <summary>
  98. /// 系统消息
  99. /// 消息类型 2024-03-06 14:37
  100. /// </summary>
  101. /// <param name="dto"></param>
  102. /// <returns></returns>
  103. [HttpPost]
  104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  105. public async Task<IActionResult> PotsMsgTypeData(MsgTypeDto dto)
  106. {
  107. if (dto.PortType < 1 || dto.PortType > 3)
  108. {
  109. return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
  110. }
  111. if (dto.UserId < 1)
  112. {
  113. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  114. }
  115. var msgData = await _messageRep.PotsMsgTypeData(dto);
  116. if (msgData.Code != 0)
  117. {
  118. return Ok(JsonView(400, msgData.Msg, new string[] { }));
  119. }
  120. return Ok(JsonView(true, msgData.Msg, msgData.Data));
  121. }
  122. /// <summary>
  123. /// 系统消息
  124. /// 消息List 2024-03-06 14:54
  125. /// </summary>
  126. /// <param name="dto"></param>
  127. /// <returns></returns>
  128. [HttpPost]
  129. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  130. public async Task<IActionResult> PotsMessagePageList(PotsMessagePageListDto dto)
  131. {
  132. #region 参数验证
  133. if (dto.PortType < 1 || dto.PortType > 3)
  134. {
  135. return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
  136. }
  137. var typeData = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 77).Select(it => it.Id).ToListAsync();
  138. if (typeData.Count < 0)
  139. {
  140. return Ok(JsonView(false, "消息类型不存在"));
  141. }
  142. if (!typeData.Contains(dto.Type))
  143. {
  144. return Ok(JsonView(false, "请输入有效的Type参数。1021 团组操作通知 1020 任务操作通知 "));
  145. }
  146. if (dto.UserId < 1)
  147. {
  148. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  149. }
  150. if (dto.ReadStatus < 1 || dto.ReadStatus > 3)
  151. {
  152. return Ok(JsonView(false, "请输入有效的ReadStatus参数。1 全部(包含已读/未读) 2 未读 3 已读"));
  153. }
  154. #endregion
  155. //userId
  156. string msgSqlWhere = $" And smra.ReadableUId = {dto.UserId}";
  157. //消息类型
  158. string typeStr = "";
  159. List<NotificationTypeView> messageTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  160. if (dto.Type == 1020) //任务操作通知
  161. {
  162. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1020).FirstOrDefault().MsgTypeIds.ToList());
  163. }
  164. else if (dto.Type == 1021)//团组操作通知
  165. {
  166. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1021).FirstOrDefault().MsgTypeIds.ToList());
  167. }
  168. else if (dto.Type == 1022)//公告通知
  169. {
  170. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1022).FirstOrDefault().MsgTypeIds.ToList());
  171. }
  172. if (!string.IsNullOrEmpty(typeStr))
  173. {
  174. msgSqlWhere += $" And sm.Type In ({typeStr})";
  175. }
  176. //是否已读处理 1 全部(包含已读/未读) 2 未读 3 已读
  177. if (dto.ReadStatus == 1) msgSqlWhere += "";
  178. else if (dto.ReadStatus == 2) msgSqlWhere += $" And smra.IsRead = {0}";
  179. else if (dto.ReadStatus == 3) msgSqlWhere += $" And smra.IsRead = {1}";
  180. string msgSql = string.Format(@"Select * From(
  181. Select row_number() over(order by sm.ReleaseTime Desc) as RowNumber,
  182. sm.Id,sm.Type,sm.Title,sm.Content,sd.DepName issuerDep,su.CnName issuerUser,
  183. sm.ReleaseTime,smra.ReadableUId,smra.IsRead,sm.DiId,sm.Param
  184. From Sys_Message sm
  185. Inner Join Sys_MessageReadAuth smra On sm.Id = smra.MsgId
  186. Inner Join Sys_Users su On sm.IssuerId = su.Id
  187. Inner Join Sys_Department sd On su.DepId = sd.Id
  188. Inner Join Sys_Users suAuth On smra.ReadableUId = suAuth.Id
  189. Where sm.IsDel = 0
  190. And smra.IsDel = 0 {0}
  191. ) Temp", msgSqlWhere);
  192. try
  193. {
  194. RefAsync<int> totalCount = 0;
  195. var data = await _sqlSugar.SqlQueryable<MessageListView>(msgSql).ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
  196. return Ok(JsonView(true, "操作成功!", data, totalCount));
  197. }
  198. catch (Exception ex)
  199. {
  200. return Ok(JsonView(false, ex.Message));
  201. }
  202. }
  203. /// <summary>
  204. /// 系统消息
  205. /// 获取消息未读条数
  206. /// </summary>
  207. /// <param name="dto"></param>
  208. /// <returns></returns>
  209. [HttpPost]
  210. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  211. public async Task<IActionResult> PotsMessageUnreadTotalCount(PotsMessageUnreadTotalCountDto dto)
  212. {
  213. #region 参数验证
  214. if (dto.UserId < 1)
  215. {
  216. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  217. }
  218. #endregion
  219. try
  220. {
  221. int messageUnReadCount = 0;
  222. int announcementUnReadCount = 0;
  223. var data = await _messageRep.GetUnReadCount(dto.UserId);
  224. if (data != null)
  225. {
  226. messageUnReadCount = data;
  227. }
  228. var data1 = await _messageRep.GetAnnouncementUnReadCount(dto.UserId);
  229. if (data1 != null)
  230. {
  231. announcementUnReadCount = data1;
  232. }
  233. return Ok(JsonView(true, "操作成功!", new { messageUnReadCount = messageUnReadCount, announcementUnReadCount = announcementUnReadCount }));
  234. }
  235. catch (Exception ex)
  236. {
  237. return Ok(JsonView(false, ex.Message));
  238. }
  239. }
  240. #endregion
  241. /// <summary>
  242. /// 获取消息详细信息
  243. /// </summary>
  244. /// <param name="dto"></param>
  245. /// <returns></returns>
  246. [HttpPost]
  247. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  248. public async Task<IActionResult> PostMsgInfo(MsgInfoDto dto)
  249. {
  250. if (dto.PortType < 1 || dto.PortType > 3)
  251. {
  252. return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
  253. }
  254. var msgData = await _messageRep.GetMsgInfo(dto);
  255. if (msgData.Code != 0)
  256. {
  257. return Ok(JsonView(false, msgData.Msg));
  258. }
  259. return Ok(JsonView(true, "操作成功!", msgData.Data));
  260. }
  261. /// <summary>
  262. /// 消息设置已读
  263. /// </summary>
  264. /// <param name="dto"></param>
  265. /// <returns></returns>
  266. [HttpPost]
  267. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  268. public async Task<IActionResult> SetMessageRead(MsgSetReadDto dto)
  269. {
  270. var msgData = await _messageRep.SetMsgRead(dto);
  271. if (msgData.Code != 0)
  272. {
  273. return Ok(JsonView(false, msgData.Msg));
  274. }
  275. return Ok(JsonView(true));
  276. }
  277. /// <summary>
  278. /// 消息 删除
  279. /// </summary>
  280. /// <param name="dto"></param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  284. public async Task<IActionResult> DeleMsg(MsgDeleteDto dto)
  285. {
  286. var msgData = await _messageRep.DelMsg(dto);
  287. if (msgData.Code != 0)
  288. {
  289. return Ok(JsonView(false, msgData.Msg));
  290. }
  291. return Ok(JsonView(true));
  292. }
  293. #endregion
  294. #region 数据类型资料
  295. /// <summary>
  296. /// 根据类型查询数据
  297. /// </summary>
  298. /// <param name="dto"></param>
  299. /// <returns></returns>
  300. [HttpPost]
  301. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  302. public async Task<IActionResult> QuerySetData(SetDataDto dto)
  303. {
  304. try
  305. {
  306. if (dto.DataType == 0)
  307. {
  308. return Ok(JsonView(false, "请传类型Id!"));
  309. }
  310. var setData = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.DataType && s.IsDel == 0).ToList();
  311. if (setData.Count == 0)
  312. {
  313. return Ok(JsonView(false, "暂无数据!"));
  314. }
  315. return Ok(JsonView(true, "查询成功!", setData));
  316. }
  317. catch (Exception ex)
  318. {
  319. return Ok(JsonView(false, "程序错误!"));
  320. throw;
  321. }
  322. }
  323. /// <summary>
  324. /// 根据类型查询数据(Array)
  325. /// </summary>
  326. /// <returns></returns>
  327. [HttpPost]
  328. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  329. public IActionResult QuerySetDataInitByArr(QuerySetDataInitByArr Dto)
  330. {
  331. var DbQuery = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => Dto.DataTypeArr.Contains(s.STid)).ToList();
  332. var GroupResult = DbQuery.GroupBy(x => x.STid).Select(x => new
  333. {
  334. key = x.Key,
  335. Arr = x.ToList()
  336. });
  337. return Ok(JsonView(true, "查询成功!", GroupResult));
  338. }
  339. /// <summary>
  340. /// 数据类型表查询
  341. /// </summary>
  342. /// <param name="dto"></param>
  343. /// <returns></returns>
  344. [HttpPost]
  345. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  346. public async Task<IActionResult> QuerySetDataType(SetDataTypeDto dto)
  347. {
  348. try
  349. {
  350. Result setDataType = await _setDataTypeRep.QuerySetDataType(dto);
  351. if (setDataType.Code == 0)
  352. {
  353. return Ok(JsonView(true, "查询成功", setDataType.Data));
  354. }
  355. else
  356. {
  357. return Ok(JsonView(false, setDataType.Msg));
  358. }
  359. }
  360. catch (Exception)
  361. {
  362. return Ok(JsonView(false, "程序错误!"));
  363. throw;
  364. }
  365. }
  366. /// <summary>
  367. /// 数据类型表操作(Status:1.新增,2.修改)
  368. /// </summary>
  369. /// <param name="dto"></param>
  370. /// <returns></returns>
  371. [HttpPost]
  372. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  373. public async Task<IActionResult> OperationSetDataType(OperationSetDataTypeDto dto)
  374. {
  375. try
  376. {
  377. if (dto.Name == "")
  378. {
  379. return Ok(JsonView(false, "请检查类型名称是否填写!"));
  380. }
  381. Result result = await _setDataTypeRep.OperationSetDataType(dto);
  382. if (result.Code != 0)
  383. {
  384. return Ok(JsonView(false, result.Msg));
  385. }
  386. return Ok(JsonView(true, result.Msg));
  387. }
  388. catch (Exception ex)
  389. {
  390. return Ok(JsonView(false, "程序错误!"));
  391. throw;
  392. }
  393. }
  394. /// <summary>
  395. /// 数据类型表操作删除
  396. /// </summary>
  397. /// <param name="dto"></param>
  398. /// <returns></returns>
  399. [HttpPost]
  400. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  401. public async Task<IActionResult> DelSetDataType(DelSetDataTypeDto dto)
  402. {
  403. try
  404. {
  405. var res = await _setDataTypeRep.SoftDeleteByIdAsync<Sys_SetDataType>(dto.Id.ToString(), dto.DeleteUserId);
  406. if (!res)
  407. {
  408. return Ok(JsonView(false, "删除失败"));
  409. }
  410. return Ok(JsonView(true, "删除成功!"));
  411. }
  412. catch (Exception ex)
  413. {
  414. return Ok(JsonView(false, "程序错误!"));
  415. throw;
  416. }
  417. }
  418. #endregion
  419. #region 数据类型板块
  420. /// <summary>
  421. /// 数据类型板块表查询
  422. /// </summary>
  423. /// <param name="dto"></param>
  424. /// <returns></returns>
  425. [HttpPost]
  426. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  427. public async Task<IActionResult> QuerySetDataInfo(SetDataIDto dto)
  428. {
  429. try
  430. {
  431. Result setData = await _setDataRepository.QuerySetData(dto);
  432. if (setData.Code == 0)
  433. {
  434. return Ok(JsonView(true, "查询成功", setData.Data));
  435. }
  436. else
  437. {
  438. return Ok(JsonView(false, setData.Msg));
  439. }
  440. }
  441. catch (Exception)
  442. {
  443. return Ok(JsonView(false, "程序错误!"));
  444. throw;
  445. }
  446. }
  447. /// <summary>
  448. /// 数据类型板块表操作(Status:1.新增,2.修改)
  449. /// </summary>
  450. /// <param name="dto"></param>
  451. /// <returns></returns>
  452. [HttpPost]
  453. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  454. public async Task<IActionResult> OperationSetData(OperationSetDataDto dto)
  455. {
  456. try
  457. {
  458. if (dto.Name == "")
  459. {
  460. return Ok(JsonView(false, "请检查板块名称是否填写!"));
  461. }
  462. Result result = await _setDataRepository.OperationSetData(dto);
  463. if (result.Code != 0)
  464. {
  465. return Ok(JsonView(false, result.Msg));
  466. }
  467. return Ok(JsonView(true, result.Msg));
  468. }
  469. catch (Exception ex)
  470. {
  471. return Ok(JsonView(false, "程序错误!"));
  472. throw;
  473. }
  474. }
  475. /// <summary>
  476. /// 数据类型表操作删除
  477. /// </summary>
  478. /// <param name="dto"></param>
  479. /// <returns></returns>
  480. [HttpPost]
  481. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  482. public async Task<IActionResult> DelSetData(DelSetDataDto dto)
  483. {
  484. try
  485. {
  486. var res = await _setDataRepository.SoftDeleteByIdAsync<Sys_SetData>(dto.Id.ToString(), dto.DeleteUserId);
  487. if (!res)
  488. {
  489. return Ok(JsonView(false, "删除失败"));
  490. }
  491. return Ok(JsonView(true, "删除成功!"));
  492. }
  493. catch (Exception ex)
  494. {
  495. return Ok(JsonView(false, "程序错误!"));
  496. throw;
  497. }
  498. }
  499. #endregion
  500. #region 企业操作
  501. /// <summary>
  502. /// 查询企业数据
  503. /// </summary>
  504. /// <param name="dto"></param>
  505. /// <returns></returns>
  506. [HttpPost]
  507. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  508. public async Task<IActionResult> getCompanyList(DtoBase dto)
  509. {
  510. if (dto.PortType == 1)
  511. {
  512. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  513. if (CompanyDataResult.Code != 0)
  514. {
  515. return Ok(JsonView(CompanyDataResult.Msg));
  516. }
  517. List<CompanyView> companyListView = _mapper.Map<List<CompanyView>>(CompanyDataResult.Data);
  518. for (int i = 0; i < companyListView.Count; i++)
  519. {
  520. if (companyListView[i].ParentCompanyId != 0)
  521. {
  522. companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
  523. }
  524. if (companyListView[i].ContactUserId != 0)
  525. {
  526. var user = _userRep.QueryDto<Sys_Users, UserInfoWebView>(x => x.Id == companyListView[i].ContactUserId).ToList();
  527. if (user.Count != 0)
  528. {
  529. companyListView[i].ContactUserName = user[0].CnName;
  530. }
  531. }
  532. }
  533. return Ok(JsonView(true, "查询成功!", companyListView));
  534. }
  535. else if (dto.PortType == 2)
  536. {
  537. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  538. if (CompanyDataResult.Code != 0)
  539. {
  540. return Ok(JsonView(CompanyDataResult.Msg));
  541. }
  542. return Ok(JsonView(true, "查询成功!", CompanyDataResult.Data));
  543. }
  544. else if (dto.PortType == 3)
  545. {
  546. return Ok(JsonView(false, "暂无数据!"));
  547. }
  548. else
  549. {
  550. return Ok(JsonView(false, "暂无数据!"));
  551. }
  552. }
  553. /// <summary>
  554. /// 添加企业数据
  555. /// </summary>
  556. /// <param name="dto"></param>
  557. /// <returns></returns>
  558. [HttpPost]
  559. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  560. public async Task<IActionResult> AddCompany(AddCompanyDto dto)
  561. {
  562. if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
  563. {
  564. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  565. }
  566. else if (string.IsNullOrWhiteSpace(dto.Tel))
  567. {
  568. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  569. }
  570. else
  571. {
  572. Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
  573. Result data = await _syscomRep.AddCompany(_Company);
  574. if (data.Code != 0)
  575. {
  576. return Ok(JsonView(false, "添加失败!"));
  577. }
  578. return Ok(JsonView(true, "添加成功"));
  579. }
  580. }
  581. /// <summary>
  582. /// 企业修改
  583. /// </summary>
  584. /// <param name="dto"></param>
  585. /// <returns></returns>
  586. [HttpPost]
  587. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  588. public async Task<IActionResult> EditCompany(EditCompanyDto dto)
  589. {
  590. if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ContactUserId == 0)
  591. {
  592. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  593. }
  594. else if (string.IsNullOrWhiteSpace(dto.Tel))
  595. {
  596. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  597. }
  598. else
  599. {
  600. bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
  601. {
  602. CompanyName = dto.CompanyName,
  603. CompanyCode = dto.CompanyCode,
  604. Address = dto.Address,
  605. ParentCompanyId = dto.ParentCompanyId,
  606. Tel = dto.Tel,
  607. ContactUserId = dto.ContactUserId,
  608. Remark = dto.Remark,
  609. });
  610. if (!res) { return Ok(JsonView(false, "修改失败")); }
  611. return Ok(JsonView(true, "修改成功!"));
  612. }
  613. }
  614. /// <summary>
  615. /// 企业删除
  616. /// </summary>
  617. /// <param name="dto"></param>
  618. /// <returns></returns>
  619. [HttpPost]
  620. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  621. public async Task<IActionResult> DelCompany(DelCompanyDto dto)
  622. {
  623. bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
  624. if (!res) { return Ok(JsonView(false, "删除失败")); }
  625. return Ok(JsonView(true, "删除成功"));
  626. }
  627. #endregion
  628. #region 部门操作
  629. /// <summary>
  630. /// 查询部门数据
  631. /// </summary>
  632. /// <param name="dto"></param>
  633. /// <returns></returns>
  634. [HttpPost]
  635. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  636. public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
  637. {
  638. try
  639. {
  640. if (dto.PortType == 1)
  641. {
  642. if (dto.CompanyId != 0)
  643. {
  644. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  645. if (result.Count == 0)
  646. {
  647. return Ok(JsonView(false, "暂无数据!"));
  648. }
  649. for (int i = 0; i < result.Count; i++)
  650. {
  651. if (result[i].ParentDepId != 0)
  652. {
  653. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  654. }
  655. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  656. if (company.Count != 0)
  657. {
  658. result[i].CompanyName = company[0].CompanyName;
  659. }
  660. return Ok(JsonView(true, "查询成功!", result));
  661. }
  662. }
  663. else
  664. {
  665. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.IsDel <= 1).ToList();
  666. if (result.Count == 0)
  667. {
  668. return Ok(JsonView(false, "暂无数据!"));
  669. }
  670. for (int i = 0; i < result.Count; i++)
  671. {
  672. if (result[i].ParentDepId != 0)
  673. {
  674. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  675. }
  676. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  677. if (company.Count != 0)
  678. {
  679. result[i].CompanyName = company[0].CompanyName;
  680. }
  681. }
  682. return Ok(JsonView(true, "查询成功!", result));
  683. }
  684. return Ok(JsonView(false, "暂无数据!"));
  685. }
  686. else if (dto.PortType == 2)
  687. {
  688. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  689. if (result.Count == 0)
  690. {
  691. return Ok(JsonView(400, "暂无数据!", new List<string>()));
  692. }
  693. return Ok(JsonView(true, "查询成功!", result));
  694. }
  695. else if (dto.PortType == 3)
  696. {
  697. return Ok(JsonView(false, "暂无数据!"));
  698. }
  699. else
  700. {
  701. return Ok(JsonView(false, "暂无数据!"));
  702. }
  703. }
  704. catch (Exception ex)
  705. {
  706. return Ok(JsonView(false, "程序错误!"));
  707. throw;
  708. }
  709. }
  710. /// <summary>
  711. /// 部门添加
  712. /// </summary>
  713. /// <param name="dto"></param>
  714. /// <returns></returns>
  715. [HttpPost]
  716. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  717. public async Task<IActionResult> AddDepartment(AddDepartmentDto dto)
  718. {
  719. try
  720. {
  721. if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  722. {
  723. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  724. }
  725. else
  726. {
  727. Sys_Department _Department = _mapper.Map<Sys_Department>(dto);
  728. int id = await _sysDepRep.AddAsyncReturnId(_Department);
  729. if (id == 0)
  730. {
  731. return Ok(JsonView(false, "添加失败!"));
  732. }
  733. return Ok(JsonView(true, "添加成功!", new { Id = id }));
  734. }
  735. }
  736. catch (Exception)
  737. {
  738. return Ok(JsonView(false, "程序错误!"));
  739. throw;
  740. }
  741. }
  742. /// <summary>
  743. /// 部门修改
  744. /// </summary>
  745. /// <param name="dto"></param>
  746. /// <returns></returns>
  747. [HttpPost]
  748. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  749. public async Task<IActionResult> EditDepartment(EditDepartmentDto dto)
  750. {
  751. try
  752. {
  753. if (dto.Id == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  754. {
  755. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  756. }
  757. else
  758. {
  759. bool res = await _sysDepRep.UpdateAsync<Sys_Department>(a => a.Id == dto.Id, a => new Sys_Department
  760. {
  761. CompanyId = dto.CompanyId,
  762. DepCode = dto.DepCode,
  763. DepName = dto.DepName,
  764. ParentDepId = dto.ParentDepId,
  765. Remark = dto.Remark,
  766. });
  767. if (!res)
  768. {
  769. return Ok(JsonView(false, "修改失败!"));
  770. }
  771. return Ok(JsonView(true, "修改成功!"));
  772. }
  773. }
  774. catch (Exception)
  775. {
  776. return Ok(JsonView(false, "程序错误!"));
  777. throw;
  778. }
  779. }
  780. /// <summary>
  781. /// 部门删除
  782. /// </summary>
  783. /// <param name="dto"></param>
  784. /// <returns></returns>
  785. [HttpPost]
  786. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  787. public async Task<IActionResult> DelDepartment(DelDepartmentDto dto)
  788. {
  789. try
  790. {
  791. if (dto.Id == 0)
  792. {
  793. return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
  794. }
  795. else
  796. {
  797. bool res = await _sysDepRep.SoftDeleteAsync<Sys_Department>(dto.Id.ToString());
  798. if (!res)
  799. {
  800. return Ok(JsonView(false, "删除失败!"));
  801. }
  802. return Ok(JsonView(true, "删除成功!"));
  803. }
  804. }
  805. catch (Exception)
  806. {
  807. return Ok(JsonView(false, "程序错误!"));
  808. throw;
  809. }
  810. }
  811. #endregion
  812. #region 岗位板块
  813. /// <summary>
  814. /// 岗位查询
  815. /// </summary>
  816. /// <param name="dto"></param>
  817. /// <returns></returns>
  818. [HttpPost]
  819. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  820. public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
  821. {
  822. try
  823. {
  824. if (dto.PortType == 1)
  825. {
  826. string sqlWhere = string.Empty;
  827. if (dto.CompanyId != 0)
  828. {
  829. sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
  830. }
  831. if (dto.DepId != 0)
  832. {
  833. sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
  834. }
  835. sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
  836. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  837. {
  838. Regex r = new Regex("And");
  839. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  840. }
  841. List<Sys_JobPostI> jobList = await _jobRep.QueryJobPost(sqlWhere);
  842. List<JobPostView> List = _mapper.Map<List<JobPostView>>(jobList);
  843. if (jobList.Count == 0)
  844. {
  845. return Ok(JsonView(false, "暂无数据!"));
  846. }
  847. return Ok(JsonView(true, "查询成功!", jobList));
  848. }
  849. else if (dto.PortType == 2)
  850. {
  851. var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId == dto.DepId).ToList();
  852. if (result.Count == 0)
  853. {
  854. return Ok(JsonView(false, "暂无数据!"));
  855. }
  856. return Ok(JsonView(true, "查询成功!", result));
  857. }
  858. else if (dto.PortType == 3)
  859. {
  860. return Ok(JsonView(false, "暂无数据!"));
  861. }
  862. else
  863. {
  864. return Ok(JsonView(false, "暂无数据!"));
  865. }
  866. }
  867. catch (Exception ex)
  868. {
  869. return Ok(JsonView(false, "程序错误!"));
  870. throw;
  871. }
  872. }
  873. /// <summary>
  874. /// 添加岗位
  875. /// </summary>
  876. /// <param name="dto"></param>
  877. /// <returns></returns>
  878. [HttpPost]
  879. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  880. public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
  881. {
  882. try
  883. {
  884. Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
  885. int id = await _jobRep.AddAsyncReturnId(sys_Job);
  886. if (id == 0)
  887. {
  888. return Ok(JsonView(false, "添加失败"));
  889. }
  890. return Ok(JsonView(true, "添加成功", new { Id = id }));
  891. }
  892. catch (Exception ex)
  893. {
  894. return Ok(JsonView(false, "程序错误!"));
  895. throw;
  896. }
  897. }
  898. /// <summary>
  899. /// 修改岗位
  900. /// </summary>
  901. /// <param name="dto"></param>
  902. /// <returns></returns>
  903. [HttpPost]
  904. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  905. public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
  906. {
  907. try
  908. {
  909. bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a => a.Id == dto.Id, a => new Sys_JobPost
  910. {
  911. CompanyId = dto.CompanyId,
  912. DepId = dto.DepId,
  913. JobName = dto.JobName,
  914. Remark = dto.Remark,
  915. });
  916. if (!res)
  917. {
  918. return Ok(JsonView(false, "修改失败"));
  919. }
  920. return Ok(JsonView(true, "修改成功"));
  921. }
  922. catch (Exception ex)
  923. {
  924. return Ok(JsonView(false, "程序错误!"));
  925. throw;
  926. }
  927. }
  928. /// <summary>
  929. /// 删除岗位
  930. /// </summary>
  931. /// <param name="dto"></param>
  932. /// <returns></returns>
  933. [HttpPost]
  934. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  935. public async Task<IActionResult> DelJobPost(DelJobPostDto dto)
  936. {
  937. try
  938. {
  939. bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
  940. if (!res)
  941. {
  942. return Ok(JsonView(false, "删除失败!"));
  943. }
  944. return Ok(JsonView(true, "删除成功"));
  945. }
  946. catch (Exception)
  947. {
  948. return Ok(JsonView(false, "程序错误!"));
  949. throw;
  950. }
  951. }
  952. #endregion
  953. #region 用户操作
  954. ///// <summary>
  955. ///// 用户表指定字段加密
  956. ///// </summary>
  957. ///// <param name="dto"></param>
  958. ///// <returns></returns>
  959. //[HttpPost]
  960. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  961. //public async Task<IActionResult> UserBatchEncryption()
  962. //{
  963. // var items = await _sqlSugar.Queryable<Sys_Users>().Select(x => new Sys_Users() { Id = x.Id, Phone = x.Phone, UrgentPhone = x.UrgentPhone, IDCard = x.IDCard }).ToListAsync();
  964. // foreach (var item in items) EncryptionProcessor.EncryptProperties(item);
  965. // var updItems = await _sqlSugar.Updateable(items).UpdateColumns(x => new { x.Phone, x.UrgentPhone, x.IDCard }).ExecuteCommandAsync();
  966. // return Ok(JsonView(updItems));
  967. //}
  968. /// <summary>
  969. /// 查询所有员工名称
  970. /// </summary>
  971. /// <param name="dto"></param>
  972. /// <returns></returns>
  973. [HttpPost]
  974. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  975. public async Task<IActionResult> GetUserNameList(DtoBase dto)
  976. {
  977. var result = _userRep.GetUserNameList(dto.PortType);
  978. if (result.Result.Code != 0)
  979. {
  980. return Ok(JsonView(false, "暂无数据!"));
  981. }
  982. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  983. }
  984. /// <summary>
  985. /// 查询所有员工(web)
  986. /// </summary>
  987. /// <param name="dto"></param>
  988. /// <returns></returns>
  989. [HttpPost]
  990. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  991. public async Task<IActionResult> GetUserList(DtoBase dto)
  992. {
  993. var result = _userRep.GetUserList(dto.PortType, string.Empty);
  994. if (result.Result.Code != 0)
  995. {
  996. return Ok(JsonView(false, "暂无数据!"));
  997. }
  998. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  999. }
  1000. /// <summary>
  1001. /// 查询用户数据
  1002. /// </summary>
  1003. /// <param name="dto"></param>
  1004. /// <returns></returns>
  1005. [HttpPost]
  1006. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1007. public async Task<IActionResult> QueryUserList(UserDto dto)
  1008. {
  1009. string sqlWhere = string.Format(" Where su.IsDel = 0 ");
  1010. if (dto.CompanyId != 0)
  1011. {
  1012. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  1013. }
  1014. if (dto.DepId != 0)
  1015. {
  1016. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  1017. }
  1018. if (dto.JobPostId != 0)
  1019. {
  1020. sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
  1021. }
  1022. List<UserInfo> _userList = await _userRep.QueryUser(sqlWhere);
  1023. if (_userList.Count == 0)
  1024. {
  1025. return Ok(JsonView(400, "暂无数据!", new List<String>()));
  1026. }
  1027. List<UserInfoWebView> userList = _mapper.Map<List<UserInfoWebView>>(_userList);
  1028. return Ok(JsonView(true, "查询成功!", userList));
  1029. }
  1030. /// <summary>
  1031. /// 员工信息 个人详细信息
  1032. /// </summary>
  1033. /// <returns></returns>
  1034. [HttpPost]
  1035. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1036. public async Task<IActionResult> UserInfo(UserInfoDto dto)
  1037. {
  1038. if (dto.Id < 1) return Ok(JsonView(false, "请选择有效的userId!"));
  1039. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1040. var _view = await _sqlSugar.Queryable<Sys_Users>()
  1041. .Where(x => x.IsDel == 0 && x.Id == dto.Id)
  1042. .Select(x => new
  1043. {
  1044. x.Id,
  1045. x.CnName,
  1046. x.EnName,
  1047. x.Number,
  1048. x.CompanyId,
  1049. x.DepId,
  1050. x.JobPostId,
  1051. x.Password,
  1052. x.Sex,
  1053. x.Ext,
  1054. x.Phone,
  1055. x.UrgentPhone,
  1056. x.Email,
  1057. x.Address,
  1058. x.Edate,
  1059. //x.Seniority,
  1060. x.Birthday,
  1061. x.IDCard,
  1062. x.StartWorkDate,
  1063. x.GraduateInstitutions,
  1064. x.Professional,
  1065. x.Education,
  1066. x.TheOrAdultEducation,
  1067. x.MaritalStatus,
  1068. x.HomeAddress,
  1069. x.UsePeriod,
  1070. x.WorkExperience,
  1071. x.Certificate,
  1072. //x.QiyeChatUserId,
  1073. x.Remark
  1074. }).FirstAsync();
  1075. //解密
  1076. EncryptionProcessor.DecryptProperties(_view);
  1077. return Ok(JsonView(true, "操作成功!", _view));
  1078. }
  1079. /// <summary>
  1080. /// 员工信息 All信息修改
  1081. /// </summary>
  1082. /// <returns></returns>
  1083. [HttpPost]
  1084. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1085. public async Task<IActionResult> EditUserInfo(EditUserInfoDto _dto)
  1086. {
  1087. EditUserInfoDtoValidator validator = new EditUserInfoDtoValidator();
  1088. var validatorRes = await validator.ValidateAsync(_dto);
  1089. if (!validatorRes.IsValid)
  1090. {
  1091. var errors = new StringBuilder();
  1092. foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
  1093. return Ok(JsonView(false, errors.ToString()));
  1094. }
  1095. var userInfo = _mapper.Map<Sys_Users>(_dto);
  1096. if (_dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1097. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1098. List<int> userIds = new List<int>() {
  1099. 4 ,//管理员
  1100. 5 ,//杨俊霄
  1101. 117 ,//人事审核号
  1102. 208 ,//雷怡
  1103. 230 ,//刘一茹
  1104. 233 ,//刘华举
  1105. 234 ,//蒋金辰
  1106. 235 ,//袁榕烽
  1107. 309 ,//赖红燕
  1108. };
  1109. if (!userIds.Contains(_dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1110. //加密
  1111. EncryptionProcessor.EncryptProperties(userInfo);
  1112. var res = await _sqlSugar.Updateable(userInfo)
  1113. .IgnoreColumns(x => new
  1114. {
  1115. x.QiyeChatUserId,
  1116. x.Rdate,
  1117. x.Seniority,
  1118. x.HrAudit,
  1119. x.CreateUserId,
  1120. x.CreateTime,
  1121. x.DeleteUserId,
  1122. x.DeleteTime,
  1123. x.IsDel
  1124. })
  1125. .Where(x => x.Id == _dto.Id)
  1126. .ExecuteCommandAsync();
  1127. if (res > 0) return Ok(JsonView(true, "操作成功!"));
  1128. return Ok(JsonView(false, "操作失败!"));
  1129. }
  1130. /// <summary>
  1131. /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
  1132. /// </summary>
  1133. /// <param name="dto"></param>
  1134. /// <returns></returns>
  1135. [HttpPost]
  1136. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1137. public async Task<IActionResult> EditUser(EditUserDto dto)
  1138. {
  1139. if(dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1140. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1141. var userIds = new List<int>() {
  1142. 4 ,//管理员
  1143. 5 ,//杨俊霄
  1144. 117 ,//人事审核号
  1145. 208 ,//雷怡
  1146. 230 ,//刘一茹
  1147. 233 ,//刘华举
  1148. 234 ,//蒋金辰
  1149. 235 ,//袁榕烽
  1150. 309 ,//赖红燕
  1151. };
  1152. if (!userIds.Contains(dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1153. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1154. {
  1155. Number = dto.Number,
  1156. CompanyId = dto.CompanyId,
  1157. DepId = dto.DepId,
  1158. JobPostId = dto.JobPostId,
  1159. Ext = dto.Ext,
  1160. UsePeriod = dto.UsePeriod,
  1161. //HrAudit = dto.HrAudit
  1162. });
  1163. if (!res)
  1164. {
  1165. return Ok(JsonView(false, "修改失败!"));
  1166. }
  1167. return Ok(JsonView(true, "修改成功!"));
  1168. }
  1169. /// <summary>
  1170. /// 修改用户信息(登录用户修改个人信息)
  1171. /// </summary>
  1172. /// <param name="dto"></param>
  1173. /// <returns></returns>
  1174. [HttpPost]
  1175. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1176. public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
  1177. {
  1178. if (string.IsNullOrWhiteSpace(dto.CnName) ||
  1179. string.IsNullOrWhiteSpace(dto.Address) ||
  1180. string.IsNullOrWhiteSpace(dto.IDCard) ||
  1181. dto.Sex != 0 && dto.Sex != 1 ||
  1182. string.IsNullOrWhiteSpace(dto.MaritalStatus) ||
  1183. string.IsNullOrWhiteSpace(dto.HomeAddress) ||
  1184. dto.Birthday >= DateTime.Now.AddYears(-1))
  1185. {
  1186. return Ok(JsonView(false, "请完善你的个人信息!"));
  1187. }
  1188. else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) ||
  1189. string.IsNullOrWhiteSpace(dto.Professional) ||
  1190. dto.Education == 0 ||
  1191. string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
  1192. {
  1193. return Ok(JsonView(false, "请完善你的学历信息!"));
  1194. }
  1195. else if (string.IsNullOrWhiteSpace(dto.Phone) ||
  1196. string.IsNullOrWhiteSpace(dto.UrgentPhone) ||
  1197. string.IsNullOrWhiteSpace(dto.Email))
  1198. {
  1199. return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
  1200. }
  1201. else
  1202. {
  1203. //指定字段加密
  1204. var phone = AesEncryptionHelper.Encrypt(dto.Phone);
  1205. var urgentPhone = AesEncryptionHelper.Encrypt(dto.UrgentPhone);
  1206. var IDCard = AesEncryptionHelper.Encrypt(dto.IDCard);
  1207. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1208. {
  1209. CnName = dto.CnName,
  1210. EnName = dto.EnName,
  1211. Sex = dto.Sex,
  1212. Phone = phone,
  1213. UrgentPhone = urgentPhone,
  1214. Email = dto.Email,
  1215. Address = dto.Address,
  1216. Edate = dto.Edate,
  1217. Birthday = dto.Birthday,
  1218. IDCard = IDCard,
  1219. GraduateInstitutions = dto.GraduateInstitutions,
  1220. Professional = dto.Professional,
  1221. Education = dto.Education,
  1222. TheOrAdultEducation = dto.TheOrAdultEducation,
  1223. MaritalStatus = dto.MaritalStatus,
  1224. HomeAddress = dto.HomeAddress,
  1225. WorkExperience = dto.WorkExperience,
  1226. Certificate = dto.Certificate
  1227. });
  1228. if (!res)
  1229. {
  1230. return Ok(JsonView(false, "修改失败!"));
  1231. }
  1232. return Ok(JsonView(true, "修改成功!"));
  1233. }
  1234. }
  1235. /// <summary>
  1236. /// 删除用户信息
  1237. /// 即为离职
  1238. /// </summary>
  1239. /// <param name="dto"></param>
  1240. /// <returns></returns>
  1241. [HttpPost]
  1242. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1243. public async Task<IActionResult> PostUserDelById(UserDelDto dto)
  1244. {
  1245. if (dto == null)
  1246. {
  1247. return Ok(JsonView(false, "参数不能为空!"));
  1248. }
  1249. var _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  1250. if (_Users != null)
  1251. {
  1252. var sys_UsersList = _sqlSugar.Queryable<Sys_Users>().Where(a => a.IsDel == 0 && a.CompanyId == _Users.CompanyId).ToList();
  1253. if (sys_UsersList.Count == 1)
  1254. {
  1255. return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
  1256. }
  1257. }
  1258. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1259. {
  1260. IsDel = 1,
  1261. DeleteUserId = dto.OperateUserId,
  1262. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  1263. Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1264. });
  1265. if (!res)
  1266. {
  1267. return Ok(JsonView(false, "操作失败!"));
  1268. }
  1269. return Ok(JsonView(true, "操作成功!"));
  1270. }
  1271. /// <summary>
  1272. /// 员工信息
  1273. /// 人事审核
  1274. /// </summary>
  1275. /// <param name="dto"></param>
  1276. /// <returns></returns>
  1277. [HttpPost]
  1278. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1279. public async Task<IActionResult> PersonnelAudit(PersonnelAuditDto dto)
  1280. {
  1281. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  1282. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  1283. if (dto.IsAudit < 1 || dto.IsAudit > 2) return Ok(JsonView(false, "请传入有效的IsAudit参数!1:通过 2拒绝"));
  1284. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users { HrAudit = dto.IsAudit });
  1285. if (res)
  1286. {
  1287. //审核成功添加员工基础页面权限
  1288. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.Id).First();
  1289. int depId = 0, postId = 0;
  1290. if (userData != null) { depId = userData.DepId; postId = userData.JobPostId; }
  1291. bool s = DefaultPostAuth(depId, postId, dto.Id, dto.UserId);
  1292. string str = $"基础页面权限添加失败!";
  1293. if (s) str = $"基础页面权限添加成功!";
  1294. return Ok(JsonView(true, $"操作成功!{str}"));
  1295. }
  1296. return Ok(JsonView(false, "操作失败!"));
  1297. }
  1298. /// <summary>
  1299. /// 部门查询员工
  1300. /// </summary>
  1301. /// <param name="dto"></param>
  1302. /// <returns></returns>
  1303. [HttpPost]
  1304. public IActionResult QueryUserByDepart(QueryUserByDepartDto dto)
  1305. {
  1306. var jw = JsonView(false);
  1307. if (dto.DepartId < 1)
  1308. {
  1309. jw.Msg = "请传入正确的部门id";
  1310. return Ok(jw);
  1311. }
  1312. string sql = $@"SELECT * FROM Sys_Users su WHERE su.JobPostId in (SELECT id FROM Sys_JobPost sj WHERE sj.IsDel = 0 AND sj.DepId = {dto.DepartId} )
  1313. AND su.IsDel = 0 ";
  1314. var result = _sqlSugar.SqlQueryable<Sys_Users>(sql).Select(x => new
  1315. {
  1316. x.Id,
  1317. x.CnName,
  1318. x.EnName
  1319. }).ToList();
  1320. jw.Data = result;
  1321. jw.Code = 200;
  1322. jw.Msg = "获取成功!";
  1323. return Ok(jw);
  1324. }
  1325. #endregion
  1326. #region 权限模块
  1327. /// <summary>
  1328. /// 权限数据页面初始化
  1329. /// </summary>
  1330. /// <param name="dto"></param>
  1331. /// <returns></returns>
  1332. //[Authorize]
  1333. [HttpPost]
  1334. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1335. public async Task<IActionResult> GetAuth(AuthDto dto)
  1336. {
  1337. Result result = new Result();
  1338. //模块数据
  1339. var setDataResult = await _setDataRepository.GetSySDefultModule();
  1340. if (setDataResult.Code != 0)
  1341. {
  1342. return Ok(JsonView(setDataResult.Msg));
  1343. }
  1344. //操作方式
  1345. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1346. //获取所有关联页面
  1347. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1348. //页面数据
  1349. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
  1350. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1351. {
  1352. return Ok(JsonView("暂无数据"));
  1353. }
  1354. ArrayList viewData = new ArrayList();
  1355. //组合页面数据
  1356. foreach (var item in SystemMenuPermissionData)
  1357. {
  1358. ArrayList ids = new ArrayList();
  1359. foreach (var viewop in PageOperation)
  1360. {
  1361. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1362. if (op != null)
  1363. {
  1364. ids.Add(viewop.Id);
  1365. }
  1366. }
  1367. viewData.Add(new
  1368. {
  1369. Id = item.Id,
  1370. Mid = item.Mid,
  1371. Name = item.Name,
  1372. SystemMenuCode = item.SystemMenuCode,
  1373. opList = ids,
  1374. selList = new string[0]
  1375. });
  1376. }
  1377. //公司数据
  1378. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  1379. if (CompanyDataResult.Code != 0)
  1380. {
  1381. return Ok(JsonView(CompanyDataResult.Msg));
  1382. }
  1383. result.Code = 0;
  1384. result.Msg = "成功!";
  1385. var Dyresult = new
  1386. {
  1387. setDataResult = setDataResult.Data,
  1388. CompanyDataResult = CompanyDataResult.Data,
  1389. SystemMenuPermissionData = viewData,
  1390. PageOperation = PageOperation,
  1391. };
  1392. return Ok(JsonView(200, "成功!", Dyresult));
  1393. }
  1394. /// <summary>
  1395. /// 获取职务权限
  1396. /// </summary>
  1397. /// <param name="dto"></param>
  1398. /// <returns></returns>
  1399. [HttpPost]
  1400. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1401. public IActionResult QueryJobAuth(QueryJobAuthDto dto)
  1402. {
  1403. //选中的操作权限
  1404. var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x => x.JpId == dto.jobid).ToList();
  1405. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1406. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1407. {
  1408. return Ok(JsonView("暂无数据"));
  1409. }
  1410. //所有操作
  1411. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  1412. //获取所有关联页面
  1413. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1414. ArrayList viewData = new ArrayList();
  1415. //组合页面数据
  1416. foreach (var item in SystemMenuPermissionData)
  1417. {
  1418. ArrayList ids = new ArrayList();
  1419. foreach (var viewop in PageOperation)
  1420. {
  1421. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1422. if (op != null)
  1423. {
  1424. ids.Add(viewop.Id);
  1425. }
  1426. }
  1427. //获取本职务的页面拥有的权限
  1428. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
  1429. viewData.Add(new
  1430. {
  1431. Id = item.Id,
  1432. Mid = item.Mid,
  1433. Name = item.Name,
  1434. SystemMenuCode = item.SystemMenuCode,
  1435. opList = ids,
  1436. selList = DBwhere.Select(x => x.FId)
  1437. });
  1438. }
  1439. return Ok(JsonView(200, "成功!", viewData));
  1440. }
  1441. /// <summary>
  1442. /// 保存岗位权限
  1443. /// </summary>
  1444. /// <param name="dto"></param>
  1445. /// <returns></returns>
  1446. [HttpPost]
  1447. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1448. public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
  1449. {
  1450. //获取所有关联页面
  1451. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1452. var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
  1453. select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1454. where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
  1455. ").ToList();
  1456. List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
  1457. foreach (var item in dto.Savejobs)
  1458. {
  1459. foreach (var fid in item.FIds)
  1460. {
  1461. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1462. if (whereobj != null)
  1463. {
  1464. adds.Add(new Sys_JobPostAuthority
  1465. {
  1466. CreateTime = DateTime.Now,
  1467. CreateUserId = dto.UserId,
  1468. FId = fid,
  1469. JpId = dto.Jpid,
  1470. SmId = item.SmId
  1471. });
  1472. }
  1473. }
  1474. }
  1475. _JobPostAuthorityRepository.BeginTran();
  1476. try
  1477. { //删除岗位
  1478. bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
  1479. int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
  1480. //获取所有职位员工
  1481. var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
  1482. List<UserInfoWebView> users = null;
  1483. var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
  1484. if (QueryUserListApiResult != null)
  1485. {
  1486. if (QueryUserListApiResult.Code == 200)
  1487. {
  1488. users = QueryUserListApiResult.Data as List<UserInfoWebView>;
  1489. }
  1490. }
  1491. if (users != null && users.Count > 0)
  1492. {
  1493. List<Sys_UserAuthority> userAuth = null;
  1494. var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
  1495. var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1496. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1497. where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
  1498. ").ToList();
  1499. foreach (var user in users)
  1500. {
  1501. //删除个人级岗位权限
  1502. isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
  1503. (RemoveUserAuthorityListAndTemp.FindAll(x => x.UId == user.Id));
  1504. userAuth = adds.Select(x => new Sys_UserAuthority
  1505. {
  1506. CreateTime = DateTime.Now,
  1507. CreateUserId = dto.UserId,
  1508. FId = x.FId,
  1509. SmId = x.SmId,
  1510. UId = user.Id,
  1511. IsTemp = 1,
  1512. }).ToList();
  1513. //添加个人级别岗位
  1514. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1515. }
  1516. }
  1517. }
  1518. catch (Exception ex)
  1519. {
  1520. _JobPostAuthorityRepository.RollbackTran();
  1521. return Ok(JsonView("系统错误!"));
  1522. }
  1523. _JobPostAuthorityRepository.CommitTran();
  1524. return Ok(JsonView(200, "成功", new { }));
  1525. }
  1526. /// <summary>
  1527. /// 获取员工权限
  1528. /// </summary>
  1529. /// <param name="dto"></param>
  1530. /// <returns></returns>
  1531. [HttpPost]
  1532. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1533. public IActionResult QueryUserAuth(QueryUserAuthDto dto)
  1534. {
  1535. //选中的员工操作权限
  1536. var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
  1537. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1538. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1539. {
  1540. return Ok(JsonView("暂无数据"));
  1541. }
  1542. //所有操作
  1543. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1544. //获取所有关联页面
  1545. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1546. ArrayList viewData = new ArrayList();
  1547. //组合页面数据
  1548. foreach (var item in SystemMenuPermissionData)
  1549. {
  1550. ArrayList ids = new ArrayList();
  1551. foreach (var viewop in PageOperation)
  1552. {
  1553. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1554. if (op != null)
  1555. {
  1556. ids.Add(viewop.Id);
  1557. }
  1558. }
  1559. //获取本员工拥有的权限
  1560. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
  1561. viewData.Add(new
  1562. {
  1563. Id = item.Id,
  1564. Mid = item.Mid,
  1565. Name = item.Name,
  1566. SystemMenuCode = item.SystemMenuCode,
  1567. opList = ids,
  1568. selList = DBwhere.Select(x => x.FId)
  1569. });
  1570. }
  1571. return Ok(JsonView(200, "成功!", viewData));
  1572. }
  1573. /// <summary>
  1574. /// 根据Id获取员工所有移动端查看权限
  1575. /// </summary>
  1576. /// <param name="dto"></param>
  1577. /// <returns></returns>
  1578. [HttpPost]
  1579. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1580. public IActionResult QueryUserAuthByUserId(QueryUserAuthByUserIdDto dto)
  1581. {
  1582. string sql = string.Format(@" Select sd1.Id as ModuleId,sd1.Name as ModuleName,sm.Id as MenuId,sm.Name as MenuName From Sys_UserAuthority as u With(Nolock)
  1583. Inner Join Sys_SystemMenuPermission as sm With(Nolock) On u.SmId = sm.Id
  1584. Inner Join Sys_SetData as sd1 With(Nolock) On sm.Mid = sd1.Id
  1585. Where u.IsDel = 0 And sm.IsDel = 0
  1586. And u.UId = {0} And u.FId = 1 ", dto.UserId);
  1587. List<SystemModule_UserAuthSqlView> _dataSource = _sqlSugar.SqlQueryable<SystemModule_UserAuthSqlView>(sql).ToList();
  1588. List<SystemModule_UserAuthView> result = new List<SystemModule_UserAuthView>();
  1589. foreach (SystemModule_UserAuthSqlView item in _dataSource)
  1590. {
  1591. if (result.FirstOrDefault(s => s.ModuleId == item.ModuleId) == null)
  1592. {
  1593. List<SystemModule_UserAuthSqlView> tempList = _dataSource.Where(s => s.ModuleId == item.ModuleId).ToList();
  1594. List<SystemMenu_UserAuthView> menuList = new List<SystemMenu_UserAuthView>();
  1595. foreach (SystemModule_UserAuthSqlView item2 in tempList)
  1596. {
  1597. SystemMenu_UserAuthView menu = new SystemMenu_UserAuthView() { MenuId = item2.MenuId, MenuName = item2.MenuName };
  1598. menuList.Add(menu);
  1599. }
  1600. SystemModule_UserAuthView module = new SystemModule_UserAuthView() { MenuList = menuList, ModuleId = item.ModuleId, ModuleName = item.ModuleName };
  1601. result.Add(module);
  1602. }
  1603. }
  1604. return Ok(JsonView(200, "成功!", result));
  1605. }
  1606. /// <summary>
  1607. /// 保存员工权限
  1608. /// </summary>
  1609. /// <param name="dto"></param>
  1610. /// <returns></returns>
  1611. [HttpPost]
  1612. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1613. public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
  1614. {
  1615. //获取所有关联页面
  1616. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1617. //获取用户当前模块所有启用页面
  1618. var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1619. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1620. where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
  1621. ").ToList();
  1622. List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
  1623. foreach (var item in dto.Savejobs)
  1624. {
  1625. foreach (var fid in item.FIds)
  1626. {
  1627. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1628. if (whereobj != null)
  1629. {
  1630. adds.Add(new Sys_UserAuthority
  1631. {
  1632. CreateTime = DateTime.Now,
  1633. CreateUserId = dto.UserId,
  1634. FId = fid,
  1635. UId = dto.uid,
  1636. SmId = item.SmId,
  1637. IsTemp = 0
  1638. });
  1639. }
  1640. }
  1641. }
  1642. _JobPostAuthorityRepository.BeginTran();
  1643. try
  1644. {
  1645. List<Sys_UserAuthority> userAuth = null;
  1646. //删除个人级岗位权限
  1647. bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
  1648. userAuth = adds.Select(x => new Sys_UserAuthority
  1649. {
  1650. CreateTime = DateTime.Now,
  1651. CreateUserId = dto.UserId,
  1652. FId = x.FId,
  1653. SmId = x.SmId,
  1654. UId = dto.uid,
  1655. IsTemp = 0,
  1656. }).ToList();
  1657. //添加个人级别岗位
  1658. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1659. }
  1660. catch (Exception ex)
  1661. {
  1662. _JobPostAuthorityRepository.RollbackTran();
  1663. return Ok(JsonView("系统错误!"));
  1664. }
  1665. _JobPostAuthorityRepository.CommitTran();
  1666. return Ok(JsonView(200, "成功", new { }));
  1667. }
  1668. #endregion
  1669. #region 页面配置
  1670. /// <summary>
  1671. /// 页面配置界面数据初始化
  1672. /// </summary>
  1673. /// <returns></returns>
  1674. //[Authorize]
  1675. [HttpPost]
  1676. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1677. public async Task<IActionResult> PageConfigInit()
  1678. {
  1679. ArrayList arr = new ArrayList();
  1680. var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
  1681. if (viewList.Code != 0)
  1682. {
  1683. return Ok(JsonView(viewList.Msg));
  1684. }
  1685. var ModList = await _setDataRepository.GetSySDefultModule();
  1686. return Ok(JsonView(new
  1687. {
  1688. viewList,
  1689. ModList,
  1690. }));
  1691. }
  1692. [HttpPost]
  1693. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1694. public async Task<IActionResult> EditPageInfo(SetDataAndPageInfoDto dto)
  1695. {
  1696. JsonView view = null;
  1697. _SystemMenuPermissionRepository.BeginTran();
  1698. var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x => x.Id == dto.Pageid, x => new Sys_SystemMenuPermission
  1699. {
  1700. AndroidUrl = dto.AndroidUrl,
  1701. CreateTime = DateTime.Now,
  1702. Icon = dto.Icon,
  1703. IosUrl = dto.IosUrl,
  1704. Name = dto.PageName,
  1705. PhoneIsEnable = dto.PagePhoneIsEnable,
  1706. CreateUserId = dto.UserId,
  1707. IsDel = 0,
  1708. IsEnable = dto.PageIsEnable,
  1709. Mid = dto.Modulid,
  1710. Remark = dto.PageRemark,
  1711. SystemMenuCode = dto.SystemMenuCode,
  1712. WebUrl = dto.WebUrl,
  1713. });
  1714. if (istrue)
  1715. {
  1716. //删除页面绑定的操作后重新绑定
  1717. await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
  1718. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1719. foreach (var item in dto.FunArr)
  1720. {
  1721. binFun.Add(new Sys_SystemMenuAndFunction
  1722. {
  1723. CreateTime = DateTime.Now,
  1724. CreateUserId = dto.UserId,
  1725. FId = item,
  1726. SmId = dto.Pageid,
  1727. IsDel = 0,
  1728. });
  1729. }
  1730. int number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1731. view = JsonView(istrue);
  1732. _SystemMenuPermissionRepository.CommitTran();
  1733. }
  1734. else
  1735. {
  1736. _SystemMenuPermissionRepository.RollbackTran();
  1737. view = JsonView("添加失败");
  1738. }
  1739. return Ok(view);
  1740. }
  1741. /// <summary>
  1742. /// 添加一个页面
  1743. /// </summary>
  1744. /// <param name="dto"></param>
  1745. /// <returns></returns>
  1746. [HttpPost]
  1747. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1748. public async Task<IActionResult> AddPageInfo(SetDataAndPageInfoDto dto)
  1749. {
  1750. JsonView view = null;
  1751. _SystemMenuPermissionRepository.BeginTran();
  1752. int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
  1753. {
  1754. AndroidUrl = dto.AndroidUrl,
  1755. CreateTime = DateTime.Now,
  1756. Icon = dto.Icon,
  1757. IosUrl = dto.IosUrl,
  1758. Name = dto.PageName,
  1759. PhoneIsEnable = dto.PagePhoneIsEnable,
  1760. CreateUserId = dto.UserId,
  1761. IsDel = 0,
  1762. IsEnable = dto.PageIsEnable,
  1763. Mid = dto.Modulid,
  1764. Remark = dto.PageRemark,
  1765. SystemMenuCode = dto.SystemMenuCode,
  1766. WebUrl = dto.WebUrl,
  1767. });
  1768. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1769. foreach (var item in dto.FunArr)
  1770. {
  1771. binFun.Add(new Sys_SystemMenuAndFunction
  1772. {
  1773. CreateTime = DateTime.Now,
  1774. CreateUserId = dto.UserId,
  1775. FId = item,
  1776. SmId = number,
  1777. IsDel = 0,
  1778. });
  1779. }
  1780. number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1781. if (number > 0)
  1782. {
  1783. view = JsonView(number);
  1784. _SystemMenuPermissionRepository.CommitTran();
  1785. }
  1786. else
  1787. {
  1788. _SystemMenuPermissionRepository.RollbackTran();
  1789. view = JsonView("添加失败");
  1790. }
  1791. return Ok(view);
  1792. }
  1793. /// <summary>
  1794. /// 删除页面
  1795. /// </summary>
  1796. /// <param></param>
  1797. /// <returns></returns>
  1798. [HttpPost]
  1799. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1800. public async Task<IActionResult> DelPageInfo(List<SystemMenuDelDto> Dto)
  1801. {
  1802. JsonView view = new JsonView();
  1803. if (Dto.Count > 0)
  1804. {
  1805. try
  1806. {
  1807. _SystemMenuPermissionRepository.BeginTran();
  1808. bool istrue = false;
  1809. foreach (var item in Dto)
  1810. {
  1811. istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
  1812. if (!istrue)
  1813. {
  1814. throw new Exception("修改失败");
  1815. }
  1816. }
  1817. view.Code = 200;
  1818. view.Msg = "删除成功!";
  1819. view.Data = istrue;
  1820. _SystemMenuPermissionRepository.CommitTran();
  1821. }
  1822. catch (Exception)
  1823. {
  1824. _SystemMenuPermissionRepository.RollbackTran();
  1825. }
  1826. }
  1827. return Ok(JsonView(view));
  1828. }
  1829. /// <summary>
  1830. /// 获取页面绑定的操作
  1831. /// </summary>
  1832. /// <param name="Dto"></param>
  1833. /// <returns></returns>
  1834. [HttpPost]
  1835. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1836. public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
  1837. {
  1838. //页面与操作关联表
  1839. var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1840. //页面功能表
  1841. var pageFunList = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1842. ArrayList arr = new ArrayList();
  1843. foreach (var item in pageFunList)
  1844. {
  1845. var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
  1846. if (FindVal == null)
  1847. {
  1848. arr.Add(new
  1849. {
  1850. id = item.Id,
  1851. name = item.FunctionName,
  1852. value = false
  1853. });
  1854. }
  1855. else
  1856. {
  1857. arr.Add(new
  1858. {
  1859. id = item.Id,
  1860. name = item.FunctionName,
  1861. value = true
  1862. });
  1863. }
  1864. }
  1865. return Ok(JsonView(arr));
  1866. }
  1867. #endregion
  1868. #region 页面操作
  1869. /// <summary>
  1870. /// 操作权限功能表
  1871. /// </summary>
  1872. /// <returns></returns>
  1873. [HttpPost]
  1874. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1875. public async Task<IActionResult> PageFunInit()
  1876. {
  1877. var PageFunInit = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, PageFunctionPermissionView>().ToList();
  1878. if (PageFunInit == null)
  1879. {
  1880. return Ok(JsonView(false, "暂无数据!"));
  1881. }
  1882. return Ok(JsonView(true, "查询成功!", PageFunInit));
  1883. }
  1884. /// <summary>
  1885. /// 操作权限功能表操作(Status 1:添加,2:编辑)
  1886. /// </summary>
  1887. /// <returns></returns>
  1888. [HttpPost]
  1889. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1890. public async Task<IActionResult> OperationFun(OperationFunInitDta dto)
  1891. {
  1892. Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
  1893. if (result.Code != 0)
  1894. {
  1895. return Ok(JsonView(false, result.Msg));
  1896. }
  1897. return Ok(JsonView(true, result.Msg));
  1898. }
  1899. /// <summary>
  1900. /// 删除功能
  1901. /// </summary>
  1902. /// <param name="dto"></param>
  1903. /// <returns></returns>
  1904. [HttpPost]
  1905. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1906. public async Task<IActionResult> DelFun(DelFunInitDta dto)
  1907. {
  1908. var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync<Sys_PageFunctionPermission>(dto.Id.ToString(), dto.DeleteUserId);
  1909. if (!res)
  1910. {
  1911. return Ok(JsonView(false, "删除失败"));
  1912. }
  1913. return Ok(JsonView(true, "删除成功!"));
  1914. }
  1915. #endregion
  1916. #region 各部门首页消息提示
  1917. /// <summary>
  1918. /// 部门首页消息提示
  1919. /// </summary>
  1920. /// <returns></returns>
  1921. [HttpGet("{portType}")]
  1922. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1923. public async Task<IActionResult> DepartmentHomePageMessagePrompts(int portType)
  1924. {
  1925. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1926. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1927. var department = currUserInfo.Department;
  1928. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1929. if (portType == 1 || portType == 2 || portType == 3) // web
  1930. {
  1931. //固定查询时间(当前月的上月)
  1932. var lastMoth = DateTime.Now.AddMonths(-1);
  1933. var (startDate, endDate) = CommonFun.GetMonthStartAndEndDates(lastMoth.Year, lastMoth.Month);
  1934. var startDateTime = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00"));
  1935. var endDateTime = Convert.ToDateTime(endDate.ToString("yyyy-MM-dd 23:59:59"));
  1936. //固定查询时间(本年)
  1937. var currStartDate = Convert.ToDateTime($"{DateTime.Now.Year}-01-01 00:00:00");
  1938. var currEntDate = Convert.ToDateTime($"{DateTime.Now.Year}-12-31 23:59:59");
  1939. if (department.Equals("总经办")) //总经办
  1940. {
  1941. //1、资料数据(市场部客户资源、op地接导游、op地接车数据、商邀数据、团组收款数据)数据提示Range(固定上个月) -- Add
  1942. #region 市场部客户资源
  1943. //1.1 市场部客户资源
  1944. var users = await _sqlSugar.Queryable<Sys_Users>()
  1945. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1946. .Where((u, d) => u.IsDel == 0 && (d.DepName.Contains("市场部") || u.Id == 21))
  1947. .Select((u, d) => new { u.Id, u.CnName })
  1948. .ToListAsync();
  1949. var marketData = await _sqlSugar.Queryable<Crm_NewClientData>()
  1950. .LeftJoin<Sys_Users>((ncd, u) => ncd.CreateUserId == u.Id)
  1951. .Where((ncd, u) => ncd.IsDel == 0 && ncd.CreateTime >= startDateTime && ncd.CreateTime <= endDateTime)
  1952. .Select((ncd, u) => new
  1953. {
  1954. Area = ncd.Location,
  1955. ncd.Client,
  1956. ncd.Contact,
  1957. ncd.Job,
  1958. Tel = ncd.Telephone,
  1959. ncd.CreateUserId,
  1960. CreatleUserName = u.CnName,
  1961. ncd.CreateTime,
  1962. })
  1963. .ToListAsync();
  1964. foreach (var item in marketData) EncryptionProcessor.DecryptProperties(item);
  1965. var marketDataGroup = marketData.GroupBy(x => x.CreateUserId).Select(g => new { CreateUserId = g.Key, Items = g.ToList(), Count = g.Count() });
  1966. var marketData2 = new List<dynamic>();
  1967. foreach (var user in users)
  1968. {
  1969. var userMarketData = marketDataGroup.FirstOrDefault(x => user.Id == x.CreateUserId);
  1970. if (userMarketData != null)
  1971. {
  1972. marketData2.Add(new
  1973. {
  1974. uId = user.Id,
  1975. name = user.CnName,
  1976. count = userMarketData.Count,
  1977. msgTips = $"上月新增市场客户资源共{userMarketData.Count}条",
  1978. userMarketData = userMarketData.Items
  1979. });
  1980. }
  1981. else
  1982. {
  1983. marketData2.Add(new
  1984. {
  1985. uId = user.Id,
  1986. name = user.CnName,
  1987. count = 0,
  1988. msgTips = $"上月新增市场客户资源共{0}条",
  1989. userMarketData = new List<dynamic>() { },
  1990. });
  1991. }
  1992. }
  1993. var marketData1 = new
  1994. {
  1995. msgTips = $"上月新增市场客户资源共{marketData.Count}条",
  1996. Data = marketData2,
  1997. };
  1998. #endregion
  1999. #region op地接导游
  2000. //1.2 op地接导游
  2001. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2002. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2003. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2004. .Select((lgd, u) => new
  2005. {
  2006. Area = lgd.UnitArea,
  2007. Client = lgd.UnitName,
  2008. lgd.Contact,
  2009. Job = "",
  2010. Tel = lgd.ContactTel,
  2011. lgd.CreateUserId,
  2012. CreatleUserName = u.CnName,
  2013. lgd.CreateTime,
  2014. })
  2015. .ToListAsync();
  2016. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2017. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2018. .Select(g => new {
  2019. uId = g.Key,
  2020. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2021. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2022. userTourGuideData = g.ToList(),
  2023. Count = g.Count()
  2024. });
  2025. var opTourGuideData1 = new
  2026. {
  2027. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2028. Data = opTourGuideDataGroups,
  2029. };
  2030. #endregion
  2031. #region op车数据
  2032. //1.3 op车数据
  2033. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2034. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2035. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2036. .Select((cd, u) => new CarDataMsgTipsView()
  2037. {
  2038. Area = cd.UnitArea,
  2039. Client = cd.UnitName,
  2040. Contact = cd.Contact,
  2041. Job = "",
  2042. Tel = cd.ContactTel,
  2043. CreateUserId = cd.CreateUserId,
  2044. CreatleUserName = u.CnName,
  2045. CreateTime = cd.CreateTime,
  2046. })
  2047. .ToListAsync();
  2048. foreach (var item in opCarData) EncryptionProcessor.DecryptProperties(item);
  2049. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2050. .Select(g => new {
  2051. uId = g.Key,
  2052. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2053. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2054. userTourGuideData = g.ToList(),
  2055. Count = g.Count()
  2056. });
  2057. var opCarData1 = new
  2058. {
  2059. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2060. Data = opCarDataGroups,
  2061. };
  2062. #endregion
  2063. #region 商邀数据
  2064. //1.4 商邀数据
  2065. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2066. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2067. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2068. .Select((ioa, u) => new
  2069. {
  2070. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2071. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2072. Client = ioa.UnitName,
  2073. ioa.Contact,
  2074. ioa.Job,
  2075. ioa.Tel,
  2076. ioa.CreateUserId,
  2077. CreatleUserName = u.CnName,
  2078. ioa.CreateTime,
  2079. })
  2080. .ToListAsync();
  2081. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2082. .Select(g => new {
  2083. uId = g.Key,
  2084. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2085. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2086. userTourGuideData = g.ToList(),
  2087. Count = g.Count()
  2088. });
  2089. var invitationData1 = new
  2090. {
  2091. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2092. Data = invitationGroups,
  2093. };
  2094. #endregion
  2095. #region 团组收款数据
  2096. //1.5 团组收款数据
  2097. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2098. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2099. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2100. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2101. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2102. .Select((fr, u, di, sd) => new
  2103. {
  2104. fr.PriceName,
  2105. fr.Price,
  2106. fr.Count,
  2107. fr.Unit,
  2108. fr.ItemSumPrice,
  2109. Currency = sd.Name,
  2110. GroupName = di.TeamName,
  2111. fr.CreateUserId,
  2112. CreateUserName = u.CnName,
  2113. fr.CreateTime,
  2114. })
  2115. .ToListAsync();
  2116. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2117. .Select(g => new
  2118. {
  2119. uId = g.Key,
  2120. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2121. msgTips = $"上月累计团组收款共{g.Count()}条",
  2122. userTourGuideData = g.ToList(),
  2123. Count = g.Count()
  2124. });
  2125. var groupCollectionData2 = new
  2126. {
  2127. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2128. Data = groupCollectionGroups,
  2129. };
  2130. #endregion
  2131. var materialData = new
  2132. {
  2133. marketData = marketData1,
  2134. opTourGuideData = opTourGuideData1,
  2135. opCarData = opCarData1,
  2136. invitationData = invitationData1,
  2137. groupCollectionData = groupCollectionData2
  2138. };
  2139. //2、费用未审核(日付申请未审核数据、团组费用未审核数据)费用提示Range(固定本年)
  2140. #region 日付申请未审核数据
  2141. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2142. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2143. .Where(dfp => dfp.IsDel == 0 &&
  2144. dfp.MAudit == 0 &&
  2145. dfp.CreateTime >= currStartDate &&
  2146. dfp.CreateTime <= currEntDate
  2147. )
  2148. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2149. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2150. .Select((dfp, u) => new
  2151. {
  2152. id = dfp.Id,
  2153. amountName = dfp.Instructions,
  2154. amount = dfp.SumPrice,
  2155. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2156. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2157. fAuditDate = dfp.FAuditDate,
  2158. dfp.CreateUserId,
  2159. CreateUserName = u.CnName,
  2160. dfp.CreateTime
  2161. })
  2162. .ToListAsync();
  2163. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2164. .Select(g => new
  2165. {
  2166. uId = g.Key,
  2167. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2168. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2169. userTourGuideData = g.ToList(),
  2170. Count = g.Count()
  2171. });
  2172. var dailyPaymentData1 = new
  2173. {
  2174. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2175. Data = dailyPaymentGroups,
  2176. };
  2177. #endregion
  2178. #region 团组费用未审核数据
  2179. var groupPaymentData = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  2180. .LeftJoin<Grp_DelegationInfo>((ccp, di) => ccp.DIId == di.Id)
  2181. .Where((ccp, di) => ccp.IsDel == 0 &&
  2182. ccp.IsAuditGM == 0 &&
  2183. ccp.CreateTime >= currStartDate &&
  2184. ccp.CreateTime <= currEntDate
  2185. )
  2186. .Select((ccp, di) => new
  2187. {
  2188. ccp.Id,
  2189. ccp.DIId,
  2190. GroupName = di.TeamName,
  2191. ccp.CreateTime,
  2192. })
  2193. .ToListAsync();
  2194. var groupPaymentGroups = groupPaymentData.GroupBy(x => x.DIId)
  2195. .Select(g => new
  2196. {
  2197. uId = g.Key,
  2198. name = g.ToList().FirstOrDefault()?.GroupName ?? "-",
  2199. msgTips = $"本年有{g.Count()}条未审核团组费用申请条",
  2200. userTourGuideData = g.ToList(),
  2201. Count = g.Count()
  2202. });
  2203. var groupPaymentData1 = new
  2204. {
  2205. msgTips = $"本年有{groupPaymentData.Count()}条未审核团组费用申请条",
  2206. Data = groupPaymentGroups,
  2207. };
  2208. #endregion
  2209. var feeUnAuditData = new
  2210. {
  2211. dailyPaymentData = dailyPaymentData1,
  2212. groupPaymentData = groupPaymentData1
  2213. };
  2214. return Ok(JsonView(new { materialData = materialData, feeUnAuditData = feeUnAuditData }));
  2215. }
  2216. else if (department.Equals("国交部"))//国交部
  2217. {
  2218. #region 团组费用录入提示
  2219. /*
  2220. * 名称:团组费用录入提示
  2221. * 描述:团组费用录入提醒(根据团组结束时间 - 3天 如果对应的数据表里没有这个团组的费用信息)
  2222. * 条件:时间范围不限制、 根据团组结束时间 - 3天 == 当前天数
  2223. */
  2224. var groupModlue = new List<int>() {
  2225. 76, //酒店预订
  2226. 79, //车/导游地接
  2227. 80, //签证
  2228. 81, //邀请/公务活动
  2229. //82, //团组客户保险
  2230. 85, //机票预订
  2231. 98, //其他款项
  2232. //285 ,//收款退还
  2233. //1015,//超支费用
  2234. };
  2235. var crrDate = DateTime.Now.ToString("yyyy-MM-dd");
  2236. var groupModlueData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => groupModlue.Contains(x.Id)).ToListAsync();
  2237. var groupFeeData = await _sqlSugar.Queryable<Sys_SetData>()
  2238. .LeftJoin<Grp_CreditCardPayment>((sd, ccp) => sd.Id == ccp.CTable)
  2239. .LeftJoin<Grp_DelegationInfo>((sd, ccp, di) => ccp.DIId == di.Id)
  2240. .Where((sd, ccp, di) => ccp.IsDel == 0 &&
  2241. di.IsDel == 0 &&
  2242. groupModlue.Contains(ccp.CTable) &&
  2243. di.VisitEndDate.AddDays(-3).ToString("yyyy-MM-dd").Equals(crrDate)
  2244. )
  2245. .GroupBy((sd, ccp, di) => new { di.Id, di.TeamName, ccp.CTable, sd.Name }) //可以多字段
  2246. .Select((sd, ccp, di) => new {
  2247. diId = di.Id,
  2248. groupName = di.TeamName,
  2249. groupType = ccp.CTable,
  2250. groupTypeName = sd.Name,
  2251. //userId = ccp.CreateUserId,
  2252. count = SqlFunc.AggregateCount(ccp.CTable),
  2253. })
  2254. .ToListAsync();
  2255. var groupFeeData1 = groupFeeData.GroupBy(x => x.diId);
  2256. var groupNotFilledFeeData = new List<dynamic>();
  2257. foreach (var groupFee in groupFeeData1)
  2258. {
  2259. var diId = groupFee.Key;
  2260. var addData = groupFeeData.Where(x => x.diId == diId).Select(x => x.groupType).ToList();
  2261. if (addData.Count < 1) continue;
  2262. var unAddData = groupModlue.Except(addData).ToList();
  2263. if (unAddData.Count < 1) continue;
  2264. foreach (var typeId in unAddData)
  2265. {
  2266. groupNotFilledFeeData.Add(new
  2267. {
  2268. diId = diId,
  2269. groupName = groupFee.FirstOrDefault()?.groupName ?? "-",
  2270. groupType = typeId,
  2271. groupTypeName = groupModlueData.Find(x => x.Id == typeId)?.Name ?? "-",
  2272. count = 0
  2273. });
  2274. }
  2275. }
  2276. #endregion
  2277. #region 日付申请 -- 未审核数据
  2278. var depUserData = await _sqlSugar.Queryable<Sys_Users>()
  2279. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2280. .LeftJoin<Sys_JobPost>((u, d, jp) => u.JobPostId == jp.Id)
  2281. .Where((u, d, jp) => u.IsDel == 0 && d.DepName.Contains("国交部"))
  2282. .Select((u, d, jp) => new
  2283. {
  2284. u.Id,
  2285. u.CnName,
  2286. u.DepId,
  2287. d.DepName,
  2288. u.JobPostId,
  2289. jp.JobName
  2290. })
  2291. .ToListAsync();
  2292. var depUserData1 = depUserData.Select(x => x.Id).ToList();
  2293. var unAuditDailyFeeData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2294. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2295. .Where((dfp, u) => dfp.IsDel == 0 &&
  2296. depUserData1.Contains(dfp.CreateUserId) &&
  2297. dfp.MAudit == 0 &&
  2298. dfp.CreateTime >= currStartDate &&
  2299. dfp.CreateTime <= currEntDate
  2300. )
  2301. .Select((dfp, u) => new
  2302. {
  2303. id = dfp.Id,
  2304. amountName = dfp.Instructions,
  2305. amount = dfp.SumPrice,
  2306. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2307. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2308. fAuditDate = dfp.FAuditDate,
  2309. dfp.CreateUserId,
  2310. CreateUserName = u.CnName,
  2311. dfp.CreateTime
  2312. })
  2313. .ToArrayAsync();
  2314. #endregion
  2315. var jobs = new List<string>() { "经理", "主管" };
  2316. if (jobs.Contains( currUserInfo.Role)) //经理、主管
  2317. {
  2318. #region 经理、主管
  2319. //经理、主管(部门下所有人员) --> 日付(-:未审核提示)、团组费用录入提醒(根据团组结束时间-3天 如果对应的数据表里没有这个团组的费用信息)
  2320. var dailyPaymentData = new
  2321. {
  2322. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2323. Data = new
  2324. {
  2325. uId = currUserInfo.UserId,
  2326. name = currUserInfo.UserName,
  2327. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2328. userTourGuideData = unAuditDailyFeeData,
  2329. Count = unAuditDailyFeeData.Count()
  2330. }
  2331. };
  2332. var groupNotFilledFeeDataAll = groupNotFilledFeeData
  2333. .GroupBy(x => x.diId)
  2334. .Select(g => new
  2335. {
  2336. uId = g.Key,
  2337. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2338. msgTips = $"-",
  2339. hotelFeeData = g.Select(x1 => new
  2340. {
  2341. x1.groupType,
  2342. x1.groupTypeName
  2343. }).ToList(),
  2344. Count = g.Count()
  2345. })
  2346. .ToList();
  2347. var groupNotFillEdFeeData1 = new
  2348. {
  2349. msgTips = $"今天有{groupNotFilledFeeDataAll.Count()}个团组费用未填写",
  2350. Data = groupNotFilledFeeDataAll,
  2351. };
  2352. #endregion
  2353. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2354. }
  2355. else if (currUserInfo.Role.Equals("计调"))//计调
  2356. {
  2357. #region 计调
  2358. //计调(myself) --> 暂定
  2359. return Ok(JsonView(false, "国交部-->计调岗位消息提示正在开发中......"));
  2360. #endregion
  2361. }
  2362. else if (currUserInfo.Role.Equals("机票"))//机票
  2363. {
  2364. #region 机票
  2365. //机票(myself) --> 日付(-:未审核提示)、机票费用(-:未录入提示)
  2366. var airTicket_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2367. var dailyPaymentData = new
  2368. {
  2369. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2370. Data = new
  2371. {
  2372. uId = currUserInfo.UserId,
  2373. name = currUserInfo.UserName,
  2374. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2375. userTourGuideData = airTicket_unAuditDailyFeeData,
  2376. Count = airTicket_unAuditDailyFeeData.Count()
  2377. }
  2378. };
  2379. var airTicket_groupNotFilledData = groupNotFilledFeeData
  2380. .Where(x => x.groupType == 85)
  2381. .GroupBy(x => x.diId)
  2382. .Select(g => new
  2383. {
  2384. uId = g.Key,
  2385. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2386. msgTips = $"-",
  2387. airTicketFeeData = g.Select(x1 => new
  2388. {
  2389. x1.groupType,
  2390. x1.groupTypeName
  2391. }).ToList(),
  2392. Count = g.Count()
  2393. })
  2394. .ToList();
  2395. var groupNotFillEdFeeData1 = new
  2396. {
  2397. msgTips = $"今天有{airTicket_groupNotFilledData.Count()}个团组费用未填写",
  2398. Data = airTicket_groupNotFilledData,
  2399. };
  2400. #endregion
  2401. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2402. }
  2403. else if (currUserInfo.Role.Equals("酒店"))//酒店
  2404. {
  2405. #region 酒店
  2406. //酒店(myself) --> 日付(-:未审核提示)、酒店费用(-:未录入提示)
  2407. var hotle_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2408. var dailyPaymentData = new
  2409. {
  2410. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2411. Data = new
  2412. {
  2413. uId = currUserInfo.UserId,
  2414. name = currUserInfo.UserName,
  2415. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2416. hotelFeeData = hotle_unAuditDailyFeeData,
  2417. Count = hotle_unAuditDailyFeeData.Count()
  2418. }
  2419. };
  2420. var hotel_groupNotFilledData = groupNotFilledFeeData
  2421. .Where(x => x.groupType == 76)
  2422. .GroupBy(x => x.diId)
  2423. .Select(g => new
  2424. {
  2425. uId = g.Key,
  2426. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2427. msgTips = $"-",
  2428. hotelFeeData = g.Select(x1 => new
  2429. {
  2430. x1.groupType,
  2431. x1.groupTypeName
  2432. }).ToList(),
  2433. Count = g.Count()
  2434. })
  2435. .ToList();
  2436. var groupNotFillEdFeeData1 = new
  2437. {
  2438. msgTips = $"今天有{hotel_groupNotFilledData.Count()}个团组费用未填写",
  2439. Data = hotel_groupNotFilledData,
  2440. };
  2441. #endregion
  2442. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2443. }
  2444. else if (currUserInfo.Role.Equals("签证"))//签证
  2445. {
  2446. #region 签证
  2447. //签证(myself) --> 日付(-:未审核提示)、签证费用(-:未录入提示)
  2448. var visa_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2449. var dailyPaymentData = new
  2450. {
  2451. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2452. Data = new
  2453. {
  2454. uId = currUserInfo.UserId,
  2455. name = currUserInfo.UserName,
  2456. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2457. visaFeeData = visa_unAuditDailyFeeData,
  2458. Count = visa_unAuditDailyFeeData.Count()
  2459. }
  2460. };
  2461. var visa_groupNotFilledData = groupNotFilledFeeData
  2462. .Where(x => x.groupType == 80)
  2463. .GroupBy(x => x.diId)
  2464. .Select(g => new
  2465. {
  2466. uId = g.Key,
  2467. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2468. msgTips = $"-",
  2469. airTicketFeeData = g.Select(x1 => new
  2470. {
  2471. x1.groupType,
  2472. x1.groupTypeName
  2473. }).ToList(),
  2474. Count = g.Count()
  2475. })
  2476. .ToList();
  2477. var groupNotFillEdFeeData1 = new
  2478. {
  2479. msgTips = $"今天有{visa_groupNotFilledData.Count()}个团组费用未填写",
  2480. Data = visa_groupNotFilledData,
  2481. };
  2482. #endregion
  2483. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2484. }
  2485. else if (currUserInfo.Role.Equals("商邀"))//商邀
  2486. {
  2487. #region 商邀
  2488. //商邀(myself) --> 日付(-:未审核提示)、商邀费用(-:未录入提示)、(公务、翻译人)(-:新增提示)
  2489. //日付
  2490. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2491. var dailyPaymentData = new
  2492. {
  2493. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2494. Data = new
  2495. {
  2496. uId = currUserInfo.UserId,
  2497. name = currUserInfo.UserName,
  2498. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2499. visaFeeData = in_unAuditDailyFeeData,
  2500. Count = in_unAuditDailyFeeData.Count()
  2501. }
  2502. };
  2503. //团组未录入费用
  2504. var in_groupNotFilledData = groupNotFilledFeeData
  2505. .Where(x => x.groupType == 81)
  2506. .GroupBy(x => x.diId)
  2507. .Select(g => new
  2508. {
  2509. uId = g.Key,
  2510. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2511. msgTips = $"-",
  2512. airTicketFeeData = g.Select(x1 => new
  2513. {
  2514. x1.groupType,
  2515. x1.groupTypeName
  2516. }).ToList(),
  2517. Count = g.Count()
  2518. })
  2519. .ToList();
  2520. var groupNotFillEdFeeData1 = new
  2521. {
  2522. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2523. Data = in_groupNotFilledData,
  2524. };
  2525. //商邀 - 基础数据
  2526. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2527. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2528. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2529. .Select((ioa, u) => new
  2530. {
  2531. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2532. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2533. Client = ioa.UnitName,
  2534. ioa.Contact,
  2535. ioa.Job,
  2536. ioa.Tel,
  2537. ioa.CreateUserId,
  2538. CreatleUserName = u.CnName,
  2539. ioa.CreateTime,
  2540. })
  2541. .ToListAsync();
  2542. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2543. .Select(g => new {
  2544. uId = g.Key,
  2545. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2546. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2547. userTourGuideData = g.ToList(),
  2548. Count = g.Count()
  2549. });
  2550. var invitationData1 = new
  2551. {
  2552. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2553. Data = invitationGroups,
  2554. };
  2555. #endregion
  2556. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData, invitationData = invitationData }));
  2557. }
  2558. else if (currUserInfo.Role.Equals("OP"))//OP
  2559. {
  2560. #region OP
  2561. //OP(myself) --> 日付(-:未审核提示)、OP费用(-:未录入提示)、(导游、车)资源信息(-:新增提示)
  2562. //日付
  2563. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2564. var dailyPaymentData = new
  2565. {
  2566. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2567. Data = new
  2568. {
  2569. uId = currUserInfo.UserId,
  2570. name = currUserInfo.UserName,
  2571. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2572. visaFeeData = in_unAuditDailyFeeData,
  2573. Count = in_unAuditDailyFeeData.Count()
  2574. }
  2575. };
  2576. //OP - 团组未录入费用
  2577. var in_groupNotFilledData = groupNotFilledFeeData
  2578. .Where(x => x.groupType == 79)
  2579. .GroupBy(x => x.diId)
  2580. .Select(g => new
  2581. {
  2582. uId = g.Key,
  2583. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2584. msgTips = $"-",
  2585. airTicketFeeData = g.Select(x1 => new
  2586. {
  2587. x1.groupType,
  2588. x1.groupTypeName
  2589. }).ToList(),
  2590. Count = g.Count()
  2591. })
  2592. .ToList();
  2593. var groupNotFillEdFeeData1 = new
  2594. {
  2595. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2596. Data = in_groupNotFilledData,
  2597. };
  2598. #region op地接导游
  2599. //1.2 op地接导游
  2600. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2601. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2602. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2603. .Select((lgd, u) => new
  2604. {
  2605. Area = lgd.UnitArea,
  2606. Client = lgd.UnitName,
  2607. lgd.Contact,
  2608. Job = "",
  2609. Tel = lgd.ContactTel,
  2610. lgd.CreateUserId,
  2611. CreatleUserName = u.CnName,
  2612. lgd.CreateTime,
  2613. })
  2614. .ToListAsync();
  2615. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2616. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2617. .Select(g => new {
  2618. uId = g.Key,
  2619. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2620. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2621. userTourGuideData = g.ToList(),
  2622. Count = g.Count()
  2623. });
  2624. var opTourGuideData1 = new
  2625. {
  2626. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2627. Data = opTourGuideDataGroups,
  2628. };
  2629. #endregion
  2630. #region op车数据
  2631. //1.3 op车数据
  2632. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2633. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2634. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2635. .Select((cd, u) => new
  2636. {
  2637. Area = cd.UnitArea,
  2638. Client = cd.UnitName,
  2639. cd.Contact,
  2640. Job = "",
  2641. Tel = cd.ContactTel,
  2642. cd.CreateUserId,
  2643. CreatleUserName = u.CnName,
  2644. cd.CreateTime,
  2645. })
  2646. .ToListAsync();
  2647. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2648. .Select(g => new {
  2649. uId = g.Key,
  2650. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2651. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2652. userTourGuideData = g.ToList(),
  2653. Count = g.Count()
  2654. });
  2655. var opCarData1 = new
  2656. {
  2657. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2658. Data = opCarDataGroups,
  2659. };
  2660. #endregion
  2661. #endregion
  2662. return Ok(JsonView(new
  2663. {
  2664. groupNotFillEdFeeData = groupNotFillEdFeeData1,
  2665. dailyPaymentData = dailyPaymentData,
  2666. CarData = opCarData1,
  2667. TourGuideData = opTourGuideData
  2668. }));
  2669. }
  2670. return Ok(JsonView(false, "国交部消息提示正在开发中......"));
  2671. }
  2672. else if (department.Equals("财务部"))//总经办
  2673. {
  2674. #region 团组收款数据
  2675. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2676. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2677. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2678. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2679. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2680. .Select((fr, u, di, sd) => new
  2681. {
  2682. fr.PriceName,
  2683. fr.Price,
  2684. fr.Count,
  2685. fr.Unit,
  2686. fr.ItemSumPrice,
  2687. Currency = sd.Name,
  2688. GroupName = di.TeamName,
  2689. fr.CreateUserId,
  2690. CreateUserName = u.CnName,
  2691. fr.CreateTime,
  2692. })
  2693. .ToListAsync();
  2694. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2695. .Select(g => new
  2696. {
  2697. uId = g.Key,
  2698. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2699. msgTips = $"上月累计团组收款共{g.Count()}条",
  2700. userTourGuideData = g.ToList(),
  2701. Count = g.Count()
  2702. });
  2703. var groupCollectionData1 = new
  2704. {
  2705. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2706. Data = groupCollectionGroups,
  2707. };
  2708. #endregion
  2709. #region 日付申请未审核数据
  2710. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2711. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2712. .Where(dfp => dfp.IsDel == 0 &&
  2713. dfp.MAudit == 0 &&
  2714. dfp.CreateTime >= currStartDate &&
  2715. dfp.CreateTime <= currEntDate
  2716. )
  2717. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2718. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2719. .Select((dfp, u) => new
  2720. {
  2721. id = dfp.Id,
  2722. amountName = dfp.Instructions,
  2723. amount = dfp.SumPrice,
  2724. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2725. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2726. fAuditDate = dfp.FAuditDate,
  2727. dfp.CreateUserId,
  2728. CreateUserName = u.CnName,
  2729. dfp.CreateTime
  2730. })
  2731. .ToListAsync();
  2732. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2733. .Select(g => new
  2734. {
  2735. uId = g.Key,
  2736. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2737. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2738. userTourGuideData = g.ToList(),
  2739. Count = g.Count()
  2740. });
  2741. var dailyPaymentData1 = new
  2742. {
  2743. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2744. Data = dailyPaymentGroups,
  2745. };
  2746. #endregion
  2747. return Ok(JsonView(new { groupCollectionData = groupCollectionData1, dailyPaymentData = dailyPaymentData1 }));
  2748. }
  2749. return Ok(JsonView(false,"其余部门消息提示正在开发者中......"));
  2750. }
  2751. return Ok(JsonView(false));
  2752. }
  2753. #endregion
  2754. }
  2755. }