员工bug fix
This commit is contained in:
parent
e44cf94993
commit
02167b163a
|
|
@ -7,7 +7,7 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class PhoneUtil {
|
||||
public static boolean validator(String phone) {
|
||||
String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
|
||||
String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[0-9]))\\d{8}$";
|
||||
if (phone.length() != 11) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import org.springframework.util.CollectionUtils;
|
|||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
|
|
@ -62,6 +63,9 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
private final PasswordEncoder passwordEncoder;
|
||||
private final UserService userService;
|
||||
|
||||
// 正则表达式:(\u4e00-\u9fa5) 表示匹配一个中文字符,.* 表示匹配零个或多个任意字符
|
||||
private final Pattern pattern = Pattern.compile(".*(\\u4e00-\\u9fa5).*");
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(TbPlussShopStaffQueryCriteria criteria, Pageable pageable){
|
||||
Page<TbPlussShopStaff> page = tbPlussShopStaffRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
|
|
@ -95,6 +99,18 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
if (!PhoneUtil.validator(resources.getPhone())){
|
||||
throw new BadRequestException("手机号格式有误");
|
||||
}
|
||||
if (userRepository.findByUsername(resources.getAccount()) != null) {
|
||||
throw new BadRequestException("员工账号已存在");
|
||||
}
|
||||
|
||||
if (pattern.matcher(resources.getCode()).find()) {
|
||||
throw new BadRequestException("员工编号不能包含中文");
|
||||
}
|
||||
|
||||
if (resources.getRoleId()==null) {
|
||||
throw new BadRequestException("请选择角色");
|
||||
}
|
||||
|
||||
resources.setCreatedAt(Instant.now().toEpochMilli());
|
||||
|
||||
//添加收银系统后台账号
|
||||
|
|
@ -117,11 +133,7 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
|
||||
Set<Role> roles = new HashSet<>();
|
||||
Role role = new Role();
|
||||
if(resources.getRoleId()!=null){
|
||||
role.setId(resources.getRoleId());
|
||||
}else {
|
||||
role.setId(2l);
|
||||
}
|
||||
role.setId(resources.getRoleId());
|
||||
roles.add(role);
|
||||
user.setRoles(roles);
|
||||
|
||||
|
|
@ -130,9 +142,6 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
job.setId(10L);
|
||||
jobs.add(job);
|
||||
user.setJobs(jobs);
|
||||
if (userRepository.findByUsername(user.getUsername()) != null) {
|
||||
throw new BadRequestException("员工账号已存在");
|
||||
}
|
||||
userRepository.save(user);
|
||||
return tbPlussShopStaffMapper.toDto(tbPlussShopStaffRepository.save(resources));
|
||||
}
|
||||
|
|
@ -143,6 +152,10 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
if (StringUtils.isBlank(resources.getPassword())) {
|
||||
resources.setPassword(null);
|
||||
}
|
||||
|
||||
if (pattern.matcher(resources.getCode()).find()) {
|
||||
throw new BadRequestException("员工编号不能包含中文");
|
||||
}
|
||||
TbPlussShopStaff tbPlussShopStaff = tbPlussShopStaffRepository.findById(resources.getId()).orElseGet(TbPlussShopStaff::new);
|
||||
User sysUser = userRepository.findByUsername(tbPlussShopStaff.getAccount());
|
||||
if(!tbPlussShopStaff.getAccount().equals(resources.getAccount())){
|
||||
|
|
@ -150,7 +163,7 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
throw new BadRequestException("员工账号不可重复");
|
||||
}
|
||||
}
|
||||
resources.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
resources.setUpdatedAt(System.currentTimeMillis());
|
||||
ValidationUtil.isNull( tbPlussShopStaff.getId(),"TbPlussShopStaff","id",resources.getId());
|
||||
tbPlussShopStaff.copy(resources);
|
||||
if (StringUtils.isNotBlank(resources.getPassword())) {
|
||||
|
|
@ -210,4 +223,4 @@ public class TbPlussShopStaffServiceImpl implements TbPlussShopStaffService {
|
|||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue