/**
  * 回退时的dto生成
  *
  * @param dto
  * @param message
  * @param muo
  * @return
  */
 public TaskAssgineeDto makeTaskAssgineeDtoBack(
     TaskAssgineeDto dto, TSuperviseTable sup, MUOUserSession muo) {
   TaskAssgineeDto dto2 = new TaskAssgineeDto();
   dto2.setExecutionId(dto.getExecutionId());
   dto2.setPreTaskAssingee(muo.getEmpid());
   // 回退前 当前办理人机构id
   dto2.setPreTaskOrg(muo.getOrgid());
   // 回退前 当前节点id
   dto2.setPreTaskId(dto.getNextTaskId());
   // 回退前 当前办理时间
   String currDate = TimeUtil.getCntDtStr(new Date(), "yyyyMMddHHmmss");
   dto2.setPreTaskTime(currDate);
   // 回退后 办理节点id
   dto2.setNextTaskId(jbpmService.getNextTaskId(dto.getExecutionId()));
   dto2.setBusinessKey(sup.getSuperviseId());
   // if(dto.getTaskAssingee()!=null&&!"".equals(dto.getTaskAssingee()))
   //        dto2.setTaskAssingee(dto.getTaskAssingee());
   dto2.setTaskAssingee(Long.valueOf(dto.getEmpIds()));
   // else {
   // dto2.setTaskAssingee(Long.valueOf(dto.getEmpIds()));
   // }
   dto2.setBusinessType(dto.getBusinessType());
   dto2.setTargetName(dto.getTargetName());
   // 存储节点配置对象主键
   dto2.setTaskExeConfigId(dto.getTaskExeConfigId());
   return dto2;
 }
 /** 部室内部会签 */
 @Override
 public String insertTaskAssignePerson(
     TaskAssgineeDto dto, MUOUserSession muo, TSuperviseTable sup) throws Exception {
   // 插入意见到意见表
   String type = "09";
   sup.setNodeName1(jbpmService.getTaskById(dto.getTaskId()).getName());
   if (sup.getOpninion() == null || "".equals(sup.getOpninion())) sup.setOpninion("");
   insertApproveOpninion(sup, muo, dto.getTaskId(), type, dto);
   String preTaskId = dto.getTaskId();
   // 插入下一个节点信息
   insertTask(dto, muo);
   // 更新当前执行人信息
   dto.setTaskAssigneeState("0");
   TProcessTaskAssignee tptagee = new TProcessTaskAssignee();
   tptagee.setId(dto.getProcessTaskAssigneeId());
   tptagee.setExecutionId(dto.getExecutionId());
   tptagee.setPreTaskId(preTaskId);
   tptagee.setPreTaskAssingee(muo.getEmpid().toString());
   tptagee.setPreTaskOrg(muo.getOrgid());
   tptagee.setPreTaskTime(TimeUtil.getCntDtStr(new Date(), "yyyyMMddHHmmss"));
   tptagee.setNextTaskId(dto.getTaskId());
   tptagee.setBusinessKey(sup.getSuperviseId());
   this.gettProcessTaskAssigneeDAO().updateByPrimaryKeySelective(tptagee);
   // 插入下一步执行人员,同时更新原来办理人员的信息,由于nextTaskId改变了
   jbpmService.insertTaskAssignPerson(dto);
   TProcessTaskAssigneePerson record = new TProcessTaskAssigneePerson();
   TProcessTaskAssigneePerson example = new TProcessTaskAssigneePerson();
   record.setExecutionId(dto.getExecutionId());
   record.setTaskId(dto.getTaskId());
   example.setExecutionId(dto.getExecutionId());
   example.setProcessTaskAssigneeId(dto.getProcessTaskAssigneeId());
   this.gettProcessTaskAssigneePersonDAO().updateEntityByTemplate(record, example);
   // 删除当前已办人员
   TProcessTaskAssigneePerson tad = new TProcessTaskAssigneePerson();
   tad.setTaskAssigneeId(muo.getEmpid());
   tad.setExecutionId(dto.getExecutionId());
   this.tProcessTaskAssigneePersonDAO.deleteByTemplate(tad);
   return "success";
 }
  public String updateBuShiAssignStatus2(
      TaskAssgineeDto dto, MUOUserSession muo, TSuperviseTable sup) throws Exception {
    if (dto.getExecutionId() == null || "".equals(dto.getExecutionId())) return "无法获取该实例ID!";
    String type = "10";
    sup.setNodeName1(jbpmService.getTaskById(dto.getTaskId()).getName());
    if (sup.getOpninion() == null || "".equals(sup.getOpninion())) sup.setOpninion("");

    // 删除当前人员办理信息
    // 删除当前已办人员
    TProcessTaskAssigneePerson tpap = new TProcessTaskAssigneePerson();
    tpap.setTaskAssigneeId(muo.getEmpid());
    tpap.setExecutionId(dto.getExecutionId());
    this.tProcessTaskAssigneePersonDAO.deleteByTemplate(tpap);

    String preTaskId = dto.getTaskId();
    // 插入下一个节点信息
    insertTask(dto, muo);
    // 更新当前执行人信息

    TProcessTaskAssignee tptagee = new TProcessTaskAssignee();
    tptagee.setId(dto.getProcessTaskAssigneeId());
    tptagee.setExecutionId(dto.getExecutionId());
    tptagee.setPreTaskId(preTaskId);
    tptagee.setPreTaskAssingee(muo.getEmpid().toString());
    tptagee.setPreTaskOrg(muo.getOrgid());
    tptagee.setPreTaskTime(TimeUtil.getCntDtStr(new Date(), "yyyyMMddHHmmss"));
    tptagee.setNextTaskId(dto.getTaskId());
    tptagee.setBusinessKey(sup.getSuperviseId());

    // 插入下一步执行人员
    this.gettProcessTaskAssigneeDAO().updateByPrimaryKeySelective(tptagee);
    TProcessTaskAssigneePerson record = new TProcessTaskAssigneePerson();
    TProcessTaskAssigneePerson example = new TProcessTaskAssigneePerson();
    record.setExecutionId(dto.getExecutionId());
    record.setTaskId(dto.getTaskId());
    example.setExecutionId(dto.getExecutionId());
    example.setProcessTaskAssigneeId(dto.getProcessTaskAssigneeId());
    this.gettProcessTaskAssigneePersonDAO().updateEntityByTemplate(record, example);
    dto.setTaskAssigneeState("0");
    // 判断内部办理是否是所有人都已经办理
    List<TProcessTaskAssigneePerson> task = jbpmService.getBsUnCompleted(dto);
    if (task.size() < 1) {
      // 获取下个节点人id,姓名
      HashMap<String, Object> hmp = new HashMap<String, Object>();
      hmp.put("empid", muo.getEmpid());
      // 获取部门主要负责人信息
      TSuperviseTable sp = tSuperviseTableDAO.queryTaskAssignZyPerson(hmp);
      if (sp != null && sp.getEmpid() != null && !"".equals(sp.getEmpid()))
        dto.setEmpIds(sp.getEmpid());
      if (sp != null && sp.getEmpname() != null && !"".equals(sp.getEmpname()))
        dto.setEmpNames(sp.getEmpname());
      dto.setIsChild("0"); // 用来判断是否负责人,显示对应按钮信息
      dto.setTaskAssigneeState("0"); // 部室提交下一步使用,如果是多个为0,则流程不走下一个节点。
      if (!(dto.getEmpIds() == null || dto.getEmpIds().equals(""))) {
        jbpmService.insertTaskAssignPerson(dto);
      }
    }
    // 插入办理意见
    insertApproveOpninion2(sup, muo, dto.getTaskId(), type, dto);
    return "success";
  }
  /**
   * 操作流程相关表,自动增加节点信息
   *
   * @param dto
   * @param muo
   * @throws Exception
   *     <pre>
   * 修改日期        修改人    修改原因
   * 2014-9-10    黄开忠    新建
   * </pre>
   */
  public void insertTask(TaskAssgineeDto dto, MUOUserSession muo) throws Exception {
    /** 黄开忠增加,20140910,处理部室办理时,将办理人员的信息加到节点流水表中。,该部分可以写成公共部分, */
    // 移除当前流程的部署
    // 刷新流程部署缓存
    /**
     * 手工插入流程步骤 1.根据EXECUTION_ID_从表JBPM4_EXECUTION得到dbid_; 2.根据得到dbid_更新表jbpm4_hist_actinst的值
     * 3.根据taskid更新表JBPM4_HIST_TASK的值 4.更新表JBPM4_TASK的dbid_ 5.插入表JBPM4_HIST_ACTINST
     * 6.插入表JBPM4_HIST_TASK的值 7.更新表JBPM4_EXECUTION数据 1.SELECT n.hisactinst_ from JBPM4_EXECUTION n
     * WHERE n.id_='superviseTable.1110030'; 2.SELECT t.htask_ FROM jbpm4_hist_actinst t WHERE
     * t.dbid_=1110035; 3.SELECT * FROM jbpm4_hist_task k WHERE k.dbid_=1110034; 4.SELECT * FROM
     * JBPM4_TASK sk WHERE sk.dbid_=1110034; 5.UPDATE JBPM4_TASK; 6.INSERT JBPM4_HIST_ACTINST;
     * 7.INSERT JBPM4_HIST_TASK; 8.UPDATE JBPM4_EXECUTION;
     */
    // JBPM4_TASK的当前dbid_,做更新jbpm4_hist_task表使用
    String dbid_0 = dto.getTaskId();
    Jbpm4Execution example = new Jbpm4Execution();
    String executionId = dto.getExecutionId();
    example.setId(executionId);
    BigDecimal dbid_init = new BigDecimal(executionId.substring(executionId.indexOf(".") + 1));
    BigDecimal dbid_hist_task = new BigDecimal(this.getNextDbid());
    BigDecimal hact_dbid =
        this.getJbpm4ExecutionDAO().expandEntityByTemplate(example).getHisactinst();
    // 更新表jbpm4_hist_actinst的状态
    Jbpm4HistActinst jhact = new Jbpm4HistActinst();
    jhact.setDbid(hact_dbid);
    jhact.setNextidx((long) 1);
    jhact.setEnd(new Date());
    jhact.setDbversion((long) 1);
    jhact.setTransition("部室办理");
    jhact.setDuration(new BigDecimal(20));
    this.jbpm4HistActinstDAO.updateByPrimaryKeySelective(jhact);

    // 更新表JBPM4_HIST_TASK
    Jbpm4HistTask jhtask = new Jbpm4HistTask();
    jhtask.setDbid(new BigDecimal(dbid_0));
    jhtask.setOutcome("部室办理");
    jhtask.setAssignee(muo.getEmpid().toString());
    jhtask.setState("completed");
    jhtask.setEnd(new Date());
    jhtask.setDbversion((long) 1);
    jhtask.setDuration(new BigDecimal(20));
    this.jbpm4HistTaskDAO.updateByPrimaryKeySelective(jhtask);

    // 更新JBPM4_TASK信息
    Jbpm4Task task = new Jbpm4Task();
    Jbpm4Task ex = new Jbpm4Task();
    // BigDecimal dbid_task=new BigDecimal(this.getNextDbid());
    task.setDbid(dbid_hist_task);
    task.setclassType("T");
    ex.setclassType("T");
    ex.setDbid(new BigDecimal(dbid_0));
    this.jbpm4TaskDAO.updateEntityByTemplate(task, ex);
    // 插入表JBPM4_HIST_TASK

    jhtask.setDbid(dbid_hist_task);
    jhtask.setDbversion((long) 0);
    jhtask.setExecution(executionId);
    jhtask.setOutcome("");
    jhtask.setAssignee("");
    jhtask.setPriority((long) 0);
    jhtask.setState("");
    jhtask.setCreate(new Date());
    jhtask.setDbversion((long) 0);
    jhtask.setNextidx((long) 1);

    this.jbpm4HistTaskDAO.insert(jhtask);
    // 插入表JBPM4_HIST_ACTINST
    BigDecimal dbid_hist_act = new BigDecimal(this.getNextDbid());

    jhact.setDbid(dbid_hist_act);
    jhact.setDbversion((long) 0);
    jhact.setTransition("办理部室");
    jhact.setClassType("task");
    jhact.setHproci(dbid_init);
    jhact.setStart(new Date());
    // jhact.setActivityName("办理部室");
    // 节点名称不固定
    String a = jbpmService.getTaskNameById(dto.getTaskId());
    jhact.setActivityName(a);
    jhact.setDbversion((long) 0);
    jhact.setNextidx((long) 1);
    jhact.setHtask(dbid_hist_task);
    jhact.setType("task");
    jhact.setExecution(executionId);
    jhact.setDuration(new BigDecimal(20)); // 默认写一个值,没什么用,如果为空时,用流程本身函数下不去
    this.jbpm4HistActinstDAO.insert(jhact);

    // 更新表JBPM4_EXECUTION
    Jbpm4Execution jexec = new Jbpm4Execution();
    jexec.setDbid(dbid_init);
    jexec.setDbversion((long) 2);
    jexec.setHisactinst(dbid_hist_act);
    this.jbpm4ExecutionDAO.updateByPrimaryKeySelective(jexec);
    dto.setTaskId(dbid_hist_task.toString());
    dto.setNextTaskId(dbid_hist_act.toString());
  }
  /** 督办处理2 */
  @Override
  public TaskAssgineeDto insertSuperviseTable2(
      TSuperviseTable supervise,
      File[] files,
      String[] filesFileName,
      MUOUserSession muo,
      String btnType,
      TaskAssgineeDto taskAssgineeDto,
      String isFirst)
      throws Exception {
    String taskId = taskAssgineeDto.getNextTaskId();
    // if(taskAssgineeDto.getTransitionName()!=null&&!"".equals(taskAssgineeDto.getTransitionName()))
    // taskAssgineeDto.setTransitionName(new
    // String(taskAssgineeDto.getTransitionName().getBytes("iso-8859-1"),"UTF-8"));
    // 生成督办信息
    String submitType = "";
    if (supervise.getSuperviseId() == null || "".equals(supervise.getSuperviseId())) {
      supervise.setOrgid(String.valueOf(muo.getOrgid()));
      supervise.setCreateor(String.valueOf(muo.getEmpid()));
      String currDate = TimeUtil.getCntDtStr(new Date(), "yyyyMMddHHmmss");
      supervise.setCreateDate(currDate.substring(0, 8));
      supervise.setCreateTime(currDate.substring(8));
      HashMap<String, Object> map = new HashMap<String, Object>();
      map.put("user", String.valueOf(muo.getEmpid()));
      TaskAssgineeDto dto1 =
          jbpmService.startProcessByDefinition(taskAssgineeDto.getDefinitionId(), map);
      taskId = dto1.getNextTaskId();
      supervise.setNodeId(taskId);
      supervise.setNodeName1(jbpmService.getTaskById(taskId).getName());
      supervise.setFlowId(dto1.getExecutionId());
      taskAssgineeDto.setExecutionId(dto1.getExecutionId());
      tSuperviseTableDAO.insertSuperviseTable(supervise);
      // 保存流程的信息
      jbpmService.saveProcessBusiness(muo, insertProcessBusiness(supervise, taskAssgineeDto));
      supervise.setOpninion("");
      submitType = "05";
    } else {
      // 修改
      tSuperviseTableDAO.updateSuperviseTable(supervise);
      // 20140902修改督办单更新时出现一倍数据的问题
      TProcessBusiness business = jbpmService.findProcessBusiness(taskAssgineeDto);
      business.setBusinessTitle(supervise.getSuperviseItem());

      jbpmService.updateProcessBusiness(business);
      submitType = "05";
      /** 2014093 */
      if (supervise.getOpninion() == null || "null".equals(supervise.getOpninion()))
        supervise.setOpninion("");
      /* jbpmService.updateProcessBusiness(insertProcessBusiness(supervise,taskAssgineeDto));*/
    }
    tFileResourceTableService.fileUploads(
        makeFileBean(supervise, taskAssgineeDto), files, filesFileName, muo); // 保存文件
    if (!"1".equals(btnType)) {
      supervise.setNodeName1(jbpmService.getTaskById(taskId).getName());
      taskAssgineeDto.setTaskExeAssginee(String.valueOf(muo.getEmpid()));
      taskAssgineeDto.setTaskId(taskId);
      jbpmService.assignTask(taskAssgineeDto);
      if (!"退回".equals(taskAssgineeDto.getTransitionName())
          && !"退回办理".equals(taskAssgineeDto.getTransitionName())) { // 进入下一步
        taskAssgineeDto.setTaskAssigneeState("0");
        // taskAssgineeDto.setPreTaskAssingee(muo.getEmpid());
        jbpmService.updateTaskAssigneeState(taskAssgineeDto);
        // 20140903 解决下个操作人为null的问题

        if ("null".equals(taskAssgineeDto.getEmpNames())) taskAssgineeDto.setEmpNames("");
        if (isFirst == null
            && taskAssgineeDto.getEmpIds() != null
            && !"".equals(taskAssgineeDto.getEmpIds())) submitType = "01";
        /*if("处理".equals(taskAssgineeDto.getTransitionName())){//
            //暂无

        }else if("批示".equals(taskAssgineeDto.getTransitionName())){
            //String[] receiveEmp=taskAssgineeDto.getEmpIds().split(",");
            //for(int i=0;i<receiveEmp.length;i++){
        //  TSuperviceReceive record=new TSuperviceReceive();
            //record.setNodeId(taskId);
            //record.setNodeName(jbpmService.getTaskById(taskId).getName());
            //record.setContent(supervise.getContent());
            //record.setSuperviseId(supervise.getSuperviseId());
            //record.setReceiveEmp(receiveEmp[i]);
            //record.setReceiveDate("");
            //record.setReceiveTime("");
            //生成督办的人。
            //tSuperviceReceiveDAO.insert(record);
        //  }
        }else*/
        if ("反馈".equals(taskAssgineeDto.getTransitionName())) {
          submitType = "07";
          List<TProcessTaskAssigneePerson> task = jbpmService.getUnCompleted(taskAssgineeDto);
          /*                  taskAssgineeDto.setPreTaskAssingee(muo.getEmpid());
                              jbpmService.updateTaskAssigneeState(taskAssgineeDto);
                              TaskAssgineeDto tad=new TaskAssgineeDto();
                              tad.setParentId(taskAssgineeDto.getParentId());
                              tad.setExecutionId(taskAssgineeDto.getExecutionId());
                              tad.setIsUpdate("10");//10:子处理节点未完成的
                              tad.setTaskAssigneeState("3");//3:作废
                              jbpmService.updateTaskAssigneeState1(tad);//将部室下子处理节点未签的前辈作废
          */ if (task != null && task.size() <= 1) { // 用于所有人都操作完成后进入下一个节点
            jbpmService.completeTask(taskId, taskAssgineeDto.getTransitionName(), null);
            String nextTaskId = jbpmService.getNextTaskId(taskAssgineeDto.getExecutionId());
            taskAssgineeDto.setNextTaskId(nextTaskId);
            supervise.setNodeId(taskId);
            TaskAssgineeDto dto = makeTaskAssgineeDto(supervise, muo, taskAssgineeDto);
            jbpmService.saceTaskAssignee(dto);
          } else {
            // 删除当前节点办理人员,表示已经办理过
            TProcessTaskAssigneePerson tpap = new TProcessTaskAssigneePerson();
            tpap.setTaskAssigneeId(muo.getEmpid());
            tpap.setExecutionId(taskAssgineeDto.getExecutionId());
            this.tProcessTaskAssigneePersonDAO.deleteByTemplate(tpap);
          }

        } else if ("结束".equals(taskAssgineeDto.getTransitionName())) {
          supervise.setNodeId(taskId);
          TaskAssgineeDto taskAssginee = makeTaskAssgineeDto(supervise, muo, taskAssgineeDto);
          taskAssginee.setNextTaskId("");
          jbpmService.saceTaskAssignee(taskAssginee);
          jbpmService.completeTask(taskId, taskAssgineeDto.getTransitionName(), null);
          // 20140904 添加操作类型为结束
          submitType = "08";
        } else { // 进入下一步
          if ("批示".equals(taskAssgineeDto.getTransitionName())) submitType = "05";
          jbpmService.completeTask(taskId, taskAssgineeDto.getTransitionName(), null);
          String nextTaskId = jbpmService.getNextTaskId(taskAssgineeDto.getExecutionId());
          taskAssgineeDto.setNextTaskId(nextTaskId);
          supervise.setNodeId(taskId);
          jbpmService.saceTaskAssignee(makeTaskAssgineeDto(supervise, muo, taskAssgineeDto));
        }

        insertApproveOpninion(supervise, muo, taskId, submitType, taskAssgineeDto);
      } else { // 退回
        insertApproveOpninion(supervise, muo, taskId, "02", taskAssgineeDto);
        jbpmService.completeTask(taskId, taskAssgineeDto.getTransitionName(), null);
        jbpmService.turnBackTaskAssignee(makeTaskAssgineeDtoBack(taskAssgineeDto, supervise, muo));
      }
    }
    return null;
  }