master
zhang chengzhi 2024-08-29 20:01:39 +08:00
parent 51c8699f86
commit 877eb048d3
19 changed files with 577 additions and 5 deletions

View File

@ -11,6 +11,7 @@
<artifactId>cloud-rule-common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
@ -23,6 +24,12 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
</dependency>
<!-- oss 图片上传 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.12.0</version>
</dependency>
</dependencies>
</project>

View File

@ -1,6 +1,7 @@
package com.muyu.rule.common.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -12,9 +13,10 @@ import lombok.NoArgsConstructor;
* @Date2024/8/27 9:18
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DataDescribe {
public class DataValue {
/**
*

View File

@ -35,6 +35,11 @@ public class RuleEngineVersion extends BaseEntity {
*
*/
private String versionName;
/**
*
*/
private String className;
/**
*
*/
@ -75,6 +80,7 @@ public class RuleEngineVersion extends BaseEntity {
.versionName(versionAddReq.getVersionName())
.versionCode(versionAddReq.getVersionCode())
.versionClazz(versionAddReq.getVersionClazz())
.className(versionAddReq.getClassName())
.build();
}

View File

@ -26,6 +26,12 @@ public class VersionAddReq {
*
*/
private String versionName;
/**
*
*/
private String className;
/**
*
*/

View File

@ -0,0 +1,162 @@
package com.muyu.rule.common.utils;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.PutObjectRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.time.LocalDateTime;
import java.util.UUID;
/**
* Oss
*/
@Log4j2
public class OssUtil {
/**
* Endpoint AccessKeyaccessKeySecretAPI访 访
*/
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
private static String accessKeyId = "LTAI5tDbRqXkC5i3SMrCSDcX";
private static String accessKeySecret = "XUzMZoHPLsjNLafHsdQnMElBWZATsu";
private static String accessPre = "https://mall-bw.oss-cn-shanghai.aliyuncs.com/";
/**
* bucket
*
* @return
*/
private static String bucketName = "mall-bw";
private static OSS ossClient;
static {
ossClient = new OSSClientBuilder().build(
endPoint,
accessKeyId,
accessKeySecret);
log.info("oss服务连接成功");
}
/**
*
*
* @param filePath
*/
public static String uploadFile(String filePath) {
return uploadFileForBucket(bucketName, getOssFilePath(filePath), filePath);
}
/**
* multipartFile
*
* @param multipartFile
*/
public static String uploadMultipartFile(MultipartFile multipartFile) {
return uploadMultipartFile(bucketName, getOssFilePath(multipartFile.getOriginalFilename()), multipartFile);
}
/**
* multipartFile
*
* @param bucketName
* @param ossPath
* @param multipartFile
*/
public static String uploadMultipartFile(String bucketName, String ossPath, MultipartFile multipartFile) {
InputStream inputStream = null;
try {
inputStream = multipartFile.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
return accessPre + ossPath;
}
/**
* 使FilePutObject ** 使
*
* @param bucketName
* @param ossPath oss
* @param filePath
*/
public static String uploadFileForBucket(String bucketName, String ossPath, String filePath) {
// 创建PutObjectRequest对象。
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
// 上传
ossClient.putObject(putObjectRequest);
return accessPre + ossPath;
}
/**
* 使bucket
*
* @param bucketName
* @param ossPath oss
* @param filePath
*/
public static String uploadFileInputStreamForBucket(String bucketName, String ossPath, String filePath) {
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
InputStream inputStream = null;
try {
inputStream = new FileInputStream(filePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
return accessPre + ossPath;
}
public static void uploadFileInputStreamForBucket(String bucketName, String ossPath, InputStream inputStream) {
ossClient.putObject(bucketName, ossPath, inputStream);
}
/**
*
*
* @param ossFilePath
* @param filePath
*/
public static void downloadFile(String ossFilePath, String filePath) {
downloadFileForBucket(bucketName, ossFilePath, filePath);
}
/**
*
*
* @param bucketName
* @param ossFilePath oss
* @param filePath
*/
public static void downloadFileForBucket(String bucketName, String ossFilePath, String filePath) {
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
}
/**
* @return
*/
public static String getOssDefaultPath() {
LocalDateTime now = LocalDateTime.now();
String url =
now.getYear() + "/" +
now.getMonth() + "/" +
now.getDayOfMonth() + "/" +
now.getHour() + "/" +
now.getMinute() + "/";
return url;
}
public static String getOssFilePath(String filePath) {
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
}
}

View File

@ -1,6 +1,6 @@
package com.muyu.rule.server;
import com.muyu.rule.common.domain.DataDescribe;
import com.muyu.rule.common.domain.DataValue;
/**
* @Author
@ -12,7 +12,7 @@ import com.muyu.rule.common.domain.DataDescribe;
public class DataTest {
public static void main(String[] args) {
DataDescribe describe = new DataDescribe();
DataValue describe = new DataValue();
describe.setKey("name");

View File

@ -35,7 +35,6 @@ public class EngineTest {
params.put("idcard","142021200212215977");
Object engineObject = EngineExecution.engineExe("Engine_2024_8_23_2347", params);
System.out.println("====>"+engineObject);

View File

@ -0,0 +1,70 @@
package com.muyu.rule.server;
import com.muyu.rule.common.domain.DataValue;
import com.muyu.rule.server.basic.BasicEngine;
import com.muyu.rule.server.basic.engine.ENGINE_VALUE_VFD1000_V1;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @Author
* @Packagecom.muyu.rule.server
* @Projectcloud-etl-rule
* @nameMain
* @Date2024/8/29 15:57
*/
public class Main {
static Map<String , BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
static {
try {
Class<?> aClass = Class.forName("com.muyu.rule.server.basic.engine.ENGINE_VALUE_VFD1000_V1");
try {
engineMap.put("ENGINE_VALUE_VFD1000_V1", (BasicEngine<DataValue>) aClass.newInstance());
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
DataValue dataValue = DataValue.builder()
.type("String")
.label("姓名")
.key("name")
.value(null)
.build();
BasicEngine<DataValue> engineValue = engineMap.get("ENGINE_VALUE_VFD1000_V1");
engineValue.set(dataValue);
engineValue.execution();
}
}

View File

@ -0,0 +1,26 @@
package com.muyu.rule.server.basic;
import com.muyu.rule.common.domain.DataValue;
import com.muyu.rule.server.basic.handler.DataEngineHandler;
/**
* @Author
* @Packagecom.muyu.rule.server.basic
* @Projectcloud-etl-rule
* @nameBasicEngine
* @Date2024/8/29 14:29
*/
public interface BasicEngine<V> {
public void set(V dataValue);
public V get();
public default void remove(){
DataEngineHandler.remove();
}
public void execution();
}

View File

@ -0,0 +1,30 @@
package com.muyu.rule.server.basic.abstracts;
import com.muyu.rule.common.domain.DataValue;
import com.muyu.rule.server.basic.BasicEngine;
import com.muyu.rule.server.basic.handler.DataEngineRowHandler;
import com.muyu.rule.server.basic.handler.DataEngineValueHandler;
/**
* @Author
* @Packagecom.muyu.rule.server.basic.abstracts
* @Projectcloud-etl-rule
* @nameDataEngineValueAu
* @Date2024/8/29 15:11
*/
public abstract class DataEngineRowActuator implements BasicEngine<DataValue[]> {
public void set(DataValue[] dataValue){
DataEngineRowHandler.set(dataValue);
}
public DataValue[] get(){
return DataEngineRowHandler.get();
}
}

View File

@ -0,0 +1,35 @@
package com.muyu.rule.server.basic.abstracts;
import com.muyu.rule.common.domain.DataValue;
import com.muyu.rule.server.basic.BasicEngine;
import com.muyu.rule.server.basic.handler.DataEngineValueHandler;
/**
* @Author
* @Packagecom.muyu.rule.server.basic.abstracts
* @Projectcloud-etl-rule
* @nameDataEngineValueAu
* @Date2024/8/29 15:11
*/
public abstract class DataEngineValueActuator implements BasicEngine<DataValue> {
public void set(DataValue dataValue){
DataEngineValueHandler.set(dataValue);
}
public DataValue get(){
return DataEngineValueHandler.get();
}
@Override
public void execution() {
this.run();
this.remove();
}
public abstract void run();
}

View File

@ -0,0 +1,23 @@
package com.muyu.rule.server.basic.engine;
import com.muyu.rule.common.domain.DataValue;
import com.muyu.rule.server.basic.abstracts.DataEngineValueActuator;
import javax.xml.crypto.Data;
/**
* @Author
* @Packagecom.muyu.rule.server.basic.engine
* @Projectcloud-etl-rule
* @nameENGINE_VALUE_VFD1000_V1
* @Date2024/8/29 15:51
*/
public class ENGINE_VALUE_VFD1000_V1 extends DataEngineValueActuator {
@Override
public void run() {
DataValue dataValue = get();
if (dataValue.getValue() == null){
System.out.println("数据为空");
}
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.rule.server.basic.engine;
import com.muyu.rule.common.domain.DataValue;
import com.muyu.rule.common.utils.Desensitization;
import com.muyu.rule.server.basic.abstracts.DataEngineValueActuator;
/**
* @Author
* @Packagecom.muyu.rule.server.basic.engine
* @Projectcloud-etl-rule
* @nameENGINE_VALUE_VFD1000_V1
* @Date2024/8/29 15:51
*/
public class ENGINE_VALUE_VFD1000_V2 extends DataEngineValueActuator {
@Override
public void run() {
DataValue dataValue = get();
String string = Desensitization.mobilePhoneDesensitization((String) dataValue.getValue());
System.out.println("手机号脱敏的结果是====>"+string);
}
}

View File

@ -0,0 +1,35 @@
package com.muyu.rule.server.basic.handler;
/**
* @Author
* @Packagecom.muyu.rule.server.basic
* @Projectcloud-etl-rule
* @nameDataEngineHandler
* @Date2024/8/29 14:21
*/
public class DataEngineHandler {
private static final ThreadLocal<Object> dataEngineHandler = new ThreadLocal<>();
public static void set(final Object handler){
dataEngineHandler.set(handler);
}
public static <T> T get(){
return (T) dataEngineHandler.get();
}
public static void remove(){
dataEngineHandler.remove();
}
}

View File

@ -0,0 +1,22 @@
package com.muyu.rule.server.basic.handler;
import com.muyu.common.core.text.Convert;
import com.muyu.rule.common.domain.DataValue;
/**
* @Author
* @Packagecom.muyu.rule.server.basic.handler
* @Projectcloud-etl-rule
* @nameDataEngineValueHandler
* @Date2024/8/29 14:35
* @Description:
*/
public class DataEngineRowHandler {
public static void set(DataValue[] dataDescribe){DataEngineHandler.set(dataDescribe);}
public static DataValue[] get(){
return DataEngineHandler.get();
}
}

View File

@ -0,0 +1,44 @@
package com.muyu.rule.server.basic.handler;
import com.muyu.common.core.text.Convert;
import com.muyu.rule.common.domain.DataValue;
/**
* @Author
* @Packagecom.muyu.rule.server.basic.handler
* @Projectcloud-etl-rule
* @nameDataEngineValueHandler
* @Date2024/8/29 14:35
*/
public class DataEngineValueHandler {
public static void set(DataValue dataDescribe){
DataEngineHandler.set(dataDescribe);
}
public static DataValue get(){
return DataEngineHandler.get();
}
public static void remove(){
DataEngineHandler.remove();
}
public static Object getValue(){
return get().getValue();
}
public static Integer getInt(){
return Convert.toInt(getValue(),null);
}
}

View File

@ -25,7 +25,7 @@ public class Engine_2024_8_23_2347 {
// 获取当前年份
LocalDate currentDate = LocalDate.now();
Integer currentYear = currentDate.getYear();
// Integer currentYear = currentDate.getYear();
// 计算年龄
Period age = Period.between(LocalDate.of(year, 1, 1), currentDate);

View File

@ -0,0 +1,81 @@
package com.muyu.rule.server.util;
import lombok.extern.log4j.Log4j2;
import java.io.*;
/**
* @Author
* @Packagecom.muyu.rule.server.util
* @Projectcloud-etl-rule
* @nameFileUtil
* @Date2024/8/29 8:39
*/
@Log4j2
public class FileLoadUtil {
public static void writeFile(String filePath,String fileName,String content){
try {
String javaFile = fileName + filePath.split(".")[0];
// File file = new File(filePath + "//" + fileName + ".java");
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(javaFile));
//写入
bufferedWriter.write(content);
//刷新
bufferedWriter.flush();
bufferedWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String readFile(String filePath,String fileName){
File file = new File(filePath + '\\' + fileName + ".java");
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String content;
String len;
for (content = "";(len=bufferedReader.readLine())!= null;content = content +len + "\n"){
}
return null;
} catch (IOException e) {
log.info("读取[{}]文件失败 ---> {}",fileName,e.getMessage(),e);
return "";
}
}
public static void main(String[] args) {
}
}