Commit 63ddc8fc authored by Nguyen Ha's avatar Nguyen Ha

fix sonar

parent adbc0add
......@@ -24,6 +24,9 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -33,6 +36,8 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
private static final Logger logger = LoggerFactory.getLogger(CampaignExecuteServiceImp.class);
private SimpleDateFormat formatter = new SimpleDateFormat(Constants.DATE_FORMAT.FOMART_DATE_TYPE_1);
private Random rand = SecureRandom.getInstanceStrong();
@Autowired
ModelMapper modelMapper;
......@@ -66,6 +71,9 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Autowired
CampaignCustomerListColumnRepository campaignCustomerListColumnRepository;
public CampaignExecuteServiceImp() throws NoSuchAlgorithmException {
}
//<editor-fold: hungtt>
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
......@@ -119,104 +127,111 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public XSSFWorkbook exportInteractiveResult(CampaignRequestDTO dto) {
public XSSFWorkbook exportInteractiveResult(CampaignRequestDTO dto) throws IOException {
Locale locale = Locale.forLanguageTag("vi");
List<ContactCustResultDTO> list = campaignExecuteRepository.getExcelInteractiveResult(dto);
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFWorkbook workbook = null;
Sheet sheet;
try {
// create font style
workbook = new XSSFWorkbook();
Font defaultFont = workbook.createFont();
defaultFont.setFontHeightInPoints((short) 13);
defaultFont.setFontName("Times New Roman");
defaultFont.setColor(IndexedColors.BLACK.getIndex());
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 18);
titleFont.setFontName("Times New Roman");
titleFont.setColor(IndexedColors.BLACK.getIndex());
titleFont.setBold(true);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 13);
headerFont.setFontName("Times New Roman");
headerFont.setColor(IndexedColors.BLACK.getIndex());
headerFont.setBold(true);
CellStyle styleTitle = workbook.createCellStyle();
styleTitle.setFont(titleFont);
styleTitle.setAlignment(HorizontalAlignment.CENTER);
CellStyle styleRowHeader = workbook.createCellStyle();
styleRowHeader.setFont(headerFont);
styleRowHeader.setAlignment(HorizontalAlignment.CENTER);
styleRowHeader.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
styleRowHeader.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styleRowHeader.setBorderRight(BorderStyle.THIN);
styleRowHeader.setRightBorderColor(IndexedColors.BLACK.getIndex());
styleRowHeader.setBorderBottom(BorderStyle.THIN);
styleRowHeader.setBottomBorderColor(IndexedColors.BLACK.getIndex());
styleRowHeader.setBorderLeft(BorderStyle.THIN);
styleRowHeader.setLeftBorderColor(IndexedColors.BLACK.getIndex());
styleRowHeader.setBorderTop(BorderStyle.THIN);
styleRowHeader.setTopBorderColor(IndexedColors.BLACK.getIndex());
CellStyle styleRow = workbook.createCellStyle();
styleRow.setFont(defaultFont);
// list header
List<String> headerList = new ArrayList<>();
headerList.add(BundleUtils.getLangString("stt", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.campaignCode", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.campaignName", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.agentId", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.phoneNumber", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.customerId", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.customerName", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.createTime", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.contactStatus", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.surveyStatus", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.status", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.recordStatus", locale));
//
String sheetName = BundleUtils.getLangString("detail", locale);
sheet = workbook.createSheet(sheetName);
// Title
String title = BundleUtils.getLangString("campaign.execute.interactive.title", locale);
int rowTitleStart = 3;
Row rowTitle = sheet.createRow(rowTitleStart);
rowTitle.setHeight((short) 800);
writeCellContent(rowTitle, styleTitle, 3, title);
sheet.addMergedRegion(new CellRangeAddress(rowTitleStart, rowTitleStart, 3, 8));
// Header
int startRowTable = 5;
int count = 1;
Row rowHeader = sheet.createRow(startRowTable);
for (int i = 0; i < headerList.size(); i++) {
writeCellContent(rowHeader, styleRowHeader, i, headerList.get(i));
}
// Content
for (int i = 0, rowIndex = 1; i < list.size(); i++) {
Row row = sheet.createRow(startRowTable + count);
int col = 0;
writeCellContent(row, styleRow, col++, rowIndex);
writeCellContent(row, styleRow, col++, list.get(i).getCampaignCode());
writeCellContent(row, styleRow, col++, list.get(i).getCampaignName());
writeCellContent(row, styleRow, col++, list.get(i).getUserName());
writeCellContent(row, styleRow, col++, list.get(i).getPhoneNumber());
writeCellContent(row, styleRow, col++, list.get(i).getCustomerName());
writeCellContent(row, styleRow, col++, list.get(i).getCustomerName());
writeCellContent(row, styleRow, col++, formatter.format(list.get(i).getCreateTime()));
writeCellContent(row, styleRow, col++, list.get(i).getContactStatus());
writeCellContent(row, styleRow, col++, list.get(i).getSurveyStatus());
writeCellContent(row, styleRow, col++, list.get(i).getStatus());
writeCellContent(row, styleRow, col++, list.get(i).getRecordStatus());
++rowIndex;
++count;
}
}catch (Exception e){
// create font style
Font defaultFont = workbook.createFont();
defaultFont.setFontHeightInPoints((short) 13);
defaultFont.setFontName("Times New Roman");
defaultFont.setColor(IndexedColors.BLACK.getIndex());
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 18);
titleFont.setFontName("Times New Roman");
titleFont.setColor(IndexedColors.BLACK.getIndex());
titleFont.setBold(true);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 13);
headerFont.setFontName("Times New Roman");
headerFont.setColor(IndexedColors.BLACK.getIndex());
headerFont.setBold(true);
CellStyle styleTitle = workbook.createCellStyle();
styleTitle.setFont(titleFont);
styleTitle.setAlignment(HorizontalAlignment.CENTER);
CellStyle styleRowHeader = workbook.createCellStyle();
styleRowHeader.setFont(headerFont);
styleRowHeader.setAlignment(HorizontalAlignment.CENTER);
styleRowHeader.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
styleRowHeader.setFillPattern(FillPatternType.SOLID_FOREGROUND);
styleRowHeader.setBorderRight(BorderStyle.THIN);
styleRowHeader.setRightBorderColor(IndexedColors.BLACK.getIndex());
styleRowHeader.setBorderBottom(BorderStyle.THIN);
styleRowHeader.setBottomBorderColor(IndexedColors.BLACK.getIndex());
styleRowHeader.setBorderLeft(BorderStyle.THIN);
styleRowHeader.setLeftBorderColor(IndexedColors.BLACK.getIndex());
styleRowHeader.setBorderTop(BorderStyle.THIN);
styleRowHeader.setTopBorderColor(IndexedColors.BLACK.getIndex());
CellStyle styleRow = workbook.createCellStyle();
styleRow.setFont(defaultFont);
// list header
List<String> headerList = new ArrayList<>();
headerList.add(BundleUtils.getLangString("stt", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.campaignCode", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.campaignName", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.agentId", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.phoneNumber", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.customerId", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.customerName", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.createTime", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.contactStatus", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.surveyStatus", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.status", locale));
headerList.add(BundleUtils.getLangString("campaign.execute.interactive.recordStatus", locale));
//
String sheetName = BundleUtils.getLangString("detail", locale);
sheet = workbook.createSheet(sheetName);
// Title
String title = BundleUtils.getLangString("campaign.execute.interactive.title", locale);
int rowTitleStart = 3;
Row rowTitle = sheet.createRow(rowTitleStart);
rowTitle.setHeight((short) 800);
writeCellContent(rowTitle, styleTitle, 3, title);
sheet.addMergedRegion(new CellRangeAddress(rowTitleStart, rowTitleStart, 3, 8));
// Header
int startRowTable = 5;
int count = 1;
Row rowHeader = sheet.createRow(startRowTable);
for (int i = 0; i < headerList.size(); i++) {
writeCellContent(rowHeader, styleRowHeader, i, headerList.get(i));
}
// Content
for (int i = 0, rowIndex = 1; i < list.size(); i++) {
Row row = sheet.createRow(startRowTable + count);
int col = 0;
writeCellContent(row, styleRow, col++, rowIndex);
writeCellContent(row, styleRow, col++, list.get(i).getCampaignCode());
writeCellContent(row, styleRow, col++, list.get(i).getCampaignName());
writeCellContent(row, styleRow, col++, list.get(i).getUserName());
writeCellContent(row, styleRow, col++, list.get(i).getPhoneNumber());
writeCellContent(row, styleRow, col++, list.get(i).getCustomerName());
writeCellContent(row, styleRow, col++, list.get(i).getCustomerName());
writeCellContent(row, styleRow, col++, formatter.format(list.get(i).getCreateTime()));
writeCellContent(row, styleRow, col++, list.get(i).getContactStatus());
writeCellContent(row, styleRow, col++, list.get(i).getSurveyStatus());
writeCellContent(row, styleRow, col++, list.get(i).getStatus());
writeCellContent(row, styleRow, col++, list.get(i).getRecordStatus());
++rowIndex;
++count;
}finally {
if (workbook != null) workbook.close();
}
return workbook;
}
......@@ -493,13 +508,13 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Override
public ResultDTO getCallStatus(CampaignRequestDTO dto) {
ResultDTO result = new ResultDTO();
Random r = new Random();
// Random r = new Random();
String[] arr = {"ACCEPT", "REJECT", "MISSING"};
if (dto != null) {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setData(arr[r.nextInt(arr.length)]);
result.setData(arr[this.rand.nextInt(arr.length)]);
} else {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment