package art.servers.gost.access.reports;
|
|
import art.library.model.devices.gost.access.types.AccessEnforcement_Detection;
|
import art.library.model.devices.gost.access.types.AccessEnforcement_Detection_Image;
|
import art.library.model.devices.gost.access.types.AccessEnforcement_Detection_State;
|
import art.library.utils.resources.Resources;
|
import art.servers.ServerException;
|
import art.servers.Shared;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.text.SimpleDateFormat;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.Optional;
|
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
public class ReportAccessZPR extends ReportAccess
|
{
|
public ReportAccessZPR(String language, String format, AccessEnforcement_Detection detection) throws Exception
|
{
|
super(language, format, detection);
|
}
|
|
@Override
|
public void loadTemplate(String language1) throws ServerException, IOException
|
{
|
String filename = "data/" + Shared.getApplicationName() + "/templates/" + language1 + "/art.library.model.devices.gost.access.AccessEnforcement-ZPR.xlsx";
|
File file = new File(filename);
|
if (file.exists() == false) file = Resources.getResourceFile(filename);
|
if (file.exists() == false)
|
{
|
throw new ServerException(Shared.getMessage(language1, "Template not found"));
|
}
|
workbook = new XSSFWorkbook(new FileInputStream(new File(filename)));
|
}
|
|
@Override
|
protected void fill() throws Exception
|
{
|
AccessEnforcement_Detection_State detectionState = detection.getLastState();
|
SimpleDateFormat formato1 = new SimpleDateFormat("dd/MM/yyyy");
|
SimpleDateFormat formato2 = new SimpleDateFormat(Shared.getMessage(language, "HH:mm:ss"));
|
XSSFSheet xssfsheet = workbook.getSheetAt(0);
|
|
// Records
|
|
try
|
{
|
if (detection.zpr != null)
|
{
|
if(detection.zpr.entryLocation != null)
|
getXSSFCell(xssfsheet, "B7").setCellValue(nonull(detection.zpr.entryLocation));
|
if(detection.zpr.entryTimestamp != null )
|
getXSSFCell(xssfsheet, "B8").setCellValue(formato1.format(detection.zpr.entryTimestamp) + " " + formato2.format(detection.zpr.entryTimestamp));
|
|
if(detection.zpr.exitLocation != null)
|
getXSSFCell(xssfsheet, "B9").setCellValue(nonull(detection.zpr.exitLocation));
|
if(detection.zpr.exitTimestamp != null)
|
getXSSFCell(xssfsheet, "B10").setCellValue(formato1.format(detection.zpr.exitTimestamp) + " " + formato2.format(detection.zpr.exitTimestamp));
|
}
|
if(detectionState.violation != null)
|
{
|
try
|
{
|
float amount = Float.parseFloat(detectionState.violation.amount);
|
float bonus = Float.parseFloat(detectionState.violation.bonus);
|
int points = Integer.parseInt(detectionState.violation.points);
|
|
getXSSFCell(xssfsheet, "E13").setCellValue(nonull(String.format("%.2f", amount)));
|
getXSSFCell(xssfsheet, "I13").setCellValue(nonull(String.format("%.2f", bonus)));
|
getXSSFCell(xssfsheet, "N13").setCellValue(nonull(String.valueOf(points)));
|
}
|
catch (Exception ex){}
|
|
getXSSFCell(xssfsheet, "M2").setCellValue(nonull(detectionState.violation.record));
|
getXSSFCell(xssfsheet, "A14").setCellValue(nonull(detectionState.violation.description));
|
getXSSFCell(xssfsheet, "A13").setCellValue(nonull(detectionState.violation.LSV));
|
getXSSFCell(xssfsheet, "C13").setCellValue(nonull(detectionState.violation.RGC));
|
getXSSFCell(xssfsheet, "D13").setCellValue(nonull(detectionState.violation.type));
|
getXSSFCell(xssfsheet, "O13").setCellValue(nonull(detectionState.violation.key));
|
}
|
}
|
catch (Exception exception)
|
{
|
exception.printStackTrace();
|
}
|
|
// Location
|
|
try
|
{
|
getXSSFCell(xssfsheet, "A5").setCellValue(formato1.format(detection.timestamp));
|
getXSSFCell(xssfsheet, "F5").setCellValue(formato2.format(detection.timestamp));
|
getXSSFCell(xssfsheet, "B18").setCellValue(nonull(detectionState.vehicle.getPlate()));
|
}
|
catch (Exception exception)
|
{
|
}
|
|
// Signature
|
|
// Pictures
|
|
try
|
{
|
List<AccessEnforcement_Detection_Image> images = detection.images;
|
|
Optional<byte[]> image1 = getImage(AccessEnforcement_Detection_Image.NAME_PLATE);
|
Optional<byte[]> image2 = getImage(AccessEnforcement_Detection_Image.NAME_OVERVIEW);
|
|
if (image1.isPresent())
|
{
|
int pictureIndex = workbook.addPicture(image1.get(), Workbook.PICTURE_TYPE_PNG);
|
|
XSSFDrawing drawing = (XSSFDrawing) xssfsheet.createDrawingPatriarch();
|
|
XSSFClientAnchor anchor = new XSSFClientAnchor();
|
anchor.setCol1(17);
|
anchor.setRow1(6);
|
anchor.setCol2(38);
|
anchor.setRow2(14);
|
|
drawing.createPicture(anchor, pictureIndex);
|
}
|
|
if (image2.isPresent())
|
{
|
int pictureIndex = workbook.addPicture(image2.get(), Workbook.PICTURE_TYPE_PNG);
|
|
XSSFDrawing drawing = (XSSFDrawing) xssfsheet.createDrawingPatriarch();
|
|
XSSFClientAnchor anchor = new XSSFClientAnchor();
|
anchor.setCol1(17);
|
anchor.setRow1(16);
|
anchor.setCol2(38);
|
anchor.setRow2(24);
|
|
drawing.createPicture(anchor, pictureIndex);
|
}
|
|
}
|
catch (Exception exception)
|
{
|
}
|
}
|
|
|
|
|
private Optional<byte[]> getImage(String imageName)
|
{
|
return detection.images.stream()
|
.filter(Objects::nonNull)
|
.filter(image -> image.name != null)
|
.filter(image -> image.name.equals(imageName))
|
.map(image -> image.data)
|
.findAny();
|
}
|
}
|