perf: 调整iec104点表和增删接口

iec104
huangfeng 20 hours ago
parent 8fcafde6aa
commit f1aed43e7c

@ -0,0 +1,9 @@
CREATE TABLE `iec_104_point` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`eqmid` int(11) DEFAULT NULL,
`field` varchar(45) DEFAULT NULL,
`stype` varchar(45) DEFAULT NULL COMMENT '类型 1:遥信 2:遥测',
`sadr` int(11) DEFAULT NULL COMMENT '点位',
`create_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

@ -24,7 +24,7 @@ public class Iec104PointController extends BasicController {
Iec104PointService iec104PointService;
@GetMapping("list")
@ApiOperation("查询iec104列表")
@ApiOperation("查询104点表")
public Response<List<Iec104Point>> list() {
List<Iec104Point> result = iec104PointService.findAll();
return Response.success(result);
@ -32,24 +32,14 @@ public class Iec104PointController extends BasicController {
@PostMapping("add")
@ApiOperation("新增")
public Response<Iec104Point> add(@Validated @RequestBody Iec104Point iec104Point) {
public Response<Iec104Point> add(@Validated @RequestBody Iec104Point iec104Point) throws Exception {
Iec104Point add = iec104PointService.add(iec104Point);
return Response.success(add);
}
@PostMapping("update")
@ApiOperation("更新")
public Response<String> update(@Validated @RequestBody Iec104Point iec104Point) throws Exception {
if (iec104Point.getId() == null) {
throw new BusinessException("id不能为空!");
}
iec104PointService.update(iec104Point);
return Response.success("OK");
}
@PostMapping("del")
@ApiOperation("删除")
public Response<String> del(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
public Response<String> del(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
if (id == null) {
throw new BusinessException("id不能为空!");
}

@ -10,6 +10,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
@JsonInclude(JsonInclude.Include.NON_NULL)
@ -38,6 +39,7 @@ public class Iec104Point {
@Column(name = "stype")
private String stype;
@NotNull(message = "点位不能为空")
@ApiModelProperty("点位")
@Column(name = "sadr")
private Integer sadr;

@ -5,6 +5,9 @@ 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 Iec104PointRepository extends JpaRepository<Iec104Point, Integer>, JpaSpecificationExecutor<Iec104Point> {
List<Iec104Point> findBySadr(Integer sadr);
}

@ -1,6 +1,7 @@
package com.xydl.cac.service;
import com.xydl.cac.entity.Iec104Point;
import com.xydl.cac.exception.BusinessException;
import java.util.List;
@ -8,9 +9,7 @@ public interface Iec104PointService {
List<Iec104Point> findAll();
Iec104Point add(Iec104Point point);
void update(Iec104Point point);
Iec104Point add(Iec104Point point) throws BusinessException;
void delete(Integer id);

@ -1,14 +1,15 @@
package com.xydl.cac.service.impl;
import com.xydl.cac.entity.Iec104Point;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.repository.Iec104PointRepository;
import com.xydl.cac.service.Iec104PointService;
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.Collections;
import java.util.Date;
import java.util.List;
@ -26,15 +27,15 @@ public class Iec104PointServiceImpl implements Iec104PointService {
}
@Override
public Iec104Point add(Iec104Point point) {
point.setId(null);
point.setCreateTime(new Date());
return iec104PointRepository.save(point);
}
@Override
public void update(Iec104Point point) {
iec104PointRepository.save(point);
public Iec104Point add(Iec104Point point) throws BusinessException {
List<Iec104Point> list = iec104PointRepository.findBySadr(point.getSadr());
if (CollectionUtils.isEmpty(list)) {
point.setId(null);
point.setCreateTime(new Date());
return iec104PointRepository.save(point);
} else {
throw new BusinessException("该点位已存在");
}
}
@Override

Loading…
Cancel
Save