用户信息表单提交
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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;
|
||||
@@ -9,6 +10,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/ocr")
|
||||
public class LoginCrawler {
|
||||
@@ -19,8 +22,9 @@ public class LoginCrawler {
|
||||
public LoginCrawler(LoginService loginService) {
|
||||
this.loginService = loginService;
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<String> ocrLocalImage(@RequestBody LoginInfoParam loginInfoParam) throws IOException, TesseractException {
|
||||
public ResponseEntity<String> ocrLocalImage(@RequestBody LoginInfoParam loginInfoParam){
|
||||
String result = loginService.loginAutomatic(loginInfoParam);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
@@ -32,6 +36,13 @@ public class LoginCrawler {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
//用户信息表单提交
|
||||
@PostMapping("/saveUserInfo")
|
||||
public ResponseEntity<String> saveUserInfo(@RequestBody LoginInfoResult loginInfoResult){
|
||||
String result = loginService.saveUserInfo(loginInfoResult);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,10 @@ public class LoginInfoResult {
|
||||
@Column(name = "lose_num", nullable = false)
|
||||
private Integer loseNum;
|
||||
|
||||
//1是开0是关
|
||||
@Column(name = "on_off", nullable = false)
|
||||
private Integer onOff;
|
||||
|
||||
/* @Column(name = "current_num", nullable = false)
|
||||
private Integer currentNum;*/
|
||||
@Column(name = "create_time", nullable = false, updatable = false)
|
||||
|
||||
@@ -20,6 +20,8 @@ public class LoginInfoParam {
|
||||
public String loginUrl;
|
||||
public Integer winNum;
|
||||
public Integer loseNum;
|
||||
//1开0是关
|
||||
public Integer onOff;
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
@@ -60,4 +62,12 @@ public class LoginInfoParam {
|
||||
public void setLoseNum(Integer loseNum) {
|
||||
this.loseNum = loseNum;
|
||||
}
|
||||
|
||||
public Integer getOnOff() {
|
||||
return onOff;
|
||||
}
|
||||
|
||||
public void setOnOff(Integer onOff) {
|
||||
this.onOff = onOff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.tem.bocai.service;
|
||||
|
||||
import com.tem.bocai.entity.LoginInfoResult;
|
||||
import com.tem.bocai.param.LoginInfoParam;
|
||||
|
||||
public interface LoginService {
|
||||
@@ -10,4 +11,6 @@ public interface LoginService {
|
||||
//获取token
|
||||
String completedToday();
|
||||
|
||||
String saveUserInfo(LoginInfoResult loginInfoResult);
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.tem.bocai.repository.LotteryResultRepository;
|
||||
import com.tem.bocai.service.LoginService;
|
||||
import com.tem.bocai.util.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.val;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import net.sourceforge.tess4j.Tesseract;
|
||||
@@ -17,6 +18,8 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import us.codecraft.webmagic.Spider;
|
||||
|
||||
@Service
|
||||
@@ -150,6 +153,33 @@ public class LoginServiceImpl implements LoginService {
|
||||
return success ? "success" : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String saveUserInfo(LoginInfoResult loginInfoResult) {
|
||||
try {
|
||||
Optional<LoginInfoResult> existingUser = loginInfoRepository.findByUsername(loginInfoResult.getUsername());
|
||||
Date now = new Date();
|
||||
|
||||
if (existingUser.isPresent()) {
|
||||
// 如果是更新,保留原有创建时间
|
||||
LoginInfoResult dbUser = existingUser.get();
|
||||
loginInfoResult.setId(dbUser.getId()); // 设置ID才能更新
|
||||
loginInfoResult.setCreateTime(dbUser.getCreateTime());
|
||||
} else {
|
||||
// 如果是新增,设置创建时间
|
||||
loginInfoResult.setCreateTime(now);
|
||||
}
|
||||
|
||||
loginInfoResult.setUpdateTime(now);
|
||||
loginInfoRepository.save(loginInfoResult);
|
||||
|
||||
return "success";
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("保存用户信息失败: " + e.getMessage());
|
||||
return "error: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加登录信息
|
||||
|
||||
Reference in New Issue
Block a user