Commit eb6c792e authored by ='s avatar =

hungtt-commit campaign-mng customer-list

parent 01f97d3a
...@@ -50,5 +50,17 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom ...@@ -50,5 +50,17 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
"AND CC.CUSTOMER_LIST_ID = :customerListId", nativeQuery = true) "AND CC.CUSTOMER_LIST_ID = :customerListId", nativeQuery = true)
List<CampaignCustomer> findCustomerContacted(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId, @Param("customerListId") Long customerListId); List<CampaignCustomer> findCustomerContacted(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId, @Param("customerListId") Long customerListId);
@Query(value = "with status_customer as (\n" +
"select complete_value \n" +
"from campaign_complete_code\n" +
"where complete_value <> 4\n" +
" and is_finish <> 1\n" +
" and campaign_type = 1\n" +
" and company_site_id = :p_company_site_id\n" +
")\n" +
"select * from campaign_customer\n" +
"where campaign_id = :p_campaign_id\n" +
" and customer_list_id = :p_cus_list_id\n" +
" and (status = 0 or status in (select * from status_customer))", nativeQuery = true)
List<CampaignCustomer> findListCustomerToDel(@Param("p_company_site_id") Long companySiteId, @Param("p_campaign_id") Long campaignId, @Param("p_cus_list_id") Long customerListId);
} }
...@@ -32,5 +32,9 @@ public interface CampaignRepositoryCustom { ...@@ -32,5 +32,9 @@ public interface CampaignRepositoryCustom {
ResultDTO getCustomerList(CampaignRequestDTO dto); ResultDTO getCustomerList(CampaignRequestDTO dto);
ResultDTO getCustomerChoosenList(CampaignRequestDTO dto); ResultDTO getCustomerChoosenList(CampaignRequestDTO dto);
ResultDTO getCampaignCustomerInformation(CampaignRequestDTO dto);
ResultDTO getCustomerListInformation(CampaignRequestDTO dto);
//</editor-fold> //</editor-fold>
} }
...@@ -32,4 +32,10 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> { ...@@ -32,4 +32,10 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Query("select c from Customer c left join com.viettel.campaign.model.ccms_full.CustomerTime ct on c.customerId = ct.customerId " + @Query("select c from Customer c left join com.viettel.campaign.model.ccms_full.CustomerTime ct on c.customerId = ct.customerId " +
"where c.ipccStatus = 'locked' and c.siteId =?1 and ct.endTime <= ?2") "where c.ipccStatus = 'locked' and c.siteId =?1 and ct.endTime <= ?2")
List<Customer> findAllByCondition(Long siteId, Date endTime); List<Customer> findAllByCondition(Long siteId, Date endTime);
@Query(value = "select * from customer a\n" +
"left join customer_list_mapping b on a.customer_id = b.customer_id\n" +
"where b.customer_list_id = :p_customer_list_id\n" +
" and a.customer_id not in (select cc.customer_id from campaign_customer cc where cc.campaign_id = :p_campaign_id and cc.customer_list_id = :p_customer_list_id)", nativeQuery = true)
List<Customer> findAllCutomerNotInCampagin(@Param("p_customer_list_id") Long customerListId, @Param("p_campaign_id") Long campaignId);
} }
...@@ -864,4 +864,111 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -864,4 +864,111 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
return resultDTO; return resultDTO;
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCampaignCustomerInformation(CampaignRequestDTO dto) {
List<CampaignInformationDTO> list = new ArrayList();
ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>();
StringBuilder sb = new StringBuilder();
try {
sb.append(" with status_customer as (");
sb.append(" select complete_value");
sb.append(" from campaign_complete_code");
sb.append(" where complete_value <> 4");
sb.append(" and is_finish <> 1");
sb.append(" and campaign_type = 1");
sb.append(" and company_site_id = :p_company_site_id");
sb.append(" ),");
sb.append(" count_customer as (");
sb.append(" select campaign_id campaignId,");
sb.append(" sum(case");
sb.append(" when customer_list_id is null then 1");
sb.append(" else 0");
sb.append(" end) totalIndividual,");
sb.append(" sum(case");
sb.append(" when status = 0 then 1");
sb.append(" else 0");
sb.append(" end) totalNotInteractive,");
sb.append(" sum(case");
sb.append(" when status in (select * from status_customer) then 1");
sb.append(" else 0");
sb.append(" end) totalNotCall");
sb.append(" from campaign_customer");
sb.append(" group by campaign_id");
sb.append(" )");
sb.append(" select a.*, b.customer_number campaignCustomer");
sb.append(" from count_customer a");
sb.append(" left join campaign b on a.campaignId = b.campaign_id");
sb.append(" where a.campaignId = :p_campaign_id");
params.put("p_campaign_id", dto.getCampaignId());
params.put("p_company_site_id", dto.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CampaignInformationDTO.class));
if (list.size() > 0) {
resultDTO.setData(list.get(0));
} else {
resultDTO.setData(list);
}
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
logger.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
return resultDTO;
}
@Override
public ResultDTO getCustomerListInformation(CampaignRequestDTO dto) {
List<CampaignInformationDTO> list = new ArrayList();
ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>();
StringBuilder sb = new StringBuilder();
try {
sb.append(" with status_customer as (");
sb.append(" select complete_value");
sb.append(" from campaign_complete_code");
sb.append(" where complete_value <> 4");
sb.append(" and is_finish <> 1");
sb.append(" and campaign_type = 1");
sb.append(" and company_site_id = :p_company_site_id");
sb.append(" ),");
sb.append(" count_customer as (");
sb.append(" select campaign_id campaignId,");
sb.append(" customer_list_id customerListId,");
sb.append(" sum(case");
sb.append(" when customer_list_id is null then 1");
sb.append(" else 0");
sb.append(" end) totalIndividual,");
sb.append(" sum(case");
sb.append(" when status = 0 then 1");
sb.append(" else 0");
sb.append(" end) totalNotInteractive,");
sb.append(" sum(case");
sb.append(" when status in (select * from status_customer) then 1");
sb.append(" else 0");
sb.append(" end) totalNotCall");
sb.append(" from campaign_customer");
sb.append(" group by customer_list_id, campaign_id");
sb.append(" )");
sb.append(" select a.*, b.customer_number campaignCustomer");
sb.append(" from count_customer a");
sb.append(" left join campaign b on a.campaignId = b.campaign_id");
sb.append(" where a.campaignId = :p_campaign_id");
sb.append(" and customerListId is not null");
params.put("p_campaign_id", dto.getCampaignId());
params.put("p_company_site_id", dto.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CampaignInformationDTO.class));
resultDTO.setListData(list);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
logger.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
return resultDTO;
}
} }
...@@ -66,6 +66,12 @@ public interface CampaignService { ...@@ -66,6 +66,12 @@ public interface CampaignService {
ResultDTO deleteCustomerListFromCampaign(CampaignRequestDTO dto); ResultDTO deleteCustomerListFromCampaign(CampaignRequestDTO dto);
ResultDTO saveFieldCustomer(CampaignRequestDTO dto); ResultDTO saveFieldCustomer(CampaignRequestDTO dto);
ResultDTO getCampaignCustomerInformation(CampaignRequestDTO dto);
ResultDTO getCustomerListInformation(CampaignRequestDTO dto);
ResultDTO saveCustomerCampaign(CampaignRequestDTO dto);
//</editor-fold> //</editor-fold>
} }
...@@ -70,6 +70,9 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -70,6 +70,9 @@ public class CampaignServiceImpl implements CampaignService {
@Autowired @Autowired
CampaignCustomerListColumnRepository campaignCustomerListColumnRepository; CampaignCustomerListColumnRepository campaignCustomerListColumnRepository;
@Autowired
CustomerRepository customerRepository;
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO search(CampaignRequestDTO requestDto) { public ResultDTO search(CampaignRequestDTO requestDto) {
...@@ -613,6 +616,61 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -613,6 +616,61 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO; return resultDTO;
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCampaignCustomerInformation(CampaignRequestDTO dto) {
return campaignRepositoryCustom.getCampaignCustomerInformation(dto);
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCustomerListInformation(CampaignRequestDTO dto) {
return campaignRepositoryCustom.getCustomerListInformation(dto);
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO saveCustomerCampaign(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
long campaignId = Long.parseLong(dto.getCampaignId());
long companySiteId = Long.parseLong(dto.getCompanySiteId());
List<CustomerListDTO> listCustomerDto = dto.getLstCustomerCampaign();
try {
// Thuc hien them giam khach hang
for (CustomerListDTO customerListDTO : listCustomerDto) {
if (customerListDTO.getTotalCusAddRemove() > 0) { // Them khach hang
// Lay ra danh sach khach hang phu hop de them
List<Customer> listCustomerToAdd = customerRepository.findAllCutomerNotInCampagin(customerListDTO.getCustomerListId(), campaignId);
for (int i = 0; i < customerListDTO.getTotalCusAddRemove(); i++) {
CampaignCustomer campaignCustomerEntity = new CampaignCustomer();
campaignCustomerEntity.setCampaignId(campaignId);
campaignCustomerEntity.setCustomerId(listCustomerToAdd.get(i).getCustomerId());
campaignCustomerEntity.setStatus((short) 0);
campaignCustomerEntity.setRecallCount(0L);
campaignCustomerEntity.setCustomerListId(customerListDTO.getCustomerListId());
campaignCustomerEntity.setCompanySiteId(companySiteId);
campaignCustomerEntity.setInCampaignStatus((short) 1);
campaignCustomerRepository.save(campaignCustomerEntity);
}
} else if (customerListDTO.getTotalCusAddRemove() < 0){ // Loai bo khach hang
long custToDel = Math.abs(customerListDTO.getTotalCusAddRemove());
// Lay ra danh sach khach hang can loai bo
List<CampaignCustomer> listCustomerToDelete = campaignCustomerRepository.findListCustomerToDel(companySiteId, campaignId, customerListDTO.getCustomerListId());
for (int j = 0; j < custToDel; j++) {
campaignCustomerRepository.delete(listCustomerToDelete.get(j));
}
}
}
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
logger.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
return resultDTO;
}
// hungtt // hungtt
private Map<String, String> setMapData(Map<String, String> mapColumn, Locale locale) { private Map<String, String> setMapData(Map<String, String> mapColumn, Locale locale) {
mapColumn.put("CUSTOMER_ID", BundleUtils.getLangString("CUSTOMER_ID", locale)); mapColumn.put("CUSTOMER_ID", BundleUtils.getLangString("CUSTOMER_ID", locale));
......
package com.viettel.campaign.web.dto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CampaignInformationDTO {
private Long campaignId;
private Long totalIndividual;
private Long totalNotInteractive;
private Long totalNotCall;
private Long campaignCustomer;
private Long customerListId;
}
...@@ -2,6 +2,7 @@ package com.viettel.campaign.web.dto.request_dto; ...@@ -2,6 +2,7 @@ package com.viettel.campaign.web.dto.request_dto;
import com.viettel.campaign.web.dto.BaseDTO; import com.viettel.campaign.web.dto.BaseDTO;
import com.viettel.campaign.web.dto.CustomerCustomDTO; import com.viettel.campaign.web.dto.CustomerCustomDTO;
import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.FieldsToShowDTO; import com.viettel.campaign.web.dto.FieldsToShowDTO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -53,4 +54,6 @@ public class CampaignRequestDTO extends BaseDTO { ...@@ -53,4 +54,6 @@ public class CampaignRequestDTO extends BaseDTO {
String createTimeFr; String createTimeFr;
String lstCustomerListId; String lstCustomerListId;
List<FieldsToShowDTO> lstFiedCustomer; List<FieldsToShowDTO> lstFiedCustomer;
List<CustomerListDTO> lstCustomerCampaign;
String customerListId;
} }
...@@ -305,6 +305,28 @@ public class CampaignController { ...@@ -305,6 +305,28 @@ public class CampaignController {
return new ResponseEntity<>(resultDTO, HttpStatus.OK); return new ResponseEntity<>(resultDTO, HttpStatus.OK);
} }
@PostMapping("/getCampaignCustomerInformation")
@ResponseBody
public ResponseEntity getCampaignCustomerInformation(@RequestBody CampaignRequestDTO campaignRequestDTO) {
campaignRequestDTO.setCustomerListId(null);
ResultDTO resultDTO = campaignService.getCampaignCustomerInformation(campaignRequestDTO);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@PostMapping("/getCustomerListInformation")
@ResponseBody
public ResponseEntity getCustomerListInformation(@RequestBody CampaignRequestDTO campaignRequestDTO) {
ResultDTO resultDTO = campaignService.getCustomerListInformation(campaignRequestDTO);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@PostMapping("/saveCustomerCampaign")
@ResponseBody
public ResponseEntity saveCustomerCampaign(@RequestBody CampaignRequestDTO campaignRequestDTO) {
ResultDTO resultDTO = campaignService.saveCustomerCampaign(campaignRequestDTO);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@RequestMapping(value = "/renewCampaign", method = RequestMethod.PUT) @RequestMapping(value = "/renewCampaign", method = RequestMethod.PUT)
public ResponseEntity<ResultDTO> renewCampaign(@RequestBody CampaignDTO campaignDTO) { public ResponseEntity<ResultDTO> renewCampaign(@RequestBody CampaignDTO campaignDTO) {
ResultDTO result = campaignService.renewCampaign(campaignDTO); ResultDTO result = campaignService.renewCampaign(campaignDTO);
......
...@@ -60,6 +60,9 @@ where a.status <> 0 ...@@ -60,6 +60,9 @@ where a.status <> 0
), ),
data as ( data as (
select a.*, rownum row_ from data_temp a select a.*, rownum row_ from data_temp a
),
count_data as (
select count(*) totalRow from data_temp
) )
select * from data select campaignCode, campaignName, userName, phoneNumber, customerName, startCall, contactStatus, surveyStatus, status, recordStatus, callTime, totalRow from data, count_data
where :p_page_size = 0 or (row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)) where :p_page_size = 0 or (row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1))
with status_customer as (
select complete_value
from campaign_complete_code
where complete_value <> 4
and is_finish <> 1
and campaign_type = 1
and company_site_id = :p_company_site_id
),
count_customer as (
select campaign_id campaignId,
sum(case
when customer_list_id is null then 1
else 0
end) totalIndividual,
sum(case
when status = 0 then 1
else 0
end) totalNotInteractive,
sum(case
when status in (select * from status_customer) then 1
else 0
end) totalNotCall
from campaign_customer
where :p_cus_list_id is null or customer_list_id = :p_cus_list_id
group by campaign_id
)
select a.*, b.customer_number campaignCustomer
from count_customer a
left join campaign b on a.campaignId = b.campaign_id
where a.campaignId = :p_campaign_id
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