员工账号重复校验

This commit is contained in:
GYJ 2024-11-21 14:30:28 +08:00
parent 7a305e8901
commit 436a38afa7
1 changed files with 30 additions and 23 deletions

View File

@ -104,27 +104,8 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbPlussShopStaffDto create(TbPlussShopStaff resources) {
if (org.apache.commons.lang3.StringUtils.isBlank(resources.getAccount())) {
throw new BadRequestException("员工账号为空");
}
if (userRepository.findByUsername(resources.getShopId()+"@"+resources.getAccount()) != null) {
throw new BadRequestException("员工账号已存在");
}
if (!PhoneUtil.validator(resources.getPhone())){
throw new BadRequestException("手机号格式有误");
}
checkStaffParams(resources);
if (pattern.matcher(resources.getCode()).find()) {
throw new BadRequestException("员工编号不能包含中文");
}
if (resources.getRoleId()==null) {
throw new BadRequestException("请选择角色");
}
if (resources.getMaxDiscountAmount().compareTo(new BigDecimal(100000000L)) > 0) {
throw new BadRequestException("最大优惠金额过大");
}
resources.setCreatedAt(Instant.now().toEpochMilli());
//添加收银系统后台账号
@ -172,9 +153,8 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
resources.setPassword(null);
}
if (pattern.matcher(resources.getCode()).find()) {
throw new BadRequestException("员工编号不能包含中文");
}
checkStaffParams(resources);
TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(resources.getId()).orElseGet(TbPlussShopStaff::new);
User sysUser = userRepository.findByUsername(resources.getShopId()+"@"+tbPlussShopStaff.getAccount());
if(!tbPlussShopStaff.getAccount().equals(resources.getAccount())){
@ -207,6 +187,33 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
Integer.valueOf(resources.getShopId()), resources.getId(), resources.getPermissions());
}
private void checkStaffParams(TbPlussShopStaff resources) {
if (StringUtils.isBlank(resources.getAccount())) {
throw new BadRequestException("员工账号为空");
}
if (userRepository.findByUsername(resources.getShopId()+"@"+resources.getAccount()) != null) {
throw new BadRequestException("员工账号已存在");
}
if (!PhoneUtil.validator(resources.getPhone())){
throw new BadRequestException("手机号格式有误");
}
if (tbPlussShopStaffRepository.queryByAccount(resources.getAccount(),resources.getShopId()) != null) {
throw new BadRequestException("账号已存在");
}
if (pattern.matcher(resources.getCode()).find()) {
throw new BadRequestException("员工编号不能包含中文");
}
if (resources.getRoleId()==null) {
throw new BadRequestException("请选择角色");
}
if (resources.getMaxDiscountAmount().compareTo(new BigDecimal(100000000L)) > 0) {
throw new BadRequestException("最大优惠金额过大");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateStatus(TbPlussShopStaff resources) {