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
71 lines
2.0 KiB
package com.example.demo.serviceImpl;
|
|
|
|
import com.example.demo.domain.vo.Consume;
|
|
import com.example.demo.domain.vo.Gold;
|
|
import com.example.demo.mapper.ConsumeMapper;
|
|
import com.example.demo.service.ConsumeService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @program: gold-java
|
|
* @ClassName ConsumeServiceImpl
|
|
* @description: 消费模块
|
|
* @author: Double
|
|
* @create: 2025−06-23 13:58
|
|
* @Version 1.0
|
|
**/
|
|
|
|
@Service
|
|
public class ConsumeServiceImpl implements ConsumeService {
|
|
|
|
@Autowired
|
|
private ConsumeMapper consumeMapper;
|
|
|
|
//消耗明细
|
|
@Override
|
|
public PageInfo<Consume> selectAll(Integer pageNum, Integer pageSize) {
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
List<Consume> consumes = consumeMapper.selectAll();
|
|
return new PageInfo<>(consumes);
|
|
}
|
|
|
|
//消耗金币统计
|
|
@Override
|
|
public Gold statsGold() {
|
|
Gold gold = new Gold();
|
|
List<Consume> consumes = consumeMapper.selectAll();
|
|
|
|
// 初始化累加器
|
|
int permanentGoldSum = 0;
|
|
int freeGoldSum = 0;
|
|
int taskGoldSum = 0;
|
|
|
|
// 遍历消费记录并累加金币
|
|
for (Consume consume : consumes) {
|
|
// 累加永久金币
|
|
if (consume.getPermanentGold() != null) {
|
|
permanentGoldSum += consume.getPermanentGold();
|
|
}
|
|
// 累加免费金币
|
|
if (consume.getFreeGold() != null) {
|
|
freeGoldSum += consume.getFreeGold();
|
|
}
|
|
// 累加任务金币
|
|
if (consume.getTaskGold() != null) {
|
|
taskGoldSum += consume.getTaskGold();
|
|
}
|
|
}
|
|
|
|
// 将累加结果设置到Gold对象
|
|
gold.setPermanentGolds(permanentGoldSum);
|
|
gold.setFreeGolds(freeGoldSum);
|
|
gold.setTaskGolds(taskGoldSum);
|
|
|
|
return gold;
|
|
}
|
|
}
|