Skip to content

Commit 6a5269d

Browse files
committed
feat: component library api
1 parent 58ed56b commit 6a5269d

File tree

11 files changed

+100
-35
lines changed

11 files changed

+100
-35
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.tinyengine.it.common.base.Result;
1616
import com.tinyengine.it.common.exception.ExceptionEnum;
1717
import com.tinyengine.it.common.log.SystemControllerLog;
18+
import com.tinyengine.it.model.dto.BundleResultDto;
1819
import com.tinyengine.it.model.dto.CustComponentDto;
1920
import com.tinyengine.it.model.dto.FileResult;
2021
import com.tinyengine.it.model.entity.Component;
@@ -53,6 +54,27 @@ public class ComponentController {
5354
@Autowired
5455
private ComponentService componentService;
5556

57+
/**
58+
* 上传bunled.json文件处理自定义组件
59+
*
60+
* @param file the file
61+
* @return result
62+
*/
63+
@Operation(summary = "上传bunled.json文件创建组件", description = "上传bunled.json文件创建组件", parameters = {
64+
@Parameter(name = "file", description = "文件参数对象")}, responses = {
65+
@ApiResponse(responseCode = "200", description = "返回信息",
66+
content = @Content(mediaType = "application/json", schema = @Schema())),
67+
@ApiResponse(responseCode = "400", description = "请求失败")})
68+
@SystemControllerLog(description = "上传bunled.json文件创建组件")
69+
@PostMapping("/component/bundle/createComponent")
70+
public Result<FileResult> bundleCreateComponent(@RequestParam MultipartFile file) {
71+
if (file.isEmpty()) {
72+
return Result.failed(ExceptionEnum.CM307);
73+
}
74+
// 返回插入和更新的条数
75+
return componentService.readFileAndBulkCreate(file);
76+
}
77+
5678
/**
5779
* 上传bunled.json文件处理自定义组件
5880
*
@@ -66,12 +88,11 @@ public class ComponentController {
6688
@ApiResponse(responseCode = "400", description = "请求失败")})
6789
@SystemControllerLog(description = "上传bunled.json文件处理自定义组件")
6890
@PostMapping("/component/bundle/split")
69-
public Result<FileResult> bundleSplit(@RequestParam MultipartFile file) {
91+
public Result<BundleResultDto> bundleSplit(@RequestParam MultipartFile file) {
7092
if (file.isEmpty()) {
7193
return Result.failed(ExceptionEnum.CM307);
7294
}
73-
// 返回插入和更新的条数
74-
return componentService.readFileAndBulkCreate(file);
95+
return componentService.bundleSplit(file);
7596
}
7697

7798
/**

base/src/main/java/com/tinyengine/it/service/app/impl/CanvasServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.tinyengine.it.service.app.impl;
1414

1515
import com.tinyengine.it.common.base.Result;
16+
import com.tinyengine.it.common.context.LoginUserContext;
1617
import com.tinyengine.it.mapper.BlockMapper;
1718
import com.tinyengine.it.mapper.PageMapper;
1819
import com.tinyengine.it.mapper.UserMapper;
@@ -38,12 +39,14 @@ public class CanvasServiceImpl implements CanvasService {
3839
private BlockMapper blockMapper;
3940
@Autowired
4041
private UserMapper userMapper;
42+
@Autowired
43+
private LoginUserContext loginUserContext;
4144

4245
@Override
4346
public Result<CanvasDto> lockCanvas(Integer id, String state, String type) {
4447
int occupier;
4548
// needTODO 先试用mock数据,后续添加登录及权限后从session获取,
46-
User user = userMapper.queryUserById(1);
49+
User user = userMapper.queryUserById(Integer.parseInt(loginUserContext.getLoginUserId()));
4750
CanvasDto canvasDto = new CanvasDto();
4851
if ("page".equals(type)) {
4952
Page page = pageMapper.queryPageById(id);

base/src/main/java/com/tinyengine/it/service/material/ComponentLibraryService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public interface ComponentLibraryService {
4343
/**
4444
* 根据条件查询表t_component_library信息
4545
*
46-
* @param material the material
46+
* @param componentLibrary the componentLibrary
4747
* @return the list
4848
*/
49-
List<ComponentLibrary> queryComponentLibraryByCondition(ComponentLibrary material);
49+
List<ComponentLibrary> queryComponentLibraryByCondition(ComponentLibrary componentLibrary);
5050

5151
/**
5252
* 根据主键id删除t_component_library数据
@@ -59,16 +59,16 @@ public interface ComponentLibraryService {
5959
/**
6060
* 根据主键id更新表t_component_library信息
6161
*
62-
* @param material the material
62+
* @param componentLibrary the componentLibrary
6363
* @return the integer
6464
*/
65-
Result<ComponentLibrary> updateComponentLibraryById(ComponentLibrary material);
65+
Result<ComponentLibrary> updateComponentLibraryById(ComponentLibrary componentLibrary);
6666

6767
/**
6868
* 新增表t_component_library数据
6969
*
70-
* @param material the material
70+
* @param componentLibrary the componentLibrary
7171
* @return the integer
7272
*/
73-
Result<ComponentLibrary> createComponentLibrary(ComponentLibrary material);
73+
Result<ComponentLibrary> createComponentLibrary(ComponentLibrary componentLibrary);
7474
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public Result<ComponentLibrary> queryComponentLibraryById(@Param("id") Integer i
6565
/**
6666
* 根据条件查询表t_component_library数据
6767
*
68-
* @param material material
68+
* @param componentLibrary componentLibrary
6969
* @return query result
7070
*/
7171
@Override
72-
public List<ComponentLibrary> queryComponentLibraryByCondition(ComponentLibrary material) {
73-
return componentLibraryMapper.queryComponentLibraryByCondition(material);
72+
public List<ComponentLibrary> queryComponentLibraryByCondition(ComponentLibrary componentLibrary) {
73+
return componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary);
7474
}
7575

7676
/**
@@ -93,32 +93,32 @@ public Result<ComponentLibrary> deleteComponentLibraryById(@Param("id") Integer
9393
/**
9494
* 根据主键id更新表t_component_library数据
9595
*
96-
* @param material material
96+
* @param componentLibrary componentLibrary
9797
* @return execute success data number
9898
*/
9999
@Override
100-
public Result<ComponentLibrary> updateComponentLibraryById(ComponentLibrary material) {
101-
int updateResult = componentLibraryMapper.updateComponentLibraryById(material);
100+
public Result<ComponentLibrary> updateComponentLibraryById(ComponentLibrary componentLibrary) {
101+
int updateResult = componentLibraryMapper.updateComponentLibraryById(componentLibrary);
102102
if(updateResult != 1){
103103
return Result.failed(ExceptionEnum.CM008);
104104
}
105-
Result<ComponentLibrary> result = this.queryComponentLibraryById(material.getId());
105+
Result<ComponentLibrary> result = this.queryComponentLibraryById(componentLibrary.getId());
106106
return result;
107107
}
108108

109109
/**
110110
* 新增表t_component_library数据
111111
*
112-
* @param material material
112+
* @param componentLibrary componentLibrary
113113
* @return execute success data number
114114
*/
115115
@Override
116-
public Result<ComponentLibrary> createComponentLibrary(ComponentLibrary material) {
117-
int createResult = componentLibraryMapper.createComponentLibrary(material);
116+
public Result<ComponentLibrary> createComponentLibrary(ComponentLibrary componentLibrary) {
117+
int createResult = componentLibraryMapper.createComponentLibrary(componentLibrary);
118118
if(createResult != 1){
119119
return Result.failed(ExceptionEnum.CM008);
120120
}
121-
Result<ComponentLibrary> result = this.queryComponentLibraryById(material.getId());
121+
Result<ComponentLibrary> result = this.queryComponentLibraryById(componentLibrary.getId());
122122
return result;
123123
}
124124
}

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ public Integer createComponent(Component component) {
142142
public Result<FileResult> readFileAndBulkCreate(MultipartFile file) {
143143
List<Component> componentList = this.bundleSplit(file).getData().getComponentList();
144144
List<ComponentLibrary> packageList = this.bundleSplit(file).getData().getPackageList();
145+
if (null == packageList || packageList.isEmpty()) {
146+
return bulkCreate(componentList);
147+
}
145148
for (ComponentLibrary componentLibrary : packageList) {
146149
componentLibrary.setIsDefault(true);
147150
componentLibrary.setIsStarted(true);
@@ -233,15 +236,19 @@ public Result<BundleResultDto> bundleSplit(MultipartFile file) {
233236
componentList.add(component);
234237
}
235238
List<Map<String, Object>> packages = bundleDto.getMaterials().getPackages();
239+
240+
BundleResultDto bundleList = new BundleResultDto();
241+
bundleList.setComponentList(componentList);
242+
if (null == packages || packages.isEmpty()) {
243+
return Result.success(bundleList);
244+
}
236245
List<ComponentLibrary> packageList = new ArrayList<>();
237246
for (Map<String, Object> library : packages) {
238247
ComponentLibrary componentLibrary = BeanUtil.mapToBean(library, ComponentLibrary.class, true);
239248
componentLibrary.setPackageName(String.valueOf(library.get("package")));
240249
componentLibrary.setFramework("Vue");
241250
packageList.add(componentLibrary);
242251
}
243-
BundleResultDto bundleList = new BundleResultDto();
244-
bundleList.setComponentList(componentList);
245252
bundleList.setPackageList(packageList);
246253
return Result.success(bundleList);
247254
}
@@ -298,15 +305,22 @@ public Result<FileResult> bulkCreate(List<Component> componentList) {
298305
componentParam.setVersion(component.getVersion());
299306
List<Component> queryComponent = findComponentByCondition(componentParam);
300307
// 查询组件库id
301-
ComponentLibrary componentLibrary = new ComponentLibrary();
302-
componentLibrary.setPackageName(String.valueOf(component.getNpm().get("package")));
303-
componentLibrary.setVersion(component.getVersion());
304-
List<ComponentLibrary> componentLibraryList = componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary);
305-
Integer componentLibraryId = null;
306-
if (!componentLibraryList.isEmpty()) {
307-
componentLibraryId = componentLibraryList.get(0).getId();
308+
String packageName = null;
309+
if(null!= component.getNpm() && null != component.getNpm().get("package")){
310+
packageName = String.valueOf(component.getNpm().get("package"));
308311
}
309-
component.setLibraryId(componentLibraryId);
312+
if(null != packageName && !packageName.isEmpty()){
313+
ComponentLibrary componentLibrary = new ComponentLibrary();
314+
componentLibrary.setPackageName(String.valueOf(component.getNpm().get("package")));
315+
componentLibrary.setVersion(component.getVersion());
316+
List<ComponentLibrary> componentLibraryList = componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary);
317+
Integer componentLibraryId = null;
318+
if (!componentLibraryList.isEmpty()) {
319+
componentLibraryId = componentLibraryList.get(0).getId();
320+
}
321+
component.setLibraryId(componentLibraryId);
322+
}
323+
310324
if (queryComponent.isEmpty()) {
311325

312326
// 插入新记录

base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void testInsertFill() throws NoSuchFieldException, IllegalAccessException {
3636
when(param.hasSetter("tenantId")).thenReturn(true);
3737
TestUtil.setPrivateValue(myMetaObjectHandler, "loginUserContext", new MockUserContext());
3838
myMetaObjectHandler.insertFill(param);
39-
verify(param, times(6)).hasSetter(anyString());
39+
verify(param, times(8)).hasSetter(anyString());
4040
}
4141

4242
@Test

base/src/test/java/com/tinyengine/it/service/app/impl/CanvasServiceImplTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.mockito.Mockito.when;
2020

2121
import com.tinyengine.it.common.base.Result;
22+
import com.tinyengine.it.common.context.LoginUserContext;
2223
import com.tinyengine.it.mapper.BlockMapper;
2324
import com.tinyengine.it.mapper.PageMapper;
2425
import com.tinyengine.it.mapper.UserMapper;
@@ -46,6 +47,8 @@ class CanvasServiceImplTest {
4647
private BlockMapper blockMapper;
4748
@Mock
4849
private UserMapper userMapper;
50+
@Mock
51+
private LoginUserContext loginUserContext;
4952
@InjectMocks
5053
private CanvasServiceImpl canvasServiceImpl;
5154

@@ -67,7 +70,7 @@ void testLockCanvasTypePage() {
6770
User user = new User();
6871
user.setId(userId);
6972
when(userMapper.queryUserById(1)).thenReturn(user);
70-
73+
when(loginUserContext.getLoginUserId()).thenReturn("1");
7174
Result<CanvasDto> result = canvasServiceImpl.lockCanvas(pageId, "occupy", "page");
7275

7376
verify(pageMapper, times(1)).updatePageById(any());
@@ -86,6 +89,7 @@ void testLockCanvasTypeIsNotPage() {
8689
User user = new User();
8790
user.setId(userId);
8891
when(userMapper.queryUserById(1)).thenReturn(user);
92+
when(loginUserContext.getLoginUserId()).thenReturn("1");
8993

9094
Result<CanvasDto> result = canvasServiceImpl.lockCanvas(pageId, "occupy", "other");
9195

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.tinyengine.it.mapper.BlockGroupBlockMapper;
2121
import com.tinyengine.it.mapper.BlockGroupMapper;
2222
import com.tinyengine.it.model.dto.BlockGroupDto;
23+
import com.tinyengine.it.model.entity.Block;
2324
import com.tinyengine.it.model.entity.BlockGroup;
2425

2526
import org.junit.jupiter.api.Assertions;
@@ -107,8 +108,13 @@ void testUpdateBlockGroupById() {
107108
@Test
108109
void testCreateBlockGroup() {
109110
BlockGroup param = new BlockGroup();
111+
Block block = new Block();
112+
block.setId(1);
113+
List<Block> blockList = new ArrayList<>();
114+
blockList.add(block);
110115
when(blockGroupMapper.createBlockGroup(param)).thenReturn(1);
111116
when(loginUserContext.getLoginUserId()).thenReturn("1");
117+
when(blockGroupMapper.queryBlockGroupAndBlockById(1, null, loginUserContext.getLoginUserId())).thenReturn(param);
112118
BlockGroup blockGroupParam = new BlockGroup();
113119
blockGroupParam.setId(1);
114120
Result<BlockGroup> result = blockGroupServiceImpl.createBlockGroup(blockGroupParam);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import com.tinyengine.it.common.base.Result;
2020
import com.tinyengine.it.common.utils.Utils;
21+
import com.tinyengine.it.mapper.ComponentLibraryMapper;
2122
import com.tinyengine.it.mapper.ComponentMapper;
2223
import com.tinyengine.it.model.dto.BundleMaterial;
2324
import com.tinyengine.it.model.dto.FileResult;
2425
import com.tinyengine.it.model.dto.JsonFile;
2526
import com.tinyengine.it.model.entity.Component;
27+
import com.tinyengine.it.model.entity.ComponentLibrary;
2628
import com.tinyengine.it.model.entity.MaterialComponent;
2729
import com.tinyengine.it.model.entity.MaterialHistoryComponent;
2830

@@ -50,6 +52,8 @@
5052
class ComponentServiceImplTest {
5153
@Mock
5254
private ComponentMapper componentMapper;
55+
@Mock
56+
private ComponentLibraryMapper componentLibraryMapper;
5357
@InjectMocks
5458
private ComponentServiceImpl componentServiceImpl;
5559

@@ -124,7 +128,11 @@ void testReadFileAndBulkCreate() {
124128
when(componentMapper.createMaterialComponent(any(MaterialComponent.class))).thenReturn(Integer.valueOf(0));
125129
when(componentMapper.createMaterialHistoryComponent(any(MaterialHistoryComponent.class)))
126130
.thenReturn(Integer.valueOf(0));
127-
131+
ComponentLibrary componentLibrary = new ComponentLibrary();
132+
componentLibrary.setId(1);
133+
List<ComponentLibrary> componentLibraryList = new ArrayList<>();
134+
componentLibraryList.add(componentLibrary);
135+
when(componentLibraryMapper.queryComponentLibraryByCondition(componentLibrary)).thenReturn(componentLibraryList);
128136
MultipartFile file = mock(MultipartFile.class);
129137
HashMap<String, Object> fileContent = new HashMap<>();
130138
BundleMaterial bundleMaterial = new BundleMaterial();
@@ -134,6 +142,7 @@ void testReadFileAndBulkCreate() {
134142
components.add(componentdata);
135143
bundleMaterial.setComponents(components);
136144
bundleMaterial.setSnippets(new ArrayList<>());
145+
bundleMaterial.setPackages(new ArrayList<>());
137146
HashMap<Object, Object> material = new HashMap<>();
138147
material.put("framework", "Vue");
139148
material.put("materials", bundleMaterial);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void testFindAllMaterialHistory() {
5555
@Test
5656
void testFindMaterialHistoryById() {
5757
MaterialHistory mockData = new MaterialHistory();
58+
mockData.setId(1);
5859
when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(mockData);
5960

6061
Result<MaterialHistory> result = materialHistoryServiceImpl.findMaterialHistoryById(1);
@@ -74,6 +75,7 @@ void testFindMaterialHistoryByCondition() {
7475
@Test
7576
void testDeleteMaterialHistoryById() {
7677
MaterialHistory param = new MaterialHistory();
78+
param.setId(1);
7779
when(materialHistoryMapper.deleteMaterialHistoryById(1)).thenReturn(1);
7880
when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param);
7981

@@ -84,6 +86,7 @@ void testDeleteMaterialHistoryById() {
8486
@Test
8587
void testUpdateMaterialHistoryById() {
8688
MaterialHistory param = new MaterialHistory();
89+
param.setId(1);
8790
when(materialHistoryMapper.updateMaterialHistoryById(param)).thenReturn(1);
8891
when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param);
8992

@@ -94,6 +97,7 @@ void testUpdateMaterialHistoryById() {
9497
@Test
9598
void testCreateMaterialHistory() {
9699
MaterialHistory param = new MaterialHistory();
100+
param.setId(1);
97101
when(materialHistoryMapper.createMaterialHistory(param)).thenReturn(1);
98102
when(materialHistoryMapper.queryMaterialHistoryById(1)).thenReturn(param);
99103

0 commit comments

Comments
 (0)