Commit 1e80dcc1 authored by Đào Nhật Quang's avatar Đào Nhật Quang

quangdn

parent 86ad7b6d
......@@ -6,6 +6,7 @@ import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import java.io.File;
import java.util.Date;
import java.util.List;
......@@ -59,5 +60,9 @@ public interface CustomerService {
List<Customer> findAllByCondition(Long siteId, Date endTime);
Customer update(Customer c);
List<DynamicExcelHeaderDTO> getDynamicHeader(Long companySiteId);
void buildTemplate(Long companySiteId);
List<CustomizeFieldDTO> getCustomizeField(Long customerId);
}
......@@ -16,6 +16,11 @@ import com.viettel.campaign.utils.SQLBuilder;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
......@@ -33,11 +38,17 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.sql.DataSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.*;
@Service
......@@ -685,6 +696,54 @@ public class CustomerServiceImpl implements CustomerService {
return result;
}
@Override
public List<DynamicExcelHeaderDTO> getDynamicHeader(Long companySiteId) {
List<DynamicExcelHeaderDTO> headerList;
try {
String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_CUSTOMER_MNG, "get-dynamic-header");
Map<String, Object> param = new HashMap<>();
param.put("p_company_site_id", companySiteId);
headerList = namedParameterJdbcTemplate.query(sql, param, new BeanPropertyRowMapper<>(DynamicExcelHeaderDTO.class));
} catch (Exception e) {
return null;
}
return headerList;
}
@Override
public void buildTemplate(Long companySiteId) {
try {
List<DynamicExcelHeaderDTO> headerList = getDynamicHeader(companySiteId);
FileInputStream fis = new FileInputStream(ResourceUtils.getFile("classpath:templates/import_customer_template.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.createCell(row.getPhysicalNumberOfCells());
cell.setCellType(CellType.STRING);
cell.setCellValue("test");
FileOutputStream fos = new FileOutputStream(ResourceUtils.getFile("classpath:templates/import_customer_template.xlsx"));
workbook.write(fos);
fos.close();
workbook.close();
} catch (Exception e) {
}
}
@Override
public List<CustomizeFieldDTO> getCustomizeField(Long customerId) {
List<CustomizeFieldDTO> customizeFieldDTOList;
try {
String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-customize-field");
Map<String, Object> param = new HashMap<>();
param.put("p_customer_id", customerId);
customizeFieldDTOList = namedParameterJdbcTemplate.query(sql, param, new BeanPropertyRowMapper<>(CustomizeFieldDTO.class));
} catch (Exception e) {
return null;
}
return customizeFieldDTOList;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO) {
......
......@@ -16,6 +16,7 @@ import org.springframework.data.domain.Sort;
public class SQLBuilder {
public static final String SQL_MODULE_CAMPAIGN_MNG = "campaign-mng";
public static final String SQL_MODULE_CAMPAIGN_STATUS_MNG = "campaign-status-mng";
public static final String SQL_MODULE_CAMPAIGN_CUSTOMER_MNG = "campaign-customer-mng";
public static String getSqlQueryById(String module,
String queryId) {
......
package com.viettel.campaign.web.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CustomizeFieldDTO {
private Long customizeFieldObjectId;
private Long objectId;
private Long customizeFieldId;
private String valueText;
private Long valueNumber;
private Date valueDate;
private Long valueCheckbox;
private Date createBy;
private Date createDate;
private String updateBy;
private Date updateDate;
private Long status;
private Long fieldOptionValueId;
private String title;
private String functionCode;
}
package com.viettel.campaign.web.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class DynamicExcelHeaderDTO {
private Long customizeFieldId;
private Long siteId;
private String functionCode;
private String createBy;
private Date createDate;
private String updateBy;
private Date updateDate;
private Long status;
private String type;
private String title;
private String placeholder;
private String description;
private Long position;
private Long required;
private Long fieldOptionsId;
private String regexpForValidation;
private Long maxLength;
private Long minLength;
private Long min;
private Long max;
private Long active;
}
......@@ -187,10 +187,11 @@ public class CustomerController {
}
@GetMapping(value = "/downloadFileTemplate")
public ResponseEntity<byte[]> downloadFileTemplate() {
public ResponseEntity<byte[]> downloadFileTemplate(@RequestParam("companySiteId") Long companySiteId) {
LOGGER.debug("--------DOWNLOAD FILE TEMPLATE---------");
try {
File file = ResourceUtils.getFile("classpath:templates/test_download.xlsx");
customerService.buildTemplate(companySiteId);
File file = ResourceUtils.getFile("classpath:templates/import_customer_template.xlsx");
byte[] content = Files.readAllBytes(file.toPath());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
......@@ -250,4 +251,10 @@ public class CustomerController {
@RequestParam("companySiteId") Long companySiteId) {
return null;// customerService.searchCustomerListInfoFromCustomerList(page, pageSize, sort, campaignId, companySiteId);
}
@PostMapping("/getCustomizeField")
public ResponseEntity<?> getCustomizeField(@RequestBody Long customerId) {
List<CustomizeFieldDTO> data = customerService.getCustomizeField(customerId);
return new ResponseEntity<>(data, HttpStatus.OK);
}
}
select CUSTOMIZE_FIELD_ID customizeFieldId,
SITE_ID companySiteId,
FUNCTION_CODE functionCode,
CREATE_BY createBy,
CREATE_DATE createDate,
UPDATE_BY updateBy,
UPDATE_DATE updateDate,
STATUS status,
TYPE type,
TITLE title,
PLACEHOLDER placeholder,
DESCRIPTION description,
POSITION position,
REQUIRED required,
FIELD_OPTIONS_ID fieldOptionsId,
REGEXP_FOR_VALIDATION regexpForValidation,
MAX_LENGTH maxLength,
MIN min,
MAX max,
MIN_LENGTH minLength,
ACTIVE active
from customize_fields
where function_code = 'CUSTOMER'
and site_id = :p_company_site_id
\ No newline at end of file
select CUSTOMIZE_FIELD_OBJECT_ID customizeFieldObjectId,
OBJECT_ID objectId,
CUSTOMIZE_FIELDS_ID customizeFieldId,
VALUE_TEXT valueText,
VALUE_NUMBER valueNumber,
VALUE_DATE valueDate,
VALUE_CHECKBOX valueCheckbox,
CREATE_BY createBy,
CREATE_DATE createDate,
UPDATE_BY updateBy,
UPDATE_DATE updateDate,
STATUS status,
FIELD_OPTION_VALUE_ID fieldOptionValueId,
TITLE title,
FUNCTION_CODE functionCode
from customize_field_object
where function_code = 'CUSTOMER' and object_id = :p_customer_id
\ No newline at end of file
......@@ -11,7 +11,8 @@ from customer_contact cc
where cc.contact_type = 2
and status = 1
), datas as (
select c.name,
select c.customer_id customerId,
c.name,
cP.phone,
cE.email,
c.customer_type cusType,
......
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