commit 6c336b65136404483571494d933061276e6873ee Author: zangshuihua <1920114288@qq.com> Date: Tue Oct 18 17:59:40 2022 +0800 shate diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/shate/DateUploadController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/shate/DateUploadController.java new file mode 100644 index 0000000..11adadf --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/shate/DateUploadController.java @@ -0,0 +1,657 @@ +package com.ruoyi.web.controller.shate; + +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.BarChart; +import com.ruoyi.common.utils.chartForWord.CustomXWPFDocument; +import com.ruoyi.common.utils.shate.PageUtils; + +import com.ruoyi.system.domain_shate.*; +import com.ruoyi.system.service_shate.IDateUploadService; +import com.ruoyi.system.service_shate.IPlantingSuitabilityService; +import com.ruoyi.system.service_shate.ISeedingSuccessService; +import com.ruoyi.system.service_shate.IVegetationHealthServices; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.ResourceUtils; +import org.springframework.web.bind.annotation.*; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.annotation.Resource; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @Author: JinSheng Song + * @Date: 2022/7/11 15:46 + */ +@RestController +@RequestMapping(value = "/api/Upload", produces = "application/json;charset=UTF-8") +@Api(tags = "文件上传记录") + +public class DateUploadController +{ + @Resource + IPlantingSuitabilityService plantingSuitabilityService; + @Resource + IVegetationHealthServices vegetationHealthServices; + @Resource + private IDateUploadService service; + + @Resource + ISeedingSuccessService seedingSuccessService; + + private String FilePathName; + + private String ExePathName; + + private String FilePaths; + + private String ShpPaths; + + + + + @RequestMapping(value = "/SelectUpload",method = {RequestMethod.POST}) + public AjaxResult SelectUpload(@RequestBody paging paging) + { +// LocalDate tomorrow = LocalDate.of(2022,10,2); +// LocalDate today = LocalDate.now(); +// +// if(tomorrow.isAfter(today)==false) +// { +// return AjaxResult.error("软件授权日期已过,请联系管理人员!"); +// } + + String type1=paging.getType1().replace(" ",""); + String type=paging.getType().replace(" ",""); + String type2=""; + + if (paging.getType2()!=null) + { + type2= paging.getType2().toUpperCase(); + } + String date=paging.getUploadTime(); + String name=paging.getType3(); + String dateTime =paging.getDateTime(); + + + if ( name!=null && name!="") + { + if (name.equals("1")) + { + name="M_Heal%"; + } + else if(name.equals("2")) + { + name="H_Heal%"; + } + + } + List Seeding= service.selectUpload(paging.getZone(),type.toUpperCase(), type1.toUpperCase(), + type2,paging.getYear(),date,name,dateTime); + pageVO vaue=new pageVO(); + List value= PageUtils.getListPaging(Seeding,paging.getPageNum(),paging.getPageSize()); + vaue.setValue(value); + vaue.setTotal(Seeding.size()); + return AjaxResult.success(vaue); + } + + + + + + + @RequestMapping(value = "/delUpload",method = {RequestMethod.POST}) + public AjaxResult DelUpload(@RequestBody UplodFile uplodFile) + { + return delUploadFile(uplodFile.getId()); +// List ids=uplodFile.getId(); +// Integer Seeding=0; +// UploadFile file=new UploadFile(); +// for (int i=0; i id) + { + List ids=id; + Integer Seeding=0; + for (int i=0; i dateUploads=infr(uplodFile.getDateUploads()); + + for (int i=0; i dateUploads=infr(uplodFile.getDateUploads()); + + for (int i=0; i infr(List dateUpload) + { + for (int i=0;i id) { + + + List ids = id; + + UploadFile file = new UploadFile(); + + + for (int i = 0; i < ids.size(); i++) { + + Integer Seeding=0; + DateUpload value = service.selectDel(ids.get(i)); + + String type1=value.getType1(); + String type= value.getType(); + + if (type1.equals("EVALUATIONINDICATORS")) { + + //value.getType2(); + + String[] typeValue = value.getFileName().split("2"); + String type2 = typeValue[0]; + type2=type2.substring(0,type2.length()-1); + file.UploadFile1(type2, value.getZone(), value.getDataTime(),service,""); + Seeding= service.DelUpload(ids.get(i)); + if (Seeding==0){return AjaxResult.error("没有此id单据!"+ids.get(i));} + + } + // && + // (type1.equals("RSIMAGES") || type1.equals("PLANTINGDISTRIBUTION") || type1.equals("VEGETATIONHEALTH")) + else if (type.equals("VEGETATIONHEALTH")) + { + String[] typeValue = value.getFileName().split("_"); + String resolution=typeValue[0]; + String type2 = "Heal"; + file.UploadFile1(type2, value.getZone(), value.getDataTime(),service,resolution); + Seeding= service.DelUpload(ids.get(i)); + if (Seeding==0){return AjaxResult.error("没有此id单据!"+ids.get(i));} + } + else + { + + String[] typeValue = value.getFileName().split("_"); + String type2 = typeValue[0]; + file.UploadFile1(type2, value.getZone(), value.getDataTime(),service,""); + Seeding= service.DelUpload(ids.get(i)); + if (Seeding==0){return AjaxResult.error("没有此id单据!"+ids.get(i));} + } + + } + + return AjaxResult.success("成功!"); + } + + public void readXml() { + try { + // 创建解析器工厂 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = factory.newDocumentBuilder(); + // 创建一个Document对象 + + String parent = new File(ResourceUtils.getURL("classpath:").getPath()).getParentFile().getParentFile().getParent(); + + + File file = new File("route.xml"); + Document doc =db.parse(file); + NodeList routeList = doc.getElementsByTagName("Rodel"); + // 遍历每个book节点 + for (int i = 0; i < routeList.getLength(); i++) { + + // 索引从零开始 + org.w3c.dom.Node book = routeList.item(i); + // 获取book节点所有属性集合 + org.w3c.dom.NamedNodeMap attrs = book.getAttributes(); + + + NodeList childNodes = book.getChildNodes(); + for (int k = 0; k < childNodes.getLength(); k++) { + // 区分,去掉空格和换行符 + if (childNodes.item(k).getNodeType() == Node.ELEMENT_NODE) { + + + this.ExePathName=childNodes.item(1).getTextContent().trim(); + + this.FilePathName=childNodes.item(3).getTextContent().trim(); + + this.FilePaths=childNodes.item(5).getTextContent().trim(); + + this.ShpPaths=childNodes.item(7).getTextContent().trim(); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + /** + * 导出Word + * @param + */ + @RequestMapping(value = "/exportWord",method = {RequestMethod.GET}) + @ResponseBody + public void exportWord(HttpServletResponse response, HttpServletRequest request) throws Exception { + //接受前端传来的数据 + String year = "2022";//request.getParameter("year"); + String zone = "01";//request.getParameter("zone"); + //创建文本对象 + CustomXWPFDocument docxDocument = new CustomXWPFDocument(); + //创建标题 + BarChart.setTitle(docxDocument,"Evaluation report of planting monitoring in ITBA Nature Reserve"); + //创建第一个段落的标题 + BarChart.createFirstLevelTopic(docxDocument, "1.Background information"); + //创建第一个段落的内容 + BarChart.createParagraphAndInsertWord(docxDocument, "Date time: "+year); + BarChart.createParagraphAndInsertWord(docxDocument, "Evaluation area: "+zone); + //创建第二段落的标题 + BarChart.createFirstLevelTopic(docxDocument, "2.Results of remote sensing monitoring of seeding success rate"); + //循环判断有多少个资源 + List seedingSuccessRates = seedingSuccessService.sqlSeeding(zone, year); + for (SeedingSuccessRate seedingSuccessRate : seedingSuccessRates) { + //创建第二段落的内容 + BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\1.png"); + BarChart.setPicTitle(docxDocument, "Spatial distribution data of successful seeding regions"); + BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\2.png"); + BarChart.setPicTitle(docxDocument, "Spatial distribution data of seeding success rate"); + BarChart.createParagraphAndInsertWord(docxDocument, ""+BarChart.changeDate(seedingSuccessRate.getImageDate())+". The total planting area in "+seedingSuccessRate.getZone()+" area was "+BarChart.getDoubleNumber((seedingSuccessRate.getSeedingSuccessArea()/seedingSuccessRate.getSeedingSuccess())) +" hm², the vegetation survival area was "+seedingSuccessRate.getSeedingSuccessArea()+" hm², and the seeding success rate was "+seedingSuccessRate.getSeedingSuccess()+"%."); + } + //第三段的标题 + BarChart.createFirstLevelTopic(docxDocument, "3.Results of remote sensing monitoring of vegetation health"); + //获取ProductCode1的集合 + List Heal_code1=new ArrayList<>(); + List vegetationHealths = vegetationHealthServices.sqlInfo(zone, year); + for (VegetationHealth vegetationHealth : vegetationHealths) { + String productCode1 = vegetationHealth.getProductCode1(); + System.out.println(productCode1); + Heal_code1.add(vegetationHealth.getProductCode1()); + } + for(int i = 0; i vegetationHealths_M = vegetationHealthServices.sqlSeeding(zone, Heal_code1.get((i+1)), year); + for (VegetationHealth vegetationHealth_m : vegetationHealths_M) { + //第三段的内容 + //第三段的第一个小标题 + BarChart.createSecondLevelTopic(docxDocument, "3."+(i+1)+".Monitoring results of medium resolution data"); + //第三段的第一个小标题的内容 + BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\2.png"); + BarChart.setPicTitle(docxDocument, "Spatial distribution data of vegetation planting area"); + BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\1.png"); + BarChart.setPicTitle(docxDocument, "Spatial distribution data of vegetation health status"); + //插入柱状图表 + String[] xAxisData = new String[]{"Health", "Normal", "Not-Health"}; + Double m1 = vegetationHealth_m.getHealthy(); + Double m2 = vegetationHealth_m.getNormal(); + Double m3 = vegetationHealth_m.getNotHealthy(); + Double[] yAxisData = new Double[]{m1, m2, m3}; + BarChart.drawTable(docxDocument,xAxisData,yAxisData); + BarChart.setPicTitle(docxDocument, "Statistical data on vegetation health"); + BarChart.createParagraphAndInsertWord(docxDocument, ""+BarChart.changeDate(vegetationHealth_m.getImageDate())+". Based on the monitoring results of high resolution satellite images, the area of healthy vegetation growth in "+vegetationHealth_m.getZone()+" region was "+vegetationHealth_m.getHealthy()+" hm², accounting for "+BarChart.getDoubleNumber((vegetationHealth_m.getHealthy()/vegetationHealth_m.getTotalArea())*100)+"%. The area with normal vegetation growth was "+vegetationHealth_m.getNormal()+" hm², accounting for "+BarChart.getDoubleNumber((vegetationHealth_m.getNormal()/vegetationHealth_m.getTotalArea())*100)+"%. The area of unhealthy vegetation growth was "+vegetationHealth_m.getNotHealthy()+" hm², accounting for "+BarChart.getDoubleNumber((vegetationHealth_m.getNotHealthy()/vegetationHealth_m.getTotalArea())*100)+"%."); + } + //第三段的第二个小标题 + List vegetationHealths_H = vegetationHealthServices.sqlSeeding(zone, Heal_code1.get(i), year); + int j=i+2; + for (VegetationHealth vegetationHealth_h : vegetationHealths_H) { + //第三段的第二个小标题 + BarChart.createSecondLevelTopic(docxDocument, "3."+j+".Monitoring results of high resolution data"); + //第三段的第二个小标题的内容 + BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\1.png"); + BarChart.setPicTitle(docxDocument, "Spatial distribution data of vegetation planting area"); + BarChart.insertPic(docxDocument, "C:\\Users\\xkrs\\Desktop\\pic\\2.png"); + BarChart.setPicTitle(docxDocument, "Spatial distribution data of vegetation health status"); + //此处插入图表 + String[] xAxisData1 = new String[]{"Health", "Normal", "Not-Health"}; + Double h1 = vegetationHealth_h.getHealthy(); + Double h2 = vegetationHealth_h.getNormal(); + Double h3 = vegetationHealth_h.getNotHealthy(); + Double[] yAxisData1 = new Double[]{h1, h2, h3}; + BarChart.drawTable(docxDocument,xAxisData1,yAxisData1); + BarChart.setPicTitle(docxDocument, "Statistical data on vegetation health"); + BarChart.createParagraphAndInsertWord(docxDocument, ""+BarChart.changeDate(vegetationHealth_h.getImageDate())+". Based on the monitoring results of high resolution satellite images, the area of healthy vegetation growth in "+vegetationHealth_h.getZone()+" region was "+vegetationHealth_h.getHealthy()+" hm², accounting for "+BarChart.getDoubleNumber((vegetationHealth_h.getHealthy()/vegetationHealth_h.getTotalArea())*100)+"%. The area with normal vegetation growth was "+vegetationHealth_h.getNormal()+" hm², accounting for "+BarChart.getDoubleNumber((vegetationHealth_h.getNormal()/vegetationHealth_h.getTotalArea())*100)+"%. The area of unhealthy vegetation growth was "+vegetationHealth_h.getNotHealthy()+" hm², accounting for "+BarChart.getDoubleNumber((vegetationHealth_h.getNotHealthy()/vegetationHealth_h.getTotalArea())*100)+"%."); + } + } + //第四个标题 + List plantingSuitabilities = plantingSuitabilityService.sqlSeeding(zone); + for (PlantingSuitability suitability : plantingSuitabilities) { + BarChart.createFirstLevelTopic(docxDocument,"4.Results of remote sensing monitoring of planting suitability"); + //第四个标题的内容 + BarChart.insertPic(docxDocument,"C:\\Users\\xkrs\\Desktop\\pic\\1.png"); + BarChart.setPicTitle(docxDocument,"Spatial distribution data of planting suitability"); + //此处插入图表 + String[] xAxisData2 = new String[]{"Health", "Normal", "Not-Health"}; + Double s1 = suitability.getVerySuitable(); + Double s2 = suitability.getSuitable(); + Double s3 = suitability.getNotSuitable(); + Double[] yAxisData2 = new Double[]{s1, s2, s3}; + BarChart.drawTable(docxDocument,xAxisData2,yAxisData2); + BarChart.setPicTitle(docxDocument,"Spatial distribution data of planting suitability"); + BarChart.createParagraphAndInsertWord(docxDocument,"In "+suitability.getZone()+" region, the area of very suitable region was "+suitability.getVerySuitable()+" hm², accounting for "+BarChart.getDoubleNumber((suitability.getVerySuitable()/suitability.getTotalArea())*100)+"%. The area of suitable grade was "+suitability.getSuitable()+" hm², accounting for "+BarChart.getDoubleNumber((suitability.getSuitable()/suitability.getTotalArea())*100)+"%. The area of unsuitable area was "+suitability.getNotSuitable()+" hm², accounting for "+BarChart.getDoubleNumber((suitability.getNotSuitable()/suitability.getTotalArea())*100)+"%."); + } + response.setCharacterEncoding("UTF-8"); + response.setContentType("application/msword"); + //文件名 + String fileName = "Evaluation report of planting monitoring in ITBA Nature Reserve - V2.0.docx"; + response.setHeader("Content-Disposition","attachment;fileName="+new String(fileName.getBytes("UTF-8"), "ISO-8859-1")); + ServletOutputStream responseOutputStream = response.getOutputStream(); + docxDocument.write(responseOutputStream); + responseOutputStream.flush(); + responseOutputStream.close(); + } + +}