Commit 66826d80 authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

Staging

See merge request !167
parents da5c9260 9921e4ce
......@@ -31,6 +31,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(Date startDate, Date endDate, String promotionCode);
List<Account> findAllByPromotionCodeAndParentIsNull(String code);
Page<Account> findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(Pageable pageable, Date startDate, Date endDate, String promotionCode);
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
......@@ -45,4 +47,5 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findByPromotionCodeAndParentIsNull(String code);
int countByPromotionCodeAndParentIsNull(String promotionCode);
}
......@@ -407,16 +407,24 @@ public class AdministratorServiceImpl implements AdministratorService {
@Override
public PromotionQueryResultDto queryPromotion(Pageable pageable, String username, String promotionCode, String strDate1, String strDate2) {
if (StringUtils.isBlank(username) && StringUtils.isBlank(promotionCode))
if (StringUtils.isBlank(username) && StringUtils.isBlank(promotionCode)) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
Account account = null;
if (!StringUtils.isBlank(username))
if (!StringUtils.isBlank(username)) {
account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
else account = accountRepository.findByPromotion(promotionCode);
if (account == null)
} else {
account = accountRepository.findByPromotion(promotionCode);
}
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getParent() != null)
}
if (account.getParent() != null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
PromotionQueryResultDto promotionQueryResultDto = new PromotionQueryResultDto(account);
promotionQueryResultDto.setUsername(username);
......@@ -434,25 +442,34 @@ public class AdministratorServiceImpl implements AdministratorService {
Page<AccountPromotionDto> accountPromotionDtoPage = new PageImpl<AccountPromotionDto>(accountPromotionDtos);
promotionQueryResultDto.setUsers(accountPromotionDtoPage);
List<Account> accounts = accountRepository.findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(dateTime1, dateTime2, account.getPromotion().getCode());
// 查询在指定的日期通过邀请码注册的账户
// List<Account> accounts = accountRepository.findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(dateTime1, dateTime2, account.getPromotion().getCode());
// 从上面的 改为查询 某用户邀请的所有账户
List<Account> accounts = accountRepository.findAllByPromotionCodeAndParentIsNull(account.getPromotion().getCode());
Promotion promotion = new Promotion();
Account finalAccount = account;
AtomicLong ipCount = new AtomicLong();
if (accounts != null && accounts.size() > 0) {
accounts.forEach(x -> {
promotion.setInvitedUsers(promotion.getInvitedUsers() + 1);
// 查询账户在指定日期充值记录
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByAdministratorAndPayMethodInAndTimestampBetween(x.getName(), Arrays.asList(1, 2, 3), dateTime1.getTime(), dateTime2.getTime());
double totalCommission = 0;
if (userPrePaidBillings != null && userPrePaidBillings.size() > 0)
if (userPrePaidBillings != null && userPrePaidBillings.size() > 0) {
totalCommission = userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
promotion.setTotalCommission(promotion.getTotalCommission() + (int) totalCommission);
promotion.setCommission(promotion.getCommission() + x.getPromotion().getCommission());
double secondCommission = 0;
ipCount.addAndGet(ipResourceRepository.countAllByOwnerAndIsDeletedAndValidTimeGreaterThan(x.getName(), false, Instant.now().toEpochMilli()));
List<Account> children = accountRepository.findByParent(x.getName());
if (children != null && children.size() > 0) {
ipCount.addAndGet(ipResourceRepository.countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(children.stream().map(Account::getName).collect(Collectors.toList()), false, Instant.now().toEpochMilli()));
}
double secondCommission = 0;
if (finalAccount.getPromotion().isSale() && x.getParent() == null) {
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(x.getPromotion().getCode());
if (secondPromotes != null && secondPromotes.size() > 0) {
......@@ -470,10 +487,11 @@ public class AdministratorServiceImpl implements AdministratorService {
}
}
}
if (finalAccount.getPromotion().isSale())
if (finalAccount.getPromotion().isSale()) {
promotion.setAllGift(promotion.getAllGift() + totalCommission * 0.1 + secondCommission * 0.02);
else
} else {
promotion.setAllGift(promotion.getAllGift() + totalCommission * 0.08);
}
promotion.setWithdrawn(promotion.getWithdrawn() + secondCommission);
promotion.setGift(promotion.getGift() + x.getPromotion().getGift());
promotion.setCommissionLastMonth(promotion.getCommissionLastMonth() + x.getPromotion().getCommissionLastMonth());
......
......@@ -135,14 +135,13 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("id").is(id).and("isDeleted").is(false));
Update update = new Update();
update.set("status", status);
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
if (result.getModifiedCount() < 1)
return false;
else
return true;
return result.getModifiedCount() >= 1;
}
@Override
......
......@@ -693,6 +693,7 @@ public class IpResourceServiceImpl implements IpResourceService {
// 1.4 ip资源到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则设置 ip 资源的状态为 1(已过期)
} else if (x.getValidTime() <= Instant.now().toEpochMilli() && x.getStatus() != 3 && x.getStatus() != 6) {
// 这个地方可变参数随便传啥都行
ipResourceRepository.updateStatus(x.getId(), 1);
// 1.5 其他
......@@ -974,8 +975,11 @@ public class IpResourceServiceImpl implements IpResourceService {
}
break;
case 5:
// 已分配
ipResources = ipResourceRepository.findShopIdInList(shopIds, false);
// 已分配且未过期
ipResources = ipResourceRepository.findShopIdInList(shopIds, false)
.stream()
.filter(x -> x.getValidTime() > Instant.now().toEpochMilli())
.collect(Collectors.toList());
if (!isParent)
notUsed = ipResourceRepository.findByOwnerAndStatusInAndIsDeletedAndBind(username, Arrays.asList(0, 2, 4, 8), false, false);
else
......
......@@ -87,6 +87,7 @@ public class PromotionTask {
log.info("End scheduled task:Scheduled.countGift...");
}
// @SchedulerLock:标识使用分布式锁。name:用来标注一个定时服务的名字,被用于写入数据库作为区分不同服务的标识
@SchedulerLock(name = "countCommission", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
@Scheduled(cron = "0 0 3 * * ?")
public void countCommission() {
......
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