added data formatter and updated data / tools
This commit is contained in:
9
src/tools/data_formatter/.gitignore
vendored
Normal file
9
src/tools/data_formatter/.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
.idea
|
||||
.idea/
|
||||
*/bin
|
||||
*.class
|
||||
*/.settings
|
||||
*/.jar
|
||||
*.bin
|
||||
out
|
||||
out/
|
||||
BIN
src/tools/data_formatter/lib/mysql-connector-java-5.0.8-bin.jar
Normal file
BIN
src/tools/data_formatter/lib/mysql-connector-java-5.0.8-bin.jar
Normal file
Binary file not shown.
3
src/tools/data_formatter/src/META-INF/MANIFEST.MF
Normal file
3
src/tools/data_formatter/src/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.irext.formatter.IRextDataFormatter
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-17
|
||||
*
|
||||
* data formatter for IREXT
|
||||
*/
|
||||
|
||||
package com.irext.formatter;
|
||||
|
||||
import com.irext.formatter.robot.DataFormatter;
|
||||
import com.irext.formatter.robot.ReHasher;
|
||||
|
||||
public class IRextDataFormatter {
|
||||
|
||||
private final static int FUNCTION_FORMAT = 0;
|
||||
private final static int FUNCTION_REHASH = 1;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
int mFunction = Integer.parseInt(args[0]);
|
||||
|
||||
switch(mFunction) {
|
||||
case FUNCTION_FORMAT: {
|
||||
if (5 != args.length) {
|
||||
System.out.println("invalid parameter");
|
||||
System.out.println("Please call this method like IRextDataFormatter [function_code = 0] " +
|
||||
"[source_db] [dest_db] [db_user] [db_password]");
|
||||
return;
|
||||
}
|
||||
String sourceDB = args[1];
|
||||
String destDB = args[2];
|
||||
String dbUser = args[3];
|
||||
String dbPassword = args[4];
|
||||
DataFormatter dataFormatter = new DataFormatter(sourceDB, destDB, dbUser, dbPassword);
|
||||
dataFormatter.dataFormat();
|
||||
break;
|
||||
}
|
||||
|
||||
case FUNCTION_REHASH: {
|
||||
if (5 != args.length) {
|
||||
System.out.println("invalid parameter");
|
||||
System.out.println("Please call this method like IRextDataFormatter [function_code = 1] " +
|
||||
"[db] [db_user] [db_password] [binary_path]");
|
||||
return;
|
||||
}
|
||||
String db = args[1];
|
||||
String dbUser = args[2];
|
||||
String dbPassword = args[3];
|
||||
String binaryPath = args[4];
|
||||
ReHasher rehasher = new ReHasher(db, dbUser, dbPassword, binaryPath);
|
||||
rehasher.rehashBinary();
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-17
|
||||
*
|
||||
* brand model
|
||||
*/
|
||||
|
||||
package com.irext.formatter.model;
|
||||
|
||||
public class Brand {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String updateTime;
|
||||
private int status;
|
||||
private int categoryID;
|
||||
private String categoryName;
|
||||
private int priority;
|
||||
private String nameEn;
|
||||
private String nameTw;
|
||||
private String contributor;
|
||||
|
||||
public Brand(int id, String name, String updateTime, int status, int categoryID, String categoryName,
|
||||
int priority, String nameEn, String nameTw, String contributor) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
this.categoryID = categoryID;
|
||||
this.categoryName = categoryName;
|
||||
this.priority = priority;
|
||||
this.nameEn = nameEn;
|
||||
this.nameTw = nameTw;
|
||||
this.contributor = contributor;
|
||||
}
|
||||
|
||||
public Brand() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getCategoryID() {
|
||||
return categoryID;
|
||||
}
|
||||
|
||||
public void setCategoryID(int categoryID) {
|
||||
this.categoryID = categoryID;
|
||||
}
|
||||
|
||||
public String getCategoryName() {
|
||||
return categoryName;
|
||||
}
|
||||
|
||||
public void setCategoryName(String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public String getNameEn() {
|
||||
return nameEn;
|
||||
}
|
||||
|
||||
public void setNameEn(String nameEn) {
|
||||
this.nameEn = nameEn;
|
||||
}
|
||||
|
||||
public String getNameTw() {
|
||||
return nameTw;
|
||||
}
|
||||
|
||||
public void setNameTw(String nameTw) {
|
||||
this.nameTw = nameTw;
|
||||
}
|
||||
|
||||
public String getContributor() {
|
||||
return contributor;
|
||||
}
|
||||
|
||||
public void setContributor(String contributor) {
|
||||
this.contributor = contributor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-17
|
||||
*
|
||||
* category model
|
||||
*/
|
||||
|
||||
package com.irext.formatter.model;
|
||||
|
||||
public class Category {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String updateTime;
|
||||
private int status;
|
||||
private String nameEn;
|
||||
private String nameTw;
|
||||
private String contributor;
|
||||
|
||||
public Category(int id, String name, String updateTime, int status, String nameEn, String nameTw,
|
||||
String contributor) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.updateTime = updateTime;
|
||||
this.status = status;
|
||||
this.nameEn = nameEn;
|
||||
this.nameTw = nameTw;
|
||||
this.contributor = contributor;
|
||||
}
|
||||
|
||||
public Category() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getNameEn() {
|
||||
return nameEn;
|
||||
}
|
||||
|
||||
public void setNameEn(String nameEn) {
|
||||
this.nameEn = nameEn;
|
||||
}
|
||||
|
||||
public String getNameTw() {
|
||||
return nameTw;
|
||||
}
|
||||
|
||||
public void setNameTw(String nameTw) {
|
||||
this.nameTw = nameTw;
|
||||
}
|
||||
|
||||
public String getContributor() {
|
||||
return contributor;
|
||||
}
|
||||
|
||||
public void setContributor(String contributor) {
|
||||
this.contributor = contributor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-17
|
||||
*
|
||||
* remote_index model
|
||||
*/
|
||||
|
||||
package com.irext.formatter.model;
|
||||
|
||||
public class IRProtocol {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private int status;
|
||||
private int type;
|
||||
private String updateTime;
|
||||
private String contributor;
|
||||
private String bootCode;
|
||||
|
||||
public IRProtocol(int id, String name, int status, int type, String updateTime,
|
||||
String contributor, String bootCode) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.status = status;
|
||||
this.type = type;
|
||||
this.updateTime = updateTime;
|
||||
this.contributor = contributor;
|
||||
this.bootCode = bootCode;
|
||||
}
|
||||
|
||||
public IRProtocol() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public String getContributor() {
|
||||
return contributor;
|
||||
}
|
||||
|
||||
public void setContributor(String contributor) {
|
||||
this.contributor = contributor;
|
||||
}
|
||||
|
||||
public String getBootCode() {
|
||||
return bootCode;
|
||||
}
|
||||
|
||||
public void setBootCode(String bootCode) {
|
||||
this.bootCode = bootCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-17
|
||||
*
|
||||
* remote_index model
|
||||
*/
|
||||
|
||||
package com.irext.formatter.model;
|
||||
|
||||
public class RemoteIndex {
|
||||
|
||||
private int id;
|
||||
private int categoryID;
|
||||
private String categoryName;
|
||||
private int brandID;
|
||||
private String brandName;
|
||||
private String cityCode;
|
||||
private String cityName;
|
||||
private String operatorID;
|
||||
private String operatorName;
|
||||
private String protocol;
|
||||
private String remote;
|
||||
private String remoteMap;
|
||||
private int status;
|
||||
private int subCategory;
|
||||
private int priority;
|
||||
private String remoteNumber;
|
||||
private String operatorNameTw;
|
||||
private String categoryNameTw;
|
||||
private String brandNameTw;
|
||||
private String cityNameTw;
|
||||
private String binaryMD5;
|
||||
private String contributor;
|
||||
private String updateTime;
|
||||
|
||||
public RemoteIndex(int id, int categoryID, String categoryName, int brandID, String brandName, String cityCode,
|
||||
String cityName, String operatorID, String operatorName, String protocol, String remote,
|
||||
String remoteMap, int status, int subCategory, int priority, String remoteNumber,
|
||||
String operatorNameTw, String categoryNameTw, String brandNameTw, String cityNameTw,
|
||||
String binaryMD5, String contributor, String updateTime) {
|
||||
this.id = id;
|
||||
this.categoryID = categoryID;
|
||||
this.categoryName = categoryName;
|
||||
this.brandID = brandID;
|
||||
this.brandName = brandName;
|
||||
this.cityCode = cityCode;
|
||||
this.cityName = cityName;
|
||||
this.operatorID = operatorID;
|
||||
this.operatorName = operatorName;
|
||||
this.protocol = protocol;
|
||||
this.remote = remote;
|
||||
this.remoteMap = remoteMap;
|
||||
this.status = status;
|
||||
this.subCategory = subCategory;
|
||||
this.priority = priority;
|
||||
this.remoteNumber = remoteNumber;
|
||||
this.operatorNameTw = operatorNameTw;
|
||||
this.categoryNameTw = categoryNameTw;
|
||||
this.brandNameTw = brandNameTw;
|
||||
this.cityNameTw = cityNameTw;
|
||||
this.binaryMD5 = binaryMD5;
|
||||
this.contributor = contributor;
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public RemoteIndex() {
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getCategoryID() {
|
||||
return categoryID;
|
||||
}
|
||||
|
||||
public void setCategoryID(int categoryID) {
|
||||
this.categoryID = categoryID;
|
||||
}
|
||||
|
||||
public String getCategoryName() {
|
||||
return categoryName;
|
||||
}
|
||||
|
||||
public void setCategoryName(String categoryName) {
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
|
||||
public int getBrandID() {
|
||||
return brandID;
|
||||
}
|
||||
|
||||
public void setBrandID(int brandID) {
|
||||
this.brandID = brandID;
|
||||
}
|
||||
|
||||
public String getBrandName() {
|
||||
return brandName;
|
||||
}
|
||||
|
||||
public void setBrandName(String brandName) {
|
||||
this.brandName = brandName;
|
||||
}
|
||||
|
||||
public String getCityCode() {
|
||||
return cityCode;
|
||||
}
|
||||
|
||||
public void setCityCode(String cityCode) {
|
||||
this.cityCode = cityCode;
|
||||
}
|
||||
|
||||
public String getCityName() {
|
||||
return cityName;
|
||||
}
|
||||
|
||||
public void setCityName(String cityName) {
|
||||
this.cityName = cityName;
|
||||
}
|
||||
|
||||
public String getOperatorID() {
|
||||
return operatorID;
|
||||
}
|
||||
|
||||
public void setOperatorID(String operatorID) {
|
||||
this.operatorID = operatorID;
|
||||
}
|
||||
|
||||
public String getOperatorName() {
|
||||
return operatorName;
|
||||
}
|
||||
|
||||
public void setOperatorName(String operatorName) {
|
||||
this.operatorName = operatorName;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getRemote() {
|
||||
return remote;
|
||||
}
|
||||
|
||||
public void setRemote(String remote) {
|
||||
this.remote = remote;
|
||||
}
|
||||
|
||||
public String getRemoteMap() {
|
||||
return remoteMap;
|
||||
}
|
||||
|
||||
public void setRemoteMap(String remoteMap) {
|
||||
this.remoteMap = remoteMap;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getSubCategory() {
|
||||
return subCategory;
|
||||
}
|
||||
|
||||
public void setSubCategory(int subCategory) {
|
||||
this.subCategory = subCategory;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void setPriority(int priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public String getRemoteNumber() {
|
||||
return remoteNumber;
|
||||
}
|
||||
|
||||
public void setRemoteNumber(String remoteNumber) {
|
||||
this.remoteNumber = remoteNumber;
|
||||
}
|
||||
|
||||
public String getOperatorNameTw() {
|
||||
return operatorNameTw;
|
||||
}
|
||||
|
||||
public void setOperatorNameTw(String operatorNameTw) {
|
||||
this.operatorNameTw = operatorNameTw;
|
||||
}
|
||||
|
||||
public String getCategoryNameTw() {
|
||||
return categoryNameTw;
|
||||
}
|
||||
|
||||
public void setCategoryNameTw(String categoryNameTw) {
|
||||
this.categoryNameTw = categoryNameTw;
|
||||
}
|
||||
|
||||
public String getBrandNameTw() {
|
||||
return brandNameTw;
|
||||
}
|
||||
|
||||
public void setBrandNameTw(String brandNameTw) {
|
||||
this.brandNameTw = brandNameTw;
|
||||
}
|
||||
|
||||
public String getCityNameTw() {
|
||||
return cityNameTw;
|
||||
}
|
||||
|
||||
public void setCityNameTw(String cityNameTw) {
|
||||
this.cityNameTw = cityNameTw;
|
||||
}
|
||||
|
||||
public String getBinaryMD5() {
|
||||
return binaryMD5;
|
||||
}
|
||||
|
||||
public void setBinaryMD5(String binaryMD5) {
|
||||
this.binaryMD5 = binaryMD5;
|
||||
}
|
||||
|
||||
public String getContributor() {
|
||||
return contributor;
|
||||
}
|
||||
|
||||
public void setContributor(String contributor) {
|
||||
this.contributor = contributor;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-17
|
||||
*
|
||||
* data formatter
|
||||
*/
|
||||
|
||||
package com.irext.formatter.robot;
|
||||
|
||||
import com.irext.formatter.utils.VeDate;
|
||||
import com.mysql.jdbc.Connection;
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
import com.mysql.jdbc.ResultSet;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class DataFormatter {
|
||||
|
||||
private String mSourceDB;
|
||||
private String mDestDB;
|
||||
private String mDBUser;
|
||||
private String mDBPassword;
|
||||
|
||||
private static String driver = "com.mysql.jdbc.Driver";
|
||||
private Connection mSourceConnection = null;
|
||||
private Connection mDestConnection = null;
|
||||
|
||||
public DataFormatter(String sourceDB, String destDB, String dbUser, String dbPassword) {
|
||||
mSourceDB = sourceDB;
|
||||
mDestDB = destDB;
|
||||
mDBUser = dbUser;
|
||||
mDBPassword = dbPassword;
|
||||
}
|
||||
|
||||
public boolean dataFormat() {
|
||||
String srcSqlString;
|
||||
String innerSrcSqlString;
|
||||
String destSqlString;
|
||||
String innerDestSqlString;
|
||||
|
||||
PreparedStatement srcStatement;
|
||||
PreparedStatement innerSrcStatement;
|
||||
PreparedStatement destStatement;
|
||||
PreparedStatement innerDestStatement;
|
||||
|
||||
ResultSet srcResultSet;
|
||||
ResultSet innerSrcResultSet;
|
||||
ResultSet destResultSet;
|
||||
ResultSet innerDestResultSet;
|
||||
|
||||
try {
|
||||
Class.forName(driver);
|
||||
mSourceConnection = (com.mysql.jdbc.Connection) DriverManager.getConnection(mSourceDB, mDBUser, mDBPassword);
|
||||
mDestConnection = (com.mysql.jdbc.Connection) DriverManager.getConnection(mDestDB, mDBUser, mDBPassword);
|
||||
|
||||
// format ir protocol
|
||||
System.out.println("format ir_protocol");
|
||||
|
||||
srcSqlString = "SELECT * FROM ir_protocol";
|
||||
srcStatement = (PreparedStatement) mSourceConnection.prepareStatement(srcSqlString);
|
||||
srcResultSet = (ResultSet) srcStatement.executeQuery();
|
||||
while(srcResultSet.next()) {
|
||||
int id = srcResultSet.getInt("id");
|
||||
String name = srcResultSet.getString("name");
|
||||
int status = srcResultSet.getInt("status");
|
||||
int type = srcResultSet.getInt("type");
|
||||
|
||||
innerDestSqlString = "SELECT * FROM ir_protocol WHERE name = '" + name + "';";
|
||||
innerDestStatement = (PreparedStatement) mSourceConnection.prepareStatement(innerDestSqlString);
|
||||
innerDestResultSet = (ResultSet) innerDestStatement.executeQuery();
|
||||
if (!innerDestResultSet.next()) {
|
||||
destSqlString = "INSERT INTO ir_protocol(name, status, type, update_time, contributor, boot_code) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?);";
|
||||
destStatement = (PreparedStatement) mDestConnection.prepareStatement(destSqlString);
|
||||
destStatement.setString(1, name);
|
||||
destStatement.setInt(2, status);
|
||||
destStatement.setInt(3, type);
|
||||
destStatement.setString(4, VeDate.getStringDateShort());
|
||||
destStatement.setString(5, "formatter");
|
||||
destStatement.setString(6, "");
|
||||
|
||||
destStatement.executeUpdate();
|
||||
|
||||
System.out.println("protocol " + name + " has been created");
|
||||
}
|
||||
}
|
||||
|
||||
// format table category
|
||||
System.out.println("format category");
|
||||
|
||||
srcSqlString = "SELECT * FROM category";
|
||||
srcStatement = (PreparedStatement) mSourceConnection.prepareStatement(srcSqlString);
|
||||
srcResultSet = (ResultSet) srcStatement.executeQuery();
|
||||
while(srcResultSet.next()) {
|
||||
int id = srcResultSet.getInt("id");
|
||||
String name = srcResultSet.getString("name");
|
||||
int status = srcResultSet.getInt("status");
|
||||
String nameEn = srcResultSet.getString("name_en");
|
||||
String nameTw = srcResultSet.getString("name_tw");
|
||||
|
||||
innerDestSqlString = "SELECT * FROM category WHERE name = '" + name + "';";
|
||||
innerDestStatement = (PreparedStatement) mDestConnection.prepareStatement(innerDestSqlString);
|
||||
innerDestResultSet = (ResultSet) innerDestStatement.executeQuery();
|
||||
if (!innerDestResultSet.next()) {
|
||||
destSqlString = "INSERT INTO category(name, status, update_time, name_en, name_tw, contributor) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?);";
|
||||
destStatement = (PreparedStatement) mDestConnection.prepareStatement(destSqlString);
|
||||
destStatement.setString(1, name);
|
||||
destStatement.setInt(2, status);
|
||||
destStatement.setString(3, VeDate.getStringDateShort());
|
||||
destStatement.setString(4, nameEn);
|
||||
destStatement.setString(5, nameTw);
|
||||
destStatement.setString(6, "formatter");
|
||||
|
||||
destStatement.executeUpdate();
|
||||
|
||||
System.out.println("category " + name + " has been created");
|
||||
}
|
||||
}
|
||||
|
||||
// format table brand
|
||||
System.out.println("format brand");
|
||||
|
||||
srcSqlString = "SELECT * FROM brand";
|
||||
srcStatement = (PreparedStatement) mSourceConnection.prepareStatement(srcSqlString);
|
||||
srcResultSet = (ResultSet) srcStatement.executeQuery();
|
||||
while(srcResultSet.next()) {
|
||||
int id = srcResultSet.getInt("id");
|
||||
String name = srcResultSet.getString("name");
|
||||
|
||||
// TODO: optimize category ID fetcher
|
||||
int categoryID = srcResultSet.getInt("category_id");
|
||||
String categoryName = srcResultSet.getString("category_name");
|
||||
int status = srcResultSet.getInt("status");
|
||||
int priority = srcResultSet.getInt("priority");
|
||||
String nameEn = srcResultSet.getString("name_en");
|
||||
String nameTw = srcResultSet.getString("name_tw");
|
||||
|
||||
innerDestSqlString = "SELECT * FROM brand WHERE name = '" + name +
|
||||
"' AND category_id = '" + categoryID + "';";
|
||||
innerDestStatement = (PreparedStatement) mDestConnection.prepareStatement(innerDestSqlString);
|
||||
innerDestResultSet = (ResultSet) innerDestStatement.executeQuery();
|
||||
if (!innerDestResultSet.next()) {
|
||||
destSqlString = "INSERT INTO brand(name, category_id, category_name, " +
|
||||
"status, update_time, priority, name_en, name_tw, contributor) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
destStatement = (PreparedStatement) mDestConnection.prepareStatement(destSqlString);
|
||||
destStatement.setString(1, name);
|
||||
destStatement.setInt(2, categoryID);
|
||||
destStatement.setString(3, categoryName);
|
||||
destStatement.setInt(4, status);
|
||||
destStatement.setString(5, VeDate.getStringDateShort());
|
||||
destStatement.setInt(6, priority);
|
||||
destStatement.setString(7, nameEn);
|
||||
destStatement.setString(8, nameTw);
|
||||
destStatement.setString(9, "formatter");
|
||||
|
||||
destStatement.executeUpdate();
|
||||
|
||||
System.out.println("brand " + name + " of "+ categoryName + " has been created");
|
||||
}
|
||||
}
|
||||
|
||||
// format table remote_index
|
||||
System.out.println("format remote index");
|
||||
|
||||
srcSqlString = "SELECT * FROM remote_index_ii";
|
||||
srcStatement = (PreparedStatement) mSourceConnection.prepareStatement(srcSqlString);
|
||||
srcResultSet = (ResultSet) srcStatement.executeQuery();
|
||||
while(srcResultSet.next()) {
|
||||
int id = srcResultSet.getInt("id");
|
||||
|
||||
// TODO: optimize category ID fetcher
|
||||
int categoryID = srcResultSet.getInt("category_id");
|
||||
String categoryName = srcResultSet.getString("category_name");
|
||||
String brandName = srcResultSet.getString("brand_name");
|
||||
String cityCode = srcResultSet.getString("city_code");
|
||||
String cityName = srcResultSet.getString("city_name");
|
||||
String operatorID = srcResultSet.getString("operator_id");
|
||||
String operatorName = srcResultSet.getString("operator_name");
|
||||
String categoryNameTw = srcResultSet.getString("category_name_tw");
|
||||
String brandNameTw = srcResultSet.getString("brand_name_tw");
|
||||
String operatorNameTw = srcResultSet.getString("operator_name_tw");
|
||||
String cityNameTw = srcResultSet.getString("city_name_tw");
|
||||
|
||||
String protocol = srcResultSet.getString("protocol");
|
||||
String remote = srcResultSet.getString("remote");
|
||||
String remoteMap = srcResultSet.getString("remote_map");
|
||||
|
||||
int status = srcResultSet.getInt("status");
|
||||
int subCate = srcResultSet.getInt("sub_cate");
|
||||
int priority = srcResultSet.getInt("priority");
|
||||
String binaryMD5 = srcResultSet.getString("binary_md5");
|
||||
|
||||
int brandID = 0;
|
||||
|
||||
if (3 != categoryID) {
|
||||
innerDestSqlString = "SELECT * FROM remote_index WHERE category_id = '" + categoryID + "' AND " +
|
||||
"brand_name = '" + brandName + "';";
|
||||
innerDestStatement = (PreparedStatement) mDestConnection.prepareStatement(innerDestSqlString);
|
||||
innerDestResultSet = (ResultSet) innerDestStatement.executeQuery();
|
||||
if (innerDestResultSet.next()) {
|
||||
brandID = innerDestResultSet.getInt("id");
|
||||
} else {
|
||||
brandID = 0;
|
||||
}
|
||||
} else {
|
||||
brandID = 0;
|
||||
}
|
||||
|
||||
if (3 != categoryID) {
|
||||
innerDestSqlString = "SELECT * FROM remote_index WHERE category_name = '" + categoryName + "' AND " +
|
||||
"brand_name = '" + brandName + "' AND protocol = '" + protocol + "' AND " +
|
||||
"remote = '" + remote + "';";
|
||||
} else {
|
||||
innerDestSqlString = "SELECT * FROM remote_index WHERE category_name = '" + categoryName + "' AND " +
|
||||
"city_code = '" + cityCode + "' AND protocol = '" + protocol + "' AND " +
|
||||
"remote = '" + remote + "';";
|
||||
}
|
||||
|
||||
innerDestStatement = (PreparedStatement) mDestConnection.prepareStatement(innerDestSqlString);
|
||||
innerDestResultSet = (ResultSet) innerDestStatement.executeQuery();
|
||||
if (!innerDestResultSet.next()) {
|
||||
destSqlString = "INSERT INTO remote_index(category_id, category_name, brand_id, brand_name, " +
|
||||
"city_code, city_name, operator_id, operator_name, category_name_tw, brand_name_tw, " +
|
||||
"city_name_tw, operator_name_tw, protocol, remote, remote_map, status, sub_cate," +
|
||||
"priority, remote_number, binary_md5, update_time, contributor) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
destStatement = (PreparedStatement) mDestConnection.prepareStatement(destSqlString);
|
||||
|
||||
destStatement.setInt(1, categoryID);
|
||||
destStatement.setString(2, categoryName);
|
||||
destStatement.setInt(3, brandID);
|
||||
destStatement.setString(4, brandName);
|
||||
destStatement.setString(5, cityCode);
|
||||
destStatement.setString(6, cityName);
|
||||
destStatement.setString(7, operatorID);
|
||||
destStatement.setString(8, operatorName);
|
||||
destStatement.setString(9, categoryNameTw);
|
||||
destStatement.setString(10, brandNameTw);
|
||||
destStatement.setString(11, cityNameTw);
|
||||
destStatement.setString(12, operatorNameTw);
|
||||
destStatement.setString(13, protocol);
|
||||
destStatement.setString(14, remote);
|
||||
destStatement.setString(15, remoteMap);
|
||||
destStatement.setInt(16, status);
|
||||
destStatement.setInt(17, subCate);
|
||||
destStatement.setInt(18, priority);
|
||||
destStatement.setString(19, id + "");
|
||||
destStatement.setString(20, binaryMD5);
|
||||
destStatement.setString(21, VeDate.getStringDateShort());
|
||||
destStatement.setString(22, "formatter");
|
||||
destStatement.executeUpdate();
|
||||
System.out.println("remote " + remoteMap + " has been created");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Created by strawmanbobi
|
||||
* 2017-01-22
|
||||
*
|
||||
* binary re-hash
|
||||
*/
|
||||
|
||||
package com.irext.formatter.robot;
|
||||
|
||||
import com.mysql.jdbc.Connection;
|
||||
import com.mysql.jdbc.PreparedStatement;
|
||||
import com.mysql.jdbc.ResultSet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class ReHasher {
|
||||
|
||||
private String mDB;
|
||||
private String mDBUser;
|
||||
private String mDBPassword;
|
||||
private String mBinaryPath;
|
||||
|
||||
private static String driver = "com.mysql.jdbc.Driver";
|
||||
private Connection mConnection = null;
|
||||
|
||||
public ReHasher(String db, String dbUser, String dbPassword, String binaryPath) {
|
||||
mDB = db;
|
||||
mDBUser = dbUser;
|
||||
mDBPassword = dbPassword;
|
||||
mBinaryPath = binaryPath;
|
||||
}
|
||||
|
||||
public boolean rehashBinary() {
|
||||
String sqlString;
|
||||
String innerSqlString;
|
||||
|
||||
PreparedStatement statement;
|
||||
PreparedStatement innerStatement;
|
||||
|
||||
ResultSet resultSet;
|
||||
ResultSet innerResultSet;
|
||||
|
||||
try {
|
||||
Class.forName(driver);
|
||||
mConnection = (Connection) DriverManager.getConnection(mDB, mDBUser, mDBPassword);
|
||||
|
||||
// traverse remote index in db
|
||||
System.out.println("re-hash binary code");
|
||||
|
||||
sqlString = "SELECT * FROM remote_index";
|
||||
statement = (PreparedStatement) mConnection.prepareStatement(sqlString);
|
||||
resultSet = (ResultSet) statement.executeQuery();
|
||||
while(resultSet.next()) {
|
||||
int id = resultSet.getInt("id");
|
||||
String protocol = resultSet.getString("protocol");
|
||||
String remote = resultSet.getString("remote");
|
||||
String binaryFilePath = mBinaryPath + "/irda_" + protocol + "_" + remote + ".bin";
|
||||
System.out.println(binaryFilePath);
|
||||
String md5 = getFileMD5(new File(binaryFilePath));
|
||||
if (null == md5) {
|
||||
md5 = "00000000000000000000000000000000";
|
||||
}
|
||||
System.out.println(md5);
|
||||
|
||||
innerSqlString = "UPDATE remote_index SET binary_md5 = ? WHERE id = '" + id + "';";
|
||||
innerStatement = (PreparedStatement) mConnection.prepareStatement(innerSqlString);
|
||||
innerStatement.setString(1, md5);
|
||||
innerStatement.executeUpdate();
|
||||
|
||||
System.out.println("md5 has been updated for code " + protocol + "_" + remote);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getFileMD5(File file) {
|
||||
if (!file.isFile()) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest digest = null;
|
||||
FileInputStream in = null;
|
||||
byte buffer[] = new byte[1024];
|
||||
int len;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
in = new FileInputStream(file);
|
||||
while ((len = in.read(buffer, 0, 1024)) != -1) {
|
||||
digest.update(buffer, 0, len);
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
BigInteger bigInt = new BigInteger(1, digest.digest());
|
||||
return bigInt.toString(16);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,590 @@
|
||||
/**
|
||||
* Created by Strawmanbobi on 2015-08-30.
|
||||
*/
|
||||
|
||||
package com.irext.formatter.utils;
|
||||
|
||||
import java.text.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
public class VeDate {
|
||||
|
||||
private static final int CAL_DAY_IN_MONTH = 42;
|
||||
/**
|
||||
* Get current time
|
||||
*
|
||||
* @return time in long format yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
public static Date getNowDate() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = formatter.format(currentTime);
|
||||
ParsePosition pos = new ParsePosition(8);
|
||||
Date currentTime_2 = formatter.parse(dateString, pos);
|
||||
return currentTime_2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current time
|
||||
*
|
||||
* @return time in short format yyyy-MM-dd HH:mm:ss
|
||||
*/
|
||||
public static Date getNowDateShort() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String dateString = formatter.format(currentTime);
|
||||
ParsePosition pos = new ParsePosition(8);
|
||||
Date currentTime_2 = formatter.parse(dateString, pos);
|
||||
return currentTime_2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current time
|
||||
*
|
||||
* @return time in string format
|
||||
*/
|
||||
public static String getStringDate() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = formatter.format(currentTime);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current time
|
||||
*
|
||||
* @return time in string format
|
||||
*/
|
||||
public static String getStringDateShort() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String dateString = formatter.format(currentTime);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current time
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getTimeShort() {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||
Date currentTime = new Date();
|
||||
String dateString = formatter.format(currentTime);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string format to long time format
|
||||
*
|
||||
* @param strDate
|
||||
* @return
|
||||
*/
|
||||
public static Date strToDateLong(String strDate) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Date strtodate = formatter.parse(strDate, pos);
|
||||
return strtodate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert long time format to string format
|
||||
*
|
||||
* @param dateDate
|
||||
* @return
|
||||
*/
|
||||
public static String dateToStrLong(Date dateDate) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = formatter.format(dateDate);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert date format to string format
|
||||
*
|
||||
* @param dateDate
|
||||
* @param k
|
||||
* @return
|
||||
*/
|
||||
public static String dateToStr(Date dateDate) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String dateString = formatter.format(dateDate);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string format to short time format
|
||||
*
|
||||
* @param strDate
|
||||
* @return
|
||||
*/
|
||||
public static Date strToDate(String strDate) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Date strtodate = formatter.parse(strDate, pos);
|
||||
return strtodate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Now
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Date getNow() {
|
||||
Date currentTime = new Date();
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last day of a month
|
||||
*
|
||||
* @param day
|
||||
* @return
|
||||
*/
|
||||
public static Date getLastDate(long day) {
|
||||
Date date = new Date();
|
||||
long date_3_hm = date.getTime() - 3600000 * 24 * day;
|
||||
Date date_3_hm_date = new Date(date_3_hm);
|
||||
return date_3_hm_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current time
|
||||
*
|
||||
* @return time in format : yyyyMMdd HHmmss
|
||||
*/
|
||||
public static String getStringToday() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");
|
||||
String dateString = formatter.format(currentTime);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current hour
|
||||
*/
|
||||
public static String getHour() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = formatter.format(currentTime);
|
||||
String hour;
|
||||
hour = dateString.substring(11, 13);
|
||||
return hour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current minute
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getTime() {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = formatter.format(currentTime);
|
||||
String min;
|
||||
min = dateString.substring(14, 16);
|
||||
return min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time format yyyyMMddhhmmss by user input
|
||||
*
|
||||
* @param sformat
|
||||
* yyyyMMddhhmmss
|
||||
* @return
|
||||
*/
|
||||
public static String getUserDate(String sformat) {
|
||||
Date currentTime = new Date();
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(sformat);
|
||||
String dateString = formatter.format(currentTime);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String getTwoHour(String st1, String st2) {
|
||||
String[] kk = null;
|
||||
String[] jj = null;
|
||||
kk = st1.split(":");
|
||||
jj = st2.split(":");
|
||||
if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0]))
|
||||
return "0";
|
||||
else {
|
||||
double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1])
|
||||
/ 60;
|
||||
double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1])
|
||||
/ 60;
|
||||
if ((y - u) > 0)
|
||||
return y - u + "";
|
||||
else
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String getTwoDay(String sj1, String sj2) {
|
||||
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
long day = 0;
|
||||
try {
|
||||
Date date = myFormatter.parse(sj1);
|
||||
Date mydate = myFormatter.parse(sj2);
|
||||
day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
return day + "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String getPreTime(String sj1, String jj) {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String mydate1 = "";
|
||||
try {
|
||||
Date date1 = format.parse(sj1);
|
||||
long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;
|
||||
date1.setTime(Time * 1000);
|
||||
mydate1 = format.format(date1);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return mydate1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static String getNextDay(String nowdate, String delay) {
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String mdate = "";
|
||||
Date d = strToDate(nowdate);
|
||||
long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24
|
||||
* 60 * 60;
|
||||
d.setTime(myTime * 1000);
|
||||
mdate = format.format(d);
|
||||
return mdate;
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param ddate
|
||||
* @return
|
||||
*/
|
||||
public static boolean isLeapYear(String ddate) {
|
||||
Date d = strToDate(ddate);
|
||||
GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
|
||||
gc.setTime(d);
|
||||
int year = gc.get(Calendar.YEAR);
|
||||
if ((year % 400) == 0)
|
||||
return true;
|
||||
else if ((year % 4) == 0) {
|
||||
if ((year % 100) == 0)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String getEDate(String str) {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Date strtodate = formatter.parse(str, pos);
|
||||
String j = strtodate.toString();
|
||||
String[] k = j.split(" ");
|
||||
return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param dat
|
||||
* @return
|
||||
*/
|
||||
public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd
|
||||
String str = dat.substring(0, 8);
|
||||
String month = dat.substring(5, 7);
|
||||
int mon = Integer.parseInt(month);
|
||||
if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8
|
||||
|| mon == 10 || mon == 12) {
|
||||
str += "31";
|
||||
} else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
|
||||
str += "30";
|
||||
} else {
|
||||
if (isLeapYear(dat)) {
|
||||
str += "29";
|
||||
} else {
|
||||
str += "28";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param date1
|
||||
* @param date2
|
||||
* @return
|
||||
*/
|
||||
public static boolean isSameWeekDates(Date date1, Date date2) {
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
cal1.setTime(date1);
|
||||
cal2.setTime(date2);
|
||||
int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
|
||||
if (0 == subYear) {
|
||||
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2
|
||||
.get(Calendar.WEEK_OF_YEAR))
|
||||
return true;
|
||||
} else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) {
|
||||
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2
|
||||
.get(Calendar.WEEK_OF_YEAR))
|
||||
return true;
|
||||
} else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) {
|
||||
if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2
|
||||
.get(Calendar.WEEK_OF_YEAR))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getSeqWeek() {
|
||||
Calendar c = Calendar.getInstance(Locale.CHINA);
|
||||
String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR));
|
||||
if (week.length() == 1)
|
||||
week = "0" + week;
|
||||
String year = Integer.toString(c.get(Calendar.YEAR));
|
||||
return year + week;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param sdate
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static String getWeek(String sdate, String num) {
|
||||
Date dd = VeDate.strToDate(sdate);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(dd);
|
||||
if (num.equals("1"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
|
||||
else if (num.equals("2"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
|
||||
else if (num.equals("3"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
|
||||
else if (num.equals("4"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
|
||||
else if (num.equals("5"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
|
||||
else if (num.equals("6"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
|
||||
else if (num.equals("0"))
|
||||
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
||||
return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param sdate
|
||||
* @return
|
||||
*/
|
||||
public static String getWeek(String sdate) {
|
||||
Date date = VeDate.strToDate(sdate);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
return new SimpleDateFormat("EEEE").format(c.getTime());
|
||||
}
|
||||
|
||||
public static String getWeekStr(String sdate) {
|
||||
String str = "";
|
||||
str = VeDate.getWeek(sdate);
|
||||
if ("1".equals(str)) {
|
||||
str = "星期日";
|
||||
} else if ("2".equals(str)) {
|
||||
str = "星期一";
|
||||
} else if ("3".equals(str)) {
|
||||
str = "星期二";
|
||||
} else if ("4".equals(str)) {
|
||||
str = "星期三";
|
||||
} else if ("5".equals(str)) {
|
||||
str = "星期四";
|
||||
} else if ("6".equals(str)) {
|
||||
str = "星期五";
|
||||
} else if ("7".equals(str)) {
|
||||
str = "星期六";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param date1
|
||||
* @param date2
|
||||
* @return
|
||||
*/
|
||||
public static long getDays(String date1, String date2) {
|
||||
if (date1 == null || date1.equals(""))
|
||||
return 0;
|
||||
if (date2 == null || date2.equals(""))
|
||||
return 0;
|
||||
SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = null;
|
||||
Date mydate = null;
|
||||
try {
|
||||
date = myFormatter.parse(date1);
|
||||
mydate = myFormatter.parse(date2);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param sdate
|
||||
* @return
|
||||
*/
|
||||
public static String getNowMonth(String sdate) {
|
||||
sdate = sdate.substring(0, 8) + "01";
|
||||
|
||||
Date date = VeDate.strToDate(sdate);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
int u = c.get(Calendar.DAY_OF_WEEK);
|
||||
String newday = VeDate.getNextDay(sdate, (1 - u) + "");
|
||||
return newday;
|
||||
}
|
||||
|
||||
/*
|
||||
* get the beginning date of a given month in calendar
|
||||
*/
|
||||
public static String getBeginDateinCal(String sdate) {
|
||||
sdate = sdate.substring(0, 7) + "-01";
|
||||
Date date = VeDate.strToDate(sdate);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
int u = c.get(Calendar.DAY_OF_WEEK);
|
||||
String newday = VeDate.getNextDay(sdate, (1 - u) + "");
|
||||
return newday;
|
||||
}
|
||||
|
||||
/*
|
||||
* get the end date of a given month in calendar
|
||||
*/
|
||||
public static String getEndDateinCal(String sdate) {
|
||||
sdate = sdate.substring(0, 7) + "-01";
|
||||
String edate = getEndDateOfMonth(sdate);
|
||||
int dayOfMonth = getDayOfMonth(sdate);
|
||||
|
||||
Date date = VeDate.strToDate(sdate);
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
int u = c.get(Calendar.DAY_OF_WEEK);
|
||||
int dayCountPrefix = u - 1;
|
||||
|
||||
int dayCountSuffix = CAL_DAY_IN_MONTH - dayCountPrefix - dayOfMonth;
|
||||
|
||||
String newday = VeDate.getNextDay(edate, dayCountSuffix + "");
|
||||
return newday;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
|
||||
public static String getNo(int k) {
|
||||
|
||||
return getUserDate("yyyyMMddhhmmss") + getRandom(k);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public static String getRandom(int i) {
|
||||
Random jjj = new Random();
|
||||
// int suiJiShu = jjj.nextInt(9);
|
||||
if (i == 0)
|
||||
return "";
|
||||
String jj = "";
|
||||
for (int k = 0; k < i; k++) {
|
||||
jj = jj + jjj.nextInt(9);
|
||||
}
|
||||
return jj;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
public static boolean RightDate(String date) {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
;
|
||||
if (date == null)
|
||||
return false;
|
||||
if (date.length() > 10) {
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
} else {
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
try {
|
||||
sdf.parse(date);
|
||||
} catch (ParseException pe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
* get day of month for date string in format 'yyyy-MM-dd'
|
||||
*/
|
||||
public static int getDayOfMonth(String date) {
|
||||
int mon = Integer.parseInt(date.substring(5, 7));
|
||||
if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8
|
||||
|| mon == 10 || mon == 12) {
|
||||
return 31;
|
||||
} else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
|
||||
return 30;
|
||||
} else {
|
||||
String comDate = date.substring(0, 7) + "-01";
|
||||
if (isLeapYear(comDate)) {
|
||||
return 29;
|
||||
} else {
|
||||
return 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user