| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272 |
- using MadRunFabric.Common;
- using MadRunFabric.Common.Options;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MongoDB.Driver;
- using SignTokenApi.IRepositories;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MadRunFabirc.Model;
- using MadRunFabric.Model;
- namespace SignTokenApi.Repositories
- {
- public class Sys_User_AccountRepository : BaseRepository<Sys_User_Account, string>, ISys_User_AccountRepository
- {
- protected readonly ILogger<BaseRepository<Sys_User_Account, string>> _logger;
- protected readonly IMongoCollection<Sys_Department> _collection_sysdepartment;
- protected readonly IMongoCollection<Sys_Role_Info> _collection_sysroleinfo;
- protected readonly IMongoCollection<Sys_DictionaryValue> _collection_sys_dictionaryvalue;
- protected readonly IMongoCollection<Pro_Project_Info> _collection_proprojectinfo;
- protected readonly IMongoCollection<Sys_Post_Info> _collection_syspostinfo;
- public Sys_User_AccountRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_User_Account, string>> logger) : base(settings, logger)
- {
- _collection_sysdepartment = _context.GetCollection<Sys_Department>();
- _collection_sysroleinfo = _context.GetCollection<Sys_Role_Info>();
- _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
- _collection_proprojectinfo = _context.GetCollection<Pro_Project_Info>();
- _collection_syspostinfo = _context.GetCollection<Sys_Post_Info>();
- _logger = logger;
- }
- /// <summary>
- /// Linq 关联查询 分页
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="provincecode"></param>
- /// <param name="citycode"></param>
- /// <param name="projectid"></param>
- /// <param name="protype"></param>
- /// <param name="systemid"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="recordCount"></param>
- /// <returns></returns>
- public IEnumerable<object> GetListsByPage(string keyword, string deptid, string roleid, string projectid, int type, string allprojectrole, int pageindex, int pagesize, out int recordCount)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- join dept in _collection_sysdepartment.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.type != 2
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- //dept_name = deptinfo.Count() > 0 ? deptinfo.First().departmenname : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.weixin,
- usa.weixin_img,
- usa.weixin_name,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist
- };
- #region 查询条件
- if (!string.IsNullOrEmpty(keyword))
- query = query.Where(s => s.usercode.Contains(keyword) || s.username.Contains(keyword) || s.mobile.Contains(keyword) || s.telephone.Contains(keyword));
- if (type != -1)
- query = query.Where(it => it.type.Equals(type));
- if (!string.IsNullOrEmpty(deptid))
- query = query.Where(it => it.dept_id.Equals(deptid));
- if (!string.IsNullOrEmpty(roleid))
- query = query.Where(it => it.role_id.Equals(roleid));
- if (!string.IsNullOrEmpty(projectid))
- query = query.Where(it => it.projectlist.Contains(projectid));
- #endregion
- recordCount = query.Count();
- var list = query.Skip((pageindex - 1) * pagesize).Take(pagesize);
- //var userpostlist_query = from post in _collection_syspostinfo.AsQueryable() where post.isdelete == 0 select post;
- var userprolist_query = from pro in _collection_proprojectinfo.AsQueryable() where pro.isdelete == 0 select pro;
- var querys = list.ToList().Select(p =>
- {
- //var userpostlist = (from post in _collection_syspostinfo.AsQueryable() where p.postlist.Contains(post.id) && post.isdelete == 0 select post).ToList();
- //var userprolist = (from pro in _collection_proprojectinfo.AsQueryable() where p.projectlist.Contains(pro.id) && pro.isdelete == 0 select pro).ToList();
- //var userpostlist = userpostlist_query.Where(x=>p.postlist.Contains(x.id)).ToList();
- var userprolist = userprolist_query.Where(x=>p.projectlist.Contains(x.id)).ToList();
- int isallproject = 0;
- if (allprojectrole.Split("|").Contains(p.role_code))
- {
- isallproject = 1;
- }
- //string postname = string.Join(',', userpostlist.Select(q => q.postname).ToList());
- string postname = string.Join(',', p.postlist.ToList());
- string projectname = string.Empty;
- if (isallproject == 0)
- {
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList());
- }
- return new
- {
- p.id,
- p.username,
- p.usercode,
- p.type,
- //p.password,
- p.sex,
- p.see_flag,
- p.birthday,
- p.call_type,
- p.dept_id,
- // p.dept_name,
- p.extensionnumber,
- p.@group,
- p.head_img,
- p.head_small_img,
- p.homephone,
- p.mail,
- p.mobile,
- p.qq,
- p.remark,
- p.role_id,
- p.role_name,
- p.role_code,
- isallproject,
- p.seat_flag,
- p.seat_level,
- p.seat_right,
- p.weixin,
- p.weixin_img,
- p.weixin_name,
- p.sina,
- p.team_id,
- p.telephone,
- p.idcard,
- p.idcardno,
- p.certificate,
- p.entrytime,
- p.transfertime,
- p.quittime,
- p.postlist,
- postname ,
- p.projectlist,
- projectname
- };
- });
- return querys;
- }
- /// <summary>
- /// Linq 关联查询 - App
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="provincecode"></param>
- /// <param name="citycode"></param>
- /// <param name="projectid"></param>
- /// <param name="protype"></param>
- /// <param name="systemid"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="recordCount"></param>
- /// <returns></returns>
- public IEnumerable<object> GetAppLists(string keyword, string deptid, string roleid, string projectid, int type, string allprojectrole)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- join dept in _collection_sysdepartment.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.type != 2
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- //dept_name = deptinfo.Count() > 0 ? deptinfo.First().departmenname : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.weixin,
- usa.weixin_img,
- usa.weixin_name,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist
- };
- #region 查询条件
- if (!string.IsNullOrEmpty(keyword))
- query = query.Where(s => s.usercode.Contains(keyword) || s.username.Contains(keyword) || s.mobile.Contains(keyword) || s.telephone.Contains(keyword));
- if (type != -1)
- query = query.Where(it => it.type.Equals(type));
- if (!string.IsNullOrEmpty(deptid))
- query = query.Where(it => it.dept_id.Equals(deptid));
- if (!string.IsNullOrEmpty(roleid))
- query = query.Where(it => it.role_id.Equals(roleid));
- if (!string.IsNullOrEmpty(projectid))
- query = query.Where(it => it.projectlist.Contains(projectid));
- #endregion
- var querys = query.ToList().Select(p =>
- {
- //var userpostlist = (from post in _collection_syspostinfo.AsQueryable() where p.postlist.Contains(post.id) && post.isdelete == 0 select post).ToList();
- var userprolist = (from pro in _collection_proprojectinfo.AsQueryable() where p.projectlist.Contains(pro.id) && pro.isdelete == 0 select pro).ToList();
- int isallproject = 0;
- if (allprojectrole.Split("|").Contains(p.role_code))
- {
- isallproject = 1;
- }
- string postname = string.Join(',', p.postlist.ToList());
- string projectname = string.Empty;
- if (isallproject == 0)
- {
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList());
- }
- return new
- {
- p.id,
- p.username,
- p.usercode,
- p.type,
- //p.password,
- p.sex,
- p.see_flag,
- p.birthday,
- p.call_type,
- p.dept_id,
- //p.dept_name,
- p.extensionnumber,
- p.@group,
- p.head_img,
- p.head_small_img,
- p.homephone,
- p.mail,
- p.mobile,
- p.qq,
- p.remark,
- p.role_id,
- p.role_name,
- p.role_code,
- isallproject,
- p.seat_flag,
- p.seat_level,
- p.seat_right,
- p.weixin,
- p.weixin_img,
- p.weixin_name,
- p.sina,
- p.team_id,
- p.telephone,
- p.idcard,
- p.idcardno,
- p.certificate,
- p.entrytime,
- p.transfertime,
- p.quittime,
- p.postlist,
- postname,
- p.projectlist,
- projectname
- };
- });
- return querys;
- }
- /// <summary>
- /// Linq 关联查询详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public object GetDetails(string id)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- join dept in _collection_sysdepartment.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.id == id
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- //dept_name = deptinfo.Count() > 0 ? deptinfo.First().departmenname : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist
- };
- //var query_syspostinfo = from post in _collection_syspostinfo.AsQueryable() where post.isdelete == 0 select post;
- var query_proprojectinfo = from pro in _collection_proprojectinfo.AsQueryable() where pro.isdelete == 0 select pro;
- var userinfo = query.FirstOrDefault();
- if (userinfo != null)
- {
- //var userpostlist = query_syspostinfo.Where(x => userinfo.postlist.Contains(x.id));
- var userprolist = query_proprojectinfo.Where(x => userinfo.projectlist.Contains(x.id));
- var postnames = string.Join(',', userinfo.postlist.ToList());
- var model = new
- {
- id = userinfo.id,
- username = userinfo.username,
- usercode = userinfo.usercode,
- type = userinfo.type,
- password = userinfo.password,
- sex = userinfo.sex,
- see_flag = userinfo.see_flag,
- birthday = userinfo.birthday,
- call_type = userinfo.call_type,
- dept_id = userinfo.dept_id,
- //dept_name = userinfo.dept_name,
- extensionnumber = userinfo.extensionnumber,
- @group = userinfo.@group,
- head_img = userinfo.head_img,
- head_small_img = userinfo.head_small_img,
- homephone = userinfo.homephone,
- mail = userinfo.mail,
- mobile = userinfo.mobile,
- qq = userinfo.qq,
- remark = userinfo.remark,
- role_id = userinfo.role_id,
- role_name = userinfo.role_name,
- role_code = userinfo.role_code,
- seat_flag = userinfo.seat_flag,
- seat_level = userinfo.seat_level,
- seat_right = userinfo.seat_right,
- sina = userinfo.sina,
- team_id = userinfo.team_id,
- telephone = userinfo.telephone,
- idcard = userinfo.idcard,
- idcardno = userinfo.idcardno,
- certificate = userinfo.certificate,
- entrytime = userinfo.entrytime,
- transfertime = userinfo.transfertime,
- quittime = userinfo.quittime,
- postlist = userinfo.postlist,
- //postname = string.Join(',', userpostlist.Select(q => q.postname).ToList()),
- postname = postnames,
- projectlist = userinfo.projectlist,
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList())
- };
- return model;
- }
- return null;
- }
- /// <summary>
- /// Linq 关联查询详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public object GetUserInfo(string usercode, string allprojectrole)
- {
- //关联查询
- var querys =
- from usa in _collection.AsQueryable()
- join dept in _collection_sysdepartment.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.usercode == usercode
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- //dept_name = deptinfo.Count() > 0 ? deptinfo.First().departmenname : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.weixin,
- usa.weixin_img,
- usa.weixin_name,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist
- };
- // var query_syspostinfo = from post in _collection_syspostinfo.AsQueryable() where post.isdelete == 0 select post;
- var query_proprojectinfo = from pro in _collection_proprojectinfo.AsQueryable() where pro.isdelete == 0 select pro;
- var userinfo = querys.FirstOrDefault();
- if (userinfo != null)
- {
- //var userpostlist = query_syspostinfo.Where(x => userinfo.postlist.Contains(x.id));
- var userprolist = query_proprojectinfo.Where(x => userinfo.projectlist.Contains(x.id));
- var postnames = string.Join(',', userinfo.postlist.ToList());
- int level = 0;
- switch (userinfo.role_code)
- {
- case "YWYG": level = 1; break;
- case "YWZG": level = 2; break;
- case "YWFJL": level = 3; break;
- case "YWJL": level = 4; break;
- case "YWZJ": level = 5; break;
- case "CJGL": level = 6; break;
- case "XTWH": level = 7; break;
- }
- int isallproject = 0;
- if (allprojectrole.Split("|").Contains(userinfo.role_code) || userinfo.type == 2)
- {
- isallproject = 1;
- }
- var model = new
- {
- id = userinfo.id,
- username = userinfo.username,
- usercode = userinfo.usercode,
- type = userinfo.type,
- //p.password,
- sex = userinfo.sex,
- see_flag = userinfo.see_flag,
- birthday = userinfo.birthday,
- call_type = userinfo.call_type,
- dept_id = userinfo.dept_id,
- //dept_name = userinfo.dept_name,
- extensionnumber = userinfo.extensionnumber,
- @group = userinfo.@group,
- head_img = userinfo.head_img,
- head_small_img = userinfo.head_small_img,
- homephone = userinfo.homephone,
- mail = userinfo.mail,
- mobile = userinfo.mobile,
- qq = userinfo.qq,
- remark = userinfo.remark,
- role_id = userinfo.role_id,
- role_name = userinfo.role_name,
- role_code = userinfo.role_code,
- level = level,
- isallproject = isallproject,
- seat_flag = userinfo.seat_flag,
- seat_level = userinfo.seat_level,
- seat_right = userinfo.seat_right,
- weixin = userinfo.weixin,
- weixin_img = userinfo.weixin_img,
- weixin_name = userinfo.weixin_name,
- sina = userinfo.sina,
- team_id = userinfo.team_id,
- telephone = userinfo.telephone,
- idcard = userinfo.idcard,
- idcardno = userinfo.idcardno,
- certificate = userinfo.certificate,
- entrytime = userinfo.entrytime,
- transfertime = userinfo.transfertime,
- quittime = userinfo.quittime,
- postlist = userinfo.postlist,
- //postname = string.Join(',', userpostlist.Select(q => q.postname).ToList()),
- postname = postnames,
- projectlist = userinfo.projectlist,
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList())
- };
- return model;
- }
- return null;
- }
- /// <summary>
- /// 列表 - 根据项目id,权限code获取列表
- /// </summary>
- /// <param name="projectid"></param>
- /// <param name="rolecode"></param>
- /// <returns></returns>
- public IEnumerable<object> GetProjectUser(string projectid, string rolecode)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- //join dept in _collection_sysdepartment.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.type != 2
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- //usa.type,
- //usa.password,
- //usa.sex,
- //usa.see_flag,
- //usa.birthday,
- //usa.call_type,
- //usa.dept_id,
- //dept_name = deptinfo.Count() > 0 ? deptinfo.First().departmenname : null,
- //usa.extensionnumber,
- //usa.@group,
- //usa.head_img,
- //usa.head_small_img,
- //usa.homephone,
- //usa.mail,
- //usa.mobile,
- //usa.qq,
- //usa.remark,
- //usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- //usa.seat_flag,
- //usa.seat_level,
- //usa.seat_right,
- //usa.weixin,
- //usa.weixin_img,
- //usa.weixin_name,
- //usa.sina,
- //usa.team_id,
- //usa.telephone,
- //usa.idcard,
- //usa.idcardno,
- //usa.certificate,
- //usa.entrytime,
- //usa.transfertime,
- //usa.quittime,
- //usa.postlist,
- usa.projectlist
- };
- #region 查询条件
- //if (!string.IsNullOrEmpty(rolecode))
- // query = query.Where(it => it.role_code.Equals(rolecode));
- if (!string.IsNullOrEmpty(rolecode))
- {
- List<string> list_rolecode = new List<string>(rolecode.Split(','));
- query = query.Where(it => list_rolecode.Contains(it.role_code));
- }
- if (!string.IsNullOrEmpty(projectid))
- query = query.Where(it => it.projectlist.Contains(projectid));
- #endregion
- return query;
- }
- //华谊售后系统使用
- /// <summary>
- /// Linq 关联查询 分页
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="provincecode"></param>
- /// <param name="citycode"></param>
- /// <param name="projectid"></param>
- /// <param name="protype"></param>
- /// <param name="systemid"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="recordCount"></param>
- /// <returns></returns>
- public IEnumerable<object> HyGetListsByPage(string keyword, string deptid, string roleid, string projectid, int type, string allprojectrole, int pageindex, int pagesize, out int recordCount)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- join dept in _collection_sys_dictionaryvalue.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.type != 2
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- //dept_name = deptinfo.Count() > 0 ? deptinfo.First().name : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.weixin,
- usa.weixin_img,
- usa.weixin_name,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist,
- usa.create_user ,
- usa.create_time
- };
- #region 查询条件
- if (!string.IsNullOrEmpty(keyword))
- query = query.Where(s => s.usercode.Contains(keyword) || s.username.Contains(keyword) || s.mobile.Contains(keyword) || s.telephone.Contains(keyword));
- if (type != -1)
- query = query.Where(it => it.type.Equals(type));
- if (!string.IsNullOrEmpty(deptid))
- query = query.Where(it => it.dept_id.Equals(deptid));
- if (!string.IsNullOrEmpty(roleid))
- query = query.Where(it => it.role_id.Equals(roleid));
- if (!string.IsNullOrEmpty(projectid))
- query = query.Where(it => it.projectlist.Contains(projectid));
- #endregion
- recordCount = query.Count();
- var list = query.Skip((pageindex - 1) * pagesize).Take(pagesize);
- var userpostlist_query = from post in _collection_syspostinfo.AsQueryable() where post.isdelete == 0 select post;
- var userprolist_query = from pro in _collection_proprojectinfo.AsQueryable() where pro.isdelete == 0 select pro;
- var querys = list.ToList().Select(p =>
- {
- //var userpostlist = (from post in _collection_syspostinfo.AsQueryable() where p.postlist.Contains(post.id) && post.isdelete == 0 select post).ToList();
- //var userprolist = (from pro in _collection_proprojectinfo.AsQueryable() where p.projectlist.Contains(pro.id) && pro.isdelete == 0 select pro).ToList();
- //var userpostlist = userpostlist_query.Where(x => p.postlist.Contains(x.id)).ToList();
- var userprolist = userprolist_query.Where(x => p.projectlist.Contains(x.id)).ToList();
- int isallproject = 0;
- if (allprojectrole.Split("|").Contains(p.role_code))
- {
- isallproject = 1;
- }
- string postname = string.Join(',', p.postlist.ToList());
- string projectname = string.Empty;
- if (isallproject == 0)
- {
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList());
- }
- return new
- {
- p.id,
- p.username,
- p.usercode,
- p.type,
- //p.password,
- p.sex,
- p.see_flag,
- p.birthday,
- p.call_type,
- p.dept_id,
- //p.dept_name,
- p.extensionnumber,
- p.@group,
- p.head_img,
- p.head_small_img,
- p.homephone,
- p.mail,
- p.mobile,
- p.qq,
- p.remark,
- p.role_id,
- p.role_name,
- p.role_code,
- isallproject,
- p.seat_flag,
- p.seat_level,
- p.seat_right,
- p.weixin,
- p.weixin_img,
- p.weixin_name,
- p.sina,
- p.team_id,
- p.telephone,
- p.idcard,
- p.idcardno,
- p.certificate,
- p.entrytime,
- p.transfertime,
- p.quittime,
- p.postlist,
- postname,
- p.projectlist,
- projectname,
- p.create_user,
- p.create_time
- };
- });
- return querys;
- }
- /// <summary>
- /// Linq 关联查询 - App
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="provincecode"></param>
- /// <param name="citycode"></param>
- /// <param name="projectid"></param>
- /// <param name="protype"></param>
- /// <param name="systemid"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="recordCount"></param>
- /// <returns></returns>
- public IEnumerable<object> HyGetAppLists(string keyword, string deptid, string roleid, string projectid, int type, string allprojectrole)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- join dept in _collection_sys_dictionaryvalue.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.type != 2
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- dept_name = usa.dept_id,// deptinfo.Count() > 0 ? deptinfo.First().name : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.weixin,
- usa.weixin_img,
- usa.weixin_name,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist,
- usa.create_user,
- usa.create_time
- };
- #region 查询条件
- if (!string.IsNullOrEmpty(keyword))
- query = query.Where(s => s.usercode.Contains(keyword) || s.username.Contains(keyword) || s.mobile.Contains(keyword) || s.telephone.Contains(keyword));
- if (type != -1)
- query = query.Where(it => it.type.Equals(type));
- if (!string.IsNullOrEmpty(deptid))
- query = query.Where(it => it.dept_id.Equals(deptid));
- if (!string.IsNullOrEmpty(roleid))
- query = query.Where(it => it.role_id.Equals(roleid));
- if (!string.IsNullOrEmpty(projectid))
- query = query.Where(it => it.projectlist.Contains(projectid));
- #endregion
- var querys = query.ToList().Select(p =>
- {
- //var userpostlist = (from post in _collection_syspostinfo.AsQueryable() where p.postlist.Contains(post.id) && post.isdelete == 0 select post).ToList();
- var userprolist = (from pro in _collection_proprojectinfo.AsQueryable() where p.projectlist.Contains(pro.id) && pro.isdelete == 0 select pro).ToList();
- int isallproject = 0;
- if (allprojectrole.Split("|").Contains(p.role_code))
- {
- isallproject = 1;
- }
- string postname = string.Join(',', p.postlist.ToList());
- string projectname = string.Empty;
- if (isallproject == 0)
- {
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList());
- }
- return new
- {
- p.id,
- p.username,
- p.usercode,
- p.type,
- //p.password,
- p.sex,
- p.see_flag,
- p.birthday,
- p.call_type,
- p.dept_id,
- p.dept_name,
- p.extensionnumber,
- p.@group,
- p.head_img,
- p.head_small_img,
- p.homephone,
- p.mail,
- p.mobile,
- p.qq,
- p.remark,
- p.role_id,
- p.role_name,
- p.role_code,
- isallproject,
- p.seat_flag,
- p.seat_level,
- p.seat_right,
- p.weixin,
- p.weixin_img,
- p.weixin_name,
- p.sina,
- p.team_id,
- p.telephone,
- p.idcard,
- p.idcardno,
- p.certificate,
- p.entrytime,
- p.transfertime,
- p.quittime,
- p.postlist,
- postname,
- p.projectlist,
- projectname,
- p.create_user,
- p.create_time
- };
- });
- return querys;
- }
- /// <summary>
- /// Linq 关联查询详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public object HyGetDetails(string id)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- join dept in _collection_sys_dictionaryvalue.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.id == id
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- dept_name = usa.dept_id,
- //deptinfo.Count() > 0 ? deptinfo.First().name : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist,
- usa.create_user,
- usa.create_time
- };
- //var query_syspostinfo = from post in _collection_syspostinfo.AsQueryable() where post.isdelete == 0 select post;
- var query_proprojectinfo = from pro in _collection_proprojectinfo.AsQueryable() where pro.isdelete == 0 select pro;
- var userinfo = query.FirstOrDefault();
- if (userinfo != null)
- {
- //var userpostlist = userinfo.postlist==null?;
- string postname = string.Join(',', userinfo.postlist.ToList());
- var userprolist = query_proprojectinfo.Where(x => userinfo.projectlist.Contains(x.id));
- var model = new
- {
- id = userinfo.id,
- username = userinfo.username,
- usercode = userinfo.usercode,
- type = userinfo.type,
- password = userinfo.password,
- sex = userinfo.sex,
- see_flag = userinfo.see_flag,
- birthday = userinfo.birthday,
- call_type = userinfo.call_type,
- dept_id = userinfo.dept_id,
- dept_name = userinfo.dept_name,
- extensionnumber = userinfo.extensionnumber,
- @group = userinfo.@group,
- head_img = userinfo.head_img,
- head_small_img = userinfo.head_small_img,
- homephone = userinfo.homephone,
- mail = userinfo.mail,
- mobile = userinfo.mobile,
- qq = userinfo.qq,
- remark = userinfo.remark,
- role_id = userinfo.role_id,
- role_name = userinfo.role_name,
- role_code = userinfo.role_code,
- seat_flag = userinfo.seat_flag,
- seat_level = userinfo.seat_level,
- seat_right = userinfo.seat_right,
- sina = userinfo.sina,
- team_id = userinfo.team_id,
- telephone = userinfo.telephone,
- idcard = userinfo.idcard,
- idcardno = userinfo.idcardno,
- certificate = userinfo.certificate,
- entrytime = userinfo.entrytime,
- transfertime = userinfo.transfertime,
- quittime = userinfo.quittime,
- postlist = userinfo.postlist,
- postname = postname,
- projectlist = userinfo.projectlist,
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList()),
- create_user = userinfo.create_user,
- create_time = userinfo.create_time
-
- };
- return model;
- }
- return null;
- }
- /// <summary>
- /// Linq 关联查询详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public object HyGetUserInfo(string usercode, string allprojectrole)
- {
- //关联查询
- var querys =
- from usa in _collection.AsQueryable()
- join dept in _collection_sys_dictionaryvalue.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.usercode == usercode
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
- usa.type,
- usa.password,
- usa.sex,
- usa.see_flag,
- usa.birthday,
- usa.call_type,
- usa.dept_id,
- dept_name = usa.dept_id,
- //deptinfo.Count() > 0 ? deptinfo.First().name : null,
- usa.extensionnumber,
- usa.@group,
- usa.head_img,
- usa.head_small_img,
- usa.homephone,
- usa.mail,
- usa.mobile,
- usa.qq,
- usa.remark,
- usa.role_id,
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
- usa.seat_flag,
- usa.seat_level,
- usa.seat_right,
- usa.weixin,
- usa.weixin_img,
- usa.weixin_name,
- usa.sina,
- usa.team_id,
- usa.telephone,
- usa.idcard,
- usa.idcardno,
- usa.certificate,
- usa.entrytime,
- usa.transfertime,
- usa.quittime,
- usa.postlist,
- usa.projectlist,
- usa.create_user,
- usa.create_time
- };
- //var query_syspostinfo = from post in _collection_syspostinfo.AsQueryable() where post.isdelete == 0 select post;
- var query_proprojectinfo = from pro in _collection_proprojectinfo.AsQueryable() where pro.isdelete == 0 select pro;
-
- var userinfo = querys.FirstOrDefault();
- if (userinfo != null)
- {
- string postname = string.Join(',', userinfo.postlist.ToList());
- //var userpostlist = query_syspostinfo.Where(x => userinfo.postlist.Contains(x.id));
- var userprolist = query_proprojectinfo.Where(x => userinfo.projectlist.Contains(x.id));
- int level = 0;
- switch (userinfo.role_code)
- {
- case "YWYG": level = 1; break;
- case "YWZG": level = 2; break;
- case "YWFJL": level = 3; break;
- case "YWJL": level = 4; break;
- case "YWZJ": level = 5; break;
- case "CJGL": level = 6; break;
- case "XTWH": level = 7; break;
- }
- int isallproject = 0;
- if (allprojectrole.Split("|").Contains(userinfo.role_code) || userinfo.type == 2)
- {
- isallproject = 1;
- }
- var model = new
- {
- id = userinfo.id,
- username = userinfo.username,
- usercode = userinfo.usercode,
- type = userinfo.type,
- //p.password,
- sex = userinfo.sex,
- see_flag = userinfo.see_flag,
- birthday = userinfo.birthday,
- call_type = userinfo.call_type,
- dept_id = userinfo.dept_id,
- dept_name = userinfo.dept_name,
- extensionnumber = userinfo.extensionnumber,
- @group = userinfo.@group,
- head_img = userinfo.head_img,
- head_small_img = userinfo.head_small_img,
- homephone = userinfo.homephone,
- mail = userinfo.mail,
- mobile = userinfo.mobile,
- qq = userinfo.qq,
- remark = userinfo.remark,
- role_id = userinfo.role_id,
- role_name = userinfo.role_name,
- role_code = userinfo.role_code,
- level = level,
- isallproject = isallproject,
- seat_flag = userinfo.seat_flag,
- seat_level = userinfo.seat_level,
- seat_right = userinfo.seat_right,
- weixin = userinfo.weixin,
- weixin_img = userinfo.weixin_img,
- weixin_name = userinfo.weixin_name,
- sina = userinfo.sina,
- team_id = userinfo.team_id,
- telephone = userinfo.telephone,
- idcard = userinfo.idcard,
- idcardno = userinfo.idcardno,
- certificate = userinfo.certificate,
- entrytime = userinfo.entrytime,
- transfertime = userinfo.transfertime,
- quittime = userinfo.quittime,
- postlist = userinfo.postlist,
- postname = postname,
- projectlist = userinfo.projectlist,
- projectname = string.Join(',', userprolist.Select(q => q.project_name).ToList()),
- create_user = userinfo.create_user,
- create_time = userinfo.create_time
- };
- return model;
- }
- return null;
- }
- /// <summary>
- /// 列表 - 根据项目id,权限code获取列表
- /// </summary>
- /// <param name="projectid"></param>
- /// <param name="rolecode"></param>
- /// <returns></returns>
- public IEnumerable<object> HyGetProjectUser(string projectid, string rolecode)
- {
- //关联查询
- var query =
- from usa in _collection.AsQueryable()
- //join dept in _collection_sysdepartment.AsQueryable() on usa.dept_id equals dept.id into deptinfo
- join role in _collection_sysroleinfo.AsQueryable() on usa.role_id equals role.id into roleinfo
- where usa.delete_flag == false && usa.type != 2
- orderby usa.create_time descending
- select new
- {
- usa.id,
- usa.username,
- usa.usercode,
-
- role_name = roleinfo.Count() > 0 ? roleinfo.First().role_name : null,
- role_code = roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
-
- usa.projectlist
- };
- #region 查询条件
- //if (!string.IsNullOrEmpty(rolecode))
- // query = query.Where(it => it.role_code.Equals(rolecode));
- if (!string.IsNullOrEmpty(rolecode))
- {
- List<string> list_rolecode = new List<string>(rolecode.Split(','));
- query = query.Where(it => list_rolecode.Contains(it.role_code));
- }
- if (!string.IsNullOrEmpty(projectid))
- query = query.Where(it => it.projectlist.Contains(projectid));
- #endregion
- return query;
- }
- }
- }
|