|
|
@@ -9,13 +9,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.backstage.api.RemotePtParameterService;
|
|
|
import org.dromara.common.core.constant.CacheNames;
|
|
|
+import org.dromara.common.core.constant.CloudMqEventConstants;
|
|
|
import org.dromara.common.core.constant.UserConstants;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.core.utils.TreeBuildUtils;
|
|
|
+import org.dromara.common.message.kafka.domain.KafkaHeader;
|
|
|
+import org.dromara.common.message.kafka.domain.KafkaMessage;
|
|
|
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
|
|
import org.dromara.common.redis.utils.CacheUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
@@ -27,6 +32,7 @@ import org.dromara.system.domain.vo.SysDeptVo;
|
|
|
import org.dromara.system.mapper.SysDeptMapper;
|
|
|
import org.dromara.system.mapper.SysRoleMapper;
|
|
|
import org.dromara.system.mapper.SysUserMapper;
|
|
|
+import org.dromara.system.mq.KafkaNormalProducer;
|
|
|
import org.dromara.system.service.ISysDeptService;
|
|
|
import org.dromara.system.service.IUserDeptService;
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
@@ -46,11 +52,14 @@ import java.util.List;
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
-
|
|
|
private final SysDeptMapper baseMapper;
|
|
|
private final SysRoleMapper roleMapper;
|
|
|
private final SysUserMapper userMapper;
|
|
|
private final IUserDeptService userDeptService;
|
|
|
+ private final KafkaNormalProducer kafkaNormalProducer;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private final RemotePtParameterService remotePtParameterService;
|
|
|
|
|
|
/**
|
|
|
* 查询部门管理数据
|
|
|
@@ -106,10 +115,10 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
return CollUtil.newArrayList();
|
|
|
}
|
|
|
return TreeBuildUtils.build(depts, (dept, tree) ->
|
|
|
- tree.setId(dept.getDeptId())
|
|
|
- .setParentId(dept.getParentId())
|
|
|
- .setName(dept.getDeptName())
|
|
|
- .setWeight(dept.getOrderNum()));
|
|
|
+ tree.setId(dept.getDeptId())
|
|
|
+ .setParentId(dept.getParentId())
|
|
|
+ .setName(dept.getDeptName())
|
|
|
+ .setWeight(dept.getOrderNum()));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -138,7 +147,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
return null;
|
|
|
}
|
|
|
SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
|
|
- .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
|
|
+ .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
|
|
dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
|
|
|
return dept;
|
|
|
}
|
|
|
@@ -152,9 +161,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public List<SysDeptVo> selectDeptByIds(List<Long> deptIds) {
|
|
|
return baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
|
|
|
- .select(SysDept::getDeptId, SysDept::getDeptName)
|
|
|
- .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
- .in(CollUtil.isNotEmpty(deptIds), SysDept::getDeptId, deptIds));
|
|
|
+ .select(SysDept::getDeptId, SysDept::getDeptName)
|
|
|
+ .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
+ .in(CollUtil.isNotEmpty(deptIds), SysDept::getDeptId, deptIds));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -184,8 +193,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public long selectNormalChildrenDeptById(Long deptId) {
|
|
|
return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
- .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
+ .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
+ .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -197,7 +206,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public boolean hasChildByDeptId(Long deptId) {
|
|
|
return baseMapper.exists(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getParentId, deptId));
|
|
|
+ .eq(SysDept::getParentId, deptId));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -209,7 +218,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public boolean checkDeptExistUser(Long deptId) {
|
|
|
return userMapper.exists(new LambdaQueryWrapper<SysUser>()
|
|
|
- .eq(SysUser::getDeptId, deptId));
|
|
|
+ .eq(SysUser::getDeptId, deptId));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -221,9 +230,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public boolean checkDeptNameUnique(SysDeptBo dept) {
|
|
|
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getDeptName, dept.getDeptName())
|
|
|
- .eq(SysDept::getParentId, dept.getParentId())
|
|
|
- .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
|
|
|
+ .eq(SysDept::getDeptName, dept.getDeptName())
|
|
|
+ .eq(SysDept::getParentId, dept.getParentId())
|
|
|
+ .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
|
|
|
return !exist;
|
|
|
}
|
|
|
|
|
|
@@ -269,6 +278,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
int count = baseMapper.insert(dept);
|
|
|
if (count > 0) {
|
|
|
bo.setDeptId(dept.getDeptId());
|
|
|
+
|
|
|
}
|
|
|
return count;
|
|
|
}
|
|
|
@@ -312,10 +322,11 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
}
|
|
|
int result = baseMapper.updateById(dept);
|
|
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
|
|
|
- && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
|
|
|
+ && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
|
|
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
|
|
updateParentDeptStatusNormal(dept);
|
|
|
}
|
|
|
+ sendCloudConsume(baseMapper.selectVoById(dept.getDeptId()));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -328,8 +339,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
String ancestors = dept.getAncestors();
|
|
|
Long[] deptIds = Convert.toLongArray(ancestors);
|
|
|
baseMapper.update(null, new LambdaUpdateWrapper<SysDept>()
|
|
|
- .set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
- .in(SysDept::getDeptId, Arrays.asList(deptIds)));
|
|
|
+ .set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
|
|
|
+ .in(SysDept::getDeptId, Arrays.asList(deptIds)));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -341,7 +352,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
*/
|
|
|
private void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
|
|
|
List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
|
|
- .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
+ .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
|
|
|
List<SysDept> list = new ArrayList<>();
|
|
|
for (SysDept child : children) {
|
|
|
SysDept dept = new SysDept();
|
|
|
@@ -375,9 +386,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
return CollUtil.newArrayList(deptId);
|
|
|
}
|
|
|
return baseMapper.selectList(Wrappers.lambdaQuery(SysDept.class)
|
|
|
- .select(SysDept::getDeptId)
|
|
|
- .eq(SysDept::getParentId, deptId).or().eq(SysDept::getDeptId, deptId).or().likeRight(SysDept::getAncestors,
|
|
|
- sysDeptVo.getAncestors() + "," + deptId)
|
|
|
+ .select(SysDept::getDeptId)
|
|
|
+ .eq(SysDept::getParentId, deptId).or().eq(SysDept::getDeptId, deptId).or().likeRight(SysDept::getAncestors,
|
|
|
+ sysDeptVo.getAncestors() + "," + deptId)
|
|
|
).stream().map(SysDept::getDeptId).toList();
|
|
|
}
|
|
|
|
|
|
@@ -394,8 +405,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public SysDeptVo selectDeptByParentIdAndName(Long parentId, String deptName) {
|
|
|
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
|
|
- .eq(SysDept::getParentId, parentId)
|
|
|
- .eq(SysDept::getDeptName, deptName));
|
|
|
+ .eq(SysDept::getParentId, parentId)
|
|
|
+ .eq(SysDept::getDeptName, deptName));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -425,11 +436,28 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public List<SysDeptVo> selectDoingClass(Date doingDate) {
|
|
|
return baseMapper.selectVoList(new LambdaQueryWrapper<SysDept>()
|
|
|
- .le(SysDept::getCheckDate, doingDate).ge(SysDept::getEndDate, doingDate));
|
|
|
+ .le(SysDept::getCheckDate, doingDate).ge(SysDept::getEndDate, doingDate));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Boolean updateCheckInStatus(Long deptId, Long userId) {
|
|
|
return userDeptService.setCheckInStatus(deptId, userId);
|
|
|
}
|
|
|
+
|
|
|
+ private void sendCloudConsume(SysDeptVo vo) {
|
|
|
+ String pushData = remotePtParameterService.getPtParameterByKey("PUSH_MQ_DATA");
|
|
|
+ if (ObjectUtil.isNotEmpty(pushData) && ObjectUtil.equals(pushData, "1")) {
|
|
|
+ KafkaMessage<SysDeptVo> message = new KafkaMessage<>();
|
|
|
+ KafkaHeader header = message.getHeader();
|
|
|
+ header.setTimestamp(System.currentTimeMillis());
|
|
|
+ header.setEventId(CloudMqEventConstants.DEPT);
|
|
|
+ header.setEventType(CloudMqEventConstants.DEPT);
|
|
|
+ header.setSender(CloudMqEventConstants.SENDER);
|
|
|
+
|
|
|
+ message.setHeader(header);
|
|
|
+ message.setBody(vo);
|
|
|
+
|
|
|
+ kafkaNormalProducer.sendKafkaMessage(CloudMqEventConstants.TOPIC, message);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|