Commit 67f0daad authored by xuxin's avatar xuxin

临时修复礼金缺失bug

parent f5da3b05
...@@ -27,10 +27,10 @@ public class PromotionTask { ...@@ -27,10 +27,10 @@ public class PromotionTask {
@Autowired @Autowired
private UserPrePaidBillingRepository userPrePaidBillingRepository; private UserPrePaidBillingRepository userPrePaidBillingRepository;
//临时修改为每2分钟执行一次 //临时修改为7月2号的11点执行执行一次
@SchedulerLock(name = "countGift", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H") @SchedulerLock(name = "countGift", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
//@Scheduled(cron = "0 0 1 1 * ?") //@Scheduled(cron = "0 0 1 1 * ?")
@Scheduled(cron = "0 0/2 * * * ?") @Scheduled(cron = "0 0 3 2 * ?")
public void countGift() { public void countGift() {
log.info("Start scheduled task:Scheduled.countGift..."); log.info("Start scheduled task:Scheduled.countGift...");
List<Account> accounts = accountRepository.findByParentIsNull(); List<Account> accounts = accountRepository.findByParentIsNull();
...@@ -65,7 +65,7 @@ public class PromotionTask { ...@@ -65,7 +65,7 @@ public class PromotionTask {
} }
} }
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、当月礼金、总共未体现礼金)并保存 // 4. 封装当前账户的返佣相关信息(总消费、上月消费、上月礼金、总共未提现礼金)并保存
Promotion promotion = account.getPromotion(); Promotion promotion = account.getPromotion();
promotion.setTotalCommission((int) (promotion.getTotalCommission() + totalCommission)); promotion.setTotalCommission((int) (promotion.getTotalCommission() + totalCommission));
promotion.setCommissionLastMonth((int) totalCommission); promotion.setCommissionLastMonth((int) totalCommission);
...@@ -80,10 +80,10 @@ public class PromotionTask { ...@@ -80,10 +80,10 @@ public class PromotionTask {
log.info("End scheduled task:Scheduled.countGift..."); log.info("End scheduled task:Scheduled.countGift...");
} }
//临时修改为每1分钟执行一次 //临时修改为7月2号的12点执行执行一次
@SchedulerLock(name = "countCommission", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H") @SchedulerLock(name = "countCommission", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
//@Scheduled(cron = "0 0 1 * * ?") //@Scheduled(cron = "0 0 1 * * ?")
@Scheduled(cron = "0 0/1 * * * ?") @Scheduled(cron = "0 0 4 2 * ?")
public void countCommission() { public void countCommission() {
log.info("Start scheduled task:Scheduled.countCommission..."); log.info("Start scheduled task:Scheduled.countCommission...");
List<Account> accounts = accountRepository.findByParentIsNull(); List<Account> accounts = accountRepository.findByParentIsNull();
......
package com.edgec.browserbackend; package com.edgec.browserbackend;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.repository.UserPaymentRepository;
import com.edgec.browserbackend.account.repository.UserPrePaidBillingRepository;
import com.edgec.browserbackend.browser.repository.IpOptionsRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.browser.service.ShopService;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
@SpringBootTest @SpringBootTest
class BrowserBackendApplicationTests { class BrowserBackendApplicationTests {
@Autowired
ShopService shopService;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
private UserShopRepository userShopRepository;
@Autowired
IpResourceRepository ipResourceRepository;
@Autowired
ShopRepository shopRepository;
@Autowired
AccountRepository accountRepository;
@Autowired
IpOptionsRepository ipOptionsRepository;
@Autowired
IpResourceService ipResourceService;
@Autowired
UserPaymentRepository userPaymentRepository;
@Autowired
UserPrePaidBillingRepository userPrePaidBillingRepository;
@Test @Test
void contextLoads() { void contextLoads() {
} }
@Test
public void testShopList() throws Exception {
/*List<Account> all = accountRepository.findAll();
List<Account> parents = all.stream().filter(x -> StringUtils.isEmpty(x.getParent())).collect(Collectors.toList());
// 移除 父账户,剩下的都是子账户了
all.removeAll(parents);
// 父账户, 子账户列表
Map<Account, List<Account>> map = new HashMap<>();
for (Account account : parents) {
List<Account> list = new ArrayList<>();
for (Account child : all) {
if (child.getParent().equals(account.getName())) {
list.add(child);
}
}
if (list.size() != 0) {
map.put(account, list);
}
}
Iterator<Map.Entry<Account, List<Account>>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<Account, List<Account>> entry = entries.next();
List<Account> children = entry.getValue();
// 查找子类所拥有的店铺
List<Shop> childrenShop = shopRepository.findByOwnerIn(children.stream().map(Account::getName).collect(Collectors.toList()));
if (childrenShop.size() == 0) {
continue;
}
List<String> ids = childrenShop.stream().map(x -> x.getShopId()).collect(Collectors.toList());
// 查出来 父账户已有的 usershop信息
List<UserShop> parentUserShops = userShopRepository.findByUsernameAndShopIdIn(entry.getKey().getName(), ids);
List<String> parentShopIds = parentUserShops.stream().map(x -> x.getShopId()).collect(Collectors.toList());
// 剩下的就是 父账户的 usershop 缺失的信息
ids.removeAll(parentShopIds);
List<UserShop> userShops = new ArrayList<>();
for (String id : ids) {
UserShop userShop = new UserShop();
userShop.setShopId(id);
userShop.setUsername(entry.getKey().getName());
userShop.setGroupId("-1");
userShops.add(userShop);
}
if (userShops.size() != 0) {
// 将父账户缺失的 usershop 信息补充完整
List<UserShop> userShops1 = userShopRepository.saveAll(userShops);
}
}
//shopService.getShopUsers("18622987110", "5e82dbd407f16f1c782b9f1e");
/*IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted("5e82e3d407f16f1c782b9f26", false);
IpResourceDto ipResourceDto = new IpResourceDto(ipResource, null, false);
IpResourceDto ipResourceDto1 = new IpResourceDto(ipResource, null, false, null);
System.out.println(ipResourceDto.equals(ipResourceDto1));
Map<String, List<String>> priceList = ipOptionsRepository.findAll().get(0).getIpPlatForm();
System.out.println(priceList);
String json = "{\"addr\":[\"8.210.63.174\"],\"ipId\":[],\"period\":1,\"unit\":\"month\",\"payMethod\":0}";
IpResourceRequestDto ipResourceRequestDto = JSON.parseObject(json, IpResourceRequestDto.class);
String username = "15919921106";
try {
ipResourceService.renewIp(username, ipResourceRequestDto);
} catch (Exception e) {
e.printStackTrace();
}
UserPayment byTradeNo = userPaymentRepository.findByTradeNo("202003141459128356");
if (byTradeNo.getPaymentMethod().equals(PaymentMethod.ALIPAY)) {
System.out.println("hhhh");
}
if (byTradeNo.getPaymentMethod().equals(PaymentMethod.WECHAT)) {
System.out.println("wwww");
}
// 输入json 字符串的快捷方式 alt + enter、alt+enter
String json = "{\"region\":\"us\",\"regionCn\":\"美国随机\",\"vendor\":\"aliyun\",\"period\":1,\"unit\":\"week\",\"amount\":2,\"price\":24,\"payMethod\":0}";
IpResourceRequestDto ipResourceRequestDto = JSON.parseObject(json, IpResourceRequestDto.class);
String username = "15919921106";
List<String> ipResourceDto = ipResourceService.buyIp(username, ipResourceRequestDto);
System.out.println(ipResourceDto);
Optional<Shop> shop = shopRepository.findById("5efbfec70718e43054d65168");
String shopCookie = shop.get().getShopCookie();
List<Account> accounts = accountRepository.findByParentIsNull();
for (Account account : accounts) {
if (account.getName().equals("17665464606")) {
// 1. 获取当前账户的邀请码信息
String code = account.getPromotion().getCode();
// 2. 获取被当前账户邀请的所有账户
List<Account> promotes = accountRepository.findByPromotionCodeAndParentIsNull(code);
double totalCommission = 0;
double secondCommission = 0;
// 3. 计算所有被当前账户邀请的账户上个月的消费信息,以及如果当前账户是销售账户则还需要计算销售账户的下下级账户的上个月消费信息
for (Account promote : promotes) {
// 3.1 获取被邀请的用户上个月的消费信息,todo 感觉这个地方最好加上支付状态
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByAdministratorAndYearAndMonthAndPayMethodIn(
promote.getName(), YearMonth.now().minusMonths(1).getYear(), YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1, 2, 3)
);
// 3.2. 计算被邀请的用户上个月的总消费金额
totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
// 3.3. 如果当前账户是本公司销售,则计算下下级用户(例如:销售人员A 邀请了 用户B,用户B 邀请了 其他用户,其他用户就是A的下下级用户)上个月总消费金额
if (account.getPromotion().isSale() && promote.getParent() == null) {
// 获取下下级账户
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(promote.getPromotion().getCode());
if (secondPromotes != null && !secondPromotes.isEmpty()) {
for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByAdministratorAndYearAndMonthAndPayMethodIn(
secondPromote.getName(), YearMonth.now().minusMonths(1).getYear(), YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1, 2, 3)
);
secondCommission += userPrePaidBillings1.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
}
}
}
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、当月礼金、总共未体现礼金)并保存
Promotion promotion = account.getPromotion();
promotion.setTotalCommission((int) (promotion.getTotalCommission() + totalCommission));
promotion.setCommissionLastMonth((int) totalCommission);
promotion.setGift(totalCommission * 0.08);
if (account.getPromotion().isSale()) {
promotion.setGift(totalCommission * 0.1 + secondCommission * 0.02);
}
promotion.setAllGift(promotion.getAllGift() + promotion.getGift());
System.out.println(111);
}
}*/
Account account = new Account();
account.setName("110110110");
account.setPhoneNumber("110110110");
accountRepository.save(account);
Account byName = accountRepository.findByName("110110110").get();
byName.setParent("110");
accountRepository.save(byName);
}
} }
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