소스정리

main
이범준 4 months ago
parent 2220903d9f
commit 63492b7efc

@ -20,11 +20,6 @@ public class ApiMainController {
@Resource(name = "apiMainService")
private ApiMainService apiMainService;
@RequestMapping(value = "/sisulDefaultList", produces = "application/json; charset=utf8", method=RequestMethod.POST)
public List<Map<String, Object>> sisulDefaultList(@RequestBody Map<String, Object> data) {
return apiMainService.sisulDefaultList(data);
}
@RequestMapping(value = "/sisulPenaltyList", produces = "application/json; charset=utf8", method=RequestMethod.POST)
public List<Map<String, Object>> sisulPenaltyList(@RequestBody Map<String, Object> data) {
return apiMainService.sisulPenaltyList(data);
@ -40,4 +35,9 @@ public class ApiMainController {
return apiMainService.selectSisulOverList(data);
}
@RequestMapping(value = "/sisulDefaultList", produces = "application/json; charset=utf8", method=RequestMethod.POST)
public List<Map<String, Object>> sisulDefaultList(@RequestBody Map<String, Object> data) {
return apiMainService.sisulDefaultList(data);
}
}

@ -5,13 +5,13 @@ import java.util.Map;
public interface ApiMainService {
List<Map<String, Object>> sisulDefaultList(Map<String, Object> data);
List<Map<String, Object>> sisulPenaltyList(Map<String, Object> data);
List<Map<String, Object>> selectSisulDefaultResiList(Map<String, Object> data);
List<Map<String, Object>> selectSisulOverList(Map<String, Object> data);
List<Map<String, Object>> sisulDefaultList(Map<String, Object> data);
}

@ -32,78 +32,6 @@ import com.ibatis.common.resources.Resources;
@Transactional
public class ApiMainServiceImpl implements ApiMainService {
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> sisulDefaultList(Map<String, Object> data) {
List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
try {
String resource = "../api.properties";
Properties properties = new Properties();
Reader reader = Resources.getResourceAsReader(resource);
properties.load(reader);
URL obj = null;
obj = new URL(properties.getProperty("URL")); // API URL
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
con.setRequestMethod("POST"); // GET, POST
con.setRequestProperty("Content-type", "application/json; charset=UTF-8");
con.setDoOutput(true);
// DATA
JSONObject param = new JSONObject();
param.put("stDate", data.get("stDate"));
param.put("edDate", data.get("edDate"));
param.put("carNo", data.get("carNo"));
OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream());
wr.write(param.toString());
wr.flush();
// API 호출
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String line;
StringBuffer sb = new StringBuffer();
while((line = in.readLine()) != null){
sb.append(line);
}
JSONParser parser = new JSONParser();
JSONArray jsonResult = (JSONArray)parser.parse(sb.toString());
Map<String, Object> resCode = new HashMap<>();
resCode.put("resCode", con.getResponseCode());
result.add(resCode);
if(jsonResult.size() != 0) {
result = getListMapFromJsonArray(jsonResult);
}
in.close();
con.disconnect();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
@Override
public List<Map<String, Object>> sisulPenaltyList(Map<String, Object> data) {
List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
@ -313,6 +241,79 @@ public class ApiMainServiceImpl implements ApiMainService {
return result;
}
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> sisulDefaultList(Map<String, Object> data) {
List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
try {
String resource = "../api.properties";
Properties properties = new Properties();
Reader reader = Resources.getResourceAsReader(resource);
properties.load(reader);
URL obj = null;
obj = new URL(properties.getProperty("URL")); // API URL
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
con.setRequestMethod("POST"); // GET, POST
con.setRequestProperty("Content-type", "application/json; charset=UTF-8");
con.setDoOutput(true);
// DATA
JSONObject param = new JSONObject();
param.put("stDate", data.get("stDate"));
param.put("edDate", data.get("edDate"));
param.put("carNo", data.get("carNo"));
OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream());
wr.write(param.toString());
wr.flush();
// API 호출
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String line;
StringBuffer sb = new StringBuffer();
while((line = in.readLine()) != null){
sb.append(line);
}
JSONParser parser = new JSONParser();
JSONArray jsonResult = (JSONArray)parser.parse(sb.toString());
Map<String, Object> resCode = new HashMap<>();
resCode.put("resCode", con.getResponseCode());
result.add(resCode);
if(jsonResult.size() != 0) {
result = getListMapFromJsonArray(jsonResult);
}
in.close();
con.disconnect();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
/**
* jsonObject --> map
* JSONObject JSONArray .

Loading…
Cancel
Save