Browse Source

1、修改部门、用户相关

develop
bobol 5 months ago
parent
commit
a13088afe9
  1. 16
      lzbi-admin/src/main/resources/application-dev.yml
  2. 18
      lzbi-admin/src/main/resources/application-test.yml
  3. 25
      lzbi-common/src/main/java/com/lzbi/common/config/IotServerApiConfig.java
  4. 2
      lzbi-common/src/main/java/com/lzbi/common/core/domain/entity/SysDept.java
  5. 3
      lzbi-common/src/main/java/com/lzbi/common/core/domain/entity/SysUser.java
  6. 1
      lzbi-module/src/main/java/com/lzbi/asset/domain/DcBusiWorkReadConfig.java
  7. 135
      lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java
  8. 101
      lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java

16
lzbi-admin/src/main/resources/application-dev.yml

@ -78,7 +78,7 @@ spring:
datasource:
# 主库数据源
master:
url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&keepAlive=true&autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000
username: luenmei
password: 123456
# url: jdbc:mysql://localhost:3306/lmlz_dcdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
@ -99,7 +99,7 @@ spring:
workDB:
driverClassName: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:postgresql://10.10.10.56:5432/dctestdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&Read_Timeout=120000
url: jdbc:postgresql://10.10.10.56:5432/dctestdb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&Read_Timeout=120000&rewriteBatchedStatements=true&keepAlive=true&autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000
username: postgres
password: 123456
primary: master
@ -157,6 +157,18 @@ iot-server-api:
orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree
# 获取组织资产参数树形结构
paramsValue: ${goal-server.iot}/biz/common/paramsValue
# 新增部门
addDept: ${goal-server.iot}/system/dept
# 修改部门
updateDept: ${goal-server.iot}/system/dept
# 删除部门
deleteDept: ${goal-server.iot}/system/dept
# 新增用户
addUser: ${goal-server.iot}/system/user
# 修改用户
updateUser: ${goal-server.iot}/system/user
# 删除用户
deleteUser: ${goal-server.iot}/system/user
# magic api
magic-server-api:

18
lzbi-admin/src/main/resources/application-test.yml

@ -88,13 +88,13 @@ spring:
# 从库数据源
slave:
# 从数据源开关/默认关闭
url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://10.10.10.56:13306/lzdc_bi_db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&keepAlive=true&autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000
username: luenmei
password: 123456
workDB:
driverClassName: org.postgresql.Driver
#type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:postgresql://10.10.10.59:5432/dcdatabase?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
url: jdbc:postgresql://10.10.10.59:5432/dcdatabase?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&keepAlive=true&autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000
username: postgres
password: 123456
primary: master
@ -146,7 +146,7 @@ wechat:
# 外部服务
goal-server:
# iot平台服务地址
iot: http://10.10.10.56:9010
iot: http://localhost:9010
magic: http://10.10.10.56:9012/magic/api
# IOT服务接口
@ -155,6 +155,18 @@ iot-server-api:
orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree
# 获取组织资产参数树形结构
paramsValue: ${goal-server.iot}/biz/common/paramsValue
# 新增部门
addDept: ${goal-server.iot}/interior/sign/system/dept
# 修改部门
updateDept: ${goal-server.iot}/interior/sign/system/dept
# 删除部门
deleteDept: ${goal-server.iot}/interior/sign/system/dept
# 新增用户
addUser: ${goal-server.iot}/interior/sign/system/user
# 修改用户
updateUser: ${goal-server.iot}/interior/sign/system/user
# 删除用户
deleteUser: ${goal-server.iot}/interior/sign/system/user
# magic api
magic-server-api:

25
lzbi-common/src/main/java/com/lzbi/common/config/IotServerApiConfig.java

@ -17,4 +17,29 @@ public class IotServerApiConfig {
* 获取参数值
*/
private String paramsValue;
/**
* 新增部门
*/
private String addDept;
/**
* 修改部门
*/
private String updateDept;
/**
* 删除部门
*/
private String deleteDept;
/**
* 新增用户
*/
private String addUser;
/**
* 修改用户
*/
private String updateUser;
/**
* 删除用户
*/
private String deleteUser;
}

2
lzbi-common/src/main/java/com/lzbi/common/core/domain/entity/SysDept.java

@ -7,6 +7,7 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
@ -27,6 +28,7 @@ public class SysDept extends BaseEntity
private static final long serialVersionUID = 1L;
/** 部门ID */
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long deptId;
/** 父部门ID */

3
lzbi-common/src/main/java/com/lzbi/common/core/domain/entity/SysUser.java

@ -3,6 +3,8 @@ package com.lzbi.common.core.domain.entity;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.lzbi.common.annotation.Excel;
@ -22,6 +24,7 @@ public class SysUser extends BaseEntity
private static final long serialVersionUID = 1L;
/** 用户ID */
@JsonFormat(shape = JsonFormat.Shape.STRING)
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
private Long userId;

1
lzbi-module/src/main/java/com/lzbi/asset/domain/DcBusiWorkReadConfig.java

@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import com.lzbi.common.annotation.Excel;
import com.lzbi.module.base.BaseModuleEntity;
import lombok.experimental.Accessors;

135
lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java

@ -1,14 +1,10 @@
package com.lzbi.system.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.lzbi.common.annotation.DataScope;
import com.lzbi.common.config.IotServerApiConfig;
import com.lzbi.common.constant.UserConstants;
import com.lzbi.common.core.domain.TreeSelect;
import com.lzbi.common.core.domain.entity.SysDept;
@ -22,20 +18,45 @@ import com.lzbi.common.utils.spring.SpringUtils;
import com.lzbi.system.mapper.SysDeptMapper;
import com.lzbi.system.mapper.SysRoleMapper;
import com.lzbi.system.service.ISysDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* 部门管理 服务实现
*
* @author ruoyi
*/
@Slf4j
@Service
public class SysDeptServiceImpl implements ISysDeptService {
// 雪花算法
private static final Snowflake snowflake = IdUtil.getSnowflake(1, 1);
@Autowired
private SysDeptMapper deptMapper;
@Autowired
private SysRoleMapper roleMapper;
@Autowired
private IotServerApiConfig iotServerApiConfig;
@Autowired
private RestTemplate restTemplate;
/**
* 查询部门管理数据
*
@ -202,14 +223,20 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int insertDept(SysDept dept) {
long deptId = snowflake.nextId();
dept.setDeptId(deptId);
SysDept info = deptMapper.selectDeptById(dept.getParentId());
// 如果父节点不为正常状态,则不允许新增子节点
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
throw new ServiceException("部门停用,不允许新增");
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.insertDept(dept);
int i = deptMapper.insertDept(dept);
// 调用IOT接口同步数据
this.insertIotDept(dept);
return i;
}
/**
@ -219,6 +246,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int updateDept(SysDept dept) {
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
@ -247,13 +275,15 @@ public class SysDeptServiceImpl implements ISysDeptService {
dept.setAllName(dept.getShortName());
updateDeptChildrenNew(dept.getDeptId(), newAllName, oldAllName);
}
int result = deptMapper.updateDept(dept);
int i = deptMapper.updateDept(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals("0", dept.getAncestors())) {
// 如果该部门是启用状态,则启用该部门的所有上级部门
updateParentDeptStatusNormal(dept);
}
return result;
// 调用IOT接口同步数据
this.updateIotDept(dept);
return i;
}
/**
@ -312,22 +342,95 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteDeptById(Long deptId) {
return deptMapper.deleteDeptById(deptId);
int i = deptMapper.deleteDeptById(deptId);
// 调用IOT接口同步数据
this.deleteIotDept(deptId);
return i;
}
private void insertIotDept(SysDept dept) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(dept), headers);
String result = restTemplate.postForObject(iotServerApiConfig.getAddDept(), entity, String.class);
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("to iot server insert dept error");
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (null == jsonObject) {
throw new RuntimeException("to iot server insert dept error");
} else {
if (jsonObject.getInteger("code") != 200) {
String msg = String.format("to iot server insert dept error, %s", result);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
log.info("to iot server insert dept success");
}
private void updateIotDept(SysDept dept) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(dept), headers);
ResponseEntity<String> exchange = restTemplate.exchange(iotServerApiConfig.getUpdateDept(), HttpMethod.PUT, entity, String.class);
String result = exchange.getBody();
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("to iot server update dept error");
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (null == jsonObject) {
throw new RuntimeException("to iot server update dept error");
} else {
if (jsonObject.getInteger("code") != 200) {
String msg = String.format("to iot server update dept error, %s", result);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
log.info("to iot server update dept success");
}
private void deleteIotDept(Long deptId) {
ResponseEntity<String> exchange = restTemplate.exchange(iotServerApiConfig.getDeleteDept() + "/" + deptId, HttpMethod.DELETE, null, String.class);
String result = exchange.getBody();
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("to iot server delete dept error");
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (null == jsonObject) {
throw new RuntimeException("to iot server delete dept error");
} else {
if (jsonObject.getInteger("code") != 200) {
String msg = String.format("to iot server delete dept error, %s", result);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
log.info("to iot server delete dept success");
}
@Override
public List<SysDept> selectOrg(Long parentId){
public List<SysDept> selectOrg(Long parentId) {
return deptMapper.selectOrg(parentId);
}
@Override
public List<SysDept> selectCompany(Long parentId){
public List<SysDept> selectCompany(Long parentId) {
return deptMapper.selectCompany(parentId);
}
@Override
//获取所有部门的hash映射,便于查询(key :depid,value:deptName)
public HashMap selectDeptMap(){
//获取所有部门的hash映射,便于查询(key :depid,value:deptName)
public HashMap selectDeptMap() {
return deptMapper.selectDeptMap();
}
/**
* 递归列表
*/

101
lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java

@ -4,9 +4,16 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.Validator;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.lzbi.common.config.IotServerApiConfig;
import com.lzbi.common.core.domain.entity.SysDept;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@ -29,6 +36,7 @@ import com.lzbi.system.mapper.SysUserPostMapper;
import com.lzbi.system.mapper.SysUserRoleMapper;
import com.lzbi.system.service.ISysConfigService;
import com.lzbi.system.service.ISysUserService;
import org.springframework.web.client.RestTemplate;
/**
* 用户 业务层处理
@ -40,6 +48,9 @@ public class SysUserServiceImpl implements ISysUserService
{
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
// 雪花算法
private static final Snowflake snowflake = IdUtil.getSnowflake(1, 2);
@Autowired
private SysUserMapper userMapper;
@ -61,6 +72,12 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired
protected Validator validator;
@Autowired
private IotServerApiConfig iotServerApiConfig;
@Autowired
private RestTemplate restTemplate;
/**
* 根据条件分页查询用户列表
*
@ -253,15 +270,19 @@ public class SysUserServiceImpl implements ISysUserService
* @return 结果
*/
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public int insertUser(SysUser user)
{
long userId = snowflake.nextId();
user.setUserId(userId);
// 新增用户信息
int rows = userMapper.insertUser(user);
// 新增用户岗位关联
insertUserPost(user);
// 新增用户与角色管理
insertUserRole(user);
// 向IOT接口同步数据
this.insertIotUser(user);
return rows;
}
@ -296,7 +317,10 @@ public class SysUserServiceImpl implements ISysUserService
userPostMapper.deleteUserPostByUserId(userId);
// 新增用户与岗位管理
insertUserPost(user);
return userMapper.updateUser(user);
int i = userMapper.updateUser(user);
// 向IOT服务同步数据
this.updateIotUser(user);
return i;
}
/**
@ -455,7 +479,7 @@ public class SysUserServiceImpl implements ISysUserService
* @return 结果
*/
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public int deleteUserByIds(Long[] userIds)
{
for (Long userId : userIds)
@ -467,7 +491,10 @@ public class SysUserServiceImpl implements ISysUserService
userRoleMapper.deleteUserRole(userIds);
// 删除用户与岗位关联
userPostMapper.deleteUserPost(userIds);
return userMapper.deleteUserByIds(userIds);
int i = userMapper.deleteUserByIds(userIds);
// 向IOT服务同步数据
this.deleteIotUser(userIds);
return i;
}
/**
@ -546,4 +573,70 @@ public class SysUserServiceImpl implements ISysUserService
public SysUser selectUserByPhonenumber(String phone) {
return userMapper.selectUserByPhonenumber(phone);
}
private void insertIotUser(SysUser user) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(user), headers);
String result = restTemplate.postForObject(iotServerApiConfig.getAddUser(), entity, String.class);
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("to iot server insert user error");
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (null == jsonObject) {
throw new RuntimeException("to iot server insert user error");
} else {
if (jsonObject.getInteger("code") != 200) {
String msg = String.format("to iot server insert user error, %s", result);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
log.info("to iot server insert user success");
}
private void updateIotUser(SysUser user) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(user), headers);
ResponseEntity<String> exchange = restTemplate.exchange(iotServerApiConfig.getUpdateUser(), HttpMethod.PUT, entity, String.class);
String result = exchange.getBody();
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("to iot server update user error");
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (null == jsonObject) {
throw new RuntimeException("to iot server update user error");
} else {
if (jsonObject.getInteger("code") != 200) {
String msg = String.format("to iot server update user error, %s", result);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
log.info("to iot server update user success");
}
private void deleteIotUser(Long[] userIds) {
String url = iotServerApiConfig.getDeleteUser() + "/" + StringUtils.joinWith(",", userIds);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.DELETE, null, String.class);
String result = exchange.getBody();
if (StringUtils.isEmpty(result)) {
throw new RuntimeException("to iot server update user error");
} else {
JSONObject jsonObject = JSONObject.parseObject(result);
if (null == jsonObject) {
throw new RuntimeException("to iot server update user error");
} else {
if (jsonObject.getInteger("code") != 200) {
String msg = String.format("to iot server update user error, %s", result);
log.error(msg);
throw new RuntimeException(msg);
}
}
}
log.info("to iot server delete user success");
}
}

Loading…
Cancel
Save