Commit 5036f086 authored by renjie's avatar renjie
parents 1a0b79dc 20eb3f2a
......@@ -169,6 +169,17 @@ public class PaymentServiceImpl implements PaymentService {
userPrePaidBillingRepository.save(bill);
if (more != 20 && more != 45 && more != 125 && more != 300)
more = 0;
if ((more == 20 && byTradeNo.getAmount() != 100) || (more != 20 && byTradeNo.getAmount() == 100))
more = 0;
if ((more == 45 && byTradeNo.getAmount() != 200) || (more != 45 && byTradeNo.getAmount() == 200))
more = 0;
if ((more == 125 && byTradeNo.getAmount() != 500) || (more != 125 && byTradeNo.getAmount() == 500))
more = 0;
if ((more == 300 && byTradeNo.getAmount() != 1000) || (more != 300 && byTradeNo.getAmount() == 1000))
more = 0;
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + more);
userBalanceRepository.save(balance);
}
......@@ -272,7 +283,7 @@ public class PaymentServiceImpl implements PaymentService {
bill.setMonth(monthValue);
if (more != 20 || more != 45 || more != 125 || more != 300)
if (more != 20 && more != 45 && more != 125 && more != 300)
more = 0;
if ((more == 20 && byTradeNo.getAmount() != 100) || (more != 20 && byTradeNo.getAmount() == 100))
more = 0;
......
......@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp", "/shop/multiadd",
.antMatchers( "/user/authCode", "/user/signUp",
"/user/reset*");
}
......
package com.edgec.browserbackend.browser.ErrorCode;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.fasterxml.jackson.annotation.JsonValue;
......@@ -14,7 +15,9 @@ public enum BrowserErrorCode implements ErrorCode {
IPNOTEXIST(BROWSER_BASE+201, "The ip do not exist"),
IPNOTBINDTOSHOP(BROWSER_BASE+202, "The ip do not bind this shop."),
GROUPNOTEXIST(BROWSER_BASE+301, "The group do not exist");
GROUPNOTEXIST(BROWSER_BASE+301, "The group do not exist"),
IPTRANSACTIONNOTEXIST(BROWSER_BASE+401, "The ipTransaction do not exist");
......
......@@ -26,7 +26,7 @@ public class IpControlloer {
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){
ResultDto resultDto = new ResultDto();
try {
List<IpResourceDto> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
IpTransactionDto ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
......@@ -100,4 +100,22 @@ public class IpControlloer {
}
return resultDto;
}
@RequestMapping(value = "/queryTransaction", method = RequestMethod.POST)
public ResultDto queryTransaction(Principal principal, @RequestBody IpTransactionDto ipTransactionDto) {
ResultDto resultDto = new ResultDto();
try {
IpTransactionDto ipTransactionDto1 = ipResourceService.queryTransaction(principal.getName(), ipTransactionDto.getTid());
resultDto.setData(ipTransactionDto1);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
}
......@@ -10,6 +10,8 @@ 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -25,6 +27,8 @@ import java.util.Map;
@RequestMapping("/shop")
public class ShopController {
private final Logger logger = LoggerFactory.getLogger(ShopController.class);
@Autowired
private ShopService shopService;
......@@ -47,8 +51,7 @@ public class ShopController {
}
@RequestMapping(value = "/multiadd", method = RequestMethod.POST)
@ResponseBody
public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) {
public ResultDto 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")){
......@@ -60,6 +63,7 @@ public class ShopController {
}
try {
shopService.addShops(principal.getName(), file);
resultDto.setStatus(0);
} catch (ClientRequestException | IOException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......@@ -69,7 +73,7 @@ public class ShopController {
}
return null;
return resultDto;
}
......
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/18 9:42 上午
**/
@Document("iptransaction")
public class IpTransaction {
@Id
private String tid;
private String username;
private long createTime;
private int status;
private List<String> ipIds;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getTid() {
return tid;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
public long getCreateTime() {
return createTime;
}
public void setTid(String tid) {
this.tid = tid;
}
public List<String> getIpIds() {
return ipIds;
}
public void setIpIds(List<String> ipIds) {
this.ipIds = ipIds;
}
}
package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/18 9:57 上午
**/
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpTransactionDto {
private String tid;
private int status;
private List<IpResourceDto> ipResourceDtos;
public IpTransactionDto(){
}
public IpTransactionDto(IpTransaction ipTransaction) {
this.tid = ipTransaction.getTid();
this.status = ipTransaction.getStatus();
ipResourceDtos = new ArrayList<>();
}
public String getTid() {
return tid;
}
public void setTid(String tid) {
this.tid = tid;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public List<IpResourceDto> getIpResourceDtos() {
return ipResourceDtos;
}
public void setIpResourceDtos(List<IpResourceDto> ipResourceDtos) {
this.ipResourceDtos = ipResourceDtos;
}
}
......@@ -7,6 +7,7 @@ public class ShopFilterDto {
private String shopName;
private String IpRegion;
private String shopAccount;
private int bindIp;
public String getShopAccount() {
return shopAccount;
......@@ -31,4 +32,12 @@ public class ShopFilterDto {
public void setShopName(String shopName) {
this.shopName = shopName;
}
public int getBindIp() {
return bindIp;
}
public void setBindIp(int bindIp) {
this.bindIp = bindIp;
}
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/18 5:21 下午
**/
public interface IpTransactionRepository extends MongoRepository<IpTransaction, String> {
}
......@@ -7,9 +7,12 @@ import java.util.List;
public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom {
List<UserShop> findByUsername(String username);
List<UserShop> findByUsernameAndIpIdIsNull(String username);
UserShop findByUsernameAndShopId(String username, String shopId);
UserShop findByShopId(String shopId);
List<UserShop> findByUsernameAndGroupId(String username, String groupId);
List<UserShop> findByUsernameAndGroupIdAndIpIdIsNull(String username, String groupId);
List<UserShop> findByUsernameAndGroupIdAndIpIdIsNotNull(String username, String groupId);
List<UserShop> findByUsernameAndShopIdIn(String username, List<String> shopIds);
List<UserShop> findByUsernameAndIpIdIsNotNull(String username);
int countByUsernameAndIpIdIsNull(String username);
......
......@@ -5,8 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.IpChargeRequestDto;
import com.edgec.browserbackend.account.domain.IpChargeResultDto;
import com.edgec.browserbackend.account.dto.CvmChargeRegion;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.service.AccountService;
......@@ -16,31 +14,26 @@ import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.*;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.edgec.browserbackend.common.dto.Result;
import com.edgec.browserbackend.common.utils.FileUtil;
import com.edgec.browserbackend.common.utils.ThreadPoolUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.swing.text.Document;
import java.io.File;
import java.text.MessageFormat;
import java.time.Instant;
import java.util.*;
import java.util.regex.Pattern;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Service
......@@ -82,6 +75,9 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private PlatformOptionsRepository platformOptionsRepository;
@Autowired
private IpTransactionRepository ipTransactionRepository;
public HttpHeaders buildPostHeader() {
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
......@@ -158,7 +154,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
@Override
public List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
public IpTransactionDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username);
if (account == null)
......@@ -173,13 +169,59 @@ public class IpResourceServiceImpl implements IpResourceService {
String price = vendorPrices.stream()
.filter(x -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(x.substring(0, x.indexOf("-"))))
.map(x -> x.substring(x.lastIndexOf("-") + 1)).collect(Collectors.joining());
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, Double.valueOf(price));
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, Double.valueOf(price) * ipResourceRequestDto.getAmount());
if (!ipChargeResultDto.isSuccess()) {
throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE);
}
String password;
if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword()))
password = ipResourceRequestDto.getPassword();
else
password = genRandom(3, 12);
IpTransaction ipTransaction = new IpTransaction();
ipTransaction.setCreateTime(Instant.now().toEpochMilli());
ipTransaction.setUsername(username);
ipTransaction.setStatus(0);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> ipIds = new ArrayList<>();
for (int i = 0; i < ipResourceRequestDto.getAmount(); i++) {
IpResource ipResource = new IpResource();
ipResource.setAddr("");
ipResource.setIpType(IpType.VENDOR);
ipResource.setPurchasedTime(Instant.now().toEpochMilli());
ipResource.setValidTime(Instant.now().toEpochMilli());
ipResource.setPort(port);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
ipResource.setStatus(0);
ipResource.setUsername(USERNAME);
if (account.getParent() != null)
ipResource.setUserParent(account.getParent());
ipResource.setRegion(ipResourceRequestDto.getRegion());
ipResource.setRegionCn(ipResourceRequestDto.getRegionCn());
ipResource.setProtocol(protocol);
ipResource.setPassword(password);
ipResource.setOwner(username);
IpResource ipResource1 = ipResourceRepository.save(ipResource);
ipResourceDtos.add(new IpResourceDto(ipResource1, null));
ipIds.add(ipResource1.getId());
}
ipTransaction.setIpIds(ipIds);
ipTransactionRepository.save(ipTransaction);
IpTransactionDto ipTransactionDto = new IpTransactionDto(ipTransaction);
ipTransactionDto.setIpResourceDtos(ipResourceDtos);
CompletableFuture.runAsync(() -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
RestTemplate restTemplate = new RestTemplate();
HttpHeaders header = buildPostHeader();
HashMap<String, Object> map = new HashMap<>();
......@@ -193,11 +235,6 @@ public class IpResourceServiceImpl implements IpResourceService {
map.put("provider", ipResourceRequestDto.getVendor());
map.put("unit", ipResourceRequestDto.getUnit());
map.put("amount", String.valueOf(ipResourceRequestDto.getAmount()));
String password;
if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword()))
password = ipResourceRequestDto.getPassword();
else
password = genRandom(3, 12);
map.put("loginPassword", password);
map.put("startscript", startscript);
map.put("ipkeptperiod", ipResourceRequestDto.getIpkeptperiod());
......@@ -205,58 +242,41 @@ public class IpResourceServiceImpl implements IpResourceService {
IpBuyResultDto ipBuyResultDto = null;
try {
ipBuyResultDto = restTemplate.postForObject(URL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class);
if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode()))
throw new Exception(ipBuyResultDto.getErrorCode());
} catch (Throwable e) {
logger.error("fail to post request", e.getMessage());
logger.error(e.getMessage());
throw e;
if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode())) {
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1);
accountService.chargeByMoney(username, -Double.valueOf(price)*ipChargeRequestDto.getAmount(), ipChargeRequestDto);
logger.error("fail to buy ip");
logger.error(ipBuyResultDto.getErrorCode());
}
try {
if (ipBuyResultDto != null && ipBuyResultDto.getIplist() != null && ipBuyResultDto.getIplist().size() >= 1) {
AtomicInteger index = new AtomicInteger();
ipBuyResultDto.getIplist().forEach(x -> {
// IpInfoResultDto ipInfoResultDto = new IpInfoResultDto();
// Map<String, String> params = new HashMap<String, String>();
// params.put("accountId", "browser");
// params.put("ip", x.getIp());
// HttpHeaders headers = buildGetHeader();
// HttpEntity<Map<String, String>> entity = new HttpEntity<>(params, headers);
// ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/ecc/ipinfo?accountId={accountId}&ip={ip}", HttpMethod.GET, entity, String.class);
// JSONObject jsonObject = JSON.parseObject(result.getBody());
// if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) {
IpResource ipResource = new IpResource();
IpResource ipResource = ipResourceRepository.findById(ipResourceDtos.get(index.get()).getId()).orElse(null);
if (ipResource != null) {
ipResource.setAddr(x.getIp());
ipResource.setIpType(IpType.VENDOR);
// ipResource.setPurchasedTime(Long.valueOf((String) jsonObject.get("createdWhen")));
// ipResource.setValidTime(Long.valueOf((String)jsonObject.get("validTill")));
ipResource.setPurchasedTime(Instant.now().toEpochMilli());
ipResource.setValidTime(Instant.parse(x.getValidTill()).toEpochMilli());
ipResource.setPort(port);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
ipResource.setStatus(0);
ipResource.setUsername(USERNAME);
if (account.getParent() != null)
ipResource.setUserParent(account.getParent());
ipResource.setRegion(ipResourceRequestDto.getRegion());
ipResource.setRegionCn(ipResourceRequestDto.getRegionCn());
ipResource.setProtocol(protocol);
ipResource.setPassword(password);
ipResource.setOwner(username);
ipResourceRepository.save(ipResource);
ipResourceDtos.add(new IpResourceDto(ipResource, null));
// }
} else {
logger.error("no ipResource");
}
index.getAndIncrement();
});
if (ipBuyResultDto.getIplist().size() < ipResourceDtos.size()) {
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1);
accountService.chargeByMoney(username, -Double.valueOf(price)*(ipResourceDtos.size() - ipBuyResultDto.getIplist().size()), ipChargeRequestDto);
}
}
ipTransaction.setStatus(1);
ipTransactionRepository.save(ipTransaction);
} catch (Exception e) {
logger.error("fail to post request", e.getMessage());
logger.error(e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}, ThreadPoolUtils.taskExecutorPool);
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1);
accountService.chargeByMoney(username, Double.valueOf(price), ipChargeRequestDto);
return ipResourceDtos;
accountService.chargeByMoney(username, Double.valueOf(price) * ipChargeRequestDto.getAmount(), ipChargeRequestDto);
return ipTransactionDto;
}
@Override
......@@ -521,4 +541,37 @@ public class IpResourceServiceImpl implements IpResourceService {
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}
@Override
public IpTransactionDto queryTransaction(String username, String tid) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
IpTransaction ipTransaction = ipTransactionRepository.findById(tid).orElse(null);
if (ipTransaction == null)
throw new ClientRequestException(BrowserErrorCode.IPTRANSACTIONNOTEXIST);
IpTransactionDto ipTransactionDto = new IpTransactionDto(ipTransaction);
for (String id : ipTransaction.getIpIds()) {
IpResource ipResource = ipResourceRepository.findById(id).orElse(null);
if (ipResource != null) {
IpResourceDto ipResourceDto = new IpResourceDto(ipResource, null);
ipTransactionDto.getIpResourceDtos().add(ipResourceDto);
}
}
// IpInfoResultDto ipInfoResultDto = new IpInfoResultDto();
// Map<String, String> params = new HashMap<String, String>();
// params.put("accountId", "browser");
// params.put("ip", x.getIp());
// HttpHeaders headers = buildGetHeader();
// HttpEntity<Map<String, String>> entity = new HttpEntity<>(params, headers);
// ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/ecc/ipinfo?accountId={accountId}&ip={ip}", HttpMethod.GET, entity, String.class);
// JSONObject jsonObject = JSON.parseObject(result.getBody());
// if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) {
// ipResource.setPurchasedTime(Long.valueOf((String) jsonObject.get("createdWhen")));
// ipResource.setValidTime(Long.valueOf((String)jsonObject.get("validTill")));
// }
return ipTransactionDto;
}
}
......@@ -359,11 +359,25 @@ public class ShopServiceImpl implements ShopService {
}
List<String> shopIds = new ArrayList<>();
if (groupId.equals("-1")) {
if (shopFilterDto.getBindIp() == 0)
shopIds = userShopRepository.findByUsername(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1)
shopIds = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else
shopIds = userShopRepository.findByUsernameAndIpIdIsNull(username).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
} else {
if (shopFilterDto.getBindIp() == 0)
shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else if (shopFilterDto.getBindIp() == 1)
shopIds = userShopRepository.findByUsernameAndGroupIdAndIpIdIsNotNull(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
else
shopIds = userShopRepository.findByUsernameAndGroupIdAndIpIdIsNull(username, groupId).stream().
map(x -> x.getShopId()).collect(Collectors.toList());
}
Page<Shop> shops;
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion()))
......
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.IpOptions;
import com.edgec.browserbackend.browser.domain.Platform;
import com.edgec.browserbackend.browser.domain.PlatformOptions;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.domain.*;
import com.edgec.browserbackend.browser.dto.*;
import java.util.List;
public interface IpResourceService {
List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
IpTransactionDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
......@@ -23,4 +20,6 @@ public interface IpResourceService {
IpOptions getIpOptions();
List<PlatformOptions> getPlatformOptions();
IpTransactionDto queryTransaction(String username, String transactionId);
}
......@@ -77,6 +77,7 @@ public class FileUtil {
inputStream.close();
//工作表对象
Sheet sheet = workbook.getSheetAt(0);
//总行数
int rowLength = sheet.getLastRowNum() -1;
//工作表的列
......@@ -87,7 +88,7 @@ public class FileUtil {
//得到指定的单元格
Cell cell = row.getCell(0);;
int size = 1;
for (int i = 2; i < rowLength; i++) {
for (int i = 1; i < rowLength + 2; i++) {
row = sheet.getRow(i);
List<Object> rowvalue = new ArrayList<>();
size = 0;
......
package com.edgec.browserbackend.common.utils;
import java.time.Instant;
public class PollerUtils {
public static void poll(int timeoutInSeconds, int intervalInSeconds, Evaluator evaluator) {
boolean result = evaluator.eval();
long start = Instant.now().toEpochMilli();
while (!result) {
long end = Instant.now().toEpochMilli();
if((end - start) > timeoutInSeconds * 1000)
return;
try {
Thread.sleep(intervalInSeconds * 1000);
} catch (InterruptedException e) {
}
result = evaluator.eval();
}
}
public static interface Evaluator {
boolean eval();
}
}
package com.edgec.browserbackend.common.utils;
import com.edgec.browserbackend.common.commons.utils.PriorityThreadPoolExecutor;
import com.edgec.browserbackend.common.commons.utils.UniquePriorityBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.*;
public abstract class ThreadPoolUtils {
private static final Logger log = LoggerFactory.getLogger(ThreadPoolUtils.class);
private static final int SCHEDULER_POOL_COUNT = 50;
public static final int MAX_WAITING_TASKS = 10;
public static final BlockingQueue<Runnable> schedulerQueue = new UniquePriorityBlockingQueue<>(50);
private static final int TASK_POOL_COUNT = 80;
public static final ExecutorService taskExecutorPool = Executors.newFixedThreadPool(TASK_POOL_COUNT, new ThreadFactory() {
int count = 1;
@Override
public Thread newThread(Runnable runnable) {
return new Thread(runnable, "intelligroup-taskexec-" + count++);
}
});
private static final int TIME_SCHEDULER_POOL_COUNT = 10;
public static final ScheduledExecutorService timeSchedulerPool = Executors.newScheduledThreadPool(TIME_SCHEDULER_POOL_COUNT, new ThreadFactory() {
int count = 1;
@Override
public Thread newThread(Runnable runnable) {
return new Thread(runnable, "intelligroup-time-scheduler-" + count++);
}
});
}
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