From 0ad75f90e6464b95bef06c88227f521c5c03d41d Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期六, 06 五月 2023 16:39:58 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAgentServiceImpl.java | 103 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 86 insertions(+), 17 deletions(-)
diff --git a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAgentServiceImpl.java b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAgentServiceImpl.java
index 7ad1181..3a4712f 100644
--- a/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAgentServiceImpl.java
+++ b/management/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/TAgentServiceImpl.java
@@ -21,6 +21,7 @@
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
+import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@@ -50,6 +51,8 @@
@Autowired
private TRechargeRecordMapper tRechargeRecordMapper;
+ @Autowired
+ private TUserToCouponMapper tUserToCouponMapper;
@Override
public EntityWrapper<TAgent> getAgentWrapper(String principal, String principalPhone, String createTime) {
@@ -74,6 +77,7 @@
wrapper.eq("id",ShiroKit.getUser().getObjectId());
}
wrapper.ne("status", StatusEnum.DELETE.getCode());
+ wrapper.orderBy("createTime",false);
return wrapper;
}
@@ -104,18 +108,32 @@
&& Objects.nonNull(order.getCouponId()) && order.getAgentId().equals(tAgent.getId())).collect(Collectors.toList());
model.addAttribute("usedCoupon",usedCoupon.size());
// 已使用优惠券金额求和,已使用优惠券id
- List<Integer> usedCouponId = usedCoupon.stream().map(TOrder::getCouponId).collect(Collectors.toList());
- // 查询已使用优惠券金额求和
- List<TCoupon> tCoupons1 = tCouponMapper.selectList(new EntityWrapper<TCoupon>().in("id", usedCouponId));
- if(CollectionUtils.isEmpty(tCoupons1)){
- model.addAttribute("couponPriceSum", BigDecimal.ZERO);
- }else {
- tCoupons1.stream().map(TCoupon::getCouponPreferentialAmount).reduce(BigDecimal::add).ifPresent(bigDecimal -> model.addAttribute("couponPriceSum", bigDecimal));
- }
+// List<Integer> usedCouponId = usedCoupon.stream().map(TOrder::getCouponId).collect(Collectors.toList());
+// if(CollectionUtils.isEmpty(usedCouponId)){
+// // 如果优惠券为空
+// model.addAttribute("couponPriceSum", BigDecimal.ZERO);
+// }else {
+// // 查询已使用优惠券金额求和
+// List<TCoupon> tCoupons1 = tCouponMapper.selectList(new EntityWrapper<TCoupon>().in("id", usedCouponId));
+// if(CollectionUtils.isEmpty(tCoupons1)){
+// model.addAttribute("couponPriceSum", BigDecimal.ZERO);
+// }else {
+// tCoupons1.stream().map(TCoupon::getCouponPreferentialAmount).reduce(BigDecimal::add).ifPresent(bigDecimal -> model.addAttribute("couponPriceSum", bigDecimal));
+// }
+// }
// 优惠券信息
// 过滤代理商发放的优惠券
- List<TCoupon> tCoupons = tCouponMapper.selectList(new EntityWrapper<TCoupon>());
- model.addAttribute("issuedCoupon",tCoupons.size());
+ List<TUserToCoupon> tUserToCoupons = tUserToCouponMapper.selectList(new EntityWrapper<TUserToCoupon>().eq("objectId",tAgent.getId())
+ .eq("roleType",3));
+ BigDecimal couponPriceSum = BigDecimal.ZERO;
+ for (TUserToCoupon userToCoupon : tUserToCoupons) {
+ TCoupon tCoupons1 = tCouponMapper.selectById(userToCoupon.getCouponId());
+ couponPriceSum = couponPriceSum.add(tCoupons1.getCouponPreferentialAmount().multiply(new BigDecimal(userToCoupon.getCouponTotal())));
+ }
+ model.addAttribute("couponPriceSum", couponPriceSum);
+ // 过滤代理商发放的优惠券
+ int sum = tUserToCoupons.stream().mapToInt(TUserToCoupon::getCouponTotal).sum();
+ model.addAttribute("issuedCoupon",sum);
// 司机信息
// 司机数
List<TDriver> drivers = tDriverMapper.selectList(new EntityWrapper<TDriver>().eq("agentId", tAgent.getId()));
@@ -138,6 +156,8 @@
List<TOrder> tOrders = tOrderMapper.selectList(new EntityWrapper<TOrder>());
// 查询优惠券
List<TCoupon> tCoupons = tCouponMapper.selectList(new EntityWrapper<TCoupon>());
+ // 用户
+ List<TUserToCoupon> tUserToCoupons = tUserToCouponMapper.selectList(new EntityWrapper<TUserToCoupon>());
// 查询司机信息
List<TDriver> tDrivers = tDriverMapper.selectList(new EntityWrapper<TDriver>());
@@ -162,16 +182,31 @@
&& Objects.nonNull(order.getCouponId()) && tAgent.getId().equals(order.getAgentId())).collect(Collectors.toList());
tAgentResp.setUsedCoupon(usedCoupon.size());
// 已使用优惠券金额求和,已使用优惠券id
- List<Integer> usedCouponId = usedCoupon.stream().map(TOrder::getCouponId).collect(Collectors.toList());
- // 查询已使用优惠券金额求和
- List<TCoupon> tCoupons1 = tCouponMapper.selectList(new EntityWrapper<TCoupon>().in("id", usedCouponId));
- tCoupons1.stream().map(TCoupon::getCouponPreferentialAmount).reduce(BigDecimal::add).ifPresent(tAgentResp::setCouponPriceSum);
+// List<Integer> usedCouponId = usedCoupon.stream().map(TOrder::getCouponId).collect(Collectors.toList());
+// if(CollectionUtils.isEmpty(usedCouponId)){
+// tAgentResp.setCouponPriceSum(BigDecimal.ZERO);
+// }else {
+// // 查询已使用优惠券金额求和
+// BigDecimal couponPriceSum = BigDecimal.ZERO;
+// for (Integer id : usedCouponId) {
+// TCoupon tCoupons1 = tCouponMapper.selectById(id);
+// couponPriceSum = couponPriceSum.add(tCoupons1.getCouponPreferentialAmount());
+// }
+// tAgentResp.setCouponPriceSum(couponPriceSum);
+// }
}
- if(!CollectionUtils.isEmpty(tCoupons)){
+ if(!CollectionUtils.isEmpty(tUserToCoupons)){
// 过滤代理商发放的优惠券
- List<TCoupon> coupons = tCoupons.stream().filter(coupon -> tAgent.getId().equals(coupon.getAgentId())).collect(Collectors.toList());
- tAgentResp.setIssuedCoupon(coupons.size());
+ List<TUserToCoupon> userToCoupons = tUserToCoupons.stream().filter(coupon -> tAgent.getId().equals(coupon.getObjectId()) && coupon.getRoleType() == 3).collect(Collectors.toList());
+ int sum = userToCoupons.stream().mapToInt(TUserToCoupon::getCouponTotal).sum();
+ tAgentResp.setIssuedCoupon(sum);
+ BigDecimal couponPriceSum = BigDecimal.ZERO;
+ for (TUserToCoupon userToCoupon : userToCoupons) {
+ TCoupon tCoupons1 = tCouponMapper.selectById(userToCoupon.getCouponId());
+ couponPriceSum = couponPriceSum.add(tCoupons1.getCouponPreferentialAmount().multiply(new BigDecimal(userToCoupon.getCouponTotal())));
+ }
+ tAgentResp.setCouponPriceSum(couponPriceSum);
}
if(!CollectionUtils.isEmpty(tDrivers)){
@@ -190,4 +225,38 @@
}
return tAgentRespList;
}
+
+ @Override
+ public void getDataStatistics(Integer agentId, Model model,Map<String, Object> map) {
+ // 代理商总数
+ Integer agentTotal = tAgentMapper.selectCount(new EntityWrapper<TAgent>()
+ .eq("id", agentId));
+ // 代理商最近一个月新增数量
+ LocalDate now = LocalDate.now();
+ LocalDate localDate = now.plusMonths(1);
+ Integer agentMonthTotal = tAgentMapper.selectCount(new EntityWrapper<TAgent>()
+ .eq("id", agentId)
+ .between("createTime", localDate, now));
+ model.addAttribute("agentTotal",agentTotal);
+ model.addAttribute("agentMonthTotal",agentMonthTotal);
+ map.put("agentTotal",agentTotal);
+ map.put("agentMonthTotal",agentMonthTotal);
+ }
+
+ @Override
+ public void getDataStatisticsByIds(List<Integer> ids, Model model, Map<String, Object> map) {
+ // 代理商总数
+ Integer agentTotal = tAgentMapper.selectCount(new EntityWrapper<TAgent>()
+ .in("id", ids));
+ // 代理商最近一个月新增数量
+ LocalDate now = LocalDate.now();
+ LocalDate localDate = now.plusMonths(1);
+ Integer agentMonthTotal = tAgentMapper.selectCount(new EntityWrapper<TAgent>()
+ .in("id", ids)
+ .between("createTime", localDate, now));
+ model.addAttribute("agentTotal",agentTotal);
+ model.addAttribute("agentMonthTotal",agentMonthTotal);
+ map.put("agentTotal",agentTotal);
+ map.put("agentMonthTotal",agentMonthTotal);
+ }
}
--
Gitblit v1.7.1