白蚁:防治点-防治部位
parent
9dff6cb59e
commit
01558a76ae
|
|
@ -0,0 +1,125 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.gunshi.project.hsz.entity.so;
|
||||
|
||||
import com.gunshi.db.dto.PageSo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.bouncycastle.cert.dane.DANEEntry;
|
||||
|
||||
@Data
|
||||
public class PrePlacePageSo {
|
||||
|
||||
|
||||
@NotNull(message = "分页参数不能为空")
|
||||
@Schema(description = "分页参数")
|
||||
private PageSo pageSo;
|
||||
|
||||
private String preId;
|
||||
|
||||
private String preName;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.gunshi.project.hsz.entity.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.gunshi.project.hsz.model.PrePlaceDetail;
|
||||
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||
import com.gunshi.project.hsz.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PrePlaceTreeVo {
|
||||
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long preId;
|
||||
|
||||
private String preName;
|
||||
|
||||
|
||||
private List<PrePlaceDetail> details;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.gunshi.project.hsz.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.hsz.model.PrePlaceDetail;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Mapper
|
||||
public interface PrePlaceDetailMapper extends BaseMapper<PrePlaceDetail> {
|
||||
|
||||
|
||||
@Select("""
|
||||
select count(*) from pre_place_detail t where t.pre_id = #{id}
|
||||
""")
|
||||
int selectByPreId(@Param("id") Serializable id);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.gunshi.project.hsz.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.hsz.entity.so.PrePlacePageSo;
|
||||
import com.gunshi.project.hsz.entity.vo.PrePlaceTreeVo;
|
||||
import com.gunshi.project.hsz.model.PrePlace;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PrePlaceMapper extends BaseMapper<PrePlace> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.gunshi.project.hsz.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||
import com.gunshi.project.hsz.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@TableName(value = "pre_place")
|
||||
public class PrePlace {
|
||||
|
||||
@TableId(value = "id")
|
||||
@Schema(description = "主键")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
|
||||
@TableField(value = "pre_name")
|
||||
@NotNull(message = "防治点不能为空", groups = {Insert.class, Update.class})
|
||||
private String preName;
|
||||
|
||||
@TableField(value = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<PrePlaceDetail> childrens;
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.gunshi.project.hsz.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import com.gunshi.project.hsz.validate.markers.Insert;
|
||||
import com.gunshi.project.hsz.validate.markers.Update;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName(value = "pre_place_detail")
|
||||
public class PrePlaceDetail {
|
||||
|
||||
@TableId(value = "id")
|
||||
@NotNull(message = "主键ID不能为空",groups = Update.class)
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "detail_name")
|
||||
@Schema(description = "防治部位")
|
||||
@NotNull(message = "防治部位不能为空", groups = {Insert.class, Update.class})
|
||||
private String detailName;
|
||||
|
||||
@TableField(value = "pre_id")
|
||||
@Schema(description = "防治点id")
|
||||
@NotNull(message = "防治点不能为空",groups = {Insert.class, Update.class})
|
||||
private Long preId;
|
||||
|
||||
@TableField(value = "remark")
|
||||
@Schema(description = "详细描述")
|
||||
private String remark;
|
||||
|
||||
@TableField(value = "_order")
|
||||
@Schema(description = "排序号")
|
||||
private Integer order;
|
||||
|
||||
@TableField(value = "is_enable")
|
||||
@Schema(description = "是否启用 0启用 1禁用")
|
||||
private Integer isEnable;
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.gunshi.project.hsz.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.hsz.entity.so.PrePlacePageSo;
|
||||
import com.gunshi.project.hsz.mapper.PrePlaceDetailMapper;
|
||||
import com.gunshi.project.hsz.mapper.PrePlaceMapper;
|
||||
import com.gunshi.project.hsz.model.PrePlace;
|
||||
import com.gunshi.project.hsz.model.PrePlaceDetail;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class PrePlaceDetailService extends ServiceImpl<PrePlaceDetailMapper, PrePlaceDetail> {
|
||||
|
||||
@Autowired
|
||||
private PrePlaceMapper prePlaceMapper;
|
||||
|
||||
public Page<PrePlaceDetail> pageQuery(PrePlacePageSo pageSo) {
|
||||
if(StringUtils.isBlank(pageSo.getPreId())) {
|
||||
throw new RuntimeException("请选择防治点");
|
||||
}
|
||||
LambdaQueryWrapper<PrePlaceDetail> query = new LambdaQueryWrapper<>();
|
||||
query.eq(PrePlaceDetail::getPreId, pageSo.getPreId());
|
||||
Page<PrePlaceDetail> prePlaceDetailPage = this.baseMapper.selectPage(pageSo.getPageSo().toPage(), query);
|
||||
return prePlaceDetailPage;
|
||||
}
|
||||
|
||||
public boolean saveData(PrePlaceDetail dto) {
|
||||
dto.setId(IdWorker.getId());
|
||||
dto.setIsEnable(0);
|
||||
Long preId = dto.getPreId();
|
||||
PrePlace prePlace = prePlaceMapper.selectById(preId);
|
||||
if(prePlace == null) {
|
||||
throw new RuntimeException("防治点不存在,请检查");
|
||||
}
|
||||
boolean save = save(dto);
|
||||
return save;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.gunshi.project.hsz.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.hsz.entity.so.PrePlacePageSo;
|
||||
import com.gunshi.project.hsz.entity.vo.PrePlaceTreeVo;
|
||||
import com.gunshi.project.hsz.mapper.PrePlaceDetailMapper;
|
||||
import com.gunshi.project.hsz.mapper.PrePlaceMapper;
|
||||
import com.gunshi.project.hsz.model.PrePlace;
|
||||
import com.gunshi.project.hsz.model.PrePlaceDetail;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class PrePlaceService extends ServiceImpl<PrePlaceMapper, PrePlace> {
|
||||
|
||||
@Autowired
|
||||
private PrePlaceDetailMapper prePlaceDetailMapper;
|
||||
|
||||
@Autowired
|
||||
private PrePlaceMapper prePlaceMapper;
|
||||
|
||||
public boolean deleteById(Serializable id) {
|
||||
//先查看细节表还有数据没
|
||||
int count = prePlaceDetailMapper.selectByPreId(id);
|
||||
if(count > 0){
|
||||
throw new RuntimeException("该防治点,还有防治部位未删,请检查");
|
||||
}
|
||||
boolean res = deleteById(id);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public List<PrePlace> tree(PrePlacePageSo dto) {
|
||||
LambdaQueryWrapper<PrePlace> wrapper = new LambdaQueryWrapper<>();
|
||||
if(!StringUtils.isBlank(dto.getPreId())){
|
||||
wrapper.eq(PrePlace::getId, dto.getPreId());
|
||||
}
|
||||
List<PrePlace> prePlaces = prePlaceMapper.selectList(wrapper);
|
||||
Iterator<PrePlace> iterator = prePlaces.iterator();
|
||||
while(iterator.hasNext()){
|
||||
PrePlace prePlace = iterator.next();
|
||||
LambdaQueryWrapper<PrePlaceDetail> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if(!StringUtils.isBlank(dto.getPreName())){
|
||||
queryWrapper.like(PrePlaceDetail::getDetailName, dto.getPreName());
|
||||
}
|
||||
List<PrePlaceDetail> prePlaceDetails = prePlaceDetailMapper.selectList(queryWrapper);
|
||||
if(prePlaceDetails.isEmpty() || !prePlaceDetails.get(0).getPreId().equals(prePlace.getId())){
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
prePlace.setChildrens(prePlaceDetails);
|
||||
}
|
||||
return prePlaces;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.gunshi.project.hsz.mapper.PrePlaceMapper">
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue