From d73687bc6115007145b4aab050e4e29ff87fd8ae Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 01 三月 2021 18:44:36 +0800 Subject: [PATCH] 布丸代码优化 --- src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java | 440 ++++++++++++++++++++++++++---------------------------- 1 files changed, 212 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..8090b78 100644 --- a/src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java +++ b/src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java @@ -25,262 +25,246 @@ @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") + 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; + } - 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 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 = ""; + 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 where zb.system.id=" + systemId + " order by zb.createtime desc"; - public HomeAd getHomeAdById(String id) { + 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 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 where system="+systemId; + return homeAdDao.getCountSQL(sql); + } - for (DetailSystem ds : detailSystemList) { - DetailSystemSelect dss = new DetailSystemSelect(); - dss.setDetailSystem(ds); - dss.setSelected(false); - dssList.add(dss); - } + @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; + } + }); - // 璁剧疆宸茬粡瀛樺湪鐨� - 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)); - } + } - } catch (Exception e) { - e.printStackTrace(); - } - return zhiBoClassList; - } - }); - } + public List<HomeAd> getSuperHomeAdList(String detailSystemId) { + return homeAdDao.list("select sh.homeAd from SuperHomeAd sh where sh.detailSystem.id=" + detailSystemId); + } - 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 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); + } - @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; - } - }); + 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 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); - } - - 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