提交 6b49c8ff authored 作者: Matrix's avatar Matrix

[核查模块] 修复了单个数组对象转换带来的异常问题

上级 78cf8e40
package com.tykj.dev.device.confirmcheck.utils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckBillEntity;
import com.tykj.dev.device.confirmcheck.entity.domain.DeviceCheckDetailEntity;
......@@ -21,6 +22,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -81,7 +83,19 @@ public class ObjTransUtil {
String userBName = checkUserB == null ? "" : checkUserB.getName();
//解析JSON并赋值
CheckDeviceStatVo[] checkDeviceStatVos = JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo[].class);
ObjectMapper objectMapper = new ObjectMapper();
CheckDeviceStatVo[] checkDeviceStatVos = new CheckDeviceStatVo[0];
try {
boolean isArray = objectMapper.readTree(statDo.getStatInfo()).isArray();
if (isArray) {
JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo[].class);
} else {
CheckDeviceStatVo checkDeviceStatVo = JacksonUtil.readValue(statDo.getStatInfo(), CheckDeviceStatVo.class);
checkDeviceStatVos = new CheckDeviceStatVo[]{checkDeviceStatVo};
}
} catch (IOException e) {
e.printStackTrace();
}
initialStat.setDeviceStatVoList(Arrays.asList(checkDeviceStatVos));
initialStat.setCheckUserAName(userAName);
initialStat.setCheckUserBName(userBName);
......@@ -138,10 +152,19 @@ public class ObjTransUtil {
Integer userAId = detailDo.getUserAId();
Integer userBId = detailDo.getUserBId();
String checkUserAName = userRepo.findById(checkUserAId).orElse(null).getName();
String checkUserBName = userRepo.findById(checkUserBId).orElse(null).getName();
String checkUserAName = "";
String checkUserBName = "";
String userAName = "";
String userBName = "";
if (checkUserAId != null && checkUserAId != 0) {
checkUserAName = userRepo.findById(checkUserAId).orElse(null).getName();
}
if (checkUserBId != null && checkUserBId != 0) {
checkUserBName = userRepo.findById(checkUserBId).orElse(null).getName();
}
if (userAId != null && userAId != 0) {
userAName = userRepo.findById(userAId).orElse(null).getName();
}
......
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.wenhao.jpa.Specifications;
import com.google.common.collect.Lists;
import com.tykj.dev.device.confirmcheck.controller.DeviceCheckController;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckBillVo;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckDetailVo;
import com.tykj.dev.device.confirmcheck.entity.vo.DevLibVo;
......@@ -20,6 +21,7 @@ import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.RequestBuilder;
import java.io.IOException;
......@@ -47,6 +49,9 @@ class DeviceCheckControllerTest extends BaseTest {
@Autowired
protected MockMvc mockMvc;
@Autowired
private DeviceCheckController checkController;
@Autowired
private DeviceCheckDetailDao detailRepo;
......@@ -68,14 +73,42 @@ class DeviceCheckControllerTest extends BaseTest {
.header("Origin", "*");
mockMvc.perform(request)
MvcResult mvcResult = mockMvc.perform(request)
.andExpect(status().isOk())
.andDo(result -> {
String resultString = result.getResponse().getContentAsString();
System.out.println("[测试结果] 自动发起核查任务测试通过,返回结果为 : " +
resultString);
deleteAutoCheckData(resultString);
.andReturn();
String resultString = mvcResult.getResponse().getContentAsString();
System.out.println("[测试结果] 自动发起核查任务测试通过,返回结果为 : " +
resultString);
// 测试 生成的数据是否都能正常访问
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(resultString);
StreamSupport
.stream(jsonNode.get("data").get("statId").spliterator(), false)
.map(JsonNode::asInt)
.forEach(statId -> {
//测试访问
checkController.findStatById(statId);
System.out.printf("[数据清理-统计] 删除id为 %d 的统计数据 %n", statId);
statRepo.deleteById(statId);
});
StreamSupport
.stream(jsonNode.get("data").get("detailId").spliterator(), false)
.map(JsonNode::asInt)
.forEach(detailId -> {
//测试访问
checkController.findDetail(detailId);
System.out.printf("[数据清理-自查] 删除id为 %d 的自查数据 %n", detailId);
detailRepo.deleteById(detailId);
});
StreamSupport
.stream(jsonNode.get("data").get("taskId").spliterator(), false)
.map(JsonNode::asInt)
.forEach(taskId -> {
System.out.printf("[数据清理-任务] 删除id为 %d 的任务数据 %n", taskId);
taskRepo.deleteById(taskId);
});
// deleteAutoCheckData(resultString);
}
private void deleteAutoCheckData(String resultString) throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论