Commit 0b754284 authored by Phạm Duy Phi's avatar Phạm Duy Phi

Merge remote-tracking branch 'origin/master'

parents dca3785a 60dc958f
...@@ -13,4 +13,5 @@ public interface CampaignRepositoryCustom { ...@@ -13,4 +13,5 @@ public interface CampaignRepositoryCustom {
List<CampaignDTO> searchCampaignExecute(String agentId, Pageable pageable); List<CampaignDTO> searchCampaignExecute(String agentId, Pageable pageable);
ResultDTO search(CampaignRequestDTO requestDto); ResultDTO search(CampaignRequestDTO requestDto);
ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO);
} }
...@@ -82,11 +82,16 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -82,11 +82,16 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
Session session = sessionFactory.openSession(); Session session = sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();
if(DataUtil.isNullOrEmpty(requestDto.getCompanySiteId())) {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
return result;
}
try { try {
StringBuilder sqlStr = new StringBuilder(); StringBuilder sqlStr = new StringBuilder();
sqlStr.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-by-params")); sqlStr.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-by-params"));
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) {
sqlStr.append(" AND UPPER(a.CAMPAIGN_CODE) LIKE :p_code"); sqlStr.append(" AND a.CAMPAIGN_CODE IN (:p_code) ");
} }
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) {
sqlStr.append(" AND UPPER(a.CAMPAIGN_NAME) LIKE :p_name"); sqlStr.append(" AND UPPER(a.CAMPAIGN_NAME) LIKE :p_name");
...@@ -97,11 +102,11 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -97,11 +102,11 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
if (!DataUtil.isNullOrEmpty(requestDto.getFromDateFr())) { if (!DataUtil.isNullOrEmpty(requestDto.getFromDateFr())) {
sqlStr.append(" AND TO_DATE(a.START_TIME, 'DD/MM/YYYY') >= :p_frDateFr"); sqlStr.append(" AND TO_DATE(a.START_TIME, 'DD/MM/YYYY') >= :p_frDateFr");
} }
if (!DataUtil.isNullOrEmpty(requestDto.getFromDateTo())) {
sqlStr.append(" AND TO_DATE(a.START_TIME, 'DD/MM/YYYY') <= :p_frDateTo");
}
if (!DataUtil.isNullOrEmpty(requestDto.getToDateFr())) { if (!DataUtil.isNullOrEmpty(requestDto.getToDateFr())) {
sqlStr.append(" AND TO_DATE(a.END_TIME, 'DD/MM/YYYY') >= :p_toDateFr"); sqlStr.append(" AND TO_DATE(a.START_TIME, 'DD/MM/YYYY') <= :p_toDateFr");
}
if (!DataUtil.isNullOrEmpty(requestDto.getFromDateTo())) {
sqlStr.append(" AND TO_DATE(a.END_TIME, 'DD/MM/YYYY') >= :p_frDateTo");
} }
if (!DataUtil.isNullOrEmpty(requestDto.getToDateTo())) { if (!DataUtil.isNullOrEmpty(requestDto.getToDateTo())) {
sqlStr.append(" AND TO_DATE(a.END_TIME, 'DD/MM/YYYY') <= :p_toDateTo"); sqlStr.append(" AND TO_DATE(a.END_TIME, 'DD/MM/YYYY') <= :p_toDateTo");
...@@ -129,12 +134,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -129,12 +134,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
SQLQuery query = session.createSQLQuery(sqlStr.toString()); SQLQuery query = session.createSQLQuery(sqlStr.toString());
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) {
query.setParameter("p_code", "%" + String[] lstCode = requestDto.getCampaignCode().split(",");
requestDto.getCampaignCode().toUpperCase() query.setParameterList("p_code", lstCode);
.replace("\\", "\\\\")
.replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_")
+ "%");
} }
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) {
...@@ -146,6 +147,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -146,6 +147,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
+ "%"); + "%");
} }
query.setParameter("p_company_site_id", requestDto.getCompanySiteId());
if (requestDto.getStatus() != null && requestDto.getStatus() > 0) { if (requestDto.getStatus() != null && requestDto.getStatus() > 0) {
query.setParameter("p_status", requestDto.getStatus()); query.setParameter("p_status", requestDto.getStatus());
} }
...@@ -213,6 +216,77 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -213,6 +216,77 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
return result; return result;
} }
@Override
public ResultDTO findByCampaignCode(CampaignRequestDTO requestDto) {
ResultDTO result = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
if(DataUtil.isNullOrEmpty(requestDto.getCompanySiteId())) {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
return result;
}
try {
StringBuilder sqlStr = new StringBuilder();
sqlStr.append(" SELECT CAMPAIGN_ID campaignId, " +
" CAMPAIGN_CODE campaignCode, " +
" CAMPAIGN_NAME campaignName, " +
" START_TIME startTime," +
" END_TIME endTime, " +
" STATUS status " +
" FROM CAMPAIGN" +
" WHERE COMPANY_SITE_ID = :p_company_site_id AND STATUS <> -1 ");
if(!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) {
sqlStr.append(" AND CAMPAIGN_CODE LIKE :p_code ");
}
sqlStr.append(" ORDER BY START_TIME DESC ");
SQLQuery query = session.createSQLQuery(sqlStr.toString());
query.setParameter("p_company_site_id", requestDto.getCompanySiteId());
if(!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) {
query.setParameter("p_code", "%" +
requestDto.getCampaignCode().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_")
+ "%");
}
query.addScalar("campaignId", new BigDecimalType());
query.addScalar("campaignCode", new StringType());
query.addScalar("campaignName", new StringType());
query.addScalar("startTime", new DateType());
query.addScalar("endTime", new DateType());
query.addScalar("status", new ShortType());
query.setResultTransformer(Transformers.aliasToBean(CampaignDTO.class));
int count = 0;
List<CampaignDTO> list = query.list();
if (list.size() > 0) {
count = query.list().size();
}
Pageable pageable = buildPageable(requestDto);
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<CampaignDTO> data = query.list();
Page<CampaignDTO> dataPage = new PageImpl<>(data, pageable, count);
result.setData(dataPage);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
session.close();
return result;
}catch (Exception ex) {
session.close();
}
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR);
return result;
}
private Pageable buildPageable(CampaignRequestDTO obj) { private Pageable buildPageable(CampaignRequestDTO obj) {
Pageable pageable = null; Pageable pageable = null;
if (DataUtil.isNullOrEmpty(obj.getSort())) { if (DataUtil.isNullOrEmpty(obj.getSort())) {
......
...@@ -9,4 +9,5 @@ public interface CampaignService { ...@@ -9,4 +9,5 @@ public interface CampaignService {
Map searchCampaignExecute(int page, int pageSize, String sort, String agentId); Map searchCampaignExecute(int page, int pageSize, String sort, String agentId);
ResultDTO search(CampaignRequestDTO requestDto); ResultDTO search(CampaignRequestDTO requestDto);
ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO);
} }
package com.viettel.campaign.service.impl; package com.viettel.campaign.service.impl;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.repository.CampaignRepository; import com.viettel.campaign.repository.CampaignRepository;
import com.viettel.campaign.service.CampaignService; import com.viettel.campaign.service.CampaignService;
import com.viettel.campaign.web.dto.CampaignDTO; import com.viettel.campaign.web.dto.CampaignDTO;
...@@ -39,4 +40,9 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -39,4 +40,9 @@ public class CampaignServiceImpl implements CampaignService {
public ResultDTO search(CampaignRequestDTO requestDto) { public ResultDTO search(CampaignRequestDTO requestDto) {
return campaignRepository.search(requestDto); return campaignRepository.search(requestDto);
} }
@Override
public ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO) {
return campaignRepository.findByCampaignCode(requestDTO);
}
} }
package com.viettel.campaign.service.impl;
<<<<<<< HEAD:src/main/java/com/viettel/campaign/service/CampaignServiceImpl.java
import com.viettel.campaign.repository.CampaignRepository;
import com.viettel.campaign.web.dto.CampaignDTO;
=======
import com.viettel.campaign.dto.CampaignDTO;
import com.viettel.campaign.dto.ResultDTO;
import com.viettel.campaign.dto.request_dto.CampaignRequestDTO;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.repository.CampaignRepository;
import com.viettel.campaign.service.CampaignService;
>>>>>>> anhvd_campaign_mng:src/main/java/com/viettel/campaign/service/impl/CampaignServiceImpl.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CampaignServiceImpl implements CampaignService {
@Autowired(required=true)
CampaignRepository campaignRepository;
@Override
public Map searchCampaignExecute(int page, int pageSize, String sort, String agentId) {
Map result = new HashMap();
List<CampaignDTO> lst = new ArrayList<>();
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
lst = campaignRepository.searchCampaignExecute(agentId, pageable);
result.put("totalItem", lst.size());
result.put("data", lst);
return result;
}
@Override
public ResultDTO search(CampaignRequestDTO requestDto) {
return campaignRepository.search(requestDto);
}
}
...@@ -4,8 +4,6 @@ import com.viettel.campaign.web.dto.BaseDTO; ...@@ -4,8 +4,6 @@ import com.viettel.campaign.web.dto.BaseDTO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.Date;
/** /**
* @author anhvd_itsol * @author anhvd_itsol
*/ */
...@@ -25,4 +23,5 @@ public class CampaignRequestDTO extends BaseDTO { ...@@ -25,4 +23,5 @@ public class CampaignRequestDTO extends BaseDTO {
Long numOfCusTo; Long numOfCusTo;
Short type; Short type;
Short chanel; Short chanel;
String companySiteId;
} }
...@@ -34,4 +34,9 @@ public class CampaignController { ...@@ -34,4 +34,9 @@ public class CampaignController {
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
@RequestMapping(value = "/findByCampaignCode", method = RequestMethod.POST)
public ResultDTO findByCampaignCode(@RequestBody CampaignRequestDTO dto) {
return campaignService.findByCampaignCode(dto);
}
} }
...@@ -30,3 +30,5 @@ LEFT JOIN (SELECT cc.campaign_id, count(*) AS SLKHDoNotCall_Khoa ...@@ -30,3 +30,5 @@ LEFT JOIN (SELECT cc.campaign_id, count(*) AS SLKHDoNotCall_Khoa
GROUP BY cc.CAMPAIGN_ID) d GROUP BY cc.CAMPAIGN_ID) d
ON d.CAMPAIGN_ID = a.CAMPAIGN_ID ON d.CAMPAIGN_ID = a.CAMPAIGN_ID
WHERE 1 = 1 WHERE 1 = 1
AND COMPANY_SITE_ID = :p_company_site_id
AND a.STATUS <> -1
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