InformationService.java~161~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:6k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.service;
- import com.chinacannel.common.TranUtil;
- import com.chinacannel.common.CommonDAO;
- import org.apache.commons.logging.LogFactory;
- import org.apache.commons.logging.Log;
- import com.chinacannel.common.DAOException;
- import java.util.List;
- import com.chinacannel.entity.Information;
- import com.chinacannel.common.PageInfo;
- import com.chinacannel.entity.Category;
- import com.chinacannel.entity.Menu;
- public class InformationService extends TranUtil {
- private CommonDAO dao = new CommonDAO();
- private static Log log = LogFactory.getLog(InformationService.class);
- public boolean AddInformation(Information inf) {
- try {
- return dao.createObject(inf);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return false;
- }
- }
- public boolean UpdateInformation(Information inf) {
- try {
- return dao.updateObject(inf);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return false;
- }
- }
- public boolean DeleteInformation(Information inf) {
- try {
- return dao.removeObject(inf);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return false;
- }
- }
- public Information GetInformationById(Long id) {
- try {
- return (Information) dao.loadObject(id, Information.class);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- public Information GetInformationByKey(String Key, String Language) {
- try {
- return (Information) dao.loadOneObjectBySQL(
- "from Information as inf where inf.inf_Key='" + Key +
- "' and inf.inf_Language='" + Language + "'");
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- public List GetInformationListByKey(String Key, String Language) {
- try {
- return dao.loadObjectListBySQL(
- "from Information as inf where inf.inf_Key='" + Key +
- "' and inf.inf_Language='" + Language + "'");
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- public List getNewsList(String Key, Category cat, Menu menu,
- String condition, String Language, int start,
- int top) {
- List list = null;
- String hql = "from Information as inf where inf.inf_Language='" +
- Language + "'";
- try {
- if (!Key.equals("")) {
- hql += " and inf.inf_Key='" + Key + "'";
- } else if (cat != null) {
- hql += " and inf.category.cat_ID='" + cat.getCat_ID() + "'";
- } else if (menu != null) {
- hql += " and inf.menu.men_ID=" + menu.getMen_ID();
- }
- if (!condition.equals("")) {
- hql += " and inf.inf_Title like '%" + condition + "%'";
- }
- hql += " order by inf.inf_Time desc";
- list = dao.loadObjectListBySQL(hql, start, top);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- return list;
- }
- public int getCount(String Key, Category cat, Menu menu, String condition,
- String Language) {
- String hql =
- "select count(*) from Information as inf where inf.inf_Language='" +
- Language + "'";
- if (!Key.equals("")) {
- hql += " and inf.inf_Key='" + Key + "'";
- } else if (cat != null) {
- hql += " and inf.category.cat_ID='" + cat.getCat_ID() + "'";
- } else if (menu != null) {
- hql += " and inf.menu.men_ID=" + menu.getMen_ID();
- }
- if(!condition.equals("")){
- hql += " and inf.inf_Title like '%" + condition + "%'";
- }
- try {
- return dao.getCountBySql(hql);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return 0;
- }
- }
- public PageInfo getPageInfo(String Key, Category cat, Menu menu,
- String condition, String Language, int pageno) {
- PageInfo pageInfo = new PageInfo(this.getCount(Key, cat, menu,
- condition, Language), pageno, 10);
- pageInfo.setRows(this.getNewsList(Key, cat, menu, condition, Language,
- pageInfo.getStartRow(),
- pageInfo.getPageSize()));
- return pageInfo;
- }
- public Information GetFirstInformationByMenuID(Long menuID) {
- try {
- return (Information) dao.loadOneObjectBySQL(
- "from Information as inf where inf.menu.men_ID=" + menuID);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- public List GetIndexInformation(Menu menu) {
- try {
- return dao.loadObjectListBySQL(
- "from Information as inf where inf.menu.men_ID=" +
- menu.getMen_ID() + " order by inf.inf_Time", 0, 5);
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- public List GetInformationByMenu(Menu menu) {
- try {
- return dao.loadObjectListBySQL(
- "from Information as inf where inf.menu.men_ID=" +
- menu.getMen_ID());
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- public Information GetIndexImgInformationByMenu(Menu menu) {
- try {
- return (Information) dao.loadOneObjectBySQL(
- "from Information as inf where inf.inf_Index=1 and inf.menu.men_ID=" +
- menu.getMen_ID());
- } catch (DAOException ex) {
- log.error(ex.getMessage(), ex);
- return null;
- }
- }
- }