Commit 405c8e2d authored by đinh thị đầm's avatar đinh thị đầm
parents 0643f641 06df4534
......@@ -26,18 +26,19 @@ public class CorsFilter implements Filter {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "Origin, Authorization, X-Requested-With, Content-Type, Accept, token1, X-Auth-Token");
response.setHeader("Access-Control-Allow-Headers", "Origin, Authorization, X-Requested-With, Content-Type, Accept, token1, X-Auth-Token, Message");
response.setHeader("Access-Control-Expose-Headers", "Message");
HttpServletRequest request = (HttpServletRequest) req;
chain.doFilter(req, response);
// chain.doFilter(req, response);
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
chain.doFilter(req, resp);
chain.doFilter(request, resp);
return;
}
if ("/".equals(request.getRequestURI())) {
chain.doFilter(req, resp);
chain.doFilter(request, resp);
return;
}
String xAuthToken = request.getHeader("X-Auth-Token");
......@@ -47,7 +48,7 @@ public class CorsFilter implements Filter {
}
Object obj = RedisUtil.getInstance().get(xAuthToken);
if (obj instanceof UserSession) {
chain.doFilter(req, resp);
chain.doFilter(request, resp);
} else {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is invalid.");
}
......
......@@ -19,5 +19,7 @@ public interface AgentsService {
ResultDTO searchCampaignAgentByName(int page, int pageSize, Long companySiteId, String userName, String fullName);
ResultDTO searchCampaignAgentSelectByName(int page, int pageSize, Long companySiteId, Long campaignId, String userName, String fullName);
ResultDTO createMultipleCampaignAgent(CampaignAgentRequestDTO campaignAgentRequestDTO);
}
......@@ -88,13 +88,18 @@ public class AgentsServiceImpl implements AgentsService {
sb.append(" a.FULL_NAME fullName,");
sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" b.FILTER_TYPE filterType,");
sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId");
sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId,");
sb.append(" d.ROLE_CODE roleCode");
sb.append(" FROM VSA_USERS a");
sb.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID");
sb.append(" INNER JOIN USER_ROLE c on a.USER_ID = c.USER_ID");
sb.append(" INNER JOIN ROLE d on c.ROLE_ID = d.ROLE_ID");
sb.append(" WHERE 1 = 1");
sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND a.STATUS = 1");
sb.append(" AND b.AGENT_ID IS NULL");
sb.append(" ORDER BY a.FULL_NAME ASC");
sb.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')");
sb.append(" ORDER BY UPPER(a.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString());
......@@ -107,6 +112,7 @@ public class AgentsServiceImpl implements AgentsService {
query.addScalar("companySiteId", new LongType());
query.addScalar("filterType", new ShortType());
query.addScalar("campaignAgentId", new LongType());
query.addScalar("roleCode", new StringType());
query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class));
int count = 0;
......@@ -157,20 +163,21 @@ public class AgentsServiceImpl implements AgentsService {
sb.append("SELECT");
sb.append(" a.USER_ID userId,");
sb.append(" a.USER_NAME userName,");
sb.append(" a.STATUS status,");
sb.append(" a.FULL_NAME fullName,");
sb.append(" a.CAMPAIGN_AGENT_ID campaignAgentId,");
sb.append(" a.FILTER_TYPE filterType,");
sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" b.FILTER_TYPE filterType,");
sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId");
sb.append(" FROM VSA_USERS a");
sb.append(" b.USER_ID userId,");
sb.append(" b.USER_NAME userName,");
sb.append(" b.STATUS status,");
sb.append(" b.FULL_NAME fullName");
sb.append(" FROM CAMPAIGN_AGENT a");
sb.append(" RIGHT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID");
sb.append(" INNER JOIN VSA_USERS b ON a.AGENT_ID = b.USER_ID");
sb.append(" WHERE 1 = 1");
sb.append(" AND b.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND b.CAMPAIGN_ID = :p_campaign_id");
sb.append(" ORDER BY a.FULL_NAME ASC");
sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND a.CAMPAIGN_ID = :p_campaign_id");
sb.append(" ORDER BY UPPER(b.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString());
......@@ -295,8 +302,8 @@ public class AgentsServiceImpl implements AgentsService {
sqlStrBuilder.append(" b.CAMPAIGN_AGENT_ID campaignAgentId");
sqlStrBuilder.append(" FROM VSA_USERS a");
sqlStrBuilder.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID");
sqlStrBuilder.append(" JOIN USER_ROLE c on a.USER_ID = c.USER_ID");
sqlStrBuilder.append(" JOIN ROLE d on c.ROLE_ID = d.ROLE_ID");
sqlStrBuilder.append(" INNER JOIN USER_ROLE c on a.USER_ID = c.USER_ID");
sqlStrBuilder.append(" INNER JOIN ROLE d on c.ROLE_ID = d.ROLE_ID");
sqlStrBuilder.append(" WHERE 1 = 1");
sqlStrBuilder.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
......@@ -310,8 +317,8 @@ public class AgentsServiceImpl implements AgentsService {
sqlStrBuilder.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')");
sqlStrBuilder.append(" AND a.STATUS = 1");
sqlStrBuilder.append(" AND b.CAMPAIGN_AGENT_ID IS NULL");
sqlStrBuilder.append(" ORDER BY a.FULL_NAME ASC");
sqlStrBuilder.append(" AND b.AGENT_ID IS NULL");
sqlStrBuilder.append(" ORDER BY UPPER(a.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
......@@ -319,7 +326,112 @@ public class AgentsServiceImpl implements AgentsService {
if (!DataUtil.isNullOrEmpty(userName)) {
query.setParameter("p_user_name", "%" +
userName
userName.trim()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
if (!DataUtil.isNullOrEmpty(fullName)) {
query.setParameter("p_full_name", "%" +
fullName.trim()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
query.addScalar("userId", new LongType());
query.addScalar("userName", new StringType());
query.addScalar("status", new ShortType());
query.addScalar("fullName", new StringType());
query.addScalar("companySiteId", new LongType());
query.addScalar("filterType", new ShortType());
query.addScalar("campaignAgentId", new LongType());
query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class));
int count = 0;
List<VSAUsersDTO> dtoList = query.list();
if (dtoList.size() > 0) {
count = query.list().size();
}
Pageable pageable = PageRequest.of(page, pageSize);
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<VSAUsersDTO> data = query.list();
Page<VSAUsersDTO> dataPage = new PageImpl<>(data, pageable, count);
resultDTO.setData(dataPage);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally {
session.close();
}
return resultDTO;
}
@Override
public ResultDTO searchCampaignAgentSelectByName(int page, int pageSize, Long companySiteId, Long campaignId, String userName, String fullName) {
ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
if (DataUtil.isNullOrZero(companySiteId)) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return resultDTO;
}
try {
// StringBuilder sb = new StringBuilder();
// sb.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-agents-by-params"));
StringBuilder sb = new StringBuilder();
sb.append("SELECT");
sb.append(" a.CAMPAIGN_AGENT_ID campaignAgentId,");
sb.append(" a.FILTER_TYPE filterType,");
sb.append(" a.COMPANY_SITE_ID companySiteId,");
sb.append(" b.USER_ID userId,");
sb.append(" b.USER_NAME userName,");
sb.append(" b.STATUS status,");
sb.append(" b.FULL_NAME fullName");
sb.append(" FROM CAMPAIGN_AGENT a");
sb.append(" INNER JOIN VSA_USERS b ON a.AGENT_ID = b.USER_ID");
sb.append(" WHERE 1 = 1");
sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND a.CAMPAIGN_ID = :p_campaign_id");
if (!DataUtil.isNullOrEmpty(userName)) {
sb.append(" AND UPPER(b.USER_NAME) LIKE UPPER(:p_user_name)");
}
if (!DataUtil.isNullOrEmpty(fullName)) {
sb.append(" AND UPPER(b.FULL_NAME) LIKE UPPER(:p_full_name)");
}
sb.append(" ORDER BY UPPER(b.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString());
query.setParameter("p_company_site_id", companySiteId);
query.setParameter("p_campaign_id", campaignId);
if (!DataUtil.isNullOrEmpty(userName)) {
query.setParameter("p_user_name", "%" +
userName.trim()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
......@@ -328,7 +440,7 @@ public class AgentsServiceImpl implements AgentsService {
if (!DataUtil.isNullOrEmpty(fullName)) {
query.setParameter("p_full_name", "%" +
fullName
fullName.trim()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
......
......@@ -3,14 +3,16 @@ package com.viettel.campaign.service.impl;
import com.github.tennaito.rsql.jpa.JpaCriteriaCountQueryVisitor;
import com.github.tennaito.rsql.jpa.JpaCriteriaQueryVisitor;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.mapper.CustomerListMapper;
import com.viettel.campaign.mapper.CustomerMapper;
import com.viettel.campaign.model.ccms_full.*;
import com.viettel.campaign.repository.ccms_full.*;
import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.utils.*;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerDetailRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerQueryDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import cz.jirutka.rsql.parser.RSQLParser;
import cz.jirutka.rsql.parser.ast.Node;
......@@ -44,8 +46,7 @@ import javax.persistence.criteria.CriteriaQuery;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.reflect.Array;
import java.nio.file.Files;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -849,7 +850,7 @@ public class CustomerServiceImpl implements CustomerService {
count = query.list().size();
}
Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort()));
Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort()).descending());
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
......@@ -946,7 +947,7 @@ public class CustomerServiceImpl implements CustomerService {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Map<String, Object> result = new HashMap<>();
StringBuilder sb = new StringBuilder();
boolean validateOk = false;
int failedCount = 0;
try {
//<editor-fold desc="Khởi tạo mảng header tĩnh" defaultstate="collapsed">
......@@ -971,6 +972,7 @@ public class CustomerServiceImpl implements CustomerService {
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(3);
......@@ -990,8 +992,8 @@ public class CustomerServiceImpl implements CustomerService {
for (int i = 0; i < header.size(); i++) {
Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) {
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.invalidTemplate", locale));
result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid");
return result;
}
}
......@@ -1001,8 +1003,8 @@ public class CustomerServiceImpl implements CustomerService {
//<editor-fold desc="Kiểm tra file dữ liệu rỗng" defaultstate="collapsed">
if (sheet.getPhysicalNumberOfRows() == 3) {
result.put("message", BundleUtils.getLangString("customer.noData", locale));
result.put("file", file);
result.put("message", "template-no-data");
result.put("content", Files.readAllBytes(file.toPath()));
return result;
} else {
Cell resultCell = sheet.getRow(3).createCell(sheet.getRow(3).getPhysicalNumberOfCells());
......@@ -1015,8 +1017,8 @@ public class CustomerServiceImpl implements CustomerService {
for (int i = 4; i < sheet.getPhysicalNumberOfRows(); i++) {
Row dataRow = sheet.getRow(i);
if (dataRow != null) {
Object[] obj = new Object[row.getPhysicalNumberOfCells()];
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
Object[] obj = new Object[row.getPhysicalNumberOfCells() - 1];
for (int j = 0; j < row.getPhysicalNumberOfCells() - 1; j++) {
Cell dataCell = dataRow.getCell(j);
if (dataCell != null) {
obj[j] = dataFormat.formatCellValue(dataCell);
......@@ -1027,7 +1029,6 @@ public class CustomerServiceImpl implements CustomerService {
} else if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.callAllowed", locale)) || headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.emailAllowed", locale))
|| headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.smsAllowed", locale))) {
obj[j] = BundleUtils.getLangString("customer.yes", locale);
break;
} else {
obj[j] = null;
}
......@@ -1046,7 +1047,7 @@ public class CustomerServiceImpl implements CustomerService {
if (!str.equals("")) {
sb.append(str);
}
} else sb.append(BundleUtils.getLangString("customer.nameRequired"));
} else sb.append(BundleUtils.getLangString("customer.nameRequired", locale));
if (rawDataList.get(i).length > 4
&& rawDataList.get(i)[2] != null
&& !rawDataList.get(i)[2].toString().trim().equals("")
......@@ -1090,9 +1091,8 @@ public class CustomerServiceImpl implements CustomerService {
Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1);
if (sb.length() > 0) {
resultCell.setCellValue(sb.toString());
validateOk = false;
failedCount++;
} else {
validateOk = true;
resultCell.setCellValue("Ok");
}
sb = new StringBuilder();
......@@ -1100,7 +1100,7 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold>
//<editor-fold desc="Insert dữ liệu nếu validate Ok" defaultstate="collapsed">
if (validateOk) {
if (failedCount == 0) {
for (int i = 0; i < rawDataList.size(); i++) {
Customer c = new Customer();
c.setName(rawDataList.get(i)[1].toString());
......@@ -1201,9 +1201,9 @@ public class CustomerServiceImpl implements CustomerService {
customerContactRepository.save(cc);
}
}
for (int j = 0; j < dynamicHeader.size(); j++) {
CustomizeFieldObject cfo = new CustomizeFieldObject();
cfo.setObjectId(saved.getCustomerId());
for (int j = 0; j < dynamicHeader.size(); j++) {
cfo.setCustomizeFieldId(dynamicHeader.get(j).getCustomizeFieldId());
if (rawDataList.get(i).length > (12 + j) && rawDataList.get(i)[12 + j] != null) {
switch (dynamicHeader.get(j).getType()) {
......@@ -1244,22 +1244,26 @@ public class CustomerServiceImpl implements CustomerService {
clm.setCustomerListId(customerListId);
customerListMappingRepository.save(clm);
}
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importSuccess", locale));
workbook.write(os);
os.flush();
os.close();
workbook.close();
result.put("content", os.toByteArray());
result.put("message", "");
} else {
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importFailed", locale));
workbook.write(os);
os.flush();
os.close();
workbook.close();
result.put("content", os.toByteArray());
result.put("message", "import-error");
}
//</editor-fold>
return result;
} catch (Exception e) {
LOGGER.info(e.getMessage());
result.put("message", BundleUtils.getLangString("customer.errorValidate", locale));
result.put("message", "validate-error");
return result;
}
}
......@@ -1869,8 +1873,6 @@ public class CustomerServiceImpl implements CustomerService {
// }
try {
StringBuilder sb = new StringBuilder();
sb.append("select");
......
......@@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -261,6 +262,7 @@ public class ScenarioServiceImpl implements ScenarioService {
File file = new File(path);
FileInputStream fis = new FileInputStream(file);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(2);
......@@ -270,18 +272,26 @@ public class ScenarioServiceImpl implements ScenarioService {
resultFont.setFontHeightInPoints((short) 11);
CellStyle resultStyle = workbook.createCellStyle();
resultStyle.setFont(resultFont);
resultStyle.setBorderLeft(BorderStyle.THIN);
resultStyle.setAlignment(HorizontalAlignment.CENTER);
resultStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
resultStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
resultStyle.setBorderRight(BorderStyle.THIN);
resultStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
resultStyle.setBorderBottom(BorderStyle.THIN);
resultStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
resultStyle.setBorderLeft(BorderStyle.THIN);
resultStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
resultStyle.setBorderTop(BorderStyle.THIN);
resultStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
//</editor-fold>
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
for (int i = 0; i < fileHeaderList.size(); i++) {
Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(fileHeaderList.get(i).split("#")[0])) {
result.put("file", file);
result.put("message", BundleUtils.getLangString("common.invalidTemplate", locale));
result.put("content", Files.readAllBytes(file.toPath()));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.INVALID_FORMAT);
return result;
}
}
......@@ -289,8 +299,8 @@ public class ScenarioServiceImpl implements ScenarioService {
//kt file du lieu rong
if (sheet.getPhysicalNumberOfRows() == 2) {
result.put("message", BundleUtils.getLangString("customer.noData", locale));
result.put("file", file);
result.put("content", Files.readAllBytes(file.toPath()));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.EMPTY);
return result;
} else {
Cell resultCell = sheet.getRow(2).createCell(sheet.getRow(2).getPhysicalNumberOfCells());
......@@ -385,7 +395,7 @@ public class ScenarioServiceImpl implements ScenarioService {
isValid = false;
} else {
// isValid = true;
resultCell.setCellValue("Ok");
resultCell.setCellValue(BundleUtils.getLangString("ok"));
}
sb = new StringBuilder();
}
......@@ -397,21 +407,24 @@ public class ScenarioServiceImpl implements ScenarioService {
lstQuestion.forEach(question -> {
questionService.add(question);
});
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importSuccess", locale));
workbook.write(os);
os.flush();
os.close();
workbook.close();
result.put("content", os.toByteArray());
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.SUCCESS);
} else {
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", BundleUtils.getLangString("customer.importFailed", locale));
workbook.write(os);
os.flush();
os.close();
workbook.close();
result.put("content", os.toByteArray());
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
}
} catch (Exception ex) {
logger.info(ex.getMessage(), ex);
result.put("message", BundleUtils.getLangString("customer.errorValidate", locale));
result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
}
logger.info("Import Questions result:", result);
return result;
}
......
......@@ -47,4 +47,11 @@ public class Constants {
public interface MIME_TYPE {
String EXCEL_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
public interface FILE_UPLOAD_RESP_CODE {
String SUCCESS = "00";
String ERROR = "01";
String INVALID_FORMAT = "02";
String EMPTY = "03";
}
}
......@@ -35,4 +35,5 @@ public class VSAUsersDTO {
// String userKazooId;
Short filterType;
Long campaignAgentId;
String roleCode;
}
......@@ -68,6 +68,13 @@ public class AgentsController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@GetMapping("/searchCampaignAgentSelect")
@ResponseBody
public ResponseEntity<ResultDTO> searchCampaignAgentSelect(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId, @RequestParam("campaignId") Long campaignId, @RequestParam("userName") String userName, @RequestParam("fullName") String fullName) {
ResultDTO result = agentsService.searchCampaignAgentSelectByName(page, pageSize, companySiteId, campaignId, userName, fullName);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/createMultipleCampaignAgent")
@ResponseBody
public ResultDTO createMultipleCampaignAgent(@RequestBody @Valid CampaignAgentRequestDTO campaignAgentRequestDTO) {
......
package com.viettel.campaign.web.rest;
import com.viettel.campaign.model.ccms_full.CampaignCustomer;
import com.viettel.campaign.model.ccms_full.Customer;
import com.viettel.campaign.model.ccms_full.CustomizeFieldObject;
import com.viettel.campaign.model.ccms_full.CustomizeFields;
import com.viettel.campaign.repository.ccms_full.CustomerQueryRepository;
import com.viettel.campaign.repository.ccms_full.impl.CustomerQueryRepositoryImpl;
import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.utils.BundleUtils;
import com.viettel.campaign.utils.Config;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.RedisUtil;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerQueryDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CustomizeRequestDTo;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
......@@ -118,12 +112,6 @@ public class CustomerController {
// VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY
String xAuthToken = request.getHeader("X-Auth-Token");
UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
if (userSession == null) {
userSession = new UserSession();
userSession.setSiteId(customerListDTO.getCompanySiteId());
userSession.setUserName("its4");
}
return customerService.createCustomerList(customerListDTO, userSession.getUserName());
}
......@@ -185,14 +173,15 @@ public class CustomerController {
}
//<editor-fold desc="Download and import excel" defaultstate="collapsed">
@GetMapping(value = "/downloadFileTemplate")
public ResponseEntity<byte[]> downloadFileTemplate(@RequestParam("companySiteId") Long companySiteId) {
@PostMapping(value = "/downloadFileTemplate")
public ResponseEntity<byte[]> downloadFileTemplate(@RequestBody Long companySiteId) {
LOGGER.info("--------DOWNLOAD FILE TEMPLATE---------");
try {
byte[] content = customerService.buildTemplate(companySiteId);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=template_import_customer.xlsx")
.header("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX)
// 2 dòng này không hiểu sao lại không hoạt động nữa
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=template_import_customer.xlsx")
// .header("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX)
.body(content);
} catch (Exception e) {
LOGGER.error(e.getMessage());
......@@ -201,34 +190,27 @@ public class CustomerController {
}
@PostMapping(value = "/importFile")
public ResponseEntity<?> importFile(@RequestParam("file") MultipartFile file,
@RequestParam("customerListId") String customerListId,
public ResponseEntity<?> importFile(@RequestPart("file") MultipartFile file,
@RequestPart("customerListId") String customerListId,
HttpServletRequest request) {
LOGGER.info("------------IMPORT FILE TEMPLATE--------------");
Locale locale = new Locale("vi", "VN");
try {
UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token"));
if (userSession == null) {
userSession = new UserSession();
userSession.setSiteId(662691L);
userSession.setUserName("its3");
}
if (file.isEmpty()) {
return new ResponseEntity<>(BundleUtils.getLangString("customer.fileNotSelected"), HttpStatus.OK);
return new ResponseEntity<>("file-empty", HttpStatus.OK);
}
if (!Objects.equals(FilenameUtils.getExtension(file.getOriginalFilename()), Constants.FileType.xlsx)) {
return new ResponseEntity<>(BundleUtils.getLangString("customer.invalidTemplate", locale), HttpStatus.OK);
return new ResponseEntity<>("template-invalid", HttpStatus.OK);
}
String path = saveUploadFile(file);
List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId());
Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, Long.parseLong(customerListId));
File fileExport = (File) map.get("file");
String message = (String) map.get("message");
byte[] content = (byte[]) map.get("content");
return ResponseEntity.ok()
.header("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=template_import_customer.xlsx")
.header("Message", message)
.body(Files.readAllBytes(fileExport.toPath()));
.body(content);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
......
......@@ -119,18 +119,11 @@ public class ScenarioController {
}
String path = saveUploadFile(file);
Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId());
File fileExport = (File) map.get("file");
String message = (String) map.get("message");
ResultDTO resultDTO= new ResultDTO();
resultDTO.setErrorCode("00");
resultDTO.setDescription(message);
resultDTO.setData(fileExport);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", Constants.MIME_TYPE.EXCEL_XLSX);
headers.add("Message", message);
String code = (String) map.get("code");
byte[] content = (byte[]) map.get("content");
return ResponseEntity.ok()
.headers(headers)
.body(Files.readAllBytes(fileExport.toPath()));
.header("Message", code)
.body(content);
} catch (Exception e) {
logger.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
......
......@@ -87,7 +87,6 @@ customer.cusType.vip = VIP
customer.cusType.blacklist = Blacklist
customer.yes = Yes
customer.not = No
customer.invalidTemplate = Invalid Template
customer.noData = Template empty
customer.nameRequired = Full name required;
customer.emailMax50 = Email must less than 50 character;
......@@ -102,7 +101,6 @@ customer.notGreaterThan = not greater than
customer.notLessThan = not less than
customer.importCustomer = IMPORT CUSTOMER
customer.notice = Attention: A record is valid when Full Name is not null and one of three fields Main phone, secondary phone or email is not null
customer.fileNotSelected=Please select a file
customer.emailInvalid=Invalid email;
customer.emailExists=Email exists;
......@@ -136,3 +134,5 @@ scenario.required.required="Require is required"
scenario.default.required="Default is required"
scenario.mappingQuestion.invalid="Mapping question invalid"
ok="Imported"
error="Error"
......@@ -89,7 +89,6 @@ customer.cusType.vip = VIP
customer.cusType.blacklist = Blacklist
customer.yes =
customer.not = Không
customer.invalidTemplate = Template sai định dạng
customer.noData = Template không có dữ liệu
customer.nameRequired = Họ và tên không được để trống;
customer.emailMax50 = Email không được quá 50 kí tự;
......@@ -104,7 +103,6 @@ customer.notGreaterThan = không được lớn hơn
customer.notLessThan = không được nhỏ hơn
customer.importCustomer = IMPORT KHÁCH HÀNG
customer.notice = Chú ý: 1 bản ghi được coi là hợp lệ bắt buộc phải có thông tin Họ và Tên và 1 trong 3 thông tin liên lạc (số điện thoại chính, số điện thoại phụ hoặc email)
customer.fileNotSelected=Bạn chưa chọn file
customer.emailInvalid=Email không đúng định dạng;
customer.emailExists=Email đã tồn tại;
......@@ -138,6 +136,9 @@ scenario.required.required="Trường Bắt buộc bắt buộc nhập"
scenario.default.required="Trường Mặc định bắt buộc nhập"
scenario.mappingQuestion.invalid="Câu hỏi liên kết không hợp lệ"
ok="Thành công"
error="Thất bại"
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