<dev>
1. 初始化工程
| package com.zorkdata.desensitization; | ||
| import com.alibaba.fastjson.JSON; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| /** | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/29 | ||
| */ | ||
| public class Test { | ||
| public static void main(String[] args) { | ||
| // String a = "{a},{b}"; | ||
|
||
| // String[] pathStrings = getPathStrings(a); | ||
| // for (String b: pathStrings) { | ||
| // System.out.println(b); | ||
| // } | ||
|
||
| String a = "a,b,"; | ||
| String[] pathStrings = getPathStrings(a); | ||
| for (String b: pathStrings) { | ||
| System.out.println(b); | ||
|
||
| System.out.printf("--"); | ||
|
|
||
| } | ||
| } | ||
| private static String[] getPathStrings(String commaSeparatedPaths) { | ||
| int length = commaSeparatedPaths.length(); | ||
| int curlyOpen = 0; | ||
| int pathStart = 0; | ||
| boolean globPattern = false; | ||
| List<String> pathStrings = new ArrayList(); | ||
| for(int i = 0; i < length; ++i) { | ||
| char ch = commaSeparatedPaths.charAt(i); | ||
| switch(ch) { | ||
|
|
||
| case ',': | ||
| if (!globPattern) { | ||
| pathStrings.add(commaSeparatedPaths.substring(pathStart, i)); | ||
| pathStart = i + 1; | ||
| } | ||
| break; | ||
| case '{': | ||
| ++curlyOpen; | ||
| if (!globPattern) { | ||
| globPattern = true; | ||
| } | ||
| break; | ||
| case '}': | ||
| --curlyOpen; | ||
| if (curlyOpen == 0 && globPattern) { | ||
| globPattern = false; | ||
| } | ||
| } | ||
| } | ||
| pathStrings.add(commaSeparatedPaths.substring(pathStart, length)); | ||
| System.out.println(JSON.toJSONString(pathStrings)); | ||
|
||
| return (String[])pathStrings.toArray(new String[0]); | ||
|
||
| } | ||
| } | ||
| package com.zorkdata.desensitization; | ||
| import com.zorkdata.desensitization.constans.ConfigConstants; | ||
| import com.zorkdata.desensitization.exception.ZorkException; | ||
| import com.zorkdata.desensitization.hadoop.HdfsLogDesensitization; | ||
| import com.zorkdata.desensitization.utils.YmlUtil; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import java.util.Map; | ||
| /** | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/22 | ||
| */ | ||
| @Slf4j | ||
| public class TransactionLogDesensitization { | ||
| private static final int PARAM_LENGTH = 2; | ||
| public static void main(String[] args) { | ||
| if (args.length != PARAM_LENGTH) { | ||
| String error = "参数缺失,请输入配置文件,例如: --conf /opt/TransactionLogDesensitization/application.yml"; | ||
| log.error(error); | ||
| System.exit(1); | ||
| } | ||
| try { | ||
| Map<String, String> conf = YmlUtil.getParams(args); | ||
| String source = conf.get(ConfigConstants.SOURCE); | ||
| if (ConfigConstants.HDFS.equals(source)) { | ||
| new HdfsLogDesensitization().initConf(conf).desensitizationHdfsLog(); | ||
| } | ||
| if (ConfigConstants.KAFKA.equals(source)) { | ||
| // TODO kafka | ||
|
||
| } | ||
| } catch (ZorkException e) { | ||
| log.info(String.valueOf(e)); | ||
| System.exit(1); | ||
| } | ||
| } | ||
| } | ||
| package com.zorkdata.datamask.util.avro; | ||
| package com.zorkdata.desensitization.avro; | ||
| /** | ||
| * @author xiesen | ||
| * @Description 日志集 schema 定义 | ||
| * @Email xiesen310@163.com | ||
| * @Date 2020/6/28 9:33 | ||
| * avro schema 定义 | ||
| * | ||
| * @author Administrator | ||
| */ | ||
| public class LogAvroMacroDef { | ||
| public static String metadata = "{\n" + | ||
| public final class AvroSchemaDef { | ||
| /** | ||
| * 指标schema定义 | ||
| */ | ||
| public static final String ZORK_METRIC_SCHEMA = "{\n" + | ||
| " \"namespace\": \"com.zork.metrics\",\n" + | ||
| " \"type\": \"record\",\n" + | ||
| " \"name\": \"metrics\",\n" + | ||
| " \"fields\": [\n" + | ||
| " {\n" + | ||
|
||
| " \"name\": \"metricsetname\",\n" + | ||
| " \"type\": [\n" + | ||
|
||
| " \"string\",\n" + | ||
|
||
| " \"null\"\n" + | ||
|
||
| " ]\n" + | ||
|
||
| " },\n" + | ||
|
||
| " {\n" + | ||
| " \"name\": \"timestamp\",\n" + | ||
| " \"type\": [\n" + | ||
| " \"string\",\n" + | ||
| " \"null\"\n" + | ||
| " ]\n" + | ||
| " },\n" + | ||
| " {\n" + | ||
| " \"name\": \"dimensions\",\n" + | ||
| " \"type\": [\n" + | ||
| " \"null\",\n" + | ||
|
||
| " {\n" + | ||
|
||
| " \"type\": \"map\",\n" + | ||
|
||
| " \"values\": \"string\"\n" + | ||
|
||
| " }\n" + | ||
|
||
| " ]\n" + | ||
| " },\n" + | ||
| " {\n" + | ||
| " \"name\": \"metrics\",\n" + | ||
| " \"type\": [\n" + | ||
| " \"null\",\n" + | ||
| " {\n" + | ||
| " \"type\": \"map\",\n" + | ||
| " \"values\": \"double\"\n" + | ||
| " }\n" + | ||
| " ]\n" + | ||
| " }\n" + | ||
| " ]\n" + | ||
| "}"; | ||
| /** | ||
| * 日志指标集定义 | ||
| */ | ||
| public static final String ZORK_LOG_SCHEMA = "{\n" + | ||
| " \"namespace\": \"com.zork.logs\",\n" + | ||
| " \"type\": \"record\",\n" + | ||
| " \"name\": \"logs\",\n" + | ||
| ... | ... | @@ -72,4 +120,8 @@ public class LogAvroMacroDef { |
| " }\n" + | ||
| " ]\n" + | ||
| "}"; | ||
| private AvroSchemaDef() { | ||
| } | ||
| } | ||
| package com.zorkdata.desensitization.config; | ||
| import com.zorkdata.desensitization.constans.RegExpConstants; | ||
| import lombok.Data; | ||
| import java.io.Serializable; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| /** | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/26 | ||
| */ | ||
| @Data | ||
| public class RegularExpressions implements Serializable { | ||
| private static final long serialVersionUID = -9099923348992729289L; | ||
| /** | ||
| * 姓名正则表达式 | ||
| */ | ||
| private String nameRegExp; | ||
|
||
| /** | ||
| * 手机号正则表达式 | ||
| */ | ||
| private String mobileRegExp; | ||
|
||
| /** | ||
| * 手机号正则表达式 | ||
| */ | ||
| private String phoneRegExp; | ||
|
||
| /** | ||
| * 邮箱正则表达式 | ||
| */ | ||
| private String emailRegExp; | ||
|
||
| /** | ||
| * 身份证正则表达式 | ||
| */ | ||
| private String idRegExp; | ||
|
||
| /** | ||
| * 银行卡号正则表达式 | ||
| */ | ||
| private String bankCardRegExp; | ||
|
||
| /** | ||
| * 家庭住址正则表达式 | ||
| */ | ||
| private String addressRegExp; | ||
|
||
| /** | ||
| * ip地址正则表达式 | ||
| */ | ||
| private String ipRegExp; | ||
|
||
| /** | ||
| * mac地址正则表达式 | ||
| */ | ||
| private String macRegExp; | ||
|
||
| public RegularExpressions(){ | ||
| } | ||
| @SuppressWarnings("all") | ||
| public RegularExpressions(Map conf){ | ||
| Map regularExpressions = (HashMap)conf.get(RegExpConstants.REG_EXP); | ||
| this.nameRegExp = String.valueOf(regularExpressions.get(RegExpConstants.NAME_REG_EXP)).trim(); | ||
| this.mobileRegExp = String.valueOf(regularExpressions.get(RegExpConstants.MOBILE_REG_EXP)).trim(); | ||
| this.phoneRegExp = String.valueOf(regularExpressions.get(RegExpConstants.PHONE_REG_EXP)).trim(); | ||
| this.emailRegExp = String.valueOf(regularExpressions.get(RegExpConstants.EMAIL_REG_EXP)).trim(); | ||
| this.idRegExp = String.valueOf(regularExpressions.get(RegExpConstants.ID_REG_EXP)).trim(); | ||
| this.bankCardRegExp = String.valueOf(regularExpressions.get(RegExpConstants.BANK_CARD_REG_EXP)).trim(); | ||
| this.addressRegExp = String.valueOf(regularExpressions.get(RegExpConstants.ADDRESS_REG_EXP)).trim(); | ||
| this.ipRegExp = String.valueOf(regularExpressions.get(RegExpConstants.IP_REG_EXP)).trim(); | ||
| this.macRegExp = String.valueOf(regularExpressions.get(RegExpConstants.MAC_REG_EXP)).trim(); | ||
| } | ||
| } | ||
| package com.zorkdata.desensitization.constans; | ||
| /** | ||
| * 符号常量 | ||
| * | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/26 | ||
| */ | ||
| public final class GeneralConstants { | ||
|
||
| public static final String COMMA = ","; | ||
| public static final String FILE_SEPARATOR = "/"; | ||
| public static final String AVRO_SUFFIX = ".avro"; | ||
| public static final String EMPTY_STR = ""; | ||
| } | ||
| package com.zorkdata.desensitization.constans; | ||
| /** | ||
| * 正则常量key | ||
| * | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/26 | ||
| */ | ||
| public final class RegExpConstants { | ||
|
||
| public static final String REG_EXP = "reg_exp"; | ||
| public static final String NAME_REG_EXP = "name"; | ||
| public static final String MOBILE_REG_EXP = "mobile"; | ||
| public static final String PHONE_REG_EXP = "phone"; | ||
| public static final String EMAIL_REG_EXP = "email"; | ||
| public static final String ID_REG_EXP = "id"; | ||
| public static final String BANK_CARD_REG_EXP = "bank_card"; | ||
| public static final String ADDRESS_REG_EXP = "address"; | ||
| public static final String IP_REG_EXP = "ip"; | ||
| public static final String MAC_REG_EXP = "mac"; | ||
| } | ||
| package com.zorkdata.datamask.util; | ||
| package com.zorkdata.desensitization.function; | ||
| import com.alibaba.fastjson.JSON; | ||
| import com.zorkdata.desensitization.config.RegularExpressions; | ||
| import java.io.Serializable; | ||
| import java.util.*; | ||
| ... | ... | @@ -6,105 +9,32 @@ import java.util.regex.Matcher; |
| import java.util.regex.Pattern; | ||
| /** | ||
| * Description: | ||
| * | ||
| * @author: wanghaiying (<a href="wanghaiying@zorkdata.com.cn">wanghaiying@zorkdata.com.cn</a>) | ||
| * Date: Create in 2020/9/23 9:30 | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/26 | ||
| */ | ||
| public class MaskUtil implements Serializable { | ||
| public class DesensitizationFunction implements Serializable { | ||
| private static final long serialVersionUID = 1L; | ||
| public static final int DEFAULT_MAP_CAPACITY = 16; | ||
| /** | ||
| * 数据格式信息 | ||
| */ | ||
| //todo 抽取到配置文件 | ||
| private List<String> dataFormats = new ArrayList<String>(){{ | ||
| add(","); | ||
| add("."); | ||
| add("@"); | ||
| add("-"); | ||
| }}; | ||
| /** | ||
| * 姓名正则 | ||
| */ | ||
| private String nameRegExp; | ||
| /** | ||
| * 手机号正则 | ||
| */ | ||
| private String mobileRegExp; | ||
| /** | ||
| * 电话号码正则 | ||
| */ | ||
| private String phoneRegExp; | ||
| /** | ||
| * 邮箱正则 | ||
| */ | ||
| private String emailRegExp; | ||
| /** | ||
| * 身份证号码(15位)正则 | ||
| */ | ||
| private String idRegExp15; | ||
| private RegularExpressions regularExpressions; | ||
| /** | ||
| * 身份证号码(18位)正则 | ||
| */ | ||
| private String idRegExp18; | ||
| private List<Pattern> patterns = new ArrayList<>(); | ||
| /** | ||
| * 银行卡号码正则 | ||
| */ | ||
| private String bankCardRegExp; | ||
| /** | ||
| * 家庭住址正则 | ||
| */ | ||
| private String addressRegExp; | ||
| /** | ||
| * ip地址正则 | ||
| */ | ||
| private String ipRegExp; | ||
| /** | ||
| * mac地址正则 | ||
| */ | ||
| private String macRegExp; | ||
| List<Pattern> patterns = new ArrayList<Pattern>() {{ | ||
| }}; | ||
| public MaskUtil(String nameRegExp, String mobileRegExp, String phoneRegExp, String emailRegExp, String idRegExp15, String idRegExp18, String bankCardRegExp, String addressRegExp, String ipRegExp, String macRegExp) { | ||
| this.nameRegExp = nameRegExp; | ||
| this.mobileRegExp = mobileRegExp; | ||
| this.phoneRegExp = phoneRegExp; | ||
| this.emailRegExp = emailRegExp; | ||
| this.idRegExp15 = idRegExp15; | ||
| this.idRegExp18 = idRegExp18; | ||
| this.bankCardRegExp = bankCardRegExp; | ||
| this.addressRegExp = addressRegExp; | ||
| this.ipRegExp = ipRegExp; | ||
| this.macRegExp = macRegExp; | ||
| public DesensitizationFunction(RegularExpressions regularExpressions) { | ||
| this.regularExpressions = regularExpressions; | ||
| } | ||
| public Map mask(Map map, ArrayList whiteList) { | ||
| patterns.add(Pattern.compile(this.nameRegExp)); | ||
| patterns.add(Pattern.compile(this.macRegExp)); | ||
| patterns.add(Pattern.compile(this.emailRegExp)); | ||
| patterns.add(Pattern.compile(this.ipRegExp)); | ||
| patterns.add(Pattern.compile(this.idRegExp18)); | ||
| patterns.add(Pattern.compile(this.idRegExp15)); | ||
| patterns.add(Pattern.compile(this.bankCardRegExp)); | ||
| patterns.add(Pattern.compile(this.mobileRegExp)); | ||
| patterns.add(Pattern.compile(this.phoneRegExp)); | ||
| patterns.add(Pattern.compile(this.addressRegExp)); | ||
| public Map desensitization(Map map, List<String> whiteList, List<String> dataFormats) { | ||
|
||
| patterns.add(Pattern.compile(regularExpressions.getNameRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getMacRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getEmailRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getIpRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getIpRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getBankCardRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getMobileRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getPhoneRegExp())); | ||
| patterns.add(Pattern.compile(regularExpressions.getAddressRegExp())); | ||
| map.forEach((k, v) -> { | ||
| if (!whiteList.contains(k)) { | ||
| ... | ... | @@ -134,18 +64,20 @@ public class MaskUtil implements Serializable { |
| } | ||
| public static void main(String[] args) { | ||
| MaskUtil maskUtil = new MaskUtil("[\\u4e00-\\u9fa5]{1,20}|[a-zA-Z\\\\.\\\\s]{1,20}", | ||
| "((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}", | ||
| "0\\d{2,3}-\\d{7,8}", | ||
| "[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+", | ||
| "[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}", | ||
| "[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])", | ||
| "([1-9]{1})(\\d{11}|\\d{15}|\\d{16}|\\d{17}|\\d{18})", | ||
| "([\u4E00-\u9FA5A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}", | ||
| "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)", | ||
| "([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"); | ||
| Map map = new HashMap(DEFAULT_MAP_CAPACITY); | ||
| RegularExpressions regularExpressions = new RegularExpressions(); | ||
| regularExpressions.setAddressRegExp("([\u4E00-\u9FA5A-Za-z0-9_]+(省|市|区|县|道|路|街|号|弄|条|室)){2,}"); | ||
| regularExpressions.setBankCardRegExp("([1-9]{1})(\\d{11}|\\d{15}|\\d{16}|\\d{17}|\\d{18})"); | ||
| regularExpressions.setEmailRegExp("[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+"); | ||
| regularExpressions.setIdRegExp("[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])"); | ||
| regularExpressions.setIpRegExp("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"); | ||
| regularExpressions.setMacRegExp("([A-Fa-f0-9]{2}-){5}[A-Fa-f0-9]{2}"); | ||
| regularExpressions.setMobileRegExp("((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}"); | ||
| regularExpressions.setPhoneRegExp("0\\d{2,3}-\\d{7,8}"); | ||
| regularExpressions.setNameRegExp("[\\u4e00-\\u9fa5]{1,20}|[a-zA-Z\\\\.\\\\s]{1,20}"); | ||
| DesensitizationFunction desensitizationFunction = new DesensitizationFunction(regularExpressions); | ||
| Map map = new HashMap(16); | ||
| map.put("姓名", "王海鹰"); | ||
| map.put("身份证号", "372925199101195158"); | ||
| map.put("手机号", "15000101879"); | ||
| ... | ... | @@ -162,10 +94,14 @@ public class MaskUtil implements Serializable { |
| map.put("normalFields", "13811110000-110101199003075517-上海市浦东新区张江微电子港-zorkdata@163.com-123456789-wanghaiying123-王海鹰-192.168.1.1-00-50-56-C0-00-08-6227002470170278192"); | ||
| String[] fieldsWhiteListArray = "messid,fundid,custid,orgid,brhid,secuid,bankcode,market,ordersno,ordergroup,count,poststr,stkcode,bsflag,orderamt,price,qty,bankcode,tacode,ofcode,transacc,taacc".split(","); | ||
| ArrayList< String> fieldsWhiteList = new ArrayList<String>(fieldsWhiteListArray.length); | ||
| List< String> fieldsWhiteList = new ArrayList<>(fieldsWhiteListArray.length); | ||
| Collections.addAll(fieldsWhiteList, fieldsWhiteListArray); | ||
| System.out.println(maskUtil.mask(map, fieldsWhiteList)); | ||
| List<String> dataFormats = new ArrayList<String>(){{ | ||
|
|
||
| add(","); | ||
| add("."); | ||
| add("@"); | ||
| add("-"); | ||
| }}; | ||
| System.out.println(JSON.toJSONString(desensitizationFunction.desensitization(map, fieldsWhiteList, dataFormats))); | ||
|
||
| } | ||
| } | ||
| package com.zorkdata.desensitization.utils; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.*; | ||
| /** | ||
| * @author: LiaoMingtao | ||
| * @date: 2020/10/22 | ||
| */ | ||
| @Slf4j | ||
| public class DateUtil { | ||
|
||
| private static final String NULL = ""; | ||
| private static final String BAR_STRING = "-"; | ||
| private static final String TIME_ZONE = "Asia/shanghai"; | ||
|
||
| private static ThreadLocal<SimpleDateFormat> UTC_FORMATTER = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+08:00")); | ||
|
||
| private static ThreadLocal<SimpleDateFormat> YYYY_MM_DD_HH_MM_SS_FORMATTER = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); | ||
|
||
| private static ThreadLocal<SimpleDateFormat> YYYY_MM_DD_FORMATTER = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd")); | ||
|
||
| /** | ||
| * 形如yyyy-MM-dd转yyyymmdd | ||
| * | ||
| * @param time 日期 | ||
| * @return yyyymmdd的日期 | ||
| */ | ||
| public static String date2date(String time) { | ||
| return time.replace(BAR_STRING, NULL); | ||
| } | ||
| /** | ||
| * 批量转日期 去除日期中的‘-’ | ||
| * | ||
| * @param timeList 例如 2019-10-11 的日期列表 | ||
| * @return List<String> | ||
| */ | ||
| public static List<String> date2date(List<String> timeList) { | ||
| List<String> resultList = new ArrayList<>(); | ||
| for (String time : timeList) { | ||
| String tempTime = date2date(time); | ||
| resultList.add(tempTime); | ||
| } | ||
| return resultList; | ||
| } | ||
| /** | ||
| * 获取两个时间段内的所有日期,日期可跨年 | ||
| * | ||
| * @param begin 开始时间 yyyy-MM-dd HH:mm:ss | ||
| * @param end 结束时间 yyyy-MM-dd HH:mm:ss | ||
| * @return List<String> | ||
| */ | ||
| public static List<String> getBetweenDate(String begin, String end) { | ||
| List<String> betweenList = new ArrayList<>(); | ||
| Calendar startDay = Calendar.getInstance(); | ||
| try { | ||
| startDay.setTime(YYYY_MM_DD_HH_MM_SS_FORMATTER.get().parse(begin)); | ||
| startDay.add(Calendar.DATE, -1); | ||
| while (true) { | ||
| startDay.add(Calendar.DATE, 1); | ||
| Date newDate = startDay.getTime(); | ||
| String newEnd = YYYY_MM_DD_FORMATTER.get().format(newDate); | ||
| betweenList.add(newEnd); | ||
| if (end.startsWith(newEnd)) { | ||
| break; | ||
| } | ||
| } | ||
| } catch (ParseException e) { | ||
| log.error(String.valueOf(e)); | ||
| } | ||
| return betweenList; | ||
| } | ||
| /** | ||
| * 普通时间转时间戳 | ||
| * | ||
| * @param time 普通时间 | ||
| * @return 时间戳 | ||
| */ | ||
| public static long time2Timestamp(String time) { | ||
| Date gpsUtcDate = null; | ||
| try { | ||
| gpsUtcDate = YYYY_MM_DD_HH_MM_SS_FORMATTER.get().parse(time); | ||
| return gpsUtcDate.getTime(); | ||
| } catch (ParseException e) { | ||
| log.error("时间戳格式转换异常:{} 原因: {}", time, e.getMessage()); | ||
| } | ||
| return 0L; | ||
| } | ||
| /** | ||
| * UTC时间转 | ||
| * | ||
| * @param utcTime UTC时间 | ||
| * @return unix时间戳 | ||
| */ | ||
| public static Long utc2timestamp(String utcTime) { | ||
| //时区定义并进行时间获取 | ||
| // UTC_FORMATTER.get().setTimeZone(TimeZone.getTimeZone(TIME_ZONE)); | ||
|
|
||
| Date gpsUtcDate = null; | ||
| try { | ||
| gpsUtcDate = UTC_FORMATTER.get().parse(utcTime); | ||
| } catch (ParseException e) { | ||
| log.error("时间戳格式转换异常:{} 原因: {}", utcTime, e.getMessage()); | ||
| return null; | ||
| } | ||
| return gpsUtcDate.getTime(); | ||
| } | ||
| } | ||
-
SonarQube analysis reported 110 issues
-
🚫 21 critical -
⚠ 70 major -
🔽 18 minor -
ℹ 1 info
Watch the comments in this conversation to review them.
22 extra issues
Note: The following issues were found on lines that were not modified in the commit. Because these issues can't be reported as line comments, they are summarized here:
-
🚫 Change this "try" to a try-with-resources. (sonar.java.source not set. Assuming 7 or greater.)📘 -
🚫 Refactor this code to not throw exceptions in finally blocks.📘 -
🚫 Refactor this code to not throw exceptions in finally blocks.📘 -
⚠ Rename "jsonObject" which hides the field declared at line 39.📘 -
⚠ Remove this expression which always evaluates to "true"📘 -
⚠ A "List" cannot contain a "K"📘 -
⚠ Replace this use of System.out or System.err by a logger.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Remove this throw statement from this finally block.📘 -
⚠ Use the URI class instead.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Define and throw a dedicated exception instead of using a generic one.📘 -
⚠ Remove this throw statement from this finally block.📘 -
🔽 Make this IP "192.168.70.2" address configurable.📘 -
🔽 Immediately return this expression instead of assigning it to the temporary variable "var7".📘 -
🔽 Immediately return this expression instead of assigning it to the temporary variable "var19".📘 -
🔽 Remove this unnecessary cast to "URL".📘
-