Skip to content

Commit

Permalink
Merge pull request #102 from SonicCloudOrg/beta2
Browse files Browse the repository at this point in the history
Beta2
  • Loading branch information
ZhouYixun authored Dec 23, 2021
2 parents b13944d + a5b73f3 commit 304a872
Show file tree
Hide file tree
Showing 18 changed files with 3,686 additions and 116 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
ports:
- "8094:8094"
sonic-server-controller:
image: "sonicorg/sonic-server-controller:v1.2.0-release"
image: "sonicorg/sonic-server-controller:v1.3.0-beta1"
environment:
- PROFILE=prod
- EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
Expand Down Expand Up @@ -81,7 +81,7 @@ services:
- sonic-server-eureka
- sonic-server-gateway
sonic-server-transport:
image: "sonicorg/sonic-server-transport:v1.2.0-release"
image: "sonicorg/sonic-server-transport:v1.3.0-beta1"
environment:
- PROFILE=prod
- EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/
Expand Down
38 changes: 19 additions & 19 deletions sonic-server-bus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@
</dependency>
</dependencies>

<!-- <build>-->
<!-- <plugins>-->
<!-- &lt;!&ndash; 只作为公共依赖,不需要打包 &ndash;&gt;-->
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <skip>true</skip>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- <groupId>com.spotify</groupId>-->
<!-- <artifactId>docker-maven-plugin</artifactId>-->
<!-- <configuration>-->
<!-- <skipDocker>true</skipDocker>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<build>
<plugins>
<!-- 只作为公共依赖,不需要打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skipDocker>true</skipDocker>
</configuration>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion sonic-server-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>sonic-server-controller</artifactId>
<version>v1.2.0-release</version>
<version>v1.3.0-beta1</version>
<packaging>jar</packaging>

<!-- 依赖列表 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@ public RespModel saveDetail(@Validated @RequestBody DeviceDetailChange deviceDet
}
}

@PutMapping("/updateUser")
public RespModel updateUser(@RequestBody JSONObject jsonObject) {
devicesService.updateUser(jsonObject);
@PutMapping("/updateDevicesUser")
public RespModel updateDevicesUser(@RequestBody JSONObject jsonObject) {
devicesService.updateDevicesUser(jsonObject);
return new RespModel(RespEnum.UPDATE_OK);
}

@PutMapping("/refreshDevicesTemper")
public RespModel refreshDevicesTemper(@RequestBody JSONObject jsonObject) {
devicesService.refreshDevicesTemper(jsonObject);
return new RespModel(RespEnum.UPDATE_OK);
}

@WebAspect
@ApiOperation(value = "获取温度概况", notes = "获取现有温度概况")
@GetMapping("/findTemper")
public RespModel<Integer> findTemper() {
return new RespModel(RespEnum.SEARCH_OK, devicesService.findTemper());
}

@WebAspect
@ApiOperation(value = "修改设备图片", notes = "修改对应设备id的图片")
@PutMapping("/updateImg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public interface DevicesRepository extends JpaRepository<Devices, Integer>, JpaS

List<Devices> findByPlatformOrderByIdDesc(int platform);

@Query(value = "select avg(temperature) as avg from devices " +
"where temperature <> 0 and status in (?1)", nativeQuery = true)
Integer findTemper(List<String> ids);

@Query(value = "select cpu from devices group by cpu", nativeQuery = true)
List<String> findCpuList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Devices {
int id;
@ApiModelProperty(value = "设备名称", example = "My HUAWEI")
String name;
@ApiModelProperty(value = "中文设备", example = "荣耀全网通")
String chiName;
@ApiModelProperty(value = "设备备注", example = "My HUAWEI")
String nickName;
@ApiModelProperty(value = "型号", example = "HUAWEI MATE 40")
Expand Down Expand Up @@ -49,6 +51,9 @@ public class Devices {
Set<TestSuites> testSuites;
@ApiModelProperty(value = "设备占用者")
String user;
@Column(columnDefinition="int default 0")
@ApiModelProperty(value = "设备温度", example = "33")
Integer temperature;

public Devices() {
}
Expand All @@ -61,14 +66,6 @@ public void setId(int id) {
this.id = id;
}

public String getNickName() {
return nickName;
}

public void setNickName(String nickName) {
this.nickName = nickName;
}

public String getName() {
return name;
}
Expand All @@ -77,6 +74,22 @@ public void setName(String name) {
this.name = name;
}

public String getChiName() {
return chiName;
}

public void setChiName(String chiName) {
this.chiName = chiName;
}

public String getNickName() {
return nickName;
}

public void setNickName(String nickName) {
this.nickName = nickName;
}

public String getModel() {
return model;
}
Expand Down Expand Up @@ -173,7 +186,6 @@ public void setTestSuites(Set<TestSuites> testSuites) {
this.testSuites = testSuites;
}


public String getUser() {
return user;
}
Expand All @@ -182,11 +194,20 @@ public void setUser(String user) {
this.user = user;
}

public float getTemperature() {
return temperature;
}

public void setTemperature(Integer temperature) {
this.temperature = temperature;
}

@Override
public String toString() {
return "Devices{" +
"id=" + id +
", name='" + name + '\'' +
", chiName='" + chiName + '\'' +
", nickName='" + nickName + '\'' +
", model='" + model + '\'' +
", udId='" + udId + '\'' +
Expand All @@ -200,6 +221,7 @@ public String toString() {
", password='" + password + '\'' +
", imgUrl='" + imgUrl + '\'' +
", user='" + user + '\'' +
", temperature='" + temperature + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public interface DevicesService {
boolean saveDetail(DeviceDetailChange deviceDetailChange);

void updateUser(JSONObject jsonObject);
void updateDevicesUser(JSONObject jsonObject);

void updateImg(UpdateDeviceImg updateDeviceImg);

Expand All @@ -38,4 +38,8 @@ Page<Devices> findAll(List<String> iOSVersion, List<String> androidVersion, List
void deviceStatus(JSONObject jsonObject);

Devices findById(int id);

Integer findTemper();

void refreshDevicesTemper(JSONObject jsonObject);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sonic.controller.services.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sonic.controller.dao.DevicesRepository;
import com.sonic.controller.models.Devices;
Expand All @@ -19,7 +20,10 @@
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down Expand Up @@ -48,7 +52,7 @@ public boolean saveDetail(DeviceDetailChange deviceDetailChange) {
}

@Override
public void updateUser(JSONObject jsonObject) {
public void updateDevicesUser(JSONObject jsonObject) {
Users users = usersService.getUserInfo(jsonObject.getString("token"));
Devices devices = findByAgentIdAndUdId(jsonObject.getInteger("agentId"),
jsonObject.getString("udId"));
Expand Down Expand Up @@ -159,9 +163,10 @@ public Page<Devices> findAll(List<String> iOSVersion, List<String> androidVersio
predicateList.add(cb.and(in));
}
if (deviceInfo != null) {
//因为是型号或者udId,所以两个条件为or
//因为是型号或者udId或者中文,所以三个条件为or
List<Predicate> modelOrUdId = new ArrayList<>();
modelOrUdId.add(cb.like(root.get("model"), "%" + deviceInfo + "%"));
modelOrUdId.add(cb.like(root.get("chiName"), "%" + deviceInfo + "%"));
modelOrUdId.add(cb.like(root.get("udId"), "%" + deviceInfo + "%"));
Predicate[] result = new Predicate[modelOrUdId.size()];
predicateList.add(cb.or(modelOrUdId.toArray(result)));
Expand Down Expand Up @@ -209,6 +214,23 @@ public JSONObject getFilterOption() {
return jsonObject;
}

public String getName(String model) {
InputStream config = getClass().getResourceAsStream("/result.json");
JSONObject jsonObject = null;
try {
jsonObject = JSON.parseObject(config, JSONObject.class);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
config.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return jsonObject.getString(model) == null ? "" : jsonObject.getString(model);
}

@Override
public void deviceStatus(JSONObject jsonMsg) {
Devices devices = findByAgentIdAndUdId(jsonMsg.getInteger("agentId")
Expand All @@ -221,6 +243,7 @@ public void deviceStatus(JSONObject jsonMsg) {
}
if (jsonMsg.getString("model") != null) {
newDevices.setName(jsonMsg.getString("model"));
newDevices.setChiName(getName(jsonMsg.getString("model")));
}
newDevices.setPlatform(jsonMsg.getInteger("platform"));
newDevices.setVersion(jsonMsg.getString("version"));
Expand All @@ -231,6 +254,7 @@ public void deviceStatus(JSONObject jsonMsg) {
newDevices.setStatus(jsonMsg.getString("status"));
newDevices.setPassword("");
newDevices.setImgUrl("");
newDevices.setTemperature(0);
save(newDevices);
} else {
devices.setAgentId(jsonMsg.getInteger("agentId"));
Expand All @@ -242,6 +266,7 @@ public void deviceStatus(JSONObject jsonMsg) {
if (jsonMsg.getString("model") != null) {
if (!jsonMsg.getString("model").equals("未知")) {
devices.setModel(jsonMsg.getString("model"));
devices.setChiName(getName(jsonMsg.getString("model")));
}
}
if (jsonMsg.getString("version") != null) {
Expand All @@ -259,7 +284,9 @@ public void deviceStatus(JSONObject jsonMsg) {
if (jsonMsg.getString("manufacturer") != null) {
devices.setManufacturer(jsonMsg.getString("manufacturer"));
}
devices.setStatus(jsonMsg.getString("status"));
if (jsonMsg.getString("status") != null) {
devices.setStatus(jsonMsg.getString("status"));
}
save(devices);
}
}
Expand All @@ -272,4 +299,23 @@ public Devices findById(int id) {
return null;
}
}

@Override
public Integer findTemper() {
return devicesRepository.findTemper(Arrays.asList(DeviceStatus.ONLINE
,DeviceStatus.DEBUGGING,DeviceStatus.TESTING));
}

@Override
public void refreshDevicesTemper(JSONObject jsonObject) {
int agentId = jsonObject.getInteger("agentId");
List<JSONObject> deviceTemList = jsonObject.getJSONArray("detail").toJavaList(JSONObject.class);
for (JSONObject d : deviceTemList) {
Devices devices = findByAgentIdAndUdId(agentId, d.getString("udId"));
if (devices != null) {
devices.setTemperature(d.getInteger("tem"));
devicesRepository.save(devices);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public RespModel runSuite(int suiteId, String strike) {
result.put("cases", suiteDetail);
for (Integer id : agentIds) {
result.put("id", id);
result.put("pf",testSuites.getPlatform());
result.put("msg", "suite");
transportFeignClient.sendTestData(result);
}
Expand Down Expand Up @@ -178,6 +179,7 @@ public RespModel runSuite(int suiteId, String strike) {
result.put("cases", suiteDetail);
for (Integer id : agentIds) {
result.put("id", id);
result.put("pf",testSuites.getPlatform());
result.put("msg", "suite");
transportFeignClient.sendTestData(result);
}
Expand Down Expand Up @@ -283,6 +285,7 @@ public RespModel<String> forceStopSuite(int resultId, String strike) {
}
JSONObject result = new JSONObject();
result.put("msg", "forceStopSuite");
result.put("pf",testSuites.getPlatform());
result.put("cases", suiteDetail);
for (Integer id : agentIds) {
result.put("id", id);
Expand All @@ -304,6 +307,7 @@ public RespModel<String> forceStopSuite(int resultId, String strike) {
}
JSONObject result = new JSONObject();
result.put("msg", "forceStopSuite");
result.put("pf",testSuites.getPlatform());
result.put("cases", suiteDetail);
for (Integer id : agentIds) {
result.put("id", id);
Expand Down
Loading

0 comments on commit 304a872

Please sign in to comment.