yujian
2019-11-06 54e6398cabe1b32b1dbc9857c6a99d8f15b549f7
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
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 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) {
        return banLiShopGoodsSetsPayMapper.listQuery((page - 1) * pageSize, pageSize, key, payType);
    }
    
    @Override
    public long countQuery(String key, Integer payType) {
        return banLiShopGoodsSetsPayMapper.countQuery(key, payType);
    }
 
 
}