Search in sources :

Example 6 with Account

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;
}
Also used : UserRoleMapper(cn.edu.zjnu.acm.judge.mapper.UserRoleMapper) ExcelUtil(cn.edu.zjnu.acm.judge.util.excel.ExcelUtil) UserProblemMapper(cn.edu.zjnu.acm.judge.mapper.UserProblemMapper) LocalDateTime(java.time.LocalDateTime) RequiredArgsConstructor(lombok.RequiredArgsConstructor) UserMapper(cn.edu.zjnu.acm.judge.mapper.UserMapper) User(cn.edu.zjnu.acm.judge.domain.User) UsernameChangeLog(cn.edu.zjnu.acm.judge.domain.UsernameChangeLog) Locale(java.util.Locale) Service(org.springframework.stereotype.Service) Map(java.util.Map) Pageable(org.springframework.data.domain.Pageable) Nonnull(javax.annotation.Nonnull) MessageSource(org.springframework.context.MessageSource) BusinessCode(cn.edu.zjnu.acm.judge.exception.BusinessCode) AccountService(cn.edu.zjnu.acm.judge.service.AccountService) EnumUtils(cn.edu.zjnu.acm.judge.util.EnumUtils) ValueCheck(cn.edu.zjnu.acm.judge.util.ValueCheck) AccountForm(cn.edu.zjnu.acm.judge.data.form.AccountForm) BusinessException(cn.edu.zjnu.acm.judge.exception.BusinessException) Collection(java.util.Collection) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) Instant(java.time.Instant) Page(org.springframework.data.domain.Page) PasswordConfiguration(cn.edu.zjnu.acm.judge.config.security.PasswordConfiguration) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) UsernameChangeLogMapper(cn.edu.zjnu.acm.judge.mapper.UsernameChangeLogMapper) TreeMap(java.util.TreeMap) Account(cn.edu.zjnu.acm.judge.data.excel.Account) CollectionUtils(org.springframework.util.CollectionUtils) AccountImportForm(cn.edu.zjnu.acm.judge.data.form.AccountImportForm) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PageImpl(org.springframework.data.domain.PageImpl) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) Account(cn.edu.zjnu.acm.judge.data.excel.Account) List(java.util.List) TreeMap(java.util.TreeMap)

Example 7 with Account

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;
}
Also used : Account(cn.edu.zjnu.acm.judge.data.excel.Account)

Example 8 with 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);
}
Also used : Account(cn.edu.zjnu.acm.judge.data.excel.Account) AccountImportForm(cn.edu.zjnu.acm.judge.data.form.AccountImportForm) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Account

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));
}
Also used : Locale(java.util.Locale) Account(cn.edu.zjnu.acm.judge.data.excel.Account)

Example 10 with Account

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));
}
Also used : Locale(java.util.Locale) Account(cn.edu.zjnu.acm.judge.data.excel.Account)

Aggregations

Account (cn.edu.zjnu.acm.judge.data.excel.Account)10 AccountImportForm (cn.edu.zjnu.acm.judge.data.form.AccountImportForm)4 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)4 Locale (java.util.Locale)4 AccountForm (cn.edu.zjnu.acm.judge.data.form.AccountForm)2 User (cn.edu.zjnu.acm.judge.domain.User)2 BusinessCode (cn.edu.zjnu.acm.judge.exception.BusinessCode)2 UserMapper (cn.edu.zjnu.acm.judge.mapper.UserMapper)2 UserProblemMapper (cn.edu.zjnu.acm.judge.mapper.UserProblemMapper)2 UserRoleMapper (cn.edu.zjnu.acm.judge.mapper.UserRoleMapper)2 EnumUtils (cn.edu.zjnu.acm.judge.util.EnumUtils)2 ValueCheck (cn.edu.zjnu.acm.judge.util.ValueCheck)2 ExcelUtil (cn.edu.zjnu.acm.judge.util.excel.ExcelUtil)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 InputStream (java.io.InputStream)2 Instant (java.time.Instant)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2