初始化

master
法外狂徒张三 2024-09-03 20:49:21 +08:00
parent 08b1a3c9f2
commit 7b43ccd7c4
3 changed files with 73 additions and 1 deletions

View File

@ -36,7 +36,7 @@ public class SysDatawarehouse{
/** 订单编号 */ /** 订单编号 */
@Excel(name = "订单编号") @Excel(name = "订单编号")
private String orderBian; private String orderBian;
/** 下单时间 */ /** 下单时间 */
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")

View File

@ -114,4 +114,6 @@ public class SysDatawarehouseController extends BaseController
sysDatawarehouseService.removeBatchByIds(Arrays.asList(orderIds)); sysDatawarehouseService.removeBatchByIds(Arrays.asList(orderIds));
return success(); return success();
} }
} }

View File

@ -0,0 +1,70 @@
package com.muyu.market.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/third")
public class ThirdPartyController {
@GetMapping("/getAirQuality")
public ResponseEntity<String> getAirQuality(@RequestParam String cityId) {
String apiKey = "02ccc3ea04810432b45399ecb183195d";
String apiUrl = "http://apis.juhe.cn/fapigw/air/historyHours";
Map<String, String> params = new HashMap<>();
params.put("key", apiKey);
params.put("cityId", cityId);
try {
URL url = new URL(apiUrl + "?" + buildParams(params));
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return ResponseEntity.ok(response.toString());
} else {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to retrieve data: HTTP error code " + responseCode);
}
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to retrieve data: " + e.getMessage());
}
}
private String buildParams(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.joining("&"));
}
}