ae95a6e438d83174cfd7c6faabad96ddde7a4ca4.svn-base 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package cn.com.goldenwater.dcproj.aop;
  2. import cn.com.goldenwater.dcproj.dao.SupervisionPlanDao;
  3. import cn.com.goldenwater.dcproj.dto.LgtdAndLttd;
  4. import cn.com.goldenwater.dcproj.model.BisInspAllObj;
  5. import cn.com.goldenwater.dcproj.service.BisInspAllObjService;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.aspectj.lang.ProceedingJoinPoint;
  8. import org.aspectj.lang.annotation.Around;
  9. import org.aspectj.lang.annotation.Aspect;
  10. import org.aspectj.lang.annotation.Pointcut;
  11. import org.slf4j.Logger;
  12. import org.slf4j.LoggerFactory;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Component;
  15. @Aspect
  16. @Component
  17. public class BisInspAllObjAop {
  18. private Logger logger = LoggerFactory.getLogger(getClass());
  19. @Autowired
  20. private BisInspAllObjService bisInspAllObjService;
  21. @Autowired
  22. private SupervisionPlanDao supervisionPlanDao;
  23. /**
  24. * 这里我们使用注解的形式
  25. * 当然,我们也可以通过切点表达式直接指定需要拦截的package,需要拦截的class 以及 method
  26. * 切点表达式: execution(...)
  27. */
  28. @Pointcut("execution(* *..BisInspAllObjDao.insert(..))")
  29. public void pointCut() {
  30. }
  31. /**
  32. * 环绕通知 @Around , 当然也可以使用 @Before (前置通知) @After (后置通知)
  33. *
  34. * @param point
  35. * @return
  36. * @throws Throwable
  37. */
  38. @Around("pointCut()")
  39. public Object around(ProceedingJoinPoint point) throws Throwable {
  40. long beginTime = System.currentTimeMillis();
  41. Object result = point.proceed();
  42. long time = System.currentTimeMillis() - beginTime;
  43. try {
  44. updateObjAdCode(point);
  45. } catch (Exception e) {
  46. logger.error(e.getMessage());
  47. }
  48. return result;
  49. }
  50. /**
  51. * 保存日志
  52. *
  53. * @param joinPoint
  54. */
  55. private void updateObjAdCode(ProceedingJoinPoint joinPoint) {
  56. //请求的参数
  57. Object[] args = joinPoint.getArgs();
  58. BisInspAllObj bisInspAllObj = (BisInspAllObj) args[0];
  59. if (StringUtils.isNotBlank(bisInspAllObj.getPtype()) && StringUtils.isNotBlank(bisInspAllObj.getCode())) {
  60. String ptype = bisInspAllObj.getPtype();
  61. if (bisInspAllObj.getPtype().length() == 1) {
  62. ptype = "00" + ptype;
  63. }
  64. if (bisInspAllObj.getPtype().length() == 2) {
  65. ptype = "0" + ptype;
  66. }
  67. LgtdAndLttd ld = supervisionPlanDao.getLgtdAndLttd(bisInspAllObj.getCode(), ptype);
  68. bisInspAllObj.setObjAdCode(ld.getAdCode());
  69. bisInspAllObjService.update(bisInspAllObj);
  70. }
  71. }
  72. }