Commit d494546719bfdd1294b7d6e13a0354e390d197f7

Authored by lijianfa_14810364212
1 parent 867b3ab4

fix:3d模板添加批量发布功能

... ... @@ -9,6 +9,7 @@ import lombok.Data;
9 9 import org.springframework.beans.BeanUtils;
10 10 import org.springframework.http.ResponseEntity;
11 11 import org.springframework.security.access.prepost.PreAuthorize;
  12 +import org.springframework.util.CollectionUtils;
12 13 import org.springframework.util.StringUtils;
13 14 import org.springframework.web.bind.annotation.*;
14 15 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -25,13 +26,15 @@ import javax.annotation.Resource;
25 26 import java.util.ArrayList;
26 27 import java.util.HashMap;
27 28 import java.util.List;
  29 +import java.util.Set;
  30 +import java.util.stream.Collectors;
28 31
29 32 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*;
30 33 import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE;
31 34
32 35 /**
33 36 * <p>
34   - * 前端控制器
  37 + * 前端控制器
35 38 * </p>
36 39 *
37 40 * @author 黎剑发
... ... @@ -44,12 +47,13 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.
44 47 public class Tk3dComponentController extends BaseController {
45 48 @Resource
46 49 Tk3dComponentService tk3dComponentService;
  50 +
47 51 @GetMapping(path = "/page")
48 52 @ApiOperation(value = "分页")
49 53 public TkPageData<Tk3dComponentDTO> page(
50   - @RequestParam(value ="id", required = false) String id,
51   - @RequestParam(value ="name", required = false) String name,
52   - @RequestParam(value ="state", required = false) Integer state,
  54 + @RequestParam(value = "id", required = false) String id,
  55 + @RequestParam(value = "name", required = false) String name,
  56 + @RequestParam(value = "state", required = false) Integer state,
53 57 @RequestParam(PAGE_SIZE) int pageSize,
54 58 @RequestParam(PAGE) int page,
55 59 @RequestParam(value = ORDER_FILED, required = false) String orderBy,
... ... @@ -59,30 +63,30 @@ public class Tk3dComponentController extends BaseController {
59 63 HashMap<String, Object> queryMap = new HashMap<>();
60 64 queryMap.put(PAGE, page);
61 65 queryMap.put(PAGE_SIZE, pageSize);
62   - queryMap.put(ORDER_FILED, orderBy!=null?orderBy:"create_time");
63   - queryMap.put(ORDER_TYPE, orderType!=null?orderType.name():OrderTypeEnum.DESC.name());
64   - queryMap.put(TENANT_ID,getTenantId().getId().toString());
65   - if(StringUtils.hasLength(id)){
66   - queryMap.put("id",id);
  66 + queryMap.put(ORDER_FILED, orderBy != null ? orderBy : "create_time");
  67 + queryMap.put(ORDER_TYPE, orderType != null ? orderType.name() : OrderTypeEnum.DESC.name());
  68 + queryMap.put(TENANT_ID, getTenantId().getId().toString());
  69 + if (StringUtils.hasLength(id)) {
  70 + queryMap.put("id", id);
67 71 }
68   - if(StringUtils.hasLength(name)){
69   - queryMap.put("name",name);
  72 + if (StringUtils.hasLength(name)) {
  73 + queryMap.put("name", name);
70 74 }
71   - if(state!=null){
72   - queryMap.put("state",state);
  75 + if (state != null) {
  76 + queryMap.put("state", state);
73 77 }
74 78
75   - return tk3dComponentService.page(queryMap,getTenantId().getId().toString());
  79 + return tk3dComponentService.page(queryMap, getTenantId().getId().toString());
76 80 }
77 81
78 82
79 83 @PostMapping
80 84 @ApiOperation("保存")
81   - public ResponseEntity<Tk3dComponentDTO> save(@ApiParam("id")@RequestParam("id") String id, @RequestParam("imageUrl") String imageUrl,@RequestBody JsonNode jsonNode) throws ThingsboardException {
82   - if(!StringUtils.hasLength(id)){
  85 + public ResponseEntity<Tk3dComponentDTO> save(@ApiParam("id") @RequestParam("id") String id, @RequestParam("imageUrl") String imageUrl, @RequestBody JsonNode jsonNode) throws ThingsboardException {
  86 + if (!StringUtils.hasLength(id)) {
83 87 throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode()));
84 88 }
85   - Tk3dComponentDTO dto=new Tk3dComponentDTO();
  89 + Tk3dComponentDTO dto = new Tk3dComponentDTO();
86 90 dto.setId(id);
87 91 dto.setImageUrl(imageUrl);
88 92 dto.setTenantId(getTenantId().getId().toString());
... ... @@ -92,11 +96,11 @@ public class Tk3dComponentController extends BaseController {
92 96
93 97 @PutMapping("/{id}/{name}")
94 98 @ApiOperation("修改名称")
95   - public ResponseEntity<Tk3dComponentDTO> put(@PathVariable("id") String id,@PathVariable("name") String name) throws ThingsboardException {
96   - if(!StringUtils.hasLength(id)){
  99 + public ResponseEntity<Tk3dComponentDTO> put(@PathVariable("id") String id, @PathVariable("name") String name) throws ThingsboardException {
  100 + if (!StringUtils.hasLength(id)) {
97 101 throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode()));
98 102 }
99   - Tk3dComponentDTO dto=tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
  103 + Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
100 104 dto.setName(name);
101 105 return ResponseEntity.ok(tk3dComponentService.save(dto));
102 106 }
... ... @@ -104,15 +108,47 @@ public class Tk3dComponentController extends BaseController {
104 108
105 109 @PutMapping("/publish/{id}/{state}")
106 110 @ApiOperation("发布")
107   - public ResponseEntity<Tk3dComponentDTO> publish(@PathVariable("id") String id,@PathVariable("state") Integer state) throws ThingsboardException {
108   - if(!StringUtils.hasLength(id)){
  111 + public ResponseEntity<Tk3dComponentDTO> publish(@PathVariable("id") String id, @PathVariable("state") Integer state) throws ThingsboardException {
  112 + if (!StringUtils.hasLength(id)) {
109 113 throw new TkDataValidationException(MessageUtils.message(ErrorMessage.INVALID_PARAMETER.getI18nCode()));
110 114 }
111   - Tk3dComponentDTO dto=tk3dComponentService.get(id,getCurrentUser().getCurrentTenantId());
  115 + Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
112 116 dto.setState(state);
113 117 return ResponseEntity.ok(tk3dComponentService.save(dto));
114 118 }
115 119
  120 +
  121 + @PutMapping("/publish/{state}")
  122 + public ResponseEntity<Boolean> publish(@PathVariable("state") Integer state, @RequestBody List<String> ids) throws ThingsboardException {
  123 + if (!CollectionUtils.isEmpty(ids)) {
  124 +
  125 + return ResponseEntity.ok(
  126 +
  127 + tk3dComponentService.save(
  128 +
  129 + ids.stream().map(id -> {
  130 +
  131 + try {
  132 + return tk3dComponentService.get(id, getTenantId().getId().toString());
  133 + } catch (ThingsboardException e) {
  134 + throw new RuntimeException(e);
  135 + }
  136 +
  137 + }).filter(e -> {
  138 + return e != null;
  139 + })
  140 + .map(e -> {
  141 + e.setState(state);
  142 + return e;
  143 + }).collect(Collectors.toList())
  144 +
  145 + )
  146 + );
  147 + } else {
  148 + return ResponseEntity.ok(false);
  149 + }
  150 + }
  151 +
116 152 @GetMapping("/{id}")
117 153 @ApiOperation("获取详情信息")
118 154 public ResponseEntity<Tk3dComponentDTO> get(@PathVariable("id") String id)
... ... @@ -127,7 +163,7 @@ public class Tk3dComponentController extends BaseController {
127 163
128 164 @GetMapping("/json/{id}/{key}.json")
129 165 @ApiOperation("获取json数据")
130   - public ResponseEntity<JsonNode> json(@PathVariable("id") String id,@PathVariable("key") String key)
  166 + public ResponseEntity<JsonNode> json(@PathVariable("id") String id, @PathVariable("key") String key)
131 167 throws Exception {
132 168 Tk3dComponentDTO dto = tk3dComponentService.get(id, getCurrentUser().getCurrentTenantId());
133 169 if (null == dto) {
... ... @@ -139,12 +175,12 @@ public class Tk3dComponentController extends BaseController {
139 175 @DeleteMapping
140 176 @ApiOperation("删除")
141 177 public ResponseEntity<Boolean> del(DeleteDTO deleteDTO) throws ThingsboardException {
142   - List<String> ids = deleteDTO.getIds()==null?null:new ArrayList<>(deleteDTO.getIds());
143   - return ResponseEntity.ok(tk3dComponentService.delete(getCurrentUser().getCurrentTenantId(),ids));
  178 + List<String> ids = deleteDTO.getIds() == null ? null : new ArrayList<>(deleteDTO.getIds());
  179 + return ResponseEntity.ok(tk3dComponentService.delete(getCurrentUser().getCurrentTenantId(), ids));
144 180 }
145 181
146 182 @Data
147   - private static class ComponentParam{
  183 + private static class ComponentParam {
148 184
149 185 @ApiModelProperty("ID")
150 186 String id;
... ...
... ... @@ -16,6 +16,8 @@ import java.util.Map;
16 16 public interface Tk3dComponentService {
17 17 TkPageData<Tk3dComponentDTO> page(Map<String, Object> queryMap, String tenantId );
18 18 Tk3dComponentDTO save(Tk3dComponentDTO dto);
  19 +
  20 + boolean save(List<Tk3dComponentDTO> dto);
19 21 Tk3dComponentDTO get(String id, String tenantId);
20 22 boolean delete(String tenantId, List<String> ids);
21 23 }
... ...
... ... @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 4 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5 import org.apache.commons.lang3.StringUtils;
6 6 import org.springframework.stereotype.Service;
  7 +import org.springframework.util.CollectionUtils;
7 8 import org.thingsboard.server.common.data.yunteng.constant.QueryConstant;
8 9 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
9 10 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
... ... @@ -12,10 +13,12 @@ import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum;
12 13 import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils;
13 14 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
14 15 import org.thingsboard.server.dao.yunteng.entities.Tk3dComponentEntity;
  16 +import org.thingsboard.server.dao.yunteng.entities.TkAlarmEntity;
15 17 import org.thingsboard.server.dao.yunteng.mapper.Tk3dComponentMapper;
16 18 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
17 19 import org.thingsboard.server.dao.yunteng.service.Tk3dComponentService;
18 20
  21 +import java.util.Collections;
19 22 import java.util.List;
20 23 import java.util.Map;
21 24
... ... @@ -32,19 +35,7 @@ public class Tk3dComponentServiceImpl extends AbstractBaseService<Tk3dComponentM
32 35
33 36 @Override
34 37 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   - );
  38 + IPage<Tk3dComponentEntity> iPage =baseMapper.page(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),tenantId,queryMap);
48 39 return getPageData(iPage, Tk3dComponentDTO.class);
49 40 }
50 41
... ... @@ -65,6 +56,17 @@ public class Tk3dComponentServiceImpl extends AbstractBaseService<Tk3dComponentM
65 56 }
66 57
67 58 @Override
  59 + public boolean save(List<Tk3dComponentDTO> list) {
  60 + if(!CollectionUtils.isEmpty(list)){
  61 + list.stream().forEach(e->{
  62 + save(e);
  63 + });
  64 + return true;
  65 + }
  66 + return false;
  67 + }
  68 +
  69 + @Override
68 70 public Tk3dComponentDTO get(String id, String tenantId) {
69 71 Tk3dComponentEntity e = baseMapper.selectById(id);
70 72 if (e != null) {
... ...
1 1 package org.thingsboard.server.dao.yunteng.mapper;
2 2
  3 +import com.baomidou.mybatisplus.core.metadata.IPage;
  4 +import org.apache.ibatis.annotations.Param;
3 5 import org.thingsboard.server.dao.yunteng.entities.Tk3dComponentEntity;
4 6 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 7 import org.apache.ibatis.annotations.Mapper;
  8 +import org.thingsboard.server.dao.yunteng.entities.TkAlarmEntity;
  9 +
  10 +import java.util.Map;
  11 +import java.util.UUID;
6 12
7 13 /**
8 14 * <p>
... ... @@ -14,5 +20,5 @@ import org.apache.ibatis.annotations.Mapper;
14 20 */
15 21 @Mapper
16 22 public interface Tk3dComponentMapper extends BaseMapper<Tk3dComponentEntity> {
17   -
  23 + IPage<Tk3dComponentEntity> page(IPage<?> page, @Param("tenantId") String tenantId, @Param("queryMap") Map<String, Object> queryMap);
18 24 }
... ...
... ... @@ -5,7 +5,9 @@
5 5 <!-- 通用查询映射结果 -->
6 6 <resultMap id="BaseResultMap" type="org.thingsboard.server.dao.yunteng.entities.Tk3dComponentEntity">
7 7 <id column="id" property="id" />
8   - <result column="content" property="content" />
  8 + <result column="name" property="name" />
  9 + <result column="imageUrl" property="imageUrl" />
  10 + <result column="state" property="state" />
9 11 <result column="created_time" property="createdTime" />
10 12 <result column="update_time" property="updateTime" />
11 13 <result column="creator" property="creator" />
... ... @@ -15,7 +17,26 @@
15 17
16 18 <!-- 通用查询结果列 -->
17 19 <sql id="Base_Column_List">
18   - id, content, created_time, update_time, creator, updater, tenant_id
  20 + id, name, image_url, state, create_time, update_time, creator, updater, tenant_id
19 21 </sql>
20 22
  23 +
  24 + <select id="page" resultMap="BaseResultMap">
  25 + select <include refid="Base_Column_List"></include> from tk_3d_component
  26 + <where>
  27 + <if test="tenantId !=null">
  28 + AND tenant_id = #{tenantId}
  29 + </if>
  30 + <if test="queryMap.id !=null">
  31 + AND id = #{queryMap.id}
  32 + </if>
  33 + <if test="queryMap.name !=null">
  34 + AND name = #{queryMap.name}
  35 + </if>
  36 + <if test="queryMap.state !=null">
  37 + AND state = #{queryMap.state}
  38 + </if>
  39 + </where>
  40 + </select>
  41 +
21 42 </mapper>
... ...