From 20f473dc4997e8b8a76f8c75d0a649be0a5ea139 Mon Sep 17 00:00:00 2001
From: admin <2780501319@qq.com>
Date: 星期五, 02 四月 2021 00:32:03 +0800
Subject: [PATCH] 广告控制逻辑代码初步编写
---
src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java | 460 +++++++++++++++++++++++++++++----------------------------
1 files changed, 232 insertions(+), 228 deletions(-)
diff --git a/src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java b/src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java
index 1f39450..d9643f9 100644
--- a/src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java
+++ b/src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java
@@ -14,273 +14,277 @@
import com.yeshi.buwan.dao.HomeAdDao;
import com.yeshi.buwan.dao.SuperHomeAdDao;
-import com.yeshi.buwan.domain.DetailSystem;
+import com.yeshi.buwan.domain.system.DetailSystem;
import com.yeshi.buwan.domain.HomeAd;
import com.yeshi.buwan.domain.SuperHomeAd;
-import com.yeshi.buwan.domain.SystemInfo;
+import com.yeshi.buwan.domain.system.SystemInfo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.web.DetailSystemSelect;
import com.yeshi.buwan.domain.web.HomeAdAdmin;
import com.yeshi.buwan.util.Constant;
+import org.yeshi.utils.StringUtil;
@Service
public class HomeAdService {
- @Resource
- private HomeAdDao homeAdDao;
- @Resource
- private SuperHomeAdDao superHomeAdDao;
+ @Resource
+ private HomeAdDao homeAdDao;
+ @Resource
+ private SuperHomeAdDao superHomeAdDao;
- public SuperHomeAdDao getSuperHomeAdDao() {
- return superHomeAdDao;
- }
+ public List<HomeAd> getHomeAdList(SystemInfo system) {
+ List<HomeAd> list = homeAdDao
+ .list("from HomeAd h where h.system.id=" + system.getId() + " order by h.orderby desc");
+ return list;
+ }
- public void setSuperHomeAdDao(SuperHomeAdDao superHomeAdDao) {
- this.superHomeAdDao = superHomeAdDao;
- }
+ @Cacheable(value = "homeCache", key = "'getHomeAdList'+'-'+#detailSystem.id+'-'+#dataKey")
+ public List<HomeAd> getHomeAdList(DetailSystem detailSystem,String dataKey) {
+ List<HomeAd> list = homeAdDao.list("select h.homeAd from SuperHomeAd h where h.detailSystem.id=? and h.homeAd.specialDataKey=? order by h.homeAd.orderby desc",detailSystem.getId(),dataKey);
+ return list;
+ }
- public HomeAdDao getHomeAdDao() {
- return homeAdDao;
- }
+ public static List<HomeAd> getIOSTestHomeAdList() {
+ List<HomeAd> list = new ArrayList<>();
+ HomeAd ad = new HomeAd();
+ ad.setPicture("http://img.zcool.cn/community/01a5a7562499216ac7254878995802.jpg");
+ VideoInfo info = new VideoInfo();
+ info.setId("161850");
+ info.setName("銆愭憯鏉负鍙枫�戣档瀹剁彮鐖跺瓙鎽旀澂婕旈椆鍓�");
+ info.setPicture("http://img2.funshion.com/pictures/poseidon01/418/985/4189850_v_still.jpg");
+ info.setThirdType("0");
+ info.setShare("0");
+ ad.setVideo(info);
+ list.add(ad);
- public void setHomeAdDao(HomeAdDao homeAdDao) {
- this.homeAdDao = homeAdDao;
- }
+ ad = new HomeAd();
+ ad.setPicture("http://img.zcool.cn/community/01ac60563acca86ac7259e0fe92cae.jpg");
+ info = new VideoInfo();
+ info.setId("161334");
+ info.setName("銆愬啹宸┿�戝啹宸�,鐗涜帀銆婂か濡绘棩璁般��");
+ info.setPicture("http://img.zcool.cn/community/01ac60563acca86ac7259e0fe92cae.jpg");
+ info.setThirdType("0");
+ info.setShare("0");
+ ad.setVideo(info);
+ list.add(ad);
- public List<HomeAd> getHomeAdList(SystemInfo system) {
- List<HomeAd> list = homeAdDao
- .list("from HomeAd h where h.system.id=" + system.getId() + " order by h.orderby desc");
- return list;
- }
+ ad = new HomeAd();
+ ad.setPicture("http://img.zcool.cn/community/01ae2b563accb032f87512f63f63ad.jpg");
+ info = new VideoInfo();
+ info.setId("163707");
+ info.setName("銆愰儹寰风翰浜庤唉銆戙�婅唉鍝ュ甫鍎垮瓙瑙佷笘闈€��");
+ info.setPicture("http://img.zcool.cn/community/01cdfb563acca06ac7259e0fb69676.jpg");
+ info.setThirdType("0");
+ info.setShare("0");
+ ad.setVideo(info);
+ list.add(ad);
- @Cacheable(value = "homeCache", key = "'getHomeAdList'+'-'+#detailSystem.id")
- public List<HomeAd> getHomeAdList(DetailSystem detailSystem) {
- List<HomeAd> list = homeAdDao.list("select h.homeAd from SuperHomeAd h where h.detailSystem.id="
- + detailSystem.getId() + " order by h.homeAd.orderby desc");
- return list;
- }
+ ad = new HomeAd();
+ ad.setPicture("http://img.zcool.cn/community/01ae2b563accb032f87512f63f63ad.jpg");
+ info = new VideoInfo();
+ info.setId("161339");
+ info.setName("銆愭涔愬枩鍓т汉銆戝紑蹇冮夯鑺便�婃劅鏌撹�呫��");
+ info.setPicture("http://img2.funshion.com/pictures/poseidon01/418/985/4189850_v_still.jpg");
+ info.setThirdType("0");
+ info.setShare("0");
+ ad.setVideo(info);
+ list.add(ad);
- public static List<HomeAd> getIOSTestHomeAdList() {
- List<HomeAd> list = new ArrayList<>();
- HomeAd ad = new HomeAd();
- ad.setPicture("http://img.zcool.cn/community/01a5a7562499216ac7254878995802.jpg");
- VideoInfo info = new VideoInfo();
- info.setId("161850");
- info.setName("銆愭憯鏉负鍙枫�戣档瀹剁彮鐖跺瓙鎽旀澂婕旈椆鍓�");
- info.setPicture("http://img2.funshion.com/pictures/poseidon01/418/985/4189850_v_still.jpg");
- info.setThirdType("0");
- info.setShare("0");
- ad.setVideo(info);
- list.add(ad);
+ return list;
+ }
- ad = new HomeAd();
- ad.setPicture("http://img.zcool.cn/community/01ac60563acca86ac7259e0fe92cae.jpg");
- info = new VideoInfo();
- info.setId("161334");
- info.setName("銆愬啹宸┿�戝啹宸�,鐗涜帀銆婂か濡绘棩璁般��");
- info.setPicture("http://img.zcool.cn/community/01ac60563acca86ac7259e0fe92cae.jpg");
- info.setThirdType("0");
- info.setShare("0");
- ad.setVideo(info);
- list.add(ad);
+ public List<HomeAd> getHomeAdList() {
- ad = new HomeAd();
- ad.setPicture("http://img.zcool.cn/community/01ae2b563accb032f87512f63f63ad.jpg");
- info = new VideoInfo();
- info.setId("163707");
- info.setName("銆愰儹寰风翰浜庤唉銆戙�婅唉鍝ュ甫鍎垮瓙瑙佷笘闈€��");
- info.setPicture("http://img.zcool.cn/community/01cdfb563acca06ac7259e0fb69676.jpg");
- info.setThirdType("0");
- info.setShare("0");
- ad.setVideo(info);
- list.add(ad);
+ List<HomeAd> list = homeAdDao.list("from HomeAd ha order by ha.orderby desc");
+ return list;
+ }
- ad = new HomeAd();
- ad.setPicture("http://img.zcool.cn/community/01ae2b563accb032f87512f63f63ad.jpg");
- info = new VideoInfo();
- info.setId("161339");
- info.setName("銆愭涔愬枩鍓т汉銆戝紑蹇冮夯鑺便�婃劅鏌撹�呫��");
- info.setPicture("http://img2.funshion.com/pictures/poseidon01/418/985/4189850_v_still.jpg");
- info.setThirdType("0");
- info.setShare("0");
- ad.setVideo(info);
- list.add(ad);
+ @SuppressWarnings("unchecked")
+ public void deleteHomeAd(final String id) {
+ homeAdDao.excute(new HibernateCallback() {
+ public Object doInHibernate(Session session) throws HibernateException {
+ try {
+ List<SuperHomeAd> list = session.createQuery("from SuperHomeAd sh where sh.homeAd.id=?")
+ .setParameter(0, id).list();
+ session.getTransaction().begin();
+ for (SuperHomeAd shd : list)
+ session.delete(shd);
+ session.createQuery("delete from HomeAd ha where ha.id=?").setParameter(0, id).executeUpdate();
+ session.flush();
+ session.getTransaction().commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ session.getTransaction().rollback();
+ }
+ return null;
+ }
+ });
- return list;
- }
+ }
- public List<HomeAd> getHomeAdList() {
+ public Serializable addHomeAd(HomeAd ad) {
+ return homeAdDao.save(ad);
+ }
- List<HomeAd> list = homeAdDao.list("from HomeAd ha order by ha.orderby desc");
- return list;
- }
+ public HomeAd getHomeAdById(String id) {
- @SuppressWarnings("unchecked")
- public void deleteHomeAd(final String id) {
- homeAdDao.excute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateException {
- try {
- List<SuperHomeAd> list = session.createQuery("from SuperHomeAd sh where sh.homeAd.id=?")
- .setParameter(0, id).list();
- session.getTransaction().begin();
- for (SuperHomeAd shd : list)
- session.delete(shd);
- session.createQuery("delete from HomeAd ha where ha.id=?").setParameter(0, id).executeUpdate();
- session.flush();
- session.getTransaction().commit();
- } catch (Exception e) {
- e.printStackTrace();
- session.getTransaction().rollback();
- }
- return null;
- }
- });
+ return homeAdDao.find(HomeAd.class, id);
+ }
- }
+ public void updateHomeAd(HomeAd ad) {
+ homeAdDao.update(ad);
+ }
- public Serializable addHomeAd(HomeAd ad) {
- return homeAdDao.save(ad);
- }
+ // 鍚庡彴鎿嶄綔
+ @SuppressWarnings("unchecked")
+ public List<HomeAdAdmin> getHomeAdAdmin(final String key, final String systemId, final int detailSystem, final String dataKey, final int page) {
+ return (List<HomeAdAdmin>) homeAdDao.excute(new HibernateCallback<List<HomeAdAdmin>>() {
+ public List<HomeAdAdmin> doInHibernate(Session session) throws HibernateException {
+ List<HomeAdAdmin> zhiBoClassList = new ArrayList<>();
+ try {
+ List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem ds where ds.system.id=" + systemId).list();
+ String sql = "";
+ List<String> andList = new ArrayList<>();
+ if (detailSystem > 0) {
+ andList.add("sh.detailSystem.id=" + detailSystem);
+ if (dataKey != null) {
+ andList.add("sh.homeAd.specialDataKey='" + dataKey + "'");
+ }
- public HomeAd getHomeAdById(String id) {
+ sql = "select sh.homeAd from SuperHomeAd sh where " + StringUtil.concat(andList, " and ") + " order by sh.homeAd.createtime desc";
+ } else {
+ andList.add("zb.system.id=" + systemId);
+ if (dataKey != null) {
+ andList.add("zb.specialDataKey='" + dataKey + "'");
+ }
+ sql = "from HomeAd zb where " + StringUtil.concat(andList, " and ") + " order by zb.createtime desc";
+ }
+ List<HomeAd> list = session.createQuery(sql).setFirstResult((page - 1) * Constant.pageCount)
+ .setMaxResults(Constant.pageCount).list();
+ for (HomeAd vb : list) {
+ List<DetailSystem> detailSystemS = session
+ .createQuery("select vb.detailSystem from SuperHomeAd vb where vb.homeAd.id=?")
+ .setParameter(0, vb.getId()).list();
- return homeAdDao.find(HomeAd.class, id);
- }
+ List<DetailSystemSelect> dssList = new ArrayList<>();
- public void updateHomeAd(HomeAd ad) {
- homeAdDao.update(ad);
- }
+ for (DetailSystem ds : detailSystemList) {
+ DetailSystemSelect dss = new DetailSystemSelect();
+ dss.setDetailSystem(ds);
+ dss.setSelected(false);
+ dssList.add(dss);
+ }
- // 鍚庡彴鎿嶄綔
- @SuppressWarnings("unchecked")
- public List<HomeAdAdmin> getHomeAdAdmin(final String key, final int detailSystem, final int page) {
- return (List<HomeAdAdmin>) homeAdDao.excute(new HibernateCallback<List<HomeAdAdmin>>() {
- public List<HomeAdAdmin> doInHibernate(Session session) throws HibernateException {
- List<HomeAdAdmin> zhiBoClassList = new ArrayList<>();
- try {
- List<DetailSystem> detailSystemList = session.createQuery("from DetailSystem").list();
- String sql = "";
- if (detailSystem > 0)
- sql = "select sh.homeAd from SuperHomeAd sh where sh.detailSystem.id=" + detailSystem
- + " order by sh.homeAd.createtime desc";
- else
- sql = "from HomeAd zb order by zb.createtime desc";
+ // 璁剧疆宸茬粡瀛樺湪鐨�
+ for (DetailSystem ds : detailSystemS) {
+ for (DetailSystemSelect dss : dssList) {
+ if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
+ dss.setSelected(true);
+ break;
+ }
+ }
+ }
+ SuperHomeAd sz = new SuperHomeAd();
+ sz.setDetailSystem(null);
+ sz.setHomeAd(vb);
+ zhiBoClassList.add(new HomeAdAdmin(sz, dssList));
+ }
- List<HomeAd> list = session.createQuery(sql).setFirstResult((page - 1) * Constant.pageCount)
- .setMaxResults(Constant.pageCount).list();
- for (HomeAd vb : list) {
- List<DetailSystem> detailSystemS = session
- .createQuery("select vb.detailSystem from SuperHomeAd vb where vb.homeAd.id=?")
- .setParameter(0, vb.getId()).list();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return zhiBoClassList;
+ }
+ });
+ }
- List<DetailSystemSelect> dssList = new ArrayList<>();
+ public long getHomeAdAdminCount(String key, String systemId, int detailSystem, String dataKey) {
+ String sql = "";
+ List<String> andList = new ArrayList<>();
+ if (detailSystem > 0) {
+ andList.add("zb.detailsystemid=" + detailSystem);
+ if (dataKey != null) {
+ andList.add("c.special_data_key='" + dataKey + "'");
+ }
- for (DetailSystem ds : detailSystemList) {
- DetailSystemSelect dss = new DetailSystemSelect();
- dss.setDetailSystem(ds);
- dss.setSelected(false);
- dssList.add(dss);
- }
+ sql = "select count(*) from (select count(*) from wk_video_super_homead zb left join wk_video_homead c on c.id=zb.homeadid where " + StringUtil.concat(andList, " and ") + " group by zb.homeadid) s";
+ } else {
+ andList.add("system=" + systemId);
+ if (dataKey != null) {
+ andList.add("special_data_key='" + dataKey + "'");
+ }
- // 璁剧疆宸茬粡瀛樺湪鐨�
- for (DetailSystem ds : detailSystemS) {
- for (DetailSystemSelect dss : dssList) {
- if (dss.getDetailSystem().getId().equalsIgnoreCase(ds.getId())) {
- dss.setSelected(true);
- break;
- }
- }
- }
- SuperHomeAd sz = new SuperHomeAd();
- sz.setDetailSystem(null);
- sz.setHomeAd(vb);
- zhiBoClassList.add(new HomeAdAdmin(sz, dssList));
- }
+ sql = "select count(*) from wk_video_homead where " + StringUtil.concat(andList, " and ");
+ }
+ return homeAdDao.getCountSQL(sql);
+ }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return zhiBoClassList;
- }
- });
- }
+ @SuppressWarnings("unchecked")
+ public void deleteHomeAdAdmin(final String classId, final String detailSystemId) {
+ homeAdDao.excute(new HibernateCallback() {
+ public Object doInHibernate(Session session) throws HibernateException {
+ try {
+ List<SuperHomeAd> list = session
+ .createQuery("from SuperHomeAd vb where vb.homeAd.id=? and vb.detailSystem.id=?")
+ .setParameter(0, classId).setParameter(1, detailSystemId).list();
+ session.getTransaction().begin();
+ if (list != null && list.size() > 0) {
+ for (SuperHomeAd vb : list)
+ session.delete(vb);
+ }
+ session.flush();
+ session.getTransaction().commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ session.getTransaction().rollback();
+ }
+ return null;
+ }
+ });
- public long getHomeAdAdminCount(String key, int detailSystem) {
- String sql = "";
- if (detailSystem > 0)
- sql = "select count(*) from (select count(*) from wk_video_super_homead zb left join wk_video_homead c on c.id=zb.homeadid where zb.detailsystemid="
- + detailSystem + " group by zb.homeadid) s";
- else
- sql = "select count(*) from wk_video_homead";
- return homeAdDao.getCountSQL(sql);
- }
+ }
- @SuppressWarnings("unchecked")
- public void deleteHomeAdAdmin(final String classId, final String detailSystemId) {
- homeAdDao.excute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateException {
- try {
- List<SuperHomeAd> list = session
- .createQuery("from SuperHomeAd vb where vb.homeAd.id=? and vb.detailSystem.id=?")
- .setParameter(0, classId).setParameter(1, detailSystemId).list();
- session.getTransaction().begin();
- if (list != null && list.size() > 0) {
- for (SuperHomeAd vb : list)
- session.delete(vb);
- }
- session.flush();
- session.getTransaction().commit();
- } catch (Exception e) {
- e.printStackTrace();
- session.getTransaction().rollback();
- }
- return null;
- }
- });
+ public List<HomeAd> getSuperHomeAdList(String detailSystemId) {
+ return homeAdDao.list("select sh.homeAd from SuperHomeAd sh where sh.detailSystem.id=" + detailSystemId);
+ }
- }
+ // 鏇存柊骞垮憡鍒楄〃
+ @SuppressWarnings("unchecked")
+ public void updateSuperHomeAdList(final String detailSystemId, final List<HomeAd> adList) {
+ homeAdDao.excute(new HibernateCallback() {
+ public Object doInHibernate(Session session) throws HibernateException {
+ try {
+ List<SuperHomeAd> list = session
+ .createQuery("from SuperHomeAd sh where sh.detailSystem.id=" + detailSystemId).list();
+ session.getTransaction().begin();
+ for (SuperHomeAd ad : list) {
+ session.delete(ad);
+ }
- public List<HomeAd> getSuperHomeAdList(String detailSystemId) {
- return homeAdDao.list("select sh.homeAd from SuperHomeAd sh where sh.detailSystem.id=" + detailSystemId);
- }
+ for (HomeAd homeAd : adList) {
+ SuperHomeAd shd = new SuperHomeAd();
+ shd.setCreatetime(System.currentTimeMillis() + "");
+ shd.setDetailSystem(new DetailSystem(detailSystemId));
+ shd.setHomeAd(homeAd);
+ session.persist(shd);
+ }
+ session.flush();
+ session.getTransaction().commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ session.getTransaction().rollback();
+ }
+ return null;
+ }
+ });
- // 鏇存柊骞垮憡鍒楄〃
- @SuppressWarnings("unchecked")
- public void updateSuperHomeAdList(final String detailSystemId, final List<HomeAd> adList) {
- homeAdDao.excute(new HibernateCallback() {
- public Object doInHibernate(Session session) throws HibernateException {
- try {
- List<SuperHomeAd> list = session
- .createQuery("from SuperHomeAd sh where sh.detailSystem.id=" + detailSystemId).list();
- session.getTransaction().begin();
- for (SuperHomeAd ad : list) {
- session.delete(ad);
- }
+ }
- for (HomeAd homeAd : adList) {
- SuperHomeAd shd = new SuperHomeAd();
- shd.setCreatetime(System.currentTimeMillis() + "");
- shd.setDetailSystem(new DetailSystem(detailSystemId));
- shd.setHomeAd(homeAd);
- session.persist(shd);
- }
- session.flush();
- session.getTransaction().commit();
- } catch (Exception e) {
- e.printStackTrace();
- session.getTransaction().rollback();
- }
- return null;
- }
- });
-
- }
-
- public void addSuperHomeAd(SuperHomeAd sv) {
- List<SuperHomeAd> list = superHomeAdDao.list("from SuperHomeAd sv where sv.homeAd.id=" + sv.getHomeAd().getId()
- + " and sv.detailSystem.id=" + sv.getDetailSystem().getId());
- if (list != null && list.size() > 0)
- return;
- superHomeAdDao.create(sv);
- }
+ public void addSuperHomeAd(SuperHomeAd sv) {
+ List<SuperHomeAd> list = superHomeAdDao.list("from SuperHomeAd sv where sv.homeAd.id=" + sv.getHomeAd().getId()
+ + " and sv.detailSystem.id=" + sv.getDetailSystem().getId());
+ if (list != null && list.size() > 0)
+ return;
+ superHomeAdDao.create(sv);
+ }
}
--
Gitblit v1.8.0