diff --git a/src/main/java/com/tinyengine/it/controller/BlockController.java b/src/main/java/com/tinyengine/it/controller/BlockController.java new file mode 100644 index 00000000..203ae844 --- /dev/null +++ b/src/main/java/com/tinyengine/it/controller/BlockController.java @@ -0,0 +1,352 @@ +package com.tinyengine.it.controller; + + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.config.log.SystemControllerLog; +import com.tinyengine.it.mapper.BlockMapper; +import com.tinyengine.it.mapper.TenantMapper; +import com.tinyengine.it.model.dto.BlockDto; +import com.tinyengine.it.model.dto.BlockParamDto; +import com.tinyengine.it.model.entity.*; +import com.tinyengine.it.service.material.BlockService; +import com.tinyengine.it.service.material.TaskRecordService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + *

+ * 区块 + *

+ * + * @author zhangjuncao + * @since 2024-10-30 + */ +@Validated +@RestController +@CrossOrigin +@RequestMapping("/material-center/api") +public class BlockController { + + @Autowired + BlockService blockService; + @Autowired + TenantMapper tenantMapper; + @Autowired + BlockMapper blockMapper; + @Autowired + TaskRecordService taskRecordService; + + /** + * 获取block列表信息 + * + * @param blockParamDto blockParamDto + * @return block列表信息 + */ + @Operation(summary = "获取区块列表信息", + description = "获取区块列表信息", + parameters = { + @Parameter(name = "request", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Block.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取区块列表api") + @GetMapping("/block/list") + public Result> getAllBlocks(@RequestBody BlockParamDto blockParamDto) { + IPage blocksList = blockService.findBlocksByPagetionList(blockParamDto); + List result = blocksList.getRecords(); + return Result.success(result); + } + + /** + * 获取区块列表满足查询条件下的条数 + * + * @param nameCn name + * @param description description + * @return the integer + */ + @Operation(summary = "获取区块列表满足查询条件下的条数", + description = "获取区块列表满足查询条件下的条数", + parameters = { + @Parameter(name = "nameCn", description = "nameCn区块中文名称"), + @Parameter(name = "description", description = "区块描述") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema())), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取区块列表满足查询条件下的条数") + @GetMapping("/block/count") + public Result getCountByCondition(@RequestParam(value = "name_cn", required = false) String nameCn, + @RequestParam(value = "description", required = false) String description) { + // 获取查询条件name_cn、description,若为空查的是全部数据,若不为空按条件查询 + List blocksList = blockMapper.findBlocksByNameCnAndDes(nameCn, description); + return Result.success(blocksList.size()); + } + + /** + * 根据id查询表block信息 + * + * @param id id + * @return BlockDto + */ + @Operation(summary = "查询区块详情", + description = "根据id查询表t_block信息并返回", + parameters = { + @Parameter(name = "id", description = "区块Id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回区块信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Block.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取区块详情api") + @GetMapping("/block/detail/{id}") + public Result getBlocksById(@PathVariable Integer id) { + BlockDto blocks = blockMapper.findBlockAndGroupAndHistoByBlockId(id); + return Result.success(blocks); + } + + /** + * 创建block + * + * @param blockDto the block dto + * @return BlockDto + */ + @Operation(summary = "创建block", + description = "创建block", + parameters = { + @Parameter(name = "map", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Block.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "区块创建api") + @PostMapping("/block/create") + public Result createBlocks(@Valid @RequestBody BlockDto blockDto) { + return blockService.createBlock(blockDto); + } + + + /** + * 删除blocks信息 + * + * @param id id + * @return BlockDto + */ + @Operation(summary = "删除blocks信息", + description = "删除blocks信息", + parameters = { + @Parameter(name = "id", description = "区块id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Block.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "删除blocks信息") + @GetMapping("/block/delete/{id}") + public Result deleteBlocks(@PathVariable Integer id) { + // 页面返回数据 + BlockDto result = blockMapper.findBlockAndGroupAndHistoByBlockId(id); + blockService.deleteBlockById(id); + return Result.success(result); + } + + /** + * 生态中心区块列表分页查询 + * + * @param blockParamDto blockParamDto + * @return BlockDto + */ + @Operation(summary = "生态中心区块列表分页查询", + description = "生态中心区块列表分页查询", + parameters = { + @Parameter(name = "request", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema())), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "生态中心区块列表分页查询api") + @GetMapping("/block") + public Result> find(@RequestBody BlockParamDto blockParamDto) { + IPage blocksIPage = blockService.findBlocksByPagetionList(blockParamDto); + List blocksList = blocksIPage.getRecords(); + List result = new ArrayList<>(); + for (Block blocks : blocksList) { + List blockDto = blockMapper.findBlockAndHistorByBlockId(blocks.getId()); + result.addAll(blockDto); + } + return Result.success(result); + } + + /** + * 查找表中所有tags + * + * @return the list + */ + @Operation(summary = "查找表中所有tags", + description = "查找表中所有tags", + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema())), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "查找表中所有tags") + @GetMapping("/block/tags") + public Result> allTags() { + List allTagsList = blockService.allTags(); + return Result.success(allTagsList); + } + + + /** + * 获取区块列表list2 + * + * @param request request + * @return the ipage + */ + @Operation(summary = "获取区块列表list2", + description = "获取区块列表list2", + parameters = { + @Parameter(name = "request", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema())), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取区块列表api") + @GetMapping("/block/list2") + public Result> getBlocks(@RequestBody Map request) { + IPage BlocksList = blockService.findBlocksByConditionPagetion(request); + return Result.success(BlocksList); + } + + + /** + * 获取所有租户 + * + * @return the list + */ + @Operation(summary = "获取所有租户", + description = "获取所有租户", + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Tenant.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取所有租户api") + @GetMapping("/block/tenants") + public Result> allTenant() { + List tenantsList = tenantMapper.queryAllTenant(); + return Result.success(tenantsList); + } + + + /** + * 获取所有用户 + * + * @return the list + */ + @Operation(summary = "获取所有用户", + description = "获取所有用户", + parameters = { + @Parameter(name = "blocks", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = User.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取所有用户api") + @GetMapping("/block/users") + public Result> allAuthor() { + + List blocksList = blockMapper.queryAllBlock(); + List userList = blockService.getUsers(blocksList); + return Result.success(userList); + } + + /** + * 获取区块列表 + * + * @param map map + * @return the list + */ + @Operation(summary = "获取区块列表", + description = "获取区块列表", + parameters = { + @Parameter(name = "map", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Block.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取区块列表") + @GetMapping("/blocks") + public Result> getAllBlockCategories(@Valid @RequestParam Map map) { + return blockService.listNew(map); + } + + + /** + * 修改block + * + * @param blockDto blockDto + * @return block dto + */ + @Operation(summary = "修改区块", + description = "修改区块", + parameters = { + @Parameter(name = "blockDto", description = "入参对象"), + @Parameter(name = "id", description = "区块id"), + @Parameter(name = "appId", description = "appId") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Block.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "区块修改api") + @PostMapping("/block/update/{id}") + public Result updateBlocks(@Valid @RequestBody BlockDto blockDto, @PathVariable Integer id, @RequestParam Integer appId) { + blockDto.setId(id); + BlockDto blocksResult = blockService.updateBlockById(blockDto); + return Result.success(blocksResult); + } + + +} diff --git a/src/main/java/com/tinyengine/it/controller/BlockGroupController.java b/src/main/java/com/tinyengine/it/controller/BlockGroupController.java new file mode 100644 index 00000000..037291a4 --- /dev/null +++ b/src/main/java/com/tinyengine/it/controller/BlockGroupController.java @@ -0,0 +1,151 @@ +package com.tinyengine.it.controller; + + +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.common.exception.ServiceException; +import com.tinyengine.it.config.log.SystemControllerLog; +import com.tinyengine.it.mapper.BlockGroupMapper; +import com.tinyengine.it.model.dto.BlockGroupDto; +import com.tinyengine.it.model.entity.BlockGroup; +import com.tinyengine.it.service.material.BlockGroupService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; + +/** + *

+ * 区块分组 + *

+ * + * @author zhangjuncao + * @since 2024-10-30 + */ +@Validated +@RestController +@RequestMapping("/material-center/api") +public class BlockGroupController { + @Autowired + BlockGroupService blockGroupService; + @Autowired + BlockGroupMapper blockGroupMapper; + + /** + * 获取区块分组 + * + * @param ids ids + * @param appId appid + * @return the list + */ + @Operation(summary = "获取区块分组", + description = "获取区块分组", + parameters = { + @Parameter(name = "ids", description = "分组ids"), + @Parameter(name = "appId", description = "appId") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema())), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取区块分组") + @GetMapping("/block-groups") + public Result> getAllBlockGroups(@RequestParam(value = "id", required = false) List ids, @RequestParam(value = "app", required = false) Integer appId) { + List blockGroupsListResult = blockGroupService.getBlockGroupByIdsOrAppId(ids, appId); + return Result.success(blockGroupsListResult); + } + + + /** + * 创建区块分组 + * + * @param blockGroup blockGroup + * @return the list + */ + @Operation(summary = "创建区块分组", + description = "创建区块分组", + parameters = { + @Parameter(name = "blockGroups", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = BlockGroup.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "创建区块分组") + @PostMapping("/block-groups/create") + public Result> createBlockGroups(@Valid @RequestBody BlockGroup blockGroup) { + return blockGroupService.createBlockGroup(blockGroup); + } + + /** + * 修改区块分组 + * + * @param id id + * @param blockGroup blockGroup + * @return the list + */ + @Operation(summary = "修改区块分组", + description = "修改区块分组", + parameters = { + @Parameter(name = "id", description = "分组id"), + @Parameter(name = "blockGroups", description = "入参对象") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = BlockGroup.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "修改区块分组") + @PostMapping("/block-groups/update/{id}") + public Result> updateBlockGroups(@Valid @PathVariable Integer id, @RequestBody BlockGroup blockGroup) { + blockGroup.setId(id); + blockGroupService.updateBlockGroupById(blockGroup); + // 页面返回数据显示 + List blockGroupsListResult = blockGroupMapper.getBlockGroupsById(blockGroup.getId()); + return Result.success(blockGroupsListResult); + } + + /** + * 根据id删除区块分组 + * + * @param id id + * @return the list + * @throws ServiceException serviceException + */ + @Operation(summary = "根据id删除区块分组", + description = "根据id删除区块分组", + parameters = { + @Parameter(name = "id", description = "分组id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = BlockGroup.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "根据id删除区块分组") + @GetMapping("/block-groups/delete/{id}") + public Result> deleteBlockGroups(@PathVariable Integer id) throws ServiceException { + BlockGroupDto blockGroups = blockGroupService.findBlockGroupById(id); + if (blockGroups == null) { + return Result.failed(ExceptionEnum.CM009); + } + // 页面返回数据显示 + List blockGroupsListResult = blockGroupMapper.getBlockGroupsById(blockGroups.getId()); + blockGroupService.deleteBlockGroupById(id); + return Result.success(blockGroupsListResult); + } +} diff --git a/src/main/java/com/tinyengine/it/controller/TaskRecordController.java b/src/main/java/com/tinyengine/it/controller/TaskRecordController.java new file mode 100644 index 00000000..1c4d80a8 --- /dev/null +++ b/src/main/java/com/tinyengine/it/controller/TaskRecordController.java @@ -0,0 +1,56 @@ +package com.tinyengine.it.controller; + +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.config.log.SystemControllerLog; +import com.tinyengine.it.model.entity.TaskRecord; +import com.tinyengine.it.service.app.TaskRecordService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +/** + *

+ * 任务记录 + *

+ * + * @author zhangjuncao + * @since 2024-10-30 + */ +@Validated +@RestController +@CrossOrigin +@RequestMapping("/app-center/api") +public class TaskRecordController { + @Autowired + TaskRecordService taskRecordService; + + /** + * 根据id查询task信息 + * + * @param id + * @return task信息 + */ + @Operation(summary = "根据id查询task信息", + description = "根据id查询task信息", + parameters = { + @Parameter(name = "id", description = "task任务主键id") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = TaskRecord.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "根据id查询task信息") + @GetMapping("/tasks/status/{id}") + public Result getTaskRecordById(@PathVariable Integer id) { + TaskRecord taskRecord = taskRecordService.queryTaskRecordById(id); + return Result.success(taskRecord); + } + +} diff --git a/src/main/java/com/tinyengine/it/controller/TaskRecordMaterialController.java b/src/main/java/com/tinyengine/it/controller/TaskRecordMaterialController.java new file mode 100644 index 00000000..d90de706 --- /dev/null +++ b/src/main/java/com/tinyengine/it/controller/TaskRecordMaterialController.java @@ -0,0 +1,86 @@ +package com.tinyengine.it.controller; + + +import com.tinyengine.it.common.enums.Enums; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.config.log.SystemControllerLog; +import com.tinyengine.it.model.entity.TaskRecord; +import com.tinyengine.it.service.material.TaskRecordService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.stream.Collectors; + +/** + *

+ * 任务记录 + *

+ * + * @author zhangjuncao + * @since 2024-10-30 + */ +@Validated +@RestController +@RequestMapping("/material-center/api") +public class TaskRecordMaterialController { + @Autowired + TaskRecordService taskRecordService; + + /** + * 根据id查询task信息 + * + * @param id + * @return task信息 + */ + @GetMapping("/tasks/{id}") + public Result getTaskRecordById(@PathVariable Integer id) { + TaskRecord taskRecord = taskRecordService.queryTaskRecordById(id); + return Result.success(taskRecord); + } + + /** + * 获取任务状态 + * + * @param taskTypeId + * @param uniqueIds + * @return + */ + @Operation(summary = "获取任务状态", + description = "获取任务状态", + parameters = { + @Parameter(name = "taskTypeId", description = "任务类型id"), + @Parameter(name = "uniqueIds", description = "uniqueIds") + }, + responses = { + @ApiResponse(responseCode = "200", description = "返回信息", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = TaskRecord.class))), + @ApiResponse(responseCode = "400", description = "请求失败")} + ) + @SystemControllerLog(description = "获取任务状态api") + @GetMapping("/tasks/status") + public Result> getTasksStatus(@RequestParam String taskTypeId, @RequestParam String uniqueIds) { + + // 使用 queries 上下文支持批量查询。若未指定 taskTypeId,则默认查询物料打包任务状态 + int taskTpyeIdTemp = Integer.parseInt(taskTypeId); + if (taskTpyeIdTemp == 0) { + // 若未指定 taskTypeId,则默认查询物料打包任务状态 + taskTpyeIdTemp = Enums.TaskType.ASSETS_BUILD.getValue(); + + } + List> taskRecords = taskRecordService.status(taskTpyeIdTemp, uniqueIds); + List taskRecordList = taskRecords.stream() + .map(items -> items != null && !items.isEmpty() ? items.get(0) : null) + .filter(task -> task != null) + .collect(Collectors.toList()); + return Result.success(taskRecordList); + } + +} diff --git a/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java b/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java index 127017eb..c470ab8b 100644 --- a/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java +++ b/src/main/java/com/tinyengine/it/mapper/BlockGroupMapper.java @@ -1,9 +1,10 @@ package com.tinyengine.it.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.tinyengine.it.model.dto.BlockGroupDto; import com.tinyengine.it.model.entity.BlockGroup; -import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.*; import java.util.List; @@ -26,7 +27,7 @@ public interface BlockGroupMapper extends BaseMapper { * @param id the id * @return the block group */ - BlockGroup queryBlockGroupById(@Param("id") Integer id); + BlockGroupDto queryBlockGroupById(@Param("id") Integer id); /** * 根据条件查询表t_block_group数据 @@ -34,7 +35,7 @@ public interface BlockGroupMapper extends BaseMapper { * @param blockGroup the block group * @return the list */ - List queryBlockGroupByCondition(BlockGroup blockGroup); + List queryBlockGroupByCondition(BlockGroup blockGroup); /** * 根据主键id删除表t_block_group数据 @@ -67,4 +68,87 @@ public interface BlockGroupMapper extends BaseMapper { * @return the list */ List queryBlockGroupByApp(Integer appId); + + /** + * 根据blockGroupId获取区块分组信息以及关联的app和block信息 + * + * @param blockGroupId the block group id + * @return the list + */ + @Results({ + @Result(column = "app", property = "appId"), + @Result(column = "app", property = "app", + one = @One(select = "com.tinyengine.it.mapper.AppMapper.queryAppById")), + @Result(column = "block_group_id", javaType = List.class, property = "blocks", + many = @Many(select = "com.tinyengine.it.mapper.BlockMapper.findBlocksByBlockGroupId")) + }) + @Select("SELECT bg.*, bs.block_group_id as block_group_id, a.id as app " + + "FROM t_block_group bg " + + "left join t_app a on bg.app_id = a.id " + + "left join t_block bs on bg.id = bs.block_group_id " + + "WHERE bg.id = #{blockGroupId} " + + "GROUP BY bg.id") + List getBlockGroupsById(int blockGroupId); + + + /** + * 根据blockGroupIds获取区块分组信息以及关联的app和block信息 + * + * @param ids the ids + * @return the list + */ + @Results({ + @Result(column = "app", property = "appId"), + @Result(column = "app", property = "app", + one = @One(select = "com.tinyengine.it.mapper.AppMapper.queryAppById")), + @Result(column = "block_group_id", javaType = List.class, property = "blocks", + many = @Many(select = "com.tinyengine.it.mapper.BlockMapper.findBlocksByBlockGroupId")) + }) + @Select("" + ) + List getBlockGroupsByIds(List ids); + + + /** + * 根据appId获取区块分组信息以及关联的app和block信息 + * + * @param appId the app id + * @return the list + */ + @Results({ + @Result(column = "app", property = "appId"), + @Result(column = "app", property = "app", + one = @One(select = "com.tinyengine.it.mapper.AppMapper.queryAppById")), + @Result(column = "block_group_id", javaType = List.class, property = "blocks", + many = @Many(select = "com.tinyengine.it.mapper.BlockMapper.findBlocksByBlockGroupId")) + }) + @Select("select bg.*, bs.block_group_id as block_group_id " + + "from t_block_group bg " + + "left join t_app a on bg.app_id = a.id " + + "left join t_block bs on bg.id = bs.block_group_id " + + "where bg.app_id = #{appId} " + + "GROUP BY bg.id") + List findGroupByAppId(int appId); + + + /** + * 根据区块id查询区块分组信息 + * + * @param blockId the block id + * @return the list + */ + @Select("select * from t_block_group bg " + + "left join t_block tb on bg.id = tb.block_group_id " + + "where tb.id = #{blockId}") + List findBlockGroupByBlockId(Integer blockId); } \ No newline at end of file diff --git a/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java b/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java index 5a7af846..053d6079 100644 --- a/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java +++ b/src/main/java/com/tinyengine/it/mapper/BlockHistoryMapper.java @@ -97,4 +97,14 @@ public interface BlockHistoryMapper extends BaseMapper { ""}) List queryBlockAndVersion(@Param("ids") List ids, @Param("materialHistoryId") Integer materialHistoryId); + + /** + * 根据blockId获取区块历史记录信息 + * + * @param blockId the block id + * @return the list + */ + @Select("select * from t_block_history bh " + + "where bh.ref_id = #{blockId}") + List findBlockHistoriesByBlockId(int blockId); } \ No newline at end of file diff --git a/src/main/java/com/tinyengine/it/mapper/BlockMapper.java b/src/main/java/com/tinyengine/it/mapper/BlockMapper.java index 50253e7d..6287f92f 100644 --- a/src/main/java/com/tinyengine/it/mapper/BlockMapper.java +++ b/src/main/java/com/tinyengine/it/mapper/BlockMapper.java @@ -1,9 +1,10 @@ package com.tinyengine.it.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.tinyengine.it.model.dto.BlockDto; import com.tinyengine.it.model.entity.Block; -import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.*; import java.util.List; @@ -59,4 +60,78 @@ public interface BlockMapper extends BaseMapper { * @return the integer */ Integer createBlock(Block block); + + /** + * 通过区块分组id获取区块信息 + * + * @param blockGroupId the block group id + * @return the list + */ + @Select("select b.* from t_block b " + + "where b.block_group_id = #{blockGroupId}") + List findBlocksByBlockGroupId(int blockGroupId); + + /** + * 根据name或者description查询表t_block信息 + * + * @param nameCn name + * @param description description + * @return the list + */ + List findBlocksByNameCnAndDes(String nameCn, String description); + + /** + * 根据区块id查询区块信息、以及关联的分组信息、区块历史信息 + * + * @param blockId the block id + * @return block dto + */ + @Results({ + @Result(column = "occupier_by", property = "occupierId"), + @Result(column = "block_id", javaType = List.class, property = "groups", + many = @Many(select = "com.tinyengine.it.mapper.BlockGroupMapper.findBlockGroupByBlockId")), + @Result(column = "block_id", javaType = List.class, property = "histories", + many = @Many(select = "com.tinyengine.it.mapper.BlockHistoryMapper.findBlockHistoriesByBlockId")), + @Result(column = "occupier_by", property = "occupier", + one = @One(select = "com.tinyengine.it.mapper.UserMapper.queryUserById")) + }) + @Select("select b.*, b.id as block_id " + + "from t_block b " + + "left join t_block_group bg on b.block_group_id = bg.id " + + "left join t_block_history bh on b.latest_history_id = bh.id " + + "where b.id = #{blockId} " + + "group by b.id") + BlockDto findBlockAndGroupAndHistoByBlockId(Integer blockId); + + + /** + * 根据区块id查询区块信息以及关联的历史信息 + * + * @param blockId the block id + * @return the list + */ + @Results({ + @Result(column = "occupier_by", property = "occupierId"), + @Result(column = "block_id", javaType = List.class, property = "histories", + many = @Many(select = "com.tinyengine.it.mapper.BlockHistoryMapper.findBlockHistoriesByBlockId")), + @Result(column = "occupier_by", property = "occupier", + one = @One(select = "com.tinyengine.it.mapper.UserMapper.queryUserById")) + }) + @Select("select b.*,bcbcb.block_id as block_categories_blocks_id,bsh.block_id as block_histories_block_id " + + "from t_block b " + + "left join t_block_history bh on b.latest_history_id = bh.id " + + "where b.id = #{blockId} " + + "group by b.id") + List findBlockAndHistorByBlockId(Integer blockId); + + + /** + * 通过区块分组id获取区块信息 + * + * @param appId the app id + * @return the list + */ + + List findBlocksByBlockGroupIdAppId(int appId); + } \ No newline at end of file diff --git a/src/main/java/com/tinyengine/it/mapper/TaskRecordMapper.java b/src/main/java/com/tinyengine/it/mapper/TaskRecordMapper.java index 49c6cc1e..743031c3 100644 --- a/src/main/java/com/tinyengine/it/mapper/TaskRecordMapper.java +++ b/src/main/java/com/tinyengine/it/mapper/TaskRecordMapper.java @@ -59,4 +59,22 @@ public interface TaskRecordMapper extends BaseMapper { * @return the integer */ Integer createTaskRecord(TaskRecord taskRecord); + + /** + * 根据taskTypeId、uniqueId按照created_at降序查询表task_record信息 + * + * @param taskTypeId the task type id + * @param uniqueId the unique id + * @return the list + */ + List findTaskRecordByTaskIdAndUniqueid(@Param("taskTypeId") Integer taskTypeId, @Param("uniqueId") Integer uniqueId); + + /** + * 根据taskTypeId、uniqueId按照id降序查询表task_record一条信息 + * + * @param taskTypeId the task type id + * @param uniqueId the unique id + * @return the task record + */ + TaskRecord getUnfinishedTask(@Param("taskTypeId") Integer taskTypeId, @Param("uniqueId") Integer uniqueId); } \ No newline at end of file diff --git a/src/main/java/com/tinyengine/it/mapper/UserMapper.java b/src/main/java/com/tinyengine/it/mapper/UserMapper.java index 0555b7af..c0a0fe93 100644 --- a/src/main/java/com/tinyengine/it/mapper/UserMapper.java +++ b/src/main/java/com/tinyengine/it/mapper/UserMapper.java @@ -59,4 +59,12 @@ public interface UserMapper extends BaseMapper { * @return the integer */ Integer createUser(User user); + + /** + * 通过ids获取用户列表信息 + * + * @param ids the ids + * @return the list + */ + List selectUsersByIds(List ids); } \ No newline at end of file diff --git a/src/main/java/com/tinyengine/it/model/dto/BlockDto.java b/src/main/java/com/tinyengine/it/model/dto/BlockDto.java new file mode 100644 index 00000000..13221e73 --- /dev/null +++ b/src/main/java/com/tinyengine/it/model/dto/BlockDto.java @@ -0,0 +1,132 @@ +package com.tinyengine.it.model.dto; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tinyengine.it.common.base.BaseEntity; +import com.tinyengine.it.model.entity.BlockGroup; +import com.tinyengine.it.model.entity.BlockHistory; +import com.tinyengine.it.model.entity.User; +import com.tinyengine.it.config.handler.ListTypeHandler; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Data +public class BlockDto extends BaseEntity { + private static final long serialVersionUID = 1L; + + @Schema(name = "label", description = "区块显示名称,严格大小写格式") + private String label; + + @Schema(name = "name", description = "区块名称") + @JsonProperty("name_cn") + private String name; + + @Schema(name = "framework", description = "技术栈") + private String framework; + + @TableField(typeHandler = JacksonTypeHandler.class) + @Schema(name = "content", description = "区块内容") + private Map content; + + @TableField(typeHandler = JacksonTypeHandler.class) + @Schema(name = "assets", description = "构建资源") + private Map assets; + + @JsonProperty("last_build_info") + @TableField(typeHandler = JacksonTypeHandler.class) + @Schema(name = "lastBuildInfo", description = "最新一次构建信息") + private Map lastBuildInfo; + + @Schema(name = "description", description = "描述") + private String description; + + @Schema(name = "tags", description = "标签") + @TableField(typeHandler = ListTypeHandler.class) + private List tags; + + @Schema(name = "latestVersion", description = "当前历史记录表最新版本") + @JsonProperty("latest_version") + private String latestVersion; + + @Schema(name = "latestHistoryId", description = "当前历史记录表ID") + @JsonProperty("latest_history_id") + private Integer latestHistoryId; + + @Schema(name = "screenshot", description = "截屏") + private String screenshot; + + @Schema(name = "path", description = "区块路径") + private String path; + + @Schema(name = "occupierId", description = "当前锁定人id") + private String occupierId; + + @Schema(name = "isOfficial", description = "是否是官方") + @JsonProperty("is_official") + private Boolean isOfficial; + + @Schema(name = "public", description = "公开状态:0,1,2") + @JsonProperty("public") + private Integer publicStatus; + + @Schema(name = "isDefault", description = "是否是默认") + @JsonProperty("is_default") + private Boolean isDefault; + + @Schema(name = "tinyReserved", description = "是否是tiny专有") + @JsonProperty("tiny_reserved") + private Boolean tinyReserved; + + @Schema(name = "npmName", description = "npm包名") + @JsonProperty("npm_name") + private String npmName; + + @Schema(name = "i18n", description = "国际化内容") + private String i18n; + + @Schema(name = "platformId", description = "设计器ID") + @JsonProperty("platform_id") + private Integer platformId; + + @Schema(name = "appId", description = "创建区块时所在appId") + @JsonProperty("created_app") + private Integer appId; + + @Schema(name = "contentBlocks", description = "*设计预留字段用途*") + @JsonProperty("content_blocks") + private String contentBlocks; + + @Schema(name = "blockGroupId", description = "区块分组id,关联t_block_group表id") + @JsonProperty("block_group_id") + private Integer blockGroupId; + + @JsonProperty("occupier") + @Schema(name = "occupierBy", description = "当前锁定人") + private User occupier; + + @TableField(exist = false) + private List public_scope_tenants = new ArrayList<>(); + + @TableField(exist = false) + @Schema(name = "groups", type = " List", description = "区块分组") + List groups = new ArrayList<>(); + + @TableField(exist = false) + @Schema(name = "histories", type = " List", description = "区块历史") + List histories = new ArrayList<>(); + + @JsonProperty("public") + public Integer getPublic() { + return this.publicStatus; + } +} diff --git a/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java b/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java new file mode 100644 index 00000000..1fb4ce42 --- /dev/null +++ b/src/main/java/com/tinyengine/it/model/dto/BlockGroupDto.java @@ -0,0 +1,44 @@ +package com.tinyengine.it.model.dto; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.tinyengine.it.common.base.BaseEntity; +import com.tinyengine.it.model.entity.App; +import com.tinyengine.it.model.entity.Block; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Data +@TableName("t_block_group") +@Schema(name = "BlockGroup对象", description = "返回对象") +public class BlockGroupDto extends BaseEntity { + + private static final long serialVersionUID = 1L; + + @Schema(name = "name", description = "分组名称") + private String name; + + @Schema(name = "appId", description = "创建分组所在app") + @JsonProperty("app_id") + private Integer appId; + + @Schema(name = "platformId", description = "设计器id") + @JsonProperty("platform_id") + private Integer platformId; + + @Schema(name = "description", description = "分组描述") + private String description; + + @JsonProperty("app") + private App app; + + @TableField(exist = false) + @Schema(name = "blocks", description = "区块") + private List blocks = new ArrayList<>(); + +} \ No newline at end of file diff --git a/src/main/java/com/tinyengine/it/model/dto/BlockParamDto.java b/src/main/java/com/tinyengine/it/model/dto/BlockParamDto.java new file mode 100644 index 00000000..c1744218 --- /dev/null +++ b/src/main/java/com/tinyengine/it/model/dto/BlockParamDto.java @@ -0,0 +1,20 @@ +package com.tinyengine.it.model.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class BlockParamDto { + private String appId; + private String sort; + + @JsonProperty("name_cn") + private String name; + + private String description; + private String label; + private String limit; + private String start; + + +} diff --git a/src/main/java/com/tinyengine/it/model/dto/OperateI18nBatchEntries.java b/src/main/java/com/tinyengine/it/model/dto/OperateI18nBatchEntries.java index 2eee77e7..ccb467d8 100644 --- a/src/main/java/com/tinyengine/it/model/dto/OperateI18nBatchEntries.java +++ b/src/main/java/com/tinyengine/it/model/dto/OperateI18nBatchEntries.java @@ -1,5 +1,6 @@ package com.tinyengine.it.model.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.util.List; @@ -13,5 +14,6 @@ public class OperateI18nBatchEntries { private List entries; private String host; + @JsonProperty("host_type") private String hostType; } diff --git a/src/main/java/com/tinyengine/it/model/entity/Block.java b/src/main/java/com/tinyengine/it/model/entity/Block.java index 505f890a..f1d8647a 100644 --- a/src/main/java/com/tinyengine/it/model/entity/Block.java +++ b/src/main/java/com/tinyengine/it/model/entity/Block.java @@ -6,10 +6,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.tinyengine.it.common.base.BaseEntity; +import com.tinyengine.it.config.handler.ListTypeHandler; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -29,6 +32,7 @@ public class Block extends BaseEntity { private String label; @Schema(name = "name", description = "区块名称") + @JsonProperty("name_cn") private String name; @Schema(name = "framework", description = "技术栈") @@ -51,7 +55,8 @@ public class Block extends BaseEntity { private String description; @Schema(name = "tags", description = "标签") - private String tags; + @TableField(typeHandler = ListTypeHandler.class) + private List tags; @Schema(name = "latestVersion", description = "当前历史记录表最新版本") @JsonProperty("latest_version") @@ -68,6 +73,7 @@ public class Block extends BaseEntity { private String path; @Schema(name = "occupierBy", description = "当前锁定人id") + @JsonProperty("occupier") private String occupierBy; @Schema(name = "isOfficial", description = "是否是官方") @@ -98,7 +104,7 @@ public class Block extends BaseEntity { private Integer platformId; @Schema(name = "appId", description = "创建区块时所在appId") - @JsonProperty("app_id") + @JsonProperty("created_app") private Integer appId; @Schema(name = "contentBlocks", description = "*设计预留字段用途*") @@ -108,4 +114,21 @@ public class Block extends BaseEntity { @Schema(name = "blockGroupId", description = "区块分组id,关联t_block_group表id") @JsonProperty("block_group_id") private Integer blockGroupId; + + @TableField(exist = false) + private List public_scope_tenants = new ArrayList<>(); + + @TableField(exist = false) + private Integer histories_length = 0; + + @TableField(exist = false) + private Boolean is_published; + + public Block(Map content, String label) { + super(); + } + + public Block() { + super(); + } } diff --git a/src/main/java/com/tinyengine/it/model/entity/BlockGroup.java b/src/main/java/com/tinyengine/it/model/entity/BlockGroup.java index 45917129..55cf679c 100644 --- a/src/main/java/com/tinyengine/it/model/entity/BlockGroup.java +++ b/src/main/java/com/tinyengine/it/model/entity/BlockGroup.java @@ -1,6 +1,7 @@ package com.tinyengine.it.model.entity; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonProperty; import com.tinyengine.it.common.base.BaseEntity; import io.swagger.v3.oas.annotations.media.Schema; @@ -24,6 +25,7 @@ public class BlockGroup extends BaseEntity { private String name; @Schema(name = "appId", description = "创建分组所在app") + @JsonProperty("app") private Integer appId; @Schema(name = "platformId", description = "设计器id") diff --git a/src/main/java/com/tinyengine/it/service/material/BlockGroupService.java b/src/main/java/com/tinyengine/it/service/material/BlockGroupService.java index ac4235b2..4b5b1aab 100644 --- a/src/main/java/com/tinyengine/it/service/material/BlockGroupService.java +++ b/src/main/java/com/tinyengine/it/service/material/BlockGroupService.java @@ -1,5 +1,7 @@ package com.tinyengine.it.service.material; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.model.dto.BlockGroupDto; import com.tinyengine.it.model.entity.BlockGroup; import org.apache.ibatis.annotations.Param; @@ -23,9 +25,9 @@ public interface BlockGroupService { * 根据主键id查询表t_block_group信息 * * @param id the id - * @return the block group + * @return the block group dto */ - BlockGroup findBlockGroupById(@Param("id") Integer id); + BlockGroupDto findBlockGroupById(@Param("id") Integer id); /** * 根据条件查询表t_block_group信息 @@ -33,7 +35,7 @@ public interface BlockGroupService { * @param blockGroup the block group * @return the list */ - List findBlockGroupByCondition(BlockGroup blockGroup); + List findBlockGroupByCondition(BlockGroup blockGroup); /** * 根据主键id删除t_block_group数据 @@ -55,7 +57,16 @@ public interface BlockGroupService { * 新增表t_block_group数据 * * @param blockGroup the block group - * @return the integer + * @return the result + */ + Result> createBlockGroup(BlockGroup blockGroup); + + /** + * 根据ids或者appId获取区块信息 + * + * @param ids ids + * @param appId the app id + * @return the list */ - Integer createBlockGroup(BlockGroup blockGroup); + List getBlockGroupByIdsOrAppId(List ids, Integer appId); } diff --git a/src/main/java/com/tinyengine/it/service/material/BlockService.java b/src/main/java/com/tinyengine/it/service/material/BlockService.java index b65a0a4b..332f28eb 100644 --- a/src/main/java/com/tinyengine/it/service/material/BlockService.java +++ b/src/main/java/com/tinyengine/it/service/material/BlockService.java @@ -1,10 +1,16 @@ package com.tinyengine.it.service.material; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.model.dto.BlockDto; +import com.tinyengine.it.model.dto.BlockParamDto; import com.tinyengine.it.model.entity.Block; +import com.tinyengine.it.model.entity.User; import org.apache.ibatis.annotations.Param; import java.util.List; +import java.util.Map; /** * The interface Block service. @@ -46,16 +52,57 @@ public interface BlockService { /** * 根据主键id更新表t_block信息 * - * @param block the block - * @return the integer + * @param blockDto the block dto + * @return the BlockDto */ - Integer updateBlockById(Block block); + BlockDto updateBlockById(BlockDto blockDto); /** * 新增表t_block数据 * - * @param block the block - * @return the integer + * @param blockDto the block dto + * @return the result + */ + Result createBlock(BlockDto blockDto); + + /** + * 区块分页查询 + * + * @param blockParamDto blockParamDto + * @return the ipage + */ + IPage findBlocksByPagetionList(BlockParamDto blockParamDto); + + /** + * 查找表中所有tags + * + * @return the list + */ + List allTags(); + + + /** + * 根据条件进行分页查询 + * + * @param request request + * @return the ipage + */ + IPage findBlocksByConditionPagetion(Map request); + + /** + * 获取用户 + * + * @param blocksList the block list + * @return the list + */ + List getUsers(List blocksList); + + + /** + * 获取区块 + * + * @param map the map + * @return the list */ - Integer createBlock(Block block); + Result> listNew(Map map); } diff --git a/src/main/java/com/tinyengine/it/service/material/TaskRecordService.java b/src/main/java/com/tinyengine/it/service/material/TaskRecordService.java new file mode 100644 index 00000000..ffa5ab36 --- /dev/null +++ b/src/main/java/com/tinyengine/it/service/material/TaskRecordService.java @@ -0,0 +1,43 @@ +package com.tinyengine.it.service.material; + +import com.tinyengine.it.model.entity.TaskRecord; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface TaskRecordService { + + + /** + * 根据主键id查询表task_record信息 + * + * @param id id + */ + TaskRecord queryTaskRecordById(@Param("id") Integer id); + + + /** + * 新增表task_record数据 + * + * @param taskRecord the task record + */ + Integer createTaskRecord(TaskRecord taskRecord); + + /** + * 获取任务状态 + * + * @param taskTypeId the task type id + * @param uniqueIds the unique ids + * @return task record + */ + List> status(int taskTypeId, String uniqueIds); + + /** + * 获取未完成任务 + * + * @param taskTypeId the task type id + * @param uniqueIds the unique ids + * @return task record + */ + TaskRecord getUnfinishedTask(int taskTypeId, int uniqueIds); +} diff --git a/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java b/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java index bfe9425b..21f994fe 100644 --- a/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java +++ b/src/main/java/com/tinyengine/it/service/material/impl/BlockGroupServiceImpl.java @@ -1,6 +1,9 @@ package com.tinyengine.it.service.material.impl; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; import com.tinyengine.it.mapper.BlockGroupMapper; +import com.tinyengine.it.model.dto.BlockGroupDto; import com.tinyengine.it.model.entity.BlockGroup; import com.tinyengine.it.service.material.BlockGroupService; @@ -10,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -40,7 +44,7 @@ public List findAllBlockGroup() { * @return block group */ @Override - public BlockGroup findBlockGroupById(@Param("id") Integer id) { + public BlockGroupDto findBlockGroupById(@Param("id") Integer id) { return blockGroupMapper.queryBlockGroupById(id); } @@ -51,7 +55,7 @@ public BlockGroup findBlockGroupById(@Param("id") Integer id) { * @return block group */ @Override - public List findBlockGroupByCondition(BlockGroup blockGroup) { + public List findBlockGroupByCondition(BlockGroup blockGroup) { return blockGroupMapper.queryBlockGroupByCondition(blockGroup); } @@ -84,7 +88,37 @@ public Integer updateBlockGroupById(BlockGroup blockGroup) { * @return insert number */ @Override - public Integer createBlockGroup(BlockGroup blockGroup) { - return blockGroupMapper.createBlockGroup(blockGroup); + public Result> createBlockGroup(BlockGroup blockGroup) { + List blockGroupsList = blockGroupMapper.queryBlockGroupByCondition(blockGroup); + if (blockGroupsList.isEmpty()) { + blockGroupMapper.createBlockGroup(blockGroup); + } else { + return Result.failed(ExceptionEnum.CM003); + } + // 页面返回数据显示 + List blockGroupsListResult = blockGroupMapper.getBlockGroupsById(blockGroup.getId()); + return Result.success(blockGroupsListResult); + } + + /** + * 根据ids或者appId获取区块信息 + * + * @param ids ids + * @param appId the app id + * @return the list + */ + @Override + public List getBlockGroupByIdsOrAppId(List ids, Integer appId) { + // 此接收到的两个参数不一定同时存在 + BlockGroup blockGroups = new BlockGroup(); + List blockGroupsListResult = new ArrayList<>(); + if (ids != null) { + blockGroupsListResult = blockGroupMapper.getBlockGroupsByIds(ids); + } + if (appId != null) { + blockGroupsListResult = blockGroupMapper.findGroupByAppId(appId); + } + + return blockGroupsListResult; } } diff --git a/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java b/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java index d217c5cb..95836b4e 100644 --- a/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java +++ b/src/main/java/com/tinyengine/it/service/material/impl/BlockServiceImpl.java @@ -1,25 +1,43 @@ package com.tinyengine.it.service.material.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.tinyengine.it.common.base.Result; +import com.tinyengine.it.common.exception.ExceptionEnum; +import com.tinyengine.it.config.log.SystemServiceLog; +import com.tinyengine.it.mapper.AppMapper; +import com.tinyengine.it.mapper.BlockHistoryMapper; import com.tinyengine.it.mapper.BlockMapper; +import com.tinyengine.it.mapper.UserMapper; +import com.tinyengine.it.model.dto.BlockDto; +import com.tinyengine.it.model.dto.BlockParamDto; +import com.tinyengine.it.model.entity.App; import com.tinyengine.it.model.entity.Block; +import org.springframework.beans.BeanUtils; +import com.tinyengine.it.model.entity.BlockHistory; +import com.tinyengine.it.model.entity.User; +import com.tinyengine.it.common.enums.Enums; import com.tinyengine.it.service.material.BlockService; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Param; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.*; +import java.util.*; +import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * The type Block service. @@ -31,6 +49,12 @@ public class BlockServiceImpl implements BlockService { @Autowired private BlockMapper blockMapper; + @Autowired + private UserMapper userMapper; + @Autowired + private AppMapper appMapper; + + private static final Logger logger = LoggerFactory.getLogger(BlockServiceImpl.class); /** * 查询表t_block所有数据 @@ -78,23 +102,66 @@ public Integer deleteBlockById(@Param("id") Integer id) { /** * 根据主键id更新表t_block数据 * - * @param block block - * @return execute success data number + * @param blockDto blockDto + * @return blockDto */ @Override - public Integer updateBlockById(Block block) { - return blockMapper.updateBlockById(block); + public BlockDto updateBlockById(BlockDto blockDto) { + // public 不是部分公开, 则public_scope_tenants为空数组 + // 把前端传参赋值给实体 + Block blocks = new Block(); + BeanUtils.copyProperties(blockDto, blocks); + blocks.setOccupierBy(String.valueOf(1)); //todo 获取用户信息 + // 处理区块截图 + if (!blockDto.getScreenshot().isEmpty() && !blockDto.getLabel().isEmpty()) { + // 图片上传,此处给默认值空字符 + blocks.setScreenshot(""); + } + + // todo 更新区块时去获取关联的分组id,进而去更新分组字段 + List groups = blockDto.getGroups().stream() + .filter(obj -> obj instanceof Integer) // 过滤出 Integer 类型的对象 + .map(obj -> (Integer) obj) // 转换为 Integer 类型 + .collect(Collectors.toList()); // 收集为 List; + if (!groups.isEmpty()) { + int groupId = groups.get(0); + blocks.setBlockGroupId(groupId); + } + blockMapper.updateBlockById(blocks); + return blockMapper.findBlockAndGroupAndHistoByBlockId(blockDto.getId()); } /** * 新增表t_block数据 * - * @param block block - * @return execute success data number + * @param blockDto the block dto + * @return execute success the result */ @Override - public Integer createBlock(Block block) { - return blockMapper.createBlock(block); + public Result createBlock(BlockDto blockDto) { + // 对接收到的参数occupier为对应的一个对象,进行特殊处理并重新赋值 + Block blocks = new Block(); + if (blockDto.getOccupier() != null) { + blocks.setOccupierBy(String.valueOf(blockDto.getOccupier().getId())); + } + BeanUtils.copyProperties(blockDto, blocks); + blocks.setIsDefault(false); + blocks.setIsOfficial(false); + blocks.setPlatformId(1); //新建区块给默认值 + // 判断创建区块时是否关联了分组,如果有,插入区块分类关联表数据 + // todo 待前端设计更改成分组,区块表里直接有分组字段,只需把分组字段做更新赋值 + List groups = blockDto.getGroups(); + if (!groups.isEmpty() && groups.get(0) instanceof Integer) { + Integer groupId = (Integer) groups.get(0); // 强制类型转换 + blocks.setBlockGroupId(groupId); + } + int result = blockMapper.createBlock(blocks); + if (result < 1) { + return Result.failed(ExceptionEnum.CM001); + } + int id = blocks.getId(); + BlockDto blocksResult = blockMapper.findBlockAndGroupAndHistoByBlockId(id); + return Result.success(blocksResult); } /** @@ -207,4 +274,190 @@ public void traverseBlocks(String content, List block) throws JsonProces public boolean isBlock(Map schema) { return schema != null && "Block".equals(schema.get("componentType")); } + + /** + * 生态中心区块列表分页查询 + * + * @param blockParamDto blockParamDto + * @return block + */ + @Override + public IPage findBlocksByPagetionList(BlockParamDto blockParamDto) { + String appId = blockParamDto.getAppId(); + // 如果 appId 存在并且不匹配指定的正则表达式,则删除它 + if (appId != null && !Pattern.matches("^[1-9]+[0-9]*$", appId)) { + blockParamDto.setAppId(null);//设置成null达到map中remove的效果 + } + // 获取查询条件 + String sort = blockParamDto.getSort(); // nodejs中页面传参"updated_at:DESC" + String nameCn = blockParamDto.getName(); + String description = blockParamDto.getDescription(); + String label = blockParamDto.getLabel(); + int limit = blockParamDto.getLimit() != null ? Integer.parseInt(blockParamDto.getLimit()) : 0; + int start = blockParamDto.getStart() != null ? Integer.parseInt(blockParamDto.getStart()) : 0; + // 把start、limit转为java分页的pageNum、pageSize + int pageNum = start == 0 && limit == 0 ? 1 : (start / limit) + 1; + int pageSize = limit == 0 ? 10 : limit; + + QueryWrapper queryWrapper = new QueryWrapper<>(); + if (StringUtils.isNotEmpty(nameCn)) { + queryWrapper.like("name", nameCn); + } + if (StringUtils.isNotEmpty(description)) { + queryWrapper.or().like("description", description); + } + if (StringUtils.isNotEmpty(label)) { + queryWrapper.or().eq("label", label); + } + + // 获取是按升序还是降序排列 + if (sort != null) { + String[] temp = sort.split(":"); + String sortOrder = temp[1]; + if ("ASC".equalsIgnoreCase(sortOrder)) { + queryWrapper.orderByAsc("created_time"); + } else if ("DESC".equalsIgnoreCase(sortOrder)) { + queryWrapper.orderByDesc("last_updated_time"); + } + } + + Page page = new Page<>(pageNum, pageSize); + return blockMapper.selectPage(page, queryWrapper); + } + + /** + * 查找表中所有tags + * + * @return list + */ + @SystemServiceLog(description = "allTags 查找表中所有tags 实现类") + @Override + public List allTags() { + QueryWrapper queryWrapper = new QueryWrapper<>(); + ObjectMapper objectMapper = new ObjectMapper(); + queryWrapper.select("tags").isNotNull("tags"); + List allBlocksList = blockMapper.selectList(queryWrapper); + List allTagsList = allBlocksList.stream() + .flatMap(blocks -> blocks.getTags().stream()) + .collect(Collectors.toList()); + + return allTagsList; + } + + /** + * 根据条件进行分页查询 + * + * @param request request + * @return the ipage + */ + @Override + public IPage findBlocksByConditionPagetion(Map request) { + String public_scope_mode = request.get("public_scope_mode"); + if (public_scope_mode != null) { + request.remove("public_scope_mode"); + } + + // 获取查询条件 + String nameCn = request.get("name_cn"); + String description = request.get("description"); + + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.and(wrapper -> + wrapper.like(StringUtils.isNotEmpty(nameCn), "name", nameCn) + .or() + .like(StringUtils.isNotEmpty(description), "description", description) + ); + List blocksList = blockMapper.selectList(queryWrapper); + Page page = new Page<>(1, blocksList.size()); + return blockMapper.selectPage(page, queryWrapper); + } + + /** + * 获取用户 + * + * @param blocksList the block list + * @return the list + */ + @Override + public List getUsers(List blocksList) { + Set userSet = new HashSet<>(); + + // 提取 createdBy 列表中的唯一值 + blocksList.forEach(item -> { + if (item.getCreatedBy() != null && !userSet.contains(item.getCreatedBy())) { + userSet.add(String.valueOf(item.getCreatedBy())); + } + }); + + List userIdsList = new ArrayList<>(userSet); + + // 模拟执行 SQL 查询并返回结果 + List users = userMapper.selectUsersByIds(userIdsList); + // return (data && data[0]) || []; + return users; + } + + /** + * 获取区块 + * + * @param map the map + * @return the list + */ + @Override + public Result> listNew(Map map) { + int groupId = 0; + int appId = 0; + if (map.get("groupId") != null) { + groupId = Integer.parseInt(map.get("groupId")); + } + if (map.get("appId") != null) { + appId = Integer.parseInt(map.get("appId")); + } + App apps = appMapper.queryAppById(appId); + if (groupId != 0) { + if (!apps.getId().equals(appId)) { + return Result.failed(ExceptionEnum.CM206); + } + } + List blocksList = new ArrayList<>(); + // 如果有 groupId, 只查group下的block + if (groupId != 0) { + blocksList = blockMapper.findBlocksByBlockGroupId(groupId); + return Result.success(blocksList); + } + // 如果没有 groupId + // 1. 查询和 app 相关的所有 group + // 2. 组合 groups 下的所有 block + // 3. 查询个人创建的 blocks + // 4. 将个人的和 groups 下的 blocks 合并去重 + blocksList = blockMapper.findBlocksByBlockGroupIdAppId(appId); + List appBlocks = blocksList; + // 通过createBy查询区块表数据 + Block blocks = new Block(); + List personalBlocks = queryBlockByCondition(blocks); + List retBlocks = new ArrayList<>(); + // 合并 personalBlocks 和 appBlocks 数组 + List combinedBlocks = Stream.concat(personalBlocks.stream(), appBlocks.stream()) + .collect(Collectors.toList()); + // 遍历合并后的数组,检查是否存在具有相同 id 的元素 + combinedBlocks.forEach(block -> { + boolean isFind = retBlocks.stream() + .anyMatch(retBlock -> Objects.equals(retBlock.getId(), block.getId())); + if (!isFind) { + retBlocks.add(block); + } + }); + // 给is_published赋值 + List result = retBlocks.stream() + .map(b -> { + boolean isPublished = b.getLastBuildInfo() != null && b.getLastBuildInfo().get("result") instanceof Boolean + ? (Boolean) b.getLastBuildInfo().get("result") : Boolean.FALSE; + b.setIs_published(isPublished); + return b; + }) + .collect(Collectors.toList()); + + return Result.success(result); + } + } diff --git a/src/main/java/com/tinyengine/it/service/material/impl/TaskRecordMaterialServiceImpl.java b/src/main/java/com/tinyengine/it/service/material/impl/TaskRecordMaterialServiceImpl.java new file mode 100644 index 00000000..27648ae3 --- /dev/null +++ b/src/main/java/com/tinyengine/it/service/material/impl/TaskRecordMaterialServiceImpl.java @@ -0,0 +1,81 @@ +package com.tinyengine.it.service.material.impl; + + +import com.tinyengine.it.config.log.SystemServiceLog; +import com.tinyengine.it.common.exception.ServiceException; +import com.tinyengine.it.mapper.TaskRecordMapper; +import com.tinyengine.it.model.entity.TaskRecord; +import com.tinyengine.it.service.material.TaskRecordService; +import org.apache.ibatis.annotations.Param; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +@Service +public class TaskRecordMaterialServiceImpl implements TaskRecordService { + + @Autowired + TaskRecordMapper taskRecordMapper; + + + /** + * 根据主键id查询表task_record信息 + * + * @param id id + */ + @Override + public TaskRecord queryTaskRecordById(@Param("id") Integer id) throws ServiceException { + return taskRecordMapper.queryTaskRecordById(id); + } + + + /** + * 新增表task_record数据 + * + * @param taskRecord the task record + */ + @Override + public Integer createTaskRecord(TaskRecord taskRecord) throws ServiceException { + return taskRecordMapper.createTaskRecord(taskRecord); + } + + /** + * 获取任务状态 + * + * @param taskTypeId the task type id + * @param uniqueIds the unique ids + * @return task record + */ + @SystemServiceLog(description = "status 获取任务状态 实现类") + @Override + public List> status(int taskTypeId, String uniqueIds) { + String[] idArray = uniqueIds.split(","); + List uniqueIdsList = Arrays.stream(idArray).map(Integer::parseInt).collect(Collectors.toList()); + + List>> queryPromises = uniqueIdsList.stream() + .map(uniqueId -> CompletableFuture.supplyAsync(() -> { + // 根据taskTypeId、uniqueId、created_at按照条件查询 + return taskRecordMapper.findTaskRecordByTaskIdAndUniqueid(taskTypeId, uniqueId); + })) + .collect(Collectors.toList()); + return queryPromises.stream() + .map(CompletableFuture::join) + .collect(Collectors.toList()); + } + + /** + * 获取未完成任务状态 + * + * @param taskTypeId the task type id + * @param uniqueIds the unique ids + * @return task record + */ + @Override + public TaskRecord getUnfinishedTask(int taskTypeId, int uniqueIds) { + return taskRecordMapper.getUnfinishedTask(taskTypeId, uniqueIds); + } +} diff --git a/src/main/resources/mappers/BlockMapper.xml b/src/main/resources/mappers/BlockMapper.xml index 1b66d1d7..81b04f63 100644 --- a/src/main/resources/mappers/BlockMapper.xml +++ b/src/main/resources/mappers/BlockMapper.xml @@ -57,7 +57,7 @@ AND is_official = #{isOfficial} - + AND `public` = #{publicStatus} @@ -148,7 +148,7 @@ is_official = #{isOfficial}, - + `public` = #{publicStatus}, @@ -258,6 +258,31 @@ + + + + + + DELETE @@ -279,64 +304,64 @@ INSERT INTO t_block ( id - , label - , name - , framework - , content - , assets - , last_build_info - , description - , tags - , latest_version - , latest_history_id - , screenshot - , path - , occupier_by - , is_official - , `public` - , is_default - , tiny_reserved - , npm_name - , i18n - , platform_id - , app_id - , content_blocks - , block_group_id - , created_by - , last_updated_by - , created_time - , last_updated_time - , tenant_id - , site_id) + , label + , name + , framework + , content + , assets + , last_build_info + , description + , tags + , latest_version + , latest_history_id + , screenshot + , path + , occupier_by + , is_official + , `public` + , is_default + , tiny_reserved + , npm_name + , i18n + , platform_id + , app_id + , content_blocks + , block_group_id + , created_by + , last_updated_by + , created_time + , last_updated_time + , tenant_id + , site_id) VALUES ( #{id} - , #{label} - , #{name} - , #{framework} - , #{content} - , #{assets} - , #{lastBuildInfo} - , #{description} - , #{tags} - , #{latestVersion} - , #{latestHistoryId} - , #{screenshot} - , #{path} - , #{occupierBy} - , #{isOfficial} - , #{publicStatus} - , #{isDefault} - , #{tinyReserved} - , #{npmName} - , #{i18n} - , #{platformId} - , #{appId} - , #{contentBlocks} - , #{blockGroupId} - , #{createdBy} - , #{lastUpdatedBy} - , #{createdTime} - , #{lastUpdatedTime} - , #{tenantId} - , #{siteId}) + , #{label} + , #{name} + , #{framework} + , #{content} + , #{assets} + , #{lastBuildInfo} + , #{description} + , #{tags} + , #{latestVersion} + , #{latestHistoryId} + , #{screenshot} + , #{path} + , #{occupierBy} + , #{isOfficial} + , #{publicStatus} + , #{isDefault} + , #{tinyReserved} + , #{npmName} + , #{i18n} + , #{platformId} + , #{appId} + , #{contentBlocks} + , #{blockGroupId} + , #{createdBy} + , #{lastUpdatedBy} + , #{createdTime} + , #{lastUpdatedTime} + , #{tenantId} + , #{siteId}) diff --git a/src/main/resources/mappers/TaskRecordMapper.xml b/src/main/resources/mappers/TaskRecordMapper.xml index 27da8a5f..58671e80 100644 --- a/src/main/resources/mappers/TaskRecordMapper.xml +++ b/src/main/resources/mappers/TaskRecordMapper.xml @@ -161,6 +161,25 @@ + + + + + + DELETE diff --git a/src/main/resources/mappers/UserMapper.xml b/src/main/resources/mappers/UserMapper.xml index 7c3ce198..226a512a 100644 --- a/src/main/resources/mappers/UserMapper.xml +++ b/src/main/resources/mappers/UserMapper.xml @@ -117,6 +117,16 @@ WHERE id=#{id} + + +