Commit d4057d96 authored by yanzg's avatar yanzg

保存结果集

parent ae1c828d
......@@ -30,7 +30,7 @@ public class MqAspect extends BaseRequestAspect {
* exec aop point aspect
*/
@Pointcut("execution(* *..mq..*Consumer.*(..))")
public void webAspect() {
public void mqAspect() {
}
/**
......@@ -39,7 +39,7 @@ public class MqAspect extends BaseRequestAspect {
* @param joinPoint
* @return
*/
@Around(value = "webAspect()")
@Around(value = "mqAspect()")
public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable {
Log.threadBegin();
long start = System.currentTimeMillis();
......
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JSONHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.vo.LogVo;
import com.yanzuoguang.util.vo.ResponseResult;
import org.aspectj.lang.ProceedingJoinPoint;
......@@ -149,7 +149,9 @@ public class WebAspect extends BaseRequestAspect {
return;
}
// 正常请求不记录
if (!logAll && responseResult.getCode() == ResultConstants.SUCCESS) {
if (!logAll
&& responseResult != null
&& responseResult.getCode() == ResultConstants.SUCCESS) {
return;
}
LogVo logVo = initLogInterVo(HttpAspectUtil.getHttpRequestUrl(), joinPoint, responseResult);
......
......@@ -36,9 +36,9 @@ public interface BaseDao {
* 删除数据
*
* @param model 需要删除的数据
* @return 删除的主键编号
* @return 删除的记录数量
*/
String remove(Object model);
int remove(Object model);
/**
* 加载数据
......
......@@ -2,13 +2,15 @@ package com.yanzuoguang.dao.Impl;
import com.yanzuoguang.dao.BaseDao;
import com.yanzuoguang.dao.DaoConst;
import com.yanzuoguang.db.Impl.AllBeanRowMapper;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.vo.InitDao;
import com.yanzuoguang.util.vo.MapRow;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -180,33 +182,32 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @param model 需要删除的数据
* @return 删除的主键编号
*/
public String remove(Object model) {
Object from = model;
public int remove(Object model) {
// 获取来源主键
Object from = model;
String keyString = getInputKey(from);
if (StringHelper.isEmpty(keyString)) {
MapRow to = new MapRow();
ObjectHelper.writeWithFrom(to, model);
from = this.queryFirst(MapRow.class, DaoConst.Load, from);
if (from == null) {
return "";
}
keyString = this.getKeyString(from);
}
// 当主键存在时,只通过主键加载
// 当主键存在值时,直接通过主键删除
if (!StringHelper.isEmpty(keyString)) {
// 去掉其他非主键的属性
from = new HashMap<String, Object>();
this.setKeyString(from, keyString);
}
// 调用删除日志
this.check(DaoConst.OperatorTypeRemove, keyString, from);
} else {
List<MapRow> rows = this.query(MapRow.class, DaoConst.Load, from);
for (MapRow row : rows) {
keyString = this.getKeyString(from);
if (StringHelper.isEmpty(keyString)) {
keyString = StringHelper.toString(AllBeanRowMapper.getLoweRowField(row, this.getKey()));
}
// 调用删除日志
this.check(DaoConst.OperatorTypeRemove, keyString, row);
}
}
// 调用删除语句
SqlData sqlData = this.getSql(DaoConst.Remove);
int ret = updateSql(sqlData, from);
String retVal = ret > 0 ? keyString : "";
return retVal;
return updateSql(sqlData, from);
}
/**
......
package com.yanzuoguang.db.Impl;
import com.yanzuoguang.extend.ConfigDb;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.MapRow;
import org.springframework.beans.*;
import org.springframework.dao.DataRetrievalFailureException;
......@@ -110,14 +110,43 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
* @param name the string containing original name
* @return the converted name
*/
private String underscoreName(String name) {
public static String underscoreName(String name) {
if (!StringUtils.hasLength(name)) {
return "";
}
return name.toLowerCase().replace("_", "");
}
/**
* 将行进行转换
*
* @param from
* @return
*/
public static MapRow toLoweRow(MapRow from) {
MapRow to = new MapRow();
for (String key : from.keySet()) {
to.put(underscoreName(key), from.get(key));
}
return to;
}
/**
* 获取空值字段
*
* @param from
* @return
*/
public static Object getLoweRowField(MapRow from, String field) {
field = underscoreName(field);
for (String key : from.keySet()) {
if (underscoreName(key).equals(field)) {
return from.get(key);
}
}
return null;
}
/**
* Extract the values for all columns in the current row.
* <p>Utilizes public setters and result setByType metadata.
......
......@@ -33,7 +33,7 @@ public interface BaseService<T> {
*
* @param models 需要删除的数据
*/
List<String> remove(T... models);
int remove(T... models);
/**
* 加载数据
......
......@@ -124,13 +124,12 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> {
*
* @param models 需要删除的数据
*/
public List<String> remove(T... models) {
List<String> ids = new ArrayList<String>();
public int remove(T... models) {
int ret = 0;
for (T item : models) {
String id = removeItem(item);
ids.add(id);
ret += removeItem(item);
}
return ids;
return ret;
}
/**
......@@ -139,8 +138,8 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> {
* @param item
* @return
*/
protected String removeItem(T item) {
String id = this.getDao().remove(item);
protected int removeItem(T item) {
int id = this.getDao().remove(item);
check("删除", this.tag, id);
return id;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment