派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/******************************************************************************
 * Copyright (C) 2015 Shenzhen Penguin Network Technology Co., Ltd
 * All Rights Reserved.
 * ±¾Èí¼þΪÉîÛÚÊÐÆó¶ìÍøÂç¿Æ¼¼ÓÐÏÞ¹«Ë¾¿ª·¢ÑÐÖÆ¡£Î´¾­±¾¹«Ë¾ÕýʽÊéÃæÍ¬Ò⣬ÆäËûÈκθöÈË¡¢ÍÅÌå
 * ²»µÃʹÓᢸ´ÖÆ¡¢Ð޸Ļò·¢²¼±¾Èí¼þ.
 *****************************************************************************/
 
package com.qxueyou.scc.media.dao;
 
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Repository;
 
import com.qxueyou.scc.base.dao.BaseDAO;
import com.qxueyou.scc.media.model.MediaVideo;
import com.qxueyou.scc.media.model.MediaVideoTrans;
import com.qxueyou.scc.media.model.MediaVideoViewVO;
import com.qxueyou.scc.school.model.SchClassSchedule;
import com.qxueyou.scc.school.model.SchReLessonVideo;
 
 
 
/**
 * 
 * @author ody.yuan
 *
 */
@Repository(value="mediaVideoDAO")
public class MediaVideoDAO extends BaseDAO {
 
    private Logger log = LogManager.getLogger(MediaVideoDAO.class);
    
    /**
     *²éѯ´íÌâ ÊղضÔÓ¦µÄÁ·Ï°¼Ç¼
     * @return
     * @throws ParseException 
     */
    @SuppressWarnings({ "unchecked"})
    public List<MediaVideoViewVO> queryMediaVideoList(String hql,List<Object> args){
        List<MediaVideoViewVO> lstViewVOs = new ArrayList<MediaVideoViewVO>();
        MediaVideoViewVO viewVO;
        List<Object[]> lst = (List<Object[]>) this.getHibernateTemplate().find(hql, args.toArray());
        try {
            for (Object[] obj : lst) {
                viewVO = new MediaVideoViewVO();
                
                viewVO.setVideoId(String.valueOf(obj[0]));
                
                String tempName = String.valueOf(obj[1]);
                if(StringUtils.isNotBlank(tempName) && tempName.indexOf(".") != -1){
                    viewVO.setName(tempName.substring(0, tempName.lastIndexOf(".")));
                }else{
                    viewVO.setName("");
                }
                
                viewVO.setUrl(String.valueOf(obj[2]));
                viewVO.setOrigUrl(String.valueOf(obj[3]));
                viewVO.setSize( null != obj[4] ? Integer.parseInt(String.valueOf(obj[4])) : 0 );
                viewVO.setPlayTime( null != obj[5] ? Integer.parseInt(String.valueOf(obj[5])) : 0 );
                viewVO.setCoverPageUrl(String.valueOf(obj[6]));
                viewVO.setPlayTimes( null != obj[7] ? Integer.parseInt(String.valueOf(obj[7])) : 0 );
                viewVO.setRemark(String.valueOf(obj[8]));
                viewVO.setFormat(String.valueOf(obj[9]));
                
                viewVO.setTeacherId(String.valueOf(obj[10]));
                viewVO.setTeacherName(String.valueOf(obj[11]));
                
                viewVO.setCacheFlag(false);
                viewVO.setDownloadFlag(false);
                
                lstViewVOs.add(viewVO);
            }
        } catch (Exception e) {
            log.error("APPÊÓÆµÁбí³ö´í£º", e);
        }
        
        return lstViewVOs;
    }
    
    /**
     * ×é×°²éѯתÂë¼Ç¼
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<MediaVideoTrans> queryTransItem(String hql,
            List<Object> args) {
        List<MediaVideoTrans> lstitems = new ArrayList<MediaVideoTrans>();
        MediaVideoTrans item;
        List<Object[]> lst = (List<Object[]>) this.getHibernateTemplate().find(hql, args.toArray());
        for (Object[] obj : lst) {
            
            item = (MediaVideoTrans) obj[0];
            item.setOrgName(String.valueOf(obj[1]));
            
            lstitems.add(item);
        }
        
        return lstitems;
    }
    
    /**
     * ×é×°²éѯתÂë¼Ç¼
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<MediaVideo> queryVideoItem(String hql,List<Object> args) {
        List<MediaVideo> lstitems = new ArrayList<MediaVideo>();
        MediaVideo item;
        List<Object[]> lst = (List<Object[]>) this.getHibernateTemplate().find(hql, args.toArray());
        for (Object[] obj : lst) {
            
            item = (MediaVideo) obj[0];
            item.setClassScheduleName(String.valueOf(obj[1]));
            item.setClassScheduleId(String.valueOf(obj[2]));
            
            lstitems.add(item);
        }
        
        return lstitems;
    }
    
    /**
     * ×é×°²éѯתÂë¼Ç¼
     * @return
     */
    @SuppressWarnings("unchecked")
    public Map<String,SchClassSchedule> queryInitMap(String hql,List<Object> args) {
        
        Map<String,SchClassSchedule> result = new HashMap<String,SchClassSchedule>();
        
        List<Object[]> lst = (List<Object[]>) this.getHibernateTemplate().find(hql, args.toArray());
        for (Object[] obj : lst) {
            result.put(String.valueOf(obj[0]), (SchClassSchedule) obj[2]);
        }
        
        return result;
    }
    
    /**
     * ×é×°²éѯתÂë¼Ç¼
     * @return
     */
    @SuppressWarnings("unchecked")
    public boolean queryInitDoubleMap(String hql,List<Object> args,Map<SchReLessonVideo,MediaVideo> reMap,Map<SchReLessonVideo,SchClassSchedule> scheMap ) {
        
        List<Object[]> lst = (List<Object[]>) this.getHibernateTemplate().find(hql, args.toArray());
        for (Object[] obj : lst) {
            
            reMap.put((SchReLessonVideo) obj[1], (MediaVideo) obj[0]);
            scheMap.put((SchReLessonVideo) obj[1], (SchClassSchedule) obj[2]);
            
        }
        
        return true;
    }
    
    /**
     * ÐÂÔöÊÓÆµ¹Û¿´´ÎÊý
     * @param videoId
     * @return true ÐÂÔö³É¹¦ false ÐÂÔöʧ°Ü
     */
    public boolean addPlayTimes(final String videoId){
        
        return getHibernateTemplate().execute(new HibernateCallback<Boolean>(){
 
            @Override
            public Boolean doInHibernate(Session session) throws HibernateException {
                
                String hql = "update MediaVideo set playTimes = playTimes+1 where videoId=:videoId and deleteFlag is false";
                Query qry = session.createQuery(hql);
                qry.setParameter("videoId", videoId);
                int count = qry.executeUpdate();
                
                return count>0;
            }
            
        });
    }
    
}