yujian
2019-02-14 5eadf208bc38b0002f127217e479aa5353228ec8
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
package com.yeshi.fanli.goods.service.impl.recommend;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.fanli.facade.goods.entity.clazz.GoodsClass;
import org.fanli.facade.goods.entity.clazz.SuperGoodsClass;
import org.fanli.facade.goods.service.clazz.SuperGoodsClassService;
import org.fanli.facade.system.entity.common.SystemManage;
import org.fanli.facade.system.service.common.SystemManageService;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.orm.hibernate4.HibernateCallback;
import com.alibaba.dubbo.config.annotation.Service;
 
import com.yeshi.fanli.goods.dao.clazz.SuperGoodsClassDao;
 
@Service(version = "1.0.0")
public class SuperGoodsClassServiceImpl implements SuperGoodsClassService {
 
    @Resource
    private SuperGoodsClassDao superGoodsClassDao;
 
    @Resource
    private SystemManageService systemService;
 
    @Cacheable(value = "classCache", key = "'getSuperGoodsClassBySystemId-'+#id")
    public List<SuperGoodsClass> getSuperGoodsClassBySystemId(long id) {
 
        return superGoodsClassDao.list(
                "from SuperGoodsClass sgc where sgc.system.id=? order by sgc.goodsClass.orderby ",
                new Serializable[] { id });
 
    }
 
    public List<SuperGoodsClass> getSuperGoodsClasss(List<Long> gcIdList) {
        if (gcIdList.size() == 0) {
            return new ArrayList<SuperGoodsClass>();
        }
        StringBuffer sb = new StringBuffer(" from SuperGoodsClass sgc ");
        Serializable[] serArr = new Serializable[gcIdList.size()];
        for (int i = 0; i < gcIdList.size(); i++) {
            if (i == 0) {
                sb.append(" where sgc.goodsClass.id=? ");
            } else {
                sb.append(" or sgc.goodsClass.id=? ");
            }
            serArr[i] = gcIdList.get(i);
        }
        // sb.append(" order by sgc.goodsClass.orderby ");
        String hql = sb.toString();
 
        return superGoodsClassDao.list(hql, serArr);
 
    }
 
    public List<SuperGoodsClass> getSuperGoodsClassList(long id, int start, int count, String key) {
        return superGoodsClassDao.list(
                "from SuperGoodsClass srs where srs.system.id=? and srs.goodsClass.name like ? order by sgc.goodsClass.orderby ",
                start, count, new Serializable[] { id, "%" + key + "%" });
 
    }
 
    @Override
    public List<SuperGoodsClass> getSuperGoodsClassAll(long id) {
        return superGoodsClassDao.list(
                "from SuperGoodsClass srs where srs.system.id=?  order by sgc.goodsClass.orderby ",
                new Serializable[] { id });
 
    }
 
    public Integer deleteSuperGoodsClass(final long gcid, final String platform, final String packageName) {
 
        return (Integer) superGoodsClassDao.excute(new HibernateCallback<Integer>() {
 
            public Integer doInHibernate(Session session) throws HibernateException {
                SystemManage system = systemService.getSystem(platform, packageName);
                Transaction transaction = session.beginTransaction();
                Query query = session
                        .createQuery("delete SuperGoodsClass shs " + " where shs.goodsClass.id=? and shs.system.id=?");
                query.setLong(0, gcid);
                query.setLong(1, system.getId());
                int i = query.executeUpdate();
                transaction.commit();
                return i;
            }
        });
    }
 
    public void addSuperGoodsClass(long gcid, String platform, String packageName) {
        SystemManage system = systemService.getSystem(platform, packageName);
        SuperGoodsClass superGoodsClass = new SuperGoodsClass();
        GoodsClass goodsClass = new GoodsClass();
        goodsClass.setId(gcid);
        superGoodsClass.setGoodsClass(goodsClass);
        ;
        superGoodsClass.setSystem(system);
        superGoodsClassDao.create(superGoodsClass);
 
    }
 
    public void deleteSuperGoodsClass(final long gcid) {
        superGoodsClassDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                Query query = session.createQuery("delete from SuperGoodsClass sgc where sgc.goodsClass.id=?");
                query.setParameter(0, gcid);
                query.executeUpdate();
                return null;
            }
        });
    }
 
}