noticeserviceimpl.java

来自「移动彩信管理平台」· Java 代码 · 共 155 行

JAVA
155
字号
package com.my7g.zj.mobile.mms.business.service;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.List;

import org.hibernate.Query;

import com.my7g.zj.mobile.mms.business.INoticeService;
import com.my7g.zj.mobile.mms.mapping.TbMmsCpNotice;
import com.my7g.zj.mobile.mms.sys.BasicDao;
import com.my7g.zj.mobile.mms.util.DividePageBean;
import com.my7g.zj.mobile.mms.util.PageBean;

public class NoticeServiceImpl extends BasicDao implements INoticeService {

	private DividePageBean dividePageBean;

	public void setDividePageBean(DividePageBean dividePageBean) {
		this.dividePageBean = dividePageBean;
		System.out.println(dividePageBean);
	}

	// 保存公告信息
	public void saveNotice(TbMmsCpNotice notice) {
		this.saveOrUpdate(notice);
	}

	// 根据id查询公告信息
	public TbMmsCpNotice findNotice(Integer id) {
		return (TbMmsCpNotice) this.getHibernateTemplate().get(
				TbMmsCpNotice.class, id);
	}

	// 根据id删除公告信息
	public void deleteNotice(Integer id) {
		this.delete(TbMmsCpNotice.class, id);
	}

	// 查询公告信息(分页查询)
	public PageBean findNotice(int page, int rowPerPage, String href,
			String groupId, String id) {
		String hql;
		if (groupId.equals("4")) {
			hql = "from TbMmsCpNotice t where t.noticeCp like '" + id
					+ "' or t.noticeCp like '%," + id
					+ ",%' or t.noticeCp like '%," + id
					+ "%' or t.noticeCp like '%" + id
					+ "%,' order by t.createTime desc";
		} else {
			hql = "from TbMmsCpNotice t where t.noticeGroup like '%" + groupId
					+ "%' order by t.createTime desc";
		}
		dividePageBean.setwaitPage(String.valueOf(page), rowPerPage);
		List noticeList = null;
		PageBean bean = null;
		Long countResult = (Long) this.getResultCount("select count(*) "
				+ hql.substring(0, hql.length() - 27));
		dividePageBean.setPageInfo(countResult.intValue());
		String pageHref = dividePageBean.gethrefPage(href, "pagesel", "page");
		noticeList = this.find(hql, rowPerPage, (page - 1) * rowPerPage);
		bean = new PageBean(pageHref, noticeList);
		return bean;
	}

	// 查询所有cp
	public List findCpUser() {
		String hql = "from TbMmsCpProvider";
		Query query = this.getSession().createQuery(hql);
		return query.list();
	}

	// 业务需要的一些处理方法
	public void copy(File src, File dst) {
		InputStream in = null;
		OutputStream out = null;
		try {
			in = new BufferedInputStream(new FileInputStream(src));
			out = new BufferedOutputStream(new FileOutputStream(dst));

			byte[] buffer = new byte[1024];
			while (in.read(buffer) > 0)
				out.write(buffer);

		} catch (Exception e) {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

	/*
	 * public String[] stringFilter(String[] str){ if(str!=null){ for(int i=0;i<str.length;i++){
	 * if(str[i]==null) } } }
	 */

	public String sparate(String[] str) {
		String names = "";
		for (int i = 0; i < str.length; i++) {
			if (str[i] != null) {
				if (i == str.length - 1)
					names += str[i];
				else
					names += str[i] + ",";
			}
		}
		return names;
	}

	public String[] link(String str) {
		if (str != null && !str.equals("")) {
			String[] fileName = str.split(",");
			return fileName;
		}

		return null;
	}

	public static void main(String[] args) {
		// ApplicationContext ress = new
		// FileSystemXmlApplicationContext("applicationContext_service");
		// FileSystemXmlApplicationContext res = new
		// FileSystemXmlApplicationContext("D:/workspace/supermms_cp/WebRoot/WEB-INF/applicationContext_service.xml");

	}

	public DividePageBean getDividePageBean() {
		return dividePageBean;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?