郑州市第一人民医院

Sys_ClassGroup_User_MapRepository.cs 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. using MadRunFabric.Common;
  2. using MadRunFabric.Common.Options;
  3. using MadRunFabric.Model;
  4. using Microsoft.Extensions.Logging;
  5. using Microsoft.Extensions.Options;
  6. using SignTokenApi.IRepositories;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using System.Linq;
  11. using MongoDB.Driver;
  12. using MadRunFabric.Common.Helpers;
  13. namespace SignTokenApi.Repositories
  14. {
  15. public class Sys_ClassGroup_User_MapRepository : BaseRepository<Sys_ClassGroup_User_Map, string>, ISys_ClassGroup_User_MapRepository
  16. {
  17. protected readonly ILogger<BaseRepository<Sys_ClassGroup_User_Map, string>> _logger;
  18. protected readonly IMongoCollection<Sys_User_Account> _collection_sys_user_account;
  19. protected readonly IMongoCollection<Sys_Role_Info> _collection_role_info;
  20. protected readonly IMongoCollection<Sys_ClassGroup> _collection_sys_classgroup;
  21. protected readonly IMongoCollection<Distri_Workorder_Plan> _collection_distri_workorder_plan;
  22. public Sys_ClassGroup_User_MapRepository(
  23. IOptions<MongodbOptions> settings,
  24. ILogger<BaseRepository<Sys_ClassGroup_User_Map, string>> logger) : base(settings, logger)
  25. {
  26. _logger = logger;
  27. _collection_sys_user_account = _context.GetCollection<Sys_User_Account>();
  28. _collection_role_info = _context.GetCollection<Sys_Role_Info>();
  29. _collection_sys_classgroup = _context.GetCollection<Sys_ClassGroup>();
  30. _collection_distri_workorder_plan = _context.GetCollection<Distri_Workorder_Plan>();
  31. }
  32. /// <summary>
  33. /// 获取排班列表
  34. /// </summary>
  35. /// <param name="projectid"></param>
  36. /// <param name="startdate"></param>
  37. /// <param name="enddate"></param>
  38. /// <param name="usercode"></param>
  39. /// <param name="groupcode"></param>
  40. /// <returns></returns>
  41. public IEnumerable<object> GetClassGroupUserList(string projectid, string listday,int card, UserInfoModel userinfo)
  42. {
  43. //, string usercode, string groupcode
  44. //获取坐席
  45. var userlist = from p in _collection_sys_user_account.AsQueryable()
  46. join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
  47. where p.delete_flag == false
  48. select new
  49. {
  50. p.id,
  51. p.head_img,
  52. p.usercode,
  53. p.username,
  54. p.projectlist,
  55. rolecode = roleinfo != null && roleinfo.Count() > 0 ? roleinfo.First().role_code : null
  56. };
  57. userlist = userlist.Where(p => p.rolecode == "SSY_DTG" || p.rolecode == "SSY_PSG");
  58. if (!string.IsNullOrEmpty(projectid))
  59. userlist = userlist.Where(p => p.projectlist.Contains(projectid));
  60. //if (!string.IsNullOrEmpty(usercode))
  61. // userlist = userlist.Where(p => p.usercode == usercode);
  62. // 如果card>0,说明是打卡调用,显示是当前用户打卡
  63. if (card > 0)
  64. userlist = userlist.Where(p => p.usercode == userinfo.usercode);
  65. #region 获取排班信息
  66. ////时间条件处理,默认当天
  67. //var datenow = DateTime.Now;
  68. //var startdatetime = datenow;
  69. //var enddatetime = datenow;
  70. //if (!string.IsNullOrEmpty(startdate) && !string.IsNullOrEmpty(enddate))
  71. //{
  72. // startdatetime = DateTime.Parse(startdate);
  73. // enddatetime = DateTime.Parse(enddate);
  74. //}
  75. var classUserlists = from p in _collection.AsQueryable()
  76. where p.isdelete == 0
  77. select new
  78. {
  79. p.id,
  80. p.projectid,
  81. p.usercode,
  82. //p.groupcode,
  83. p.date,
  84. p.isstatus,
  85. p.classgroupList,
  86. p.isjoin,
  87. p.distri_planList,
  88. p.isdelete
  89. };
  90. if (!string.IsNullOrEmpty(projectid))
  91. classUserlists = classUserlists.Where(x => x.projectid == projectid);
  92. //if (!string.IsNullOrEmpty(usercode))
  93. // classUserlists = classUserlists.Where(x => x.usercode == usercode);
  94. //if (!string.IsNullOrEmpty(groupcode))
  95. // classUserlists = classUserlists.Where(x => string.Join(",", x.classgroupList.ToList().Select(p => p.code)).Contains(groupcode));
  96. if (userinfo.isallproject == 0)
  97. classUserlists = classUserlists.Where(it => userinfo.projectlist.Contains(it.projectid));
  98. //由于 x.date 需要处理,所以 ToList
  99. var classUserlist = classUserlists.ToList();
  100. //if (!string.IsNullOrEmpty(startdatetime.ToString()))
  101. // classUserlist = classUserlist.Where(x => Convert.ToDateTime(x.date + " 00:00:00") >= Convert.ToDateTime(startdatetime.ToString("yyyy-MM-dd") + " 00:00:00")).ToList();
  102. //if (!string.IsNullOrEmpty(enddatetime.ToString()))
  103. // classUserlist = classUserlist.Where(x => Convert.ToDateTime(x.date + " 00:00:00") <= Convert.ToDateTime(enddatetime.ToString("yyyy-MM-dd") + " 23:59:59")).ToList();
  104. //获取最后一个点击日期
  105. var dayend = "";
  106. if (!string.IsNullOrWhiteSpace(listday))
  107. {
  108. //var typearr = listday.Split(',');
  109. string[] typearr = listday.Split(',');
  110. dayend = typearr[typearr.Length - 1];
  111. }
  112. else
  113. {
  114. dayend = DateTime.Now.ToString("yyyy-MM-dd");
  115. }
  116. classUserlist = classUserlist.Where(x => x.date == dayend).ToList();
  117. #endregion
  118. //班别
  119. var classlist = _collection_sys_classgroup.AsQueryable().ToList();
  120. classlist = classlist.Where(x => x.isdelete == 0).ToList();
  121. //配送计划
  122. DateTime dt_Plan = DateTime.Now;
  123. var distriPlanList = _collection_distri_workorder_plan.AsQueryable().Where(x=>x.isdelete == 0 && x.planstate == 0 && x.enddate >= dt_Plan).ToList(); // && x.startdate <= dt_Plan不用了,在计划结束之前排班就行
  124. var list = userlist.ToList().Select(p =>
  125. {
  126. #region 排班结果 model
  127. //变量去
  128. string classuserid = null;
  129. int isstatus_class = 0; //出勤状态(0未排版 1正常 2休息 3请假)
  130. bool isjoin_class = false; //是否参与计划
  131. var groupList_class = new List<ClassGroupList>(); //绑定班别
  132. var distri_planList_class = new List<DistriPlanList>(); //绑定计划
  133. var modelClassUser = classUserlist.FirstOrDefault(cu => cu.usercode == p.usercode);
  134. if (modelClassUser != null)
  135. {
  136. classuserid = modelClassUser.id;
  137. isstatus_class = modelClassUser.isstatus;
  138. groupList_class = modelClassUser.classgroupList;
  139. isjoin_class = modelClassUser.isjoin;
  140. distri_planList_class = modelClassUser.distri_planList;
  141. }
  142. #endregion
  143. #region 出勤状态列表
  144. var isstatusList = EnumberHelper.EnumToList<EnumClassGroupUserIsStatus>().Select(s => {
  145. return new
  146. {
  147. s.EnumName,
  148. s.EnumValue,
  149. ischeck = s.EnumValue == isstatus_class ? true : false //出勤状态选中
  150. };
  151. });
  152. #endregion
  153. #region 班别 - 排班
  154. var classlist_Class = classlist.Select(c =>
  155. {
  156. var roleList = new List<ClassGroupRoleList>();
  157. bool ischeck_class = false;
  158. foreach (var item in c.roleList)
  159. {
  160. if (groupList_class != null && groupList_class.Count > 0)
  161. {
  162. var modelClass = groupList_class.FirstOrDefault(x => x.code == c.code);
  163. if (modelClass != null)
  164. {
  165. ischeck_class = true;
  166. //判断是否选中
  167. var model_role = new ClassGroupRoleList();
  168. if (modelClass.roleList != null && modelClass.roleList.Count > 0)
  169. {
  170. var model_rolebycode = modelClass.roleList.FirstOrDefault(x => x.rolecode == item.rolecode);
  171. if (model_rolebycode != null)
  172. {
  173. item.ischeck = false;
  174. if (model_rolebycode.ischeck == true)
  175. item.ischeck = true;
  176. }
  177. }
  178. }
  179. }
  180. roleList.Add(item);
  181. }
  182. return new
  183. {
  184. c.code,
  185. c.name,
  186. ischeck = ischeck_class, //班别是否选中
  187. roleList
  188. //c.starttime,
  189. //c.endtime,
  190. //c.remark
  191. };
  192. });
  193. #endregion
  194. #region 配送计划列表
  195. var distriPlanList_Plan = distriPlanList.Select(d =>
  196. {
  197. bool ischeck_plan = false;
  198. if (groupList_class != null)
  199. {
  200. if (distri_planList_class != null && distri_planList_class.Count > 0)
  201. {
  202. var modelPlan = distri_planList_class.FirstOrDefault(x => x.planid == d.id);
  203. if (modelPlan != null)
  204. ischeck_plan = true;
  205. }
  206. }
  207. return new
  208. {
  209. d.id,
  210. d.planname,
  211. ischeck = ischeck_plan //计划是否选中
  212. };
  213. });
  214. #endregion
  215. return new
  216. {
  217. p.id,
  218. p.usercode,
  219. p.username,
  220. p.head_img,
  221. classuserid, //排班id
  222. isstatus_class, //排班状态
  223. isstatusList, //排班状态列表
  224. classlist_Class, //班别结果列表
  225. isjoin_class, //是否参与计划
  226. distriPlanList_Plan, //配送计划结果
  227. };
  228. }).ToList();
  229. return list;
  230. }
  231. /// <summary>
  232. /// 获取当月排班标记
  233. /// </summary>
  234. /// <param name="projectid"></param>
  235. /// <param name="startdate"></param>
  236. /// <param name="enddate"></param>
  237. /// <param name="usercode"></param>
  238. /// <param name="groupcode"></param>
  239. /// <returns></returns>
  240. public object GetClassGroupMarker(string projectid, string usercode, UserInfoModel userinfo)
  241. {
  242. //获取坐席
  243. var markerlist = from map in _collection.AsQueryable()
  244. //join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
  245. where map.isdelete == 0
  246. select new
  247. {
  248. map.id,
  249. map.date,
  250. map.usercode,
  251. map.isstatus
  252. };
  253. //var list = markerlist.ToList();
  254. if (!string.IsNullOrEmpty(usercode))
  255. markerlist = markerlist.Where(x => x.usercode == usercode);
  256. List<string> dateList_normal = new List<string>();
  257. List<string> dateList_rest = new List<string>();
  258. List<string> dateList_eave = new List<string>();
  259. foreach (var item in markerlist)
  260. {
  261. if (item.isstatus == 1)
  262. {
  263. dateList_normal.Add(item.date);
  264. }
  265. else if (item.isstatus == 2)
  266. {
  267. dateList_rest.Add(item.date);
  268. }
  269. else if (item.isstatus == 3)
  270. {
  271. dateList_eave.Add(item.date);
  272. }
  273. }
  274. var obj = new
  275. {
  276. dateList_normal = dateList_normal,
  277. dateList_rest = dateList_rest,
  278. dateList_eave = dateList_eave
  279. };
  280. return obj;
  281. }
  282. /// <summary>
  283. /// 获取班次时间段上班的人员 - 今天
  284. /// </summary>
  285. /// <param name="today"></param>
  286. /// <param name="userinfo"></param>
  287. /// <returns></returns>
  288. public object GetWorkUserListByDay(UserInfoModel userinfo)
  289. {
  290. DateTime dtnow = DateTime.Now;
  291. string nowDay = dtnow.ToString("yyyy-MM-dd");
  292. //获取坐席
  293. var listmapuser = from map in _collection.AsQueryable()
  294. //join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
  295. where map.isdelete == 0 && map.isstatus == (int)EnumClassGroupUserIsStatus.正常
  296. select new
  297. {
  298. map.id,
  299. map.projectid,
  300. map.date,
  301. map.usercode,
  302. map.isstatus,
  303. map.classgroupList
  304. };
  305. //班别列表
  306. var listClass = (from map in _collection_sys_classgroup.AsQueryable()
  307. where map.isdelete == 0
  308. select map).ToList();
  309. listClass = listClass.ToList().Where(x => DateTime.Parse(nowDay + " " + x.starttime) <= dtnow && DateTime.Parse(nowDay + " " + x.endtime) >= dtnow).ToList();
  310. if (userinfo.isallproject == 0)
  311. listmapuser = listmapuser.Where(it => userinfo.projectlist.Contains(it.projectid));
  312. if (!string.IsNullOrEmpty(nowDay))
  313. listmapuser = listmapuser.Where(x => x.date == nowDay);
  314. #region 获取用户符合条件的用户
  315. //var listUser = (await _sys_user_accountrepository.Get(x => x.delete_flag == false && x.lock_flag == false)).ToList();
  316. List<string> listUserCode = new List<string>();
  317. foreach (var item in listmapuser)
  318. {
  319. //获取班别code
  320. var list_code = new List<string> { }; //班别code
  321. var list_r = item.classgroupList.ToList();
  322. foreach (var item_r in list_r)
  323. {
  324. if (item_r.roleList != null && item_r.roleList.Count > 0)
  325. {
  326. //角色 - 班别
  327. var mode_r = item_r.roleList.Where(x => x.ischeck == true && x.rolecode == "SSY_PSG").ToList(); // && x.rolecode == rolecode
  328. if (mode_r != null && mode_r.Count > 0)
  329. list_code.Add(item_r.code);
  330. }
  331. }
  332. if (list_code != null && list_code.Count > 0)
  333. {
  334. listClass = listClass.Where(x => list_code.Contains(x.code)).ToList();
  335. foreach (var item_Class in listClass)
  336. {
  337. listUserCode.Add(item.usercode);
  338. }
  339. }
  340. }
  341. #endregion
  342. if (listUserCode.Contains(userinfo.usercode))
  343. listUserCode.Remove(userinfo.usercode);
  344. return listUserCode;
  345. }
  346. }
  347. }