|
|
@ -1,6 +1,7 @@ |
|
|
|
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 org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -23,9 +24,45 @@ public class ConsumeServiceImpl implements ConsumeService { |
|
|
|
@Autowired |
|
|
|
private ConsumeMapper consumeMapper; |
|
|
|
|
|
|
|
//消耗明细 |
|
|
|
@Override |
|
|
|
public List<Consume> selectAll() { |
|
|
|
List<Consume> consumes = consumeMapper.selectAll(); |
|
|
|
return 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; |
|
|
|
} |
|
|
|
} |