use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountServiceImpl method parseExcel.
@Override
public List<Account> parseExcel(InputStream inputStream, @Nonnull Locale locale) {
Objects.requireNonNull(locale, "locale");
List<Account> accounts = ExcelUtil.parse(inputStream, Account.class, locale).stream().filter(account -> StringUtils.hasText(account.getId())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(accounts)) {
return accounts;
}
Map<String, List<Account>> groupBy = accounts.stream().collect(Collectors.groupingBy(Account::getId, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER), Collectors.toList()));
List<String> exists = userMapper.findAllByUserIds(groupBy.keySet());
for (String exist : exists) {
for (Account account : groupBy.get(exist)) {
account.setExists(true);
}
}
return accounts;
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountExcelControllerTest method toAccount.
private Account toAccount(User user) {
Account account = new Account();
account.setId(user.getId());
account.setPassword(user.getPassword());
account.setEmail(user.getEmail());
account.setSchool(user.getSchool());
return account;
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountExcelControllerTest method testImportUsers.
/**
* Test of importUsers method, of class AccountController.
*
* {@link AccountExcelController#importUsers(AccountImportForm)}
*/
@Test
public void testImportUsers() throws Exception {
log.info("importUsers");
AccountImportForm form = new AccountImportForm();
Account account = toAccount(mockDataService.user(false));
Account account2 = toAccount(mockDataService.user(false));
form.setContent(Arrays.asList(account, account2));
expect(form, HttpStatus.NO_CONTENT);
account.setExists(true);
account2.setExists(true);
expect(form, HttpStatus.BAD_REQUEST);
form.getExistsPolicy().add(AccountImportForm.ExistPolicy.ENABLE);
expect(form, HttpStatus.NO_CONTENT);
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountExcelController method findAllXls.
@GetMapping("api/accounts.xls")
public ResponseEntity<?> findAllXls(AccountForm form, Pageable pageable, @Nullable Locale requestLocale) throws IOException {
Locale locale = Optional.ofNullable(requestLocale).orElse(Locale.ROOT);
List<Account> content = accountService.findAllForExport(form, pageable);
return ExcelUtil.toResponse(Account.class, content, locale, ExcelType.XLS, accountService.getExcelName(locale));
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountExcelController method findAllXlsx.
@GetMapping("api/accounts.xlsx")
public ResponseEntity<?> findAllXlsx(AccountForm form, Pageable pageable, @Nullable Locale requestLocale) throws IOException {
Locale locale = Optional.ofNullable(requestLocale).orElse(Locale.ROOT);
List<Account> content = accountService.findAllForExport(form, pageable);
return ExcelUtil.toResponse(Account.class, content, locale, ExcelType.XLSX, accountService.getExcelName(locale));
}
Aggregations