SystemController.cs 130 KB

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