935090232@qq.com
2021-06-06 e83f7fa1f5648745940863444fed16f7f9135ce7
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
157
package com.matrix.system.hive.service.imp;
 
import java.util.ArrayList;
import java.util.List;
 
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.dao.UtilDao;
import com.matrix.system.common.tools.ServiceUtil;
import com.matrix.system.constance.TableMapping;
 
import com.matrix.system.hive.bean.SysGoods;
import com.matrix.system.hive.dao.SysGoodsDao;
import com.matrix.system.hive.service.SysGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.matrix.system.constance.Dictionary;
 
 
/**
 * @date 2016-07-03 20:53
 */
@Service("sysGoodsService")
public class SysGoodsServiceImpl implements SysGoodsService {
 
    @Autowired
    private SysGoodsDao sysGoodsDao;
 
 
    @Autowired
    private ServiceUtil serviceUtil;
 
    @Autowired
    private UtilDao utilDao;
 
    public static final String TABLE_NAME = "sys_goods";
 
    /**
     * @author 姜友瑶
     * @time 2016-07-31
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int add(SysGoods sysGoods) {
        SysUsers users = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        sysGoods.setDeleted(Dictionary.DELETED_N);
        // 校验去重
        if (serviceUtil.addCheckRepeatTowColumn(TABLE_NAME, "GOODS_NO", sysGoods.getGoodsNo(), "shop_id", users.getShopId())) {
            throw new GlobleException("编号" + sysGoods.getGoodsNo() + "重复");
        }
        int i = sysGoodsDao.insert(sysGoods);
        return i;
    }
 
    /**
     * @author 姜友瑶
     * @time 2016-07-31
     */
    @Override
    public int modify(SysGoods sysGoods) {
        // 校验去重
        if (serviceUtil.updateCheckRepeat(TABLE_NAME, "GOODS_NO", sysGoods.getGoodsNo(), "ID", sysGoods.getId())) {
            throw new GlobleException("编号" + sysGoods.getGoodsNo() + "重复");
        }
        // 更新或者添加sku
        //updateSku(sysGoods);
        return sysGoodsDao.update(sysGoods);
    }
 
    /**
     * @author 姜友瑶
     * @time 2016-07-31
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int remove(List<Long> list) {
        // 查询是否存在被绑定的sku
        for (Long id : list) {
            // 此处由于taocan_info表已经删除,因此不需要检测taocan_info表,而是改为检测shopping_goods_assemble,改写dao.xml中的方法
            if (sysGoodsDao.getbindTaocanCount(id) > 0) {
                throw new GlobleException("产品中的sku被销售产品绑定,请先删除对应的销售产品!");
            }
            if (sysGoodsDao.getbindProjCount(id) > 0) {
                throw new GlobleException("产品中的sku被项目绑定,请先删除对应的项目!");
            }
        }
        return sysGoodsDao.deleteByIds(list);
 
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeById(Long id) {
        // 查询是否存在被绑定的sku
        if (sysGoodsDao.getbindTaocanCount(id) > 0) {
            throw new GlobleException("产品中的sku被套餐绑定,请先删除对应的套餐!");
        }
        if (sysGoodsDao.getbindProjCount(id) > 0) {
            throw new GlobleException("产品中的sku被项目绑定,请先删除对应的项目!");
        }
        return sysGoodsDao.deleteById(id);
 
    }
 
 
    /**
     * 验证是否可以删除sku
     *
     * @author:jyy
     * @date 2016年9月18日 下午1:53:48
     */
    private boolean checkIsDelete(Long id) {
        if (utilDao.selectCount(TableMapping.SYS_PROJ_GOODS, "SKU_ID", id + "") > 0) {
            throw new GlobleException("有项目消耗产品绑定了该产品,必须先接触绑定关系!");
        }
        if (utilDao.selectCount(TableMapping.SHOPPING_GOODS_ASSEMBLE, "assemble_sku_id", id + "") > 0) {
            throw new GlobleException("有商品绑定了该产品,必须先接触绑定关系!");
        }
        if (utilDao.selectCount(TableMapping.SYS_STORE_INFO, "SKU_ID", id + "") > 0) {
            throw new GlobleException("库存中已经存在该产品,不能删除该产品!");
        }
        return true;
    }
 
 
    @Override
    public List<SysGoods> findInPage(SysGoods sysGoods, PaginationVO pageVo) {
        return sysGoodsDao.selectInPage(sysGoods, pageVo);
    }
 
    @Override
    public List<SysGoods> findByModel(SysGoods sysGoods) {
        return sysGoodsDao.selectByModel(sysGoods);
    }
 
    @Override
    public int findTotal(SysGoods sysGoods) {
        return sysGoodsDao.selectTotalRecord(sysGoods);
 
    }
 
    @Override
    public SysGoods findById(Long id) {
        return sysGoodsDao.selectById(id);
    }
 
    @Override
    public List<SysGoods> findAllNo() {
        return sysGoodsDao.selectAllNo();
    }
 
}