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 ReportAccessVPV extends ReportAccess
|
{
|
public ReportAccessVPV(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-VPV.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.vpv != null)
|
{
|
// getXSSFCell(xssfsheet, "M2").setCellValue(nonull(detection.vpv.record)); //TODO RECORD WHERE?
|
getXSSFCell(xssfsheet, "A12").setCellValue(nonull(detection.vpv.description));
|
getXSSFCell(xssfsheet, "A11").setCellValue(nonull(detection.vpv.LSV));
|
getXSSFCell(xssfsheet, "C11").setCellValue(nonull(detection.vpv.RGC));
|
getXSSFCell(xssfsheet, "D11").setCellValue(nonull(detection.vpv.type));
|
getXSSFCell(xssfsheet, "E11").setCellValue(nonull(detection.vpv.amount));
|
getXSSFCell(xssfsheet, "I11").setCellValue(nonull(detection.vpv.bonus));
|
getXSSFCell(xssfsheet, "N11").setCellValue(nonull(detection.vpv.points));
|
getXSSFCell(xssfsheet, "O11").setCellValue(nonull(detection.vpv.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, "B7").setCellValue(nonull(detection.device.location));
|
getXSSFCell(xssfsheet, "B8").setCellValue(nonull(detection.device.direction));
|
getXSSFCell(xssfsheet, "B16").setCellValue(nonull(detectionState.vehicle.getPlate()));
|
}
|
catch (Exception exception)
|
{
|
}
|
|
// Signature
|
|
try
|
{
|
|
String policeLicense = getPoliceLicense();
|
|
getXSSFCell(xssfsheet, "D22").setCellValue(nonull(policeLicense));
|
|
//TODO SIGNATURE?
|
//
|
// byte[] data = Files.readAllBytes(new File("data/" + Shared.getApplicationName() + "/templates/" + language + "/" + getPoliceLicense() + ".png").toPath());
|
// XSSFDrawing drawing = xssfsheet.createDrawingPatriarch();
|
// XSSFClientAnchor anchor = new XSSFClientAnchor(Units.EMU_PER_PIXEL,Units.EMU_PER_PIXEL, -Units.EMU_PER_PIXEL, -Units.EMU_PER_PIXEL, 1, 33, 5, 35);
|
// anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE); //0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
|
// drawing.createPicture(anchor, workbook.addPicture(data, Workbook.PICTURE_TYPE_JPEG));
|
}
|
catch (Exception exception)
|
{
|
}
|
|
// Pictures
|
|
try
|
{
|
List<AccessEnforcement_Detection_Image> images = detection.images;
|
|
Optional<byte[]> image1 = getImage(AccessEnforcement_Detection_Image.NAME_PLATE); //TODO GET IMAGE NAMES
|
Optional<byte[]> image2 = getImage(AccessEnforcement_Detection_Image.NAME_PLATE); //TODO GET IMAGE NAMES
|
|
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(1);
|
anchor.setCol2(39);
|
anchor.setRow2(11);
|
|
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(12);
|
anchor.setCol2(39);
|
anchor.setRow2(22);
|
|
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();
|
}
|
}
|