|  | @@ -6,6 +6,16 @@ import com.deepoove.poi.data.Rows;
 | 
	
		
			
				|  |  |  import com.deepoove.poi.data.TableRenderData;
 | 
	
		
			
				|  |  |  import com.deepoove.poi.data.Tables;
 | 
	
		
			
				|  |  |  import com.deepoove.poi.data.style.BorderStyle;
 | 
	
		
			
				|  |  | +import com.miniframe.core.exception.BusinessException;
 | 
	
		
			
				|  |  | +import com.miniframe.core.ext.UtilTools;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.*;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.dao.DAccidentMapper;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.dao.DJobMapper;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.dao.DSourceMapper;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.dao.DSourceValMapper;
 | 
	
		
			
				|  |  | +import com.miniframe.template.DSourceVo;
 | 
	
		
			
				|  |  | +import com.miniframe.tools.CommonUtils;
 | 
	
		
			
				|  |  | +import com.miniframe.tools.XIDateTimeUtils;
 | 
	
		
			
				|  |  |  import com.miniframe.tools.XIFileUtils;
 | 
	
		
			
				|  |  |  import com.miniframe.tools.XIPdfUtils;
 | 
	
		
			
				|  |  |  import org.apache.poi.xwpf.usermodel.XWPFTable;
 | 
	
	
		
			
				|  | @@ -14,72 +24,174 @@ import java.io.BufferedOutputStream;
 | 
	
		
			
				|  |  |  import java.io.OutputStream;
 | 
	
		
			
				|  |  |  import java.net.URL;
 | 
	
		
			
				|  |  |  import java.util.ArrayList;
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.concurrent.TimeUnit;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  public class WordReport {
 | 
	
		
			
				|  |  | -    public static void testAnimal(OutputStream bos ) throws Exception {
 | 
	
		
			
				|  |  | -        WordData data =new WordData();
 | 
	
		
			
				|  |  | -        data.setPname("1号运输大巷");
 | 
	
		
			
				|  |  | -        data.setStype("火灾源");
 | 
	
		
			
				|  |  | -        data.setQjtime("3h23m12s");
 | 
	
		
			
				|  |  | -        List<String> headers =new ArrayList<>();
 | 
	
		
			
				|  |  | -        headers.add("编号");
 | 
	
		
			
				|  |  | -        headers.add("距起点相对位置");
 | 
	
		
			
				|  |  | -        headers.add("发生时间");
 | 
	
		
			
				|  |  | -        headers.add("火源温度");
 | 
	
		
			
				|  |  | -        headers.add("SO2");
 | 
	
		
			
				|  |  | -        headers.add("CO");
 | 
	
		
			
				|  |  | -        headers.add("CO2");
 | 
	
		
			
				|  |  | -        RowRenderData header = Rows.of(headers.toArray(new String[0]))
 | 
	
		
			
				|  |  | -                .bgColor("F2F2F2")
 | 
	
		
			
				|  |  | -                .center()
 | 
	
		
			
				|  |  | -                .textColor("7F7f7F").textFontFamily("Hei").textFontSize(9).create();
 | 
	
		
			
				|  |  | +    public static void testAnimal(OutputStream bos ,Integer aid) throws Exception {
 | 
	
		
			
				|  |  | +        DAccidentMapper adao= UtilTools.getBean(DAccidentMapper.class);
 | 
	
		
			
				|  |  | +        DAccident accident =adao.selectByPrimaryKey(aid);
 | 
	
		
			
				|  |  | +        if(accident==null){
 | 
	
		
			
				|  |  | +            throw  new BusinessException("");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        DJobMapper jobDao =UtilTools.getBean(DJobMapper.class);
 | 
	
		
			
				|  |  | +        DJob job = jobDao.selectByPrimaryKey(accident.getJid());
 | 
	
		
			
				|  |  | +        if(job==null){//未求解
 | 
	
		
			
				|  |  | +            throw  new BusinessException("");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(job.getState().equals("-1")||job.getState().equals("0")){//求解未完成
 | 
	
		
			
				|  |  | +            throw  new BusinessException("");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Date startTime =XIDateTimeUtils.getDateFromZonedStr(job.getStarttime());
 | 
	
		
			
				|  |  | +        Date endTime =XIDateTimeUtils.getDateFromZonedStr(job.getEndtime());
 | 
	
		
			
				|  |  | +        long timeDifference = endTime.getTime()-startTime.getTime(); // 假设为时间差,单位为毫秒
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<String> rowt =new ArrayList<>();
 | 
	
		
			
				|  |  | -        rowt.add("100");
 | 
	
		
			
				|  |  | -        rowt.add("0.2");
 | 
	
		
			
				|  |  | -        rowt.add("2024.12.7 12:00:00");
 | 
	
		
			
				|  |  | -        rowt.add("837K");
 | 
	
		
			
				|  |  | -        rowt.add("200 ppm/s");
 | 
	
		
			
				|  |  | -        rowt.add("130 ppm/s");
 | 
	
		
			
				|  |  | -        rowt.add("1000 ppm/s");
 | 
	
		
			
				|  |  | +        long seconds = TimeUnit.MILLISECONDS.toSeconds(timeDifference);
 | 
	
		
			
				|  |  | +        long minutes = TimeUnit.MILLISECONDS.toMinutes(timeDifference);
 | 
	
		
			
				|  |  | +        long hours = TimeUnit.MILLISECONDS.toHours(timeDifference);
 | 
	
		
			
				|  |  | +        if(accident.getStype().equals("Fire")){
 | 
	
		
			
				|  |  | +            WordData data =new WordData();
 | 
	
		
			
				|  |  | +            data.setPname("1号运输大巷");
 | 
	
		
			
				|  |  | +            data.setStype("火灾源");
 | 
	
		
			
				|  |  | +            data.setQjtime(hours+"h"+minutes+"m"+seconds+"s");
 | 
	
		
			
				|  |  | +            List<String> headers =new ArrayList<>();
 | 
	
		
			
				|  |  | +            headers.add("编号");
 | 
	
		
			
				|  |  | +            headers.add("距起点相对位置");
 | 
	
		
			
				|  |  | +            headers.add("发生时间");
 | 
	
		
			
				|  |  | +            headers.add("火源温度");
 | 
	
		
			
				|  |  | +            headers.add("SO2");
 | 
	
		
			
				|  |  | +            headers.add("CO");
 | 
	
		
			
				|  |  | +            headers.add("CO2");
 | 
	
		
			
				|  |  | +            RowRenderData header = Rows.of(headers.toArray(new String[0]))
 | 
	
		
			
				|  |  | +                    .bgColor("F2F2F2")
 | 
	
		
			
				|  |  | +                    .center()
 | 
	
		
			
				|  |  | +                    .textColor("7F7f7F").textFontFamily("Hei").textFontSize(9).create();
 | 
	
		
			
				|  |  | +            List<String> rowt =new ArrayList<>();
 | 
	
		
			
				|  |  | +            rowt.add("100");
 | 
	
		
			
				|  |  | +            rowt.add("0.2");
 | 
	
		
			
				|  |  | +            rowt.add("2024.12.7 12:00:00");
 | 
	
		
			
				|  |  | +            rowt.add("837K");
 | 
	
		
			
				|  |  | +            rowt.add("200 ppm/s");
 | 
	
		
			
				|  |  | +            rowt.add("130 ppm/s");
 | 
	
		
			
				|  |  | +            rowt.add("1000 ppm/s");
 | 
	
		
			
				|  |  | +            RowRenderData row = Rows.of(rowt.toArray(new String[0]))
 | 
	
		
			
				|  |  | +                    .center().create();
 | 
	
		
			
				|  |  | +            BorderStyle borderStyle = new BorderStyle();
 | 
	
		
			
				|  |  | +            borderStyle.setColor("A6A6A6");
 | 
	
		
			
				|  |  | +            borderStyle.setSize(4);
 | 
	
		
			
				|  |  | +            borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE);
 | 
	
		
			
				|  |  | +            TableRenderData table = Tables.ofA4MediumWidth().addRow(header).addRow(row).
 | 
	
		
			
				|  |  | +                    border(borderStyle).center()
 | 
	
		
			
				|  |  | +                    .create();
 | 
	
		
			
				|  |  | +            table.addRow(row);
 | 
	
		
			
				|  |  | +            data.setOrder(table);
 | 
	
		
			
				|  |  | +            List<WordPerson> persons =new ArrayList<>();
 | 
	
		
			
				|  |  | +            WordPerson person =new WordPerson();
 | 
	
		
			
				|  |  | +            person.setIndex("1");
 | 
	
		
			
				|  |  | +            person.setCode("23");
 | 
	
		
			
				|  |  | +            person.setNum("32");
 | 
	
		
			
				|  |  | +            person.setPname("3号运输巷道第2开采区");
 | 
	
		
			
				|  |  | +            person.setSite("0.2");
 | 
	
		
			
				|  |  | +            person.setTime("0h30m23s");
 | 
	
		
			
				|  |  | +            persons.add(person);
 | 
	
		
			
				|  |  | +            data.setPersons(persons);
 | 
	
		
			
				|  |  | +            //TODO 文件路径问题
 | 
	
		
			
				|  |  | +//            XWPFTemplate template = XWPFTemplate.compile(XIFileUtils.getResourceFilePath("templates/word/report.docx")).render(data);
 | 
	
		
			
				|  |  | +            XWPFTemplate template = XWPFTemplate.compile("/home/disaster/server/disaster_sever/src/main/resources/templates/word/report.docx").render(data);
 | 
	
		
			
				|  |  | +            template.writeAndClose(bos);
 | 
	
		
			
				|  |  | +        }else if(accident.getStype().equals("Water")){
 | 
	
		
			
				|  |  | +//            data.setStype("水灾灾源");
 | 
	
		
			
				|  |  | +            WaterWordData data =new WaterWordData();
 | 
	
		
			
				|  |  | +            data.setQjtime(hours+"h"+minutes+"m"+seconds+"s");
 | 
	
		
			
				|  |  | +            List<WaterSource> sources =new ArrayList<>();
 | 
	
		
			
				|  |  | +            DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
 | 
	
		
			
				|  |  | +            DSourceSQLBuilder dss = new DSourceSQLBuilder();
 | 
	
		
			
				|  |  | +            DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
 | 
	
		
			
				|  |  | +            dssc.andAidEqualTo(aid);
 | 
	
		
			
				|  |  | +            List<DSource> dources = dsm.selectByExample(dss);
 | 
	
		
			
				|  |  | +            DSourceValSQLBuilder dsvs = new DSourceValSQLBuilder();
 | 
	
		
			
				|  |  | +            DSourceValMapper dsvm = UtilTools.getBean(DSourceValMapper.class);
 | 
	
		
			
				|  |  | +            for (DSource ds : dources) {
 | 
	
		
			
				|  |  | +                DSourceValSQLBuilder.Criteria dsvc = dsvs.createCriteria();
 | 
	
		
			
				|  |  | +                dsvc.andSidEqualTo(ds.getId());
 | 
	
		
			
				|  |  | +                List<DSourceVal> dSourceVals = dsvm.selectByExample(dsvs);
 | 
	
		
			
				|  |  | +                double maxValue = dSourceVals.stream().mapToDouble(DSourceVal::getVal1).max().getAsDouble();
 | 
	
		
			
				|  |  | +                WaterSource source =new WaterSource();
 | 
	
		
			
				|  |  | +                source.setCode(ds.getId().toString());
 | 
	
		
			
				|  |  | +                source.setStype("水灾灾源");
 | 
	
		
			
				|  |  | +                source.setPname(ds.getPname());
 | 
	
		
			
				|  |  | +                source.setSite(CommonUtils.floatTodobule(ds.getSite())+"");
 | 
	
		
			
				|  |  | +                source.setTime(job.getAcctime());
 | 
	
		
			
				|  |  | +                source.setVal(maxValue+"m3/s");
 | 
	
		
			
				|  |  | +                sources.add(source);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            data.setSources(sources);
 | 
	
		
			
				|  |  | +            List<WordPerson> persons =new ArrayList<>();
 | 
	
		
			
				|  |  | +            WordPerson person =new WordPerson();
 | 
	
		
			
				|  |  | +            person.setIndex("1");
 | 
	
		
			
				|  |  | +            person.setCode("23");
 | 
	
		
			
				|  |  | +            person.setNum("32");
 | 
	
		
			
				|  |  | +            person.setPname("3号运输巷道第2开采区");
 | 
	
		
			
				|  |  | +            person.setSite("0.2");
 | 
	
		
			
				|  |  | +            person.setTime("0h30m23s");
 | 
	
		
			
				|  |  | +            persons.add(person);
 | 
	
		
			
				|  |  | +            data.setPersons(persons);
 | 
	
		
			
				|  |  | +            //TODO 文件路径问题
 | 
	
		
			
				|  |  | +//            XWPFTemplate template = XWPFTemplate.compile(XIFileUtils.getResourceFilePath("templates/word/waterreport.docx")).render(data);
 | 
	
		
			
				|  |  | +          XWPFTemplate template = XWPFTemplate.compile("/home/disaster/server/disaster_sever/src/main/resources/templates/word/waterreport.docx").render(data);
 | 
	
		
			
				|  |  | +            template.writeAndClose(bos);
 | 
	
		
			
				|  |  | +        }else if(accident.getStype().equals("Gass1")||accident.getStype().equals("Gass")){
 | 
	
		
			
				|  |  | +            WordData data =new WordData();
 | 
	
		
			
				|  |  | +            data.setPname("1号运输大巷");
 | 
	
		
			
				|  |  | +            data.setStype("瓦斯爆炸灾源");
 | 
	
		
			
				|  |  | +            data.setQjtime(hours+"h"+minutes+"m"+seconds+"s");
 | 
	
		
			
				|  |  | +            List<String> headers =new ArrayList<>();
 | 
	
		
			
				|  |  | +            headers.add("编号");
 | 
	
		
			
				|  |  | +            headers.add("距起点相对位置");
 | 
	
		
			
				|  |  | +            headers.add("发生时间");
 | 
	
		
			
				|  |  | +            headers.add("火源温度");
 | 
	
		
			
				|  |  | +            headers.add("SO2");
 | 
	
		
			
				|  |  | +            headers.add("CO");
 | 
	
		
			
				|  |  | +            headers.add("CO2");
 | 
	
		
			
				|  |  | +            RowRenderData header = Rows.of(headers.toArray(new String[0]))
 | 
	
		
			
				|  |  | +                    .bgColor("F2F2F2")
 | 
	
		
			
				|  |  | +                    .center()
 | 
	
		
			
				|  |  | +                    .textColor("7F7f7F").textFontFamily("Hei").textFontSize(9).create();
 | 
	
		
			
				|  |  | +            List<String> rowt =new ArrayList<>();
 | 
	
		
			
				|  |  | +            rowt.add("100");
 | 
	
		
			
				|  |  | +            rowt.add("0.2");
 | 
	
		
			
				|  |  | +            rowt.add("2024.12.7 12:00:00");
 | 
	
		
			
				|  |  | +            rowt.add("837K");
 | 
	
		
			
				|  |  | +            rowt.add("200 ppm/s");
 | 
	
		
			
				|  |  | +            rowt.add("130 ppm/s");
 | 
	
		
			
				|  |  | +            rowt.add("1000 ppm/s");
 | 
	
		
			
				|  |  | +            RowRenderData row = Rows.of(rowt.toArray(new String[0]))
 | 
	
		
			
				|  |  | +                    .center().create();
 | 
	
		
			
				|  |  | +            BorderStyle borderStyle = new BorderStyle();
 | 
	
		
			
				|  |  | +            borderStyle.setColor("A6A6A6");
 | 
	
		
			
				|  |  | +            borderStyle.setSize(4);
 | 
	
		
			
				|  |  | +            borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE);
 | 
	
		
			
				|  |  | +            TableRenderData table = Tables.ofA4MediumWidth().addRow(header).addRow(row).
 | 
	
		
			
				|  |  | +                    border(borderStyle).center()
 | 
	
		
			
				|  |  | +                    .create();
 | 
	
		
			
				|  |  | +            table.addRow(row);
 | 
	
		
			
				|  |  | +            data.setOrder(table);
 | 
	
		
			
				|  |  | +            List<WordPerson> persons =new ArrayList<>();
 | 
	
		
			
				|  |  | +            WordPerson person =new WordPerson();
 | 
	
		
			
				|  |  | +            person.setIndex("1");
 | 
	
		
			
				|  |  | +            person.setCode("23");
 | 
	
		
			
				|  |  | +            person.setNum("32");
 | 
	
		
			
				|  |  | +            person.setPname("3号运输巷道第2开采区");
 | 
	
		
			
				|  |  | +            person.setSite("0.2");
 | 
	
		
			
				|  |  | +            person.setTime("0h30m23s");
 | 
	
		
			
				|  |  | +            persons.add(person);
 | 
	
		
			
				|  |  | +            data.setPersons(persons);
 | 
	
		
			
				|  |  | +            //TODO 文件路径问题
 | 
	
		
			
				|  |  | +            //XWPFTemplate template = XWPFTemplate.compile(XIFileUtils.getResourceFilePath("templates/word/report.docx")).render(data);
 | 
	
		
			
				|  |  | +            XWPFTemplate template = XWPFTemplate.compile("/home/disaster/server/disaster_sever/src/main/resources/templates/word/report.docx").render(data);
 | 
	
		
			
				|  |  | +            template.writeAndClose(bos);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        RowRenderData row = Rows.of(rowt.toArray(new String[0]))
 | 
	
		
			
				|  |  | -                .center().create();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        BorderStyle borderStyle = new BorderStyle();
 | 
	
		
			
				|  |  | -        borderStyle.setColor("A6A6A6");
 | 
	
		
			
				|  |  | -        borderStyle.setSize(4);
 | 
	
		
			
				|  |  | -        borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE);
 | 
	
		
			
				|  |  | -        TableRenderData table = Tables.ofA4MediumWidth().addRow(header).addRow(row).
 | 
	
		
			
				|  |  | -                border(borderStyle).center()
 | 
	
		
			
				|  |  | -                .create();
 | 
	
		
			
				|  |  | -        table.addRow(row);
 | 
	
		
			
				|  |  | -        table.addRow(row);
 | 
	
		
			
				|  |  | -        data.setOrder(table);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        List<WordPerson> persons =new ArrayList<>();
 | 
	
		
			
				|  |  | -        WordPerson person =new WordPerson();
 | 
	
		
			
				|  |  | -        person.setIndex("1");
 | 
	
		
			
				|  |  | -        person.setCode("23");
 | 
	
		
			
				|  |  | -        person.setNum("32");
 | 
	
		
			
				|  |  | -        person.setPname("3号运输巷道第2开采区");
 | 
	
		
			
				|  |  | -        person.setSite("0.2");
 | 
	
		
			
				|  |  | -        person.setTime("0h30m23s");
 | 
	
		
			
				|  |  | -        persons.add(person);
 | 
	
		
			
				|  |  | -        persons.add(person);
 | 
	
		
			
				|  |  | -        data.setPersons(persons);
 | 
	
		
			
				|  |  | -        //TODO 文件路径问题
 | 
	
		
			
				|  |  | -//        XWPFTemplate template = XWPFTemplate.compile(XIFileUtils.getResourceFilePath("disaster_sever/templates/word/report.docx")).render(data);
 | 
	
		
			
				|  |  | -        XWPFTemplate template = XWPFTemplate.compile("/home/disaster/server/disaster_sever/src/main/resources/templates/word/report.docx").render(data);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        template.writeAndClose(bos);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -//         XWPFTemplate.compile("D://pname.docx").render(new HashMap<String, Object>() {
 | 
	
		
			
				|  |  | -//            {
 | 
	
		
			
				|  |  | -//                put("pname", "sdf");
 | 
	
		
			
				|  |  | -//            }
 | 
	
		
			
				|  |  | -//        }).writeToFile("D:///out_example_animal.docx");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |