diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/DaoAspect.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/DaoAspect.java new file mode 100644 index 00000000..57f36847 --- /dev/null +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/DaoAspect.java @@ -0,0 +1,160 @@ +package com.xhpc.charging.station; + + +import com.xhpc.common.core.constant.CacheConstants; +import com.xhpc.common.core.utils.SecurityUtils; +import com.xhpc.common.core.utils.StringUtils; +import com.xhpc.common.redis.service.RedisService; +import com.xhpc.system.api.model.LoginUser; +import org.apache.commons.beanutils.BeanUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.util.Date; + +/* + * TODO AO切面,插入创建人,创建时间,修改人,修改时间 + * @author fjd + * @date 2020-07-09 11:59 + */ +@Aspect +@Component +@Configuration +public class DaoAspect { + + private static final String CREATE_USER = "createBy"; + private static final String CREATE_TIME = "createTime"; + private static final String UPDATE_USER = "updateBy"; + private static final String UPDATE_TIME = "updateTime"; + private static final String TENANT_ID = "tenantId"; + + @Pointcut("execution(* com.xhpc..*.update*(..))") + public void daoUpdate() { + + } + + @Pointcut("execution(* com.xhpc..*.insert*(..))") + public void daoCreate() { + + } + + @Autowired + private RedisService redisService; + + @Around("daoUpdate()") + public Object doAroundUpdate(ProceedingJoinPoint point) throws Throwable { + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes == null) { + return point.proceed(); + } + HttpServletRequest request = attributes.getRequest(); + try { + String token = request.getHeader(CacheConstants.HEADER); + token = token.substring(7); + LoginUser loginUser = new LoginUser(); + try { + loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token); + } catch (Exception e) { + } + String userName = ""; + try { + userName = SecurityUtils.getUsername(); + } catch (Exception e) { + } + if (StringUtils.isEmpty(userName)) { + userName = loginUser.getUsername(); + } + if (StringUtils.isEmpty(userName)) { + userName = "admin"; + } + if (userName != null) { + Object[] objects = point.getArgs(); + if (objects != null && objects.length > 0) { + for (Object arg : objects) { + if (isProperty(arg, UPDATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_USER))) { + BeanUtils.setProperty(arg, UPDATE_USER, userName); + } + if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { + BeanUtils.setProperty(arg, UPDATE_TIME, new Date()); + } + } + } + } + } catch (Exception e) { + } + Object object = point.proceed(); + return object; + + } + + @Around("daoCreate()") + public Object doAroundCreate(ProceedingJoinPoint point) throws Throwable { + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes == null) { + return point.proceed(); + } + HttpServletRequest request = attributes.getRequest(); + try { + Object[] objects = point.getArgs(); + if (objects != null && objects.length > 0) { + for (Object arg : objects) { + String token = request.getHeader(CacheConstants.HEADER); + token = token.substring(7); + LoginUser loginUser = new LoginUser(); + try { + loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token); + } catch (Exception e) { + } + String userName = ""; + try { + userName = SecurityUtils.getUsername(); + } catch (Exception e) { + } + if (StringUtils.isEmpty(userName)) { + userName = loginUser.getUsername(); + } + if (StringUtils.isEmpty(userName)) { + userName = "admin"; + } + Date date = new Date(); + if (isProperty(arg, CREATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, CREATE_USER))) { + BeanUtils.setProperty(arg, CREATE_USER, userName); + } + if (isProperty(arg, UPDATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_USER))) { + BeanUtils.setProperty(arg, UPDATE_USER, userName); + } + + if (isProperty(arg, CREATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, CREATE_TIME))) { + BeanUtils.setProperty(arg, CREATE_TIME, date); + } + if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { + BeanUtils.setProperty(arg, UPDATE_TIME, date); + } + + if (isProperty(arg, TENANT_ID) && StringUtils.isEmpty(BeanUtils.getProperty(arg, TENANT_ID))) { + BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + } + } + } + } catch (Exception e) { + } + Object object = point.proceed(); + return object; + } + + public static boolean isProperty(Object bean, String field) { + + return StringUtils.isProperty(bean, field); + } + +} diff --git a/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/DaoAspect.java b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/DaoAspect.java new file mode 100644 index 00000000..afa7ebd7 --- /dev/null +++ b/xhpc-modules/xhpc-general/src/main/java/com/xhpc/general/DaoAspect.java @@ -0,0 +1,160 @@ +package com.xhpc.general; + + +import com.xhpc.common.core.constant.CacheConstants; +import com.xhpc.common.core.utils.SecurityUtils; +import com.xhpc.common.core.utils.StringUtils; +import com.xhpc.common.redis.service.RedisService; +import com.xhpc.system.api.model.LoginUser; +import org.apache.commons.beanutils.BeanUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.util.Date; + +/* + * TODO AO切面,插入创建人,创建时间,修改人,修改时间 + * @author fjd + * @date 2020-07-09 11:59 + */ +@Aspect +@Component +@Configuration +public class DaoAspect { + + private static final String CREATE_USER = "createBy"; + private static final String CREATE_TIME = "createTime"; + private static final String UPDATE_USER = "updateBy"; + private static final String UPDATE_TIME = "updateTime"; + private static final String TENANT_ID = "tenantId"; + + @Pointcut("execution(* com.xhpc..*.update*(..))") + public void daoUpdate() { + + } + + @Pointcut("execution(* com.xhpc..*.insert*(..))") + public void daoCreate() { + + } + + @Autowired + private RedisService redisService; + + @Around("daoUpdate()") + public Object doAroundUpdate(ProceedingJoinPoint point) throws Throwable { + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes == null) { + return point.proceed(); + } + HttpServletRequest request = attributes.getRequest(); + try { + String token = request.getHeader(CacheConstants.HEADER); + token = token.substring(7); + LoginUser loginUser = new LoginUser(); + try { + loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token); + } catch (Exception e) { + } + String userName = ""; + try { + userName = SecurityUtils.getUsername(); + } catch (Exception e) { + } + if (StringUtils.isEmpty(userName)) { + userName = loginUser.getUsername(); + } + if (StringUtils.isEmpty(userName)) { + userName = "admin"; + } + if (userName != null) { + Object[] objects = point.getArgs(); + if (objects != null && objects.length > 0) { + for (Object arg : objects) { + if (isProperty(arg, UPDATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_USER))) { + BeanUtils.setProperty(arg, UPDATE_USER, userName); + } + if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { + BeanUtils.setProperty(arg, UPDATE_TIME, new Date()); + } + } + } + } + } catch (Exception e) { + } + Object object = point.proceed(); + return object; + + } + + @Around("daoCreate()") + public Object doAroundCreate(ProceedingJoinPoint point) throws Throwable { + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes == null) { + return point.proceed(); + } + HttpServletRequest request = attributes.getRequest(); + try { + Object[] objects = point.getArgs(); + if (objects != null && objects.length > 0) { + for (Object arg : objects) { + String token = request.getHeader(CacheConstants.HEADER); + token = token.substring(7); + LoginUser loginUser = new LoginUser(); + try { + loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token); + } catch (Exception e) { + } + String userName = ""; + try { + userName = SecurityUtils.getUsername(); + } catch (Exception e) { + } + if (StringUtils.isEmpty(userName)) { + userName = loginUser.getUsername(); + } + if (StringUtils.isEmpty(userName)) { + userName = "admin"; + } + Date date = new Date(); + if (isProperty(arg, CREATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, CREATE_USER))) { + BeanUtils.setProperty(arg, CREATE_USER, userName); + } + if (isProperty(arg, UPDATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_USER))) { + BeanUtils.setProperty(arg, UPDATE_USER, userName); + } + + if (isProperty(arg, CREATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, CREATE_TIME))) { + BeanUtils.setProperty(arg, CREATE_TIME, date); + } + if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { + BeanUtils.setProperty(arg, UPDATE_TIME, date); + } + + if (isProperty(arg, TENANT_ID) && StringUtils.isEmpty(BeanUtils.getProperty(arg, TENANT_ID))) { + BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + } + } + } + } catch (Exception e) { + } + Object object = point.proceed(); + return object; + } + + public static boolean isProperty(Object bean, String field) { + + return StringUtils.isProperty(bean, field); + } + +} diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/DaoAspect.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/DaoAspect.java new file mode 100644 index 00000000..8dfe8aaf --- /dev/null +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/DaoAspect.java @@ -0,0 +1,160 @@ +package com.xhpc.invoice.aspect; + + +import com.xhpc.common.core.constant.CacheConstants; +import com.xhpc.common.core.utils.SecurityUtils; +import com.xhpc.common.core.utils.StringUtils; +import com.xhpc.common.redis.service.RedisService; +import com.xhpc.system.api.model.LoginUser; +import org.apache.commons.beanutils.BeanUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.util.Date; + +/* + * TODO AO切面,插入创建人,创建时间,修改人,修改时间 + * @author fjd + * @date 2020-07-09 11:59 + */ +@Aspect +@Component +@Configuration +public class DaoAspect { + + private static final String CREATE_USER = "createBy"; + private static final String CREATE_TIME = "createTime"; + private static final String UPDATE_USER = "updateBy"; + private static final String UPDATE_TIME = "updateTime"; + private static final String TENANT_ID = "tenantId"; + + @Pointcut("execution(* com.xhpc..*.update*(..))") + public void daoUpdate() { + + } + + @Pointcut("execution(* com.xhpc..*.insert*(..))") + public void daoCreate() { + + } + + @Autowired + private RedisService redisService; + + @Around("daoUpdate()") + public Object doAroundUpdate(ProceedingJoinPoint point) throws Throwable { + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes == null) { + return point.proceed(); + } + HttpServletRequest request = attributes.getRequest(); + try { + String token = request.getHeader(CacheConstants.HEADER); + token = token.substring(7); + LoginUser loginUser = new LoginUser(); + try { + loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token); + } catch (Exception e) { + } + String userName = ""; + try { + userName = SecurityUtils.getUsername(); + } catch (Exception e) { + } + if (StringUtils.isEmpty(userName)) { + userName = loginUser.getUsername(); + } + if (StringUtils.isEmpty(userName)) { + userName = "admin"; + } + if (userName != null) { + Object[] objects = point.getArgs(); + if (objects != null && objects.length > 0) { + for (Object arg : objects) { + if (isProperty(arg, UPDATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_USER))) { + BeanUtils.setProperty(arg, UPDATE_USER, userName); + } + if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { + BeanUtils.setProperty(arg, UPDATE_TIME, new Date()); + } + } + } + } + } catch (Exception e) { + } + Object object = point.proceed(); + return object; + + } + + @Around("daoCreate()") + public Object doAroundCreate(ProceedingJoinPoint point) throws Throwable { + + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes == null) { + return point.proceed(); + } + HttpServletRequest request = attributes.getRequest(); + try { + Object[] objects = point.getArgs(); + if (objects != null && objects.length > 0) { + for (Object arg : objects) { + String token = request.getHeader(CacheConstants.HEADER); + token = token.substring(7); + LoginUser loginUser = new LoginUser(); + try { + loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token); + } catch (Exception e) { + } + String userName = ""; + try { + userName = SecurityUtils.getUsername(); + } catch (Exception e) { + } + if (StringUtils.isEmpty(userName)) { + userName = loginUser.getUsername(); + } + if (StringUtils.isEmpty(userName)) { + userName = "admin"; + } + Date date = new Date(); + if (isProperty(arg, CREATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, CREATE_USER))) { + BeanUtils.setProperty(arg, CREATE_USER, userName); + } + if (isProperty(arg, UPDATE_USER) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_USER))) { + BeanUtils.setProperty(arg, UPDATE_USER, userName); + } + + if (isProperty(arg, CREATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, CREATE_TIME))) { + BeanUtils.setProperty(arg, CREATE_TIME, date); + } + if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { + BeanUtils.setProperty(arg, UPDATE_TIME, date); + } + + if (isProperty(arg, TENANT_ID) && StringUtils.isEmpty(BeanUtils.getProperty(arg, TENANT_ID))) { + BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + } + } + } + } catch (Exception e) { + } + Object object = point.proceed(); + return object; + } + + public static boolean isProperty(Object bean, String field) { + + return StringUtils.isProperty(bean, field); + } + +} diff --git a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/pojo/XhpcInvoice.java b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/pojo/XhpcInvoice.java index 474fa6e5..26450ac0 100644 --- a/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/pojo/XhpcInvoice.java +++ b/xhpc-modules/xhpc-invoice/src/main/java/com/xhpc/invoice/pojo/XhpcInvoice.java @@ -159,6 +159,8 @@ public class XhpcInvoice implements Serializable { */ private Integer delFlag; + private String tenantId; + private static final long serialVersionUID = 1L; -} \ No newline at end of file +} diff --git a/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml index d77b9192..2bcd6dfc 100644 --- a/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml +++ b/xhpc-modules/xhpc-invoice/src/main/resources/mapper/XhpcInvoiceMapper.xml @@ -261,7 +261,7 @@ creator_id, creator_type, creator, create_time, `status`, invoicing_time, drawer, finance_notes, electric_invoice_url, - updator, update_time, del_flag) + updator, update_time, del_flag, tenant_id) values (#{receiveEmail,jdbcType=VARCHAR}, #{titleType,jdbcType=INTEGER}, #{titleContent,jdbcType=VARCHAR}, #{dutyNumber,jdbcType=VARCHAR}, #{invoiceContent,jdbcType=VARCHAR}, #{invoiceMoney,jdbcType=DECIMAL}, #{invoiceOrderEletricTotalMoney,jdbcType=DECIMAL}, #{invoiceOrderServiceTotalMoney,jdbcType=DECIMAL}, @@ -270,7 +270,8 @@ #{creatorId,jdbcType=BIGINT}, #{creatorType,jdbcType=INTEGER}, #{creator,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, #{invoicingTime,jdbcType=TIMESTAMP}, #{drawer,jdbcType=VARCHAR}, #{financeNotes,jdbcType=VARCHAR}, #{electricInvoiceUrl,jdbcType=VARCHAR}, - #{updator,jdbcType=BIGINT}, #{updateTime,jdbcType=DATE}, #{delFlag,jdbcType=INTEGER}) + #{updator,jdbcType=BIGINT}, #{updateTime,jdbcType=DATE}, #{delFlag,jdbcType=INTEGER}, + #{tenantId,jdbcType=VARCHAR}) @@ -354,6 +355,9 @@ del_flag, + + tenant_id + @@ -434,6 +438,9 @@ #{delFlag,jdbcType=INTEGER}, + + #{tenantId,jdbcType=INTEGER}, + del_flag, + + tenant_id, + @@ -598,6 +608,9 @@ #{delFlag,jdbcType=INTEGER}, + + #{tenantId,jdbcType=INTEGER}, + @@ -749,4 +762,4 @@ WHERE invoice_id = #{invoiceId}; - \ No newline at end of file + diff --git a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/aspect/DaoAspect.java b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/aspect/DaoAspect.java index 3ce86cc4..fde262d8 100644 --- a/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/aspect/DaoAspect.java +++ b/xhpc-modules/xhpc-order/src/main/java/com/xhpc/order/aspect/DaoAspect.java @@ -33,6 +33,7 @@ public class DaoAspect { private static final String CREATE_TIME = "createTime"; private static final String UPDATE_USER = "updateBy"; private static final String UPDATE_TIME = "updateTime"; + private static final String TENANT_ID = "tenantId"; @Pointcut("execution(* com.xhpc..*.update*(..))") public void daoUpdate() { @@ -134,6 +135,10 @@ public class DaoAspect { if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { BeanUtils.setProperty(arg, UPDATE_TIME, date); } + + if (isProperty(arg, TENANT_ID) && StringUtils.isEmpty(BeanUtils.getProperty(arg, TENANT_ID))) { + BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + } } } } catch (Exception e) { diff --git a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/aspect/DaoAspect.java b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/aspect/DaoAspect.java index f1b194b5..49887a2a 100644 --- a/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/aspect/DaoAspect.java +++ b/xhpc-modules/xhpc-payment/src/main/java/com/xhpc/payment/aspect/DaoAspect.java @@ -33,6 +33,7 @@ public class DaoAspect { private static final String CREATE_TIME = "createTime"; private static final String UPDATE_USER = "updateBy"; private static final String UPDATE_TIME = "updateTime"; + private static final String TENANT_ID = "tenantId"; @Pointcut("execution(* com.xhpc..*.update*(..))") public void daoUpdate() { @@ -135,6 +136,9 @@ public class DaoAspect { if (isProperty(arg, UPDATE_TIME) && StringUtils.isEmpty(BeanUtils.getProperty(arg, UPDATE_TIME))) { BeanUtils.setProperty(arg, UPDATE_TIME, date); } + if (isProperty(arg, TENANT_ID) && StringUtils.isEmpty(BeanUtils.getProperty(arg, TENANT_ID))) { + BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + } } } } catch (Exception e) { diff --git a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/aspect/UserDaoAspect.java b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/aspect/UserDaoAspect.java index c63e46d4..df932d4a 100644 --- a/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/aspect/UserDaoAspect.java +++ b/xhpc-modules/xhpc-user/src/main/java/com/xhpc/user/aspect/UserDaoAspect.java @@ -121,7 +121,9 @@ public class UserDaoAspect { BeanUtils.setProperty(arg, UPDATE_TIME, date); } - BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + if (isProperty(arg, TENANT_ID) && StringUtils.isEmpty(BeanUtils.getProperty(arg, TENANT_ID))) { + BeanUtils.setProperty(arg, TENANT_ID, loginUser.getTenantId()); + } } } } catch (Exception e) {