From 91730b4f7dd828691ee52dbea339a0efc5a8648b Mon Sep 17 00:00:00 2001 From: bynt Date: Mon, 8 May 2023 10:21:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/domain/vo/CallDeductDataVO.java | 58 +++++++++++++++++++ .../repository/CallDeductRepository.java | 6 +- .../service/impl/CallDeductServiceImpl.java | 33 ++++------- .../com/baiye/timed/ReportDeductsSync.java | 9 +-- 4 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/vo/CallDeductDataVO.java diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/vo/CallDeductDataVO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/vo/CallDeductDataVO.java new file mode 100644 index 00000000..c56e230e --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/vo/CallDeductDataVO.java @@ -0,0 +1,58 @@ +package com.baiye.modules.platform.domain.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import java.util.Date; + +/** + * @author Enzo + * @date : 2022/11/9 + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class CallDeductDataVO { + + private Long id; + @ApiModelProperty(value = "扣减时长") + private Integer deductDuration; + + @ApiModelProperty(value = "扣减金额") + private Double deductAmount; + + @ApiModelProperty(value = "线索id") + private Long clueId; + + @ApiModelProperty(value = "人员id") + private Long memberId; + + @ApiModelProperty(value = "所属公司") + private Long companyId; + + @ApiModelProperty(value = "状态") + private Boolean status; + + @ApiModelProperty(value = "扣减时的版本号") + private Integer version; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "消费类型1 话费消耗 2 套餐充值 3 余额充值 4 资源兑换") + private Integer type; + + @ApiModelProperty(value = "套餐类型") + private String comboType; + + + @ApiModelProperty(value = "用户名") + private String username; + + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java index 62fc04a7..3fefade7 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java @@ -17,6 +17,7 @@ package com.baiye.modules.platform.repository; import cn.hutool.core.date.DateTime; import com.baiye.modules.platform.domain.CallDeduct; +import com.baiye.modules.platform.domain.vo.CallDeductDataVO; import com.baiye.modules.platform.domain.vo.CallDeductVO; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; @@ -52,8 +53,9 @@ public interface CallDeductRepository extends JpaRepository, J * @param endDate * @return */ - @Query(value = "from CallDeduct where companyId = ?1 and createTime >= ?2 and createTime <= ?3") - List queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate); + @Query(value = "SELECT new com.baiye.modules.platform.domain.vo.CallDeductDataVO(c.id,c.deductDuration,c.deductAmount," + + " c.clueId, c.memberId,c.companyId,c.status,c.version,c.createTime,c.type,c.comboType,u.username) FROM CallDeduct c, User u WHERE u.id = c.memberId and c.companyId = ?1 and c.createTime between ?2 and ?3") + List queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate); /** * 公司id查找记录 diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CallDeductServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CallDeductServiceImpl.java index 94e72f0d..c30c2c6e 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CallDeductServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CallDeductServiceImpl.java @@ -8,6 +8,8 @@ import cn.hutool.core.text.StrPool; import cn.hutool.core.util.ObjectUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.modules.platform.domain.CallDeduct; +import com.baiye.modules.platform.domain.Company; +import com.baiye.modules.platform.domain.vo.CallDeductDataVO; import com.baiye.modules.system.domain.User; import com.baiye.modules.platform.domain.vo.CallDeductResponseVO; import com.baiye.modules.platform.domain.vo.CallDeductVO; @@ -29,10 +31,7 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Enzo @@ -91,24 +90,18 @@ public class CallDeductServiceImpl implements CallDeductService { Map map = Maps.newHashMap(); String queryTime = criteria.getQueryTime(); DateTime parse = DateUtil.parse(queryTime, DatePattern.NORM_MONTH_PATTERN); - DateTime endDate = DateUtil.offsetMonth(parse, DefaultNumberConstants.ONE_NUMBER); - List deductList = + DateTime endDate = DateUtil.offsetMonth(parse, DefaultNumberConstants.FIVE_NUMBER); + List deductList = callDeductRepository.queryByCompanyIdAndTime (companyId, parse, endDate); - deductList.forEach(deduct -> { - User byId = userRepository.findById(deduct.getMemberId()).orElseGet(User::new); - if (ObjectUtil.isNotNull(byId)) { - deduct.setUsername(byId.getUsername()); - } - }); - List list = PageUtil.toPage(pageable.getPageNumber(), + List list = PageUtil.toPage(pageable.getPageNumber(), pageable.getPageSize(), deductList); - CompanyDto companyById = companyService.findCompanyById(companyId); + Company byId = companyService.findById(companyId); map.put("content", list); map.put("chargeBill", queryTime); map.put("totalElements", deductList.size()); - map.put("companyName", companyById.getCompanyName()); + map.put("companyName", byId.getCompanyName()); map.put("billTarikh", DateUtil.format(endDate, DatePattern.NORM_DATE_PATTERN)); return map; } @@ -130,18 +123,12 @@ public class CallDeductServiceImpl implements CallDeductService { String queryTime = criteria.getQueryTime(); DateTime parse = DateUtil.parse(queryTime, "yyyy-MM"); DateTime endDate = DateUtil.offsetMonth(parse, DefaultNumberConstants.ONE_NUMBER); - List deductList = + List deductList = callDeductRepository.queryByCompanyIdAndTime (companyId, parse, endDate); - deductList.forEach(deduct -> { - User byId = userRepository.findById(deduct.getMemberId()).orElseGet(User::new); - if (ObjectUtil.isNotNull(byId)) { - deduct.setUsername(byId.getUsername()); - } - }); List> list = new ArrayList<>(); - for (CallDeduct deduct : deductList) { + for (CallDeductDataVO deduct : deductList) { Map map = new LinkedHashMap<>(); map.put("账号名称", deduct.getUsername()); map.put("费用类型", deduct.getType() == DefaultNumberConstants.ONE_NUMBER ? "日结话费" : "套餐充值"); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java index 8a69e75a..99adbab5 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import com.baiye.modules.platform.domain.CallDeduct; +import com.baiye.modules.platform.domain.vo.CallDeductDataVO; import com.baiye.modules.platform.repository.CallDeductRepository; import com.baiye.modules.platform.repository.CompanyRepository; import com.baiye.modules.report.dao.ReportDeductRepository; @@ -56,10 +57,10 @@ public class ReportDeductsSync { } List list = new ArrayList<>(); - List callDeducts; + if (companyId != null) { - callDeducts = callDeductRepository.queryByCompanyIdAndTime(companyId, beginOfDay, endOfDay); - double sum = callDeducts.stream().mapToDouble(CallDeduct::getDeductAmount).sum(); + List callDeducts = callDeductRepository.queryByCompanyIdAndTime(companyId, beginOfDay, endOfDay); + double sum = callDeducts.stream().mapToDouble(CallDeductDataVO::getDeductAmount).sum(); ReportDeduct reportDeduct = new ReportDeduct(); reportDeduct.setDeductAmount(sum); reportDeduct.setBalance(map.get(companyId) == null ? 0.0 : map.get(companyId)); @@ -67,7 +68,7 @@ public class ReportDeductsSync { reportDeduct.setCompanyId(companyId); list.add(reportDeduct); } else { - callDeducts = callDeductRepository.queryByCompanyIdAndTime(beginOfDay, endOfDay); + List callDeducts = callDeductRepository.queryByCompanyIdAndTime(beginOfDay, endOfDay); Map> collect = callDeducts.stream().collect(Collectors.groupingBy(CallDeduct::getCompanyId, Collectors.toList())); for (Long key : map.keySet()) { ReportDeduct reportDeduct = new ReportDeduct();