Commit 1ee230c0 by 陶光胜

门店保存修改

parent a7cc018a
package com.gic.store.utils;
import com.gic.log.api.dto.SystemSetLogDTO;
import com.gic.log.api.service.LogApiService;
import com.gic.store.dto.StoreInfoDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.beans.PropertyDescriptor;
import java.util.Date;
/**
* @author zhiwj
* @date 2019/7/10
*/
@Component
public class LogUtils {
private static LogApiService logApiService;
public static <T> void saveAddLog(T obj) {
saveLog(obj, 1);
}
public static <T> void saveUpdateLog(T obj) {
saveLog(obj, 2);
}
@Autowired
public void setLogApiService(LogApiService logApiService) {
LogUtils.logApiService = logApiService;
}
public static <T> void saveLog(T obj, Integer type) {
// 日志
SystemSetLogDTO systemSetLogDTO = new SystemSetLogDTO();
// systemSetLogDTO.setEnterpriesId(storeBrandDTO.getEnterpriseId() + "");
systemSetLogDTO.setLogTime(new Date());
// systemSetLogDTO.setInterfaceName("com.gic.store.service.StoreBrandApiService.saveOrUpdateStoreBrand");
StringBuilder content = new StringBuilder();
getContent(obj, type, content, systemSetLogDTO);
systemSetLogDTO.setContent(content.toString());
if (StringUtils.isNotBlank(systemSetLogDTO.getContent())) {
logApiService.saveSystemSetLog(systemSetLogDTO);
}
}
private static <T> void getContent(T obj, Integer type, StringBuilder content, SystemSetLogDTO systemSetLogDTO) {
if (obj instanceof Iterable) {
for (Object o : (Iterable) obj) {
getContent(o, type, content, systemSetLogDTO);
}
}
final BeanWrapper dtoBean = new BeanWrapperImpl(obj);
PropertyDescriptor[] pds = dtoBean.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
if ("storeId".equals(pd.getName()) && obj instanceof StoreInfoDTO) {
Object storeId = dtoBean.getPropertyValue(pd.getName());
if (storeId != null) {
systemSetLogDTO.setRelationId(Long.valueOf(storeId.toString()));
}
} else {
String name = PropertyNameMap.get(pd.getName());
if (StringUtils.isNotBlank(name)) {
Object value = dtoBean.getPropertyValue(pd.getName());
if (value != null) {
if (value instanceof Iterable) {
for (Object o : (Iterable) value) {
getContent(o, type, content, systemSetLogDTO);
}
} else {
content.append(name).append(" : ").append(value).append("<br/>");
// if (type == 1) {
// content.append(name).append(" 新增 ").append(value).append("<br/>");
// } else if (type == 2) {
// content.append(name).append(" 修改为 ").append(value).append("<br/>");
// }
}
}
}
}
}
}
}
package com.gic.store.utils.log;
import com.gic.store.utils.LogUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* 日志aop
* @ClassName: LogAspect

* @Description: 

* @author guojuxing

* @date 2019/7/31 1:52 PM

*/
@Aspect
public class LogAspect {
private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
@Pointcut("execution(* com.gic.store.service.outer.*.save*(..))")
public void saveCell() {
}
@Pointcut("execution(public * com.gic.store.service.outer.*.update*(..))")
public void updateCell() {
}
@Pointcut("execution(* com.gic.store.service.outer.*.delete*(..))")
public void deleteCell() {
}
@AfterReturning(value = "saveCell()", argNames = "joinPoint,object", returning = "object")
public void saveLog(JoinPoint joinPoint, Object object) {
if (joinPoint.getArgs() == null) {
return;
}
String methodName = joinPoint.getSignature().getName();
String operContent = "";
logger.info("aspectLog:{}", joinPoint.getArgs());
LogUtils.saveAddLog(arrToList(joinPoint.getArgs()));
}
@AfterReturning(value = "updateCell()", argNames = "joinPoint,object", returning = "object")
public void updateLog(JoinPoint joinPoint, Object object) {
if (joinPoint.getArgs() == null) {
return;
}
String methodName = joinPoint.getSignature().getName();
String operContent = "";
logger.info("aspectLog:{}", joinPoint.getArgs());
LogUtils.saveUpdateLog(arrToList(joinPoint.getArgs()));
}
private List<Object> arrToList(Object[] args) {
List<Object> resultList = new ArrayList<>(args.length);
for (Object obj : args) {
resultList.add(obj);
}
return resultList;
}
}
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