Commit 6f785531 authored by đinh thị đầm's avatar đinh thị đầm
parents 1da529f9 6d5f50f1
......@@ -14,6 +14,14 @@ import java.util.List;
@Transactional(DataSourceQualify.CCMS_FULL)
public interface CampaignCustomerRepository extends JpaRepository<CampaignCustomer, Long>, CampaignCustomerRepositoryCustom {
CampaignCustomer findCampaignCustomerByCampaignCustomerId(Long id);
CampaignCustomer findCampaignCustomerByCampaignIdAndCompanySiteIdAndCustomerId(Long campaignId, Long companySiteId, Long customerId);
List<CampaignCustomer> findCampaignCustomersByCampaignIdAndCompanySiteIdAndCustomerIdAndInCampaignStatus(Long campaignId, Long companySiteId, Long customerId, Short inCampaingStatus);
CampaignCustomer findCampaignCustomersByCampaignIdAndCustomerId(Long campaignId, Long customerId);
@Query(value = "SELECT COUNT(*) " +
" FROM CAMPAIGN_CUSTOMER CC " +
" JOIN CAMPAIGN C ON CC.CAMPAIGN_ID = C.CAMPAIGN_ID " +
......@@ -34,10 +42,6 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
"AND CCC.STATUS = 1 ", nativeQuery = true)
Long getCustomerRecall(@Param("campaignId") Long campaignId, @Param("customerId") Long customerId);
CampaignCustomer findCampaignCustomerByCampaignCustomerId(Long id);
@Query(value = "select C.NAME, " +
"C.EMAIL, " +
"C.PLACE_OF_BIRTH, " +
......@@ -57,10 +61,6 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
, nativeQuery = true)
Long searchCustomer(@Param("site_id") Long pSiteId);
@Query(value = "SELECT * FROM CAMPAIGN_CUSTOMER CC " +
"WHERE CC.STATUS = 0 " +
"AND CC.CAMPAIGN_ID = :campaignId " +
......@@ -88,10 +88,6 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
" 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);
CampaignCustomer findCampaignCustomerByCampaignIdAndCompanySiteIdAndCustomerId(Long campaignId, Long companySiteId, Long customerId);
List<CampaignCustomer> findCampaignCustomersByCampaignIdAndCompanySiteIdAndCustomerIdAndInCampaignStatus(Long campaignId, Long companySiteId, Long customerId, Short inCampaingStatus);
@Query(value = "select complete_value from campaign_complete_code where status = 1 and complete_type = 1", nativeQuery = true)
List<Short> getStatus();
}
......@@ -21,4 +21,6 @@ public interface CampaignExecuteRepository {
List<ContactCustResultDTO> getInteractiveResult(CampaignRequestDTO dto, Pageable pageable);
List<ContactCustResultDTO> getExcelInteractiveResult(CampaignRequestDTO dto);
List<ContactQuestResultDTO> createListContacQuestResult(List<ContactQuestResultDTO> dtoList);
}
......@@ -2,8 +2,15 @@ package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.model.ccms_full.ContactCustResult;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.sql.Date;
@Repository
public interface ContactCustResultRepository extends JpaRepository<ContactCustResult, Long> {
@Query(value = "SELECT MAX(createTime) FROM ContactCustResult WHERE campaignId = :campaignId AND agentId = :agentId AND status = 1")
Date getMaxCreateTime(@Param("campaignId") Long campaignId, @Param("agentId") Long agentId);
}
......@@ -2,15 +2,13 @@ package com.viettel.campaign.repository.ccms_full.impl;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.repository.ccms_full.CampaignExecuteRepository;
import com.viettel.campaign.repository.ccms_full.ContactQuestResultRepository;
import com.viettel.campaign.repository.ccms_full.TimeRangeDialModeRepository;
import com.viettel.campaign.repository.ccms_full.TimeZoneDialModeRepository;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.DataUtil;
import com.viettel.campaign.utils.HibernateUtil;
import com.viettel.campaign.web.dto.ApParamDTO;
import com.viettel.campaign.web.dto.CampaignDTO;
import com.viettel.campaign.web.dto.ContactCustResultDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
......@@ -57,6 +55,9 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
@Autowired
TimeRangeDialModeRepository rangeDialModeRepository;
@Autowired
ContactQuestResultRepository contactQuestResultRepository;
@Override
public List<ApParamDTO> getComboBoxStatus(String companySiteId, String completeType) {
List<ApParamDTO> list = new ArrayList<>();
......@@ -584,4 +585,28 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
return result;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public List<ContactQuestResultDTO> createListContacQuestResult(List<ContactQuestResultDTO> dtoList) {
ResultDTO resultDTO = new ResultDTO();
List<ContactQuestResultDTO> list = new ArrayList<>();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
// list = contactQuestResultRepository.saveAll(dtoList);
} catch (Exception e) {
logger.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally {
session.close();
}
return list;
}
}
......@@ -800,74 +800,74 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>();
// StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-customer-list-choosen");
String sql = "with campaign_customer_id as (\n" +
" select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl\n" +
" where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id\n" +
"),\n" +
"customer_table as (\n" +
" select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a\n" +
" left join customer b on a.customer_id = b.customer_id\n" +
" where b.status = 1\n" +
" group by a.customer_list_id\n" +
"),\n" +
"customer_active_table as (\n" +
" select count(a.customer_id) customerActive, a.customer_list_id customerListId from customer_list_mapping a\n" +
" left join customer b on a.customer_id = b.customer_id\n" +
" where b.status = 1 and b.ipcc_status = 'active'\n" +
" group by a.customer_list_id\n" +
"),\n" +
"customer_lock_table as (\n" +
" select count(a.customer_id) customerLock, a.customer_list_id customerListId from customer_list_mapping a\n" +
" left join customer b on a.customer_id = b.customer_id\n" +
" where b.status = 1 and b.ipcc_status = 'locked'\n" +
" group by a.customer_list_id\n" +
"),\n" +
"customer_dnc_table as (\n" +
" select count(a.customer_id) customerDnc, a.customer_list_id customerListId from customer_list_mapping a\n" +
" left join customer b on a.customer_id = b.customer_id\n" +
" where b.status = 1 and b.call_allowed = 0\n" +
" group by a.customer_list_id\n" +
"),\n" +
"customer_filter_table as (\n" +
" select count(a.customer_id) customerFilter, a.customer_list_id customerListId from campaign_customer a\n" +
" where a.campaign_id = :p_campaign_id and a.in_campaign_status = 1\n" +
" group by a.customer_list_id\n" +
"),\n" +
"data_temp as (\n" +
"select a.customer_list_id customerListId,\n" +
" a.customer_list_code customerListCode,\n" +
" a.customer_list_name customerListName,\n" +
" nvl(b.totalCustomer, 0) totalCusList,\n" +
" nvl(c.customerActive, 0) totalCusActive,\n" +
" nvl(d.customerLock, 0) totalCusLock,\n" +
" nvl(e.customerDnc, 0) totalCusDnc,\n" +
" nvl(null, 0) totalCusAddRemove,\n" +
" nvl(f.customerFilter, 0) totalCusFilter\n" +
"from customer_list a\n" +
"left join customer_table b on a.customer_list_id = b.customerListId\n" +
"left join customer_active_table c on a.customer_list_id = c.customerListId\n" +
"left join customer_lock_table d on a.customer_list_id = d.customerListId\n" +
"left join customer_dnc_table e on a.customer_list_id = e.customerListId\n" +
"left join customer_filter_table f on a.customer_list_id = f.customerListId\n" +
"where a.customer_list_id in (select CUSTOMER_LIST_ID from campaign_customer_id)\n" +
"),\n" +
"data as (\n" +
"select a.*, rownum row_ from data_temp a\n" +
"),\n" +
"count_data as (\n" +
"select count(*) totalRow from data_temp\n" +
")\n" +
"select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusActive, a.totalCusLock, a.totalCusDnc, a.totalCusAddRemove, a.totalCusFilter, totalRow from data a, count_data\n" +
"where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)\n" +
"order by a.customerListName";
sb.append(" with campaign_customer_id as (");
sb.append(" select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl");
sb.append(" where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id");
sb.append(" ),");
sb.append(" customer_table as (");
sb.append(" select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a");
sb.append(" left join customer b on a.customer_id = b.customer_id");
sb.append(" where b.status = 1");
sb.append(" group by a.customer_list_id");
sb.append(" ),");
sb.append(" customer_active_table as (");
sb.append(" select count(a.customer_id) customerActive, a.customer_list_id customerListId from customer_list_mapping a");
sb.append(" left join customer b on a.customer_id = b.customer_id");
sb.append(" where b.status = 1 and b.ipcc_status = 'active'");
sb.append(" group by a.customer_list_id");
sb.append(" ),");
sb.append(" customer_lock_table as (");
sb.append(" select count(a.customer_id) customerLock, a.customer_list_id customerListId from customer_list_mapping a");
sb.append(" left join customer b on a.customer_id = b.customer_id");
sb.append(" where b.status = 1 and b.ipcc_status = 'locked'");
sb.append(" group by a.customer_list_id");
sb.append(" ),");
sb.append(" customer_dnc_table as (");
sb.append(" select count(a.customer_id) customerDnc, a.customer_list_id customerListId from customer_list_mapping a");
sb.append(" left join customer b on a.customer_id = b.customer_id");
sb.append(" where b.status = 1 and b.call_allowed = 0");
sb.append(" group by a.customer_list_id");
sb.append(" ),");
sb.append(" customer_filter_table as (");
sb.append(" select count(a.customer_id) customerFilter, a.customer_list_id customerListId from campaign_customer a");
sb.append(" where a.campaign_id = :p_campaign_id and a.in_campaign_status = 1");
sb.append(" group by a.customer_list_id");
sb.append(" ),");
sb.append(" data_temp as (");
sb.append(" select a.customer_list_id customerListId,");
sb.append(" a.customer_list_code customerListCode,");
sb.append(" a.customer_list_name customerListName,");
sb.append(" nvl(b.totalCustomer, 0) totalCusList,");
sb.append(" nvl(c.customerActive, 0) totalCusActive,");
sb.append(" nvl(d.customerLock, 0) totalCusLock,");
sb.append(" nvl(e.customerDnc, 0) totalCusDnc,");
sb.append(" nvl(null, 0) totalCusAddRemove,");
sb.append(" nvl(f.customerFilter, 0) totalCusFilter");
sb.append(" from customer_list a");
sb.append(" left join customer_table b on a.customer_list_id = b.customerListId");
sb.append(" left join customer_active_table c on a.customer_list_id = c.customerListId");
sb.append(" left join customer_lock_table d on a.customer_list_id = d.customerListId");
sb.append(" left join customer_dnc_table e on a.customer_list_id = e.customerListId");
sb.append(" left join customer_filter_table f on a.customer_list_id = f.customerListId");
sb.append(" where a.customer_list_id in (select CUSTOMER_LIST_ID from campaign_customer_id)");
sb.append(" ),");
sb.append(" data as (");
sb.append(" select a.*, rownum row_ from data_temp a");
sb.append(" ),");
sb.append(" count_data as (");
sb.append(" select count(*) totalRow from data_temp");
sb.append(" )");
sb.append(" select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusActive, a.totalCusLock, a.totalCusDnc, a.totalCusAddRemove, a.totalCusFilter, totalRow from data a, count_data");
sb.append(" where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)");
sb.append(" order by a.customerListName");
params.put("p_campaign_id", dto.getCampaignId());
params.put("p_company_site_id", dto.getCompanySiteId());
params.put("p_page_number", dto.getPage().toString());
params.put("p_page_size", dto.getPageSize().toString());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(CustomerListDTO.class));
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CustomerListDTO.class));
int total = 0;
if (list.size() > 0) {
total = list.get(0).getTotalRow();
......
......@@ -10,7 +10,6 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.List;
@Service
public interface CampaignExecuteService {
//<editor-fold: hungtt>
ResultDTO getComboBoxStatus(String companySiteId, String completeType);
......@@ -37,7 +36,7 @@ public interface CampaignExecuteService {
ResultDTO getAgentLogout(CampaignRequestDTO dto);
ResultDTO callCustomer(ContactCustResultDTO dto, UserSession userSession);
ResultDTO updateContactCustResult(ContactCustResultDTO dto, UserSession userSession);
ResultDTO recallCustomer(ContactCustResultDTO dto);
......
......@@ -538,11 +538,36 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
}
@Override
public ResultDTO callCustomer(ContactCustResultDTO dto, UserSession userSession) {
public ResultDTO updateContactCustResult(ContactCustResultDTO dto, UserSession userSession) {
ResultDTO result = new ResultDTO();
ContactCustResult ccr = new ContactCustResult();
try {
ContactCustResult ccr = ccResultRepository.save(modelMapper.map(dto, ContactCustResult.class));
if (dto.getEventCall().equalsIgnoreCase("call")) {
ccr = ccResultRepository.save(modelMapper.map(dto, ContactCustResult.class));
} else if (dto.getContactCustResultId() != null) {
ccr = ccResultRepository.getOne(dto.getContactCustResultId());
if (dto.getEventCall().equalsIgnoreCase("ringing")) {
ccr.setCallId(dto.getCallId());
ccr.setUpdateBy(userSession.getUserId());
ccr.setUpdateTime(new Date());
ccr = ccResultRepository.save(ccr);
} else if (dto.getEventCall().equalsIgnoreCase("ended")) {
ccr.setDurationCall(dto.getDurationCall());
ccr.setStartCall(dto.getStartCall());
ccr.setReceiveTime(dto.getReceiveTime()); //
ccr.setPreEndTime(ccResultRepository.getMaxCreateTime(dto.getCampaignId(), dto.getAgentId()));
ccr.setEndTime(dto.getEndTime());
ccr.setWaitTime(dto.getWaitTime());
ccr = ccResultRepository.save(ccr);
CampaignCustomer cc = campaignCustomerRepository.findCampaignCustomersByCampaignIdAndCustomerId(dto.getCampaignId(), dto.getCustomerId());
cc.setCallTime(dto.getStartCall());
cc = campaignCustomerRepository.save(cc);
Agents ag = agentsRepository.findByAgentId(dto.getAgentId().toString());
ag.setSystemStatus("AVAILABLE");
ag = agentsRepository.save(ag);
}
}
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
......@@ -682,7 +707,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
}
@Override
@Transactional
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO createListContacQuestResult(List<ContactQuestResultDTO> dtoList) {
ResultDTO resultDTO = new ResultDTO();
List<ContactQuestResult> lstContactQuestResult = new ArrayList<>();
......@@ -692,7 +717,8 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
}
try {
List<ContactQuestResult> dataReturn = contactQuestResultRepository.saveAll(lstContactQuestResult);
List<ContactQuestResult> dataReturn = new ArrayList<>();
dataReturn = contactQuestResultRepository.saveAll(lstContactQuestResult);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(dataReturn);
......
......@@ -55,4 +55,5 @@ public class ContactCustResultDTO extends BaseDTO {
private Boolean enableEdit;
private Integer totalRow;
private String eventCall;
}
package com.viettel.campaign.web.rest;
import com.viettel.campaign.model.ccms_full.ContactQuestResult;
import com.viettel.campaign.service.CampaignExecuteService;
import com.viettel.campaign.utils.RedisUtil;
import com.viettel.campaign.web.dto.*;
......@@ -25,7 +24,7 @@ import java.util.List;
@RestController
@RequestMapping("/ipcc/campaign/execute")
@CrossOrigin
//@CrossOrigin
public class CampaignExecuteController {
private static final Logger logger = LoggerFactory.getLogger(CampaignController.class);
......@@ -136,12 +135,12 @@ public class CampaignExecuteController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/callCustomer")
@PostMapping("/updateContactCustResult")
@ResponseBody
public ResponseEntity<ResultDTO> callCustomer(@RequestBody ContactCustResultDTO requestDto, HttpServletRequest request) {
public ResponseEntity<ResultDTO> updateContactCustResult(@RequestBody ContactCustResultDTO requestDto, HttpServletRequest request) {
String xAuthToken = request.getHeader("X-Auth-Token");
UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
ResultDTO result = campaignExecuteService.callCustomer(requestDto, userSession);
ResultDTO result = campaignExecuteService.updateContactCustResult(requestDto, userSession);
return new ResponseEntity<>(result, HttpStatus.OK);
}
......@@ -166,7 +165,7 @@ public class CampaignExecuteController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/createListContactQuestResult")
@PutMapping("/createListContactQuestResult")
@ResponseBody
public ResponseEntity<ResultDTO> createListContactQuestResult(@RequestBody List<ContactQuestResultDTO> dtoList) {
ResultDTO result = null;
......
......@@ -37,7 +37,7 @@ import java.util.Map;
@RequestMapping("/ipcc/customer")
@CrossOrigin(origins = "*")
public class CustomerController {
private CustomerQueryRepository customerQueryRepo;
private CustomerQueryRepository customerQueryRepo;
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerController.class);
......@@ -198,20 +198,16 @@ public class CustomerController {
try {
UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token"));
if (file.isEmpty()) {
return new ResponseEntity<>("file-empty", HttpStatus.BAD_REQUEST);
return new ResponseEntity<>("file-empty", HttpStatus.NO_CONTENT);
}
String path = saveUploadFile(file);
List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId());
Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, Long.parseLong(customerListId));
String message = (String) map.get("message");
byte[] content = (byte[]) map.get("content");
if (message.equals("import-success")) {
return ResponseEntity.ok()
.header("Message", message)
.body(content);
} else {
return ResponseEntity.badRequest().header("Message", message).body(content);
}
return ResponseEntity.ok()
.header("Message", message)
.body(content);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
......@@ -266,18 +262,15 @@ public class CustomerController {
}
private String saveUploadFile(MultipartFile file) {
try {
String currentTime = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss").format(new Date());
String fileName = FilenameUtils.getBaseName(file.getOriginalFilename()) + "_" + currentTime + "." + FilenameUtils.getExtension(file.getOriginalFilename());
byte[] content = file.getBytes();
// File uploadFolder = new File(BundleUtils.getGlobalConfig("import.uploadFolder"));
File uploadFolder = new File(Config.EXCEL_DIR);
if (!uploadFolder.exists()) {
uploadFolder.mkdir();
}
// Path path = Paths.get(BundleUtils.getGlobalConfig("import.uploadFolder"), fileName);
Path path = Paths.get(Config.EXCEL_DIR, fileName);
Files.write(path, content);
return path.toString();
......@@ -287,7 +280,7 @@ public class CustomerController {
return null;
}
// @GetMapping("/query")
// @GetMapping("/query")
// public ResponseEntity<List<Customer>> query(@RequestParam(value = "search") String query) {
// List<Customer> things = customerQueryRepo.findAll(query);
// if (things.isEmpty()) {
......@@ -295,16 +288,16 @@ public class CustomerController {
// }
// return ResponseEntity.ok(things);
// }
@GetMapping(path = "", produces = { MediaType.APPLICATION_JSON_VALUE })
@GetMapping(path = "", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Customer>> query(@RequestParam(value = "search") String query) {
List<Customer> result = null;
try {
result= customerService.searchByQuery(query);
}catch (IllegalArgumentException iae){
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
result = customerService.searchByQuery(query);
} catch (IllegalArgumentException iae) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(result);
}
return ResponseEntity.status(HttpStatus.OK)
return ResponseEntity.status(HttpStatus.OK)
.body(result);
}
......@@ -317,7 +310,7 @@ public class CustomerController {
@PostMapping("/searchIndividualCustomer")
@ResponseBody
public ResponseEntity searchCustomizeFields(@RequestBody CampaignCustomerDTO campaignCustomerDTO ) {
public ResponseEntity searchCustomizeFields(@RequestBody CampaignCustomerDTO campaignCustomerDTO) {
ResultDTO result = customerService.searchCustomizeFields(campaignCustomerDTO);
return new ResponseEntity<>(result, HttpStatus.OK);
}
......
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