1. 项目数据

2. 更改系统日志使用 rocket 队列
This commit is contained in:
ant 2024-07-26 18:33:47 +08:00
parent 1835bf6f1e
commit 024a53d3c2
25 changed files with 323 additions and 122 deletions

View File

@ -24,6 +24,10 @@
<groupId>com.chushang</groupId>
<artifactId>chushang-common-security</artifactId>
</dependency>
<dependency>
<groupId>com.chushang</groupId>
<artifactId>chushang-common-mq</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -22,6 +22,7 @@ import com.chushang.common.core.constant.ServiceConstant;
import com.chushang.common.log.entity.SysLogEntity;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.common.log.enums.LogTypeEnum;
import com.chushang.common.mq.produce.MqProduceService;
import com.chushang.security.utils.SecurityUtils;
import com.chushang.security.entity.vo.LoginUser;
import lombok.RequiredArgsConstructor;
@ -59,6 +60,7 @@ import java.util.stream.Collectors;
public class SysLogAspect {
final RedissonClient redissonClient;
private final MqProduceService<SysLogEntity> mqProduceService;
@Pointcut("@annotation(com.chushang.common.log.annotation.SysLog)")
public void logPointCut() {
@ -177,8 +179,9 @@ public class SysLogAspect {
assert syslog != null;
// if (null != ex){
// 入队列, 方便在system 统一查询
RList<SysLogEntity> list = redissonClient.getList(ServiceConstant.QUEUE_NAME);
list.add(sysLogEntity);
// RList<SysLogEntity> list = redissonClient.getList(ServiceConstant.QUEUE_NAME);
// list.add(sysLogEntity);
mqProduceService.send( ServiceConstant.QUEUE_NAME, sysLogEntity);
//// sysLogService.save(sysLogEntity);
// }else {
// log.info("log {}", JSONObject.toJSONString(sysLogEntity));

View File

@ -3,10 +3,10 @@ package com.chushang.inspection.project.vo;
import lombok.Data;
@Data
public class CountTaskVO {
public class CountVO {
private Long projectId;
private int totalTask;
private int total;
}

View File

@ -156,7 +156,7 @@ public class WrkProjectController {
* 项目数据 展示
*/
@GetMapping(value = "/project/data")
@RequiresPermissions("inspection:project:info")
// @RequiresPermissions("inspection:project:info")
public AjaxResult projectData(ProjectQuery projectQuery)
{
return AjaxResult.success(projectService.projectData(projectQuery));

View File

@ -4,9 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chushang.common.core.util.StringUtils;
import com.chushang.inspection.project.po.PollingTask;
import com.chushang.inspection.project.vo.CountTaskVO;
import com.chushang.inspection.project.vo.CountVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Set;
@ -26,5 +25,5 @@ public interface PollingTaskMapper extends BaseMapper<PollingTask> {
// 此处为null
return pollingTask.getSearchIndex();
}
List<CountTaskVO> countByProjectIds(@Param("projectIds") Set<Long> projectIds);
List<CountVO> countByProjectIds(@Param("projectIds") Set<Long> projectIds);
}

View File

@ -1,5 +1,6 @@
package com.chushang.inspection.project.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chushang.common.mybatis.page.CommonParam;
@ -7,14 +8,15 @@ import com.chushang.inspection.project.dto.TaskDTO;
import com.chushang.inspection.project.dto.TaskExcelDTO;
import com.chushang.inspection.project.dto.TaskQuery;
import com.chushang.inspection.project.po.PollingTask;
import com.chushang.inspection.project.po.Template;
import com.chushang.inspection.project.vo.ConfigVO;
import com.chushang.inspection.project.vo.CountTaskVO;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.project.vo.TaskVO;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @auther: zhao
@ -46,6 +48,18 @@ public interface PollingTaskService extends IService<PollingTask>{
return ObjectUtil.isNotEmpty(task) ? task.getName() : "";
}
List<CountTaskVO> countByProjectIds(Set<Long> projectIds);
List<CountVO> countByProjectIds(Set<Long> projectIds);
default Map<Long, Integer> countByProjectIdsMap(Set<Long> projectIds){
List<CountVO> countVOS = countByProjectIds(projectIds);
if (CollectionUtil.isNotEmpty(countVOS)){
return countVOS.stream().collect(Collectors.toMap(
CountVO::getProjectId,
CountVO::getTotal,
Integer::sum
));
}
return Map.of();
}
}

View File

@ -1,7 +1,6 @@
package com.chushang.inspection.project.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
@ -14,13 +13,10 @@ import com.chushang.common.mybatis.utils.WrapperUtils;
import com.chushang.datascope.annotation.DataScope;
import com.chushang.inspection.project.dto.ContractDTO;
import com.chushang.inspection.project.dto.ProjectDTO;
import com.chushang.inspection.project.po.PollingTask;
import com.chushang.inspection.project.po.WrkAudit;
import com.chushang.inspection.project.po.WrkProjectContract;
import com.chushang.inspection.project.query.ProjectQuery;
import com.chushang.inspection.project.vo.CountTaskVO;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.project.vo.ProjectVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.service.StoreService;
import com.chushang.inspection.terminal.service.TerminalService;
import com.chushang.inspection.work.service.WrkInfoService;
@ -265,7 +261,6 @@ public class WrkProjectService extends ServiceImpl<WrkProjectMapper, WrkProject>
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(commonParam.getPage(), commonParam.getLimit()),
sql
);
List<WrkProject> recordList = page.getRecords();
List<ProjectVO> list = BeanUtil.copyToList(recordList, ProjectVO.class);
Set<Long> deptIds = list.stream().map(ProjectVO::getDeptId).collect(Collectors.toSet());
@ -273,24 +268,26 @@ public class WrkProjectService extends ServiceImpl<WrkProjectMapper, WrkProject>
= remoteDeptService.getDeptNameByIds(deptIds, SecurityConstants.INNER);
Set<Long> projectIds = list.stream().map(ProjectVO::getProjectId).collect(Collectors.toSet());
// 任务总数
List<CountTaskVO> totalTaskMap = taskService.countByProjectIds(projectIds);
List<PollingTask> taskList = taskService.list(new LambdaQueryWrapper<PollingTask>()
.in(PollingTask::getProjectId, projectIds));
if (CollectionUtil.isNotEmpty(taskList)){
Set<Long> taskIds = taskList.stream().map(PollingTask::getId).collect(Collectors.toSet());
Map<Long, Integer> totalTaskMap = taskService.countByProjectIdsMap(projectIds);
// 商户总数
List<Store> storeList = storeService.list(new LambdaQueryWrapper<Store>()
.in(Store::getLowerTaskId, taskIds));
Map<Long, List<Store>> storeMap
= storeList.stream().collect(Collectors.groupingBy(Store::getLowerTaskId));
// 商户id
Set<Long> storeIds = storeList.stream().map(Store::getStoreId).collect(Collectors.toSet());
}
Map<Long, Integer> totalStoreMap = storeService.countByProjectIdsMap(projectIds);
// 终端总数
Map<Long, Integer> totalTerminalMap = terminalService.countByProjectIdsMap(projectIds);
// 巡检工单总数
Map<Long, Integer> countInsMap = wrkInfoService.countByProjectIdsMap(projectIds, Set.of(5, 21));
// 工单总数
Map<Long, Integer> countWrkMap = wrkInfoService.countByProjectIdsMap(projectIds, Set.of());
list.forEach(p->{
Long deptId = p.getDeptId();
Long projectId = p.getProjectId();
p.setDeptName(deptNameMap.get(deptId));
p.setTotalWrk(countWrkMap.getOrDefault(projectId, 0));
p.setTotalIns(countInsMap.getOrDefault(projectId, 0));
p.setTotalTerminal(totalTerminalMap.getOrDefault(projectId, 0));
p.setTotalStore(totalStoreMap.getOrDefault(projectId, 0));
p.setTotalTask(totalTaskMap.getOrDefault(projectId, 0));
});
return new PageResult(list,page.getTotal(),page.getSize(),page.getCurrent());
}
}

View File

@ -27,7 +27,7 @@ import com.chushang.inspection.project.dto.TaskDTO;
import com.chushang.inspection.project.dto.TaskExcelDTO;
import com.chushang.inspection.project.dto.TaskQuery;
import com.chushang.inspection.project.vo.ConfigVO;
import com.chushang.inspection.project.vo.CountTaskVO;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.project.vo.TaskVO;
import com.chushang.inspection.project.service.PollingTaskService;
import com.chushang.security.utils.SecurityUtils;
@ -248,7 +248,7 @@ public class PollingTaskServiceImpl extends ServiceImpl<PollingTaskMapper, Polli
}
@Override
public List<CountTaskVO> countByProjectIds(Set<Long> projectIds) {
public List<CountVO> countByProjectIds(Set<Long> projectIds) {
return baseMapper.countByProjectIds(projectIds);
}

View File

@ -3,12 +3,14 @@ package com.chushang.inspection.terminal.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chushang.datascope.annotation.DataScope;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.query.StoreQuery;
import com.chushang.inspection.terminal.vo.StoreVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* @auther: zhao
@ -19,4 +21,7 @@ public interface StoreMapper extends BaseMapper<Store> {
@DataScope(deptAlias = "s")
List<StoreVO> pageList(@Param("query") StoreQuery query,
Page<Store> page);
List<CountVO> countByProjectIds(@Param("projectIds") Set<Long> projectIds);
}

View File

@ -3,6 +3,7 @@ package com.chushang.inspection.terminal.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chushang.datascope.annotation.DataScope;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.project.vo.TerminalAppVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.po.Terminal;
@ -15,6 +16,7 @@ import com.chushang.inspection.work.query.DispatchQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* @auther: zhao
@ -30,4 +32,5 @@ public interface TerminalMapper extends BaseMapper<Terminal> {
@DataScope(deptAlias = "t")
List<DispatchDTO> getStoreByTasKIdOrIds(@Param("query") DispatchQuery query);
List<CountVO> countByProjectIds(@Param("projectIds") Set<Long> projectIds);
}

View File

@ -1,13 +1,20 @@
package com.chushang.inspection.terminal.service;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.inspection.project.po.Template;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.query.StoreQuery;
import com.chushang.inspection.work.dto.WrkIcbcJsReceive;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @auther: zhao
* @date: 2024/6/21 16:39
@ -20,4 +27,17 @@ public interface StoreService extends IService<Store>{
void upload(MultipartFile file, Long taskId);
Store save(WrkIcbcJsReceive dto);
List<CountVO> countByProjectIds(Set<Long> projectIds);
default Map<Long, Integer> countByProjectIdsMap(Set<Long> projectIds){
List<CountVO> countVOS = countByProjectIds(projectIds);
if (CollectionUtil.isNotEmpty(countVOS)){
return countVOS.stream().collect(Collectors.toMap(
CountVO::getProjectId,
CountVO::getTotal,
Integer::sum
));
}
return Map.of();
}
}

View File

@ -1,8 +1,10 @@
package com.chushang.inspection.terminal.service;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.project.vo.TerminalApp;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.po.Terminal;
@ -14,6 +16,8 @@ import com.chushang.inspection.work.query.DispatchQuery;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @auther: zhao
@ -62,4 +66,18 @@ public interface TerminalService extends IService<Terminal>{
JSONObject getTerMap(Long terminalId);
List<CountVO> countByProjectIds(Set<Long> projectIds);
default Map<Long, Integer> countByProjectIdsMap(Set<Long> projectIds){
List<CountVO> countVOS = countByProjectIds(projectIds);
if (CollectionUtil.isNotEmpty(countVOS)){
return countVOS.stream().collect(Collectors.toMap(
CountVO::getProjectId,
CountVO::getTotal,
Integer::sum
));
}
return Map.of();
}
}

View File

@ -16,6 +16,7 @@ import com.chushang.inspection.project.po.PollingTask;
import com.chushang.inspection.project.po.Template;
import com.chushang.inspection.project.service.PollingTaskService;
import com.chushang.inspection.project.service.TbTemplateService;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.query.StoreQuery;
import com.chushang.inspection.terminal.service.StoreService;
@ -83,4 +84,9 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
return store;
}
@Override
public List<CountVO> countByProjectIds(Set<Long> projectIds) {
return baseMapper.countByProjectIds(projectIds);
}
}

View File

@ -15,6 +15,7 @@ import com.chushang.common.mybatis.enums.Operator;
import com.chushang.common.mybatis.page.CommonParam;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.common.mybatis.utils.WrapperUtils;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.project.vo.TerminalApp;
import com.chushang.inspection.project.vo.TerminalAppVO;
import com.chushang.inspection.terminal.po.Store;
@ -148,6 +149,11 @@ public class TerminalServiceImpl extends ServiceImpl<TerminalMapper, Terminal> i
return JSONObject.of("terminal", getById(terminalId), "terminalIns", terminalInsService.getById(terminalId));
}
@Override
public List<CountVO> countByProjectIds(Set<Long> projectIds) {
return baseMapper.countByProjectIds(projectIds);
}
@Override
@Transactional(rollbackFor = Exception.class)
public long updateTerminalAndStore(TerminalQuery query) {

View File

@ -222,7 +222,7 @@ public class WrkInfoController {
* 提交 工单
*/
@PostMapping("/submit")
@RequiresPermissions("wrk:submit")
@RequiresPermissions("wrk:info:submit")
@SysLog(value = "工单提交", businessType = BusinessType.INSERT)
public AjaxResult submit(@Validated @RequestBody WrkInfoDTO info) {
wrkInfoService.submit(info);
@ -241,5 +241,11 @@ public class WrkInfoController {
return AjaxResult.success();
}
@GetMapping(value = "/data")
@RequiresPermissions("wrk:info:dispatch")
public AjaxResult wrkData(){
return AjaxResult.success();
}
}

View File

@ -3,6 +3,7 @@ package com.chushang.inspection.work.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chushang.datascope.annotation.DataScope;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.work.po.WrkInfo;
import com.chushang.inspection.work.query.ReviewedQuery;
import com.chushang.inspection.work.query.WrkAppQuery;
@ -11,6 +12,7 @@ import com.chushang.inspection.work.vo.*;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Set;
/**
* @auther: zhao
@ -32,4 +34,7 @@ public interface WrkInfoMapper extends BaseMapper<WrkInfo> {
@DataScope(deptAlias = "i")
List<WrkInfoExportVO> exportDispatchPage(@Param("query") WrkInfoQuery query);
List<CountVO> countByProjectIds(@Param("projectIds") Set<Long> projectIds,
@Param("wrkTypes") Set<Integer> wrkTypes);
}

View File

@ -1,7 +1,9 @@
package com.chushang.inspection.work.service;
import cn.hutool.core.collection.CollectionUtil;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.inspection.project.dto.AuditDTO;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.po.Terminal;
import com.chushang.inspection.terminal.po.TerminalIns;
@ -16,6 +18,9 @@ import com.chushang.inspection.work.vo.WrkInfoDetailsVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @auther: zhao
@ -46,4 +51,17 @@ public interface WrkInfoService extends IService<WrkInfo> {
Long dispatch(WrkInfo wrkInfo, Store store, Terminal terminal, TerminalIns terminalIns);
List<CountVO> countByProjectIds(Set<Long> projectIds, Set<Integer> wrkType);
default Map<Long, Integer> countByProjectIdsMap(Set<Long> projectIds, Set<Integer> wrkType){
List<CountVO> countVOS = countByProjectIds(projectIds, wrkType);
if (CollectionUtil.isNotEmpty(countVOS)){
return countVOS.stream().collect(Collectors.toMap(
CountVO::getProjectId,
CountVO::getTotal,
Integer::sum
));
}
return Map.of();
}
}

View File

@ -33,6 +33,7 @@ import com.chushang.inspection.project.dto.AuditDTO;
import com.chushang.inspection.project.po.InspectionData;
import com.chushang.inspection.project.service.InspectionDataService;
import com.chushang.inspection.project.service.PollingTaskService;
import com.chushang.inspection.project.vo.CountVO;
import com.chushang.inspection.terminal.po.FiveStore;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.po.Terminal;
@ -647,6 +648,11 @@ public class WrkInfoServiceImpl extends ServiceImpl<WrkInfoMapper, WrkInfo> impl
return wrkInfo.getWrkId();
}
@Override
public List<CountVO> countByProjectIds(Set<Long> projectIds, Set<Integer> wrkType) {
return baseMapper.countByProjectIds(projectIds, wrkType);
}
/**
* 计算经纬度 偏差
*/

View File

@ -2,8 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.chushang.inspection.project.mapper.PollingTaskMapper">
<select id="countByProjectIds" resultType="com.chushang.inspection.project.vo.CountTaskVO">
SELECT COUNT(*) AS totalTask, pt.project_id AS projectId
<select id="countByProjectIds" resultType="com.chushang.inspection.project.vo.CountVO">
SELECT COUNT(*) AS total, pt.project_id AS projectId
FROM ta_polling_task pt
where pt.del_state = 0
<if test="projectIds != null and projectIds.size() != 0">

View File

@ -37,4 +37,17 @@
</if>
ORDER BY s.${query.orderBy} ${query.isAsc}
</select>
<select id="countByProjectIds" resultType="com.chushang.inspection.project.vo.CountVO">
SELECT COUNT(*) AS total, s.project_id
FROM st_store s
where s.del_state = 0
<if test="projectIds != null and projectIds.size() != 0">
AND s.project_id IN
<foreach collection="projectIds" open="(" close=")" item="projectId" separator=",">
#{projectId}
</foreach>
</if>
GROUP BY s.project_id
</select>
</mapper>

View File

@ -237,4 +237,17 @@
</foreach>
</if>
</select>
<select id="countByProjectIds" resultType="com.chushang.inspection.project.vo.CountVO">
SELECT COUNT(*) AS total, t.project_id AS projectId
FROM st_terminal t
where t.del_state = 0
<if test="projectIds != null and projectIds.size() != 0">
AND t.project_id IN
<foreach collection="projectIds" open="(" close=")" item="projectId" separator=",">
#{projectId}
</foreach>
</if>
GROUP BY t.project_id
</select>
</mapper>

View File

@ -249,4 +249,23 @@
LEFT JOIN wrk_info_terminal_ins_record itir ON i.wrk_id = itir.wrk_id
WHERE i.del_state = 0
</sql>
<select id="countByProjectIds" resultType="com.chushang.inspection.project.vo.CountVO">
SELECT COUNT(*) AS total, wi.project_id AS projectId
FROM wrk_info wi
where wi.del_state = 0
<if test="projectIds != null and projectIds.size() > 0">
AND wi.project_id IN
<foreach collection="projectIds" open="(" close=")" item="projectId" separator=",">
#{projectId}
</foreach>
</if>
<if test="wrkTypes != null and wrkTypes.size() > 0">
AND wi.work_type IN
<foreach collection="wrkTypes" open="(" close=")" separator="," item="wrkType">
#{wrkType}
</foreach>
</if>
GROUP BY wi.project_id
</select>
</mapper>

View File

@ -1,83 +1,83 @@
package com.chushang.system.component;
import com.chushang.common.core.constant.ServiceConstant;
import com.chushang.common.log.entity.SysLogEntity;
import com.chushang.system.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @auther: zhao
* @date: 2024/4/12 17:09
*/
@Slf4j
@Component
public class LogRedisComponent {
private final SysLogService logService;
private final RedissonClient redissonClient;
public LogRedisComponent(SysLogService logService, RedissonClient redissonClient){
log.info("构造器执行");
this.logService = logService;
this.redissonClient = redissonClient;
}
private final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
@PostConstruct
public void redisStart() {
log.info("线程执行");
Thread startLogQueueThread = startLogQueueThread();
scheduledThreadPoolExecutor.scheduleWithFixedDelay(()->{
Thread runLog = startLogQueueThread;
try {
boolean runLogThreadAlive = runLog.isAlive();
if (!runLogThreadAlive) {
throw new NullPointerException("runLogThread alive false");
}
} catch (Exception ex) {
System.out.println("logQueueThread 重启线程");
runLog = startLogQueueThread();
}
}, 10 ,30, TimeUnit.SECONDS);
log.info("RedisLogQueueCollect is starting!");
}
private Thread startLogQueueThread() {
Thread logQueueThread = new Thread(this::logQueueThread);
logQueueThread.start();
return logQueueThread;
}
private void logQueueThread()
{
while (true) {
if (log.isDebugEnabled()){
log.debug("读取redis 数据");
}
try {
try {
// 每1000 毫秒从 redis 获取一遍 入队数据
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("", e);
Thread.currentThread().interrupt();
}
if (!redissonClient.isShutdown()){
RQueue<SysLogEntity> list = redissonClient.getQueue(ServiceConstant.QUEUE_NAME);
List<SysLogEntity> reqList = list.poll(5000);
logService.saveBatch(reqList);
}else {
if (log.isDebugEnabled()) log.debug(" Redisson is shutdown");
}
} catch (RuntimeException e) {
log.error("logQueueThread error, 并重启线程!", e);
}
}
}
}
//package com.chushang.system.component;
//
//import com.chushang.common.core.constant.ServiceConstant;
//import com.chushang.common.log.entity.SysLogEntity;
//import com.chushang.system.service.SysLogService;
//import lombok.extern.slf4j.Slf4j;
//import org.redisson.api.RQueue;
//import org.redisson.api.RedissonClient;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import java.util.List;
//import java.util.concurrent.ScheduledThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
///**
// * @auther: zhao
// * @date: 2024/4/12 17:09
// */
//@Slf4j
//@Component
//public class LogRedisComponent {
//
// private final SysLogService logService;
// private final RedissonClient redissonClient;
// public LogRedisComponent(SysLogService logService, RedissonClient redissonClient){
// log.info("构造器执行");
// this.logService = logService;
// this.redissonClient = redissonClient;
// }
// private final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
// @PostConstruct
// public void redisStart() {
// log.info("线程执行");
// Thread startLogQueueThread = startLogQueueThread();
// scheduledThreadPoolExecutor.scheduleWithFixedDelay(()->{
// Thread runLog = startLogQueueThread;
// try {
// boolean runLogThreadAlive = runLog.isAlive();
// if (!runLogThreadAlive) {
// throw new NullPointerException("runLogThread alive false");
// }
// } catch (Exception ex) {
// System.out.println("logQueueThread 重启线程");
// runLog = startLogQueueThread();
// }
// }, 10 ,30, TimeUnit.SECONDS);
// log.info("RedisLogQueueCollect is starting!");
// }
//
// private Thread startLogQueueThread() {
// Thread logQueueThread = new Thread(this::logQueueThread);
// logQueueThread.start();
// return logQueueThread;
// }
//
// private void logQueueThread()
// {
// while (true) {
// if (log.isDebugEnabled()){
// log.debug("读取redis 数据");
// }
// try {
// try {
// // 每1000 毫秒从 redis 获取一遍 入队数据
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// log.error("", e);
// Thread.currentThread().interrupt();
// }
// if (!redissonClient.isShutdown()){
// RQueue<SysLogEntity> list = redissonClient.getQueue(ServiceConstant.QUEUE_NAME);
// List<SysLogEntity> reqList = list.poll(5000);
// logService.saveBatch(reqList);
// }else {
// if (log.isDebugEnabled()) log.debug(" Redisson is shutdown");
// }
// } catch (RuntimeException e) {
// log.error("logQueueThread error, 并重启线程!", e);
// }
// }
// }
//}

View File

@ -0,0 +1,45 @@
package com.chushang.system.consumer;
import com.alibaba.fastjson2.JSON;
import com.chushang.common.core.constant.SecurityConstants;
import com.chushang.common.core.constant.ServiceConstant;
import com.chushang.common.core.context.SecurityContextHolder;
import com.chushang.common.core.util.SpringUtils;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.core.web.Result;
import com.chushang.common.log.entity.SysLogEntity;
import com.chushang.system.service.SysLogService;
import com.chushang.task.entity.TaskInfo;
import com.chushang.task.entity.dto.UpdateTaskDTO;
import com.chushang.task.enums.TaskStatusEnum;
import com.chushang.task.enums.TaskTypeEnum;
import com.chushang.task.feign.RemoteTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* @auther: zhao
* @date: 2024/6/12 16:59
*/
@Slf4j
@Component
@RocketMQMessageListener(topic = ServiceConstant.QUEUE_NAME, consumerGroup = ServiceConstant.SYSTEM_CONSUMER_GROUP)
public class LogConsumerService implements RocketMQListener<SysLogEntity> {
@Resource
private SysLogService logService;
/**
* 执行 下发的 后台任务
*/
@Override
public void onMessage(SysLogEntity logEntity) {
log.info("消费日志 {}", JSON.toJSONString(logEntity));
logService.save(logEntity);
}
}

View File

@ -31,6 +31,7 @@ public class RemoteDeptController implements RemoteDeptService {
@GetMapping(value = "/getDeptNameByIds")
@InnerAuth
public Map<Long, String> getDeptNameByIds(@RequestParam Set<Long> deptIds, String source) {
if (CollectionUtil.isEmpty(deptIds)) return Map.of();
List<SysDept> sysDepts = deptService.listByIds(deptIds);
if (CollectionUtil.isNotEmpty(sysDepts)){
return sysDepts.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));