|
@@ -0,0 +1,399 @@
|
|
|
+package nc.bs.servlet.service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonGenerationException;
|
|
|
+import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+
|
|
|
+import javax.servlet.ServletException;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+
|
|
|
+import nc.bs.framework.adaptor.IHttpServletAdaptor;
|
|
|
+import nc.bs.framework.common.InvocationInfoProxy;
|
|
|
+import nc.bs.framework.common.NCLocator;
|
|
|
+import nc.bs.framework.server.ISecurityTokenCallback;
|
|
|
+import nc.dz.json.Data;
|
|
|
+import nc.dz.json.Entry;
|
|
|
+import nc.dz.json.Result;
|
|
|
+import nc.dz.json.Root;
|
|
|
+import nc.gy.log.NcLog;
|
|
|
+import nc.itf.uap.IUAPQueryBS;
|
|
|
+import nc.jdbc.framework.processor.BeanListProcessor;
|
|
|
+import nc.md.persist.framework.IMDPersistenceQueryService;
|
|
|
+import nc.pub.util.DataSourceUtil;
|
|
|
+import nc.vo.ic.m4455.entity.SapplyBillBodyVO;
|
|
|
+import nc.vo.ic.m4455.entity.SapplyBillVO;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import nc.vo.pubapp.pattern.pub.SqlBuilder;
|
|
|
+
|
|
|
+
|
|
|
+public class Outbdapplication查询出库申请单的数据 extends BaseServlet implements IHttpServletAdaptor{
|
|
|
+
|
|
|
+ private IUAPQueryBS iuapquerybs=(IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
|
|
|
+
|
|
|
+ private ArrayList<String> pickDates = new ArrayList<String>();// 领料时间
|
|
|
+
|
|
|
+ private ArrayList<String> proNos = new ArrayList<String>();// 工程编号
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAction(HttpServletRequest request, HttpServletResponse req)
|
|
|
+ throws ServletException, IOException {
|
|
|
+ try {
|
|
|
+ NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
|
|
|
+ DataSourceUtil.setDataSource();
|
|
|
+ String invocatpk_group=InvocationInfoProxy.getInstance().getGroupId();
|
|
|
+ InvocationInfoProxy.getInstance().setGroupId(invocatpk_group);
|
|
|
+ String createStr = buildJson(request, req, this.getClass().getName());
|
|
|
+ // com.alibaba.fastjson.JSONObject json = JSON.parseObject(createStr);
|
|
|
+ // NcLog.initUI("json:"+json.toString(),"dzgy_query");
|
|
|
+ // com.alibaba.fastjson.JSONArray bodyArray = json.getJSONArray("result");
|
|
|
+ JSONObject jsonObject = new JSONObject(createStr);
|
|
|
+
|
|
|
+ NcLog.initUI("json:"+jsonObject.toString(),"dzgy_query");
|
|
|
+
|
|
|
+ String token =request.getParameter("token");
|
|
|
+
|
|
|
+ if(!(token!=null && !token.equals("")&&("07a81a68-c60c-4ee4-83dc-25aa51a51497").equals(token))){
|
|
|
+ req.getWriter().write(formatRSJsonData("失败",
|
|
|
+ "请确认通讯密码是否正确!","").toString());
|
|
|
+ NcLog.initUI("通讯密码不正确!","dzgy_query");
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// for (int i = 0; i < bodyArray.size(); i++) {
|
|
|
+// com.alibaba.fastjson.JSONObject jsonObject = bodyArray.getJSONObject(i);
|
|
|
+// checkJson(jsonObject);
|
|
|
+// String pickDate=jsonObject.getString("pickDate");//领料时间
|
|
|
+// String proNo=jsonObject.getString("proNo");//工程编号
|
|
|
+// pickDates.add(pickDate);
|
|
|
+// proNos.add(proNo);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+// Map<String,ArrayList<SapplyBillBodyVO>> map=getMapSapplyBodyVO(); //查询的结果集
|
|
|
+
|
|
|
+
|
|
|
+// for (int i = 0; i < bodyArray.size(); i++) {
|
|
|
+// com.alibaba.fastjson.JSONObject jsonObject = bodyArray.getJSONObject(i);
|
|
|
+// String proNo=jsonObject.getString("proNo");//工程编号
|
|
|
+// String pickDate=jsonObject.getString("pickDate");//领料时间
|
|
|
+//
|
|
|
+// ArrayList<SapplyBillBodyVO> bodyvo=map.get(proNo+pickDate);
|
|
|
+//
|
|
|
+// String rutunjson=getJsonExample(bodyvo);
|
|
|
+//
|
|
|
+// req.getWriter().write(rutunjson);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ checkJson(jsonObject);
|
|
|
+ String pickDate=jsonObject.getString("pickDate");//领料时间
|
|
|
+ String proNo=jsonObject.getString("proNo");//工程编号
|
|
|
+// String corpcode=jsonObject.getString("corpcode");//公司
|
|
|
+// ArrayList<SapplyBillBodyVO> bodyvos= getMapSapplyBodyVO(pickDate,proNo,corpcode);
|
|
|
+
|
|
|
+ ArrayList<SapplyBillBodyVO> bodyvos= getMapSapplyBodyVO(pickDate,proNo);
|
|
|
+
|
|
|
+ if(null==bodyvos || bodyvos.size()==0){
|
|
|
+ req.getWriter().write(formatRSJsonData("失败","数据为空!","").toString());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String rutunjson=getJsonExample(bodyvos);
|
|
|
+
|
|
|
+ req.getWriter().write(rutunjson);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ req.getWriter().write(formatRSJsonData("失败", e.getMessage(),"").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void checkJson(JSONObject jsonObject) throws Exception {
|
|
|
+
|
|
|
+ StringBuffer mags = new StringBuffer();
|
|
|
+ Boolean empty = true;
|
|
|
+
|
|
|
+ String pickDate = "pickDate";
|
|
|
+// String proNo = "proNo";
|
|
|
+// String[] HeadKey = {pickDate,proNo};
|
|
|
+
|
|
|
+ String[] HeadKey = {pickDate};
|
|
|
+
|
|
|
+ for (String as : HeadKey) {
|
|
|
+ if (jsonObject.getString(as).isEmpty()) {
|
|
|
+ empty = false;
|
|
|
+ mags.append("'" + as + "'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty) {
|
|
|
+ throw new Exception("以下字段不可为空:"+mags);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/* private Map<String,ArrayList<SapplyBillBodyVO>> getMapSapplyBodyVO() throws BusinessException{
|
|
|
+
|
|
|
+ SqlBuilder sqlbulid =new SqlBuilder();
|
|
|
+
|
|
|
+ String sql =" select p.project_code vbcdef1,h.vbillcode vbcdef2,a.Vdef3 vbcdef3,a.dbilldate vbcdef4,m.code vbcdef5 ,m.name vbcdef6 "
|
|
|
+ + " m.materialspec || m.materialtype vbcdef7 , b.noutboundastnum ,b.nnum from ic_sapply_b b "
|
|
|
+ + " innser join ic_sapply_h h on h.cgeneralhid =b.cgeneralhid "
|
|
|
+ + " inner join bd_project p on p.pk_project=b.Cprojectid "
|
|
|
+ + " inner join org_stockorg o on o.pk_stockorg =h.cissueorg "
|
|
|
+ + " inner join bd_material m on m. pk_material =b.cmaterialvid "
|
|
|
+ + " and nvl(a.dr,0)=0 and nvl(b.dr,0)=0 and nvl(p.dr,0)=0 and o.code='0103' and ";
|
|
|
+
|
|
|
+ sqlbulid.append(sql);
|
|
|
+ sqlbulid.append("a.dbilldate", pickDates.toArray(new String[pickDates.size()]) );
|
|
|
+ sqlbulid.append(" and " );
|
|
|
+ sqlbulid.append("p.project_code", proNos.toArray(new String[proNos.size()]) );
|
|
|
+
|
|
|
+
|
|
|
+ ArrayList<SapplyBillBodyVO> bodyvos=(ArrayList<SapplyBillBodyVO>) iuapquerybs.executeQuery(sqlbulid.toString(), new BeanListProcessor(SapplyBillBodyVO.class));
|
|
|
+
|
|
|
+ if(bodyvos == null || bodyvos.size() == 0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,ArrayList<SapplyBillBodyVO>> map = new HashMap<String, ArrayList<SapplyBillBodyVO>>();
|
|
|
+
|
|
|
+ for(SapplyBillBodyVO vo : bodyvos){
|
|
|
+
|
|
|
+ if(null==map.get(vo.getVbcdef1()+vo.getVbcdef4())){
|
|
|
+ ArrayList<SapplyBillBodyVO> sappbillbody=new ArrayList<SapplyBillBodyVO> ();
|
|
|
+ sappbillbody.add(vo);
|
|
|
+ }else{
|
|
|
+
|
|
|
+ map.get(vo.getVbcdef1()+vo.getVbcdef4()).add(vo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private ArrayList<SapplyBillBodyVO> getMapSapplyBodyVO(String pickDates, String proNos) throws BusinessException{
|
|
|
+
|
|
|
+ StringBuffer sbf=new StringBuffer();
|
|
|
+// String sql =" select h.cgeneralhid,p.project_code vbcdef1,h.vbillcode vbcdef2,h.Vdef3 vbcdef3,h.dbilldate vbcdef4,m.code vbcdef5 ,m.name vbcdef6, "
|
|
|
+ String sql =" select h.cgeneralhid,p.project_code vbcdef1,h.vbillcode vbcdef2,case when h.vdef3 is not null then (select name from bd_defdoc where pk_defdoc=h.vdef3) else '' end as vbcdef3,"
|
|
|
+ + " h.dbilldate vbcdef4,m.code vbcdef5 ,m.name vbcdef6, "
|
|
|
+ + " m.materialspec || m.materialtype vbcdef7 , e.noutboundastnum vbcdef8 ,b.nnum from ic_sapply_b b "
|
|
|
+ + " inner join ic_sapply_h h on h.cgeneralhid =b.cgeneralhid "
|
|
|
+// + " inner join bd_project p on p.pk_project=b.Cprojectid "
|
|
|
+ + " inner join bd_project p on p.pk_project=h.vdef2 "
|
|
|
+ + " inner join org_stockorg o on o.pk_stockorg =h.cissueorg "
|
|
|
+ + " inner join bd_material m on m. pk_material =b.cmaterialvid "
|
|
|
+ + " inner join ic_sapply_e e on e. cgeneralbid =b.cgeneralbid "
|
|
|
+ + " and nvl(h.dr,0)=0 and nvl(b.dr,0)=0 and nvl(p.dr,0)=0 and nvl(m.dr,0)=0 and nvl(o.dr,0)=0 "
|
|
|
+ + " and e.noutboundastnum is not null "
|
|
|
+ + " and nvl(e.dr,0)=0 "
|
|
|
+// + " and o.code='0103' "
|
|
|
+ + " and substr (h.dbilldate,1,10) ='"+pickDates+"' ";
|
|
|
+
|
|
|
+ sbf.append(sql);
|
|
|
+
|
|
|
+ if(null!=proNos && !"".equals(proNos)){
|
|
|
+ sbf.append(" and p.project_code='"+proNos+"'");
|
|
|
+ }
|
|
|
+
|
|
|
+// if(null!=corpcode && !"".equals(corpcode)){
|
|
|
+// sbf.append(" and o.code='"+corpcode+"'");
|
|
|
+// }
|
|
|
+
|
|
|
+ ArrayList<SapplyBillBodyVO> bodyvos=(ArrayList<SapplyBillBodyVO>) iuapquerybs.executeQuery(sbf.toString(), new BeanListProcessor(SapplyBillBodyVO.class));
|
|
|
+
|
|
|
+
|
|
|
+ return bodyvos;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/* private String getJsonExample(ArrayList<SapplyBillBodyVO> sapbodyvos) throws JSONException{
|
|
|
+
|
|
|
+ // 创建最外层的JSONObject
|
|
|
+ JSONObject root = new JSONObject();
|
|
|
+
|
|
|
+ // 创建result对象
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ // 创建data数组
|
|
|
+ JSONArray data = new JSONArray();
|
|
|
+
|
|
|
+ // 创建data数组中的第一个对象
|
|
|
+ JSONObject dataItem = new JSONObject();
|
|
|
+ dataItem.put("proNo", sapbodyvos.get(0).getVbcdef1());//工程编号
|
|
|
+ dataItem.put("bi1INo", sapbodyvos.get(0).getVbcdef2());//领料单编号
|
|
|
+ dataItem.put("smanager", sapbodyvos.get(0).getVbcdef3());//领料人
|
|
|
+ dataItem.put("pickDate", sapbodyvos.get(0).getVbcdef4());//领料时间
|
|
|
+
|
|
|
+ // 创建entry数组
|
|
|
+ JSONArray entryArray = new JSONArray();
|
|
|
+
|
|
|
+ for(SapplyBillBodyVO bodyvo:sapbodyvos){
|
|
|
+
|
|
|
+ // 创建entry数组中的第一个对象
|
|
|
+ JSONObject entryItem = new JSONObject();
|
|
|
+ entryItem.put("matNum", bodyvo.getVbcdef5());//物料编码
|
|
|
+ entryItem.put("matName", bodyvo.getVbcdef6());//物料名称
|
|
|
+ entryItem.put("matModel", bodyvo.getVbcdef7());//规格型号
|
|
|
+ entryItem.put("qty", bodyvo.getVbcdef8());//已出库数量
|
|
|
+ entryItem.put("guistOty", bodyvo.getNnum());//申请数量
|
|
|
+ entryItem.put("quistDate", sapbodyvos.get(0).getVbcdef4());//申请领料日期
|
|
|
+ entryItem.put("sourceBi11",sapbodyvos.get(0).getVbcdef2());//申请计划单号
|
|
|
+ // 将entryItem添加到entryArray
|
|
|
+ entryArray.put(entryItem);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 将entryArray添加到dataItem
|
|
|
+ dataItem.put("entry", entryArray);
|
|
|
+
|
|
|
+ // 将dataItem添加到data数组
|
|
|
+ data.put(dataItem);
|
|
|
+
|
|
|
+ // 将data数组添加到result对象
|
|
|
+ result.put("data", data);
|
|
|
+
|
|
|
+ // 将result对象添加到root对象
|
|
|
+ root.put("result", result);
|
|
|
+
|
|
|
+ // 添加其他字段到root对象
|
|
|
+ root.put("status", "成功");
|
|
|
+ root.put("error", "");
|
|
|
+ root.put("message", "");
|
|
|
+
|
|
|
+ return root.toString();
|
|
|
+
|
|
|
+
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private String getJsonExample(ArrayList<SapplyBillBodyVO> sapbodyvos) throws JSONException, JsonGenerationException, JsonMappingException, IOException{
|
|
|
+
|
|
|
+
|
|
|
+ Map<String,ArrayList<SapplyBillBodyVO>> map=new HashMap<String,ArrayList<SapplyBillBodyVO>>();
|
|
|
+ //按表头分单
|
|
|
+ for(SapplyBillBodyVO bodyvo:sapbodyvos){
|
|
|
+
|
|
|
+ if(null==map.get(bodyvo.getCgeneralhid()) || map.get(bodyvo.getCgeneralhid()).size()==0){
|
|
|
+
|
|
|
+ ArrayList<SapplyBillBodyVO> sarrysap=new ArrayList<SapplyBillBodyVO>();
|
|
|
+
|
|
|
+ sarrysap.add(bodyvo);
|
|
|
+
|
|
|
+ map.put(bodyvo.getCgeneralhid(), sarrysap);
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ ArrayList<SapplyBillBodyVO> sarrysaps=map.get(bodyvo.getCgeneralhid());
|
|
|
+
|
|
|
+ sarrysaps.add(bodyvo);
|
|
|
+
|
|
|
+ map.put(bodyvo.getCgeneralhid(), sarrysaps);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<Data> dataList =new ArrayList<Data>();
|
|
|
+
|
|
|
+ for(Map.Entry<String,ArrayList<SapplyBillBodyVO>> entrymap : map.entrySet()){
|
|
|
+
|
|
|
+ List<Entry> entryList = new ArrayList<Entry>();
|
|
|
+
|
|
|
+ Data data = new Data();
|
|
|
+ data.setEntry(entryList);
|
|
|
+ data.setBi1INo(entrymap.getValue().get(0).getVbcdef2());//领料单编号
|
|
|
+ data.setSmanager(entrymap.getValue().get(0).getVbcdef3()==null?"":entrymap.getValue().get(0).getVbcdef3());//领料人
|
|
|
+ data.setProNo(entrymap.getValue().get(0).getVbcdef1());//工程编号
|
|
|
+ data.setPickDate(entrymap.getValue().get(0).getVbcdef4());//领料时间
|
|
|
+ dataList.add(data);
|
|
|
+
|
|
|
+ for(SapplyBillBodyVO bodyvo:entrymap.getValue()){
|
|
|
+ Entry entry = new Entry();
|
|
|
+ entry.setQuistDate(bodyvo.getVbcdef4());//申请领料日期
|
|
|
+ entry.setGuistOty(bodyvo.getNnum().toString());//申请数量
|
|
|
+ entry.setMatModel(bodyvo.getVbcdef7());//规格型号
|
|
|
+ entry.setQty(bodyvo.getVbcdef8()==null ? "0":bodyvo.getVbcdef8());//已出库数量
|
|
|
+ entry.setSourceBi11(bodyvo.getVbcdef2());//申请计划单号
|
|
|
+ entry.setMatName(bodyvo.getVbcdef6());//物料名称
|
|
|
+ entry.setMatNum(bodyvo.getVbcdef5());//物料编码
|
|
|
+ entryList.add(entry);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Result result = new Result();
|
|
|
+ result.setData(dataList);
|
|
|
+
|
|
|
+ Root root = new Root("", result, "", "成功");
|
|
|
+
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+
|
|
|
+ String jsonString = objectMapper.writeValueAsString(root);
|
|
|
+
|
|
|
+ return jsonString;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|