@ -11,6 +11,7 @@ import com.model2d3d.viewer.back.common.response.SimpleDataResponse;
import com.model2d3d.viewer.back.dao.ex.BasicCompanyMapperExt ;
import com.model2d3d.viewer.back.dao.ex.BasicRoleUserRelationMapperExt ;
import com.model2d3d.viewer.back.dao.ex.BasicUserMapperExt ;
import com.model2d3d.viewer.back.dao.ex.UserBuildingRelationMapperExt ;
import com.model2d3d.viewer.back.dto.user.DeleteUserParam ;
import com.model2d3d.viewer.back.dto.user.ModifyPassword ;
import com.model2d3d.viewer.back.dto.user.OptUserParam ;
@ -28,6 +29,7 @@ import com.model2d3d.viewer.back.vo.company.CompanyPageDTO;
import com.model2d3d.viewer.back.vo.user.UserPageDTO ;
import java.text.MessageFormat ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.List ;
import java.util.Objects ;
@ -72,6 +74,8 @@ public class UserServiceImpl implements UserService {
private MsgLanguageChange msgLanguageChange ;
@Autowired
private BasicCompanyMapperExt basicCompanyMapperExt ;
@Autowired
private UserBuildingRelationMapperExt userBuildingRelationMapperExt ;
@Override
@ -82,7 +86,7 @@ public class UserServiceImpl implements UserService {
param . setLoginName ( param . getUsername ( ) ) ;
// }
// if (!"1".equals(companyId)) {//非顶级账号
param . setCompanyId ( companyId ) ;
// param.setCompanyId(companyId);
// } else if (null == param.getCompanyId()) {//admin账号必须能选择企业归属
// return new SimpleDataResponse(ResponseCode.MSG_ERROR, "companyId is required");
// }
@ -114,6 +118,8 @@ public class UserServiceImpl implements UserService {
insertUserRoleRelation ( userId , currentUnix , basicUser . getId ( ) , param . getRoleId ( ) ) ;
insertUserBuildingRelation ( userId , currentUnix , basicUser . getId ( ) , param . getBuildingIds ( ) ) ;
BasicCompany basicCompany = basicCompanyMapperExt . selectById ( basicUser . getCompanyId ( ) ) ;
//邮箱通知密码
@ -132,6 +138,26 @@ public class UserServiceImpl implements UserService {
}
}
private void insertUserBuildingRelation ( String creatorId , long currentUnix , String userId , List < Long > buildingIds ) {
// 先删除原有的关联关系
if ( userId ! = null ) {
userBuildingRelationMapperExt . delete ( new LambdaQueryWrapper < UserBuildingRelation > ( )
. eq ( UserBuildingRelation : : getUserId , userId ) ) ;
}
// 重新插入关联关系
if ( Objects . nonNull ( userId ) & & CollectionUtils . isNotEmpty ( buildingIds ) ) {
List < UserBuildingRelation > userBuildingRelationList = new ArrayList < > ( ) ;
for ( Long buildingId : buildingIds ) {
UserBuildingRelation userBuildingRelation = new UserBuildingRelation ( ) ;
userBuildingRelation . setBuildingId ( buildingId ) ;
userBuildingRelation . setUserId ( userId ) ;
userBuildingRelation . setCreateTime ( currentUnix ) ;
userBuildingRelationList . add ( userBuildingRelation ) ;
}
userBuildingRelationMapperExt . insert ( userBuildingRelationList ) ;
}
}
private void insertUserRoleRelation ( String creatorId , long currentUnix , String userId , String roleId ) {
// 先删除原有的关联关系
@ -180,11 +206,11 @@ public class UserServiceImpl implements UserService {
// if (StringUtils.isBlank(param.getLoginName())) {
param . setLoginName ( param . getUsername ( ) ) ;
// }
if ( ! "1" . equals ( companyId ) ) { //非顶级账号
param . setCompanyId ( companyId ) ;
} else if ( null = = param . getCompanyId ( ) ) { //admin账号必须能选择企业归属
return new SimpleDataResponse ( ResponseCode . MSG_ERROR , "companyId is required" ) ;
}
// if (!"1".equals(companyId)) { //非顶级账号
// param.setCompanyId(companyId);
// } else if (null == param.getCompanyId()) { //admin账号必须能选择企业归属
// return new SimpleDataResponse(ResponseCode.MSG_ERROR, "companyId is required");
// }
//校验参数
SimpleDataResponse checkResult = checkParam ( param , languageType ) ;
if ( 200 ! = checkResult . getCode ( ) ) {
@ -213,18 +239,21 @@ public class UserServiceImpl implements UserService {
}
long currentUnix = System . currentTimeMillis ( ) ;
BasicUser basicUser = new BasicUser ( ) ;
BeanUtils . copyProperties ( param , basicUser ) ;
basicUser . setId ( param . getUserId ( ) ) ;
basicUser . setModifierId ( userId ) ;
basicUser . setModifyTime ( currentUnix ) ;
// basicUser.setCompanyId(companyId);
if ( StringUtils . isBlank ( param . getMobileNumber ( ) ) ) {
basicUser . setMobileNumber ( "" ) ;
}
basicUserMapperExt . updateById ( basicUser ) ;
insertUserRoleRelation ( userId , currentUnix , basicUser . getId ( ) , param . getRoleId ( ) ) ;
LambdaUpdateWrapper < BasicUser > updateWrapper = new LambdaUpdateWrapper < > ( ) ;
updateWrapper . eq ( BasicUser : : getId , param . getUserId ( ) )
. set ( BasicUser : : getCompanyId , param . getCompanyId ( ) )
. set ( BasicUser : : getUsername , param . getUsername ( ) )
. set ( BasicUser : : getLoginName , param . getLoginName ( ) )
. set ( BasicUser : : getEmail , param . getEmail ( ) )
. set ( BasicUser : : getMobileNumber , param . getMobileNumber ( ) )
. set ( BasicUser : : getModifierId , userId )
. set ( BasicUser : : getModifyTime , currentUnix ) ;
basicUserMapperExt . update ( null , updateWrapper ) ;
insertUserRoleRelation ( userId , currentUnix , param . getUserId ( ) , param . getRoleId ( ) ) ;
insertUserBuildingRelation ( userId , currentUnix , param . getUserId ( ) , param . getBuildingIds ( ) ) ;
return SimpleDataResponse . success ( ) ;
} catch ( Exception e ) {