Skip to content

Commit

Permalink
v1.5更新:增加详细数据页;bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFeng2021 committed Apr 12, 2024
1 parent 2c521b4 commit 9752975
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 40 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Forest-Dashboard-New
***
#### 项目简介
**V1.5更新 2024.4.12**
* 增加详细数据页
* 多语言支持(中/英/日)
* BUG修复
* 切换账号功能

**V1.3更新 2023.7.21**
* 表格专注时间列改为x时x分

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ public Boolean isLogin(){

@GetMapping("/logout")
public String logout(){return mainService.logout();}

@GetMapping("/getPlantsDetail")
public List<PlantsDetail> getPlantsdetail(){return mainService.getPlantsDetail();}
}
12 changes: 12 additions & 0 deletions src/main/java/com/entity/PlantsDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.entity;

import lombok.Data;

@Data
public class PlantsDetail {
private String start_time;
private String end_time;
private boolean isSucceed;
private String tag;
private Integer id;
}
2 changes: 2 additions & 0 deletions src/main/java/com/service/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface MainService {
public Boolean isLogin();

String logout();

public List<PlantsDetail> getPlantsDetail();
}

38 changes: 35 additions & 3 deletions src/main/java/com/service/impl/MainServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MainServiceImpl implements MainService {
Boolean isLogin = false;
String token;
String userId;
String[] tagArray = new String[50];

@Override
public List<Plants> getAllTrees() {
Expand All @@ -39,7 +40,6 @@ public List<Plants> getAllTrees() {
String tokenStr = "remember_token=" + token;
headers.set("Cookie", tokenStr);
headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67");
// 注意几个请求参数
HttpEntity<String> res = restTemplate
.exchange("https://forest-china.upwardsware.com/api/v1/plants?seekrua=extension_chrome-5.12.0&from_date=1970-01-01T00:00:00.000Z"
, HttpMethod.GET, new HttpEntity<>(null, headers),
Expand All @@ -51,7 +51,6 @@ public List<Plants> getAllTrees() {
JSONArray objs = JSONArray.parseArray(res.getBody());
MyHashMap myHashMap = new MyHashMap();
JSONArray tag_objs = JSONArray.parseArray(JSONObject.parseObject(tag_res.getBody()).getString("tags"));
String[] tagArray = new String[50];
if (tag_objs != null) {
for (int i = 0; i < tag_objs.size(); i++) {
String title = tag_objs.getJSONObject(i).get("title").toString();
Expand All @@ -71,7 +70,7 @@ public List<Plants> getAllTrees() {
Date endDay = dft.parse(endTime);//结束时间
Long starTime = start.getTime();
Long endtime = endDay.getTime();
int time = (int) ((endtime - starTime) / 60 / 1000);//时间戳相差的毫秒数
int time = (int) ((endtime - starTime) / 60 / 1000);
myHashMap.put(tag, time);
DetailsData detailsData = new DetailsData();
detailsData.setTag(tagArray[tag]);
Expand Down Expand Up @@ -168,4 +167,37 @@ public String logout() {
token = null;
return "ok";
}

@Override
public List<PlantsDetail> getPlantsDetail() {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
HttpHeaders headers = new HttpHeaders();
String tokenStr = "remember_token=" + token;
headers.set("Cookie", tokenStr);
headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.67");
HttpEntity<String> res = restTemplate
.exchange("https://forest-china.upwardsware.com/api/v1/plants?seekrua=extension_chrome-5.12.0&from_date=1970-01-01T00:00:00.000Z"
, HttpMethod.GET, new HttpEntity<>(null, headers),
String.class);
JSONArray objs = JSONArray.parseArray(res.getBody());
List<PlantsDetail> plantsDetails=new ArrayList<>();
if (objs != null) {
for (int i = 0; i < objs.size(); i++) {
String startTime = objs.getJSONObject(i).get("start_time").toString();
String endTime = objs.getJSONObject(i).get("end_time").toString();
String isSucceed = objs.getJSONObject(i).get("is_success").toString();
int tag = objs.getJSONObject(i).getIntValue("tag");
boolean is_succeed = isSucceed.equals("true");
PlantsDetail plantsDetail = new PlantsDetail();
plantsDetail.setStart_time(startTime);
plantsDetail.setEnd_time(endTime);
plantsDetail.setSucceed(is_succeed);
plantsDetail.setTag(tagArray[tag]);
plantsDetail.setId(i+1);
plantsDetails.add(plantsDetail);
}
return plantsDetails;
} else return null;
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard | Forest专注森林</title>
<script type="module" crossorigin src="/assets/index-39f71ba1.js"></script>
<link rel="stylesheet" href="/assets/index-18717541.css">
<script type="module" crossorigin src="/assets/index-88d68c0a.js"></script>
<link rel="stylesheet" href="/assets/index-eae9e251.css">
</head>
<body>
<div id="app"></div>
Expand Down

0 comments on commit 9752975

Please sign in to comment.