admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
src/main/java/com/yeshi/buwan/service/imp/HomeAdService.java
@@ -22,6 +22,7 @@
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 {
@@ -36,10 +37,9 @@
        return list;
    }
    @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");
    @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;
    }
@@ -136,19 +136,28 @@
    // 后台操作
    @SuppressWarnings("unchecked")
    public List<HomeAdAdmin> getHomeAdAdmin(final String key, final String systemId, final int detailSystem, final int page) {
    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 = "";
                    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";
                    List<String> andList = new ArrayList<>();
                    if (detailSystem > 0) {
                        andList.add("sh.detailSystem.id=" + detailSystem);
                        if (dataKey != null) {
                            andList.add("sh.homeAd.specialDataKey='" + dataKey + "'");
                        }
                        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) {
@@ -188,13 +197,24 @@
        });
    }
    public long getHomeAdAdminCount(String key, String systemId, int detailSystem) {
    public long getHomeAdAdminCount(String key, String systemId, int detailSystem, String dataKey) {
        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;
        List<String> andList = new ArrayList<>();
        if (detailSystem > 0) {
            andList.add("zb.detailsystemid=" + detailSystem);
            if (dataKey != null) {
                andList.add("c.special_data_key='" + dataKey + "'");
            }
            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 + "'");
            }
            sql = "select count(*) from  wk_video_homead where " + StringUtil.concat(andList, " and ");
        }
        return homeAdDao.getCountSQL(sql);
    }