/**
   * 2 得到你要修改的样品所有检查项--手动选择--是其中一项
   *
   * @return
   */
  public String sfProjects() {
    fslibProjList = new ArrayList<TemplateProjectVo>();
    List<StandardProject> spList = new ArrayList<StandardProject>();
    List<StandardProject> resultList = new ArrayList<StandardProject>();

    // 加载所有的项目
    WorkPlaceQuality wq =
        workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, wplaceQualityId);
    List<StandardLibray> alllibs = workPlaceSampleBiz.getLib(wq);

    for (StandardLibray sl : alllibs) {
      List<StandardProject> newProjList =
          standardProjectBiz.getEntitiesByTwoColumn(
              StandardProject.class, "standardLibray", sl, "del_flag", false);
      for (StandardProject newproj : newProjList) {
        spList.add(newproj);
      }
    }
    // 加载所有的选择的项
    resultList = workPlaceSampleBiz.getProj(wq);

    if (resultList != null && resultList.size() > 0) {

      spList = removeSpDuplicate(spList);
      for (StandardProject spro : spList) {
        TemplateProjectVo vo = new TemplateProjectVo();
        vo.setId(spro.getId());
        vo.setName(spro.getName());
        vo.setSp_code(spro.getSp_code());
        vo.setSp_code_name(spro.getSp_code_name());
        vo.setDetection(spro.getDetection());
        vo.setLocale_detection(spro.getLocale_detection());
        vo.setSp_company_name(spro.getSp_company_name());
        vo.setSp_target(spro.getSp_target());
        vo.setSp_according(spro.getSp_according());
        vo.setRemark(spro.getRemark());
        for (StandardProject tp : resultList) {
          if (tp.getSp_according()
                  .replaceAll(" ", "")
                  .equals(spro.getSp_according().replaceAll(" ", ""))
              && tp.getSp_code_name()
                  .replaceAll(" ", "")
                  .equals(spro.getSp_code_name().replaceAll(" ", ""))) {
            vo.setTemplId(spro.getId());
          }
        }
        fslibProjList.add(vo);
      }
    }
    return "allProj_list";
  }
  public String fillUpdateSample() {
    WorkPlaceSample sampleDB =
        workPlaceSampleBiz.getEntityById(WorkPlaceSample.class, sample.getId());

    // sampleDB.setLocation(sample.getLocation());
    sampleDB.setCstel(sample.getCstel());
    sampleDB.setExcursionLimits(sample.getExcursionLimits());
    sampleDB.setTwacr(sample.getTwacr());
    sampleDB.setTwacac(sample.getTwacac());
    sampleDB.setAtbtm(sample.getAtbtm());
    // sampleDB.setJobSiteChecName(sample.getJobSiteChecName());
    // sampleDB.setJobSiteRecheckName(sample.getJobSiteRecheckName());
    // sampleDB.setSmokeSamplePeople(sample.getSmokeSamplePeople());
    // String time = jobSiteTime.substring(0, 19);

    // sampleDB.setJobSiteDate(UtilTools.getStingTime(time));

    workPlaceSampleBiz.saveOrUpdateEntity(sampleDB);
    return editwPlaceQuality();
  }
  /**
   * III保存 样品标准
   *
   * @return
   */
  public String manualUpdateSample() {
    String[] firstRightSelect =
        (String[]) ActionContext.getContext().getParameters().get("firstRightSelect"); // 选择的标准项目
    String[] all_ids =
        (String[]) ActionContext.getContext().getParameters().get("secondRightSelect"); // 选择的标准项目
    String[] allProj =
        (String[]) ActionContext.getContext().getParameters().get("thirdRightSelect"); // 选择的标准项目
    String[] selectedProj = allProj != null ? allProj : all_ids;

    workPlaceSampleBiz.manuaUpdateSample(wplaceQualityId, selectedProj);

    ActionContext.getContext().getSession().put("wplaceQualityId", wplaceQualityId);
    return "close";
  }
  /** 提交填报-------------------------------------------------------------------- */
  public String fillQuality() {
    User loginUser = getCurrentUser();

    if (loginUser == null) {
      this.setMsg("用户登陆已过期,请重新登陆!!!");
      logger.info("用户登陆已过期,请重新登陆!!!");
      // return and list
      return shutdown();
    }
    String[] ids = (String[]) ActionContext.getContext().getParameters().get("user_ids");
    if (ids != null && ids.length > 0) {
      for (String idStr : ids) {
        Long id = Long.parseLong(idStr);
        WorkPlaceQuality selected = workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, id);

        selected.setStatus(WebConstants.REPORT_STATUS_5);

        selected.setFillDate(UtilTools.getCurrentTime());

        selected.setFillName(loginUser.getName());
        libs = workPlaceSampleBiz.getLib(selected);
        WorkPlaceEvalResult wpevalResult = selected.getWorkPlaceEvalResult();
        StandardLibray sl = null;
        if (libs != null && libs.size() > 0) {
          sl = libs.get(0);
          wpevalResult.setEvalRemark("经检测,报告书中的样品符合" + sl.getSlib_code() + sl.getName() + "的要求");
        }

        workPlaceQualityBiz.saveOrUpdateEntity(selected);
      }
      this.setMsg("成功填报(所有)选择!!!");
      logger.info("成功填报(所有)选择!!!");
    }
    if (wplaceQualityId != null) {
      return editwPlaceQuality();
    }
    return listWplaceQualitys();
  }
  /**
   * 到相应业务的处理UI
   *
   * @return
   */
  public String editwPlaceQuality() {
    qualityList = qualityBiz.getEntitiesByColumn(Quality.class, "del_flag", false);
    if (wplaceQualityId != null) {
      workPlaceQuality = workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, wplaceQualityId);
      workPlaceEvalResult = workPlaceQuality.getWorkPlaceEvalResult();
      String tempNo = workPlaceQuality.getAcceptNum();
      String tempshNo = workPlaceQuality.getRecordNum();
      if (!UtilTools.isEmpty(workPlaceQuality.getArea())) {
        // String[] tempArea = kitchenQuality.getArea().split(",");
        town = workPlaceQuality.getArea();
        // street = tempArea[1];
      }
      year = tempNo.substring(1, 5);
      slcode = tempNo.substring(5, tempNo.length());
      shnumbercode = tempshNo.substring(4, 5);
      shcode = tempshNo.substring(5, tempshNo.length());
      acceptDate = UtilTools.getDate(workPlaceQuality.getAcceptDate());

      libs = workPlaceSampleBiz.getLib(workPlaceQuality);
      projs = workPlaceSampleBiz.getDetectionProj(workPlaceQuality);
      // allProjs = workPlaceSampleBiz.getAllProj(workPlaceQuality);
      // /localeDetection = getLocaleDetection(projs);
      workPlaceSamples =
          workPlaceSampleBiz.getEntitiesByColumn(
              WorkPlaceSample.class, "workPlaceQuality", workPlaceQuality);
      user = getCurrentUser();
      nowTime = UtilTools.getCurrentDateTime();
      // List<KitchenSample> flist =
      // kitchenSampleBiz.getEntitiesByColumn(KitchenSample.class,
      // "kitchenQuality", kitchenQuality);
      // sampleSize = getSampleSize(flist);

    }
    // 受理 根据不同的流程到不同的页面
    if (flowPath == null) {
      flowTitle = "受理";
      flowPath = 1;
    }
    if (flowPath.equals(WebConstants.FLOW_PATH_1)) {
      flowTitle = "受理";
      return "edit_workPlace";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_2)) {
      flowTitle = "验收";
      return "check_workPlace";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_3)) {
      flowTitle = "检验结果填报";
      return "fill_workPlace";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_4)) {
      flowTitle = "检验结果复核";
      return "recheck_workPlace";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_5)) {
      flowTitle = "评价";
      return "evalu_workPlace";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_6)) {
      flowTitle = "签发";
      return "sign_workPlace";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_7)) {
      flowTitle = "报告打印";
      return "print_workPlace";
    } else flowTitle = "受理";
    flowPath = 1;
    return "edit_workPlace";
  }
  /**
   * 受理保存 修改
   *
   * @return
   */
  public String saveOrupdateWork() {

    User loginUser = getCurrentUser();
    if (loginUser == null) {
      this.setMsg("用户登陆已过期,请重新登陆!!!");
      logger.info("用户登陆已过期,请重新登陆!!!");
      // return list
      return shutdown();
    }
    String area = null;
    if (!UtilTools.isEmpty(town)) {
      area = town; // + "," + street;
      workPlaceQuality.setArea(area);
    }

    WorkPlaceQuality wpDB = null;
    WorkPlaceEvalResult weDB = null;
    // Integer qId = Integer.parseInt(qualityId);
    if (workPlaceQuality != null) {
      // add new
      String slnumber = workPlaceQuality.getNumber_code() + year + slcode;
      String shnumber = year + shnumbercode + shcode;
      workPlaceQuality.setAcceptNum(slnumber);
      workPlaceQuality.setRecordNum(shnumber);
      List<WorkPlaceQuality> cqList =
          workPlaceQualityBiz.getEntitiesByTwoColumn(
              WorkPlaceQuality.class, "acceptNum", slnumber, "del_flag", false);

      if (workPlaceQuality != null && workPlaceQuality.getId() == null) {
        workPlaceQuality.setStatus(WebConstants.REPORT_STATUS_2);
        if (cqList != null && cqList.size() > 0) {
          this.setMsg("受理编号已存在");
          return editwPlaceQuality();
        }
        if (!UtilTools.isEmpty(acceptDate)) {
          workPlaceQuality.setAcceptDate(UtilTools.getStingTime(acceptDate));
          workPlaceQuality.setSampleDate(UtilTools.getStingTime(acceptDate));
        } else {
          workPlaceQuality.setAcceptDate(UtilTools.getCurrentTime());
          workPlaceQuality.setSampleDate(UtilTools.getCurrentTime());
        }

        Quality qlity =
            qualityBiz.getEntityById(Quality.class, workPlaceQuality.getQuality().getId());
        if (aibefore != null) {
          workPlaceQuality.setAibefore(aibefore.toString());
        }
        workPlaceQuality.setQuality(qlity);
        workPlaceQuality.setAcceptName(loginUser.getName());

        workPlaceEvalResult = new WorkPlaceEvalResult();
        workPlaceQuality.setWorkPlaceEvalResult(workPlaceEvalResult);
        workPlaceEvalResult.setWorkPlaceQuality(workPlaceQuality);

        workPlaceQuality = workPlaceQualityBiz.saveOrUpdateEntity(workPlaceQuality);
        wplaceQualityId = workPlaceQuality.getId();
        if (aibefore != null) {
          workPlaceSampleBiz.addSamples(workPlaceQuality, aibefore);
        }
        List<NumberCode> numList =
            numberCodeBiz.getEntitiesByTwoColumn(
                NumberCode.class,
                "qualityNum",
                WebConstants.CATEGORY_QUALITY_ZYC,
                "shnum",
                workPlaceQuality.getRecordNum());
        if (numList != null && numList.size() > 0) {
          numberCodeBiz.deleteEntity(NumberCode.class, numList.get(0).getId());
        }
        return editwPlaceQuality();

      }
      // update exist
      else if (workPlaceQuality != null && workPlaceQuality.getId() != null) {
        if (cqList != null && cqList.size() > 1) {
          this.setMsg("受理编号已存在");
          return editwPlaceQuality();
        }
        wpDB = workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, workPlaceQuality.getId());
        String accUserName = wpDB.getAcceptName();
        // Template template = templateBiz.getEntityById(Template.class,
        // templateId);
        if (!loginUser.getName().equals(accUserName)) {
          this.setMsg("对不起,不是自已受理的样品不能修改");
          return editwPlaceQuality();
        }

        if (workPlaceQuality.getAcceptDate() != null) {
          wpDB.setAcceptDate(workPlaceQuality.getAcceptDate());
        }

        wpDB.setAddress(workPlaceQuality.getAddress());
        if (!UtilTools.isEmpty(workPlaceQuality.getArea())) {
          wpDB.setArea(workPlaceQuality.getArea());
        }

        Quality qlity =
            qualityBiz.getEntityById(Quality.class, workPlaceQuality.getQuality().getId());

        wpDB.setCheckUnit(workPlaceQuality.getCheckUnit());
        // wpDB.setHbcategory(kitchenQuality.getHbcategory());

        wpDB.setQuality(qlity);

        wpDB.setNumber_code(workPlaceQuality.getNumber_code()); // 检查

        // wpDB.setQuality(kitchenQuality.getQuality());
        wpDB.setRecordNum(workPlaceQuality.getRecordNum());
        // wpDB.setSamplNum(kitchenQuality.getSamplNum());

        wpDB.setSamplSource(workPlaceQuality.getSamplSource());
        wpDB.setSamplUnit(workPlaceQuality.getSamplUnit());

        wpDB.setStandNum(workPlaceQuality.getStandNum());
        wpDB.setStatus(WebConstants.REPORT_STATUS_2); // 修改

        // weDB = wpDB.getWorkPlaceEvalResult();
        // weDB.setModifiedDate(UtilTools.getCurrentTime());
        // weDB.setModifiedName(loginUser.getName());
        // weDB.setEvalRemark(workPlaceEvalResult.getEvalRemark());
        // weDB.setSensAppr(workPlaceEvalResult.getSensAppr());
        // weDB.setSensEval(workPlaceEvalResult.getSensEval());
        // feDB.setSensRemark(kitchenEvalResult.getSensRemark());
        // weDB.setSensSugg(workPlaceEvalResult.getSensSugg());
        if (aibefore != null) {
          wpDB.setAibefore(aibefore.toString());
        }
        // wpDB.setWorkPlaceEvalResult(weDB);
        workPlaceQuality = workPlaceQualityBiz.saveOrUpdateEntity(wpDB);
        wplaceQualityId = workPlaceQuality.getId();
        if (aibefore != null) {
          workPlaceSampleBiz.addSamples(workPlaceQuality, aibefore);
        }
        this.setMsg("修改作业场所样品成功!");
        logger.info("修改作业场所样品成功!");
        return editwPlaceQuality();
      }
    } else {
      ActionContext.getContext().getSession().remove("wplaceQualityId");
      return editwPlaceQuality();
    }

    // return and list
    return editwPlaceQuality();
  }
 public String loadSample() {
   sample = workPlaceSampleBiz.getEntityById(WorkPlaceSample.class, sampleId);
   return "load_sample";
 }
 /**
  * 删除其中的样品项目
  *
  * @return
  */
 public String deletdSamplePro() {
   workPlaceSampleBiz.deleteEntity(WorkPlaceSample.class, sprojId);
   this.setMsg("删除样品项目成功!!!");
   return editwPlaceQuality();
 }
  /**
   * II加载标准项目 因为标准可能是两个,所以重新加载
   *
   * @return
   */
  public String loadAllLibs() {
    loadlibList = workPlaceSampleBiz.loadAllLibs(wplaceQualityId); // 加载这个类别编号下面的所有标准

    return "load_libs";
  }