Merge pull request 'main' (#2) from main into V0.1

This commit is contained in:
xiaoguangbin 2023-05-25 14:45:08 +08:00
commit 4d6157d517
5 changed files with 80 additions and 34 deletions

View File

@ -14,6 +14,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
@Component @Component
@Slf4j @Slf4j
@ -42,6 +43,8 @@ public class FTPUtil {
//声明FTP客户端 //声明FTP客户端
FTPClient ftp = new FTPClient(); FTPClient ftp = new FTPClient();
try { try {
// 切换为本地被动模式可以解决FTP上传后文件为空的问题但需要服务器将FTP服务添加至防火墙白名单
ftp.enterLocalPassiveMode();
//连接 //连接
ftp.connect(host, port); ftp.connect(host, port);
//登录 //登录
@ -101,9 +104,12 @@ public class FTPUtil {
public InputStream downloadFTPFile(String localPath, String fileName){ public InputStream downloadFTPFile(String localPath, String fileName){
InputStream in = null; InputStream in = null;
FTPClient ftpClient = this.LoginFTP();
//传输模式 //传输模式
try { try {
FTPClient ftpClient = this.LoginFTP();
if (Objects.isNull(ftpClient)){
throw new RuntimeException("ftp连接失败!");
}
List<String> paths = Arrays.asList(localPath.split("/")); List<String> paths = Arrays.asList(localPath.split("/"));
if (CollectionUtils.isNotEmpty(paths)){ if (CollectionUtils.isNotEmpty(paths)){
for (String workPath:paths) { for (String workPath:paths) {
@ -111,11 +117,10 @@ public class FTPUtil {
ftpClient.changeWorkingDirectory(workPath); ftpClient.changeWorkingDirectory(workPath);
} }
} }
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
// 设置编码当文件中存在中文且上传后文件乱码时可使用此配置项 // 设置编码当文件中存在中文且上传后文件乱码时可使用此配置项
ftpClient.setControlEncoding(encoding); ftpClient.setControlEncoding(encoding);
// 切换为本地被动模式可以解决FTP上传后文件为空的问题但需要服务器将FTP服务添加至防火墙白名单
// ftp.enterLocalPassiveMode();
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles()); List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
if (CollectionUtils.isNotEmpty(ftpFiles)){ if (CollectionUtils.isNotEmpty(ftpFiles)){

View File

@ -35,11 +35,12 @@ public class LogManageController {
List<LogManage> result = new ArrayList<>(); List<LogManage> result = new ArrayList<>();
try { try {
FTPClient ftpClient = ftpUtil.LoginFTP(); FTPClient ftpClient = ftpUtil.LoginFTP();
//切换工作文件路径
ftpClient.changeWorkingDirectory(workPath);
if(Objects.isNull(ftpClient)){ if(Objects.isNull(ftpClient)){
throw new RuntimeException("ftp连接失败!"); throw new RuntimeException("ftp连接失败!");
} }
//切换工作文件路径
ftpClient.changeWorkingDirectory(workPath);
ftpClient.enterLocalPassiveMode();
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories()); List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listDirectories());
if (CollectionUtils.isNotEmpty(ftpFiles)){ if (CollectionUtils.isNotEmpty(ftpFiles)){
int num =1; int num =1;
@ -122,6 +123,7 @@ public class LogManageController {
ftpClient.changeWorkingDirectory(workPath); ftpClient.changeWorkingDirectory(workPath);
} }
} }
ftpClient.enterLocalPassiveMode();
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles()); List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
if (CollectionUtils.isNotEmpty(ftpFiles)){ if (CollectionUtils.isNotEmpty(ftpFiles)){
for (FTPFile ftpFile:ftpFiles) { for (FTPFile ftpFile:ftpFiles) {

View File

@ -7,8 +7,8 @@ import java.util.List;
public interface ISysTaskStationService extends IService<SysTaskStation> { public interface ISysTaskStationService extends IService<SysTaskStation> {
void create(String taskId, List<SysTaskStation> taskStations); void create(String taskId, String ipAddr, List<SysTaskStation> taskStations);
void updateStation(String taskId, List<SysTaskStation> stationList); void updateStation(String taskId, String ipAddr, List<SysTaskStation> stationList);
} }

View File

@ -175,16 +175,28 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> impl
@Transactional @Transactional
public Result create(List<SysTask> sysTasks){ public Result create(List<SysTask> sysTasks){
Result result = new Result(); Result result = new Result();
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
//获取当前操作人用户名
String username = JwtUtil.getUserNameByToken(request);
//设置IP地址
String ipAddr = IpUtils.getIpAddr(request);
//如果新增排班任务不为空 //如果新增排班任务不为空
if (CollectionUtils.isNotEmpty(sysTasks)){ if (CollectionUtils.isNotEmpty(sysTasks)){
//遍历排班任务进行存储 //遍历排班任务进行存储
for (SysTask sysTask:sysTasks) { for (SysTask sysTask:sysTasks) {
//操作人
sysTask.setCreateBy(username);
//操作人的ip
sysTask.setOperateIp(ipAddr);
//id //id
sysTask.setId(String.valueOf(IdWorker.getId())); sysTask.setId(String.valueOf(IdWorker.getId()));
//创建时间
sysTask.setCreateTime(new Date());
this.baseMapper.insert(sysTask); this.baseMapper.insert(sysTask);
//如果排班任务中台站信息不为空 //如果排班任务中台站信息不为空
if (CollectionUtils.isNotEmpty(sysTask.getStationList())){ if (CollectionUtils.isNotEmpty(sysTask.getStationList())){
sysTaskStationService.create(sysTask.getId(), sysTask.getStationList()); sysTaskStationService.create(sysTask.getId(), ipAddr, sysTask.getStationList());
} }
} }
} }
@ -197,6 +209,12 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> impl
@Transactional @Transactional
public Result update(List<SysTask> sysTasks) { public Result update(List<SysTask> sysTasks) {
Result result = new Result(); Result result = new Result();
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
//获取当前操作人用户名
String username = JwtUtil.getUserNameByToken(request);
//设置IP地址
String ipAddr = IpUtils.getIpAddr(request);
//如果新增排班任务不为空 //如果新增排班任务不为空
if (CollectionUtils.isNotEmpty(sysTasks)){ if (CollectionUtils.isNotEmpty(sysTasks)){
//获取第一个排班任务的信息 //获取第一个排班任务的信息
@ -204,12 +222,18 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> impl
this.deleteByDate(task.getSchedulingDate()); this.deleteByDate(task.getSchedulingDate());
//遍历排班任务进行存储 //遍历排班任务进行存储
for (SysTask sysTask:sysTasks) { for (SysTask sysTask:sysTasks) {
//操作人
sysTask.setCreateBy(username);
//操作人的ip
sysTask.setOperateIp(ipAddr);
//id //id
sysTask.setId(String.valueOf(IdWorker.getId())); sysTask.setId(String.valueOf(IdWorker.getId()));
//创建时间
sysTask.setCreateTime(new Date());
this.baseMapper.insert(sysTask); this.baseMapper.insert(sysTask);
//如果排班任务中台站信息不为空 //如果排班任务中台站信息不为空
if (CollectionUtils.isNotEmpty(sysTask.getStationList())){ if (CollectionUtils.isNotEmpty(sysTask.getStationList())){
sysTaskStationService.create(sysTask.getId(), sysTask.getStationList()); sysTaskStationService.create(sysTask.getId(), ipAddr, sysTask.getStationList());
} }
} }
} }
@ -349,12 +373,15 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> impl
} }
@Override @Override
@Transactional
public ImportViewVo importExcel(List<SysTaskExportVo> dataList, int headRow) { public ImportViewVo importExcel(List<SysTaskExportVo> dataList, int headRow) {
ImportViewVo importViewVo = new ImportViewVo(); ImportViewVo importViewVo = new ImportViewVo();
//获取用户信息 //获取用户信息
List<SysUser> userList = sysUserMapper.selectList(new LambdaQueryWrapper<>()); List<SysUser> userList = sysUserMapper.selectList(new LambdaQueryWrapper<>());
//获取台站信息 //获取台站信息
List<GardsStations> stationsList = gardsStationsService.getGardsStations(); List<GardsStations> stationsList = gardsStationsService.getGardsStations();
//获取排班任务信息
List<SysTask> sysTaskList = this.baseMapper.selectList(new LambdaQueryWrapper<SysTask>());
//存储排班任务信息 //存储排班任务信息
List<SysTask> taskList = new ArrayList<>(); List<SysTask> taskList = new ArrayList<>();
//导入失败的结果集 //导入失败的结果集
@ -467,10 +494,7 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> impl
} }
//判断当前数据库中的排班任务信息是否为空 //判断当前数据库中的排班任务信息是否为空
if (CollectionUtils.isNotEmpty(taskList)){ if (CollectionUtils.isNotEmpty(taskList)){
//遍历可以新增的数据信息 this.addOrUpdate(sysTaskList,taskList);
for (SysTask sysTask:taskList) {
this.addOrUpdate(sysTask);
}
} }
} }
} catch (ParseException e) { } catch (ParseException e) {
@ -482,25 +506,37 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> impl
return importViewVo; return importViewVo;
} }
private void addOrUpdate(SysTask sysTask){ private void addOrUpdate(List<SysTask> sysTaskList,List<SysTask> taskList){
//根据用户名称及排班日期查询对应的数据 //获取request
LambdaQueryWrapper<SysTask> queryWrapper = new LambdaQueryWrapper<>(); HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
queryWrapper.eq(SysTask::getUserId, sysTask.getUserId()); //获取当前操作人用户名
queryWrapper.eq(SysTask::getSchedulingDate, sysTask.getSchedulingDate()); String username = JwtUtil.getUserNameByToken(request);
SysTask task = this.baseMapper.selectOne(queryWrapper); //设置IP地址
String ipAddr = IpUtils.getIpAddr(request);
for (SysTask sysTask:taskList) {
List<SysTask> tasks = sysTaskList.stream()
.filter(item -> item.getUserId().equals(sysTask.getUserId()) && item.getSchedulingDate().equals(sysTask.getSchedulingDate())).collect(Collectors.toList());
//如果查询到的内容不为空则进行修改 //如果查询到的内容不为空则进行修改
if (Objects.nonNull(task)){ if (CollectionUtils.isNotEmpty(tasks)){
SysTask task = tasks.get(0);
List<SysTaskStation> stationList = sysTask.getStationList(); List<SysTaskStation> stationList = sysTask.getStationList();
if (CollectionUtils.isNotEmpty(stationList)){ if (CollectionUtils.isNotEmpty(stationList)){
sysTaskStationService.updateStation(task.getId(), stationList); sysTaskStationService.updateStation(task.getId(), ipAddr, stationList);
} }
}else {//如果查询的内容为空则进行新增 }else {//如果查询的内容为空则进行新增
//操作人
sysTask.setCreateBy(username);
//操作人的ip
sysTask.setOperateIp(ipAddr);
//id //id
sysTask.setId(String.valueOf(IdWorker.getId())); sysTask.setId(String.valueOf(IdWorker.getId()));
//创建时间
sysTask.setCreateTime(new Date());
this.baseMapper.insert(sysTask); this.baseMapper.insert(sysTask);
//如果排班任务中台站信息不为空 //如果排班任务中台站信息不为空
if (CollectionUtils.isNotEmpty(sysTask.getStationList())){ if (CollectionUtils.isNotEmpty(sysTask.getStationList())){
sysTaskStationService.create(sysTask.getId(), sysTask.getStationList()); sysTaskStationService.create(sysTask.getId(), ipAddr, sysTask.getStationList());
}
} }
} }

View File

@ -18,11 +18,12 @@ public class SysTaskStationServiceImpl extends ServiceImpl<SysTaskStationMapper,
@Override @Override
@Transactional @Transactional
public void create(String taskId, List<SysTaskStation> taskStations) { public void create(String taskId, String ipAddr, List<SysTaskStation> taskStations) {
for (SysTaskStation sysTaskStation:taskStations) { for (SysTaskStation sysTaskStation:taskStations) {
if (StringUtils.isBlank(sysTaskStation.getStationId())){ if (StringUtils.isBlank(sysTaskStation.getStationId())){
throw new RuntimeException("台站信息不能为空"); throw new RuntimeException("台站信息不能为空");
} }
sysTaskStation.setOperateIp(ipAddr);
sysTaskStation.setId(String.valueOf(IdWorker.getId())); sysTaskStation.setId(String.valueOf(IdWorker.getId()));
sysTaskStation.setTaskId(taskId); sysTaskStation.setTaskId(taskId);
this.baseMapper.insert(sysTaskStation); this.baseMapper.insert(sysTaskStation);
@ -30,7 +31,8 @@ public class SysTaskStationServiceImpl extends ServiceImpl<SysTaskStationMapper,
} }
@Override @Override
public void updateStation(String taskId, List<SysTaskStation> stationList) { @Transactional
public void updateStation(String taskId, String ipAddr, List<SysTaskStation> stationList) {
LambdaQueryWrapper<SysTaskStation> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysTaskStation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysTaskStation::getTaskId, taskId); queryWrapper.eq(SysTaskStation::getTaskId, taskId);
this.baseMapper.delete(queryWrapper); this.baseMapper.delete(queryWrapper);
@ -38,6 +40,7 @@ public class SysTaskStationServiceImpl extends ServiceImpl<SysTaskStationMapper,
if (StringUtils.isBlank(sysTaskStation.getStationId())){ if (StringUtils.isBlank(sysTaskStation.getStationId())){
throw new RuntimeException("台站信息不能为空"); throw new RuntimeException("台站信息不能为空");
} }
sysTaskStation.setOperateIp(ipAddr);
sysTaskStation.setId(String.valueOf(IdWorker.getId())); sysTaskStation.setId(String.valueOf(IdWorker.getId()));
sysTaskStation.setTaskId(taskId); sysTaskStation.setTaskId(taskId);
sysTaskStation.setCreateTime(new Date()); sysTaskStation.setCreateTime(new Date());