Skip to content

Commit cca5e8b

Browse files
authored
fix: modify t_i18n_entry table and block (#161)
* fix: update page history bug * fix: format code and fix style issue * fix: modify page histiry entity * feat: add code submission rules * fix: modify app schema for test * fix: modify t_i18n_entry u_idx_i18n_entity
1 parent 0b94204 commit cca5e8b

File tree

7 files changed

+54
-22
lines changed

7 files changed

+54
-22
lines changed

app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ create table `t_i18n_entry`
511511
`last_updated_by` varchar(60) not null comment '最后修改人',
512512
`last_updated_time` timestamp not null default current_timestamp comment '更新时间',
513513
primary key (`id`) using btree,
514-
unique index `u_idx_i18n_entity` (`key`, `host_id`, `host_type`) using btree
514+
unique index `u_idx_i18n_entity` (`key`, `host_id`, `host_type`,`lang_id`) using btree
515515
) engine = innodb comment = '国际化语言配置表';
516516

517517
drop table if exists `t_i18n_lang`;

base/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public Integer deleteBlockGroupById(@Param("id") Integer id) {
103103
public Integer updateBlockGroupById(BlockGroup blockGroup) {
104104
// 判断是对正常的分组修改,还是在分组下添加区块操作的修改
105105
List<Block> blockList = blockGroup.getBlocks();
106-
List<Integer> blockIds = blockList.stream().map(Block::getId).collect(Collectors.toList());
107106
List<BlockGroupBlock> blockGroupBlocks = blockGroupBlockMapper.findBlockGroupBlockByBlockGroupId(blockGroup.getId());
108107
List<Integer> groupBlockIds = blockGroupBlocks.stream().map(BlockGroupBlock::getBlockId).collect(Collectors.toList());
109108

@@ -113,9 +112,11 @@ public Integer updateBlockGroupById(BlockGroup blockGroup) {
113112
// 删除区块分组与区块历史版本关系
114113
blockCarriersRelationMapper.deleteBlockCarriersRelation(blockGroup.getId(), hostType, null);
115114
// 删除区块分组与区块关系
116-
return blockGroupBlockMapper.deleteBlockGroupBlockByGroupId(blockGroup.getId());
115+
blockGroupBlockMapper.deleteBlockGroupBlockByGroupId(blockGroup.getId());
116+
return blockGroupMapper.updateBlockGroupById(blockGroup);
117117
}
118118
// 处理参数分组区块
119+
List<Integer> blockIds = blockList.stream().map(Block::getId).collect(Collectors.toList());
119120
int result = getBlockGroupIds(groupBlockIds, blockIds, blockGroup.getId());
120121
// 更新区块分组和区块历史关系表
121122
List<BlockCarriersRelation> blockCarriersRelations = new ArrayList<>();

base/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.tinyengine.it.common.exception.ExceptionEnum;
2525
import com.tinyengine.it.common.log.SystemServiceLog;
2626
import com.tinyengine.it.mapper.AppMapper;
27+
import com.tinyengine.it.mapper.BlockGroupBlockMapper;
2728
import com.tinyengine.it.mapper.BlockGroupMapper;
2829
import com.tinyengine.it.mapper.BlockHistoryMapper;
2930
import com.tinyengine.it.mapper.BlockMapper;
@@ -37,7 +38,9 @@
3738
import com.tinyengine.it.model.dto.SchemaI18n;
3839
import com.tinyengine.it.model.entity.App;
3940
import com.tinyengine.it.model.entity.Block;
41+
import com.tinyengine.it.model.entity.BlockCarriersRelation;
4042
import com.tinyengine.it.model.entity.BlockGroup;
43+
import com.tinyengine.it.model.entity.BlockGroupBlock;
4144
import com.tinyengine.it.model.entity.BlockHistory;
4245
import com.tinyengine.it.model.entity.User;
4346
import com.tinyengine.it.service.app.I18nEntryService;
@@ -88,6 +91,8 @@ public class BlockServiceImpl implements BlockService {
8891
private I18nEntryMapper i18nEntryMapper;
8992
@Autowired
9093
private BlockGroupMapper blockGroupMapper;
94+
@Autowired
95+
private BlockGroupBlockMapper blockGroupBlockMapper;
9196

9297
/**
9398
* 查询表t_block所有数据
@@ -150,23 +155,33 @@ public Integer updateBlockById(BlockDto blockDto) {
150155
Block blocks = new Block();
151156
BeanUtils.copyProperties(blockDto, blocks);
152157
blocks.setOccupierBy(String.valueOf(1));
153-
blocks.setLatestHistoryId(blockDto.getLatestHistoryId().getId());
158+
if(blockDto.getLatestHistoryId() != null){
159+
blocks.setLatestHistoryId(blockDto.getLatestHistoryId().getId());
160+
}
154161
// 处理区块截图
155162
if (!blockDto.getScreenshot().isEmpty() && !blockDto.getLabel().isEmpty()) {
156163
// 图片上传,此处给默认值空字符
157164
blocks.setScreenshot("");
158165
}
166+
167+
if(blockDto.getGroups().isEmpty()){
168+
return blockMapper.updateBlockById(blocks);
169+
}
170+
159171
// 过滤出 Integer 类型的对象
160172
// 转换为 Integer 类型
161173
// 收集为 List<Integer>;
162174
List<Integer> groups = blockDto.getGroups().stream()
163175
.filter(obj -> obj instanceof Integer)
164176
.map(obj -> (Integer) obj)
165177
.collect(Collectors.toList());
166-
if (!groups.isEmpty()) {
178+
167179
int groupId = groups.get(0);
168-
blocks.setBlockGroupId(groupId);
169-
}
180+
BlockGroupBlock blockGroupBlock = new BlockGroupBlock();
181+
blockGroupBlock.setBlockGroupId(groupId);
182+
blockGroupBlock.setBlockId(blockDto.getId());
183+
blockGroupBlockMapper.createBlockGroupBlock(blockGroupBlock);
184+
170185
return blockMapper.updateBlockById(blocks);
171186
}
172187

@@ -190,7 +205,10 @@ public Result<BlockDto> createBlock(BlockDto blockDto) {
190205
List<Object> groups = blockDto.getGroups();
191206
if (!groups.isEmpty() && groups.get(0) instanceof Integer) {
192207
Integer groupId = (Integer) groups.get(0); // 强制类型转换
193-
blocks.setBlockGroupId(groupId);
208+
BlockGroupBlock blockGroupBlock = new BlockGroupBlock();
209+
blockGroupBlock.setBlockGroupId(groupId);
210+
blockGroupBlock.setBlockId(blockDto.getId());
211+
blockGroupBlockMapper.createBlockGroupBlock(blockGroupBlock);
194212
}
195213
int result = blockMapper.createBlock(blocks);
196214
if (result < 1) {
@@ -394,6 +412,9 @@ public List<BlockDto> getNotInGroupBlocks(NotGroupDto notGroupDto) {
394412
int userId = 1;
395413
User user = userMapper.queryUserById(userId);
396414
List<BlockDto> blocksList = blockMapper.findBlocksReturn(notGroupDto);
415+
if(blocksList == null || blocksList.isEmpty()){
416+
return blocksList;
417+
}
397418
for (BlockDto blockDto : blocksList) {
398419
List<BlockGroup> blockGroups = blockGroupMapper.findBlockGroupByBlockId(blockDto.getId());
399420
List<Object> objectGroups = new ArrayList<>(blockGroups);

base/src/main/resources/mappers/BlockGroupBlock.xml renamed to base/src/main/resources/mappers/BlockGroupBlockMapper.xml

File renamed without changes.

base/src/main/resources/mappers/BlockGroupMapper.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@
181181
b.renter_id as block_renter_id,
182182
b.site_id as block_site_id
183183
FROM t_block_group bg
184-
JOIN
184+
LEFT JOIN
185185
r_block_group_block rbg ON rbg.block_group_id = bg.id
186-
JOIN
186+
LEFT JOIN
187187
t_block b ON b.id = rbg.block_id
188188
<if test="createdBy != null">
189189
AND b.created_by = #{createdBy}
@@ -240,9 +240,9 @@
240240
b.renter_id as block_renter_id,
241241
b.site_id as block_site_id
242242
FROM t_block_group bg
243-
JOIN
243+
LEFT JOIN
244244
r_block_group_block rbg ON rbg.block_group_id = bg.id
245-
JOIN
245+
LEFT JOIN
246246
t_block b ON b.id = rbg.block_id
247247
<if test="createdBy != null">
248248
AND b.created_by = #{createdBy}
@@ -303,9 +303,9 @@
303303
b.renter_id as block_renter_id,
304304
b.site_id as block_site_id
305305
FROM t_block_group bg
306-
JOIN
306+
LEFT JOIN
307307
r_block_group_block rbg ON rbg.block_group_id = bg.id
308-
JOIN
308+
LEFT JOIN
309309
t_block b ON b.id = rbg.block_id
310310
<if test="createdBy != null">
311311
AND b.created_by = #{createdBy}

base/src/test/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImplTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import static org.mockito.Mockito.when;
1717

1818
import com.tinyengine.it.common.base.Result;
19+
import com.tinyengine.it.mapper.BlockCarriersRelationMapper;
20+
import com.tinyengine.it.mapper.BlockGroupBlockMapper;
1921
import com.tinyengine.it.mapper.BlockGroupMapper;
2022
import com.tinyengine.it.model.dto.BlockGroupDto;
2123
import com.tinyengine.it.model.entity.BlockGroup;
@@ -26,6 +28,7 @@
2628
import org.mockito.InjectMocks;
2729
import org.mockito.Mock;
2830
import org.mockito.MockitoAnnotations;
31+
import org.springframework.beans.factory.annotation.Autowired;
2932

3033
import java.util.ArrayList;
3134
import java.util.Arrays;
@@ -41,6 +44,10 @@ class BlockGroupServiceImplTest {
4144
private BlockGroupMapper blockGroupMapper;
4245
@InjectMocks
4346
private BlockGroupServiceImpl blockGroupServiceImpl;
47+
@Mock
48+
private BlockCarriersRelationMapper blockCarriersRelationMapper;
49+
@Mock
50+
private BlockGroupBlockMapper blockGroupBlockMapper;
4451

4552
@BeforeEach
4653
void setUp() {
@@ -86,8 +93,11 @@ void testDeleteBlockGroupById() {
8693
@Test
8794
void testUpdateBlockGroupById() {
8895
BlockGroup param = new BlockGroup();
96+
param.setId(1);
97+
param.setBlocks(new ArrayList<>());
8998
when(blockGroupMapper.updateBlockGroupById(param)).thenReturn(1);
90-
99+
when(blockGroupBlockMapper.deleteBlockGroupBlockByGroupId(null)).thenReturn(1);
100+
when(blockCarriersRelationMapper.deleteBlockCarriersRelation(null, null, null)).thenReturn(1);
91101
Integer result = blockGroupServiceImpl.updateBlockGroupById(param);
92102
Assertions.assertEquals(1, result);
93103
}

base/src/test/java/com/tinyengine/it/service/material/impl/BlockServiceImplTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
import com.tinyengine.it.common.base.Result;
2626
import com.tinyengine.it.common.enums.Enums;
2727
import com.tinyengine.it.mapper.AppMapper;
28+
import com.tinyengine.it.mapper.BlockGroupMapper;
2829
import com.tinyengine.it.mapper.BlockMapper;
2930
import com.tinyengine.it.mapper.UserMapper;
3031
import com.tinyengine.it.model.dto.BlockDto;
3132
import com.tinyengine.it.model.dto.BlockParamDto;
3233
import com.tinyengine.it.model.dto.NotGroupDto;
3334
import com.tinyengine.it.model.entity.App;
3435
import com.tinyengine.it.model.entity.Block;
36+
import com.tinyengine.it.model.entity.BlockGroup;
3537
import com.tinyengine.it.model.entity.User;
3638

3739
import org.junit.jupiter.api.Assertions;
@@ -63,6 +65,8 @@ class BlockServiceImplTest {
6365
private UserMapper userMapper;
6466
@Mock
6567
private AppMapper appMapper;
68+
@Mock
69+
private BlockGroupMapper blockGroupMapper;
6670

6771
@BeforeEach
6872
void setUp() {
@@ -118,7 +122,6 @@ void testCreateBlock() {
118122
blockDto.setFramework("cc");
119123
blockDto.setPlatformId(1);
120124
blockDto.setAppId(1);
121-
blockDto.setGroups(asList(1));
122125
blockDto.setName("testBlock");
123126
Result<BlockDto> result = blockServiceImpl.createBlock(blockDto);
124127
Assertions.assertEquals("test", result.getData().getName());
@@ -238,18 +241,15 @@ void testAllTags() {
238241
@Test
239242
void testGetNotInGroupBlocks() {
240243
BlockDto blockDto = new BlockDto();
241-
blockDto.setLastBuildInfo(new HashMap<>());
242-
blockDto.setContent(new HashMap<>());
243-
blockDto.setAssets(new HashMap<>());
244-
blockDto.setPublicStatus(Enums.Scope.PUBLIC_IN_TENANTS.getValue());
245244
List<BlockDto> mockData = Arrays.asList(blockDto);
246245
NotGroupDto notGroupDto =new NotGroupDto();
247-
notGroupDto.setGroupId(1);
246+
List<BlockGroup> blockGroups = new ArrayList<>();
248247
when(blockMapper.findBlocksReturn(notGroupDto)).thenReturn(mockData);
249248
when(userMapper.queryUserById(anyInt())).thenReturn(new User());
249+
when(blockGroupMapper.findBlockGroupByBlockId(blockDto.getId())).thenReturn(blockGroups);
250250

251251
List<BlockDto> result = blockServiceImpl.getNotInGroupBlocks(notGroupDto);
252-
Assertions.assertEquals(blockDto, result.get(0));
252+
Assertions.assertEquals(new ArrayList<>(), result);
253253
}
254254

255255
@Test

0 commit comments

Comments
 (0)