| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.qiniu.util.Md5; |
| | | import com.ycl.jxkg.domain.entity.UserEventLog; |
| | | import com.ycl.jxkg.domain.form.UpdatePwdForm; |
| | | import com.ycl.jxkg.enums.RoleEnum; |
| | | import com.ycl.jxkg.enums.UserStatusEnum; |
| | | import com.ycl.jxkg.domain.form.RegisterForm; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.vo.StudentVO; |
| | | import com.ycl.jxkg.enums.general.YesOrNoEnum; |
| | | import com.ycl.jxkg.event.UserEvent; |
| | | import com.ycl.jxkg.exception.BusinessException; |
| | | import com.ycl.jxkg.domain.User; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | | import com.ycl.jxkg.event.OnRegistrationCompleteEvent; |
| | | import com.ycl.jxkg.mapper.UserMapper; |
| | | import com.ycl.jxkg.service.AuthenticationService; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import com.ycl.jxkg.vo.admin.user.UserPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.user.UserPageRequestVO; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.context.ApplicationEventPublisher; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.*; |
| | | |
| | | |
| | | @Service |
| | | public class UserServiceImpl extends BaseServiceImpl<User> implements UserService { |
| | | @RequiredArgsConstructor |
| | | public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService { |
| | | |
| | | private final UserMapper userMapper; |
| | | private final ApplicationEventPublisher eventPublisher; |
| | | |
| | | @Autowired |
| | | public UserServiceImpl(UserMapper userMapper, ApplicationEventPublisher eventPublisher) { |
| | | super(userMapper); |
| | | this.userMapper = userMapper; |
| | | this.eventPublisher = eventPublisher; |
| | | } |
| | | private final AuthenticationService authenticationService; |
| | | |
| | | |
| | | @Override |
| | | public List<User> getUsers() { |
| | | return userMapper.getAllUser(); |
| | | } |
| | | |
| | | @Override |
| | | public User getUserById(Integer id) { |
| | | return userMapper.getUserById(id); |
| | | } |
| | | |
| | | @Override |
| | | public User getUserByUserName(String username) { |
| | | return userMapper.getUserByUserName(username); |
| | | } |
| | | |
| | | @Override |
| | | public int insertByFilter(User record) { |
| | | return super.insertByFilter(record); |
| | | } |
| | | |
| | | @Override |
| | | public int updateByIdFilter(User record) { |
| | | return super.updateByIdFilter(record); |
| | | } |
| | | |
| | | @Override |
| | | public int updateById(User record) { |
| | | return super.updateById(record); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void insertUser(User user) { |
| | | userMapper.insertSelective(user); |
| | | user.setLastUpdatePasswordTime(new Date()); |
| | | userMapper.insert(user); |
| | | eventPublisher.publishEvent(new OnRegistrationCompleteEvent(user)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = BusinessException.class) |
| | | public void insertUsers(List<User> users) { |
| | | users.stream().forEach(item -> { |
| | | item.setLastUpdatePasswordTime(new Date()); |
| | | }); |
| | | userMapper.insertUsers(users); |
| | | throw new BusinessException("test BusinessException roll back"); |
| | | } |
| | |
| | | User changePictureUser = new User(); |
| | | changePictureUser.setId(user.getId()); |
| | | changePictureUser.setImagePath(imagePath); |
| | | userMapper.updateByPrimaryKeySelective(changePictureUser); |
| | | userMapper.updateById(changePictureUser); |
| | | } |
| | | |
| | | @Override |
| | | public void teacherRegister(RegisterForm form) { |
| | | User teacher = new User(); |
| | | BeanUtils.copyProperties(form, teacher); |
| | | teacher.setRole(RoleEnum.ADMIN.getCode()); |
| | | teacher.setUserUuid(UUID.randomUUID().toString()); |
| | | teacher.setLastActiveTime(new Date()); |
| | | teacher.setStatus(UserStatusEnum.Enable.getCode()); |
| | | teacher.setDeleted(0); |
| | | this.insertUser(teacher); |
| | | // 发布注册事件,保存注册日志 |
| | | UserEventLog userEventLog = new UserEventLog(teacher.getId(), teacher.getUserName(), teacher.getRealName(), new Date()); |
| | | userEventLog.setContent("欢迎 " + teacher.getUserName() + " 注册来到江西空管音视频培训系统"); |
| | | eventPublisher.publishEvent(new UserEvent(userEventLog)); |
| | | } |
| | | |
| | | @Override |
| | | public void studentRegister(RegisterForm form) { |
| | | User student = new User(); |
| | | BeanUtils.copyProperties(form, student); |
| | | student.setRole(RoleEnum.ADMIN.getCode()); |
| | | student.setUserUuid(UUID.randomUUID().toString()); |
| | | student.setLastActiveTime(new Date()); |
| | | student.setStatus(UserStatusEnum.Enable.getCode()); |
| | | student.setDeleted(0); |
| | | this.insertUser(student); |
| | | // 发布注册事件,保存注册日志 |
| | | UserEventLog userEventLog = new UserEventLog(student.getId(), student.getUserName(), student.getRealName(), new Date()); |
| | | userEventLog.setContent("欢迎 " + student.getUserName() + " 注册来到江西空管音视频培训系统"); |
| | | eventPublisher.publishEvent(new UserEvent(userEventLog)); |
| | | } |
| | | |
| | | @Override |
| | | public List<StudentVO> classesStudent(Integer classesId) { |
| | | return userMapper.classesStudent(classesId); |
| | | } |
| | | |
| | | @Override |
| | | public void updatePassword(UpdatePwdForm form) { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .eq(User::getId, form.getUserId()) |
| | | .set(User::getPassword, authenticationService.pwdEncode(form.getNewPassword())) |
| | | .set(User::getLastUpdatePasswordTime, new Date()) |
| | | .update(); |
| | | } |
| | | } |