/** 全部取消------------------------------------------------------------------- */
  public String rollSignQuality() {
    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_6);

        selected.setSignDate(UtilTools.getCurrentTime());

        selected.setSignName(loginUser.getName());

        workPlaceQualityBiz.saveOrUpdateEntity(selected);
      }
      this.setMsg("成功取消签发(所有)选择!!!");
      logger.info("成功取消签发(所有)选择!!!");
    }
    if (wplaceQualityId != null) {
      return editwPlaceQuality();
    }
    return listWplaceQualitys();
  }
  /**
   * 1111 受理提交----------------------------------------------------------------
   *
   * @return
   */
  public String slSingnUp() {

    WorkPlaceQuality fq =
        workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, workPlaceQuality.getId());
    fq.setStatus(WebConstants.REPORT_STATUS_3); // 提交状态
    workPlaceQualityBiz.saveOrUpdateEntity(fq);
    wplaceQualityId = fq.getId();
    // return listFoodQualitys();
    return editwPlaceQuality();
  }
  /**
   * 加载查询列表
   *
   * @return
   */
  public String listWplaceQualitys() {
    if (flowPath.equals(WebConstants.FLOW_PATH_1)) {
      types = ReportType.getAccept();
      flowTitle = "受理";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_2)) {
      types = ReportType.getCheck();
      flowTitle = "验收";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_3)) {
      types = ReportType.getFill();
      flowTitle = "检验结果填报";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_4)) {
      types = ReportType.getRecheck();
      flowTitle = "检验结果复核";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_5)) {
      types = ReportType.getEvalu();
      flowTitle = "评价";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_6)) {
      types = ReportType.getSign();
      flowTitle = "签发";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_7)) {
      types = ReportType.getPrint();
      flowTitle = "报告打印";
    }
    if (cons == null) {
      cons = new Conditions();
    }
    user = getCurrentUser();
    // cons.setUser(getCurrentUser());
    cons.setFlowPath(flowPath);
    pageBean =
        workPlaceQualityBiz.queryWorkPlaceQualitys(condition, cons, orderBy, orderType, pageIndex);
    logger.info("count working place  quality list :" + pageBean.getTotalRow());

    return "workPlace_list";
  }
  /**
   * 作业场所受理 删除
   *
   * @return
   */
  public String deleteWorkQuality() {
    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);

        if (loginUser.getName().equals(selected.getAcceptName())) {
          if (selected.getStatus() < 3) {
            selected.setDel_flag(true);
            workPlaceQualityBiz.saveOrUpdateEntity(selected);
            NumberCode newCode = new NumberCode();
            newCode.setQualityNum(WebConstants.CATEGORY_QUALITY_ZYC);
            newCode.setShnum(selected.getRecordNum());
            numberCodeBiz.saveOrUpdateEntity(newCode);
          } else {
            this.setMsg("已提交,不能删除!!!");
            if (wplaceQualityId != null) {
              return shutdown();
            }
            return listWplaceQualitys();
          }
        } else {
          this.setMsg("不是你受理的,不能删除!!!");
          if (wplaceQualityId != null) {
            return shutdown();
          }
          return listWplaceQualitys();
        }
      }
      this.setMsg("成功删除(所有)选择!!!");
      logger.info("成功删除(所有)选择!!!");
    }
    if (wplaceQualityId != null) {
      return shutdown();
    }
    return listWplaceQualitys();
  }
 /**
  * 下一个标准
  *
  * @return
  */
 public String next() {
   wplaceQualityId = workPlaceQuality.getId();
   Long id = wplaceQualityId + 1;
   workPlaceQuality = workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, id);
   if (workPlaceQuality == null) {
     this.setMsg("数据库没有查到此标准");
   } else {
     wplaceQualityId = id;
   }
   return editwPlaceQuality();
 }
 /**
  * 受理编号查询
  *
  * @return
  */
 public String queryNumber() {
   List<WorkPlaceQuality> flist =
       workPlaceQualityBiz.getEntitiesByTwoColumn(
           WorkPlaceQuality.class, "acceptNum", searchNumber, "del_flag", false);
   if (flist != null && flist.size() > 0) {
     workPlaceQuality = flist.get(0);
   } else {
     this.setMsg("数据库中没有查找到此受理编号");
   }
   wplaceQualityId = workPlaceQuality.getId();
   return editwPlaceQuality();
 }
 public String searchPlace() {
   workPlaceList =
       workPlaceQualityBiz.getEntitiesByThreeColumn(
           WorkPlaceQuality.class, "number_code", shnumbercode, "area", town, "del_flag", false);
   for (int i = 0; i < workPlaceList.size(); i++) {
     WorkPlaceQuality wq = workPlaceList.get(i);
     if (wq.getStatus() < WebConstants.REPORT_STATUS_8) {
       workPlaceList.remove(i);
     }
   }
   return "search_place";
 }
  /**
   * 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 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();
  }
  /**
   * 到输入界面
   *
   * @return
   */
  public String addNew() {
    List<NumberCode> numList =
        numberCodeBiz.getEntitiesByColumnInOrder(
            NumberCode.class, "qualityNum", WebConstants.CATEGORY_QUALITY_ZYC, "shnum", "asc");

    if (numList != null && numList.size() > 0) {
      NumberCode code = numList.get(0);
      shcode = code.getShnum().substring(5, code.getShnum().length());
    } else {
      Long maxId = workPlaceQualityBiz.getMaxId();
      String numberCode = UtilTools.serialNumber(maxId.toString());
      shcode = numberCode;
    }
    qualityList = qualityBiz.getEntitiesByColumn(Quality.class, "del_flag", false);
    year = UtilTools.getCurrentDate().substring(0, 4);
    user = getCurrentUser();
    return "new_workPlace";
  }
  /**
   * 初使化列表
   *
   * @return
   */
  public String initPage() {
    cons = new Conditions();
    condition = new WorkPlaceQuality();
    if (flowPath.equals(WebConstants.FLOW_PATH_1)) {
      types = ReportType.getAccept();
      cons.setType(2);
      flowTitle = "受理";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_2)) {
      types = ReportType.getCheck();
      cons.setType(3);
      flowTitle = "验收";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_3)) {
      types = ReportType.getFill();
      cons.setType(4);
      flowTitle = "检验结果填报";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_4)) {
      types = ReportType.getRecheck();
      cons.setType(5);
      flowTitle = "检验结果复核";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_5)) {
      types = ReportType.getEvalu();
      cons.setType(6);
      flowTitle = "评价";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_6)) {
      types = ReportType.getSign();
      cons.setType(7);
      flowTitle = "签发";
    } else if (flowPath.equals(WebConstants.FLOW_PATH_7)) {
      types = ReportType.getPrint();
      cons.setType(8);
      flowTitle = "报告打印";
    }

    user = getCurrentUser();
    cons.setUser(new User());
    cons.setFlowPath(flowPath);
    pageBean =
        workPlaceQualityBiz.queryWorkPlaceQualitys(condition, cons, orderBy, orderType, pageIndex);
    return "workPlace_list";
  }
  /**
   * 到相应业务的处理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();
  }
  /**
   * I手动为每一个样品选择标准
   *
   * @return
   */
  public String selectAllLib() {

    workPlaceQuality = workPlaceQualityBiz.getEntityById(WorkPlaceQuality.class, wplaceQualityId);
    ActionContext.getContext().getSession().put("wplaceQualityId", wplaceQualityId);
    return "manual_selectall";
  }