| | |
| | | import com.yeshi.buwan.dao.SuperRecommendAdDao; |
| | | import com.yeshi.buwan.dao.WXAdDao; |
| | | import com.yeshi.buwan.dao.WXStatisticsDao; |
| | | import com.yeshi.buwan.domain.DetailSystem; |
| | | import com.yeshi.buwan.domain.system.DetailSystem; |
| | | import com.yeshi.buwan.domain.RecommendAd; |
| | | import com.yeshi.buwan.domain.SuperRecommendAd; |
| | | import com.yeshi.buwan.domain.SystemInfo; |
| | | import com.yeshi.buwan.domain.system.SystemInfo; |
| | | import com.yeshi.buwan.domain.WXAd; |
| | | import com.yeshi.buwan.domain.WXStatistics; |
| | | import com.yeshi.buwan.domain.ad.AdStatistics; |
| | |
| | | |
| | | @Service |
| | | public class AdService { |
| | | @Resource |
| | | private RecommendAdDao recommendAdDao; |
| | | @Resource |
| | | private MineAdDao mineAdDao; |
| | | @Resource |
| | | private AdStatisticsDao adStatisticsDao; |
| | | @Resource |
| | | private WXAdDao wxAdDao; |
| | | @Resource |
| | | private WXStatisticsDao wxStatisticsDao; |
| | | @Resource |
| | | private SuperRecommendAdDao superRecommendAdDao; |
| | | @Resource |
| | | private CommonAdPositionAdDao commonAdPositionAdDao; |
| | | @Resource |
| | | private CommonAdStatisticsDao commonAdStatisticsDao; |
| | | @Resource |
| | | private CommonAdDao commonAdDao; |
| | | @Resource |
| | | private RecommendAdDao recommendAdDao; |
| | | @Resource |
| | | private MineAdDao mineAdDao; |
| | | @Resource |
| | | private AdStatisticsDao adStatisticsDao; |
| | | @Resource |
| | | private WXAdDao wxAdDao; |
| | | @Resource |
| | | private WXStatisticsDao wxStatisticsDao; |
| | | @Resource |
| | | private SuperRecommendAdDao superRecommendAdDao; |
| | | @Resource |
| | | private CommonAdPositionAdDao commonAdPositionAdDao; |
| | | @Resource |
| | | private CommonAdStatisticsDao commonAdStatisticsDao; |
| | | @Resource |
| | | private CommonAdDao commonAdDao; |
| | | |
| | | @Resource |
| | | private CommonAdPositionDao commonAdPositionDao; |
| | | @Resource |
| | | private CommonAdPositionDao commonAdPositionDao; |
| | | |
| | | public CommonAdDao getCommonAdDao() { |
| | | return commonAdDao; |
| | | } |
| | | |
| | | public void setCommonAdDao(CommonAdDao commonAdDao) { |
| | | this.commonAdDao = commonAdDao; |
| | | } |
| | | // 获取广告 |
| | | public List<RecommendAd> getRecommendAdList() { |
| | | |
| | | public CommonAdStatisticsDao getCommonAdStatisticsDao() { |
| | | return commonAdStatisticsDao; |
| | | } |
| | | return recommendAdDao.list("from RecommendAd"); |
| | | } |
| | | |
| | | public void setCommonAdStatisticsDao(CommonAdStatisticsDao commonAdStatisticsDao) { |
| | | this.commonAdStatisticsDao = commonAdStatisticsDao; |
| | | } |
| | | public List<RecommendAd> getRecommendAdList(int type) { |
| | | |
| | | public CommonAdPositionAdDao getCommonAdPositionAdDao() { |
| | | return commonAdPositionAdDao; |
| | | } |
| | | return recommendAdDao.list("from RecommendAd a where a.platform=3 or a.platform=" + type); |
| | | } |
| | | |
| | | public void setCommonAdPositionAdDao(CommonAdPositionAdDao commonAdPositionAdDao) { |
| | | this.commonAdPositionAdDao = commonAdPositionAdDao; |
| | | } |
| | | public RecommendAd getAdById(String id) { |
| | | |
| | | public SuperRecommendAdDao getSuperRecommendAdDao() { |
| | | return superRecommendAdDao; |
| | | } |
| | | return recommendAdDao.find(RecommendAd.class, id); |
| | | } |
| | | |
| | | public void setSuperRecommendAdDao(SuperRecommendAdDao superRecommendAdDao) { |
| | | this.superRecommendAdDao = superRecommendAdDao; |
| | | } |
| | | public void updateRecommendAd(RecommendAd ad) { |
| | | |
| | | public WXStatisticsDao getWxStatisticsDao() { |
| | | return wxStatisticsDao; |
| | | } |
| | | recommendAdDao.update(ad); |
| | | } |
| | | |
| | | public void setWxStatisticsDao(WXStatisticsDao wxStatisticsDao) { |
| | | this.wxStatisticsDao = wxStatisticsDao; |
| | | } |
| | | public void addRecommendAd(RecommendAd ad) { |
| | | recommendAdDao.create(ad); |
| | | } |
| | | |
| | | public WXAdDao getWxAdDao() { |
| | | return wxAdDao; |
| | | } |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteRecommendAd(final String id) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperRecommendAd> list = session |
| | | .createQuery("from SuperRecommendAd sv where sv.recommendAd.id=?").setParameter(0, id) |
| | | .list(); |
| | | for (SuperRecommendAd sv : list) |
| | | session.delete(sv); |
| | | session.delete(new RecommendAd(id)); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | public void setWxAdDao(WXAdDao wxAdDao) { |
| | | this.wxAdDao = wxAdDao; |
| | | } |
| | | } |
| | | |
| | | public AdStatisticsDao getAdStatisticsDao() { |
| | | return adStatisticsDao; |
| | | } |
| | | public List<MineAd> getMineAdList(String key) { |
| | | return mineAdDao.list( |
| | | "from MineAd ma where ma.open=1 and ma.adKey.key=? order by ma.first desc,ma.percent desc", |
| | | new String[]{key}); |
| | | } |
| | | |
| | | public void setAdStatisticsDao(AdStatisticsDao adStatisticsDao) { |
| | | this.adStatisticsDao = adStatisticsDao; |
| | | } |
| | | /** |
| | | * 后台操作 |
| | | */ |
| | | |
| | | public MineAdDao getMineAdDao() { |
| | | return mineAdDao; |
| | | } |
| | | @SuppressWarnings("unchecked") |
| | | public List<RecommendAdAdmin> getRecommendAdAdmin(final String key, final int detailSystem, final int page) { |
| | | return (List<RecommendAdAdmin>) recommendAdDao.excute(new HibernateCallback<List<RecommendAdAdmin>>() { |
| | | public List<RecommendAdAdmin> doInHibernate(Session session) throws HibernateException { |
| | | List<RecommendAdAdmin> zhiBoClassList = new ArrayList<RecommendAdAdmin>(); |
| | | try { |
| | | List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list(); |
| | | String sql = ""; |
| | | if (detailSystem > 0) |
| | | sql = "select sh.recommendAd from SuperRecommendAd sh where sh.detailSystem.id=" + detailSystem |
| | | + " order by sh.recommendAd.createtime desc"; |
| | | else |
| | | sql = "from RecommendAd zb order by zb.createtime desc"; |
| | | |
| | | public void setMineAdDao(MineAdDao mineAdDao) { |
| | | this.mineAdDao = mineAdDao; |
| | | } |
| | | List<RecommendAd> list = session.createQuery(sql).setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | for (RecommendAd vb : list) { |
| | | List<DetailSystem> detailSystemS = session |
| | | .createQuery( |
| | | "select vb.detailSystem from SuperRecommendAd vb where vb.recommendAd.id=?") |
| | | .setParameter(0, vb.getId()).list(); |
| | | |
| | | public RecommendAdDao getRecommendAdDao() { |
| | | return recommendAdDao; |
| | | } |
| | | List<DetailSystemSelect> dssList = new ArrayList<DetailSystemSelect>(); |
| | | |
| | | public void setRecommendAdDao(RecommendAdDao recommendAdDao) { |
| | | this.recommendAdDao = recommendAdDao; |
| | | } |
| | | for (DetailSystem ds : detailSystemList) { |
| | | DetailSystemSelect dss = new DetailSystemSelect(); |
| | | dss.setDetailSystem(ds); |
| | | dss.setSelected(false); |
| | | dssList.add(dss); |
| | | } |
| | | |
| | | // 获取广告 |
| | | public List<RecommendAd> getRecommendAdList() { |
| | | // 设置已经存在的 |
| | | for (DetailSystem ds : detailSystemS) { |
| | | for (DetailSystemSelect dss : dssList) { |
| | | if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) { |
| | | dss.setSelected(true); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | SuperRecommendAd sz = new SuperRecommendAd(); |
| | | sz.setDetailSystem(null); |
| | | sz.setRecommendAd(vb); |
| | | zhiBoClassList.add(new RecommendAdAdmin(sz, dssList)); |
| | | } |
| | | |
| | | return recommendAdDao.list("from RecommendAd"); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return zhiBoClassList; |
| | | } |
| | | }); |
| | | |
| | | public List<RecommendAd> getRecommendAdList(int type) { |
| | | } |
| | | |
| | | return recommendAdDao.list("from RecommendAd a where a.platform=3 or a.platform=" + type); |
| | | } |
| | | public long getRecommendAdAdminCount(String key, int detailSystem) { |
| | | String sql = ""; |
| | | if (detailSystem > 0) |
| | | sql = "select count(*) from (select count(*) from wk_video_super_recommendad zb left join wk_ad_recommend c on c.id=zb.recommendadid where zb.detailsystem=" |
| | | + detailSystem + " group by zb.recommendadid) s"; |
| | | else |
| | | sql = "select count(*) from (select count(*) from wk_video_super_recommendad zb left join wk_ad_recommend c on c.id=zb.recommendadid group by zb.recommendadid) s"; |
| | | |
| | | public RecommendAd getAdById(String id) { |
| | | return recommendAdDao.getCountSQL(sql); |
| | | } |
| | | |
| | | return recommendAdDao.find(RecommendAd.class, id); |
| | | } |
| | | @SuppressWarnings("rawtypes") |
| | | public void addRecommendAdAdmin(final String classid, final String detailSystemId) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List list = session |
| | | .createQuery("from SuperRecommendAd vb where vb.recommendAd.id=? and vb.detailSystem.id=?") |
| | | .setParameter(0, classid).setParameter(1, detailSystemId).list(); |
| | | if (list == null || list.size() == 0) { |
| | | SuperRecommendAd vb = new SuperRecommendAd(); |
| | | vb.setCreatetime(System.currentTimeMillis() + ""); |
| | | vb.setDetailSystem(new DetailSystem(detailSystemId)); |
| | | vb.setRecommendAd(new RecommendAd(classid)); |
| | | session.persist(vb); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | |
| | | public void updateRecommendAd(RecommendAd ad) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | recommendAdDao.update(ad); |
| | | } |
| | | } |
| | | |
| | | public void addRecommendAd(RecommendAd ad) { |
| | | recommendAdDao.create(ad); |
| | | } |
| | | @SuppressWarnings({"unchecked", "rawtypes"}) |
| | | public void deleteRecommendAdAdmin(final String classId, final String detailSystemId) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperRecommendAd> list = session |
| | | .createQuery("from SuperRecommendAd vb where vb.recommendAd.id=? and vb.detailSystem.id=?") |
| | | .setParameter(0, classId).setParameter(1, detailSystemId).list(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperRecommendAd vb : list) |
| | | session.delete(vb); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public void deleteRecommendAd(final String id) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperRecommendAd> list = session |
| | | .createQuery("from SuperRecommendAd sv where sv.recommendAd.id=?").setParameter(0, id) |
| | | .list(); |
| | | for (SuperRecommendAd sv : list) |
| | | session.delete(sv); |
| | | session.delete(new RecommendAd(id)); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | public void AddStatistics(String key, String platform, int type) { |
| | | AdStatistics ad = new AdStatistics(); |
| | | ad.setKey(key); |
| | | ad.setPlatformId(platform); |
| | | ad.setTime(System.currentTimeMillis() + ""); |
| | | ad.setType(type); |
| | | adStatisticsDao.create(ad); |
| | | } |
| | | |
| | | public List<MineAd> getMineAdList(String key) { |
| | | return mineAdDao.list( |
| | | "from MineAd ma where ma.open=1 and ma.adKey.key=? order by ma.first desc,ma.percent desc", |
| | | new String[] { key }); |
| | | } |
| | | /** |
| | | * 获取微信广告 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<WXAd> getWinAd(SystemInfo system) { |
| | | List<WXAd> list = wxAdDao.list("from WXAd w where w.system.id=" + system.getId()); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 后台操作 |
| | | */ |
| | | public List<WXAd> getWinAd() { |
| | | List<WXAd> list = wxAdDao.list("from WXAd"); |
| | | return list; |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public List<RecommendAdAdmin> getRecommendAdAdmin(final String key, final int detailSystem, final int page) { |
| | | return (List<RecommendAdAdmin>) recommendAdDao.excute(new HibernateCallback<List<RecommendAdAdmin>>() { |
| | | public List<RecommendAdAdmin> doInHibernate(Session session) throws HibernateException { |
| | | List<RecommendAdAdmin> zhiBoClassList = new ArrayList<RecommendAdAdmin>(); |
| | | try { |
| | | List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list(); |
| | | String sql = ""; |
| | | if (detailSystem > 0) |
| | | sql = "select sh.recommendAd from SuperRecommendAd sh where sh.detailSystem.id=" + detailSystem |
| | | + " order by sh.recommendAd.createtime desc"; |
| | | else |
| | | sql = "from RecommendAd zb order by zb.createtime desc"; |
| | | /** |
| | | * 添加微信广告 |
| | | * |
| | | * @param ad |
| | | */ |
| | | public void addWX(WXAd ad) { |
| | | wxAdDao.create(ad); |
| | | } |
| | | |
| | | List<RecommendAd> list = session.createQuery(sql).setFirstResult((page - 1) * Constant.pageCount) |
| | | .setMaxResults(Constant.pageCount).list(); |
| | | for (RecommendAd vb : list) { |
| | | List<DetailSystem> detailSystemS = session |
| | | .createQuery( |
| | | "select vb.detailSystem from SuperRecommendAd vb where vb.recommendAd.id=?") |
| | | .setParameter(0, vb.getId()).list(); |
| | | public void deleteWX(WXAd ad) { |
| | | wxAdDao.delete(ad); |
| | | } |
| | | |
| | | List<DetailSystemSelect> dssList = new ArrayList<DetailSystemSelect>(); |
| | | public WXAd getWXAd(Serializable id) { |
| | | return wxAdDao.find(WXAd.class, id); |
| | | } |
| | | |
| | | for (DetailSystem ds : detailSystemList) { |
| | | DetailSystemSelect dss = new DetailSystemSelect(); |
| | | dss.setDetailSystem(ds); |
| | | dss.setSelected(false); |
| | | dssList.add(dss); |
| | | } |
| | | public void updateWXAd(WXAd ad) { |
| | | wxAdDao.update(ad); |
| | | } |
| | | |
| | | // 设置已经存在的 |
| | | for (DetailSystem ds : detailSystemS) { |
| | | for (DetailSystemSelect dss : dssList) { |
| | | if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) { |
| | | dss.setSelected(true); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | SuperRecommendAd sz = new SuperRecommendAd(); |
| | | sz.setDetailSystem(null); |
| | | sz.setRecommendAd(vb); |
| | | zhiBoClassList.add(new RecommendAdAdmin(sz, dssList)); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return zhiBoClassList; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | public long getRecommendAdAdminCount(String key, int detailSystem) { |
| | | String sql = ""; |
| | | if (detailSystem > 0) |
| | | sql = "select count(*) from (select count(*) from wk_video_super_recommendad zb left join wk_ad_recommend c on c.id=zb.recommendadid where zb.detailsystem=" |
| | | + detailSystem + " group by zb.recommendadid) s"; |
| | | else |
| | | sql = "select count(*) from (select count(*) from wk_video_super_recommendad zb left join wk_ad_recommend c on c.id=zb.recommendadid group by zb.recommendadid) s"; |
| | | |
| | | return recommendAdDao.getCountSQL(sql); |
| | | } |
| | | |
| | | @SuppressWarnings("rawtypes") |
| | | public void addRecommendAdAdmin(final String classid, final String detailSystemId) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List list = session |
| | | .createQuery("from SuperRecommendAd vb where vb.recommendAd.id=? and vb.detailSystem.id=?") |
| | | .setParameter(0, classid).setParameter(1, detailSystemId).list(); |
| | | if (list == null || list.size() == 0) { |
| | | SuperRecommendAd vb = new SuperRecommendAd(); |
| | | vb.setCreatetime(System.currentTimeMillis() + ""); |
| | | vb.setDetailSystem(new DetailSystem(detailSystemId)); |
| | | vb.setRecommendAd(new RecommendAd(classid)); |
| | | session.persist(vb); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| | | public void deleteRecommendAdAdmin(final String classId, final String detailSystemId) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperRecommendAd> list = session |
| | | .createQuery("from SuperRecommendAd vb where vb.recommendAd.id=? and vb.detailSystem.id=?") |
| | | .setParameter(0, classId).setParameter(1, detailSystemId).list(); |
| | | if (list != null && list.size() > 0) { |
| | | for (SuperRecommendAd vb : list) |
| | | session.delete(vb); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | public void AddStatistics(String key, String platform, int type) { |
| | | AdStatistics ad = new AdStatistics(); |
| | | ad.setKey(key); |
| | | ad.setPlatformId(platform); |
| | | ad.setTime(System.currentTimeMillis() + ""); |
| | | ad.setType(type); |
| | | adStatisticsDao.create(ad); |
| | | } |
| | | |
| | | /** |
| | | * 获取微信广告 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<WXAd> getWinAd(SystemInfo system) { |
| | | List<WXAd> list = wxAdDao.list("from WXAd w where w.system.id=" + system.getId()); |
| | | return list; |
| | | } |
| | | |
| | | public List<WXAd> getWinAd() { |
| | | List<WXAd> list = wxAdDao.list("from WXAd"); |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 添加微信广告 |
| | | * |
| | | * @param ad |
| | | */ |
| | | public void addWX(WXAd ad) { |
| | | wxAdDao.create(ad); |
| | | } |
| | | |
| | | public void deleteWX(WXAd ad) { |
| | | wxAdDao.delete(ad); |
| | | } |
| | | |
| | | public WXAd getWXAd(Serializable id) { |
| | | return wxAdDao.find(WXAd.class, id); |
| | | } |
| | | |
| | | public void updateWXAd(WXAd ad) { |
| | | wxAdDao.update(ad); |
| | | } |
| | | |
| | | /** |
| | | * 插入微信统计代码 |
| | | * |
| | | * @param bean |
| | | */ |
| | | public void insertWXStatistics(WXStatistics bean) { |
| | | wxStatisticsDao.create(bean); |
| | | } |
| | | /** |
| | | * 插入微信统计代码 |
| | | * |
| | | * @param bean |
| | | */ |
| | | public void insertWXStatistics(WXStatistics bean) { |
| | | wxStatisticsDao.create(bean); |
| | | } |
| | | |
| | | /** |
| | | * 推荐广告条 |
| | | */ |
| | | @Cacheable(value = "homeCache",key="'getRecommendAdList'+'-'+#detailSystem") |
| | | public List<RecommendAd> getRecommendAdList(String detailSystem) { |
| | | return recommendAdDao |
| | | .list("select hs.recommendAd FROM SuperRecommendAd hs where hs.detailSystem.id=" + detailSystem); |
| | | } |
| | | /** |
| | | * 推荐广告条 |
| | | */ |
| | | @Cacheable(value = "homeCache", key = "'getRecommendAdList'+'-'+#detailSystem") |
| | | public List<RecommendAd> getRecommendAdList(String detailSystem) { |
| | | return recommendAdDao |
| | | .list("select hs.recommendAd FROM SuperRecommendAd hs where hs.detailSystem.id=" + detailSystem); |
| | | } |
| | | |
| | | public void addRecommendAd(SuperRecommendAd sv) { |
| | | List<SuperRecommendAd> list = superRecommendAdDao.list("from SuperRecommendAd sv where sv.recommendAd.id=" |
| | | + sv.getRecommendAd().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId()); |
| | | if (list != null && list.size() > 0) |
| | | return; |
| | | superRecommendAdDao.create(sv); |
| | | } |
| | | public void addRecommendAd(SuperRecommendAd sv) { |
| | | List<SuperRecommendAd> list = superRecommendAdDao.list("from SuperRecommendAd sv where sv.recommendAd.id=" |
| | | + sv.getRecommendAd().getId() + " and sv.detailSystem.id=" + sv.getDetailSystem().getId()); |
| | | if (list != null && list.size() > 0) |
| | | return; |
| | | superRecommendAdDao.create(sv); |
| | | } |
| | | |
| | | public void updateSuperRecommendAd(SuperRecommendAd hotSearch) { |
| | | superRecommendAdDao.update(hotSearch); |
| | | } |
| | | public void updateSuperRecommendAd(SuperRecommendAd hotSearch) { |
| | | superRecommendAdDao.update(hotSearch); |
| | | } |
| | | |
| | | public void deleteSuperRecommendAd(SuperRecommendAd hotSearch) { |
| | | superRecommendAdDao.delete(hotSearch); |
| | | } |
| | | public void deleteSuperRecommendAd(SuperRecommendAd hotSearch) { |
| | | superRecommendAdDao.delete(hotSearch); |
| | | } |
| | | |
| | | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| | | public void updateSuperRecommendAdList(final String detailSystemId, final List<SuperRecommendAd> typeList) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperRecommendAd> list = session |
| | | .createQuery("from SuperRecommendAd sh where sh.detailSystem.id=" + detailSystemId).list(); |
| | | for (SuperRecommendAd ad : list) { |
| | | session.delete(ad); |
| | | } |
| | | @SuppressWarnings({"unchecked", "rawtypes"}) |
| | | public void updateSuperRecommendAdList(final String detailSystemId, final List<SuperRecommendAd> typeList) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<SuperRecommendAd> list = session |
| | | .createQuery("from SuperRecommendAd sh where sh.detailSystem.id=" + detailSystemId).list(); |
| | | for (SuperRecommendAd ad : list) { |
| | | session.delete(ad); |
| | | } |
| | | |
| | | for (SuperRecommendAd videoType : typeList) { |
| | | session.persist(videoType); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | for (SuperRecommendAd videoType : typeList) { |
| | | session.persist(videoType); |
| | | } |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | @Cacheable(value = "classCache",key="'getCommonAdByPid'+'-'+#pid") |
| | | public List<CommonAdPositionAd> getCommonAdByPid(String pid) { |
| | | return commonAdPositionAdDao.list("from CommonAdPositionAd pa where pa.adPosition.id=?", |
| | | new Serializable[] { pid + "" }); |
| | | } |
| | | @Cacheable(value = "classCache", key = "'getCommonAdByPid'+'-'+#pid") |
| | | public List<CommonAdPositionAd> getCommonAdByPid(String pid) { |
| | | return commonAdPositionAdDao.list("from CommonAdPositionAd pa where pa.adPosition.id=?", |
| | | new Serializable[]{pid + ""}); |
| | | } |
| | | |
| | | // 添加广告统计 |
| | | public void addCommonAdStatistics(int type, String pid, String commonAdid, String device) { |
| | | CommonAdStatistics cas = new CommonAdStatistics(); |
| | | cas.setCommonAd(new CommonAd(commonAdid)); |
| | | cas.setCreatetime(System.currentTimeMillis() + ""); |
| | | cas.setType(type); |
| | | cas.setPositionid(pid); |
| | | cas.setDevice(device); |
| | | commonAdStatisticsDao.create(cas); |
| | | } |
| | | // 添加广告统计 |
| | | public void addCommonAdStatistics(int type, String pid, String commonAdid, String device) { |
| | | CommonAdStatistics cas = new CommonAdStatistics(); |
| | | cas.setCommonAd(new CommonAd(commonAdid)); |
| | | cas.setCreatetime(System.currentTimeMillis() + ""); |
| | | cas.setType(type); |
| | | cas.setPositionid(pid); |
| | | cas.setDevice(device); |
| | | commonAdStatisticsDao.create(cas); |
| | | } |
| | | |
| | | public List<CommonAdPosition> getCommonAdPositionList() { |
| | | return (List<CommonAdPosition>) commonAdPositionDao.list("from CommonAdPosition"); |
| | | } |
| | | public List<CommonAdPosition> getCommonAdPositionList() { |
| | | return (List<CommonAdPosition>) commonAdPositionDao.list("from CommonAdPosition"); |
| | | } |
| | | |
| | | public List<CommonAdPositionAd> getCommonAdPositionAd(String key, int pid, int pageIndex) { |
| | | List<CommonAdPositionAd> adList = new ArrayList<CommonAdPositionAd>(); |
| | | adList = commonAdPositionAdDao.list("from CommonAdPositionAd ca where ca.adPosition.id=" + pid + "", |
| | | (pageIndex - 1) * Constant.pageCount, Constant.pageCount, null); |
| | | public List<CommonAdPositionAd> getCommonAdPositionAd(String key, int pid, int pageIndex) { |
| | | List<CommonAdPositionAd> adList = new ArrayList<CommonAdPositionAd>(); |
| | | adList = commonAdPositionAdDao.list("from CommonAdPositionAd ca where ca.adPosition.id=" + pid + "", |
| | | (pageIndex - 1) * Constant.pageCount, Constant.pageCount, null); |
| | | |
| | | for (CommonAdPositionAd ad : adList) { |
| | | ad.setCommonAdPositionList(commonAdPositionDao |
| | | .list("select pa.adPosition from CommonAdPositionAd pa where pa.ad.id=" + ad.getAd().getId())); |
| | | for (CommonAdPositionAd ad : adList) { |
| | | ad.setCommonAdPositionList(commonAdPositionDao |
| | | .list("select pa.adPosition from CommonAdPositionAd pa where pa.ad.id=" + ad.getAd().getId())); |
| | | |
| | | } |
| | | return adList; |
| | | } |
| | | } |
| | | return adList; |
| | | } |
| | | |
| | | public long getCommonAdPositionAdCount(String key, int pid) { |
| | | return commonAdPositionAdDao |
| | | .getCount("select count(*) from CommonAdPositionAd ca where ca.adPosition.id=" + pid + ""); |
| | | } |
| | | public long getCommonAdPositionAdCount(String key, int pid) { |
| | | return commonAdPositionAdDao |
| | | .getCount("select count(*) from CommonAdPositionAd ca where ca.adPosition.id=" + pid + ""); |
| | | } |
| | | |
| | | public Serializable addCommonAd(CommonAd commonAd) { |
| | | return commonAdDao.save(commonAd); |
| | | } |
| | | public Serializable addCommonAd(CommonAd commonAd) { |
| | | return commonAdDao.save(commonAd); |
| | | } |
| | | |
| | | public void addCommonAdPositionAd(CommonAdPositionAd commonAdPositionAd) { |
| | | commonAdPositionAdDao.create(commonAdPositionAd); |
| | | } |
| | | public void addCommonAdPositionAd(CommonAdPositionAd commonAdPositionAd) { |
| | | commonAdPositionAdDao.create(commonAdPositionAd); |
| | | } |
| | | |
| | | public CommonAd getCommonAdById(String id) { |
| | | return commonAdDao.find(CommonAd.class, id); |
| | | } |
| | | public CommonAd getCommonAdById(String id) { |
| | | return commonAdDao.find(CommonAd.class, id); |
| | | } |
| | | |
| | | // 更新 |
| | | public void updateCommonAd(CommonAd commonAd) { |
| | | commonAdDao.update(commonAd); |
| | | } |
| | | // 更新 |
| | | public void updateCommonAd(CommonAd commonAd) { |
| | | commonAdDao.update(commonAd); |
| | | } |
| | | |
| | | @SuppressWarnings({ "unchecked", "rawtypes" }) |
| | | public void deleteCommonAd(final CommonAd ca) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<CommonAdPositionAd> list = session |
| | | .createQuery("from CommonAdPositionAd cp where cp.ad.id=" + ca.getId()).list(); |
| | | for (CommonAdPositionAd cp : list) { |
| | | session.delete(cp); |
| | | } |
| | | session.delete(ca); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | if (session.getTransaction().isActive()) |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | @SuppressWarnings({"unchecked", "rawtypes"}) |
| | | public void deleteCommonAd(final CommonAd ca) { |
| | | recommendAdDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | try { |
| | | session.getTransaction().begin(); |
| | | List<CommonAdPositionAd> list = session |
| | | .createQuery("from CommonAdPositionAd cp where cp.ad.id=" + ca.getId()).list(); |
| | | for (CommonAdPositionAd cp : list) { |
| | | session.delete(cp); |
| | | } |
| | | session.delete(ca); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | } catch (Exception e) { |
| | | session.getTransaction().rollback(); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | public void deleteCommonAdPositionAd(CommonAdPositionAd ad) { |
| | | commonAdPositionAdDao.delete(ad); |
| | | } |
| | | public void deleteCommonAdPositionAd(CommonAdPositionAd ad) { |
| | | commonAdPositionAdDao.delete(ad); |
| | | } |
| | | |
| | | public void deleteCommonAdPositionAd(String adid, String pid) { |
| | | List<CommonAdPositionAd> list = commonAdPositionAdDao |
| | | .list("from CommonAdPositionAd ca where ca.ad.id=" + adid + " and ca.adPosition.id=" + pid); |
| | | for (CommonAdPositionAd ca : list) |
| | | deleteCommonAdPositionAd(ca); |
| | | } |
| | | public void deleteCommonAdPositionAd(String adid, String pid) { |
| | | List<CommonAdPositionAd> list = commonAdPositionAdDao |
| | | .list("from CommonAdPositionAd ca where ca.ad.id=" + adid + " and ca.adPosition.id=" + pid); |
| | | for (CommonAdPositionAd ca : list) |
| | | deleteCommonAdPositionAd(ca); |
| | | } |
| | | |
| | | } |