Commit 4aa07a6e authored by Phạm Duy Phi's avatar Phạm Duy Phi

phi pd commit: viet chuc nang them va xoa nhieu dong

parent 2656eba5
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.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);
}
......@@ -3,6 +3,7 @@ package com.viettel.campaign.service;
import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import java.util.List;
import java.util.Map;
public interface CustomerListService {
......@@ -14,4 +15,6 @@ public interface CustomerListService {
ResultDTO updateCustomerList(CustomerListDTO customerListDTO);
ResultDTO deleteCustomerList(CustomerListDTO customerListDTO);
ResultDTO deleteIds(List<Long> ids);
}
......@@ -3,6 +3,7 @@ package com.viettel.campaign.service;
import com.viettel.campaign.mapper.CustomerListMapper;
import com.viettel.campaign.model.CustomerList;
import com.viettel.campaign.repository.CustomerListRepository;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -49,13 +50,13 @@ public class CustomerListServiceImpl implements CustomerListService {
if (customerListDTO != null) {
// insert
customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerList = customerListRepository.save(customerList);
customerListRepository.save(customerList);
resultDTO.setErrorCode("0");
resultDTO.setDescription("Customer List: " + customerList.getCustomerListId() + " created!");
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode("-2");
resultDTO.setDescription("CustomerListDTO null");
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -77,11 +78,11 @@ public class CustomerListServiceImpl implements CustomerListService {
customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerList = customerListRepository.save(customerList);
resultDTO.setErrorCode("0");
resultDTO.setDescription("Customer List: " + customerList.getCustomerListId() + " updated!");
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode("-2");
resultDTO.setDescription("CustomerListDTO null");
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -102,11 +103,11 @@ public class CustomerListServiceImpl implements CustomerListService {
// delete
customerListRepository.deleteById(customerListDTO.getCustomerListId());
resultDTO.setErrorCode("0");
resultDTO.setDescription("Customer List: " + customerList.getCustomerListId() + " deleted!");
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode("-2");
resultDTO.setDescription("CustomerListDTO null");
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -114,4 +115,22 @@ public class CustomerListServiceImpl implements CustomerListService {
return resultDTO;
}
@Override
public ResultDTO deleteIds(List<Long> ids) {
ResultDTO resultDTO = new ResultDTO();
try {
if (ids != null) {
customerListRepository.deleteIds(ids);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
package com.viettel.campaign.web.rest;
import com.viettel.campaign.model.CustomerList;
import com.viettel.campaign.service.CustomerListService;
import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO;
......@@ -10,6 +11,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Controller
......@@ -73,4 +76,16 @@ public class CustomerListController {
result = customerListService.deleteCustomerList(customerListDTO);
return result;
}
@PostMapping("/ids")
@ResponseBody
public ResultDTO deleteIds(@RequestBody @Valid List<CustomerListDTO> customerListDTOList) {
List<Long> ids = new ArrayList<>();
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