OperationLogAspect.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. package com.caimei.modules.user.aop;
  2. import com.caimei.modules.user.entity.*;
  3. import com.caimei.modules.user.service.*;
  4. import com.caimei.modules.user.utils.HttpContextUtils;
  5. import com.caimei.modules.user.web.ClubTemporaryController;
  6. import com.caimei.modules.user.web.newUser.AgencyController;
  7. import com.thinkgem.jeesite.common.utils.StringUtils;
  8. import com.thinkgem.jeesite.modules.sys.security.SystemAuthorizingRealm;
  9. import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
  10. import org.aspectj.lang.JoinPoint;
  11. import org.aspectj.lang.annotation.AfterReturning;
  12. import org.aspectj.lang.annotation.Aspect;
  13. import org.aspectj.lang.annotation.Pointcut;
  14. import org.aspectj.lang.reflect.MethodSignature;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Component;
  17. import com.thinkgem.jeesite.modules.sys.security.SystemAuthorizingRealm.Principal;
  18. import org.slf4j.Logger;
  19. import org.slf4j.LoggerFactory;
  20. import javax.servlet.http.HttpServletRequest;
  21. import java.io.IOException;
  22. import java.lang.reflect.Method;
  23. import java.math.BigDecimal;
  24. import java.util.ArrayList;
  25. import java.util.Date;
  26. import java.util.List;
  27. @Aspect
  28. @Component
  29. public class OperationLogAspect {
  30. protected Logger logger = LoggerFactory.getLogger(getClass());
  31. @Autowired
  32. private SysLogService sysLogService;
  33. @Autowired
  34. private ClubTemporaryService clubTemporaryService;
  35. //定义切点 @Pointcut
  36. //在注解的位置切入代码
  37. @Pointcut("@annotation(com.caimei.modules.user.aop.OperationLogAnnotation)")
  38. public void logPointCut() {
  39. }
  40. @AfterReturning("logPointCut()")
  41. public void saveSysLog(JoinPoint joinPoint) throws IOException {
  42. HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
  43. //保存日志
  44. OperationalLogs sysLog = new OperationalLogs();
  45. //从切面织入点处通过反射机制获取织入点处的方法
  46. MethodSignature signature = (MethodSignature) joinPoint.getSignature();
  47. //获取切入点所在的方法
  48. Method method = signature.getMethod();
  49. sysLog.setActioncontent(null);
  50. //获取操作类型
  51. OperationLogAnnotation myLog = method.getAnnotation(OperationLogAnnotation.class);
  52. if (myLog != null) {
  53. String value = myLog.operType();
  54. sysLog.setOperationtype(value);//保存获取的操作类型
  55. System.out.println("Operationtype操作类型=" + value);
  56. }
  57. //获取请求的类名
  58. String className = joinPoint.getTarget().getClass().getName();
  59. //获取请求操作类型
  60. String operType = myLog.operType();
  61. sysLog.setOperationtype(operType);
  62. //获取请求操作内容
  63. AgencyController A = new AgencyController();
  64. ClubTemporaryController B = new ClubTemporaryController();
  65. String email = request.getParameter("contractEmail");//修改后邮箱
  66. String bindm = request.getParameter("bindMobile");//修改后手机电话
  67. String jgname = request.getParameter("name");//修改后机构名字
  68. String sname = request.getParameter("sname");//修改后机构简称
  69. String uname = request.getParameter("userName");//修改后的联系人
  70. String linkMan = request.getParameter("linkMan");//修改后的联系人
  71. String Identity = request.getParameter("linkManIdentity");//联系人身份
  72. String address = request.getParameter("address");//详细地址
  73. String socialCreditCode = request.getParameter("socialCreditCode");//营业执照编号
  74. String headpic = request.getParameter("headpic");//门头照
  75. String businessLicenseImage = request.getParameter("businessLicenseImage");//营业执照
  76. String ClubType = request.getParameter("firstClubType");//机构类型
  77. String mainpro = request.getParameter("mainpro");//主营业务
  78. String contractPhone = request.getParameter("contractPhone");//固定电话
  79. String fax = request.getParameter("fax");//传真
  80. String empnum = request.getParameter("empnum");//公司人数
  81. String info = request.getParameter("info");//公司简介
  82. String area = request.getParameter("area");//机构面积
  83. String bedNums = request.getParameter("bedNums");//美容院床位
  84. String beauticians = request.getParameter("beauticians");//美容师数
  85. String monthAchievement = request.getParameter("monthAchievement");//月业绩
  86. String promotionAchievement = request.getParameter("promotionAchievement");//促销业绩
  87. String yearAchievement = request.getParameter("yearAchievement");//年业绩
  88. String cateA = request.getParameter("cateA");//A类会员
  89. String consumeA = request.getParameter("consumeA");//A类会员消费金额
  90. String cateB = request.getParameter("empnum");//B类会员
  91. String consumeB = request.getParameter("consumeB");//B类会员消费金额
  92. String cateC = request.getParameter("cateC");//C类会员
  93. String consumeC = request.getParameter("consumeC");//C类会员消费金额
  94. String highestAchievement = request.getParameter("highestAchievement");//最高业绩
  95. String reachPepole = request.getParameter("reachPepole");//到店人数
  96. String clinchPepole = request.getParameter("clinchPepole");//成交人数
  97. String shortName = request.getParameter("shortName");//成交人数
  98. String methodName = myLog.operModul();
  99. ArrayList<String> list = new ArrayList();
  100. //*
  101. // 未确认机构编辑
  102. // */
  103. if("1".equals(myLog.oper())&& "编辑".equals(myLog.operType())){
  104. if (B.clubT.getLinkMan() != "") {
  105. sysLog.setContact(B.clubT.getLinkMan());
  106. }
  107. if (B.clubT.getLinkMan() == null) {
  108. if (linkMan != null) {
  109. list.add("新增了联系人");
  110. }
  111. }
  112. if (!B.clubT.getLinkMan().equals(linkMan)) {
  113. list.add("修改了联系人");
  114. }
  115. if (B.clubT.getShortName() == null) {
  116. if (shortName != null) {
  117. list.add("新增了机构简称");
  118. }
  119. }
  120. if (!B.clubT.getShortName().equals(shortName)) {
  121. list.add("修改了机构简称");
  122. }
  123. if (B.clubT.getName() == null) {
  124. if (jgname != null) {
  125. list.add("新增了机构名称");
  126. }
  127. }
  128. if (!B.clubT.getName().equals(jgname)) {
  129. list.add("修改了机构名称");
  130. }
  131. if (B.clubT.getBindMobile() == null) {
  132. if (bindm != null) {
  133. list.add("新增了手机号");
  134. }
  135. }
  136. if (!B.clubT.getBindMobile().equals(bindm)) {
  137. list.add("修改了手机号");
  138. }
  139. if (B.clubT.getContractEmail() == null) {
  140. if (email != null) {
  141. list.add("新增邮箱");
  142. }
  143. }
  144. if (!B.clubT.getContractEmail().equals(email)) {
  145. list.add("修改了邮箱");
  146. }
  147. if (!B.clubT.getAddress().equals(address)) {
  148. list.add("修改了详细地址");
  149. }
  150. if (B.clubT.getBusinessLicense() == null) {
  151. if (businessLicenseImage != null) {
  152. list.add("新增了营业执照");
  153. }
  154. } else {
  155. if (!B.clubT.getBusinessLicense().equals(businessLicenseImage)) {
  156. list.add("修改了营业执照");
  157. }
  158. }
  159. if (B.clubT.getShopPhoto() == null) {
  160. if (headpic != null) {
  161. list.add("新增了门头照");
  162. }
  163. if (!B.clubT.getShopPhoto().equals(headpic)) {
  164. list.add("修改了门头照");
  165. }
  166. }
  167. if (B.clubT.getSocialCreditCode() == null) {
  168. if (socialCreditCode != null) {
  169. list.add("新增了营业执照编号");
  170. }
  171. if (!B.clubT.getSocialCreditCode().equals(socialCreditCode)) {
  172. list.add("修改了营业执照编号");
  173. }
  174. }
  175. if (B.clubT.getFirstClubType() == null) {
  176. if (ClubType != null) {
  177. list.add("新增了机构类型");
  178. }
  179. } else if (!B.clubT.getFirstClubType().equals(ClubType)) {
  180. list.add("修改了机构类型");
  181. }
  182. }
  183. if ("编辑".equals(myLog.operType())&& "2".equals(myLog.oper()) ) {
  184. logger.info(A.cmClu.getHighestAchievement()+"*****"+A.cmClu.getReachPepole()+"*****"+A.cmClu.getClinchPepole());
  185. if ("".equals(A.cmClu.getHighestAchievement()) || A.cmClu.getReachPepole() == null || A.cmClu.getClinchPepole() == null) {
  186. if (!"".equals(highestAchievement) || !"".equals(reachPepole) || !"".equals(clinchPepole)) {
  187. list.add("新增了活动业绩信息");
  188. }
  189. } else {
  190. if (!highestAchievement.equals(A.cmClu.getHighestAchievement())) {
  191. list.add("修改了活动业绩的最高业绩信息");
  192. }
  193. if (Integer.parseInt(reachPepole) != A.cmClu.getReachPepole()) {
  194. list.add("修改了活动业绩的到店人数信息");
  195. }
  196. if (Integer.parseInt(clinchPepole) != A.cmClu.getClinchPepole()) {
  197. list.add("修改了活动业绩的成交人数信息");
  198. }
  199. }
  200. if (A.cmClu.getConsumeA() == null || A.cmClu.getConsumeB() == null || A.cmClu.getConsumeC() == null) {
  201. if (A.cmClu.getConsumeA() != null || A.cmClu.getConsumeB() != null || A.cmClu.getConsumeC() != null) {
  202. list.add("新增了会员消费金额信息");
  203. }
  204. } else {
  205. BigDecimal cateAs = new BigDecimal(consumeA);
  206. BigDecimal cateBs = new BigDecimal(consumeB);
  207. BigDecimal cateCs = new BigDecimal(consumeC);
  208. if (A.cmClu.getConsumeA() != cateAs) {
  209. list.add("修改了A类会员消费金额");
  210. }
  211. if (A.cmClu.getConsumeB() != cateBs) {
  212. list.add("修改了B类会员消费金额");
  213. }
  214. if (A.cmClu.getConsumeC() != cateCs) {
  215. list.add("修改了C类会员消费金额");
  216. }
  217. }
  218. if (A.cmClu.getCateA() == null || A.cmClu.getCateB() == null || A.cmClu.getCateC() == null) {
  219. if (!"".equals(cateA) || !"".equals(cateB) || !"".equals(cateC)) {
  220. list.add("新增了会员信息");
  221. }
  222. } else {
  223. if (A.cmClu.getCateA() != Integer.parseInt(cateA)) {
  224. list.add("修改了A会员信息");
  225. }
  226. if (A.cmClu.getCateB() != Integer.parseInt(cateB)) {
  227. list.add("修改了B会员信息");
  228. }
  229. if (A.cmClu.getCateC() != Integer.parseInt(cateC)) {
  230. list.add("修改了C会员信息");
  231. }
  232. }
  233. if ("".equals(A.cmClu.getMonthAchievement()) || "".equals(A.cmClu.getPromotionAchievement()) || "".equals(A.cmClu.getYearAchievement())) {
  234. if (!"".equals(monthAchievement) || !"".equals(promotionAchievement) || !"".equals(yearAchievement)) {
  235. list.add("新增了业绩信息");
  236. }
  237. } else {
  238. if (!monthAchievement.equals(A.cmClu.getMonthAchievement())) {
  239. list.add("修改了月业绩信息");
  240. }
  241. if (promotionAchievement != A.cmClu.getPromotionAchievement()) {
  242. list.add("修改了促销业绩信息");
  243. }
  244. if (yearAchievement != A.cmClu.getYearAchievement()) {
  245. list.add("修改了年业绩信息");
  246. }
  247. }
  248. if (A.cmClu.getArea() == null || A.cmClu.getBedNums() == null || A.cmClu.getBeauticians() == null) {
  249. if (!"".equals(area) || !"".equals(bedNums) || !"".equals(beauticians)) {
  250. list.add("更新了基本信息");
  251. }
  252. } else {
  253. if (A.cmClu.getArea() != Integer.parseInt(area)) {
  254. list.add("修改了机构面积");
  255. }
  256. if (A.cmClu.getBedNums() != Integer.parseInt(bedNums)) {
  257. list.add("修改了美容床数");
  258. }
  259. if (A.cmClu.getBeauticians() != Integer.parseInt(beauticians)) {
  260. list.add("修改了美容师数");
  261. }
  262. }
  263. if (A.newCm.getInfo() == null) {
  264. if (!"".equals(info)) {
  265. list.add("新增了公司简介");
  266. }
  267. } else if (!A.newCm.getInfo().equals(info)) {
  268. list.add("修改了公司简介");
  269. }
  270. if (empnum.equals(A.cmClu.getEmpnum())) {
  271. list.add("更新了公司人数");
  272. }
  273. if (A.newCm.getFax() == null) {
  274. if (!"".equals(fax)) {
  275. list.add("新增了传真");
  276. }
  277. } else if (!A.newCm.getFax().equals(fax)) {
  278. list.add("修改了传真");
  279. }
  280. if (A.newCm.getContractPhone() == null) {
  281. if (!"".equals(contractPhone)) {
  282. list.add("新增了固定电话");
  283. }
  284. } else if (!A.newCm.getContractPhone().equals(contractPhone)) {
  285. list.add("修改了固定电话");
  286. }
  287. if (!A.newCm.getAddress().equals(address)) {
  288. list.add("修改了详细地址");
  289. }
  290. if (Identity != null) {
  291. if (A.newCm.getLinkManIdentity() != Integer.parseInt(Identity)) {
  292. list.add("修改了联系人身份");
  293. }
  294. }
  295. if (A.newCm.getUserName() == null) {
  296. if (uname != null) {
  297. list.add("新增了联系人");
  298. }
  299. }
  300. if (!A.newCm.getUserName().equals(uname)) {
  301. list.add("修改了联系人");
  302. }
  303. if (A.newCm.getFirstClubType() == null) {
  304. if (ClubType != null) {
  305. list.add("新增了机构类型");
  306. }
  307. } else if (!A.newCm.getFirstClubType().equals(ClubType)) {
  308. list.add("修改了机构类型");
  309. }
  310. if (A.newCm.getBusinessLicenseImage() == null) {
  311. if (businessLicenseImage != null) {
  312. list.add("新增了营业执照");
  313. }
  314. } else {
  315. if (!A.newCm.getBusinessLicenseImage().equals(businessLicenseImage)) {
  316. list.add("修改了营业执照");
  317. }
  318. }
  319. if (A.newCm.getHeadpic() == null) {
  320. if (headpic != null) {
  321. list.add("新增了门头照");
  322. }
  323. if (!A.newCm.getHeadpic().equals(headpic)) {
  324. list.add("修改了门头照");
  325. }
  326. }
  327. if (A.newCm.getSocialCreditCode() == null) {
  328. if (socialCreditCode != null) {
  329. list.add("新增了营业执照编号");
  330. }
  331. if (!A.newCm.getSocialCreditCode().equals(socialCreditCode)) {
  332. list.add("修改了营业执照编号");
  333. }
  334. }
  335. if (A.newCm.getAddress() == null) {
  336. if (address != null) {
  337. list.add("新增了详细地址");
  338. }
  339. }
  340. if (A.newCm.getSname() == null) {
  341. if (sname != null) {
  342. list.add("新增了机构简称");
  343. }
  344. }
  345. if (!A.newCm.getSname().equals(sname)) {
  346. list.add("修改了机构简称");
  347. }
  348. if (A.newCm.getName() == null) {
  349. if (jgname != null) {
  350. list.add("新增了机构名称");
  351. }
  352. }
  353. if (!A.newCm.getName().equals(jgname)) {
  354. list.add("修改了机构名称");
  355. }
  356. if (A.newCm.getBindMobile() == null) {
  357. if (bindm != null) {
  358. list.add("新增了手机号");
  359. }
  360. }
  361. if (!A.newCm.getBindMobile().equals(bindm)) {
  362. list.add("修改了手机号");
  363. }
  364. if (A.newCm.getContractEmail() == null) {
  365. if (email != null) {
  366. list.add("新增了注册邮箱");
  367. }
  368. }
  369. if (!A.newCm.getContractEmail().equals(email)) {
  370. list.add("修改了邮箱");
  371. }
  372. sysLog.setActioncontent(StringUtils.strip(list.toString(), "[]"));
  373. }
  374. if (sysLog.getActioncontent() == null) {
  375. sysLog.setActioncontent(methodName);
  376. }
  377. //获取操作时间
  378. sysLog.setOperationtime(new Date());
  379. //获取操作员
  380. Principal principal = UserUtils.getPrincipal();
  381. System.out.println("操作员" + principal.getName());
  382. String username = principal.getName();
  383. sysLog.setOperator(username);
  384. //获取机构名称和联系人
  385. String id = request.getParameter("id");
  386. if ("编辑".equals(myLog.operType())) {
  387. sysLog.setInstitutionName(jgname);
  388. sysLog.setContact(uname);
  389. }
  390. if ("更换协销".equals(myLog.operType())) {
  391. System.out.println("更换协销" + A.newCms.getLinkMan());
  392. System.out.println("更换协销" + A.newCm.getLinkMan());
  393. if (!"".equals(A.newCms.getLinkMan())) {
  394. sysLog.setActioncontent(A.newCm.getLinkMan() + "更换为" + A.newCms.getLinkMan());
  395. }
  396. sysLog.setContact(A.newCm.getUserName());
  397. sysLog.setInstitutionName(A.newCm.getLinkMan());
  398. }
  399. if ("设置机构类别".equals(myLog.operType())) {
  400. System.out.println("机构类别" + A.types);
  401. if ("1".equals(A.types)) {
  402. sysLog.setActioncontent("设置为资质机构");
  403. } else {
  404. sysLog.setActioncontent("设置为个人机构");
  405. }
  406. sysLog.setContact(A.cmUs.getUserName());
  407. sysLog.setInstitutionName(A.cmUs.getName());
  408. }
  409. if ("审核".equals(myLog.operType())) {
  410. System.out.println("审核" + A.cmUs.getAuditStatus());
  411. if (StringUtils.equals("1", A.cmUs.getAuditStatus())) {
  412. sysLog.setActioncontent("审核通过");
  413. } else {
  414. sysLog.setActioncontent("审核不通过");
  415. }
  416. sysLog.setContact(A.cmUs.getUserName());
  417. sysLog.setInstitutionName(A.cmUs.getName());
  418. }
  419. if ("更改状态".equals(myLog.operType())) {
  420. sysLog.setContact(A.cmUs.getUserName());
  421. sysLog.setInstitutionName(A.cmUs.getName());
  422. }
  423. if ("修改密码".equals(myLog.operType())) {
  424. String Inst = A.cmUs.getName();
  425. String Contact = A.cmUs.getUserName();
  426. sysLog.setContact(Contact);
  427. sysLog.setInstitutionName(Inst);
  428. }
  429. if ("确认注册".equals(myLog.operType())) {
  430. sysLog.setActioncontent(methodName);
  431. ClubTemporary club = clubTemporaryService.get(id);
  432. if (club != null) {
  433. String Inst = club.getLinkMan();
  434. String Contact = club.getName();
  435. sysLog.setContact(Contact);
  436. sysLog.setInstitutionName(Inst);
  437. System.out.println("contact=" + sysLog.getContact());
  438. }
  439. }
  440. //调用service保存SysLog实体类到数据库
  441. if (!"".equals(sysLog.getActioncontent())) {
  442. // if (sysLog.getInstitutionName() != null && sysLog.getContact() != null) {
  443. int i = sysLogService.insert(sysLog);
  444. list.removeAll(list);
  445. }
  446. }
  447. // }
  448. }