Commit 5036f086 authored by renjie's avatar renjie
parents 1a0b79dc 20eb3f2a
...@@ -169,6 +169,17 @@ public class PaymentServiceImpl implements PaymentService { ...@@ -169,6 +169,17 @@ public class PaymentServiceImpl implements PaymentService {
userPrePaidBillingRepository.save(bill); 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); balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + more);
userBalanceRepository.save(balance); userBalanceRepository.save(balance);
} }
...@@ -272,7 +283,7 @@ public class PaymentServiceImpl implements PaymentService { ...@@ -272,7 +283,7 @@ public class PaymentServiceImpl implements PaymentService {
bill.setMonth(monthValue); bill.setMonth(monthValue);
if (more != 20 || more != 45 || more != 125 || more != 300) if (more != 20 && more != 45 && more != 125 && more != 300)
more = 0; more = 0;
if ((more == 20 && byTradeNo.getAmount() != 100) || (more != 20 && byTradeNo.getAmount() == 100)) if ((more == 20 && byTradeNo.getAmount() != 100) || (more != 20 && byTradeNo.getAmount() == 100))
more = 0; more = 0;
......
...@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception { public void configure(WebSecurity web) throws Exception {
web.ignoring() web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp", "/shop/multiadd", .antMatchers( "/user/authCode", "/user/signUp",
"/user/reset*"); "/user/reset*");
} }
......
package com.edgec.browserbackend.browser.ErrorCode; package com.edgec.browserbackend.browser.ErrorCode;
import com.edgec.browserbackend.browser.domain.IpTransaction;
import com.edgec.browserbackend.common.commons.error.ErrorCode; import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
...@@ -14,7 +15,9 @@ public enum BrowserErrorCode implements ErrorCode { ...@@ -14,7 +15,9 @@ public enum BrowserErrorCode implements ErrorCode {
IPNOTEXIST(BROWSER_BASE+201, "The ip do not exist"), IPNOTEXIST(BROWSER_BASE+201, "The ip do not exist"),
IPNOTBINDTOSHOP(BROWSER_BASE+202, "The ip do not bind this shop."), 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 { ...@@ -26,7 +26,7 @@ public class IpControlloer {
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){ public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
List<IpResourceDto> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto); IpTransactionDto ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto); resultDto.setData(ipResourceDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
...@@ -100,4 +100,22 @@ public class IpControlloer { ...@@ -100,4 +100,22 @@ public class IpControlloer {
} }
return resultDto; 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; ...@@ -10,6 +10,8 @@ import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.service.ShopService; import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.FileUtil; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -25,6 +27,8 @@ import java.util.Map; ...@@ -25,6 +27,8 @@ import java.util.Map;
@RequestMapping("/shop") @RequestMapping("/shop")
public class ShopController { public class ShopController {
private final Logger logger = LoggerFactory.getLogger(ShopController.class);
@Autowired @Autowired
private ShopService shopService; private ShopService shopService;
...@@ -47,8 +51,7 @@ public class ShopController { ...@@ -47,8 +51,7 @@ public class ShopController {
} }
@RequestMapping(value = "/multiadd", method = RequestMethod.POST) @RequestMapping(value = "/multiadd", method = RequestMethod.POST)
@ResponseBody public ResultDto addShops(Principal principal, @RequestParam("file") MultipartFile file) {
public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
String name = file.getOriginalFilename(); String name = file.getOriginalFilename();
if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){ if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){
...@@ -60,6 +63,7 @@ public class ShopController { ...@@ -60,6 +63,7 @@ public class ShopController {
} }
try { try {
shopService.addShops(principal.getName(), file); shopService.addShops(principal.getName(), file);
resultDto.setStatus(0);
} catch (ClientRequestException | IOException e) { } catch (ClientRequestException | IOException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
...@@ -69,7 +73,7 @@ public class ShopController { ...@@ -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 { ...@@ -7,6 +7,7 @@ public class ShopFilterDto {
private String shopName; private String shopName;
private String IpRegion; private String IpRegion;
private String shopAccount; private String shopAccount;
private int bindIp;
public String getShopAccount() { public String getShopAccount() {
return shopAccount; return shopAccount;
...@@ -31,4 +32,12 @@ public class ShopFilterDto { ...@@ -31,4 +32,12 @@ public class ShopFilterDto {
public void setShopName(String shopName) { public void setShopName(String shopName) {
this.shopName = 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; ...@@ -7,9 +7,12 @@ import java.util.List;
public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom { public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom {
List<UserShop> findByUsername(String username); List<UserShop> findByUsername(String username);
List<UserShop> findByUsernameAndIpIdIsNull(String username);
UserShop findByUsernameAndShopId(String username, String shopId); UserShop findByUsernameAndShopId(String username, String shopId);
UserShop findByShopId(String shopId); UserShop findByShopId(String shopId);
List<UserShop> findByUsernameAndGroupId(String username, String groupId); 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> findByUsernameAndShopIdIn(String username, List<String> shopIds);
List<UserShop> findByUsernameAndIpIdIsNotNull(String username); List<UserShop> findByUsernameAndIpIdIsNotNull(String username);
int countByUsernameAndIpIdIsNull(String username); int countByUsernameAndIpIdIsNull(String username);
......
...@@ -359,11 +359,25 @@ public class ShopServiceImpl implements ShopService { ...@@ -359,11 +359,25 @@ public class ShopServiceImpl implements ShopService {
} }
List<String> shopIds = new ArrayList<>(); List<String> shopIds = new ArrayList<>();
if (groupId.equals("-1")) { if (groupId.equals("-1")) {
shopIds = userShopRepository.findByUsername(username).stream(). if (shopFilterDto.getBindIp() == 0)
map(x -> x.getShopId()).collect(Collectors.toList()); 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 { } else {
shopIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream(). if (shopFilterDto.getBindIp() == 0)
map(x -> x.getShopId()).collect(Collectors.toList()); 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; Page<Shop> shops;
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion())) if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion()))
......
package com.edgec.browserbackend.browser.service; package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.IpOptions; import com.edgec.browserbackend.browser.domain.*;
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.dto.*; import com.edgec.browserbackend.browser.dto.*;
import java.util.List; import java.util.List;
public interface IpResourceService { 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; IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception;
...@@ -23,4 +20,6 @@ public interface IpResourceService { ...@@ -23,4 +20,6 @@ public interface IpResourceService {
IpOptions getIpOptions(); IpOptions getIpOptions();
List<PlatformOptions> getPlatformOptions(); List<PlatformOptions> getPlatformOptions();
IpTransactionDto queryTransaction(String username, String transactionId);
} }
...@@ -77,6 +77,7 @@ public class FileUtil { ...@@ -77,6 +77,7 @@ public class FileUtil {
inputStream.close(); inputStream.close();
//工作表对象 //工作表对象
Sheet sheet = workbook.getSheetAt(0); Sheet sheet = workbook.getSheetAt(0);
//总行数 //总行数
int rowLength = sheet.getLastRowNum() -1; int rowLength = sheet.getLastRowNum() -1;
//工作表的列 //工作表的列
...@@ -87,7 +88,7 @@ public class FileUtil { ...@@ -87,7 +88,7 @@ public class FileUtil {
//得到指定的单元格 //得到指定的单元格
Cell cell = row.getCell(0);; Cell cell = row.getCell(0);;
int size = 1; int size = 1;
for (int i = 2; i < rowLength; i++) { for (int i = 1; i < rowLength + 2; i++) {
row = sheet.getRow(i); row = sheet.getRow(i);
List<Object> rowvalue = new ArrayList<>(); List<Object> rowvalue = new ArrayList<>();
size = 0; 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