pancy пре 1 година
родитељ
комит
40bd1195f2
1 измењених фајлова са 67 додато и 13 уклоњено
  1. 67 13
      tbb/tbb/src/private/nc/bs/tbb/servlet/InitBudgetServlet.java

+ 67 - 13
tbb/tbb/src/private/nc/bs/tbb/servlet/InitBudgetServlet.java

@@ -8,6 +8,8 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.codehaus.jettison.json.JSONException;
+
 import nc.bs.dao.BaseDAO;
 import nc.bs.dao.DAOException;
 import nc.bs.framework.adaptor.IHttpServletAdaptor;
@@ -50,48 +52,73 @@ public class InitBudgetServlet extends BaseServlet implements IHttpServletAdapto
 			NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
 			String createStr = buildJson(req, resp, this.getClass().getName());
 			JSONObject json = JSONObject.fromObject(createStr);
+			JSONObject returnobj = new JSONObject();
+			JSONArray result = new JSONArray();
+			JSONArray errMessage = new JSONArray();
 			String checkresult = checkJson(json);
 			if(checkresult != null){
-				resp.getWriter().write(formatRSJsonData("失败",
-						checkresult,"").toString());
+				errMessage.add(formatRSJsonData("失败",
+						checkresult,""));
+				returnobj.put("info", "失败");
+				returnobj.put("errMessage", checkresult);
+				returnobj.put("result", errMessage);
+				resp.getWriter().write(returnobj.toString());
 				return;
 			}
 			JSONArray bodyArray = json.getJSONArray("result");
-			JSONArray result = new JSONArray();
+			
 			for (Object Object : bodyArray) {
 				JSONObject bodyObject = JSONObject.fromObject(Object);
 				String objcode = QueryModelCode(bodyObject.getString("objname"));//应用模型编码
 				String code_entity = bodyObject.getString("code_entity");//责任主体
 				String entityPk = QueryOrgPk(code_entity);//责任主体pk
 				if(entityPk==null){
-					result.add(formatRSJsonData("失败",
+					errMessage.add(formatRSJsonData("失败",
 							"责任主体"+bodyObject.getString("code_entity")+"未查到,请检查","").toString());
-					continue;
+					returnobj.put("info", "失败");
+					returnobj.put("errMessage", "责任主体"+bodyObject.getString("code_entity")+"未查到,请检查");
+					returnobj.put("result", errMessage);
+					resp.getWriter().write(returnobj.toString());
+					return;
 				}
 				String pk_year = bodyObject.getString("pk_year");//会计年度
 				List<String> ListMeasure = QueryMeasureCode(bodyObject.getString("code_measure"));//预算编码
 				if(ListMeasure.get(0)==null){
-					result.add(formatRSJsonData("失败",
+					errMessage.add(formatRSJsonData("失败",
 							"预算编码"+bodyObject.getString("code_measure")+"未查到,请检查","").toString());
-					continue;
+					returnobj.put("info", "失败");
+					returnobj.put("errMessage", "预算编码"+bodyObject.getString("code_measure")+"未查到,请检查");
+					returnobj.put("result", errMessage);
+					resp.getWriter().write(returnobj.toString());
+					return;
 				}
 				String code_measure = ListMeasure.get(0);//预算编码
 				String measurePk = ListMeasure.get(1);//预算编码pk
 				List<String> ListVersion = QueryVersionCode(bodyObject.getString("code_version"));
 				if(ListVersion.get(0)==null){
-					result.add(formatRSJsonData("失败",
+					errMessage.add(formatRSJsonData("失败",
 							"预算版本"+bodyObject.getString("code_version")+"未查到,请检查","").toString());
-					continue;
+					returnobj.put("info", "失败");
+					returnobj.put("errMessage", "预算版本"+bodyObject.getString("code_version")+"未查到,请检查");
+					returnobj.put("result", errMessage);
+					resp.getWriter().write(returnobj.toString());
+					return;
 				}
 				String code_version = ListVersion.get(0);//预算版本编码
 				String versionPk = ListVersion.get(1);//预算版本pk
 				UFDouble value = new UFDouble(bodyObject.getString("value"));//预算总额
 				UFDouble actualUse = new UFDouble(QueryNmny(objcode,code_entity,pk_year,code_measure,code_version,sjsy));//本年度实际使用数
 				UFDouble pupremny = new UFDouble(QueryNmny(objcode,code_entity,pk_year,code_measure,code_version,yzs));//预占数
-				//预算总额-本年度实际使用数-预占数<0抛异常
-				if(value.sub(actualUse).sub(pupremny).compareTo(UFDouble.ZERO_DBL)<0){
-					result.add(formatRSJsonData("失败",
+				UFDouble Frozen = new UFDouble(QueryFrozen(code_entity,pk_year,code_measure));//冻结金额
+				//预算总额-本年度实际使用数-预占数-冻结金额<0抛异常
+				if(value.sub(actualUse).sub(pupremny).sub(Frozen).compareTo(UFDouble.ZERO_DBL)<0){
+					errMessage.add(formatRSJsonData("失败",
 							bodyObject.getString("objname")+pk_year+"年"+bodyObject.getString("code_measure")+"可用额度不足,请检查","").toString());
+					returnobj.put("info", "失败");
+					returnobj.put("errMessage", bodyObject.getString("objname")+pk_year+"年"+bodyObject.getString("code_measure")+"可用额度不足,请检查");
+					returnobj.put("result", errMessage);
+					resp.getWriter().write(returnobj.toString());
+					return;
 				}
 				else{
 					//查询一些不知道什么东西的数据
@@ -153,7 +180,11 @@ public class InitBudgetServlet extends BaseServlet implements IHttpServletAdapto
 						     "",bodyObject.getString("objname")+pk_year+"年"+bodyObject.getString("code_measure")+"预算修改成功").toString());
 				}
 			}
-			resp.getWriter().write(result.toString());
+			returnobj.put("info", "成功");
+			returnobj.put("errMessage", "");
+			returnobj.put("result", result);
+			resp.getWriter().write(returnobj.toString());
+			
 		}  catch (Exception e) {
 			// TODO 自动生成的 catch 块
 			resp.getWriter().write(formatRSJsonData("失败",
@@ -331,6 +362,25 @@ public class InitBudgetServlet extends BaseServlet implements IHttpServletAdapto
 		}
 	}
 	
+	/**
+	 * 查询冻结金额
+	 * @param code_entity
+	 * @param pk_year
+	 * @param code_measure
+	 * @return
+	 * @throws Exception
+	 */
+	public String QueryFrozen(String code_entity,String pk_year,String yscode) throws Exception{
+		String qrysql = "select PreActual from V_THAPE_YS where code_entity = '"+code_entity+"' and pk_year = '"+pk_year+"' and yscode = '"+yscode+"'";
+		Object object = "";
+			object = iuap.executeQuery(qrysql, new ColumnProcessor());
+		if (object==null) {
+			return "0";
+		}else {
+			return object.toString();
+		}
+	}
+	
 	/**
 	 * 查询pk
 	 * @param objcode
@@ -506,4 +556,8 @@ public class InitBudgetServlet extends BaseServlet implements IHttpServletAdapto
 		str.append("null)");
 		basedao.executeUpdate(str.toString());
 	}
+	
+	
+	
+	
 }