Commit dab1fa7a authored by renjie's avatar renjie

information和过期

parent 3b295221
......@@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.web.cors.CorsConfiguration;
......@@ -15,6 +16,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@SpringBootApplication
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableScheduling
public class BrowserBackendApplication {
public static void main(String[] args) {
......
package com.edgec.browserbackend.account.domain;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -38,6 +40,8 @@ public class AccountDto {
private List<String> whiteList = new ArrayList<>();
private ShopSummary shopSummary;
public AccountDto(){
}
......@@ -183,4 +187,12 @@ public class AccountDto {
public void setToken(String token) {
this.token = token;
}
public ShopSummary getShopSummary() {
return shopSummary;
}
public void setShopSummary(ShopSummary shopSummary) {
this.shopSummary = shopSummary;
}
}
......@@ -12,9 +12,12 @@ import com.edgec.browserbackend.account.utils.AccountServicePool;
import com.edgec.browserbackend.auth.exception.AuthErrorCode;
import com.edgec.browserbackend.auth.repository.UserRepository;
import com.edgec.browserbackend.auth.service.UserAuthService;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.PageInfo;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.utils.CommonStringUtils;
import org.slf4j.Logger;
......@@ -79,18 +82,15 @@ public class AccountServiceImpl implements AccountService {
@Autowired
private InvoiceRepository invoiceRepository;
@Autowired
private CloudUserOrderRepository cloudUserOrderRepository;
@Autowired
private PaymentService paymentService;
@Autowired
private UserAuthService userAuthService;
@Autowired
private UserRepository userRepository;
@Autowired
private ShopService shopService;
@Override
public List<UserBillList> getUserBills0(String name) {
......@@ -333,6 +333,10 @@ public class AccountServiceImpl implements AccountService {
List<AccountDto> child = repository.findByParent(name).stream().map(item -> new AccountDto(item)).collect(Collectors.toList());
current.setChild(child);
ShopSummary shopSummary = shopService.getShopSummary(name);
if (shopSummary != null)
current.setShopSummary(shopSummary);
resultDto.setStatus(0);
resultDto.setData(current);
} catch (Exception e) {
......
......@@ -20,7 +20,6 @@ public class IpResource {
private String region;
private String regionCn;
//0:正常, 1:已过期, 2:即将过期
@Transient
private int status;
private List<String> port;
private long purchasedTime;
......@@ -108,14 +107,6 @@ public class IpResource {
this.validTime = validTime;
}
public String getIpAddr() {
return addr;
}
public void setIpAddr(String ipAddr) {
this.addr = ipAddr;
}
public Vendor getVendor() {
return vendor;
}
......
package com.edgec.browserbackend.browser.domain;
public class ShopSummary {
private int total;
private int unbind;
private int willExpire;
private int expired;
public int getExpired() {
return expired;
}
public void setExpired(int expired) {
this.expired = expired;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getUnbind() {
return unbind;
}
public void setUnbind(int unbind) {
this.unbind = unbind;
}
public int getWillExpire() {
return willExpire;
}
public void setWillExpire(int willExpire) {
this.willExpire = willExpire;
}
}
......@@ -21,9 +21,10 @@ public class IpResourceRequestDto {
private String unit="month";
private int amount = 1;
private boolean autorenew = false;
private int ipkeptperiod = 0;
private int ipkeptperiod = 7;
private String startscript = "";
private String password;
private String instanceSpecKey;
private String imageKey;
......@@ -148,4 +149,20 @@ public class IpResourceRequestDto {
public void setStartscript(String startscript) {
this.startscript = startscript;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void setIpkeptperiod(int ipkeptperiod) {
this.ipkeptperiod = ipkeptperiod;
}
public void setRegionCn(String regionCn) {
this.regionCn = regionCn;
}
}
......@@ -19,4 +19,6 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
Page<IpResource> findByRegionLikeAndIdInAndIsDeleted(String region, List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByValidTimeBetween(long beginTime, long endTime);
int countByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
}
......@@ -12,4 +12,5 @@ public interface ShopRepository extends MongoRepository<Shop, String> {
Page<Shop> findByShopIdInAndShopAccountLike(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByShopIdInAndShopNameLike(List<String> shopIds, String shopName, Pageable pageable);
Page<Shop> findByShopIdIn(List<String> shopIds, Pageable pageable);
List<Shop> findByOwnerAndIpIsNotNull(String username);
}
......@@ -11,4 +11,7 @@ public interface UserShopRepository extends MongoRepository<UserShop, String>, U
UserShop findByShopId(String shopId);
List<UserShop> findByUsernameAndGroupId(String username, String groupId);
List<UserShop> findByUsernameAndShopIdIn(String username, List<String> shopIds);
List<UserShop> findByUsernameAndIpIdIsNotNull(String username);
int countByUsernameAndIpIdIsNull(String username);
int countByUsername(String username);
}
......@@ -90,7 +90,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
public static String makeRandomPassword(int len){
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@$%^&*.?".toCharArray();
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
StringBuilder sb = new StringBuilder();
Random r = new Random();
for (int x = 0; x < len; ++x) {
......@@ -141,9 +141,14 @@ public class IpResourceServiceImpl implements IpResourceService {
map.put("provider", ipResourceRequestDto.getVendor());
map.put("unit", ipResourceRequestDto.getUnit());
map.put("amount", String.valueOf(ipResourceRequestDto.getAmount()));
String password = makeRandomPassword(16);
String password;
if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword()))
password = ipResourceRequestDto.getPassword();
else
password = makeRandomPassword(16);
map.put("loginPassword", password);
map.put("startscript", startscript);
map.put("ipkeptperiod", ipResourceRequestDto.getIpkeptperiod());
HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto ipBuyResultDto = null;
try {
......@@ -168,7 +173,7 @@ public class IpResourceServiceImpl implements IpResourceService {
// JSONObject jsonObject = JSON.parseObject(result.getBody());
// if (ipInfoResultDto != null && StringUtils.isBlank(ipInfoResultDto.getErrorCode())) {
IpResource ipResource = new IpResource();
ipResource.setIpAddr(x.getIp());
ipResource.setAddr(x.getIp());
ipResource.setIpType(IpType.VENDOR);
// ipResource.setPurchasedTime(Long.valueOf((String) jsonObject.get("createdWhen")));
// ipResource.setValidTime(Long.valueOf((String)jsonObject.get("validTill")));
......@@ -347,31 +352,17 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResources.addAll(notUsed);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList());
Page<IpResource> ipResources1 = null;
if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getRegion())) {
Page<IpResource> ipResources1 = ipResourceRepository.findByRegionLikeAndIdInAndIsDeleted(ipFilterDto.getRegion(), allIpIds, false, pageable);
ipResources1.getContent().forEach(x -> {
ShopDto shopDto;
if (x.getShopId() == null) {
shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
}
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli())
x.setStatus(2);
else if (x.getValidTime() <= Instant.now().toEpochMilli())
x.setStatus(1);
else
x.setStatus(0);
ipResourceDtos.add(new IpResourceDto(x, shopDto));
});
ipResources1 = ipResourceRepository.findByRegionLikeAndIdInAndIsDeleted(ipFilterDto.getRegion(), allIpIds, false, pageable);
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getAddr())) {
Page<IpResource> ipResources1 = ipResourceRepository.findByAddrLikeAndIdInAndIsDeleted(ipFilterDto.getAddr(), allIpIds, false, pageable);
ipResources1.getContent().forEach(x -> {
ipResources1 = ipResourceRepository.findByAddrLikeAndIdInAndIsDeleted(ipFilterDto.getAddr(), allIpIds, false, pageable);
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getVendor())) {
ipResources1 = ipResourceRepository.findByVendorLikeAndIdInAndIsDeleted(ipFilterDto.getVendor(), allIpIds, false, pageable);
} else {
ipResources.forEach(x -> {
ShopDto shopDto;
if (x.getShopId() == null) {
shopDto = new ShopDto();
......@@ -382,17 +373,26 @@ public class IpResourceServiceImpl implements IpResourceService {
else
shopDto = new ShopDto();
}
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli())
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli()) {
x.setStatus(2);
else if (x.getValidTime() <= Instant.now().toEpochMilli())
ipResourceRepository.save(x);
}
else if (x.getValidTime() <= Instant.now().minusSeconds(60*60*24*7).toEpochMilli()) {
deleteIp(username, Arrays.asList(x.getAddr()));
return;
}
else if (x.getValidTime() <= Instant.now().toEpochMilli()) {
x.setStatus(1);
else
ipResourceRepository.save(x);
}
else {
x.setStatus(0);
ipResourceRepository.save(x);
}
ipResourceDtos.add(new IpResourceDto(x, shopDto));
});
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getVendor())) {
Page<IpResource> ipResources1 = ipResourceRepository.findByVendorLikeAndIdInAndIsDeleted(ipFilterDto.getVendor(), allIpIds, false, pageable);
if (ipResources1 != null) {
ipResources1.getContent().forEach(x -> {
ShopDto shopDto;
if (x.getShopId() == null) {
......@@ -404,32 +404,22 @@ public class IpResourceServiceImpl implements IpResourceService {
else
shopDto = new ShopDto();
}
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli())
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli()) {
x.setStatus(2);
else if (x.getValidTime() <= Instant.now().toEpochMilli())
x.setStatus(1);
else
x.setStatus(0);
ipResourceDtos.add(new IpResourceDto(x, shopDto));
});
} else {
ipResources.forEach(x -> {
ShopDto shopDto;
if (x.getShopId() == null) {
shopDto = new ShopDto();
} else {
Shop shop = shopRepository.findById(x.getShopId()).orElse(null);
if (shop != null)
shopDto = new ShopDto(shop);
else
shopDto = new ShopDto();
ipResourceRepository.save(x);
}
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli())
x.setStatus(2);
else if (x.getValidTime() <= Instant.now().toEpochMilli())
else if (x.getValidTime() <= Instant.now().minusSeconds(60*60*24*7).toEpochMilli()) {
deleteIp(username, Arrays.asList(x.getAddr()));
return;
}
else if (x.getValidTime() <= Instant.now().toEpochMilli()) {
x.setStatus(1);
else
ipResourceRepository.save(x);
}
else {
x.setStatus(0);
ipResourceRepository.save(x);
}
ipResourceDtos.add(new IpResourceDto(x, shopDto));
});
}
......
......@@ -5,10 +5,7 @@ import com.edgec.browserbackend.account.domain.User;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.Group;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.UserShop;
import com.edgec.browserbackend.browser.domain.*;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.PageInfo;
......@@ -343,4 +340,18 @@ public class ShopServiceImpl implements ShopService {
shopPageResultDto.setShopPage(pageInfo);
return shopPageResultDto;
}
@Override
public ShopSummary getShopSummary(String username) {
ShopSummary shopSummary = new ShopSummary();
int unbind = userShopRepository.countByUsernameAndIpIdIsNull(username);
shopSummary.setUnbind(unbind);
List<String> bind = userShopRepository.findByUsernameAndIpIdIsNotNull(username).stream().map(x -> x.getIpId()).collect(Collectors.toList());
int expired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(1, bind, false);
int willexpired = ipResourceRepository.countByStatusAndIdInAndIsDeleted(2, bind, false);
shopSummary.setExpired(expired);
shopSummary.setWillExpire(willexpired);
shopSummary.setTotal(userShopRepository.countByUsername(username));
return shopSummary;
}
}
......@@ -3,6 +3,7 @@ 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.dto.*;
import java.util.List;
......
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.Shop;
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;
......@@ -26,4 +27,6 @@ public interface ShopService {
void assignShops(String username, List<String> shopIds, List<String> users);
ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto);
ShopSummary getShopSummary(String username);
}
......@@ -27,27 +27,36 @@ public class ExpireSoonWarn {
@Scheduled(cron = "0 0 1 * * ?")
public void sendMessages() {
this.sendExpiredIpAccount(3);
this.sendExpiredIpAccount(0);
this.sendExpiredIpAccount(7);
}
private void sendExpiredIpAccount(int day) {
List<IpResource> ipResources = ipResourceRepository.findByValidTimeBetween(
Instant.now().atZone(ZoneOffset.UTC).plusDays(day - 1).toEpochSecond() * 1000,
Instant.now().atZone(ZoneOffset.UTC).plusDays(day).toEpochSecond() * 1000);
List<IpResource> ipResources = null;
if (day == 7) {
ipResources = ipResourceRepository.findByValidTimeBetween(
Instant.now().atZone(ZoneOffset.UTC).plusDays(day - 1).toEpochSecond() * 1000,
Instant.now().atZone(ZoneOffset.UTC).plusDays(day).toEpochSecond() * 1000);
} else {
ipResources = ipResourceRepository.findByValidTimeBetween(
Instant.now().atZone(ZoneOffset.UTC).minusDays(1).toEpochSecond() * 1000,
Instant.now().atZone(ZoneOffset.UTC).plusDays(day).toEpochSecond() * 1000);
}
if (ipResources != null && ipResources.size() > 0) {
Map<String, List<IpResource>> map = ipResources.stream().collect(Collectors.groupingBy(IpResource::getOwner));
for (String key : map.keySet()) {
sendToAccount(key, day, map.get(key).size());
sendToAccount(key, day, map.get(key).size(), map.get(key).stream().map(x -> x.getAddr()).collect(Collectors.toList()));
}
}
}
private void sendToAccount(String username, int day, int amount) {
private void sendToAccount(String username, int day, int amount, List<String> ips) {
Account account = accountRepository.findByName(username);
JSONObject param = new JSONObject();
param.put("day", day);
param.put("amount", amount);
param.put("ips", ips);
SmsUtils.sendIpSms(account.getPhoneNumber(), SmsUtils.SmsTemplateCode.VPS_EXPIRE, param);
}
......
......@@ -99,7 +99,7 @@ public class SmsUtils {
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("PhoneNumbers", phoneNum);
request.putQueryParameter("SignName", "防关联浏览器");
request.putQueryParameter("SignName", "防关联VPS");
request.putQueryParameter("TemplateCode", smsTemplateCode.getCode());
request.putQueryParameter("TemplateParam", param.toJSONString());
try {
......
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