feat: 增加类型的属性点表的接口
parent
bc12a598d6
commit
27345fcecf
@ -0,0 +1,46 @@
|
||||
package com.xydl.cac.controller;
|
||||
|
||||
import com.xydl.cac.entity.ModevTypePoint;
|
||||
import com.xydl.cac.model.Response;
|
||||
import com.xydl.cac.service.ModevTypePointService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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("modevtypepoint")
|
||||
@Slf4j
|
||||
public class ModevTypePointController extends BasicController {
|
||||
|
||||
@Resource
|
||||
ModevTypePointService service;
|
||||
|
||||
@GetMapping("listAll")
|
||||
@ApiOperation("查询列表")
|
||||
public Response<List<ModevTypePoint>> listAll(Integer modevtypeId) {
|
||||
List<ModevTypePoint> result = service.listAll(modevtypeId);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation("新增")
|
||||
public Response<ModevTypePoint> add(@Validated @RequestBody ModevTypePoint item) throws Exception {
|
||||
ModevTypePoint result = service.add(item);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation("删除")
|
||||
public Response<String> delete(@Validated @NotNull(message = "ID不能为空!") Integer id) {
|
||||
service.delete(id);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
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 java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "modevtype_point")
|
||||
@ApiModel("监测设备类型属性点表")
|
||||
public class ModevTypePoint {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("监测设备类型表id")
|
||||
@Column(name = "modevtype_id")
|
||||
private Integer modevtypeId;
|
||||
|
||||
@ApiModelProperty("对应tablename表的字段名")
|
||||
@Column(name = "field")
|
||||
private String field;
|
||||
|
||||
@ApiModelProperty("对应tablename表的字段名称描述")
|
||||
@Column(name = "field_desc")
|
||||
private String fieldDesc;
|
||||
|
||||
@Transient
|
||||
private String unit;
|
||||
|
||||
@Transient
|
||||
private List<Object> data;
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.xydl.cac.repository;
|
||||
|
||||
import com.xydl.cac.entity.ModevTypePoint;
|
||||
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 ModevTypePointRepository extends JpaRepository<ModevTypePoint, Integer>, JpaSpecificationExecutor<ModevTypePoint> {
|
||||
|
||||
List<ModevTypePoint> findByModevtypeId(Integer modevtypeId);
|
||||
|
||||
List<ModevTypePoint> findByModevtypeIdAndField(Integer modevtypeId, String field);
|
||||
|
||||
void deleteByModevtypeId(Integer modevtypeId);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.xydl.cac.service;
|
||||
|
||||
import com.xydl.cac.entity.ModevTypePoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ModevTypePointService {
|
||||
|
||||
List<ModevTypePoint> listAll(Integer modevtypeId);
|
||||
|
||||
ModevTypePoint add(ModevTypePoint item) throws Exception;
|
||||
|
||||
void delete(Integer id);
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.xydl.cac.service.impl;
|
||||
|
||||
import com.xydl.cac.entity.ModevTypePoint;
|
||||
import com.xydl.cac.exception.BusinessException;
|
||||
import com.xydl.cac.repository.ModevTypePointRepository;
|
||||
import com.xydl.cac.service.ModevTypePointService;
|
||||
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;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ModevTypePointServiceImpl implements ModevTypePointService {
|
||||
|
||||
@Resource
|
||||
ModevTypePointRepository repository;
|
||||
|
||||
@Override
|
||||
public List<ModevTypePoint> listAll(Integer modevtypeId) {
|
||||
List<ModevTypePoint> list = repository.findByModevtypeId(modevtypeId);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModevTypePoint add(ModevTypePoint item) throws Exception {
|
||||
item.setId(null);
|
||||
List<ModevTypePoint> list = repository.findByModevtypeIdAndField(item.getModevtypeId(), item.getField());
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
throw new BusinessException("该监测装置类型的该字段已存在");
|
||||
}
|
||||
return repository.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Integer id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue