cloudcc-cli 1.9.6 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ package com.cloudcc.core;
2
+
3
+ public interface CCTrigger {
4
+ public void do_insert_before() throws Exception;
5
+
6
+ public void do_insert_after() throws Exception;
7
+
8
+ public void do_update_before() throws Exception;
9
+
10
+ public void do_update_after() throws Exception;
11
+
12
+ public void do_upsert_before() throws Exception;
13
+
14
+ public void do_upsert_after() throws Exception;
15
+
16
+ public void do_delete_before() throws Exception;
17
+
18
+ public void do_delete_after() throws Exception;
19
+
20
+ public void setRecordOldVal(String id);
21
+
22
+ public void do_approval() throws Exception;
23
+
24
+ public String getObjectApiName();
25
+ }
@@ -0,0 +1,16 @@
1
+ package com.cloudcc.core;
2
+
3
+ import java.util.Map;
4
+
5
+ public abstract class CCTriggerHandler extends CCService {
6
+ public Map record_new;
7
+ public Map record_old;
8
+ public ServiceResult trigger;
9
+
10
+ public CCTriggerHandler(Map triggernew, Map triggerold, ServiceResult svc, UserInfo uinfo) {
11
+ super(uinfo);
12
+ this.record_new = triggernew;
13
+ this.record_old = triggerold;
14
+ this.trigger = svc;
15
+ }
16
+ }
@@ -0,0 +1,39 @@
1
+ package com.cloudcc.core;
2
+
3
+ /**
4
+ * @author jarry
5
+ *
6
+ * 系统日志输出
7
+ */
8
+ public class DevLogger {
9
+ UserInfo userInfo;
10
+ public DevLogger(UserInfo userInfo){
11
+ this.userInfo = userInfo;
12
+ }
13
+
14
+ /**
15
+ * info日志
16
+ * @param log
17
+ */
18
+ public static void devLogInfo(String log){
19
+ System.out.println("Info日志"+log);
20
+ }
21
+
22
+ /**
23
+ * Error日志
24
+ * @param log
25
+ */
26
+ public static void devLogError(String log){
27
+ System.out.println("Info日志"+log);
28
+ }
29
+
30
+ /**
31
+ * 异常日志
32
+ * @param log
33
+ * @param e
34
+ */
35
+ public static void devLogError(String log,Exception e){
36
+ System.out.println("Info日志"+log);
37
+ System.out.println(e);
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ package com.cloudcc.core;
2
+
3
+ public enum OperatationEnum {
4
+ INSERT,UPDATE,UPSERT,DELETE,APPROVE
5
+ }
@@ -0,0 +1,6 @@
1
+ package com.cloudcc.core;
2
+
3
+ public interface PeakInterf {
4
+ public UserInfo uinfo = new UserInfo();
5
+ public void execute();
6
+ }
@@ -0,0 +1,22 @@
1
+ package com.cloudcc.core;
2
+
3
+ public class SendEmail {
4
+ public SendEmail(UserInfo userInfo) {
5
+
6
+ }
7
+
8
+ //Receive address, cc address, password address, subject, email content, text content
9
+ public ServiceResult sendMailFromSystem(String[] toAddress, String[] ccAddress, String bccAddress, String subject,
10
+ String content, boolean isText) {
11
+ ServiceResult srt = new ServiceResult();
12
+ return srt;
13
+ }
14
+
15
+ //Email template id, receipt address, cc address, password address, record id
16
+ public ServiceResult sendEmailNew(String templateId, String[] toAddress, String[] ccAddress, String bccAddress,
17
+ String recordId) {
18
+ ServiceResult srt = new ServiceResult();
19
+ return srt;
20
+ }
21
+
22
+ }
@@ -0,0 +1,36 @@
1
+ package com.cloudcc.core;
2
+
3
+ import java.util.HashMap;
4
+
5
+ import com.alibaba.fastjson.JSONObject;
6
+
7
+ public class ServiceResult extends HashMap<String, Object> {
8
+ public String success;
9
+ public String message;
10
+ public String Id;
11
+
12
+ public void addErrorMessage(String msg) throws Exception {
13
+ this.put("message", msg);
14
+ this.put("success", "false");
15
+ throw new Exception(msg);
16
+ }
17
+
18
+ public String getMessage() {
19
+ return (String) this.get("message");
20
+ }
21
+
22
+ public String getSuccess() {
23
+ return (String) this.get("success");
24
+ }
25
+
26
+ public String getId() {
27
+ return (String) this.get("id");
28
+ }
29
+
30
+ @Override
31
+ public String toString() {
32
+ JSONObject data = new JSONObject();
33
+ data.putAll(this);
34
+ return data.toString();
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+
2
+ package com.cloudcc.core;
3
+
4
+ import java.text.SimpleDateFormat;
5
+
6
+ public class TimeUtil {
7
+
8
+ public static SimpleDateFormat getSimpleDateFormat(String string, UserInfo userInfo) {
9
+ return new SimpleDateFormat(string);
10
+ }
11
+ }
@@ -0,0 +1,167 @@
1
+ package com.cloudcc.core;
2
+
3
+ import java.io.BufferedReader;
4
+ import java.io.File;
5
+ import java.io.FileReader;
6
+ import java.io.IOException;
7
+ import java.util.HashMap;
8
+ import java.util.Map;
9
+ import java.util.regex.Matcher;
10
+ import java.util.regex.Pattern;
11
+
12
+ import com.alibaba.fastjson.JSONObject;
13
+
14
+ public class Tool {
15
+ /**
16
+ * 读取cloudcc-cli.config.js文件内容,解析use属性,获取对应内容
17
+ *
18
+ * @return Map包含currentEnv和对应的配置信息
19
+ */
20
+ public static Map<String, String> getConfig() {
21
+ Map<String, String> result = new HashMap<>();
22
+ try {
23
+ // 获取配置文件路径
24
+ String configPath = new File("").getAbsolutePath() + "/cloudcc-cli.config.js";
25
+ File configFile = new File(configPath);
26
+
27
+ if (!configFile.exists()) {
28
+ System.err.println("配置文件不存在: " + configPath);
29
+ return null;
30
+ }
31
+
32
+ // 读取文件内容
33
+ StringBuilder content = new StringBuilder();
34
+ try (BufferedReader reader = new BufferedReader(new FileReader(configFile))) {
35
+ String line;
36
+ while ((line = reader.readLine()) != null) {
37
+ // 跳过注释行
38
+ if (line.trim().startsWith("//")) {
39
+ continue;
40
+ }
41
+ content.append(line).append("\n");
42
+ }
43
+ }
44
+
45
+ String fileContent = content.toString();
46
+
47
+ // 替换 'module.exports = ' 为空字符串,并移除注释
48
+ String jsonStr = fileContent.replaceFirst("module\\.exports\\s*=\\s*", "")
49
+ .replaceAll("//[^\\n]*", ""); // 移除单行注释
50
+
51
+ // 使用正则表达式提取配置对象,处理最后可能有多余的分号
52
+ Pattern configPattern = Pattern.compile("\\{([\\s\\S]*)\\}\\s*;?\\s*$");
53
+ Matcher configMatcher = configPattern.matcher(jsonStr);
54
+ if (configMatcher.find()) {
55
+ jsonStr = "{" + configMatcher.group(1) + "}";
56
+ }
57
+
58
+ // 使用正则表达式提取use值
59
+ Pattern usePattern = Pattern.compile("\"use\"\\s*:\\s*\"([^\"]*)\"");
60
+ Matcher useMatcher = usePattern.matcher(jsonStr);
61
+
62
+ if (!useMatcher.find()) {
63
+ System.err.println("无法找到use属性");
64
+ return null;
65
+ }
66
+
67
+ String currentEnv = useMatcher.group(1);
68
+ result.put("currentEnv", currentEnv);
69
+
70
+ // 创建更精确的正则表达式来匹配环境配置块
71
+ Pattern envPattern = Pattern.compile(
72
+ "\"" + Pattern.quote(currentEnv) + "\"\\s*:\\s*\\{([^\\{\\}]*(\\{[^\\{\\}]*\\})*[^\\{\\}]*)\\}");
73
+ Matcher envMatcher = envPattern.matcher(jsonStr);
74
+
75
+ if (envMatcher.find()) {
76
+ String envConfig = envMatcher.group(1);
77
+ // 解析配置项(考虑到键和值可能包含更复杂的内容)
78
+ Pattern itemPattern = Pattern.compile("\"([^\"]+)\"\\s*:\\s*\"([^\"]*)\"");
79
+ Matcher itemMatcher = itemPattern.matcher(envConfig);
80
+ while (itemMatcher.find()) {
81
+ result.put(itemMatcher.group(1), itemMatcher.group(2));
82
+ }
83
+
84
+ // 获取secretKey
85
+ String secretKey = result.get("secretKey");
86
+ if (secretKey != null) {
87
+ // 从缓存文件中读取相关信息
88
+ Map<String, Object> cacheData = readCache(secretKey);
89
+ if (cacheData != null) {
90
+ // 将缓存信息添加到结果中
91
+ for (Map.Entry<String, Object> entry : cacheData.entrySet()) {
92
+ result.put(entry.getKey(), String.valueOf(entry.getValue()));
93
+ }
94
+ }
95
+ }
96
+ } else {
97
+ System.err.println("无法找到环境配置: " + currentEnv);
98
+ }
99
+
100
+ return result;
101
+ } catch (IOException e) {
102
+ System.err.println("读取配置文件失败: " + e.getMessage());
103
+ e.printStackTrace();
104
+ return null;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * 读取.cloudcc-cache.json缓存文件并根据secretKey获取相关信息
110
+ *
111
+ * @param secretKey 密钥
112
+ * @return 包含缓存信息的Map
113
+ */
114
+ private static Map<String, Object> readCache(String secretKey) {
115
+ try {
116
+ // 获取缓存文件路径
117
+ String cachePath = new File("").getAbsolutePath() + "/.cloudcc-cache.json";
118
+ File cacheFile = new File(cachePath);
119
+
120
+ if (!cacheFile.exists()) {
121
+ System.err.println("缓存文件不存在: " + cachePath);
122
+ return null;
123
+ }
124
+
125
+ // 读取文件内容
126
+ StringBuilder content = new StringBuilder();
127
+ try (BufferedReader reader = new BufferedReader(new FileReader(cacheFile))) {
128
+ String line;
129
+ while ((line = reader.readLine()) != null) {
130
+ content.append(line).append("\n");
131
+ }
132
+ }
133
+
134
+ String jsonContent = content.toString();
135
+ // 使用Fastjson解析JSON内容
136
+ JSONObject jsonObject = JSONObject.parseObject(jsonContent);
137
+
138
+ // 检查secretKey是否存在
139
+ if (!jsonObject.containsKey(secretKey)) {
140
+ System.err.println("缓存文件中不存在该secretKey: " + secretKey);
141
+ return null;
142
+ }
143
+
144
+ // 获取secretKey对应的数据
145
+ JSONObject secretKeyData = jsonObject.getJSONObject(secretKey);
146
+
147
+ // 将JSON对象转换为Map
148
+ Map<String, Object> resultMap = new HashMap<>();
149
+ for (String key : secretKeyData.keySet()) {
150
+ resultMap.put(key, secretKeyData.get(key));
151
+ }
152
+ return resultMap;
153
+ } catch (IOException e) {
154
+ System.err.println("读取缓存文件失败: " + e.getMessage());
155
+ e.printStackTrace();
156
+ return null;
157
+ } catch (Exception e) {
158
+ System.err.println("解析缓存文件失败: " + e.getMessage());
159
+ e.printStackTrace();
160
+ return null;
161
+ }
162
+ }
163
+
164
+ public static void main(String[] args) {
165
+ System.out.println(getConfig());
166
+ }
167
+ }
@@ -0,0 +1,86 @@
1
+ package com.cloudcc.core;
2
+
3
+ import java.lang.reflect.Constructor;
4
+ import java.lang.reflect.InvocationTargetException;
5
+ import java.util.Set;
6
+
7
+ import org.reflections.Reflections;
8
+
9
+ public class TriggerInvoker {
10
+ UserInfo uinfo = null;
11
+ String operate = "";
12
+ String triggerTime = "";
13
+
14
+ public TriggerInvoker(UserInfo userInfo, String operate, String triggerTime) {
15
+ this.uinfo = userInfo;
16
+ this.operate = operate;
17
+ this.triggerTime = triggerTime;
18
+ }
19
+
20
+ public TriggerInvoker() {
21
+
22
+ }
23
+
24
+ public ServiceResult handler(CCObject data) throws Exception {
25
+ String objectApiName = data.getObjectApiName();
26
+ ServiceResult sr = new ServiceResult();
27
+ Reflections ref = new Reflections("com.cloudcc.trigger");
28
+ Set<Class<? extends CCTrigger>> clsSets = ref.getSubTypesOf(CCTrigger.class);
29
+ for (Class<? extends CCTrigger> subCls : clsSets) {
30
+ try {
31
+ Constructor cons = subCls.getConstructor(CCObject.class, CCObject.class, ServiceResult.class,
32
+ UserInfo.class);
33
+ CCTrigger trigger = (CCTrigger) cons.newInstance(data, null, sr, uinfo);
34
+ String objectApiNameTmp = (String) trigger.getObjectApiName();
35
+ if (objectApiName != null && objectApiName.equals(objectApiNameTmp)) {
36
+ if ("before".equals(triggerTime) && "insert".equals(operate)) {
37
+ trigger.do_insert_before();
38
+ }
39
+ if ("after".equals(triggerTime) && "insert".equals(operate)) {
40
+ String id = (String) data.get("id");
41
+ trigger.setRecordOldVal(id);
42
+ trigger.do_insert_after();
43
+ }
44
+ if ("before".equals(triggerTime) && "update".equals(operate)) {
45
+ trigger.do_update_before();
46
+ }
47
+ if ("after".equals(triggerTime) && "update".equals(operate)) {
48
+ String id = (String) data.get("id");
49
+ trigger.setRecordOldVal(id);
50
+ trigger.do_update_after();
51
+ }
52
+ if ("before".equals(triggerTime) && "upsert".equals(operate)) {
53
+ trigger.do_upsert_before();
54
+ }
55
+ if ("after".equals(triggerTime) && "upsert".equals(operate)) {
56
+ String id = (String) data.get("id");
57
+ trigger.setRecordOldVal(id);
58
+ trigger.do_upsert_after();
59
+ }
60
+ if ("before".equals(triggerTime) && "delete".equals(operate)) {
61
+ trigger.do_delete_before();
62
+ }
63
+ if ("after".equals(triggerTime) && "delete".equals(operate)) {
64
+ String id = (String) data.get("id");
65
+ trigger.setRecordOldVal(id);
66
+ trigger.do_delete_after();
67
+ }
68
+ if ("approval".equals(operate)) {
69
+ trigger.do_approval();
70
+ }
71
+ }
72
+ } catch (NoSuchMethodException e) {
73
+ throw new RuntimeException(e);
74
+ } catch (InvocationTargetException e) {
75
+ throw new RuntimeException(e);
76
+ } catch (InstantiationException e) {
77
+ throw new RuntimeException(e);
78
+ } catch (IllegalAccessException e) {
79
+ throw new RuntimeException(e);
80
+ } catch (Exception ex) {
81
+ throw ex;
82
+ }
83
+ }
84
+ return sr;
85
+ }
86
+ }
@@ -0,0 +1,9 @@
1
+ package com.cloudcc.core;
2
+
3
+ public @interface TriggerMethod {
4
+ String name();
5
+ OperatationEnum operate();
6
+ TriggerTimeEnum triggerTime();
7
+ boolean isEnable() ;
8
+ String remark() default "";
9
+ }
@@ -0,0 +1,5 @@
1
+ package com.cloudcc.core;
2
+
3
+ public enum TriggerTimeEnum {
4
+ BEFORE,AFTER
5
+ }
@@ -0,0 +1,57 @@
1
+ package com.cloudcc.core;
2
+
3
+ public class UserInfo extends CCObject {
4
+ // 绑定信息
5
+ public String binding;
6
+
7
+ // 获取用户ID
8
+ public String getUserId() {
9
+ return (String) this.get("id");
10
+ }
11
+
12
+ // 获取角色ID
13
+ public String getRoleId() {
14
+ return (String) this.get("role");
15
+ }
16
+
17
+ // 构造方法,传入用户名和密码
18
+ public UserInfo(String username, String pwd) throws Exception {
19
+ this.put("userName", username);
20
+ this.put("password", pwd);
21
+ }
22
+
23
+ // 默认构造方法
24
+ public UserInfo() {
25
+
26
+ }
27
+
28
+ // 获取登录名
29
+ public String getLoginName() {
30
+ return (String) this.get("userName");
31
+ }
32
+
33
+ // 获取配置文件ID
34
+ public String getProfileId() {
35
+ return (String) this.get("profileId");
36
+ }
37
+
38
+ // 设置绑定信息
39
+ public void setBinding(String bind) {
40
+ this.binding = bind;
41
+ this.put("binding", bind);
42
+ }
43
+
44
+ // 获取绑定信息
45
+ public String getBinding() {
46
+ if (this.binding == null) {
47
+ return (String) this.get("binding");
48
+ } else {
49
+ return this.binding;
50
+ }
51
+ }
52
+
53
+ // 获取用户名
54
+ public String getUserName() {
55
+ return (String) this.get("name");
56
+ }
57
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudcc-cli",
3
- "version": "1.9.6",
3
+ "version": "1.9.7",
4
4
  "description": "cloudcc-cli",
5
5
  "keywords": [
6
6
  "cloudcc",
@@ -16,7 +16,8 @@
16
16
  },
17
17
  "scripts": {
18
18
  "cc-pull": "git fetch --tags -f && git pull",
19
- "publish-lib": "npm publish --registry https://registry.npmjs.org && git add . && git commit -m 'update' && git push && curl https://npmmirror.com/sync/cloudcc-cli"
19
+ "publish-lib": "npm publish --registry https://registry.npmjs.org && git add . && git commit -m 'update' && git push && curl https://npmmirror.com/sync/cloudcc-cli",
20
+ "package-jar": "mvn clean && mvn package"
20
21
  },
21
22
  "dependencies": {
22
23
  "axios": "^0.21.4",
package/pom.xml ADDED
@@ -0,0 +1,100 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
2
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
+ <modelVersion>4.0.0</modelVersion>
4
+
5
+ <groupId>com.cloudcc.core</groupId>
6
+ <artifactId>ccopenapi</artifactId>
7
+ <version>0.0.1</version>
8
+ <packaging>jar</packaging>
9
+ <name>ccopenapi</name>
10
+ <dependencies>
11
+ <!-- 添加 fastjson 依赖 -->
12
+ <dependency>
13
+ <groupId>com.alibaba</groupId>
14
+ <artifactId>fastjson</artifactId>
15
+ <version>1.2.75</version>
16
+ </dependency>
17
+ <!-- 添加 log4j 依赖 -->
18
+ <dependency>
19
+ <groupId>log4j</groupId>
20
+ <artifactId>log4j</artifactId>
21
+ <version>1.2.17</version>
22
+ </dependency>
23
+ <!-- 添加 org.reflections 依赖 -->
24
+ <dependency>
25
+ <groupId>org.reflections</groupId>
26
+ <artifactId>reflections</artifactId>
27
+ <version>0.9.12</version>
28
+ </dependency>
29
+ <!-- 添加 Jackson 依赖 -->
30
+ <dependency>
31
+ <groupId>com.fasterxml.jackson.core</groupId>
32
+ <artifactId>jackson-databind</artifactId>
33
+ <version>2.13.3</version>
34
+ </dependency>
35
+ <!-- 添加 slf4j 依赖 -->
36
+ <dependency>
37
+ <groupId>org.slf4j</groupId>
38
+ <artifactId>slf4j-api</artifactId>
39
+ <version>1.7.32</version>
40
+ </dependency>
41
+ <dependency>
42
+ <groupId>org.slf4j</groupId>
43
+ <artifactId>slf4j-log4j12</artifactId>
44
+ <version>1.7.32</version>
45
+ </dependency>
46
+ </dependencies>
47
+
48
+ <build>
49
+ <plugins>
50
+ <plugin>
51
+ <groupId>org.codehaus.mojo</groupId>
52
+ <artifactId>build-helper-maven-plugin</artifactId>
53
+ <version>3.2.0</version>
54
+ <executions>
55
+ <execution>
56
+ <id>add-extra-source</id>
57
+ <phase>generate-sources</phase>
58
+ <goals>
59
+ <goal>add-source</goal>
60
+ </goals>
61
+ <configuration>
62
+ <sources>
63
+ <source>${project.basedir}/java</source>
64
+ </sources>
65
+ </configuration>
66
+ </execution>
67
+ </executions>
68
+ </plugin>
69
+
70
+ <plugin>
71
+ <groupId>org.apache.maven.plugins</groupId>
72
+ <artifactId>maven-compiler-plugin</artifactId>
73
+ <version>3.8.1</version>
74
+ <configuration>
75
+ <source>8</source>
76
+ <target>8</target>
77
+ </configuration>
78
+ </plugin>
79
+
80
+ <plugin>
81
+ <groupId>org.apache.maven.plugins</groupId>
82
+ <artifactId>maven-jar-plugin</artifactId>
83
+ <version>3.2.0</version>
84
+ <executions>
85
+ <execution>
86
+ <goals>
87
+ <goal>jar</goal>
88
+ </goals>
89
+ <configuration>
90
+ <includes>
91
+ <include>com/cloudcc/**/*.class</include>
92
+ </includes>
93
+ <classifier>classes</classifier> <!-- 添加 classifier 元素 -->
94
+ </configuration>
95
+ </execution>
96
+ </executions>
97
+ </plugin>
98
+ </plugins>
99
+ </build>
100
+ </project>
@@ -11,7 +11,10 @@ async function create(name) {
11
11
  try {
12
12
  fs.mkdirSync(classesPath, { recursive: true })
13
13
  const javaTmp =
14
- `// @SOURCE_CONTENT_START
14
+ `package classes.${name};
15
+
16
+ import com.cloudcc.core.*;
17
+ // @SOURCE_CONTENT_START
15
18
  public class ${name}{
16
19
  private UserInfo userInfo;
17
20
  private CCService cs;
@@ -24,14 +27,28 @@ public class ${name}{
24
27
  this.cs=cs;
25
28
  }
26
29
 
27
- public String demo(String str){
30
+ public String getName(String str){
28
31
  str = "demo";
29
32
  return str;
30
33
  }
31
34
  }
32
35
  // @SOURCE_CONTENT_END
36
+ `
37
+ const javaTestTmp =
38
+ `package classes.${name};
39
+
40
+ import com.cloudcc.core.*;
41
+
42
+ public class ${name}Test {
43
+ public static void main(String[] args) {
44
+ ${name} obj = new ${name}(new UserInfo());
45
+ String name = obj.getName("test");
46
+ System.out.println("name:" + name);
47
+ }
48
+ }
33
49
  `
34
50
  fs.writeFileSync(path.join(classesPath, name + ".java"), javaTmp)
51
+ fs.writeFileSync(path.join(classesPath, name + "Test.java"), javaTestTmp)
35
52
  fs.writeFileSync(path.join(classesPath, "config.json"), `{"name":"${name}","version":"${getPackageJson().extandVersion || '2'}"}`)
36
53
  console.log()
37
54
  console.log(chalk.green("Successfully Created:" + name))