Commit 8740b74e authored by Phạm Duy Phi's avatar Phạm Duy Phi
parents 5dad221c e5740e4c
package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignCfg;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -9,13 +8,13 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
@Transactional(DataSourceQualify.CCMS_FULL)
public interface CampaignCfgRepository extends JpaRepository<CampaignCfg, Long> {
@Query("select c from CampaignCfg c where c.campaignCompleteCodeId in (:p_ids) and c.companySiteId=:p_company_site_id and c.status = 1")
List<CampaignCfg> findAllCampaignCfg(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
@Query("FROM CampaignCfg u WHERE u.status = 1 AND u.completeValue NOT IN (1,2,3,4)")
Page<CampaignCfg> findAll(Pageable pageable);
......
......@@ -536,22 +536,22 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>();
List<FieldsToShowDTO> list = new ArrayList<>();
StringBuilder stringBuilder = new StringBuilder();
StringBuilder sb = new StringBuilder();
try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-not-show");
String sql = "with column_name_temp as (\n" +
" select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual\n" +
" where table_name = 'CUSTOMER'\n" +
")\n" +
"select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)\n" +
"union all\n" +
"select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual\n" +
"where function_code = 'CUSTOMER'\n" +
" and site_id = :p_company_site_id\n" +
" and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id)\n";
sb.append(" with column_name_temp as (");
sb.append(" select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual");
sb.append(" where table_name = 'CUSTOMER'");
sb.append(" )");
sb.append(" select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)");
sb.append(" union all");
sb.append(" select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual");
sb.append(" where function_code = 'CUSTOMER'");
sb.append(" and site_id = :p_company_site_id");
sb.append(" and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id)");
params.put("p_company_site_id", dto.getCompanySiteId());
params.put("p_campaign_id", dto.getCampaignId());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(list);
......@@ -569,25 +569,25 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>();
List<FieldsToShowDTO> list = new ArrayList<>();
StringBuilder sqlBuilder = new StringBuilder();
StringBuilder sb = new StringBuilder();
try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-to-show");
String sql = "with field_name as (\n" +
"select a.campaign_cus_list_column_id id, to_char(a.column_name) columnName, a.order_index, a.customize_field_id customizeFieldId, 1 isFix\n" +
"from campaign_customerlist_column a, dual\n" +
"where a.campaign_id = :p_campaign_id\n" +
" and a.company_site_id = :p_company_site_id\n" +
" and column_name is not null\n" +
"union all\n" +
"select a.campaign_cus_list_column_id id, a.customize_field_title columnName, a.order_index, a.customize_field_id customizeFieldId, 0 isFix\n" +
"from campaign_customerlist_column a\n" +
"where a.campaign_id = :p_campaign_id\n" +
" and a.company_site_id = :p_company_site_id\n" +
")\n" +
"select id, columnName, customizeFieldId, isFix from field_name where columnName is not null order by order_index\n";
sb.append(" with field_name as (");
sb.append(" select a.campaign_cus_list_column_id id, to_char(a.column_name) columnName, a.order_index, a.customize_field_id customizeFieldId, 1 isFix");
sb.append(" from campaign_customerlist_column a, dual");
sb.append(" where a.campaign_id = :p_campaign_id");
sb.append(" and a.company_site_id = :p_company_site_id");
sb.append(" and column_name is not null");
sb.append(" union all");
sb.append(" select a.campaign_cus_list_column_id id, a.customize_field_title columnName, a.order_index, a.customize_field_id customizeFieldId, 0 isFix");
sb.append(" from campaign_customerlist_column a");
sb.append(" where a.campaign_id = :p_campaign_id");
sb.append(" and a.company_site_id = :p_company_site_id");
sb.append(" )");
sb.append(" select id, columnName, customizeFieldId, isFix from field_name where columnName is not null order by order_index");
params.put("p_campaign_id", dto.getCampaignId());
params.put("p_company_site_id", dto.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(list);
......
......@@ -268,6 +268,7 @@ public class CampaignCfgServiceImpl implements CampaignCfgService {
ResultDTO resultDTO = new ResultDTO();
try {
if (completeCodeDTO != null) {
if (completeCodeRepository.findAllCampaignCfg(completeCodeDTO.getListId(), completeCodeDTO.getCompanySiteId()).size() > 0) {
completeCodeRepository.deletedList(completeCodeDTO.getListId(), completeCodeDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
......@@ -276,6 +277,11 @@ public class CampaignCfgServiceImpl implements CampaignCfgService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) {
// e.printStackTrace();
}
......
......@@ -10,4 +10,5 @@ public class CampaignCfgRequestDTO {
List<Long> listId;
Long companySiteId;
Long campaignCompleteCodeID;
String completeValue;
}
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