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
package com.yeshi.fanli.service.impl.hongbao;
 
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.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.goods.SuperHongBaoActivityDao;
import com.yeshi.fanli.entity.bus.su.hongbao.SuperHongBaoActivity;
import com.yeshi.fanli.entity.bus.user.HongBaoActivity;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.hongbao.SuperHongBaoActivityService;
 
@Service
public class SuperHongBaoActivityServiceImpl implements
        SuperHongBaoActivityService {
    
    @Resource
    private SuperHongBaoActivityDao superHongBaoActivityDao; 
    
    @Resource
    private BusinessSystemService businessSystemService;
    
    public List<SuperHongBaoActivity> getSuperHongBaoActivitysByHongBaoActivitys(
            List<Long> hbaIdList) {
        if (hbaIdList.size() == 0) {
            return new ArrayList<SuperHongBaoActivity>();
        }
        StringBuffer sb = new StringBuffer(" from SuperHongBaoActivity shba ");
        Serializable[] serArr = new Serializable[hbaIdList.size()];
        for (int i = 0; i < hbaIdList.size(); i++) {
            if (i == 0) {
                sb.append(" where shba.hongBaoActivity.id=? ");
            } else {
                sb.append(" or shba.hongBaoActivity.id=? ");
            }
            serArr[i] = hbaIdList.get(i);
        }
        String hql = sb.toString();
 
        return superHongBaoActivityDao.list(hql, serArr);
 
    }
 
    public List<SuperHongBaoActivity> getSuperHongBaoActivityBySystemId(
            long id, int start, int count) {
        return superHongBaoActivityDao.list("from SuperHongBaoActivity srs where srs.system.id=?",start,count,new Serializable[]{id});
    }
 
    public List<SuperHongBaoActivity> getSuperHongBaoActivityBySystemId(
            long id, int start, int count, String likekey) {
        return superHongBaoActivityDao.list("from SuperHongBaoActivity srs where srs.system.id=? and srs.hongBaoActivity.name like ?",start,count,new Serializable[]{id, "%"+likekey+"%"});
 
    }
 
    public Integer deleteSuperHongBaoActivity(final long id, final String platform,
            final String packageName) {
        return  (Integer) superHongBaoActivityDao.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 SuperHongBaoActivity shs "
                            + " where shs.hongBaoActivity.id=? and shs.system.id=?");
                query.setLong(0, id);
                query.setLong(1, system.getId());
                int i = query.executeUpdate();
                transaction.commit();
                return i ;
            }
        });
    }
 
    public void addSuperHongBaoActivity(long id, String platform,
            String packageName) {
        BusinessSystem system = businessSystemService.getBusinessSystem(platform,packageName);
        SuperHongBaoActivity superHongBaoActivity = new SuperHongBaoActivity();
        HongBaoActivity hongBaoActivity = new HongBaoActivity();
        hongBaoActivity.setId(id);
        superHongBaoActivity.setHongBaoActivity(hongBaoActivity);
        superHongBaoActivity.setSystem(system);
        superHongBaoActivityDao.create(superHongBaoActivity);
    }
 
}