@Override
 public BusinessResult updateLeaf(BeanContext origBean, BeanContext newBean) {
   VolunteerTrainCourseBusiness vtcb =
       (VolunteerTrainCourseBusiness)
           SingleBusinessPoolManager.getBusObj(BusTieConstant.BUS_CPATH_VOLUNTEERTRAINCOURSE);
   BusinessResult result = super.updateLeaf(origBean, newBean);
   TrainCourseBean bean = (TrainCourseBean) newBean;
   vtcb.updateCourseName(bean.getId(), bean.getName());
   return result;
 }
  @Override
  public BusinessResult deleteLeaf(String objectId) {
    VolunteerTrainCourseBusiness vtcb =
        (VolunteerTrainCourseBusiness)
            SingleBusinessPoolManager.getBusObj(BusTieConstant.BUS_CPATH_VOLUNTEERTRAINCOURSE);
    // 检查培训记录表
    Map<String, String> filter = new HashMap<String, String>();
    filter.put("traincourseId_=", objectId);

    List list = vtcb.queryDataByCondition(filter, null);
    if (list.size() > 0) {
      throw new MiServerException.Conflicted("该课程已经被培训记录关联,请先解除关联关系");
    }
    return super.deleteLeaf(objectId);
  }
/**
 * @author gudong
 * @since $Date:2014-02-10$
 */
public class BackendVolunteerAction extends BaseBackendAction<VolunteerBusiness> {
  private static Logger log = LoggerFactory.getLogger(BackendVolunteerAction.class);
  protected static SourceCodeBusiness SOURBUS =
      (SourceCodeBusiness) SingleBusinessPoolManager.getBusObj(BusTieConstant.BUS_CPATH_SOURCECODE);
  private static SystemSettingBusiness ssb =
      (SystemSettingBusiness)
          SingleBusinessPoolManager.getBusObj(BusTieConstant.BUS_CPATH_SYSTEMSETTING);

  protected List<SourceCodeBean> listSource;
  private VolunteerBean volunteer;

  public List<SourceCodeBean> getListSource() {
    return listSource;
  }

  public void setListSource(List<SourceCodeBean> listSource) {
    this.listSource = listSource;
  }

  public VolunteerBean getVolunteer() {
    return volunteer;
  }

  public void setVolunteer(VolunteerBean volunteer) {
    this.volunteer = volunteer;
  }

  @Override
  public VolunteerBusiness getBusiness() {
    if (business == null) {
      business = new VolunteerBusiness();
    }
    return (VolunteerBusiness) business;
  }

  /** */
  private static final long serialVersionUID = -5222876000116738224L;

  @Override
  public String getActionPrex() {
    return getRequest().getContextPath() + "/backend/volunteer";
  }

  @Override
  public String getCustomJs() {
    return getRequest().getContextPath() + "/js/volunteer.js";
  }

  public String getCustomJsp() {
    return "/pages/volunteer/volunteer.jsp";
  };

  @Override
  public String getTableTitle() {
    return "<ul class=\"breadcrumb\"><li>志愿者管理</li><li class=\"active\">志愿者</li></ul>";
  }

  @Override
  public TableQueryVo getModel() {
    TableQueryVo model = super.getModel();
    model.getSort().remove("name");
    model.getSort().put("modifyTime", "desc");
    BackendUserBean sessionUser =
        (BackendUserBean) getSession().getAttribute(WebappsConstants.LOGIN_BACKEND_USER_SESSION_ID);
    if (!sessionUser.getName().equals("admin") && sessionUser.isOnlySeeNewUser()) {
      model.getFilter().put("status in", new int[] {0, 1});
    }
    return model;
  }

  @Override
  public TableInitVo getTableInit() {
    TableInitVo init = new TableInitVo();
    init.getAoColumns().add(new TableHeaderVo("name", "志愿者").enableSearch());
    init.getAoColumns().add(new TableHeaderVo("code", "工号").enableSearch());
    init.getAoColumns().add(new TableHeaderVo("identityCard", "证件号").enableSearch());
    init.getAoColumns()
        .add(
            new TableHeaderVo("status", "状态")
                .enableSearch()
                .addSearchOptions(
                    new String[][] {
                      {"0", "1", "2", "3", "4"}, {"已注册", "通过审核", "通过面试", "未通过审核", "未通过面试"}
                    }));

    List<SourceCodeBean> sourceList =
        (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
    String[][] sources = new String[2][sourceList.size()];
    if (sourceList.size() > 0) {
      for (int i = 0; i < sourceList.size(); i++) {
        sources[0][i] = sourceList.get(i).getCode();
        sources[1][i] = sourceList.get(i).getName();
      }
    } else {
      sources = null;
    }
    init.getAoColumns()
        .add(new TableHeaderVo("occupation", "来源").addSearchOptions(sources).enableSearch());
    init.getAoColumns()
        .add(
            new TableHeaderVo("registerFrom", "渠道")
                .addSearchOptions(new String[][] {{"1", "2"}, {"医院", "微信"}})
                .enableSearch());
    init.getAoColumns()
        .add(
            new TableHeaderVo("sex", "性别")
                .addSearchOptions(new String[][] {{"1", "2"}, {"男", "女"}}));

    init.getAoColumns()
        .add(
            new TableHeaderVo("iconpath", "图像")
                .setHiddenColumn(true)
                .enableSearch()
                .addSearchOptions(new String[][] {{"null", "!null"}, {"没有", "有"}}));
    init.getAoColumns()
        .add(
            new TableHeaderVo("fingerpath", "指纹")
                .setHiddenColumn(true)
                .enableSearch()
                .addSearchOptions(new String[][] {{"null", "!null"}, {"没有", "有"}}));

    init.getAoColumns().add(new TableHeaderVo("cellPhone", "手机", false));
    init.getAoColumns()
        .add(
            new TableHeaderVo("wechat", "微信", false)
                .addSearchOptions(new String[][] {{"null", "!null"}, {"没有", "有"}})
                .enableSearch());
    init.getAoColumns().add(new TableHeaderVo("email", "邮箱", false));
    init.getAoColumns()
        .add(
            new TableHeaderVo("trainCounter_eq", "培训记录(=)", false)
                .setHiddenColumn(true)
                .enableSearch());
    init.getAoColumns()
        .add(
            new TableHeaderVo("trainCounter_gt", "培训记录(>)", false)
                .setHiddenColumn(true)
                .enableSearch());
    init.getAoColumns().add(new TableHeaderVo("trainCounter", "培训记录"));
    init.getAoColumns()
        .add(new TableHeaderVo("createTime_gteq", "注册时间").setHiddenColumn(true).enableSearch());
    init.getAoColumns()
        .add(new TableHeaderVo("createTime_lteq", "注册时间").setHiddenColumn(true).enableSearch());
    init.getAoColumns()
        .add(new TableHeaderVo("modifyTime_gteq", "更新时间").setHiddenColumn(true).enableSearch());
    init.getAoColumns()
        .add(new TableHeaderVo("modifyTime_lteq", "更新时间").setHiddenColumn(true).enableSearch());

    init.getAoColumns().add(new TableHeaderVo("createTime", "注册时间"));
    init.getAoColumns().add(new TableHeaderVo("modifyTime", "更新时间"));

    return init;
  }

  /**
   * @return
   * @throws Exception
   */
  public String index() throws Exception {
    this.listSource = (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
    return INDEX_SUCCESS;
  }

  @Override
  public String save() throws Exception {

    this.listSource = (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
    BusinessResult result = getBusiness().save(getRequest(), volunteer);
    if (result.getErrors().size() > 0) {
      for (Object error : result.getErrors()) {
        addActionError(error.toString());
      }
      return INPUT;
    }
    if (result.getMessages().size() > 0) {
      for (Object message : result.getMessages()) {
        addActionMessage(message.toString());
      }
      return SUCCESS;
    }
    return SUCCESS;
  }

  @Override
  public String edit() throws Exception {
    this.listSource = (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
    volunteer = (VolunteerBean) getBusiness().getLeaf(getId()).getResponseData();
    return SUCCESS;
  }

  @Override
  public String delete() throws Exception {
    if (getIds() != null) {
      for (String id : getIds()) {
        getBusiness().deleteLeaf(getRequest(), id);
      }
    }
    return SUCCESS;
  }

  /** @return */
  public String resetPassword() {
    this.volunteer = (VolunteerBean) getBusiness().getLeaf(getId()).getResponseData();
    this.listSource = (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
    if (volunteer != null) {
      SystemSettingBean systemSetting = ssb.getLeaf();
      volunteer.setPassword(StringUtil.toMD5(systemSetting.getDefaultPassword()));
      getBusiness().updateLeaf(volunteer, volunteer);
      addActionMessage("密码重置成功!");
    } else {
      addActionError("获取用户失败!重置密码失败!");
    }
    return SUCCESS;
  }

  @Override
  public String add() {
    this.listSource = (List<SourceCodeBean>) SOURBUS.getAllLeaves().getResponseData();
    volunteer = new VolunteerBean();
    return SUCCESS;
  }

  public String search() {
    TableQueryVo param = new TableQueryVo();
    // 通过面试的人,才有资格进行培训记录
    param.getFilter().put("status", 2);
    param.getFilter().put("name", volunteer.getName());
    param.setIDisplayLength(5000);
    param.setIDisplayStart(0);
    TableDataVo dataVo = getBusiness().query(param);
    JSONArray jsonArray = JSONArray.fromObject(dataVo.getAaData());
    writeJson(jsonArray);
    return null;
  }
}