Bläddra i källkod

Export-tb-code-detail

new-feature
Viet.LeQ2 1 år sedan
förälder
incheckning
980ca55776
8 ändrade filer med 305 tillägg och 7 borttagningar
  1. Binär
      build/libs/smart-farm-0.0.1-SNAPSHOT.war
  2. +6
    -0
      src/main/java/vn/azteam/tpf/repository/TBCodeDetailsRepository.java
  3. +84
    -1
      src/main/java/vn/azteam/tpf/service/TBCodeQueryService.java
  4. +26
    -0
      src/main/java/vn/azteam/tpf/service/dto/ExportTBCodeDTO.java
  5. +22
    -0
      src/main/java/vn/azteam/tpf/service/dto/TBExampleStampCreationDTO.java
  6. +118
    -0
      src/main/java/vn/azteam/tpf/service/util/ExcelWriteUtility.java
  7. +33
    -0
      src/main/java/vn/azteam/tpf/web/rest/TBCodeResource.java
  8. +16
    -6
      src/main/java/vn/azteam/tpf/web/rest/TBExampleStampResource.java

Binär
build/libs/smart-farm-0.0.1-SNAPSHOT.war Visa fil


+ 6
- 0
src/main/java/vn/azteam/tpf/repository/TBCodeDetailsRepository.java Visa fil

@@ -2,9 +2,12 @@ package vn.azteam.tpf.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import vn.azteam.tpf.domain.TBCodeDetails;

import java.util.List;
import java.util.Optional;

@Repository
@@ -13,4 +16,7 @@ public interface TBCodeDetailsRepository extends JpaRepository<TBCodeDetails, Lo
// @Query("select tb_code_details from TBCodeDetails tb_code_details where tb_code_details.code =:code")
Optional<TBCodeDetails> findByCode(String code);

@Query(value = "SELECT dt FROM TBCodeDetails dt INNER JOIN TBCode tc ON (dt.tbCodeId = tc.id) \n" +
" WHERE tc.code= :tbCodeValue")
List<TBCodeDetails> findByTBCode(@Param("tbCodeValue") String tbCodeValue);
}

+ 84
- 1
src/main/java/vn/azteam/tpf/service/TBCodeQueryService.java Visa fil

@@ -9,13 +9,21 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vn.azteam.tpf.domain.*;
import vn.azteam.tpf.repository.TBCodeDetailsRepository;
import vn.azteam.tpf.repository.TBCodeRepository;
import vn.azteam.tpf.service.dto.ExportTBCodeDTO;
import vn.azteam.tpf.service.dto.TBCodeCriteria;
import vn.azteam.tpf.service.dto.TBCodeDTO;
import vn.azteam.tpf.service.mapper.TBCodeMapper;
import vn.azteam.tpf.service.util.ExcelWriteUtility;
import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;

import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@Transactional(readOnly = true)
@@ -24,10 +32,12 @@ public class TBCodeQueryService extends QueryService<TBCode> {
private final Logger log = LoggerFactory.getLogger(TBCodeQueryService.class);
private final TBCodeRepository tBCodeRepository;

private final TBCodeDetailsRepository tbCodeDetailsRepository;
private final TBCodeMapper tBCodeMapper;

public TBCodeQueryService(TBCodeRepository tBCodeRepository, TBCodeMapper tBCodeMapper) {
public TBCodeQueryService(TBCodeRepository tBCodeRepository, TBCodeDetailsRepository tbCodeDetailsRepository, TBCodeMapper tBCodeMapper) {
this.tBCodeRepository = tBCodeRepository;
this.tbCodeDetailsRepository = tbCodeDetailsRepository;
this.tBCodeMapper = tBCodeMapper;
}

@@ -124,4 +134,77 @@ public class TBCodeQueryService extends QueryService<TBCode> {
return specification;
}

public byte[] exportInfoTBCode(String tbCodeValue) {
try {
Optional<TBCode> tbCode = tBCodeRepository.findByCode(tbCodeValue);
if (!tbCode.isPresent()) {
throw new BadRequestAlertException("1047", "TB Code export could found", "1047");
}
log.info("exportInfoTBCode: start query");
List<ExportTBCodeDTO> queryResult =
this.getInfoTbCodeDetailByTbCode(tbCodeValue);
log.info("exportInfoTBCode: end query, result {}", queryResult.size());

return this.createExcelFile(queryResult, tbCodeValue);
} catch (Exception exception) {
log.error("exportInfoCampaignCalling exception", exception);
}
return new byte[0];
}

private List<ExportTBCodeDTO> getInfoTbCodeDetailByTbCode(String tbCodeValue) {
List<TBCodeDetails> tbCodeDetails = tbCodeDetailsRepository.findByTBCode(tbCodeValue);
List<ExportTBCodeDTO> callingCampaignExportDTOList = new ArrayList<>();
if (!tbCodeDetails.isEmpty()) {
tbCodeDetails.forEach(c -> {
ExportTBCodeDTO exportTBCodeDTO = new ExportTBCodeDTO();
exportTBCodeDTO.setDetailCode(c.getCode());
exportTBCodeDTO.setStatus(c.getStatus().getName());

callingCampaignExportDTOList.add(exportTBCodeDTO);
});
}
return callingCampaignExportDTOList;
}

public byte[] createExcelFile(List<ExportTBCodeDTO> contents, String tbCodeValue) throws IOException {
log.info("createExcelFile");
List<List<Object>> data = new ArrayList<>();
data.add(createReportHeader());
contents.forEach(
cicBadDebtExportDTO -> {
List<Object> rowData = convertRecordToArray(cicBadDebtExportDTO, tbCodeValue);
data.add(rowData);
}
);
return ExcelWriteUtility.writeExcelToByteArray(data, null);
}

public List<Object> createReportHeader() {
log.info("createReportHeader");
List<Object> header = new ArrayList<>();
header.add("Code");
header.add("Status");
// header.add("User");
// header.add("Completed");
// header.add("Completed (Another reason)");
// header.add("Partial completed");
// header.add("Follow");
// header.add("No Answer");
// header.add("Drop Call");
return header;
}

public List<Object> convertRecordToArray(ExportTBCodeDTO content, String campaignName) {
return getObjects(content, campaignName);
}

public List<Object> getObjects(ExportTBCodeDTO content, String campaignName) {
//log.info("convertRecordToArray");
List<Object> row = new ArrayList<>();
//row.add(campaignName);
row.add(content.getDetailCode());
row.add(content.getStatus());
return row;
}
}

+ 26
- 0
src/main/java/vn/azteam/tpf/service/dto/ExportTBCodeDTO.java Visa fil

@@ -0,0 +1,26 @@
package vn.azteam.tpf.service.dto;

import java.io.Serializable;

public class ExportTBCodeDTO implements Serializable {

private String detailCode;

private String status;

public String getDetailCode() {
return detailCode;
}

public void setDetailCode(String detailCode) {
this.detailCode = detailCode;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}
}

+ 22
- 0
src/main/java/vn/azteam/tpf/service/dto/TBExampleStampCreationDTO.java Visa fil

@@ -0,0 +1,22 @@
package vn.azteam.tpf.service.dto;

import java.io.Serializable;

public class TBExampleStampCreationDTO implements Serializable {

private String exampleStampName;

private String description;

private Integer width;

private Integer height;

private Integer x;

private Integer y;

private Integer size;

private String exampleStampImage;
}

+ 118
- 0
src/main/java/vn/azteam/tpf/service/util/ExcelWriteUtility.java Visa fil

@@ -0,0 +1,118 @@
package vn.azteam.tpf.service.util;

import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.function.Function;

public class ExcelWriteUtility {
private static final Logger logger = LoggerFactory.getLogger(ExcelWriteUtility.class);
private static final DataFormatter dataFormatter = new DataFormatter();

public ExcelWriteUtility() {
}

public static byte[] writeExcelToByteArray(List<List<Object>> inputData, Function<Object, String> dataFormatter) throws IOException {
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
writeExcel(inputData, byteOutputStream, dataFormatter);
return byteOutputStream.toByteArray();
}

public static void writeExcelToFile(List<List<Object>> inputData, File outFile, Function<Object, String> dataFormatter) throws IOException {
OutputStream outputStream = null;

try {
outputStream = new FileOutputStream(outFile);
writeExcel(inputData, outputStream, dataFormatter);
} finally {
if (outputStream != null) {
outputStream.close();
}

}

}

public static void writeExcel(List<List<Object>> inputData, OutputStream outputStream, Function<Object, String> dataFormatter) throws IOException {
new ArrayList();
Workbook workbook = null;

try {
workbook = WorkbookFactory.create(true);
Sheet sheet = getOrCreateSheet(workbook);

for (int rowNum = 0; rowNum < inputData.size(); ++rowNum) {
List<Object> rowData = (List) inputData.get(rowNum);
writeRowData(sheet, rowNum, rowData, dataFormatter);
}

workbook.write(outputStream);
} finally {
if (workbook != null) {
workbook.close();
}

}
}

private static void writeRowData(Sheet sheet, int rowNum, List<Object> rowData, Function<Object, String> dataFormatter) {
Row row = getOrCreateRow(sheet, rowNum);

for (int col = 0; col < rowData.size(); ++col) {
Cell cell = getOrCreateCell(row, col);
if (dataFormatter != null) {
setCellValue(cell, dataFormatter.apply(rowData.get(col)));
} else {
setCellValue(cell, rowData.get(col));
}
}

}

private static Sheet getOrCreateSheet(Workbook workbook) {
int numOfSheet = workbook.getNumberOfSheets();
return numOfSheet <= 0 ? workbook.createSheet() : workbook.getSheetAt(0);
}

private static Row getOrCreateRow(Sheet sheet, int rowNum) {
Row r = sheet.getRow(rowNum);
if (r == null) {
r = sheet.createRow(rowNum);
}

return r;
}

private static Cell getOrCreateCell(Row row, int colNum) {
Cell c = row.getCell(colNum);
if (c == null) {
c = row.createCell(colNum);
}

return c;
}

private static void setCellValue(Cell cell, Object value) {
if (value instanceof String) {
cell.setCellValue((String) value);
} else if (value instanceof RichTextString) {
cell.setCellValue((RichTextString) value);
} else if (value instanceof Number) {
cell.setCellValue(((Number) value).doubleValue());
} else if (value instanceof Date) {
cell.setCellValue((Date) value);
} else if (value instanceof Calendar) {
cell.setCellValue((Calendar) value);
} else {
cell.setCellValue(Objects.toString(value, ""));
}

}
}

+ 33
- 0
src/main/java/vn/azteam/tpf/web/rest/TBCodeResource.java Visa fil

@@ -5,9 +5,11 @@ import io.github.jhipster.web.util.ResponseUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import vn.azteam.tpf.domain.TBCode;
@@ -21,8 +23,10 @@ import vn.azteam.tpf.web.rest.util.HeaderUtil;
import vn.azteam.tpf.web.rest.util.PaginationUtil;
import vn.azteam.tpf.web.rest.util.RandomStringUtil;

import java.io.ByteArrayInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.time.Instant;
import java.util.Comparator;
import java.util.List;
@@ -199,6 +203,35 @@ public class TBCodeResource {
}
}

// @PostMapping("/uploadJsonAndMultipartData")
// public ResponseEntity<String> handleJsonAndMultipartInput(@RequestPart("data") JsonRequest json, @RequestPart("file") MultipartFile file) {
// return ResponseEntity.ok()
// .body(json.getId() + json.getName());
// }

@GetMapping(value = "/tb-codes/export")
public ResponseEntity<InputStreamResource> exportTbCode(
@RequestParam(value="tbCodeValue") String tbCodeValue) {
try {

if (StringUtils.isBlank(tbCodeValue)) {
throw new BadRequestAlertException("1047", "TB Code export could not empty", "1047");
}

byte[] out = tBCodeQueryService.exportInfoTBCode(tbCodeValue);

String fileName = "Export_detail_code_by_tb_code" + tbCodeValue + ".xlsx";
InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(out));
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename= " + fileName)
.contentLength(out.length)
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.body(resource);
} catch (Exception e) {
throw e;
}
}

@GetMapping("/tb-codes/{id}")
@Timed
public ResponseEntity<TBCodeDTO> getTBCodes(@PathVariable Long id) {

+ 16
- 6
src/main/java/vn/azteam/tpf/web/rest/TBExampleStampResource.java Visa fil

@@ -2,24 +2,31 @@ package vn.azteam.tpf.web.rest;


import com.codahale.metrics.annotation.Timed;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import vn.azteam.tpf.domain.TBCodeStatusEnum;
import vn.azteam.tpf.service.TBExampleStampQueryService;
import vn.azteam.tpf.service.dto.TBExampleStampCriteria;
import vn.azteam.tpf.service.dto.TBExampleStampDTO;
import vn.azteam.tpf.service.UserService;
import vn.azteam.tpf.service.dto.*;
import vn.azteam.tpf.service.util.PageableUtil;
import vn.azteam.tpf.service.util.UserRoleUtil;
import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
import vn.azteam.tpf.web.rest.util.HeaderUtil;
import vn.azteam.tpf.web.rest.util.PaginationUtil;
import vn.azteam.tpf.web.rest.util.RandomStringUtil;

import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RestController
@@ -34,12 +41,15 @@ public class TBExampleStampResource {

private final UserRoleUtil userRoleUtil;

private final UserService userService;

private final PageableUtil pageableUtil;

public TBExampleStampResource(TBExampleStampQueryService tBExampleStampQueryService, UserRoleUtil userRoleUtil, PageableUtil pageableUtil){
public TBExampleStampResource(TBExampleStampQueryService tBExampleStampQueryService, UserRoleUtil userRoleUtil, UserService userService, PageableUtil pageableUtil){

this.tBExampleStampQueryService = tBExampleStampQueryService;
this.userRoleUtil = userRoleUtil;
this.userService = userService;
this.pageableUtil = pageableUtil;
}


Laddar…
Avbryt
Spara