| | |
| | | package com.yeshi.buwan.service.imp; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.buwan.dao.VideoResourceDao; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.hibernate.HibernateException; |
| | | import org.hibernate.SQLQuery; |
| | | import org.hibernate.Session; |
| | | import org.springframework.orm.hibernate4.HibernateCallback; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.yeshi.buwan.dao.VideoResourceDao; |
| | | import com.yeshi.buwan.domain.LeShiAccount; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.VideoResource; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import javax.annotation.Resource; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class VideoResourceService { |
| | | @Resource |
| | | private VideoResourceDao videoResourceDao; |
| | | @Resource |
| | | private VideoResourceDao videoResourceDao; |
| | | |
| | | public List<VideoResource> getResourceList() { |
| | | return videoResourceDao.list("from VideoResource"); |
| | | } |
| | | public List<VideoResource> getResourceList() { |
| | | return videoResourceDao.list("from VideoResource"); |
| | | } |
| | | |
| | | public VideoResource getResource(String id) { |
| | | return (VideoResource) videoResourceDao.find(VideoResource.class, id); |
| | | } |
| | | public VideoResource getResource(String id) { |
| | | return (VideoResource) videoResourceDao.find(VideoResource.class, id); |
| | | } |
| | | |
| | | public void addResource(VideoResource re) { |
| | | videoResourceDao.create(re); |
| | | } |
| | | public void addResource(VideoResource re) { |
| | | videoResourceDao.create(re); |
| | | } |
| | | |
| | | public void deleteResource(String id) { |
| | | VideoResource re = new VideoResource(); |
| | | re.setId(id); |
| | | videoResourceDao.delete(re); |
| | | } |
| | | public void deleteResource(String id) { |
| | | VideoResource re = new VideoResource(); |
| | | re.setId(id); |
| | | videoResourceDao.delete(re); |
| | | } |
| | | |
| | | public void updateResource(VideoResource re) { |
| | | videoResourceDao.update(re); |
| | | } |
| | | public void updateResource(VideoResource re) { |
| | | videoResourceDao.update(re); |
| | | } |
| | | |
| | | public String resourceListToJson(List<VideoResource> list, List<LeShiAccount> accountList) { |
| | | JSONObject object = new JSONObject(); |
| | | JSONArray array = new JSONArray(); |
| | | VideoResource vr; |
| | | for (Iterator<VideoResource> iterator = list.iterator(); iterator.hasNext(); array |
| | | .add(StringUtil.outPutResultJson(vr))) |
| | | vr = (VideoResource) iterator.next(); |
| | | public String resourceListToJson(List<VideoResource> list) { |
| | | JSONObject object = new JSONObject(); |
| | | JSONArray array = new JSONArray(); |
| | | VideoResource vr; |
| | | for (Iterator<VideoResource> iterator = list.iterator(); iterator.hasNext(); array |
| | | .add(StringUtil.outPutResultJson(vr))) |
| | | vr = (VideoResource) iterator.next(); |
| | | |
| | | object.put("Type", array); |
| | | return object.toString(); |
| | | } |
| | | object.put("Type", array); |
| | | return object.toString(); |
| | | } |
| | | |
| | | public void excuteSQL(final String sql) { |
| | | videoResourceDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | session.getTransaction().begin(); |
| | | session.createSQLQuery(sql).executeUpdate(); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | public void excuteSQL(final String sql) { |
| | | videoResourceDao.excute(new HibernateCallback() { |
| | | public Object doInHibernate(Session session) throws HibernateException { |
| | | session.getTransaction().begin(); |
| | | session.createSQLQuery(sql).executeUpdate(); |
| | | session.flush(); |
| | | session.getTransaction().commit(); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public List<VideoResource> getResourceByVideo(final VideoInfo vi) { |
| | | |
| | | final String sql="select vr.* from wk_video_resource vr left join wk_resource_video rv on vr.id=rv.resourceid where rv.videoid = ? "; |
| | | |
| | | return (List<VideoResource>) videoResourceDao.excute(new HibernateCallback<List<VideoResource>>() { |
| | | @SuppressWarnings("unchecked") |
| | | public List<VideoResource> getResourceByVideo(final VideoInfo vi) { |
| | | |
| | | @Override |
| | | public List<VideoResource> doInHibernate(Session session) |
| | | throws HibernateException { |
| | | SQLQuery query = session.createSQLQuery(sql); |
| | | query.setParameter(0, vi.getId()); |
| | | query.addEntity(VideoResource.class); |
| | | return query.list(); |
| | | } |
| | | }); |
| | | |
| | | // List<VideoResource> list = videoResourceDao.list("from VideoResource vr left join ResourceVideo rv where rv.video.id = ? and vr.id=rv.resource.id",new Serializable[]{vi.getId()}); |
| | | } |
| | | final String sql = "select vr.* from wk_video_resource vr left join wk_resource_video rv on vr.id=rv.resourceid where rv.videoid = ? "; |
| | | |
| | | return (List<VideoResource>) videoResourceDao.excute(new HibernateCallback<List<VideoResource>>() { |
| | | |
| | | @Override |
| | | public List<VideoResource> doInHibernate(Session session) |
| | | throws HibernateException { |
| | | SQLQuery query = session.createSQLQuery(sql); |
| | | query.setParameter(0, vi.getId()); |
| | | query.addEntity(VideoResource.class); |
| | | return query.list(); |
| | | } |
| | | }); |
| | | |
| | | // List<VideoResource> list = videoResourceDao.list("from VideoResource vr left join ResourceVideo rv where rv.juhe.id = ? and vr.id=rv.resource.id",new Serializable[]{vi.getId()}); |
| | | } |
| | | |
| | | } |