package com.yeshi.fanli.service.impl.goods;
|
|
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.goods.CollectionGoodsDao;
|
import com.yeshi.fanli.entity.bus.user.CollectionGoods;
|
import com.yeshi.fanli.service.inter.goods.CollectionGoodsService;
|
import com.yeshi.fanli.util.Constant;
|
|
@Service
|
public class CollectionGoodsServiceImpl implements CollectionGoodsService {
|
|
@Resource
|
private CollectionGoodsDao dao;
|
|
@Override
|
public void save(CollectionGoods cg) {
|
cg.setCreateTime(System.currentTimeMillis());
|
dao.save(cg);
|
}
|
|
@Override
|
public CollectionGoods findByUidAndAuctionId(long uid, long auctionId) {
|
List<CollectionGoods> list = dao.list("from CollectionGoods cg where cg.userInfo.id=? and auctionId=?", 0, 1,
|
new Serializable[] { uid, auctionId });
|
if (list.size() > 0) {
|
return list.get(0);
|
}
|
return null;
|
}
|
|
@Override
|
public void delete(CollectionGoods find) {
|
dao.delete(find);
|
}
|
|
@Override
|
public List<CollectionGoods> findCollectionGoods(long uid, int page) {
|
return dao.list("from CollectionGoods cg where cg.userInfo.id = ? order by id desc",
|
(page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, new Serializable[] { uid });
|
}
|
|
@Override
|
public int getCount(long uid) {
|
return (int) dao.getCount("select count(*) from CollectionGoods cg where cg.userInfo.id = ?",
|
new Serializable[] { uid });
|
}
|
|
@Override
|
public void delete(long auctionId, long uid) {
|
dao.excute(new HibernateCallback() {
|
|
@Override
|
public Object doInHibernate(Session session) throws HibernateException {
|
Query query = session
|
.createQuery("delete from CollectionGoods cg where cg.userInfo.id = ? and auctionId = ?");
|
query.setParameter(0, uid);
|
query.setParameter(1, auctionId);
|
query.executeUpdate();
|
return null;
|
}
|
});
|
}
|
|
@Override
|
public void clear(long uid) {
|
dao.excute(new HibernateCallback() {
|
|
@Override
|
public Object doInHibernate(Session session) throws HibernateException {
|
Query query = session.createQuery(" delete from CollectionGoods cg where cg.userInfo.id = ?");
|
query.setParameter(0, uid);
|
query.executeUpdate();
|
return null;
|
}
|
});
|
}
|
|
@Override
|
public CollectionGoods findByAuctionId(long auctionId) {
|
List<CollectionGoods> list = dao.list("from CollectionGoods cg where cg.auctionId=" + auctionId);
|
if (list != null && list.size() > 0)
|
return list.get(0);
|
else
|
return null;
|
}
|
|
}
|