Skip to content

Commit 0f435e5

Browse files
committed
feat:update product tools ban
1 parent ccd5aad commit 0f435e5

File tree

14 files changed

+348
-8
lines changed

14 files changed

+348
-8
lines changed

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mysql,redis,emqx和influxdb环境。
8888
欢迎加入群聊一起交流讨论有关Aiot相关的话题,免费获取智控台的前端源码,链接过期了可以issue或email提醒一下作者。
8989

9090
<div style="width: 250px;margin: 0 auto;">
91-
<img src="./images/f1d07cf6a241ec0ac1601643364be3df.jpg" width="250px"/>
91+
<img src="./images/ede859c2bbe032886b842748dcfdc503.jpg" width="250px"/>
9292
</div>
9393

9494

162 KB
Loading
-164 KB
Binary file not shown.

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ mysql,redis,emqx和influxdb环境,安装详情请看官方文档。
116116
欢迎加入群聊一起交流讨论有关Aiot相关的话题,免费获取智控台的前端源码,链接过期了可以issue或email提醒一下作者。
117117

118118
<div style="width: 250px;margin: 0 auto;">
119-
<img src="./docs/images/f1d07cf6a241ec0ac1601643364be3df.jpg" width="250px"/>
119+
<img src="./docs/images/ede859c2bbe032886b842748dcfdc503.jpg" width="250px"/>
120120
</div>
121121

122122
## 致谢

src/main/java/top/rslly/iot/controllers/Tool.java

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
2929
import top.rslly.iot.param.request.*;
3030
import top.rslly.iot.services.*;
31-
import top.rslly.iot.services.agent.AiServiceImpl;
32-
import top.rslly.iot.services.agent.KnowledgeChatServiceImpl;
33-
import top.rslly.iot.services.agent.OtaXiaozhiPassiveServiceImpl;
34-
import top.rslly.iot.services.agent.OtaXiaozhiServiceImpl;
31+
import top.rslly.iot.services.agent.*;
3532
import top.rslly.iot.services.iot.AlarmEventServiceImpl;
3633
import top.rslly.iot.services.iot.HardWareServiceImpl;
3734
import top.rslly.iot.services.iot.OtaPassiveServiceImpl;
@@ -82,6 +79,8 @@ public class Tool {
8279
private KnowledgeChatServiceImpl knowledgeChatService;
8380
@Autowired
8481
private OtaXiaozhiPassiveServiceImpl otaXiaozhiPassiveService;
82+
@Autowired
83+
private ProductToolsBanServiceImpl productToolsBanService;
8584

8685
@Operation(summary = "用于获取平台运行环境信息", description = "单位为百分比")
8786
@RequestMapping(value = "/machineMessage", method = RequestMethod.GET)
@@ -435,4 +434,45 @@ public JsonResult<?> deleteXiaoZhiOtaPassive(@RequestParam("id") int id,
435434
return otaXiaozhiPassiveService.otaXiaozhiPassiveDelete(id);
436435
}
437436

437+
// 禁止内部工具productban
438+
@Operation(summary = "禁止内部工具", description = "禁止内部工具")
439+
@RequestMapping(value = "/productToolsBan", method = RequestMethod.GET)
440+
public JsonResult<?> getProductToolsBan(@RequestParam("productId") int productId,
441+
@RequestHeader("Authorization") String header) {
442+
try {
443+
if (!safetyService.controlAuthorizeProduct(header, productId))
444+
return ResultTool.fail(ResultCode.NO_PERMISSION);
445+
} catch (NullPointerException e) {
446+
return ResultTool.fail(ResultCode.PARAM_NOT_VALID);
447+
}
448+
return productToolsBanService.getProductToolsBan(productId);
449+
}
450+
451+
@Operation(summary = "禁止内部工具", description = "禁止内部工具")
452+
@RequestMapping(value = "/productToolsBan", method = RequestMethod.POST)
453+
public JsonResult<?> postProductToolsBan(
454+
@Valid @RequestBody ProductToolsBan productToolsBan,
455+
@RequestHeader("Authorization") String header) {
456+
try {
457+
if (!safetyService.controlAuthorizeProduct(header, productToolsBan.getProductId()))
458+
return ResultTool.fail(ResultCode.NO_PERMISSION);
459+
} catch (NullPointerException e) {
460+
return ResultTool.fail(ResultCode.PARAM_NOT_VALID);
461+
}
462+
return productToolsBanService.postProductToolsBan(productToolsBan);
463+
}
464+
465+
@Operation(summary = "禁止内部工具", description = "禁止内部工具")
466+
@RequestMapping(value = "/productToolsBan", method = RequestMethod.DELETE)
467+
public JsonResult<?> deleteProductToolsBan(@RequestParam("productId") int productId,
468+
@RequestHeader("Authorization") String header) {
469+
try {
470+
if (!safetyService.controlAuthorizeProduct(header, productId))
471+
return ResultTool.fail(ResultCode.NO_PERMISSION);
472+
} catch (NullPointerException e) {
473+
return ResultTool.fail(ResultCode.PARAM_NOT_VALID);
474+
}
475+
return productToolsBanService.deleteProductToolsBan(productId);
476+
}
477+
438478
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright © 2023-2030 The ruanrongman Authors
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package top.rslly.iot.dao;
21+
22+
import org.springframework.data.jpa.repository.JpaRepository;
23+
import org.springframework.transaction.annotation.Transactional;
24+
import top.rslly.iot.models.ProductToolsBanEntity;
25+
26+
import java.util.List;
27+
28+
public interface ProductToolsBanRepository extends JpaRepository<ProductToolsBanEntity, Long> {
29+
List<ProductToolsBanEntity> findAllByProductId(int productId);
30+
31+
@Transactional
32+
List<ProductToolsBanEntity> deleteAllByProductId(int productId);
33+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright © 2023-2030 The ruanrongman Authors
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package top.rslly.iot.models;
21+
22+
import javax.persistence.*;
23+
import java.util.Objects;
24+
25+
@Entity
26+
@Table(name = "product_tools_ban", schema = "cwliot1.8", catalog = "")
27+
public class ProductToolsBanEntity {
28+
private int id;
29+
private int productId;
30+
private String toolsName;
31+
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name = "id")
35+
public int getId() {
36+
return id;
37+
}
38+
39+
public void setId(int id) {
40+
this.id = id;
41+
}
42+
43+
@Basic
44+
@Column(name = "product_id")
45+
public int getProductId() {
46+
return productId;
47+
}
48+
49+
public void setProductId(int productId) {
50+
this.productId = productId;
51+
}
52+
53+
@Basic
54+
@Column(name = "tools_name")
55+
public String getToolsName() {
56+
return toolsName;
57+
}
58+
59+
public void setToolsName(String toolsName) {
60+
this.toolsName = toolsName;
61+
}
62+
63+
@Override
64+
public boolean equals(Object o) {
65+
if (this == o)
66+
return true;
67+
if (o == null || getClass() != o.getClass())
68+
return false;
69+
ProductToolsBanEntity that = (ProductToolsBanEntity) o;
70+
return id == that.id && productId == that.productId
71+
&& Objects.equals(toolsName, that.toolsName);
72+
}
73+
74+
@Override
75+
public int hashCode() {
76+
return Objects.hash(id, productId, toolsName);
77+
}
78+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright © 2023-2030 The ruanrongman Authors
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package top.rslly.iot.param.request;
21+
22+
import lombok.Data;
23+
24+
import javax.validation.constraints.NotEmpty;
25+
import java.util.List;
26+
27+
@Data
28+
public class ProductToolsBan {
29+
private int productId;
30+
@NotEmpty(message = "工具名称列表不能为空")
31+
private List<String> toolsName;
32+
}

src/main/java/top/rslly/iot/services/SafetyServiceImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ public boolean controlAuthorizeProduct(String token, int productId) {
244244
String token_deal = token.replace(JwtTokenUtil.TOKEN_PREFIX, "");
245245
String role = JwtTokenUtil.getUserRole(token_deal);
246246
String username = JwtTokenUtil.getUsername(token_deal);
247-
log.info("role {}", role);
248247
if (role.equals("ROLE_" + "wx_user")) {
249248
if (wxUserService.findAllByName(username).isEmpty()) {
250249
return false;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright © 2023-2030 The ruanrongman Authors
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package top.rslly.iot.services.agent;
21+
22+
import com.alibaba.fastjson.JSON;
23+
import top.rslly.iot.param.request.ProductToolsBan;
24+
import top.rslly.iot.utility.result.JsonResult;
25+
26+
import java.util.List;
27+
28+
public interface ProductToolsBanService {
29+
30+
List<String> getProductToolsBanList(int productId);
31+
32+
JsonResult<?> getProductToolsBan(int productId);
33+
34+
JsonResult<?> postProductToolsBan(ProductToolsBan productToolsBan);
35+
36+
JsonResult<?> deleteProductToolsBan(int productId);
37+
}

0 commit comments

Comments
 (0)