Commit d4057d96 authored by yanzg's avatar yanzg

保存结果集

parent ae1c828d
...@@ -30,7 +30,7 @@ public class MqAspect extends BaseRequestAspect { ...@@ -30,7 +30,7 @@ public class MqAspect extends BaseRequestAspect {
* exec aop point aspect * exec aop point aspect
*/ */
@Pointcut("execution(* *..mq..*Consumer.*(..))") @Pointcut("execution(* *..mq..*Consumer.*(..))")
public void webAspect() { public void mqAspect() {
} }
/** /**
...@@ -39,7 +39,7 @@ public class MqAspect extends BaseRequestAspect { ...@@ -39,7 +39,7 @@ public class MqAspect extends BaseRequestAspect {
* @param joinPoint * @param joinPoint
* @return * @return
*/ */
@Around(value = "webAspect()") @Around(value = "mqAspect()")
public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable { public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable {
Log.threadBegin(); Log.threadBegin();
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
......
package com.yanzuoguang.cloud.aop; package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.contants.ResultConstants; import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper; import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.JSONHelper; import com.yanzuoguang.util.helper.JSONHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log; import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.vo.LogVo; import com.yanzuoguang.util.vo.LogVo;
import com.yanzuoguang.util.vo.ResponseResult; import com.yanzuoguang.util.vo.ResponseResult;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -149,7 +149,9 @@ public class WebAspect extends BaseRequestAspect { ...@@ -149,7 +149,9 @@ public class WebAspect extends BaseRequestAspect {
return; return;
} }
// 正常请求不记录 // 正常请求不记录
if (!logAll && responseResult.getCode() == ResultConstants.SUCCESS) { if (!logAll
&& responseResult != null
&& responseResult.getCode() == ResultConstants.SUCCESS) {
return; return;
} }
LogVo logVo = initLogInterVo(HttpAspectUtil.getHttpRequestUrl(), joinPoint, responseResult); LogVo logVo = initLogInterVo(HttpAspectUtil.getHttpRequestUrl(), joinPoint, responseResult);
......
...@@ -36,9 +36,9 @@ public interface BaseDao { ...@@ -36,9 +36,9 @@ public interface BaseDao {
* 删除数据 * 删除数据
* *
* @param model 需要删除的数据 * @param model 需要删除的数据
* @return 删除的主键编号 * @return 删除的记录数量
*/ */
String remove(Object model); int remove(Object model);
/** /**
* 加载数据 * 加载数据
......
...@@ -2,13 +2,15 @@ package com.yanzuoguang.dao.Impl; ...@@ -2,13 +2,15 @@ package com.yanzuoguang.dao.Impl;
import com.yanzuoguang.dao.BaseDao; import com.yanzuoguang.dao.BaseDao;
import com.yanzuoguang.dao.DaoConst; 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.exception.CodeException;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.vo.InitDao; import com.yanzuoguang.util.vo.InitDao;
import com.yanzuoguang.util.vo.MapRow; import com.yanzuoguang.util.vo.MapRow;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -180,33 +182,32 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao { ...@@ -180,33 +182,32 @@ public abstract class BaseDaoImpl extends BaseDaoSql implements BaseDao {
* @param model 需要删除的数据 * @param model 需要删除的数据
* @return 删除的主键编号 * @return 删除的主键编号
*/ */
public String remove(Object model) { public int remove(Object model) {
Object from = model;
// 获取来源主键 // 获取来源主键
Object from = model;
String keyString = getInputKey(from); 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)) { if (!StringHelper.isEmpty(keyString)) {
// 去掉其他非主键的属性
from = new HashMap<String, Object>(); from = new HashMap<String, Object>();
this.setKeyString(from, keyString); this.setKeyString(from, keyString);
} // 调用删除日志
this.check(DaoConst.OperatorTypeRemove, keyString, from); 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); SqlData sqlData = this.getSql(DaoConst.Remove);
int ret = updateSql(sqlData, from); return updateSql(sqlData, from);
String retVal = ret > 0 ? keyString : "";
return retVal;
} }
/** /**
......
package com.yanzuoguang.db.Impl; package com.yanzuoguang.db.Impl;
import com.yanzuoguang.extend.ConfigDb; import com.yanzuoguang.extend.ConfigDb;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.vo.MapRow; import com.yanzuoguang.util.vo.MapRow;
import org.springframework.beans.*; import org.springframework.beans.*;
import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.DataRetrievalFailureException;
...@@ -110,14 +110,43 @@ public class AllBeanRowMapper<T> implements RowMapper<T> { ...@@ -110,14 +110,43 @@ public class AllBeanRowMapper<T> implements RowMapper<T> {
* @param name the string containing original name * @param name the string containing original name
* @return the converted name * @return the converted name
*/ */
private String underscoreName(String name) { public static String underscoreName(String name) {
if (!StringUtils.hasLength(name)) { if (!StringUtils.hasLength(name)) {
return ""; return "";
} }
return name.toLowerCase().replace("_", ""); 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. * Extract the values for all columns in the current row.
* <p>Utilizes public setters and result setByType metadata. * <p>Utilizes public setters and result setByType metadata.
......
...@@ -33,7 +33,7 @@ public interface BaseService<T> { ...@@ -33,7 +33,7 @@ public interface BaseService<T> {
* *
* @param models 需要删除的数据 * @param models 需要删除的数据
*/ */
List<String> remove(T... models); int remove(T... models);
/** /**
* 加载数据 * 加载数据
......
...@@ -124,13 +124,12 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> { ...@@ -124,13 +124,12 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> {
* *
* @param models 需要删除的数据 * @param models 需要删除的数据
*/ */
public List<String> remove(T... models) { public int remove(T... models) {
List<String> ids = new ArrayList<String>(); int ret = 0;
for (T item : models) { for (T item : models) {
String id = removeItem(item); ret += removeItem(item);
ids.add(id);
} }
return ids; return ret;
} }
/** /**
...@@ -139,8 +138,8 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> { ...@@ -139,8 +138,8 @@ public abstract class BaseServiceImpl<T> implements BaseService<T> {
* @param item * @param item
* @return * @return
*/ */
protected String removeItem(T item) { protected int removeItem(T item) {
String id = this.getDao().remove(item); int id = this.getDao().remove(item);
check("删除", this.tag, id); check("删除", this.tag, id);
return 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