80 lines
3.3 KiB
Plaintext
80 lines
3.3 KiB
Plaintext
package com.sercurityControl.proteam.service.impl;
|
|
|
|
import com.securityControl.common.core.utils.aes.ListHelper;
|
|
import com.sercurityControl.proteam.domain.LoginLogBean;
|
|
import com.sercurityControl.proteam.domain.OperateLogBean;
|
|
import com.sercurityControl.proteam.mapper.LogsMapper;
|
|
import com.sercurityControl.proteam.util.DateTimeHelper;
|
|
import com.sercurityControl.proteam.util.FileHelper;
|
|
import com.sercurityControl.proteam.util.FtpUtil;
|
|
import com.sercurityControl.proteam.util.LogFileUploadTask;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.io.File;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 日志记录推送
|
|
*/
|
|
@Service
|
|
public class LogsServiceImpl {
|
|
|
|
@Autowired
|
|
LogsMapper mapper;
|
|
|
|
@Value("${file.upload_path}")
|
|
private String UPLOAD_PATH;
|
|
|
|
public void LoginFileUpload() {
|
|
System.out.println("开始日志文件上传");
|
|
try {
|
|
String currentDay = DateTimeHelper.getNowDate();
|
|
List<LoginLogBean> loginDatas = mapper.getLoginLogData(currentDay);
|
|
if(ListHelper.isEmpty(loginDatas)){
|
|
loginDatas=LogFileUploadTask.getLoginList();
|
|
}
|
|
String loginLogfileName = "98524dc664ed4acb959e37561c504af4_user_login_" + currentDay+ ".log";
|
|
boolean tf = FileHelper.fileIsExists(UPLOAD_PATH + "/"+loginLogfileName);
|
|
if (!tf) {//不存在
|
|
System.out.println(UPLOAD_PATH + loginLogfileName + "file not exists");
|
|
File file = new File(UPLOAD_PATH + loginLogfileName);
|
|
file.createNewFile();
|
|
boolean logintf = FileHelper.fileWriteLoginLogData(UPLOAD_PATH + loginLogfileName, loginDatas);
|
|
if (logintf) {
|
|
FtpUtil.ftpUpload(UPLOAD_PATH + loginLogfileName, loginLogfileName, 1);
|
|
}
|
|
} else {//存在
|
|
System.out.println(UPLOAD_PATH + loginLogfileName + "file exists");
|
|
FtpUtil.ftpUpload(UPLOAD_PATH + loginLogfileName, loginLogfileName, 1);
|
|
}
|
|
List<OperateLogBean> operateDatas = mapper.getOperateLogData(currentDay);
|
|
if(ListHelper.isEmpty(operateDatas)){
|
|
operateDatas=LogFileUploadTask.getOperList();
|
|
}
|
|
String operateLogfileName = "98524dc664ed4acb959e37561c504af4_menu_usage_" + DateTimeHelper.getNowDate() + ".log";
|
|
boolean tfs = FileHelper.fileIsExists(UPLOAD_PATH + operateLogfileName);
|
|
if (!tfs) {//不存在
|
|
System.out.println(UPLOAD_PATH + operateLogfileName + "file not exists");
|
|
File file = new File(UPLOAD_PATH + operateLogfileName);
|
|
file.createNewFile();
|
|
boolean operatetf = FileHelper.fileWriteOperateLogData(UPLOAD_PATH + operateLogfileName, operateDatas);
|
|
if (operatetf) {
|
|
FtpUtil.ftpUpload(UPLOAD_PATH + operateLogfileName, operateLogfileName, 2);
|
|
}
|
|
} else {//存在
|
|
System.out.println(UPLOAD_PATH + operateLogfileName + "file exists");
|
|
FtpUtil.ftpUpload(UPLOAD_PATH + operateLogfileName, operateLogfileName, 2);
|
|
}
|
|
} catch (Exception e) {
|
|
System.err.println(e.toString());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|