Commit 89b8756b authored by Vu Duy Anh's avatar Vu Duy Anh

anhvd commit

parents 69d7839d 013f9821
......@@ -189,6 +189,18 @@
<artifactId>modelmapper</artifactId>
<version>2.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
</dependencies>
<dependencyManagement>
......
package com.viettel.campaign.repository;
import com.viettel.campaign.model.Campaign;
import com.viettel.campaign.web.dto.CampaignDTO;
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;
......@@ -16,4 +18,6 @@ public interface CampaignRepository extends JpaRepository<Campaign, Long>, Campa
" AND cc.recallTime <= sysdate " +
" AND cc.agentId = :pAgentId")
Long countRecallCustomer(@Param("pCompanySiteId") Long pCompanySiteId, @Param("pAgentId") Long pAgentId);
Campaign findCampaignByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);
}
......@@ -18,4 +18,6 @@ public interface CampaignService {
Map countRecallCustomer(Long companySiteId, Long agentId);
ResultDTO findCampaignById(Long campaignId);
ResultDTO changeCampaignStatus(CampaignDTO dto);
}
......@@ -126,7 +126,7 @@ public class CampaignServiceImpl implements CampaignService {
ResultDTO resultDTO = new ResultDTO();
try {
Campaign campaign = campaignRepository.findById(campaignId).orElse(null);
if(campaign != null) {
if (campaign != null) {
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(campaign);
......@@ -139,6 +139,31 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO;
}
@Override
public ResultDTO changeCampaignStatus(CampaignDTO dto) {
ResultDTO result = new ResultDTO();
try {
Campaign entity = campaignRepository.findCampaignByCampaignIdAndCompanySiteId(dto.getCampaignId(), dto.getCompanySiteId());
if (entity != null) {
entity.setStatus(dto.getStatus().longValue());
entity.setUpdateTime(new Date());
entity.setUpdateBy(dto.getUpdateBy());
campaignRepository.save(entity);
result.setData(entity);
result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
} else {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription("Entity not found");
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(e.getMessage());
}
return result;
}
private String generateCampaignCode(String campaignType, Short chanel) {
int year = Calendar.getInstance().get(Calendar.YEAR);
String maxIndexStr = campaignRepository.getMaxCampaignIndex();
......
......@@ -64,10 +64,17 @@ public class CampaignController {
return new ResponseEntity<>(result, HttpStatus.OK);
}
<<<<<<< HEAD
@RequestMapping(value = "/find-campaign-by-id/{campaignId}", method = RequestMethod.GET)
public ResponseEntity<ResultDTO> findCampaignById(@PathVariable Long campaignId) {
ResultDTO resultDTO = campaignService.findCampaignById(campaignId);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
=======
@PostMapping("/changeCampaignStatus")
public ResultDTO changeCampaignStatus(@RequestBody CampaignDTO dto) {
return campaignService.changeCampaignStatus(dto);
}
>>>>>>> 013f98210fde3ae2b1cbd585f96db122812c2a8b
}
......@@ -7,13 +7,24 @@ import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import org.apache.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.Valid;
import java.io.File;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Controller
......@@ -159,4 +170,60 @@ public class CustomerController {
ResultDTO result = customerService.getCustomerContact(customerId, contactType, contact);
return new ResponseEntity(result, HttpStatus.OK);
}
@GetMapping(value = "/downloadFileTemplate")
public ResponseEntity<byte[]> downloadFileTemplate() {
LOGGER.debug("--------DOWNLOAD FILE TEMPLATE---------");
try {
File file = ResourceUtils.getFile("classpath:templates/test_download.xlsx");
byte[] content = Files.readAllBytes(file.toPath());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(content);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
@PostMapping(value = "/importFile")
public ResponseEntity<byte[]> importFile(@RequestParam("file") MultipartFile file) {
LOGGER.debug("--------IMPORT FILE TEMPLATE---------");
try {
List<CustomerDTO> listCustomer = new ArrayList<>();
XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream());
XSSFSheet sheet = workbook.getSheetAt(0);
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
CustomerDTO customer = new CustomerDTO();
XSSFRow row = sheet.getRow(i);
customer.setCustomerId(Double.valueOf(row.getCell(0).getNumericCellValue()).longValue());
customer.setCreateDate(row.getCell(1).getDateCellValue());
customer.setName(row.getCell(2).getStringCellValue());
listCustomer.add(customer);
}
// for (int i = 0; i < listCustomer.size(); i++) {
// validate du lieu
// }
// if (okay) {
// for (int i = 0; i < listCustomer.size(); i++) {
// customerService.createCustomer(listCustomer.get(i));
// }
// return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
// .contentType(MediaType.APPLICATION_OCTET_STREAM)
// .body(file.getBytes());
// } else {
// return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
// .header("Message", "Validate failed!")
// .contentType(MediaType.APPLICATION_OCTET_STREAM)
// .body(file.getBytes());
// }
return null;
} catch (Exception e) {
LOGGER.error(e.getMessage());
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
}
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