| | |
| | | package com.zy.core; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.lang.reflect.Array; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * news stories for zoneyung |
| | |
| | | } |
| | | |
| | | public static void info(String format, Object... arguments) { |
| | | if (format.contains("[RCS Debug]")) { |
| | | ConfigService configService = SpringUtils.getBean(ConfigService.class); |
| | | if(configService != null) { |
| | | boolean show = true; |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "rcsDebugShowLog")); |
| | | if(config != null) { |
| | | show = config.getValue().equals("true"); |
| | | } |
| | | |
| | | if (!show) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | RedisUtil redisUtil = null; |
| | | try { |
| | | redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | if(redisUtil != null) { |
| | | Object object = redisUtil.get(RedisKeyType.LOG_LIMIT.key + format); |
| | | if (object != null) { |
| | | return; |
| | | } |
| | | redisUtil.set(RedisKeyType.LOG_LIMIT.key + format, "lock", 3); |
| | | } |
| | | }catch (Exception e) {} |
| | | |
| | | log.info(format, arguments); |
| | | offer(NewsLevel.INFO, format, arguments); |
| | | } |
| | | |
| | | public static void warn(String format, Object... arguments) { |
| | | if (format.contains("[RCS Debug]")) { |
| | | ConfigService configService = SpringUtils.getBean(ConfigService.class); |
| | | if(configService != null) { |
| | | boolean show = true; |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "rcsDebugShowLog")); |
| | | if(config != null) { |
| | | show = config.getValue().equals("true"); |
| | | } |
| | | |
| | | if (!show) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | RedisUtil redisUtil = null; |
| | | try { |
| | | redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | if(redisUtil != null) { |
| | | Object object = redisUtil.get(RedisKeyType.LOG_LIMIT.key + format); |
| | | if (object != null) { |
| | | return; |
| | | } |
| | | redisUtil.set(RedisKeyType.LOG_LIMIT.key + format, "lock", 3); |
| | | } |
| | | }catch (Exception e) {} |
| | | |
| | | log.warn(format, arguments); |
| | | offer(NewsLevel.WARN, format, arguments); |
| | | } |
| | | |
| | | public static void error(String format, Object... arguments) { |
| | | if (format.contains("[RCS Debug]")) { |
| | | ConfigService configService = SpringUtils.getBean(ConfigService.class); |
| | | if(configService != null) { |
| | | boolean show = true; |
| | | Config config = configService.selectOne(new EntityWrapper<Config>().eq("code", "rcsDebugShowLog")); |
| | | if(config != null) { |
| | | show = config.getValue().equals("true"); |
| | | } |
| | | |
| | | if (!show) { |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | RedisUtil redisUtil = null; |
| | | try { |
| | | redisUtil = SpringUtils.getBean(RedisUtil.class); |
| | | if(redisUtil != null) { |
| | | Object object = redisUtil.get(RedisKeyType.LOG_LIMIT.key + format); |
| | | if (object != null) { |
| | | return; |
| | | } |
| | | redisUtil.set(RedisKeyType.LOG_LIMIT.key + format, "lock", 3); |
| | | } |
| | | }catch (Exception e) {} |
| | | |
| | | log.error(format, arguments); |
| | | offer(NewsLevel.ERROR, format, arguments); |
| | | } |
| | | |
| | | public static String print() { |
| | | public static void taskInfo(Integer wrkNo, String format, Object... arguments) { |
| | | info(format, arguments); |
| | | offerTask(wrkNo, format, arguments); |
| | | } |
| | | |
| | | public static void taskWarn(Integer wrkNo, String format, Object... arguments) { |
| | | warn(format, arguments); |
| | | offerTask(wrkNo, format, arguments); |
| | | } |
| | | |
| | | public static void taskError(Integer wrkNo, String format, Object... arguments) { |
| | | error(format, arguments); |
| | | offerTask(wrkNo, format, arguments); |
| | | } |
| | | |
| | | public static String printStr() { |
| | | StringBuilder sb = new StringBuilder("["); |
| | | List<NewsDomain> domains = NEWS_QUEUE.data(); |
| | | for (int i = 0; i < domains.size(); i++) { |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | public static List<Map<String, Object>> print() { |
| | | List<Map<String, Object>> res = new ArrayList<>(); |
| | | for (NewsDomain datum : NEWS_QUEUE.data()) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("l", datum.level.idx); |
| | | map.put("v", datum.content); |
| | | map.put("t", datum.date); |
| | | res.add(map); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | private static boolean offerTask(Integer wrkNo, String msg, Object[] args) { |
| | | WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class); |
| | | if (wrkMastService == null) { |
| | | return false; |
| | | } |
| | | |
| | | WrkMast wrkMast = wrkMastService.selectByWorkNo(wrkNo); |
| | | if (wrkMast == null) { |
| | | return false; |
| | | } |
| | | String systemMsg = replace(msg, args); |
| | | if (!systemMsg.equals(wrkMast.getSystemMsg())) { |
| | | wrkMast.setSystemMsg(systemMsg); |
| | | wrkMast.setModiTime(new Date()); |
| | | wrkMastService.updateById(wrkMast); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private static boolean offer(NewsLevel level, String msg, Object[] args) { |
| | | return NEWS_QUEUE.offer(new NewsDomain(level, replace(msg, args), (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()))); |
| | | } |
| | | |
| | | private static String replace(String str, Object[] objs){ |
| | | public static String replace(String str, Object[] objs){ |
| | | if (null == objs || objs.length == 0 || null == str || "".equals(str.trim())) { |
| | | return str; |
| | | } else { |