Compare commits
No commits in common. "5ad6980bf794159144c6cf51122c1375cea9eb0c" and "cbc271154023b382bf41990e2083e51c46a05b9d" have entirely different histories.
5ad6980bf7
...
cbc2711540
|
@ -6,7 +6,12 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
|||
/**
|
||||
* 需要时,当查询数据不存在时抛出的异常
|
||||
*
|
||||
* <p>
|
||||
* 暂时先这样,后续完善异常体系时可能会更改。
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
* @see xyz.zhouxy.plusone.util.AssertResult
|
||||
*/
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public class DataNotExistException extends PlusoneException {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.zhouxy.plusone.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Repository 基础接口
|
||||
|
@ -11,7 +10,7 @@ import java.util.Optional;
|
|||
*/
|
||||
public interface IRepository<T extends AggregateRoot<ID>, ID extends Serializable> {
|
||||
|
||||
Optional<T> find(ID id);
|
||||
T find(ID id);
|
||||
|
||||
T save(T entity);
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.Serializable;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -21,23 +20,23 @@ public abstract class JdbcEntityDaoSupport<T extends Entity<ID>, ID extends Seri
|
|||
extends PlusoneJdbcDaoSupport {
|
||||
|
||||
protected RowMapper<T> rowMapper;
|
||||
protected ResultSetExtractor<Optional<T>> resultSetExtractor;
|
||||
protected ResultSetExtractor<T> resultSetExtractor;
|
||||
|
||||
protected JdbcEntityDaoSupport(@Nonnull NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
||||
super(namedParameterJdbcTemplate);
|
||||
this.rowMapper = (ResultSet rs, int rowNum) -> mapRow(rs);
|
||||
this.resultSetExtractor = (ResultSet rs) -> rs.next() ? Optional.of(mapRow(rs)) : Optional.empty();
|
||||
this.resultSetExtractor = (ResultSet rs) -> rs.next() ? mapRow(rs) : null;
|
||||
}
|
||||
|
||||
protected final Optional<T> queryForObject(String sql) {
|
||||
protected final T queryForObject(String sql) {
|
||||
return queryForObject(sql, this.resultSetExtractor);
|
||||
}
|
||||
|
||||
protected final Optional<T> queryForObject(String sql, SqlParameterSource paramSource) {
|
||||
protected final T queryForObject(String sql, SqlParameterSource paramSource) {
|
||||
return queryForObject(sql, paramSource, this.resultSetExtractor);
|
||||
}
|
||||
|
||||
protected final Optional<T> queryForObject(String sql, String paramName, Object value) {
|
||||
protected final T queryForObject(String sql, String paramName, Object value) {
|
||||
return queryForObject(sql, new MapSqlParameterSource(paramName, value), this.resultSetExtractor);
|
||||
}
|
||||
|
||||
|
@ -67,7 +66,7 @@ public abstract class JdbcEntityDaoSupport<T extends Entity<ID>, ID extends Seri
|
|||
this.rowMapper = rowMapper;
|
||||
}
|
||||
|
||||
protected void setResultSetExtractor(@Nonnull ResultSetExtractor<Optional<T>> resultSetExtractor) {
|
||||
protected void setResultSetExtractor(@Nonnull ResultSetExtractor<T> resultSetExtractor) {
|
||||
this.resultSetExtractor = resultSetExtractor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.zhouxy.plusone.jdbc;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -21,7 +20,7 @@ public abstract class JdbcRepositorySupport<T extends AggregateRoot<ID>, ID exte
|
|||
|
||||
protected abstract void doDelete(@Nonnull T entity);
|
||||
|
||||
protected abstract Optional<T> doFindById(@Nonnull ID id);
|
||||
protected abstract T doFindById(@Nonnull ID id);
|
||||
|
||||
protected abstract T doInsert(@Nonnull T entity);
|
||||
|
||||
|
@ -36,7 +35,7 @@ public abstract class JdbcRepositorySupport<T extends AggregateRoot<ID>, ID exte
|
|||
}
|
||||
|
||||
@Override
|
||||
public final Optional<T> find(ID id) {
|
||||
public final T find(ID id) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("Id cannot be null.");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package xyz.zhouxy.plusone.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
@ -65,16 +66,17 @@ public abstract class PlusoneJdbcDaoSupport {
|
|||
}
|
||||
|
||||
protected final <T> Stream<T> queryForStream(String sql, String paramName, Object value, Class<T> elementType) {
|
||||
return queryForStream(sql, new MapSqlParameterSource(paramName, value), elementType);
|
||||
return this.jdbc.queryForList(sql, new MapSqlParameterSource(paramName, value), elementType).stream();
|
||||
}
|
||||
|
||||
protected final boolean queryExists(String sql, SqlParameterSource parameterSource) {
|
||||
Boolean isExists = this.jdbc.queryForObject(sql, parameterSource, Boolean.TYPE);
|
||||
Boolean isExists = this.jdbc.query(sql, parameterSource, ResultSet::next);
|
||||
return Boolean.TRUE.equals(isExists);
|
||||
}
|
||||
|
||||
protected final boolean queryExists(String sql, String paramName, Object value) {
|
||||
return queryExists(sql, new MapSqlParameterSource(paramName, value));
|
||||
Boolean isExists = this.jdbc.query(sql, new MapSqlParameterSource(paramName, value), ResultSet::next);
|
||||
return Boolean.TRUE.equals(isExists);
|
||||
}
|
||||
|
||||
protected final int update(String sql, SqlParameterSource parameterSource) {
|
||||
|
@ -82,7 +84,7 @@ public abstract class PlusoneJdbcDaoSupport {
|
|||
}
|
||||
|
||||
protected final int update(String sql, String paramName, Object value) {
|
||||
return update(sql, new MapSqlParameterSource(paramName, value));
|
||||
return this.jdbc.update(sql, new MapSqlParameterSource(paramName, value));
|
||||
}
|
||||
|
||||
protected final int batchUpdate(String sql, SqlParameterSource[] batchArgs) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import xyz.zhouxy.plusone.system.application.query.params.AccountQueryParams;
|
|||
import xyz.zhouxy.plusone.system.application.service.AccountManagementService;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateAccountCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.UpdateAccountCommand;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
import xyz.zhouxy.plusone.util.RestfulResult;
|
||||
|
||||
/**
|
||||
|
@ -76,6 +77,7 @@ public class AccountManagementController {
|
|||
adminAuthLogic.checkLogin();
|
||||
adminAuthLogic.checkPermission("sys-account-details");
|
||||
var accountDetails = service.queryAccountDetails(accountId);
|
||||
AssertResult.nonNull(accountDetails);
|
||||
return success("查询成功", accountDetails);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,34 +21,18 @@ public class AccountLoginException extends PlusoneException {
|
|||
}
|
||||
|
||||
public static AccountLoginException accountNotExistException() {
|
||||
return accountNotExistException("用户账户不存在");
|
||||
}
|
||||
|
||||
public static AccountLoginException accountNotExistException(String msg) {
|
||||
return new AccountLoginException(4030101, msg);
|
||||
return new AccountLoginException(4030101, "用户账户不存在");
|
||||
}
|
||||
|
||||
public static AccountLoginException otpErrorException() {
|
||||
return otpErrorException("验证码错误");
|
||||
}
|
||||
|
||||
public static AccountLoginException otpErrorException(String msg) {
|
||||
return new AccountLoginException(4030501, msg);
|
||||
return new AccountLoginException(4030501, "验证码错误");
|
||||
}
|
||||
|
||||
public static AccountLoginException otpNotExistsException() {
|
||||
return otpNotExistsException("验证码不存在或已过期");
|
||||
}
|
||||
|
||||
public static AccountLoginException otpNotExistsException(String msg) {
|
||||
return new AccountLoginException(4030502, msg);
|
||||
return new AccountLoginException(4030502, "验证码不存在或已过期");
|
||||
}
|
||||
|
||||
public static AccountLoginException passwordErrorException() {
|
||||
return passwordErrorException("用户密码错误");
|
||||
}
|
||||
|
||||
public static AccountLoginException passwordErrorException(String msg) {
|
||||
return new AccountLoginException(4030200, msg);
|
||||
return new AccountLoginException(4030200, "用户密码错误");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package xyz.zhouxy.plusone.system.application.service;
|
||||
|
||||
import xyz.zhouxy.plusone.system.constant.AuthLogic;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -9,6 +10,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import xyz.zhouxy.plusone.system.application.common.util.PrincipalUtil;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountLoginException;
|
||||
import xyz.zhouxy.plusone.system.application.query.AccountQueries;
|
||||
|
@ -17,7 +19,6 @@ import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject;
|
|||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordByOtpCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordCommand;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.ChangePasswordWithoutLoginCommand;
|
||||
import xyz.zhouxy.plusone.system.constant.AuthLogic;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Account;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.AccountRepository;
|
||||
import xyz.zhouxy.plusone.system.domain.model.account.Email;
|
||||
|
@ -64,8 +65,7 @@ public class AccountContextService {
|
|||
@Transactional
|
||||
public void changePassword(ChangePasswordCommand command) {
|
||||
adminAuthLogic.checkLogin();
|
||||
Account account = accountRepository.find(adminAuthLogic.getLoginIdAsLong())
|
||||
.orElseThrow(() -> AccountLoginException.accountNotExistException("当前所登录的账号不存在"));
|
||||
Account account = accountRepository.find(adminAuthLogic.getLoginIdAsLong());
|
||||
account.checkPassword(command.getPassword());
|
||||
account.changePassword(command.getNewPassword(), command.getPasswordConfirmation());
|
||||
accountRepository.save(account);
|
||||
|
@ -77,10 +77,9 @@ public class AccountContextService {
|
|||
String principal = command.getAccount();
|
||||
Principal emailOrMobilePhone = PrincipalUtil.getEmailOrMobilePhone(principal);
|
||||
|
||||
Account account = (emailOrMobilePhone instanceof Email
|
||||
Account account = emailOrMobilePhone instanceof Email
|
||||
? accountRepository.findByEmail((Email) emailOrMobilePhone)
|
||||
: accountRepository.findByMobilePhone((MobilePhone) emailOrMobilePhone))
|
||||
.orElseThrow(() -> AccountLoginException.accountNotExistException("当前所登录的账号不存在"));
|
||||
: accountRepository.findByMobilePhone((MobilePhone) emailOrMobilePhone);
|
||||
account.checkPassword(command.getOldPassword());
|
||||
account.changePassword(command.getNewPassword(), command.getPasswordConfirmation());
|
||||
accountRepository.save(account);
|
||||
|
@ -91,12 +90,12 @@ public class AccountContextService {
|
|||
public void changePasswordByOtp(ChangePasswordByOtpCommand command) {
|
||||
|
||||
var principal = command.getAccount();
|
||||
Optional<Account> account = switch (command.getPrincipalType()) {
|
||||
Account account = switch (command.getPrincipalType()) {
|
||||
case EMAIL -> accountRepository.findByEmail(Email.of(principal));
|
||||
case MOBILE_PHONE -> accountRepository.findByMobilePhone(MobilePhone.of(principal));
|
||||
default -> throw InvalidInputException.unsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
};
|
||||
account.orElseThrow(AccountLoginException::accountNotExistException);
|
||||
Assert.notNull(account, AccountLoginException::accountNotExistException);
|
||||
|
||||
mailAndSmsVerifyService.checkOtp(principal, command.getOtp());
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.exception.AccountRegisterException;
|
||||
import xyz.zhouxy.plusone.system.application.query.AccountQueries;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.AccountQueryParams;
|
||||
|
@ -77,16 +76,16 @@ public class AccountManagementService {
|
|||
public void deleteAccounts(List<Long> ids) {
|
||||
Account accountToDelete;
|
||||
for (var id : ids) {
|
||||
accountToDelete = accountRepository.find(id)
|
||||
.orElseThrow(() -> new DataNotExistException("该账号不存在"));
|
||||
accountToDelete = accountRepository.find(id);
|
||||
AssertResult.nonNull(accountToDelete);
|
||||
accountRepository.delete(accountToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAccountInfo(Long id, @Valid UpdateAccountCommand command) {
|
||||
Assert.isTrue(Objects.equals(id, command.getId()), "参数错误: id 不匹配");
|
||||
Account account = accountRepository.find(id)
|
||||
.orElseThrow(() -> new DataNotExistException("该账号不存在"));
|
||||
Account account = accountRepository.find(id);
|
||||
AssertResult.nonNull(account, "该账号不存在");
|
||||
account.setAccountInfo(command.getNickname(), command.getAvatar(), command.getSex());
|
||||
account.setUpdatedBy(adminAuthLogic.getLoginIdAsLong());
|
||||
accountRepository.save(account);
|
||||
|
@ -97,13 +96,6 @@ public class AccountManagementService {
|
|||
return accountQueries.queryAccountOverviewPage(queryParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询账号详细信息,如果查不到将抛出 {@link DataNotExistException}。
|
||||
*
|
||||
* @param accountId 账号 id
|
||||
* @return 账号信息
|
||||
* @throws DataNotExistException 查询不到数据时抛出异常
|
||||
*/
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public AccountDetails queryAccountDetails(@PathVariable("accountId") Long accountId) {
|
||||
var accountDetails = accountQueries.queryAccountDetails(accountId);
|
||||
|
|
|
@ -44,11 +44,12 @@ public class AdminLoginService {
|
|||
@ValidateDto
|
||||
public LoginInfoViewObject loginByPassword(LoginByPasswordCommand command) {
|
||||
var principal = command.getPrincipal();
|
||||
Account account = (switch (command.getPrincipalType()) {
|
||||
Account account = switch (command.getPrincipalType()) {
|
||||
case USERNAME -> accountRepository.findByUsername(Username.of(principal));
|
||||
case EMAIL -> accountRepository.findByEmail(Email.of(principal));
|
||||
case MOBILE_PHONE -> accountRepository.findByMobilePhone(MobilePhone.of(principal));
|
||||
}).orElseThrow(AccountLoginException::accountNotExistException);
|
||||
};
|
||||
Assert.notNull(account, AccountLoginException::accountNotExistException);
|
||||
var isPasswordCorrect = account.checkPassword(command.getPassword());
|
||||
Assert.isTrue(isPasswordCorrect, AccountLoginException::passwordErrorException);
|
||||
|
||||
|
@ -60,11 +61,12 @@ public class AdminLoginService {
|
|||
@ValidateDto
|
||||
public LoginInfoViewObject loginByOtp(LoginByOtpCommand command) {
|
||||
var principal = command.getPrincipal();
|
||||
Account account = (switch (command.getPrincipalType()) {
|
||||
Account account = switch (command.getPrincipalType()) {
|
||||
case EMAIL -> accountRepository.findByEmail(Email.of(principal));
|
||||
case MOBILE_PHONE -> accountRepository.findByMobilePhone(MobilePhone.of(principal));
|
||||
default -> throw InvalidInputException.unsupportedPrincipalTypeException("输入邮箱地址或手机号");
|
||||
}).orElseThrow(AccountLoginException::accountNotExistException);
|
||||
};
|
||||
Assert.notNull(account, AccountLoginException::accountNotExistException);
|
||||
|
||||
mailAndSmsVerifyService.checkOtp(principal, command.getOtp());
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.springframework.transaction.annotation.Propagation;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.query.DictQueries;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.DictQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.DictOverview;
|
||||
|
@ -46,21 +45,21 @@ public class DictManagementService {
|
|||
public void deleteDicts(List<Long> ids) {
|
||||
Dict dictToDelete;
|
||||
for (Long id : ids) {
|
||||
dictToDelete = dictRepository.find(id).orElseThrow(DataNotExistException::new);
|
||||
dictToDelete = dictRepository.find(id);
|
||||
dictRepository.delete(dictToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDict(Long id, @Valid UpdateDictCommand command) {
|
||||
Assert.isTrue(Objects.equals(id, command.getId()), "id 不匹配");
|
||||
Dict dictToUpdate = dictRepository.find(command.getId()).orElseThrow(DataNotExistException::new);
|
||||
Dict dictToUpdate = dictRepository.find(command.getId());
|
||||
dictToUpdate.updateDict(command.getDictType(), command.getDictLabel(), command.getKeyLabelMap());
|
||||
dictRepository.save(dictToUpdate);
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public Dict findDictDetails(Long dictId) {
|
||||
return dictRepository.find(dictId).orElseThrow(DataNotExistException::new);
|
||||
return dictRepository.find(dictId);
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.util.Assert;
|
||||
|
||||
import xyz.zhouxy.plusone.domain.IWithOrderNumber;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.exception.UnsupportedMenuTypeException;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject;
|
||||
import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand;
|
||||
|
@ -23,6 +22,7 @@ import xyz.zhouxy.plusone.system.domain.model.menu.Menu;
|
|||
import xyz.zhouxy.plusone.system.domain.model.menu.MenuConstructor;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.MenuRepository;
|
||||
import xyz.zhouxy.plusone.system.domain.service.MenuService;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
||||
/**
|
||||
* 菜单管理
|
||||
|
@ -88,16 +88,15 @@ public class MenuManagementService {
|
|||
|
||||
// ==================== delete ====================
|
||||
public void deleteMenu(Long id) {
|
||||
Menu menuToDelete = menuRepository.find(id)
|
||||
.orElseThrow(DataNotExistException::new);
|
||||
Menu menuToDelete = menuRepository.find(id);
|
||||
AssertResult.nonNull(menuToDelete);
|
||||
menuRepository.delete(menuToDelete);
|
||||
}
|
||||
|
||||
// ==================== update ====================
|
||||
public void updateMenu(Long id, @Valid UpdateMenuCommand command) {
|
||||
Assert.isTrue(Objects.equals(id, command.getId()), "id 不匹配");
|
||||
Menu menuToUpdate = menuRepository.find(command.getId())
|
||||
.orElseThrow(DataNotExistException::new);
|
||||
Menu menuToUpdate = menuRepository.find(command.getId());
|
||||
menuToUpdate.updateMenuInfo(
|
||||
command.getMenuType(),
|
||||
command.getParentId(),
|
||||
|
@ -119,7 +118,7 @@ public class MenuManagementService {
|
|||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public MenuViewObject findById(Long id) {
|
||||
var menu = menuRepository.find(id);
|
||||
return MenuViewObject.of(menu.orElseThrow(DataNotExistException::new));
|
||||
return MenuViewObject.of(menu);
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.system.application.query.RoleQueries;
|
||||
import xyz.zhouxy.plusone.system.application.query.params.RoleQueryParams;
|
||||
import xyz.zhouxy.plusone.system.application.query.result.RoleOverview;
|
||||
|
@ -63,7 +62,7 @@ public class RoleManagementService {
|
|||
|
||||
public void updateRole(@Valid UpdateRoleCommand command) {
|
||||
Long roleId = command.getId();
|
||||
Role roleToUpdate = _roleRepository.find(roleId).orElseThrow(DataNotExistException::new);
|
||||
Role roleToUpdate = _roleRepository.find(roleId);
|
||||
roleToUpdate.update(
|
||||
command.getName(),
|
||||
command.getIdentifier(),
|
||||
|
@ -75,7 +74,7 @@ public class RoleManagementService {
|
|||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
Role role = _roleRepository.find(id).orElseThrow(DataNotExistException::new);
|
||||
Role role = _roleRepository.find(id);
|
||||
_roleRepository.delete(role);
|
||||
}
|
||||
|
||||
|
@ -86,7 +85,7 @@ public class RoleManagementService {
|
|||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
public Role findById(Long id) {
|
||||
return _roleRepository.find(id).orElseThrow(DataNotExistException::new);
|
||||
return _roleRepository.find(id);
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.SUPPORTS)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package xyz.zhouxy.plusone.system.domain.model.account;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import xyz.zhouxy.plusone.domain.IRepository;
|
||||
|
||||
|
@ -15,11 +14,11 @@ public interface AccountRepository extends IRepository<Account, Long> {
|
|||
|
||||
Collection<Account> findByRoleId(Long roleId);
|
||||
|
||||
Optional<Account> findByEmail(Email email);
|
||||
Account findByEmail(Email email);
|
||||
|
||||
Optional<Account> findByMobilePhone(MobilePhone mobilePhone);
|
||||
Account findByMobilePhone(MobilePhone mobilePhone);
|
||||
|
||||
Optional<Account> findByUsername(Username username);
|
||||
Account findByUsername(Username username);
|
||||
|
||||
boolean existsUsername(Username username);
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.sql.SQLException;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -45,7 +44,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final Optional<Account> doFindById(@Nonnull Long id) {
|
||||
protected final Account doFindById(@Nonnull Long id) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
|
@ -57,7 +56,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Account> findByEmail(Email email) {
|
||||
public Account findByEmail(Email email) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
|
@ -69,7 +68,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Account> findByMobilePhone(MobilePhone mobilePhone) {
|
||||
public Account findByMobilePhone(MobilePhone mobilePhone) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
|
@ -81,7 +80,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Account> findByUsername(Username username) {
|
||||
public Account findByUsername(Username username) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, email, mobile_phone, username, "password", salt, avatar, sex, nickname, status,
|
||||
|
@ -94,25 +93,25 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
|
||||
@Override
|
||||
public boolean exists(Long id) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE id = :id AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_account WHERE id = :id AND deleted = 0 LIMIT 1",
|
||||
"id", id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsUsername(Username username) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_account WHERE username = :username AND deleted = 0 LIMIT 1",
|
||||
"username", username.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsEmail(Email email) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE email = :email AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_account WHERE email = :email AND deleted = 0 LIMIT 1",
|
||||
"email", email.value());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsMobilePhone(MobilePhone mobilePhone) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_account WHERE mobile_phone = :mobile_phone AND deleted = 0 LIMIT 1",
|
||||
"mobile_phone", mobilePhone.value());
|
||||
}
|
||||
|
||||
|
@ -144,7 +143,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
generateParamSource(id, entity));
|
||||
assertUpdateOneRow(i);
|
||||
this.accountRoleDAO.insertAccountRoleRefs(id, entity.getRoleIds());
|
||||
return find(id).orElseThrow();
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,7 +167,7 @@ public class AccountRepositoryImpl extends JdbcRepositorySupport<Account, Long>
|
|||
generateParamSource(entity));
|
||||
assertUpdateOneRow(i);
|
||||
this.accountRoleDAO.saveAccountRoleRefs(entity);
|
||||
return find(entity.getId().orElseThrow()).orElseThrow();
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -16,7 +15,6 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
|||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
||||
|
@ -36,7 +34,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Dict> doFindById(@Nonnull Long id) {
|
||||
public Dict doFindById(@Nonnull Long id) {
|
||||
return queryForObject("SELECT id, dict_type, dict_label, \"version\" WHERE id = :id AND deleted = 0",
|
||||
"id", id);
|
||||
}
|
||||
|
@ -51,7 +49,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
|||
generateParamSource(id, entity));
|
||||
AssertResult.updateOneRow(i);
|
||||
this.dictValueDAO.insertDictValues(id, entity);
|
||||
return find(id).orElseThrow(DataNotExistException::new);
|
||||
return find(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +66,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
|||
generateParamSource(entity));
|
||||
AssertResult.updateOneRow(i);
|
||||
this.dictValueDAO.updateDictValues(entity);
|
||||
return find(entity.getId().orElseThrow()).orElseThrow(DataNotExistException::new);
|
||||
return find(entity.getId().orElseThrow());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,7 +81,7 @@ public class DictRepositoryImpl extends JdbcRepositorySupport<Dict, Long> implem
|
|||
|
||||
@Override
|
||||
public boolean exists(Long id) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_dict_type WHERE id = :id AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_dict_type WHERE id = :id AND deleted = 0 LIMIT 1",
|
||||
new MapSqlParameterSource("id", id));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import java.time.LocalDateTime;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -18,7 +17,6 @@ import org.springframework.stereotype.Repository;
|
|||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
@ -40,7 +38,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final Optional<Menu> doFindById(@Nonnull Long id) {
|
||||
protected final Menu doFindById(@Nonnull Long id) {
|
||||
return queryForObject("""
|
||||
SELECT
|
||||
id, parent_id, "type", "name", "path", title, icon, hidden, order_number, status, remarks,
|
||||
|
@ -66,7 +64,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
|||
int i = update(sql, paramSource);
|
||||
AssertResult.updateOneRow(i);
|
||||
this.actionDAO.saveActions(id, entity.getActions());
|
||||
return find(id).orElseThrow(DataNotExistException::new);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +97,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
|||
// 保存权限
|
||||
Long id = entity.getId().orElseThrow();
|
||||
this.actionDAO.saveActions(id, entity.getActions());
|
||||
return find(entity.getId().orElseThrow()).orElseThrow(DataNotExistException::new);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,7 +113,7 @@ public class MenuRepositoryImpl extends JdbcRepositorySupport<Menu, Long> implem
|
|||
|
||||
@Override
|
||||
public boolean exists(Long id) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_menu WHERE id = :id AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_menu WHERE id = :id AND deleted = 0 LIMIT 1",
|
||||
"id", id);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -16,7 +15,6 @@ import org.springframework.stereotype.Repository;
|
|||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import xyz.zhouxy.plusone.constant.EntityStatus;
|
||||
import xyz.zhouxy.plusone.exception.DataNotExistException;
|
||||
import xyz.zhouxy.plusone.jdbc.JdbcRepositorySupport;
|
||||
import xyz.zhouxy.plusone.util.AssertResult;
|
||||
|
||||
|
@ -38,7 +36,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
|||
}
|
||||
|
||||
@Override
|
||||
protected final Optional<Role> doFindById(@Nonnull Long id) {
|
||||
protected final Role doFindById(@Nonnull Long id) {
|
||||
return queryForObject("""
|
||||
SELECT "id","name","identifier","status","remarks","version"
|
||||
FROM "sys_role"
|
||||
|
@ -60,7 +58,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
|||
|
||||
@Override
|
||||
public boolean exists(Long id) {
|
||||
return queryExists("SELECT EXISTS (SELECT 1 FROM sys_role WHERE id = :id AND deleted = 0 LIMIT 1)",
|
||||
return queryExists("SELECT 1 FROM sys_role WHERE id = :id AND deleted = 0 LIMIT 1",
|
||||
"id", id);
|
||||
}
|
||||
|
||||
|
@ -76,7 +74,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
|||
AssertResult.updateOneRow(i);
|
||||
this.roleMenuRefDAO.saveRoleMenuRefs(id, entity);
|
||||
this.rolePermissionRefDAO.saveRolePermissionRefs(id, entity);
|
||||
return find(id).orElseThrow(DataNotExistException::new);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,7 +97,7 @@ public class RoleRepositoryImpl extends JdbcRepositorySupport<Role, Long> implem
|
|||
this.roleMenuRefDAO.saveRoleMenuRefs(id, entity);
|
||||
this.rolePermissionRefDAO.clearRolePermissionRefs(entity);
|
||||
this.rolePermissionRefDAO.saveRolePermissionRefs(id, entity);
|
||||
return find(entity.getId().orElseThrow()).orElseThrow(DataNotExistException::new);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue