SystemController.cs 136 KB

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