Skip to content

Commit ad25aba

Browse files
authored
fix: Fix block update bug (#245)
1 parent 414f7ba commit ad25aba

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

base/src/main/java/com/tinyengine/it/controller/BlockController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,19 @@ public Result<List<String>> allTags() {
255255
@GetMapping("/block/notgroup/{groupId}")
256256
public Result<List<BlockDto>> findBlocksNotInGroup(@PathVariable Integer groupId,
257257
@RequestParam(value = "label_contains", required = false) String label,
258+
@RequestParam(value = "name_cn_contains", required = false) String name,
258259
@RequestParam(value = "tags_contains", required = false) String[] tags,
259260
@RequestParam(value = "createdBy", required = false) String createdBy) {
260261
NotGroupDto notGroupDto = new NotGroupDto();
261262
notGroupDto.setGroupId(groupId);
262263
notGroupDto.setLabel(label);
264+
notGroupDto.setName(name);
263265
notGroupDto.setCreatedBy(createdBy);
264266
notGroupDto.setTags(null);
267+
if (tags != null && tags.length > 0) {
268+
notGroupDto.setTags(JsonUtils.encode(tags)); // 将数组转换为有效的 JSON 字符串
269+
}
270+
265271

266272
List<BlockDto> blocksList = blockService.getNotInGroupBlocks(notGroupDto);
267273
return Result.success(blocksList);

base/src/main/java/com/tinyengine/it/mapper/BlockGroupBlockMapper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,16 @@ public interface BlockGroupBlockMapper extends BaseMapper<BlockGroupBlock> {
9494
* 通过区块分组id和区块删除区块与分组关联关系
9595
* @param blockId the block id
9696
* @param groupId the block group id
97-
* @return the list
97+
* @return the Integer
9898
*/
9999
@Delete("delete from r_block_group_block where block_group_id = #{groupId} and block_id = #{blockId}")
100100
Integer deleteByGroupIdAndBlockId(Integer groupId, Integer blockId);
101+
102+
/**
103+
* 通过区块id删除区块与分组关联关系
104+
* @param blockId the block id
105+
* @return the Integer
106+
*/
107+
@Delete("delete from r_block_group_block where block_id = #{blockId}")
108+
Integer deleteByBlockId(Integer blockId);
101109
}

base/src/main/java/com/tinyengine/it/mapper/BlockMapper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ public interface BlockMapper extends BaseMapper<Block> {
156156
})
157157
@Select("<script>" + "SELECT b.* " + "FROM t_block b " + "<where>"
158158
+ " <if test='notGroupDto.label != null and notGroupDto.label != \"\"'> "
159-
+ " AND b.label LIKE CONCAT('%', #{notGroupDto.label}, '%') " + " </if>"
159+
+ " OR b.label LIKE CONCAT('%', #{notGroupDto.label}, '%') " + " </if>"
160+
+ " <if test='notGroupDto.name != null and notGroupDto.name != \"\"'> "
161+
+ " OR b.name LIKE CONCAT('%', #{notGroupDto.name}, '%') " + " </if>"
160162
+ " <if test='notGroupDto.createdBy != null and notGroupDto.createdBy != \"\"'> "
161-
+ " AND b.created_by LIKE CONCAT('%', #{notGroupDto.createdBy}, '%') " + " </if>"
162-
+ " <if test='notGroupDto.tags != null and notGroupDto.tags.length > 0'> "
163-
+ " AND JSON_CONTAINS(b.tags, #{notGroupDto.tags})" + " </if>" + "</where>" + "</script>")
163+
+ " OR b.created_by LIKE CONCAT('%', #{notGroupDto.createdBy}, '%') " + " </if>"
164+
+ " <if test='notGroupDto.tags != null and notGroupDto.tags != \"\"'> "
165+
+ " OR JSON_CONTAINS(b.tags, #{notGroupDto.tags})" + " </if>" + "</where>" + "</script>")
164166
List<BlockDto> findBlocksReturn(@Param("notGroupDto") NotGroupDto notGroupDto);
165167

166168
/**

base/src/main/java/com/tinyengine/it/model/dto/NotGroupDto.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ public class NotGroupDto {
3131
@Schema(name = "label", description = "区块编码")
3232
private String label;
3333

34+
@Schema(name = "name", description = "区块名称")
35+
private String name;
36+
37+
3438
@Schema(name = "createdBY", description = "创建人id")
3539
private String createdBy;
3640

3741
@Schema(name = "tags", description = "区块标签")
38-
private String [] tags;
42+
private String tags;
3943
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public List<Block> queryBlockByCondition(Block block) {
153153
*/
154154
@Override
155155
public Integer deleteBlockById(Integer id) {
156-
return baseMapper.deleteBlockById(id);
156+
baseMapper.deleteBlockById(id);
157+
return blockGroupBlockMapper.deleteByBlockId(id);
157158
}
158159

159160
/**
@@ -171,7 +172,7 @@ public Result<BlockDto> updateBlockById(BlockParam blockParam) {
171172
if (blockResult == null) {
172173
return Result.failed(ExceptionEnum.CM001);
173174
}
174-
if (!Objects.equals(blockResult.getAppId(), blockParam.getAppId())) {
175+
if (!Objects.equals(blockResult.getOccupierBy(), loginUserContext.getLoginUserId())) {
175176
return Result.failed(ExceptionEnum.CM007);
176177
}
177178
// 把前端传参赋值给实体

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.tinyengine.it.common.base.Result;
2828
import com.tinyengine.it.common.context.LoginUserContext;
2929
import com.tinyengine.it.mapper.AppMapper;
30+
import com.tinyengine.it.mapper.BlockGroupBlockMapper;
3031
import com.tinyengine.it.mapper.BlockGroupMapper;
3132
import com.tinyengine.it.mapper.BlockMapper;
3233
import com.tinyengine.it.mapper.UserMapper;
@@ -69,6 +70,9 @@ class BlockServiceImplTest {
6970
@Mock
7071
private LoginUserContext loginUserContext;
7172

73+
@Mock
74+
private BlockGroupBlockMapper blockGroupBlockMapper;
75+
7276
@InjectMocks
7377
private BlockServiceImpl blockServiceImpl;
7478

@@ -110,6 +114,7 @@ void testQueryBlockByCondition() {
110114
@Test
111115
void testDeleteBlockById() {
112116
when(blockMapper.deleteBlockById(123)).thenReturn(1);
117+
when(blockGroupBlockMapper.deleteByBlockId(123)).thenReturn(1);
113118

114119
Integer result = blockServiceImpl.deleteBlockById(123);
115120
Assertions.assertEquals(1, result);

0 commit comments

Comments
 (0)