|
@ -1,7 +1,12 @@
|
|
|
package com.yihu.ehr.service;
|
|
|
|
|
|
import com.yihu.ehr.dbhelper.common.DBList;
|
|
|
import com.yihu.ehr.dbhelper.common.DBQuery;
|
|
|
import com.yihu.ehr.dbhelper.jdbc.DBHelper;
|
|
|
import com.yihu.ehr.framework.model.DataGridResult;
|
|
|
import com.yihu.ehr.framework.model.Result;
|
|
|
import com.yihu.ehr.model.DataAcquistion;
|
|
|
import com.yihu.ehr.service.intf.IDataAcquisitionManager;
|
|
|
import com.yihu.ehr.util.httpclient.HttpClientUtil;
|
|
|
import com.yihu.ehr.util.httpclient.HttpHelper;
|
|
|
import com.yihu.ehr.util.json.JSON;
|
|
|
import org.json.JSONObject;
|
|
@ -9,14 +14,19 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* Created by chenweida on 2016/3/18.
|
|
|
*/
|
|
|
@Service("dataAcquisitionManager")
|
|
|
public class DataAcquisitionManager implements IDataAcquisitionManager {
|
|
|
|
|
|
DBQuery query = new DBQuery();
|
|
|
DBHelper db = new DBHelper();
|
|
|
|
|
|
@Override
|
|
|
public String gate(JSONObject jo, Map<String,Object> params) {
|
|
|
public String gate(JSONObject jo, Map<String, Object> params) {
|
|
|
String responMsg = "";
|
|
|
String path = (String) jo.get("url");
|
|
|
String requestType = (String) jo.get("request_type");//1是查询 2是文件上传
|
|
@ -27,28 +37,144 @@ public class DataAcquisitionManager implements IDataAcquisitionManager {
|
|
|
return responMsg;
|
|
|
}
|
|
|
|
|
|
private String getResponMsg(String path, String requestType, String urlType, Map<String,Object> params) {
|
|
|
//1是查询
|
|
|
if("1".equals(requestType)){
|
|
|
if("1".equals(urlType)){
|
|
|
@Override
|
|
|
public Result getDataAcquisition(int page, int size) throws Exception {
|
|
|
String sql = "select * from data_acquisition where 1=1";
|
|
|
|
|
|
DBList list = query.queryBySql(sql, page, size);
|
|
|
|
|
|
return DataGridResult.fromDBList(list);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public DataAcquistion getDataAcquisitionById(String dataId) throws Exception {
|
|
|
|
|
|
String sql = "select * from data_acquisition where id='" + dataId + "'";
|
|
|
DBList list = query.queryBySql(sql);
|
|
|
if (list != null && list.getList().size() > 0) {
|
|
|
DataAcquistion d = new DataAcquistion();
|
|
|
d.setId((String) list.getList().get(0).get("id"));
|
|
|
d.setName((String) list.getList().get(0).get("name"));
|
|
|
d.setRequest_type((String) list.getList().get(0).get("request_type"));
|
|
|
d.setTransactioncode((String) list.getList().get(0).get("transactioncode"));
|
|
|
d.setUrl((String) list.getList().get(0).get("url"));
|
|
|
d.setUrl_type((String) list.getList().get(0).get("url_type"));
|
|
|
return d;
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result addDataAcquisition(String url, String request_type, String transactioncode, String url_type, String name) throws Exception {
|
|
|
String sql = "insert into data_acquisition (id,url,request_type,transactioncode,url_type,name) values " +
|
|
|
"('" + UUID.randomUUID() + "'," +
|
|
|
" '" + url + "' ," +
|
|
|
" '" + request_type + "' ," +
|
|
|
" '" + transactioncode + "' ," +
|
|
|
" '" + url_type + "' ," +
|
|
|
" '" + name + "' " +
|
|
|
")";
|
|
|
db.execute(sql);
|
|
|
return Result.success("保存成功");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result getDataAcquisitionByCode(String transactioncode) throws Exception {
|
|
|
String sql = "select * from data_acquisition where transactioncode='" + transactioncode + "'";
|
|
|
DBList list = query.queryBySql(sql);
|
|
|
if (list.getList() != null && list.getList().size() > 0) {
|
|
|
return DataGridResult.fromDBList(list);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object getDataAcquisitionByName(String name) throws Exception {
|
|
|
String sql = "select * from data_acquisition where name='" + name + "'";
|
|
|
DBList list = query.queryBySql(sql);
|
|
|
if (list.getList() != null && list.getList().size() > 0) {
|
|
|
return DataGridResult.fromDBList(list);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object getDataAcquisitionByCode(String transactioncode, String id) throws Exception {
|
|
|
String sql = "select * from data_acquisition where transactioncode='" + transactioncode + "' and id !='" + id + "'";
|
|
|
DBList list = query.queryBySql(sql);
|
|
|
if (list.getList() != null && list.getList().size() > 0) {
|
|
|
return DataGridResult.fromDBList(list);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Object getDataAcquisitionByName(String name, String id) throws Exception {
|
|
|
String sql = "select * from data_acquisition where name='" + name + "' and id !='" + id + "'";
|
|
|
DBList list = query.queryBySql(sql);
|
|
|
if (list.getList() != null && list.getList().size() > 0) {
|
|
|
return DataGridResult.fromDBList(list);
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result updateDataAcquisition(String url, String request_type, String transactioncode, String url_type, String name, String id) throws Exception {
|
|
|
String sql = "update data_acquisition set " +
|
|
|
" url= '" + url + "' ," +
|
|
|
" request_type='" + request_type + "' ," +
|
|
|
" transactioncode='" + transactioncode + "' ," +
|
|
|
" url_type='" + url_type + "' ," +
|
|
|
" name='" + name + "' where id='" + id + "'";
|
|
|
db.execute(sql);
|
|
|
|
|
|
return Result.success("更新成功");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result deleteAataAcquisition(String id) throws Exception {
|
|
|
String sql = "delete from data_acquisition where id='" + id + "'";
|
|
|
db.execute(sql);
|
|
|
return Result.success("删除成功");
|
|
|
}
|
|
|
|
|
|
private String getResponMsg(String path, String requestType, String urlType, Map<String, Object> params) {
|
|
|
//1是拉推数据
|
|
|
String responseMsg = "";
|
|
|
if ("1".equals(requestType)) {
|
|
|
if ("1".equals(urlType)) {
|
|
|
//post
|
|
|
responseMsg = HttpHelper.post(path, params).getBody();
|
|
|
} else if ("2".equals(urlType)) {
|
|
|
//get
|
|
|
responseMsg = HttpHelper.get(path, params).getBody();
|
|
|
}
|
|
|
//2文件上传
|
|
|
} else if ("2".equals(requestType)) {
|
|
|
/*
|
|
|
if ("1".equals(urlType)) {
|
|
|
//post
|
|
|
HttpHelper.post(path,params);
|
|
|
}else if ("2".equals(urlType)){
|
|
|
responseMsg = HttpHelper.post(path, params).getBody();
|
|
|
} else if ("2".equals(urlType)) {
|
|
|
//get
|
|
|
HttpHelper.get(path,params);
|
|
|
responseMsg = HttpHelper.get(path, params).getBody();
|
|
|
}
|
|
|
//2是文件上传
|
|
|
}else if("2".equals(requestType)){
|
|
|
*/
|
|
|
File f = JSON.json2File(params);
|
|
|
//文件上传
|
|
|
if("1".equals(urlType)){
|
|
|
if ("1".equals(urlType)) {
|
|
|
//post
|
|
|
HttpHelper.postFile(path,null,f);
|
|
|
responseMsg = HttpHelper.postFile(path, null, f).getBody();
|
|
|
}
|
|
|
//删除文件
|
|
|
f.delete();
|
|
|
}
|
|
|
return "";
|
|
|
return responseMsg;
|
|
|
}
|
|
|
|
|
|
|