feat: 增加按区域统计装置数量

dev
huangfeng 1 year ago
parent 574881f87a
commit 45a9d262c9

@ -30,6 +30,13 @@ public class JgController extends BasicController {
return Response.success(result);
}
@GetMapping("sensorCount")
@ApiOperation("查询监测装置数量")
public Response<List<Jg>> sensorCount(Integer bdzid) {
List<Jg> result = service.sensorCount(bdzid);
return Response.success(result);
}
@PostMapping("add")
@ApiOperation("新增")
public Response<Jg> add(@Validated @RequestBody Jg item) throws Exception {

@ -30,10 +30,10 @@ public class ModevTypeController extends BasicController {
return Response.success(result);
}
@GetMapping("listAllCount")
@ApiOperation("查询数量列表")
public Response<List<ModevType>> listAllCount() {
List<ModevType> result = service.listAllCount();
@GetMapping("sensorCount")
@ApiOperation("查询监测装置数量")
public Response<List<ModevType>> sensorCount() {
List<ModevType> result = service.sensorCount();
return Response.success(result);
}

@ -56,6 +56,9 @@ public class Jg {
@Transient
private String bdzName;
@Transient
private long sensorCount;
@Transient
private List<Zsb> children;

@ -8,6 +8,8 @@ public interface JgService {
List<Jg> listAll(Integer bdzid);
List<Jg> sensorCount(Integer bdzid);
Jg add(Jg item) throws Exception;
void update(Jg item) throws Exception;

@ -8,7 +8,7 @@ public interface ModevTypeService {
List<ModevType> listAll();
List<ModevType> listAllCount();
List<ModevType> sensorCount();
ModevType add(ModevType item) throws Exception;

@ -6,6 +6,7 @@ import com.xydl.cac.entity.Zsb;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.repository.BdzRepository;
import com.xydl.cac.repository.JgRepository;
import com.xydl.cac.repository.NSensorRepository;
import com.xydl.cac.repository.ZsbRepository;
import com.xydl.cac.service.JgService;
import com.xydl.cac.task.CacheTask;
@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -29,6 +31,8 @@ public class JgServiceImpl implements JgService {
BdzRepository bdzRepository;
@Resource
ZsbRepository zsbRepository;
@Resource
NSensorRepository sensorRepository;
@Override
public List<Jg> listAll(Integer bdzid) {
@ -50,6 +54,38 @@ public class JgServiceImpl implements JgService {
}
}
@Override
public List<Jg> sensorCount(Integer bdzid) {
List<Jg> result;
if (bdzid == null) {
if (CacheTask.jg_Cache == null) {
CacheTask.jg_Cache = repository.findAll();
this.fillBdzName(CacheTask.jg_Cache);
}
result = CacheTask.jg_Cache;
} else {
result = repository.findByBdzid(bdzid);
Optional<Bdz> optional = bdzRepository.findById(bdzid);
if (optional.isPresent() && !CollectionUtils.isEmpty(result)) {
for (Jg jg : result) {
jg.setBdzName(optional.get().getMc());
}
}
}
for (Jg jg : result) {
List<Zsb> zsbList = zsbRepository.findByJgid(jg.getId());
List<Integer> idList = new ArrayList<>();
for (Zsb zsb : zsbList) {
idList.add(zsb.getId());
}
if (idList.size() > 0) {
long count = sensorRepository.countByZsbIdIn(idList);
jg.setSensorCount(count);
}
}
return result;
}
private void fillBdzName(List<Jg> list) {
List<Bdz> bdzList = bdzRepository.findAll();
if (!CollectionUtils.isEmpty(list) && !CollectionUtils.isEmpty(bdzList)) {

@ -38,7 +38,7 @@ public class ModevTypeServiceImpl implements ModevTypeService {
}
@Override
public List<ModevType> listAllCount() {
public List<ModevType> sensorCount() {
List<ModevType> list = this.listAll();
for (ModevType modevType : list) {
long count = sensorRepository.countByTypeId(modevType.getId());

Loading…
Cancel
Save