xiaoyong931011
2022-06-07 7fa0a141a3c88ca90c67c966260bf26f03f255da
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/UserServiceImpl.java
@@ -7,10 +7,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.farmer.cms.common.response.Result;
import com.xcong.farmer.cms.modules.system.dto.AdminAddUserDto;
import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto;
import com.xcong.farmer.cms.modules.system.dto.AdminUpdateUserDto;
import com.xcong.farmer.cms.modules.system.dto.AdminUserDto;
import com.xcong.farmer.cms.modules.system.dto.*;
import com.xcong.farmer.cms.modules.system.entity.*;
import com.xcong.farmer.cms.modules.system.mapper.*;
import com.xcong.farmer.cms.modules.system.service.IUserService;
@@ -28,6 +25,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.*;
@Service
@@ -45,8 +43,13 @@
    @Override
    public Result getUserInPage(AdminUserDto adminUserDto) {
        UserEntity userlogin = LoginUserUtil.getLoginUser();
        Page<AdminUserVo> page = new Page<>(adminUserDto.getPageNum(), adminUserDto.getPageSize());
        UserEntity userEntity = new UserEntity();
        long belongId = userlogin.getBelongId() == null ? 0L : userlogin.getBelongId();
        if(belongId > 0L){
            userEntity.setBelongId(belongId);
        }
        if(StrUtil.isNotEmpty(adminUserDto.getUsername())){
            userEntity.setUsername(adminUserDto.getUsername());
        }
@@ -77,6 +80,7 @@
    @Override
    @Transactional
    public Result addUser(AdminAddUserDto adminAddUserDto) {
        UserEntity userlogin = LoginUserUtil.getLoginUser();
        String username = adminAddUserDto.getUsername();
        if(StrUtil.isEmpty(username)){
            return Result.fail("请输入用户名");
@@ -89,6 +93,10 @@
        if(StrUtil.isEmpty(phone)){
            return Result.fail("请输入联系电话");
        }
        Long belongId = adminAddUserDto.getBelongId() == null ? 0L:adminAddUserDto.getBelongId();
        if(belongId == 0L){
            return Result.fail("请选择所属公司");
        }
        UserEntity userEntity = new UserEntity();
        userEntity.setUsername(username);
        userEntity.setPhone(phone);
@@ -100,6 +108,7 @@
        }
        userEntity.setPassword(SecureUtil.md5(UserEntity.PASSWORD_DEFAULT));
        userEntity.setStatus(UserEntity.STATUS_ENABLE);
        userEntity.setBelongId(belongId);
        int insert = this.baseMapper.insert(userEntity);
        if(insert > 0){
            saveUserRole(roleIds,userEntity.getId());
@@ -230,7 +239,8 @@
    @Override
    public Result userMenu() {
        Long userId = LoginUserUtil.getLoginUser().getId();
        UserEntity loginUser = LoginUserUtil.getLoginUser();
        Long userId = loginUser.getId();
        List<AdminUserMenuVo> adminUserMenuVos = new ArrayList<>();
        QueryWrapper<UserRoleEntity> userRoleQueryWrapper = new QueryWrapper<>();
@@ -314,6 +324,32 @@
        return Result.ok("删除成功");
    }
    @Override
    @Transactional
    public Result updatePassword(AdminUpdatePasswordDto adminUpdatePasswordDto) {
        UserEntity loginUser = LoginUserUtil.getLoginUser();
        Long userId = loginUser.getId();
        UserEntity userEntity =  this.baseMapper.selectById(userId);
        if(ObjectUtil.isEmpty(userEntity)){
            return Result.fail("用户不存在");
        }
        String oldPassword = adminUpdatePasswordDto.getOldPassword();
        if(StrUtil.isEmpty(oldPassword)){
            return Result.fail("请输入原密码");
        }
        String newPassword = adminUpdatePasswordDto.getNewPassword();
        if(StrUtil.isEmpty(newPassword)){
            return Result.fail("请输入新密码");
        }
        String s = SecureUtil.md5(oldPassword);
        if(!userEntity.getPassword().equals(s)){
            return Result.fail("原密码不正确,请联系管理员重置密码");
        }
        userEntity.setPassword(SecureUtil.md5(newPassword));
        this.baseMapper.updateById(userEntity);
        return Result.ok("修改成功");
    }
    private void saveUserRole(String roleIds,Long userId) {
        if (StrUtil.isNotEmpty(roleIds)) {
            String[] roleIdList = roleIds.split(StringPool.COMMA);