yujian
2019-11-11 3ce9e928e082ff8abf697dba560cbfbb412e89f8
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
148
149
150
151
152
153
154
155
156
package com.yeshi.fanli.service.impl.shop;
 
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.mybatis.shop.BanLiShopGoodsSetsPayMapper;
import com.yeshi.fanli.entity.shop.BanLiShopGoodsSetsPay;
import com.yeshi.fanli.exception.shop.BanLiShopGoodsSetPayException;
import com.yeshi.fanli.service.inter.shop.BanLiShopGoodsSetPayService;
 
@Service
public class BanLiShopGoodsSetPayServiceImpl implements BanLiShopGoodsSetPayService {
 
    @Resource
    private BanLiShopGoodsSetsPayMapper banLiShopGoodsSetsPayMapper;
 
    @Override
    public List<BanLiShopGoodsSetsPay> listByGoodsSetId(Long goodsSetId) {
        return banLiShopGoodsSetsPayMapper.listByGoodsSetId(goodsSetId);
    }
 
    @Override
    public int countByGoodsSetId(Long goodsSetId) {
        return (int) banLiShopGoodsSetsPayMapper.countByGoodsSetId(goodsSetId);
    }
 
    @Override
    public BanLiShopGoodsSetsPay selectByPrimaryKey(Long id) {
        return banLiShopGoodsSetsPayMapper.selectByPrimaryKey(id);
    }
 
    @Transactional
    @Override
    public void addSetPay(BanLiShopGoodsSetsPay pay) throws BanLiShopGoodsSetPayException {
        if (pay.getId() == null)// 新增
        {
            // 判断参数是否齐全
            if (pay.getGoodsSet() == null || pay.getGoodsSet().getId() == null)
                throw new BanLiShopGoodsSetPayException(1, "套餐不存在");
 
            if (pay.getPayType() == null)
                throw new BanLiShopGoodsSetPayException(1, "请指定支付方式");
 
            if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO) {
                if (pay.getHongBaoPrice() == null)
                    throw new BanLiShopGoodsSetPayException(1, "请指定价格");
            } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_BALANCE) {
                if (pay.getBalancePrice() == null)
                    throw new BanLiShopGoodsSetPayException(1, "请指定价格");
            } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO_MONEY) {
                if (pay.getHongBaoPrice() == null || pay.getMoneyPrice() == null)
                    throw new BanLiShopGoodsSetPayException(1, "请指定价格");
            } else if (pay.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_MONEY) {
                if (pay.getMoneyPrice() == null)
                    throw new BanLiShopGoodsSetPayException(1, "请指定价格");
            }
            if (pay.getCreateTime() == null)
                pay.setCreateTime(new Date());
            banLiShopGoodsSetsPayMapper.insertSelective(pay);
 
            if (pay.getWeight() == null) {// 权重更新
                BanLiShopGoodsSetsPay update = new BanLiShopGoodsSetsPay();
                update.setId(pay.getId());
                update.setWeight((int) pay.getId().longValue());
                banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(update);
            }
        } else {// 修改
            updateSelectiveByPrimaryKey(pay);
        }
    }
    
    @Override
    public void saveObject(BanLiShopGoodsSetsPay record) throws BanLiShopGoodsSetPayException {
        // 判断参数是否齐全
        if (record.getGoodsSet() == null || record.getGoodsSet().getId() == null)
            throw new BanLiShopGoodsSetPayException(1, "套餐不存在");
 
        if (record.getPayType() == null)
            throw new BanLiShopGoodsSetPayException(1, "请指定支付方式");
 
        if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO) {
            if (record.getHongBaoPrice() == null)
                throw new BanLiShopGoodsSetPayException(1, "请指定红包支付价格");
        } else if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_BALANCE) {
            if (record.getBalancePrice() == null)
                throw new BanLiShopGoodsSetPayException(1, "请指定余额支付价格");
        } else if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_HONGBAO_MONEY) {
            if (record.getHongBaoPrice() == null || record.getMoneyPrice() == null)
                throw new BanLiShopGoodsSetPayException(1, "请指定红包、现金支付价格");
        } else if (record.getPayType() == BanLiShopGoodsSetsPay.PAY_TYPE_MONEY) {
            if (record.getMoneyPrice() == null)
                throw new BanLiShopGoodsSetPayException(1, "请指定现金支付价格");
        }
 
        record.setUpdateTime(new Date());
        if (record.getId() == null) {
            record.setCreateTime(new Date());
            banLiShopGoodsSetsPayMapper.insertSelective(record);
 
            if (record.getWeight() == null) {// 权重更新
                BanLiShopGoodsSetsPay update = new BanLiShopGoodsSetsPay();
                update.setId(record.getId());
                update.setWeight((int) record.getId().longValue());
                banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(update);
            }
        } else {
            BanLiShopGoodsSetsPay resultObj = banLiShopGoodsSetsPayMapper.selectByPrimaryKey(record.getId());
            if (resultObj == null)
                throw new BanLiShopGoodsSetPayException(1, "修改内容已不存在");
            
            record.setCreateTime(resultObj.getCreateTime());
            banLiShopGoodsSetsPayMapper.updateByPrimaryKey(record);
        }
    }
 
    @Override
    public void updateSelectiveByPrimaryKey(BanLiShopGoodsSetsPay pay) {
        if (pay.getId() == null)
            return;
        if (pay.getUpdateTime() == null)
            pay.setUpdateTime(new Date());
 
        banLiShopGoodsSetsPayMapper.updateByPrimaryKeySelective(pay);
    }
 
    @Transactional
    @Override
    public void delete(List<Long> idsList) {
        if (idsList != null)
            for (Long id : idsList)
                deleteByPrimaryKey(id);
    }
 
    @Override
    public void deleteByPrimaryKey(Long id) {
        banLiShopGoodsSetsPayMapper.deleteByPrimaryKey(id);
    }
 
    
    @Override
    public List<BanLiShopGoodsSetsPay> listQuery(int page, int pageSize, String key, Integer payType, Long setId) {
        return banLiShopGoodsSetsPayMapper.listQuery((page - 1) * pageSize, pageSize, key, payType, setId);
    }
    
    @Override
    public long countQuery(String key, Integer payType, Long setId) {
        return banLiShopGoodsSetsPayMapper.countQuery(key, payType, setId);
    }
 
 
}