admin
2022-04-07 e1cc0d03fadc2d251d36c0dc3650f75e830d5363
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.yeshi.makemoney.app.service.impl.goldcorn;
 
import java.lang.Exception;
import javax.annotation.Resource;
 
import com.ks.lib.common.exception.ParamsException;
import com.yeshi.makemoney.app.entity.SystemEnum;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
 
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.bean.BeanUtil;
 
import java.util.List;
 
import com.yeshi.makemoney.app.dao.goldcorn.GoldCornMoneyExchangeRateRecordDao;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornMoneyExchangeRateRecord;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornMoneyExchangeRateRecordService;
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornMoneyExchangeRateRecordQuery;
import com.yeshi.makemoney.app.dao.goldcorn.GoldCornMoneyExchangeRateRecordDao.DaoQuery;
 
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
 
@Service
public class GoldCornMoneyExchangeRateRecordServiceImpl implements GoldCornMoneyExchangeRateRecordService {
 
    @Resource
    private GoldCornMoneyExchangeRateRecordDao goldCornMoneyExchangeRateRecordDao;
 
    @Override
    public List<GoldCornMoneyExchangeRateRecord> list(GoldCornMoneyExchangeRateRecordQuery goldCornMoneyExchangeRateRecordQuery, int page, int pageSize) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(goldCornMoneyExchangeRateRecordQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        return goldCornMoneyExchangeRateRecordDao.list(daoQuery);
    }
 
    @Override
    public long count(GoldCornMoneyExchangeRateRecordQuery goldCornMoneyExchangeRateRecordQuery) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(goldCornMoneyExchangeRateRecordQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return goldCornMoneyExchangeRateRecordDao.count(daoQuery);
    }
 
    @Override
    public GoldCornMoneyExchangeRateRecord get(String id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("_id").is(id));
        return goldCornMoneyExchangeRateRecordDao.findOne(query);
    }
 
    @Override
    public void add(GoldCornMoneyExchangeRateRecord goldCornMoneyExchangeRateRecord) throws Exception {
 
 
        if (goldCornMoneyExchangeRateRecord.getCreateTime() == null) {
            goldCornMoneyExchangeRateRecord.setCreateTime(new Date());
        }
 
        if (goldCornMoneyExchangeRateRecord.getId() == null) {
            goldCornMoneyExchangeRateRecord.setId(goldCornMoneyExchangeRateRecord.toId());
        }
 
        //查询主键ID是否存在
        if (goldCornMoneyExchangeRateRecordDao.get(goldCornMoneyExchangeRateRecord.getId()) != null) {
            throw new Exception("已存在");
        }
 
 
        //保存
        goldCornMoneyExchangeRateRecordDao.save(goldCornMoneyExchangeRateRecord);
    }
 
    @Override
    public void update(GoldCornMoneyExchangeRateRecord goldCornMoneyExchangeRateRecord) {
        if (goldCornMoneyExchangeRateRecord.getUpdateTime() == null) {
            goldCornMoneyExchangeRateRecord.setUpdateTime(new Date());
        }
        //更新
        goldCornMoneyExchangeRateRecordDao.updateSelective(goldCornMoneyExchangeRateRecord);
    }
 
    @Override
    public void delete(List<String> idList) {
        for (String id : idList) {
            goldCornMoneyExchangeRateRecordDao.delete(id);
        }
    }
 
    @Override
    public BigDecimal getRate(String day, SystemEnum system, Date time) throws ParamsException {
        if (StringUtil.isNullOrEmpty(day) || system == null || time == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "参数不完整");
        }
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.day = day;
        daoQuery.maxValidateTime = time;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.desc("validateTime")});
        daoQuery.count = 1;
        daoQuery.system = system;
        List<GoldCornMoneyExchangeRateRecord> list = goldCornMoneyExchangeRateRecordDao.list(daoQuery);
        if (list != null && list.size() > 0) {
            return list.get(0).getRate();
        }
        return null;
    }
 
 
}