Merge branch 'iec61850' of http://61.169.135.146:8081/git/cac/backend into iec61850

iec104
郭承 8 months ago
commit 5aaf229240

@ -21,7 +21,7 @@ import java.util.Map;
@Slf4j
public class BusiAdapter {
@Value("${cac.i2.enable}")
@Value("${cac.i2.enable:false}")
public boolean enable;
@Value("${cac.i2.url}")
public String url;

@ -34,12 +34,12 @@ public class IcdConfigController extends BasicController {
DataService dataService;
@PostMapping("upload")
@ApiOperation("处理icd文件")
@ApiOperation("上传客户端icd文件")
public Response<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file != null && file.getInputStream() != null) {
String filename = file.getOriginalFilename();
String content = IOUtils.toString(file.getInputStream(), Charset.forName("UTF-8"));
configService.upload(content, filename);
configService.upload(content, filename, 0);
return Response.success("OK");
} else {
return Response.fail("缺少上传文件");
@ -47,9 +47,9 @@ public class IcdConfigController extends BasicController {
}
@GetMapping("listFile")
@ApiOperation("查询icd文件列表")
@ApiOperation("查询客户端icd文件列表")
public Response<List<IcdFile>> listFile() throws Exception {
List<IcdFile> result = configService.listFile();
List<IcdFile> result = configService.listFile(0);
for (IcdFile file : result) {
file.setXml(null);
}
@ -57,7 +57,7 @@ public class IcdConfigController extends BasicController {
}
@GetMapping("listIed")
@ApiOperation("查询icd文件的IED列表")
@ApiOperation("查询客户端icd文件的IED列表")
public Response<List<IcdIed>> listIed() throws Exception {
List<IcdIed> result = configService.listIed();
return Response.success(result);

@ -1,21 +1,24 @@
package com.xydl.cac.controller;
import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.iec.IecServerService;
import com.xydl.cac.iec.RealTimeDataService;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.IcdFileConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
@RestController
@Api(tags = {"Iec服务端接口"})
@ -23,11 +26,36 @@ import java.util.HashMap;
@Slf4j
public class IecServerController extends BasicController {
@Resource
IcdFileConfigService configService;
@Resource
IecServerService iecServerService;
@Resource
RealTimeDataService realTimeDataService;
@PostMapping("upload")
@ApiOperation("上传服务端icd文件")
public Response<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file != null && file.getInputStream() != null) {
String filename = file.getOriginalFilename();
String content = IOUtils.toString(file.getInputStream(), Charset.forName("UTF-8"));
configService.upload(content, filename, 1);
return Response.success("OK");
} else {
return Response.fail("缺少上传文件");
}
}
@GetMapping("listFile")
@ApiOperation("查询服务端icd文件列表")
public Response<List<IcdFile>> listFile() throws Exception {
List<IcdFile> result = configService.listFile(1);
for (IcdFile file : result) {
file.setXml(null);
}
return Response.success(result);
}
@PostMapping("start")
@ApiOperation("启动IEC服务端")
public Response<String> start(@Validated @NotNull(message = "fileId不能为空!") Integer fileId) throws Exception {

@ -38,6 +38,14 @@ public class IcdFile {
@Column(name = "xml")
private String xml;
@ApiModelProperty(name = "是否服务端")
@Column(name = "srv")
private Integer srv;
@ApiModelProperty(name = "是否启动")
@Column(name = "start")
private Integer start;
@Transient
private List<IcdConfigType> configList;
@Transient

@ -41,4 +41,8 @@ public class IcdIed {
@Column(name = "name")
private String name;
@ApiModelProperty(name = "是否启动")
@Column(name = "start")
private Integer start;
}

@ -1,6 +1,7 @@
package com.xydl.cac.iec;
import com.xydl.cac.entity.IcdFile;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.repository.IcdFileRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -19,18 +20,22 @@ public class IecServerService {
IecServer iecServer = new IecServer();
public void startServer(Integer fileId) {
public void startServer(Integer fileId) throws BusinessException {
Optional<IcdFile> optional = fileRepository.findById(fileId);
if (optional.isPresent()) {
IcdFile icdFile = optional.get();
try {
iecServer.start(icdFile.getXml(), 102);
iecServer.filename = icdFile.getFilename();
iecServer.fileId = icdFile.getId();
RealTimeDataService.iecServer = iecServer;
} catch (Exception e) {
log.error("启动IEC61850服务端异常.", e);
}
if (!optional.isPresent()) {
throw new BusinessException("未找到该文件");
}
IcdFile icdFile = optional.get();
if (icdFile.getSrv() != 1) {
throw new BusinessException("该文件不是服务端文件");
}
try {
iecServer.start(icdFile.getXml(), 102);
iecServer.filename = icdFile.getFilename();
iecServer.fileId = icdFile.getId();
RealTimeDataService.iecServer = iecServer;
} catch (Exception e) {
log.error("启动IEC61850服务端异常.", e);
}
}

@ -11,5 +11,9 @@ import java.util.List;
@Repository
public interface IcdFileRepository extends JpaRepository<IcdFile, Integer>, JpaSpecificationExecutor<IcdFile> {
List<IcdFile> findByMd5(String md5);
List<IcdFile> findByMd5AndSrv(String md5, Integer srv);
List<IcdFile> findBySrv(Integer srv);
List<IcdFile> findBySrvAndStart(Integer srv, Integer start);
}

@ -9,9 +9,9 @@ import java.util.List;
public interface IcdFileConfigService {
void upload(String xml, String filename) throws Exception;
void upload(String xml, String filename, int srv) throws Exception;
List<IcdFile> listFile();
List<IcdFile> listFile(int srv);
List<IcdIed> listIed();

@ -41,9 +41,9 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
DataService dataService;
@Override
public void upload(String xml, String filename) throws Exception {
public void upload(String xml, String filename, int srv) throws Exception {
String md5 = Md5.getMD5Code(xml);
List<IcdFile> files = fileRepository.findByMd5(md5);
List<IcdFile> files = fileRepository.findByMd5AndSrv(md5, srv);
if (!CollectionUtils.isEmpty(files)) {
throw new BusinessException("该文件已存在");
}
@ -51,9 +51,15 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
IcdFile icdFile = IcdXmlUtil.loadIcdType(xml);
icdFile.setMd5(md5);
icdFile.setFilename(filename);
icdFile.setSrv(srv);
icdFile.setStart(0);
fileRepository.save(icdFile);
if (srv == 1) {
return;
}
for (IcdIed ied : icdFile.getIedList()) {
ied.setIcdFileId(icdFile.getId());
ied.setStart(0);
iedRepository.save(ied);
}
for (IcdConfigType config : icdFile.getConfigList()) {
@ -85,15 +91,15 @@ public class IcdFileConfigServiceImpl implements IcdFileConfigService {
}
@Override
public List<IcdFile> listFile() {
List<IcdFile> files = fileRepository.findAll();
public List<IcdFile> listFile(int srv) {
List<IcdFile> files = fileRepository.findBySrv(srv);
return files;
}
@Override
public List<IcdIed> listIed() {
List<IcdIed> result = new ArrayList<>();
List<IcdFile> icdFileList = fileRepository.findAll();
List<IcdFile> icdFileList = fileRepository.findBySrv(0);
if (CollectionUtils.isEmpty(icdFileList)) {
return result;
}

@ -4,6 +4,7 @@ import com.xydl.cac.entity.*;
import com.xydl.cac.repository.*;
import com.xydl.cac.service.ModevTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -17,6 +18,8 @@ import java.util.List;
@Slf4j
public class Client61850Task {
@Value("${cac.iec.enable:true}")
public boolean enable;
@Resource
AsyncTask asyncTask;
@Resource
@ -32,6 +35,9 @@ public class Client61850Task {
@Scheduled(cron = "0 * * * * ?")
public void collectAll() {
if (!enable) {
return;
}
Calendar cal = Calendar.getInstance();
int h = cal.get(Calendar.HOUR_OF_DAY);
int m = cal.get(Calendar.MINUTE);

@ -20,7 +20,7 @@ import java.net.URLEncoder;
@Slf4j
public class DingTalkPushUtil {
@Value("${cac.dingding.send}")
@Value("${cac.dingding.send:false}")
private boolean send;
@Value("${cac.dingding.token}")
private String token;

@ -31,6 +31,8 @@ spring:
cac:
datapath: /home/xydl/ncac/data
iec:
enable: true
i2:
enable: false
url: http://192.168.1.190:8080/busi-back-ws/service/XydlService

@ -31,6 +31,8 @@ spring:
cac:
datapath: /home/xydl/ncac/data
iec:
enable: true
i2:
enable: false
url: http://192.168.1.190:8080/busi-back-ws/service/XydlService

Loading…
Cancel
Save