UserInfoService.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.maxkey.persistence.service;
  17. import java.io.IOException;
  18. import java.io.InputStream;
  19. import java.util.ArrayList;
  20. import java.util.Comparator;
  21. import java.util.Date;
  22. import java.util.List;
  23. import java.util.TreeSet;
  24. import java.util.stream.Collectors;
  25. import org.apache.mybatis.jpa.persistence.JpaBaseService;
  26. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  27. import org.apache.poi.ss.usermodel.Cell;
  28. import org.apache.poi.ss.usermodel.CellType;
  29. import org.apache.poi.ss.usermodel.Row;
  30. import org.apache.poi.ss.usermodel.Sheet;
  31. import org.apache.poi.ss.usermodel.Workbook;
  32. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  33. import org.maxkey.constants.ConstantsStatus;
  34. import org.maxkey.crypto.ReciprocalUtils;
  35. import org.maxkey.crypto.password.PasswordReciprocal;
  36. import org.maxkey.entity.ChangePassword;
  37. import org.maxkey.entity.UserInfo;
  38. import org.maxkey.persistence.db.PasswordPolicyValidator;
  39. import org.maxkey.persistence.kafka.KafkaIdentityAction;
  40. import org.maxkey.persistence.kafka.KafkaIdentityTopic;
  41. import org.maxkey.persistence.kafka.KafkaPersistService;
  42. import org.maxkey.persistence.mapper.UserInfoMapper;
  43. import org.maxkey.util.DateUtils;
  44. import org.maxkey.util.StringUtils;
  45. import org.maxkey.web.WebContext;
  46. import org.slf4j.Logger;
  47. import org.slf4j.LoggerFactory;
  48. import org.springframework.beans.factory.annotation.Autowired;
  49. import org.springframework.jdbc.core.JdbcTemplate;
  50. import org.springframework.security.crypto.password.PasswordEncoder;
  51. import org.springframework.stereotype.Repository;
  52. import org.springframework.util.CollectionUtils;
  53. import org.springframework.web.multipart.MultipartFile;
  54. import com.google.common.collect.Lists;
  55. /**
  56. * @author Crystal.Sea
  57. *
  58. */
  59. @Repository
  60. public class UserInfoService extends JpaBaseService<UserInfo> {
  61. final static Logger _logger = LoggerFactory.getLogger(UserInfoService.class);
  62. @Autowired
  63. private PasswordEncoder passwordEncoder;
  64. @Autowired
  65. PasswordPolicyValidator passwordPolicyValidator;
  66. @Autowired
  67. KafkaPersistService kafkaPersistService;
  68. @Autowired
  69. protected JdbcTemplate jdbcTemplate;
  70. public UserInfoService() {
  71. super(UserInfoMapper.class);
  72. }
  73. /* (non-Javadoc)
  74. * @see com.connsec.db.service.BaseService#getMapper()
  75. */
  76. @Override
  77. public UserInfoMapper getMapper() {
  78. return (UserInfoMapper)super.getMapper();
  79. }
  80. public boolean insert(UserInfo userInfo) {
  81. userInfo = passwordEncoder(userInfo);
  82. if (super.insert(userInfo)) {
  83. if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
  84. UserInfo loadUserInfo = loadUserRelated(userInfo.getId());
  85. kafkaPersistService.send(
  86. KafkaIdentityTopic.USERINFO_TOPIC,
  87. loadUserInfo,
  88. KafkaIdentityAction.CREATE_ACTION);
  89. }
  90. return true;
  91. }
  92. return false;
  93. }
  94. public boolean update(UserInfo userInfo) {
  95. userInfo = passwordEncoder(userInfo);
  96. if (super.update(userInfo)) {
  97. if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
  98. UserInfo loadUserInfo = loadUserRelated(userInfo.getId());
  99. kafkaPersistService.send(
  100. KafkaIdentityTopic.USERINFO_TOPIC,
  101. loadUserInfo,
  102. KafkaIdentityAction.UPDATE_ACTION);
  103. }
  104. changePasswordProvisioning(userInfo);
  105. return true;
  106. }
  107. return false;
  108. }
  109. public boolean delete(UserInfo userInfo) {
  110. UserInfo loadUserInfo = null;
  111. if(kafkaPersistService.getApplicationConfig().isKafkaSupport()) {
  112. loadUserInfo = loadUserRelated(userInfo.getId());
  113. }
  114. if( super.delete(userInfo)){
  115. kafkaPersistService.send(
  116. KafkaIdentityTopic.USERINFO_TOPIC,
  117. loadUserInfo,
  118. KafkaIdentityAction.DELETE_ACTION);
  119. return true;
  120. }
  121. return false;
  122. }
  123. public UserInfo loadUserRelated(String userId) {
  124. UserInfo loadUserInfo =this.get(userId);
  125. loadUserInfo.setDepts(getMapper().loadDeptsByUserId(userId));
  126. loadUserInfo.setAdjoints(getMapper().loadAdjointsByUserId(userId));
  127. return loadUserInfo;
  128. }
  129. public boolean updateGridList(String gridList) {
  130. try {
  131. if (gridList != null && !gridList.equals("")) {
  132. WebContext.getUserInfo().setGridList(Integer.parseInt(gridList));
  133. getMapper().updateGridList(WebContext.getUserInfo());
  134. }
  135. }catch(Exception e) {
  136. e.printStackTrace();
  137. return false;
  138. }
  139. return true;
  140. }
  141. public boolean updateProtectedApps(UserInfo userinfo) {
  142. try {
  143. if(WebContext.getUserInfo() != null) {
  144. userinfo.setModifiedBy(WebContext.getUserInfo().getId());
  145. }
  146. userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
  147. return getMapper().updateProtectedApps(userinfo) > 0;
  148. } catch (Exception e) {
  149. e.printStackTrace();
  150. }
  151. return false;
  152. }
  153. public UserInfo loadByUsername(String username) {
  154. return getMapper().loadByUsername(username);
  155. }
  156. public UserInfo loadByAppIdAndUsername(String appId,String username){
  157. try {
  158. UserInfo userinfo = new UserInfo();
  159. userinfo.setUsername(username);
  160. return getMapper().loadByAppIdAndUsername(userinfo) ;
  161. } catch (Exception e) {
  162. e.printStackTrace();
  163. }
  164. return null;
  165. }
  166. public void logisticDeleteAllByCid(String cid){
  167. try {
  168. getMapper().logisticDeleteAllByCid(cid);
  169. } catch(Exception e) {
  170. e.printStackTrace();
  171. }
  172. }
  173. public UserInfo passwordEncoder(UserInfo userInfo) {
  174. //密码不为空,则需要进行加密处理
  175. if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
  176. String password = passwordEncoder.encode(userInfo.getPassword());
  177. userInfo.setDecipherable(ReciprocalUtils.encode(PasswordReciprocal.getInstance().rawPassword(userInfo.getUsername(), userInfo.getPassword())));
  178. _logger.debug("decipherable : "+userInfo.getDecipherable());
  179. userInfo.setPassword(password);
  180. userInfo.setPasswordLastSetTime(DateUtils.getCurrentDateTimeAsString());
  181. userInfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
  182. }
  183. return userInfo;
  184. }
  185. public boolean changePassword(String oldPassword,
  186. String newPassword,
  187. String confirmPassword) {
  188. try {
  189. WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT, "");
  190. UserInfo userInfo = WebContext.getUserInfo();
  191. UserInfo changeUserInfo = new UserInfo();
  192. changeUserInfo.setUsername(userInfo.getUsername());
  193. changeUserInfo.setPassword(newPassword);
  194. changeUserInfo.setId(userInfo.getId());
  195. changeUserInfo.setDecipherable(userInfo.getDecipherable());
  196. if(newPassword.equals(confirmPassword)){
  197. if(oldPassword==null ||
  198. passwordEncoder.matches(oldPassword, userInfo.getPassword())){
  199. if(changePassword(changeUserInfo,true) ){
  200. userInfo.setPassword(changeUserInfo.getPassword());
  201. userInfo.setDecipherable(changeUserInfo.getDecipherable());
  202. return true;
  203. }
  204. return false;
  205. }else {
  206. if(oldPassword!=null &&
  207. passwordEncoder.matches(newPassword, userInfo.getPassword())) {
  208. WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
  209. WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_MATCH"));
  210. }else {
  211. WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
  212. WebContext.getI18nValue("PasswordPolicy.OLD_PASSWORD_NOT_MATCH"));
  213. }
  214. }
  215. }else {
  216. WebContext.setAttribute(PasswordPolicyValidator.PASSWORD_POLICY_VALIDATE_RESULT,
  217. WebContext.getI18nValue("PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH"));
  218. }
  219. } catch (Exception e) {
  220. e.printStackTrace();
  221. }
  222. return false;
  223. }
  224. public boolean changePassword(UserInfo changeUserInfo,boolean passwordPolicy) {
  225. try {
  226. _logger.debug("decipherable old : " + changeUserInfo.getDecipherable());
  227. _logger.debug("decipherable new : " + ReciprocalUtils.encode(PasswordReciprocal.getInstance()
  228. .rawPassword(changeUserInfo.getUsername(), changeUserInfo.getPassword())));
  229. if (passwordPolicy && passwordPolicyValidator.validator(changeUserInfo) == false) {
  230. return false;
  231. }
  232. if (WebContext.getUserInfo() != null) {
  233. changeUserInfo.setModifiedBy(WebContext.getUserInfo().getId());
  234. }
  235. changeUserInfo = passwordEncoder(changeUserInfo);
  236. if (getMapper().changePassword(changeUserInfo) > 0) {
  237. changePasswordProvisioning(changeUserInfo);
  238. return true;
  239. }
  240. return false;
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. }
  244. return false;
  245. }
  246. public String randomPassword() {
  247. return passwordPolicyValidator.generateRandomPassword();
  248. }
  249. public void changePasswordProvisioning(UserInfo userInfo) {
  250. if(userInfo.getPassword()!=null && !userInfo.getPassword().equals("")) {
  251. ChangePassword changePassword=new ChangePassword();
  252. changePassword.setId(userInfo.getId());
  253. changePassword.setUid(userInfo.getId());
  254. changePassword.setUsername(userInfo.getUsername());
  255. changePassword.setDecipherable(userInfo.getDecipherable());
  256. changePassword.setPassword(userInfo.getPassword());
  257. kafkaPersistService.send(
  258. KafkaIdentityTopic.PASSWORD_TOPIC,
  259. changePassword,
  260. KafkaIdentityAction.PASSWORD_ACTION);
  261. }
  262. }
  263. public boolean changeAppLoginPassword(UserInfo userinfo) {
  264. try {
  265. if(WebContext.getUserInfo() != null) {
  266. userinfo.setModifiedBy(WebContext.getUserInfo().getId());
  267. }
  268. userinfo.setModifiedDate(DateUtils.getCurrentDateTimeAsString());
  269. return getMapper().changeAppLoginPassword(userinfo) > 0;
  270. } catch (Exception e) {
  271. e.printStackTrace();
  272. }
  273. return false;
  274. }
  275. /**
  276. * 锁定用户:islock:1 用户解锁 2 用户锁定
  277. * @param userInfo
  278. */
  279. public void locked(UserInfo userInfo) {
  280. try {
  281. if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
  282. userInfo.setIsLocked(ConstantsStatus.STOP);
  283. getMapper().locked(userInfo);
  284. }
  285. } catch(Exception e) {
  286. e.printStackTrace();
  287. }
  288. }
  289. /**
  290. * 用户登录成功后,重置错误密码次数和解锁用户
  291. * @param userInfo
  292. */
  293. public void unlock(UserInfo userInfo) {
  294. try {
  295. if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
  296. userInfo.setIsLocked(ConstantsStatus.START);
  297. userInfo.setBadPasswordCount(0);
  298. getMapper().unlock(userInfo);
  299. }
  300. } catch(Exception e) {
  301. e.printStackTrace();
  302. }
  303. }
  304. /**
  305. * 更新错误密码次数
  306. * @param userInfo
  307. */
  308. public void updateBadPasswordCount(UserInfo userInfo) {
  309. try {
  310. if(userInfo != null && StringUtils.isNotEmpty(userInfo.getId())) {
  311. int updateBadPWDCount = userInfo.getBadPasswordCount() + 1;
  312. userInfo.setBadPasswordCount(updateBadPWDCount);
  313. getMapper().updateBadPWDCount(userInfo);
  314. }
  315. } catch(Exception e) {
  316. e.printStackTrace();
  317. }
  318. }
  319. public boolean importing(MultipartFile file) {
  320. if(file ==null){
  321. return false;
  322. }
  323. InputStream is = null;
  324. Workbook wb = null;
  325. List<UserInfo> userInfoList = null;
  326. try {
  327. is = file.getInputStream();
  328. String xls = ".xls";
  329. String xlsx = ".xlsx";
  330. int columnSize = 46;
  331. userInfoList = Lists.newArrayList();
  332. if (file.getOriginalFilename().toLowerCase().endsWith(xls)) {
  333. wb = new HSSFWorkbook(is);
  334. } else if (file.getOriginalFilename().toLowerCase().endsWith(xlsx)) {
  335. wb = new XSSFWorkbook(is);
  336. } else {
  337. throw new RuntimeException("maxKey用户导入没有Excel类型");
  338. }
  339. int sheetSize = wb.getNumberOfSheets();
  340. //遍历sheet页
  341. for (int i = 0; i < sheetSize; i++) {
  342. Sheet sheet = wb.getSheetAt(i);
  343. int rowSize = sheet.getLastRowNum() + 1;
  344. //遍历行
  345. for (int j = 1; j < rowSize; j++) {
  346. Row row = sheet.getRow(j);
  347. //略过空行和前3行
  348. if (row == null || j <3 ) {
  349. continue;
  350. } else {
  351. //其他行是数据行
  352. UserInfo userInfo = new UserInfo();
  353. userInfo.setCreatedDate(DateUtils.formatDateTime(new Date()));
  354. for (int k = 0; k < columnSize; k++) {
  355. if (k == 0) {
  356. // 登录账号
  357. Cell cell = row.getCell(k);
  358. userInfo.setUsername(getValue(cell));
  359. } else if (k == 1) {
  360. // 密码
  361. Cell cell = row.getCell(k);
  362. userInfo.setPassword(getValue(cell));
  363. } else if (k == 2) {
  364. // 用户显示
  365. Cell cell = row.getCell(k);
  366. userInfo.setDisplayName(getValue(cell));
  367. } else if (k == 3) {
  368. // 姓
  369. Cell cell = row.getCell(k);
  370. userInfo.setFamilyName(getValue(cell));
  371. } else if (k == 4) {
  372. // 名
  373. Cell cell = row.getCell(k);
  374. userInfo.setGivenName(getValue(cell));
  375. } else if (k == 5) {
  376. // 中间名
  377. Cell cell = row.getCell(k);
  378. userInfo.setMiddleName(getValue(cell));
  379. } else if (k == 6) {
  380. // 昵称
  381. Cell cell = row.getCell(k);
  382. userInfo.setNickName(getValue(cell));
  383. } else if (k == 7) {
  384. // 性别
  385. Cell cell = row.getCell(k);
  386. String gender = getValue(cell);
  387. userInfo.setGender(gender.equals("")? 1 : Integer.valueOf(getValue(cell)));
  388. } else if (k == 8) {
  389. // 语言偏好
  390. Cell cell = row.getCell(k);
  391. userInfo.setPreferredLanguage(getValue(cell));
  392. } else if (k == 9) {
  393. // 时区
  394. Cell cell = row.getCell(k);
  395. userInfo.setTimeZone(getValue(cell));
  396. } else if (k == 10) {
  397. // 用户类型
  398. Cell cell = row.getCell(k);
  399. userInfo.setUserType(getValue(cell));
  400. } else if (k == 11) {
  401. // 员工编码
  402. Cell cell = row.getCell(k);
  403. userInfo.setEmployeeNumber(getValue(cell));
  404. } else if (k == 12) {
  405. // AD域账号
  406. Cell cell = row.getCell(k);
  407. userInfo.setWindowsAccount(getValue(cell));
  408. }else if (k == 13) {
  409. // 所属机构
  410. Cell cell = row.getCell(k);
  411. userInfo.setOrganization(getValue(cell));
  412. }else if (k == 14) {
  413. // 分支机构
  414. Cell cell = row.getCell(k);
  415. userInfo.setDivision(getValue(cell));
  416. }else if (k == 15) {
  417. // 部门编号
  418. Cell cell = row.getCell(k);
  419. userInfo.setDepartmentId(getValue(cell));
  420. }else if (k == 16) {
  421. // 部门名称
  422. Cell cell = row.getCell(k);
  423. userInfo.setDepartment(getValue(cell));
  424. }else if (k == 17) {
  425. // 成本中心
  426. Cell cell = row.getCell(k);
  427. userInfo.setCostCenter(getValue(cell));
  428. }else if (k == 18) {
  429. // 职位
  430. Cell cell = row.getCell(k);
  431. userInfo.setJobTitle(getValue(cell));
  432. }else if (k == 19) {
  433. // 级别
  434. Cell cell = row.getCell(k);
  435. userInfo.setJobLevel(getValue(cell));
  436. }else if (k == 20) {
  437. // 上级经理
  438. Cell cell = row.getCell(k);
  439. userInfo.setManager(getValue(cell));
  440. }else if (k == 21) {
  441. // 助理
  442. Cell cell = row.getCell(k);
  443. userInfo.setAssistant(getValue(cell));
  444. }else if (k == 22) {
  445. // 入职时间
  446. Cell cell = row.getCell(k);
  447. userInfo.setEntryDate(getValue(cell));
  448. }else if (k == 23) {
  449. // 离职时间
  450. Cell cell = row.getCell(k);
  451. userInfo.setQuitDate(getValue(cell));
  452. }else if (k == 24) {
  453. // 工作-国家
  454. Cell cell = row.getCell(k);
  455. userInfo.setWorkCountry(getValue(cell));
  456. }else if (k == 25) {
  457. // 工作-省
  458. Cell cell = row.getCell(k);
  459. userInfo.setWorkRegion(getValue(cell));
  460. }else if (k == 26) {
  461. // 工作-城市
  462. Cell cell = row.getCell(k);
  463. userInfo.setTimeZone(getValue(cell));
  464. }else if (k == 27) {
  465. // 工作-地址
  466. Cell cell = row.getCell(k);
  467. userInfo.setWorkLocality(getValue(cell));
  468. }else if (k == 28) {
  469. // 邮编
  470. Cell cell = row.getCell(k);
  471. userInfo.setWorkPostalCode(getValue(cell));
  472. }else if (k == 29) {
  473. // 传真
  474. Cell cell = row.getCell(k);
  475. userInfo.setWorkFax(getValue(cell));
  476. }else if (k == 30) {
  477. // 工作电话
  478. Cell cell = row.getCell(k);
  479. userInfo.setWorkPhoneNumber(getValue(cell));
  480. }else if (k == 31) {
  481. // 工作邮件
  482. Cell cell = row.getCell(k);
  483. userInfo.setWorkEmail(getValue(cell));
  484. }else if (k == 32) {
  485. // 证件类型 todo 现在数据库中存储的是tinyint
  486. // Cell cell = row.getCell(k);
  487. // userInfo.setIdType(getValue(cell));
  488. }else if (k == 33) {
  489. // 证件号码
  490. Cell cell = row.getCell(k);
  491. userInfo.setIdCardNo(getValue(cell));
  492. } else if (k == 34) {
  493. // 出生日期
  494. Cell cell = row.getCell(k);
  495. userInfo.setBirthDate(getValue(cell));
  496. }else if (k == 35) {
  497. // 婚姻状态 todo 现在数据字段类型是 tinyint
  498. // Cell cell = row.getCell(k);
  499. // userInfo.setMarried(getValue(cell));
  500. }else if (k == 36) {
  501. // 开始工作时间
  502. Cell cell = row.getCell(k);
  503. userInfo.setStartWorkDate(getValue(cell));
  504. }else if (k == 37) {
  505. // 个人主页
  506. Cell cell = row.getCell(k);
  507. userInfo.setWebSite(getValue(cell));
  508. }else if (k == 38) {
  509. // 即时通讯
  510. Cell cell = row.getCell(k);
  511. userInfo.setDefineIm(getValue(cell));
  512. }else if (k == 39) {
  513. // 国家
  514. Cell cell = row.getCell(k);
  515. userInfo.setHomeCountry(getValue(cell));
  516. }else if (k == 40) {
  517. // 省
  518. Cell cell = row.getCell(k);
  519. userInfo.setHomeRegion(getValue(cell));
  520. }else if (k == 41) {
  521. // 城市
  522. Cell cell = row.getCell(k);
  523. userInfo.setHomeLocality(getValue(cell));
  524. }else if (k == 42) {
  525. // 家庭地址
  526. Cell cell = row.getCell(k);
  527. userInfo.setHomeStreetAddress(getValue(cell));
  528. }else if (k == 43) {
  529. // 家庭邮编
  530. Cell cell = row.getCell(k);
  531. userInfo.setHomePostalCode(getValue(cell));
  532. }else if (k == 44) {
  533. // 家庭传真
  534. Cell cell = row.getCell(k);
  535. userInfo.setHomeFax(getValue(cell));
  536. }else if (k == 45) {
  537. // 家庭电话
  538. Cell cell = row.getCell(k);
  539. userInfo.setHomePhoneNumber(getValue(cell));
  540. }else if (k == 46) {
  541. // 家庭邮箱
  542. Cell cell = row.getCell(k);
  543. userInfo.setHomeEmail(getValue(cell));
  544. }
  545. }
  546. userInfo.setStatus(1);
  547. userInfoList.add(passwordEncoder(userInfo));
  548. }
  549. }
  550. }
  551. // 数据去重
  552. if(CollectionUtils.isEmpty(userInfoList)){
  553. userInfoList = userInfoList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getUsername()))), ArrayList::new));
  554. }
  555. } catch (IOException e) {
  556. e.printStackTrace();
  557. }finally {
  558. if (is != null) {
  559. try {
  560. is.close();
  561. } catch (IOException e) {
  562. e.printStackTrace();
  563. }
  564. }
  565. if(wb != null) {
  566. try {
  567. wb.close();
  568. } catch (IOException e) {
  569. e.printStackTrace();
  570. }
  571. }
  572. }
  573. return batchInsert(userInfoList);
  574. }
  575. /**
  576. * 根据数据格式返回数据
  577. *
  578. * @param cell
  579. * @return
  580. */
  581. public static String getValue(Cell cell) {
  582. if (cell == null) {
  583. return "";
  584. } else if (cell.getCellType() == CellType.BOOLEAN) {
  585. return String.valueOf(cell.getBooleanCellValue());
  586. } else if (cell.getCellType() == CellType.NUMERIC) {
  587. cell.setBlank();
  588. return String.valueOf(cell.getStringCellValue().trim());
  589. } else {
  590. return String.valueOf(cell.getStringCellValue().trim());
  591. }
  592. }
  593. public boolean changeSharedSecret(UserInfo userInfo){
  594. return getMapper().changeSharedSecret(userInfo)>0;
  595. }
  596. public boolean changePasswordQuestion(UserInfo userInfo){
  597. return getMapper().changePasswordQuestion(userInfo)>0;
  598. }
  599. public boolean changeAuthnType(UserInfo userInfo){
  600. return getMapper().changeAuthnType(userInfo)>0;
  601. }
  602. public boolean changeEmail(UserInfo userInfo){
  603. return getMapper().changeEmail(userInfo)>0;
  604. }
  605. public boolean changeMobile(UserInfo userInfo){
  606. return getMapper().changeMobile(userInfo)>0;
  607. }
  608. public UserInfo queryUserInfoByEmailMobile(String emailMobile) {
  609. return getMapper().queryUserInfoByEmailMobile(emailMobile);
  610. }
  611. public int updateProfile(UserInfo userInfo){
  612. return getMapper().updateProfile(userInfo);
  613. }
  614. public void setPasswordPolicyValidator(PasswordPolicyValidator passwordPolicyValidator) {
  615. this.passwordPolicyValidator = passwordPolicyValidator;
  616. }
  617. }