Merge branch 'script_gj' into 'master'

修改

See merge request !1013
This commit is contained in:
2024-11-20 13:49:03 +08:00
5 changed files with 143 additions and 13 deletions
+7
View File
@@ -530,6 +530,13 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15to18</artifactId>
<version>1.70</version> <!-- 确保使用最新版本 -->
</dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.fangjia</groupId>--> <!-- <groupId>com.fangjia</groupId>-->
<!-- <artifactId>fangjia-open</artifactId>--> <!-- <artifactId>fangjia-open</artifactId>-->
@@ -177,7 +177,6 @@ class AutoAddDistrictBatch extends BaseBatch{
q.put("match_id", new BasicDBObject('$exists',false)) q.put("match_id", new BasicDBObject('$exists',false))
q.put("old_match_id", new BasicDBObject('$exists',false)) q.put("old_match_id", new BasicDBObject('$exists',false))
q.put("city", c) q.put("city", c)
q.put("name", "钱江大厦")
def dbcursor = thirdSeaweedMappingColl.find(q).batchSize(5000) def dbcursor = thirdSeaweedMappingColl.find(q).batchSize(5000)
def rMap = [:] def rMap = [:]
for(def d : dbcursor){ for(def d : dbcursor){
@@ -4,7 +4,6 @@ import com.fangjia.script.BaseBatch
import com.fangjia.script.BatchOwner import com.fangjia.script.BatchOwner
import com.fangjia.script.Watcher import com.fangjia.script.Watcher
import com.fangjia.script.commData.CommonDatautils import com.fangjia.script.commData.CommonDatautils
import com.fangjia.script.common.DataHandleUtils
import com.fangjia.script.gj.district.FangjiaClientUtils import com.fangjia.script.gj.district.FangjiaClientUtils
import com.fangjia.script.util.CommonUtils import com.fangjia.script.util.CommonUtils
import com.fangjia.script.util.DataUtil import com.fangjia.script.util.DataUtil
@@ -12,14 +11,11 @@ import com.fangjia.script.util.DateUtils
import com.fangjia.script.util.MongoUtils import com.fangjia.script.util.MongoUtils
import com.mongodb.BasicDBObject import com.mongodb.BasicDBObject
import com.mongodb.DBCollection import com.mongodb.DBCollection
import org.bson.types.ObjectId
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.atomic.AtomicLong import java.util.concurrent.atomic.AtomicLong
/** /**
* 第三方小区与我们小区映射关系表 * 第三方小区与我们小区映射关系表
*/ */
@@ -44,7 +40,7 @@ class ThirdPriceMappingBatch extends BaseBatch{
@Override @Override
public void process(Object args) { public void process(Object args) {
// //将新增数据同步过来 // //将新增数据同步过来
// addNemCommunity() addNemCommunity()
// //接口进行匹配 // //接口进行匹配
match() match()
@@ -0,0 +1,115 @@
package com.fangjia.script.gj.xiamen
import org.bouncycastle.crypto.engines.SM4Engine;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.util.encoders.Hex;
import java.security.SecureRandom;
/**
* @author shenjian
* @since 2024/10/9
*/
public class CryptoSm4Util {
/**
* 默认密钥
*/
private static final String DEFAULT_SECRET_KEY = "A1B2C3D4E5F60789A1B2C3D4E5F60789";
private static final String CHARSET = "UTF-8";
// String plaintext -> Base64-encoded String ciphertext
public static String encrypt(String key, String plaintext) {
try {
byte[] keyBytes = Hex.decode(key);
byte[] iv = generateIV();
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new SM4Engine()));
cipher.init(true, new ParametersWithIV(new KeyParameter(keyBytes), iv));
byte[] input = plaintext.getBytes(CHARSET);
byte[] encrypted = new byte[cipher.getOutputSize(input.length)];
int length1 = cipher.processBytes(input, 0, input.length, encrypted, 0);
int length2 = cipher.doFinal(encrypted, length1);
byte[] finalEncrypted = new byte[length1 + length2];
System.arraycopy(encrypted, 0, finalEncrypted, 0, finalEncrypted.length);
return Hex.toHexString(iv) + Hex.toHexString(finalEncrypted);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
private static byte[] generateIV() {
byte[] iv = new byte[16];
new SecureRandom().nextBytes(iv);
return iv;
}
// Base64-encoded String ciphertext -> String plaintext
public static String decrypt(String key, String ciphertext) {
try {
byte[] keyBytes = Hex.decode(key);
byte[] iv = Hex.decode(ciphertext.substring(0, 32));
byte[] encryptedData = Hex.decode(ciphertext.substring(32));
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new SM4Engine()));
cipher.init(false, new ParametersWithIV(new KeyParameter(keyBytes), iv));
byte[] decrypted = new byte[cipher.getOutputSize(encryptedData.length)];
int length1 = cipher.processBytes(encryptedData, 0, encryptedData.length, decrypted, 0);
int length2 = cipher.doFinal(decrypted, length1);
byte[] finalDecrypted = new byte[length1 + length2];
System.arraycopy(decrypted, 0, finalDecrypted, 0, finalDecrypted.length);
return new String(finalDecrypted, CHARSET).trim();
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
/**
* 使用默认密钥加密
*
* @param str 加密内容
* @return 以String密文输入, String明文输出
*/
public static String encode(String str) {
return encode(DEFAULT_SECRET_KEY, str);
}
/**
* 自定义密钥加密
*
* @param key 自定义密钥
* @param str 加密的内容
* @return String明文输入, String密文输出
*/
public static String encode(String key, String str) {
return encrypt(key, str);
}
/**
* 使用默认密钥解密
*
* @param str 解密内容
* @return 以String密文输入, String明文输出
*/
public static String decode(String str) {
return decode(DEFAULT_SECRET_KEY, str);
}
/**
* 自定义密钥解密
*
* @param key 自定义密钥
* @param str 加密内容
* @return 以String密文输入, String明文输出
*/
public static String decode(String key, String str) {
return decrypt(key, str);
}
public static void main(def a){
println encrypt( DEFAULT_SECRET_KEY, "测试")
}
}
@@ -15,9 +15,13 @@ import com.mongodb.DBCollection
/** /**
* 厦门涉台园区数据同步 * 厦门涉台园区数据同步
*/ */
@BatchOwner(Watcher.GaoJuan) @BatchOwner(Watcher.GaoJuan)
class RelatedTaiWanBatch extends BaseBatch{ class RelatedTaiWanBatch extends BaseBatch{
def curDate = Integer.parseInt(DateUtils.formatDateByPattern(new Date(), "yyyyMM")); def curDate = Integer.parseInt(DateUtils.formatDateByPattern(new Date(), "yyyyMM"));
DBCollection yuanqu_qiye_coll = MongoUtils.getCollectionByName("crawl", "qzd_shetai_company_detail", "192.168.0.206", 27020) DBCollection yuanqu_qiye_coll = MongoUtils.getCollectionByName("crawl", "qzd_shetai_company_detail", "192.168.0.206", 27020)
@@ -28,6 +32,8 @@ class RelatedTaiWanBatch extends BaseBatch{
def zimaoqu_datas = ["中国(福建)自由贸易试验区厦门片区","中国(福建)自由贸易试验区福州片区","中国(福建)自由贸易试验区平潭片区"] def zimaoqu_datas = ["中国(福建)自由贸易试验区厦门片区","中国(福建)自由贸易试验区福州片区","中国(福建)自由贸易试验区平潭片区"]
static main(args) { static main(args) {
runBatch(new RelatedTaiWanBatch(), args); runBatch(new RelatedTaiWanBatch(), args);
} }
@@ -37,14 +43,10 @@ class RelatedTaiWanBatch extends BaseBatch{
def day = new Date().getDate() def day = new Date().getDate()
if(day == 10){ if(day == 10){
//createDatas() //企业库获取涉台园区企业 // createDatas() //企业库获取涉台园区企业
updateRangeByPoint() //更改企业所在自贸区 updateRangeByPoint() //更改企业所在自贸区
export() //导出数据 export() //导出数据
} }
// else{
// exportEmptyFile()
// }
} }
@@ -153,10 +155,18 @@ class RelatedTaiWanBatch extends BaseBatch{
} }
def allDatas = [] def allDatas = []
allDatas.addAll(rows) allDatas.addAll(rows)
// FileUtils.batchCreateFile(rows, fileName, null, "utf-8", false);
FileUtils.batchCreateFileByCustomSuffix(rows, fileName, null, "utf-8", false, "|@|","|+|"); //原不加密之前
// FileUtils.batchCreateFileByCustomSuffix(rows, fileName, null, "utf-8", false, "|@|","|+|");
// XmBankFtpUtils.ftpUpload(fileName, curDate)
def str1 = FileUtils.createFileStringByCustomSuffix(rows, fileName, "utf-8", "|@|","|+|");
def str1_encryptedText = CryptoSm4Util.encrypt( CryptoSm4Util.DEFAULT_SECRET_KEY, str1)
FileUtils.createEncryptFile(fileName, str1_encryptedText, false)
XmBankFtpUtils.ftpUpload(fileName, curDate) XmBankFtpUtils.ftpUpload(fileName, curDate)
def fileName2 = "/home/goojia/xmbank/free_trade_zone_${curDate}_init.dat.rdy" def fileName2 = "/home/goojia/xmbank/free_trade_zone_${curDate}_init.dat.rdy"
if(CommonDatautils.isWindow()){ if(CommonDatautils.isWindow()){
fileName2 = "D:\\数据\\厦门\\涉台园区\\free_trade_zone_${curDate}_init.dat.rdy" fileName2 = "D:\\数据\\厦门\\涉台园区\\free_trade_zone_${curDate}_init.dat.rdy"
@@ -182,4 +192,7 @@ class RelatedTaiWanBatch extends BaseBatch{
FileUtils.batchCreateFileByCustomSuffix([rdy_datas], fileName2, null, "utf-8", false, "","|+|"); FileUtils.batchCreateFileByCustomSuffix([rdy_datas], fileName2, null, "utf-8", false, "","|+|");
XmBankFtpUtils.ftpUpload(fileName2, curDate) XmBankFtpUtils.ftpUpload(fileName2, curDate)
} }
} }