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