Commit 60dc958f authored by Vu Duy Anh's avatar Vu Duy Anh

anhvd commit campaign services

parent 4bedb387
......@@ -13,5 +13,5 @@ public interface CampaignRepositoryCustom {
List<CampaignDTO> searchCampaignExecute(String agentId, Pageable pageable);
ResultDTO search(CampaignRequestDTO requestDto);
ResultDTO findByCompanySiteId(CampaignRequestDTO requestDTO);
ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO);
}
......@@ -91,7 +91,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
StringBuilder sqlStr = new StringBuilder();
sqlStr.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-by-params"));
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())) {
sqlStr.append(" AND UPPER(a.CAMPAIGN_NAME) LIKE :p_name");
......@@ -134,12 +134,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
SQLQuery query = session.createSQLQuery(sqlStr.toString());
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) {
query.setParameter("p_code", "%" +
requestDto.getCampaignCode().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_")
+ "%");
String[] lstCode = requestDto.getCampaignCode().split(",");
query.setParameterList("p_code", lstCode);
}
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) {
......@@ -221,7 +217,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
}
@Override
public ResultDTO findByCompanySiteId(CampaignRequestDTO requestDto) {
public ResultDTO findByCampaignCode(CampaignRequestDTO requestDto) {
ResultDTO result = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
......@@ -243,10 +239,20 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
" 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());
......
......@@ -9,5 +9,5 @@ public interface CampaignService {
Map searchCampaignExecute(int page, int pageSize, String sort, String agentId);
ResultDTO search(CampaignRequestDTO requestDto);
ResultDTO findByCompanySiteId(CampaignRequestDTO requestDTO);
ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO);
}
......@@ -42,11 +42,7 @@ public class CampaignServiceImpl implements CampaignService {
}
@Override
public ResultDTO findByCompanySiteId(CampaignRequestDTO requestDTO) {
requestDTO.setCompanySiteId("663192");
requestDTO.setPage(0);
requestDTO.setPageSize(10);
Pageable pageable = PageRequest.of(requestDTO.getPage(), requestDTO.getPageSize(), null);
return campaignRepository.findByCompanySiteId(requestDTO);
public ResultDTO findByCampaignCode(CampaignRequestDTO requestDTO) {
return campaignRepository.findByCampaignCode(requestDTO);
}
}
package com.viettel.campaign.web.rest.controller;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.service.CampaignService;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
......@@ -10,7 +9,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
......@@ -36,9 +34,9 @@ public class CampaignController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
@RequestMapping(value = "/findByCompanySiteId", method = RequestMethod.POST)
public ResultDTO findByCompanySiteId(CampaignRequestDTO dto) {
return campaignService.findByCompanySiteId(dto);
@RequestMapping(value = "/findByCampaignCode", method = RequestMethod.POST)
public ResultDTO findByCampaignCode(@RequestBody CampaignRequestDTO dto) {
return campaignService.findByCampaignCode(dto);
}
}
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