package com.lf.server.service.show;
|
|
import com.alibaba.fastjson.JSON;
|
import com.lf.server.entity.all.ResponseMsg;
|
import com.lf.server.entity.show.ExportEntity;
|
import com.lf.server.helper.RestHelper;
|
import com.lf.server.helper.StringHelper;
|
import org.apache.http.NameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import java.lang.reflect.Field;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 在线制图
|
* @author WWW
|
*/
|
@Service
|
public class ExportService {
|
@Value("${sys.path.exportServer}")
|
private String exportServer;
|
|
public String post(ExportEntity entity) {
|
List<NameValuePair> nvPair = getPostEntity(entity);
|
String url = exportServer + "/Export/Start";
|
|
String str = RestHelper.post(url, nvPair);
|
if (StringHelper.isEmpty(str)) {
|
return null;
|
}
|
|
ResponseMsg<String> msg = JSON.parseObject(str, ResponseMsg.class);
|
if (msg == null || msg.getCode() != 200) {
|
return null;
|
}
|
|
return msg.getResult();
|
}
|
|
private List<NameValuePair> getPostEntity(ExportEntity entity) {
|
List<NameValuePair> list = new ArrayList<NameValuePair>();
|
|
Field[] fields = entity.getClass().getDeclaredFields();
|
for (Field field : fields) {
|
try {
|
field.setAccessible(true);
|
Object obj = field.get(entity);
|
|
String val = null;
|
if (obj != null) {
|
val = String.valueOf(obj);
|
}
|
|
BasicNameValuePair nvp = new BasicNameValuePair(field.getName(), val);
|
list.add(nvp);
|
} catch (Exception ex) {
|
//
|
}
|
}
|
|
return list;
|
}
|
}
|