新增统计
This commit is contained in:
parent
c7d310271d
commit
2346b115a6
@ -155,7 +155,7 @@ public class CountController extends AbstractController {
|
||||
})
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@GetMapping("counthiddendangerreportdetail/{year}")
|
||||
public SuccessResultData<Map<String, Object>> countHiddenDangerReportDetail(@PathVariable("year") String year) {
|
||||
public SuccessResultData<Map<String, Object>> countHiddenDangerReportDetail(@PathVariable("year") String year) throws Exception {
|
||||
return countService.countHiddenDangerReportDetail(year);
|
||||
}
|
||||
|
||||
|
@ -71,5 +71,5 @@ public interface ICountService {
|
||||
* @return
|
||||
* @throws SearchException
|
||||
*/
|
||||
SuccessResultData<Map<String, Object>> countHiddenDangerReportDetail(String year) throws SearchException;
|
||||
SuccessResultData<Map<String, Object>> countHiddenDangerReportDetail(String year) throws Exception;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -228,23 +229,26 @@ public class CountServiceImpl extends BaseService implements ICountService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuccessResultData<Map<String, Object>> countHiddenDangerReportDetail(String year) throws SearchException {
|
||||
public SuccessResultData<Map<String, Object>> countHiddenDangerReportDetail(String year) throws Exception {
|
||||
LOG.debug("获取三级区域");
|
||||
List<DataDictionaryDTO> areaDTOs = dataDictionaryService.listDictionaryByParentId("3f62e230-47a5-4ad9-ab01-08fd2c5218d8");
|
||||
// 获取检查项列表
|
||||
List<CheckItemDTO> checkItemDTOs = listCheckItemDTO();
|
||||
// 检查项详细列表
|
||||
List<CheckItemOptionDTO> checkItemOptionDTOs = listCheckItemOptionDTO();
|
||||
// 组合检查项
|
||||
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
// 检查结果
|
||||
List<Map<String, Object>> listCheckItemOptionArea = new ArrayList<>();
|
||||
for (DataDictionaryDTO areaDTO : areaDTOs) {
|
||||
Map<String, Object> resultListMap = getHashMap(3);
|
||||
resultListMap.put("areaName", areaDTO.getDictionaryName());
|
||||
Map<String, Object> areaMap = getHashMap(4);
|
||||
areaMap.put("areaName", areaDTO.getDictionaryName());
|
||||
// 网格员的Id列表
|
||||
List<String> userIdList = listGridPersonnelUserId(areaDTO.getDictionaryId());
|
||||
// 网格员的所有上报项
|
||||
List<HiddenDangerReportDTO> listHiddenDangerReport = hiddenDangerReportService.listHiddenDangerReportSimpleByUserIdsYear(userIdList, year);
|
||||
// 遍历所有的检查项
|
||||
List<Map<String, Object>> listCheckItemOption = new ArrayList<>();
|
||||
for (CheckItemOptionDTO checkItemOptionDTO : checkItemOptionDTOs) {
|
||||
Map<String, Object> checkItemOptionMap = HashMapUtil.beanToMap(checkItemOptionDTO);
|
||||
int checkCount = 0;
|
||||
for (HiddenDangerReportDTO hiddenDangerReportDTO : listHiddenDangerReport) {
|
||||
// 检查项相同
|
||||
@ -253,43 +257,138 @@ public class CountServiceImpl extends BaseService implements ICountService {
|
||||
checkCount++;
|
||||
}
|
||||
}
|
||||
Map<String, Object> checkItemOptionMap = HashMapUtil.beanToMap(checkItemOptionDTO);
|
||||
checkItemOptionMap.put("checkCount", checkCount);
|
||||
listCheckItemOption.add(checkItemOptionMap);
|
||||
}
|
||||
areaMap.put("listCheckItemOption", listCheckItemOption);
|
||||
listCheckItemOptionArea.add(areaMap);
|
||||
}
|
||||
return null;
|
||||
// 封装结果
|
||||
// 构建检查项列表
|
||||
List<Map<String, Object>> checkItemList = buildCheckItem(checkItemDTOs);
|
||||
// 检查详细结果加入地区的结果列表
|
||||
List<Map<String, Object>> checkItemOptionList = buildCheckItemOptionArea(checkItemOptionDTOs, listCheckItemOptionArea);
|
||||
// 构建检查项详细列表,检查项、检查详细项合并
|
||||
buildCheckItemAndCheckItemOption(checkItemList, checkItemOptionList);
|
||||
|
||||
// 返回结果
|
||||
Map<String, Object> result = getHashMap(4);
|
||||
result.put("year", year);
|
||||
result.put("checkItemList", checkItemList);
|
||||
return new SuccessResultData<>(result);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> listCheckItem(List<CheckItemDTO> checkItemDTOs) throws Exception {
|
||||
List<Map<String, Object>> checkItemMapList = new ArrayList<>();
|
||||
if (checkItemDTOs) {
|
||||
return checkItemMapList;
|
||||
}
|
||||
// 处理一级选项
|
||||
for (CheckItemDTO checkItemDTO : checkItemDTOs) {
|
||||
if (checkItemDTO.getCheckItemParentId() == null || checkItemDTO.getCheckItemParentId() == 0) {
|
||||
checkItemMapList.add(HashMapUtil.beanToMap(checkItemDTO));
|
||||
}
|
||||
}
|
||||
// 处理二级选项
|
||||
for (Map<String, Object> checkItemMap : checkItemMapList) {
|
||||
List<Map<String, Object>> subCheckItemList = new ArrayList<>();
|
||||
for (CheckItemDTO checkItemDTO : checkItemDTOs) {
|
||||
if (StringUtils.equals(checkItemMap.get("checkItemId").toString(), checkItemDTO.getCheckItemParentId())) {
|
||||
subCheckItemList.add(HashMapUtil.beanToMap(checkItemDTO));
|
||||
/**
|
||||
* 构建检查结果到检查项中
|
||||
*
|
||||
* @param checkItemList
|
||||
* @param checkItemOptionList
|
||||
*/
|
||||
private void buildCheckItemAndCheckItemOption(List<Map<String, Object>> checkItemList, List<Map<String, Object>> checkItemOptionList) {
|
||||
for (Map<String, Object> checkItem : checkItemList) {
|
||||
List<Map<String, Object>> checkItemOptions = new ArrayList<>();
|
||||
for (int i = 0; i < checkItemOptionList.size(); i++) {
|
||||
Map<String, Object> checkItemOption = checkItemOptionList.get(i);
|
||||
if (StringUtils.equals(checkItem.get("checkItemId").toString(), checkItemOption.get("checkItemId").toString())) {
|
||||
checkItemOptions.add(checkItemOption);
|
||||
checkItemOptionList.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
// 处理选项
|
||||
List<Map<String, Object>> subCheckItem = (List<Map<String, Object>>) checkItem.get("subCheckItem");
|
||||
if (subCheckItem != null && !subCheckItem.isEmpty()) {
|
||||
buildCheckItemAndCheckItemOption(subCheckItem, checkItemOptionList);
|
||||
}
|
||||
checkItem.put("checkItemOptions", checkItemOptions);
|
||||
}
|
||||
}
|
||||
|
||||
private void buildCheckItem(List<CheckItemDTO> checkItemDTOs) {
|
||||
List<Map<String, Object>> checkItemMapList = new ArrayList<>();
|
||||
for (CheckItemDTO checkItemDTO : checkItemDTOs) {
|
||||
if (checkItemDTO.getCheckItemParentId() == null || StringUtils.equals(checkItemDTO.getCheckItemParentId(), "0")) {
|
||||
/**
|
||||
* 构建具体的检查项结果,将地区的检查结果根据检查项的不同重新构建;
|
||||
* 比如说,原来的结果是地区1下面的各个检查总数的统计,
|
||||
* 现在将其转换为每一个检查结果下,地区的总数统计。
|
||||
* <p>
|
||||
* 格式如下所示:option1中包含了[{area1: 0}, {area2: 0}]数组
|
||||
* <p>
|
||||
* | | area1 | area2 | area3 | area4 | area5 |
|
||||
* | option1 | 0 | 0 | 0 | 0 | 0 |
|
||||
* | option2 | 0 | 0 | 0 | 0 | 0 |
|
||||
* | option3 | 0 | 0 | 0 | 0 | 0 |
|
||||
* | option4 | 0 | 0 | 0 | 0 | 0 |
|
||||
*
|
||||
* @param checkItemOptionDTOs
|
||||
* @param listCheckItemOptionArea
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<Map<String, Object>> buildCheckItemOptionArea(List<CheckItemOptionDTO> checkItemOptionDTOs, List<Map<String, Object>> listCheckItemOptionArea) throws Exception {
|
||||
List<Map<String, Object>> checkItemOptionList = new ArrayList<>();
|
||||
for (CheckItemOptionDTO checkItemOptionDTO : checkItemOptionDTOs) {
|
||||
Map<String, Object> checkItemOptionMap = HashMapUtil.beanToMap(checkItemOptionDTO);
|
||||
List<Map<String, Object>> areaList = new ArrayList<>();
|
||||
for (Map<String, Object> checkItemOptionArea : listCheckItemOptionArea) {
|
||||
Map<String, Object> areaMap = getHashMap(3);
|
||||
areaMap.put("areaName", checkItemOptionArea.get("areaName"));
|
||||
List<Map<String, Object>> checkItemOptions = (List<Map<String, Object>>) checkItemOptionArea.get("listCheckItemOption");
|
||||
for (Map<String, Object> checkItemOption : checkItemOptions) {
|
||||
if (StringUtils.equals(checkItemOptionDTO.getCheckItemOptionId(), checkItemOption.get("checkItemOptionId").toString())) {
|
||||
areaMap.put("checkCount", checkItemOption.get("checkCount"));
|
||||
areaList.add(areaMap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
checkItemOptionMap.put("areaList", areaList);
|
||||
checkItemOptionList.add(checkItemOptionMap);
|
||||
}
|
||||
return checkItemOptionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建检查项列表。由于检查项是动态的,不确定层级,要动态构建列表
|
||||
*
|
||||
* @param checkItemDTOs
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<Map<String, Object>> buildCheckItem(List<CheckItemDTO> checkItemDTOs) throws Exception {
|
||||
// 中间变量
|
||||
Map<String, List<Map<String, Object>>> tempMap = new HashMap<>(20);
|
||||
for (CheckItemDTO checkItemDTO : checkItemDTOs) {
|
||||
String parentId = checkItemDTO.getCheckItemParentId();
|
||||
if (StringUtils.isBlank(parentId)) {
|
||||
continue;
|
||||
}
|
||||
List<Map<String, Object>> tempList = tempMap.get(parentId);
|
||||
if (tempList == null) {
|
||||
tempList = new ArrayList<>();
|
||||
tempMap.put(parentId, tempList);
|
||||
}
|
||||
tempList.add(HashMapUtil.beanToMap(checkItemDTO));
|
||||
}
|
||||
// 组合列表
|
||||
for (Map.Entry<String, List<Map<String, Object>>> kv : tempMap.entrySet()) {
|
||||
// 取出当前的键值
|
||||
String key = kv.getKey();
|
||||
List<Map<String, Object>> value = kv.getValue();
|
||||
// 从temp找到对应的父级
|
||||
for (Map.Entry<String, List<Map<String, Object>>> kv2 : tempMap.entrySet()) {
|
||||
List<Map<String, Object>> value2 = kv2.getValue();
|
||||
boolean find = false;
|
||||
for (Map<String, Object> map : value2) {
|
||||
// 加入父级
|
||||
if (StringUtils.equals(map.get("checkItemId").toString(), key)) {
|
||||
map.put("subCheckItem", value);
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tempMap.get("0");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,7 +453,9 @@ public class CountServiceImpl extends BaseService implements ICountService {
|
||||
/**
|
||||
* 统计隐患问题
|
||||
*
|
||||
* @param checkIds
|
||||
* @param checkItemOptionDTOs
|
||||
* @param userIdList
|
||||
* @param year
|
||||
* @return
|
||||
*/
|
||||
private Integer countCheckHiddenDanger(List<CheckItemOptionDTO> checkItemOptionDTOs, List<String> userIdList, String year) {
|
||||
@ -481,7 +582,7 @@ public class CountServiceImpl extends BaseService implements ICountService {
|
||||
/**
|
||||
* 获取检查ID列表
|
||||
*
|
||||
* @param userIds
|
||||
* @param userIdList
|
||||
* @return
|
||||
*/
|
||||
private List<String> listNeedReCheckIds(List<String> userIdList) {
|
||||
|
Loading…
Reference in New Issue
Block a user