admin
2019-03-14 eed607d87b2eee1f09b4a28da614f3ad0b46601d
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
package com.yeshi.fanli.service.impl.goods;
 
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.springframework.cache.annotation.Cacheable;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.goods.SuperRecommendSectionDao;
import com.yeshi.fanli.entity.bus.recommend.RecommendSection;
import com.yeshi.fanli.entity.bus.su.recommend.SuperRecommendSection;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.goods.SuperRecommendSectionService;
 
@Service
public class SuperRecommendSectionServiceImpl implements SuperRecommendSectionService {
 
    @Resource
    private SuperRecommendSectionDao superRecommendSectionDao;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
    public List<SuperRecommendSection> getSuperRecommendSectionBySystemId(long id, int start, int count) {
        return superRecommendSectionDao.list("from SuperRecommendSection srs where srs.system.id=?", start, count,
                new Serializable[] { id });
 
    }
 
    public List<SuperRecommendSection> getSuperRecommendSectionBySystemId(long id, int start, int count, String key) {
        return superRecommendSectionDao.list(
                "from SuperRecommendSection srs where srs.system.id=? and srs.recommendSection.name like ?", start,
                count, new Serializable[] { id, key });
 
    }
 
    @Cacheable(value = "supersectionCache", key = "'s-'+#id")
    public List<SuperRecommendSection> getSuperRecommendSectionBySystemId(long id) {
        return superRecommendSectionDao.list("from SuperRecommendSection srs where srs.system.id=?",
                new Serializable[] { id });
    }
 
    public List<SuperRecommendSection> getSuperRecommendSectionsBySections(List<Long> rsIdList) {
        if (rsIdList.size() == 0) {
            return new ArrayList<SuperRecommendSection>();
        }
        StringBuffer sb = new StringBuffer(" from SuperRecommendSection srb ");
        Serializable[] serArr = new Serializable[rsIdList.size()];
        for (int i = 0; i < rsIdList.size(); i++) {
            if (i == 0) {
                sb.append(" where srb.recommendSection.id=? ");
            } else {
                sb.append(" or srb.recommendSection.id=? ");
            }
            serArr[i] = rsIdList.get(i);
        }
        String hql = sb.toString();
 
        return superRecommendSectionDao.list(hql, serArr);
 
    }
 
    @Transactional(rollbackFor = Exception.class)
    public Integer deleteSuperRecommendSection(final long rsid, final String platform, final String packageName) {
        return (Integer) superRecommendSectionDao.excute(new HibernateCallback<Integer>() {
 
            public Integer doInHibernate(Session session) throws HibernateException {
                BusinessSystem system = businessSystemService.getBusinessSystem(platform, packageName);
                Query query = session.createQuery(
                        "delete SuperRecommendSection srb " + " where srb.recommendSection.id=? and srb.system.id=?");
                query.setLong(0, rsid);
                query.setLong(1, system.getId());
                int i = query.executeUpdate();
                return i;
            }
        });
    }
 
    public void addSuperRecommendSection(long rbid, String platform, String packageName) {
 
        BusinessSystem system = businessSystemService.getBusinessSystem(platform, packageName);
        SuperRecommendSection superRecommendSection = new SuperRecommendSection();
        RecommendSection recommendSection = new RecommendSection();
        recommendSection.setId(rbid);
        superRecommendSection.setRecommendSection(recommendSection);
        superRecommendSection.setSystem(system);
        superRecommendSectionDao.create(superRecommendSection);
 
    }
 
    public void deleteSuperRecommendSections(final long[] rsids) {
 
        superRecommendSectionDao.excute(new HibernateCallback() {
 
            public Object doInHibernate(Session session) throws HibernateException {
 
                StringBuffer sb = new StringBuffer("delete from SuperRecommendSection s ");
                for (int i = 0; i < rsids.length; i++) {
                    if (i == 0) {
                        sb.append(" where s.recommendSection.id=? ");
                    } else {
                        sb.append(" or s.recommendSection.id=?");
                    }
                }
                Query query = session.createQuery(sb.toString());
                for (int i = 0; i < rsids.length; i++) {
                    query.setLong(i, rsids[i]);
                }
                query.executeUpdate();
                return null;
            }
        });
 
    }
 
}