|
楼主 |
发表于 2016-12-9 16:52:05
|
显示全部楼层
package gems;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.sql.Date;
import javax.naming.NamingException;
import com.alibaba.fastjson.JSONObject;
import com.justep.baas.action.ActionContext;
import com.justep.baas.data.DataUtils;
import com.justep.baas.data.Table;
import com.justep.baas.data.Transform;
public class Operation {
private static final String DATASOURCE_jiudian = "jiudian";
public static JSONObject getcardinfo(JSONObject params, ActionContext context) throws SQLException, NamingException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Connection conn = context.getConnection(DATASOURCE_jiudian);
java.sql.Date begintime = null;
java.sql.Date endtime = null;;
String xm = params.getString("xm");
String sfz = params.getString("sfz");
String dm = params.getString("dm");
Calendar c = Calendar.getInstance();
// c.add(Calendar.MONTH, 0);
// c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
// String first = sdf.format(c.getTime());
String year=String.valueOf(c.get(Calendar.YEAR));
String month=String.valueOf(c.get(Calendar.MONTH)+1);
String day=String.valueOf(c.get(Calendar.DAY_OF_MONTH));
String first=year+"-01-01";
String end=year+"-"+month+"-"+day;
String first1=params.getString("begintime");
String end1=params.getString("endtime");
try
{
if (params.getString("begintime")==null)
{
begintime =java.sql.Date.valueOf(first.toString()); ;
endtime =java.sql.Date.valueOf(end.toString()); ;
}
else
{
begintime =java.sql.Date.valueOf(first1.toString()); ;
endtime =java.sql.Date.valueOf(end1.toString()); ;
}
// System.out.println("begintime1="+begintime);
}
catch(Exception e){
//System.out.println("wrong="+e);
}
CallableStatement stat = conn.prepareCall("{call p_nai_ykt_Repo_student(?, ?,?,?,?,?)}");
try {
// 设置IN参数,参数以顺序匹配
stat.setString(1, "0");
stat.setDate(2, begintime);
stat.setDate(3, endtime);
stat.setString(4, xm);
stat.setString(5, dm);
stat.setString(6, sfz);
// 设置OUT参数
//stat.registerOutParameter(2, Types.INTEGER);
// 执行存储过程
stat.execute();
// 获取OUT参数的值
//int outValue = stat.getInt(2);
// 获取返回的数据集
ResultSet rs = stat.getResultSet();
// ResultSet转换为Table
Table table = Transform.resultSetToTable(rs,"",null);
int rowCount = 0;
while(rs.next())
{
rowCount++;
// System.out.print("xflszwdm="+rs.getString("xflszwdm") + "\t");
System.out.print("zwdmmc00="+rs.getString("zwdmmc00") + "\n");
}
// else{
//System.out.println(" rowCount="+ rowCount);
//
// }
rs.close();
return Transform.tableToJson(table);
//return table;
}
finally {
stat.close();
}
}
public static JSONObject getcardinfo_detail(JSONObject params, ActionContext context) throws SQLException, NamingException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
Connection conn = context.getConnection(DATASOURCE_jiudian);
Date begintime = null;
Date endtime = null;;
String xm = params.getString("xm");
String sfz = params.getString("sfz");
String dm = params.getString("dm");
Calendar c = Calendar.getInstance();
// c.add(Calendar.MONTH, 0);
// c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
// String first = sdf.format(c.getTime());
String year=String.valueOf(c.get(Calendar.YEAR));
String month=String.valueOf(c.get(Calendar.MONTH)+1);
String day=String.valueOf(c.get(Calendar.DAY_OF_MONTH));
String first=year+"-01-01";
String end=year+"-"+month+"-"+day;
String first1=params.getString("begintime");
String end1=params.getString("endtime");
try
{
if (params.getString("begintime")==null)
{
begintime =java.sql.Date.valueOf(first.toString()); ;
endtime =java.sql.Date.valueOf(end.toString()); ;
}
else
{
begintime =java.sql.Date.valueOf(first1.toString()); ;
endtime =java.sql.Date.valueOf(end1.toString()); ;
}
// System.out.println("begintime1="+begintime);
// System.out.println("endime1="+endtime);
}
catch(Exception e){
//System.out.println("wrong="+e);
}
CallableStatement stat = conn.prepareCall("{call p_nai_ykt_Repo_student(?, ?,?,?,?,?)}");
try {
// 设置IN参数,参数以顺序匹配
stat.setString(1, "1");
stat.setDate(2, begintime);
stat.setDate(3, endtime);
stat.setString(4, xm);
stat.setString(5, dm);
stat.setString(6, sfz);
// 设置OUT参数
//stat.registerOutParameter(2, Types.INTEGER);
// 执行存储过程
stat.execute();
// 获取OUT参数的值
//int outValue = stat.getInt(2);
// 获取返回的数据集
ResultSet rs = stat.getResultSet();
// ResultSet转换为Table
//System.out.println("结果集detail的dm="+dm);
//System.out.println("detail_begintime1="+begintime);
// System.out.println("detail_endime1="+endtime);
Table table = Transform.resultSetToTable(rs,"",null);
int rowCount = 0;
while(rs.next())
{
rowCount++;
// System.out.print("xflssj00="+rs.getString("xflssj00") + "\t");
System.out.print("xflsje00="+rs.getString("xflsje00") + "\n");
}
System.out.println("------------------------------");
rs.close();
return Transform.tableToJson(table);
} finally {
stat.close();
}
}
}
|
|