Advertisement
Hombre_muerto

FeatureHistoryController

Sep 3rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.34 KB | None | 0 0
  1. package pl.lc.ekartanalyst.basic.controller;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.lang.reflect.Array;
  5. import java.text.SimpleDateFormat;
  6. import java.util.*;
  7.  
  8. import org.apache.poi.hssf.usermodel.HSSFCell;
  9. import org.apache.poi.hssf.usermodel.HSSFRow;
  10. import org.apache.poi.hssf.usermodel.HSSFSheet;
  11. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  12. import org.geotools.data.ows.HTTPResponse;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18.  
  19. import pl.kg.ut.postgres.spatial.json.GeoJson;
  20. import pl.lc.common.core.domain.FileResponse;
  21. import pl.lc.ekartanalyst.basic.dao.proc.BasicProcedures;
  22. import pl.lc.ekartanalyst.basic.dao.proc.FeatureClassesHistory;
  23. import pl.lc.ekartanalyst.basic.dao.proc.FeatureCountProc.CountByFeatureClassNameParams;
  24. import pl.lc.ekartanalyst.basic.dao.proc.FeatureFindProc;
  25. import pl.lc.ekartanalyst.basic.dao.proc.FeatureFindProc.FindByFeatureClassNameParams;
  26. import pl.lc.ekartanalyst.dispatch.dao.proc.DispatchProc;
  27. import pl.lc.ekartanalyst.dispatch.domain.LaneOccupancy;
  28. import pl.lc.ekartanalyst.mapadm.domain.FeatureClass;
  29. import pl.kg.ut.postgres.spatial.json.GeoJsonFeature;
  30.  
  31. import com.google.common.base.Preconditions;
  32. import pl.lc.ut.portal.criterion.sql.ISpatialCriterion;
  33. import pl.lc.ut.portal.http.ResponseUtils;
  34. import pl.lc.ut.portal.web.dao.GeoConjunctionCriterion;
  35. import pl.lc.ut.portal.web.dao.ISpatialComparison;
  36. import pl.lc.ut.portal.web.dao.ISpatialFindCriterion;
  37. import pl.lc.ut.portal.web.dao.ISpatialFindOrder;
  38.  
  39. import javax.servlet.ServletOutputStream;
  40. import javax.servlet.http.HttpServletResponse;
  41. import javax.xml.bind.annotation.XmlTransient;
  42.  
  43. @Controller
  44. @RequestMapping("/basic/feature/history")
  45. public class FeatureHistoryController {
  46.     @RequestMapping(value = "/readHistoryLayer")
  47.     @ResponseBody
  48.     public FeatureClass readHistoryLayer(@RequestParam String featureClassName) {
  49.         Preconditions.checkNotNull(featureClassName);
  50.         return BasicProcedures.getHistoryTablesProc().getHistoryLayer(featureClassName);
  51.     }
  52.  
  53.     @RequestMapping(value = "/countByName")
  54.     @ResponseBody
  55.     public Integer countByName(@RequestBody CountByFeatureClassNameParams params) {
  56.         Preconditions.checkNotNull(params.featureClassName);
  57.         return BasicProcedures.getHistoryTablesProc().countByFeatureClassName(params.featureClassName, params.criterion);
  58.     }
  59.  
  60.     @RequestMapping(value = "/findByName")
  61.     @ResponseBody
  62.     public List<GeoJsonFeature> findByName(
  63.             @RequestBody FindByFeatureClassNameParams params) throws Exception {
  64.         return BasicProcedures.getHistoryTablesProc().findByFeatureClassName(params);
  65.     }
  66.  
  67.     @RequestMapping(value = "/findDeletedByName")
  68.     @ResponseBody
  69.     public List<GeoJsonFeature> findDeletedByName(
  70.             @RequestBody FindByFeatureClassNameParams params) throws Exception {
  71.         return BasicProcedures.getDeletedFeatureHistoryFindProc().findByFeatureClassName(params);
  72.     }
  73.  
  74.     @RequestMapping(value = "/readHistoryForLayers")
  75.     @ResponseBody
  76.     public Map<String, FeatureClassesHistory.ChangesMonit> readHistoryForLayers(@RequestBody FindByFeatureClassNameParams f){
  77.         return new FeatureClassesHistory().temp(f);
  78.     }
  79.  
  80.  
  81.     @RequestMapping(value = "/writeXlsFile")
  82.     @ResponseBody
  83.     public void writeXlsFile(@RequestBody ISpatialFindCriterion criterion, HTTPResponse response) throws Exception{
  84.  
  85.  
  86.  
  87. //        Map<String, FeatureClassesHistory.ChangesMonit> zakladki = new FeatureClassesHistory().temp(f);
  88. //
  89. //        for zakladka :
  90. //        FeatureClass fc = BasicProcedures.getHistoryTablesProc().getHistoryLayer(featureClassName);
  91. //          list<geojson> wiersze = BasicProcedures.getHistoryTablesProc().findByFeatureClassName(params);
  92.  
  93.  
  94.  
  95.         SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss");
  96.         String dateString = format.format( new Date()   );
  97.         String excelFileName = "Zmiany_Olsztyn_"+dateString+".xlsx";//name of excel file
  98.  
  99.         String sheetName = "Sheet1";//name of sheet
  100.  
  101.         HSSFWorkbook wb = new HSSFWorkbook();
  102.         HSSFSheet sheet = wb.createSheet(sheetName);
  103.  
  104.         //iterating r number of rows
  105.         for (int r=0;r < 5; r++ )
  106.         {
  107.             HSSFRow row = sheet.createRow(r);
  108.  
  109.             //iterating c number of columns
  110.             for (int c=0;c < 5; c++ )
  111.             {
  112.                 HSSFCell cell = row.createCell(c);
  113.  
  114.                 cell.setCellValue("Cell "+r+" "+c);
  115.             }
  116.         }
  117.  
  118.         FileOutputStream fileOut = new FileOutputStream(excelFileName);
  119.  
  120.         //write this workbook to an Outputstream.
  121.         wb.write(fileOut);
  122.  
  123.  
  124.     }
  125.  
  126.     @RequestMapping(value = "/writeXlsFileFlash")
  127.     @ResponseBody
  128.     @XmlTransient
  129.     public void writeXlsFile(@RequestBody CritObject crit, HttpServletResponse response) throws Exception{
  130.  
  131. //        SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy_HH-mm-ss");
  132. //        String dateString = format.format( new Date()   );
  133. //        String excelFileName = "Zmiany_Olsztyn_"+dateString+".xlsx";//name of excel file
  134.  
  135.         ResponseUtils.excelResponse(response, "Zmiany_Olsztyn.xls");
  136.         ServletOutputStream out = response.getOutputStream();
  137.  
  138.         ISpatialFindCriterion criterion = crit.criterion;
  139.  
  140.         String sheetName = "Sheet1";//name of sheet
  141.  
  142.         HSSFWorkbook wb = new HSSFWorkbook();
  143.  
  144.         FindByFeatureClassNameParams f = new FindByFeatureClassNameParams(null,0,null,criterion,null);
  145.  
  146.         Map<String, FeatureClassesHistory.ChangesMonit> zakladki = new FeatureClassesHistory().temp(f);
  147.  
  148.         for (FeatureClassesHistory.ChangesMonit zakladka : zakladki.values())
  149.         {
  150.  
  151.             f.featureClassName = zakladka.featureClassName;
  152.             sheetName = f.featureClassName.toString().replace("."," ");
  153.  
  154.             FeatureClass fc = BasicProcedures.getHistoryTablesProc().getHistoryLayer(zakladka.featureClassName);
  155.  
  156.             List<GeoJsonFeature> wiersze = BasicProcedures.getHistoryTablesProc().findByFeatureClassName(f);
  157.  
  158.             HSSFSheet sheet = wb.createSheet(sheetName);
  159.  
  160.             HSSFRow rowH = sheet.createRow(0);
  161.             HSSFCell cellH;
  162.  
  163.             String[] columnNames = { "hst_last_update",
  164.                     "hst_operation_type",
  165.                     "hst_username",
  166.                     "geosecma_src",
  167.                     "geosecma_src_id",
  168.                     "stan",
  169.                     "rodzaj",
  170.                     "numer",
  171.                     "uwagi",
  172.                     "city_id",
  173.                     "street_id",
  174.                     "address_point_id",
  175.                     "city_name",
  176.                     "street_name",
  177.                     "address_point_number",
  178.                     "glebokosc_poczatku",
  179.                     "rzedna_poczatku",
  180.                     "glebokosc_konca",
  181.                     "rzedna_konca",
  182.                     "wlasnosc",
  183.                     "kategoria",
  184.                     "rok_budowy",
  185.                     "wlasciciel",
  186.                     "kaskada",
  187.                     "gid_powiazany_z_geosecma_src_id",
  188.                     "glebokosc_przylacza",
  189.                     "rzedna_przylacza",
  190.                     "glebokosc_wlaczenia",
  191.                     "rzedna_wlaczenia",
  192.                     "protokol_odbioru_koncowego",
  193.                     "data_odbioru_koncowego",
  194.                     "nr_dok_geo_powyk",
  195.                     "dane_inwestora",
  196.                     "ocena_stanu_tech",
  197.                     "f_out_type",
  198.                     "f_level_type_pt1",
  199.                     "f_level_type_pt2",
  200.                     "f_level_type_service",
  201.                     "f_level_type_connection",
  202.                     "ulice",
  203.                     "material",
  204.                     "srednica",
  205.                     "gid",
  206.                     "stan_z_ibak",
  207.                     "the_geom_length",
  208.                     "" };
  209.  
  210.             for (int y = 0; y < 45; y++){
  211.                     cellH = rowH.createCell(y);
  212.                     cellH.setCellValue(columnNames[y]);
  213.             }
  214.  
  215.             //iterating r number of rows
  216.             for (int r=0;r < wiersze.size(); r++ ) {
  217.                 HSSFRow row = sheet.createRow(r+1);
  218.  
  219.                 for (int c = 0; c < 45; c++) {
  220.  
  221.                         HSSFCell cell = row.createCell(c);
  222.                         cell.setCellValue(wiersze.get(r).getProperties().get("hst_last_update").toString());
  223.  
  224.                 }
  225.             }
  226.  
  227. //                Iterator it = wiersze.iterator();
  228. //                    while(it.hasNext())
  229. //                    {
  230. //                        HSSFCell cell = row.createCell();
  231. //                        cell.setCellValue(wiersze.toString());
  232. //                    }
  233.  
  234.         }
  235.  
  236.         FileOutputStream fileOut = new FileOutputStream("Zmiany_Olsztyn.xlsx");
  237.  
  238.         //write this workbook to an Outputstream.
  239.         wb.write(out);
  240.         fileOut.flush();
  241.         fileOut.close();
  242. //        return fileOut;
  243.     }
  244.  
  245.     static class CritObject {
  246.         public ISpatialFindCriterion criterion;
  247.     }
  248.  
  249. //    public class FindByFeatureClassNameParamsHist {
  250. //        public String featureClassName;
  251. //        public Integer start;
  252. //        public Integer limit;
  253. //        public ISpatialFindCriterion criterion;
  254. //        public List<ISpatialFindOrder> order;
  255. //
  256. //        public FindByFeatureClassNameParamsHist() {}
  257. //
  258. //        public FindByFeatureClassNameParamsHist(String featureClassName,
  259. //                                            Integer start, Integer limit,
  260. //                                            ISpatialFindCriterion criterion,
  261. //                                            List<ISpatialFindOrder> order)
  262. //        {
  263. //            this.featureClassName = featureClassName;
  264. //            this.start = start;
  265. //            this.limit = limit;
  266. //            this.criterion = criterion;
  267. //            this.order = order;
  268. //        }
  269. //    }
  270. //
  271. //    public static class FindByLayerIdsParamsHist {
  272. //        public List<Integer> layerIds;
  273. //        public Integer start;
  274. //        public Integer limit;
  275. //        public ISpatialFindCriterion criterion;
  276. //        public List<ISpatialFindOrder> order;
  277. //
  278. //        public FindByLayerIdsParamsHist() {}
  279. //
  280. //        public FindByLayerIdsParamsHist(List<Integer> layerIds,
  281. //                                    Integer start, Integer limit,
  282. //                                    ISpatialFindCriterion criterion,
  283. //                                    List<ISpatialFindOrder> order)
  284. //        {
  285. //            this.layerIds = layerIds;
  286. //            this.start = start;
  287. //            this.limit = limit;
  288. //            this.criterion = criterion;
  289. //            this.order = order;
  290. //        }
  291. //    }
  292. //
  293. //    public ChangesMonit createChangesMonits(FeatureClass fc, int size){
  294. //        ChangesMonit chm = new ChangesMonit();
  295. //        chm.featureClassChanges = size;
  296. //        chm.featureClassLabel = fc.getLabel();
  297. //        chm.featureClassName = fc.getName();
  298. //
  299. //        return chm;
  300. //    }
  301. //
  302. //    public class ChangesMonit {
  303. //
  304. //        public String featureClassLabel;
  305. //        public String featureClassName;
  306. //        public int featureClassChanges;
  307. //
  308. //    }
  309.  
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement