调整
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.tem.bocai.controller;
|
||||
|
||||
import com.tem.bocai.entity.LotteryResult;
|
||||
import com.tem.bocai.repository.LotteryResultRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -8,6 +11,9 @@ import java.util.*;
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class ChartController {
|
||||
|
||||
@Autowired
|
||||
private LotteryResultRepository lotteryResultRepository;
|
||||
|
||||
// 获取折线图1数据
|
||||
@GetMapping("/charts/line1")
|
||||
@@ -24,79 +30,35 @@ public class ChartController {
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// 获取折线图2数据
|
||||
@GetMapping("/charts/line2")
|
||||
public Map<String, Object> getLineChartData2() {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
// 模拟数据 - 实际项目中应该从数据库获取
|
||||
List<Integer> data = Arrays.asList(28, 48, 40, 19, 86, 27, 90);
|
||||
List<String> labels = Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月", "7月");
|
||||
|
||||
response.put("data", data);
|
||||
response.put("labels", labels);
|
||||
response.put("title", "折线图2数据");
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
// 获取表格数据
|
||||
@GetMapping("/table")
|
||||
public List<Map<String, Object>> getTableData() {
|
||||
List<Map<String, Object>> tableData = new ArrayList<>();
|
||||
|
||||
// 模拟数据 - 实际项目中应该从数据库获取
|
||||
Map<String, Object> item1 = new HashMap<>();
|
||||
item1.put("id", 1);
|
||||
item1.put("name", "项目1");
|
||||
item1.put("value", 120);
|
||||
item1.put("status", "正常");
|
||||
tableData.add(item1);
|
||||
|
||||
Map<String, Object> item2 = new HashMap<>();
|
||||
item2.put("id", 2);
|
||||
item2.put("name", "项目2");
|
||||
item2.put("value", 230);
|
||||
item2.put("status", "警告");
|
||||
tableData.add(item2);
|
||||
|
||||
Map<String, Object> item3 = new HashMap<>();
|
||||
item3.put("id", 3);
|
||||
item3.put("name", "项目3");
|
||||
item3.put("value", 180);
|
||||
item3.put("status", "正常");
|
||||
tableData.add(item3);
|
||||
|
||||
Map<String, Object> item4 = new HashMap<>();
|
||||
item4.put("id", 4);
|
||||
item4.put("name", "项目4");
|
||||
item4.put("value", 90);
|
||||
item4.put("status", "异常");
|
||||
tableData.add(item4);
|
||||
|
||||
Map<String, Object> item5 = new HashMap<>();
|
||||
item5.put("id", 5);
|
||||
item5.put("name", "项目5");
|
||||
item5.put("value", 320);
|
||||
item5.put("status", "正常");
|
||||
tableData.add(item5);
|
||||
|
||||
Map<String, Object> item6 = new HashMap<>();
|
||||
item6.put("id", 6);
|
||||
item6.put("name", "项目6");
|
||||
item6.put("value", 270);
|
||||
item6.put("status", "警告");
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
tableData.add(item6);
|
||||
try {
|
||||
// 获取今日日期的字符串表示(格式:yyyy-MM-dd)
|
||||
String today = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date());
|
||||
System.out.println("今日日期: " + today);
|
||||
|
||||
// 从数据库获取今日的LotteryResult数据
|
||||
List<LotteryResult> lotteryResults = lotteryResultRepository.findByTimeContaining(today);
|
||||
System.out.println("获取到" + lotteryResults.size() + "条今日数据");
|
||||
|
||||
// 将LotteryResult对象转换为前端需要的Map格式
|
||||
for (LotteryResult result : lotteryResults) {
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("id", result.getId());
|
||||
item.put("name", result.getIssue()); // 使用期号作为名称
|
||||
item.put("time", result.getTime()); // 添加开奖时间
|
||||
// 将List<String>转换为逗号分隔的字符串,避免序列化问题
|
||||
item.put("result", result.getResult()); // 添加开奖号码
|
||||
tableData.add(item);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("获取表格数据失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return tableData;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,11 @@ package com.tem.bocai.controller;
|
||||
import com.tem.bocai.entity.LoginInfoResult;
|
||||
import com.tem.bocai.param.LoginInfoParam;
|
||||
import com.tem.bocai.service.LoginService;
|
||||
import com.tem.bocai.util.ImageOcrService;
|
||||
import net.sourceforge.tess4j.TesseractException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/ocr")
|
||||
@@ -43,6 +40,13 @@ public class LoginCrawler {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
// 获取用户设置信息
|
||||
@GetMapping("/userSettings")
|
||||
public ResponseEntity<LoginInfoResult> getUserSettings(){
|
||||
LoginInfoResult result = loginService.getUserSettings();
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LotteryResult {
|
||||
private String time; // 开奖时间
|
||||
|
||||
@Column(name = "result")
|
||||
private List<String> result; // 开奖号码
|
||||
private String result; // 开奖号码
|
||||
|
||||
@Column(name = "winner", nullable = false)
|
||||
private String winner; //
|
||||
@@ -54,83 +54,4 @@ public class LotteryResult {
|
||||
@Column(name = "glh_result", nullable = false)
|
||||
private String glh_result; //[ "龙", "龙", "龙", "虎", "虎" ] 龙虎
|
||||
|
||||
public String getIssue() {
|
||||
return issue;
|
||||
}
|
||||
|
||||
public void setIssue(String issue) {
|
||||
this.issue = issue;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public List<String> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(List<String> result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getWinner() {
|
||||
return winner;
|
||||
}
|
||||
|
||||
public void setWinner(String winner) {
|
||||
this.winner = winner;
|
||||
}
|
||||
|
||||
public String getSum1() {
|
||||
return sum1;
|
||||
}
|
||||
|
||||
public void setSum1(String sum1) {
|
||||
this.sum1 = sum1;
|
||||
}
|
||||
|
||||
public String getSum2() {
|
||||
return sum2;
|
||||
}
|
||||
|
||||
public void setSum2(String sum2) {
|
||||
this.sum2 = sum2;
|
||||
}
|
||||
|
||||
public String getGd2() {
|
||||
return gd2;
|
||||
}
|
||||
|
||||
public void setGd2(String gd2) {
|
||||
this.gd2 = gd2;
|
||||
}
|
||||
|
||||
public String getGd1() {
|
||||
return gd1;
|
||||
}
|
||||
|
||||
public void setGd1(String gd1) {
|
||||
this.gd1 = gd1;
|
||||
}
|
||||
|
||||
public String getGlh_result() {
|
||||
return glh_result;
|
||||
}
|
||||
|
||||
public void setGlh_result(String glh_result) {
|
||||
this.glh_result = glh_result;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import com.tem.bocai.entity.LotteryResult;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface LotteryResultRepository extends JpaRepository<LotteryResult, Long> {
|
||||
// 可以添加自定义查询方法
|
||||
// 根据时间查询(使用like匹配日期部分)
|
||||
List<LotteryResult> findByTimeContaining(String date);
|
||||
}
|
||||
@@ -13,4 +13,7 @@ public interface LoginService {
|
||||
|
||||
String saveUserInfo(LoginInfoResult loginInfoResult);
|
||||
|
||||
// 获取用户设置信息
|
||||
LoginInfoResult getUserSettings();
|
||||
|
||||
}
|
||||
|
||||
@@ -249,5 +249,21 @@ public class LoginServiceImpl implements LoginService {
|
||||
return SQLiteUtil.addOrUpdateLoginInfo(loginInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginInfoResult getUserSettings() {
|
||||
try {
|
||||
// 获取最新的用户设置信息
|
||||
Optional<LoginInfoResult> existingUser = loginInfoRepository.findFirstByOrderByCreateTimeDesc();
|
||||
if (existingUser.isPresent()) {
|
||||
return existingUser.get();
|
||||
}
|
||||
// 如果没有找到,返回一个空的对象
|
||||
return new LoginInfoResult();
|
||||
} catch (Exception e) {
|
||||
System.err.println("获取用户设置信息失败: " + e.getMessage());
|
||||
return new LoginInfoResult();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user