Commit a4fd7a9b authored by Phạm Duy Phi's avatar Phạm Duy Phi

phi pd commit:

- tao CustomerListController, CustomerListMapper, CustomerListRepository, CustomerListService, CustomerListServiceImpl
parent f54e8e0e
......@@ -15,6 +15,7 @@ import java.util.Map;
@Controller
@RequestMapping("/ipcc/customer")
@CrossOrigin("*")
public class CustomerController {
private static final Logger LOGGER = Logger.getLogger(CustomerController.class);
......
package com.viettel.campaign.controller;
import com.viettel.campaign.dto.CustomerListDTO;
import com.viettel.campaign.dto.ResultDTO;
import com.viettel.campaign.service.CustomerListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map;
@Controller
@RequestMapping(path = "/ipcc/customerlist")
@CrossOrigin(origins = "*")
public class CustomerListController {
@Autowired(required=true)
CustomerListService customerListService;
@GetMapping("/findAll")
@ResponseBody
public ResponseEntity findAllCustomerList(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort) {
Map result = customerListService.getCustomerList(page, pageSize, sort);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/create")
@ResponseBody
public ResultDTO createCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO) {
ResultDTO result = new ResultDTO();
//LogUtil logUtil = new LogUtil();
//logUtil.initKpiLog("createCust")
try {
//LOGGER.info("Returning createCustomer: start");
result = customerListService.createCustomerList(customerListDTO);
//LOGGER.info("Returning createCustomer:" + result.getErrorCode());
//logUtil.endKpiLog(customerDTO, 0, result.getErrorCode(), result.getDetail(), CustomerController.class, customerDTO.getAgentProcess(), this.serverPort);
} catch (Exception e) {
result.setErrorCode("-1");
// LOGGER.error(e);
//logUtil.endKpiLog(customerDTO, 1, result.getErrorCode(), e.getMessage(), CustomerController.class, customerDTO.getAgentProcess(), this.serverPort);
}
return result;
// return new ResponseEntity<>("", HttpStatus.OK);
}
@PutMapping("/update")
@ResponseBody
public ResultDTO updateCompleteCode(@RequestBody @Valid CustomerListDTO customerListDTO) {
ResultDTO result = new ResultDTO();
//LogUtil logUtil = new LogUtil();
//logUtil.initKpiLog("createCust");
try {
//LOGGER.info("Returning createCustomer: start");
result = customerListService.updateCustomerList(customerListDTO);
//LOGGER.info("Returning createCustomer:" + result.getErrorCode());
//logUtil.endKpiLog(customerDTO, 0, result.getErrorCode(), result.getDetail(), CustomerController.class, customerDTO.getAgentProcess(), this.serverPort);
} catch (Exception e) {
result.setErrorCode("-1");
// LOGGER.error(e);
//logUtil.endKpiLog(customerDTO, 1, result.getErrorCode(), e.getMessage(), CustomerController.class, customerDTO.getAgentProcess(), this.serverPort);
}
return result;
}
@PostMapping("/delete")
@ResponseBody
public ResultDTO deleteCompleteCode(@RequestBody @Valid CustomerListDTO customerListDTO) {
ResultDTO result = new ResultDTO();
result = customerListService.deleteCustomerList(customerListDTO);
return result;
}
}
......@@ -3,20 +3,22 @@ package com.viettel.campaign.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
public class CustomerListDTO extends BaseDTO {
private String customerListId;
private String customerListPK;
private String customerSiteId;
private long customerListId;
// private String customerListPK;
private long customerSiteId;
private String customerListCode;
private String customerListName;
private String status;
private short status;
private String createBy;
private String createAt;
private Date createAt;
private String updateBy;
private String updateAt;
private Date updateAt;
private String source;
private String deptCreate;
}
package com.viettel.campaign.mapper;
import com.viettel.campaign.dto.CustomerListDTO;
import com.viettel.campaign.model.CustomerList;
public class CustomerListMapper extends BaseMapper<CustomerList, CustomerListDTO> {
@Override
public CustomerListDTO toDtoBean(CustomerList customerList) {
CustomerListDTO obj = new CustomerListDTO();
if (customerList != null) {
obj.setCreateAt(customerList.getCreateAt());
obj.setCreateBy(customerList.getCreateBy());
obj.setCustomerListCode(customerList.getCustomerListCode());
obj.setCustomerListId(customerList.getCustomerListId());
obj.setCustomerSiteId(customerList.getCustomerSiteId());
obj.setCustomerListName(customerList.getCustomerListName());
obj.setDeptCreate(customerList.getDeptCreate());
obj.setSource(customerList.getSource());
obj.setStatus(customerList.getStatus());
obj.setUpdateAt(customerList.getUpdateAt());
obj.setUpdateBy(customerList.getUpdateBy());
}
return obj;
}
@Override
public CustomerList toPersistenceBean(CustomerListDTO dtoBean) {
CustomerList obj = new CustomerList();
if (dtoBean != null) {
obj.setCreateAt(dtoBean.getCreateAt());
obj.setCreateBy(dtoBean.getCreateBy());
obj.setCustomerListCode(dtoBean.getCustomerListCode());
obj.setCustomerListId(dtoBean.getCustomerListId());
obj.setCustomerListName(dtoBean.getCustomerListName());
obj.setCustomerSiteId(dtoBean.getCustomerSiteId());
obj.setDeptCreate(dtoBean.getDeptCreate());
obj.setSource(dtoBean.getSource());
obj.setStatus(dtoBean.getStatus());
obj.setUpdateAt(dtoBean.getUpdateAt());
obj.setUpdateBy(dtoBean.getUpdateBy());
}
return obj;
}
}
package com.viettel.campaign.repository;
import com.viettel.campaign.model.CustomerList;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CustomerListRepository extends JpaRepository<CustomerList, Long> {
CustomerList findCustomerListByCustomerListId(long customerListId);
}
package com.viettel.campaign.service;
import com.viettel.campaign.dto.CustomerListDTO;
import com.viettel.campaign.dto.ResultDTO;
import java.util.Map;
public interface CustomerListService {
Map getCustomerList(int page, int pageSize, String sort);
ResultDTO createCustomerList(CustomerListDTO customerListDTO);
ResultDTO updateCustomerList(CustomerListDTO customerListDTO);
ResultDTO deleteCustomerList(CustomerListDTO customerListDTO);
}
package com.viettel.campaign.service;
import com.viettel.campaign.dto.CustomerListDTO;
import com.viettel.campaign.dto.ResultDTO;
import com.viettel.campaign.mapper.CustomerListMapper;
import com.viettel.campaign.model.CustomerList;
import com.viettel.campaign.repository.CustomerListRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import java.util.*;
@Service
public class CustomerListServiceImpl implements CustomerListService {
@Autowired
EntityManager entityManager;
@Autowired
CustomerListRepository customerListRepository;
@Override
public Map getCustomerList(int page, int pageSize, String sort) {
Map result = new HashMap();
List<CustomerList> list = new ArrayList<>();
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
Page<CustomerList> pc = customerListRepository.findAll(pageable);
result.put("totalItem", pc.getTotalElements());
result.put("customerList", pc.iterator());
return result;
}
@Override
public ResultDTO createCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
Date today = new Date();
CustomerList customerList = new CustomerList();
try {
if (customerListDTO != null) {
// insert
customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerList = customerListRepository.save(customerList);
resultDTO.setErrorCode("0");
resultDTO.setDescription("Customer List: " + customerList.getCustomerListId() + " created!");
} else {
resultDTO.setErrorCode("-2");
resultDTO.setDescription("CustomerListDTO null");
}
} catch (Exception e) {
e.printStackTrace();
}
return resultDTO;
}
@Override
public ResultDTO updateCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
Date today = new Date();
CustomerList customerList = customerListRepository.findCustomerListByCustomerListId(customerListDTO.getCustomerListId());
try {
if (customerListDTO != null) {
// update
customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerList = customerListRepository.save(customerList);
resultDTO.setErrorCode("0");
resultDTO.setDescription("Customer List: " + customerList.getCustomerListId() + " updated!");
} else {
resultDTO.setErrorCode("-2");
resultDTO.setDescription("CustomerListDTO null");
}
} catch (Exception e) {
e.printStackTrace();
}
return resultDTO;
}
@Override
public ResultDTO deleteCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
Date today = new Date();
CustomerList customerList = new CustomerList();
try {
if (customerListDTO != null) {
// delete
customerListRepository.deleteById(customerListDTO.getCustomerListId());
resultDTO.setErrorCode("0");
resultDTO.setDescription("Customer List: " + customerList.getCustomerListId() + " deleted!");
} else {
resultDTO.setErrorCode("-2");
resultDTO.setDescription("CustomerListDTO null");
}
} catch (Exception e) {
e.printStackTrace();
}
return resultDTO;
}
}
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