StaffServices.cs 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Transactions;
  9. using Bowin.Common.Linq;
  10. using Bowin.Common.Linq.Entity;
  11. using Bowin.Common.Utility;
  12. using Bowin.Common.DataTime;
  13. using EMIS.Entities;
  14. using EMIS.Utility;
  15. using EMIS.ViewModel;
  16. using EMIS.ViewModel.UniversityManage.TeacherManage;
  17. using EMIS.ViewModel.SystemManage.UserManage;
  18. using EMIS.ViewModel.CacheManage;
  19. using EMIS.DataLogic.UniversityManage.TeacherManage;
  20. namespace EMIS.CommonLogic.UniversityManage.TeacherManage
  21. {
  22. public class StaffServices : BaseServices, IStaffServices
  23. {
  24. public Lazy<StaffDAL> staffDAL { get; set; }
  25. public Lazy<DataTimeHelper> TimeHelper { get; set; }
  26. /// <summary>
  27. /// 查询教师信息View
  28. /// </summary>
  29. /// <param name="configuretView"></param>
  30. /// <param name="campusID"></param>
  31. /// <param name="collegeID"></param>
  32. /// <param name="departmentID"></param>
  33. /// <param name="isPhoto"></param>
  34. /// <param name="teacherTypeID"></param>
  35. /// <param name="incumbencyState"></param>
  36. /// <param name="titleID"></param>
  37. /// <param name="isDualTeacher"></param>
  38. /// <param name="pageIndex"></param>
  39. /// <param name="pageSize"></param>
  40. /// <returns></returns>
  41. public IGridResultSet<StaffView> GetStaffViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID,
  42. int? incumbencyState, int? titleID, int? isDualTeacher, int pageIndex, int pageSize)
  43. {
  44. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  45. if (collegeID.HasValue)
  46. {
  47. expStaff = expStaff.And(x => x.CollegeID == collegeID);
  48. }
  49. if (departmentID.HasValue)
  50. {
  51. expStaff = expStaff.And(x => x.DepartmentID == departmentID);
  52. }
  53. if (isPhoto.HasValue)
  54. {
  55. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  56. {
  57. expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != "");
  58. }
  59. if (isPhoto.Value == (int)CF_GeneralExist.No)
  60. {
  61. expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == "");
  62. }
  63. }
  64. if (teacherTypeID.HasValue)
  65. {
  66. expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID);
  67. }
  68. if (incumbencyState.HasValue)
  69. {
  70. expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState);
  71. }
  72. if (titleID.HasValue)
  73. {
  74. expStaff = expStaff.And(x => x.TitleID == titleID);
  75. }
  76. if (isDualTeacher.HasValue)
  77. {
  78. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes)
  79. {
  80. expStaff = expStaff.And(x => x.IsDualTeacher == true);
  81. }
  82. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo)
  83. {
  84. expStaff = expStaff.And(x => x.IsDualTeacher != true);
  85. }
  86. }
  87. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  88. if (campusID.HasValue)
  89. {
  90. //校区
  91. query = query.Where(x => x.CampusID == campusID);
  92. }
  93. //查询条件
  94. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  95. {
  96. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  97. }
  98. return this.GetQueryByDataRange(query, x => x.UserID).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode)
  99. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet<StaffView>(pageIndex, pageSize);
  100. }
  101. /// <summary>
  102. /// 查询教师信息List
  103. /// </summary>
  104. /// <param name="configuretView"></param>
  105. /// <param name="campusID"></param>
  106. /// <param name="collegeID"></param>
  107. /// <param name="departmentID"></param>
  108. /// <param name="isPhoto"></param>
  109. /// <param name="teacherTypeID"></param>
  110. /// <param name="incumbencyState"></param>
  111. /// <param name="titleID"></param>
  112. /// <param name="isDualTeacher"></param>
  113. /// <returns></returns>
  114. public IList<StaffView> GetStaffViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto, int? teacherTypeID,
  115. int? incumbencyState, int? titleID, int? isDualTeacher)
  116. {
  117. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  118. if (collegeID.HasValue)
  119. {
  120. expStaff = expStaff.And(x => x.CollegeID == collegeID);
  121. }
  122. if (departmentID.HasValue)
  123. {
  124. expStaff = expStaff.And(x => x.DepartmentID == departmentID);
  125. }
  126. if (isPhoto.HasValue)
  127. {
  128. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  129. {
  130. expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != "");
  131. }
  132. if (isPhoto.Value == (int)CF_GeneralExist.No)
  133. {
  134. expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == "");
  135. }
  136. }
  137. if (teacherTypeID.HasValue)
  138. {
  139. expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID);
  140. }
  141. if (incumbencyState.HasValue)
  142. {
  143. expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState);
  144. }
  145. if (titleID.HasValue)
  146. {
  147. expStaff = expStaff.And(x => x.TitleID == titleID);
  148. }
  149. if (isDualTeacher.HasValue)
  150. {
  151. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes)
  152. {
  153. expStaff = expStaff.And(x => x.IsDualTeacher == true);
  154. }
  155. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo)
  156. {
  157. expStaff = expStaff.And(x => x.IsDualTeacher != true);
  158. }
  159. }
  160. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  161. if (campusID.HasValue)
  162. {
  163. //校区
  164. query = query.Where(x => x.CampusID == campusID);
  165. }
  166. //查询条件
  167. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  168. {
  169. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  170. }
  171. return this.GetQueryByDataRange(query, x => x.UserID).OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode)
  172. .ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  173. }
  174. /// <summary>
  175. /// 查询教师信息View
  176. /// </summary>
  177. /// <param name="configuretView"></param>
  178. /// <param name="campusID"></param>
  179. /// <param name="collegeID"></param>
  180. /// <param name="loginID"></param>
  181. /// <param name="name"></param>
  182. /// <param name="pageIndex"></param>
  183. /// <param name="pageSize"></param>
  184. /// <returns></returns>
  185. public IGridResultSet<StaffView> GetStaffViewGrid(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, string loginID, string name, int pageIndex, int pageSize)
  186. {
  187. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  188. if (collegeID.HasValue)
  189. {
  190. expStaff = expStaff.And(x => x.CollegeID == collegeID);
  191. }
  192. if (!string.IsNullOrEmpty(loginID))
  193. {
  194. expStaff = expStaff.And(x => x.Sys_User.LoginID.Contains(loginID));
  195. }
  196. if (!string.IsNullOrEmpty(name))
  197. {
  198. expStaff = expStaff.And(x => x.Sys_User.Name.Contains(name));
  199. }
  200. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  201. if (campusID.HasValue)
  202. {
  203. //校区
  204. query = query.Where(x => x.CampusID == campusID);
  205. }
  206. //查询条件
  207. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  208. {
  209. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  210. }
  211. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length)
  212. .ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet<StaffView>(pageIndex, pageSize);
  213. }
  214. /// <summary>
  215. /// 查询教师信息List
  216. /// </summary>
  217. /// <param name="configuretView"></param>
  218. /// <param name="campusID"></param>
  219. /// <param name="collegeID"></param>
  220. /// <param name="loginID"></param>
  221. /// <param name="name"></param>
  222. /// <returns></returns>
  223. public IList<StaffView> GetStaffViewList(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, string loginID, string name)
  224. {
  225. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  226. if (collegeID.HasValue)
  227. {
  228. expStaff = expStaff.And(x => x.CollegeID == collegeID);
  229. }
  230. if (!string.IsNullOrEmpty(loginID))
  231. {
  232. expStaff = expStaff.And(x => x.Sys_User.LoginID.Contains(loginID));
  233. }
  234. if (!string.IsNullOrEmpty(name))
  235. {
  236. expStaff = expStaff.And(x => x.Sys_User.Name.Contains(name));
  237. }
  238. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  239. if (campusID.HasValue)
  240. {
  241. //校区
  242. query = query.Where(x => x.CampusID == campusID);
  243. }
  244. //查询条件
  245. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  246. {
  247. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  248. }
  249. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.StaffCode.Length)
  250. .ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  251. }
  252. /// <summary>
  253. /// 查询教师信息View(无数据范围)
  254. /// </summary>
  255. /// <param name="configuretView"></param>
  256. /// <param name="campusID"></param>
  257. /// <param name="collegeID"></param>
  258. /// <param name="departmentID"></param>
  259. /// <param name="isPhoto"></param>
  260. /// <param name="teacherTypeID"></param>
  261. /// <param name="incumbencyState"></param>
  262. /// <param name="titleID"></param>
  263. /// <param name="isDualTeacher"></param>
  264. /// <param name="pageIndex"></param>
  265. /// <param name="pageSize"></param>
  266. /// <returns></returns>
  267. public IGridResultSet<StaffView> GetStaffViewGridWithNoDataRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto,
  268. int? teacherTypeID, int? incumbencyState, int? titleID, int? isDualTeacher, int pageIndex, int pageSize)
  269. {
  270. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  271. if (collegeID.HasValue)
  272. {
  273. expStaff = expStaff.And(x => x.CollegeID == collegeID);
  274. }
  275. if (departmentID.HasValue)
  276. {
  277. expStaff = expStaff.And(x => x.DepartmentID == departmentID);
  278. }
  279. if (isPhoto.HasValue)
  280. {
  281. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  282. {
  283. expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != "");
  284. }
  285. if (isPhoto.Value == (int)CF_GeneralExist.No)
  286. {
  287. expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == "");
  288. }
  289. }
  290. if (teacherTypeID.HasValue)
  291. {
  292. expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID);
  293. }
  294. if (incumbencyState.HasValue)
  295. {
  296. expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState);
  297. }
  298. if (titleID.HasValue)
  299. {
  300. expStaff = expStaff.And(x => x.TitleID == titleID);
  301. }
  302. if (isDualTeacher.HasValue)
  303. {
  304. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes)
  305. {
  306. expStaff = expStaff.And(x => x.IsDualTeacher == true);
  307. }
  308. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo)
  309. {
  310. expStaff = expStaff.And(x => x.IsDualTeacher != true);
  311. }
  312. }
  313. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  314. if (campusID.HasValue)
  315. {
  316. //校区
  317. query = query.Where(x => x.CampusID == campusID);
  318. }
  319. //查询条件
  320. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  321. {
  322. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  323. }
  324. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet<StaffView>(pageIndex, pageSize);
  325. }
  326. /// <summary>
  327. /// 查询教师信息List(无数据范围)
  328. /// </summary>
  329. /// <param name="configuretView"></param>
  330. /// <param name="campusID"></param>
  331. /// <param name="collegeID"></param>
  332. /// <param name="departmentID"></param>
  333. /// <param name="isPhoto"></param>
  334. /// <param name="teacherTypeID"></param>
  335. /// <param name="incumbencyState"></param>
  336. /// <param name="titleID"></param>
  337. /// <param name="isDualTeacher"></param>
  338. /// <returns></returns>
  339. public IList<StaffView> GetStaffViewListWithNoDataRange(ConfiguretView configuretView, Guid? campusID, Guid? collegeID, Guid? departmentID, int? isPhoto,
  340. int? teacherTypeID, int? incumbencyState, int? titleID, int? isDualTeacher)
  341. {
  342. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  343. if (collegeID.HasValue)
  344. {
  345. expStaff = expStaff.And(x => x.CollegeID == collegeID);
  346. }
  347. if (departmentID.HasValue)
  348. {
  349. expStaff = expStaff.And(x => x.DepartmentID == departmentID);
  350. }
  351. if (isPhoto.HasValue)
  352. {
  353. if (isPhoto.Value == (int)CF_GeneralExist.Have)
  354. {
  355. expStaff = expStaff.And(x => x.PhotoUrl != null && x.PhotoUrl != "");
  356. }
  357. if (isPhoto.Value == (int)CF_GeneralExist.No)
  358. {
  359. expStaff = expStaff.And(x => x.PhotoUrl == null || x.PhotoUrl == "");
  360. }
  361. }
  362. if (teacherTypeID.HasValue)
  363. {
  364. expStaff = expStaff.And(x => x.TeacherTypeID == teacherTypeID);
  365. }
  366. if (incumbencyState.HasValue)
  367. {
  368. expStaff = expStaff.And(x => x.IncumbencyState == incumbencyState);
  369. }
  370. if (titleID.HasValue)
  371. {
  372. expStaff = expStaff.And(x => x.TitleID == titleID);
  373. }
  374. if (isDualTeacher.HasValue)
  375. {
  376. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes)
  377. {
  378. expStaff = expStaff.And(x => x.IsDualTeacher == true);
  379. }
  380. if (isDualTeacher.Value == (int)CF_GeneralPurpose.IsNo)
  381. {
  382. expStaff = expStaff.And(x => x.IsDualTeacher != true);
  383. }
  384. }
  385. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  386. if (campusID.HasValue)
  387. {
  388. //校区
  389. query = query.Where(x => x.CampusID == campusID);
  390. }
  391. //查询条件
  392. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  393. {
  394. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  395. }
  396. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  397. }
  398. /// <summary>
  399. /// 查询教师信息StaffView(全部)
  400. /// </summary>
  401. /// <param name="configuretView"></param>
  402. /// <param name="pageIndex"></param>
  403. /// <param name="pageSize"></param>
  404. /// <returns></returns>
  405. public IGridResultSet<StaffView> GetAllStaffView(ConfiguretView configuretView, int pageIndex, int pageSize)
  406. {
  407. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  408. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  409. //查询条件
  410. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  411. {
  412. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  413. }
  414. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToGridResultSet<StaffView>(pageIndex, pageSize);
  415. }
  416. /// <summary>
  417. /// 查询教师信息List(全部)
  418. /// </summary>
  419. /// <param name="configuretView"></param>
  420. /// <returns></returns>
  421. public IList<StaffView> GetAllStaffList(ConfiguretView configuretView)
  422. {
  423. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  424. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  425. //查询条件
  426. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  427. {
  428. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  429. }
  430. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  431. }
  432. /// <summary>
  433. /// 查询对应的教师信息StaffView(全部)
  434. /// </summary>
  435. /// <returns></returns>
  436. public List<StaffView> GetListStaffView()
  437. {
  438. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  439. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  440. return query.OrderBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ThenBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ToList();
  441. }
  442. /// <summary>
  443. /// 查询对应的教师信息CF_Staff(全部)
  444. /// </summary>
  445. /// <returns></returns>
  446. public List<CF_Staff> GetStaffList()
  447. {
  448. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  449. var query = staffDAL.Value.staffRepository.GetList(expStaff);
  450. return this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.Sys_User.LoginID.Length).ThenBy(x => x.Sys_User.LoginID).ToList();
  451. }
  452. /// <summary>
  453. /// 查询对应的教师信息CF_Staff
  454. /// </summary>
  455. /// <param name="userID"></param>
  456. /// <returns></returns>
  457. public CF_Staff GetStaff(Guid? userID)
  458. {
  459. try
  460. {
  461. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  462. expStaff = expStaff.And(x => x.UserID == userID);
  463. var query = staffDAL.Value.staffRepository.GetList(expStaff, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffManageDepartment), (x => x.CF_StaffProfile), (x => x.Sys_User)).SingleOrDefault();
  464. return query;
  465. }
  466. catch (Exception ex)
  467. {
  468. throw new Exception(ex.Message);
  469. }
  470. }
  471. /// <summary>
  472. /// 查询对应的教师信息CF_StaffProfile
  473. /// </summary>
  474. /// <param name="userID"></param>
  475. /// <returns></returns>
  476. public CF_StaffProfile GetStaffProfile(Guid? userID)
  477. {
  478. try
  479. {
  480. Expression<Func<CF_StaffProfile, bool>> expStaffProfile = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  481. expStaffProfile = expStaffProfile.And(x => x.UserID == userID);
  482. var query = staffDAL.Value.staffProfileRepository.GetList(expStaffProfile).SingleOrDefault();
  483. return query;
  484. }
  485. catch (Exception ex)
  486. {
  487. throw new Exception(ex.Message);
  488. }
  489. }
  490. /// <summary>
  491. /// 查询对应的教师信息CF_Staff
  492. /// </summary>
  493. /// <param name="exp"></param>
  494. /// <returns></returns>
  495. public CF_Staff GetStaff(Expression<Func<CF_Staff, bool>> exp)
  496. {
  497. try
  498. {
  499. return staffDAL.Value.staffRepository.GetSingle(exp);
  500. }
  501. catch (Exception ex)
  502. {
  503. throw new Exception(ex.Message);
  504. }
  505. }
  506. /// <summary>
  507. /// 查询对应的教师信息StaffView
  508. /// </summary>
  509. /// <param name="userID"></param>
  510. /// <returns></returns>
  511. public StaffView GetStaffView(Guid? userID)
  512. {
  513. try
  514. {
  515. var query = staffDAL.Value.GetStaffViewQueryable(x => x.UserID == userID).SingleOrDefault();
  516. return query;
  517. }
  518. catch (Exception ex)
  519. {
  520. throw new Exception(ex.Message);
  521. }
  522. }
  523. /// <summary>
  524. /// 查询对应的教师信息StaffView
  525. /// </summary>
  526. /// <param name="exp"></param>
  527. /// <returns></returns>
  528. public StaffView GetStaffView(Expression<Func<CF_Staff, bool>> exp)
  529. {
  530. try
  531. {
  532. var query = staffDAL.Value.GetStaffViewQueryable(exp).SingleOrDefault();
  533. return query;
  534. }
  535. catch (Exception ex)
  536. {
  537. throw new Exception(ex.Message);
  538. }
  539. }
  540. /// <summary>
  541. /// 查询对应的教师信息List
  542. /// </summary>
  543. /// <param name="userID"></param>
  544. /// <returns></returns>
  545. public List<StaffView> GetListStaffView(Guid? userID)
  546. {
  547. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  548. expStaff = expStaff.And(x => x.UserID == userID);
  549. var query = staffDAL.Value.GetStaffViewQueryable(expStaff);
  550. return query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.StaffCode.Length).ThenBy(x => x.StaffCode).ToList();
  551. }
  552. /// <summary>
  553. /// 编辑(新增、修改,业务主键:教职工号或证件号码)
  554. /// </summary>
  555. /// <param name="staffView"></param>
  556. /// <param name="photoUrl"></param>
  557. public void StaffEdit(StaffView staffView, string photoUrl)
  558. {
  559. try
  560. {
  561. var userVerify = staffDAL.Value.UserRepository.GetList(x => x.UserID != staffView.UserID && x.LoginID == staffView.StaffCode).SingleOrDefault();
  562. if (userVerify == null)
  563. {
  564. if (!string.IsNullOrEmpty(staffView.CertificatesNum))
  565. {
  566. var staffVerify = staffDAL.Value.staffRepository.GetList(x => x.UserID != staffView.UserID && x.CertificatesNum == staffView.CertificatesNum).SingleOrDefault();
  567. if (staffVerify != null)
  568. {
  569. throw new Exception("已存在相同的证件号码(证件号码重复),请核查。");
  570. }
  571. }
  572. var college = staffDAL.Value.CollegeRepository.GetList(x => x.CollegeID == staffView.CollegeID).SingleOrDefault();
  573. if (staffView.DepartmentID.HasValue)
  574. {
  575. var department = staffDAL.Value.DepartmentRepository.GetList(x => x.DepartmentID == staffView.DepartmentID).SingleOrDefault();
  576. if (department.CollegeID != staffView.CollegeID)
  577. {
  578. throw new Exception("所属教研室和" + RSL.Get("College") + "不匹配,请核查。");
  579. }
  580. }
  581. var teacherInitPassword = staffDAL.Value.ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.TeacherInitPassword).SingleOrDefault();
  582. var teacherRoleList = staffDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Teacher && x.RoleName.Contains("教师")).ToList();
  583. List<Sys_User> newUserInList = new List<Sys_User>();
  584. List<Sys_User> newUserUpList = new List<Sys_User>();
  585. List<CF_Staff> newStaffInList = new List<CF_Staff>();
  586. List<CF_Staff> newStaffUpList = new List<CF_Staff>();
  587. List<CF_StaffProfile> newStaffProfileInList = new List<CF_StaffProfile>();
  588. List<CF_StaffProfile> newStaffProfileUpList = new List<CF_StaffProfile>();
  589. List<CF_StaffManageCampus> newStaffManageCampusInList = new List<CF_StaffManageCampus>();
  590. List<CF_StaffManageCollege> newStaffManageCollegeInList = new List<CF_StaffManageCollege>();
  591. List<CF_StaffManageDepartment> newStaffManageDepartmentInList = new List<CF_StaffManageDepartment>();
  592. List<Guid?> CampusUserIDDelList = new List<Guid?>();
  593. List<Guid?> CollegeUserIDDelList = new List<Guid?>();
  594. List<Guid?> DepartmentUserIDDelList = new List<Guid?>();
  595. if (staffView.UserID != Guid.Empty)
  596. {
  597. //表示修改
  598. var staff = staffDAL.Value.staffRepository.GetList(x => x.UserID == staffView.UserID, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege),
  599. (x => x.CF_StaffManageDepartment), (x => x.CF_StaffProfile), (x => x.Sys_User)).SingleOrDefault();
  600. if (staff == null)
  601. {
  602. throw new Exception("数据有误,请核查。");
  603. }
  604. else
  605. {
  606. staff.Sys_User.LoginID = staffView.StaffCode.Trim();
  607. staff.Sys_User.Name = staffView.Name.Trim();
  608. this.SetModifyStatus(staff.Sys_User);
  609. newUserUpList.Add(staff.Sys_User);
  610. staff.StaffCode = staffView.StaffCode.Trim();
  611. if (staff.CollegeID != staffView.CollegeID)
  612. {
  613. CampusUserIDDelList.Add(staffView.UserID);
  614. var staffManageCampus = new CF_StaffManageCampus();
  615. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  616. staffManageCampus.UserID = staffView.UserID;
  617. staffManageCampus.CampusID = college.CampusID;
  618. this.SetNewStatus(staffManageCampus);
  619. newStaffManageCampusInList.Add(staffManageCampus);
  620. CollegeUserIDDelList.Add(staffView.UserID);
  621. var staffManageCollege = new CF_StaffManageCollege();
  622. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  623. staffManageCollege.UserID = staffView.UserID;
  624. staffManageCollege.CollegeID = staffView.CollegeID;
  625. this.SetNewStatus(staffManageCollege);
  626. newStaffManageCollegeInList.Add(staffManageCollege);
  627. DepartmentUserIDDelList.Add(staffView.UserID);
  628. if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty)
  629. {
  630. var staffManageDepartment = new CF_StaffManageDepartment();
  631. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  632. staffManageDepartment.UserID = staffView.UserID;
  633. staffManageDepartment.DepartmentID = staffView.DepartmentID;
  634. this.SetNewStatus(staffManageDepartment);
  635. newStaffManageDepartmentInList.Add(staffManageDepartment);
  636. }
  637. }
  638. else
  639. {
  640. if (staff.CF_StaffManageCampus.Count() <= 0 || staff.CF_StaffManageCampus == null)
  641. {
  642. var staffManageCampus = new CF_StaffManageCampus();
  643. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  644. staffManageCampus.UserID = staffView.UserID;
  645. staffManageCampus.CampusID = college.CampusID;
  646. this.SetNewStatus(staffManageCampus);
  647. newStaffManageCampusInList.Add(staffManageCampus);
  648. }
  649. if (staff.CF_StaffManageCollege.Count() <= 0 || staff.CF_StaffManageCollege == null)
  650. {
  651. var staffManageCollege = new CF_StaffManageCollege();
  652. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  653. staffManageCollege.UserID = staffView.UserID;
  654. staffManageCollege.CollegeID = staffView.CollegeID;
  655. this.SetNewStatus(staffManageCollege);
  656. newStaffManageCollegeInList.Add(staffManageCollege);
  657. }
  658. if (staff.DepartmentID != staffView.DepartmentID)
  659. {
  660. DepartmentUserIDDelList.Add(staffView.UserID);
  661. if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty)
  662. {
  663. var staffManageDepartment = new CF_StaffManageDepartment();
  664. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  665. staffManageDepartment.UserID = staffView.UserID;
  666. staffManageDepartment.DepartmentID = staffView.DepartmentID;
  667. this.SetNewStatus(staffManageDepartment);
  668. newStaffManageDepartmentInList.Add(staffManageDepartment);
  669. }
  670. }
  671. else
  672. {
  673. if (staff.CF_StaffManageDepartment.Count() <= 0 || staff.CF_StaffManageDepartment == null)
  674. {
  675. if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty)
  676. {
  677. var staffManageDepartment = new CF_StaffManageDepartment();
  678. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  679. staffManageDepartment.UserID = staffView.UserID;
  680. staffManageDepartment.DepartmentID = staffView.DepartmentID;
  681. this.SetNewStatus(staffManageDepartment);
  682. newStaffManageDepartmentInList.Add(staffManageDepartment);
  683. }
  684. }
  685. }
  686. }
  687. staff.CollegeID = staffView.CollegeID;
  688. staff.DepartmentID = staffView.DepartmentID;
  689. staff.SexID = staffView.SexID;
  690. staff.BirthDate = staffView.BirthDate;
  691. staff.NationID = staffView.NationID;
  692. staff.PoliticsID = staffView.PoliticsID;
  693. staff.CertificatesType = staffView.CertificatesType;
  694. staff.CertificatesNum = staffView.CertificatesNum;
  695. staff.TeacherTypeID = staffView.TeacherTypeID;
  696. staff.IncumbencyState = staffView.IncumbencyState;
  697. staff.SituationID = staffView.SituationID;
  698. staff.TitleID = staffView.TitleID;
  699. staff.LiteracyLevelID = staffView.LiteracyLevelID;
  700. staff.LearnPositionID = staffView.LearnPositionID;
  701. staff.IsDualTeacher = staffView.IsDualTeacher;
  702. staff.PaymentLevelID = staffView.PaymentLevelID;
  703. staff.WorkDate = staffView.WorkDate;
  704. staff.ComeSchoolDate = staffView.ComeSchoolDate;
  705. if (!string.IsNullOrEmpty(photoUrl))
  706. {
  707. staff.PhotoUrl = photoUrl;
  708. }
  709. staff.Profile = staffView.Profile;
  710. staff.Remark = staffView.Remark;
  711. this.SetModifyStatus(staff);
  712. newStaffUpList.Add(staff);
  713. if (staff.CF_StaffProfile == null)
  714. {
  715. var staffProfile = new CF_StaffProfile();
  716. staffProfile.UserID = staff.UserID;
  717. staffProfile.UsedName = staffView.UsedName;
  718. staffProfile.Nationality = staffView.Nationality;
  719. staffProfile.Place = staffView.Place;
  720. staffProfile.Email = staffView.Email;
  721. staffProfile.ZIPCode = staffView.ZIPCode;
  722. staffProfile.WeChatNum = staffView.WeChatNum;
  723. staffProfile.QQ = staffView.QQ;
  724. staffProfile.Telephone = staffView.Telephone;
  725. staffProfile.OfficeTelephone = staffView.OfficeTelephone;
  726. staffProfile.HousePhone = staffView.HousePhone;
  727. staffProfile.Mobile = staffView.Mobile;
  728. staffProfile.Speciality = staffView.Speciality;
  729. staffProfile.HealthStateID = staffView.HealthStateID;
  730. staffProfile.ReligionID = staffView.ReligionID;
  731. staffProfile.Account = staffView.Account;
  732. staffProfile.Residence = staffView.Residence;
  733. staffProfile.HomeAddress = staffView.HomeAddress;
  734. staffProfile.Address = staffView.Address;
  735. staffProfile.NowAddress = staffView.NowAddress;
  736. this.SetNewStatus(staffProfile);
  737. newStaffProfileInList.Add(staffProfile);
  738. }
  739. else
  740. {
  741. staff.CF_StaffProfile.UsedName = staffView.UsedName;
  742. staff.CF_StaffProfile.Nationality = staffView.Nationality;
  743. staff.CF_StaffProfile.Place = staffView.Place;
  744. staff.CF_StaffProfile.Email = staffView.Email;
  745. staff.CF_StaffProfile.ZIPCode = staffView.ZIPCode;
  746. staff.CF_StaffProfile.WeChatNum = staffView.WeChatNum;
  747. staff.CF_StaffProfile.QQ = staffView.QQ;
  748. staff.CF_StaffProfile.Telephone = staffView.Telephone;
  749. staff.CF_StaffProfile.OfficeTelephone = staffView.OfficeTelephone;
  750. staff.CF_StaffProfile.HousePhone = staffView.HousePhone;
  751. staff.CF_StaffProfile.Mobile = staffView.Mobile;
  752. staff.CF_StaffProfile.Speciality = staffView.Speciality;
  753. staff.CF_StaffProfile.HealthStateID = staffView.HealthStateID;
  754. staff.CF_StaffProfile.ReligionID = staffView.ReligionID;
  755. staff.CF_StaffProfile.Account = staffView.Account;
  756. staff.CF_StaffProfile.Residence = staffView.Residence;
  757. staff.CF_StaffProfile.HomeAddress = staffView.HomeAddress;
  758. staff.CF_StaffProfile.Address = staffView.Address;
  759. staff.CF_StaffProfile.NowAddress = staffView.NowAddress;
  760. this.SetModifyStatus(staff.CF_StaffProfile);
  761. newStaffProfileUpList.Add(staff.CF_StaffProfile);
  762. }
  763. }
  764. }
  765. else
  766. {
  767. //表示新增
  768. var newUser = new Sys_User();
  769. newUser.UserID = Guid.NewGuid();
  770. newUser.LoginID = staffView.StaffCode.Trim();
  771. newUser.Name = staffView.Name.Trim();
  772. if (teacherInitPassword == null)
  773. {
  774. newUser.Password = ("A" + staffView.StaffCode.Trim()).MD5();
  775. }
  776. else
  777. {
  778. if (teacherInitPassword.Value != null)
  779. {
  780. newUser.Password = teacherInitPassword.Value;
  781. }
  782. else
  783. {
  784. newUser.Password = ("A" + staffView.StaffCode.Trim()).MD5();
  785. }
  786. }
  787. this.SetNewStatus(newUser, (int)SYS_STATUS.USABLE);
  788. newUserInList.Add(newUser);
  789. newUser.Sys_Role = new HashSet<Sys_Role>();
  790. if (teacherRoleList != null && teacherRoleList.Count() > 0)
  791. {
  792. teacherRoleList.ForEach(x => newUser.Sys_Role.Add(x));
  793. }
  794. else
  795. {
  796. //对应角色为空时,默认为不分配用户角色
  797. }
  798. var newStaff = new CF_Staff();
  799. newStaff.UserID = newUser.UserID;
  800. newStaff.StaffCode = staffView.StaffCode.Trim();
  801. newStaff.CollegeID = staffView.CollegeID;
  802. var staffManageCampus = new CF_StaffManageCampus();
  803. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  804. staffManageCampus.UserID = newStaff.UserID;
  805. staffManageCampus.CampusID = college.CampusID;
  806. this.SetNewStatus(staffManageCampus);
  807. newStaffManageCampusInList.Add(staffManageCampus);
  808. var staffManageCollege = new CF_StaffManageCollege();
  809. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  810. staffManageCollege.UserID = newStaff.UserID;
  811. staffManageCollege.CollegeID = staffView.CollegeID;
  812. this.SetNewStatus(staffManageCollege);
  813. newStaffManageCollegeInList.Add(staffManageCollege);
  814. newStaff.DepartmentID = staffView.DepartmentID;
  815. if (staffView.DepartmentID.HasValue && staffView.DepartmentID != Guid.Empty)
  816. {
  817. var staffManageDepartment = new CF_StaffManageDepartment();
  818. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  819. staffManageDepartment.UserID = newStaff.UserID;
  820. staffManageDepartment.DepartmentID = staffView.DepartmentID;
  821. this.SetNewStatus(staffManageDepartment);
  822. newStaffManageDepartmentInList.Add(staffManageDepartment);
  823. }
  824. newStaff.SexID = staffView.SexID;
  825. newStaff.BirthDate = staffView.BirthDate;
  826. newStaff.NationID = staffView.NationID;
  827. newStaff.PoliticsID = staffView.PoliticsID;
  828. newStaff.CertificatesType = staffView.CertificatesType;
  829. newStaff.CertificatesNum = staffView.CertificatesNum;
  830. newStaff.TeacherTypeID = staffView.TeacherTypeID;
  831. newStaff.IncumbencyState = staffView.IncumbencyState;
  832. newStaff.SituationID = staffView.SituationID;
  833. newStaff.TitleID = staffView.TitleID;
  834. newStaff.LiteracyLevelID = staffView.LiteracyLevelID;
  835. newStaff.LearnPositionID = staffView.LearnPositionID;
  836. newStaff.IsDualTeacher = staffView.IsDualTeacher;
  837. newStaff.PaymentLevelID = staffView.PaymentLevelID;
  838. newStaff.WorkDate = staffView.WorkDate;
  839. newStaff.ComeSchoolDate = staffView.ComeSchoolDate;
  840. if (!string.IsNullOrEmpty(photoUrl))
  841. {
  842. newStaff.PhotoUrl = photoUrl;
  843. }
  844. newStaff.Profile = staffView.Profile;
  845. newStaff.Remark = staffView.Remark;
  846. this.SetNewStatus(newStaff);
  847. newStaffInList.Add(newStaff);
  848. var newStaffProfile = new CF_StaffProfile();
  849. newStaffProfile.UserID = newStaff.UserID;
  850. newStaffProfile.UsedName = staffView.UsedName;
  851. newStaffProfile.Nationality = staffView.Nationality;
  852. newStaffProfile.Place = staffView.Place;
  853. newStaffProfile.Email = staffView.Email;
  854. newStaffProfile.ZIPCode = staffView.ZIPCode;
  855. newStaffProfile.WeChatNum = staffView.WeChatNum;
  856. newStaffProfile.QQ = staffView.QQ;
  857. newStaffProfile.Telephone = staffView.Telephone;
  858. newStaffProfile.OfficeTelephone = staffView.OfficeTelephone;
  859. newStaffProfile.HousePhone = staffView.HousePhone;
  860. newStaffProfile.Mobile = staffView.Mobile;
  861. newStaffProfile.Speciality = staffView.Speciality;
  862. newStaffProfile.HealthStateID = staffView.HealthStateID;
  863. newStaffProfile.ReligionID = staffView.ReligionID;
  864. newStaffProfile.Account = staffView.Account;
  865. newStaffProfile.Residence = staffView.Residence;
  866. newStaffProfile.HomeAddress = staffView.HomeAddress;
  867. newStaffProfile.Address = staffView.Address;
  868. newStaffProfile.NowAddress = staffView.NowAddress;
  869. this.SetNewStatus(newStaffProfile);
  870. newStaffProfileInList.Add(newStaffProfile);
  871. }
  872. using (TransactionScope ts = new TransactionScope())
  873. {
  874. UnitOfWork.Delete<CF_StaffManageDepartment>(x => DepartmentUserIDDelList.Contains(x.UserID));
  875. UnitOfWork.Delete<CF_StaffManageCollege>(x => CollegeUserIDDelList.Contains(x.UserID));
  876. UnitOfWork.Delete<CF_StaffManageCampus>(x => CampusUserIDDelList.Contains(x.UserID));
  877. UnitOfWork.BulkInsert<Sys_User>(newUserInList);
  878. UnitOfWork.BulkInsert(newUserInList, (x => x.Sys_Role));
  879. UnitOfWork.BulkInsert<CF_Staff>(newStaffInList);
  880. UnitOfWork.BulkInsert<CF_StaffProfile>(newStaffProfileInList);
  881. UnitOfWork.BulkInsert<CF_StaffManageCampus>(newStaffManageCampusInList);
  882. UnitOfWork.BulkInsert<CF_StaffManageCollege>(newStaffManageCollegeInList);
  883. UnitOfWork.BulkInsert<CF_StaffManageDepartment>(newStaffManageDepartmentInList);
  884. if (newUserUpList != null && newUserUpList.Count() > 0)
  885. {
  886. UnitOfWork.BatchUpdate(newUserUpList);
  887. }
  888. if (newStaffUpList != null && newStaffUpList.Count() > 0)
  889. {
  890. UnitOfWork.BatchUpdate(newStaffUpList);
  891. }
  892. if (newStaffProfileUpList != null && newStaffProfileUpList.Count() > 0)
  893. {
  894. UnitOfWork.BatchUpdate(newStaffProfileUpList);
  895. }
  896. ts.Complete();
  897. }
  898. }
  899. else
  900. {
  901. var staffVerify = staffDAL.Value.staffRepository.GetList(x => x.UserID != staffView.UserID, (x => x.Sys_User)).Where(x => x.Sys_User.LoginID == staffView.StaffCode.Trim()).SingleOrDefault();
  902. if (staffVerify != null)
  903. {
  904. throw new Exception("已存在相同的教职工号(教职工号重复),请核查。");
  905. }
  906. else
  907. {
  908. var studentVerify = staffDAL.Value.StudentRepository.GetList(x => x.UserID != staffView.UserID,
  909. (x => x.Sys_User)).Where(x => x.Sys_User.LoginID == staffView.StaffCode.Trim()).SingleOrDefault();
  910. if (studentVerify != null)
  911. {
  912. throw new Exception("学生信息中已存在相同的用户(用户名重复),请核查。");
  913. }
  914. else
  915. {
  916. throw new Exception("用户信息中已存在相同的用户(用户名重复),请核查。");
  917. }
  918. }
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. throw new Exception(ex.Message);
  924. }
  925. }
  926. /// <summary>
  927. /// 删除
  928. /// </summary>
  929. /// <param name="userIDs"></param>
  930. /// <returns></returns>
  931. public bool StaffDelete(List<Guid?> userIDs)
  932. {
  933. try
  934. {
  935. UnitOfWork.Remove<CF_StaffManageDepartment>(x => userIDs.Contains(x.UserID));
  936. UnitOfWork.Remove<CF_StaffManageCollege>(x => userIDs.Contains(x.UserID));
  937. UnitOfWork.Remove<CF_StaffManageCampus>(x => userIDs.Contains(x.UserID));
  938. UnitOfWork.Remove<CF_StaffProfile>(x => userIDs.Contains(x.UserID));
  939. UnitOfWork.Remove<CF_Staff>(x => userIDs.Contains(x.UserID));
  940. var userList = staffDAL.Value.UserRepository.GetList(x => userIDs.Contains(x.UserID), (x => x.Sys_Role)).ToList();
  941. userList.ForEach(x => x.Sys_Role = new HashSet<Sys_Role>());
  942. UnitOfWork.Remove<Sys_User>(x => userIDs.Contains(x.UserID));
  943. UnitOfWork.Commit();
  944. return true;
  945. }
  946. catch (Exception)
  947. {
  948. throw;
  949. }
  950. }
  951. /// <summary>
  952. /// 验证
  953. /// </summary>
  954. /// <param name="collegeID"></param>
  955. /// <param name="departmentID"></param>
  956. /// <returns></returns>
  957. public bool GetVerification(Guid? collegeID, Guid? departmentID)
  958. {
  959. try
  960. {
  961. var college = staffDAL.Value.CollegeRepository.GetList(x => x.CollegeID == collegeID).SingleOrDefault();
  962. if (departmentID.HasValue)
  963. {
  964. var department = staffDAL.Value.DepartmentRepository.GetList(x => x.DepartmentID == departmentID).SingleOrDefault();
  965. if (department.CollegeID != collegeID)
  966. {
  967. return false;
  968. }
  969. }
  970. return true;
  971. }
  972. catch (Exception ex)
  973. {
  974. throw new Exception(ex.Message);
  975. }
  976. }
  977. /// <summary>
  978. /// 删除照片(单个删除)
  979. /// </summary>
  980. /// <param name="userID"></param>
  981. public void DeletePhoto(Guid? userID)
  982. {
  983. try
  984. {
  985. var staff = staffDAL.Value.staffRepository.GetList(x => x.UserID == userID).SingleOrDefault();
  986. if (staff != null)
  987. {
  988. if (!string.IsNullOrEmpty(staff.PhotoUrl))
  989. {
  990. FileUploadHelper.DeleteFile(staff.PhotoUrl);
  991. staff.PhotoUrl = null;
  992. this.UnitOfWork.Commit();
  993. }
  994. else
  995. {
  996. throw new Exception("对应的照片不存在。");
  997. }
  998. }
  999. else
  1000. {
  1001. throw new Exception("对应的信息未保存,数据有误。");
  1002. }
  1003. }
  1004. catch (Exception ex)
  1005. {
  1006. throw new Exception(ex.Message);
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// 删除照片(批量删除)
  1011. /// </summary>
  1012. /// <param name="userIDs"></param>
  1013. /// <returns></returns>
  1014. public bool PicDelete(List<Guid?> userIDs)
  1015. {
  1016. try
  1017. {
  1018. List<string> photoUrlList = new List<string>();
  1019. List<CF_Staff> staffUpList = new List<CF_Staff>();
  1020. var staffList = staffDAL.Value.staffRepository.GetList(x => userIDs.Contains(x.UserID)).ToList();
  1021. foreach (var staff in staffList)
  1022. {
  1023. if (staff != null)
  1024. {
  1025. if (!string.IsNullOrEmpty(staff.PhotoUrl))
  1026. {
  1027. photoUrlList.Add(staff.PhotoUrl);
  1028. staff.PhotoUrl = null;
  1029. staffUpList.Add(staff);
  1030. }
  1031. }
  1032. }
  1033. using (TransactionScope ts = new TransactionScope())
  1034. {
  1035. foreach (var photoUrl in photoUrlList)
  1036. {
  1037. FileUploadHelper.DeleteFile(photoUrl);
  1038. }
  1039. if (staffUpList != null && staffUpList.Count() > 0)
  1040. {
  1041. UnitOfWork.BatchUpdate(staffUpList);
  1042. }
  1043. ts.Complete();
  1044. }
  1045. return true;
  1046. }
  1047. catch (Exception)
  1048. {
  1049. throw;
  1050. }
  1051. }
  1052. /// <summary>
  1053. /// 查询教师对应的角色信息UserView
  1054. /// </summary>
  1055. /// <param name="configuretView"></param>
  1056. /// <param name="userID"></param>
  1057. /// <param name="roleID"></param>
  1058. /// <param name="dataRange"></param>
  1059. /// <param name="roleStatus"></param>
  1060. /// <param name="pageIndex"></param>
  1061. /// <param name="pageSize"></param>
  1062. /// <returns></returns>
  1063. public IGridResultSet<UserView> GetRoleListViewGrid(ConfiguretView configuretView, Guid? userID, Guid? roleID, int? dataRange, int? roleStatus, int pageIndex, int pageSize)
  1064. {
  1065. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1066. expStaff = expStaff.And(x => x.UserID == userID);
  1067. var query = staffDAL.Value.GetStaffRoleViewQueryable(expStaff);
  1068. if (roleID.HasValue)
  1069. {
  1070. query = query.Where(x => x.RoleID == roleID);
  1071. }
  1072. if (dataRange.HasValue)
  1073. {
  1074. query = query.Where(x => x.DataRange == dataRange);
  1075. }
  1076. if (roleStatus.HasValue)
  1077. {
  1078. query = query.Where(x => x.RoleStatus == roleStatus);
  1079. }
  1080. //查询条件
  1081. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  1082. {
  1083. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  1084. }
  1085. return query.OrderBy(x => x.LoginID.Length).ThenBy(x => x.LoginID).ThenBy(x => x.RoleOrderNo).ToGridResultSet<UserView>(pageIndex, pageSize);
  1086. }
  1087. /// <summary>
  1088. /// 查询教师对应的角色信息List
  1089. /// </summary>
  1090. /// <param name="configuretView"></param>
  1091. /// <param name="userID"></param>
  1092. /// <param name="roleID"></param>
  1093. /// <param name="dataRange"></param>
  1094. /// <param name="roleStatus"></param>
  1095. /// <returns></returns>
  1096. public IList<UserView> GetRoleListViewList(ConfiguretView configuretView, Guid? userID, Guid? roleID, int? dataRange, int? roleStatus)
  1097. {
  1098. Expression<Func<CF_Staff, bool>> expStaff = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  1099. expStaff = expStaff.And(x => x.UserID == userID);
  1100. var query = staffDAL.Value.GetStaffRoleViewQueryable(expStaff);
  1101. if (roleID.HasValue)
  1102. {
  1103. query = query.Where(x => x.RoleID == roleID);
  1104. }
  1105. if (dataRange.HasValue)
  1106. {
  1107. query = query.Where(x => x.DataRange == dataRange);
  1108. }
  1109. if (roleStatus.HasValue)
  1110. {
  1111. query = query.Where(x => x.RoleStatus == roleStatus);
  1112. }
  1113. //查询条件
  1114. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  1115. {
  1116. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
  1117. }
  1118. return query.OrderBy(x => x.LoginID.Length).ThenBy(x => x.LoginID).ThenBy(x => x.RoleOrderNo).ToList();
  1119. }
  1120. /// <summary>
  1121. /// 导入照片
  1122. /// </summary>
  1123. /// <param name="photoPaths"></param>
  1124. /// <param name="importPicType"></param>
  1125. public void StaffPicImport(IList<string> photoPaths, string importPicType)
  1126. {
  1127. List<CF_Staff> staffUpList = new List<CF_Staff>();
  1128. var mapList = photoPaths.Select(s => new
  1129. {
  1130. PhotoName = Path.GetFileNameWithoutExtension(s).Trim(),
  1131. PhotoPath = s,
  1132. }).ToArray();
  1133. var photoNameList = mapList.Select(s => s.PhotoName).Distinct().ToArray();
  1134. var userList = new List<Sys_User>();
  1135. var staffList = new List<CF_Staff>();
  1136. switch (importPicType)
  1137. {
  1138. case "StaffCode":
  1139. userList = staffDAL.Value.UserRepository.GetList(x => photoNameList.Contains(x.LoginID), (x => x.CF_Staff)).ToList();
  1140. break;
  1141. case "IDNumber":
  1142. staffList = staffDAL.Value.staffRepository.GetList(x => photoNameList.Contains(x.CertificatesNum)).ToList();
  1143. break;
  1144. }
  1145. foreach (var map in mapList)
  1146. {
  1147. switch (importPicType)
  1148. {
  1149. case "StaffCode":
  1150. var user = userList.FirstOrDefault(w => w.LoginID == map.PhotoName);
  1151. if (user == null)
  1152. {
  1153. throw new Exception("导入照片中存在无法匹对信息(名称:" + map.PhotoName + "-教职工号)" + ",请检查。");
  1154. }
  1155. else
  1156. {
  1157. if (user.CF_Staff == null)
  1158. {
  1159. throw new Exception("导入照片中存在无法匹对信息(名称:" + map.PhotoName + "-教职工号)" + ",请检查。");
  1160. }
  1161. else
  1162. {
  1163. user.CF_Staff.PhotoUrl = map.PhotoPath;
  1164. staffUpList.Add(user.CF_Staff);
  1165. }
  1166. }
  1167. break;
  1168. case "IDNumber":
  1169. var staff = staffList.FirstOrDefault(w => w.CertificatesNum == map.PhotoName);
  1170. if (staff == null)
  1171. {
  1172. throw new Exception("导入照片中存在无法匹对信息(名称:" + map.PhotoName + "-证件号码)" + ",请检查。");
  1173. }
  1174. else
  1175. {
  1176. staff.PhotoUrl = map.PhotoPath;
  1177. staffUpList.Add(staff);
  1178. }
  1179. break;
  1180. }
  1181. }
  1182. if (staffUpList != null && staffUpList.Count() > 0)
  1183. {
  1184. UnitOfWork.BatchUpdate(staffUpList);
  1185. }
  1186. }
  1187. /// <summary>
  1188. /// Excel教师信息导入
  1189. /// </summary>
  1190. /// <param name="cellheader"></param>
  1191. /// <param name="inCount"></param>
  1192. /// <param name="upCount"></param>
  1193. /// <param name="errdataList"></param>
  1194. /// <param name="errCount"></param>
  1195. /// <param name="sourcePhysicalPath"></param>
  1196. public void StaffImport(Dictionary<string, string> cellheader, out int? inCount, out int? upCount, out List<StaffView> errdataList, out int? errCount, string sourcePhysicalPath)
  1197. {
  1198. try
  1199. {
  1200. StringBuilder errorMsg = new StringBuilder();
  1201. List<StaffView> errList = new List<StaffView>();
  1202. cellheader.Remove("ErrorMessage");
  1203. List<StaffView> enlist = NpoiExcelHelper.ExcelToEntityList<StaffView>(cellheader, sourcePhysicalPath, out errorMsg, out errList);
  1204. cellheader.Add("ErrorMessage", "未导入原因");
  1205. //对List集合进行有效性校验
  1206. if (enlist.Count() <= 0)
  1207. {
  1208. throw new Exception("Excel文件数据为空,请检查。");
  1209. }
  1210. Regex reg = null; //正则表达式
  1211. DateTime result; //用于返回判断日期字段格式
  1212. inCount = 0; //导入个数
  1213. upCount = 0; //更新个数
  1214. errCount = 0; //失败个数
  1215. string errorMsgStr = ""; //错误信息
  1216. var teacherInitPassword = staffDAL.Value.ParameterRepository.GetList(x => x.ParameterTypeID == (int)CF_ParameterType.TeacherInitPassword).SingleOrDefault();
  1217. var teacherRoleList = staffDAL.Value.RoleRepository.GetList(x => x.TypeID == (int)SYS_RoleType.Teacher && x.RoleName.Contains("教师")).ToList();
  1218. List<Sys_User> newUserInList = new List<Sys_User>();
  1219. List<Sys_User> newUserUpList = new List<Sys_User>();
  1220. List<CF_Staff> newStaffInList = new List<CF_Staff>();
  1221. List<CF_Staff> newStaffUpList = new List<CF_Staff>();
  1222. List<CF_StaffProfile> newStaffProfileInList = new List<CF_StaffProfile>();
  1223. List<CF_StaffProfile> newStaffProfileUpList = new List<CF_StaffProfile>();
  1224. List<CF_StaffManageCampus> newStaffManageCampusInList = new List<CF_StaffManageCampus>();
  1225. List<CF_StaffManageCollege> newStaffManageCollegeInList = new List<CF_StaffManageCollege>();
  1226. List<CF_StaffManageDepartment> newStaffManageDepartmentInList = new List<CF_StaffManageDepartment>();
  1227. List<Guid?> CampusUserIDDelList = new List<Guid?>();
  1228. List<Guid?> CollegeUserIDDelList = new List<Guid?>();
  1229. List<Guid?> DepartmentUserIDDelList = new List<Guid?>();
  1230. //将循环中相关数据库查询统一查询出来进行匹配(尽量避免在循环中进行数据库查询)
  1231. //用户信息
  1232. var userList = staffDAL.Value.UserRepository.GetList(x => true).ToList();
  1233. //教职工号
  1234. var staffCodeList = enlist.Where(x => !string.IsNullOrEmpty(x.StaffCode)).Select(x => x.StaffCode.Trim()).ToList();
  1235. //对比后的newUserList
  1236. var newUserList = userList.Where(x => staffCodeList.Contains(x.LoginID)).ToList();
  1237. //性别
  1238. var sexList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Sex).ToList();
  1239. //民族
  1240. var nationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Nation).ToList();
  1241. //政治面貌
  1242. var politicsList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Politics).ToList();
  1243. //证件类型
  1244. var certificatesTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_CertificatesType).ToList();
  1245. //教师类型
  1246. var teacherTypeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_TeacherType).ToList();
  1247. //在职状态
  1248. var incumbencyStateList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_IncumbencyState).ToList();
  1249. //任课状况
  1250. var situationList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Situation).ToList();
  1251. //职称
  1252. var titleList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Title).ToList();
  1253. //文化程度
  1254. var literacyLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LiteracyLevel).ToList();
  1255. //学位
  1256. var learnPositionList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_LearnPosition).ToList();
  1257. //是否
  1258. var generalPurposeList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_GeneralPurpose).ToList();
  1259. //课酬级别
  1260. var paymentLevelList = IdNameExt.GetDictionaryItem(DictionaryItem.TP_PaymentLevel).ToList();
  1261. //健康状况
  1262. var healthStateList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_HealthState).ToList();
  1263. //宗教信仰
  1264. var religionList = IdNameExt.GetDictionaryItem(DictionaryItem.CF_Religion).ToList();
  1265. //院系所信息
  1266. var collegeList = staffDAL.Value.CollegeRepository.GetList(x => true).ToList();
  1267. //院系所
  1268. var collegeNameList = enlist.Where(x => !string.IsNullOrEmpty(x.CollegeName)).Select(x => x.CollegeName.Trim()).ToList();
  1269. //对比后的newCollegeList
  1270. var newCollegeList = collegeList.Where(x => collegeNameList.Contains(x.Name)).ToList();
  1271. //教研室信息
  1272. var departmentList = staffDAL.Value.DepartmentRepository.GetList(x => true).ToList();
  1273. //所属教研室
  1274. var departmentNameList = enlist.Where(x => !string.IsNullOrEmpty(x.DepartmentName)).Select(x => x.DepartmentName.Trim()).ToList();
  1275. //对比后的newDepartmentList
  1276. var newDepartmentList = departmentList.Where(x => departmentNameList.Contains(x.Name)).ToList();
  1277. //证件号码
  1278. var certificatesNumList = enlist.Where(x => !string.IsNullOrEmpty(x.CertificatesNum)).Select(x => x.CertificatesNum.Trim()).ToList();
  1279. //教师信息
  1280. var staffList = staffDAL.Value.staffRepository.GetList(x => true, (x => x.CF_StaffManageDepartment), (x => x.CF_StaffManageCollege),
  1281. (x => x.CF_StaffManageCampus), (x => x.CF_StaffProfile), (x => x.Sys_User)).ToList();
  1282. //对比后的certificatesNumStaffList
  1283. var certificatesNumStaffList = staffList.Where(x => certificatesNumList.Contains(x.CertificatesNum)).ToList();
  1284. //对比后的newUserIDList
  1285. var newUserIDList = newUserList.Select(x => x.UserID).ToList();
  1286. //对比后的newStaffList
  1287. var newStaffList = staffList.Where(x => newUserIDList.Contains(x.UserID)).ToList();
  1288. //循环检测数据列,对各数据列进行验证(必填、字典项验证、数据格式等)
  1289. for (int i = 0; i < enlist.Count; i++)
  1290. {
  1291. StaffView en = enlist[i]; //Excel表数据视图
  1292. Sys_User newUser = new Sys_User();
  1293. CF_Staff newStaff = new CF_Staff();
  1294. CF_StaffProfile newStaffProfile = new CF_StaffProfile();
  1295. //教职工号
  1296. if (string.IsNullOrWhiteSpace(en.StaffCode))
  1297. {
  1298. errCount++;
  1299. errorMsgStr = "教职工号不能为空";
  1300. en.ErrorMessage = errorMsgStr;
  1301. errList.Add(en);
  1302. errorMsg.AppendLine(errorMsgStr);
  1303. continue;
  1304. }
  1305. else
  1306. {
  1307. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  1308. if (!reg.IsMatch(en.StaffCode.Trim()))
  1309. {
  1310. errCount++;
  1311. errorMsgStr = "教职工号格式不正确,请检查(数字或英文字母)";
  1312. en.ErrorMessage = errorMsgStr;
  1313. errList.Add(en);
  1314. errorMsg.AppendLine(errorMsgStr);
  1315. continue;
  1316. }
  1317. else
  1318. {
  1319. newUser.LoginID = en.StaffCode.Trim();
  1320. newStaff.StaffCode = en.StaffCode.Trim();
  1321. }
  1322. }
  1323. //姓名
  1324. if (string.IsNullOrWhiteSpace(en.Name))
  1325. {
  1326. errCount++;
  1327. errorMsgStr = "姓名不能为空";
  1328. en.ErrorMessage = errorMsgStr;
  1329. errList.Add(en);
  1330. errorMsg.AppendLine(errorMsgStr);
  1331. continue;
  1332. }
  1333. else
  1334. {
  1335. newUser.Name = en.Name.Trim();
  1336. }
  1337. //曾用名
  1338. if (string.IsNullOrWhiteSpace(en.UsedName))
  1339. {
  1340. //暂不考虑
  1341. }
  1342. else
  1343. {
  1344. newStaffProfile.UsedName = en.UsedName.Trim();
  1345. }
  1346. //性别
  1347. if (string.IsNullOrWhiteSpace(en.SexStr))
  1348. {
  1349. errCount++;
  1350. errorMsgStr = "性别不能为空";
  1351. en.ErrorMessage = errorMsgStr;
  1352. errList.Add(en);
  1353. errorMsg.AppendLine(errorMsgStr);
  1354. continue;
  1355. }
  1356. else
  1357. {
  1358. var sex = sexList.Where(x => x.Name == en.SexStr.Trim()).SingleOrDefault();
  1359. if (sex == null)
  1360. {
  1361. errCount++;
  1362. errorMsgStr = "性别不存在,请检查";
  1363. en.ErrorMessage = errorMsgStr;
  1364. errList.Add(en);
  1365. errorMsg.AppendLine(errorMsgStr);
  1366. continue;
  1367. }
  1368. else
  1369. {
  1370. newStaff.SexID = sex.Value;
  1371. }
  1372. }
  1373. //出生日期
  1374. if (string.IsNullOrWhiteSpace(en.BirthDateStr))
  1375. {
  1376. //暂不考虑
  1377. }
  1378. else
  1379. {
  1380. //reg = new Regex(@"(\d{4})-(\d{1,2})-(\d{1,2})"); //日期正则表达式,2017-12-28
  1381. if (!DateTime.TryParse(en.BirthDateStr, out result))
  1382. {
  1383. errCount++;
  1384. errorMsgStr = "出生日期格式不正确,请检查";
  1385. en.ErrorMessage = errorMsgStr;
  1386. errList.Add(en);
  1387. errorMsg.AppendLine(errorMsgStr);
  1388. continue;
  1389. }
  1390. else
  1391. {
  1392. newStaff.BirthDate = Convert.ToDateTime(en.BirthDateStr);
  1393. }
  1394. }
  1395. //民族
  1396. if (string.IsNullOrWhiteSpace(en.NationStr))
  1397. {
  1398. //暂不考虑
  1399. }
  1400. else
  1401. {
  1402. var nation = nationList.Where(x => x.Name == en.NationStr.Trim()).SingleOrDefault();
  1403. if (nation == null)
  1404. {
  1405. errCount++;
  1406. errorMsgStr = "民族不存在,请检查";
  1407. en.ErrorMessage = errorMsgStr;
  1408. errList.Add(en);
  1409. errorMsg.AppendLine(errorMsgStr);
  1410. continue;
  1411. }
  1412. else
  1413. {
  1414. newStaff.NationID = nation.Value;
  1415. }
  1416. }
  1417. //政治面貌
  1418. if (string.IsNullOrWhiteSpace(en.PoliticsStr))
  1419. {
  1420. //暂不考虑
  1421. }
  1422. else
  1423. {
  1424. var politics = politicsList.Where(x => x.Name == en.PoliticsStr.Trim()).SingleOrDefault();
  1425. if (politics == null)
  1426. {
  1427. errCount++;
  1428. errorMsgStr = "政治面貌不存在,请检查";
  1429. en.ErrorMessage = errorMsgStr;
  1430. errList.Add(en);
  1431. errorMsg.AppendLine(errorMsgStr);
  1432. continue;
  1433. }
  1434. else
  1435. {
  1436. newStaff.PoliticsID = politics.Value;
  1437. }
  1438. }
  1439. //院系所
  1440. if (string.IsNullOrWhiteSpace(en.CollegeName))
  1441. {
  1442. errCount++;
  1443. errorMsgStr = RSL.Get("College") + "不能为空";
  1444. en.ErrorMessage = errorMsgStr;
  1445. errList.Add(en);
  1446. errorMsg.AppendLine(errorMsgStr);
  1447. continue;
  1448. }
  1449. else
  1450. {
  1451. var college = newCollegeList.Where(x => x.Name == en.CollegeName.Trim()).SingleOrDefault();
  1452. if (college == null)
  1453. {
  1454. errCount++;
  1455. errorMsgStr = RSL.Get("College") + "不存在,请检查";
  1456. en.ErrorMessage = errorMsgStr;
  1457. errList.Add(en);
  1458. errorMsg.AppendLine(errorMsgStr);
  1459. continue;
  1460. }
  1461. else
  1462. {
  1463. newStaff.CollegeID = college.CollegeID;
  1464. en.CampusID = college.CampusID;
  1465. }
  1466. }
  1467. //所属教研室
  1468. if (string.IsNullOrWhiteSpace(en.DepartmentName))
  1469. {
  1470. //暂不考虑
  1471. }
  1472. else
  1473. {
  1474. var department = newDepartmentList.Where(x => x.Name == en.DepartmentName.Trim()).SingleOrDefault();
  1475. if (department == null)
  1476. {
  1477. errCount++;
  1478. errorMsgStr = "所属教研室不存在,请检查";
  1479. en.ErrorMessage = errorMsgStr;
  1480. errList.Add(en);
  1481. errorMsg.AppendLine(errorMsgStr);
  1482. continue;
  1483. }
  1484. else
  1485. {
  1486. //判断院系所与所属教研室是否匹配
  1487. if (department.CollegeID != newStaff.CollegeID)
  1488. {
  1489. errCount++;
  1490. errorMsgStr = "所属教研室和" + RSL.Get("College") + "不匹配,请核查。";
  1491. en.ErrorMessage = errorMsgStr;
  1492. errList.Add(en);
  1493. errorMsg.AppendLine(errorMsgStr);
  1494. continue;
  1495. }
  1496. else
  1497. {
  1498. newStaff.DepartmentID = department.DepartmentID;
  1499. }
  1500. }
  1501. }
  1502. //证件类型
  1503. if (string.IsNullOrWhiteSpace(en.CertificatesTypeStr))
  1504. {
  1505. //默认为身份证
  1506. newStaff.CertificatesType = (int)CF_CertificatesType.IdCrad;
  1507. }
  1508. else
  1509. {
  1510. var certificatesType = certificatesTypeList.Where(x => x.Name == en.CertificatesTypeStr.Trim()).SingleOrDefault();
  1511. if (certificatesType == null)
  1512. {
  1513. errCount++;
  1514. errorMsgStr = "证件类型不存在,请检查";
  1515. en.ErrorMessage = errorMsgStr;
  1516. errList.Add(en);
  1517. errorMsg.AppendLine(errorMsgStr);
  1518. continue;
  1519. }
  1520. else
  1521. {
  1522. newStaff.CertificatesType = certificatesType.Value;
  1523. }
  1524. }
  1525. //证件号码
  1526. if (string.IsNullOrWhiteSpace(en.CertificatesNum))
  1527. {
  1528. //暂不考虑
  1529. }
  1530. else
  1531. {
  1532. if (string.IsNullOrWhiteSpace(en.CertificatesTypeStr))
  1533. {
  1534. errCount++;
  1535. errorMsgStr = "证件号码不为空时,证件类型不能为空";
  1536. en.ErrorMessage = errorMsgStr;
  1537. errList.Add(en);
  1538. errorMsg.AppendLine(errorMsgStr);
  1539. continue;
  1540. }
  1541. else
  1542. {
  1543. reg = new Regex(@"^[0-9a-zA-Z\s?]+$"); //正则表达式(请输入数字或英文字母)
  1544. if (!reg.IsMatch(en.CertificatesNum.Trim()))
  1545. {
  1546. errCount++;
  1547. errorMsgStr = "证件号码格式不正确,请检查(数字或英文字母)";
  1548. en.ErrorMessage = errorMsgStr;
  1549. errList.Add(en);
  1550. errorMsg.AppendLine(errorMsgStr);
  1551. continue;
  1552. }
  1553. else
  1554. {
  1555. newStaff.CertificatesNum = en.CertificatesNum.Trim();
  1556. }
  1557. }
  1558. }
  1559. //教师类型
  1560. if (string.IsNullOrWhiteSpace(en.TeacherTypeStr))
  1561. {
  1562. errCount++;
  1563. errorMsgStr = "教师类型不能为空";
  1564. en.ErrorMessage = errorMsgStr;
  1565. errList.Add(en);
  1566. errorMsg.AppendLine(errorMsgStr);
  1567. continue;
  1568. }
  1569. else
  1570. {
  1571. var teacherType = teacherTypeList.Where(x => x.Name == en.TeacherTypeStr.Trim()).SingleOrDefault();
  1572. if (teacherType == null)
  1573. {
  1574. errCount++;
  1575. errorMsgStr = "教师类型不存在,请检查";
  1576. en.ErrorMessage = errorMsgStr;
  1577. errList.Add(en);
  1578. errorMsg.AppendLine(errorMsgStr);
  1579. continue;
  1580. }
  1581. else
  1582. {
  1583. newStaff.TeacherTypeID = teacherType.Value;
  1584. }
  1585. }
  1586. //在职状态
  1587. if (string.IsNullOrWhiteSpace(en.IncumbencyStateStr))
  1588. {
  1589. errCount++;
  1590. errorMsgStr = "在职状态不能为空";
  1591. en.ErrorMessage = errorMsgStr;
  1592. errList.Add(en);
  1593. errorMsg.AppendLine(errorMsgStr);
  1594. continue;
  1595. }
  1596. else
  1597. {
  1598. var incumbencyState = incumbencyStateList.Where(x => x.Name == en.IncumbencyStateStr.Trim()).SingleOrDefault();
  1599. if (incumbencyState == null)
  1600. {
  1601. errCount++;
  1602. errorMsgStr = "在职状态不存在,请检查";
  1603. en.ErrorMessage = errorMsgStr;
  1604. errList.Add(en);
  1605. errorMsg.AppendLine(errorMsgStr);
  1606. continue;
  1607. }
  1608. else
  1609. {
  1610. newStaff.IncumbencyState = incumbencyState.Value;
  1611. }
  1612. }
  1613. //任课状况
  1614. if (string.IsNullOrWhiteSpace(en.SituationStr))
  1615. {
  1616. //暂不考虑
  1617. }
  1618. else
  1619. {
  1620. var situation = situationList.Where(x => x.Name == en.SituationStr.Trim()).SingleOrDefault();
  1621. if (situation == null)
  1622. {
  1623. errCount++;
  1624. errorMsgStr = "任课状况不存在,请检查";
  1625. en.ErrorMessage = errorMsgStr;
  1626. errList.Add(en);
  1627. errorMsg.AppendLine(errorMsgStr);
  1628. continue;
  1629. }
  1630. else
  1631. {
  1632. newStaff.SituationID = situation.Value;
  1633. }
  1634. }
  1635. //职称
  1636. if (string.IsNullOrWhiteSpace(en.TitleStr))
  1637. {
  1638. //暂不考虑
  1639. }
  1640. else
  1641. {
  1642. var title = titleList.Where(x => x.Name == en.TitleStr.Trim()).SingleOrDefault();
  1643. if (title == null)
  1644. {
  1645. errCount++;
  1646. errorMsgStr = "职称不存在,请检查";
  1647. en.ErrorMessage = errorMsgStr;
  1648. errList.Add(en);
  1649. errorMsg.AppendLine(errorMsgStr);
  1650. continue;
  1651. }
  1652. else
  1653. {
  1654. newStaff.TitleID = title.Value;
  1655. }
  1656. }
  1657. //文化程度
  1658. if (string.IsNullOrWhiteSpace(en.LiteracyLevelStr))
  1659. {
  1660. //暂不考虑
  1661. }
  1662. else
  1663. {
  1664. var literacyLevel = literacyLevelList.Where(x => x.Name == en.LiteracyLevelStr.Trim()).SingleOrDefault();
  1665. if (literacyLevel == null)
  1666. {
  1667. errCount++;
  1668. errorMsgStr = "文化程度不存在,请检查";
  1669. en.ErrorMessage = errorMsgStr;
  1670. errList.Add(en);
  1671. errorMsg.AppendLine(errorMsgStr);
  1672. continue;
  1673. }
  1674. else
  1675. {
  1676. newStaff.LiteracyLevelID = literacyLevel.Value;
  1677. }
  1678. }
  1679. //学位
  1680. if (string.IsNullOrWhiteSpace(en.LearnPositionStr))
  1681. {
  1682. //暂不考虑
  1683. }
  1684. else
  1685. {
  1686. var learnPosition = learnPositionList.Where(x => x.Name == en.LearnPositionStr.Trim()).SingleOrDefault();
  1687. if (learnPosition == null)
  1688. {
  1689. errCount++;
  1690. errorMsgStr = "学位不存在,请检查";
  1691. en.ErrorMessage = errorMsgStr;
  1692. errList.Add(en);
  1693. errorMsg.AppendLine(errorMsgStr);
  1694. continue;
  1695. }
  1696. else
  1697. {
  1698. newStaff.LearnPositionID = learnPosition.Value;
  1699. }
  1700. }
  1701. //是否双师型
  1702. if (string.IsNullOrWhiteSpace(en.IsDualTeacherStr))
  1703. {
  1704. newStaff.IsDualTeacher = false;
  1705. }
  1706. else
  1707. {
  1708. var isDualTeacher = generalPurposeList.Where(x => x.Name == en.IsDualTeacherStr.Trim()).SingleOrDefault();
  1709. if (isDualTeacher == null)
  1710. {
  1711. errCount++;
  1712. errorMsgStr = "是否双师型不存在,请检查";
  1713. en.ErrorMessage = errorMsgStr;
  1714. errList.Add(en);
  1715. errorMsg.AppendLine(errorMsgStr);
  1716. continue;
  1717. }
  1718. else
  1719. {
  1720. newStaff.IsDualTeacher = isDualTeacher.Value == (int)CF_GeneralPurpose.IsYes ? true : false;
  1721. }
  1722. }
  1723. //课酬级别
  1724. if (string.IsNullOrWhiteSpace(en.PaymentLevelStr))
  1725. {
  1726. //暂不考虑
  1727. }
  1728. else
  1729. {
  1730. var paymentLevel = paymentLevelList.Where(x => x.Name == en.PaymentLevelStr.Trim()).SingleOrDefault();
  1731. if (paymentLevel == null)
  1732. {
  1733. errCount++;
  1734. errorMsgStr = "课酬级别不存在,请检查";
  1735. en.ErrorMessage = errorMsgStr;
  1736. errList.Add(en);
  1737. errorMsg.AppendLine(errorMsgStr);
  1738. continue;
  1739. }
  1740. else
  1741. {
  1742. newStaff.PaymentLevelID = paymentLevel.Value;
  1743. }
  1744. }
  1745. //国籍
  1746. if (string.IsNullOrWhiteSpace(en.Nationality))
  1747. {
  1748. //暂不考虑
  1749. }
  1750. else
  1751. {
  1752. newStaffProfile.Nationality = en.Nationality.Trim();
  1753. }
  1754. //籍贯
  1755. if (string.IsNullOrWhiteSpace(en.Place))
  1756. {
  1757. //暂不考虑
  1758. }
  1759. else
  1760. {
  1761. newStaffProfile.Place = en.Place.Trim();
  1762. }
  1763. //参加工作年月
  1764. if (string.IsNullOrWhiteSpace(en.WorkDateStr))
  1765. {
  1766. //暂不考虑
  1767. }
  1768. else
  1769. {
  1770. if (!DateTime.TryParse(en.WorkDateStr, out result))
  1771. {
  1772. errCount++;
  1773. errorMsgStr = "参加工作年月格式不正确,请检查";
  1774. en.ErrorMessage = errorMsgStr;
  1775. errList.Add(en);
  1776. errorMsg.AppendLine(errorMsgStr);
  1777. continue;
  1778. }
  1779. else
  1780. {
  1781. newStaff.WorkDate = Convert.ToDateTime(en.WorkDateStr);
  1782. }
  1783. }
  1784. //来校年月
  1785. if (string.IsNullOrWhiteSpace(en.ComeSchoolDateStr))
  1786. {
  1787. //暂不考虑
  1788. }
  1789. else
  1790. {
  1791. if (!DateTime.TryParse(en.ComeSchoolDateStr, out result))
  1792. {
  1793. errCount++;
  1794. errorMsgStr = "来校年月格式不正确,请检查";
  1795. en.ErrorMessage = errorMsgStr;
  1796. errList.Add(en);
  1797. errorMsg.AppendLine(errorMsgStr);
  1798. continue;
  1799. }
  1800. else
  1801. {
  1802. newStaff.ComeSchoolDate = Convert.ToDateTime(en.ComeSchoolDateStr);
  1803. }
  1804. }
  1805. //电子邮箱
  1806. if (string.IsNullOrWhiteSpace(en.Email))
  1807. {
  1808. //暂不考虑
  1809. }
  1810. else
  1811. {
  1812. reg = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); //正则表达式
  1813. if (!reg.IsMatch(en.Email.Trim()))
  1814. {
  1815. errCount++;
  1816. errorMsgStr = "电子邮箱格式不正确,请检查";
  1817. en.ErrorMessage = errorMsgStr;
  1818. errList.Add(en);
  1819. errorMsg.AppendLine(errorMsgStr);
  1820. continue;
  1821. }
  1822. else
  1823. {
  1824. newStaffProfile.Email = en.Email.Trim();
  1825. }
  1826. }
  1827. //邮政编码
  1828. if (string.IsNullOrWhiteSpace(en.ZIPCode))
  1829. {
  1830. //暂不考虑
  1831. }
  1832. else
  1833. {
  1834. reg = new Regex(@"[1-9]\d{5}(?!\d)"); //正则表达式
  1835. if (!reg.IsMatch(en.ZIPCode.Trim()))
  1836. {
  1837. errCount++;
  1838. errorMsgStr = "邮政编码格式不正确,请检查";
  1839. en.ErrorMessage = errorMsgStr;
  1840. errList.Add(en);
  1841. errorMsg.AppendLine(errorMsgStr);
  1842. continue;
  1843. }
  1844. else
  1845. {
  1846. newStaffProfile.ZIPCode = en.ZIPCode.Trim();
  1847. }
  1848. }
  1849. //微信号
  1850. if (string.IsNullOrWhiteSpace(en.WeChatNum))
  1851. {
  1852. //暂不考虑
  1853. }
  1854. else
  1855. {
  1856. newStaffProfile.WeChatNum = en.WeChatNum.Trim();
  1857. }
  1858. //QQ
  1859. if (string.IsNullOrWhiteSpace(en.QQ))
  1860. {
  1861. //暂不考虑
  1862. }
  1863. else
  1864. {
  1865. reg = new Regex(@"[1-9][0-9]{4,}"); //正则表达式
  1866. if (!reg.IsMatch(en.QQ.Trim()))
  1867. {
  1868. errCount++;
  1869. errorMsgStr = "QQ格式不正确,请检查";
  1870. en.ErrorMessage = errorMsgStr;
  1871. errList.Add(en);
  1872. errorMsg.AppendLine(errorMsgStr);
  1873. continue;
  1874. }
  1875. else
  1876. {
  1877. newStaffProfile.QQ = en.QQ.Trim();
  1878. }
  1879. }
  1880. //家庭电话
  1881. if (string.IsNullOrWhiteSpace(en.Telephone))
  1882. {
  1883. //暂不考虑
  1884. }
  1885. else
  1886. {
  1887. newStaffProfile.Telephone = en.Telephone.Trim();
  1888. }
  1889. //办公电话
  1890. if (string.IsNullOrWhiteSpace(en.OfficeTelephone))
  1891. {
  1892. //暂不考虑
  1893. }
  1894. else
  1895. {
  1896. newStaffProfile.OfficeTelephone = en.OfficeTelephone.Trim();
  1897. }
  1898. //住宅电话
  1899. if (string.IsNullOrWhiteSpace(en.HousePhone))
  1900. {
  1901. //暂不考虑
  1902. }
  1903. else
  1904. {
  1905. newStaffProfile.HousePhone = en.HousePhone.Trim();
  1906. }
  1907. //移动电话
  1908. if (string.IsNullOrWhiteSpace(en.Mobile))
  1909. {
  1910. //暂不考虑
  1911. }
  1912. else
  1913. {
  1914. newStaffProfile.Mobile = en.Mobile.Trim();
  1915. }
  1916. //健康状况
  1917. if (string.IsNullOrWhiteSpace(en.HealthStateStr))
  1918. {
  1919. newStaffProfile.HealthStateID = (int)CF_HealthState.Healthy;
  1920. }
  1921. else
  1922. {
  1923. var healthState = healthStateList.Where(x => x.Name == en.HealthStateStr.Trim()).SingleOrDefault();
  1924. if (healthState == null)
  1925. {
  1926. errCount++;
  1927. errorMsgStr = "健康状况不存在,请检查";
  1928. en.ErrorMessage = errorMsgStr;
  1929. errList.Add(en);
  1930. errorMsg.AppendLine(errorMsgStr);
  1931. continue;
  1932. }
  1933. else
  1934. {
  1935. newStaffProfile.HealthStateID = healthState.Value;
  1936. }
  1937. }
  1938. //宗教信仰
  1939. if (string.IsNullOrWhiteSpace(en.ReligionStr))
  1940. {
  1941. //暂不考虑
  1942. }
  1943. else
  1944. {
  1945. var religion = religionList.Where(x => x.Name == en.ReligionStr.Trim()).SingleOrDefault();
  1946. if (religion == null)
  1947. {
  1948. errCount++;
  1949. errorMsgStr = "宗教信仰不存在,请检查";
  1950. en.ErrorMessage = errorMsgStr;
  1951. errList.Add(en);
  1952. errorMsg.AppendLine(errorMsgStr);
  1953. continue;
  1954. }
  1955. else
  1956. {
  1957. newStaffProfile.ReligionID = religion.Value;
  1958. }
  1959. }
  1960. //特长
  1961. if (string.IsNullOrWhiteSpace(en.Speciality))
  1962. {
  1963. //暂不考虑
  1964. }
  1965. else
  1966. {
  1967. newStaffProfile.Speciality = en.Speciality.Trim();
  1968. }
  1969. //银行卡号
  1970. if (string.IsNullOrWhiteSpace(en.Account))
  1971. {
  1972. //暂不考虑
  1973. }
  1974. else
  1975. {
  1976. reg = new Regex(@"^[0-9]*$"); //正则表达式
  1977. if (!reg.IsMatch(en.Account.Trim()))
  1978. {
  1979. errCount++;
  1980. errorMsgStr = "银行卡号格式不正确,请检查";
  1981. en.ErrorMessage = errorMsgStr;
  1982. errList.Add(en);
  1983. errorMsg.AppendLine(errorMsgStr);
  1984. continue;
  1985. }
  1986. else
  1987. {
  1988. newStaffProfile.Account = en.Account.Trim();
  1989. }
  1990. }
  1991. //户口所在地
  1992. if (string.IsNullOrWhiteSpace(en.Residence))
  1993. {
  1994. //暂不考虑
  1995. }
  1996. else
  1997. {
  1998. newStaffProfile.Residence = en.Residence.Trim();
  1999. }
  2000. //家庭住址
  2001. if (string.IsNullOrWhiteSpace(en.HomeAddress))
  2002. {
  2003. //暂不考虑
  2004. }
  2005. else
  2006. {
  2007. newStaffProfile.HomeAddress = en.HomeAddress.Trim();
  2008. }
  2009. //通信地址
  2010. if (string.IsNullOrWhiteSpace(en.Address))
  2011. {
  2012. //暂不考虑
  2013. }
  2014. else
  2015. {
  2016. newStaffProfile.Address = en.Address.Trim();
  2017. }
  2018. //现住地址
  2019. if (string.IsNullOrWhiteSpace(en.NowAddress))
  2020. {
  2021. //暂不考虑
  2022. }
  2023. else
  2024. {
  2025. newStaffProfile.NowAddress = en.NowAddress.Trim();
  2026. }
  2027. //简介
  2028. if (string.IsNullOrWhiteSpace(en.Profile))
  2029. {
  2030. //暂不考虑
  2031. }
  2032. else
  2033. {
  2034. newStaff.Profile = en.Profile.Trim();
  2035. }
  2036. //备注
  2037. if (string.IsNullOrWhiteSpace(en.Remark))
  2038. {
  2039. //暂不考虑
  2040. }
  2041. else
  2042. {
  2043. newStaff.Remark = en.Remark.Trim();
  2044. }
  2045. ////Excel表重复性验证(注:当数据表中没有此记录,但是Excel中有重复数据时的去掉)
  2046. //for (int j = i + 1; j < enlist.Count; j++)
  2047. //{
  2048. // StaffView enA = enlist[j];
  2049. // //根据Excel表中的业务主键进行去重(教职工号或证件号码唯一)
  2050. // if (en.StaffCode == enA.StaffCode && en.CertificatesNum == enA.CertificatesNum)
  2051. // {
  2052. // //用于标识Excel表中的重复记录(由于是批量进行插入数据表)
  2053. // }
  2054. //}
  2055. //数据表重复性验证(教职工号或证件号码唯一)
  2056. var userVerify = newUserList.Where(x => x.LoginID == newUser.LoginID).SingleOrDefault();
  2057. if (userVerify == null)
  2058. {
  2059. //判断证件号码
  2060. if (!string.IsNullOrEmpty(newStaff.CertificatesNum))
  2061. {
  2062. if (!newStaffUpList.Any(x => x.CertificatesNum == newStaff.CertificatesNum))
  2063. {
  2064. if (!newStaffInList.Any(x => x.CertificatesNum == newStaff.CertificatesNum))
  2065. {
  2066. var certificatesNumVerify = certificatesNumStaffList.Where(x => x.CertificatesNum == newStaff.CertificatesNum).ToList();
  2067. if (certificatesNumVerify != null && certificatesNumVerify.Count() > 0)
  2068. {
  2069. errCount++;
  2070. errorMsgStr = "证件号码已存在(重复),请检查";
  2071. en.ErrorMessage = errorMsgStr;
  2072. errList.Add(en);
  2073. errorMsg.AppendLine(errorMsgStr);
  2074. continue;
  2075. }
  2076. }
  2077. else
  2078. {
  2079. errCount++;
  2080. errorMsgStr = "证件号码重复(Excel中),请检查";
  2081. en.ErrorMessage = errorMsgStr;
  2082. errList.Add(en);
  2083. errorMsg.AppendLine(errorMsgStr);
  2084. continue;
  2085. }
  2086. }
  2087. else
  2088. {
  2089. errCount++;
  2090. errorMsgStr = "证件号码重复(Excel中),请检查";
  2091. en.ErrorMessage = errorMsgStr;
  2092. errList.Add(en);
  2093. errorMsg.AppendLine(errorMsgStr);
  2094. continue;
  2095. }
  2096. }
  2097. //新增
  2098. if (!newUserInList.Any(x => x.LoginID == newUser.LoginID))
  2099. {
  2100. newUser.UserID = Guid.NewGuid();
  2101. if (teacherInitPassword == null)
  2102. {
  2103. newUser.Password = ("A" + newUser.LoginID.Trim()).MD5();
  2104. }
  2105. else
  2106. {
  2107. if (teacherInitPassword.Value != null)
  2108. {
  2109. newUser.Password = teacherInitPassword.Value;
  2110. }
  2111. else
  2112. {
  2113. newUser.Password = ("A" + newUser.LoginID.Trim()).MD5();
  2114. }
  2115. }
  2116. this.SetNewStatus(newUser, (int)SYS_STATUS.USABLE);
  2117. newUserInList.Add(newUser);
  2118. newUser.Sys_Role = new HashSet<Sys_Role>();
  2119. if (teacherRoleList != null && teacherRoleList.Count() > 0)
  2120. {
  2121. teacherRoleList.ForEach(x => newUser.Sys_Role.Add(x));
  2122. }
  2123. else
  2124. {
  2125. //对应角色为空时,默认为不分配用户角色
  2126. }
  2127. newStaff.UserID = newUser.UserID;
  2128. var staffManageCampus = new CF_StaffManageCampus();
  2129. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  2130. staffManageCampus.UserID = newUser.UserID;
  2131. staffManageCampus.CampusID = en.CampusID;
  2132. this.SetNewStatus(staffManageCampus);
  2133. newStaffManageCampusInList.Add(staffManageCampus);
  2134. var staffManageCollege = new CF_StaffManageCollege();
  2135. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  2136. staffManageCollege.UserID = newUser.UserID;
  2137. staffManageCollege.CollegeID = newStaff.CollegeID;
  2138. this.SetNewStatus(staffManageCollege);
  2139. newStaffManageCollegeInList.Add(staffManageCollege);
  2140. if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty)
  2141. {
  2142. var staffManageDepartment = new CF_StaffManageDepartment();
  2143. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  2144. staffManageDepartment.UserID = newUser.UserID;
  2145. staffManageDepartment.DepartmentID = newStaff.DepartmentID;
  2146. this.SetNewStatus(staffManageDepartment);
  2147. newStaffManageDepartmentInList.Add(staffManageDepartment);
  2148. }
  2149. this.SetNewStatus(newStaff);
  2150. newStaffInList.Add(newStaff);
  2151. newStaffProfile.UserID = newStaff.UserID;
  2152. this.SetNewStatus(newStaffProfile);
  2153. newStaffProfileInList.Add(newStaffProfile);
  2154. inCount++;
  2155. }
  2156. else
  2157. {
  2158. //Excel表重复性验证
  2159. //(注:当数据表中没有此记录,但是Excel中有重复数据,可在此处进行抛出到失败数据文件中)
  2160. errCount++;
  2161. errorMsgStr = "教职工号重复(Excel中),请检查";
  2162. en.ErrorMessage = errorMsgStr;
  2163. errList.Add(en);
  2164. errorMsg.AppendLine(errorMsgStr);
  2165. continue;
  2166. }
  2167. }
  2168. else
  2169. {
  2170. //更新(判断Excel有重复时,以最后一条记录更新为准)
  2171. var staffVerify = newStaffList.Where(x => x.UserID == userVerify.UserID).SingleOrDefault();
  2172. if (staffVerify == null)
  2173. {
  2174. errCount++;
  2175. errorMsgStr = "教职工号冲突(与其它帐号冲突),请检查";
  2176. en.ErrorMessage = errorMsgStr;
  2177. errList.Add(en);
  2178. errorMsg.AppendLine(errorMsgStr);
  2179. continue;
  2180. }
  2181. else
  2182. {
  2183. //判断证件号码
  2184. if (!string.IsNullOrEmpty(newStaff.CertificatesNum))
  2185. {
  2186. if (!newStaffInList.Any(x => x.CertificatesNum == newStaff.CertificatesNum))
  2187. {
  2188. if (!newStaffUpList.Any(x => x.CertificatesNum == newStaff.CertificatesNum))
  2189. {
  2190. var certificatesNumVerify = certificatesNumStaffList.Where(x => x.UserID != userVerify.UserID
  2191. && x.CertificatesNum == newStaff.CertificatesNum).ToList();
  2192. if (certificatesNumVerify != null && certificatesNumVerify.Count() > 0)
  2193. {
  2194. errCount++;
  2195. errorMsgStr = "证件号码已存在(与其它教职工号冲突),请检查";
  2196. en.ErrorMessage = errorMsgStr;
  2197. errList.Add(en);
  2198. errorMsg.AppendLine(errorMsgStr);
  2199. continue;
  2200. }
  2201. }
  2202. else
  2203. {
  2204. errCount++;
  2205. errorMsgStr = "证件号码重复(Excel中),请检查";
  2206. en.ErrorMessage = errorMsgStr;
  2207. errList.Add(en);
  2208. errorMsg.AppendLine(errorMsgStr);
  2209. continue;
  2210. }
  2211. }
  2212. else
  2213. {
  2214. errCount++;
  2215. errorMsgStr = "证件号码重复(Excel中),请检查";
  2216. en.ErrorMessage = errorMsgStr;
  2217. errList.Add(en);
  2218. errorMsg.AppendLine(errorMsgStr);
  2219. continue;
  2220. }
  2221. }
  2222. staffVerify.Sys_User.LoginID = newUser.LoginID.Trim();
  2223. staffVerify.Sys_User.Name = newUser.Name.Trim();
  2224. this.SetModifyStatus(staffVerify.Sys_User);
  2225. newUserUpList.Add(staffVerify.Sys_User);
  2226. staffVerify.StaffCode = newUser.LoginID.Trim();
  2227. if (staffVerify.CollegeID != newStaff.CollegeID)
  2228. {
  2229. CampusUserIDDelList.Add(staffVerify.UserID);
  2230. var staffManageCampus = new CF_StaffManageCampus();
  2231. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  2232. staffManageCampus.UserID = staffVerify.UserID;
  2233. staffManageCampus.CampusID = en.CampusID;
  2234. this.SetNewStatus(staffManageCampus);
  2235. newStaffManageCampusInList.Add(staffManageCampus);
  2236. CollegeUserIDDelList.Add(staffVerify.UserID);
  2237. var staffManageCollege = new CF_StaffManageCollege();
  2238. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  2239. staffManageCollege.UserID = staffVerify.UserID;
  2240. staffManageCollege.CollegeID = newStaff.CollegeID;
  2241. this.SetNewStatus(staffManageCollege);
  2242. newStaffManageCollegeInList.Add(staffManageCollege);
  2243. DepartmentUserIDDelList.Add(staffVerify.UserID);
  2244. if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty)
  2245. {
  2246. var staffManageDepartment = new CF_StaffManageDepartment();
  2247. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  2248. staffManageDepartment.UserID = staffVerify.UserID;
  2249. staffManageDepartment.DepartmentID = newStaff.DepartmentID;
  2250. this.SetNewStatus(staffManageDepartment);
  2251. newStaffManageDepartmentInList.Add(staffManageDepartment);
  2252. }
  2253. }
  2254. else
  2255. {
  2256. if (staffVerify.CF_StaffManageCampus.Count() <= 0 || staffVerify.CF_StaffManageCampus == null)
  2257. {
  2258. var staffManageCampus = new CF_StaffManageCampus();
  2259. staffManageCampus.StaffManageCampusID = Guid.NewGuid();
  2260. staffManageCampus.UserID = staffVerify.UserID;
  2261. staffManageCampus.CampusID = en.CampusID;
  2262. this.SetNewStatus(staffManageCampus);
  2263. newStaffManageCampusInList.Add(staffManageCampus);
  2264. }
  2265. if (staffVerify.CF_StaffManageCollege.Count() <= 0 || staffVerify.CF_StaffManageCollege == null)
  2266. {
  2267. var staffManageCollege = new CF_StaffManageCollege();
  2268. staffManageCollege.StaffManageCollegeID = Guid.NewGuid();
  2269. staffManageCollege.UserID = staffVerify.UserID;
  2270. staffManageCollege.CollegeID = newStaff.CollegeID;
  2271. this.SetNewStatus(staffManageCollege);
  2272. newStaffManageCollegeInList.Add(staffManageCollege);
  2273. }
  2274. if (staffVerify.DepartmentID != newStaff.DepartmentID)
  2275. {
  2276. DepartmentUserIDDelList.Add(staffVerify.UserID);
  2277. if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty)
  2278. {
  2279. var staffManageDepartment = new CF_StaffManageDepartment();
  2280. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  2281. staffManageDepartment.UserID = staffVerify.UserID;
  2282. staffManageDepartment.DepartmentID = newStaff.DepartmentID;
  2283. this.SetNewStatus(staffManageDepartment);
  2284. newStaffManageDepartmentInList.Add(staffManageDepartment);
  2285. }
  2286. }
  2287. else
  2288. {
  2289. if (staffVerify.CF_StaffManageDepartment.Count() <= 0 || staffVerify.CF_StaffManageDepartment == null)
  2290. {
  2291. if (newStaff.DepartmentID.HasValue && newStaff.DepartmentID != Guid.Empty)
  2292. {
  2293. var staffManageDepartment = new CF_StaffManageDepartment();
  2294. staffManageDepartment.StaffManageDepartmentID = Guid.NewGuid();
  2295. staffManageDepartment.UserID = staffVerify.UserID;
  2296. staffManageDepartment.DepartmentID = newStaff.DepartmentID;
  2297. this.SetNewStatus(staffManageDepartment);
  2298. newStaffManageDepartmentInList.Add(staffManageDepartment);
  2299. }
  2300. }
  2301. }
  2302. }
  2303. staffVerify.CollegeID = newStaff.CollegeID;
  2304. staffVerify.DepartmentID = newStaff.DepartmentID;
  2305. staffVerify.SexID = newStaff.SexID;
  2306. staffVerify.BirthDate = newStaff.BirthDate;
  2307. staffVerify.NationID = newStaff.NationID;
  2308. staffVerify.PoliticsID = newStaff.PoliticsID;
  2309. staffVerify.CertificatesType = newStaff.CertificatesType;
  2310. staffVerify.CertificatesNum = newStaff.CertificatesNum;
  2311. staffVerify.TeacherTypeID = newStaff.TeacherTypeID;
  2312. staffVerify.IncumbencyState = newStaff.IncumbencyState;
  2313. staffVerify.SituationID = newStaff.SituationID;
  2314. staffVerify.TitleID = newStaff.TitleID;
  2315. staffVerify.LiteracyLevelID = newStaff.LiteracyLevelID;
  2316. staffVerify.LearnPositionID = newStaff.LearnPositionID;
  2317. staffVerify.IsDualTeacher = newStaff.IsDualTeacher;
  2318. staffVerify.PaymentLevelID = newStaff.PaymentLevelID;
  2319. staffVerify.WorkDate = newStaff.WorkDate;
  2320. staffVerify.ComeSchoolDate = newStaff.ComeSchoolDate;
  2321. staffVerify.Profile = newStaff.Profile;
  2322. staffVerify.Remark = newStaff.Remark;
  2323. this.SetModifyStatus(staffVerify);
  2324. newStaffUpList.Add(staffVerify);
  2325. if (staffVerify.CF_StaffProfile == null)
  2326. {
  2327. var staffProfile = new CF_StaffProfile();
  2328. staffProfile.UserID = staffVerify.UserID;
  2329. staffProfile.UsedName = newStaffProfile.UsedName;
  2330. staffProfile.Nationality = newStaffProfile.Nationality;
  2331. staffProfile.Place = newStaffProfile.Place;
  2332. staffProfile.Email = newStaffProfile.Email;
  2333. staffProfile.ZIPCode = newStaffProfile.ZIPCode;
  2334. staffProfile.WeChatNum = newStaffProfile.WeChatNum;
  2335. staffProfile.QQ = newStaffProfile.QQ;
  2336. staffProfile.Telephone = newStaffProfile.Telephone;
  2337. staffProfile.OfficeTelephone = newStaffProfile.OfficeTelephone;
  2338. staffProfile.HousePhone = newStaffProfile.HousePhone;
  2339. staffProfile.Mobile = newStaffProfile.Mobile;
  2340. staffProfile.Speciality = newStaffProfile.Speciality;
  2341. staffProfile.HealthStateID = newStaffProfile.HealthStateID;
  2342. staffProfile.ReligionID = newStaffProfile.ReligionID;
  2343. staffProfile.Account = newStaffProfile.Account;
  2344. staffProfile.Residence = newStaffProfile.Residence;
  2345. staffProfile.HomeAddress = newStaffProfile.HomeAddress;
  2346. staffProfile.Address = newStaffProfile.Address;
  2347. staffProfile.NowAddress = newStaffProfile.NowAddress;
  2348. this.SetNewStatus(staffProfile);
  2349. newStaffProfileInList.Add(staffProfile);
  2350. }
  2351. else
  2352. {
  2353. staffVerify.CF_StaffProfile.UsedName = newStaffProfile.UsedName;
  2354. staffVerify.CF_StaffProfile.Nationality = newStaffProfile.Nationality;
  2355. staffVerify.CF_StaffProfile.Place = newStaffProfile.Place;
  2356. staffVerify.CF_StaffProfile.Email = newStaffProfile.Email;
  2357. staffVerify.CF_StaffProfile.ZIPCode = newStaffProfile.ZIPCode;
  2358. staffVerify.CF_StaffProfile.WeChatNum = newStaffProfile.WeChatNum;
  2359. staffVerify.CF_StaffProfile.QQ = newStaffProfile.QQ;
  2360. staffVerify.CF_StaffProfile.Telephone = newStaffProfile.Telephone;
  2361. staffVerify.CF_StaffProfile.OfficeTelephone = newStaffProfile.OfficeTelephone;
  2362. staffVerify.CF_StaffProfile.HousePhone = newStaffProfile.HousePhone;
  2363. staffVerify.CF_StaffProfile.Mobile = newStaffProfile.Mobile;
  2364. staffVerify.CF_StaffProfile.Speciality = newStaffProfile.Speciality;
  2365. staffVerify.CF_StaffProfile.HealthStateID = newStaffProfile.HealthStateID;
  2366. staffVerify.CF_StaffProfile.ReligionID = newStaffProfile.ReligionID;
  2367. staffVerify.CF_StaffProfile.Account = newStaffProfile.Account;
  2368. staffVerify.CF_StaffProfile.Residence = newStaffProfile.Residence;
  2369. staffVerify.CF_StaffProfile.HomeAddress = newStaffProfile.HomeAddress;
  2370. staffVerify.CF_StaffProfile.Address = newStaffProfile.Address;
  2371. staffVerify.CF_StaffProfile.NowAddress = newStaffProfile.NowAddress;
  2372. this.SetModifyStatus(staffVerify.CF_StaffProfile);
  2373. newStaffProfileUpList.Add(staffVerify.CF_StaffProfile);
  2374. }
  2375. upCount++;
  2376. }
  2377. }
  2378. }
  2379. using (TransactionScope ts = new TransactionScope())
  2380. {
  2381. UnitOfWork.Delete<CF_StaffManageDepartment>(x => DepartmentUserIDDelList.Contains(x.UserID));
  2382. UnitOfWork.Delete<CF_StaffManageCollege>(x => CollegeUserIDDelList.Contains(x.UserID));
  2383. UnitOfWork.Delete<CF_StaffManageCampus>(x => CampusUserIDDelList.Contains(x.UserID));
  2384. UnitOfWork.BulkInsert<Sys_User>(newUserInList);
  2385. UnitOfWork.BulkInsert(newUserInList, (x => x.Sys_Role));
  2386. UnitOfWork.BulkInsert<CF_Staff>(newStaffInList);
  2387. UnitOfWork.BulkInsert<CF_StaffProfile>(newStaffProfileInList);
  2388. UnitOfWork.BulkInsert<CF_StaffManageCampus>(newStaffManageCampusInList);
  2389. UnitOfWork.BulkInsert<CF_StaffManageCollege>(newStaffManageCollegeInList);
  2390. UnitOfWork.BulkInsert<CF_StaffManageDepartment>(newStaffManageDepartmentInList);
  2391. if (newUserUpList != null && newUserUpList.Count() > 0)
  2392. {
  2393. UnitOfWork.BatchUpdate(newUserUpList);
  2394. }
  2395. if (newStaffUpList != null && newStaffUpList.Count() > 0)
  2396. {
  2397. UnitOfWork.BatchUpdate(newStaffUpList);
  2398. }
  2399. if (newStaffProfileUpList != null && newStaffProfileUpList.Count() > 0)
  2400. {
  2401. UnitOfWork.BatchUpdate(newStaffProfileUpList);
  2402. }
  2403. ts.Complete();
  2404. }
  2405. errdataList = errList.Distinct().ToList(); //错误列表List
  2406. }
  2407. catch (Exception)
  2408. {
  2409. throw;
  2410. }
  2411. }
  2412. }
  2413. }