|
@ -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(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 递归列表 |
|
|
* 递归列表 |
|
|
*/ |
|
|
*/ |
|
|