修正员工基础信息编辑
This commit is contained in:
+15
@@ -110,6 +110,21 @@ public class NailArtistInfoDTO {
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 登录手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
private String contactPhone;
|
||||
|
||||
/**
|
||||
* 微信号
|
||||
*/
|
||||
private String wechatId;
|
||||
|
||||
/**
|
||||
* 排班模式摘要
|
||||
*/
|
||||
|
||||
+47
-6
@@ -197,16 +197,11 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
* @return NailArtistInfoDTO result consumed by the caller or returned to the frontend
|
||||
*/
|
||||
public NailArtistInfoDTO saveOrUpdateNailArtistInfo(NailArtistInfoDTO dto) {
|
||||
NailArtistInfoDO entity = new NailArtistInfoDO();
|
||||
BeanUtils.copyProperties(dto, entity);
|
||||
|
||||
NailArtistInfoDO existing = getOne(new LambdaQueryWrapper<NailArtistInfoDO>()
|
||||
.eq(NailArtistInfoDO::getUserId, dto.getUserId())
|
||||
.eq(NailArtistInfoDO::getIsDelete, 0)
|
||||
.last("LIMIT 1"));
|
||||
if (existing != null) {
|
||||
entity.setId(existing.getId());
|
||||
}
|
||||
NailArtistInfoDO entity = existing == null ? buildNewArtistInfoEntity(dto) : mergeArtistInfoEntity(existing, dto);
|
||||
if (entity.getStatus() == null) {
|
||||
entity.setStatus(1);
|
||||
}
|
||||
@@ -232,6 +227,46 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
return convertToDTO(entity);
|
||||
}
|
||||
|
||||
private NailArtistInfoDO buildNewArtistInfoEntity(NailArtistInfoDTO dto) {
|
||||
NailArtistInfoDO entity = new NailArtistInfoDO();
|
||||
BeanUtils.copyProperties(dto, entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private NailArtistInfoDO mergeArtistInfoEntity(NailArtistInfoDO entity, NailArtistInfoDTO dto) {
|
||||
if (dto.getIdentity() != null) {
|
||||
entity.setIdentity(dto.getIdentity());
|
||||
}
|
||||
if (dto.getExperience() != null) {
|
||||
entity.setExperience(dto.getExperience());
|
||||
}
|
||||
if (dto.getSkills() != null) {
|
||||
entity.setSkills(dto.getSkills());
|
||||
}
|
||||
if (dto.getRating() != null) {
|
||||
entity.setRating(dto.getRating());
|
||||
}
|
||||
if (dto.getStatus() != null) {
|
||||
entity.setStatus(dto.getStatus());
|
||||
}
|
||||
if (dto.getColor() != null) {
|
||||
entity.setColor(dto.getColor());
|
||||
}
|
||||
if (dto.getParticipateProduction() != null) {
|
||||
entity.setParticipateProduction(dto.getParticipateProduction());
|
||||
}
|
||||
if (dto.getWorkStartTime() != null) {
|
||||
entity.setWorkStartTime(dto.getWorkStartTime());
|
||||
}
|
||||
if (dto.getWorkEndTime() != null) {
|
||||
entity.setWorkEndTime(dto.getWorkEndTime());
|
||||
}
|
||||
if (dto.getPortfolio() != null) {
|
||||
entity.setPortfolio(dto.getPortfolio());
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
private void syncArtistNickname(NailArtistInfoDTO dto) {
|
||||
if (dto.getUserId() == null || !StringUtils.hasText(dto.getNickname())) {
|
||||
return;
|
||||
@@ -429,6 +464,9 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
dto.setNickname(user.getNickname());
|
||||
dto.setSignature(user.getSignature());
|
||||
dto.setAvatar(resolveAccessibleAvatar(user.getAvatar()));
|
||||
dto.setPhone(user.getPhone());
|
||||
dto.setContactPhone(user.getContactPhone());
|
||||
dto.setWechatId(user.getWechatId());
|
||||
dto.setUserType(user.getType());
|
||||
dto.setUserTypeName(resolveUserTypeName(user.getType()));
|
||||
if (dto.getParticipateProduction() == null) {
|
||||
@@ -457,6 +495,9 @@ public class NailArtistInfoServiceImpl extends ServiceImpl<NailArtistInfoMapper,
|
||||
dto.setNickname(user.getNickname());
|
||||
dto.setSignature(user.getSignature());
|
||||
dto.setAvatar(resolveAccessibleAvatar(user.getAvatar()));
|
||||
dto.setPhone(user.getPhone());
|
||||
dto.setContactPhone(user.getContactPhone());
|
||||
dto.setWechatId(user.getWechatId());
|
||||
dto.setUserType(user.getType());
|
||||
dto.setUserTypeName(resolveUserTypeName(user.getType()));
|
||||
dto.setIdentity("美甲师");
|
||||
|
||||
+84
-1
@@ -35,6 +35,7 @@ import com.xiaowang.jayucloud.core.modules.user.service.UserService;
|
||||
import com.xiaowang.jayucloud.core.modules.user.vo.UserVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -182,10 +183,34 @@ public class AdminManagerController {
|
||||
public Result<NailArtistInfoDTO> saveEmployee(HttpServletRequest request,
|
||||
@RequestBody NailArtistInfoDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (dto.getUserId() == null) {
|
||||
throw new RuntimeException("员工用户ID不能为空");
|
||||
}
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, dto.getUserId(), "无权编辑其他店铺员工");
|
||||
}
|
||||
return Result.success(nailArtistInfoService.saveOrUpdateNailArtistInfo(dto));
|
||||
syncEmployeeUserBasics(dto);
|
||||
return Result.success(nailArtistInfoService.saveOrUpdateNailArtistInfo(buildEmployeeArtistSaveDTO(dto)));
|
||||
}
|
||||
|
||||
@PostMapping("/employees/{userId}/reset-password")
|
||||
@RequirePermission("user:reset_password")
|
||||
@OperationGuard(action = "manager-employee-reset-password", ttlSeconds = 10, message = "密码重置处理中,请勿重复点击")
|
||||
public Result<Boolean> resetEmployeePassword(HttpServletRequest request,
|
||||
@PathVariable Long userId) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
if (!adminScopeHelper.isPlatformAdmin(currentUser)) {
|
||||
adminScopeHelper.ensureUserAccessibleInCurrentShop(currentUser, userId, "无权重置其他店铺员工密码");
|
||||
}
|
||||
UserVO targetUser = userService.getUserById(userId);
|
||||
if (targetUser == null) {
|
||||
throw new RuntimeException("目标员工不存在");
|
||||
}
|
||||
adminScopeHelper.ensureAssignableUserType(currentUser, targetUser.getType());
|
||||
if (!Integer.valueOf(3).equals(targetUser.getType())) {
|
||||
throw new RuntimeException("只能重置员工密码");
|
||||
}
|
||||
return Result.success(userService.resetManagedEmployeePassword(userId, currentUser.getId()));
|
||||
}
|
||||
|
||||
@PostMapping("/employees/users")
|
||||
@@ -318,4 +343,62 @@ public class AdminManagerController {
|
||||
adminScopeHelper.requireShopContext(currentUser);
|
||||
return Result.success(shopService.saveScheduleException(dto));
|
||||
}
|
||||
|
||||
private void syncEmployeeUserBasics(NailArtistInfoDTO dto) {
|
||||
if (!hasEmployeeUserBasicChanges(dto)) {
|
||||
return;
|
||||
}
|
||||
UserDTO userDTO = new UserDTO();
|
||||
if (dto.getNickname() != null) {
|
||||
if (!StringUtils.hasText(dto.getNickname())) {
|
||||
throw new RuntimeException("员工昵称不能为空");
|
||||
}
|
||||
userDTO.setNickname(dto.getNickname().trim());
|
||||
}
|
||||
if (dto.getAvatar() != null) {
|
||||
userDTO.setAvatar(dto.getAvatar().trim());
|
||||
}
|
||||
if (dto.getPhone() != null) {
|
||||
if (!StringUtils.hasText(dto.getPhone())) {
|
||||
throw new RuntimeException("登录手机号不能为空");
|
||||
}
|
||||
userDTO.setPhone(dto.getPhone().trim());
|
||||
}
|
||||
if (dto.getContactPhone() != null) {
|
||||
userDTO.setContactPhone(trimProvided(dto.getContactPhone()));
|
||||
}
|
||||
if (dto.getWechatId() != null) {
|
||||
userDTO.setWechatId(trimProvided(dto.getWechatId()));
|
||||
}
|
||||
boolean updated = userService.updateUser(dto.getUserId(), userDTO);
|
||||
if (!updated) {
|
||||
throw new RuntimeException("员工账号不存在,无法保存基础信息");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasEmployeeUserBasicChanges(NailArtistInfoDTO dto) {
|
||||
return dto.getNickname() != null
|
||||
|| dto.getAvatar() != null
|
||||
|| dto.getPhone() != null
|
||||
|| dto.getContactPhone() != null
|
||||
|| dto.getWechatId() != null;
|
||||
}
|
||||
|
||||
private NailArtistInfoDTO buildEmployeeArtistSaveDTO(NailArtistInfoDTO dto) {
|
||||
NailArtistInfoDTO artistDTO = new NailArtistInfoDTO();
|
||||
artistDTO.setId(dto.getId());
|
||||
artistDTO.setUserId(dto.getUserId());
|
||||
artistDTO.setIdentity(trimProvided(dto.getIdentity()));
|
||||
artistDTO.setExperience(dto.getExperience());
|
||||
artistDTO.setSkills(trimProvided(dto.getSkills()));
|
||||
artistDTO.setRating(dto.getRating());
|
||||
artistDTO.setStatus(dto.getStatus());
|
||||
artistDTO.setColor(trimProvided(dto.getColor()));
|
||||
artistDTO.setPortfolio(trimProvided(dto.getPortfolio()));
|
||||
return artistDTO;
|
||||
}
|
||||
|
||||
private String trimProvided(String value) {
|
||||
return value == null ? null : value.trim();
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -252,6 +252,15 @@ public interface UserService extends IService<UserDO> {
|
||||
*/
|
||||
boolean resetPassword(Long targetUserId, Long currentUserId);
|
||||
|
||||
/**
|
||||
* 重置店务员工密码
|
||||
*
|
||||
* @param targetUserId 目标员工用户ID
|
||||
* @param currentUserId 当前操作用户ID
|
||||
* @return 重置是否成功
|
||||
*/
|
||||
boolean resetManagedEmployeePassword(Long targetUserId, Long currentUserId);
|
||||
|
||||
/**
|
||||
* Run business method `resetPasswordByPhone`.
|
||||
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||
|
||||
+26
@@ -1836,6 +1836,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean resetManagedEmployeePassword(Long targetUserId, Long currentUserId) {
|
||||
UserDO targetUser = userMapper.selectById(targetUserId);
|
||||
if (targetUser == null || Integer.valueOf(1).equals(targetUser.getIsDelete())) {
|
||||
throw new RuntimeException("目标员工不存在");
|
||||
}
|
||||
UserDO currentUser = userMapper.selectById(currentUserId);
|
||||
if (currentUser == null || Integer.valueOf(1).equals(currentUser.getIsDelete())) {
|
||||
throw new RuntimeException("当前用户不存在");
|
||||
}
|
||||
if (!Integer.valueOf(2).equals(currentUser.getType()) && !Integer.valueOf(4).equals(currentUser.getType())) {
|
||||
throw new RuntimeException("当前账号无权重置员工密码");
|
||||
}
|
||||
if (!Integer.valueOf(3).equals(targetUser.getType())) {
|
||||
throw new RuntimeException("只能重置员工密码");
|
||||
}
|
||||
targetUser.setPassword(passwordEncoder.encode(resolveAdminDefaultPassword()));
|
||||
targetUser.setUpdateTime(LocalDateTime.now());
|
||||
boolean updated = userMapper.updateById(targetUser) > 0;
|
||||
if (updated) {
|
||||
userSessionService.revokeAllUserSessions(targetUserId);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user