fix(algorithm):修改算法方案新增和修改逻辑
因为修改平面图,但是没有删除之前保存的图片,这里做了修改
This commit is contained in:
parent
ef7c1c9e9d
commit
a3fa17bdb1
@ -20,6 +20,8 @@ import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmClassComponent;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmClassComponentService;
|
||||
import com.yfd.platform.modules.basedata.domain.SubstationPatroldevice;
|
||||
import com.yfd.platform.modules.basedata.service.impl.SubstationPatroldeviceServiceImpl;
|
||||
import com.yfd.platform.modules.patroltask.domain.TaskTodo;
|
||||
@ -32,6 +34,7 @@ import com.yfd.platform.system.mapper.QuartzJobMapper;
|
||||
import com.yfd.platform.utils.HttpRESTfulUtils;
|
||||
import com.yfd.platform.utils.QuartzManage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
@ -40,6 +43,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -47,7 +51,6 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @date 2019-01-07
|
||||
*/
|
||||
@Component
|
||||
@ -64,6 +67,7 @@ public class JobRunner implements ApplicationRunner {
|
||||
private final HttpRESTfulUtils httpUtil;
|
||||
private final HttpServerConfig config;
|
||||
private final IPlatformParentSystemService platformParentSystemService;
|
||||
private final IAlgorithmClassComponentService algorithmClassComponentService;
|
||||
|
||||
/**
|
||||
* 项目启动时重新激活启用的定时任务
|
||||
@ -71,7 +75,7 @@ public class JobRunner implements ApplicationRunner {
|
||||
* @param applicationArguments /
|
||||
*/
|
||||
@Override
|
||||
public void run(ApplicationArguments applicationArguments) {
|
||||
public void run(ApplicationArguments applicationArguments) throws ParseException {
|
||||
|
||||
log.info("--------------------注入系统定时任务---------------------");
|
||||
List<QuartzJob> quartzJobs =
|
||||
@ -91,11 +95,19 @@ public class JobRunner implements ApplicationRunner {
|
||||
log.info("--------------------自启动上级系统注册---------------------");
|
||||
List<PlatformParentSystem> list =
|
||||
platformParentSystemService.list(new LambdaQueryWrapper<PlatformParentSystem>().eq(PlatformParentSystem::getIsEnable, "1"));
|
||||
if (list != null && list.size() > 0) {
|
||||
if (list != null && !list.isEmpty()) {
|
||||
PlatformParentSystem platformParentSystem = list.get(0);
|
||||
platformParentSystemService.sendRegisterToSuper(platformParentSystem.getId());
|
||||
}
|
||||
|
||||
log.info("--------------------自启动算法任务---------------------");
|
||||
// List<AlgorithmClassComponent> classComponents =
|
||||
// algorithmClassComponentService.list(new LambdaQueryWrapper<AlgorithmClassComponent>().eq(AlgorithmClassComponent::getIsenable, "1"));
|
||||
// if (classComponents != null && !classComponents.isEmpty()) {
|
||||
// for (AlgorithmClassComponent classComponent : classComponents) {
|
||||
// algorithmClassComponentService.createAlgorithmTaskList(classComponent);
|
||||
// }
|
||||
// }
|
||||
log.info("--------------------自启动算法任务完成---------------------");
|
||||
log.info("--------------------自启动上级系统注册完成---------------------");
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeDeviceService;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService;
|
||||
import com.yfd.platform.modules.basedata.domain.Substation;
|
||||
import com.yfd.platform.modules.basedata.service.ISubstationService;
|
||||
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
||||
import com.yfd.platform.utils.FileUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
@ -62,6 +63,8 @@ public class AlgorithmArrangeController {
|
||||
@Resource
|
||||
private ISysDictionaryItemsService sysDictionaryItemsService;
|
||||
@Resource
|
||||
private ISubstationService substationService;
|
||||
@Resource
|
||||
private HttpServerConfig httpServerConfig;
|
||||
|
||||
@GetMapping("/getAlgorithmArrangePage")
|
||||
@ -112,6 +115,11 @@ public class AlgorithmArrangeController {
|
||||
return ResponseResult.error("文件上传失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(algorithmArrange.getStationId())) {
|
||||
Substation substation = substationService.getById(algorithmArrange.getStationId());
|
||||
algorithmArrange.setStationName(substation.getStationName());
|
||||
algorithmArrange.setStationCode(substation.getStationCode());
|
||||
}
|
||||
boolean save = algorithmArrangeService.save(algorithmArrange);
|
||||
if (!save) {
|
||||
return ResponseResult.error();
|
||||
@ -151,6 +159,11 @@ public class AlgorithmArrangeController {
|
||||
algorithmArrange.setLastmodifydate(LocalDateTime.now());
|
||||
// 文件上传逻辑
|
||||
if (file != null && !file.isEmpty()) {
|
||||
String id = algorithmArrange.getId();
|
||||
AlgorithmArrange arrange = algorithmArrangeService.getById(id);
|
||||
if (StrUtil.isNotBlank(arrange.getImageUrl())) {
|
||||
algorithmArrangeService.removeImage(httpServerConfig.getPlanFilePath() + arrange.getImageUrl());
|
||||
}
|
||||
try {
|
||||
// 调用服务层方法
|
||||
String fileUrl = algorithmArrangeService.uploadImage(file);
|
||||
@ -160,6 +173,11 @@ public class AlgorithmArrangeController {
|
||||
return ResponseResult.error("文件上传失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(algorithmArrange.getStationId())) {
|
||||
Substation substation = substationService.getById(algorithmArrange.getStationId());
|
||||
algorithmArrange.setStationName(substation.getStationName());
|
||||
algorithmArrange.setStationCode(substation.getStationCode());
|
||||
}
|
||||
boolean save = algorithmArrangeService.updateById(algorithmArrange);
|
||||
if (!save) {
|
||||
return ResponseResult.error();
|
||||
|
@ -27,4 +27,6 @@ public interface IAlgorithmArrangeService extends IService<AlgorithmArrange> {
|
||||
* 返回值说明: java.lang.String
|
||||
***********************************/
|
||||
String uploadImage(MultipartFile file);
|
||||
|
||||
boolean removeImage(String filePath);
|
||||
}
|
||||
|
@ -32,8 +32,19 @@ public interface IAlgorithmClassComponentService extends IService<AlgorithmClass
|
||||
***********************************/
|
||||
boolean deleteAlgorithmClassComponent(String id);
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 批量新增算法关联主设备部件
|
||||
* 参数说明 algorithmClassComponentList
|
||||
* 返回值说明: boolean
|
||||
***********************************/
|
||||
boolean batchAddAlgorithmClassComponent(List<AlgorithmClassComponent> algorithmClassComponentList);
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 设置算法关联主设备部件状态
|
||||
* 参数说明 id 算法部件id
|
||||
* 参数说明 isenable 状态
|
||||
* 返回值说明: boolean
|
||||
***********************************/
|
||||
boolean setAlgorithmClassComponentStatus(String id, String isenable) throws ParseException;
|
||||
|
||||
boolean createAlgorithmTaskList(AlgorithmClassComponent algorithmClassComponent) throws ParseException;
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.yfd.platform.config.HttpServerConfig;
|
||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange;
|
||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrangeDevice;
|
||||
@ -22,6 +23,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -130,6 +135,24 @@ public class AlgorithmArrangeServiceImpl extends ServiceImpl<AlgorithmArrangeMap
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeImage(String filePath) {
|
||||
Path path = Paths.get(filePath);
|
||||
try {
|
||||
if (Files.exists(path)) {
|
||||
Files.deleteIfExists(path);
|
||||
log.info("文件删除成功: {}", filePath);
|
||||
return true;
|
||||
} else {
|
||||
log.warn("文件不存在,跳过删除: {}", filePath);
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("删除文件 {} 时发生异常", filePath, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************
|
||||
* 用途说明: 转换方法
|
||||
* 参数说明 originalList 原始列表
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.yfd.platform.modules.algorithm.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@ -12,16 +11,12 @@ import com.yfd.platform.modules.algorithm.domain.AlgorithmDevice;
|
||||
import com.yfd.platform.modules.algorithm.mapper.AlgorithmClassComponentMapper;
|
||||
import com.yfd.platform.modules.algorithm.mapper.AlgorithmDeviceMapper;
|
||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmClassComponentService;
|
||||
import com.yfd.platform.modules.patroltask.domain.TaskTodo;
|
||||
import com.yfd.platform.utils.CronScheduleUtils;
|
||||
import org.quartz.CronExpression;
|
||||
import org.quartz.TriggerUtils;
|
||||
import org.quartz.impl.triggers.CronTriggerImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -79,11 +74,22 @@ public class AlgorithmClassComponentServiceImpl extends ServiceImpl<AlgorithmCla
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 批量新增算法关联主设备部件
|
||||
* 参数说明 algorithmClassComponentList
|
||||
* 返回值说明: boolean
|
||||
***********************************/
|
||||
@Override
|
||||
public boolean batchAddAlgorithmClassComponent(List<AlgorithmClassComponent> algorithmClassComponentList) {
|
||||
return this.saveOrUpdateBatch(algorithmClassComponentList);
|
||||
}
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 设置算法关联主设备部件状态
|
||||
* 参数说明 id 算法部件id
|
||||
* 参数说明 isenable 状态
|
||||
* 返回值说明: boolean
|
||||
***********************************/
|
||||
@Override
|
||||
public boolean setAlgorithmClassComponentStatus(String id, String isenable) throws ParseException {
|
||||
AlgorithmClassComponent algorithmClassComponent = this.getById(id);
|
||||
@ -115,6 +121,11 @@ public class AlgorithmClassComponentServiceImpl extends ServiceImpl<AlgorithmCla
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************
|
||||
* 用途说明: 根据cron表达式设置定时任务
|
||||
* 参数说明 algorithmClassComponent
|
||||
* 返回值说明: boolean
|
||||
***********************************/
|
||||
@Override
|
||||
public boolean createAlgorithmTaskList(AlgorithmClassComponent algorithmClassComponent) throws ParseException {
|
||||
// 判断cron表达式有效性
|
||||
|
Loading…
Reference in New Issue
Block a user