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.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<String> 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<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
if (CollectionUtils.isNotEmpty(ftpFiles)){

View File

@ -35,11 +35,12 @@ public class LogManageController {
List<LogManage> 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<FTPFile> 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<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
if (CollectionUtils.isNotEmpty(ftpFiles)){
for (FTPFile ftpFile:ftpFiles) {

View File

@ -7,8 +7,8 @@ import java.util.List;
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
public Result create(List<SysTask> 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<SysTaskMapper, SysTask> impl
@Transactional
public Result update(List<SysTask> 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<SysTaskMapper, SysTask> 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<SysTaskMapper, SysTask> impl
}
@Override
@Transactional
public ImportViewVo importExcel(List<SysTaskExportVo> dataList, int headRow) {
ImportViewVo importViewVo = new ImportViewVo();
//获取用户信息
List<SysUser> userList = sysUserMapper.selectList(new LambdaQueryWrapper<>());
//获取台站信息
List<GardsStations> stationsList = gardsStationsService.getGardsStations();
//获取排班任务信息
List<SysTask> sysTaskList = this.baseMapper.selectList(new LambdaQueryWrapper<SysTask>());
//存储排班任务信息
List<SysTask> taskList = new ArrayList<>();
//导入失败的结果集
@ -467,10 +494,7 @@ public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask> 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<SysTaskMapper, SysTask> impl
return importViewVo;
}
private void addOrUpdate(SysTask sysTask){
//根据用户名称及排班日期查询对应的数据
LambdaQueryWrapper<SysTask> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysTask::getUserId, sysTask.getUserId());
queryWrapper.eq(SysTask::getSchedulingDate, sysTask.getSchedulingDate());
SysTask task = this.baseMapper.selectOne(queryWrapper);
private void addOrUpdate(List<SysTask> sysTaskList,List<SysTask> taskList){
//获取request
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
//获取当前操作人用户名
String username = JwtUtil.getUserNameByToken(request);
//设置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();
if (CollectionUtils.isNotEmpty(stationList)){
sysTaskStationService.updateStation(task.getId(), 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(), sysTask.getStationList());
sysTaskStationService.create(sysTask.getId(), ipAddr, sysTask.getStationList());
}
}
}

View File

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