From 7b1c9d178464c3c5d63413136b1e630619aa0cc5 Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Wed, 24 May 2023 09:08:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat=EF=BC=9A=E6=8E=92=E7=8F=AD=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E6=96=B0=E5=A2=9E=E5=8F=8A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ISysTaskStationService.java | 4 +- .../service/impl/SysTaskServiceImpl.java | 86 +++++++++++++------ .../impl/SysTaskStationServiceImpl.java | 7 +- 3 files changed, 68 insertions(+), 29 deletions(-) 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 Date: Thu, 25 May 2023 10:23:50 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat=EF=BC=9A=E6=97=A5=E5=BF=97=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=99=BB=E5=BD=95=E4=BB=A5=E5=8F=8A=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/jeecg/common/util/FTPUtil.java | 10 +++++++--- .../jeecg/modules/controller/LogManageController.java | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) 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..07246b27 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) { @@ -114,8 +120,6 @@ public class FTPUtil { 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..bb69914b 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,11 @@ 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); List ftpFiles = Arrays.asList(ftpClient.listDirectories()); if (CollectionUtils.isNotEmpty(ftpFiles)){ int num =1; From 1ff408dcb625c34035abb0199df2fca22c8d5d8d Mon Sep 17 00:00:00 2001 From: qiaoqinzheng Date: Thu, 25 May 2023 11:21:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat=EF=BC=9A=E6=97=A5=E5=BF=97=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=88=87=E6=8D=A2=E5=B7=A5=E4=BD=9C=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=90=8E=E8=AE=BE=E7=BD=AE=E8=A2=AB=E5=8A=A8=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/jeecg/common/util/FTPUtil.java | 1 + .../java/org/jeecg/modules/controller/LogManageController.java | 2 ++ 2 files changed, 3 insertions(+) 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 07246b27..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 @@ -117,6 +117,7 @@ public class FTPUtil { ftpClient.changeWorkingDirectory(workPath); } } + ftpClient.enterLocalPassiveMode(); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); // 设置编码,当文件中存在中文且上传后文件乱码时可使用此配置项 ftpClient.setControlEncoding(encoding); 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 bb69914b..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 @@ -40,6 +40,7 @@ public class LogManageController { } //切换工作文件路径 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) {