// 1.创建存储过程(输入参数,输出参数int 类型,输入类型集合-返回java中处理)
create or replace procedure "FM_BILL_HIS_CODE"(start_num in varchar,
end_num in varchar,
bill_type_id in varchar ,
out_int out int,
out_list out SYS_REFCURSOR) as--返回集合
begin
if bill_type_id = '2' then
merge into fm_bill a
using (select * from view_hrp_his@dblink where substr(billcode,4,11) between start_num and end_num and length(billcode)=14 and billtypecode=bill_type_id )b
on (a.bill_code = substr(b.billcode,4,11) and a.bill_code between start_num and end_num and a.bill_type_code = bill_type_id )
when matched then
update set a.use_name = b.useperson,
a.bill_status = decode(b.billstatus,'1','6','2','8','3','8',''),
a.his_status = b.billstatus,
a.destory_status = decode(b.billstatus,'2','6','3','6',null),
a.destory_date = decode(b.billstatus,'2',b.destorydate,'3',b.destorydate,null),
a.expend_use = b.useperson,
a.bill_money = b.usemoney,
a.expend_date = b.usedate,
a.is_his = '1'
where a.is_his='0';
open out_list for select a.*,start_num,end_num,'0' from view_hrp_his@dblink a
where (
(substr(a.billcode,19,11) between start_num and end_num and length(a.billcode)=29)
or (substr(a.billcode,34,11) between start_num and end_num and length(a.billcode)=44)
or (substr(a.billcode,49,11) between start_num and end_num and length(a.billcode)=59)
or (substr(a.billcode,64,11) between start_num and end_num and length(a.billcode)=74)
or (substr(a.billcode,79,11) between start_num and end_num and length(a.billcode)=89)
) and length(a.billcode) != 14 and a.billtypecode='2';
out_int:=2;
else
merge into fm_bill a
using (select * from view_hrp_his@dblink where billcode between start_num and end_num and billtypecode=bill_type_id )b
on (a.bill_code = b.billcode and a.bill_code between start_num and end_num and a.bill_type_code = bill_type_id )
when matched then
update set a.use_name = b.useperson,
a.bill_status = decode(b.billstatus,'1','6','2','8','3','8',''),
a.his_status = b.billstatus,
a.destory_status = decode(b.billstatus,'2','6','3','6',null),
a.destory_date = decode(b.billstatus,'2',b.destorydate,'3',b.destorydate,null),
a.expend_use = b.useperson,
a.bill_money = b.usemoney,
a.expend_date = b.usedate,
a.is_his = '1' where a.is_his='0';
out_int:=3;
end if;
exception
when others then
out_int:=0;
dbms_output.put_line('error');
end;
// 第二步骤,java数据同步
@RequestMapping(params = "sysnocheBill")
@ResponseBody
public AjaxJson sysnocheBill(String ids,HttpServletRequest request){
AjaxJson j = new AjaxJson();
String msg="同步失败";
// 添加单据
BaseDaoUtil b = new BaseDaoUtil();
PreparedStatement ps = null;
Connection conn = b.getCon();
int count = 0;
try {
FmBillUseBEntity t = systemService.getEntity(FmBillUseBEntity.class,ids);
CallableStatement call=conn.prepareCall("{call fm_bill_his_code(?,?,?,?,?)}");//运行sp_test_1存储过程(注:存储过程接收参数和输出参数Java都有打?问号)
call.setString(1, t.getStartNum());//设置参数
call.setString(2, t.getEndNum());//设置参数
call.setString(3, t.getBillTypeCode());//设置参数
call.registerOutParameter(4, OracleTypes.INTEGER);//接收返回值
//call.registerOutParameter(5, OracleTypes.CURSOR);//接收返回值
call.execute();//执行
count=call.getInt(4); //拿取存储过程返回值
if(count !=0){
// 批量处理^多门诊数据
/** 更新数据信息 **/
if(count == 2){// 门诊票据
/*ResultSet rs=(ResultSet)call.getObject(5);//拿取存储过程返回的集合
if(rs != null){
while(rs.next()){
String billCode=rs.getString("BILLCODE");
String usePerson=rs.getString("USEPERSON");
String useMoney=rs.getString("USEMONEY");
String useDate=rs.getString("USEDATE");
if(useDate.length() == 21){
useDate=useDate.substring(0,useDate.length()-2);
}
String hisBillStatus=rs.getString("BILLSTATUS");
String destoryDate=rs.getString("DESTORYDATE");
if(destoryDate != null && destoryDate.length() == 21){
destoryDate=destoryDate.substring(0,destoryDate.length()-2);
}
String[] aa = billCode.split("\\^");
String mainCode =null;
String billCodes="";
for(int i=0;i
mainCode=aa[0];
// 门诊
if(mainCode != null && mainCode.length() == 14){
mainCode = mainCode.substring(3);
}
// 执行第一张票据(只保存第一张票据的金额,其他的金额改为0) 例如:'12313^12313^43535'
opteraBillCode(mainCode,usePerson,useMoney,useDate,hisBillStatus,null,destoryDate);
}else{
if(aa[i] != null && aa[i].length() == 14){
aa[i] = aa[i].substring(3);
}
billCodes=billCodes+"'"+aa[i]+"',";
}
}
opteraBillCode(billCodes.substring(0,billCodes.length()-1),usePerson,useMoney,useDate,hisBillStatus,mainCode,destoryDate);
}
}*/
}
msg = "成功";
}else{
msg = "同步失败HIS数据有重复使用记录请检查!";
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(ps != null){
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
j.setMsg(msg);
return j;
}