126 lines
4.5 KiB
Java
126 lines
4.5 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.hsz.entity.so.PrePlacePageSo;
|
|
import com.gunshi.project.hsz.model.PrePlace;
|
|
import com.gunshi.project.hsz.model.PrePlaceDetail;
|
|
import com.gunshi.project.hsz.service.PrePlaceDetailService;
|
|
import com.gunshi.project.hsz.service.PrePlaceService;
|
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
|
import com.gunshi.project.hsz.validate.markers.Update;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
@Tag(name = "白蚁-防治点")
|
|
@RestController
|
|
@RequestMapping(value="/bypp")
|
|
public class PrePlaceController {
|
|
|
|
@Autowired
|
|
private PrePlaceService prePlaceService;
|
|
|
|
@Autowired
|
|
private PrePlaceDetailService prePlaceDetailService;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<PrePlace> insert(@Validated(Insert.class) @RequestBody PrePlace dto) {
|
|
dto.setId(IdWorker.getId());
|
|
dto.setCreateTime(new Date());
|
|
boolean result = prePlaceService.save(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<PrePlace> update(@Validated(Update.class) @RequestBody PrePlace dto) {
|
|
boolean result = prePlaceService.updateById(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
boolean b = prePlaceService.deleteById(id);
|
|
return R.ok(b);
|
|
}
|
|
|
|
@Operation(summary = "列表")
|
|
@GetMapping("/list")
|
|
public List<PrePlace> list() {
|
|
List<PrePlace> list = prePlaceService.lambdaQuery().orderByAsc(PrePlace::getCreateTime).list();
|
|
return list;
|
|
}
|
|
|
|
|
|
@Operation(summary = "防治部位新增")
|
|
@PostMapping("/detail/insert")
|
|
public R<PrePlaceDetail> detailInsert(@Validated(Insert.class) @RequestBody PrePlaceDetail dto) {
|
|
boolean result = prePlaceDetailService.saveData(dto);
|
|
return R.ok(result ? dto:null);
|
|
}
|
|
|
|
@Operation(summary = "防治部位修改")
|
|
@PostMapping("/detail/update")
|
|
public R<PrePlaceDetail> detailUpdate(@Validated(Update.class) @RequestBody PrePlaceDetail dto) {
|
|
boolean result = prePlaceDetailService.updateById(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "防治部位列表")
|
|
@GetMapping("/detail/list")
|
|
public List<PrePlaceDetail> detailList() {
|
|
List<PrePlaceDetail> list = prePlaceDetailService.lambdaQuery().orderByAsc(PrePlaceDetail::getOrder).list();
|
|
return list;
|
|
}
|
|
|
|
@Operation(summary = "防治部位列表")
|
|
@PostMapping("/detail/page")
|
|
public R<Page<PrePlaceDetail>> detailList(@RequestBody PrePlacePageSo pageSo) {
|
|
return R.ok(prePlaceDetailService.pageQuery(pageSo));
|
|
}
|
|
|
|
|
|
@Operation(summary = "防治部位删除")
|
|
@GetMapping("/detail/del/{id}")
|
|
public R<Boolean> detailDel(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
boolean b = prePlaceDetailService.removeById(id);
|
|
return R.ok(b);
|
|
}
|
|
|
|
@Operation(summary = "是否启用")
|
|
@GetMapping("/switch/{id}")
|
|
public R<Boolean> isEnable(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
PrePlaceDetail byId = prePlaceDetailService.getById(id);
|
|
if(byId == null) {
|
|
throw new RuntimeException("该数据不存在,请检查");
|
|
}
|
|
Integer isEnable = byId.getIsEnable();
|
|
if(isEnable > 0){
|
|
byId.setIsEnable(0);
|
|
}else{
|
|
byId.setIsEnable(1);
|
|
}
|
|
boolean result = prePlaceDetailService.updateById(byId);
|
|
return R.ok(result ? false : true);
|
|
}
|
|
|
|
//查询防治部位 (可根据 防治点查询,也可以根据防治部位查询)
|
|
@Operation(summary = "查询防治部位(可根据 防治点查询,也可以根据防治部位查询)")
|
|
@PostMapping("/tree")
|
|
public List<PrePlace> tree(@RequestBody PrePlacePageSo dto) {
|
|
List<PrePlace> res = prePlaceService.tree(dto);
|
|
return res;
|
|
}
|
|
}
|