提交 b99865e2 authored 作者: Matrix's avatar Matrix

[核查模块] 修复了一些自动核查相关的BUG

[测试模块] 增加了出现异常后的自动回滚
上级 992e22e5
...@@ -21,7 +21,7 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEnt ...@@ -21,7 +21,7 @@ public interface DeviceCheckDetailDao extends JpaRepository<DeviceCheckDetailEnt
*/ */
@Modifying @Modifying
@Query("update DeviceCheckDetailEntity o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5,o.checkedCount=?6 where o.id=?1") @Query("update DeviceCheckDetailEntity o set o.checkDetail=?2,o.checkResult = ?3,o.userAId =?4,o.userBId=?5,o.checkedCount=?6 where o.id=?1")
void updateCheckDetail(Integer id, String checkDetail, String checkResult, int userAId, int userBId, long checkedCount); void updateCheckDetail(Integer id, String checkDetail, String checkResult, int userAId, int userBId, Integer checkedCount);
@Modifying @Modifying
@Query("update DeviceCheckDetailEntity o set o.checkStatus=?2 where o.id=?1") @Query("update DeviceCheckDetailEntity o set o.checkStatus=?2 where o.id=?1")
......
package com.tykj.dev.confirmcheck; package com.tykj.dev.confirmcheck;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.wenhao.jpa.Specifications; import com.github.wenhao.jpa.Specifications;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.tykj.dev.device.confirmcheck.entity.vo.CheckBillVo; import com.tykj.dev.device.confirmcheck.entity.vo.CheckBillVo;
...@@ -20,9 +22,11 @@ import org.springframework.test.context.ActiveProfiles; ...@@ -20,9 +22,11 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.RequestBuilder; import org.springframework.test.web.servlet.RequestBuilder;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.stream.StreamSupport;
import static com.tykj.dev.misc.utils.JacksonUtil.toJSon; import static com.tykj.dev.misc.utils.JacksonUtil.toJSon;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
...@@ -63,9 +67,41 @@ class DeviceCheckControllerTest extends BaseTest { ...@@ -63,9 +67,41 @@ class DeviceCheckControllerTest extends BaseTest {
request = post("/check/confirm/check/auto") request = post("/check/confirm/check/auto")
.header("Origin", "*"); .header("Origin", "*");
mockMvc.perform(request) mockMvc.perform(request)
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(mvcResult1 -> System.out.println("[测试结果] 自动发起核查任务测试通过")); .andDo(result -> {
String resultString = result.getResponse().getContentAsString();
System.out.println("[测试结果] 自动发起核查任务测试通过,返回结果为 : " +
resultString);
deleteAutoCheckData(resultString);
});
}
private void deleteAutoCheckData(String resultString) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(resultString);
StreamSupport
.stream(jsonNode.get("data").get("statId").spliterator(), false)
.map(JsonNode::asInt)
.forEach(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 -> {
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);
});
} }
@Test @Test
......
...@@ -4,6 +4,7 @@ import org.junit.runner.RunWith; ...@@ -4,6 +4,7 @@ import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
/** /**
* BaseTest. * BaseTest.
...@@ -14,5 +15,6 @@ import org.springframework.test.context.junit4.SpringRunner; ...@@ -14,5 +15,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = UnionApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(classes = UnionApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@Transactional
public class BaseTest { public class BaseTest {
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论