| Line 75... |
Line 75... |
| 75 |
import org.json.JSONArray;
|
75 |
import org.json.JSONArray;
|
| 76 |
import org.json.JSONObject;
|
76 |
import org.json.JSONObject;
|
| 77 |
import org.springframework.beans.factory.annotation.Autowired;
|
77 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 78 |
import org.springframework.beans.factory.annotation.Value;
|
78 |
import org.springframework.beans.factory.annotation.Value;
|
| 79 |
import org.springframework.cache.annotation.Cacheable;
|
79 |
import org.springframework.cache.annotation.Cacheable;
|
| 80 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 81 |
import org.springframework.http.HttpHeaders;
|
80 |
import org.springframework.http.HttpHeaders;
|
| 82 |
import org.springframework.http.HttpStatus;
|
81 |
import org.springframework.http.HttpStatus;
|
| 83 |
import org.springframework.http.MediaType;
|
82 |
import org.springframework.http.MediaType;
|
| 84 |
import org.springframework.http.ResponseEntity;
|
83 |
import org.springframework.http.ResponseEntity;
|
| 85 |
import org.springframework.stereotype.Controller;
|
84 |
import org.springframework.stereotype.Controller;
|
| Line 87... |
Line 86... |
| 87 |
import org.springframework.ui.Model;
|
86 |
import org.springframework.ui.Model;
|
| 88 |
import org.springframework.web.bind.annotation.*;
|
87 |
import org.springframework.web.bind.annotation.*;
|
| 89 |
|
88 |
|
| 90 |
import javax.servlet.http.HttpServletRequest;
|
89 |
import javax.servlet.http.HttpServletRequest;
|
| 91 |
import javax.servlet.http.HttpServletResponse;
|
90 |
import javax.servlet.http.HttpServletResponse;
|
| 92 |
import java.io.ByteArrayInputStream;
|
- |
|
| 93 |
import java.io.ByteArrayOutputStream;
|
91 |
import java.io.ByteArrayOutputStream;
|
| 94 |
import java.io.IOException;
|
92 |
import java.io.IOException;
|
| 95 |
import java.io.InputStream;
|
- |
|
| 96 |
import java.time.LocalDate;
|
93 |
import java.time.LocalDate;
|
| 97 |
import java.time.LocalDateTime;
|
94 |
import java.time.LocalDateTime;
|
| 98 |
import java.time.LocalTime;
|
95 |
import java.time.LocalTime;
|
| 99 |
import java.time.YearMonth;
|
96 |
import java.time.YearMonth;
|
| 100 |
import java.time.format.DateTimeFormatter;
|
97 |
import java.time.format.DateTimeFormatter;
|
| Line 823... |
Line 820... |
| 823 |
|
820 |
|
| 824 |
}
|
821 |
}
|
| 825 |
return responseSender.ok(customerOrderAndInsuranceDetails);
|
822 |
return responseSender.ok(customerOrderAndInsuranceDetails);
|
| 826 |
}
|
823 |
}
|
| 827 |
|
824 |
|
| 828 |
@RequestMapping(value = "/store/generateInvoice", method = RequestMethod.GET)
|
825 |
@RequestMapping(value = "/store/generateInvoice", method = RequestMethod.GET, produces = MediaType.APPLICATION_PDF_VALUE)
|
| 829 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
826 |
public ResponseEntity<byte[]> generateInvoice(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
| 830 |
InvoicePdfModel pdfModel = null;
|
827 |
InvoicePdfModel pdfModel = null;
|
| 831 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(orderId);
|
828 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(orderId);
|
| 832 |
pdfModel = orderService.getInvoicePdfModel(fo.getFofoId(), orderId);
|
829 |
pdfModel = orderService.getInvoicePdfModel(fo.getFofoId(), orderId);
|
| 833 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
830 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 834 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
831 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 835 |
try {
|
832 |
try {
|
| 836 |
byteArrayOutputStream.close();
|
833 |
byteArrayOutputStream.close();
|
| 837 |
} catch (IOException e) {
|
834 |
} catch (IOException e) {
|
| 838 |
// TODO Auto-generated catch block
|
- |
|
| 839 |
e.printStackTrace();
|
835 |
e.printStackTrace();
|
| 840 |
}
|
836 |
}
|
| - |
|
837 |
byte[] pdfBytes = byteArrayOutputStream.toByteArray();
|
| 841 |
final HttpHeaders headers = new HttpHeaders();
|
838 |
final HttpHeaders headers = new HttpHeaders();
|
| 842 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
839 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 843 |
// headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
- |
|
| 844 |
|
- |
|
| 845 |
headers.setContentType(MediaType.parseMediaType("application/pdf"));
|
- |
|
| 846 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
840 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
| 847 |
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
841 |
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
| 848 |
headers.add("Pragma", "no-cache");
|
842 |
headers.add("Pragma", "no-cache");
|
| 849 |
headers.add("Expires", "0");
|
843 |
headers.add("Expires", "0");
|
| 850 |
|
- |
|
| 851 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
844 |
headers.setContentLength(pdfBytes.length);
|
| 852 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
- |
|
| 853 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
- |
|
| 854 |
return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
|
845 |
return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK);
|
| 855 |
// return responseSender.ok(new
|
- |
|
| 856 |
// ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(),
|
- |
|
| 857 |
// headers,HttpStatus.OK));
|
- |
|
| 858 |
/*
|
- |
|
| 859 |
* ResponseEntity<byte[]> response = new
|
- |
|
| 860 |
* ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers,
|
- |
|
| 861 |
* HttpStatus.OK); return response;{
|
- |
|
| 862 |
*/
|
- |
|
| 863 |
|
846 |
|
| 864 |
}
|
847 |
}
|
| 865 |
|
848 |
|
| 866 |
@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
849 |
@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 867 |
@Cacheable(value = "storesListing", cacheManager = "thirtyMinsTimeOutCacheManager")
|
850 |
@Cacheable(value = "storesListing", cacheManager = "thirtyMinsTimeOutCacheManager")
|