Compare commits

..

2 Commits

Author SHA1 Message Date
Chengliang 46f1c9fde1 master分支初始化 8 months ago
Chengliang 59e17ca9f5 2 years ago

12
.gitignore vendored

@ -1,17 +1,15 @@
/weaver-hrm-organization.iml
/weaver-develop.iml
/out/
/.idea/
.idea/
HELP.md
target/
### IntelliJ IDEA ###
.idea
/src/test
/test
/src/rebel.xml
/src/META-INF
/WEB-INF/config
/log
/weaver-develop.iml
/log

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="weaver-develop:jar">
<output-path>$PROJECT_DIR$/out/artifacts/weaver_develop_jar</output-path>
<root id="archive" name="weaver-develop.jar">
<element id="module-output" name="weaver-develop" />
</root>
</artifact>
</component>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
</component>
</project>

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="classbean">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../weaver/ecology/classbean" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="lib">
<CLASSES>
<root url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib" recursive="false" type="SOURCES" />
</library>
</component>

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: test.MainTest

@ -1,22 +0,0 @@
package com.engine.mzg.exception;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class CustomizeRunTimeException extends RuntimeException{
public CustomizeRunTimeException(String message) {
super(message);
}
public CustomizeRunTimeException(Throwable cause) {
super(cause);
}
public CustomizeRunTimeException(String message, Throwable cause) {
super(message, cause);
}
}

@ -1,20 +0,0 @@
package com.engine.mzg.util;
/**
* @Author weaver_cl
* @Description:
* @Date 2023/2/21
* @Version V1.0
**/
public class ExceptionUtil {
public static String getRealMessage(Throwable e) {
while (e != null) {
Throwable cause = e.getCause();
if (cause == null) {
return e.getMessage();
}
e = cause;
}
return "";
}
}

@ -1,192 +0,0 @@
package com.engine.mzg.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.exception.ECException;
import com.engine.mzg.exception.CustomizeRunTimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import weaver.general.BaseBean;
import weaver.hrm.User;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
*
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: </p>
*
* @author qiantao
* @version 1.0
**/
@Slf4j
public class ResponseResult<T, R> {
private static final long serialVersionUID = 1L;
private final User user;
private final BaseBean baseBean = new BaseBean();
private final Boolean isLog = "true".equals(baseBean.getPropValue("hrmSalary", "log"));
public ResponseResult(User user) {
this.user = user;
}
/**
* ()
*/
public String customRun(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return getJsonString(f.apply(t));
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
*
*/
public String run(Function<T, R> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
return Ok(f.apply(t));
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!");
}
}
/**
*
*/
public String run(Consumer<T> f, T t) {
try {
if (isLog) {
log.info("run api , param {}", t);
}
f.accept(t);
return Ok();
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
return Error(ExceptionUtil.getRealMessage(e));
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
/**
*
*/
public String run(Supplier<R> f) {
try {
if (isLog) {
log.info("run api");
}
return Ok(f.get());
} catch (CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
log.error("api run fail", e);
Throwable cause = e.getCause();
return Error(cause.getMessage());
} catch (Exception e) {
log.error("api run fail", e);
return Error("系统异常!", e);
}
}
private static String getJsonString(Object apidatas) {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(apidatas);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return "";
}
/**
*
*/
private String Ok() {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", true);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
*
*/
private String Ok(R r) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", true);
apidatas.put("data", r);
String success = JSON.toJSONString(apidatas);
if (isLog) {
log.info("run salary api success return {}", success);
}
return success;
}
/**
*
*/
private static String Error(String message) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", false);
apidatas.put("errormsg", message);
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
/**
*
*/
private static String Error(String message, Exception e) {
Map<String, Object> apidatas = new HashMap<>();
apidatas.put("api_status", false);
apidatas.put("errormsg", message);
apidatas.put("error", e.getMessage());
return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
}
}

@ -0,0 +1,14 @@
package test;
/**
* @Author weaver_cl
* @Description:
* @Date 2022/10/9
* @Version V1.0
**/
public class MainTest {
public static void main(String[] args) {
}
}
Loading…
Cancel
Save