新增监测装置类型表 增删改查
parent
e686bf09ed
commit
f5f58d39e2
@ -0,0 +1,72 @@
|
|||||||
|
package com.xydl.cac.controller;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
import com.xydl.cac.model.Response;
|
||||||
|
import com.xydl.cac.service.ModevTypeService;
|
||||||
|
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("modevtype")
|
||||||
|
@Slf4j
|
||||||
|
public class ModevTypeController extends BasicController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ModevTypeService service;
|
||||||
|
|
||||||
|
@GetMapping("listAll")
|
||||||
|
@ApiOperation("查询列表")
|
||||||
|
public Response<List<ModevType>> listAll(Integer bdzid) {
|
||||||
|
try {
|
||||||
|
List<ModevType> result = service.listAll(bdzid);
|
||||||
|
return Response.success(result);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("add")
|
||||||
|
@ApiOperation("新增")
|
||||||
|
public Response<ModevType> add(@Validated @RequestBody ModevType item) {
|
||||||
|
try {
|
||||||
|
ModevType 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 ModevType 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不能为空!") Integer id) {
|
||||||
|
try {
|
||||||
|
service.delete(id);
|
||||||
|
return Response.success("OK");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return Response.fail(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.xydl.cac.entity;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "modevtype")
|
||||||
|
@ApiModel("监测装置类型表")
|
||||||
|
public class ModevType {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotEmpty(message = "名称不能为空")
|
||||||
|
@Column(name = "mc")
|
||||||
|
private String mc;
|
||||||
|
|
||||||
|
@NotEmpty(message = "表名不能为空")
|
||||||
|
@Column(name = "tablename")
|
||||||
|
private String tablename;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
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 ModevTypeRepository extends JpaRepository<ModevType, Integer>, JpaSpecificationExecutor<ModevType> {
|
||||||
|
List<ModevType> findByMc(String mc);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ModevTypeService {
|
||||||
|
|
||||||
|
List<ModevType> listAll(Integer modevtypeid);
|
||||||
|
|
||||||
|
ModevType add(ModevType item) throws Exception;
|
||||||
|
|
||||||
|
void update(ModevType item) throws Exception;
|
||||||
|
|
||||||
|
void delete(Integer id);
|
||||||
|
|
||||||
|
ModevType detail(Integer id) throws Exception;
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.ModevType;
|
||||||
|
import com.xydl.cac.repository.ModevTypeRepository;
|
||||||
|
import com.xydl.cac.service.ModevTypeService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class ModevTypeServiceImpl implements ModevTypeService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ModevTypeRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModevType> listAll(Integer modevtypeid) {
|
||||||
|
return repository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModevType add(ModevType item) throws Exception {
|
||||||
|
item.setId(null);
|
||||||
|
List<ModevType> byMc = repository.findByMc(item.getMc());
|
||||||
|
if (!byMc.isEmpty()) {
|
||||||
|
throw new Exception("该监测装置类型已存在");
|
||||||
|
}
|
||||||
|
return repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(ModevType item) throws Exception {
|
||||||
|
List<ModevType> byMc = repository.findByMc(item.getMc());
|
||||||
|
if (!byMc.isEmpty()) {
|
||||||
|
throw new Exception("该监测装置类型已存在");
|
||||||
|
}
|
||||||
|
repository.save(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Integer id) {
|
||||||
|
repository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModevType detail(Integer id) throws Exception {
|
||||||
|
Optional<ModevType> optional = repository.findById(id);
|
||||||
|
if (!optional.isPresent()) {
|
||||||
|
throw new Exception("未找到该类型");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue