feat: 一些调整
This commit is contained in:
parent
3a3220d7d3
commit
d0e6a54bf0
|
|
@ -29,14 +29,6 @@ public class SSEController extends ControllerBase {
|
|||
@GetMapping(value = "connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
@ApiMark(moduleName = "连接", apiName = "SSE", isPublic = true)
|
||||
public SseEmitter connect(@RequestParam String userId) {
|
||||
SseEmitter sse = 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;
|
||||
return sseManagerService.connect(Integer.valueOf(userId));
|
||||
}
|
||||
}
|
||||
|
|
@ -527,7 +527,7 @@ public class TicketController extends ControllerBase {
|
|||
}
|
||||
}
|
||||
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.setFirstMessageId(notReadeds.iterator().next());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.nflg.mobilebroken.repository.entity.TBaseDepartment;
|
|||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class BaseDepartmentVO extends TBaseDepartment {
|
||||
|
|
@ -12,4 +13,17 @@ public class BaseDepartmentVO extends TBaseDepartment {
|
|||
* 子级
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,13 @@ import com.nflg.mobilebroken.admin.pojo.query.DepartmentQuery;
|
|||
import com.nflg.mobilebroken.admin.pojo.vo.BaseDepartmentVO;
|
||||
import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||
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.service.ITBaseDepartmentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -26,29 +24,68 @@ public class AdminDepartmentService {
|
|||
ITBaseDepartmentService departmentService;
|
||||
public ApiResult<PageData<BaseDepartmentVO>> getList(DepartmentQuery 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());
|
||||
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()));
|
||||
if(StrUtil.isNotBlank(query.getDeptCodeOrName()) || Objects.nonNull(query.getDeptStatus())){
|
||||
List<BaseDepartmentVO> allList = Convert.toList(BaseDepartmentVO.class,departmentService.lambdaQuery()
|
||||
.eq(TBaseDepartment::getDataValidStatus,1)
|
||||
.list()) ;
|
||||
Map<Long, BaseDepartmentVO> collect = allList.stream().collect(Collectors.toMap(BaseDepartmentVO::getId, Function.identity()));
|
||||
List<BaseDepartmentVO> allParents=new ArrayList<>();
|
||||
for (BaseDepartmentVO data:dataResult){
|
||||
allParents.addAll(getAllParents(data, collect)) ;
|
||||
allParents.addAll(getAllParents(data, collect));
|
||||
|
||||
}
|
||||
allParents.addAll(dataResult);
|
||||
allParents=allParents.stream().distinct().collect(Collectors.toList());
|
||||
return ApiResult.success(buildTree(allParents),query,result.getTotal());
|
||||
}
|
||||
else {
|
||||
for (BaseDepartmentVO data:dataResult){
|
||||
initNodeChildren(data);
|
||||
initNodeChildren(data,query);
|
||||
}
|
||||
}
|
||||
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());
|
||||
ids.addAll(immediateChildren.stream().map(u->u.getId()).collect(Collectors.toSet()));
|
||||
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) {
|
||||
List<TBaseDepartment> depts = departmentService.lambdaQuery().eq(TBaseDepartment::getDeptParentId, parentId).eq(TBaseDepartment::getDataValidStatus,1).list();
|
||||
return Convert.toList(BaseDepartmentVO.class,depts);
|
||||
|
||||
}
|
||||
|
||||
private List<BaseDepartmentVO> getAllParents(BaseDepartmentVO node, Map<Long, BaseDepartmentVO> idToNodeMap) {
|
||||
|
|
@ -83,6 +130,7 @@ public class AdminDepartmentService {
|
|||
parents.add(parentNode);
|
||||
parentId = parentNode.getDeptParentId(); // 移动到上一级
|
||||
}
|
||||
|
||||
Collections.reverse(parents); // 如果需要从根节点开始排序,则反转列表
|
||||
return parents;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,14 +31,6 @@ public class SSEController extends ControllerBase {
|
|||
*/
|
||||
@GetMapping(value = "connect",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter connect(@RequestParam Integer userId) {
|
||||
SseEmitter sse = adminSSEManagerService.connect(userId);
|
||||
// try {
|
||||
// sse.send("您已连接");
|
||||
// } catch (IOException e) {
|
||||
// log.error("sse发送数据出错",e);
|
||||
// sse.complete();
|
||||
// throw new NflgException(STATE.BusinessError,"sse发送数据出错");
|
||||
// }
|
||||
return sse;
|
||||
return adminSSEManagerService.connect(userId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ public class AdminMessageServiceImpl extends ServiceImpl<AdminMessageMapper, Adm
|
|||
remove(new LambdaQueryWrapper<AdminMessage>()
|
||||
.eq(AdminMessage::getIsRead, false)
|
||||
.eq(AdminMessage::getSubType, message.getSubType())
|
||||
.eq(AdminMessage::getSourceId, message.getSourceId())
|
||||
.eq(AdminMessage::getUserId, message.getUserId()));
|
||||
save(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -265,12 +265,14 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
|
|||
private void bindChildren1(AreaSimpleVO vo) {
|
||||
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());
|
||||
vo.setChildren(vos);
|
||||
vos.forEach(this::bindChildren1);
|
||||
}
|
||||
|
||||
private void bindChildren(AreaSimpleVO vo) {
|
||||
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());
|
||||
vo.setChildren(vos);
|
||||
vos.forEach(this::bindChildren);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<mapper namespace="com.nflg.mobilebroken.repository.mapper.TBaseDepartmentMapper">
|
||||
<sql id="whr">
|
||||
<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 test="query.deptStatus!=null">
|
||||
and dept_status=#{query.deptStatus}
|
||||
|
|
@ -13,10 +13,6 @@
|
|||
select *
|
||||
from t_base_department
|
||||
where data_valid_status=1
|
||||
<if test="query.deptCodeOrName==null || query.deptCodeOrName==''">
|
||||
and dept_parent_id=0
|
||||
</if>
|
||||
|
||||
<include refid="whr"/>
|
||||
</select>
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ public class SSEManagerBase {
|
|||
if (Objects.nonNull(old)){
|
||||
log.warn("停止旧连接:"+userId);
|
||||
try {
|
||||
old.send(SseEmitter.event().name("被踢下线").data("你已在其他地方连接"));
|
||||
old.complete();
|
||||
} catch (Exception e) {
|
||||
old.completeWithError(e);
|
||||
|
|
|
|||
Loading…
Reference in New Issue