Commit 8fcc4f8f authored by Phạm Duy Phi's avatar Phạm Duy Phi

phi pd commit: check ma danh sach truoc khi them moi

parent 3933b412
...@@ -3,14 +3,19 @@ package com.viettel.campaign.repository; ...@@ -3,14 +3,19 @@ package com.viettel.campaign.repository;
import com.viettel.campaign.model.CustomerList; import com.viettel.campaign.model.CustomerList;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
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;
import java.util.List; import java.util.List;
public interface CustomerListRepository extends JpaRepository<CustomerList, Long> { public interface CustomerListRepository extends JpaRepository<CustomerList, Long> {
CustomerList findCustomerListByCustomerListId(long customerListId); CustomerList findCustomerListByCustomerListId(long customerListId);
@Query("delete from CustomerList c where c.customerListId in :ids") CustomerList findByCustomerListCode(String customerListCode);
ResultDTO deleteIds(@Param("ids") List<Long> ids);
@Modifying
@Query("delete from CustomerList c where c.customerListId in (:ids)")
int deleteIds(@Param("ids") List<Long> ids);
} }
...@@ -61,7 +61,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -61,7 +61,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
item.setContent((String) obj[2]); item.setContent((String) obj[2]);
item.setStartTime((Date) obj[3]); item.setStartTime((Date) obj[3]);
item.setEndTime((Date) obj[4]); item.setEndTime((Date) obj[4]);
item.setStatus((BigDecimal) obj[5]); item.setStatus((Short) obj[5]);
lst.add(item); lst.add(item);
} }
......
...@@ -12,6 +12,7 @@ import org.springframework.data.domain.PageRequest; ...@@ -12,6 +12,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
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 javax.persistence.EntityManager; import javax.persistence.EntityManager;
import java.util.*; import java.util.*;
...@@ -49,11 +50,17 @@ public class CustomerListServiceImpl implements CustomerListService { ...@@ -49,11 +50,17 @@ public class CustomerListServiceImpl implements CustomerListService {
try { try {
if (customerListDTO != null) { if (customerListDTO != null) {
// insert // insert
customerList = customerListMapper.toPersistenceBean(customerListDTO); CustomerList findCustomer = customerListRepository.findByCustomerListCode(customerListDTO.getCustomerListCode());
customerListRepository.save(customerList); if (findCustomer == null) {
customerList = customerListMapper.toPersistenceBean(customerListDTO);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); customerListRepository.save(customerList);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
...@@ -116,6 +123,7 @@ public class CustomerListServiceImpl implements CustomerListService { ...@@ -116,6 +123,7 @@ public class CustomerListServiceImpl implements CustomerListService {
return resultDTO; return resultDTO;
} }
@Transactional
@Override @Override
public ResultDTO deleteIds(List<Long> ids) { public ResultDTO deleteIds(List<Long> ids) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
...@@ -131,6 +139,6 @@ public class CustomerListServiceImpl implements CustomerListService { ...@@ -131,6 +139,6 @@ public class CustomerListServiceImpl implements CustomerListService {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return resultDTO;
} }
} }
...@@ -79,12 +79,8 @@ public class CustomerListController { ...@@ -79,12 +79,8 @@ public class CustomerListController {
@PostMapping("/ids") @PostMapping("/ids")
@ResponseBody @ResponseBody
public ResultDTO deleteIds(@RequestBody @Valid List<CustomerListDTO> customerListDTOList) { public ResultDTO deleteIds(@RequestBody @Valid List<Long> ids) {
List<Long> ids = new ArrayList<>();
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
for (CustomerListDTO customerList: customerListDTOList) {
ids.add(customerList.getCustomerListId());
}
result = customerListService.deleteIds(ids); result = customerListService.deleteIds(ids);
return result; return result;
} }
......
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