Parcourir la source

fix(投票选项): 批量插入数据.

eric il y a 2 ans
Parent
commit
4a30d6291c

+ 1 - 1
src/main/resources/mapper/OptionMapper.xml

@@ -47,7 +47,7 @@
         INSERT INTO t_option (vote_id, value)
         VALUES
         <foreach collection="entities" item="entity" separator=",">
-            (#{voteId}, #{value})
+            (#{entity.voteId}, #{entity.value})
         </foreach>
     </insert>
 

+ 53 - 0
src/test/java/com/finikes/oc/vote/dao/OptionDaoTest.java

@@ -0,0 +1,53 @@
+package com.finikes.oc.vote.dao;
+
+import com.finikes.oc.App;
+import com.finikes.oc.vote.entity.Option;
+import org.junit.jupiter.api.MethodOrderer;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = App.class)
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
+class OptionDaoTest {
+
+    @Autowired
+    private OptionDao optionDao;
+
+    @Test
+    void deleteByVoteId() {
+        optionDao.deleteByVoteId(0);
+    }
+
+    @Test
+    void bulkInsert() {
+        List<Option> options = new ArrayList<>();
+        for (int i = 0; i < 10; i++) {
+            Option option = new Option();
+            option.setVoteId(0);
+            option.setValue(UUID.randomUUID().toString());
+            options.add(option);
+        }
+        optionDao.bulkInsert(options);
+    }
+
+    @Test
+    void selectByVoteIds() {
+        List<Integer> integers = IntStream.range(0, 10)
+                .boxed()
+                .collect(Collectors.toList());
+        optionDao.selectByVoteIds(integers);
+    }
+}