/src/main/java/com/sichuang/schedule/service/impl/AccessRecordService.java

https://bitbucket.org/sichuangzixun/serviceschedule · Java · 41 lines · 32 code · 5 blank · 4 comment · 3 complexity · 22023809cd1f4d70044f6d48034eafcf MD5 · raw file

  1. package com.sichuang.schedule.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.sichuang.schedule.controller.BaseController;
  4. import com.sichuang.schedule.dao.AccessRecordMapper;
  5. import com.sichuang.schedule.model.entity.AccessRecord;
  6. import com.sichuang.schedule.model.entity.User;
  7. import com.sichuang.schedule.service.IAccessRecordService;
  8. import org.springframework.stereotype.Service;
  9. import javax.annotation.Resource;
  10. import javax.servlet.http.HttpServletRequest;
  11. import java.util.Date;
  12. /**
  13. * @author xs
  14. * @date 2018/9/20 15:51
  15. */
  16. @Service
  17. public class AccessRecordService implements IAccessRecordService{
  18. @Resource private AccessRecordMapper accessRecordMapper;
  19. @Override
  20. public int add(HttpServletRequest request) {
  21. AccessRecord accessRecord = new AccessRecord();
  22. accessRecord.setAccessUrl(request.getRequestURI());
  23. String param = JSON.toJSONString(request.getParameterMap());
  24. if(param.length() > 255){
  25. param = param.substring(0,255);
  26. }
  27. accessRecord.setAccessParam(param);
  28. User userSession = BaseController.getUserSession(request);
  29. if(userSession != null){
  30. accessRecord.setAccessUserId(userSession.getUserId());
  31. accessRecord.setAccessUserName(userSession.getLoginName());
  32. }
  33. accessRecord.setAccessTime(new Date());
  34. return accessRecordMapper.insertSelective(accessRecord);
  35. }
  36. }