You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.0 KiB

  1. package com.example.demo.serviceImpl;
  2. import com.example.demo.domain.vo.Consume;
  3. import com.example.demo.domain.vo.Gold;
  4. import com.example.demo.mapper.ConsumeMapper;
  5. import com.example.demo.service.ConsumeService;
  6. import com.github.pagehelper.PageHelper;
  7. import com.github.pagehelper.PageInfo;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import java.util.List;
  11. /**
  12. * @program: gold-java
  13. * @ClassName ConsumeServiceImpl
  14. * @description: 消费模块
  15. * @author: Double
  16. * @create: 202506-23 13:58
  17. * @Version 1.0
  18. **/
  19. @Service
  20. public class ConsumeServiceImpl implements ConsumeService {
  21. @Autowired
  22. private ConsumeMapper consumeMapper;
  23. //消耗明细
  24. @Override
  25. public PageInfo<Consume> selectAll(Integer pageNum, Integer pageSize) {
  26. PageHelper.startPage(pageNum, pageSize);
  27. List<Consume> consumes = consumeMapper.selectAll();
  28. return new PageInfo<>(consumes);
  29. }
  30. //消耗金币统计
  31. @Override
  32. public Gold statsGold() {
  33. Gold gold = new Gold();
  34. List<Consume> consumes = consumeMapper.selectAll();
  35. // 初始化累加器
  36. int permanentGoldSum = 0;
  37. int freeGoldSum = 0;
  38. int taskGoldSum = 0;
  39. // 遍历消费记录并累加金币
  40. for (Consume consume : consumes) {
  41. // 累加永久金币
  42. if (consume.getPermanentGold() != null) {
  43. permanentGoldSum += consume.getPermanentGold();
  44. }
  45. // 累加免费金币
  46. if (consume.getFreeGold() != null) {
  47. freeGoldSum += consume.getFreeGold();
  48. }
  49. // 累加任务金币
  50. if (consume.getTaskGold() != null) {
  51. taskGoldSum += consume.getTaskGold();
  52. }
  53. }
  54. // 将累加结果设置到Gold对象
  55. gold.setPermanentGolds(permanentGoldSum);
  56. gold.setFreeGolds(freeGoldSum);
  57. gold.setTaskGolds(taskGoldSum);
  58. return gold;
  59. }
  60. }