|  |  | 
 |  |  | import com.doumee.biz.system.SystemUserBiz; | 
 |  |  | import com.doumee.core.constants.ResponseStatus; | 
 |  |  | import com.doumee.core.exception.BusinessException; | 
 |  |  | import com.doumee.core.model.LoginUserInfo; | 
 |  |  | import com.doumee.core.utils.Constants; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.system.dto.CreateSystemUserDTO; | 
 |  |  | import com.doumee.dao.system.dto.CreateUserRoleDTO; | 
 |  |  | import com.doumee.dao.system.dto.ResetSystemUserPwdDTO; | 
 |  |  | import com.doumee.dao.system.dto.UpdatePwdDto; | 
 |  |  | import com.doumee.dao.system.dto.*; | 
 |  |  | import com.doumee.dao.system.model.SystemDepartment; | 
 |  |  | import com.doumee.dao.system.model.SystemDepartmentUser; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | 
 |  |  | import com.doumee.service.system.*; | 
 |  |  | import org.apache.commons.lang3.RandomStringUtils; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.apache.shiro.SecurityUtils; | 
 |  |  | import org.springframework.beans.BeanUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | import java.util.Objects; | 
 |  |  |  | 
 |  |  | @Service | 
 |  |  | public class SystemUserBizImpl implements SystemUserBiz { | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public void companyCreateUser(CreateCompanyUserDTO createCompanyUserDTO) { | 
 |  |  |         if(Objects.isNull(createCompanyUserDTO) | 
 |  |  |                 ||StringUtils.isBlank(createCompanyUserDTO.getUserName()) | 
 |  |  |                 ||StringUtils.isBlank(createCompanyUserDTO.getRealName()) | 
 |  |  |                 ||StringUtils.isBlank(createCompanyUserDTO.getPassword()) ){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         SystemUser queryUserDto = new SystemUser(); | 
 |  |  |         queryUserDto.setUsername(createCompanyUserDTO.getUserName()); | 
 |  |  |         queryUserDto.setDeleted(Boolean.FALSE); | 
 |  |  |         SystemUser user = systemUserService.findOne(queryUserDto); | 
 |  |  |         if (user != null) { | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "用户名已存在"); | 
 |  |  |         } | 
 |  |  |         SystemUser systemUser  = new SystemUser(); | 
 |  |  |         BeanUtils.copyProperties(createCompanyUserDTO,systemUser); | 
 |  |  |         systemUser.setCompanyId(loginUserInfo.getCompanyId()); | 
 |  |  |         systemUser.setRealname(createCompanyUserDTO.getRealName()); | 
 |  |  |         systemUser.setUsername(createCompanyUserDTO.getUserName()); | 
 |  |  |         // 生成密码盐 | 
 |  |  |         String salt = RandomStringUtils.randomAlphabetic(6); | 
 |  |  |         // 生成密码 | 
 |  |  |         systemUser.setPassword(Utils.Secure.encryptPassword(systemUser.getPassword(), salt)); | 
 |  |  |         systemUser.setSalt(salt); | 
 |  |  |         Integer userId = systemUserService.create(systemUser); | 
 |  |  |         if(systemUser.getType().equals(Constants.UserType.COMPANY.getKey())){ | 
 |  |  |             SystemUserRole newUserRole = new SystemUserRole(); | 
 |  |  |             newUserRole.setUserId(userId); | 
 |  |  |             newUserRole.setRoleId(createCompanyUserDTO.getRoleId()); | 
 |  |  |             systemUserRoleService.create(newUserRole); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public void companyUpdUser(CreateCompanyUserDTO updCreateCompanyUserDTO) { | 
 |  |  |         if(Objects.isNull(updCreateCompanyUserDTO) | 
 |  |  |                 ||Objects.isNull(updCreateCompanyUserDTO.getId()) | 
 |  |  |                 ||StringUtils.isBlank(updCreateCompanyUserDTO.getRealName())){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         SystemUser systemUser  = systemUserService.findById(updCreateCompanyUserDTO.getId()); | 
 |  |  |         if(Objects.isNull(systemUser)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         systemUser.setRealname(updCreateCompanyUserDTO.getRealName()); | 
 |  |  |         systemUser.setMobile(updCreateCompanyUserDTO.getMobile()); | 
 |  |  |         systemUserService.updateById(systemUser); | 
 |  |  |         if(systemUser.getType().equals(Constants.UserType.COMPANY.getKey())){ | 
 |  |  |             // 删除关联角色 | 
 |  |  |             SystemUserRole deleteDto = new SystemUserRole(); | 
 |  |  |             deleteDto.setUserId(systemUser.getId()); | 
 |  |  |             systemUserRoleService.delete(deleteDto); | 
 |  |  |             SystemUserRole newUserRole = new SystemUserRole(); | 
 |  |  |             newUserRole.setUserId(systemUser.getId()); | 
 |  |  |             newUserRole.setRoleId(updCreateCompanyUserDTO.getRoleId()); | 
 |  |  |             systemUserRoleService.create(newUserRole); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public void updUserStatus(Integer id,Integer status) { | 
 |  |  |  | 
 |  |  |         SystemUser systemUser  = systemUserService.findById(id); | 
 |  |  |         if(Objects.isNull(systemUser)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         systemUser.setStatus(status); | 
 |  |  |         systemUserService.updateById(systemUser); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     public void updPassword(CreateCompanyUserDTO updCreateCompanyUserDTO) { | 
 |  |  |         if(Objects.isNull(updCreateCompanyUserDTO) | 
 |  |  |                 ||Objects.isNull(updCreateCompanyUserDTO.getId()) | 
 |  |  |                 ||StringUtils.isBlank(updCreateCompanyUserDTO.getPassword())){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         SystemUser systemUser  = systemUserService.findById(updCreateCompanyUserDTO.getId()); | 
 |  |  |         if(Objects.isNull(systemUser)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
 |  |  |         } | 
 |  |  |         // 生成密码盐 | 
 |  |  |         String salt = RandomStringUtils.randomAlphabetic(6); | 
 |  |  |         // 生成密码 | 
 |  |  |         systemUser.setPassword(Utils.Secure.encryptPassword(updCreateCompanyUserDTO.getPassword(), salt)); | 
 |  |  |         systemUser.setSalt(salt); | 
 |  |  |         systemUserService.updateById(systemUser); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private <K,V> K getKey(Map<K,V> map,V v){ | 
 |  |  |  |