DeviceAlgorithmChargingHistoryServiceImpl.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.xy.service;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.map.MapUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  7. import com.xy.collections.list.JArrayList;
  8. import com.xy.dto.*;
  9. import com.xy.dto.be.MercDto;
  10. import com.xy.entity.DeviceAlgorithmChargingHistory;
  11. import com.xy.mapper.DeviceAlgorithmChargingHistoryMapper;
  12. import com.xy.service.be.MercService;
  13. import com.xy.utils.*;
  14. import io.swagger.annotations.Api;
  15. import io.swagger.annotations.ApiOperation;
  16. import lombok.AllArgsConstructor;
  17. import org.springframework.stereotype.Service;
  18. import org.springframework.web.bind.annotation.RequestBody;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.stream.Collectors;
  23. import static com.xy.utils.Beans.copy;
  24. import static com.xy.utils.PlusBeans.toIPage;
  25. import static com.xy.utils.PlusBeans.toPageBean;
  26. /**
  27. * <p>
  28. * 设备算法计费历史表 服务实现类
  29. * </p>
  30. *
  31. * @author lijin
  32. * @since 2023-06-29
  33. */
  34. @Service
  35. @AllArgsConstructor
  36. @Api(tags = "设备算法计费历史表")
  37. public class DeviceAlgorithmChargingHistoryServiceImpl extends ServiceImpl<DeviceAlgorithmChargingHistoryMapper, DeviceAlgorithmChargingHistory> implements DeviceAlgorithmChargingHistoryService {
  38. private OrderMercManageService orderMercManageService;
  39. private MercService mercService;
  40. private DeviceTypeAlgorithmBeforConfigServiceImpl deviceTypeAlgorithmBeforConfigService;
  41. private DeviceInfoService deviceInfoService;
  42. private MercFeeConfigService mercFeeConfigService;
  43. @Override
  44. @ApiOperation("分页查询")
  45. public R<PageBean<DeviceAlgorithmChargingHistoryDto.Vo>> page(@RequestBody DeviceAlgorithmChargingHistoryDto.Page page) {
  46. LambdaQueryWrapper<DeviceAlgorithmChargingHistory> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceAlgorithmChargingHistory.class).build();
  47. IPage<DeviceAlgorithmChargingHistory> iPage = page(PlusBeans.toIPage(page.getPage()), lambdaQueryWrapper);
  48. PageBean<DeviceAlgorithmChargingHistoryDto.Vo> pageBean = toPageBean(DeviceAlgorithmChargingHistoryDto.Vo.class, iPage);
  49. List<DeviceAlgorithmChargingHistoryDto.Vo> records = pageBean.getRecords();
  50. if (Emptys.check(records)) {
  51. copy(records).target(
  52. () -> orderMercManageService.list(new OrderMercManageDto.SelectList().setId(new JArrayList<>(records).getProperty(DeviceAlgorithmChargingHistoryDto.Vo::getOrderId))).getData()
  53. , DeviceAlgorithmChargingHistoryDto.Vo::getOrderId, DeviceAlgorithmChargingHistoryDto.Vo::getFiles, OrderMercManageDto.Vo::getId, OrderMercManageDto.Vo::getFiles
  54. ).builder();
  55. }
  56. return R.ok(pageBean);
  57. }
  58. public R<PageBean<DeviceAlgorithmChargingHistoryDto.PageByTopMercVO>> pageByTopMerc(DeviceAlgorithmChargingHistoryDto.PageByTopMerc page) {
  59. Long curMercId = page.getCurMercId();
  60. Long chooseMercId = page.getChooseMercId();
  61. List<Long> mercIds = new ArrayList<>();
  62. if (chooseMercId == null) {
  63. mercIds = R.feignCheckData(mercService.getChildMercIds(new MercDto.QuerySubDTO().setParentMercID(curMercId)));
  64. } else {
  65. // 指定商户ID
  66. mercIds.add(chooseMercId);
  67. }
  68. if (CollUtil.isEmpty(mercIds)) {
  69. return R.ok();
  70. }
  71. PageBean pageBean = page.getPage();
  72. LambdaQueryWrapper<DeviceAlgorithmChargingHistory> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceAlgorithmChargingHistory.class)
  73. .ge(DeviceAlgorithmChargingHistory::getCreateTime, page.getBeginCreateTime())
  74. .le(DeviceAlgorithmChargingHistory::getCreateTime, page.getEndCreateTime())
  75. .in(DeviceAlgorithmChargingHistory::getMercId, mercIds)
  76. .build()
  77. .orderByDesc(!Emptys.check(pageBean.getOrders()), DeviceAlgorithmChargingHistory::getCreateTime);
  78. IPage<DeviceAlgorithmChargingHistory> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
  79. PageBean<DeviceAlgorithmChargingHistoryDto.PageByTopMercVO> voPageBean = toPageBean(DeviceAlgorithmChargingHistoryDto.PageByTopMercVO.class, iPage);
  80. List<DeviceAlgorithmChargingHistoryDto.PageByTopMercVO> records = voPageBean.getRecords();
  81. if (Emptys.check(records)) {
  82. // 佣金配置查询
  83. List<MercFeeConfigDto.ListFeeConfigByMercVO> feeConfigByMercVOS = R.feignCheckData(mercFeeConfigService.listFeeConfigByMerc(new MercFeeConfigDto.ListFeeConfigByMercDTO().setMercId(curMercId)));
  84. Map<Long, MercFeeConfigDto.ListFeeConfigByMercVO> configByMercVOMap = MapUtil.newHashMap();
  85. if (CollUtil.isNotEmpty(feeConfigByMercVOS)) {
  86. configByMercVOMap = feeConfigByMercVOS.stream().collect(Collectors.toMap(MercFeeConfigDto.ListFeeConfigByMercVO::getMercId, f -> f));
  87. }
  88. List<Long> deviceIds = records.stream().map(DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getDeviceId).distinct().collect(Collectors.toList());
  89. List<DeviceInfoDto.Vo> deviceList = R.feignCheckData(deviceInfoService.listCommon(new DeviceInfoDto.ListCommon().setDeviceIds(deviceIds)));
  90. Map<Long, DeviceInfoDto.Vo> devcieMap = deviceList.stream().collect(Collectors.toMap(DeviceInfoDto.Vo::getDeviceId, d -> d));
  91. copy(records)
  92. .target(() -> orderMercManageService.list(new OrderMercManageDto.SelectList().setId(new JArrayList<>(records).getProperty(DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getOrderId))).getData()
  93. , DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getOrderId, DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getFiles, OrderMercManageDto.Vo::getId, OrderMercManageDto.Vo::getFiles
  94. ).target(() -> mercService.list(new MercDto.SelectList().setMercIds(new JArrayList<>(records).getProperty(DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getMercId).comparing())).getData()
  95. , DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getMercId, DeviceAlgorithmChargingHistoryDto.PageByTopMercVO::getMercName, MercDto.Vo::getId, MercDto.Vo::getName)
  96. .builder();
  97. for (DeviceAlgorithmChargingHistoryDto.PageByTopMercVO record : records) {
  98. // 初始0 佣金费用
  99. int extraMoney = 0;
  100. Long mercId = record.getMercId();
  101. MercFeeConfigDto.ListFeeConfigByMercVO listFeeConfigByMercVO = configByMercVOMap.get(mercId);
  102. if (listFeeConfigByMercVO != null) {
  103. extraMoney = listFeeConfigByMercVO.getFeeConfig().getFeeActive();
  104. }
  105. record.setAgentMoney(extraMoney);
  106. }
  107. }
  108. return R.ok(voPageBean);
  109. }
  110. /**
  111. * 财务管理-支出管理-设备激活费明细
  112. *
  113. * @param page
  114. * @return
  115. */
  116. public R<PageBean<DeviceAlgorithmChargingHistoryDto.MySpendPageVO>> mySpendPage(DeviceAlgorithmChargingHistoryDto.PageByTopMerc page) {
  117. Long curMercId = page.getCurMercId();
  118. List<Long> mercIds = new ArrayList<>();
  119. // 指定商户ID
  120. mercIds.add(curMercId);
  121. PageBean pageBean = page.getPage();
  122. LambdaQueryWrapper<DeviceAlgorithmChargingHistory> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, DeviceAlgorithmChargingHistory.class)
  123. .ge(DeviceAlgorithmChargingHistory::getCreateTime, page.getBeginCreateTime())
  124. .le(DeviceAlgorithmChargingHistory::getCreateTime, page.getEndCreateTime())
  125. .in(DeviceAlgorithmChargingHistory::getMercId, mercIds)
  126. .build()
  127. .orderByDesc(!Emptys.check(pageBean.getOrders()), DeviceAlgorithmChargingHistory::getCreateTime);
  128. IPage<DeviceAlgorithmChargingHistory> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
  129. PageBean<DeviceAlgorithmChargingHistoryDto.MySpendPageVO> voPageBean = toPageBean(DeviceAlgorithmChargingHistoryDto.MySpendPageVO.class, iPage);
  130. List<DeviceAlgorithmChargingHistoryDto.MySpendPageVO> records = voPageBean.getRecords();
  131. if (Emptys.check(records)) {
  132. List<OrderMercManageDto.Vo> orderMercManages = orderMercManageService.list(new OrderMercManageDto.SelectList().setId(new JArrayList<>(records).getProperty(DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getOrderId))).getData();
  133. copy(records)
  134. .target(() -> orderMercManages, DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getOrderId, DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getFiles, OrderMercManageDto.Vo::getId, OrderMercManageDto.Vo::getFiles)
  135. .target(() -> orderMercManages, DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getOrderId, DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getBalanceMone, OrderMercManageDto.Vo::getId, OrderMercManageDto.Vo::getBalanceMoney)
  136. .target(() -> mercService.list(new MercDto.SelectList().setMercIds(new JArrayList<>(records).getProperty(DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getMercId).comparing())).getData()
  137. , DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getMercId, DeviceAlgorithmChargingHistoryDto.MySpendPageVO::getMercName, MercDto.Vo::getId, MercDto.Vo::getName)
  138. .builder();
  139. }
  140. return R.ok(voPageBean);
  141. }
  142. }