⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 choiceserviceimp.java

📁 java论坛
💻 JAVA
字号:
package com.laoer.bbscs.service.imp;

import java.util.*;

import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.dao.*;
import com.laoer.bbscs.exception.*;
import com.laoer.bbscs.service.*;
import com.laoer.bbscs.service.web.*;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import com.laoer.bbscs.comm.BBSCSUtil;
import org.apache.commons.io.FileUtils;
import java.io.File;
import com.laoer.bbscs.comm.Constant;
import java.io.*;

/**
 * <p>Title: TianyiBBS</p>
 *
 * <p>Description: BBSCS</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: Laoer.com</p>
 *
 * @author Laoer
 * @version 7.0
 */
public class ChoiceServiceImp
    implements ChoiceService {

  private static final Log logger = LogFactory.getLog(ChoiceServiceImp.class);

  private ChoiceCategoryDAO choiceCategoryDAO;

  private ChoiceDAO choiceDAO;

  public ChoiceServiceImp() {
  }

  /**
   *
   * @param choiceCategory ChoiceCategory
   * @return ChoiceCategory
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public ChoiceCategory saveChoiceCategory(ChoiceCategory choiceCategory) throws BbscsException {
    try {
      return this.getChoiceCategoryDAO().saveChoiceCategory(choiceCategory);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   *
   * @param id String
   * @return ChoiceCategory
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public ChoiceCategory findChoiceCategoryById(String id) {
    return this.getChoiceCategoryDAO().findChoiceCategoryById(id);
  }

  /**
   *
   * @param bid long
   * @param usestat int
   * @return List
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public List findChoiceCategorysByBoardId(long bid, int usestat) {
    return this.getChoiceCategoryDAO().findChoiceCategorysByBoardId(bid, usestat);
  }

  /**
   *
   * @param choiceCategory ChoiceCategory
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public void removeChoiceCategory(ChoiceCategory choiceCategory) throws BbscsException {
    try {
      this.getChoiceDAO().removeChoiceByCategoryID(choiceCategory.getId());
      this.getChoiceCategoryDAO().removeChoiceCategory(choiceCategory);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   *
   * @param choice Choice
   * @return Choice
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public Choice saveChoice(Choice choice) throws BbscsException {
    return this.getChoiceDAO().saveChoice(choice);
  }

  /**
   *
   * @param id String
   * @return Choice
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public Choice findChoiceById(String id) {
    return this.getChoiceDAO().findChoiceById(id);
  }

  public Choice findChoiceByCategoryIDPostID(String categoryID, String postID) {
    return this.getChoiceDAO().findChoiceByCategoryIDPostID(categoryID, postID);
  }

  /**
   *
   * @param categoryID String
   * @param pages Pages
   * @return PageList
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public PageList findChoicesByCategoryID(String categoryID, Pages pages) {
    PageList pl = new PageList();
    if (pages.getTotalNum() == -1) {
      pages.setTotalNum(this.getChoiceDAO().getChoicesNumByCategoryID(categoryID));
    }
    pages.executeCount();

    List l = this.getChoiceDAO().findChoicesByCategoryID(categoryID, pages.getSpage(), pages.getPerPageNum());
    pl.setObjectList(l);
    pl.setPages(pages);
    return pl;
  }

  public List findChoicesByCategoryID(String categoryID) {
    return this.getChoiceDAO().findChoicesByCategoryID(categoryID);
  }

  /**
   *
   * @param ids List
   * @return List
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public List findChoicesInIds(List ids) {
    return this.getChoiceDAO().findChoicesInIds(ids);
  }

  /**
   *
   * @param choice Choice
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public void removeChoice(Choice choice) throws BbscsException {
    try {
      this.getChoiceDAO().removeChoice(choice);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   *
   * @param id String
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.ChoiceService method
   */
  public void removeChoiceById(String id) throws BbscsException {
    try {
      this.getChoiceDAO().removeChoiceById(id);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  public void removeChoices(List ids) throws BbscsException {
    try {
      this.getChoiceDAO().removeChoice(ids);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  public void createChoicePage(long bid) throws BbscsException {
    StringBuffer sb = new StringBuffer();
    sb.append("<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">");
    List cclist = this.getChoiceCategoryDAO().findChoiceCategorysByBoardId(bid, 1);
    int counter = 0;
    for (int i = 0; i < cclist.size(); i++) {
      ChoiceCategory cc = (ChoiceCategory) cclist.get(i);
      if (counter == 0) {
        counter = 2;
        sb.append("<tr>");
      }
      sb.append("<td width=\"50%\" valign=\"top\">");
      sb.append("<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">");
      sb.append("<tr>");
      sb.append("<td colspan=\"2\"><strong>");
      sb.append(cc.getCategoryName());
      sb.append("</strong></td>");
      sb.append("</tr>");
      List choicelist = this.getChoiceDAO().findChoicesByCategoryID(cc.getId(), 0, 5);
      for (int j = 0; j < choicelist.size(); j++) {
        Choice c = (Choice) choicelist.get(j);
        sb.append("<tr>");
        sb.append("<td width=\"65%\" valign=\"top\">");
        sb.append("<a href=\"");
        sb.append(BBSCSUtil.getActionMappingURLWithoutPrefix("read?action=topic&id=" + c.getPostMainID() +
            "&bid=" + c.getBoardID()));
        sb.append("\">");
        sb.append(c.getTitle());
        sb.append("</a>");
        sb.append("</td>");
        sb.append("<td width=\"35%\" valign=\"top\"><div align=\"right\">");
        sb.append("<a href=\"");
        sb.append(BBSCSUtil.getActionMappingURLWithoutPrefix("userInfo?action=id&id=" + c.getUserID()));
        sb.append("\">");
        sb.append(c.getUserNickName());
        sb.append("</a>");
        sb.append("</div></td>");
        sb.append("</tr>");
      }
      sb.append("</table>");
      sb.append("</td>");

      if (counter == 1) {
        counter = 0;
        sb.append("</tr>");
      }
      else {
        counter = counter - 1;
      }

    }
    sb.append("</table>");

    File choiceFile = new File(BBSCSUtil.getIncludePath() + "Choice_" + bid + ".html");
    try {
      FileUtils.writeStringToFile(choiceFile, sb.toString(), Constant.CHARSET);
    }
    catch (IOException ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  public ChoiceCategoryDAO getChoiceCategoryDAO() {
    return choiceCategoryDAO;
  }

  public ChoiceDAO getChoiceDAO() {
    return choiceDAO;
  }

  public void setChoiceCategoryDAO(ChoiceCategoryDAO choiceCategoryDAO) {
    this.choiceCategoryDAO = choiceCategoryDAO;
  }

  public void setChoiceDAO(ChoiceDAO choiceDAO) {
    this.choiceDAO = choiceDAO;
  }
}

⌨️ 快捷键说明

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