init
This commit is contained in:
parent
4e5162e804
commit
c5ee8354d1
@ -0,0 +1,15 @@
|
||||
package top.biwin.xinayu.common.dto.request;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2026-01-24 21:52
|
||||
*/
|
||||
@Data
|
||||
public class GoofishAddCookieRequest {
|
||||
private String id;
|
||||
private String value;
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package top.biwin.xinayu.common.dto.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 闲鱼账号用户名密码登陆方式
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2026-01-24 21:25
|
||||
*/
|
||||
@Data
|
||||
public class GoofishPwdLoginRequest {
|
||||
|
||||
@JsonProperty("account_id")
|
||||
private String accountId;
|
||||
private String account;
|
||||
private String password;
|
||||
@JsonProperty("show_browser")
|
||||
private Boolean show_browser;
|
||||
|
||||
}
|
||||
@ -9,7 +9,9 @@ import java.util.Optional;
|
||||
@Repository
|
||||
public interface GoofishAccountRepository extends JpaRepository<GoofishAccountEntity, Long> {
|
||||
|
||||
Optional<GoofishAccountEntity> findByUserId(Long UserId);
|
||||
Optional<GoofishAccountEntity> findByUserId(Long UserId);
|
||||
|
||||
long countByEnabled(Boolean enabled);
|
||||
long countByEnabled(Boolean enabled);
|
||||
|
||||
Optional<GoofishAccountEntity> findByUsername(String username);
|
||||
}
|
||||
|
||||
@ -3,15 +3,24 @@ package top.biwin.xinayu.server.controller;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.biwin.xianyu.core.entity.GoofishAccountEntity;
|
||||
import top.biwin.xianyu.core.repository.GoofishAccountRepository;
|
||||
import top.biwin.xianyu.goofish.qrcode.QrLoginService;
|
||||
import top.biwin.xinayu.common.dto.request.GoofishAddCookieRequest;
|
||||
import top.biwin.xinayu.common.dto.request.GoofishPwdLoginRequest;
|
||||
import top.biwin.xinayu.common.dto.response.BaseResponse;
|
||||
import top.biwin.xinayu.common.dto.response.GoofishAccountResponse;
|
||||
import top.biwin.xinayu.common.dto.response.QrLoginResponse;
|
||||
import top.biwin.xinayu.server.util.CurrentUserUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -23,36 +32,98 @@ import java.util.stream.Collectors;
|
||||
@RestController
|
||||
@RequestMapping("/goofish")
|
||||
public class GoofishAccountController {
|
||||
@Autowired
|
||||
private GoofishAccountRepository goofishAccountRepository;
|
||||
@Autowired
|
||||
private QrLoginService qrLoginService;
|
||||
@Autowired
|
||||
private GoofishAccountRepository goofishAccountRepository;
|
||||
|
||||
/**
|
||||
* 获取所有Cookie的详细信息(包括值和状态)
|
||||
* 对应Python的 get_cookies_details 接口
|
||||
*/
|
||||
@GetMapping("/details")
|
||||
public ResponseEntity<List<GoofishAccountResponse>> getAllGoofishAccountDetails() {
|
||||
List<GoofishAccountEntity> goofishAccountEntities = new ArrayList<>();
|
||||
if (CurrentUserUtil.isSuperAdmin()) {
|
||||
goofishAccountEntities.addAll(goofishAccountRepository.findAll());
|
||||
} else {
|
||||
goofishAccountRepository.findByUserId(CurrentUserUtil.getCurrentUserId())
|
||||
.ifPresent(goofishAccountEntities::add);
|
||||
/**
|
||||
* 获取所有Cookie的详细信息(包括值和状态)
|
||||
* 对应Python的 get_cookies_details 接口
|
||||
*/
|
||||
@GetMapping("/details")
|
||||
public ResponseEntity<List<GoofishAccountResponse>> getAllGoofishAccountDetails() {
|
||||
List<GoofishAccountEntity> goofishAccountEntities = new ArrayList<>();
|
||||
if (CurrentUserUtil.isSuperAdmin()) {
|
||||
goofishAccountEntities.addAll(goofishAccountRepository.findAll());
|
||||
} else {
|
||||
goofishAccountRepository.findByUserId(CurrentUserUtil.getCurrentUserId())
|
||||
.ifPresent(goofishAccountEntities::add);
|
||||
}
|
||||
|
||||
// 构建详细信息响应
|
||||
return ResponseEntity.ok(goofishAccountEntities.stream().map(account -> {
|
||||
GoofishAccountResponse response = new GoofishAccountResponse();
|
||||
response.setId(account.getId());
|
||||
response.setCookie(account.getCookie());
|
||||
response.setEnabled(account.getEnabled());
|
||||
response.setAutoConfirm(account.getAutoConfirm());
|
||||
response.setRemark(account.getRemark() != null ? account.getRemark() : "");
|
||||
response.setPauseDuration(account.getPauseDuration() != null ? account.getPauseDuration() : 10);
|
||||
response.setUsername(account.getUsername());
|
||||
response.setLoginPassword(account.getPassword());
|
||||
response.setShowBrowser(account.getShowBrowser() == 1);
|
||||
return response;
|
||||
}).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
// 构建详细信息响应
|
||||
return ResponseEntity.ok(goofishAccountEntities.stream().map(account -> {
|
||||
GoofishAccountResponse response = new GoofishAccountResponse();
|
||||
response.setId(account.getId());
|
||||
response.setCookie(account.getCookie());
|
||||
response.setEnabled(account.getEnabled());
|
||||
response.setAutoConfirm(account.getAutoConfirm());
|
||||
response.setRemark(account.getRemark() != null ? account.getRemark() : "");
|
||||
response.setPauseDuration(account.getPauseDuration() != null ? account.getPauseDuration() : 10);
|
||||
response.setUsername(account.getUsername());
|
||||
response.setLoginPassword(account.getPassword());
|
||||
response.setShowBrowser(account.getShowBrowser() == 1);
|
||||
return response;
|
||||
}).collect(Collectors.toList()));
|
||||
}
|
||||
@PostMapping("/qr-login/generate")
|
||||
public ResponseEntity<QrLoginResponse> generateQrCode() {
|
||||
return ResponseEntity.ok(qrLoginService.generateQrCode());
|
||||
}
|
||||
|
||||
@GetMapping("/qr-login/check/{sessionId}")
|
||||
public Map<String, Object> checkQrCodeStatus(@PathVariable String sessionId) {
|
||||
return qrLoginService.checkQrCodeStatus(sessionId);
|
||||
}
|
||||
|
||||
@PostMapping("/password-login")
|
||||
public ResponseEntity<BaseResponse> passwordLogin(@RequestBody GoofishPwdLoginRequest request) {
|
||||
if (request.getAccountId() == null || request.getAccount() == null || request.getPassword() == null) {
|
||||
return ResponseEntity.ok(BaseResponse.builder()
|
||||
.success(false)
|
||||
.message("账号ID、登录账号和密码不能为空")
|
||||
.build());
|
||||
}
|
||||
|
||||
// TODO 自动化操作浏览器完成登陆,并写 goofishAccount 表
|
||||
// browserService.startPasswordLogin(
|
||||
// request.getAccount_id(),
|
||||
// request.getAccount(),
|
||||
// request.getPassword(),
|
||||
// request.getShow_browser() != null && request.getShow_browser(),
|
||||
// userId
|
||||
// );
|
||||
|
||||
return ResponseEntity.ok(BaseResponse.builder()
|
||||
.success(true)
|
||||
.message("登录任务已启动")
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/cookies")
|
||||
public ResponseEntity<BaseResponse> loginByCookie(@RequestBody GoofishAddCookieRequest request) {
|
||||
GoofishAccountEntity entity = goofishAccountRepository.findByUsername(request.getId())
|
||||
.map(account -> {
|
||||
account.setCookie(account.getCookie());
|
||||
return account;
|
||||
})
|
||||
.orElseGet(() -> {
|
||||
GoofishAccountEntity newAccount = new GoofishAccountEntity();
|
||||
// TODO 该属性,应该利用 cookie 真实去获取, 这里暂时写死
|
||||
newAccount.setId(1000L);
|
||||
newAccount.setCookie(request.getValue());
|
||||
newAccount.setUserId(1L);
|
||||
newAccount.setAutoConfirm(1);
|
||||
newAccount.setUsername(request.getId());
|
||||
return newAccount;
|
||||
});
|
||||
|
||||
goofishAccountRepository.save(entity);
|
||||
return ResponseEntity.ok(BaseResponse.builder()
|
||||
.success(true)
|
||||
.message("手动添加 cookie 成功")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
package top.biwin.xinayu.server.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.biwin.xianyu.goofish.qrcode.QrLoginService;
|
||||
import top.biwin.xinayu.common.dto.response.QrLoginResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2026-01-23 22:37
|
||||
*/
|
||||
@RestController
|
||||
public class QrLoginController {
|
||||
@Autowired
|
||||
private QrLoginService qrLoginService;
|
||||
|
||||
@PostMapping("/qr-login/generate")
|
||||
public ResponseEntity<QrLoginResponse> generateQrCode() {
|
||||
return ResponseEntity.ok(qrLoginService.generateQrCode());
|
||||
}
|
||||
|
||||
@GetMapping("/qr-login/check/{sessionId}")
|
||||
public Map<String, Object> checkQrCodeStatus(@PathVariable String sessionId) {
|
||||
return qrLoginService.checkQrCodeStatus(sessionId);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user