Commit 3ec149b9 authored by đinh thị đầm's avatar đinh thị đầm
parents 065c5c6a a3114bcf
...@@ -19,7 +19,9 @@ import org.hibernate.transform.Transformers; ...@@ -19,7 +19,9 @@ import org.hibernate.transform.Transformers;
import org.hibernate.type.*; import org.hibernate.type.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.*; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -27,9 +29,10 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -27,9 +29,10 @@ import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query; import java.util.ArrayList;
import java.math.BigDecimal; import java.util.HashMap;
import java.util.*; import java.util.List;
import java.util.Map;
@Repository @Repository
public class CampaignRepositoryImpl implements CampaignRepositoryCustom { public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
...@@ -638,7 +641,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -638,7 +641,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
"),\n" + "),\n" +
"data as (\n" + "data as (\n" +
"select a.*, rownum row_ from data_temp a\n" + "select a.*, rownum row_ from data_temp a\n" +
"where a.totalCusList > 0" + "where a.totalCusCampaign > 0" +
"),\n" + "),\n" +
"count_data as (\n" + "count_data as (\n" +
"select count(*) totalRow from data_temp\n" + "select count(*) totalRow from data_temp\n" +
......
...@@ -393,17 +393,15 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -393,17 +393,15 @@ public class ScenarioServiceImpl implements ScenarioService {
//insert data //insert data
if (isValid) { if (isValid) {
logger.info("----- Data valid, start import scenario question -----");
List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId); List<ScenarioQuestionDTO> lstQuestion = buildQuestionsLst(rawDataList, scenarioId, campaignId, companySiteId);
lstQuestion.forEach(question -> { lstQuestion.forEach(question -> {
// questionService.add(question); questionService.add(question);
}); });
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos); workbook.write(fos);
result.put("file", file); result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importSuccess", locale)); result.put("message", BundleUtils.getLangString("customer.importSuccess", locale));
} else { } else {
logger.info("----- Data invalid, can't import scenario question -----");
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos); workbook.write(fos);
result.put("file", file); result.put("file", file);
......
...@@ -121,20 +121,18 @@ public class ScenarioController { ...@@ -121,20 +121,18 @@ public class ScenarioController {
Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId()); Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId());
File fileExport = (File) map.get("file"); File fileExport = (File) map.get("file");
String message = (String) map.get("message"); String message = (String) map.get("message");
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO= new ResultDTO();
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode("00");
resultDTO.setDescription(message); resultDTO.setDescription(message);
return new ResponseEntity<>(resultDTO, HttpStatus.OK); resultDTO.setData(fileExport);
// return ResponseEntity.ok() HttpHeaders headers = new HttpHeaders();
// .header("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX) headers.add("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX);
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=import_scenario_result.xlsx") headers.add("Message", message);
// .header("Message", message) return ResponseEntity.ok()
// .body(Files.readAllBytes(fileExport.toPath())); .headers(headers)
.body(Files.readAllBytes(fileExport.toPath()));
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage()); logger.error(e.getMessage());
ResultDTO resultDTO = new ResultDTO();
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
} }
......
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