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;
|
}
|
});
|
|
}
|
|
}
|