public void uploadPictures(int modelOrderColorId, LocalDate expressDate, File simple, File front, File back, File left, File right, File top, File below) {
ModelOrderColor moc = baseDao.getById(ModelOrderColor.class, modelOrderColorId);
ModelOrder mo = moc.getModelOrder();
File[] files = {simple, front, back, left, right, top, below};
List<Property> props = propertiesDao.getByType(IPropertyDao.ORIENTATION);
String webPath = ProjectProperties.getString(ProjectProperties.ROOT_PICTURES);
String nasPath = ProjectProperties.getString(ProjectProperties.NAS_PUBLIC_PICTURES);
File nasFile = new File(nasPath + mo.getCustomerNo());
if (!nasFile.exists()) {
nasFile.mkdir();
}
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMdd");
String expressDateStr = format.format(expressDate);
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file == null) {
continue;
}
Property prop = props.get(i);
Picture p = pictureDao.getOne(moc.getId(), prop.getId()); if (p == null) {
p = new Picture();
p.setModelOrderColor(moc);
p.setOrientation(prop);
p.setExpressDate(expressDate);
pictureDao.save(p);
} else {
p.setExpressDate(expressDate);
pictureDao.update(p);
}
try {
BufferedImage img = ImageIO.read(file);
BufferedImage thumbnail = Scalr.resize(img, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, 1440, 900);
ImageIO.write(thumbnail, "jpg", new File(webPath + moc.getId() + "_" + prop.getId() + ".jpg"));
StringBuilder sb = new StringBuilder();
sb.append(mo.getModelOrderType().getValue());
sb.append("^");
sb.append(moc.getName().replaceAll("\\\\|\\||/|\"|>|<|\\?|:|\\*", ""));
sb.append("^");
sb.append(expressDateStr);
sb.append("^");
sb.append(prop.getOrderNo());
sb.append(".jpg");
ImageIO.write(thumbnail, "jpg", new File(nasFile, sb.toString()));
thumbnail = Scalr.resize(img, Scalr.Method.QUALITY, Scalr.Mode.FIT_TO_HEIGHT, 300);
ImageIO.write(thumbnail, "jpg", new File(webPath + moc.getId() + "_" + prop.getId() + ".min.jpg"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}