133 lines
4.9 KiB
Java
133 lines
4.9 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.hsz.entity.so.TermiteSurveyPageSo;
|
|
import com.gunshi.project.hsz.model.TermiteSurvey;
|
|
import com.gunshi.project.hsz.model.TermiteSurveyDetail;
|
|
import com.gunshi.project.hsz.service.TermiteSurveyDetailService;
|
|
import com.gunshi.project.hsz.service.TermiteSurveyService;
|
|
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.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 描述: 白蚁普查
|
|
* author: xusan
|
|
* date: 2024-08-28 10:29:58
|
|
*/
|
|
@Tag(name = "白蚁普查")
|
|
@RestController
|
|
@RequestMapping(value="/termite/survey")
|
|
public class TermiteSurveyController extends AbstractCommonFileController{
|
|
|
|
@Autowired
|
|
private TermiteSurveyService service;
|
|
@Autowired
|
|
private TermiteSurveyDetailService termiteSurveyDetailService;
|
|
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<TermiteSurvey> insert(@Validated(Insert.class) @RequestBody TermiteSurvey dto) {
|
|
return R.ok(service.saveData(dto));
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<TermiteSurvey> update(@Validated(Update.class) @RequestBody TermiteSurvey dto) {
|
|
return R.ok(service.updateData(dto));
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Long id) {
|
|
return R.ok(service.delData(id));
|
|
}
|
|
|
|
@Operation(summary = "详情")
|
|
@GetMapping("/detail/{id}")
|
|
public R<TermiteSurvey> detail(@Schema(name = "id") @PathVariable("id") Long id) {
|
|
return R.ok(service.detail(id));
|
|
}
|
|
|
|
@Operation(summary = "分页")
|
|
@PostMapping("/page")
|
|
public R<Page<TermiteSurvey>> page(@RequestBody @Validated TermiteSurveyPageSo page) {
|
|
return R.ok(service.pageQuery(page));
|
|
}
|
|
|
|
@Operation(summary = "分页")
|
|
@PostMapping("/pageDetail")
|
|
public R<Page<TermiteSurveyDetail>> pageDetail(@RequestBody @Validated TermiteSurveyPageSo page) {
|
|
return R.ok(termiteSurveyDetailService.pageQuery(page));
|
|
}
|
|
|
|
@Operation(summary = "统计")
|
|
@PostMapping("/count")
|
|
public R<Map<String,Long>> count(@RequestBody @Validated TermiteSurveyPageSo page) {
|
|
page.getPageSo().setPageSize(1000000);
|
|
Page<TermiteSurveyDetail> termiteSurveyPage = termiteSurveyDetailService.pageQuery(page);
|
|
List<TermiteSurveyDetail> records = termiteSurveyPage.getRecords();
|
|
Map<String,Long> countMap = new HashMap<>();
|
|
countMap.put("totalPoint",0l);
|
|
countMap.put("hasAnt",0l);
|
|
countMap.put("notAnt",0l);
|
|
countMap.put("noData",0l);
|
|
if(CollectionUtils.isEmpty(records)){
|
|
return R.ok(countMap);
|
|
}
|
|
|
|
page.getPageSo().setPageSize(1000000);
|
|
page.setPileNumber(null);
|
|
page.setSearchDate(null);
|
|
Page<TermiteSurveyDetail> totalPage = termiteSurveyDetailService.pageQuery(page);
|
|
|
|
if(CollectionUtils.isNotEmpty(totalPage.getRecords())){
|
|
//所有点 去除空的
|
|
long pileNumberCount = totalPage.getRecords().stream()
|
|
//.map(TermiteSurveyDetail::getPileNumber).filter(e -> StringUtils.isNotEmpty(e))
|
|
.collect(Collectors.toSet()).stream().count();
|
|
countMap.put("totalPoint", pileNumberCount);
|
|
}
|
|
|
|
|
|
//有危害 && 未处置
|
|
long harmNumCount = records.stream()
|
|
.filter(e-> Objects.nonNull(e.getIsHarm()) && Objects.nonNull(e.getIsHandle())
|
|
&& e.getIsHarm().intValue() > 0 && e.getIsHandle().intValue()!=1).count();
|
|
countMap.put("hasAnt", harmNumCount);
|
|
|
|
//无危害 || (有危害&& 以处置)
|
|
long handleNummCount = records.stream()
|
|
.filter(e-> Objects.nonNull(e.getIsHarm()) && Objects.nonNull(e.getIsHandle())
|
|
&& (e.getIsHarm().intValue() == 0 || e.getIsHarm().intValue() > 0 && e.getIsHandle().intValue()==1)).count();
|
|
|
|
countMap.put("notAnt", handleNummCount);
|
|
|
|
//无数据
|
|
long count = records.stream().filter(e -> Objects.isNull(e.getIsHandle()) || e.getIsHandle().intValue() == 0).count();
|
|
countMap.put("noData",count);
|
|
|
|
return R.ok(countMap);
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
public String getGroupId() {
|
|
return "termiteSurvey";
|
|
}
|
|
} |