| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.zswl.dataservice.service.mqtt;
- import com.zswl.dataservice.dao.UserDao;
- import com.zswl.dataservice.dao.mqtt.OperationLogsDao;
- import com.zswl.dataservice.domain.base.SuperEntity;
- import com.zswl.dataservice.domain.user.User;
- import com.zswl.dataservice.domain.mqtt.OperationLogs;
- import com.zswl.dataservice.model.operLogs.OperationLogsModel;
- import com.zswl.dataservice.model.operLogs.OperationLogsSearchParam;
- import com.zswl.dataservice.service.base.SuperService;
- import com.zswl.dataservice.utils.DateUtils;
- import com.zswl.dataservice.utils.bean.BeanUtils;
- import com.zswl.dataservice.utils.mqtt.type.LogsLevel;
- import com.zswl.dataservice.utils.page.PageEntityUtil;
- import com.zswl.dataservice.utils.result.ResultContent;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.ObjectUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.Pageable;
- import org.springframework.stereotype.Service;
- /**
- * @author TRX
- * @date 2024/5/24
- */
- @Slf4j
- @Service
- public class OperationLogsService extends SuperService {
- @Autowired
- OperationLogsDao operationLogsDao;
- @Autowired
- UserDao userDao;
- public ResultContent addLogs(String content, LogsLevel level) {
- OperationLogs logs = new OperationLogs();
- logs.setContent(content);
- if(level == null) {
- level = LogsLevel.Low;
- }
- logs.setLevel(level);
- User user = getCrrentUser();
- if (ObjectUtils.isNotEmpty(user)) {
- logs.setUid(user.getId());
- logs.setUserName(user.getUserName());
- logs.setLoginName(user.getLoginName());
- }
- logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
- operationLogsDao.save(logs);
- return ResultContent.buildSuccess();
- }
- public ResultContent addLogs(String content, LogsLevel level, SuperEntity entity) {
- OperationLogs logs = new OperationLogs();
- logs.setContent(content);
- if(level == null) {
- level = LogsLevel.Low;
- }
- logs.setLevel(level);
- User user = getCrrentUser();
- if (ObjectUtils.isNotEmpty(user)) {
- logs.setUid(user.getId());
- logs.setUserName(user.getUserName());
- logs.setLoginName(user.getLoginName());
- }
- logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
- if (ObjectUtils.isNotEmpty(entity)) {
- logs.setDataId(entity.getId());
- logs.setBackObj(entity);
- }
- operationLogsDao.save(logs);
- return ResultContent.buildSuccess();
- }
- /**
- * 日志列表
- *
- * @param pageable
- * @param param
- * @return
- */
- public ResultContent<Page<OperationLogsModel>> pageLogs(Pageable pageable, OperationLogsSearchParam param) {
- Page<OperationLogs> page = operationLogsDao.page(pageable, param);
- return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
- }
- public OperationLogsModel toModel(OperationLogs entity) {
- OperationLogsModel model = new OperationLogsModel();
- if (ObjectUtils.isNotEmpty(entity)) {
- BeanUtils.copyProperties(entity, model);
- }
- return model;
- }
- }
|