Commit aeb4dbcb7085f1c1254b356aef5fe12209138935
1 parent
e2fd7aca
1.
Showing
5 changed files
with
206 additions
and
145 deletions
src/main/java/com/bsth/controller/UserController.java
| 1 | -package com.bsth.controller; | ||
| 2 | - | ||
| 3 | -import com.bsth.service.UserService; | ||
| 4 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | -import org.springframework.web.bind.annotation.RestController; | ||
| 7 | - | ||
| 8 | -/** | ||
| 9 | - * Created by panzhao on 2017/9/4. | ||
| 10 | - */ | ||
| 11 | -@RestController | ||
| 12 | -@RequestMapping("/user") | ||
| 13 | -public class UserController { | ||
| 14 | - | ||
| 15 | - @Autowired | ||
| 16 | - UserService userService; | ||
| 17 | - | ||
| 18 | - @RequestMapping("load_db_data") | ||
| 19 | - private void loadDbData(){ | ||
| 20 | - userService.loadData(); | ||
| 21 | - } | ||
| 22 | -} | 1 | +package com.bsth.controller; |
| 2 | + | ||
| 3 | +import com.bsth.service.UserService; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RestController; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * Created by panzhao on 2017/9/4. | ||
| 10 | + */ | ||
| 11 | +@RestController | ||
| 12 | +@RequestMapping("/user") | ||
| 13 | +public class UserController { | ||
| 14 | + | ||
| 15 | + @Autowired | ||
| 16 | + UserService userService; | ||
| 17 | + | ||
| 18 | + @RequestMapping("load_db_data") | ||
| 19 | + public void loadDbData(){ | ||
| 20 | + userService.loadData(); | ||
| 21 | + } | ||
| 22 | +} |
src/main/java/com/bsth/server_rs/base_info/line/buffer/LineBufferData.java
| 1 | -package com.bsth.server_rs.base_info.line.buffer; | ||
| 2 | - | ||
| 3 | -import com.bsth.Application; | ||
| 4 | -import com.bsth.server_rs.base_info.line.Line; | ||
| 5 | -import com.google.common.collect.ArrayListMultimap; | ||
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | -import org.springframework.boot.CommandLineRunner; | ||
| 8 | -import org.springframework.core.annotation.Order; | ||
| 9 | -import org.springframework.stereotype.Component; | ||
| 10 | - | ||
| 11 | -import java.util.ArrayList; | ||
| 12 | -import java.util.HashMap; | ||
| 13 | -import java.util.List; | ||
| 14 | -import java.util.Map; | ||
| 15 | -import java.util.concurrent.TimeUnit; | ||
| 16 | - | ||
| 17 | -/** | ||
| 18 | - * 线路数据缓存(自更新) | ||
| 19 | - * Created by panzhao on 2017/3/27. | ||
| 20 | - */ | ||
| 21 | -@Component | ||
| 22 | -@Order(5) | ||
| 23 | -public class LineBufferData implements CommandLineRunner { | ||
| 24 | - | ||
| 25 | - @Autowired | ||
| 26 | - LineRefreshThread lineRefreshThread; | ||
| 27 | - | ||
| 28 | - private static List<Line> data; | ||
| 29 | - private static Map<String, Line> idMap; | ||
| 30 | - private static ArrayListMultimap<String, Line> companyListMap; | ||
| 31 | - | ||
| 32 | - public static List<Line> findAll(){ | ||
| 33 | - return data; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - public static Line findOne(String lineCode){ | ||
| 37 | - return idMap.get(lineCode); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - public static List<Line> findByCompany(String company){ | ||
| 41 | - return companyListMap.get(company); | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public static void replaceAll(List<Line> newData){ | ||
| 45 | - data = newData; | ||
| 46 | - Map<String, Line> idMapCopy = new HashMap<>(); | ||
| 47 | - ArrayListMultimap<String, Line> listMap = ArrayListMultimap.create(); | ||
| 48 | - | ||
| 49 | - for(Line line : data){ | ||
| 50 | - idMapCopy.put(line.getLineCode(), line); | ||
| 51 | - listMap.put(line.getCompany(), line); | ||
| 52 | - } | ||
| 53 | - idMap = idMapCopy; | ||
| 54 | - | ||
| 55 | - companyListMap = listMap; | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - @Override | ||
| 59 | - public void run(String... strings) throws Exception { | ||
| 60 | - Application.mainServices.scheduleWithFixedDelay(lineRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - public static List<String> findCodesByCompany(String company) { | ||
| 64 | - List<Line> list = companyListMap.get(company); | ||
| 65 | - List<String> codes = new ArrayList<>(list.size()); | ||
| 66 | - | ||
| 67 | - for(Line line : list) | ||
| 68 | - codes.add(line.getLineCode()); | ||
| 69 | - return codes; | ||
| 70 | - } | ||
| 71 | -} | 1 | +package com.bsth.server_rs.base_info.line.buffer; |
| 2 | + | ||
| 3 | +import com.bsth.Application; | ||
| 4 | +import com.bsth.server_rs.base_info.line.Line; | ||
| 5 | +import com.google.common.collect.ArrayListMultimap; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.boot.CommandLineRunner; | ||
| 8 | +import org.springframework.core.annotation.Order; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +import java.util.ArrayList; | ||
| 12 | +import java.util.HashMap; | ||
| 13 | +import java.util.List; | ||
| 14 | +import java.util.Map; | ||
| 15 | +import java.util.concurrent.TimeUnit; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * 线路数据缓存(自更新) | ||
| 19 | + * Created by panzhao on 2017/3/27. | ||
| 20 | + */ | ||
| 21 | +@Component | ||
| 22 | +@Order(5) | ||
| 23 | +public class LineBufferData implements CommandLineRunner { | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + LineRefreshThread lineRefreshThread; | ||
| 27 | + | ||
| 28 | + private static List<Line> data; | ||
| 29 | + private static Map<String, Line> idMap = new HashMap<>(); | ||
| 30 | + private static ArrayListMultimap<String, Line> companyListMap; | ||
| 31 | + | ||
| 32 | + public static List<Line> findAll(){ | ||
| 33 | + return data; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public static Line findOne(String lineCode){ | ||
| 37 | + return idMap.get(lineCode); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static List<Line> findByCompany(String company){ | ||
| 41 | + return companyListMap.get(company); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static void replaceAll(List<Line> newData){ | ||
| 45 | + data = newData; | ||
| 46 | + Map<String, Line> idMapCopy = new HashMap<>(); | ||
| 47 | + ArrayListMultimap<String, Line> listMap = ArrayListMultimap.create(); | ||
| 48 | + | ||
| 49 | + for(Line line : data){ | ||
| 50 | + idMapCopy.put(line.getLineCode(), line); | ||
| 51 | + listMap.put(line.getCompany(), line); | ||
| 52 | + } | ||
| 53 | + idMap = idMapCopy; | ||
| 54 | + | ||
| 55 | + companyListMap = listMap; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + @Override | ||
| 59 | + public void run(String... strings) throws Exception { | ||
| 60 | + Application.mainServices.scheduleWithFixedDelay(lineRefreshThread, 10, 60 * 60, TimeUnit.SECONDS); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public static List<String> findCodesByCompany(String company) { | ||
| 64 | + List<Line> list = companyListMap.get(company); | ||
| 65 | + List<String> codes = new ArrayList<>(list.size()); | ||
| 66 | + | ||
| 67 | + for(Line line : list) | ||
| 68 | + codes.add(line.getLineCode()); | ||
| 69 | + return codes; | ||
| 70 | + } | ||
| 71 | +} |
src/main/java/com/bsth/server_rs/dks/DksRestService.java
| @@ -156,7 +156,7 @@ public class DksRestService { | @@ -156,7 +156,7 @@ public class DksRestService { | ||
| 156 | String oldLineCode = ""; | 156 | String oldLineCode = ""; |
| 157 | BusVo vo = null; | 157 | BusVo vo = null; |
| 158 | int max = 0; | 158 | int max = 0; |
| 159 | - String maxCodes = ""; | 159 | + String maxCodes = "", maxCompanyCode = "", maxCompanyName = ""; |
| 160 | for (int i = 0, len = configs.size();i < len;i++) { | 160 | for (int i = 0, len = configs.size();i < len;i++) { |
| 161 | LineServiceConfig config = configs.get(i); | 161 | LineServiceConfig config = configs.get(i); |
| 162 | if (i == 0) { | 162 | if (i == 0) { |
| @@ -167,11 +167,15 @@ public class DksRestService { | @@ -167,11 +167,15 @@ public class DksRestService { | ||
| 167 | vo.setMonth(month); | 167 | vo.setMonth(month); |
| 168 | vo.setBusFirstCount(config.getCarCount()); | 168 | vo.setBusFirstCount(config.getCarCount()); |
| 169 | vo.setBusFirstCodes(config.getCarCodes()); | 169 | vo.setBusFirstCodes(config.getCarCodes()); |
| 170 | + vo.setCompanyCode(config.getCompanyCode()); | ||
| 171 | + vo.setCompanyName(config.getCompanyName()); | ||
| 170 | } else if (!oldLineCode.equals(config.getLineCode())) { | 172 | } else if (!oldLineCode.equals(config.getLineCode())) { |
| 171 | oldLineCode = config.getLineCode(); | 173 | oldLineCode = config.getLineCode(); |
| 172 | vo.setBusMaxCount(max); | 174 | vo.setBusMaxCount(max); |
| 173 | vo.setBusMaxCount(max); | 175 | vo.setBusMaxCount(max); |
| 174 | vo.setBusMaxCodes(maxCodes); | 176 | vo.setBusMaxCodes(maxCodes); |
| 177 | + vo.setCompanyCode(maxCompanyCode); | ||
| 178 | + vo.setCompanyName(maxCompanyName); | ||
| 175 | result.add(vo); | 179 | result.add(vo); |
| 176 | max = 0; | 180 | max = 0; |
| 177 | vo = new BusVo(); | 181 | vo = new BusVo(); |
| @@ -180,10 +184,14 @@ public class DksRestService { | @@ -180,10 +184,14 @@ public class DksRestService { | ||
| 180 | vo.setMonth(month); | 184 | vo.setMonth(month); |
| 181 | vo.setBusFirstCount(config.getCarCount()); | 185 | vo.setBusFirstCount(config.getCarCount()); |
| 182 | vo.setBusFirstCodes(config.getCarCodes()); | 186 | vo.setBusFirstCodes(config.getCarCodes()); |
| 187 | + vo.setCompanyCode(config.getCompanyCode()); | ||
| 188 | + vo.setCompanyName(config.getCompanyName()); | ||
| 183 | } | 189 | } |
| 184 | if (max < config.getCarCount()) { | 190 | if (max < config.getCarCount()) { |
| 185 | max = config.getCarCount(); | 191 | max = config.getCarCount(); |
| 186 | maxCodes = config.getCarCodes(); | 192 | maxCodes = config.getCarCodes(); |
| 193 | + maxCompanyCode = config.getCompanyCode(); | ||
| 194 | + maxCompanyName = config.getCompanyName(); | ||
| 187 | } | 195 | } |
| 188 | if (i == len - 1) { | 196 | if (i == len - 1) { |
| 189 | vo.setBusMaxCount(max); | 197 | vo.setBusMaxCount(max); |
| @@ -192,6 +200,8 @@ public class DksRestService { | @@ -192,6 +200,8 @@ public class DksRestService { | ||
| 192 | } | 200 | } |
| 193 | vo.setBusLastCount(config.getCarCount()); | 201 | vo.setBusLastCount(config.getCarCount()); |
| 194 | vo.setBusLastCodes(config.getCarCodes()); | 202 | vo.setBusLastCodes(config.getCarCodes()); |
| 203 | + vo.setCompanyCode(config.getCompanyCode()); | ||
| 204 | + vo.setCompanyName(config.getCompanyName()); | ||
| 195 | } | 205 | } |
| 196 | 206 | ||
| 197 | return result; | 207 | return result; |
| @@ -327,6 +337,8 @@ public class DksRestService { | @@ -327,6 +337,8 @@ public class DksRestService { | ||
| 327 | sb.append(car).append(","); | 337 | sb.append(car).append(","); |
| 328 | } | 338 | } |
| 329 | object.setCarCodes(sb.toString()); | 339 | object.setCarCodes(sb.toString()); |
| 340 | + object.setCompanyCode(line == null ? "" : line.getCompany()); | ||
| 341 | + object.setCompanyName(line == null ? "" : line.getCompanyName()); | ||
| 330 | 342 | ||
| 331 | objects.add(object); | 343 | objects.add(object); |
| 332 | } | 344 | } |
| @@ -339,7 +351,7 @@ public class DksRestService { | @@ -339,7 +351,7 @@ public class DksRestService { | ||
| 339 | 351 | ||
| 340 | try { | 352 | try { |
| 341 | jdbcTemplate.update("delete from control_interface.bsth_t_plan where schedule_date = ?", new Object[]{ dateTime.toString("yyyy-MM-dd") }); | 353 | jdbcTemplate.update("delete from control_interface.bsth_t_plan where schedule_date = ?", new Object[]{ dateTime.toString("yyyy-MM-dd") }); |
| 342 | - jdbcTemplate.batchUpdate("insert into control_interface.bsth_t_plan (line_code, line_name, schedule_date, conductor_count, driver_count, car_count, car_codes) values (?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { | 354 | + jdbcTemplate.batchUpdate("insert into control_interface.bsth_t_plan (line_code, line_name, schedule_date, conductor_count, driver_count, car_count, car_codes, company_code, company_name) values (?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { |
| 343 | @Override | 355 | @Override |
| 344 | public void setValues(PreparedStatement ps, int i) throws SQLException { | 356 | public void setValues(PreparedStatement ps, int i) throws SQLException { |
| 345 | LineServiceConfig object = objects.get(i); | 357 | LineServiceConfig object = objects.get(i); |
| @@ -350,6 +362,8 @@ public class DksRestService { | @@ -350,6 +362,8 @@ public class DksRestService { | ||
| 350 | ps.setInt(5, object.getDriverCount()); | 362 | ps.setInt(5, object.getDriverCount()); |
| 351 | ps.setInt(6, object.getCarCount()); | 363 | ps.setInt(6, object.getCarCount()); |
| 352 | ps.setString(7, object.getCarCodes()); | 364 | ps.setString(7, object.getCarCodes()); |
| 365 | + ps.setString(8, object.getCompanyCode()); | ||
| 366 | + ps.setString(9, object.getCompanyName()); | ||
| 353 | } | 367 | } |
| 354 | 368 | ||
| 355 | @Override | 369 | @Override |
| @@ -359,6 +373,7 @@ public class DksRestService { | @@ -359,6 +373,7 @@ public class DksRestService { | ||
| 359 | }); | 373 | }); |
| 360 | tran.commit(status); | 374 | tran.commit(status); |
| 361 | } catch (Exception e) { | 375 | } catch (Exception e) { |
| 376 | + log.error("planComputation", e); | ||
| 362 | tran.rollback(status); | 377 | tran.rollback(status); |
| 363 | } | 378 | } |
| 364 | } | 379 | } |
| @@ -435,6 +450,7 @@ public class DksRestService { | @@ -435,6 +450,7 @@ public class DksRestService { | ||
| 435 | }); | 450 | }); |
| 436 | tran.commit(status); | 451 | tran.commit(status); |
| 437 | } catch (Exception e) { | 452 | } catch (Exception e) { |
| 453 | + log.error("", e); | ||
| 438 | tran.rollback(status); | 454 | tran.rollback(status); |
| 439 | } | 455 | } |
| 440 | } | 456 | } |
| @@ -612,6 +628,7 @@ public class DksRestService { | @@ -612,6 +628,7 @@ public class DksRestService { | ||
| 612 | }); | 628 | }); |
| 613 | tran.commit(status); | 629 | tran.commit(status); |
| 614 | } catch (Exception e) { | 630 | } catch (Exception e) { |
| 631 | + log.error("", e); | ||
| 615 | tran.rollback(status); | 632 | tran.rollback(status); |
| 616 | } | 633 | } |
| 617 | } | 634 | } |
| @@ -715,6 +732,10 @@ public class DksRestService { | @@ -715,6 +732,10 @@ public class DksRestService { | ||
| 715 | 732 | ||
| 716 | private String busMaxCodes; | 733 | private String busMaxCodes; |
| 717 | 734 | ||
| 735 | + private String companyCode; | ||
| 736 | + | ||
| 737 | + private String companyName; | ||
| 738 | + | ||
| 718 | public String getLineCode() { | 739 | public String getLineCode() { |
| 719 | return lineCode; | 740 | return lineCode; |
| 720 | } | 741 | } |
| @@ -786,6 +807,22 @@ public class DksRestService { | @@ -786,6 +807,22 @@ public class DksRestService { | ||
| 786 | public void setBusMaxCodes(String busMaxCodes) { | 807 | public void setBusMaxCodes(String busMaxCodes) { |
| 787 | this.busMaxCodes = busMaxCodes; | 808 | this.busMaxCodes = busMaxCodes; |
| 788 | } | 809 | } |
| 810 | + | ||
| 811 | + public String getCompanyCode() { | ||
| 812 | + return companyCode; | ||
| 813 | + } | ||
| 814 | + | ||
| 815 | + public void setCompanyCode(String companyCode) { | ||
| 816 | + this.companyCode = companyCode; | ||
| 817 | + } | ||
| 818 | + | ||
| 819 | + public String getCompanyName() { | ||
| 820 | + return companyName; | ||
| 821 | + } | ||
| 822 | + | ||
| 823 | + public void setCompanyName(String companyName) { | ||
| 824 | + this.companyName = companyName; | ||
| 825 | + } | ||
| 789 | } | 826 | } |
| 790 | 827 | ||
| 791 | /** | 828 | /** |
src/main/java/com/bsth/server_rs/dks/LineServiceConfig.java
| @@ -22,6 +22,10 @@ public class LineServiceConfig { | @@ -22,6 +22,10 @@ public class LineServiceConfig { | ||
| 22 | 22 | ||
| 23 | private String carCodes; | 23 | private String carCodes; |
| 24 | 24 | ||
| 25 | + private String companyCode; | ||
| 26 | + | ||
| 27 | + private String companyName; | ||
| 28 | + | ||
| 25 | public String getLineCode() { | 29 | public String getLineCode() { |
| 26 | return lineCode; | 30 | return lineCode; |
| 27 | } | 31 | } |
| @@ -85,4 +89,20 @@ public class LineServiceConfig { | @@ -85,4 +89,20 @@ public class LineServiceConfig { | ||
| 85 | public void setCarCodes(String carCodes) { | 89 | public void setCarCodes(String carCodes) { |
| 86 | this.carCodes = carCodes; | 90 | this.carCodes = carCodes; |
| 87 | } | 91 | } |
| 92 | + | ||
| 93 | + public String getCompanyCode() { | ||
| 94 | + return companyCode; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public void setCompanyCode(String companyCode) { | ||
| 98 | + this.companyCode = companyCode; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public String getCompanyName() { | ||
| 102 | + return companyName; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + public void setCompanyName(String companyName) { | ||
| 106 | + this.companyName = companyName; | ||
| 107 | + } | ||
| 88 | } | 108 | } |
src/main/java/com/bsth/service/impl/UserServiceImpl.java
| 1 | -package com.bsth.service.impl; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.PasswordUser; | ||
| 4 | -import com.bsth.repository.UserRepository; | ||
| 5 | -import com.bsth.service.UserService; | ||
| 6 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | -import org.springframework.boot.CommandLineRunner; | ||
| 8 | -import org.springframework.core.annotation.Order; | ||
| 9 | -import org.springframework.stereotype.Service; | ||
| 10 | - | ||
| 11 | -import java.util.HashMap; | ||
| 12 | -import java.util.Iterator; | ||
| 13 | -import java.util.Map; | ||
| 14 | - | ||
| 15 | -/** | ||
| 16 | - * Created by panzhao on 2017/3/26. | ||
| 17 | - */ | ||
| 18 | -@Service | ||
| 19 | -@Order(4) | ||
| 20 | -public class UserServiceImpl implements UserService , CommandLineRunner { | ||
| 21 | - | ||
| 22 | - @Autowired | ||
| 23 | - UserRepository userRepository; | ||
| 24 | - | ||
| 25 | - private Map<String, PasswordUser> pwd2UserMap; | ||
| 26 | - | ||
| 27 | - @Override | ||
| 28 | - public PasswordUser get(String pwd) { | ||
| 29 | - return pwd2UserMap.get(pwd); | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - @Override | ||
| 33 | - public void loadData(){ | ||
| 34 | - Map<String, PasswordUser> map = new HashMap<>(); | ||
| 35 | - Iterator<PasswordUser> iterator = userRepository.findAll().iterator(); | ||
| 36 | - PasswordUser user; | ||
| 37 | - while (iterator.hasNext()){ | ||
| 38 | - user = iterator.next(); | ||
| 39 | - map.put(user.getPwd(), user); | ||
| 40 | - } | ||
| 41 | - pwd2UserMap = map; | ||
| 42 | - | ||
| 43 | - System.out.println("加载user size:" + pwd2UserMap.size()); | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - @Override | ||
| 47 | - public void run(String... strings) throws Exception { | ||
| 48 | - loadData(); | ||
| 49 | - } | ||
| 50 | -} | 1 | +package com.bsth.service.impl; |
| 2 | + | ||
| 3 | +import com.bsth.entity.PasswordUser; | ||
| 4 | +import com.bsth.repository.UserRepository; | ||
| 5 | +import com.bsth.service.UserService; | ||
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.boot.CommandLineRunner; | ||
| 10 | +import org.springframework.core.annotation.Order; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | + | ||
| 13 | +import java.util.HashMap; | ||
| 14 | +import java.util.Iterator; | ||
| 15 | +import java.util.Map; | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Created by panzhao on 2017/3/26. | ||
| 19 | + */ | ||
| 20 | +@Service | ||
| 21 | +@Order(4) | ||
| 22 | +public class UserServiceImpl implements UserService , CommandLineRunner { | ||
| 23 | + | ||
| 24 | + private final static Logger log = LoggerFactory.getLogger(UserServiceImpl.class); | ||
| 25 | + | ||
| 26 | + @Autowired | ||
| 27 | + UserRepository userRepository; | ||
| 28 | + | ||
| 29 | + private Map<String, PasswordUser> pwd2UserMap; | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public PasswordUser get(String pwd) { | ||
| 33 | + return pwd2UserMap.get(pwd); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public void loadData(){ | ||
| 38 | + Map<String, PasswordUser> map = new HashMap<>(); | ||
| 39 | + Iterator<PasswordUser> iterator = userRepository.findAll().iterator(); | ||
| 40 | + PasswordUser user; | ||
| 41 | + while (iterator.hasNext()){ | ||
| 42 | + user = iterator.next(); | ||
| 43 | + map.put(user.getPwd(), user); | ||
| 44 | + } | ||
| 45 | + pwd2UserMap = map; | ||
| 46 | + | ||
| 47 | + log.info("加载user size:" + pwd2UserMap.size()); | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public void run(String... strings) throws Exception { | ||
| 52 | + loadData(); | ||
| 53 | + } | ||
| 54 | +} |