package com.vst.webapp.action;
import com.lowagie.text.Image;
import com.vst.model.*;
import com.vst.service.*;
import com.vst.util.ReportUtil;
import com.vst.util.StringUtil;
import com.vst.webapp.util.FileHelper;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* Created by IntelliJ IDEA.
* User: �������������
* Date: 13.07.2009
* Time: 11:53:17
* To change this template use File | Settings | File Templates.
*/
public class RTFObjectInspection implements Controller {
DetailManager detailManager;
PhotoManager photoManager;
ObjectInspectionManager objectInspectionManager;
ExpertManager expertManager;
CompanyLicenseManager companyLicenseManager;
RegionManager regionManager;
InspectionAnswerManager inspectionAnswerManager;
QuestionManager questionManager;
AnswerManager answerManager;
ThicknessManager thicknessManager;
DiameterManager diameterManager;
MaterialManager materialManager;
GostManager gostManager;
EquipmentInspectionManager equipmentInspectionManager;
PipeLineElementManager pipeLineElementManager;
PipeLineElementDefectManager pipeLineElementDefectManager;
VisualInspectionManager visualInspectionManager;
MaterialClassificationManager materialClassificationManager;
DetailDurabilityManager detailDurabilityManager;
public void setDetailDurabilityManager(DetailDurabilityManager detailDurabilityManager) {
this.detailDurabilityManager = detailDurabilityManager;
}
public void setMaterialClassificationManager(MaterialClassificationManager materialClassificationManager) {
this.materialClassificationManager = materialClassificationManager;
}
public void setVisualInspectionManager(VisualInspectionManager visualInspectionManager) {
this.visualInspectionManager = visualInspectionManager;
}
public void setPipeLineElementManager(PipeLineElementManager pipeLineElementManager) {
this.pipeLineElementManager = pipeLineElementManager;
}
public PipeLineElementDefectManager getPipeLineElementDefectManager() {
return pipeLineElementDefectManager;
}
public void setPipeLineElementDefectManager(PipeLineElementDefectManager pipeLineElementDefectManager) {
this.pipeLineElementDefectManager = pipeLineElementDefectManager;
}
public void setEquipmentInspectionManager(EquipmentInspectionManager equipmentInspectionManager) {
this.equipmentInspectionManager = equipmentInspectionManager;
}
public void setGostManager(GostManager gostManager) {
this.gostManager = gostManager;
}
public void setDiameterManager(DiameterManager diameterManager) {
this.diameterManager = diameterManager;
}
public void setMaterialManager(MaterialManager materialManager) {
this.materialManager = materialManager;
}
public void setThicknessManager(ThicknessManager thicknessManager) {
this.thicknessManager = thicknessManager;
}
public void setDetailManager(DetailManager detailManager) {
this.detailManager = detailManager;
}
public void setQuestionManager(QuestionManager questionManager) {
this.questionManager = questionManager;
}
public void setAnswerManager(AnswerManager answerManager) {
this.answerManager = answerManager;
}
public InspectionAnswerManager getInspectionAnswerManager() {
return inspectionAnswerManager;
}
public void setInspectionAnswerManager(InspectionAnswerManager inspectionAnswerManager) {
this.inspectionAnswerManager = inspectionAnswerManager;
}
public void setRegionManager(RegionManager regionManager) {
this.regionManager = regionManager;
}
public void setPhotoManager(PhotoManager photoManager) {
this.photoManager = photoManager;
}
public void setCompanyLicenseManager(CompanyLicenseManager companyLicenseManager) {
this.companyLicenseManager = companyLicenseManager;
}
public void setExpertManager(ExpertManager expertManager) {
this.expertManager = expertManager;
}
public void setObjectInspectionManager(ObjectInspectionManager objectInspectionManager) {
this.objectInspectionManager = objectInspectionManager;
}
public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
Integer objectId = Integer.valueOf(httpServletRequest.getParameter("objectId"));
ObjectInspection objectInspection = objectInspectionManager.getObjectInspectionBy(objectId);
String filename = FileHelper.getUniqueFileName(httpServletRequest);
FileInputStream fileInputStream = new FileInputStream(FileHelper.getCurrentPath(httpServletRequest) + "document.mht");
File file = new File(FileHelper.getCurrentPath(httpServletRequest) + "document.mht");
byte[] templateBytes = new byte[(int) file.length()];
fileInputStream.read(templateBytes);
StringBuilder template = ReportUtil.convertToStringBuilder(templateBytes);
template = ReportUtil.changeFile(template, "document", "8D882234");
fileInputStream.close();
if (template.length() == 0) {
throw new Exception("Template is not specifired.");
}
ReportUtil.replaceAllLabel(template, String.valueOf(new char[]{(char) 61, (char) 13, (char) 10}), "");
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
ReportUtil.replaceAllLabel(template, "ObjectName", objectInspection.getCustomerOrganization());
ReportUtil.replaceAllLabel(template, "CustomerFio", objectInspection.getCustomerFio());
ReportUtil.replaceAllLabel(template, "CustomerHouse", objectInspection.getCustomerHouse());
ReportUtil.replaceAllLabel(template, "CustomerSity", objectInspection.getCustomerSity());
ReportUtil.replaceAllLabel(template, "telephoneNumber", objectInspection.getCustomerTelephone());
ReportUtil.replaceAllLabel(template, "postIndex", objectInspection.getCustomerPostIndex());
ReportUtil.replaceAllLabel(template, "CustomerStreet", objectInspection.getCustomerStreet());
ReportUtil.replaceAllLabel(template, "Year", String.valueOf(calendar.get(Calendar.YEAR)));
Region region = regionManager.getRegionById(objectInspection.getCustomerRegion().getRegionId());
ReportUtil.replaceAllLabel(template, "CustomerRegion", region.getRegionName());
List expertList = objectInspection.getTrueexpertList();
String extractBookmark = ReportUtil.extractBookmark(template, "ExpertBookmark", "%expert_bookmark%");
String resultInformation = "";
String newInformation = "";
for (int i = 0; i < expertList.size(); i++) {
Expert expert = (Expert) expertList.get(i);
expert = (Expert) expertManager.getExpertById(expert.getExpertId());
newInformation = extractBookmark.replaceAll("ExpertFio", String.valueOf(expert.getExpertFio()));
newInformation = newInformation.replaceAll("ExpertComment", String.valueOf(expert.getDescription()));
newInformation = newInformation.replaceAll("ExpertNumber", String.valueOf(expert.getNumberExpert()));
newInformation = newInformation.replaceAll("ExpertDocumentDateBegin", String.valueOf(expert.getStartDateForLook()));
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%expert_bookmark%", resultInformation);
List companyLicenseList = companyLicenseManager.getList();
ReportUtil.extractBookmarkForImageList(template, "FirstCompanyLicense", "%first_company_license%");
ReportUtil.extractBookmarkForImageList(template, "SecondCompanyLicense", "%second_company_license%");
resultInformation = "";
for (int i = 0; i < companyLicenseList.size(); i++) {
CompanyLicense companyLicense = (CompanyLicense) companyLicenseList.get(i);
Photo photo = photoManager.getByIdPhoto(companyLicense.getPhoto().getPhotoId());
File filePhoto = new File(photo.getWayToPhoto());
if (filePhoto.exists()) {
filePhoto.delete();
}
filePhoto.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(photo.getWayToPhoto());
Blob blob = photo.getPhotoPlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
Image image = Image.getInstance(photo.getWayToPhoto());
newInformation = ReportUtil.createPhoto("CompanyLicense", image.height(), image.width(), photo.getWayToPhoto());
ReportUtil.insertImage(photo.getWayToPhoto(), photo.getPhotoPlob().getBytes(1, (int) photo.getPhotoPlob().length()), template);
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%first_company_license%", resultInformation);
ReportUtil.replaceAllLabel(template, "%second_company_license%", resultInformation);
objectInspectionManager.fillQuestionsLists(objectInspection);
List questions = objectInspection.getObjectQuestions();
extractBookmark = ReportUtil.extractBookmarkForTable(template, "FirstObjectQuestionsBookmark", "%first_object_questions_bookmark%");
ReportUtil.extractBookmarkForTable(template, "SecondObjectQuestionsBookmark", "%second_object_questions_bookmark%");
resultInformation = "";
if (questions != null && !questions.isEmpty()) {
for (int i = 0; i < questions.size(); i++) {
String answerString = "";
InspectionAnswer inspectionAnswer = (InspectionAnswer) questions.get(i);
inspectionAnswer = inspectionAnswerManager.getById(inspectionAnswer.getInspectionAnswerId());
answerString = inspectionAnswer.getAnswerContents();
if (inspectionAnswer.getAnswerComment() != null) {
answerString += "\n" + inspectionAnswer.getAnswerComment();
}
newInformation = extractBookmark.replaceAll("number", String.valueOf(i + 1));
newInformation = newInformation.replaceAll("objectQuestion", getQuestion(inspectionAnswer));
newInformation = newInformation.replaceAll("objectAnswer", answerString);
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%first_object_questions_bookmark%", resultInformation);
ReportUtil.replaceAllLabel(template, "%second_object_questions_bookmark%", resultInformation);
}
List questions1 = new ArrayList();
List questions2 = new ArrayList();
List questions3 = new ArrayList();
questions = objectInspection.getDocQuestions();
if (questions != null && !questions.isEmpty()) {
for (int i = 0; i < questions.size(); i++) {
InspectionAnswer inspectionAnswer = (InspectionAnswer) questions.get(i);
inspectionAnswer = inspectionAnswerManager.getById(inspectionAnswer.getInspectionAnswerId());
if (inspectionAnswer.getQuestion().getDocumentType().getDocumentTypeId().longValue() == 1) {
questions1.add(inspectionAnswer);
} else if (inspectionAnswer.getQuestion().getDocumentType().getDocumentTypeId().longValue() == 2) {
questions2.add(inspectionAnswer);
} else if (inspectionAnswer.getQuestion().getDocumentType().getDocumentTypeId().longValue() == 3) {
questions3.add(inspectionAnswer);
}
}
}
extractBookmark = ReportUtil.extractBookmarkForTableInTable(template, "FirstDocumentQuestionsBookmarkOne", "%first_document_questions_bookmark_one%");
ReportUtil.extractBookmarkForTableInTable(template, "SecondDocumentQuestionsBookmarkOne", "%second_document_questions_bookmark_one%");
resultInformation = "";
if (questions1 != null && !questions1.isEmpty()) {
for (int i = 0; i < questions1.size(); i++) {
InspectionAnswer inspectionAnswer = (InspectionAnswer) questions1.get(i);
inspectionAnswer = inspectionAnswerManager.getById(inspectionAnswer.getInspectionAnswerId());
newInformation = extractBookmark.replaceAll("objectQuestion", getQuestion(inspectionAnswer));
newInformation = newInformation.replaceAll("objectAnswer", getAnswer(inspectionAnswer));
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%first_document_questions_bookmark_one%", resultInformation);
ReportUtil.replaceAllLabel(template, "%second_document_questions_bookmark_one%", resultInformation);
}
extractBookmark = ReportUtil.extractBookmarkForTableInTable(template, "FirstDocumentQuestionsBookmarkThree", "%first_document_questions_bookmark_three%");
ReportUtil.extractBookmarkForTableInTable(template, "SecondDocumentQuestionsBookmarkThree", "%second_document_questions_bookmark_three%");
resultInformation = "";
if (questions2 != null && !questions2.isEmpty()) {
for (int i = 0; i < questions2.size(); i++) {
InspectionAnswer inspectionAnswer = (InspectionAnswer) questions2.get(i);
inspectionAnswer = inspectionAnswerManager.getById(inspectionAnswer.getInspectionAnswerId());
newInformation = extractBookmark.replaceAll("objectQuestion", getQuestion(inspectionAnswer));
newInformation = newInformation.replaceAll("objectAnswer", getAnswer(inspectionAnswer));
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%first_document_questions_bookmark_three%", resultInformation);
ReportUtil.replaceAllLabel(template, "%second_document_questions_bookmark_three%", resultInformation);
}
extractBookmark = ReportUtil.extractBookmarkForTableInTable(template, "FirstDocumentQuestionsBookmarkTwo", "%first_ddocument_questions_bookmark_two%");
ReportUtil.extractBookmarkForTableInTable(template, "SecondDocumentQuestionsBookmarkTwo", "%second_document_questions_bookmark_two%");
resultInformation = "";
if (questions3 != null && !questions3.isEmpty()) {
for (int i = 0; i < questions3.size(); i++) {
InspectionAnswer inspectionAnswer = (InspectionAnswer) questions3.get(i);
inspectionAnswer = inspectionAnswerManager.getById(inspectionAnswer.getInspectionAnswerId());
newInformation = extractBookmark.replaceAll("objectQuestion", getQuestion(inspectionAnswer));
newInformation = newInformation.replaceAll("objectAnswer", getAnswer(inspectionAnswer));
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%first_ddocument_questions_bookmark_two%", resultInformation);
ReportUtil.replaceAllLabel(template, "%second_document_questions_bookmark_two%", resultInformation);
}
List pipeList = detailManager.getAllPipe();
List tapList = detailManager.getAllTapGroupByCorner();
List transitionList = detailManager.getAllTransition();
extractBookmark = ReportUtil.extractBookmarkForTable(template, "PipeDetailList", "%pipe_detail_list%");
resultInformation = "";
int j = 1;
if (pipeList != null && !pipeList.isEmpty()) {
for (int i = 0; i < pipeList.size(); i++) {
Pipe pipe = (Pipe) pipeList.get(i);
Gost gost = gostManager.getGostById(pipe.getGost().getGostId());
Diameter diameter = diameterManager.getDiameterById(pipe.getDiametr().getDiametrId());
Thickness thickness = thicknessManager.getThicknessById(pipe.getThickness().getThicknessId());
Material material = materialManager.getMaterial(String.valueOf(pipe.getMaterial().getMaterialId()));
newInformation = extractBookmark.replaceAll("Num", String.valueOf(j++));
newInformation = newInformation.replaceAll("ElementName", "Труба");
newInformation = newInformation.replaceAll("Diameter", String.valueOf(diameter.getDiametrCount()));
newInformation = newInformation.replaceAll("Thickness", String.valueOf(thickness.getThicknessCount()));
newInformation = newInformation.replaceAll("Material", material.getMaterialName());
newInformation = newInformation.replaceAll("Gost", gost.getGostName());
newInformation = newInformation.replaceAll("Information", "");
resultInformation += newInformation;
}
}
if (tapList != null && !tapList.isEmpty()) {
for (int i = 0; i < tapList.size(); i++) {
Tap tap = (Tap) tapList.get(i);
Diameter diameter = diameterManager.getDiameterById(tap.getDiametr().getDiametrId());
Thickness thickness = thicknessManager.getThicknessById(tap.getThickness().getThicknessId());
Material material = materialManager.getMaterial(String.valueOf(tap.getMaterial().getMaterialId()));
Gost gost = gostManager.getGostById(tap.getGost().getGostId());
newInformation = extractBookmark.replaceAll("Num", String.valueOf(j++));
newInformation = newInformation.replaceAll("ElementName", "Угольник " + tap.getCorner());
newInformation = newInformation.replaceAll("Diameter", String.valueOf(diameter.getDiametrCount()));
newInformation = newInformation.replaceAll("Thickness", String.valueOf(thickness.getThicknessCount()));
newInformation = newInformation.replaceAll("Material", material.getMaterialName());
newInformation = newInformation.replaceAll("Gost", gost.getGostName());
newInformation = newInformation.replaceAll("Information", "");
resultInformation += newInformation;
}
}
if (transitionList != null && !transitionList.isEmpty()) {
for (int i = 0; i < transitionList.size(); i++) {
Transition transition = (Transition) transitionList.get(i);
Diameter diameter1 = diameterManager.getDiameterById(transition.getFirstDiametr().getDiametrId());
Thickness thickness1 = thicknessManager.getThicknessById(transition.getFirstThickness().getThicknessId());
Diameter diameter2 = diameterManager.getDiameterById(transition.getSecondDiametr().getDiametrId());
Thickness thickness2 = thicknessManager.getThicknessById(transition.getSecondThickness().getThicknessId());
Material material = materialManager.getMaterial(String.valueOf(transition.getMaterial().getMaterialId()));
Gost gost = gostManager.getGostById(transition.getGost().getGostId());
newInformation = extractBookmark.replaceAll("Num", String.valueOf(j++));
newInformation = newInformation.replaceAll("ElementName", "Переход");
newInformation = newInformation.replaceAll("Diameter", diameter1.getDiametrCount() + "x" + diameter2.getDiametrCount());
newInformation = newInformation.replaceAll("Thickness", thickness1.getThicknessCount() + "x" + thickness2.getThicknessCount());
newInformation = newInformation.replaceAll("Material", material.getMaterialName());
newInformation = newInformation.replaceAll("Gost", gost.getGostName());
newInformation = newInformation.replaceAll("Information", "");
resultInformation += newInformation;
}
}
ReportUtil.replaceAllLabel(template, "%pipe_detail_list%", resultInformation);
List flangeList = detailManager.getAllFlange();
extractBookmark = ReportUtil.extractBookmarkForTable(template, "FlangeList", "%flange_list%");
resultInformation = "";
if (flangeList != null && !flangeList.isEmpty()) {
for (int i = 0; i < flangeList.size(); i++) {
Flange flange = (Flange) flangeList.get(i);
Gost gost = gostManager.getGostById(flange.getGost().getGostId());
Diameter diameter = diameterManager.getDiameterById(flange.getDiametr().getDiametrId());
newInformation = extractBookmark.replaceAll("Num", String.valueOf(i + 1));
newInformation = newInformation.replaceAll("ElementName", "Фланец");
newInformation = newInformation.replaceAll("Diameter", String.valueOf(diameter.getDiametrCount()));
newInformation = newInformation.replaceAll("Pressure", String.valueOf(flange.getPressure()));
newInformation = newInformation.replaceAll("Gost", gost.getGostName());
newInformation = newInformation.replaceAll("Information", "");
resultInformation += newInformation;
}
}
ReportUtil.replaceAllLabel(template, "%flange_list%", resultInformation);
List equipmentInspectionList = equipmentInspectionManager.getList();
extractBookmark = ReportUtil.extractBookmarkForTable(template, "EquipmentInspection", "%equipment_inspection%");
resultInformation = "";
if (equipmentInspectionList != null && !equipmentInspectionList.isEmpty()) {
for (int i = 0; i < equipmentInspectionList.size(); i++) {
EquipmentInspection equipmentInspection = (EquipmentInspection) equipmentInspectionList.get(i);
newInformation = extractBookmark.replaceAll("number", String.valueOf(i + 1));
newInformation = newInformation.replaceAll("type", equipmentInspection.getType());
newInformation = newInformation.replaceAll("mark", equipmentInspection.getMark());
if (equipmentInspection.getDateForLook() == null) {
newInformation = newInformation.replaceAll("date", " ");
} else {
newInformation = newInformation.replaceAll("date", equipmentInspection.getDateForLook());
}
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%equipment_inspection%", resultInformation);
}
List pipeLineList = objectInspection.getPipeLineList();
List defectList = new ArrayList();
for (int i = 0; i < pipeLineList.size(); i++) {
PipeLineElement pipeLineElement = (PipeLineElement) pipeLineList.get(i);
defectList.addAll(pipeLineElement.getPipeLineElementDefectList());
}
ReportUtil.extractBookmarkForImageList(template, "DefectPhotoBookmark", "%defect_photo_bookmark%");
resultInformation = "";
for (int i = 0; i < defectList.size(); i++) {
PipeLineElementDefect pipeLineElementDefect = (PipeLineElementDefect) defectList.get(i);
Photo photo1 = photoManager.getByIdPhoto(pipeLineElementDefect.getFirstPhoto().getPhotoId());
Photo photo2 = photoManager.getByIdPhoto(pipeLineElementDefect.getSecondPhoto().getPhotoId());
if (!photo1.getWayToPhoto().equals("no photo")) {
File filePhoto = new File(photo1.getWayToPhoto());
if (filePhoto.exists()) {
filePhoto.delete();
}
filePhoto.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(photo1.getWayToPhoto());
Blob blob = photo1.getPhotoPlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
Image image = Image.getInstance(photo1.getWayToPhoto());
newInformation = ReportUtil.createPhoto("DefectPhotoBookmark", image.height(), image.width(), photo1.getWayToPhoto());
ReportUtil.insertImage(photo1.getWayToPhoto(), photo1.getPhotoPlob().getBytes(1, (int) photo1.getPhotoPlob().length()), template);
}
if (!photo2.getWayToPhoto().equals("no photo")) {
File filePhoto = new File(photo2.getWayToPhoto());
if (filePhoto.exists()) {
filePhoto.delete();
}
filePhoto.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(photo2.getWayToPhoto());
Blob blob = photo2.getPhotoPlob();
byte[] bufer = new byte[62000];
InputStream inputStream = blob.getBinaryStream();
while (inputStream.read(bufer) != -1) {
fileOutputStream.write(bufer);
}
inputStream.close();
fileOutputStream.close();
Image image = Image.getInstance(photo2.getWayToPhoto());
newInformation += ReportUtil.createPhoto("DefectPhotoBookmark", image.height(), image.width(), photo2.getWayToPhoto());
ReportUtil.insertImage(photo2.getWayToPhoto(), photo2.getPhotoPlob().getBytes(1, (int) photo2.getPhotoPlob().length()), template);
}
newInformation += "\n<p class=3DMsoNormal align=3Dcenter style=3D'text-align:center'>" + "Фото " + String.valueOf(i + 1) + ". " + pipeLineElementDefect.getComment() + "</p>\n";
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%defect_photo_bookmark%", resultInformation);
List pipeLine = new ArrayList();
for (int i = 1; i < 7; i++) {
pipeLine.addAll(pipeLineElementManager.getPipeLineListByObjectInspectionAndDetailType(new Integer(i), objectId, FileHelper.getCurrentPath(httpServletRequest)));
}
extractBookmark = ReportUtil.extractBookmarkForTableInTable(template, "PipeLineElementListFourDocument", "%pipe_line_element_list_fourdocument%");
resultInformation = "";
for (int i = 0; i < pipeLine.size(); i++) {
PipeLineElement pipeLineElement = (PipeLineElement) pipeLine.get(i);
Detail detail = detailManager.getDetailById(pipeLineElement.getDetail().getDetailId());
MaterialClassification materialClassification = materialClassificationManager.getMaterialClassificationByMaterialId(Integer.valueOf(detail.getMaterial().getMaterialId().toString()));
double durability = getMiddleDurability(pipeLineElement, FileHelper.getCurrentPath(httpServletRequest));
newInformation = extractBookmark.replaceAll("numberPosition", String.valueOf(i + 1));
if (materialClassification != null) {
newInformation = newInformation.replaceAll("powerOne", String.valueOf(materialClassification.getPowerOne()));
newInformation = newInformation.replaceAll("powerTwo", String.valueOf(materialClassification.getPowerTwo()));
newInformation = newInformation.replaceAll("resultDurability", getDurabilityResult(durability, materialClassification));
}
newInformation = newInformation.replaceAll("numberElement", pipeLineElement.getNumberElement());
newInformation = newInformation.replaceAll("material", detail.getMaterial().getMaterialName());
if (durability==-1){
newInformation = newInformation.replaceAll("durability", "");
}else{
newInformation = newInformation.replaceAll("durability", String.valueOf(durability));
}
newInformation = newInformation.replaceAll("description", " ");
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%pipe_line_element_list_fourdocument%", resultInformation);
extractBookmark = ReportUtil.extractBookmarkForTableInTable(template, "PipeLineElementListFiveDocument", "%pipe_line_element_list_fivedocument%");
resultInformation = "";
for (int i = 0; i < pipeLine.size(); i++) {
PipeLineElement pipeLineElement = (PipeLineElement) pipeLine.get(i);
VisualInspection visualInspection = visualInspectionManager.getById(pipeLineElement.getVisualInspection().getInspectionId());
newInformation = extractBookmark.replaceAll("numberPosition", String.valueOf(i + 1));
newInformation = newInformation.replaceAll("numberElement", pipeLineElement.getNumberElement());
newInformation = newInformation.replaceAll("realThickness", String.valueOf(pipeLineElement.getThickness()));
if (visualInspection.isInspectionValidity()) {
newInformation = newInformation.replaceAll("inspectionValidity", "годен");
} else {
newInformation = newInformation.replaceAll("inspectionValidity", "не годен");
}
newInformation = newInformation.replaceAll("description", visualInspection.getInspectionDescription());
if (pipeLineElement.getDetailType().getTypeId().intValue() == 1) {
Pipe pipe = detailManager.getPipeById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", pipe.getDiametr().getDiametrCount() + "*" + pipe.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 2) {
Tap tap = detailManager.getTapById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", tap.getDiametr().getDiametrCount() + "*" + tap.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 5) {
Zaglushka zaglushka = detailManager.getZaglushkaById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", zaglushka.getDiametr().getDiametrCount() + "*" + zaglushka.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 6) {
Flange flange = detailManager.getFlangeById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", flange.getDiametr().getDiametrCount() + "*" + flange.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 3) {
Transition transition = detailManager.getTransitionById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", transition.getFirstDiametr().getDiametrCount() + "*" + transition.getFirstThickness().getThicknessCount() + "\n<span style=3D'mso-bookmark:PipeLineElementListFourDocument'><span style=3D'font-size:9.0pt;mso-bidi-font-family:Arial'>Ø </span></span>" + transition.getSecondDiametr().getDiametrCount() + "*" + transition.getSecondThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 4) {
Tee tee = detailManager.getTeeById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", tee.getFirstDiametr().getDiametrCount() + "*" + tee.getFirstThickness().getThicknessCount() + "\n<span style=3D'mso-bookmark:PipeLineElementListFourDocument'><span style=3D'font-size:9.0pt;mso-bidi-font-family:Arial'>Ø </span></span>" + tee.getSecondDiametr().getDiametrCount() + "*" + tee.getSecondThickness().getThicknessCount());
}
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%pipe_line_element_list_fivedocument%", resultInformation);
extractBookmark = ReportUtil.extractBookmarkForTableInTable(template, "DefectDocument", "%defect_document%");
resultInformation = "";
for (int i = 0; i < pipeLine.size(); i++) {
PipeLineElement pipeLineElement = (PipeLineElement) pipeLine.get(i);
VisualInspection visualInspection = visualInspectionManager.getById(pipeLineElement.getVisualInspection().getInspectionId());
newInformation = extractBookmark.replaceAll("numberPosition", String.valueOf(i + 1));
newInformation = newInformation.replaceAll("numberElement", pipeLineElement.getNumberElement());
if (visualInspection.isInspectionValidity()) {
newInformation = newInformation.replaceAll("resultDurability", "годен");
} else {
newInformation = newInformation.replaceAll("resultDurability", "не годен");
}
newInformation = newInformation.replaceAll("description", visualInspection.getInspectionDescription());
if (pipeLineElement.getDetailType().getTypeId().intValue() == 1) {
Pipe pipe = detailManager.getPipeById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", pipe.getDiametr().getDiametrCount() + "*" + pipe.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 2) {
Tap tap = detailManager.getTapById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", tap.getDiametr().getDiametrCount() + "*" + tap.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 5) {
Zaglushka zaglushka = detailManager.getZaglushkaById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", zaglushka.getDiametr().getDiametrCount() + "*" + zaglushka.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 6) {
Flange flange = detailManager.getFlangeById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", flange.getDiametr().getDiametrCount() + "*" + flange.getThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 3) {
Transition transition = detailManager.getTransitionById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", transition.getFirstDiametr().getDiametrCount() + "*" + transition.getFirstThickness().getThicknessCount() + "\n<span style=3D'mso-bookmark:PipeLineElementListFourDocument'><span style=3D'font-size:9.0pt;mso-bidi-font-family:Arial'>Ø </span></span>" + transition.getSecondDiametr().getDiametrCount() + "*" + transition.getSecondThickness().getThicknessCount());
} else if (pipeLineElement.getDetailType().getTypeId().intValue() == 4) {
Tee tee = detailManager.getTeeById(pipeLineElement.getDetail().getDetailId());
newInformation = newInformation.replaceAll("progectSize", tee.getFirstDiametr().getDiametrCount() + "*" + tee.getFirstThickness().getThicknessCount() + "\n<span style=3D'mso-bookmark:PipeLineElementListFourDocument'><span style=3D'font-size:9.0pt;mso-bidi-font-family:Arial'>Ø </span></span>" + tee.getSecondDiametr().getDiametrCount() + "*" + tee.getSecondThickness().getThicknessCount());
}
newInformation = newInformation.replaceAll("defect", getDefectList(pipeLineElement, FileHelper.getCurrentPath(httpServletRequest)));
resultInformation += newInformation;
}
ReportUtil.replaceAllLabel(template, "%defect_document%", resultInformation);
template = new StringBuilder(StringUtil.modifyRussianEncoding(template.toString()));
File tmpFile = new File(filename);
FileOutputStream fileOutputStream = new FileOutputStream(tmpFile.getAbsolutePath());
fileOutputStream.write(template.toString().getBytes());
fileOutputStream.close();
return new ModelAndView("redirect:" + FileHelper.getFileName(filename));
}
private String getAnswer(InspectionAnswer inspectionAnswer) {
String answerString = "";
if (inspectionAnswer.getAnswers() != null && !inspectionAnswer.getAnswers().isEmpty()) {
List answers = inspectionAnswer.getAnswers();
for (int j = 0; j < answers.size(); j++) {
Answer answer = (Answer) answers.get(j);
if (answer.getAnswerId() != null && answer.getAnswerId().longValue() != -1) {
answer = answerManager.getAnswer(String.valueOf(answer.getAnswerId()));
answerString += answer.getContents();
if (j != (answers.size() - 1)) {
answerString += ";\n";
}
}
}
}
if (inspectionAnswer.getAnswerComment() != null) {
answerString += "\n" + inspectionAnswer.getAnswerComment();
}
return answerString;
}
private String getQuestion(InspectionAnswer inspectionAnswer) {
String questionString = "";
if (inspectionAnswer.getQuestion().getQuestionId() != null) {
Question question = questionManager.getQuestion(String.valueOf(inspectionAnswer.getQuestion().getQuestionId()));
questionString = question.getContents();
}
return questionString;
}
private double getMiddleDurability(PipeLineElement pipeLineElement, String currentPath) throws IOException, SQLException {
List list = detailDurabilityManager.getDetailDurabilityListByElementId(pipeLineElement.getIdElement(), currentPath);
double sum = 0;
for (int i = 0; i < list.size(); i++) {
DetailDurability detailDurability = (DetailDurability) list.get(i);
sum += detailDurability.getDurabilityValue().doubleValue();
}
if (list.size()!=0){
sum = sum / list.size();
} else{
sum=-1;
}
return sum;
}
private String getDurabilityResult(double durability, MaterialClassification materialClassification) {
if (durability <= materialClassification.getPowerTwo() && durability >= materialClassification.getPowerOne() && durability!=-1) {
return "годен";
} else {
return "не годен";
}
}
private String getDefectList(PipeLineElement pipeLineElement,String cp) throws IOException {
String s = "";
List list = pipeLineElementDefectManager.getPipeLineElementDefectByPipeLineElement(pipeLineElement.getIdElement(),cp);
if (list.isEmpty() || list.size() == 0) {
s+="Дефектов не обнаруженно";
} else {
for (int i = 0; i < list.size(); i++) {
PipeLineElementDefect pipeLineElementDefect = (PipeLineElementDefect) list.get(i);
s += pipeLineElementDefect.getDefectType().getDefectTypeName() + "\n";
s += pipeLineElementDefect.getDefectVarity().getVarityName() + "\n\n\n\n";
}
}
return s;
}
}