diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/common/util/FTPUtil.java b/jeecg-module-log-manage/src/main/java/org/jeecg/common/util/FTPUtil.java index 8a45cdbe..d8fb73d2 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/common/util/FTPUtil.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/common/util/FTPUtil.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import java.util.Objects; @Component @Slf4j @@ -42,6 +43,8 @@ public class FTPUtil { //声明FTP客户端 FTPClient ftp = new FTPClient(); try { + // 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单 + ftp.enterLocalPassiveMode(); //连接 ftp.connect(host, port); //登录 @@ -101,9 +104,12 @@ public class FTPUtil { public InputStream downloadFTPFile(String localPath, String fileName){ InputStream in = null; - FTPClient ftpClient = this.LoginFTP(); //传输模式 try { + FTPClient ftpClient = this.LoginFTP(); + if (Objects.isNull(ftpClient)){ + throw new RuntimeException("ftp连接失败!"); + } List paths = Arrays.asList(localPath.split("/")); if (CollectionUtils.isNotEmpty(paths)){ for (String workPath:paths) { @@ -111,11 +117,10 @@ public class FTPUtil { ftpClient.changeWorkingDirectory(workPath); } } + ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 ftpClient.setControlEncoding(encoding); - // 切换为本地被动模式,可以解决FTP上传后文件为空的问题,但需要服务器将FTP服务添加至防火墙白名单 -// ftp.enterLocalPassiveMode(); ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE); List ftpFiles = Arrays.asList(ftpClient.listFiles()); if (CollectionUtils.isNotEmpty(ftpFiles)){ diff --git a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java index 21a15d09..69050723 100644 --- a/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java +++ b/jeecg-module-log-manage/src/main/java/org/jeecg/modules/controller/LogManageController.java @@ -35,11 +35,12 @@ public class LogManageController { List result = new ArrayList<>(); try { FTPClient ftpClient = ftpUtil.LoginFTP(); - //切换工作文件路径 - ftpClient.changeWorkingDirectory(workPath); if(Objects.isNull(ftpClient)){ throw new RuntimeException("ftp连接失败!"); } + //切换工作文件路径 + ftpClient.changeWorkingDirectory(workPath); + ftpClient.enterLocalPassiveMode(); List ftpFiles = Arrays.asList(ftpClient.listDirectories()); if (CollectionUtils.isNotEmpty(ftpFiles)){ int num =1; @@ -122,6 +123,7 @@ public class LogManageController { ftpClient.changeWorkingDirectory(workPath); } } + ftpClient.enterLocalPassiveMode(); List ftpFiles = Arrays.asList(ftpClient.listFiles()); if (CollectionUtils.isNotEmpty(ftpFiles)){ for (FTPFile ftpFile:ftpFiles) { diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysTaskStationService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysTaskStationService.java index a08ce1c6..98bb915f 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysTaskStationService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysTaskStationService.java @@ -7,8 +7,8 @@ import java.util.List; public interface ISysTaskStationService extends IService { - void create(String taskId, List taskStations); + void create(String taskId, String ipAddr, List taskStations); - void updateStation(String taskId, List stationList); + void updateStation(String taskId, String ipAddr, List stationList); } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskServiceImpl.java index 7d62eedd..0e5474d9 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskServiceImpl.java @@ -175,16 +175,28 @@ public class SysTaskServiceImpl extends ServiceImpl impl @Transactional public Result create(List sysTasks){ Result result = new Result(); + //获取request + HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); + //获取当前操作人用户名 + String username = JwtUtil.getUserNameByToken(request); + //设置IP地址 + String ipAddr = IpUtils.getIpAddr(request); //如果新增排班任务不为空 if (CollectionUtils.isNotEmpty(sysTasks)){ //遍历排班任务进行存储 for (SysTask sysTask:sysTasks) { + //操作人 + sysTask.setCreateBy(username); + //操作人的ip + sysTask.setOperateIp(ipAddr); //id sysTask.setId(String.valueOf(IdWorker.getId())); + //创建时间 + sysTask.setCreateTime(new Date()); this.baseMapper.insert(sysTask); //如果排班任务中台站信息不为空 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 impl @Transactional public Result update(List sysTasks) { Result result = new Result(); + //获取request + HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); + //获取当前操作人用户名 + String username = JwtUtil.getUserNameByToken(request); + //设置IP地址 + String ipAddr = IpUtils.getIpAddr(request); //如果新增排班任务不为空 if (CollectionUtils.isNotEmpty(sysTasks)){ //获取第一个排班任务的信息 @@ -204,12 +222,18 @@ public class SysTaskServiceImpl extends ServiceImpl impl this.deleteByDate(task.getSchedulingDate()); //遍历排班任务进行存储 for (SysTask sysTask:sysTasks) { + //操作人 + sysTask.setCreateBy(username); + //操作人的ip + sysTask.setOperateIp(ipAddr); //id sysTask.setId(String.valueOf(IdWorker.getId())); + //创建时间 + sysTask.setCreateTime(new Date()); this.baseMapper.insert(sysTask); //如果排班任务中台站信息不为空 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 impl } @Override + @Transactional public ImportViewVo importExcel(List dataList, int headRow) { ImportViewVo importViewVo = new ImportViewVo(); //获取用户信息 List userList = sysUserMapper.selectList(new LambdaQueryWrapper<>()); //获取台站信息 List stationsList = gardsStationsService.getGardsStations(); + //获取排班任务信息 + List sysTaskList = this.baseMapper.selectList(new LambdaQueryWrapper()); //存储排班任务信息 List taskList = new ArrayList<>(); //导入失败的结果集 @@ -467,10 +494,7 @@ public class SysTaskServiceImpl extends ServiceImpl impl } //判断当前数据库中的排班任务信息是否为空 if (CollectionUtils.isNotEmpty(taskList)){ - //遍历可以新增的数据信息 - for (SysTask sysTask:taskList) { - this.addOrUpdate(sysTask); - } + this.addOrUpdate(sysTaskList,taskList); } } } catch (ParseException e) { @@ -482,25 +506,37 @@ public class SysTaskServiceImpl extends ServiceImpl impl return importViewVo; } - private void addOrUpdate(SysTask sysTask){ - //根据用户名称及排班日期查询对应的数据 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysTask::getUserId, sysTask.getUserId()); - queryWrapper.eq(SysTask::getSchedulingDate, sysTask.getSchedulingDate()); - SysTask task = this.baseMapper.selectOne(queryWrapper); - //如果查询到的内容不为空,则进行修改 - if (Objects.nonNull(task)){ - List stationList = sysTask.getStationList(); - if (CollectionUtils.isNotEmpty(stationList)){ - sysTaskStationService.updateStation(task.getId(), stationList); - } - }else {//如果查询的内容为空,则进行新增 - //id - sysTask.setId(String.valueOf(IdWorker.getId())); - this.baseMapper.insert(sysTask); - //如果排班任务中台站信息不为空 - if (CollectionUtils.isNotEmpty(sysTask.getStationList())){ - sysTaskStationService.create(sysTask.getId(), sysTask.getStationList()); + private void addOrUpdate(List sysTaskList,List taskList){ + //获取request + HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); + //获取当前操作人用户名 + String username = JwtUtil.getUserNameByToken(request); + //设置IP地址 + String ipAddr = IpUtils.getIpAddr(request); + for (SysTask sysTask:taskList) { + List tasks = sysTaskList.stream() + .filter(item -> item.getUserId().equals(sysTask.getUserId()) && item.getSchedulingDate().equals(sysTask.getSchedulingDate())).collect(Collectors.toList()); + //如果查询到的内容不为空,则进行修改 + if (CollectionUtils.isNotEmpty(tasks)){ + SysTask task = tasks.get(0); + List stationList = sysTask.getStationList(); + if (CollectionUtils.isNotEmpty(stationList)){ + sysTaskStationService.updateStation(task.getId(), ipAddr, stationList); + } + }else {//如果查询的内容为空,则进行新增 + //操作人 + sysTask.setCreateBy(username); + //操作人的ip + sysTask.setOperateIp(ipAddr); + //id + sysTask.setId(String.valueOf(IdWorker.getId())); + //创建时间 + sysTask.setCreateTime(new Date()); + this.baseMapper.insert(sysTask); + //如果排班任务中台站信息不为空 + if (CollectionUtils.isNotEmpty(sysTask.getStationList())){ + sysTaskStationService.create(sysTask.getId(), ipAddr, sysTask.getStationList()); + } } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskStationServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskStationServiceImpl.java index 03b1cd58..48ae9f91 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskStationServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysTaskStationServiceImpl.java @@ -18,11 +18,12 @@ public class SysTaskStationServiceImpl extends ServiceImpl taskStations) { + public void create(String taskId, String ipAddr, List taskStations) { for (SysTaskStation sysTaskStation:taskStations) { if (StringUtils.isBlank(sysTaskStation.getStationId())){ throw new RuntimeException("台站信息不能为空"); } + sysTaskStation.setOperateIp(ipAddr); sysTaskStation.setId(String.valueOf(IdWorker.getId())); sysTaskStation.setTaskId(taskId); this.baseMapper.insert(sysTaskStation); @@ -30,7 +31,8 @@ public class SysTaskStationServiceImpl extends ServiceImpl stationList) { + @Transactional + public void updateStation(String taskId, String ipAddr, List stationList) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(SysTaskStation::getTaskId, taskId); this.baseMapper.delete(queryWrapper); @@ -38,6 +40,7 @@ public class SysTaskStationServiceImpl extends ServiceImpl