yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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
package com.yeshi.fanli.service.impl.goods;
 
import java.io.Serializable;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.goods.GoodsSecondClassDao;
import com.yeshi.fanli.entity.bus.clazz.GoodsSecondClass;
import com.yeshi.fanli.exception.NotExistObjectException;
import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
import com.yeshi.fanli.util.Constant;
 
@Service
public class GoodsSecondClassServiceImpl implements GoodsSecondClassService {
 
    @Resource
    private GoodsSecondClassDao goodsSecondClassDao;
    @Cacheable(value="classCache",key="'getGoodsSecondClassByGoodsClassId-'+#id")
    public List<GoodsSecondClass> getGoodsSecondClassByGoodsClassId(long id) {
 
        List<GoodsSecondClass> list = goodsSecondClassDao.list(
                "from GoodsSecondClass gsc " + "where gsc.parent.id=? order by gsc.orderby ",
                new Serializable[] { id });
 
        return list;
    }
 
    public List<GoodsSecondClass> getSecondClassList(int index, String key,
            long cid) {
 
        int start = index * Constant.PAGE_SIZE;
 
        List<GoodsSecondClass> list = goodsSecondClassDao
                .list("from GoodsSecondClass gsc where gsc.parent.id=? and gsc.name like ? order by gsc.orderby",
                        start, Constant.PAGE_SIZE, new Serializable[] { cid,
                                "%" + key + "%" });
 
        return list;
    }
 
    public int getCount(long cid, String key) {
        Long lcount = goodsSecondClassDao
                .getCount(
                        "select count(*) from GoodsSecondClass gsc where gsc.parent.id=? and gsc.name like ? ",
                        new Serializable[] { cid, "%" + key + "%" });
        return lcount.intValue();
    }
 
    public void addSecondClass(GoodsSecondClass secondClass) {
        secondClass.setCreatetime(System.currentTimeMillis());
        goodsSecondClassDao.save(secondClass);
    }
 
    public void deleteSecondClass(long sid) {
        goodsSecondClassDao.delete(new GoodsSecondClass(sid));
    }
 
    public GoodsSecondClass getSecondClass(long scid) {
        return goodsSecondClassDao.find(GoodsSecondClass.class, scid);
    }
 
    public void updateSecondClass(GoodsSecondClass secondClass)
            throws NotExistObjectException {
        GoodsSecondClass find = goodsSecondClassDao.find(
                GoodsSecondClass.class, secondClass.getId());
        if (find == null) {
            throw new NotExistObjectException("不存在该用户");
        }
        find.setName(secondClass.getName());
        find.setPicture(secondClass.getPicture());
        find.setOrderby(secondClass.getOrderby());
        find.setKey(secondClass.getKey());
        goodsSecondClassDao.update(find);
    }
 
    public void deleteSecondClassByGC(final long id) {
        goodsSecondClassDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session)
                    throws HibernateException {
                session.createQuery(
                        "delete from GoodsSecondClass gsc where gsc.parent.id=?")
                        .setParameter(0, id).executeUpdate();
                return null;
            }
        });
    }
 
}