| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.DownloadEntity; |
| | | import com.lf.server.entity.show.ExportEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.FileHelper; |
| | | import com.lf.server.helper.PathHelper; |
| | | import com.lf.server.helper.RestHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import com.lf.server.service.data.DownloadService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.File; |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 在线制图 |
| | |
| | | */ |
| | | @Service |
| | | public class ExportService { |
| | | @Value("${sys.path.exportServer}") |
| | | @Value("${sys.exportServer}") |
| | | private String exportServer; |
| | | |
| | | public String post(ExportEntity entity) { |
| | | List<NameValuePair> nvPair = getPostEntity(entity); |
| | | @Autowired |
| | | PathHelper pathHelper; |
| | | |
| | | @Autowired |
| | | DownloadService downloadService; |
| | | |
| | | /** |
| | | * POST请求出图服务 |
| | | * |
| | | * @param ue 用户类 |
| | | * @param entity 在线制图类 |
| | | * @return 成功 |
| | | * @throws Exception |
| | | */ |
| | | public String post(UserEntity ue, ExportEntity entity) throws Exception { |
| | | Map<String, Object> map = getMapData(entity); |
| | | String url = exportServer + "/Export/Start"; |
| | | |
| | | String str = RestHelper.post(url, nvPair); |
| | | String str = RestHelper.postForRest(url, map); |
| | | if (StringHelper.isEmpty(str)) { |
| | | return null; |
| | | } |
| | | |
| | | ResponseMsg<String> msg = JSON.parseObject(str, ResponseMsg.class); |
| | | if (msg == null || msg.getCode() != 200) { |
| | | if (msg == null || msg.getCode() != StaticData.TWO_HUNDRED) { |
| | | return null; |
| | | } |
| | | |
| | | return msg.getResult(); |
| | | String file = pathHelper.getConfig().getDownloadPath() + File.separator + msg.getResult(); |
| | | File f = new File(file); |
| | | if (!f.exists() && !f.isDirectory()) { |
| | | return null; |
| | | } |
| | | |
| | | DownloadEntity de = getDownloadEntity(ue, entity, file); |
| | | int rows = downloadService.insert(de); |
| | | |
| | | return rows > 0 ? de.getGuid() : null; |
| | | } |
| | | |
| | | private List<NameValuePair> getPostEntity(ExportEntity entity) { |
| | | List<NameValuePair> list = new ArrayList<NameValuePair>(); |
| | | /** |
| | | * 获取Map数据 |
| | | */ |
| | | private Map<String, Object> getMapData(ExportEntity entity) { |
| | | Map<String, Object> map = new HashMap<String, Object>(3); |
| | | |
| | | Field[] fields = entity.getClass().getDeclaredFields(); |
| | | for (Field field : fields) { |
| | | try { |
| | | if ("serialVersionUID".equals(field.getName())) { |
| | | continue; |
| | | } |
| | | |
| | | 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); |
| | | map.put(field.getName(), obj); |
| | | } catch (Exception ex) { |
| | | // |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, ExportEntity entity, String file) throws Exception { |
| | | DownloadEntity de = new DownloadEntity(); |
| | | de.setName(FileHelper.getFileName(file)); |
| | | // 1-Shp文件,2-专题图,3-元数据,4-业务数据,5-管道分析,6-统计报告,7-附件文件,8-瓦片文件 |
| | | de.setType(2); |
| | | de.setSizes(FileHelper.sizeToMb(new File(file).length())); |
| | | de.setDepid(ue.getDepid()); |
| | | de.setDcount(0); |
| | | // de.setPwd(null) |
| | | de.setUrl(FileHelper.getRelativePath(file)); |
| | | // de.setDescr("专题图文件") |
| | | de.setDescr(StringHelper.isEmpty(entity.getTitle()) ? "专题图文件" : entity.getTitle().trim()); |
| | | de.setGuid(FileHelper.getFileMd5(file)); |
| | | de.setCreateUser(ue.getId()); |
| | | // de.setGeom(null) |
| | | |
| | | return de; |
| | | } |
| | | } |