Browse Source

1、修改部门、用户相关

develop
bobol 7 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: datasource:
# 主库数据源 # 主库数据源
master: 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 username: luenmei
password: 123456 password: 123456
# url: jdbc:mysql://localhost:3306/lmlz_dcdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true # 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: workDB:
driverClassName: org.postgresql.Driver driverClassName: org.postgresql.Driver
type: com.alibaba.druid.pool.DruidDataSource 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 username: postgres
password: 123456 password: 123456
primary: master primary: master
@ -157,6 +157,18 @@ iot-server-api:
orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree
# 获取组织资产参数树形结构 # 获取组织资产参数树形结构
paramsValue: ${goal-server.iot}/biz/common/paramsValue 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 api
magic-server-api: magic-server-api:

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

@ -88,13 +88,13 @@ spring:
# 从库数据源 # 从库数据源
slave: 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 username: luenmei
password: 123456 password: 123456
workDB: workDB:
driverClassName: org.postgresql.Driver driverClassName: org.postgresql.Driver
#type: com.alibaba.druid.pool.DruidDataSource #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 username: postgres
password: 123456 password: 123456
primary: master primary: master
@ -146,7 +146,7 @@ wechat:
# 外部服务 # 外部服务
goal-server: goal-server:
# iot平台服务地址 # iot平台服务地址
iot: http://10.10.10.56:9010 iot: http://localhost:9010
magic: http://10.10.10.56:9012/magic/api magic: http://10.10.10.56:9012/magic/api
# IOT服务接口 # IOT服务接口
@ -155,6 +155,18 @@ iot-server-api:
orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree
# 获取组织资产参数树形结构 # 获取组织资产参数树形结构
paramsValue: ${goal-server.iot}/biz/common/paramsValue 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 api
magic-server-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 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.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -27,6 +28,7 @@ public class SysDept extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 部门ID */ /** 部门ID */
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long deptId; private Long deptId;
/** 父部门ID */ /** 父部门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.Date;
import java.util.List; import java.util.List;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.lzbi.common.annotation.Excel; import com.lzbi.common.annotation.Excel;
@ -22,6 +24,7 @@ public class SysUser extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 用户ID */ /** 用户ID */
@JsonFormat(shape = JsonFormat.Shape.STRING)
@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
private Long userId; 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 com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import com.lzbi.common.annotation.Excel;
import com.lzbi.module.base.BaseModuleEntity; import com.lzbi.module.base.BaseModuleEntity;
import lombok.experimental.Accessors; 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; package com.lzbi.system.service.impl;
import java.util.ArrayList; import cn.hutool.core.lang.Snowflake;
import java.util.HashMap; import cn.hutool.core.util.IdUtil;
import java.util.Iterator; import com.alibaba.fastjson2.JSONObject;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lzbi.common.annotation.DataScope; import com.lzbi.common.annotation.DataScope;
import com.lzbi.common.config.IotServerApiConfig;
import com.lzbi.common.constant.UserConstants; import com.lzbi.common.constant.UserConstants;
import com.lzbi.common.core.domain.TreeSelect; import com.lzbi.common.core.domain.TreeSelect;
import com.lzbi.common.core.domain.entity.SysDept; 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.SysDeptMapper;
import com.lzbi.system.mapper.SysRoleMapper; import com.lzbi.system.mapper.SysRoleMapper;
import com.lzbi.system.service.ISysDeptService; 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 * @author ruoyi
*/ */
@Slf4j
@Service @Service
public class SysDeptServiceImpl implements ISysDeptService { public class SysDeptServiceImpl implements ISysDeptService {
// 雪花算法
private static final Snowflake snowflake = IdUtil.getSnowflake(1, 1);
@Autowired @Autowired
private SysDeptMapper deptMapper; private SysDeptMapper deptMapper;
@Autowired @Autowired
private SysRoleMapper roleMapper; private SysRoleMapper roleMapper;
@Autowired
private IotServerApiConfig iotServerApiConfig;
@Autowired
private RestTemplate restTemplate;
/** /**
* 查询部门管理数据 * 查询部门管理数据
* *
@ -202,14 +223,20 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int insertDept(SysDept dept) { public int insertDept(SysDept dept) {
long deptId = snowflake.nextId();
dept.setDeptId(deptId);
SysDept info = deptMapper.selectDeptById(dept.getParentId()); SysDept info = deptMapper.selectDeptById(dept.getParentId());
// 如果父节点不为正常状态,则不允许新增子节点 // 如果父节点不为正常状态,则不允许新增子节点
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
throw new ServiceException("部门停用,不允许新增"); throw new ServiceException("部门停用,不允许新增");
} }
dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); 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 结果 * @return 结果
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int updateDept(SysDept dept) { public int updateDept(SysDept dept) {
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
@ -247,13 +275,15 @@ public class SysDeptServiceImpl implements ISysDeptService {
dept.setAllName(dept.getShortName()); dept.setAllName(dept.getShortName());
updateDeptChildrenNew(dept.getDeptId(), newAllName, oldAllName); 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()) if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals("0", dept.getAncestors())) { && !StringUtils.equals("0", dept.getAncestors())) {
// 如果该部门是启用状态,则启用该部门的所有上级部门 // 如果该部门是启用状态,则启用该部门的所有上级部门
updateParentDeptStatusNormal(dept); updateParentDeptStatusNormal(dept);
} }
return result; // 调用IOT接口同步数据
this.updateIotDept(dept);
return i;
} }
/** /**
@ -312,22 +342,95 @@ public class SysDeptServiceImpl implements ISysDeptService {
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int deleteDeptById(Long deptId) { 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 @Override
public List<SysDept> selectOrg(Long parentId){ public List<SysDept> selectOrg(Long parentId) {
return deptMapper.selectOrg(parentId); return deptMapper.selectOrg(parentId);
} }
@Override @Override
public List<SysDept> selectCompany(Long parentId){ public List<SysDept> selectCompany(Long parentId) {
return deptMapper.selectCompany(parentId); return deptMapper.selectCompany(parentId);
} }
@Override @Override
//获取所有部门的hash映射,便于查询(key :depid,value:deptName) //获取所有部门的hash映射,便于查询(key :depid,value:deptName)
public HashMap selectDeptMap(){ public HashMap selectDeptMap() {
return deptMapper.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.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.validation.Validator; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; 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.mapper.SysUserRoleMapper;
import com.lzbi.system.service.ISysConfigService; import com.lzbi.system.service.ISysConfigService;
import com.lzbi.system.service.ISysUserService; 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 Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
// 雪花算法
private static final Snowflake snowflake = IdUtil.getSnowflake(1, 2);
@Autowired @Autowired
private SysUserMapper userMapper; private SysUserMapper userMapper;
@ -61,6 +72,12 @@ public class SysUserServiceImpl implements ISysUserService
@Autowired @Autowired
protected Validator validator; protected Validator validator;
@Autowired
private IotServerApiConfig iotServerApiConfig;
@Autowired
private RestTemplate restTemplate;
/** /**
* 根据条件分页查询用户列表 * 根据条件分页查询用户列表
* *
@ -253,15 +270,19 @@ public class SysUserServiceImpl implements ISysUserService
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public int insertUser(SysUser user) public int insertUser(SysUser user)
{ {
long userId = snowflake.nextId();
user.setUserId(userId);
// 新增用户信息 // 新增用户信息
int rows = userMapper.insertUser(user); int rows = userMapper.insertUser(user);
// 新增用户岗位关联 // 新增用户岗位关联
insertUserPost(user); insertUserPost(user);
// 新增用户与角色管理 // 新增用户与角色管理
insertUserRole(user); insertUserRole(user);
// 向IOT接口同步数据
this.insertIotUser(user);
return rows; return rows;
} }
@ -296,7 +317,10 @@ public class SysUserServiceImpl implements ISysUserService
userPostMapper.deleteUserPostByUserId(userId); userPostMapper.deleteUserPostByUserId(userId);
// 新增用户与岗位管理 // 新增用户与岗位管理
insertUserPost(user); 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 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional(rollbackFor = Exception.class)
public int deleteUserByIds(Long[] userIds) public int deleteUserByIds(Long[] userIds)
{ {
for (Long userId : userIds) for (Long userId : userIds)
@ -467,7 +491,10 @@ public class SysUserServiceImpl implements ISysUserService
userRoleMapper.deleteUserRole(userIds); userRoleMapper.deleteUserRole(userIds);
// 删除用户与岗位关联 // 删除用户与岗位关联
userPostMapper.deleteUserPost(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) { public SysUser selectUserByPhonenumber(String phone) {
return userMapper.selectUserByPhonenumber(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