From 55be6ade29b55739b1f5439425489b461ea9937c Mon Sep 17 00:00:00 2001 From: iteaj Date: Fri, 6 Jun 2025 17:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=A7=E5=B1=8F=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/sql/patch.sql | 5 +- .../spi/file/LocalUploadService.java | 4 +- .../iboot/plugin/iotview/IotViewResult.java | 17 +---- .../iotview/controller/ProjectController.java | 62 ++++++++++++++++--- .../iboot/plugin/iotview/entity/Project.java | 18 ++++-- .../service/impl/ProjectServiceImpl.java | 18 ++++++ 6 files changed, 91 insertions(+), 33 deletions(-) diff --git a/docs/sql/patch.sql b/docs/sql/patch.sql index 52afb684..4f9f39d7 100644 --- a/docs/sql/patch.sql +++ b/docs/sql/patch.sql @@ -3,7 +3,7 @@ INSERT INTO `sys_menu` VALUES (1480,'产品数据',1421,88,'/iot/collectData/pro # 2025-06-04 create table isv_project ( - id bigint auto_increment, + id char(36), project_name varchar(64) null comment '项目名称', state int null comment '状态', index_image varchar(256) null comment '项目封面', @@ -11,6 +11,5 @@ create table isv_project ( is_delete int null comment '是否删除', content json null comment '项目内容', create_time datetime default now() not null comment '创建时间', - constraint isv_project_pk - primary key (id) + constraint isv_project_pk primary key (id) ) comment '大屏项目'; \ No newline at end of file diff --git a/framework/src/main/java/com/iteaj/framework/spi/file/LocalUploadService.java b/framework/src/main/java/com/iteaj/framework/spi/file/LocalUploadService.java index 3536db45..3d59b381 100644 --- a/framework/src/main/java/com/iteaj/framework/spi/file/LocalUploadService.java +++ b/framework/src/main/java/com/iteaj/framework/spi/file/LocalUploadService.java @@ -98,8 +98,8 @@ public class LocalUploadService implements UploadService, InitializingBean { uploadRootUri = uploadRootUri.replaceAll("\\*", ""); } - if(uploadRootUri.endsWith(File.separator)) { - this.uploadRootUri = uploadRootUri.substring(0, uploadRootUri.length()-1); + if(uploadRootUri.endsWith("/")) { + uploadRootUri = uploadRootUri.substring(0, uploadRootUri.length()-1); } this.uploadRootUri = uploadRootUri; diff --git a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/IotViewResult.java b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/IotViewResult.java index 1382ab28..e0c5794f 100644 --- a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/IotViewResult.java +++ b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/IotViewResult.java @@ -1,13 +1,9 @@ package com.iteaj.iboot.plugin.iotview; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.annotation.JsonIgnore; import com.iteaj.framework.result.AbstractResult; import com.iteaj.framework.result.HttpResult; -import com.iteaj.framework.result.PageResult; import com.iteaj.framework.result.Result; -import com.iteaj.iboot.plugin.iotview.entity.Project; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -17,7 +13,9 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class IotViewResult extends AbstractResult { - private long count; + public IotViewResult(Result result) { + this(result.getData(), result.getMessage(), result.getCode()); + } protected IotViewResult(String message, long code) { super(message, code); @@ -27,15 +25,6 @@ public class IotViewResult extends AbstractResult { super(data, message, code); } - public static Result build(Result result) { - if(result instanceof PageResult) { - final Page data = (Page)((PageResult) result).getData(); - return new IotViewResult(data.getRecords(), result.getMessage(), result.getCode()) - .setCount(data.getTotal()); - } - return null; - } - public String getMsg() { return getMessage(); } diff --git a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/controller/ProjectController.java b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/controller/ProjectController.java index 359cdd42..cf89f6b5 100644 --- a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/controller/ProjectController.java +++ b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/controller/ProjectController.java @@ -1,9 +1,11 @@ package com.iteaj.iboot.plugin.iotview.controller; +import java.io.IOException; import java.util.List; import com.iteaj.framework.logger.Logger; import com.iteaj.framework.result.Result; -import com.iteaj.framework.security.Logical; +import com.iteaj.framework.spi.file.UploadResult; +import com.iteaj.framework.spi.file.UploadService; import com.iteaj.iboot.plugin.iotview.IotViewResult; import org.springframework.web.bind.annotation.*; import com.iteaj.framework.security.CheckPermission; @@ -12,6 +14,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.iteaj.iboot.plugin.iotview.entity.Project; import com.iteaj.iboot.plugin.iotview.service.IProjectService; import com.iteaj.framework.BaseController; +import org.springframework.web.multipart.MultipartFile; /** * 大屏项目管理 @@ -22,9 +25,11 @@ import com.iteaj.framework.BaseController; @RequestMapping("/isv/project") public class ProjectController extends BaseController { + private final UploadService uploadService; private final IProjectService projectService; - public ProjectController(IProjectService projectService) { + public ProjectController(UploadService uploadService, IProjectService projectService) { + this.uploadService = uploadService; this.projectService = projectService; } @@ -37,7 +42,7 @@ public class ProjectController extends BaseController { @Logger("浏览大屏项目功能") @CheckPermission({"isv:project:view"}) public Result> list(Page page, Project entity) { - return IotViewResult.build(this.projectService.page(page, entity)); + return new IotViewResult(this.projectService.page(page, entity)); } /** @@ -51,14 +56,36 @@ public class ProjectController extends BaseController { } /** - * 新增或者更新记录 + * 创建项目 + * @param entity + */ + @PostMapping("/create") + @Logger("创建大屏项目") + @CheckPermission(value = {"isv:project:add"}) + public Result create(@RequestBody Project entity) { + return new IotViewResult(this.projectService.save(entity)); + } + + /** + * 更新大屏记录 * @param entity */ - @PostMapping("/saveOrUpdate") + @PostMapping("/edit") @Logger("新增或者更新大屏项目记录") - @CheckPermission(value = {"isv:project:edit", "isv:project:add"}, logical = Logical.OR) - public Result saveOrUpdate(@RequestBody Project entity) { - return this.projectService.saveOrUpdate(entity); + @CheckPermission(value = {"isv:project:edit"}) + public Result edit(@RequestBody Project entity) { + return new IotViewResult(this.projectService.updateById(entity)); + } + + + /** + * 获取大屏详情记录 + * @param projectId + */ + @GetMapping("/getData") + @Logger("新增或者更新大屏项目记录") + public Result detail(String projectId) { + return new IotViewResult(this.projectService.getById(projectId)); } /** @@ -71,5 +98,24 @@ public class ProjectController extends BaseController { public Result remove(@RequestBody List idList) { return this.projectService.removeByIds(idList); } + + /** + * 上传大屏略缩图 + * @param id + * @param file + * @return + */ + @PostMapping("upload") + public Result upload(String id, MultipartFile file) { + try { + final UploadResult isv = uploadService.upload(file.getInputStream(), file.getOriginalFilename(), id, "/isv"); + final Project project = new Project().setIndexImage(isv.getUrl()); + project.setId(id); + projectService.updateById(project); + return IotViewResult.Success(isv.getUrl()); + } catch (IOException e) { + return IotViewResult.Fail("上传失败"); + } + } } diff --git a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/entity/Project.java b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/entity/Project.java index e19c3074..874e7f8b 100644 --- a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/entity/Project.java +++ b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/entity/Project.java @@ -1,12 +1,14 @@ package com.iteaj.iboot.plugin.iotview.entity; -import com.iteaj.framework.BaseEntity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.util.Date; +import com.iteaj.framework.Entity; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; +import java.util.Date; + /** *

* 大屏项目 @@ -16,13 +18,15 @@ import lombok.experimental.Accessors; * @since 2025-06-04 */ @Data -@EqualsAndHashCode(callSuper = true) @Accessors(chain = true) @TableName("isv_project") -public class Project extends BaseEntity { +public class Project implements Entity { private static final long serialVersionUID = 1L; + @TableId(type = IdType.ASSIGN_UUID) + private String id; + /** * 项目名称 */ @@ -58,5 +62,7 @@ public class Project extends BaseEntity { */ private Date createTime; - + public void setId(String id) { + this.id = id; + } } diff --git a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/service/impl/ProjectServiceImpl.java b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/service/impl/ProjectServiceImpl.java index 86c23489..8e1a543a 100644 --- a/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/service/impl/ProjectServiceImpl.java +++ b/iboot-plugin/iboot-iotview/src/main/java/com/iteaj/iboot/plugin/iotview/service/impl/ProjectServiceImpl.java @@ -1,5 +1,7 @@ package com.iteaj.iboot.plugin.iotview.service.impl; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.iteaj.framework.result.BooleanResult; import com.iteaj.iboot.plugin.iotview.entity.Project; import com.iteaj.iboot.plugin.iotview.mapper.ProjectMapper; import com.iteaj.iboot.plugin.iotview.service.IProjectService; @@ -17,4 +19,20 @@ import org.springframework.stereotype.Service; @Service public class ProjectServiceImpl extends BaseServiceImpl implements IProjectService { + @Override + public BooleanResult save(Project entity) { + entity.setState(-1); + this.getOne(Wrappers.lambdaQuery().eq(Project::getProjectName, entity.getProjectName())) + .ifPresentThrow("项目名称已经存在"); + return super.save(entity); + } + + @Override + public BooleanResult updateById(Project entity) { + this.getOne(Wrappers.lambdaQuery() + .eq(Project::getId, entity.getId()) + .eq(Project::getProjectName, entity.getProjectName())) + .ifPresentThrow("项目名称已经存在"); + return super.updateById(entity); + } }