Commit bfee1df5 authored by renjie's avatar renjie

购买ip返送

parent b0e8a610
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
......@@ -8,13 +9,14 @@ import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -45,8 +47,30 @@ public class ShopController {
}
@RequestMapping(value = "/multiadd", method = RequestMethod.POST)
public List<String> addShops(Principal principal, @RequestBody List<Shop> shops) {
public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto();
String name=file.getOriginalFilename();
if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", BrowserErrorCode.INFORMATIONNOTCOMPELETE.getCode());
statusInfo.put("message", "文件格式错误");
resultDto.setStatusInfo(statusInfo);
}
try {
shopService.addShops(principal.getName(), file);
} catch (ClientRequestException | IOException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 40102);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return null;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
......
......@@ -137,6 +137,10 @@ public class IpResourceServiceImpl implements IpResourceService {
HashMap<String, Object> map = new HashMap<>();
map.put("name", ipResourceRequestDto.getName());
map.put("region", ipResourceRequestDto.getRegion());
if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 6)
ipResourceRequestDto.setPeriod(7);
else if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 12)
ipResourceRequestDto.setPeriod(14);
map.put("period", String.valueOf(ipResourceRequestDto.getPeriod()));
map.put("provider", ipResourceRequestDto.getVendor());
map.put("unit", ipResourceRequestDto.getUnit());
......@@ -229,6 +233,10 @@ public class IpResourceServiceImpl implements IpResourceService {
RestTemplate restTemplate = new RestTemplate();
HashMap<String, Object> map = new HashMap<>();
map.put("iplist", ipResourceRequestDto.getAddr());
if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 6)
ipResourceRequestDto.setPeriod(7);
else if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 12)
ipResourceRequestDto.setPeriod(14);
map.put("period", ipResourceRequestDto.getPeriod());
HttpHeaders headers = buildPostHeader();
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(map, headers);
......
......@@ -28,7 +28,9 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -98,8 +100,8 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public List<String> addShops(String username, List<Shop> shops) {
Workbook workbook = FileUtil.readExcel("");
public List<String> addShops(String username, MultipartFile file) throws IOException {
List<Object> list = FileUtil.readExcel(file.getInputStream());
return null;
}
......
......@@ -5,14 +5,16 @@ import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface ShopService {
String addShop(String useranme, ShopResultDto shopResultDto);
List<String> addShops(String username, List<Shop> shops);
List<String> addShops(String username, MultipartFile file) throws IOException;
String updateShop(String username, ShopResultDto shopResultDto);
......
package com.edgec.browserbackend.common.utils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -68,29 +67,38 @@ public class FileUtil {
}
//读取excel
public static Workbook readExcel(String filePath){
Workbook wb = null;
if(filePath==null){
return null;
}
String extString = filePath.substring(filePath.lastIndexOf("."));
InputStream is = null;
public static List<Object> readExcel(InputStream inputStream){
List<Object> list = new ArrayList<>();
Workbook workbook = null;
try {
is = new FileInputStream(filePath);
if(".xls".equals(extString)){
return wb = new HSSFWorkbook(is);
}else if(".xlsx".equals(extString)){
return wb = new XSSFWorkbook(is);
}else{
return wb = null;
}
workbook = WorkbookFactory.create(inputStream);
inputStream.close();
//工作表对象
Sheet sheet = workbook.getSheetAt(0);
//总行数
int rowLength = sheet.getLastRowNum() -1;
//工作表的列
Row row = sheet.getRow(0);
//总列数
int colLength = row.getLastCellNum();
//得到指定的单元格
Cell cell = row.getCell(0);
for (int i = 2; i < rowLength; i++) {
row = sheet.getRow(i);
for (int j = 0; j < colLength; j++) {
cell = row.getCell(j);
// System.out.println(cell);
if (cell != null) {
String cellValue = cell.getRichStringCellValue().getString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
log.error("parse excel file error :", e);
}
return wb;
return list ;
}
public static Object getCellFormatValue(Cell cell){
......
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