admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
src/main/java/com/yeshi/buwan/dao/VideoInfoDao.java
@@ -1,15 +1,252 @@
package com.yeshi.buwan.dao;
import com.yeshi.buwan.dao.base.BaseDao;
import com.yeshi.buwan.query.BaseQuery;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Repository;
import com.yeshi.buwan.domain.VideoInfo;
import org.yeshi.utils.StringUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Repository
public class VideoInfoDao extends BaseDao<VideoInfo> {
    /**
     * 选择性更新
     *
     * @param bean
     */
    public void updateSelective(VideoInfo bean) {
        List<String> wheres = new ArrayList<>();
        List<Serializable> params = new ArrayList<>();
        if (bean.getTag() != null) {
            wheres.add("vi.tag=?");
            params.add(bean.getTag());
        }
        if (bean.getTotalNumber() != null) {
            wheres.add("vi.totalNumber=?");
            params.add(bean.getTotalNumber());
        }
        if (bean.getPicture() != null) {
            wheres.add("vi.picture=?");
            params.add(bean.getPicture());
        }
        if (bean.getName() != null) {
            wheres.add("vi.name=?");
            params.add(bean.getName());
        }
        if (bean.getIntroduction() != null) {
            wheres.add("vi.introduction=?");
            params.add(bean.getIntroduction());
        }
        if (bean.getDuration() != null) {
            wheres.add("vi.duration=?");
            params.add(bean.getDuration());
        }
        if (bean.getMainActor() != null) {
            wheres.add("vi.mainActor=?");
            params.add(bean.getMainActor());
        }
        if (bean.getYear() != null) {
            wheres.add("vi.year=?");
            params.add(bean.getYear());
        }
        if (bean.getBeizhu() != null) {
            wheres.add("vi.beizhu=?");
            params.add(bean.getBeizhu());
        }
        if (bean.getQulity() != null) {
            wheres.add("vi.qulity=?");
            params.add(bean.getQulity());
        }
        if (bean.getScore() != null) {
            wheres.add("vi.score=?");
            params.add(bean.getScore());
        }
        if (bean.getShare() != null) {
            wheres.add("vi.share=?");
            params.add(bean.getShare());
        }
        if (bean.getShow() != null) {
            wheres.add("vi.show=?");
            params.add(bean.getShow());
        }
        if (bean.getWatchCount() != null) {
            wheres.add("vi.watchCount=?");
            params.add(bean.getWatchCount());
        }
        if (bean.getOrderby() != null) {
            wheres.add("vi.orderby=?");
            params.add(bean.getOrderby());
        }
        if (bean.getNowNumber() != null) {
            wheres.add("vi.nowNumber=?");
            params.add(bean.getNowNumber());
        }
        if (bean.getFinish() != null) {
            wheres.add("vi.finish=?");
            params.add(bean.getFinish());
        }
        if (bean.getBaseurl() != null) {
            wheres.add("vi.baseurl=?");
            params.add(bean.getBaseurl());
        }
        if (bean.getMonth() != null) {
            wheres.add("vi.month=?");
            params.add(bean.getMonth());
        }
        if (bean.getDay() != null) {
            wheres.add("vi.day=?");
            params.add(bean.getDay());
        }
        if (bean.getArea() != null) {
            wheres.add("vi.area=?");
            params.add(bean.getArea());
        }
        if (bean.getFocus() != null) {
            wheres.add("vi.focus=?");
            params.add(bean.getFocus());
        }
        if (bean.getLeafctgs() != null) {
            wheres.add("vi.leafctgs=?");
            params.add(bean.getLeafctgs());
        }
        if (bean.getDirector() != null) {
            wheres.add("vi.director=?");
            params.add(bean.getDirector());
        }
        if (bean.getKeyword() != null) {
            wheres.add("vi.keyword=?");
            params.add(bean.getKeyword());
        }
        if (bean.getVpicture() != null) {
            wheres.add("vi.vpicture=?");
            params.add(bean.getVpicture());
        }
        if (bean.getHpicture() != null) {
            wheres.add("vi.hpicture=?");
            params.add(bean.getHpicture());
        }
        if (bean.getLatestVpicture() != null) {
            wheres.add("vi.latestVpicture=?");
            params.add(bean.getLatestVpicture());
        }
        if (bean.getLatestHpicture() != null) {
            wheres.add("vi.latestHpicture=?");
            params.add(bean.getLatestHpicture());
        }
        if (bean.getContentType() != null) {
            wheres.add("vi.contentType=?");
            params.add(bean.getContentType());
        }
        if (bean.getCanSave() != null) {
            wheres.add("vi.canSave=?");
            params.add(bean.getCanSave());
        }
        if (bean.getAdmin() != null) {
            wheres.add("vi.admin=?");
            params.add(bean.getAdmin());
        }
        if (bean.getVideoType() != null) {
            wheres.add("vi.videoType=?");
            params.add(bean.getVideoType());
        }
        if (bean.getCommentCount() != null) {
            wheres.add("vi.commentCount=?");
            params.add(bean.getCommentCount());
        }
        if (bean.getLatestWatchCount() != null) {
            wheres.add("vi.latestWatchCount=?");
            params.add(bean.getLatestWatchCount());
        }
        if (bean.getVideocount() != null) {
            wheres.add("vi.videocount=?");
            params.add(bean.getVideocount());
        }
        if (bean.getType() != null) {
            wheres.add("vi.type=?");
            params.add(bean.getType());
        }
        wheres.add("vi.updatetime=?");
        params.add(System.currentTimeMillis() + "");
        String hql = "update VideoInfo vi set " + StringUtil.concat(wheres, ",") + " where vi.id=" + bean.getId();
        Serializable[] ps = new Serializable[params.size()];
        params.toArray(ps);
        update(hql, ps);
    }
    public List<VideoInfo> list(DaoQuery query) {
        String hql = "from VideoInfo vi ";
        List<Serializable> paramList = new ArrayList<>();
        List<String> andList = new ArrayList<>();
        if (query.show != null) {
            andList.add("vi.show= ?");
            paramList.add(query.show);
        }
        if (query.name != null) {
            andList.add("vi.name= ?");
            paramList.add(query.name);
        }
        if (query.minId != null) {
            andList.add("vi.id>=" + query.minId);
        }
        if (andList.size() > 0) {
            hql += "where " + StringUtil.concat(andList, " and ");
        }
        Serializable[] params = new Serializable[paramList.size()];
        paramList.toArray(params);
        return findList(hql, (int) query.start, query.count, params);
    }
    public long count(DaoQuery query) {
        String hql = "from VideoInfo vi ";
        List<Serializable> paramList = new ArrayList<>();
        List<String> andList = new ArrayList<>();
        if (query.show != null) {
            andList.add("vi.show= ?");
            paramList.add(query.show);
        }
        if (query.name != null) {
            andList.add("vi.name= ?");
            paramList.add(query.name);
        }
        if (query.minId != null) {
            andList.add("vi.id>=" + query.minId);
        }
        if (andList.size() > 0) {
            hql += "where " + StringUtil.concat(andList, " and ");
        }
        Serializable[] params = new Serializable[paramList.size()];
        paramList.toArray(params);
        return getCount(hql, params);
    }
    /**
     * 根据名字查询
@@ -20,7 +257,53 @@
     * @return
     */
    public List<VideoInfo> listByName(String name, int start, int count) {
        return list("from VideoInfo vi where vi.name=?", start, count, new Serializable[]{name});
        DaoQuery query = new DaoQuery();
        query.start = start;
        query.count = count;
        query.name = name;
        return list(query);
    }
    /**
     * 根据主键批量查询
     *
     * @param videoIds
     * @return
     */
    public List<VideoInfo> listByVideoIds(List<String> videoIds) {
        String hql = "from VideoInfo vi where ";
        List<String> ors = new ArrayList<>();
        for (String vi : videoIds) {
            ors.add(" vi.id=? ");
        }
        hql += StringUtil.concat(ors, "or");
        String[] videos = new String[videoIds.size()];
        videoIds.toArray(videos);
        return list(hql, videos);
    }
    /**
     * 统计视频附加信息(包含地区,分类,来源)
     *
     * @param videoId -视频ID
     */
    public void statisticVideoExtraInfo(final String videoId) {
        excute(new HibernateCallback() {
            @Override
            public Object doInHibernate(Session session) throws HibernateException {
                session.getTransaction().begin();
                session.createSQLQuery(String.format("call copyvideotemp(%s)", videoId)).executeUpdate();
                session.getTransaction().commit();
                return null;
            }
        });
    }
    public static class DaoQuery extends BaseQuery {
        public String show;
        public String name;
        public Long minId;
    }
}