---添加事件监听测试
This commit is contained in:
@ -17,6 +17,10 @@
|
||||
<properties>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<libServerUrl>http://10.10.2.102:9500</libServerUrl>
|
||||
<libServerUser>admin</libServerUser>
|
||||
<libServerPwd>Gas@Dev123</libServerPwd>
|
||||
<ignoreUpload>false</ignoreUpload>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -38,14 +42,26 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<groupId>com.geg</groupId>
|
||||
<artifactId>tanuki-compiler-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<libServerUrl>${libServerUrl}</libServerUrl>
|
||||
<libServerUser>${libServerUser}</libServerUser>
|
||||
<libServerPwd>${libServerPwd}</libServerPwd>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jarupload</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package com.xjrsoft.common;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.pictc.listener.ListenerParameterContext;
|
||||
import com.pictc.listener.ListenerR;
|
||||
import com.pictc.listener.PEventListener;
|
||||
|
||||
@Component
|
||||
public class ListenerDemo {
|
||||
|
||||
@PEventListener("#source == 'lng_upload_file'")
|
||||
public ListenerR<Long> add(ListenerParameterContext context){
|
||||
Map<String,Object> data = (Map<String, Object>) context.getData();
|
||||
|
||||
return ListenerR.success(1L);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.pictc.listener;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ListenerR<T> implements Serializable{
|
||||
|
||||
/**
|
||||
* @Fields {todo}(用一句话描述这个变量表示什么)
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private boolean success;
|
||||
|
||||
private T data;
|
||||
|
||||
public static <T>ListenerR<T> success(T data){
|
||||
return new ListenerR<T>().setData(data).setSuccess(true);
|
||||
}
|
||||
|
||||
public static <T>ListenerR<T> error(){
|
||||
return new ListenerR<T>();
|
||||
}
|
||||
|
||||
}
|
||||
@ -11,6 +11,8 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.pictc.utils.CollectionUtils;
|
||||
import com.pictc.utils.ObjectUtils;
|
||||
|
||||
@ -26,17 +28,17 @@ public class PEventListenerPublisher {
|
||||
PEventListenerPublisher.rest = rest;
|
||||
}
|
||||
|
||||
public static boolean publish(Object source,Object data) {
|
||||
return publish(source, data, false);
|
||||
public static <T>ListenerR<T> publish(Object source,Object data,Class<T> responseType) {
|
||||
return publish(source, data,responseType,false);
|
||||
}
|
||||
|
||||
public static boolean publish(Object source,Object data,boolean single) {
|
||||
public static <T>ListenerR<T> publish(Object source,Object data,Class<T> responseType,boolean single) {
|
||||
ListenerParameterContext conetext = new ListenerParameterContext();
|
||||
conetext.setSource(TNacosManager.getAppName()+":"+source.getClass().getCanonicalName());
|
||||
conetext.setSource(TNacosManager.getAppName()+":"+source);
|
||||
conetext.setData(data);
|
||||
conetext.setSingle(single);
|
||||
Set<String> services = TNacosManager.getNotSelfServices();
|
||||
boolean flag = single?false:true;
|
||||
ListenerR<T> res = new ListenerR<T>();
|
||||
if(CollectionUtils.isNotEmpty(services)) {
|
||||
HttpHeaders headers = TNacosManager.createNewHeaders();
|
||||
byte[] bytes = ObjectUtils.toBytes(conetext);
|
||||
@ -45,10 +47,22 @@ public class PEventListenerPublisher {
|
||||
URI uri = TNacosManager.getServiceURI(serviceId);
|
||||
if(uri!=null) {
|
||||
RequestEntity<byte[]> request = new RequestEntity<byte[]>(bytes,headers,HttpMethod.POST,uri);
|
||||
ResponseEntity<Boolean> responseEntity = rest.exchange(request,boolean.class);
|
||||
if(single && responseEntity.hasBody() && responseEntity.getBody()) {
|
||||
return true;
|
||||
ResponseEntity<String> responseEntity = rest.exchange(request,String.class);
|
||||
if(responseEntity.hasBody()) {
|
||||
String json = responseEntity.getBody();
|
||||
JSONObject jsonData = JSON.parseObject(json);
|
||||
res.setSuccess(jsonData.getBooleanValue("success"));
|
||||
if(jsonData.containsKey("data")) {
|
||||
Object rdata = jsonData.get("data");
|
||||
if(rdata instanceof JSONObject) {
|
||||
res.setData(((JSONObject)rdata).toJavaObject(responseType));
|
||||
}else {
|
||||
res.setData(jsonData.getObject("data", responseType));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(single) return res;
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
@ -56,7 +70,7 @@ public class PEventListenerPublisher {
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.pictc.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FlowDataUtils {
|
||||
|
||||
|
||||
public static <T>T parseData(String tblName,Map<String,Object> formData){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -33,10 +33,8 @@ public class MybatisTools implements ApplicationContextAware {
|
||||
for (BaseMapper<?> mapper : mapperBeans.values()) {
|
||||
// 获取Mapper接口的Class对象(因为mapper是代理对象,需要获取原始接口)
|
||||
Class<?> mapperInterface = getMapperInterface(mapper.getClass());
|
||||
|
||||
// 解析Mapper接口对应的实体类
|
||||
Class<?> entityClass = resolveEntityClass(mapperInterface);
|
||||
|
||||
if (entityClass != null) {
|
||||
ENTITY_MAPPER_MAP.put(entityClass, mapper);
|
||||
}
|
||||
|
||||
@ -18,21 +18,18 @@ import com.xjrsoft.module.datalog.vo.DataChangeLogVo;
|
||||
public class DatalogServiceImpl implements DatalogService{
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> T insert(T entity) {
|
||||
return DataLogTools.insert(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> T insert(T entity, DataOperationListener<T> listener) {
|
||||
return DataLogTools.insert(entity,listener);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> List<T> insertBatch(List<T> entitys) {
|
||||
List<T> res = Lists.newArrayList();
|
||||
@ -43,7 +40,6 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> List<T> insertBatch(List<T> entitys, DataOperationListener<T> listener) {
|
||||
List<T> res = Lists.newArrayList();
|
||||
@ -54,7 +50,6 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean updateById(T entity) {
|
||||
DataLogTools.update(entity);
|
||||
@ -62,7 +57,6 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean updateById(T entity, DataOperationListener<T> listener) {
|
||||
DataLogTools.update(entity,listener);
|
||||
@ -70,7 +64,6 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> T delete(T entity) {
|
||||
return DataLogTools.delete(entity);
|
||||
@ -78,7 +71,6 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> T deleteById(Class<T> klazz, long id) {
|
||||
return DataLogTools.deleteById(klazz, id);
|
||||
@ -86,28 +78,24 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> T deleteById(Class<T> klazz, long id, DataOperationListener<T> listener) {
|
||||
return DataLogTools.deleteById(klazz,id,listener);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean deleteByIds(Class<T> klazz, @Valid List<Long> ids) {
|
||||
return DataLogTools.deleteByIds(klazz, ids);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean deleteByIds(Class<T> klazz, @Valid List<Long> ids, DataOperationListener<T> listener) {
|
||||
return DataLogTools.deleteByIds(klazz,ids,listener);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> List<DataChangeLogVo> findLogsByEntityId(Class<T> klazz, long dataId) {
|
||||
return DataLogTools.findLogsByEntityId(klazz, dataId);
|
||||
@ -115,28 +103,24 @@ public class DatalogServiceImpl implements DatalogService{
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean enable(Class<T> klazz, @Valid List<Long> ids) {
|
||||
return DataLogTools.enable(klazz, ids);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean enable(Class<T> klazz, @Valid List<Long> ids, DataOperationListener<T> listener) {
|
||||
return DataLogTools.enable(klazz,ids,listener);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean disable(Class<T> klazz, @Valid List<Long> ids) {
|
||||
return DataLogTools.disable(klazz, ids);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@GlobalTransactional(rollbackFor = Exception.class) // Seata全局事务注解
|
||||
@Override
|
||||
public <T> boolean disable(Class<T> klazz, @Valid List<Long> ids, DataOperationListener<T> listener) {
|
||||
return DataLogTools.disable(klazz,ids,listener);
|
||||
|
||||
@ -33,7 +33,7 @@ public class UpdateLngBBankDto implements Serializable {
|
||||
/**
|
||||
* 助记码(自动生成,4位,0001……)
|
||||
*/
|
||||
@LogField(name="助记码(自动生成,4位,0001……)",index=1)
|
||||
@LogField(name="助记码",index=1)
|
||||
@ApiModelProperty("助记码(自动生成,4位,0001……)")
|
||||
private String code;
|
||||
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package com.xjrsoft.module;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.pictc.listener.ListenerParameterContext;
|
||||
import com.pictc.listener.ListenerR;
|
||||
import com.pictc.listener.PEventListener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ListenerDemo {
|
||||
|
||||
@PEventListener("#source == 'lng_upload_file'")
|
||||
public ListenerR<Long> add(ListenerParameterContext context){
|
||||
log.info("表名:{}",context.getSource());
|
||||
Map<String,Object> data = (Map<String, Object>) context.getData();
|
||||
log.info("数据:{}",data);
|
||||
return ListenerR.success(1L);
|
||||
}
|
||||
|
||||
|
||||
@PEventListener
|
||||
public ListenerR<Long> add2(ListenerParameterContext context){
|
||||
Map<String,Object> data = (Map<String, Object>) context.getData();
|
||||
log.info("表名:{}",context.getSource());
|
||||
log.info("数据:{}",data);
|
||||
return ListenerR.success(1L);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user