yujian
2019-03-14 4aadf484e193995c23ee1d5bb1971a497d2f9a0d
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
158
159
160
161
162
163
164
package com.yeshi.fanli.service.impl.config;
 
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
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 org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.goods.SuperHotSearchDao;
import com.yeshi.fanli.entity.bus.search.HotSearch;
import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.SuperHotSearchService;
 
@Service
public class SuperHotSearchSerivceImpl implements SuperHotSearchService {
 
    @Resource
    private SuperHotSearchDao superHotSearchDao;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
    public List<SuperHotSearch> getSuperHotSearchBySystemId(long id) {
 
        return superHotSearchDao.list("from SuperHotSearch shs where shs.system.id=? order by hotSearch.orderby desc",
                new Serializable[] { id });
    }
 
    public List<SuperHotSearch> getSuperHotSearchsByHotSearchs(List<Long> hsIdList) {
        if (hsIdList.size() == 0) {
            return new ArrayList<SuperHotSearch>();
        }
        StringBuffer sb = new StringBuffer(" from SuperHotSearch shs ");
        Serializable[] serArr = new Serializable[hsIdList.size()];
        for (int i = 0; i < hsIdList.size(); i++) {
            if (i == 0) {
                sb.append(" where shs.hotSearch.id=? ");
            } else {
                sb.append(" or shs.hotSearch.id=? ");
            }
            serArr[i] = hsIdList.get(i);
        }
        String hql = sb.toString();
 
        return superHotSearchDao.list(hql, serArr);
 
    }
 
    public List<SuperHotSearch> getSuperHotSearchBySystemId(long id, int strat, int count) {
        return superHotSearchDao.list("from SuperHotSearch shs where shs.system.id=?", strat, count,
                new Serializable[] { id });
 
    }
 
    public List<SuperHotSearch> getSuperHotSearchBySystemId(long id, int strat, int count, String key) {
        return superHotSearchDao.list("from SuperHotSearch srs where srs.system.id=? and srs.hotSearch.name like ?",
                strat, count, new Serializable[] { id, key });
 
    }
    
    @Override
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<SuperHotSearch> listSuperHotSearch(List<Long> list) {
        
        List<SuperHotSearch> listObj = (List<SuperHotSearch>) superHotSearchDao.excute(new HibernateCallback<List<SuperHotSearch>>() {
            public List<SuperHotSearch> doInHibernate(Session session) throws HibernateException {
                Query query = session.createQuery("from SuperHotSearch srs where srs.hotSearch.id in (:array)");
                 query.setParameterList("array",list);     
                 return query.list();
            }
        });
        
        return listObj;
    }
    
    
    public Integer deleteSuperHotSearch(final long hsid, final String platform, final String packageName) {
        return (Integer) superHotSearchDao.excute(new HibernateCallback<Integer>() {
 
            public Integer doInHibernate(Session session) throws HibernateException {
                BusinessSystem system = businessSystemService.getBusinessSystem(platform, packageName);
                Transaction transaction = session.beginTransaction();
                Query query = session
                        .createQuery("delete SuperHotSearch shs " + " where shs.hotSearch.id=? and shs.system.id=?");
                query.setLong(0, hsid);
                query.setLong(1, system.getId());
                int i = query.executeUpdate();
                transaction.commit();
                return i;
            }
        });
    }
 
    public void addSuperHotSearch(long hsid, String platform, String packageName) {
        BusinessSystem system = businessSystemService.getBusinessSystem(platform, packageName);
        SuperHotSearch superHotSearch = new SuperHotSearch();
        HotSearch hotSearch = new HotSearch();
        hotSearch.setId(hsid);
        superHotSearch.setHotSearch(hotSearch);
        superHotSearch.setSystem(system);
        superHotSearchDao.create(superHotSearch);
    }
 
    @Cacheable(value = "crgCache", key = "'getSuperHotSearchBySystemIdCache'+#id")
    @Override
    public List<SuperHotSearch> getSuperHotSearchBySystemIdCache(long id) {
        return getSuperHotSearchBySystemId(id);
    }
 
    
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public List<SuperHotSearch> getHotSearchSystem(Long id, Long systemId) {
        
        List<SuperHotSearch> listObj = (List<SuperHotSearch>) superHotSearchDao.excute(new HibernateCallback<List<SuperHotSearch>>() {
            public List<SuperHotSearch> doInHibernate(Session session) throws HibernateException {
                 
                Query query = session.createQuery("from SuperHotSearch shs " + " where shs.hotSearch.id=? and shs.system.id=?");
                query.setLong(0, id);
                query.setLong(1,systemId);
                    
                return query.list();
            }
        });
        
        return listObj;
    }
    
    @Override
    public Integer deleteSuper(Long id, Long systemId) {
        return (Integer) superHotSearchDao.excute(new HibernateCallback<Integer>() {
            public Integer doInHibernate(Session session) throws HibernateException {
                Transaction transaction = session.beginTransaction();
                Query query = session
                        .createQuery("delete SuperHotSearch shs " + " where shs.hotSearch.id=? and shs.system.id=?");
                query.setLong(0, id);
                query.setLong(1, systemId);
                int i = query.executeUpdate();
                transaction.commit();
                return i;
            }
        });
    }
    
    @Override
    public void addSuper(Long id, BusinessSystem system) {
        SuperHotSearch superHotSearch = new SuperHotSearch();
        HotSearch hotSearch = new HotSearch();
        hotSearch.setId(id);
        superHotSearch.setHotSearch(hotSearch);
        superHotSearch.setSystem(system);
        superHotSearchDao.create(superHotSearch);
    }
}