Helius
2021-01-12 04f9d0857969531f13ccd296717a718f2cd702cf
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
 
package com.matrix.system.hive.service.imp;
 
import java.util.List;
 
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.system.common.tools.ServiceUtil;
import com.matrix.system.hive.bean.SysGoodsType;
import com.matrix.system.hive.dao.SysGoodsTypeDao;
import com.matrix.system.hive.service.SysGoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
 
 
/**
 *
 * @date 2016-07-03 20:53
 */
@Service("sysGoodsTypeService")
public class  SysGoodsTypeServiceImpl implements SysGoodsTypeService {
 
    
    @Autowired 
    private SysGoodsTypeDao sysGoodsTypeDao;
    public final String TABLE = "sys_goods_type";
    @Autowired
    private ServiceUtil serviceUtil;
    @Override
    public int add(SysGoodsType sysGoodsType){
        if(sysGoodsType.getTypeNo()==null || sysGoodsType.getTypeNo().equals("")){
            return sysGoodsTypeDao.insert(sysGoodsType);
        }
        if (serviceUtil.addCheckRepeat(TABLE, "TYPE_NO", sysGoodsType.getTypeNo())) {
            throw new GlobleException("编号已被使用!");
        }
        return sysGoodsTypeDao.insert(sysGoodsType);
        
    }
       
    @Override
    public int modify(SysGoodsType sysGoodsType){
        if(sysGoodsType.getTypeNo()==null || sysGoodsType.getTypeNo().equals("")){
            return sysGoodsTypeDao.update(sysGoodsType);
        }
        if (serviceUtil.updateCheckRepeat(TABLE, "TYPE_NO", sysGoodsType.getTypeNo(), "ID", sysGoodsType.getId())) {
            throw new GlobleException("编号已被使用!");
        }
        return sysGoodsTypeDao.update(sysGoodsType);
    
    }
    
    @Override
    public int remove(List<Long> list){
    
        return sysGoodsTypeDao.deleteByIds(list);
    
    }
 
    @Override
    /**
     * 删除节点及其下面的所有子节点
     * @author LW
     */
    public int removeById(Long id){
        rescuRemove( id);
        return    sysGoodsTypeDao.deleteById(id);
    }
    /**
     * 递归删除子元素
    * @Title: remove 
    * @author:jyy
    * @param id    
    * void    返回类型 
    * @date 2016年8月5日 上午11:50:41 
    * @throws
     */
    private void rescuRemove(Long id){
        SysGoodsType sysGoodsType=new SysGoodsType();
        sysGoodsType.setParentId(id);
        List<SysGoodsType> goodsTypes=
        sysGoodsTypeDao.selectByModel(sysGoodsType);
        if(goodsTypes.size()>0){
            for (SysGoodsType sysGoodsType2 : goodsTypes) {
                rescuRemove(sysGoodsType2.getId());
                sysGoodsTypeDao.deleteById(sysGoodsType2.getId());
            }
        }
    }
    @Override
    public List<SysGoodsType> findInPage(SysGoodsType sysGoodsType,  PaginationVO pageVo){
    
        return sysGoodsTypeDao.selectInPage(sysGoodsType , pageVo);
    
    }
    
    @Override
    public List<SysGoodsType> findByModel(SysGoodsType sysGoodsType){
    
        return sysGoodsTypeDao.selectByModel(sysGoodsType);
    
    }
    
    @Override
    public int  findTotal(SysGoodsType sysGoodsType){
    
        return sysGoodsTypeDao.selectTotalRecord(sysGoodsType);
    
    }
    
    @Override
    public SysGoodsType findById(Long id){
    
        return sysGoodsTypeDao.selectById(id);
    
    }
}