package xin.glue.ui.G.G08;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.sql.CallableStatement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.posdata.glue.biz.activity.PosActivity;
import com.posdata.glue.biz.constants.PosBizControlConstants;
import com.posdata.glue.context.PosContext;
import com.posdata.glue.dao.PosGenericDao;
import com.posdata.glue.dao.vo.PosParameter;
import com.posdata.glue.dao.vo.PosRow;
import com.posdata.glue.dao.vo.PosRowSet;
public class SendBack extends PosActivity{
//外销退回
public String runActivity(PosContext context) {
String[] SLAB_NO= (String[])context.get("SERIALNUMBER");
String[] SEND_NO= (String[])context.get("PLANVEHICLEID"); //发运指示号
String[] MEMO = (String[])context.get("MEMO");//退回备注
String[] LISTNUMBER = (String[])context.get("LISTNUMBER");//明细编码
String[] chk= (String[])context.get("CHK");
String[] GBZL = (String[])context.get("GBZL");
String[] PLT_TRS_EMP_ID = (String[])context.get("REG_NM");
String err= new String();
String mes= new String();
PosGenericDao dao = this.getDao("mesdao");
ArrayList al = new ArrayList();
for(int i = 0 ; i < chk.length ; i++){
if(chk[i].equals("")||chk[i] == null||chk[i].equals("N"))continue;
// PosParameter param = new PosParameter();
// param.setWhereClauseParameter(0, SLAB_NO[i]);
// param.setWhereClauseParameter(1, err);
// param.setWhereClauseParameter(2, mes);
// int updtCnt = getDao("mesdao").update("UIG080010_03.CAL", param);
try{
PosParameter param1 = new PosParameter();
param1.setWhereClauseParameter(0, SEND_NO[i]);
param1.setWhereClauseParameter(1, SLAB_NO[i]);
PosRowSet rs = this.getDao("mesdao").find("UIG080010_05.SELECT", param1);
if(rs.hasNext())
{
PosRow rsRow = rs.next();
String flag = (String) rsRow.getAttribute("AFFIRM_FLAG");
if("0".equals(flag))
{
context.put("MESSAGES",SLAB_NO[i] + " 未进行审核,不可退回! ");
return PosBizControlConstants.SUCCESS;
}
if("2".equals(flag))
{
context.put("MESSAGES",SLAB_NO[i] + " 审核不通过,不可退回! ");
return PosBizControlConstants.SUCCESS;
}
}
else
{
String msg = sendGet("http://10.90.0.166:8083/api/TqMes/IS_Leave_Factory?forecast_no=",SEND_NO[i]);
JSONObject jsonObj = JSONObject.parseObject(msg);
String condition = jsonObj.getString("condition");
if("FALSE".equals(condition.toUpperCase()))
{
if(MEMO[i] == null || "".equals(MEMO[i]))
{
context.put("MESSAGES",SLAB_NO[i] + " 请输入退回原因!");
return PosBizControlConstants.SUCCESS;
}
PosParameter param2 = new PosParameter();
param2.setWhereClauseParameter(0, MEMO[i]);
param2.setWhereClauseParameter(1, PLT_TRS_EMP_ID[0]);
param2.setWhereClauseParameter(2, SLAB_NO[i]);
param2.setWhereClauseParameter(3, SEND_NO[i]);
this.getDao("mesdao").update("UIG080010_05.INSERT", param2);
context.put("MESSAGES",SLAB_NO[i] + " 已出厂,如要删除明细需走审批流程,请去审批界面进行审核! ");
return PosBizControlConstants.SUCCESS;
}
}
}catch (Exception e)
{
context.put("MESSAGES",e.getMessage());
return PosBizControlConstants.SUCCESS;
}
CallableStatement cstm = null;
cstm = dao.getCallableStatement("UIG080010_03.CAL");
try
{
cstm.setString(1, SLAB_NO[i]);
cstm.setString(2, PLT_TRS_EMP_ID[0]);
cstm.registerOutParameter(3, java.sql.Types.VARCHAR);
cstm.registerOutParameter(4, java.sql.Types.VARCHAR);
cstm.execute();
//财务数据上抛 移入存储过程MES_LG_KC.BACKLIST_BP
/*cstm = this.getDao("mesdao").getCallableStatement("UPLOAD_DATA.CAL");
cstm.setString(1, SLAB_NO[i]);
cstm.setString(2, "69A");
cstm.setString(3, "D");
cstm.setString(4, "板坯外销撤回");
cstm.setString(5, PLT_TRS_EMP_ID[0]);
cstm.registerOutParameter(6, java.sql.Types.VARCHAR);
cstm.execute();
String err1 = cstm.getString(6);*/
}catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if(cstm != null)
{
try
{
al.add(""+SLAB_NO[i]+""+""+cstm.getString(4)+"");
cstm.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
context.put("BK", al);System.out.println(al);
}
return PosBizControlConstants.SUCCESS;
}
/**
* 向指定URL发送GET方法的请求
*
* @param url
* 发送请求的URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return URL 所代表远程资源的响应结果
*/
public String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream(),"UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
}