修复分页和编辑保存异常

This commit is contained in:
loray513 2024-12-05 12:32:01 +08:00
parent 33ad6d0b28
commit 66c2cea19e
1 changed files with 28 additions and 18 deletions

View File

@ -74,7 +74,10 @@ public class IndicatorController {
setSuccess(result); setSuccess(result);
if(list != null){ if(list != null){
result.setData(list); HashMap<String, Object> hashMap =new HashMap<>();
hashMap.put("data", list);
hashMap.put("totalCount", result.getTotal());
result.setData(hashMap);
if(result.getTotal() == null){ if(result.getTotal() == null){
result.setTotal((long) list.size()); result.setTotal((long) list.size());
} }
@ -459,30 +462,37 @@ public class IndicatorController {
} }
if(label_list != null && label_list.size()>0){ if(label_list != null && label_list.size()>0){
boolean saveTmpFlag = false;
for (int i = 0; i < label_list.size(); i++) { for (int i = 0; i < label_list.size(); i++) {
if(!updateFlag){ if(!updateFlag){
if(i > 0 && i <(label_list.size())) { if(i > 0 && i <(label_list.size())) {
label_list.get(i).setParentId(label_list.get(i-1).getId()); label_list.get(i).setParentId(label_list.get(i-1).getId());
} }
label_list.get(i).setCreateTime(date); label_list.get(i).setCreateTime(date);
saveTmpFlag = true;
}else { }else {
if (label_list.get(i).getId() == null) { if (label_list.get(i).getId() == null) {
log.error("-------- 保存指标异常, 更新指标时, 标签id不能为空" + label_list.get(i)); // 新增指标
throw new RuntimeException("更新指标时, 标签id不能为空" + label_list.get(i)); if(i > 0 && i <(label_list.size())) {
} label_list.get(i).setParentId(label_list.get(i-1).getId());
List<IndicatorLabel> I_L_list =indicatorLabelRepository.lambdaQuery().eq(IndicatorLabel::getIndicatorId,indicator.getId()).list();
boolean ILFlag = false;
for (int j=0; j<I_L_list.size(); j++) {
if(label_list.get(i).getId() == I_L_list.get(j).getLabelId()){
ILFlag = true;
} }
label_list.get(i).setCreateTime(date);
saveTmpFlag = true;
} else {
List<IndicatorLabel> I_L_list = indicatorLabelRepository.lambdaQuery().eq(IndicatorLabel::getIndicatorId, indicator.getId()).list();
boolean ILFlag = false;
for (int j = 0; j < I_L_list.size(); j++) {
if (label_list.get(i).getId().equals(I_L_list.get(j).getLabelId())) {
ILFlag = true;
}
}
if (!ILFlag) {
log.error("-------- 保存指标异常, 更新指标id : " + label_list.get(i).getId() + "无效请输入正确的指标id");
throw new RuntimeException("更新指标id : " + label_list.get(i).getId() + "无效请输入正确的指标id");
}
Label label = labelRepository.getById(label_list.get(i).getId());
label_list.get(i).setParentId(label.getParentId());
} }
if(!ILFlag){
log.error("-------- 保存指标异常, 更新指标id : "+label_list.get(i).getId()+"无效请输入正确的指标id");
throw new RuntimeException("更新指标id : "+label_list.get(i).getId()+"无效请输入正确的指标id");
}
Label label = labelRepository.getById(label_list.get(i).getId());
label_list.get(i).setParentId(label.getParentId());
} }
label_list.get(i).setTableName(tableName); label_list.get(i).setTableName(tableName);
label_list.get(i).setUpdateTime(date); label_list.get(i).setUpdateTime(date);
@ -493,7 +503,7 @@ public class IndicatorController {
System.out.println("___"+label_list.get(i).getId()); System.out.println("___"+label_list.get(i).getId());
if(label_flag){ if(label_flag){
if(!updateFlag){ if(!updateFlag || saveTmpFlag){
IndicatorLabel indicator_label = new IndicatorLabel(); IndicatorLabel indicator_label = new IndicatorLabel();
indicator_label.setIndicatorId(indicator.getId()); indicator_label.setIndicatorId(indicator.getId());
indicator_label.setLabelId(label_list.get(i).getId()); indicator_label.setLabelId(label_list.get(i).getId());
@ -624,7 +634,7 @@ public class IndicatorController {
public Result searchIndicator(@RequestBody Search search) { public Result searchIndicator(@RequestBody Search search) {
Result result = new Result(); Result result = new Result();
try { try {
Page<IndicatorVo> query = new Page(search.getCurrentPage(), search.getPageSize()); Page<IndicatorVo> query = new Page(search.getCurrentPage()-1, search.getPageSize());
Page<IndicatorVo> page = indicatorMapper.getIndicatorPage(query,search.getValue()); Page<IndicatorVo> page = indicatorMapper.getIndicatorPage(query,search.getValue());
for (IndicatorVo vo : page.getRecords()) { for (IndicatorVo vo : page.getRecords()) {
LambdaQueryChainWrapper<IndicatorLabel> wrapper = indicatorLabelRepository.lambdaQuery().eq(IndicatorLabel::getIndicatorId,vo.getId()); LambdaQueryChainWrapper<IndicatorLabel> wrapper = indicatorLabelRepository.lambdaQuery().eq(IndicatorLabel::getIndicatorId,vo.getId());
@ -632,7 +642,7 @@ public class IndicatorController {
for (IndicatorLabel indicatorLabel : wrapper.select(IndicatorLabel::getLabelId).list()) { for (IndicatorLabel indicatorLabel : wrapper.select(IndicatorLabel::getLabelId).list()) {
list.add(indicatorLabel.getLabelId()); list.add(indicatorLabel.getLabelId());
} }
List<Label> labelList = labelMapper.selectBatchIds(list); List<Label> labelList = labelRepository.lambdaQuery().in(Label::getId,list).orderByAsc(Label::getLabelLevel).list();
vo.setLableList(labelList); vo.setLableList(labelList);
} }
result.setTotal(page.getTotal()); result.setTotal(page.getTotal());