CP56Time2a bug fix
This commit is contained in:
parent
3d6689090c
commit
d3d501bdad
29
sql/v2.1.sql
29
sql/v2.1.sql
@ -476,6 +476,33 @@ CREATE TABLE `xhpc_setting_config` (
|
|||||||
AUTO_INCREMENT = 3
|
AUTO_INCREMENT = 3
|
||||||
;
|
;
|
||||||
|
|
||||||
|
-- ICCard
|
||||||
|
ALTER TABLE `xhpc_operator`
|
||||||
|
ADD COLUMN `corp_no` VARCHAR(30) NULL DEFAULT NULL COMMENT '运营商代码,用于桩编号前缀,如80836代表翔桦' AFTER `name`;
|
||||||
|
ALTER TABLE `xhpc_operator`
|
||||||
|
ADD COLUMN `corp_type` TINYINT NULL DEFAULT NULL COMMENT '运营商类型1:平台2:合作运营商' AFTER `corp_no`;
|
||||||
|
CREATE TABLE `t_iccard_client_users`
|
||||||
|
(
|
||||||
|
`usersID` INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`usersName` VARCHAR(100) NULL DEFAULT NULL COMMENT '命名规则:字母数字组合' COLLATE 'utf8mb4_unicode_ci',
|
||||||
|
`usersPwd` VARCHAR(100) NULL DEFAULT NULL COMMENT '用户密码' COLLATE 'utf8_general_ci',
|
||||||
|
`usersPhone` VARCHAR(50) NULL DEFAULT NULL COMMENT '用户电话' COLLATE 'utf8_general_ci',
|
||||||
|
`usersEmail` VARCHAR(50) NULL DEFAULT NULL COMMENT '用户Email' COLLATE 'utf8_general_ci',
|
||||||
|
`usersAdress` VARCHAR(300) NULL DEFAULT NULL COMMENT '用户地址' COLLATE 'utf8_general_ci',
|
||||||
|
`usersLevel` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '用户级别 3.运营商管理员 4.平台管理员',
|
||||||
|
`usersCorp` INT(11) NOT NULL DEFAULT '0' COMMENT '所属运营商id,对应xhpc_operator.operator_id',
|
||||||
|
`corpNo` VARCHAR(10) NOT NULL DEFAULT '0' COMMENT '所属运营商前缀' COLLATE 'utf8mb4_bin',
|
||||||
|
`corpName` VARCHAR(50) NOT NULL DEFAULT '0' COMMENT '所属运营商名称' COLLATE 'utf8mb4_bin',
|
||||||
|
`usersTime` DATETIME NULL DEFAULT NULL COMMENT '添加日期',
|
||||||
|
PRIMARY KEY (`usersID`),
|
||||||
|
UNIQUE INDEX `usersName` (`usersName`)
|
||||||
|
)
|
||||||
|
COMMENT ='发卡客户端用户表'
|
||||||
|
COLLATE = 'utf8mb4_bin'
|
||||||
|
ENGINE = InnoDB
|
||||||
|
AUTO_INCREMENT = 1
|
||||||
|
;
|
||||||
|
|
||||||
CREATE TABLE `xhpc_invoice`
|
CREATE TABLE `xhpc_invoice`
|
||||||
(
|
(
|
||||||
`invoice_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '发票id',
|
`invoice_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '发票id',
|
||||||
@ -568,4 +595,4 @@ ALTER TABLE `ry-cloud`.`t_iccard_info`
|
|||||||
ADD COLUMN `tenant_id` varchar(10) NOT NULL DEFAULT '000000' COMMENT '租户id' AFTER `createTime`;
|
ADD COLUMN `tenant_id` varchar(10) NOT NULL DEFAULT '000000' COMMENT '租户id' AFTER `createTime`;
|
||||||
|
|
||||||
ALTER TABLE `xhpc_statistics_station`
|
ALTER TABLE `xhpc_statistics_station`
|
||||||
ADD COLUMN `source` INT(4) NULL COMMENT '订单来源(0 C端用户 1 流量方用户 2社区用户 3B端用户)' AFTER `tenant_id`;
|
ADD COLUMN `source` INT(4) NULL COMMENT '订单来源(0 C端用户 1 流量方用户 2社区用户 3B端用户)' AFTER `tenant_id`;
|
||||||
|
|||||||
@ -84,6 +84,23 @@ public class HexUtils {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] cp56toBytes(String hex) {
|
||||||
|
|
||||||
|
if (hex == null) return null;
|
||||||
|
hex = hex.trim();
|
||||||
|
if (hex.length() != 14)
|
||||||
|
return null;
|
||||||
|
byte[] b = new byte[hex.length() / 2];
|
||||||
|
for (int i = 0; i < hex.length(); i = i + 2) {
|
||||||
|
if (i == 0) {
|
||||||
|
b[i / 2] = Integer.decode("0x" + hex.substring(1, 2).concat(hex.substring(0, 1))).byteValue();
|
||||||
|
} else {
|
||||||
|
b[i / 2] = Integer.decode("0x" + hex.substring(i, i + 2)).byteValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] stringToBytes(String str, int len) {
|
public static byte[] stringToBytes(String str, int len) {
|
||||||
|
|
||||||
byte[] data = str.getBytes();
|
byte[] data = str.getBytes();
|
||||||
@ -192,12 +209,13 @@ public class HexUtils {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
System.out.println(Long.valueOf(10L).toString());
|
// System.out.println(Long.valueOf(10L).toString());
|
||||||
// System.out.println(reverseHexInt("FF00"));
|
// System.out.println(reverseHexInt("FF00"));
|
||||||
// byte[] data1 = toBytes(reverseHex("10270000"));
|
// byte[] data1 = toBytes(reverseHex("10270000"));
|
||||||
// System.out.println(toInteger(data1, 0, 4));
|
// System.out.println(toInteger(data1, 0, 4));
|
||||||
System.out.println(reverseHexInt("D80E"));
|
// System.out.println(reverseHexInt("D80E"));
|
||||||
System.out.println(toHexInt(3800));
|
System.out.println(toHexInt(15));
|
||||||
|
// System.out.println(toHexInt(3800));
|
||||||
// System.out.println(toHexInt(100000));
|
// System.out.println(toHexInt(100000));
|
||||||
// System.out.println(toBits("1000"));
|
// System.out.println(toBits("1000"));
|
||||||
// System.out.println(toHex(new byte[]{104, 13, 19, 123, 0, 3, 105, -123, 71, -123, -106, 50, 84, 1, 0, 72, 106, 104,
|
// System.out.println(toHex(new byte[]{104, 13, 19, 123, 0, 3, 105, -123, 71, -123, -106, 50, 84, 1, 0, 72, 106, 104,
|
||||||
@ -207,4 +225,30 @@ public class HexUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String toBinaryString(String hex) {
|
||||||
|
|
||||||
|
String hex_char, bin_char, binary;
|
||||||
|
binary = "";
|
||||||
|
int len = hex.length() / 2;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
hex_char = hex.substring(2 * i, 2 * i + 2);
|
||||||
|
int conv_int = Integer.parseInt(hex_char, 16);
|
||||||
|
bin_char = Integer.toBinaryString(conv_int);
|
||||||
|
bin_char = zero_pad_bin_char(bin_char);
|
||||||
|
if (i == 0) binary = bin_char;
|
||||||
|
else binary = binary + bin_char;
|
||||||
|
//out.printf("%s %s\n", hex_char,bin_char);
|
||||||
|
}
|
||||||
|
return binary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String zero_pad_bin_char(String bin_char) {
|
||||||
|
|
||||||
|
int len = bin_char.length();
|
||||||
|
if (len == 8) return bin_char;
|
||||||
|
String zero_pad = "0";
|
||||||
|
for (int i = 1; i < 8 - len; i++) zero_pad = zero_pad + "0";
|
||||||
|
return zero_pad + bin_char;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import com.xhpc.pp.utils.HexUtils;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMAT;
|
import static cn.hutool.core.date.DatePattern.NORM_DATETIME_FORMATTER;
|
||||||
import static com.xhpc.evcs.utils.DateUtil.DATE_FORMAT_DATE_TIME;
|
import static com.xhpc.evcs.utils.DateUtil.DATE_FORMAT_DATE_TIME;
|
||||||
|
|
||||||
public class CP56Time2a {
|
public class CP56Time2a {
|
||||||
@ -27,8 +27,8 @@ public class CP56Time2a {
|
|||||||
dt.setField(DateField.SECOND, milliseconds / 1000);
|
dt.setField(DateField.SECOND, milliseconds / 1000);
|
||||||
dt.setField(DateField.MINUTE, minutes);
|
dt.setField(DateField.MINUTE, minutes);
|
||||||
dt.setField(DateField.HOUR_OF_DAY, hours);
|
dt.setField(DateField.HOUR_OF_DAY, hours);
|
||||||
dt.setField(DateField.DAY_OF_MONTH, days);
|
|
||||||
dt.setField(DateField.MONTH, months - 1);
|
dt.setField(DateField.MONTH, months - 1);
|
||||||
|
dt.setField(DateField.DAY_OF_MONTH, days);
|
||||||
dt.setField(DateField.YEAR, years + 2000);
|
dt.setField(DateField.YEAR, years + 2000);
|
||||||
return dt.toCalendar().getTime();
|
return dt.toCalendar().getTime();
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ public class CP56Time2a {
|
|||||||
return reversehilo.concat(HexUtils.toHex(result)).substring(0, 14);
|
return reversehilo.concat(HexUtils.toHex(result)).substring(0, 14);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String decode(byte b[]) {
|
public static String decode(byte[] b) {
|
||||||
|
|
||||||
int year = b[6] & 0x7F;
|
int year = b[6] & 0x7F;
|
||||||
int month = b[5] & 0x0F;
|
int month = b[5] & 0x0F;
|
||||||
@ -90,8 +90,8 @@ public class CP56Time2a {
|
|||||||
calendar.setTime(date);
|
calendar.setTime(date);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
String milliSecond = String.format("%04X", (calendar.get(Calendar.SECOND) * 1000) + calendar.get(Calendar.MILLISECOND));
|
String milliSecond = String.format("%04X", (calendar.get(Calendar.SECOND) * 1000) + calendar.get(Calendar.MILLISECOND));
|
||||||
builder.append(milliSecond.substring(2, 4));
|
builder.append(milliSecond, 2, 4);
|
||||||
builder.append(milliSecond.substring(0, 2));
|
builder.append(milliSecond, 0, 2);
|
||||||
builder.append(String.format("%02X", calendar.get(Calendar.MINUTE) & 0x3F));
|
builder.append(String.format("%02X", calendar.get(Calendar.MINUTE) & 0x3F));
|
||||||
builder.append(String.format("%02X", calendar.get(Calendar.HOUR_OF_DAY) & 0x1F));
|
builder.append(String.format("%02X", calendar.get(Calendar.HOUR_OF_DAY) & 0x1F));
|
||||||
int week = calendar.get(Calendar.DAY_OF_WEEK);
|
int week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
@ -110,10 +110,9 @@ public class CP56Time2a {
|
|||||||
* @param b 时标CP56Time2a(长度为7 的int数组)
|
* @param b 时标CP56Time2a(长度为7 的int数组)
|
||||||
* @return 解析结果
|
* @return 解析结果
|
||||||
*/
|
*/
|
||||||
public static String TimeScale(int b[]) {
|
public static String TimeScale(int[] b) {
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
int year = b[6] & 0x7F;
|
int year = b[6] & 0x7F;
|
||||||
int month = b[5] & 0x0F;
|
int month = b[5] & 0x0F;
|
||||||
int day = b[4] & 0x1F;
|
int day = b[4] & 0x1F;
|
||||||
@ -121,17 +120,24 @@ public class CP56Time2a {
|
|||||||
int hour = b[3] & 0x1F;
|
int hour = b[3] & 0x1F;
|
||||||
int minute = b[2] & 0x3F;
|
int minute = b[2] & 0x3F;
|
||||||
int second = (b[1] << 8) + b[0];
|
int second = (b[1] << 8) + b[0];
|
||||||
|
|
||||||
result.append("20");
|
result.append("20");
|
||||||
result.append(year).append("-");
|
result.append(year).append("-");
|
||||||
result.append(String.format("%02d", month)).append("-");
|
result.append(String.format("%02d", month)).append("-");
|
||||||
result.append(String.format("%02d", day)).append(" ");
|
result.append(String.format("%02d", day)).append(" ");
|
||||||
result.append(hour).append(":").append(minute).append(":");
|
result.append(hour).append(":").append(minute).append(":");
|
||||||
result.append(second / 1000 + "." + second % 1000);
|
result.append(second / 1000 + "." + second % 1000);
|
||||||
|
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String TimeScale(byte[] bytes) {
|
||||||
|
|
||||||
|
int[] b = new int[bytes.length];
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
b[i] = bytes[i];
|
||||||
|
}
|
||||||
|
return TimeScale(b);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 时间转16进制字符串
|
* 时间转16进制字符串
|
||||||
*/
|
*/
|
||||||
@ -141,8 +147,8 @@ public class CP56Time2a {
|
|||||||
calendar.setTime(date);
|
calendar.setTime(date);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
String milliSecond = String.format("%04X", (calendar.get(Calendar.SECOND) * 1000) + calendar.get(Calendar.MILLISECOND));
|
String milliSecond = String.format("%04X", (calendar.get(Calendar.SECOND) * 1000) + calendar.get(Calendar.MILLISECOND));
|
||||||
builder.append(milliSecond.substring(2, 4));
|
builder.append(milliSecond, 2, 4);
|
||||||
builder.append(milliSecond.substring(0, 2));
|
builder.append(milliSecond, 0, 2);
|
||||||
builder.append(String.format("%02X", calendar.get(Calendar.MINUTE) & 0x3F));
|
builder.append(String.format("%02X", calendar.get(Calendar.MINUTE) & 0x3F));
|
||||||
builder.append(String.format("%02X", calendar.get(Calendar.HOUR_OF_DAY) & 0x1F));
|
builder.append(String.format("%02X", calendar.get(Calendar.HOUR_OF_DAY) & 0x1F));
|
||||||
int week = calendar.get(Calendar.DAY_OF_WEEK);
|
int week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
@ -155,7 +161,6 @@ public class CP56Time2a {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Date toDate(byte[] bytes) {
|
public static Date toDate(byte[] bytes) {
|
||||||
|
|
||||||
int milliseconds1 = bytes[0] < 0 ? 256 + bytes[0] : bytes[0];
|
int milliseconds1 = bytes[0] < 0 ? 256 + bytes[0] : bytes[0];
|
||||||
@ -184,31 +189,18 @@ public class CP56Time2a {
|
|||||||
public static byte[] toBytes(Date aDate) {
|
public static byte[] toBytes(Date aDate) {
|
||||||
|
|
||||||
byte[] result = new byte[7];
|
byte[] result = new byte[7];
|
||||||
|
|
||||||
final Calendar aTime = Calendar.getInstance();
|
final Calendar aTime = Calendar.getInstance();
|
||||||
|
|
||||||
aTime.setTime(aDate);
|
aTime.setTime(aDate);
|
||||||
|
|
||||||
final int milliseconds = aTime.get(Calendar.MILLISECOND);
|
final int milliseconds = aTime.get(Calendar.MILLISECOND);
|
||||||
|
|
||||||
result[0] = (byte) (milliseconds % 256);
|
result[0] = (byte) (milliseconds % 256);
|
||||||
|
|
||||||
result[1] = (byte) (milliseconds / 256);
|
result[1] = (byte) (milliseconds / 256);
|
||||||
|
|
||||||
result[2] = (byte) aTime.get(Calendar.MINUTE);
|
result[2] = (byte) aTime.get(Calendar.MINUTE);
|
||||||
|
|
||||||
result[3] = (byte) aTime.get(Calendar.HOUR_OF_DAY);
|
result[3] = (byte) aTime.get(Calendar.HOUR_OF_DAY);
|
||||||
|
|
||||||
result[4] = (byte) aTime.get(Calendar.DAY_OF_MONTH);
|
result[4] = (byte) aTime.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
result[5] = (byte) aTime.get(Calendar.MONTH);
|
result[5] = (byte) aTime.get(Calendar.MONTH);
|
||||||
|
|
||||||
result[6] = (byte) (aTime.get(Calendar.YEAR) % 100);
|
result[6] = (byte) (aTime.get(Calendar.YEAR) % 100);
|
||||||
|
|
||||||
System.out.println("Year->" + aTime.get(Calendar.YEAR));
|
System.out.println("Year->" + aTime.get(Calendar.YEAR));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getCP56time2a(String hex) {
|
private static String getCP56time2a(String hex) {
|
||||||
@ -222,20 +214,17 @@ public class CP56Time2a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
// Date time = Calendar.getInstance().getTime();
|
// Date time = Calendar.getInstance().getTime();
|
||||||
// System.out.println(String.format("--未编码--: %s", time));
|
// System.out.println(String.format("--未编码--: %s", time));
|
||||||
// String hex = toCp56Hex(time);
|
// String hex = toCp56Hex(time);
|
||||||
// System.out.println("--编码1--:" + hex);
|
// System.out.println("--编码1--:" + hex);
|
||||||
System.out.println("--下达1--:" + DateUtil.format(cp56toDate("F0552E151E0815"),
|
System.out.println(HexUtils.toBinaryString("CA600D173F0116"));
|
||||||
NORM_DATETIME_FORMAT));
|
System.out.println("--下达1--:" + DateUtil.format(cp56toDate("C05D0D171F0116"), NORM_DATETIME_FORMATTER));
|
||||||
|
System.out.println("toCp56Hex = " + toCp56Hex(cp56toDate("C05D0D171F0116")));
|
||||||
// System.out.println("--下达2--:" + DateUtil.format(cp56toDate(""), NORM_DATETIME_FORMAT));
|
// System.out.println("--下达2--:" + DateUtil.format(cp56toDate(""), NORM_DATETIME_FORMAT));
|
||||||
|
|
||||||
|
|
||||||
String dateStr = "2017-03-01 22:33:23";
|
String dateStr = "2017-03-01 22:33:23";
|
||||||
Date date = DateUtil.parse(dateStr);
|
Date date = DateUtil.parse(dateStr);
|
||||||
Date newDate = DateUtil.offset(date, DateField.DAY_OF_MONTH, 2);
|
Date newDate = DateUtil.offset(date, DateField.DAY_OF_MONTH, 2);
|
||||||
|
|
||||||
System.out.println("--变为--:" + newDate.toString());
|
System.out.println("--变为--:" + newDate.toString());
|
||||||
System.out.println("sudo date " + newDate.getTime());
|
System.out.println("sudo date " + newDate.getTime());
|
||||||
// System.out.println("--D0073211110815--:" + DateUtil.format(cp56toDate("D0073211110815"), NORM_DATETIME_FORMAT));
|
// System.out.println("--D0073211110815--:" + DateUtil.format(cp56toDate("D0073211110815"), NORM_DATETIME_FORMAT));
|
||||||
@ -243,7 +232,6 @@ public class CP56Time2a {
|
|||||||
// String encode = encode(time);
|
// String encode = encode(time);
|
||||||
// System.out.println(String.format("--编码2--:%s", encode));
|
// System.out.println(String.format("--编码2--:%s", encode));
|
||||||
// System.out.println("--解码2--:" + decode(HexUtils.toBytes(encode)));
|
// System.out.println("--解码2--:" + decode(HexUtils.toBytes(encode)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user