/// <summary>
/// 总部审核
/// </summary>
/// <param name="ht"></param>
/// <returns></returns>
public int Update(Hashtable ht)
{
//修改
StringBuilder sb = new StringBuilder();
sb.Append("declare \r\n");
sb.Append("n_id number; \r\n");
sb.Append("n_branch_id number;\r\n");
sb.Append("n_stock_exist_count number;\r\n");
sb.Append("n_stock number;\r\n");
sb.Append("v_code varchar2(50);\r\n");
sb.Append("cursor parts_apply_refer_data is select parts_id,fact_send_count,fact_receive_count,send_add_count,bohui_count from t_parts_apply_refer where apply_id=:apply_id;\r\n");
sb.Append(" parts_apply_refer_row parts_apply_refer_data%rowtype;\r\n");
sb.Append("begin \r\n");
sb.Append("lock table t_parts_stock in share mode wait 10;\r\n");
sb.Append("lock table t_newparts_apply in share mode wait 10;\r\n");
sb.Append("select id into n_id from t_parts_check where apply_id=:apply_id; \r\n");
sb.Append("select branch_id,apply_code into n_branch_id,v_code from t_newparts_apply where id=:apply_id; \r\n");
sb.Append("update t_parts_check set identify_audit_result=:identify_audit_result,identify_status=:identify_status,update_person=:update_person,update_time=sysdate where apply_id=:apply_id; \r\n");
sb.Append("update t_newparts_apply set status = :parts_apply_status , update_person=:update_person,update_time=sysdate where id = :apply_id; \r\n");
//审核通过,库存加入坏件
if (ht["parts_apply_status"].ToString()=="12")
{
sb.Append(" for parts_apply_refer_row in parts_apply_refer_data loop \r\n"); //循环遍历配件申请配件表中每一行数据
sb.Append("n_stock_exist_count:=0;\r\n");
sb.Append("if parts_apply_refer_row.bohui_count>0 then \r\n"); //只有驳回大于0的记录才能入库
sb.Append("select count(0),max(stock_count) into n_stock_exist_count,n_stock from t_parts_stock where branch_id=n_branch_id and parts_id=parts_apply_refer_row.parts_id and return_type=2; \r\n");
sb.Append("if n_stock_exist_count>0 then \r\n"); //如果说当前库存这条记录的库存数大于0就更新库存
sb.Append("update t_parts_stock set stock_count=stock_count+parts_apply_refer_row.bohui_count,update_time=sysdate where branch_id=n_branch_id and parts_id=parts_apply_refer_row.parts_id and return_type=2; \r\n");
sb.Append("insert into t_parts_in_out_history (id,part_id,parts_class,in_out_type,in_out_count,branch_id,precedure_code,operation_time,operation_person,remark,current_stock) values (seq_parts_his.nextval,parts_apply_refer_row.parts_id,2,1,parts_apply_refer_row.bohui_count,n_branch_id,v_code,sysdate,:update_person,'收件异常入库',n_stock+parts_apply_refer_row.bohui_count); \r\n");
sb.Append("else \r\n"); //否则添加当前库存这条记录的相关信息
sb.Append("insert into t_parts_stock (id,parts_id,branch_id,repair_id,stock_count,alarm_count,return_type,update_time) values (seq_parts_stock.nextval,parts_apply_refer_row.parts_id,n_branch_id,null,parts_apply_refer_row.bohui_count,1,2,sysdate); \r\n");
sb.Append("insert into t_parts_in_out_history (id,part_id,parts_class,in_out_type,in_out_count,branch_id,precedure_code,operation_time,operation_person,remark,current_stock) values (seq_parts_his.nextval,parts_apply_refer_row.parts_id,2,1,parts_apply_refer_row.bohui_count,n_branch_id,v_code,sysdate,:update_person,'收件异常入库',parts_apply_refer_row.bohui_count); \r\n");
sb.Append("end if; \r\n");
sb.Append("end if; \r\n");
sb.Append("end loop; \r\n");
}
//添加流程
sb.Append("insert into t_procedure_log (procedure_type,refer_id,status,handle_person,handle_time,remark) values (2,:apply_id,:parts_apply_status,:update_person,sysdate,:identify_audit_result); \r\n");
sb.Append("insert into t_procedure_log (procedure_type,refer_id,status,handle_person,handle_time,remark) values (7,n_id,:identify_status,:update_person,sysdate,:identify_audit_result); \r\n");
sb.Append("end; \r\n");
return oc.Execute(sb.ToString(),ht);
}