Commit b1e902ae authored by Tu Bach's avatar Tu Bach

tubn commit update campaign execute

parent 787e4ca1
......@@ -6,9 +6,11 @@ import org.springframework.data.domain.Pageable;
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.util.List;
@Repository
public interface ApParamRepository extends JpaRepository<ApParam, Long>, ApParamRepositoryCustom {
Page<ApParam> findAll(Pageable pageable);
......
package com.viettel.campaign.repository;
import com.viettel.campaign.model.ApParam;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ApParamRepositoryCustom {
}
......@@ -6,9 +6,11 @@ import org.springframework.data.domain.Pageable;
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.util.List;
@Repository
public interface CampaignCompleteCodeRepository extends JpaRepository<CampaignCompleteCode, Long> {
Page<CampaignCompleteCode> findAll(Pageable pageable);
......
......@@ -4,9 +4,11 @@ import com.viettel.campaign.web.dto.CampaignDTO;
import com.viettel.campaign.dto.request_dto.CampaignRequestDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CampaignRepositoryCustom {
List<CampaignDTO> searchCampaignExecute(String agentId, Pageable pageable);
ResultDTO search(CampaignRequestDTO requestDto);
......
......@@ -5,9 +5,11 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Long> {
Page<Customer> findAll(Pageable pageable);
......
......@@ -18,6 +18,7 @@ import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Repository
......@@ -30,26 +31,41 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
public List<CampaignDTO> searchCampaignExecute(String agentId, Pageable pageable) {
List<CampaignDTO> lst = new ArrayList<>();
String expression = new StringBuilder()
.append(" SELECT C.CAMPAIGN_ID, C.CAMPAIGN_NAME, C.STATUS ")
.append(" SELECT C.CAMPAIGN_ID, C.CAMPAIGN_NAME, C.CONTENT, C.START_TIME, C.END_TIME, C.STATUS ")
//.append(" SELECT CAMPAIGN_COMPLETE_CODE_ID AS CAMPAIGN_ID, COMPLETE_NAME AS CAMPAIGN_NAME, DESCRIPTION AS CONTENT, UPDATE_BY AS START_TIME, UPDATE_BY AS END_TIME, STATUS ")
.append(" FROM CAMPAIGN C ")
.append(" INNER JOIN CAMPAIGN_AGENT CA ON C.CAMPAIGN_ID = CA.CAMPAIGN_ID ")
.append(" WHERE 1 = 1 ")
.append(" AND CA.AGENT_ID = :pAgentId ")
//.append(" AND CA.AGENT_ID = :pAgentId ")
.append(" AND C.STATUS IN (2,3) ")
.toString();
Query query = entityManager.createNativeQuery(expression);
query.setParameter("pAgentId", agentId);
try {
Query query = entityManager.createNativeQuery(expression);
//query.setParameter("pAgentId", agentId);
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<Object[]> data = query.getResultList();
List<Object[]> data = query.getResultList();
for (Object[] obj : data) {
CampaignDTO item = new CampaignDTO();
item.setCampaignId((BigDecimal) obj[0]);
item.setCampaignName((String) obj[1]);
item.setStatus((BigDecimal) obj[0]);
for (Object[] obj : data) {
CampaignDTO item = new CampaignDTO();
item.setCampaignId((BigDecimal) obj[0]);
item.setCampaignName((String) obj[1]);
item.setContent((String) obj[2]);
item.setStartTime((Date) obj[3]);
item.setEndTime((Date) obj[4]);
item.setStatus((BigDecimal) obj[5]);
lst.add(item);
}
lst.add(item);
return lst;
} catch (Exception e) {
e.printStackTrace();
}
return lst;
......
package com.viettel.campaign.service;
import com.viettel.campaign.dto.ResultDTO;
import com.viettel.campaign.dto.request_dto.CampaignRequestDTO;
import com.viettel.campaign.model.Campaign;
import org.springframework.data.domain.Page;
import com.viettel.campaign.web.dto.ResultDTO;
import java.util.Map;
......
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;
import com.viettel.campaign.web.dto.ResultDTO;
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;
......@@ -24,18 +19,18 @@ import java.util.Map;
@Service
public class CampaignServiceImpl implements CampaignService {
@Autowired(required=true)
@Autowired
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);
List<CampaignDTO> lst = campaignRepository.searchCampaignExecute(agentId, pageable);
List<CampaignDTO> count = campaignRepository.searchCampaignExecute(agentId, null);
result.put("totalItem", lst.size());
result.put("totalItem", count.size());
result.put("data", lst);
return result;
......
package com.viettel.campaign.web.rest.controller;
import com.viettel.campaign.dto.ResultDTO;
import com.viettel.campaign.dto.request_dto.CampaignRequestDTO;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.service.CampaignService;
import com.viettel.campaign.web.dto.ResultDTO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.domain.Page;
import java.util.Map;
......
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