2024-10-13 16:54:05 +08:00
|
|
|
package com.rabbiter.em.controller;
|
|
|
|
|
|
|
|
import com.rabbiter.em.annotation.Authority;
|
|
|
|
import com.rabbiter.em.constants.Constants;
|
|
|
|
import com.rabbiter.em.common.Result;
|
|
|
|
import com.rabbiter.em.entity.AuthorityType;
|
|
|
|
import com.rabbiter.em.entity.Address;
|
|
|
|
import com.rabbiter.em.service.AddressService;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2025-04-06 21:55:03 +08:00
|
|
|
import org.springframework.web.client.RestTemplate;
|
2024-10-13 16:54:05 +08:00
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Authority(AuthorityType.requireLogin)
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/api/address")
|
|
|
|
public class AddressController {
|
|
|
|
@Resource
|
|
|
|
private AddressService addressService;
|
|
|
|
|
|
|
|
/*
|
|
|
|
查询
|
|
|
|
*/
|
|
|
|
@GetMapping("/{userId}")
|
|
|
|
public Result findAllById(@PathVariable Long userId) {
|
|
|
|
return Result.success(addressService.findAllById(userId));
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping
|
|
|
|
public Result findAll() {
|
|
|
|
List<Address> list = addressService.list();
|
|
|
|
return Result.success(list);
|
|
|
|
}
|
|
|
|
|
2025-04-06 21:55:03 +08:00
|
|
|
@GetMapping("/deepseek/{qq}")
|
|
|
|
public Result callDeepSeek(@PathVariable String qq) {
|
|
|
|
try {
|
|
|
|
// 验证QQ号格式
|
|
|
|
if(!qq.matches("^[1-9][0-9]{4,10}$")) {
|
|
|
|
return Result.error(Constants.CODE_400, "无效的QQ号");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 调用DeepSeek API
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
String apiUrl = "https://api.deepseek.com/qq/" + qq;
|
|
|
|
String response = restTemplate.getForObject(apiUrl, String.class);
|
|
|
|
|
|
|
|
return Result.success(response);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return Result.error(Constants.CODE_500, "调用DeepSeek失败: " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
2024-10-13 16:54:05 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
保存
|
|
|
|
*/
|
|
|
|
@PostMapping
|
|
|
|
public Result save(@RequestBody Address address) {
|
|
|
|
boolean b = addressService.saveOrUpdate(address);
|
|
|
|
if(b){
|
|
|
|
return Result.success();
|
|
|
|
}else{
|
|
|
|
return Result.error(Constants.CODE_500,"保存地址失败");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@PutMapping
|
|
|
|
public Result update(@RequestBody Address address) {
|
|
|
|
addressService.updateById(address);
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
删除
|
|
|
|
*/
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
public Result delete(@PathVariable Long id) {
|
|
|
|
addressService.removeById(id);
|
|
|
|
return Result.success();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|