Commit 31e34bb6fccf901570a30aafa4a6296862fff1a5
Merge branch 'fix/3d-component' into 'master_dev'
feat: 添加3d组件编辑器数据存储 See merge request yunteng/thingskit!448
Showing
11 changed files
with
390 additions
and
3 deletions
... | ... | @@ -5,4 +5,32 @@ COMMENT ON COLUMN "public"."tk_configuration_content_node"."configuration_node_i |
5 | 5 | update tk_configuration_content_node set configuration_node_id = id; |
6 | 6 | --更新组态内容节点表的主键ID为uuid |
7 | 7 | CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; |
8 | -update tk_configuration_content_node set id = uuid_generate_v4(); | |
\ No newline at end of file | ||
8 | +update tk_configuration_content_node set id = uuid_generate_v4(); | |
9 | + | |
10 | +--添加3d组件的新表 | |
11 | +CREATE TABLE "public"."tk_3d_component" ( | |
12 | + "id" varchar(36) COLLATE "pg_catalog"."default" NOT NULL, | |
13 | + "content" text COLLATE "pg_catalog"."default" NOT NULL, | |
14 | + "creator" varchar(36) COLLATE "pg_catalog"."default", | |
15 | + "updater" varchar(36) COLLATE "pg_catalog"."default", | |
16 | + "tenant_id" varchar(36) COLLATE "pg_catalog"."default" NOT NULL, | |
17 | + "create_time" timestamp(6), | |
18 | + "update_time" timestamp(6), | |
19 | + "name" varchar(128) COLLATE "pg_catalog"."default", | |
20 | + "state" int2 | |
21 | +) | |
22 | +; | |
23 | +COMMENT ON COLUMN "public"."tk_3d_component"."id" IS '主建'; | |
24 | +COMMENT ON COLUMN "public"."tk_3d_component"."content" IS '模板内容'; | |
25 | +COMMENT ON COLUMN "public"."tk_3d_component"."creator" IS '创建用户'; | |
26 | +COMMENT ON COLUMN "public"."tk_3d_component"."updater" IS '更新用户'; | |
27 | +COMMENT ON COLUMN "public"."tk_3d_component"."tenant_id" IS '租户ID'; | |
28 | +COMMENT ON COLUMN "public"."tk_3d_component"."create_time" IS '创建时间'; | |
29 | +COMMENT ON COLUMN "public"."tk_3d_component"."update_time" IS '更新时间'; | |
30 | +COMMENT ON COLUMN "public"."tk_3d_component"."name" IS '名称'; | |
31 | +COMMENT ON COLUMN "public"."tk_3d_component"."state" IS '状态:0未发布,1已发布'; | |
32 | + | |
33 | +-- ---------------------------- | |
34 | +-- Primary Key structure for table tk_3d_component | |
35 | +-- ---------------------------- | |
36 | +ALTER TABLE "public"."tk_3d_component" ADD CONSTRAINT "tk_3d_component_pkey" PRIMARY KEY ("id"); | |
\ No newline at end of file | ... | ... |
... | ... | @@ -249,7 +249,7 @@ public class ThingsboardSecurityConfiguration { |
249 | 249 | .exceptionHandling().accessDeniedHandler(restAccessDeniedHandler) |
250 | 250 | .and() |
251 | 251 | .addFilterBefore(buildRestLoginProcessingFilter(), UsernamePasswordAuthenticationFilter.class) |
252 | - //thingskit | |
252 | + //thingskit | |
253 | 253 | .addFilterBefore(buildSmsCodeLoginProcessingFilter(),UsernamePasswordAuthenticationFilter.class) |
254 | 254 | .addFilterBefore(buildRestPublicLoginProcessingFilter(), UsernamePasswordAuthenticationFilter.class) |
255 | 255 | .addFilterBefore(buildJwtTokenAuthenticationProcessingFilter(), UsernamePasswordAuthenticationFilter.class) | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/Tk3dComponentController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.JsonNode; | |
4 | +import io.swagger.annotations.Api; | |
5 | +import io.swagger.annotations.ApiOperation; | |
6 | +import io.swagger.annotations.ApiParam; | |
7 | +import org.springframework.http.ResponseEntity; | |
8 | +import org.springframework.security.access.prepost.PreAuthorize; | |
9 | +import org.springframework.util.StringUtils; | |
10 | +import org.springframework.web.bind.annotation.*; | |
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
13 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.*; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; | |
17 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
18 | +import org.thingsboard.server.controller.BaseController; | |
19 | +import org.thingsboard.server.dao.yunteng.service.Tk3dComponentService; | |
20 | + | |
21 | +import javax.annotation.Resource; | |
22 | +import java.util.ArrayList; | |
23 | +import java.util.HashMap; | |
24 | +import java.util.List; | |
25 | + | |
26 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
27 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; | |
28 | + | |
29 | +/** | |
30 | + * <p> | |
31 | + * 前端控制器 | |
32 | + * </p> | |
33 | + * | |
34 | + * @author 黎剑发 | |
35 | + * @since 2024-10-14 | |
36 | + */ | |
37 | +@RestController | |
38 | +@RequestMapping("api/yt/3d_component") | |
39 | +@Api(tags = {"3D模型管理"}) | |
40 | +@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | |
41 | +public class Tk3dComponentController extends BaseController { | |
42 | + @Resource | |
43 | + Tk3dComponentService tk3dComponentService; | |
44 | + @GetMapping(path = "/page") | |
45 | + @ApiOperation(value = "分页") | |
46 | + public TkPageData<Tk3dComponentDTO> page( | |
47 | + @RequestParam(value ="id", required = false) String id, | |
48 | + @RequestParam(value ="name", required = false) String name, | |
49 | + @RequestParam(value ="state", required = false) Integer state, | |
50 | + @RequestParam(PAGE_SIZE) int pageSize, | |
51 | + @RequestParam(PAGE) int page, | |
52 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
53 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | |
54 | + throws ThingsboardException { | |
55 | + | |
56 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
57 | + queryMap.put(PAGE, page); | |
58 | + queryMap.put(PAGE_SIZE, pageSize); | |
59 | + queryMap.put(ORDER_FILED, orderBy!=null?orderBy:"create_time"); | |
60 | + queryMap.put(ORDER_TYPE, orderType!=null?orderType.name():OrderTypeEnum.DESC.name()); | |
61 | + queryMap.put(TENANT_ID,getTenantId().getId().toString()); | |
62 | + if(StringUtils.hasLength(id)){ | |
63 | + queryMap.put("id",id); | |
64 | + } | |
65 | + if(StringUtils.hasLength(name)){ | |
66 | + queryMap.put("name",name); | |
67 | + } | |
68 | + if(state!=null){ | |
69 | + queryMap.put("state",state); | |
70 | + } | |
71 | + | |
72 | + return tk3dComponentService.page(queryMap,getTenantId().getId().toString()); | |
73 | + } | |
74 | + | |
75 | + | |
76 | + @PostMapping("/{id}") | |
77 | + @ApiOperation("保存") | |
78 | + public ResponseEntity<Tk3dComponentDTO> save(@ApiParam("id")@PathVariable("id") String id, @RequestBody JsonNode jsonNode) throws ThingsboardException { | |
79 | + if(!StringUtils.hasLength(id)){ | |
80 | + throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode())); | |
81 | + } | |
82 | + Tk3dComponentDTO dto=new Tk3dComponentDTO(); | |
83 | + dto.setId(id); | |
84 | + dto.setTenantId(getTenantId().getId().toString()); | |
85 | + dto.setContent(jsonNode); | |
86 | + return ResponseEntity.ok(tk3dComponentService.save(dto)); | |
87 | + } | |
88 | + | |
89 | + @PutMapping("/{id}/{name}") | |
90 | + @ApiOperation("修改名称") | |
91 | + public ResponseEntity<Tk3dComponentDTO> put(@PathVariable("id") String id,@PathVariable("name") String name) throws ThingsboardException { | |
92 | + if(!StringUtils.hasLength(id)){ | |
93 | + throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode())); | |
94 | + } | |
95 | + Tk3dComponentDTO dto=tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId()); | |
96 | + dto.setName(name); | |
97 | + return ResponseEntity.ok(tk3dComponentService.save(dto)); | |
98 | + } | |
99 | + | |
100 | + @PutMapping("/publish/{id}/{state}") | |
101 | + @ApiOperation("发布") | |
102 | + public ResponseEntity<Tk3dComponentDTO> publish(@PathVariable("id") String id,@PathVariable("state") Integer state) throws ThingsboardException { | |
103 | + if(!StringUtils.hasLength(id)){ | |
104 | + throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode())); | |
105 | + } | |
106 | + Tk3dComponentDTO dto=tk3dComponentService.get(id,getCurrentUser().getCurrentTenantId()); | |
107 | + dto.setState(state); | |
108 | + return ResponseEntity.ok(tk3dComponentService.save(dto)); | |
109 | + } | |
110 | + | |
111 | + @GetMapping("/{id}") | |
112 | + @ApiOperation("获取详情信息") | |
113 | + public ResponseEntity<Tk3dComponentDTO> get(@PathVariable("id") String id) | |
114 | + throws Exception { | |
115 | + Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId()); | |
116 | + if (null == dto) { | |
117 | + throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode())); | |
118 | + } | |
119 | + return ResponseEntity.ok(dto); | |
120 | + } | |
121 | + | |
122 | + | |
123 | + @GetMapping("/json/{id}/{key}.json") | |
124 | + @ApiOperation("获取json数据") | |
125 | + public ResponseEntity<JsonNode> json(@PathVariable("id") String id,@PathVariable("key") String key) | |
126 | + throws Exception { | |
127 | + Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId()); | |
128 | + if (null == dto) { | |
129 | + throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode())); | |
130 | + } | |
131 | + return ResponseEntity.ok(dto.getContent().get(key)); | |
132 | + } | |
133 | + | |
134 | + @DeleteMapping | |
135 | + @ApiOperation("删除") | |
136 | + public ResponseEntity<Boolean> del(DeleteDTO deleteDTO) throws ThingsboardException { | |
137 | + List<String> ids = deleteDTO.getIds()==null?null:new ArrayList<>(deleteDTO.getIds()); | |
138 | + return ResponseEntity.ok(tk3dComponentService.delete(getCurrentUser().getCurrentTenantId(),ids)); | |
139 | + } | |
140 | + | |
141 | +} | ... | ... |
common/dao-api/src/main/java/org/thingsboard/server/dao/yunteng/service/Tk3dComponentService.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | +import org.thingsboard.server.common.data.yunteng.dto.Tk3dComponentDTO; | |
3 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
4 | + | |
5 | +import java.util.List; | |
6 | +import java.util.Map; | |
7 | + | |
8 | +/** | |
9 | + * <p> | |
10 | + * 服务类 | |
11 | + * </p> | |
12 | + * | |
13 | + * @author 黎剑发 | |
14 | + * @since 2024-10-14 | |
15 | + */ | |
16 | +public interface Tk3dComponentService { | |
17 | + TkPageData<Tk3dComponentDTO> page(Map<String, Object> queryMap, String tenantId ); | |
18 | + Tk3dComponentDTO save(Tk3dComponentDTO dto); | |
19 | + Tk3dComponentDTO get(String id, String tenantId); | |
20 | + boolean delete(String tenantId, List<String> ids); | |
21 | +} | ... | ... |
... | ... | @@ -153,7 +153,8 @@ public final class ModelConstants { |
153 | 153 | /** api调用记录表 */ |
154 | 154 | public static final String TK_OPEN_API_RECORD = "tk_open_api_record"; |
155 | 155 | |
156 | - | |
156 | + /** 3d组件表 */ | |
157 | + public static final String TK_3D_COMPONENT_NAME = "tk_3d_component"; | |
157 | 158 | } |
158 | 159 | |
159 | 160 | public static class TableFields { | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/Tk3dComponentDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.JsonNode; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Getter; | |
6 | +import lombok.Setter; | |
7 | +import lombok.experimental.Accessors; | |
8 | + | |
9 | +import java.io.Serializable; | |
10 | + | |
11 | +/** | |
12 | + * <p> | |
13 | + * | |
14 | + * </p> | |
15 | + * | |
16 | + * @author 黎剑发 | |
17 | + * @since 2024-10-14 | |
18 | + */ | |
19 | +@Getter | |
20 | +@Setter | |
21 | +@Accessors(chain = true) | |
22 | +public class Tk3dComponentDTO extends TenantDTO implements Serializable { | |
23 | + | |
24 | + private static final long serialVersionUID = 1L; | |
25 | + | |
26 | + @ApiModelProperty("模板内容") | |
27 | + private JsonNode content; | |
28 | + | |
29 | + @ApiModelProperty("是否发布:0否,1是") | |
30 | + Integer state; | |
31 | + | |
32 | + | |
33 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.entities; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.TableField; | |
4 | +import com.baomidou.mybatisplus.annotation.TableName; | |
5 | +import java.io.Serializable; | |
6 | + | |
7 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
8 | +import com.fasterxml.jackson.databind.JsonNode; | |
9 | +import io.swagger.annotations.ApiModel; | |
10 | +import io.swagger.annotations.ApiModelProperty; | |
11 | +import lombok.Data; | |
12 | +import lombok.EqualsAndHashCode; | |
13 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | |
14 | + | |
15 | +/** | |
16 | + * <p> | |
17 | + * | |
18 | + * </p> | |
19 | + * | |
20 | + * @author 黎剑发 | |
21 | + * @since 2024-10-14 | |
22 | + */ | |
23 | +@Data | |
24 | +@EqualsAndHashCode(callSuper = true) | |
25 | +@TableName(ModelConstants.Table.TK_3D_COMPONENT_NAME) | |
26 | +@ApiModel(value = "Tk3dComponentEntity对象") | |
27 | +public class Tk3dComponentEntity extends TenantBaseEntity implements Serializable { | |
28 | + private static final long serialVersionUID = -4715245103595332141L; | |
29 | + @TableField | |
30 | + String name; | |
31 | + | |
32 | + @TableField | |
33 | + @ApiModelProperty("是否发布:0否,1是") | |
34 | + Integer state; | |
35 | + | |
36 | + @ApiModelProperty("模板内容") | |
37 | + @TableField(typeHandler = JacksonTypeHandler.class) | |
38 | + private JsonNode content; | |
39 | + | |
40 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | +import org.apache.commons.lang3.StringUtils; | |
6 | +import org.springframework.stereotype.Service; | |
7 | +import org.thingsboard.server.common.data.yunteng.constant.QueryConstant; | |
8 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
9 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
10 | +import org.thingsboard.server.common.data.yunteng.dto.Tk3dComponentDTO; | |
11 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
12 | +import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; | |
13 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; | |
14 | +import org.thingsboard.server.dao.yunteng.entities.Tk3dComponentEntity; | |
15 | +import org.thingsboard.server.dao.yunteng.mapper.Tk3dComponentMapper; | |
16 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
17 | +import org.thingsboard.server.dao.yunteng.service.Tk3dComponentService; | |
18 | + | |
19 | +import java.util.List; | |
20 | +import java.util.Map; | |
21 | + | |
22 | +/** | |
23 | + * <p> | |
24 | + * 服务实现类 | |
25 | + * </p> | |
26 | + * | |
27 | + * @author 黎剑发 | |
28 | + * @since 2024-10-14 | |
29 | + */ | |
30 | +@Service | |
31 | +public class Tk3dComponentServiceImpl extends AbstractBaseService<Tk3dComponentMapper, Tk3dComponentEntity> implements Tk3dComponentService { | |
32 | + | |
33 | + @Override | |
34 | + public TkPageData<Tk3dComponentDTO> page(Map<String, Object> queryMap, String tenantId) { | |
35 | + String id = queryMap.containsKey("id") ? queryMap.get("id").toString() : null; | |
36 | + String name = queryMap.containsKey("name") ? queryMap.get("name").toString() : null; | |
37 | + Integer state = queryMap.containsKey("state") ? Integer.parseInt(queryMap.get("state").toString()) : null; | |
38 | + | |
39 | + IPage<Tk3dComponentEntity> iPage = | |
40 | + baseMapper.selectPage( | |
41 | + getPage(queryMap, queryMap.containsKey(QueryConstant.ORDER_FILED) ? queryMap.get(QueryConstant.ORDER_FILED).toString() : "create_time", queryMap.containsKey(QueryConstant.ORDER_TYPE) ? queryMap.get(QueryConstant.ORDER_TYPE).toString().equalsIgnoreCase(OrderTypeEnum.ASC.name()) : false), | |
42 | + new LambdaQueryWrapper<Tk3dComponentEntity>() | |
43 | + .eq(StringUtils.isNotEmpty(tenantId), Tk3dComponentEntity::getTenantId, tenantId) | |
44 | + .eq(StringUtils.isNotEmpty(id), Tk3dComponentEntity::getId, id) | |
45 | + .like(StringUtils.isNotEmpty(name), Tk3dComponentEntity::getName, name) | |
46 | + .eq(state!=null, Tk3dComponentEntity::getState, state) | |
47 | + ); | |
48 | + return getPageData(iPage, Tk3dComponentDTO.class); | |
49 | + } | |
50 | + | |
51 | + @Override | |
52 | + public Tk3dComponentDTO save(Tk3dComponentDTO dto) { | |
53 | + | |
54 | + if (baseMapper.exists(new LambdaQueryWrapper<Tk3dComponentEntity>() | |
55 | + .eq(Tk3dComponentEntity::getTenantId, dto.getTenantId()) | |
56 | + .eq(Tk3dComponentEntity::getId, dto.getId()))) { | |
57 | + baseMapper.updateById(dto.getEntity(Tk3dComponentEntity.class)); | |
58 | + } else { | |
59 | + baseMapper.insert(dto.getEntity(Tk3dComponentEntity.class)); | |
60 | + } | |
61 | + | |
62 | + return dto; | |
63 | + } | |
64 | + | |
65 | + @Override | |
66 | + public Tk3dComponentDTO get(String id, String tenantId) { | |
67 | + Tk3dComponentEntity e = baseMapper.selectById(id); | |
68 | + if (e != null) { | |
69 | + return e.getDTO(Tk3dComponentDTO.class); | |
70 | + } else { | |
71 | + return null; | |
72 | + } | |
73 | + } | |
74 | + | |
75 | + @Override | |
76 | + public boolean delete(String tenantId, List<String> ids) { | |
77 | + if(null ==ids){ | |
78 | + throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode())); | |
79 | + } | |
80 | + return baseMapper.delete(new LambdaQueryWrapper<Tk3dComponentEntity>().eq(Tk3dComponentEntity::getTenantId,tenantId) | |
81 | + .in(Tk3dComponentEntity::getId,ids))>0; | |
82 | + } | |
83 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.mapper; | |
2 | + | |
3 | +import org.thingsboard.server.dao.yunteng.entities.Tk3dComponentEntity; | |
4 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |
5 | +import org.apache.ibatis.annotations.Mapper; | |
6 | + | |
7 | +/** | |
8 | + * <p> | |
9 | + * Mapper 接口 | |
10 | + * </p> | |
11 | + * | |
12 | + * @author 黎剑发 | |
13 | + * @since 2024-10-14 | |
14 | + */ | |
15 | +@Mapper | |
16 | +public interface Tk3dComponentMapper extends BaseMapper<Tk3dComponentEntity> { | |
17 | + | |
18 | +} | ... | ... |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.Tk3dComponentMapper"> | |
4 | + | |
5 | + <!-- 通用查询映射结果 --> | |
6 | + <resultMap id="BaseResultMap" type="org.thingsboard.server.dao.yunteng.entities.Tk3dComponentEntity"> | |
7 | + <id column="id" property="id" /> | |
8 | + <result column="content" property="content" /> | |
9 | + <result column="created_time" property="createdTime" /> | |
10 | + <result column="update_time" property="updateTime" /> | |
11 | + <result column="creator" property="creator" /> | |
12 | + <result column="updater" property="updater" /> | |
13 | + <result column="tenant_id" property="tenantId" /> | |
14 | + </resultMap> | |
15 | + | |
16 | + <!-- 通用查询结果列 --> | |
17 | + <sql id="Base_Column_List"> | |
18 | + id, content, created_time, update_time, creator, updater, tenant_id | |
19 | + </sql> | |
20 | + | |
21 | +</mapper> | ... | ... |