admin
2021-11-19 7511509c68bd2892aad48a0612d497387660214d
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.yeshi.location.app.service.impl.vip;
 
import java.lang.Exception;
import javax.annotation.Resource;
 
import com.yeshi.location.app.entity.SystemEnum;
import com.yeshi.location.app.entity.vip.VIPPriceType;
import com.yeshi.location.app.exception.vip.VIPException;
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.location.app.dao.vip.VIPPriceDao;
import com.yeshi.location.app.entity.vip.VIPPrice;
import com.yeshi.location.app.service.inter.vip.VIPPriceService;
import com.yeshi.location.app.service.query.vip.VIPPriceQuery;
import com.yeshi.location.app.dao.vip.VIPPriceDao.DaoQuery;
 
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
 
@Service
public class VIPPriceServiceImpl implements VIPPriceService {
 
    @Resource
    private VIPPriceDao vIPPriceDao;
 
    @Override
    public List<VIPPrice> list(VIPPriceQuery vIPPriceQuery, int page, int pageSize) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(vIPPriceQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.asc("order")});
        return vIPPriceDao.list(daoQuery);
    }
 
    @Override
    public long count(VIPPriceQuery vIPPriceQuery) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(vIPPriceQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return vIPPriceDao.count(daoQuery);
    }
 
    @Override
    public VIPPrice get(String id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("_id").is(id));
        return vIPPriceDao.findOne(query);
    }
 
    @Override
    public void add(VIPPrice price) throws Exception {
        if (price == null || price.getSystem() == null || price.getActualPrice() == null || price.getType() == null) {
            throw new VIPException(1, "参数不完整");
        }
 
        if (price.getCreateTime() == null) {
            price.setCreateTime(new Date());
        }
 
        if (price.getOrder() == null) {
            price.setOrder(price.getActualPrice().multiply(new BigDecimal(100)).intValue());
        }
 
 
        price.setId(price.getSystem().name() + "-" + StringUtil.Md5(price.getType().name()));
        vIPPriceDao.save(price);
    }
 
    @Override
    public void update(VIPPrice vIPPrice) {
        if (vIPPrice.getUpdateTime() == null) {
            vIPPrice.setUpdateTime(new Date());
        }
        //更新
        vIPPriceDao.updateSelective(vIPPrice);
    }
 
    @Override
    public void delete(List<String> idList) {
        for (String id : idList) {
            vIPPriceDao.delete(id);
        }
    }
 
 
    @Override
    public List<VIPPrice> listValidPrice(SystemEnum system) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.count = Integer.MAX_VALUE;
        daoQuery.system = system;
        daoQuery.show = true;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.asc("order")});
        return vIPPriceDao.list(daoQuery);
    }
 
    @Override
    public VIPPrice selectByPrimaryKey(String id) {
        return vIPPriceDao.get(id);
    }
 
    @Override
    public VIPPrice selectByType(VIPPriceType type, SystemEnum system) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.type = type;
        daoQuery.system = system;
        daoQuery.count = 1;
 
        List<VIPPrice> list = vIPPriceDao.list(daoQuery);
        if (list == null || list.size() == 0) {
            return null;
        }
        return list.get(0);
    }
 
    @Override
    public VIPPrice selectByIOSProductId(String productId, SystemEnum system) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.iosProductId = productId;
        daoQuery.system = system;
 
        List<VIPPrice> list = vIPPriceDao.list(daoQuery);
        if (list == null || list.size() == 0) {
            return null;
        }
        return list.get(0);
    }
 
 
}