Commit 0cad1285 authored by đinh thị đầm's avatar đinh thị đầm

sql-query

parent d04f3bdb
This diff is collapsed.
...@@ -15,4 +15,9 @@ public interface ApParamRepository extends JpaRepository<ApParam, Long>, ApParam ...@@ -15,4 +15,9 @@ public interface ApParamRepository extends JpaRepository<ApParam, Long>, ApParam
@Query(value = "SELECT p FROM ApParam p WHERE parName LIKE concat('%', :parName, '%') ") @Query(value = "SELECT p FROM ApParam p WHERE parName LIKE concat('%', :parName, '%') ")
List<ApParam> findParamByName(@Param("parName") String parName, Pageable pageable); List<ApParam> findParamByName(@Param("parName") String parName, Pageable pageable);
@Query(value = "select a from ApParam a WHERE status = 1 AND parType = 'CAMPAIGN_TYPE'")
List<ApParam> findAllParam();
} }
...@@ -4,6 +4,7 @@ import com.viettel.campaign.model.CampaignCompleteCode; ...@@ -4,6 +4,7 @@ import com.viettel.campaign.model.CampaignCompleteCode;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
...@@ -14,7 +15,13 @@ public interface CampaignCompleteCodeRepository extends JpaRepository<CampaignCo ...@@ -14,7 +15,13 @@ public interface CampaignCompleteCodeRepository extends JpaRepository<CampaignCo
Page<CampaignCompleteCode> findAll(Pageable pageable); Page<CampaignCompleteCode> findAll(Pageable pageable);
@Query("FROM CampaignCompleteCode WHERE completeName LIKE concat('%', :name, '%') ") @Query("FROM CampaignCompleteCode WHERE completeName LIKE concat('%', :name, '%') ")
List<CampaignCompleteCode> findByName(@Param("name") String Name, Pageable pageable); List<CampaignCompleteCode> findByName(@Param("name") String name, Pageable pageable);
List<CampaignCompleteCode> findByCompleteNameContains(String name, Pageable pageable);
@Modifying
@Query("delete from CampaignCompleteCode c where c.campaignCompleteCodeId in (:ids)")
int deleteds(@Param("ids") List<Long> ids);
List<CampaignCompleteCode> findByCompleteNameContains(String Name, Pageable pageable);
} }
...@@ -40,7 +40,6 @@ public class CampaignCompleteCodeRepositoryIpml implements CampaignCompleteCodeR ...@@ -40,7 +40,6 @@ public class CampaignCompleteCodeRepositoryIpml implements CampaignCompleteCodeR
@Override @Override
public List<CampaignCompleteCode> findByName(String name, Pageable pageable) { public List<CampaignCompleteCode> findByName(String name, Pageable pageable) {
// return campaignCompleteCodeRepository.findByName(name , pageable);
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession(); Session session = sessionFactory.openSession();
...@@ -49,11 +48,11 @@ public class CampaignCompleteCodeRepositoryIpml implements CampaignCompleteCodeR ...@@ -49,11 +48,11 @@ public class CampaignCompleteCodeRepositoryIpml implements CampaignCompleteCodeR
List<CampaignCompleteCode> resultList = null; List<CampaignCompleteCode> resultList = null;
try { try {
StringBuilder sql = new StringBuilder(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_STATUS_MNG, "search-campaign-status-by-params")); StringBuilder sql = new StringBuilder(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_STATUS_MNG, "search-campaign-status-by-params"));
SQLQuery query = session.createSQLQuery(sql.toString()); SQLQuery query = session.createSQLQuery(sql.toString());
query.setParameter(":p_name", name); query.setParameter(":p_name", name);
// add SCalar // add SCalar
query.addScalar("campaignId", new LongType()); query.addScalar("campaignId", new LongType());
query.addScalar("completeValue", new StringType()); query.addScalar("completeValue", new StringType());
...@@ -76,10 +75,13 @@ public class CampaignCompleteCodeRepositoryIpml implements CampaignCompleteCodeR ...@@ -76,10 +75,13 @@ public class CampaignCompleteCodeRepositoryIpml implements CampaignCompleteCodeR
} }
@Override @Override
public List<CampaignCompleteCode> findByCompleteNameContains(String Name, Pageable pageable) { public List<CampaignCompleteCode> findByCompleteNameContains(String name, Pageable pageable) {
// List<CampaignCompleteCodeDTO> lst = new ArrayList<>(); return campaignCompleteCodeRepository.findByCompleteNameContains(name,pageable);
// return lst; }
return null;
@Override
public int deleteds(List<Long> ids) {
return 0;
} }
@Override @Override
......
...@@ -13,4 +13,9 @@ public interface ApParamService { ...@@ -13,4 +13,9 @@ public interface ApParamService {
List<ApParam> getParamByName(int page, int pageSize, String sort, String parName); List<ApParam> getParamByName(int page, int pageSize, String sort, String parName);
ResultDTO createApParam(ApParamDTO apParamDTO); ResultDTO createApParam(ApParamDTO apParamDTO);
List<ApParam>findAllParam();
} }
...@@ -33,6 +33,7 @@ public class ApParamServiceImpl implements ApParamService { ...@@ -33,6 +33,7 @@ public class ApParamServiceImpl implements ApParamService {
return lst; return lst;
} }
@Override @Override
public ResultDTO createApParam(ApParamDTO apParamDTO) { public ResultDTO createApParam(ApParamDTO apParamDTO) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
...@@ -57,4 +58,9 @@ public class ApParamServiceImpl implements ApParamService { ...@@ -57,4 +58,9 @@ public class ApParamServiceImpl implements ApParamService {
return null; return null;
} }
@Override
public List<ApParam> findAllParam() {
return apParamRepository.findAllParam();
}
} }
...@@ -3,6 +3,7 @@ package com.viettel.campaign.service; ...@@ -3,6 +3,7 @@ package com.viettel.campaign.service;
import com.viettel.campaign.web.dto.CampaignCompleteCodeDTO; import com.viettel.campaign.web.dto.CampaignCompleteCodeDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface CampaignCompleteCodeService { public interface CampaignCompleteCodeService {
...@@ -16,4 +17,7 @@ public interface CampaignCompleteCodeService { ...@@ -16,4 +17,7 @@ public interface CampaignCompleteCodeService {
ResultDTO updateCompleteCode(CampaignCompleteCodeDTO completeCodeDTO); ResultDTO updateCompleteCode(CampaignCompleteCodeDTO completeCodeDTO);
ResultDTO deleteCompleteCode(CampaignCompleteCodeDTO completeCodeDTO); ResultDTO deleteCompleteCode(CampaignCompleteCodeDTO completeCodeDTO);
ResultDTO deleteList(List<Long> completeCodeDtos);
} }
package com.viettel.campaign.service; package com.viettel.campaign.service;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.web.dto.CampaignCompleteCodeDTO; import com.viettel.campaign.web.dto.CampaignCompleteCodeDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.mapper.CampaignCompleteCodeMapper; import com.viettel.campaign.mapper.CampaignCompleteCodeMapper;
import com.viettel.campaign.model.CampaignCompleteCode; import com.viettel.campaign.model.CampaignCompleteCode;
import com.viettel.campaign.repository.CampaignCompleteCodeRepository; import com.viettel.campaign.repository.CampaignCompleteCodeRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
import java.util.*; import java.util.*;
@Service @Service
@ComponentScan
public class CampaignCompleteCodeServiceImpl implements CampaignCompleteCodeService { public class CampaignCompleteCodeServiceImpl implements CampaignCompleteCodeService {
@Autowired @Autowired
CampaignCompleteCodeRepository completeCodeRepository; CampaignCompleteCodeRepository completeCodeRepository;
private Logger log = LoggerFactory.getLogger(CampaignCompleteCodeServiceImpl.class);
@Override @Override
public Map listAllCompleteCode(int page, int pageSize, String sort) { public Map listAllCompleteCode(int page, int pageSize, String sort) {
Map result = new HashMap(); Map result = new HashMap();
...@@ -117,6 +127,27 @@ public class CampaignCompleteCodeServiceImpl implements CampaignCompleteCodeServ ...@@ -117,6 +127,27 @@ public class CampaignCompleteCodeServiceImpl implements CampaignCompleteCodeServ
e.printStackTrace(); e.printStackTrace();
} }
return resultDTO;
}
@Transactional
@Override
public ResultDTO deleteList(List<Long> completeCodeDtos) {
ResultDTO resultDTO = new ResultDTO();
// for (int i = 0; i < completeCodeDtos.size(); i++) {
try {
completeCodeRepository.deleteds(completeCodeDtos);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
log.error(e.getMessage(), e);
resultDTO.setErrorCode("-1");
return resultDTO;
}
// }
resultDTO.setErrorCode("0");
return resultDTO; return resultDTO;
} }
} }
...@@ -13,6 +13,7 @@ import java.util.List; ...@@ -13,6 +13,7 @@ import java.util.List;
@Controller @Controller
@RequestMapping("/ipcc/apParam") @RequestMapping("/ipcc/apParam")
@CrossOrigin(origins = "*")
public class ApParamController { public class ApParamController {
private static final Logger LOGGER = Logger.getLogger(CustomerController.class); private static final Logger LOGGER = Logger.getLogger(CustomerController.class);
...@@ -39,4 +40,13 @@ public class ApParamController { ...@@ -39,4 +40,13 @@ public class ApParamController {
return new ResponseEntity(lst, HttpStatus.OK); return new ResponseEntity(lst, HttpStatus.OK);
} }
@GetMapping(path = "/findAllParam")
@ResponseBody
public ResponseEntity findAllParam(){
List<ApParam> findAll = apParamService.findAllParam();
if(findAll.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity(findAll, HttpStatus.OK);
}
} }
...@@ -11,6 +11,7 @@ import org.springframework.stereotype.Controller; ...@@ -11,6 +11,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
...@@ -81,4 +82,11 @@ public class CampaignCompleteCodeController { ...@@ -81,4 +82,11 @@ public class CampaignCompleteCodeController {
result = completeCodeService.deleteCompleteCode(completeCodeDTO); result = completeCodeService.deleteCompleteCode(completeCodeDTO);
return result; return result;
} }
@PostMapping("/listDelete")
@ResponseBody
public ResponseEntity<ResultDTO> deleteList(@RequestBody @Valid List<Long>completeCodeDtos ){
ResultDTO resultDTO = completeCodeService.deleteList(completeCodeDtos);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
} }
SELECT PAR_NAME,AP_PARAM_ID, PAR_TYPE FROM AP_PARAM a WHERE STATUS= 1 AND PAR_TYPE = 'CAMPAIGN_TYPE'
DELETE FROM CAMPAIGN_COMPLETE_CODE WHERE CAMPAIGN_ID IN (0,1)
select *from CAMPAIGN_COMPLETE_CODE
SELECT
a.CAMPAIGN_ID campaignId,
a.COMPLETE_VALUE completeValue,
a.COMPLETE_NAME completeName,
a.COMPLETE_TYPE completeType,
-- a.CAMPAIGN_TYPE campaignType,
c.PAR_NAME campaignType,
b.CHANEL chanel,
a.DESCRIPTION description,
a.STATUS status
FROM CAMPAIGN_COMPLETE_CODE a
LEFT JOIN CAMPAIGN b ON a.CAMPAIGN_ID = b.CAMPAIGN_ID
LEFT JOIN AP_PARAM c ON a.CAMPAIGN_TYPE = to_char(c.AP_PARAM_ID)
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