Skip to content

Commit

Permalink
feat: add product role and use bing search
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanrongman committed Feb 19, 2025
1 parent 6fc04d6 commit 99c9084
Show file tree
Hide file tree
Showing 23 changed files with 679 additions and 38 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mysql,redis,emqx和influxdb环境。
欢迎加入群聊一起交流讨论有关Aiot相关的话题,链接过期了可以issue或email提醒一下作者。

<div style="width: 250px;margin: 0 auto;">
<img src="./images/fd0ac036093fa0c241a58774bc0d78c.jpg" width="250px"/>
<img src="./images/89c13c4bacf448872ae23ae094fa2ba.jpg" width="250px"/>
</div>


Expand Down
Binary file added docs/images/89c13c4bacf448872ae23ae094fa2ba.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/fd0ac036093fa0c241a58774bc0d78c.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mysql,redis,emqx和influxdb环境,安装详情请看官方文档。
欢迎加入群聊一起交流讨论有关Aiot相关的话题,链接过期了可以issue或email提醒一下作者。

<div style="width: 250px;margin: 0 auto;">
<img src="./docs/images/fd0ac036093fa0c241a58774bc0d78c.jpg" width="250px"/>
<img src="./docs/images/89c13c4bacf448872ae23ae094fa2ba.jpg" width="250px"/>
</div>


Expand Down
39 changes: 35 additions & 4 deletions src/main/java/top/rslly/iot/controllers/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import top.rslly.iot.param.request.AiControl;
import top.rslly.iot.param.request.ControlParam;
import top.rslly.iot.param.request.MetaData;
import top.rslly.iot.param.request.ReadData;
import top.rslly.iot.param.request.*;
import top.rslly.iot.services.*;
import top.rslly.iot.utility.RedisUtil;
import top.rslly.iot.utility.RuntimeMessage;
import top.rslly.iot.utility.SseEmitterUtil;
import top.rslly.iot.utility.ai.chain.Router;
import top.rslly.iot.utility.ai.tools.ControlTool;
import top.rslly.iot.utility.result.JsonResult;
import top.rslly.iot.utility.result.ResultCode;
import top.rslly.iot.utility.result.ResultTool;

import javax.servlet.ServletOutputStream;
Expand All @@ -63,7 +61,11 @@ public class Tool {
@Autowired
private OtaServiceImpl otaService;
@Autowired
private ProductRoleServiceImpl productRoleService;
@Autowired
private AiServiceImpl aiService;
@Autowired
private SafetyServiceImpl safetyService;

@Operation(summary = "用于获取平台运行环境信息", description = "单位为百分比")
@RequestMapping(value = "/machineMessage", method = RequestMethod.GET)
Expand Down Expand Up @@ -142,6 +144,35 @@ public void audioTmpGet(@PathVariable("name") String name, HttpServletResponse r
aiService.audioTmpGet(name, response);
}

@Operation(summary = "获取产品角色列表", description = "仅获取当前用户产品角色列表")
@RequestMapping(value = "/productRole", method = RequestMethod.GET)
public JsonResult<?> getProductRole(@RequestHeader("Authorization") String header) {
return productRoleService.getProductRole(header);
}

@Operation(summary = "添加产品角色", description = "仅添加当前用户产品角色")
@RequestMapping(value = "/productRole", method = RequestMethod.POST)
public JsonResult<?> postProductRole(@RequestBody ProductRole productRole) {
return productRoleService.postProductRole(productRole);
}

@Operation(summary = "修改产品角色", description = "仅修改当前用户产品角色")
@RequestMapping(value = "/productRole", method = RequestMethod.PUT)
public JsonResult<?> putProductRole(@RequestBody ProductRole productRole,
@RequestHeader("Authorization") String header) {
if (!safetyService.controlAuthorizeProduct(header, productRole.getProductId()))
return ResultTool.fail(ResultCode.NO_PERMISSION);
return productRoleService.putProductRole(productRole);
}

@Operation(summary = "删除产品角色", description = "仅删除当前用户产品角色")
@RequestMapping(value = "/productRole", method = RequestMethod.DELETE)
public JsonResult<?> deleteProductRole(@RequestParam("id") int id,
@RequestHeader("Authorization") String header) {
if (!safetyService.controlAuthorizeProductRole(header, id))
return ResultTool.fail(ResultCode.NO_PERMISSION);
return productRoleService.deleteProductRole(id);
}

// ota list and delete
@RequestMapping(value = "/micro/{name}", method = RequestMethod.GET)
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/top/rslly/iot/dao/ProductRoleRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
import top.rslly.iot.models.ProductRoleEntity;

import java.util.List;

public interface ProductRoleRepository extends JpaRepository<ProductRoleEntity, Integer> {
List<ProductRoleEntity> findAllById(int id);

List<ProductRoleEntity> findAllByProductId(int productId);

@Transactional
List<ProductRoleEntity> deleteById(int id);
}
126 changes: 126 additions & 0 deletions src/main/java/top/rslly/iot/models/ProductRoleEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.models;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "product_role", schema = "cwliot1.8", catalog = "")
public class ProductRoleEntity {

private int id;
private int productId;
private String assistantName;
private String userName;
private String role;
private String roleIntroduction;
private String voice;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Basic
@Column(name = "product_id")
public int getProductId() {
return productId;
}

public void setProductId(int productId) {
this.productId = productId;
}

@Basic
@Column(name = "assistant_name")
public String getAssistantName() {
return assistantName;
}

public void setAssistantName(String assistantName) {
this.assistantName = assistantName;
}

@Basic
@Column(name = "user_name")
public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

@Basic
@Column(name = "role")
public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}

@Basic
@Column(name = "role_introduction")
public String getRoleIntroduction() {
return roleIntroduction;
}

public void setRoleIntroduction(String roleIntroduction) {
this.roleIntroduction = roleIntroduction;
}

@Basic
@Column(name = "voice")
public String getVoice() {
return voice;
}

public void setVoice(String voice) {
this.voice = voice;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ProductRoleEntity that = (ProductRoleEntity) o;
return id == that.id && productId == that.productId
&& Objects.equals(assistantName, that.assistantName)
&& Objects.equals(userName, that.userName) && Objects.equals(role, that.role)
&& Objects.equals(roleIntroduction, that.roleIntroduction)
&& Objects.equals(voice, that.voice);
}

@Override
public int hashCode() {
return Objects.hash(id, productId, assistantName, userName, role, roleIntroduction, voice);
}
}
32 changes: 32 additions & 0 deletions src/main/java/top/rslly/iot/param/request/ProductRole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.param.request;

import lombok.Data;

@Data
public class ProductRole {
private int productId;
private String assistantName;
private String userName;
private String role;
private String roleIntroduction;
private String voice;
}
41 changes: 41 additions & 0 deletions src/main/java/top/rslly/iot/services/ProductRoleService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright © 2023-2030 The ruanrongman Authors
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.rslly.iot.services;

import top.rslly.iot.models.ProductRoleEntity;
import top.rslly.iot.param.request.ProductRole;
import top.rslly.iot.utility.result.JsonResult;

import java.util.List;

public interface ProductRoleService {

List<ProductRoleEntity> findAllById(int id);

List<ProductRoleEntity> findAllByProductId(int productId);

JsonResult<?> getProductRole(String token);

JsonResult<?> postProductRole(ProductRole productRole);

JsonResult<?> putProductRole(ProductRole productRole);

JsonResult<?> deleteProductRole(int id);
}
Loading

0 comments on commit 99c9084

Please sign in to comment.