UserServiceImpl.java 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547
  1. package jnpf.permission.service.impl;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
  5. import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
  6. import cn.hutool.core.bean.BeanUtil;
  7. import cn.hutool.core.collection.CollectionUtil;
  8. import cn.hutool.core.util.ObjectUtil;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.dynamic.datasource.annotation.DSTransactional;
  11. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  12. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  13. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  14. import com.baomidou.mybatisplus.core.metadata.IPage;
  15. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  16. import com.github.pagehelper.PageHelper;
  17. import com.github.pagehelper.PageInfo;
  18. import com.github.pagehelper.page.PageMethod;
  19. import com.google.common.collect.BiMap;
  20. import com.google.common.collect.HashBiMap;
  21. import com.google.common.collect.Lists;
  22. import jnpf.base.Pagination;
  23. import jnpf.base.UserInfo;
  24. import jnpf.base.entity.DictionaryDataEntity;
  25. import jnpf.base.entity.SuperBaseEntity;
  26. import jnpf.base.service.DictionaryDataService;
  27. import jnpf.base.service.SuperServiceImpl;
  28. import jnpf.base.service.SysconfigService;
  29. import jnpf.base.vo.DownloadVO;
  30. import jnpf.config.ConfigValueUtil;
  31. import jnpf.constant.*;
  32. import jnpf.database.source.DbBase;
  33. import jnpf.database.util.DataSourceUtil;
  34. import jnpf.database.util.TenantDataSourceUtil;
  35. import jnpf.emnus.SysParamEnum;
  36. import jnpf.entity.FileParameter;
  37. import jnpf.exception.DataException;
  38. import jnpf.message.util.OnlineUserModel;
  39. import jnpf.message.util.OnlineUserProvider;
  40. import jnpf.model.BaseSystemInfo;
  41. import jnpf.model.SystemParamModel;
  42. import jnpf.model.tenant.TenantVO;
  43. import jnpf.permission.entity.*;
  44. import jnpf.permission.mapper.UserMapper;
  45. import jnpf.permission.model.organize.OrganizeSelectorVO;
  46. import jnpf.permission.model.rolerelaiton.RoleRelationPage;
  47. import jnpf.permission.model.user.UserIdListVo;
  48. import jnpf.permission.model.user.UserRelationIds;
  49. import jnpf.permission.model.user.mod.UserConditionModel;
  50. import jnpf.permission.model.user.mod.UserImportModel;
  51. import jnpf.permission.model.user.page.PageUser;
  52. import jnpf.permission.model.user.page.PaginationUser;
  53. import jnpf.permission.model.user.page.UserPagination;
  54. import jnpf.permission.model.user.vo.*;
  55. import jnpf.permission.service.*;
  56. import jnpf.util.*;
  57. import jnpf.util.context.RequestContext;
  58. import lombok.Cleanup;
  59. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  60. import org.apache.poi.ss.usermodel.Workbook;
  61. import org.dromara.x.file.storage.core.FileInfo;
  62. import org.springframework.beans.factory.annotation.Autowired;
  63. import org.springframework.stereotype.Service;
  64. import org.springframework.util.ObjectUtils;
  65. import org.springframework.web.multipart.MultipartFile;
  66. import java.text.SimpleDateFormat;
  67. import java.util.*;
  68. import java.util.stream.Collectors;
  69. import static jnpf.util.Constants.ADMIN_KEY;
  70. /**
  71. * 用户信息
  72. *
  73. * @author JNPF开发平台组
  74. * @version V3.1.0
  75. * @copyright 引迈信息技术有限公司
  76. * @date 2019年9月26日 上午9:18
  77. */
  78. @Service
  79. public class UserServiceImpl extends SuperServiceImpl<UserMapper, UserEntity> implements UserService {
  80. @Autowired
  81. private UserRelationService userRelationService;
  82. @Autowired
  83. private RedisUtil redisUtil;
  84. @Autowired
  85. private OrganizeService organizeService;
  86. @Autowired
  87. private PositionService positionService;
  88. @Autowired
  89. private RoleService roleService;
  90. @Autowired
  91. private CacheKeyUtil cacheKeyUtil;
  92. @Autowired
  93. private DataSourceUtil dataSourceUtil;
  94. @Autowired
  95. private ConfigValueUtil configValueUtil;
  96. @Autowired
  97. private DictionaryDataService dictionaryDataService;
  98. @Autowired
  99. private RoleRelationService roleRelationService;
  100. @Autowired
  101. private UserMapper userMapper;
  102. @Autowired
  103. private SysconfigService sysconfigApi;
  104. @Autowired
  105. private OrganizeAdministratorService organizeAdministratorService;
  106. @Autowired
  107. private UserOldPasswordService userOldPasswordService;
  108. @Autowired
  109. private GroupService groupService;
  110. @Autowired
  111. private PermissionGroupService permissionGroupService;
  112. @Autowired
  113. private UserService userService;
  114. @Autowired
  115. private SocialsUserService socialsUserService;
  116. @Override
  117. public List<UserEntity> getList(UserPagination pagination) {
  118. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  119. queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY);
  120. boolean filterLastTime = false;
  121. //关键字(账户、姓名、手机)
  122. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  123. filterLastTime = true;
  124. queryWrapper.lambda().and(
  125. t -> t.like(UserEntity::getAccount, pagination.getKeyword())
  126. .or().like(UserEntity::getRealName, pagination.getKeyword())
  127. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  128. );
  129. }
  130. if (pagination.getEnabledMark() != null) {
  131. queryWrapper.lambda().eq(UserEntity::getEnabledMark, pagination.getEnabledMark());
  132. }
  133. if (StringUtil.isNotEmpty(pagination.getGender())) {
  134. queryWrapper.lambda().eq(UserEntity::getGender, pagination.getGender());
  135. }
  136. //有分组id过滤
  137. if (StringUtil.isNotEmpty(pagination.getGroupId())) {
  138. List<UserRelationEntity> listUser = userRelationService.getListByObjectId(pagination.getGroupId(), PermissionConst.GROUP);
  139. List<String> users = listUser.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  140. if (CollectionUtil.isEmpty(users)) {
  141. return pagination.setData(Collections.EMPTY_LIST, 0);
  142. }
  143. List<List<String>> lists = Lists.partition(users, 1000);
  144. queryWrapper.lambda().and(t -> {
  145. for (List<String> userItem : lists) {
  146. t.in(UserEntity::getId, userItem).or();
  147. }
  148. });
  149. }
  150. //有岗位id
  151. if (StringUtil.isNotEmpty(pagination.getPositionId())) {
  152. List<UserRelationEntity> listUser = userRelationService.getListByObjectId(pagination.getPositionId(), PermissionConst.POSITION);
  153. List<String> users = listUser.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  154. if (CollectionUtil.isEmpty(users)) {
  155. return pagination.setData(Collections.EMPTY_LIST, 0);
  156. }
  157. List<List<String>> lists = Lists.partition(users, 1000);
  158. queryWrapper.lambda().and(t -> {
  159. for (List<String> userItem : lists) {
  160. t.in(UserEntity::getId, userItem).or();
  161. }
  162. });
  163. } else if (StringUtil.isNotEmpty(pagination.getOrganizeId())) {
  164. //有组织id
  165. List<String> orgIds = new ArrayList<>();
  166. orgIds.add(pagination.getOrganizeId());
  167. if (Objects.equals(pagination.getShowSubOrganize(), 1)) {
  168. List<OrganizeEntity> allChild = organizeService.getAllChild(pagination.getOrganizeId());
  169. orgIds.addAll(allChild.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  170. }
  171. List<PositionEntity> listPost = positionService.getListByOrgIds(orgIds);
  172. List<String> listPostId = listPost.stream().map(PositionEntity::getId).collect(Collectors.toList());
  173. List<UserRelationEntity> listUser = userRelationService.getListByObjectIdAll(listPostId);
  174. List<String> users = listUser.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  175. if (CollectionUtil.isEmpty(users)) {
  176. return pagination.setData(Collections.EMPTY_LIST, 0);
  177. }
  178. List<List<String>> lists = Lists.partition(users, 1000);
  179. queryWrapper.lambda().and(t -> {
  180. for (List<String> userItem : lists) {
  181. t.in(UserEntity::getId, userItem).or();
  182. }
  183. });
  184. }
  185. //有角色id
  186. if (StringUtil.isNotEmpty(pagination.getRoleId())) {
  187. List<RoleRelationEntity> listUser = roleRelationService.getListByRoleId(pagination.getRoleId(), PermissionConst.USER);
  188. List<String> users = listUser.stream().map(RoleRelationEntity::getObjectId).collect(Collectors.toList());
  189. if (CollectionUtil.isEmpty(users)) {
  190. return pagination.setData(Collections.EMPTY_LIST, 0);
  191. }
  192. List<List<String>> lists = Lists.partition(users, 1000);
  193. queryWrapper.lambda().and(t -> {
  194. for (List<String> userItem : lists) {
  195. t.in(UserEntity::getId, userItem).or();
  196. }
  197. });
  198. }
  199. long count = this.count(queryWrapper);
  200. queryWrapper.lambda().select(UserEntity::getId);
  201. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  202. if (filterLastTime) {
  203. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  204. }
  205. if (Objects.equals(pagination.getDataType(), 1)) {
  206. return this.list(queryWrapper);
  207. }
  208. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize(), count, false);
  209. page.setOptimizeCountSql(false);
  210. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  211. if (!iPage.getRecords().isEmpty()) {
  212. List<String> ids = iPage.getRecords().stream().map(m -> m.getId()).collect(Collectors.toList());
  213. queryWrapper = new QueryWrapper<>();
  214. queryWrapper.lambda().in(UserEntity::getId, ids);
  215. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  216. if (filterLastTime) {
  217. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  218. }
  219. iPage.setRecords(this.list(queryWrapper));
  220. }
  221. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  222. }
  223. @Override
  224. public List<UserEntity> getList(boolean filterEnabledMark) {
  225. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  226. if (filterEnabledMark) {
  227. queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1);
  228. }
  229. queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY);
  230. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  231. return this.list(queryWrapper);
  232. }
  233. @Override
  234. public List<UserEntity> getUserNameList(List<String> idList) {
  235. if (idList.size() > 0) {
  236. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  237. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getEnabledMark).in(UserEntity::getId, idList);
  238. return this.list(queryWrapper);
  239. }
  240. return new ArrayList<>();
  241. }
  242. @Override
  243. public List<UserEntity> getUserNameList(Set<String> idList) {
  244. if (idList.size() > 0) {
  245. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  246. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount).in(UserEntity::getId, idList);
  247. return this.list(queryWrapper);
  248. }
  249. return new ArrayList<>();
  250. }
  251. @Override
  252. public Map<String, Object> getUserMap() {
  253. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  254. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount);
  255. Map<String, Object> userMap = new HashMap<>();
  256. this.list(queryWrapper).stream().forEach(user -> userMap.put(user.getId(), user.getRealName() + "/" + user.getAccount()));
  257. return userMap;
  258. }
  259. @Override
  260. public Map<String, Object> getUserNameAndIdMap() {
  261. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  262. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount);
  263. Map<String, Object> userMap = new HashMap<>();
  264. this.list(queryWrapper).stream().forEach(user -> userMap.put(user.getRealName() + "/" + user.getAccount(), user.getId()));
  265. return userMap;
  266. }
  267. @Override
  268. public Map<String, Object> getUserNameAndIdMap(boolean enabledMark) {
  269. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  270. if (enabledMark) {
  271. queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1);
  272. }
  273. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount);
  274. Map<String, Object> userMap = new HashMap<>();
  275. this.list(queryWrapper).stream().forEach(user -> userMap.put(user.getRealName() + "/" + user.getAccount(), user.getId()));
  276. return userMap;
  277. }
  278. @Override
  279. public UserEntity getByRealName(String realName) {
  280. UserEntity userEntity = new UserEntity();
  281. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  282. queryWrapper.lambda().eq(UserEntity::getRealName, realName);
  283. queryWrapper.lambda().select(UserEntity::getId);
  284. List<UserEntity> list = this.list(queryWrapper);
  285. if (list.size() > 0) {
  286. userEntity = list.get(0);
  287. }
  288. return userEntity;
  289. }
  290. @Override
  291. public UserEntity getByRealName(String realName, String account) {
  292. UserEntity userEntity = new UserEntity();
  293. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  294. queryWrapper.lambda().eq(UserEntity::getRealName, realName);
  295. queryWrapper.lambda().eq(UserEntity::getAccount, account);
  296. queryWrapper.lambda().select(UserEntity::getId);
  297. List<UserEntity> list = this.list(queryWrapper);
  298. if (list.size() > 0) {
  299. userEntity = list.get(0);
  300. }
  301. return userEntity;
  302. }
  303. @Override
  304. public List<UserEntity> getAdminList() {
  305. QueryWrapper<UserEntity> query = new QueryWrapper<>();
  306. query.lambda().eq(UserEntity::getIsAdministrator, 1);
  307. query.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  308. return list(query);
  309. }
  310. @Override
  311. public List<UserEntity> getList(PaginationUser pagination, String organizeId, Boolean flag, Boolean filter, Integer enabledMark, String gender) {
  312. // 定义变量判断是否需要使用修改时间倒序
  313. boolean filterLastTime = false;
  314. String userId = UserProvider.getUser().getUserId();
  315. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  316. if (flag) {
  317. queryWrapper.lambda().ne(UserEntity::getId, userId);
  318. }
  319. if (filter) {
  320. queryWrapper.lambda().ne(UserEntity::getAccount, ADMIN_KEY);
  321. }
  322. //组织机构
  323. if (!StringUtil.isEmpty(organizeId)) {
  324. List<String> orgIdList = organizeService.getUnderOrganizationss(organizeId);
  325. orgIdList.add(organizeId);
  326. PageHelper.startPage((int) pagination.getCurrentPage(), (int) pagination.getPageSize(), false);
  327. //组织数量很多时解析SQL很慢, COUNT不解析SQL不去除ORDERBY
  328. PageMethod.getLocalPage().keepOrderBy(true);
  329. // 用户id
  330. List<String> query = new ArrayList<>(16);
  331. String dbSchema = null;
  332. // 判断是否为多租户
  333. if (configValueUtil.isMultiTenancy() && DbBase.DM.equalsIgnoreCase(dataSourceUtil.getDbType())) {
  334. dbSchema = dataSourceUtil.getDbSchema();
  335. }
  336. String keyword = null;
  337. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  338. keyword = "%" + pagination.getKeyword() + "%" ;
  339. }
  340. query = userMapper.query(orgIdList, keyword, dbSchema, enabledMark, gender);
  341. Long count = this.baseMapper.count(orgIdList, keyword, dbSchema, enabledMark, gender);
  342. PageInfo pageInfo = new PageInfo(query);
  343. // 赋值分页参数
  344. pagination.setTotal(count);
  345. pagination.setCurrentPage(pageInfo.getPageNum());
  346. pagination.setPageSize(pageInfo.getPageSize());
  347. if (pageInfo.getList().size() > 0) {
  348. // 存放返回结果
  349. QueryWrapper<UserEntity> queryWrapper1 = new QueryWrapper<>();
  350. List<List<String>> lists = Lists.partition(query, 1000);
  351. queryWrapper1.lambda().and(t -> {
  352. for (List<String> id : lists) {
  353. t.or().in(UserEntity::getId, id);
  354. }
  355. });
  356. queryWrapper1.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  357. List<UserEntity> entityList = getBaseMapper().selectList(queryWrapper1);
  358. return entityList;
  359. } else {
  360. return new ArrayList<>();
  361. }
  362. }
  363. if (!UserProvider.getUser().getIsAdministrator()) {
  364. // 通过权限转树
  365. List<OrganizeAdministratorEntity> listss = organizeAdministratorService.getOrganizeAdministratorEntity(UserProvider.getUser().getUserId());
  366. Set<String> orgIds = new HashSet<>(16);
  367. // 判断自己是哪些组织的管理员
  368. listss.stream().forEach(t -> {
  369. if (t != null) {
  370. if (t.getThisLayerSelect() != null && t.getThisLayerSelect() == 1) {
  371. orgIds.add(t.getOrganizeId());
  372. }
  373. if (t.getSubLayerSelect() != null && t.getSubLayerSelect() == 1) {
  374. List<String> underOrganizations = organizeService.getUnderOrganizations(t.getOrganizeId(), false);
  375. orgIds.addAll(underOrganizations);
  376. }
  377. }
  378. });
  379. List<String> list1 = new ArrayList<>(orgIds);
  380. // 得到所有有权限的组织
  381. List<OrganizeEntity> organizeName = new ArrayList<>(organizeService.getOrganizeName(list1, null, false, null).values());
  382. // 用户关系表得到所有的人
  383. List<String> collect = organizeName.stream().map(OrganizeEntity::getId).collect(Collectors.toList());
  384. List<UserRelationEntity> listByObjectIdAll = userRelationService.getListByOrgId(collect);
  385. List<String> collect1 = listByObjectIdAll.stream().map(UserRelationEntity::getUserId).distinct().collect(Collectors.toList());
  386. return getUserNames(collect1, pagination, false, ObjectUtil.equal(enabledMark, 1));
  387. }
  388. //关键字(账户、姓名、手机)
  389. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  390. filterLastTime = true;
  391. queryWrapper.lambda().and(
  392. t -> t.like(UserEntity::getAccount, pagination.getKeyword())
  393. .or().like(UserEntity::getRealName, pagination.getKeyword())
  394. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  395. );
  396. }
  397. if (enabledMark != null) {
  398. queryWrapper.lambda().eq(UserEntity::getEnabledMark, enabledMark);
  399. }
  400. if (StringUtil.isNotEmpty(gender)) {
  401. queryWrapper.lambda().eq(UserEntity::getGender, gender);
  402. }
  403. //不分页
  404. if (Objects.equals(pagination.getDataType(), 1)) {
  405. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  406. if (filterLastTime) {
  407. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  408. }
  409. return this.list(queryWrapper);
  410. }
  411. //分页
  412. //排序
  413. long count = this.count(queryWrapper);
  414. queryWrapper.lambda().select(UserEntity::getId);
  415. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  416. if (filterLastTime) {
  417. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  418. }
  419. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize(), count, false);
  420. page.setOptimizeCountSql(false);
  421. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  422. if (!iPage.getRecords().isEmpty()) {
  423. List<String> ids = iPage.getRecords().stream().map(m -> m.getId()).collect(Collectors.toList());
  424. queryWrapper = new QueryWrapper<>();
  425. queryWrapper.lambda().in(UserEntity::getId, ids);
  426. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  427. if (filterLastTime) {
  428. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  429. }
  430. iPage.setRecords(this.list(queryWrapper));
  431. }
  432. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  433. }
  434. @Override
  435. public List<UserEntity> getList(PageUser pagination, Boolean filterCurrentUser) {
  436. // 定义变量判断是否需要使用修改时间倒序
  437. boolean filterLastTime = false;
  438. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  439. if (filterCurrentUser) {
  440. String userId = UserProvider.getUser().getUserId();
  441. queryWrapper.lambda().ne(UserEntity::getId, userId);
  442. }
  443. queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
  444. //关键字(账户、姓名、手机)
  445. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  446. filterLastTime = true;
  447. queryWrapper.lambda().and(
  448. t -> t.like(UserEntity::getAccount, pagination.getKeyword())
  449. .or().like(UserEntity::getRealName, pagination.getKeyword())
  450. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  451. );
  452. }
  453. if (CollectionUtil.isNotEmpty(pagination.getIdList())) {
  454. List<List<String>> partition = Lists.partition(pagination.getIdList(), 1000);
  455. queryWrapper.lambda().and(t -> {
  456. for (List<String> list : partition) {
  457. t.in(UserEntity::getId, list).or();
  458. }
  459. });
  460. }
  461. //排序
  462. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  463. if (filterLastTime) {
  464. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  465. }
  466. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  467. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  468. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  469. }
  470. @Override
  471. public List<UserEntity> getUserPage(Pagination pagination) {
  472. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  473. queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
  474. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  475. //通过关键字查询
  476. queryWrapper.lambda().and(
  477. t -> t.like(UserEntity::getAccount, pagination.getKeyword())
  478. .or().like(UserEntity::getRealName, pagination.getKeyword())
  479. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  480. );
  481. }
  482. queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
  483. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getAccount, UserEntity::getRealName, UserEntity::getGender, UserEntity::getEnabledMark);
  484. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  485. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  486. return iPage.getRecords();
  487. }
  488. @Override
  489. public List<UserEntity> getListByOrganizeId(String organizeId, String keyword) {
  490. List<String> userIds = userRelationService.getListByObjectId(organizeId, PermissionConst.ORGANIZE).stream()
  491. .map(UserRelationEntity::getUserId).collect(Collectors.toList());
  492. if (userIds.size() > 0) {
  493. QueryWrapper<UserEntity> query = new QueryWrapper<>();
  494. if (userIds.size() > 0) {
  495. query.lambda().in(UserEntity::getId, userIds);
  496. }
  497. // 通过关键字查询
  498. if (StringUtil.isNotEmpty(keyword)) {
  499. query.lambda().and(
  500. t -> t.like(UserEntity::getAccount, keyword)
  501. .or().like(UserEntity::getRealName, keyword)
  502. );
  503. }
  504. // 只查询正常的用户
  505. query.lambda().ne(UserEntity::getEnabledMark, 0);
  506. query.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  507. return this.list(query);
  508. }
  509. return new ArrayList<>(0);
  510. }
  511. @Override
  512. public List<UserEntity> getListByManagerId(String managerId, String keyword) {
  513. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  514. queryWrapper.lambda().eq(UserEntity::getManagerId, managerId);
  515. // 通过关键字查询
  516. if (StringUtil.isNotEmpty(keyword)) {
  517. queryWrapper.lambda().and(
  518. t -> t.like(UserEntity::getAccount, keyword)
  519. .or().like(UserEntity::getRealName, keyword)
  520. );
  521. }
  522. // 只查询正常的用户
  523. queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1);
  524. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  525. return this.list(queryWrapper);
  526. }
  527. @Override
  528. public UserEntity getInfo(String id) {
  529. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  530. queryWrapper.lambda().eq(UserEntity::getId, String.valueOf(id));
  531. return this.getOne(queryWrapper);
  532. }
  533. @Override
  534. public UserEntity getUserByAccount(String account) {
  535. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  536. queryWrapper.lambda().eq(UserEntity::getAccount, account);
  537. return this.getOne(queryWrapper);
  538. }
  539. @Override
  540. public UserEntity getUserByMobile(String mobile) {
  541. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  542. queryWrapper.lambda().eq(UserEntity::getMobilePhone, mobile);
  543. List<UserEntity> list = this.list(queryWrapper);
  544. return CollectionUtil.isNotEmpty(list) ? list.get(0) : null;
  545. }
  546. @Override
  547. public Boolean setAdminListByIds(List<String> adminIds) {
  548. // 将所有的管理员取消
  549. QueryWrapper<UserEntity> query = new QueryWrapper<>();
  550. query.lambda().eq(UserEntity::getIsAdministrator, 1);
  551. // admin不允许移除管理员
  552. query.lambda().ne(UserEntity::getAccount, ADMIN_KEY);
  553. List<UserEntity> list1 = this.list(query);
  554. for (UserEntity entity : list1) {
  555. entity.setIsAdministrator(0);
  556. this.updateById(entity);
  557. }
  558. // 重新赋值管理员
  559. List<UserEntity> list = new ArrayList<>();
  560. adminIds.stream().forEach(adminId -> {
  561. UserEntity userEntity = new UserEntity();
  562. userEntity.setId(adminId);
  563. userEntity.setIsAdministrator(1);
  564. // admin无需添加
  565. if (!ADMIN_KEY.equals(userEntity.getAccount())) {
  566. list.add(userEntity);
  567. }
  568. });
  569. List<String> adminList = list1.stream().map(UserEntity::getId).collect(Collectors.toList());
  570. adminList.removeAll(list.stream().map(UserEntity::getId).collect(Collectors.toList()));
  571. delCurUser(MsgCode.PS010.get(), adminList);
  572. updateStand(adminList, 1);
  573. return this.updateBatchById(list);
  574. }
  575. @Override
  576. public boolean isExistByAccount(String account) {
  577. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  578. queryWrapper.lambda().eq(UserEntity::getAccount, account);
  579. List<UserEntity> list = this.list(queryWrapper);
  580. if (CollectionUtil.isNotEmpty(list)) {
  581. return true;
  582. }
  583. return false;
  584. }
  585. @Override
  586. @DSTransactional
  587. public Boolean create(UserEntity entity) throws Exception {
  588. beforeCheck();
  589. if (StringUtil.isNotEmpty(entity.getGroupId()) && entity.getGroupId().contains(",")) {
  590. entity.setGroupId(null);
  591. }
  592. //添加用户 初始化
  593. String userId = RandomUtil.uuId();
  594. if (StringUtil.isNotEmpty(entity.getId())) {
  595. userId = entity.getId();
  596. }
  597. BaseSystemInfo sysInfo = sysconfigApi.getSysInfo();
  598. entity.setPassword(Md5Util.getStringMd5(sysInfo.getNewUserDefaultPassword()));
  599. entity.setId(userId);
  600. if (StringUtil.isEmpty(entity.getAccount())) {
  601. throw new DataException(MsgCode.PS007.get());
  602. }
  603. if (StringUtil.isEmpty(entity.getRealName())) {
  604. throw new DataException(MsgCode.PS008.get());
  605. }
  606. //获取头像
  607. String oldHeadIcon = entity.getHeadIcon();
  608. if (StringUtil.isEmpty(oldHeadIcon)) {
  609. entity.setHeadIcon("001.png");
  610. } else {
  611. //获取头像
  612. String[] headIcon = oldHeadIcon.split("/");
  613. if (headIcon.length > 0) {
  614. entity.setHeadIcon(headIcon[headIcon.length - 1]);
  615. }
  616. }
  617. entity.setSecretkey(RandomUtil.uuId());
  618. entity.setPassword(Md5Util.getStringMd5(entity.getPassword().toLowerCase() + entity.getSecretkey().toLowerCase()));
  619. entity.setIsAdministrator(0);
  620. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  621. String groupId = entity.getGroupId();
  622. if (StringUtil.isNotEmpty(groupId)) {
  623. UserRelationEntity groupRelation = new UserRelationEntity();
  624. groupRelation.setId(RandomUtil.uuId());
  625. groupRelation.setObjectType(PermissionConst.GROUP);
  626. groupRelation.setObjectId(groupId);
  627. groupRelation.setUserId(entity.getId());
  628. groupRelation.setCreatorTime(entity.getCreatorTime());
  629. groupRelation.setCreatorUserId(entity.getCreatorUserId());
  630. userRelationService.save(groupRelation);
  631. }
  632. //添加岗位关系
  633. if (StringUtil.isNotEmpty(entity.getPositionId())) {
  634. String[] split = entity.getPositionId().split(",");
  635. for (String s : split) {
  636. UserRelationEntity posRelation = new UserRelationEntity();
  637. posRelation.setId(RandomUtil.uuId());
  638. posRelation.setObjectType(PermissionConst.POSITION);
  639. posRelation.setObjectId(s);
  640. posRelation.setUserId(entity.getId());
  641. posRelation.setCreatorTime(entity.getCreatorTime());
  642. posRelation.setCreatorUserId(entity.getCreatorUserId());
  643. userRelationService.save(posRelation);
  644. }
  645. }
  646. //添加组织关系
  647. if (StringUtil.isNotEmpty(entity.getOrganizeId())) {
  648. String[] split = entity.getOrganizeId().split(",");
  649. for (String s : split) {
  650. UserRelationEntity posRelation = new UserRelationEntity();
  651. posRelation.setId(RandomUtil.uuId());
  652. posRelation.setObjectType(PermissionConst.ORGANIZE);
  653. posRelation.setObjectId(s);
  654. posRelation.setUserId(entity.getId());
  655. posRelation.setCreatorTime(entity.getCreatorTime());
  656. posRelation.setCreatorUserId(entity.getCreatorUserId());
  657. userRelationService.save(posRelation);
  658. }
  659. }
  660. //添加角色关系
  661. if (StringUtil.isNotEmpty(entity.getRoleId())) {
  662. String[] split = entity.getRoleId().split(",");
  663. for (String s : split) {
  664. RoleRelationEntity posRelation = new RoleRelationEntity();
  665. posRelation.setId(RandomUtil.uuId());
  666. posRelation.setObjectType(PermissionConst.USER);
  667. posRelation.setObjectId(entity.getId());
  668. posRelation.setRoleId(s);
  669. posRelation.setCreatorTime(entity.getCreatorTime());
  670. posRelation.setCreatorUserId(entity.getCreatorUserId());
  671. roleRelationService.save(posRelation);
  672. }
  673. } else {
  674. //创建没有角色的时候,默认使用者
  675. RoleEntity byEnCode = roleService.getByEnCode(PermissionConst.USER_CODE);
  676. RoleRelationEntity posRelation = new RoleRelationEntity();
  677. posRelation.setId(RandomUtil.uuId());
  678. posRelation.setObjectType(PermissionConst.USER);
  679. posRelation.setObjectId(entity.getId());
  680. posRelation.setRoleId(byEnCode.getId());
  681. posRelation.setCreatorTime(entity.getCreatorTime());
  682. posRelation.setCreatorUserId(entity.getCreatorUserId());
  683. roleRelationService.save(posRelation);
  684. }
  685. //写入时清空
  686. entity.setGroupId("");
  687. entity.setPositionId("");
  688. entity.setOrganizeId("");
  689. entity.setRoleId("");
  690. entity.setQuickQuery(PinYinUtil.getFirstSpell(entity.getRealName()));
  691. //清理获取所有用户的redis缓存
  692. redisUtil.remove(cacheKeyUtil.getAllUser());
  693. this.save(entity);
  694. return true;
  695. }
  696. /**
  697. * 验证是否还有额度
  698. */
  699. @Override
  700. public void beforeCheck() {
  701. String tenantId = UserProvider.getUser().getTenantId();
  702. // 开启多租住的
  703. if (StringUtil.isNotEmpty(tenantId)) {
  704. TenantVO cacheTenantInfo = TenantDataSourceUtil.getCacheTenantInfo(tenantId);
  705. long count = this.count();
  706. if (cacheTenantInfo.getAccountNum() != 0 && cacheTenantInfo.getAccountNum() < count) {
  707. throw new DataException(MsgCode.PS009.get());
  708. }
  709. }
  710. }
  711. @Override
  712. @DSTransactional
  713. public Boolean update(String userId, UserEntity entity) throws Exception {
  714. //更新用户
  715. entity.setId(userId);
  716. if (StringUtil.isEmpty(entity.getAccount())) {
  717. throw new DataException(MsgCode.PS007.get());
  718. }
  719. if (StringUtil.isEmpty(entity.getRealName())) {
  720. throw new DataException(MsgCode.PS008.get());
  721. }
  722. //获取头像
  723. String oldHeadIcon = entity.getHeadIcon();
  724. if (StringUtil.isEmpty(oldHeadIcon)) {
  725. entity.setHeadIcon("001.png");
  726. }
  727. entity.setLastModifyTime(DateUtil.getNowDate());
  728. entity.setLastModifyUserId(UserProvider.getUser().getUserId());
  729. //获取头像
  730. String[] headIcon = entity.getHeadIcon().split("/");
  731. if (headIcon.length > 0) {
  732. entity.setHeadIcon(headIcon[headIcon.length - 1]);
  733. }
  734. entity.setQuickQuery(PinYinUtil.getFirstSpell(entity.getRealName()));
  735. //清理获取所有用户的redis缓存
  736. redisUtil.remove(cacheKeyUtil.getAllUser());
  737. if (StringUtil.isNotEmpty(entity.getGroupId()) && entity.getGroupId().contains(",")) {
  738. entity.setGroupId(null);
  739. }
  740. this.updateById(entity);
  741. return true;
  742. }
  743. @Override
  744. @DSTransactional
  745. public void delete(UserEntity entity) {
  746. this.removeById(entity.getId());
  747. //删除用户关联
  748. QueryWrapper<UserRelationEntity> queryWrapper = new QueryWrapper<>();
  749. queryWrapper.lambda().eq(UserRelationEntity::getUserId, entity.getId());
  750. userRelationService.remove(queryWrapper);
  751. //删除用户关联角色
  752. QueryWrapper<RoleRelationEntity> roleRelationQuery = new QueryWrapper<>();
  753. roleRelationQuery.lambda().eq(RoleRelationEntity::getObjectId, entity.getId());
  754. roleRelationService.remove(roleRelationQuery);
  755. //删除用户绑定关系
  756. QueryWrapper<SocialsUserEntity> socialsUserEntityQueryWrapper = new QueryWrapper<>();
  757. socialsUserEntityQueryWrapper.lambda().eq(SocialsUserEntity::getUserId, entity.getId());
  758. socialsUserService.remove(socialsUserEntityQueryWrapper);
  759. }
  760. @Override
  761. @DSTransactional
  762. public void batchDelete(List<String> userIdList) {
  763. if (userIdList == null || userIdList.isEmpty()) {
  764. return;
  765. }
  766. this.removeBatchByIds(userIdList);
  767. //删除用户关联
  768. QueryWrapper<UserRelationEntity> queryWrapper = new QueryWrapper<>();
  769. queryWrapper.lambda().in(UserRelationEntity::getUserId, userIdList);
  770. userRelationService.remove(queryWrapper);
  771. //删除用户关联角色
  772. QueryWrapper<RoleRelationEntity> roleRelationQuery = new QueryWrapper<>();
  773. roleRelationQuery.lambda().in(RoleRelationEntity::getObjectId, userIdList);
  774. roleRelationService.remove(roleRelationQuery);
  775. }
  776. @Override
  777. public void updatePassword(UserEntity entity) {
  778. entity.setSecretkey(RandomUtil.uuId());
  779. entity.setPassword(Md5Util.getStringMd5(entity.getPassword().toLowerCase() + entity.getSecretkey().toLowerCase()));
  780. entity.setChangePasswordDate(DateUtil.getNowDate());
  781. this.updateById(entity);
  782. //加入到旧密码记录表
  783. UserOldPasswordEntity userOldPasswordEntity = new UserOldPasswordEntity();
  784. userOldPasswordEntity.setOldPassword(entity.getPassword());
  785. userOldPasswordEntity.setSecretkey(entity.getSecretkey());
  786. userOldPasswordEntity.setUserId(entity.getId());
  787. userOldPasswordEntity.setAccount(entity.getAccount());
  788. userOldPasswordService.create(userOldPasswordEntity);
  789. }
  790. @Override
  791. public List<UserEntity> getUserName(List<String> id) {
  792. return getUserName(id, false);
  793. }
  794. /**
  795. * 查询用户名称
  796. *
  797. * @param id 主键值
  798. * @return
  799. */
  800. @Override
  801. public List<UserEntity> getUserName(List<String> id, boolean filterEnabledMark) {
  802. List<UserEntity> list = new ArrayList<>();
  803. // 达梦数据库无法null值入参
  804. id.removeAll(Collections.singleton(null));
  805. if (id.size() > 0) {
  806. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  807. queryWrapper.lambda().in(UserEntity::getId, id);
  808. if (filterEnabledMark) {
  809. queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
  810. }
  811. list = this.list(queryWrapper);
  812. }
  813. return list;
  814. }
  815. @Override
  816. public List<UserEntity> getListByUserIds(List<String> id) {
  817. List<UserEntity> list = new ArrayList<>();
  818. // 达梦数据库无法null值入参
  819. id.removeAll(Collections.singleton(null));
  820. if (id.size() > 0) {
  821. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  822. queryWrapper.lambda().in(UserEntity::getId, id);
  823. list = this.list(queryWrapper);
  824. }
  825. return list;
  826. }
  827. @Override
  828. public List<UserEntity> getUserList(List<String> id) {
  829. List<UserEntity> list = new ArrayList<>();
  830. // 达梦数据库无法null值入参
  831. id.removeAll(Collections.singleton(null));
  832. if (id.size() > 0) {
  833. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  834. queryWrapper.lambda().in(UserEntity::getId, id);
  835. queryWrapper.lambda().eq(UserEntity::getEnabledMark, 1);
  836. list = this.list(queryWrapper);
  837. }
  838. return list;
  839. }
  840. @Override
  841. public UserEntity getUserEntity(String account) {
  842. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  843. queryWrapper.lambda().eq(UserEntity::getAccount, account);
  844. return this.baseMapper.selectOne(queryWrapper);
  845. }
  846. @Override
  847. public List<String> getListId() {
  848. return this.baseMapper.getListId();
  849. }
  850. @Override
  851. public void update(UserEntity entity, String type) {
  852. UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
  853. if ("Position".equals(type)) {
  854. wrapper.lambda().set(UserEntity::getPositionId, entity.getPositionId());
  855. } else {
  856. wrapper.lambda().set(UserEntity::getRoleId, entity.getRoleId());
  857. }
  858. wrapper.lambda().eq(UserEntity::getId, entity.getId());
  859. this.update(wrapper);
  860. }
  861. @Override
  862. public void updateLastTime(UserEntity entity, String type) {
  863. UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
  864. if ("Position".equals(type)) {
  865. wrapper.lambda().set(UserEntity::getPositionId, entity.getPositionId());
  866. } else {
  867. wrapper.lambda().set(UserEntity::getRoleId, entity.getRoleId());
  868. }
  869. wrapper.lambda().set(UserEntity::getLastModifyTime, new Date());
  870. wrapper.lambda().set(UserEntity::getLastModifyUserId, entity.getLastModifyUserId());
  871. wrapper.lambda().eq(UserEntity::getId, entity.getId());
  872. this.update(wrapper);
  873. }
  874. @Override
  875. public boolean isSubordinate(String id, String managerId) {
  876. int num = 0;
  877. return recursionSubordinates(id, managerId, num);
  878. }
  879. @Override
  880. public DownloadVO exportExcel(String dataType, String selectKey, PaginationUser pagination) {
  881. List<UserEntity> entityList = new ArrayList<>();
  882. if ("0".equals(dataType)) {
  883. entityList = getList(pagination, pagination.getOrganizeId(), false, true, null, null);
  884. } else if ("1".equals(dataType)) {
  885. entityList = getList(false);
  886. }
  887. List<UserExportVO> modeList = new ArrayList<>();
  888. Map<String, OrganizeEntity> orgMaps = null;
  889. // 长度超过300代表是全部数据
  890. if (entityList.size() > 300) {
  891. orgMaps = organizeService.getOrgMaps(null, true, null);
  892. }
  893. // 得到民族集合
  894. List<DictionaryDataEntity> dataServiceList = dictionaryDataService.getListByTypeDataCode("Nation");
  895. Map<String, String> dataServiceMap = dataServiceList.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  896. // 得到证件类型
  897. List<DictionaryDataEntity> dataServiceList1 = dictionaryDataService.getListByTypeDataCode("certificateType");
  898. Map<String, String> dataServiceMap1 = dataServiceList1.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  899. // 得到文化程度
  900. List<DictionaryDataEntity> dataServiceList2 = dictionaryDataService.getListByTypeDataCode("Education");
  901. Map<String, String> dataServiceMap2 = dataServiceList2.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  902. // 得到职级
  903. List<DictionaryDataEntity> dataServiceList3 = dictionaryDataService.getListByTypeDataCode("Rank");
  904. Map<String, String> dataServiceMap3 = dataServiceList3.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName));
  905. // 得到性别
  906. List<DictionaryDataEntity> dataServiceList4 = dictionaryDataService.getListByTypeDataCode("sex");
  907. Map<String, String> dataServiceMap4 = dataServiceList4.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName));
  908. for (UserEntity entity : entityList) {
  909. UserExportVO model = new UserExportVO();
  910. model.setAccount(entity.getAccount());
  911. model.setRealName(entity.getRealName());
  912. // 组织
  913. // 定义多组织集合
  914. StringJoiner stringJoiner = new StringJoiner(";");
  915. // 获取该用户的所有组织关系
  916. List<UserRelationEntity> allOrgRelationByUserId = userRelationService.getAllOrgRelationByUserId(entity.getId());
  917. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  918. for (UserRelationEntity userRelationEntity : allOrgRelationByUserId) {
  919. String id = userRelationEntity.getObjectId();
  920. OrganizeEntity organize = null;
  921. // 得到该组织信息
  922. if (orgMaps != null) {
  923. organize = orgMaps.get(id);
  924. } else {
  925. organize = organizeService.getInfo(id);
  926. }
  927. // 得到父级id树
  928. if (organize != null && ObjectUtil.equal(organize.getEnabledMark(), 1) && StringUtil.isNotEmpty(organize.getOrganizeIdTree())) {
  929. stringJoiner.add(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organize.getOrganizeIdTree(), "/"));
  930. }
  931. }
  932. model.setOrganizeId(stringJoiner.toString());
  933. // 主管
  934. UserEntity info = getInfo(entity.getManagerId());
  935. if (Objects.nonNull(info) && StringUtil.isNotEmpty(info.getRealName()) && StringUtil.isNotEmpty(info.getAccount())) {
  936. model.setManagerId(info.getRealName() + "/" + info.getAccount());
  937. }
  938. // 岗位
  939. List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(entity.getId(), PermissionConst.POSITION);
  940. StringBuffer positionName = new StringBuffer();
  941. for (UserRelationEntity userRelationEntity : listByObjectType) {
  942. if (StringUtil.isNotEmpty(userRelationEntity.getObjectId())) {
  943. PositionEntity positionEntity = positionService.getInfo(userRelationEntity.getObjectId());
  944. if (Objects.nonNull(positionEntity) && ObjectUtil.equal(positionEntity.getEnabledMark(), 1)) {
  945. positionName.append("," + positionEntity.getFullName() + "/" + positionEntity.getEnCode());
  946. }
  947. }
  948. }
  949. // 判断岗位是否需要导出
  950. if (positionName.length() > 0) {
  951. model.setPositionId(positionName.toString().replaceFirst(",", ""));
  952. }
  953. // 角色
  954. List<UserRelationEntity> listByObjectType1 = userRelationService.getListByObjectType(entity.getId(), PermissionConst.ROLE);
  955. StringBuffer roleName = new StringBuffer();
  956. for (UserRelationEntity userRelationEntity : listByObjectType1) {
  957. if (StringUtil.isNotEmpty(userRelationEntity.getObjectId())) {
  958. RoleEntity roleEntity = roleService.getInfo(userRelationEntity.getObjectId());
  959. if (Objects.nonNull(roleEntity) && ObjectUtil.equal(roleEntity.getEnabledMark(), 1)) {
  960. roleName.append("," + roleEntity.getFullName());
  961. }
  962. }
  963. }
  964. if (roleName.length() > 0) {
  965. model.setRoleId(roleName.toString().replaceFirst(",", ""));
  966. }
  967. model.setDescription(entity.getDescription());
  968. // 性别
  969. if (dataServiceMap4.containsKey(entity.getGender())) {
  970. model.setGender(dataServiceMap4.get(entity.getGender()));
  971. }
  972. // 民族
  973. if (dataServiceMap.containsKey(entity.getNation())) {
  974. model.setNation(dataServiceMap.get(entity.getNation()));
  975. }
  976. model.setNativePlace(entity.getNativePlace());
  977. // 证件类型
  978. if (dataServiceMap1.containsKey(entity.getCertificatesType())) {
  979. model.setCertificatesType(dataServiceMap1.get(entity.getCertificatesType()));
  980. }
  981. model.setCertificatesNumber(entity.getCertificatesNumber());
  982. // 文化程度
  983. if (dataServiceMap2.containsKey(entity.getEducation())) {
  984. model.setEducation(dataServiceMap2.get(entity.getEducation()));
  985. }
  986. // 生日
  987. SimpleDateFormat sf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  988. if (entity.getBirthday() != null) {
  989. String birthday = sf1.format(entity.getBirthday());
  990. model.setBirthday(birthday);
  991. }
  992. model.setTelePhone(entity.getTelePhone());
  993. model.setLandline(entity.getLandline());
  994. model.setMobilePhone(entity.getMobilePhone());
  995. model.setEmail(entity.getEmail());
  996. model.setUrgentContacts(entity.getUrgentContacts());
  997. model.setUrgentTelePhone(entity.getUrgentTelePhone());
  998. model.setPostalAddress(entity.getPostalAddress());
  999. model.setSortCode(entity.getSortCode() == null ? 0 : entity.getSortCode());
  1000. // 设置状态
  1001. if (entity.getEnabledMark() == null) {
  1002. model.setEnabledMark("禁用");
  1003. } else {
  1004. if (entity.getEnabledMark() == 2) {
  1005. model.setEnabledMark("锁定");
  1006. } else if (entity.getEnabledMark() == 1) {
  1007. model.setEnabledMark("正常");
  1008. } else {
  1009. model.setEnabledMark("禁用");
  1010. }
  1011. }
  1012. // 入职时间
  1013. if (entity.getEntryDate() != null) {
  1014. String entryDate = sf1.format(entity.getEntryDate());
  1015. model.setEntryDate(entryDate);
  1016. }
  1017. // 职级
  1018. if (dataServiceMap3.containsKey(entity.getRanks())) {
  1019. model.setRanks(dataServiceMap3.get(entity.getRanks()));
  1020. }
  1021. modeList.add(model);
  1022. }
  1023. return exportUtil(selectKey, "用户信息", modeList, 0);
  1024. }
  1025. private DownloadVO exportUtil(String selectKey, String explain, List modeList, int type) {
  1026. List list = JsonUtil.listToJsonField(JsonUtil.getJsonToList(modeList, UserExportVO.class));
  1027. if (type == 1) {
  1028. list = JsonUtil.listToJsonField(JsonUtil.getJsonToList(modeList, UserExportExceptionVO.class));
  1029. }
  1030. List<ExcelExportEntity> entitys = new ArrayList<>();
  1031. String[] splitData = selectKey.split(",");
  1032. if (splitData.length > 0) {
  1033. for (int i = 0; i < splitData.length; i++) {
  1034. if (splitData[i].equals("account")) {
  1035. entitys.add(new ExcelExportEntity("账号", "account"));
  1036. }
  1037. if (splitData[i].equals("realName")) {
  1038. entitys.add(new ExcelExportEntity("姓名", "realName"));
  1039. }
  1040. if (splitData[i].equals("gender")) {
  1041. entitys.add(new ExcelExportEntity("性别", "gender"));
  1042. }
  1043. if (splitData[i].equals("email")) {
  1044. entitys.add(new ExcelExportEntity("电子邮箱", "email"));
  1045. }
  1046. if (splitData[i].equals("organizeId")) {
  1047. entitys.add(new ExcelExportEntity("所属组织", "organizeId"));
  1048. }
  1049. if (splitData[i].equals("managerId")) {
  1050. entitys.add(new ExcelExportEntity("直属主管", "managerId"));
  1051. }
  1052. if (splitData[i].equals("positionId")) {
  1053. entitys.add(new ExcelExportEntity("岗位", "positionId"));
  1054. }
  1055. if (splitData[i].equals("ranks")) {
  1056. entitys.add(new ExcelExportEntity("职级", "ranks"));
  1057. }
  1058. if (splitData[i].equals("roleId")) {
  1059. entitys.add(new ExcelExportEntity("角色", "roleId"));
  1060. }
  1061. if (splitData[i].equals("sortCode")) {
  1062. entitys.add(new ExcelExportEntity("排序", "sortCode"));
  1063. }
  1064. if (splitData[i].equals("enabledMark")) {
  1065. entitys.add(new ExcelExportEntity("状态", "enabledMark"));
  1066. }
  1067. if (splitData[i].equals("description")) {
  1068. entitys.add(new ExcelExportEntity("说明", "description", 25));
  1069. }
  1070. if (splitData[i].equals("nation")) {
  1071. entitys.add(new ExcelExportEntity("民族", "nation"));
  1072. }
  1073. if (splitData[i].equals("nativePlace")) {
  1074. entitys.add(new ExcelExportEntity("籍贯", "nativePlace"));
  1075. }
  1076. if (splitData[i].equals("entryDate")) {
  1077. entitys.add(new ExcelExportEntity("入职时间", "entryDate"));
  1078. }
  1079. if (splitData[i].equals("certificatesType")) {
  1080. entitys.add(new ExcelExportEntity("证件类型", "certificatesType"));
  1081. }
  1082. if (splitData[i].equals("certificatesNumber")) {
  1083. entitys.add(new ExcelExportEntity("证件号码", "certificatesNumber"));
  1084. }
  1085. if (splitData[i].equals("education")) {
  1086. entitys.add(new ExcelExportEntity("文化程度", "education"));
  1087. }
  1088. if (splitData[i].equals("birthday")) {
  1089. entitys.add(new ExcelExportEntity("出生年月", "birthday"));
  1090. }
  1091. if (splitData[i].equals("telePhone")) {
  1092. entitys.add(new ExcelExportEntity("办公电话", "telePhone"));
  1093. }
  1094. if (splitData[i].equals("landline")) {
  1095. entitys.add(new ExcelExportEntity("办公座机", "landline"));
  1096. }
  1097. if (splitData[i].equals("mobilePhone")) {
  1098. entitys.add(new ExcelExportEntity("手机号码", "mobilePhone"));
  1099. }
  1100. if (splitData[i].equals("urgentContacts")) {
  1101. entitys.add(new ExcelExportEntity("紧急联系", "urgentContacts"));
  1102. }
  1103. if (splitData[i].equals("urgentTelePhone")) {
  1104. entitys.add(new ExcelExportEntity("紧急电话", "urgentTelePhone"));
  1105. }
  1106. if (splitData[i].equals("postalAddress")) {
  1107. entitys.add(new ExcelExportEntity("通讯地址", "postalAddress", 25));
  1108. }
  1109. if (splitData[i].equals("errorsInfo")) {
  1110. entitys.add(new ExcelExportEntity("异常原因", "errorsInfo", 50));
  1111. }
  1112. }
  1113. }
  1114. ExportParams exportParams = new ExportParams(null, "用户信息");
  1115. exportParams.setType(ExcelType.XSSF);
  1116. DownloadVO vo = DownloadVO.builder().build();
  1117. try {
  1118. @Cleanup Workbook workbook = new HSSFWorkbook();
  1119. if (entitys.size() > 0) {
  1120. workbook = ExcelExportUtil.exportExcel(exportParams, entitys, list);
  1121. }
  1122. String name = explain + DateUtil.dateFormatByPattern(new Date(), "yyyyMMddHHmmss") + ".xlsx" ;
  1123. MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, name);
  1124. FileInfo fileInfo = FileUploadUtils.uploadFile(new FileParameter(FileTypeConstant.TEMPORARY, name), multipartFile);
  1125. vo.setName(fileInfo.getFilename());
  1126. vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + "Temporary") + "&name=" + name);
  1127. } catch (Exception e) {
  1128. log.error("用户信息导出Excel错误:" + e.getMessage());
  1129. }
  1130. return vo;
  1131. }
  1132. @Override
  1133. public Map<String, Object> importPreview(List<UserExportVO> personList) {
  1134. List<Map<String, Object>> dataRow = new ArrayList<>();
  1135. List<Map<String, Object>> columns = new ArrayList<>();
  1136. for (int i = 0; i < personList.size(); i++) {
  1137. Map<String, Object> dataRowMap = new HashMap<>();
  1138. UserExportVO model = personList.get(i);
  1139. dataRowMap.put("account", model.getAccount());
  1140. dataRowMap.put("realName", model.getRealName());
  1141. dataRowMap.put("organizeId", model.getOrganizeId());
  1142. dataRowMap.put("managerId", model.getManagerId());
  1143. dataRowMap.put("positionId", model.getPositionId());
  1144. dataRowMap.put("roleId", model.getRoleId());
  1145. dataRowMap.put("description", model.getDescription());
  1146. dataRowMap.put("gender", model.getGender());
  1147. dataRowMap.put("nation", model.getNation());
  1148. dataRowMap.put("nativePlace", model.getNativePlace());
  1149. dataRowMap.put("certificatesType", model.getCertificatesType());
  1150. dataRowMap.put("certificatesNumber", model.getCertificatesNumber());
  1151. dataRowMap.put("education", model.getEducation());
  1152. dataRowMap.put("birthday", model.getBirthday());
  1153. dataRowMap.put("telePhone", model.getTelePhone());
  1154. dataRowMap.put("landline", model.getLandline());
  1155. dataRowMap.put("mobilePhone", model.getMobilePhone());
  1156. dataRowMap.put("email", model.getEmail());
  1157. dataRowMap.put("urgentContacts", model.getUrgentContacts());
  1158. dataRowMap.put("urgentTelePhone", model.getUrgentTelePhone());
  1159. dataRowMap.put("postalAddress", model.getPostalAddress());
  1160. dataRowMap.put("sortCode", model.getSortCode());
  1161. dataRowMap.put("enabledMark", model.getEnabledMark());
  1162. dataRowMap.put("entryDate", model.getEntryDate());
  1163. dataRowMap.put("ranks", model.getRanks());
  1164. dataRow.add(dataRowMap);
  1165. }
  1166. for (int i = 1; i <= personList.size(); i++) {
  1167. Map<String, Object> columnsMap = new HashMap<>();
  1168. columnsMap.put("AllowDBNull", true);
  1169. columnsMap.put("AutoIncrement", false);
  1170. columnsMap.put("AutoIncrementSeed", 0);
  1171. columnsMap.put("AutoIncrementStep", 1);
  1172. columnsMap.put("Caption", this.getColumns(i));
  1173. columnsMap.put("ColumnMapping", 1);
  1174. columnsMap.put("ColumnName", this.getColumns(i));
  1175. columnsMap.put("Container", null);
  1176. columnsMap.put("DataType", "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
  1177. columnsMap.put("DateTimeMode", 3);
  1178. columnsMap.put("DefaultValue", null);
  1179. columnsMap.put("DesignMode", false);
  1180. columnsMap.put("Expression", "");
  1181. columnsMap.put("ExtendedProperties", "");
  1182. columnsMap.put("MaxLength", -1);
  1183. columnsMap.put("Namespace", "");
  1184. columnsMap.put("Ordinal", 0);
  1185. columnsMap.put("Prefix", "");
  1186. columnsMap.put("ReadOnly", false);
  1187. columnsMap.put("Site", null);
  1188. columnsMap.put("Table", personList);
  1189. columnsMap.put("Unique", false);
  1190. columns.add(columnsMap);
  1191. }
  1192. Map<String, Object> map = new HashMap<>();
  1193. map.put("dataRow", dataRow);
  1194. map.put("columns", columns);
  1195. return map;
  1196. }
  1197. @Override
  1198. public UserImportVO importData(List<UserExportVO> dataList) {
  1199. // List<UserImportModel> importModels = new ArrayList<>(16);
  1200. List<UserExportExceptionVO> exceptionList = new ArrayList<>(16);
  1201. // 得到民族集合
  1202. List<DictionaryDataEntity> dataServiceList = dictionaryDataService.getListByTypeDataCode("Nation");
  1203. BiMap<String, String> dataServiceMap = HashBiMap.create(dataServiceList.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)));
  1204. // 得到证件类型
  1205. List<DictionaryDataEntity> dataServiceList1 = dictionaryDataService.getListByTypeDataCode("certificateType");
  1206. BiMap<String, String> dataServiceMap1 = HashBiMap.create(dataServiceList1.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)));
  1207. // 得到文化程度
  1208. List<DictionaryDataEntity> dataServiceList2 = dictionaryDataService.getListByTypeDataCode("Education");
  1209. BiMap<String, String> dataServiceMap2 = HashBiMap.create(dataServiceList2.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)));
  1210. // 得到职级
  1211. List<DictionaryDataEntity> dataServiceList3 = dictionaryDataService.getListByTypeDataCode("Rank");
  1212. BiMap<String, String> dataServiceMap3 = HashBiMap.create(dataServiceList3.stream().collect(Collectors.toMap(DictionaryDataEntity::getId, DictionaryDataEntity::getFullName)));
  1213. // 得到性别
  1214. List<DictionaryDataEntity> dataServiceList4 = dictionaryDataService.getListByTypeDataCode("sex");
  1215. BiMap<String, String> dataServiceMap4 = HashBiMap.create(dataServiceList4.stream().collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName)));
  1216. // // 去除重复的account
  1217. // Map<String, Long> collect = dataList.stream().filter(t -> StringUtil.isNotBlank(t.getAccount())).collect(Collectors.groupingBy(t -> t.getAccount(), Collectors.counting()));
  1218. // List<String> collect1 = collect.entrySet().stream().filter(entry -> entry.getValue() > 1).map(entry -> entry.getKey()).collect(Collectors.toList());
  1219. // for (String account : collect1) {
  1220. // List<UserExportVO> collect2 = dataList.stream().filter(t -> account.equals(t.getAccount())).collect(Collectors.toList());
  1221. // dataList.removeAll(collect2);
  1222. // exceptionList.addAll(collect2);
  1223. // }
  1224. // Map<String, UserExportVO> userExportVOMap = dataList.stream().collect(Collectors.toMap(UserExportVO::getAccount, Function.identity()));
  1225. //记录成功了几条
  1226. int sum = 0;
  1227. //记录第几条失败
  1228. int num = 0;
  1229. for (UserExportVO exportVO : dataList) {
  1230. UserImportModel model = new UserImportModel();
  1231. UserExportExceptionVO exceptionVO = JsonUtil.getJsonToBean(exportVO, UserExportExceptionVO.class);
  1232. StringJoiner exceptionMsg = new StringJoiner(";");
  1233. // 处理账号
  1234. if (StringUtil.isNotEmpty(exportVO.getAccount())) {
  1235. UserEntity userByAccount = getUserByAccount(exportVO.getAccount());
  1236. if (Objects.nonNull(userByAccount)) {
  1237. // 账号重复
  1238. exceptionMsg.add("账号已存在");
  1239. }
  1240. String regex = "^[a-z0-9A-Z\u4e00-\u9fa5]+$" ;
  1241. if (!exportVO.getAccount().matches(regex)) {
  1242. // 账号重复
  1243. exceptionMsg.add("账户值不能含有特殊符号");
  1244. }
  1245. model.setAccount(exportVO.getAccount());
  1246. } else {
  1247. // 账号为空
  1248. exceptionMsg.add("账号不能为空");
  1249. }
  1250. // 处理姓名
  1251. if (StringUtil.isEmpty(exportVO.getRealName())) {
  1252. // 姓名为空
  1253. exceptionMsg.add("姓名不能为空");
  1254. }
  1255. model.setRealName(exportVO.getRealName());
  1256. // 处理组织id
  1257. String organizeId = exportVO.getOrganizeId();
  1258. if (StringUtil.isEmpty(organizeId)) {
  1259. // 判断如果所属组织为空,则为错误数据
  1260. exceptionMsg.add("所属组织不能为空");
  1261. } else {
  1262. StringJoiner orgName = new StringJoiner("、");
  1263. // 处理多级组织
  1264. String[] organizeIds = organizeId.split(";");
  1265. // 储存字段
  1266. StringJoiner orgIds = new StringJoiner(",");
  1267. // 处理单个组织
  1268. for (String id : organizeIds) {
  1269. String[] split = id.split("/");
  1270. // 定义一个标志,当前部门如果不存在则存到错误集合中
  1271. if (split.length > 0) {
  1272. for (int i = 0; i < split.length; i++) {
  1273. String orgId = split[i];
  1274. OrganizeEntity organizeEntity = organizeService.getInfoByFullName(orgId);
  1275. if (organizeEntity != null) {
  1276. if (i == split.length - 1) {
  1277. orgIds.add(organizeEntity.getId());
  1278. }
  1279. } else {
  1280. orgName.add(id);
  1281. break;
  1282. }
  1283. }
  1284. }
  1285. }
  1286. if (orgName.length() > 0) {
  1287. exceptionMsg.add("找不到该所属组织(" + orgName.toString() + ")");
  1288. } else {
  1289. model.setOrganizeId(orgIds.toString());
  1290. }
  1291. }
  1292. // 处理性别
  1293. if (StringUtil.isEmpty(exportVO.getGender())) {
  1294. // 性别为必填项,不给默认为错误,不给默认值
  1295. exceptionMsg.add("性别不能为空");
  1296. } else {
  1297. if (dataServiceMap4.containsValue(exportVO.getGender())) {
  1298. model.setGender(dataServiceMap4.inverse().get(exportVO.getGender()));
  1299. } else {
  1300. exceptionMsg.add("找不到该性别");
  1301. }
  1302. }
  1303. // 处理主管id
  1304. String managerId = exportVO.getManagerId();
  1305. if (StringUtil.isNotEmpty(managerId)) {
  1306. String[] split1 = managerId.split("/");
  1307. if (split1.length > 0) {
  1308. String account = split1[split1.length - 1];
  1309. UserEntity entity = getUserByAccount(account);
  1310. if (Objects.nonNull(entity) && StringUtil.isNotEmpty(entity.getAccount())) {
  1311. model.setManagerId(entity.getId());
  1312. }
  1313. }
  1314. }
  1315. String tmpOrganizeId = StringUtil.isEmpty(model.getOrganizeId()) ? "" : model.getOrganizeId();
  1316. // 处理岗位id
  1317. String positionId = exportVO.getPositionId();
  1318. if (StringUtil.isNotEmpty(positionId)) {
  1319. StringBuilder positionIdBuffer = new StringBuilder();
  1320. String[] positionIds = positionId.split(",");
  1321. for (String id : positionIds) {
  1322. // 岗位名称+编码
  1323. String[] positionName = id.split("/");
  1324. // 无编码无名称代表是无用数据,不予保存
  1325. if (positionName.length > 1) {
  1326. // 通过名称和编码获取岗位信息
  1327. List<PositionEntity> positionEntityList = positionService.getListByFullName(positionName[0], positionName[1]);
  1328. if (positionEntityList != null && positionEntityList.size() > 0) {
  1329. PositionEntity positionEntity = positionEntityList.get(0);
  1330. String[] split = tmpOrganizeId.split(",");
  1331. boolean flag = false;
  1332. for (String orgId : split) {
  1333. List<PositionEntity> list = positionService.getListByOrganizeId(Collections.singletonList(orgId), false);
  1334. if (list.stream().anyMatch(t -> t.getId().equals(positionEntity.getId()))) {
  1335. flag = true;
  1336. break;
  1337. }
  1338. }
  1339. if (flag) {
  1340. positionIdBuffer.append("," + positionEntity.getId());
  1341. }
  1342. }
  1343. }
  1344. }
  1345. model.setPositionId(positionIdBuffer.toString().replaceFirst(",", ""));
  1346. }
  1347. model.setDescription(exportVO.getDescription());
  1348. // 处理民族
  1349. if (StringUtil.isNotEmpty(exportVO.getNation())) {
  1350. if (dataServiceMap.containsValue(exportVO.getNation())) {
  1351. model.setNation(dataServiceMap.inverse().get(exportVO.getNation()));
  1352. }
  1353. }
  1354. model.setNativePlace(exportVO.getNativePlace());
  1355. // 处理证件类型
  1356. if (StringUtil.isNotEmpty(exportVO.getCertificatesType())) {
  1357. if (dataServiceMap1.containsValue(exportVO.getCertificatesType())) {
  1358. model.setCertificatesType(dataServiceMap1.inverse().get(exportVO.getCertificatesType()));
  1359. }
  1360. }
  1361. model.setCertificatesNumber(exportVO.getCertificatesNumber());
  1362. // 处理文化程度
  1363. if (StringUtil.isNotEmpty(exportVO.getEducation())) {
  1364. if (dataServiceMap2.containsValue(exportVO.getEducation())) {
  1365. model.setEducation(dataServiceMap2.inverse().get(exportVO.getEducation()));
  1366. }
  1367. }
  1368. // 处理生日
  1369. if (StringUtil.isNotEmpty(exportVO.getBirthday())) {
  1370. Date date = DateUtil.stringToDate(exportVO.getBirthday());
  1371. model.setBirthday(date);
  1372. }
  1373. model.setTelePhone(exportVO.getTelePhone());
  1374. model.setMobilePhone(exportVO.getMobilePhone());
  1375. model.setLandline(exportVO.getLandline());
  1376. model.setEmail(exportVO.getEmail());
  1377. model.setUrgentContacts(exportVO.getUrgentContacts());
  1378. model.setUrgentTelePhone(exportVO.getUrgentTelePhone());
  1379. model.setPostalAddress(exportVO.getPostalAddress());
  1380. model.setSortCode(exportVO.getSortCode() == null ? 0 : exportVO.getSortCode());
  1381. // 入职时间
  1382. if (StringUtil.isNotEmpty(exportVO.getEntryDate())) {
  1383. Date date = DateUtil.stringToDate(exportVO.getEntryDate());
  1384. model.setEntryDate(date);
  1385. }
  1386. // 设置状态
  1387. if ("锁定".equals(exportVO.getEnabledMark())) {
  1388. model.setEnabledMark(2);
  1389. } else if ("正常".equals(exportVO.getEnabledMark())) {
  1390. model.setEnabledMark(1);
  1391. } else {
  1392. model.setEnabledMark(0);
  1393. }
  1394. // 处理证件类型
  1395. if (StringUtil.isNotEmpty(exportVO.getRanks())) {
  1396. if (dataServiceMap3.containsValue(exportVO.getRanks())) {
  1397. model.setRanks(dataServiceMap3.inverse().get(exportVO.getRanks()));
  1398. }
  1399. }
  1400. if (exceptionMsg.length() > 0) {
  1401. exceptionVO.setErrorsInfo(exceptionMsg.toString());
  1402. exceptionList.add(exceptionVO);
  1403. continue;
  1404. }
  1405. UserEntity entitys = JsonUtil.getJsonToBean(model, UserEntity.class);
  1406. entitys.setHeadIcon("001.png");
  1407. try {
  1408. create(entitys);
  1409. sum++;
  1410. } catch (Exception e) {
  1411. if (e instanceof DataException) {
  1412. exceptionVO.setErrorsInfo(e.getMessage());
  1413. } else {
  1414. exceptionVO.setErrorsInfo("数据有误");
  1415. }
  1416. exceptionList.add(exceptionVO);
  1417. log.error("导入第" + (num + 1) + "条数据失败");
  1418. }
  1419. }
  1420. UserImportVO vo = new UserImportVO();
  1421. vo.setSnum(sum);
  1422. if (exceptionList.size() > 0) {
  1423. vo.setResultType(1);
  1424. vo.setFailResult(exceptionList);
  1425. vo.setFnum(exceptionList.size());
  1426. return vo;
  1427. } else {
  1428. vo.setResultType(0);
  1429. return vo;
  1430. }
  1431. }
  1432. @Override
  1433. public void getOrganizeIdTree(String organizeId, StringBuffer organizeParentIdList) {
  1434. OrganizeEntity entity = organizeService.getInfo(organizeId);
  1435. if (Objects.nonNull(entity) && StringUtil.isNotEmpty(entity.getParentId())) {
  1436. // 记录id
  1437. organizeParentIdList.append(organizeId + ",");
  1438. getOrganizeIdTree(entity.getParentId(), organizeParentIdList);
  1439. }
  1440. }
  1441. @Override
  1442. public DownloadVO exportExceptionData(List<UserExportExceptionVO> dataList) {
  1443. DownloadVO vo = exportUtil("account,realName,gender,email,organizeId,managerId,positionId,roleId,sortCode,enabledMark,description,nation," +
  1444. "nativePlace,entryDate,certificatesType,certificatesNumber,education,birthday,telePhone,landline,mobilePhone,urgentContacts," +
  1445. "urgentTelePhone,postalAddress,ranks,errorsInfo"
  1446. , "错误报告", dataList, 1);
  1447. return vo;
  1448. }
  1449. @Override
  1450. public List<UserEntity> getUserName(List<String> id, Pagination pagination) {
  1451. List<UserEntity> list = new ArrayList<>();
  1452. id.removeAll(Collections.singleton(null));
  1453. if (id.size() > 0) {
  1454. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  1455. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  1456. queryWrapper.lambda().and(
  1457. t -> t.like(UserEntity::getRealName, pagination.getKeyword())
  1458. .or().like(UserEntity::getAccount, pagination.getKeyword())
  1459. );
  1460. }
  1461. queryWrapper.lambda().in(UserEntity::getId, id);
  1462. queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
  1463. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount,
  1464. UserEntity::getGender, UserEntity::getHeadIcon, UserEntity::getMobilePhone);
  1465. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  1466. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  1467. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  1468. }
  1469. return pagination.setData(list, list.size());
  1470. }
  1471. @Override
  1472. public List<UserEntity> getUserNames(List<String> id, PaginationUser pagination, Boolean flag, Boolean enabledMark) {
  1473. List<UserEntity> list = new ArrayList<>();
  1474. id.removeAll(Collections.singleton(null));
  1475. if (id.size() > 0) {
  1476. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  1477. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  1478. queryWrapper.lambda().and(
  1479. t -> t.like(UserEntity::getRealName, pagination.getKeyword())
  1480. .or().like(UserEntity::getAccount, pagination.getKeyword())
  1481. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  1482. );
  1483. }
  1484. List<List<String>> lists = Lists.partition(id, 1000);
  1485. queryWrapper.lambda().and(t -> {
  1486. for (List<String> userId : lists) {
  1487. t.or().in(UserEntity::getId, userId);
  1488. }
  1489. });
  1490. if (flag) {
  1491. queryWrapper.lambda().ne(UserEntity::getId, UserProvider.getUser().getUserId());
  1492. }
  1493. if (enabledMark) {
  1494. queryWrapper.lambda().ne(UserEntity::getEnabledMark, 0);
  1495. }
  1496. if (StringUtil.isNotEmpty(pagination.getGender())) {
  1497. queryWrapper.lambda().eq(UserEntity::getGender, pagination.getGender());
  1498. }
  1499. queryWrapper.lambda().orderByDesc(UserEntity::getCreatorTime);
  1500. // queryWrapper.lambda().select(UserEntity::getId, UserEntity::getRealName, UserEntity::getAccount,
  1501. // UserEntity::getGender, UserEntity::getMobilePhone);
  1502. if (ObjectUtil.isEmpty(pagination) || Objects.equals(pagination.getDataType(), 1)) {
  1503. return this.list(queryWrapper);
  1504. }
  1505. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  1506. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  1507. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  1508. }
  1509. return ObjectUtil.isEmpty(pagination) ? new ArrayList<>() : pagination.setData(list, list.size());
  1510. }
  1511. @Override
  1512. public List<UserEntity> getListByRoleId(String roleId) {
  1513. List<UserEntity> list = new ArrayList<>();
  1514. // 根据roleId获取,用户与组织的关联对象集合
  1515. userRelationService.getListByRoleId(roleId).forEach(u -> {
  1516. list.add(this.getInfo(u.getUserId()));
  1517. });
  1518. return list;
  1519. }
  1520. @Override
  1521. public List<UserEntity> getListByRoleIds(List<String> roleIds) {
  1522. QueryWrapper<UserRelationEntity> query = new QueryWrapper<>();
  1523. query.lambda().eq(UserRelationEntity::getObjectType, "role").in(UserRelationEntity::getObjectId, roleIds);
  1524. List<UserRelationEntity> list = userRelationService.list(query);
  1525. if (CollectionUtil.isNotEmpty(list)) {
  1526. List<String> userIds = list.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  1527. return listByIds(userIds);
  1528. }
  1529. return new ArrayList<>();
  1530. }
  1531. @Override
  1532. public List<String> getFullNameByIds(List<String> ids) {
  1533. List<String> list = new ArrayList<>();
  1534. if (ids != null) {
  1535. ids.forEach(selectedId -> {
  1536. if (StringUtil.isNotEmpty(selectedId)) {
  1537. String[] split = selectedId.split("--");
  1538. // 截取type后获取详情
  1539. if (split.length > 1) {
  1540. String type = split[1];
  1541. if (PermissionConst.COMPANY.equalsIgnoreCase(type) || PermissionConst.DEPARTMENT.equalsIgnoreCase(type)) {
  1542. OrganizeEntity organizeEntity = organizeService.getInfo(split[0]);
  1543. if (organizeEntity != null) {
  1544. list.add(organizeEntity.getFullName());
  1545. }
  1546. } else if (PermissionConst.ROLE.equalsIgnoreCase(type)) {
  1547. RoleEntity roleEntity = roleService.getInfo(split[0]);
  1548. if (roleEntity != null) {
  1549. list.add(roleEntity.getFullName());
  1550. }
  1551. } else if (PermissionConst.POSITION.equalsIgnoreCase(type)) {
  1552. PositionEntity positionEntity = positionService.getInfo(split[0]);
  1553. if (positionEntity != null) {
  1554. list.add(positionEntity.getFullName());
  1555. }
  1556. } else if (PermissionConst.GROUP.equalsIgnoreCase(type)) {
  1557. GroupEntity groupEntity = groupService.getInfo(split[0]);
  1558. if (groupEntity != null) {
  1559. list.add(groupEntity.getFullName());
  1560. }
  1561. } else if ("user".equalsIgnoreCase(type)) {
  1562. UserEntity userEntity = this.getInfo(split[0]);
  1563. if (userEntity != null) {
  1564. list.add(userEntity.getRealName());
  1565. }
  1566. }
  1567. } else {
  1568. UserEntity userEntity = this.getInfo(split[0]);
  1569. if (userEntity != null) {
  1570. list.add(userEntity.getRealName());
  1571. }
  1572. }
  1573. }
  1574. });
  1575. }
  1576. return list;
  1577. }
  1578. @Override
  1579. public List<BaseInfoVo> selectedByIds(List<String> ids) {
  1580. List<BaseInfoVo> list = new ArrayList<>();
  1581. List<OrganizeEntity> organizeEntityList = organizeService.list();
  1582. Map<String, Object> allOrgsTreeName = organizeService.getAllOrgsTreeName();
  1583. List<OrganizeSelectorVO> organizeSelectorList = JsonUtil.getJsonToList(organizeEntityList, OrganizeSelectorVO.class);
  1584. for (OrganizeSelectorVO item : organizeSelectorList) {
  1585. if (PermissionConst.DEPARTMENT.equals(item.getCategory())) {
  1586. item.setIcon(PermissionConst.DEPARTMENT_ICON);
  1587. } else {
  1588. item.setIcon(PermissionConst.COMPANY_ICON);
  1589. }
  1590. item.setFullName(item.getOrgNameTree());
  1591. if (StringUtil.isNotEmpty(item.getParentId()) && Objects.nonNull(allOrgsTreeName.get(item.getParentId()))) {
  1592. item.setParentName(allOrgsTreeName.get(item.getParentId()).toString());
  1593. }
  1594. String[] orgs = item.getOrganizeIdTree().split(",");
  1595. item.setOrganizeIds(Arrays.asList(orgs));
  1596. }
  1597. if (ids != null) {
  1598. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1599. ids.forEach(selectedId -> {
  1600. if (StringUtil.isNotEmpty(selectedId)) {
  1601. // 判断是否为系统参数
  1602. if (JnpfConst.SYSTEM_PARAM.containsKey(selectedId)) {
  1603. UserIdListVo vo = new UserIdListVo();
  1604. vo.setId(selectedId);
  1605. vo.setFullName(JnpfConst.SYSTEM_PARAM.get(selectedId));
  1606. }
  1607. //组织
  1608. String[] split = selectedId.split("--");
  1609. // 截取type后获取详情
  1610. if (split.length > 1) {
  1611. String type = split[1];
  1612. if (PermissionConst.COMPANY.equalsIgnoreCase(type) || PermissionConst.DEPARTMENT.equalsIgnoreCase(type)) {
  1613. OrganizeEntity organizeEntity = organizeService.getInfo(split[0]);
  1614. if (organizeEntity != null) {
  1615. BaseInfoVo vo = JsonUtil.getJsonToBean(organizeEntity, BaseInfoVo.class);
  1616. if ("department".equals(organizeEntity.getCategory())) {
  1617. vo.setIcon(PermissionConst.DEPARTMENT_ICON);
  1618. } else if ("company".equals(organizeEntity.getCategory())) {
  1619. vo.setIcon(PermissionConst.COMPANY_ICON);
  1620. }
  1621. vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/"));
  1622. vo.setOrganizeIds(organizeService.getOrgIdTree(organizeEntity));
  1623. vo.setType(organizeEntity.getCategory());
  1624. list.add(vo);
  1625. }
  1626. } else if (PermissionConst.ROLE.equalsIgnoreCase(type)) {
  1627. RoleEntity roleEntity = roleService.getInfo(split[0]);
  1628. if (roleEntity != null) {
  1629. BaseInfoVo vo = JsonUtil.getJsonToBean(roleEntity, BaseInfoVo.class);
  1630. List<RoleRelationEntity> relationListByRoleId = roleRelationService.getListByRoleId(vo.getId(), null);
  1631. StringJoiner orgName = new StringJoiner(",");
  1632. relationListByRoleId.forEach(item -> {
  1633. orgName.add(item.getObjectId());
  1634. });
  1635. vo.setId(selectedId);
  1636. vo.setOrganize(orgName.toString());
  1637. vo.setType(SysParamEnum.ROLE.getCode());
  1638. vo.setIcon(PermissionConst.ROLE_ICON);
  1639. vo.setOrgNameTree(vo.getFullName());
  1640. list.add(vo);
  1641. }
  1642. } else if (SysParamEnum.POS.getCode().equalsIgnoreCase(type) ||
  1643. SysParamEnum.SUBPOS.getCode().equalsIgnoreCase(type) ||
  1644. SysParamEnum.PROGENYPOS.getCode().equalsIgnoreCase(type)) {
  1645. PositionEntity positionEntity = positionService.getInfo(split[0]);
  1646. if (positionEntity != null) {
  1647. BaseInfoVo vo = JsonUtil.getJsonToBean(positionEntity, BaseInfoVo.class);
  1648. vo.setId(selectedId);
  1649. OrganizeEntity info = organizeService.getInfo(positionEntity.getOrganizeId());
  1650. String orgName = "" ;
  1651. if (info != null) {
  1652. vo.setOrganize(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/"));
  1653. orgName = vo.getOrganize();
  1654. }
  1655. vo.setType(SysParamEnum.get(type).getCode());
  1656. vo.setIcon(PermissionConst.POSITION_ICON);
  1657. vo.setOrgNameTree(orgName + "/" + positionEntity.getFullName() + SysParamEnum.get(type).getSuffix());
  1658. list.add(vo);
  1659. }
  1660. } else if (SysParamEnum.GROUP.getCode().equalsIgnoreCase(type)) {
  1661. GroupEntity groupEntity = groupService.getInfo(split[0]);
  1662. if (groupEntity != null) {
  1663. BaseInfoVo vo = JsonUtil.getJsonToBean(groupEntity, BaseInfoVo.class);
  1664. vo.setIcon(PermissionConst.GROUP_ICON);
  1665. vo.setId(selectedId);
  1666. vo.setType(SysParamEnum.GROUP.getCode());
  1667. vo.setOrgNameTree(groupEntity.getFullName() + SysParamEnum.get(type).getSuffix());
  1668. list.add(vo);
  1669. }
  1670. } else if (SysParamEnum.USER.getCode().equalsIgnoreCase(type)) {
  1671. UserEntity userEntity = this.getInfo(split[0]);
  1672. if (userEntity != null) {
  1673. BaseInfoVo vo = JsonUtil.getJsonToBean(userEntity, BaseInfoVo.class);
  1674. List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(userEntity.getId(), PermissionConst.ORGANIZE);
  1675. StringJoiner orgName = new StringJoiner(",");
  1676. listByObjectType.forEach(userRelationEntity -> {
  1677. OrganizeEntity info = organizeService.getInfo(userRelationEntity.getObjectId());
  1678. if (info != null) {
  1679. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/");
  1680. orgName.add(fullNameByOrgIdTree);
  1681. }
  1682. });
  1683. vo.setId(selectedId);
  1684. vo.setOrganize(orgName.toString());
  1685. vo.setType(SysParamEnum.USER.getCode());
  1686. vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
  1687. vo.setFullName(vo.getRealName() + "/" + vo.getAccount());
  1688. vo.setOrgNameTree(vo.getFullName());
  1689. list.add(vo);
  1690. }
  1691. } else {
  1692. BaseInfoVo vo = new BaseInfoVo();
  1693. List<OrganizeSelectorVO> collect = organizeSelectorList.stream()
  1694. .filter(it -> split[0].equals(it.getId()))
  1695. .collect(Collectors.toList());
  1696. if (!collect.isEmpty()) {
  1697. vo = BeanUtil.copyProperties(collect.get(0), BaseInfoVo.class);
  1698. String id = split[0];
  1699. SysParamEnum sysParamEnum = SysParamEnum.get(type);
  1700. String suffix = sysParamEnum != null ? sysParamEnum.getSuffix() : "" ;
  1701. vo.setId(selectedId);
  1702. vo.setOrgNameTree(allOrgsTreeName.get(id) + suffix);
  1703. }
  1704. vo.setId(selectedId);
  1705. vo.setFullName(SysParamEnum.get(split[1]).getName());
  1706. vo.setRealName(orgIdNameMaps.get(split[0]) + "\\" + vo.getFullName());
  1707. vo.setType(split[1]);
  1708. list.add(vo);
  1709. }
  1710. } else {
  1711. UserEntity userEntity = this.getInfo(split[0]);
  1712. if (userEntity != null) {
  1713. extracted(userEntity, orgIdNameMaps, list, userEntity.getRealName() + "/" + userEntity.getAccount());
  1714. }
  1715. if (selectedId.equals("@userId")) {
  1716. UserInfo user = UserProvider.getUser();
  1717. userEntity = this.getInfo(user.getUserId());
  1718. userEntity.setId("@userId");
  1719. String userName = "当前用户" ;
  1720. extracted(userEntity, orgIdNameMaps, list, userName);
  1721. }
  1722. }
  1723. }
  1724. });
  1725. }
  1726. return list;
  1727. }
  1728. private void extracted(UserEntity userEntity, Map<String, String> orgIdNameMaps, List<BaseInfoVo> list, String userName) {
  1729. BaseInfoVo vo = JsonUtil.getJsonToBean(userEntity, BaseInfoVo.class);
  1730. List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(userEntity.getId(), PermissionConst.ORGANIZE);
  1731. StringJoiner orgName = new StringJoiner(",");
  1732. listByObjectType.forEach(userRelationEntity -> {
  1733. OrganizeEntity info = organizeService.getInfo(userRelationEntity.getObjectId());
  1734. if (info != null) {
  1735. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/");
  1736. orgName.add(fullNameByOrgIdTree);
  1737. }
  1738. });
  1739. vo.setOrganize(orgName.toString());
  1740. vo.setType("user");
  1741. vo.setHeadIcon(UploaderUtil.uploaderImg(vo.getHeadIcon()));
  1742. vo.setFullName(vo.getRealName() + "/" + vo.getAccount());
  1743. vo.setOrgNameTree(userName);
  1744. list.add(vo);
  1745. }
  1746. @Override
  1747. public Boolean delCurRoleUser(String message, List<String> objectIdAll) {
  1748. List<PermissionGroupEntity> list = permissionGroupService.list(objectIdAll).stream().filter(t -> Objects.equals(t.getEnabledMark(), 1)).collect(Collectors.toList());
  1749. List<String> member = list.stream().filter(t -> StringUtil.isNotEmpty(t.getPermissionMember())).map(PermissionGroupEntity::getPermissionMember).collect(Collectors.toList());
  1750. List<String> userIdList = new ArrayList<>();
  1751. if (list.stream().filter(t -> Objects.equals(t.getType(), 0)).count() > 0) {
  1752. userIdList.addAll(getUserMap().keySet());
  1753. } else {
  1754. // 判断角色下面的人
  1755. userIdList.addAll(this.getUserIdList(member));
  1756. }
  1757. delCurUser(message, userIdList);
  1758. return true;
  1759. }
  1760. @Override
  1761. public List<UserEntity> getList(List<String> orgIdList, String keyword) {
  1762. // 得到用户关系表
  1763. List<UserRelationEntity> listByObjectId = userRelationService.getListByOrgId(orgIdList);
  1764. if (listByObjectId.isEmpty()) {
  1765. return new ArrayList<>();
  1766. }
  1767. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  1768. queryWrapper.lambda().in(UserEntity::getId, listByObjectId.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList())).and(
  1769. t -> t.like(UserEntity::getRealName, keyword)
  1770. .or().like(UserEntity::getAccount, keyword)
  1771. );
  1772. return this.list(queryWrapper);
  1773. }
  1774. @Override
  1775. public List<UserEntity> getListBySyn(List<String> orgIdList, String keyword) {
  1776. // 得到用户关系表
  1777. List<UserRelationEntity> listByObjectId = userRelationService.getListByOrgId(orgIdList);
  1778. //根据userId分类
  1779. Map<String, List<UserRelationEntity>> collect = listByObjectId.stream().collect(Collectors.groupingBy(UserRelationEntity::getUserId));
  1780. if (listByObjectId.isEmpty()) {
  1781. return new ArrayList<>();
  1782. }
  1783. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  1784. queryWrapper.lambda().in(UserEntity::getId, listByObjectId.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList())).and(
  1785. t -> t.like(UserEntity::getRealName, keyword)
  1786. .or().like(UserEntity::getAccount, keyword)
  1787. );
  1788. List<UserEntity> list = this.list(queryWrapper);
  1789. ArrayList<UserEntity> userEntities = new ArrayList<>();
  1790. for (UserEntity userEntity : list) {
  1791. List<UserRelationEntity> userRelationEntities = collect.get(userEntity.getId());
  1792. for (UserRelationEntity userRelationEntity : userRelationEntities) {
  1793. UserEntity entity = BeanUtil.copyProperties(userEntity, UserEntity.class);
  1794. entity.setOrganizeId(userRelationEntity.getObjectId());
  1795. userEntities.add(entity);
  1796. }
  1797. }
  1798. return userEntities;
  1799. }
  1800. @Override
  1801. public List<String> getUserIdList(List<String> idList) {
  1802. Set<String> userIds = new LinkedHashSet<>();
  1803. idList.forEach(selectedId -> {
  1804. if (StringUtil.isNotEmpty(selectedId)) {
  1805. if (selectedId.equals("@userId")) {
  1806. userIds.add(UserProvider.getUser().getUserId());
  1807. return;
  1808. }
  1809. String[] split = selectedId.split("--");
  1810. if (Arrays.stream(split).count() == 1) {
  1811. UserEntity info = userService.getInfo(selectedId);
  1812. if (BeanUtil.isNotEmpty(info)) {
  1813. userIds.add(info.getId());
  1814. }
  1815. return;
  1816. }
  1817. if (selectedId.substring(selectedId.length() - 3).equalsIgnoreCase(SysParamEnum.ORG.getCode())) {
  1818. ArrayList<String> strings = new ArrayList<>();
  1819. if (selectedId.contains(SysParamEnum.SUBORG.getCode())) {
  1820. List<OrganizeEntity> listByParentId = organizeService.getListByParentId(split[0]);
  1821. if (listByParentId != null) {
  1822. strings.addAll(listByParentId.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  1823. }
  1824. }
  1825. if (selectedId.contains(SysParamEnum.PROGENYORG.getCode())) {
  1826. List<OrganizeEntity> grandSonList = organizeService.getAllChild(split[0]);
  1827. if (grandSonList != null) {
  1828. strings.addAll(grandSonList.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  1829. }
  1830. }
  1831. strings.add(split[0]);
  1832. List<PositionEntity> listByOrgIds = positionService.getListByOrgIds(strings.stream()
  1833. .filter(Objects::nonNull).collect(Collectors.toList()));
  1834. List<String> positionIds = listByOrgIds.stream().map(PositionEntity::getId).collect(Collectors.toList());
  1835. List<UserRelationEntity> listByObjectIdAll = userRelationService.getListByObjectIdAll(positionIds);
  1836. userIds.addAll(listByObjectIdAll.stream().map(UserRelationEntity::getUserId).collect(Collectors.toList()));
  1837. } else if (selectedId.substring(selectedId.length() - 3).equalsIgnoreCase(SysParamEnum.POS.getCode())) {
  1838. ArrayList<String> strings = new ArrayList<>();
  1839. strings.add(split[0]);
  1840. PositionEntity info = positionService.getInfo(split[0]);
  1841. if (info != null && selectedId.contains(SysParamEnum.SUBPOS.getCode())) {
  1842. List<PositionEntity> byParentId = positionService.getByParentId(info.getId());
  1843. if (null != byParentId && !byParentId.isEmpty()) {
  1844. strings.addAll(byParentId.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1845. }
  1846. }
  1847. if (info != null && selectedId.contains(SysParamEnum.PROGENYPOS.getCode())) {
  1848. List<PositionEntity> grandSonList = positionService.getAllChild(info.getId());
  1849. if (null != grandSonList) {
  1850. strings.addAll(grandSonList.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1851. }
  1852. }
  1853. List<String> collect = userRelationService.getListByObjectIdAll(strings)
  1854. .stream()
  1855. .map(UserRelationEntity::getUserId)
  1856. .collect(Collectors.toList());
  1857. userIds.addAll(collect);
  1858. } else if (selectedId.contains(SysParamEnum.GROUP.getCode())) {
  1859. List<String> collect = userRelationService.getListByObjectId(split[0])
  1860. .stream()
  1861. .map(UserRelationEntity::getUserId)
  1862. .collect(Collectors.toList());
  1863. userIds.addAll(collect);
  1864. } else if (selectedId.contains(SysParamEnum.ROLE.getCode())) {
  1865. List<String> collect = roleRelationService.getListByRoleId(split[0], PermissionConst.USER)
  1866. .stream()
  1867. .map(RoleRelationEntity::getObjectId)
  1868. .collect(Collectors.toList());
  1869. userIds.addAll(collect);
  1870. } else if (selectedId.contains(SysParamEnum.USER.getCode())) {
  1871. UserEntity info = userService.getInfo(split[0]);
  1872. if (BeanUtil.isNotEmpty(info)) {
  1873. userIds.add(info.getId());
  1874. }
  1875. }
  1876. }
  1877. });
  1878. return new ArrayList<>(userIds);
  1879. }
  1880. @Override
  1881. public List<BaseInfoVo> getObjList(List<String> userIds, PaginationUser pagination) {
  1882. // 得到所有的用户id关系
  1883. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1884. List<UserEntity> userEntityList = getUserIdListByOrganize(userIds, pagination);
  1885. if (userEntityList.isEmpty()) {
  1886. return Collections.emptyList();
  1887. }
  1888. List<UserIdListVo> jsonToList = JsonUtil.getJsonToList(userEntityList, UserIdListVo.class);
  1889. jsonToList.forEach(userIdListVo -> {
  1890. List<UserRelationEntity> listByObjectType = userRelationService.getListByObjectType(userIdListVo.getId(), PermissionConst.ORGANIZE);
  1891. StringJoiner orgName = new StringJoiner(",");
  1892. listByObjectType.forEach(userRelationEntity -> {
  1893. OrganizeEntity info = organizeService.getInfo(userRelationEntity.getObjectId());
  1894. if (info != null) {
  1895. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, info.getOrganizeIdTree(), "/");
  1896. orgName.add(fullNameByOrgIdTree);
  1897. }
  1898. });
  1899. userIdListVo.setOrganize(orgName.toString());
  1900. userIdListVo.setType(SysParamEnum.USER.getCode());
  1901. userIdListVo.setFullName(userIdListVo.getRealName() + "/" + userIdListVo.getAccount());
  1902. userIdListVo.setHeadIcon(UploaderUtil.uploaderImg(userIdListVo.getHeadIcon()));
  1903. });
  1904. return JsonUtil.getJsonToList(jsonToList, BaseInfoVo.class);
  1905. }
  1906. private List<UserEntity> getUserIdListByOrganize(List<String> userIds, PaginationUser pagination) {
  1907. List<String> userObjectIds = getUserIdList(userIds);
  1908. if (userObjectIds.isEmpty()) {
  1909. return Collections.emptyList();
  1910. }
  1911. LambdaQueryWrapper<UserEntity> wrapper = new LambdaQueryWrapper<>();
  1912. wrapper.ne(UserEntity::getAccount, ADMIN_KEY);
  1913. wrapper.ne(UserEntity::getEnabledMark, 0);
  1914. //idList范围过滤
  1915. if (userObjectIds.size() > 1000) {
  1916. List<List<String>> lists = Lists.partition(userObjectIds, 1000);
  1917. wrapper.and(t -> {
  1918. for (List<String> item : lists) {
  1919. t.in(UserEntity::getId, item).or();
  1920. }
  1921. });
  1922. } else {
  1923. wrapper.in(UserEntity::getId, userObjectIds);
  1924. }
  1925. //关键字
  1926. if (StringUtil.isNotEmpty(pagination.getKeyword())) {
  1927. wrapper.and(
  1928. t -> t.like(UserEntity::getRealName, pagination.getKeyword())
  1929. .or().like(UserEntity::getAccount, pagination.getKeyword())
  1930. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  1931. );
  1932. }
  1933. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  1934. IPage<UserEntity> iPage = userService.page(page, wrapper);
  1935. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  1936. }
  1937. @Override
  1938. public List<UserByRoleVO> getListByAuthorize(String organizeId, jnpf.base.Page page) {
  1939. List<UserByRoleVO> jsonToList = new ArrayList<>(16);
  1940. List<String> collect0 = organizeAdministratorService.getListByAuthorize().stream().map(OrganizeEntity::getId).collect(Collectors.toList());
  1941. // 有权限的组织
  1942. Map<String, OrganizeEntity> orgMaps = organizeService.getOrganizeName(collect0, null, true, null);
  1943. Map<String, String> orgIdNameMaps = organizeService.getInfoList();
  1944. List<DictionaryDataEntity> dataServiceList4 = dictionaryDataService.getListByTypeDataCode("sex");
  1945. Map<String, String> dataServiceMap4 = dataServiceList4.stream().filter(t -> ObjectUtil.equal(t.getEnabledMark(), 1)).collect(Collectors.toMap(DictionaryDataEntity::getEnCode, DictionaryDataEntity::getFullName));
  1946. //判断是否搜索关键字
  1947. if (StringUtil.isNotEmpty(page.getKeyword())) {
  1948. //通过关键字查询
  1949. List<UserEntity> list = getList(new ArrayList<>(orgMaps.keySet()), page.getKeyword());
  1950. //遍历用户给要返回的值插入值
  1951. for (UserEntity entity : list) {
  1952. UserByRoleVO vo = new UserByRoleVO();
  1953. vo.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
  1954. vo.setId(entity.getId());
  1955. vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
  1956. vo.setEnabledMark(entity.getEnabledMark());
  1957. vo.setIsLeaf(true);
  1958. vo.setHasChildren(false);
  1959. vo.setIcon(PermissionConst.USER_ICON);
  1960. vo.setType("user");
  1961. vo.setGender(dataServiceMap4.get(entity.getGender()));
  1962. List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
  1963. StringBuilder stringBuilder = new StringBuilder();
  1964. listByUserId.forEach(t -> {
  1965. OrganizeEntity organizeEntity = orgMaps.get(t.getObjectId());
  1966. if (organizeEntity != null) {
  1967. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity.getOrganizeIdTree(), "/");
  1968. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  1969. stringBuilder.append("," + fullNameByOrgIdTree);
  1970. }
  1971. }
  1972. });
  1973. if (stringBuilder.length() > 0) {
  1974. vo.setOrganize(stringBuilder.toString().replaceFirst(",", ""));
  1975. }
  1976. jsonToList.add(vo);
  1977. }
  1978. return jsonToList;
  1979. }
  1980. //获取所有组织
  1981. List<OrganizeEntity> collect = new ArrayList<>(orgMaps.values());
  1982. //判断时候传入组织id
  1983. //如果传入组织id,则取出对应的子集
  1984. if (!"0".equals(organizeId)) {
  1985. //通过组织查询部门及人员
  1986. OrganizeEntity organizeEntity = orgMaps.get(organizeId);
  1987. if (organizeEntity != null) {
  1988. // 取出子组织
  1989. List<OrganizeEntity> collect1 = collect.stream().filter(t -> !t.getId().equals(organizeEntity.getId()) && t.getOrganizeIdTree().contains(organizeEntity.getId())).collect(Collectors.toList());
  1990. // 判断组织关系中是否有子部门id
  1991. List<OrganizeEntity> organizeEntities = new ArrayList<>();
  1992. for (OrganizeEntity entity : collect1) {
  1993. OrganizeEntity organizeEntity1 = orgMaps.get(entity.getId());
  1994. if (organizeEntity1 != null) {
  1995. organizeEntities.add(organizeEntity1);
  1996. }
  1997. }
  1998. // 得到子集的子集
  1999. List<OrganizeEntity> collect2 = collect.stream().filter(t -> t.getOrganizeIdTree().contains(organizeId)).collect(Collectors.toList());
  2000. // 移除掉上级不是同一个的
  2001. List<OrganizeEntity> collect3 = new ArrayList<>();
  2002. collect2.forEach(t -> {
  2003. organizeEntities.forEach(oe -> {
  2004. if (!oe.getId().equals(t.getId()) && t.getOrganizeIdTree().contains(oe.getId())) {
  2005. collect3.add(t);
  2006. }
  2007. });
  2008. });
  2009. organizeEntities.removeAll(collect3);
  2010. //取出组织下的人员
  2011. List<UserEntity> entityList = getListByOrganizeId(organizeId, null);
  2012. for (UserEntity entity : entityList) {
  2013. UserByRoleVO vo = new UserByRoleVO();
  2014. vo.setId(entity.getId());
  2015. vo.setHeadIcon(UploaderUtil.uploaderImg(entity.getHeadIcon()));
  2016. vo.setFullName(entity.getRealName() + "/" + entity.getAccount());
  2017. vo.setEnabledMark(entity.getEnabledMark());
  2018. vo.setIsLeaf(true);
  2019. vo.setHasChildren(false);
  2020. vo.setIcon(PermissionConst.USER_ICON);
  2021. vo.setType("user");
  2022. vo.setGender(dataServiceMap4.get(entity.getGender()));
  2023. List<UserRelationEntity> listByUserId = userRelationService.getListByUserId(entity.getId()).stream().filter(t -> t != null && PermissionConst.ORGANIZE.equals(t.getObjectType())).collect(Collectors.toList());
  2024. StringJoiner stringJoiner = new StringJoiner(",");
  2025. listByUserId.forEach(t -> {
  2026. OrganizeEntity organizeEntity1 = orgMaps.get(t.getObjectId());
  2027. if (organizeEntity1 != null) {
  2028. String fullNameByOrgIdTree = organizeService.getFullNameByOrgIdTree(orgIdNameMaps, organizeEntity1.getOrganizeIdTree(), "/");
  2029. if (StringUtil.isNotEmpty(fullNameByOrgIdTree)) {
  2030. stringJoiner.add(fullNameByOrgIdTree);
  2031. }
  2032. }
  2033. });
  2034. vo.setOrganize(stringJoiner.toString());
  2035. jsonToList.add(vo);
  2036. }
  2037. for (OrganizeEntity entitys : organizeEntities) {
  2038. UserByRoleVO vo = new UserByRoleVO();
  2039. vo.setId(entitys.getId());
  2040. vo.setType(entitys.getCategory());
  2041. vo.setFullName(entitys.getFullName());
  2042. if ("department".equals(entitys.getCategory())) {
  2043. vo.setIcon(PermissionConst.DEPARTMENT_ICON);
  2044. } else {
  2045. vo.setIcon(PermissionConst.COMPANY_ICON);
  2046. }
  2047. vo.setHasChildren(true);
  2048. vo.setIsLeaf(false);
  2049. vo.setEnabledMark(entitys.getEnabledMark());
  2050. if (StringUtil.isNotEmpty(entitys.getOrganizeIdTree())) {
  2051. String[] split = entitys.getOrganizeIdTree().split(organizeEntity.getId());
  2052. if (split.length > 1) {
  2053. vo.setFullName(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, split[1], "/"));
  2054. }
  2055. }
  2056. jsonToList.add(vo);
  2057. }
  2058. }
  2059. return jsonToList;
  2060. }
  2061. List<String> list = new ArrayList<>(16);
  2062. for (OrganizeEntity organizeEntity : collect) {
  2063. if (organizeEntity != null && organizeEntity.getEnabledMark() == 1) {
  2064. UserByRoleVO userByRoleVO = new UserByRoleVO();
  2065. userByRoleVO.setId(organizeEntity.getId());
  2066. userByRoleVO.setType(organizeEntity.getCategory());
  2067. if ("department".equals(organizeEntity.getCategory())) {
  2068. userByRoleVO.setIcon(PermissionConst.DEPARTMENT_ICON);
  2069. } else {
  2070. userByRoleVO.setIcon(PermissionConst.COMPANY_ICON);
  2071. }
  2072. userByRoleVO.setHasChildren(true);
  2073. userByRoleVO.setIsLeaf(false);
  2074. userByRoleVO.setEnabledMark(organizeEntity.getEnabledMark());
  2075. // 处理断层
  2076. if (StringUtil.isNotEmpty(organizeEntity.getOrganizeIdTree())) {
  2077. List<String> list1 = new ArrayList<>();
  2078. String[] split = organizeEntity.getOrganizeIdTree().split(",");
  2079. list1 = Arrays.asList(split);
  2080. Collections.reverse(list1);
  2081. for (String orgId : list1) {
  2082. OrganizeEntity organizeEntity1 = orgMaps.get(orgId);
  2083. if (organizeEntity1 != null && !organizeEntity1.getId().equals(organizeEntity.getId())) {
  2084. // 记录id
  2085. list.add(organizeEntity.getId());
  2086. break;
  2087. }
  2088. }
  2089. }
  2090. if (!list.contains(organizeEntity.getId())) {
  2091. jsonToList.add(userByRoleVO);
  2092. }
  2093. }
  2094. }
  2095. jsonToList.forEach(t -> {
  2096. OrganizeEntity entity = orgMaps.get(t.getId());
  2097. if (entity != null) {
  2098. t.setFullName(organizeService.getFullNameByOrgIdTree(orgIdNameMaps, entity.getOrganizeIdTree(), "/"));
  2099. }
  2100. t.setParentId(entity.getParentId());
  2101. });
  2102. return jsonToList;
  2103. }
  2104. private String getColumns(Integer key) {
  2105. Map<Integer, String> map = new HashMap<>();
  2106. map.put(1, "账号");
  2107. map.put(2, "姓名");
  2108. map.put(3, "性别");
  2109. map.put(4, "手机");
  2110. map.put(5, "说明");
  2111. map.put(6, "状态");
  2112. map.put(7, "排序");
  2113. map.put(8, "是否管理员");
  2114. map.put(9, "锁定标志");
  2115. map.put(10, "添加时间");
  2116. map.put(11, "部门");
  2117. return map.get(key);
  2118. }
  2119. /**
  2120. * 判断上级是否直属主管的值是否为我的下属
  2121. *
  2122. * @param id
  2123. * @param managerId
  2124. * @param num
  2125. */
  2126. private boolean recursionSubordinates(String id, String managerId, int num) {
  2127. UserEntity entity = getInfo(managerId);
  2128. num++;
  2129. if (entity != null && entity.getId().equals(id)) {
  2130. return true;
  2131. }
  2132. if (num < 10) {
  2133. if (entity != null) {
  2134. return recursionSubordinates(id, entity.getManagerId(), num);
  2135. }
  2136. return false;
  2137. } else {
  2138. return false;
  2139. }
  2140. }
  2141. /**
  2142. * 查询给定的条件是否有默认当前登录者的默认用户值
  2143. *
  2144. * @param userConditionModel
  2145. * @return
  2146. */
  2147. @Override
  2148. public String getDefaultCurrentValueUserId(UserConditionModel userConditionModel) {
  2149. UserInfo userInfo = UserProvider.getUser();
  2150. int currentFinded = 0;
  2151. if (userConditionModel.getUserIds() != null && !userConditionModel.getUserIds().isEmpty() && userConditionModel.getUserIds().contains(userInfo.getUserId())) {
  2152. currentFinded = 1;
  2153. }
  2154. if (currentFinded == 0 && userConditionModel.getDepartIds() != null && !userConditionModel.getDepartIds().isEmpty()) {
  2155. List<OrganizeEntity> orgList = organizeService.getOrgEntityList(userConditionModel.getDepartIds(), true);
  2156. List<String> orgLIdList = orgList.stream().map(OrganizeEntity::getId).collect(Collectors.toList());
  2157. if (orgLIdList != null && !orgLIdList.isEmpty()) {
  2158. List<String> userIds = userRelationService.getListByObjectIdAll(orgLIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  2159. if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) {
  2160. currentFinded = 1;
  2161. }
  2162. }
  2163. }
  2164. if (currentFinded == 0 && userConditionModel.getRoleIds() != null && !userConditionModel.getRoleIds().isEmpty()) {
  2165. List<RoleEntity> roleList = roleService.getListByIds(userConditionModel.getRoleIds(), null, false);
  2166. List<String> roleIdList = roleList.stream().filter(t -> t.getEnabledMark() == 1).map(RoleEntity::getId).collect(Collectors.toList());
  2167. if (roleIdList != null && !roleIdList.isEmpty()) {
  2168. List<String> userIds = userRelationService.getListByObjectIdAll(roleIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  2169. if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) {
  2170. currentFinded = 1;
  2171. }
  2172. }
  2173. }
  2174. if (currentFinded == 0 && userConditionModel.getPositionIds() != null && !userConditionModel.getPositionIds().isEmpty()) {
  2175. List<PositionEntity> positionList = positionService.getPosList(userConditionModel.getPositionIds());
  2176. List<String> positionIdList = positionList.stream().filter(t -> t.getEnabledMark() == 1).map(PositionEntity::getId).collect(Collectors.toList());
  2177. if (positionIdList != null && !positionIdList.isEmpty()) {
  2178. List<String> userIds = userRelationService.getListByObjectIdAll(positionIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  2179. if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) {
  2180. currentFinded = 1;
  2181. }
  2182. }
  2183. }
  2184. if (currentFinded == 0 && userConditionModel.getGroupIds() != null && !userConditionModel.getGroupIds().isEmpty()) {
  2185. List<GroupEntity> groupList = groupService.getListByIds(userConditionModel.getGroupIds());
  2186. List<String> groupIdList = groupList.stream().map(GroupEntity::getId).collect(Collectors.toList());
  2187. if (groupIdList != null && !groupIdList.isEmpty()) {
  2188. List<String> userIds = userRelationService.getListByObjectIdAll(groupIdList).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  2189. if (userIds != null && !userIds.isEmpty() && userIds.contains(userInfo.getUserId())) {
  2190. currentFinded = 1;
  2191. }
  2192. }
  2193. }
  2194. return (currentFinded == 1) ? userInfo.getUserId() : "" ;
  2195. }
  2196. @Override
  2197. public List<UserEntity> getUserAccount(List<String> ids) {
  2198. List<UserEntity> list = new ArrayList<>();
  2199. if (!ids.isEmpty()) {
  2200. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  2201. queryWrapper.lambda().in(UserEntity::getAccount, ids);
  2202. list = this.list(queryWrapper);
  2203. }
  2204. return list;
  2205. }
  2206. @Override
  2207. public void updateStand(List<String> ids, int standing) {
  2208. List<UserEntity> userName = getUserName(new ArrayList<>(ids), false);
  2209. for (UserEntity user : userName) {
  2210. String positionId = user.getPositionId();
  2211. String organizeId = user.getOrganizeId();
  2212. String id = user.getId();
  2213. UpdateWrapper<UserEntity> wrapper = new UpdateWrapper<>();
  2214. wrapper.lambda().eq(UserEntity::getId, id);
  2215. wrapper.lambda().set(UserEntity::getOrganizeId, organizeId);
  2216. wrapper.lambda().set(UserEntity::getPositionId, positionId);
  2217. update(wrapper);
  2218. }
  2219. if (!ids.isEmpty()) {
  2220. UpdateWrapper<UserEntity> pcWrapper = new UpdateWrapper<>();
  2221. pcWrapper.lambda().in(UserEntity::getId, ids);
  2222. pcWrapper.lambda().eq(UserEntity::getStanding, standing);
  2223. pcWrapper.lambda().set(UserEntity::getStanding, 3);
  2224. update(pcWrapper);
  2225. UpdateWrapper<UserEntity> appWrapper = new UpdateWrapper<>();
  2226. appWrapper.lambda().in(UserEntity::getId, ids);
  2227. appWrapper.lambda().eq(UserEntity::getAppStanding, standing);
  2228. appWrapper.lambda().set(UserEntity::getAppStanding, 3);
  2229. update(appWrapper);
  2230. }
  2231. }
  2232. @Override
  2233. public Boolean delCurUser(String message, List<String> userIds) {
  2234. if (userIds.isEmpty()) {
  2235. return true;
  2236. }
  2237. //用户不强制下线,websokit推送刷新即可
  2238. List<OnlineUserModel> users = new ArrayList<>();
  2239. List<OnlineUserModel> onlineUserList = OnlineUserProvider.getOnlineUserList();
  2240. for (OnlineUserModel onlineUserModel : onlineUserList) {
  2241. String userId = onlineUserModel.getUserId();
  2242. if (userIds.contains(userId)) {
  2243. users.add(onlineUserModel);
  2244. }
  2245. }
  2246. if (!ObjectUtils.isEmpty(users)) {
  2247. for (OnlineUserModel user : users) {
  2248. JSONObject obj = new JSONObject();
  2249. obj.put("method", "refresh");
  2250. obj.put("msg", StringUtil.isEmpty(message) ? MsgCode.PS010.get() : message);
  2251. if (user != null) {
  2252. OnlineUserProvider.sendMessage(user, obj);
  2253. }
  2254. }
  2255. }
  2256. return true;
  2257. }
  2258. @Override
  2259. public void majorStandFreshUser() {
  2260. UserInfo userInfo = UserProvider.getUser();
  2261. List<OnlineUserModel> onlineUserList = OnlineUserProvider.getOnlineUserList();
  2262. for (OnlineUserModel onlineUserModel : onlineUserList) {
  2263. String userId = onlineUserModel.getUserId();
  2264. //当前用户,同平台的其他客户端需要强制刷新
  2265. if (userInfo.getUserId().equals(userId)
  2266. && Objects.equals(!RequestContext.isOrignPc(), onlineUserModel.getIsMobileDevice())) {
  2267. JSONObject obj = new JSONObject();
  2268. obj.put("method", "refresh");
  2269. obj.put("msg", MsgCode.PS010.get());
  2270. OnlineUserProvider.sendMessage(onlineUserModel, obj);
  2271. }
  2272. }
  2273. }
  2274. @Override
  2275. public Boolean logoutUser(String message, List<String> userIds) {
  2276. if (userIds.isEmpty()) {
  2277. return true;
  2278. }
  2279. //用户不强制下线
  2280. List<OnlineUserModel> users = new ArrayList<>();
  2281. List<OnlineUserModel> onlineUserList = OnlineUserProvider.getOnlineUserList();
  2282. for (OnlineUserModel onlineUserModel : onlineUserList) {
  2283. String userId = onlineUserModel.getUserId();
  2284. if (userIds.contains(userId) && !Objects.equals(UserProvider.getUser().getToken(), onlineUserModel.getToken())) {
  2285. users.add(onlineUserModel);
  2286. }
  2287. }
  2288. if (!ObjectUtils.isEmpty(users)) {
  2289. for (OnlineUserModel user : users) {
  2290. JSONObject obj = new JSONObject();
  2291. obj.put("method", "logout");
  2292. obj.put("msg", StringUtil.isEmpty(message) ? MsgCode.PS011.get() : message);
  2293. if (user != null) {
  2294. OnlineUserProvider.sendMessage(user, obj);
  2295. }
  2296. //先移除对象, 并推送下线信息, 避免网络原因导致就用户未断开 新用户连不上WebSocket
  2297. OnlineUserProvider.removeModel(user);
  2298. //通知所有在线,有用户离线
  2299. //功能已删除
  2300. // for (OnlineUserModel item : OnlineUserProvider.getOnlineUserList().stream().filter(t -> !Objects.equals(user.getUserId(), t.getUserId()) && Objects.equals(user.getTenantId(), t.getTenantId())).collect(Collectors.toList())) {
  2301. // if (!item.getUserId().equals(user.getUserId())) {
  2302. // JSONObject objs = new JSONObject();
  2303. // objs.put("method", "Offline");
  2304. // //推送给前端
  2305. // OnlineUserProvider.sendMessage(item, objs);
  2306. // }
  2307. // }
  2308. UserProvider.logoutByToken(user.getToken());
  2309. }
  2310. }
  2311. return true;
  2312. }
  2313. @Override
  2314. public List<UserEntity> getPageByIds(RoleRelationPage pagination) {
  2315. QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
  2316. queryWrapper.lambda().select(UserEntity::getId, UserEntity::getAccount, UserEntity::getRealName, UserEntity::getGender,
  2317. UserEntity::getMobilePhone, UserEntity::getEnabledMark);
  2318. boolean flag = false;
  2319. //关键字(账户、姓名、手机)
  2320. if (!StringUtil.isEmpty(pagination.getKeyword())) {
  2321. flag = true;
  2322. queryWrapper.lambda().and(
  2323. t -> t.like(UserEntity::getAccount, pagination.getKeyword())
  2324. .or().like(UserEntity::getRealName, pagination.getKeyword())
  2325. .or().like(UserEntity::getMobilePhone, pagination.getKeyword())
  2326. );
  2327. }
  2328. List<List<String>> lists = Lists.partition(pagination.getIdList(), 1000);
  2329. queryWrapper.lambda().and(t -> {
  2330. for (List<String> item : lists) {
  2331. t.in(UserEntity::getId, item).or();
  2332. }
  2333. });
  2334. queryWrapper.lambda().orderByAsc(UserEntity::getSortCode).orderByDesc(UserEntity::getCreatorTime);
  2335. if (flag) {
  2336. queryWrapper.lambda().orderByDesc(UserEntity::getLastModifyTime);
  2337. return this.list(queryWrapper);
  2338. }
  2339. Page<UserEntity> page = new Page<>(pagination.getCurrentPage(), pagination.getPageSize());
  2340. IPage<UserEntity> iPage = this.page(page, queryWrapper);
  2341. return pagination.setData(iPage.getRecords(), iPage.getTotal());
  2342. }
  2343. @Override
  2344. public UserRelationIds getUserObjectIdList(String userId) {
  2345. List<UserRelationEntity> listUser = userRelationService.getListByObjectType(userId, null);
  2346. List<String> group = listUser.stream().filter(t -> PermissionConst.GROUP.equals(t.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  2347. List<String> organize = listUser.stream().filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  2348. List<String> position = listUser.stream().filter(t -> PermissionConst.POSITION.equals(t.getObjectType())).map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  2349. List<String> rogAndPos = listUser.stream().filter(t -> PermissionConst.ORGANIZE.equals(t.getObjectType()) || PermissionConst.POSITION.equals(t.getObjectType()))
  2350. .map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  2351. rogAndPos.add(userId);
  2352. List<String> role = roleRelationService.getListByObjectId(rogAndPos, null).stream().map(RoleRelationEntity::getRoleId).collect(Collectors.toList());
  2353. UserRelationIds userRelationIds = UserRelationIds.builder()
  2354. .group(group)
  2355. .organize(organize)
  2356. .position(position)
  2357. .role(role)
  2358. .build();
  2359. return userRelationIds;
  2360. }
  2361. @Override
  2362. public Map<String, String> getSystemFieldValue(SystemParamModel model) {
  2363. Map<String, String> mapList = new HashMap<>();
  2364. List<String> needList = model.getList();
  2365. UserInfo userInfo = UserProvider.getUser();
  2366. String userId = userInfo.getUserId();
  2367. List<String> organizeIds = userInfo.getOrganizeIds();
  2368. List<String> positionIds = userInfo.getPositionIds();
  2369. for (String key : needList) {
  2370. List<String> dataValue = new ArrayList<>();
  2371. String values = "" ;
  2372. switch (key) {
  2373. case DataInterfaceVarConst.CURRENTTIME:
  2374. values = String.valueOf(DateUtil.stringToDate(DateUtil.getNow()).getTime());
  2375. break;
  2376. case DataInterfaceVarConst.USER:
  2377. values = userId;
  2378. break;
  2379. case DataInterfaceVarConst.ORG:
  2380. values = JsonUtil.getObjectToString(organizeIds);
  2381. break;
  2382. case DataInterfaceVarConst.POSITIONID:
  2383. values = JsonUtil.getObjectToString(positionIds);
  2384. break;
  2385. case DataInterfaceVarConst.USERANDSUB:
  2386. dataValue.add(userId);
  2387. if (!positionIds.isEmpty()) {
  2388. dataValue.addAll(userRelationService.getUserAndSub(positionIds, null).stream()
  2389. .map(SuperBaseEntity.SuperIBaseEntity::getId).collect(Collectors.toList()));
  2390. }
  2391. values = JsonUtil.getObjectToString(dataValue);
  2392. break;
  2393. case DataInterfaceVarConst.USERANDPROGENY:
  2394. dataValue.add(userId);
  2395. if (!positionIds.isEmpty()) {
  2396. dataValue.addAll(userRelationService.getUserProgeny(positionIds, null).stream()
  2397. .map(SuperBaseEntity.SuperIBaseEntity::getId).collect(Collectors.toList()));
  2398. }
  2399. values = JsonUtil.getObjectToString(dataValue);
  2400. break;
  2401. case DataInterfaceVarConst.ORGANDSUB:
  2402. if (!organizeIds.isEmpty()) {
  2403. List<OrganizeEntity> listByParentIds = organizeService.getListByParentIds(organizeIds);
  2404. dataValue.addAll(organizeIds);
  2405. dataValue.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  2406. }
  2407. values = JsonUtil.getObjectToString(dataValue);
  2408. break;
  2409. case DataInterfaceVarConst.ORGANIZEANDPROGENY:
  2410. if (!organizeIds.isEmpty()) {
  2411. List<OrganizeEntity> allChild = organizeService.getProgeny(organizeIds, null);
  2412. dataValue.addAll(allChild.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  2413. }
  2414. values = JsonUtil.getObjectToString(dataValue);
  2415. break;
  2416. case DataInterfaceVarConst.POSITIONANDSUB:
  2417. if (!positionIds.isEmpty()) {
  2418. List<PositionEntity> listByParentIds = positionService.getListByParentIds(positionIds);
  2419. dataValue.addAll(positionIds);
  2420. dataValue.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  2421. }
  2422. values = JsonUtil.getObjectToString(dataValue);
  2423. break;
  2424. case DataInterfaceVarConst.POSITIONANDPROGENY:
  2425. if (!positionIds.isEmpty()) {
  2426. List<PositionEntity> allChild = positionService.getProgeny(positionIds, null);
  2427. dataValue.addAll(allChild.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  2428. }
  2429. values = JsonUtil.getObjectToString(dataValue);
  2430. break;
  2431. default:
  2432. break;
  2433. }
  2434. mapList.put(key, values);
  2435. }
  2436. return mapList;
  2437. }
  2438. }