feat: 增加61850下载配置操作功能
parent
bd05b58dc4
commit
a4c0d7be24
@ -0,0 +1,82 @@
|
||||
package com.xydl.cac.controller;
|
||||
|
||||
import com.xydl.cac.entity.IedDlConfig;
|
||||
import com.xydl.cac.entity.IedDlRecord;
|
||||
import com.xydl.cac.entity.RemoteConfig;
|
||||
import com.xydl.cac.entity.RemoteDownload;
|
||||
import com.xydl.cac.exception.BusinessException;
|
||||
import com.xydl.cac.model.Response;
|
||||
import com.xydl.cac.service.IedDlConfigService;
|
||||
import com.xydl.cac.service.IedDlRecordService;
|
||||
import com.xydl.cac.service.RemoteConfigService;
|
||||
import com.xydl.cac.service.RemoteDownloadService;
|
||||
import com.xydl.cac.util.SFTPTool;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Api(tags = {"61850下载文件相关接口"})
|
||||
@RequestMapping("ieddl")
|
||||
@Slf4j
|
||||
public class IedDlController extends BasicController {
|
||||
|
||||
@Resource
|
||||
IedDlConfigService configService;
|
||||
@Resource
|
||||
IedDlRecordService recordService;
|
||||
|
||||
@GetMapping("listAll")
|
||||
@ApiOperation("查询全部列表")
|
||||
public Response<List<IedDlConfig>> listAll() {
|
||||
List<IedDlConfig> result = configService.listAll();
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation("新增")
|
||||
public Response<IedDlConfig> add(@Validated @RequestBody IedDlConfig item) throws Exception {
|
||||
IedDlConfig result = configService.add(item);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation("更新")
|
||||
public Response<String> update(@Validated @RequestBody IedDlConfig item) throws Exception {
|
||||
if (item.getId() == null) {
|
||||
throw new BusinessException("id不能为空!");
|
||||
}
|
||||
configService.update(item);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation("删除")
|
||||
public Response<String> delete(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
|
||||
if (id == null) {
|
||||
throw new BusinessException("id不能为空!");
|
||||
}
|
||||
configService.delete(id);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
@GetMapping("listDownload")
|
||||
@ApiOperation("查询下载记录列表")
|
||||
public Response<Page<IedDlRecord>> list(@ApiParam("类型") @RequestParam(value = "configId", required = false) Integer configId,
|
||||
@ApiParam("页码") @RequestParam(value = "pageNum", required = false) Integer pageNum,
|
||||
@ApiParam("每页数量") @RequestParam(value = "pageSize", required = false) Integer pageSize) throws Exception {
|
||||
pageNum = this.initPageNum(pageNum);
|
||||
pageSize = this.initPageSize(pageSize);
|
||||
Page<IedDlRecord> result = recordService.list(configId, pageNum, pageSize);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.xydl.cac.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "ied_dl_config")
|
||||
@ApiModel("61850装置文件下载配置表")
|
||||
public class IedDlConfig {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@NotNull(message = "iedId不能为空")
|
||||
@ApiModelProperty("iedId")
|
||||
@Column(name = "ied_id")
|
||||
private Integer iedId;
|
||||
|
||||
@NotNull(message = "devId不能为空")
|
||||
@ApiModelProperty("devId")
|
||||
@Column(name = "dev_id")
|
||||
private Integer devId;
|
||||
|
||||
@ApiModelProperty("目录")
|
||||
@Column(name = "path")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("后缀名")
|
||||
@Column(name = "suffix")
|
||||
private String suffix;
|
||||
|
||||
@NotNull(message = "是否删除不能为空")
|
||||
@ApiModelProperty("下载后是否删除")
|
||||
@Column(name = "todel")
|
||||
private Integer todel;
|
||||
|
||||
@NotNull(message = "状态不能为空")
|
||||
@ApiModelProperty("状态 0:停用 1:启用")
|
||||
@Column(name = "active")
|
||||
private Integer active;
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.xydl.cac.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "ied_dl_record")
|
||||
@ApiModel("61850装置文件下载记录表")
|
||||
public class IedDlRecord {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("configId")
|
||||
@Column(name = "config_id")
|
||||
private Integer configId;
|
||||
|
||||
@ApiModelProperty("路径")
|
||||
@Column(name = "path")
|
||||
private String path;
|
||||
|
||||
@ApiModelProperty("文件名")
|
||||
@Column(name = "filename")
|
||||
private String filename;
|
||||
|
||||
@ApiModelProperty("创建时间")
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.xydl.cac.repository;
|
||||
|
||||
import com.xydl.cac.entity.IedDlConfig;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface IedDlConfigRepository extends JpaRepository<IedDlConfig, Integer>, JpaSpecificationExecutor<IedDlConfig> {
|
||||
|
||||
List<IedDlConfig> findByDevId(Integer devId);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.xydl.cac.repository;
|
||||
|
||||
import com.xydl.cac.entity.IedDlRecord;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface IedDlRecordRepository extends JpaRepository<IedDlRecord, Integer>, JpaSpecificationExecutor<IedDlRecord> {
|
||||
|
||||
List<IedDlRecord> findByConfigId(Integer configId);
|
||||
|
||||
List<IedDlRecord> findByConfigIdAndFilename(Integer configId, String filename);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.xydl.cac.service;
|
||||
|
||||
import com.xydl.cac.entity.IedDlConfig;
|
||||
import com.xydl.cac.exception.BusinessException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IedDlConfigService {
|
||||
|
||||
List<IedDlConfig> listAll();
|
||||
|
||||
IedDlConfig get(Integer id) throws BusinessException;
|
||||
|
||||
IedDlConfig add(IedDlConfig item) throws Exception;
|
||||
|
||||
void update(IedDlConfig item) throws Exception;
|
||||
|
||||
void delete(Integer id);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.xydl.cac.service;
|
||||
|
||||
import com.xydl.cac.entity.IedDlRecord;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
public interface IedDlRecordService {
|
||||
|
||||
Page<IedDlRecord> list(Integer configId, int pageNum, int pageSize) throws Exception;
|
||||
|
||||
void add(IedDlRecord item);
|
||||
|
||||
boolean exist(IedDlRecord item);
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.xydl.cac.service.impl;
|
||||
|
||||
import com.xydl.cac.entity.IedDlConfig;
|
||||
import com.xydl.cac.exception.BusinessException;
|
||||
import com.xydl.cac.repository.IedDlConfigRepository;
|
||||
import com.xydl.cac.service.IedDlConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class IedDlConfigServiceImpl implements IedDlConfigService {
|
||||
|
||||
@Resource
|
||||
IedDlConfigRepository repository;
|
||||
|
||||
@Override
|
||||
public List<IedDlConfig> listAll() {
|
||||
List<IedDlConfig> list = repository.findAll();
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IedDlConfig get(Integer id) throws BusinessException {
|
||||
Optional<IedDlConfig> optional = repository.findById(id);
|
||||
if (!optional.isPresent()) {
|
||||
throw new BusinessException("未找到该记录");
|
||||
}
|
||||
return optional.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IedDlConfig add(IedDlConfig item) throws Exception {
|
||||
List<IedDlConfig> list = repository.findByDevId(item.getDevId());
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
throw new BusinessException("已存在该devId的配置");
|
||||
}
|
||||
item.setId(null);
|
||||
return repository.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(IedDlConfig item) throws Exception {
|
||||
repository.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Integer id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.xydl.cac.service.impl;
|
||||
|
||||
import com.xydl.cac.entity.IedDlRecord;
|
||||
import com.xydl.cac.repository.IedDlRecordRepository;
|
||||
import com.xydl.cac.service.IedDlRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class IedDlRecordServiceImpl implements IedDlRecordService {
|
||||
|
||||
@Resource
|
||||
IedDlRecordRepository repository;
|
||||
|
||||
@Override
|
||||
public Page<IedDlRecord> list(Integer configId, int pageNum, int pageSize) throws Exception {
|
||||
PageRequest request = PageRequest.of(pageNum - 1, pageSize);
|
||||
Specification<IedDlRecord> specification = (root, query, builder) -> {
|
||||
Predicate predicate = builder.conjunction();
|
||||
if (configId != null) {
|
||||
predicate.getExpressions().add(builder.equal(root.get("configId"), configId));
|
||||
}
|
||||
query.orderBy(builder.desc(root.get("id")));
|
||||
return predicate;
|
||||
};
|
||||
Page<IedDlRecord> result = repository.findAll(specification, request);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(IedDlRecord item) {
|
||||
item.setId(null);
|
||||
repository.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exist(IedDlRecord item) {
|
||||
List<IedDlRecord> list = repository.findByConfigIdAndFilename(item.getConfigId(), item.getFilename());
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue