|
@@ -1,13 +1,17 @@
|
|
|
package org.jeecg.modules.interlockUser.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
|
+import org.jeecg.common.util.PasswordUtil;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.base.entity.InterlockBase;
|
|
|
+import org.jeecg.modules.base.service.BaseCommonService;
|
|
|
import org.jeecg.modules.base.service.IInterlockBaseService;
|
|
|
import org.jeecg.modules.interlockSystemLimit.entity.InterlockSystemLimit;
|
|
|
import org.jeecg.modules.interlockSystemLimit.service.IInterlockSystemLimitService;
|
|
@@ -19,6 +23,7 @@ import org.jeecg.modules.iotedgeCollectData.entity.IoTEdgeDevices;
|
|
|
import org.jeecg.modules.iotedgeCollectData.mapper.IotedgeCollectDataMapper;
|
|
|
import org.jeecg.modules.iotedgeCollectData.service.IIotedgeCollectDataService;
|
|
|
import org.jeecg.modules.iotedgeCollectData.service.RestClientService;
|
|
|
+import org.jeecg.modules.ssoClient.constants.SSOConstants;
|
|
|
import org.jeecg.modules.system.entity.SysUser;
|
|
|
import org.jeecg.modules.system.entity.SysUserRole;
|
|
|
import org.jeecg.modules.system.mapper.SysUserRoleMapper;
|
|
@@ -29,6 +34,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.Cookie;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.xml.ws.ServiceMode;
|
|
@@ -44,6 +50,9 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class InterlockUserServiceImpl extends ServiceImpl<InterlockUserMapper, InterlockUser> implements IInterlockUserService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private BaseCommonService baseCommonService;
|
|
|
+
|
|
|
@Autowired
|
|
|
@SuppressWarnings("all")
|
|
|
private ISysUserService sysUserService;
|
|
@@ -100,6 +109,15 @@ public class InterlockUserServiceImpl extends ServiceImpl<InterlockUserMapper, I
|
|
|
interlockUser.setRole(interlockUserAdd.getRole());//角色(0管理员1其他角色)
|
|
|
//由于权限表中需要用户id,所以先添加用户表信息后在添加系统权限信息
|
|
|
this.save(interlockUser);
|
|
|
+
|
|
|
+ //邮箱用户不添加系统用户,在第一次登陆的时候添加;普通用户sso不存在新增的时候添加系统用户;普通用户sso存在不添加系统用户,在第一次登陆的时候添加
|
|
|
+ boolean b = addSystemUser(interlockUserAdd);
|
|
|
+ //系统用户添加失败,删除联锁用户,返回添加失败
|
|
|
+ if(!b){
|
|
|
+ this.removeById(interlockUser);
|
|
|
+ return Result.error("用户添加失败!");
|
|
|
+ }
|
|
|
+
|
|
|
String userId = interlockUser.getId();
|
|
|
//创建一个用户权限列表,用来存放系统权限信息 填充权限信息列表
|
|
|
List<InterlockSystemLimit> interlockSystemLimitList = new ArrayList<>(interlockUserAdd.getSystemLimitList());
|
|
@@ -184,6 +202,64 @@ public class InterlockUserServiceImpl extends ServiceImpl<InterlockUserMapper, I
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
+ public boolean addSystemUser(InterlockUserAdd interlockUserAdd){
|
|
|
+ //普通用户
|
|
|
+ if(interlockUserAdd.getInterlockUserType().equals("normal")){
|
|
|
+ //sso账户不存在
|
|
|
+ if(!(interlockUserAdd.getIsExistSSO())){
|
|
|
+ JSONObject addJSONObject = toAddJSONObject(interlockUserAdd.getUsername(), interlockUserAdd.getPassword());
|
|
|
+ return addUser(addJSONObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加系统用户参数,没有角色
|
|
|
+ */
|
|
|
+ private JSONObject toAddJSONObject(String username, String password){
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("workNo", "");
|
|
|
+ jsonObject.put("password", password);
|
|
|
+ jsonObject.put("confirmpassword", password);
|
|
|
+ jsonObject.put("phone", "18888888888");
|
|
|
+ jsonObject.put("selecteddeparts", "");
|
|
|
+ jsonObject.put("selectedroles", "");
|
|
|
+ jsonObject.put("activitiSync", "1");
|
|
|
+ jsonObject.put("departIds", "");
|
|
|
+ jsonObject.put("userIdentity", "1");
|
|
|
+ jsonObject.put("username", username);
|
|
|
+ jsonObject.put("realname", username);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加系统用户
|
|
|
+ */
|
|
|
+ private boolean addUser(JSONObject jsonObject){
|
|
|
+ String selectedRoles = jsonObject.getString("selectedroles");
|
|
|
+ String selectedDeparts = jsonObject.getString("selecteddeparts");
|
|
|
+ try {
|
|
|
+ SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
|
|
|
+ user.setCreateTime(new Date());//设置创建时间
|
|
|
+ String salt = oConvertUtils.randomGen(8);
|
|
|
+ user.setSalt(salt);
|
|
|
+ String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
|
|
|
+ user.setPassword(passwordEncode);
|
|
|
+ user.setStatus(1);
|
|
|
+ user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
+ //用户表字段org_code不能在这里设置他的值
|
|
|
+ user.setOrgCode(null);
|
|
|
+ // 保存用户走一个service 保证事务
|
|
|
+ sysUserService.saveUser(user, selectedRoles, selectedDeparts);
|
|
|
+ baseCommonService.addLog("添加用户,username: " +user.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* author: sl
|
|
|
* version: 1.0
|