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
package com.yeshi.fanli.service.impl.user;
 
import java.io.Serializable;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.user.MoneyRecordDao;
import com.yeshi.fanli.entity.bus.user.MoneyRecord;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.user.MoneyRecordService;
import com.yeshi.fanli.util.Constant;
 
@Service
public class MoneyRecordServiceImpl implements MoneyRecordService {
 
    @Resource
    private MoneyRecordDao moneyRecordDao;
    
    @Resource
    private OrderService orderService;
 
    public List<MoneyRecord> getMoneyRecord(long uid,int page) {
        
        int start = page *  Constant.PAGE_SIZE;
        
        List<MoneyRecord> mrList =     moneyRecordDao.list("from MoneyRecord mr where mr.userInfo.id=? order by mr.createtime desc", start,Constant.PAGE_SIZE, new Serializable[] { uid });
        return mrList;
    }
    
    public void addMoneyRecord(MoneyRecord moneyRecord) {
        moneyRecordDao.create(moneyRecord);
    }
 
    public int getCount(long uid) {
        Long lcount = moneyRecordDao.getCount("select count(m.id) from MoneyRecord m where m.userInfo.id=?", new Serializable[]{uid});
        return lcount.intValue();
    }
 
    public void deleteMoneyRecordByEid(final long eid) {
        moneyRecordDao.excute(new HibernateCallback() {
 
            public Object doInHibernate(Session session)
                    throws HibernateException {
                Query q = session.createQuery("delete from MoneyRecord mr where mr.extract.id = ? ");
                q.setParameter(0, eid);
                q.executeUpdate();
                return null;
            }
        });
    }
 
    @Override
    public List<MoneyRecord> findAll() {
        return moneyRecordDao.list("from MoneyRecord");
    }
}