| | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.makemoney.app.exception.goldcorn.GoldCornConsumeRecordException; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationOperation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import org.yeshi.utils.bean.BeanUtil; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.yeshi.makemoney.app.dao.goldcorn.GoldCornConsumeRecordDao; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord; |
| | |
| | | @Resource |
| | | private GoldCornConsumeRecordDao goldCornConsumeRecordDao; |
| | | |
| | | @Override |
| | | public List<GoldCornConsumeRecord> list(GoldCornConsumeRecordQuery goldCornConsumeRecordQuery, int page, int pageSize) { |
| | | private DaoQuery createDaoQuery(GoldCornConsumeRecordQuery goldCornConsumeRecordQuery) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.type = goldCornConsumeRecordQuery.getType(); |
| | | daoQuery.uid = goldCornConsumeRecordQuery.getUid(); |
| | | daoQuery.minCreateTime = goldCornConsumeRecordQuery.toStartTime(); |
| | | daoQuery.maxCreateTime = goldCornConsumeRecordQuery.toEndTime(); |
| | | daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.desc("createTime")}); |
| | | daoQuery.eventId = goldCornConsumeRecordQuery.getEventId(); |
| | | return daoQuery; |
| | | } |
| | | |
| | | @Override |
| | | public List<GoldCornConsumeRecord> list(GoldCornConsumeRecordQuery goldCornConsumeRecordQuery, int page, int pageSize) { |
| | | DaoQuery daoQuery = createDaoQuery(goldCornConsumeRecordQuery); |
| | | daoQuery.start = (page - 1) * pageSize; |
| | | daoQuery.count = pageSize; |
| | | return goldCornConsumeRecordDao.list(daoQuery); |
| | |
| | | |
| | | @Override |
| | | public long count(GoldCornConsumeRecordQuery goldCornConsumeRecordQuery) { |
| | | DaoQuery daoQuery = new DaoQuery(); |
| | | daoQuery.type = goldCornConsumeRecordQuery.getType(); |
| | | daoQuery.uid = goldCornConsumeRecordQuery.getUid(); |
| | | daoQuery.minCreateTime = goldCornConsumeRecordQuery.toStartTime(); |
| | | daoQuery.maxCreateTime = goldCornConsumeRecordQuery.toEndTime(); |
| | | DaoQuery daoQuery = createDaoQuery(goldCornConsumeRecordQuery); |
| | | return goldCornConsumeRecordDao.count(daoQuery); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal sumMoney(GoldCornConsumeRecordQuery query) { |
| | | Criteria criteria = goldCornConsumeRecordDao.getCriteria(createDaoQuery(query)); |
| | | List<AggregationOperation> list = new ArrayList<>(); |
| | | if (criteria != null) { |
| | | list.add(Aggregation.match(criteria)); |
| | | } |
| | | list.add(Aggregation.project("money")); |
| | | |
| | | list.add(Aggregation.group().sum("money").as("money")); |
| | | AggregationResults<Map> results = goldCornConsumeRecordDao.aggregate(list, Map.class); |
| | | Object money = results.getUniqueMappedResult().get("money"); |
| | | return money == null ? new BigDecimal(0) : new BigDecimal(money + "").divide(new BigDecimal(100), 2, RoundingMode.FLOOR); |
| | | } |
| | | |
| | | |
| | | } |