feat: 一些调整

This commit is contained in:
曹鹏飞 2025-02-25 14:08:07 +08:00
parent 3a3220d7d3
commit d0e6a54bf0
9 changed files with 84 additions and 38 deletions

View File

@ -29,14 +29,6 @@ public class SSEController extends ControllerBase {
@GetMapping(value = "connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE) @GetMapping(value = "connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
@ApiMark(moduleName = "连接", apiName = "SSE", isPublic = true) @ApiMark(moduleName = "连接", apiName = "SSE", isPublic = true)
public SseEmitter connect(@RequestParam String userId) { public SseEmitter connect(@RequestParam String userId) {
SseEmitter sse = sseManagerService.connect(Integer.valueOf(userId)); return sseManagerService.connect(Integer.valueOf(userId));
// try {
// sse.send("您已连接");
// } catch (IOException e) {
// log.error("sse发送数据出错", e);
// sse.complete();
// throw new NflgException(STATE.BusinessError, "sse发送数据出错");
// }
return sse;
} }
} }

View File

@ -527,7 +527,7 @@ public class TicketController extends ControllerBase {
} }
} }
if (CollectionUtil.isNotEmpty(notReadeds)) { if (CollectionUtil.isNotEmpty(notReadeds)) {
redisTemplate.opsForSet().add(key, notReadeds.toArray(String[]::new)); redisTemplate.opsForSet().add(key, notReadeds.stream().toArray(String[]::new));
vo.setNotReadCount(notReadeds.size()); vo.setNotReadCount(notReadeds.size());
vo.setFirstMessageId(notReadeds.iterator().next()); vo.setFirstMessageId(notReadeds.iterator().next());
} }

View File

@ -4,6 +4,7 @@ import com.nflg.mobilebroken.repository.entity.TBaseDepartment;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
import java.util.Objects;
@Data @Data
public class BaseDepartmentVO extends TBaseDepartment { public class BaseDepartmentVO extends TBaseDepartment {
@ -12,4 +13,17 @@ public class BaseDepartmentVO extends TBaseDepartment {
* 子级 * 子级
*/ */
private List<BaseDepartmentVO> children; private List<BaseDepartmentVO> children;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BaseDepartmentVO that = (BaseDepartmentVO) o;
return Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
} }

View File

@ -7,15 +7,13 @@ import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
import com.nflg.mobilebroken.admin.pojo.vo.BaseDepartmentVO; import com.nflg.mobilebroken.admin.pojo.vo.BaseDepartmentVO;
import com.nflg.mobilebroken.common.pojo.ApiResult; import com.nflg.mobilebroken.common.pojo.ApiResult;
import com.nflg.mobilebroken.common.pojo.PageData; import com.nflg.mobilebroken.common.pojo.PageData;
import com.nflg.mobilebroken.common.util.PageUtil;
import com.nflg.mobilebroken.repository.entity.TBaseDepartment; import com.nflg.mobilebroken.repository.entity.TBaseDepartment;
import com.nflg.mobilebroken.repository.service.ITBaseDepartmentService; import com.nflg.mobilebroken.repository.service.ITBaseDepartmentService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -26,29 +24,68 @@ public class AdminDepartmentService {
ITBaseDepartmentService departmentService; ITBaseDepartmentService departmentService;
public ApiResult<PageData<BaseDepartmentVO>> getList(DepartmentQuery query){ public ApiResult<PageData<BaseDepartmentVO>> getList(DepartmentQuery query){
Page<TBaseDepartment> result = departmentService.selectListByPage(query); Page<TBaseDepartment> result = departmentService.selectListByPage(query);
// List<BaseDepartmentVO> dataResult = Convert.toList(BaseDepartmentVO.class, result.getRecords());
//// if(StrUtil.isNotBlank(query.getDeptCodeOrName())){
//// List<BaseDepartmentVO> alldept = Convert.toList(BaseDepartmentVO.class,departmentService.lambdaQuery().eq(TBaseDepartment::getDataValidStatus,1).list()) ;
//// Map<Long, BaseDepartmentVO> collect = alldept.stream().collect(Collectors.toMap(BaseDepartmentVO::getId, Function.identity()));
//// List<BaseDepartmentVO> allParents=new ArrayList<>();
//// for (BaseDepartmentVO data:dataResult){
//// allParents.addAll(getAllParents(data, collect)) ;
//// }
//// allParents.addAll(dataResult);
//// return ApiResult.success(buildTree(allParents),query,result.getTotal());
//// }
//// else {
//// for (BaseDepartmentVO data:dataResult){
//// initNodeChildren(data);
//// }
//// }
//// return ApiResult.success(dataResult,query,result.getTotal());
List<BaseDepartmentVO> dataResult = Convert.toList(BaseDepartmentVO.class, result.getRecords()); List<BaseDepartmentVO> dataResult = Convert.toList(BaseDepartmentVO.class, result.getRecords());
if(StrUtil.isNotBlank(query.getDeptCodeOrName())){ if(StrUtil.isNotBlank(query.getDeptCodeOrName()) || Objects.nonNull(query.getDeptStatus())){
List<BaseDepartmentVO> alldept = Convert.toList(BaseDepartmentVO.class,departmentService.lambdaQuery().eq(TBaseDepartment::getDataValidStatus,1).list()) ; List<BaseDepartmentVO> allList = Convert.toList(BaseDepartmentVO.class,departmentService.lambdaQuery()
Map<Long, BaseDepartmentVO> collect = alldept.stream().collect(Collectors.toMap(BaseDepartmentVO::getId, Function.identity())); .eq(TBaseDepartment::getDataValidStatus,1)
.list()) ;
Map<Long, BaseDepartmentVO> collect = allList.stream().collect(Collectors.toMap(BaseDepartmentVO::getId, Function.identity()));
List<BaseDepartmentVO> allParents=new ArrayList<>(); List<BaseDepartmentVO> allParents=new ArrayList<>();
for (BaseDepartmentVO data:dataResult){ for (BaseDepartmentVO data:dataResult){
allParents.addAll(getAllParents(data, collect)) ; allParents.addAll(getAllParents(data, collect));
} }
allParents.addAll(dataResult); allParents.addAll(dataResult);
allParents=allParents.stream().distinct().collect(Collectors.toList());
return ApiResult.success(buildTree(allParents),query,result.getTotal()); return ApiResult.success(buildTree(allParents),query,result.getTotal());
} }
else { else {
for (BaseDepartmentVO data:dataResult){ for (BaseDepartmentVO data:dataResult){
initNodeChildren(data); initNodeChildren(data,query);
} }
} }
return ApiResult.success(dataResult,query,result.getTotal()); return ApiResult.success(dataResult,query,result.getTotal());
} }
public List<Long> getAllChildIds(TBaseDepartment vo ,List<Long> ids){ // public ApiResult<PageData<BaseDepartmentVO>> getList(DepartmentQuery query){
// if (StrUtil.isBlank(query.getDeptCodeOrName()) && Objects.isNull(query.getDeptStatus())){
// return ApiResult.success(getNonQuery(query));
// }
// else {
// return ApiResult.success(null);
// }
// }
private PageData<BaseDepartmentVO> getNonQuery(DepartmentQuery query) {
Page<TBaseDepartment> page = departmentService.lambdaQuery()
.eq(TBaseDepartment::getDataValidStatus, 1)
.eq(TBaseDepartment::getDeptParentId, 0)
.page(new Page<>(query.getPage(), query.getPageSize()));
return PageUtil.convert(page, d -> {
BaseDepartmentVO vo = Convert.convert(BaseDepartmentVO.class, d);
initNodeChildren(vo);
return vo;
});
}
public List<Long> getAllChildIds(TBaseDepartment vo, List<Long> ids) {
List<BaseDepartmentVO> immediateChildren = findChildDepartmentsByParentId(vo.getId()); List<BaseDepartmentVO> immediateChildren = findChildDepartmentsByParentId(vo.getId());
ids.addAll(immediateChildren.stream().map(u->u.getId()).collect(Collectors.toSet())); ids.addAll(immediateChildren.stream().map(u->u.getId()).collect(Collectors.toSet()));
for (BaseDepartmentVO child : immediateChildren) { for (BaseDepartmentVO child : immediateChildren) {
@ -68,10 +105,20 @@ public class AdminDepartmentService {
} }
} }
private void initNodeChildren(BaseDepartmentVO node, DepartmentQuery query) {
List<BaseDepartmentVO> immediateChildren = findChildDepartmentsByParentId(node.getId());
if(query!=null && query.getDeptStatus()!=null){
immediateChildren=immediateChildren.stream().filter(u->query.getDeptStatus().equals(u.getDeptStatus())).collect(Collectors.toList());
}
node.setChildren(immediateChildren);
for (BaseDepartmentVO child : immediateChildren) {
initNodeChildren(child,query);
}
}
private List<BaseDepartmentVO> findChildDepartmentsByParentId(Long parentId) { private List<BaseDepartmentVO> findChildDepartmentsByParentId(Long parentId) {
List<TBaseDepartment> depts = departmentService.lambdaQuery().eq(TBaseDepartment::getDeptParentId, parentId).eq(TBaseDepartment::getDataValidStatus,1).list(); List<TBaseDepartment> depts = departmentService.lambdaQuery().eq(TBaseDepartment::getDeptParentId, parentId).eq(TBaseDepartment::getDataValidStatus,1).list();
return Convert.toList(BaseDepartmentVO.class,depts); return Convert.toList(BaseDepartmentVO.class,depts);
} }
private List<BaseDepartmentVO> getAllParents(BaseDepartmentVO node, Map<Long, BaseDepartmentVO> idToNodeMap) { private List<BaseDepartmentVO> getAllParents(BaseDepartmentVO node, Map<Long, BaseDepartmentVO> idToNodeMap) {
@ -83,6 +130,7 @@ public class AdminDepartmentService {
parents.add(parentNode); parents.add(parentNode);
parentId = parentNode.getDeptParentId(); // 移动到上一级 parentId = parentNode.getDeptParentId(); // 移动到上一级
} }
Collections.reverse(parents); // 如果需要从根节点开始排序则反转列表 Collections.reverse(parents); // 如果需要从根节点开始排序则反转列表
return parents; return parents;
} }

View File

@ -31,14 +31,6 @@ public class SSEController extends ControllerBase {
*/ */
@GetMapping(value = "connect",produces = MediaType.TEXT_EVENT_STREAM_VALUE) @GetMapping(value = "connect",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter connect(@RequestParam Integer userId) { public SseEmitter connect(@RequestParam Integer userId) {
SseEmitter sse = adminSSEManagerService.connect(userId); return adminSSEManagerService.connect(userId);
// try {
// sse.send("您已连接");
// } catch (IOException e) {
// log.error("sse发送数据出错",e);
// sse.complete();
// throw new NflgException(STATE.BusinessError,"sse发送数据出错");
// }
return sse;
} }
} }

View File

@ -51,6 +51,7 @@ public class AdminMessageServiceImpl extends ServiceImpl<AdminMessageMapper, Adm
remove(new LambdaQueryWrapper<AdminMessage>() remove(new LambdaQueryWrapper<AdminMessage>()
.eq(AdminMessage::getIsRead, false) .eq(AdminMessage::getIsRead, false)
.eq(AdminMessage::getSubType, message.getSubType()) .eq(AdminMessage::getSubType, message.getSubType())
.eq(AdminMessage::getSourceId, message.getSourceId())
.eq(AdminMessage::getUserId, message.getUserId())); .eq(AdminMessage::getUserId, message.getUserId()));
save(message); save(message);
} }

View File

@ -265,12 +265,14 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
private void bindChildren1(AreaSimpleVO vo) { private void bindChildren1(AreaSimpleVO vo) {
List<AppArea> datas = appAreaService.lambdaQuery().eq(AppArea::getParentId, vo.getId()).eq(AppArea::getEnable, true).list(); List<AppArea> datas = appAreaService.lambdaQuery().eq(AppArea::getParentId, vo.getId()).eq(AppArea::getEnable, true).list();
List<AreaSimpleVO> vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getName())).collect(Collectors.toList()); List<AreaSimpleVO> vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getName())).collect(Collectors.toList());
vo.setChildren(vos);
vos.forEach(this::bindChildren1); vos.forEach(this::bindChildren1);
} }
private void bindChildren(AreaSimpleVO vo) { private void bindChildren(AreaSimpleVO vo) {
List<TBaseArea> datas = adminAreaService.lambdaQuery().eq(TBaseArea::getParentAreaRowId, vo.getId()).eq(TBaseArea::getAreaState, 1).list(); List<TBaseArea> datas = adminAreaService.lambdaQuery().eq(TBaseArea::getParentAreaRowId, vo.getId()).eq(TBaseArea::getAreaState, 1).list();
List<AreaSimpleVO> vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getAreaName())).collect(Collectors.toList()); List<AreaSimpleVO> vos = datas.stream().map(d -> new AreaSimpleVO().setId(d.getId()).setName(d.getAreaName())).collect(Collectors.toList());
vo.setChildren(vos);
vos.forEach(this::bindChildren); vos.forEach(this::bindChildren);
} }

View File

@ -3,7 +3,7 @@
<mapper namespace="com.nflg.mobilebroken.repository.mapper.TBaseDepartmentMapper"> <mapper namespace="com.nflg.mobilebroken.repository.mapper.TBaseDepartmentMapper">
<sql id="whr"> <sql id="whr">
<if test="query.deptCodeOrName!=null and query.deptCodeOrName!=''"> <if test="query.deptCodeOrName!=null and query.deptCodeOrName!=''">
and (dept_code=#{query.deptCodeOrName} or dept_name=#{query.deptCodeOrName}) and (dept_code like concat('%', #{query.deptCodeOrName},'%') or dept_name like concat('%', #{query.deptCodeOrName},'%'))
</if> </if>
<if test="query.deptStatus!=null"> <if test="query.deptStatus!=null">
and dept_status=#{query.deptStatus} and dept_status=#{query.deptStatus}
@ -13,10 +13,6 @@
select * select *
from t_base_department from t_base_department
where data_valid_status=1 where data_valid_status=1
<if test="query.deptCodeOrName==null || query.deptCodeOrName==''">
and dept_parent_id=0
</if>
<include refid="whr"/> <include refid="whr"/>
</select> </select>

View File

@ -42,6 +42,7 @@ public class SSEManagerBase {
if (Objects.nonNull(old)){ if (Objects.nonNull(old)){
log.warn("停止旧连接:"+userId); log.warn("停止旧连接:"+userId);
try { try {
old.send(SseEmitter.event().name("被踢下线").data("你已在其他地方连接"));
old.complete(); old.complete();
} catch (Exception e) { } catch (Exception e) {
old.completeWithError(e); old.completeWithError(e);