71 lines
2.4 KiB
Java
71 lines
2.4 KiB
Java
package com.upchina.common.service;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.upchina.common.entity.ScheduleLog;
|
|
import com.upchina.common.handler.BizException;
|
|
import com.upchina.common.mapper.ScheduleLogMapper;
|
|
import com.upchina.common.query.ListScheduleLogQuery;
|
|
import com.upchina.common.result.ResponseStatus;
|
|
import com.upchina.common.util.CodecUtil;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.List;
|
|
|
|
@Service
|
|
public class ScheduleLogService {
|
|
|
|
private static final String salt = "UP_OEM_SCHEDULE_LOG";
|
|
|
|
@Resource
|
|
private ScheduleLogMapper scheduleLogMapper;
|
|
|
|
public List<ScheduleLog> list(ListScheduleLogQuery query) {
|
|
checkToken(query);
|
|
String serverName = query.getServerName();
|
|
String scheduleName = query.getScheduleName();
|
|
LocalDate date = query.getDate();
|
|
Integer result = query.getResult();
|
|
QueryWrapper<ScheduleLog> wrapper = Wrappers.query();
|
|
wrapper.eq(StrUtil.isNotEmpty(serverName), "server_name", serverName)
|
|
.eq(StrUtil.isNotEmpty(scheduleName), "schedule_name", scheduleName)
|
|
.eq(date != null, "date", date)
|
|
.eq(result != null && result != 0, "result", result);
|
|
return scheduleLogMapper.selectList(wrapper);
|
|
}
|
|
|
|
@Transactional
|
|
public Integer save(ScheduleLog log) {
|
|
if (log.getId() == null) {
|
|
scheduleLogMapper.insert(log);
|
|
} else {
|
|
scheduleLogMapper.updateById(log);
|
|
}
|
|
return log.getId();
|
|
}
|
|
|
|
@Transactional
|
|
public void clearHistory(int saveDays) {
|
|
LocalDate saveDate = LocalDate.now().minusDays(saveDays);
|
|
QueryWrapper<ScheduleLog> wrapper = Wrappers.query();
|
|
wrapper.lt("date", saveDate);
|
|
scheduleLogMapper.delete(wrapper);
|
|
}
|
|
|
|
private void checkToken(ListScheduleLogQuery query) {
|
|
String token = query.getToken();
|
|
LocalDate date = query.getDate();
|
|
String dateStr = date.format(DateTimeFormatter.BASIC_ISO_DATE);
|
|
String hash = CodecUtil.md5(dateStr + salt);
|
|
if (!hash.equals(token)) {
|
|
throw new BizException(ResponseStatus.AUTH_FAIL);
|
|
}
|
|
}
|
|
|
|
}
|