|
@@ -15,6 +15,7 @@ import com.bz.smart_city.service.*;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -24,6 +25,7 @@ import java.math.BigInteger;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -722,4 +724,91 @@ public class UserServiceImpl implements UserService {
|
|
|
return userMapper.bindUniqId(phone,uniqId);
|
|
|
|
|
|
}
|
|
|
+ private void updatePlatformUser(User user ){
|
|
|
+ user.setId(user.getId());
|
|
|
+ user.setUpdateBy("admin");
|
|
|
+ user.setUpdateDate(LocalDateTime.now());;
|
|
|
+ userMapper.update(user);
|
|
|
+ }
|
|
|
+ private void addPlatformUser(User user){
|
|
|
+
|
|
|
+
|
|
|
+ user.setPassword("");
|
|
|
+ user.setStatus(1);
|
|
|
+ user.setCreateBy("admin");
|
|
|
+ user.setCreateDate(LocalDateTime.now());
|
|
|
+ user.setUpdateBy("admin");
|
|
|
+ user.setUpdateDate(LocalDateTime.now());
|
|
|
+ user.setIsSuperAdmin(0);
|
|
|
+ userMapper.insertSelective(user);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addPlatformSiteUser(User user,ConfigPlatformUser configPlatformUser){
|
|
|
+ SiteUser siteUser = new SiteUser();
|
|
|
+ BeanUtils.copyProperties(configPlatformUser,siteUser);
|
|
|
+ //siteUser.setSiteId(1);
|
|
|
+ siteUser.setUserId(user.getId());
|
|
|
+ //siteUser.setStatus(1);
|
|
|
+ //siteUser.setIsAdmin(0);
|
|
|
+ //siteUser.setOrganId(-1);
|
|
|
+ // siteUser.setType(3);
|
|
|
+ //siteUser.setCreateBy("admin");
|
|
|
+ siteUser.setCreateDate(LocalDateTime.now());
|
|
|
+ // siteUser.setUpdateBy("admin");
|
|
|
+ siteUser.setUpdateDate(LocalDateTime.now());
|
|
|
+ siteUserMapper.insert(siteUser);
|
|
|
+
|
|
|
+ }
|
|
|
+ private UserRole addPlatformRole(User user,ConfigPlatformUser configPlatformUser){
|
|
|
+ //添加用户角色关系
|
|
|
+ UserRole userRole = new UserRole();
|
|
|
+ BeanUtils.copyProperties(configPlatformUser,userRole);
|
|
|
+ userRole.setUid(user.getId());
|
|
|
+ // userRole.setRid(25);
|
|
|
+ //userRole.setStatus(1);
|
|
|
+ //userRole.setCreateBy("admin");
|
|
|
+ userRole.setCreateDate(LocalDateTime.now());
|
|
|
+ // userRole.setUpdateBy("admin");
|
|
|
+ userRole.setUpdateDate(LocalDateTime.now());
|
|
|
+ userRoleMapper.insert(userRole);
|
|
|
+ return userRole;
|
|
|
+ }
|
|
|
+ private void addPlatformRoleRelation(UserRole userRole,ConfigPlatformUser configPlatformUser){
|
|
|
+ UserRoleProgram userRoleProgram = new UserRoleProgram();
|
|
|
+ BeanUtils.copyProperties(configPlatformUser,userRoleProgram);
|
|
|
+ userRoleProgram.setUserRoleId(userRole.getId());
|
|
|
+ //userRoleProgram.setProgramId(77);
|
|
|
+ // userRoleProgram.setStatus(1);
|
|
|
+ // userRoleProgram.setCreateBy("admin");
|
|
|
+ userRoleProgram.setDateCreate(LocalDateTime.now());
|
|
|
+ //userRoleProgram.setUpdateBy("admin");
|
|
|
+ userRoleProgram.setDateUpdate(LocalDateTime.now());
|
|
|
+ userRoleProgramService.insertSelective(userRoleProgram);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void savePlatformUser(Map<String, Object> args) {
|
|
|
+ String mobilePhone= (String) args.get("mobilePhone");
|
|
|
+ String userName= (String) args.get("username");
|
|
|
+ String uniqId= (String) args.get("uniqId");
|
|
|
+ User userTemp = userMapper.findUserByMobile(mobilePhone);
|
|
|
+ User user = new User();
|
|
|
+ user.setMobilePhone(mobilePhone);
|
|
|
+ user.setUsername(userName);
|
|
|
+ user.setUniqid(uniqId);
|
|
|
+ if (userTemp != null) {
|
|
|
+ user.setId(userTemp.getId());
|
|
|
+ updatePlatformUser(user);
|
|
|
+ }else {
|
|
|
+ //添加用户
|
|
|
+ addPlatformUser(user);
|
|
|
+ ConfigPlatformUser configPlatformUser=userMapper.findPlatformUserConfig((String)args.get("tenantId"));
|
|
|
+ addPlatformSiteUser(user,configPlatformUser);
|
|
|
+ UserRole userRole=addPlatformRole(user,configPlatformUser);
|
|
|
+ addPlatformRoleRelation(userRole,configPlatformUser);
|
|
|
+
|
|
|
+ //添加用户角色关系
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|