Commit dab1fa7a authored by renjie's avatar renjie

information和过期

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