新增监测装置表 增删改查
parent
c9325d67d5
commit
bdd17d063b
@ -0,0 +1,86 @@
|
|||||||
|
package com.xydl.cac.controller;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Modev;
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
import com.xydl.cac.model.Response;
|
||||||
|
import com.xydl.cac.service.ModevService;
|
||||||
|
import com.xydl.cac.service.ModevTypeService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
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 = {"监测设备相关接口"})
|
||||||
|
@RequestMapping("modev")
|
||||||
|
@Slf4j
|
||||||
|
public class ModevController extends BasicController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ModevService service;
|
||||||
|
|
||||||
|
@GetMapping("listAll")
|
||||||
|
@ApiOperation("查询列表")
|
||||||
|
public Response<List<Modev>> listAll(@NotNull(message = "主设备编号不能缺少") @Param("bdzid") Integer bdzid) {
|
||||||
|
try {
|
||||||
|
List<Modev> result = service.listAll(bdzid);
|
||||||
|
return Response.success(result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("add")
|
||||||
|
@ApiOperation("新增")
|
||||||
|
public Response<Modev> add(@Validated @RequestBody Modev item) {
|
||||||
|
try {
|
||||||
|
Modev result = service.add(item);
|
||||||
|
return Response.success(result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("update")
|
||||||
|
@ApiOperation("更新")
|
||||||
|
public Response<String> update(@Validated @RequestBody Modev item) {
|
||||||
|
try {
|
||||||
|
if (item.getId() == null) {
|
||||||
|
throw new Exception("ID不能为空!");
|
||||||
|
}
|
||||||
|
service.update(item);
|
||||||
|
return Response.success("OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("delete")
|
||||||
|
@ApiOperation("删除")
|
||||||
|
public Response<String> delete(@Validated @NotNull(message = "ID不能为空!") @Param("id") Integer id) {
|
||||||
|
try {
|
||||||
|
service.delete(id);
|
||||||
|
return Response.success("OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("detail")
|
||||||
|
@ApiOperation("详情")
|
||||||
|
public Response<Modev> detail(@Validated @NotNull(message = "ID不能为空!") Integer id) {
|
||||||
|
try {
|
||||||
|
Modev detail = service.detail(id);
|
||||||
|
return Response.success(detail);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
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.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "modev")
|
||||||
|
@ApiModel("监测装置表")
|
||||||
|
public class Modev {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotEmpty(message = "名称不能为空")
|
||||||
|
@Column(name = "name")
|
||||||
|
@ApiModelProperty("监测设备名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotNull(message = "监测设备类型不能缺少")
|
||||||
|
@Column(name = "modevtid")
|
||||||
|
@ApiModelProperty("监测设备类型编号")
|
||||||
|
private Integer modevtid;
|
||||||
|
|
||||||
|
@Column(name = "address")
|
||||||
|
private Integer address;
|
||||||
|
|
||||||
|
@Column(name = "frequency")
|
||||||
|
private Integer frequency;
|
||||||
|
|
||||||
|
@Column(name = "portname")
|
||||||
|
private String portname;
|
||||||
|
|
||||||
|
@Column(name = "carelevel")
|
||||||
|
private Integer carelevel;
|
||||||
|
|
||||||
|
@Column(name = "zsbid")
|
||||||
|
@NotNull(message = "名称不能为空")
|
||||||
|
@ApiModelProperty("监测设备类型编号")
|
||||||
|
private Integer zsbid;
|
||||||
|
|
||||||
|
@Column(name = "iedid")
|
||||||
|
private Integer iedid;
|
||||||
|
|
||||||
|
@Column(name = "equipmentmodel")
|
||||||
|
private String equipmentmodel;
|
||||||
|
|
||||||
|
@Column(name = "manufacture")
|
||||||
|
private String manufacture;
|
||||||
|
|
||||||
|
@Column(name = "factoryint")
|
||||||
|
private String factoryint;
|
||||||
|
|
||||||
|
@Column(name = "manufacturedate")
|
||||||
|
private Date manufacturedate;
|
||||||
|
|
||||||
|
@Column(name = "rundate")
|
||||||
|
private Date rundate;
|
||||||
|
|
||||||
|
@Column(name = "location")
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
@Column(name = "note")
|
||||||
|
private String note;
|
||||||
|
|
||||||
|
@Column(name = "znxjdevid")
|
||||||
|
private String znxjdevid;
|
||||||
|
|
||||||
|
@Column(name = "ip")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Column(name = "username")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Column(name = "pwd")
|
||||||
|
private String pwd;
|
||||||
|
|
||||||
|
@Column(name = "port")
|
||||||
|
private String port;
|
||||||
|
|
||||||
|
@Column(name = "npresetid")
|
||||||
|
private Integer npresetid;
|
||||||
|
|
||||||
|
@Column(name = "nruleid")
|
||||||
|
private Integer nruleid;
|
||||||
|
|
||||||
|
@Column(name = "nmetertype")
|
||||||
|
private Integer nmetertype;
|
||||||
|
|
||||||
|
@Column(name = "mainEid")
|
||||||
|
private Integer mainEid;
|
||||||
|
|
||||||
|
@Column(name = "secondEid")
|
||||||
|
private Integer secondEid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Modev;
|
||||||
|
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 ModevRepository extends JpaRepository<Modev, Integer>, JpaSpecificationExecutor<Modev> {
|
||||||
|
List<Modev> findByZsbid(Integer zsbid);
|
||||||
|
List<Modev> findByZsbidAndName(Integer zsbid,String name);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Modev;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ModevService {
|
||||||
|
|
||||||
|
List<Modev> listAll(Integer modevtypeid);
|
||||||
|
|
||||||
|
Modev add(Modev item) throws Exception;
|
||||||
|
|
||||||
|
void update(Modev item) throws Exception;
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
Modev detail(Integer id) throws Exception;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Modev;
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
import com.xydl.cac.repository.ModevRepository;
|
||||||
|
import com.xydl.cac.service.ModevService;
|
||||||
|
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 ModevServiceImpl implements ModevService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ModevRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Modev> listAll(Integer zsbid) {
|
||||||
|
return repository.findByZsbid(zsbid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Modev add(Modev item) throws Exception {
|
||||||
|
item.setId(null);
|
||||||
|
List<Modev> byZsbidAndName = repository.findByZsbidAndName(item.getZsbid(), item.getName());
|
||||||
|
if (!CollectionUtils.isEmpty(byZsbidAndName)) {
|
||||||
|
throw new Exception("该监测装置已存在");
|
||||||
|
}
|
||||||
|
return repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Modev item) throws Exception {
|
||||||
|
List<Modev> byMc = repository.findByZsbidAndName(item.getZsbid(), item.getName());
|
||||||
|
if (!CollectionUtils.isEmpty(byMc)) {
|
||||||
|
for (Modev it : byMc) {
|
||||||
|
if (it.getId() != item.getId()) {
|
||||||
|
throw new Exception("该监测装置类型已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Modev detail(Integer id) throws Exception {
|
||||||
|
Optional<Modev> optional = repository.findById(id);
|
||||||
|
if (!optional.isPresent()) {
|
||||||
|
throw new Exception("未找到该类型");
|
||||||
|
}
|
||||||
|
return optional.get();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue