UDN-企业互联网技术人气社区

板块导航

浏览  : 479
回复  : 6

[公共] UAP生成的生产报告子表明细在NC界面显示重复

[复制链接]
uec_xm7hS07x8X的头像 楼主
发表于 2018-9-10 17:02:32 | 显示全部楼层 |阅读模式
package nc.pubimpl.mmpac.wr.me;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.impl.pubapp.pattern.data.bill.BillInsert;
import nc.impl.pubapp.pattern.data.bill.BillQuery;
import nc.itf.mmpac.wr.pwr.IPwrMaintainService;
import nc.itf.uap.iuapQueryBS;
import nc.itf.uap.pf.IPfExchangeService;
import nc.jdbc.framework.processor.BeanProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.pubitf.mmpac.entrance.me.IWrDataMes4NC;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
import nc.vo.mmpac.pmo.pac0002.entity.PMOHeadVO;
import nc.vo.mmpac.wr.entity.AggWrVO;
import nc.vo.mmpac.wr.entity.WrItemVO;
import nc.vo.mmpac.wr.entity.WrQualityVO;
import nc.vo.mmpac.wr.entity.WrVO;
import nc.vo.mmpac.wr.enumeration.WrQualityProcessMethodEnum;
import nc.vo.pub.BusinessException;
import nc.vo.pub.ISuperVO;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
* 创建生产报告服务
*/
public class WrDataServiceImpl implements IWrDataMes4NC {
private BaseDAO baseDAO = null;
private Map<String, String> kv = new HashMap<String, String>();
public JSONObject insertWrBill(String jsonParam) throws Exception {
  JSONObject jsonResult = new JSONObject();
  Logger.info("开始创建生产报告!\n");
  JSONArray jsonArray = new JSONArray(jsonParam);
  JSONObject jsonObj = jsonArray.getJSONObject(0);
  JSONArray ouputlist = jsonObj.getJSONArray("DocInputDtos");
  if (ouputlist == null || ouputlist.length() == 0) {
   throw new Exception("传输的产出数据行为空!");
  }
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  JSONArray datalist = new JSONArray();
  // 新增的生产报告数组
  // AggWrVO[] aggWrVOs = new AggWrVO[ouputlist.length()];
  Map<String, AggWrVO> aggWrVOsMap = new HashMap<String, AggWrVO>();
  for (int i = 0; i < ouputlist.length(); i++) {
   JSONObject output = ouputlist.getJSONObject(i);
   String srcID = output.getString("SrcID");
   if (!(output.toString().indexOf("DocID") > 0)) {
    JSONObject re = new JSONObject();
    re.put("SrcID", srcID);
    re.put("IsSuccess", false);
    re.put("SyncErrMsg", "未查到相应数据");
    datalist.put(re);
    continue;
   }
   String pk_dmo = output.getString("DocID");
   
   PMOHeadVO pmo = (PMOHeadVO) getBaseDAO().executeQuery("select * from mm_pmo where vbillcode='"+pk_dmo+"'", new BeanProcessor(PMOHeadVO.class));   
   // 根据离散订单pk 先查离散订单VO,然后单击转换创建对应的生产报告VO
   BillQuery<PMOAggVO> query = new BillQuery<PMOAggVO>(PMOAggVO.class);
   PMOAggVO aggDmoVO = (PMOAggVO)query.query( new String[]{ pmo.getCpmohid() } )[0];
//   IPMOQueryService dmoQueryService = NCLocator.getInstance().lookup(
//     IPMOQueryService.class);
//   PMOAggVO aggDmoVO = dmoQueryService.queryAggVObyHid4SN(new String[]{pmo.getCpmohid()})[0];
   if (aggDmoVO == null) {
    JSONObject re = new JSONObject();
    re.put("SrcID", srcID);
    re.put("IsSuccess", false);
    re.put("SyncErrMsg", "未查到相应数据");
    datalist.put(re);
    continue;
   }
   PMOAggVO aggDmoVO2 = new PMOAggVO();
   aggDmoVO2.setParent(aggDmoVO.getParent());
//   UFDateTime ufdt = (UFDateTime) aggDmoVO.getParent()
//     .getAttributeValue("tplanstarttime");
   // 单据转换规则以后 处理表体行的数量,入库批次,时间,( 一对一转换)
   AggWrVO aggWrVOs2 = (AggWrVO) NCLocator
     .getInstance()
     .lookup(IPfExchangeService.class).runChangeData("55A2", "55A4", aggDmoVO , null);
   WrItemVO[] itemVOs = aggWrVOs2.getChildrenVO();
   try {
    itemVOs[0].setNbwrastnum(new UFDouble(output
      .getString("TotalQty")));// 完工数量
    itemVOs[0]
      .setNbwrnum(new UFDouble(output.getString("TotalQty")));// 完工主数量
    itemVOs[0].setVbinbatchcode(output.getString("LotNumber"));// 入库批次号
    itemVOs[0].setVbrowno(10 + "");// 行号
    itemVOs[0].setTbendtime(new UFDateTime(sdf.parse(output
      .getString("CompleteTime")).getTime()));// 完成时间
    itemVOs[0].setTbstarttime(new UFDateTime(sdf.parse(output
      .getString("ActualStartDateTime")).getTime()));// 开始时间ActualStartDateTime
    itemVOs[0].setVbdef10(output.getString("BarCode"));// 条码用自定义字段10存放
   
    String pk_qg = output.getString("QualityGrade");
   
    if("A".equals(pk_qg)||"A1".equals(pk_qg)||"A2".equals(pk_qg)||"B".equals(pk_qg)||"C".equals(pk_qg)){
     pk_qg = ((DefdocVO)getBaseDAO().executeQuery("select * from bd_defdoc where name='"+pk_qg+"'", new BeanProcessor(DefdocVO.class))).getPk_defdoc();
     itemVOs[0].setVbfree1(pk_qg);
    }else{
     JSONObject re = new JSONObject();
     re.put("SrcID", srcID);
     re.put("IsSuccess", false);
     re.put("SyncErrMsg", "质量等级必须为A,A1,A2,B,C中的一个");
     datalist.put(re);
     continue;
    }
    itemVOs[0].setVbdef19(output.getString("AxisNum"));
    itemVOs[0].setVbdef20(output.getString("BoxNum"));
    itemVOs[0].setFbproducttype(1);
    itemVOs[0].setFbsourcetype(2);
   
   } catch (Exception e) {
    e.printStackTrace();
   }
   aggWrVOs2.getParentVO().setVtrantypecode("55A4-01");
   aggWrVOs2.getParentVO().setVtrantypeid(getVtrantypeId("55A4-01",aggWrVOs2.getParentVO().getPk_group()));
   aggWrVOs2.getParentVO().setFbillstatus(1);// 自由态单据
   aggWrVOsMap.put(srcID, aggWrVOs2);
  }
  // 将多个生产报告进行合单处理,同离散生产订单的合并成一个生产报告
  Map<String, Map<String, AggWrVO>> aggWrVOMap = new HashMap<String, Map<String, AggWrVO>>();
  for (String key : aggWrVOsMap.keySet()) {
   AggWrVO aggVo = aggWrVOsMap.get(key);
   if (aggVo == null) {
    continue;
   }
   String pk_dmo = aggVo.getChildrenVO()[0].getCbmoid();// 生产订单id
   Map<String, AggWrVO> aggWrVOEntry = aggWrVOMap.get(pk_dmo);
   if (aggWrVOEntry == null||aggWrVOEntry.size() == 0) {
    aggWrVOEntry = new HashMap<>();
    aggWrVOEntry.put(key, aggVo);
    aggWrVOMap.put(pk_dmo, aggWrVOEntry);
   } else {
    aggWrVOEntry.put(key, aggVo);
    aggWrVOMap.put(pk_dmo, aggWrVOEntry);
   }
  }
  // 最终返回的data数据
  // 最终的合并后的生产报告list
  // 然后便利map处理相同生产订单的生产报告
  int ok = 0;// 成功值默认为失败!
  int successNum = 0;// 成功条数
  int errorNum = 0;// 失败条数
  if (aggWrVOMap.size() != 0) {
   for (String key : aggWrVOMap.keySet()) {
    JSONObject resultDataMap = new JSONObject();
    //整合Aggvo
    Map<String, AggWrVO> aggWrVOEntry = aggWrVOMap.get(key);
    AggWrVO aggWrVO = new AggWrVO();
    WrVO wrVO = new WrVO();
    WrItemVO[] itemVOs = new WrItemVO[aggWrVOEntry.size()];
    int flag = 0;
    for (AggWrVO aggvo : aggWrVOEntry.values()) {
     if (flag == 0) {
      wrVO = aggvo.getParentVO();
     }
     itemVOs[flag] = aggvo.getChildrenVO()[0];
     itemVOs[flag].setVbrowno((flag + 1) * 10 + "");// 行号重新排
     flag++;
    }
    aggWrVO.setParentVO(wrVO);
    aggWrVO.setChildrenVO(itemVOs);
    String[] srcidlist = aggWrVOEntry.keySet().toArray(
      new String[0]);
    // 批量保存处理
    try {
     // 手动质检
     setQulityDefalutValue(aggWrVO);
     //BillInsert<AggWrVO> bo = new BillInsert<AggWrVO>();
     AggWrVO[] newAggWrVOs = getMaintainServce().insert(new AggWrVO[]{aggWrVO});
     //AggWrVO[] newAggWrVOs = bo.insert(new AggWrVO[]{aggWrVO});
     WrItemVO[] superVOs = newAggWrVOs[0].getChildrenVO();
     for (int i = 0; i < superVOs.length; i++) {
      WrItemVO wrItemVO = superVOs;
      resultDataMap.put("SrcID", srcidlist);// 来源pk
      resultDataMap.put("ErpID", wrItemVO.getPk_wr_product());// NC生成报告的行pk
      resultDataMap.put("IsSuccess", true);
      datalist.put(resultDataMap);
      successNum++;// 成功条数加1
     }
    } catch (Exception e) {
     // 处理失败的数据
     for (int i = 0; i < aggWrVO.getChildrenVO().length; i++) {
      resultDataMap.put("SrcID", srcidlist);
      resultDataMap.put("IsSuccess", false);
      resultDataMap.put("SyncErrMsg", e.getMessage());
      datalist.put(resultDataMap);
      errorNum++;// 失败条数加1
     }
     continue;
    }
   }
  }
  // 处理ok值,0失败,1成功,2部分成功
  String msg = "创建完工报告失败!";
  if (errorNum > 0 && successNum > 0) {
   ok = 2;
   msg = successNum + "条数据成功," + errorNum + "条数据失败!";
  } else if (errorNum > 0 && successNum == 0) {
   ok = 0;
   msg = "创建完工报告全部失败!";
  } else if (errorNum == 0 && successNum > 0) {
   ok = 1;
   msg = "创建完工报告全部成功!";
  }
  jsonResult.put("Data", datalist);
  jsonResult.put("ok", ok);
  jsonResult.put("msg", msg);
  Logger.info("生成完工报告成功!\n");
  return jsonResult;
}
public void setQulityDefalutValue(AggWrVO aggWrVO)
   throws JSONException {
  WrQualityVO qualityVO = null;
  ISuperVO[] superVOs = aggWrVO.getChildren(WrItemVO.class);
  Integer row = 10;
  UFDouble reworkcount = new UFDouble("0");
//  UFDouble goodcount = new UFDouble(json.getString("TotalQty"));
//  String vginstockbcode = json.getString("LotNumber");
  for (ISuperVO superVO : superVOs) {
   WrItemVO itemVO = (WrItemVO) superVO;
   itemVO.setVbrowno(row.toString());
   row = row + 10;
   if (MMValueCheck.isEmpty(itemVO.getQualityvos())) {
    qualityVO = new WrQualityVO();
    qualityVO.setPk_group(itemVO.getPk_group());
    qualityVO.setPk_org(itemVO.getPk_org());
    qualityVO.setPk_org_v(itemVO.getPk_org_v());
    qualityVO.setCgmaterialid(itemVO.getCbmaterialid());
    qualityVO.setCgmaterialvid(itemVO.getCbmaterialvid());
    qualityVO.setCgmainmaterialid(itemVO.getCbmainmaterialid());
    qualityVO.setCgmainmatterialvid(itemVO.getCbmainmaterialvid());
    qualityVO.setCgmainbomid(itemVO.getCbmainbomid());
    qualityVO.setFgproducttype(itemVO.getFbproducttype());
    qualityVO.setCgunitid(itemVO.getCbunitid());
    qualityVO.setCgastunitid(itemVO.getCbastunitid());
    qualityVO.setVgchangerate(itemVO.getVbchangerate());
    qualityVO.setNgastnum(calNassitNum(itemVO.getVbchangerate(),
      itemVO.getNbwrastnum()));
    qualityVO.setNgnum(itemVO.getNbwrastnum());
    qualityVO.setFgprocessmethod(WrQualityProcessMethodEnum.PRODIN
      .toIntValue());
    qualityVO.setVginstockbid(itemVO.getVbinbatchid());
    qualityVO.setVginstockbcode(itemVO.getVbinbatchcode());
    qualityVO.setCgproductorid(itemVO.getCbproductorid());
    qualityVO.setCgprojectid(itemVO.getCbprojectid());
    qualityVO.setCgcustomerid(itemVO.getCbcustomerid());
    qualityVO.setCgffileid(itemVO.getCbffileid());
    qualityVO.setCgvendorid(itemVO.getCbvendorid());
    qualityVO.setVgfree1(itemVO.getVbfree1());
    qualityVO.setVgfree2(itemVO.getVbfree2());
    qualityVO.setVgfree3(itemVO.getVbfree3());
    qualityVO.setVgfree4(itemVO.getVbfree4());
    qualityVO.setVgfree5(itemVO.getVbfree5());
    qualityVO.setVgfree6(itemVO.getVbfree6());
    qualityVO.setVgfree7(itemVO.getVbfree7());
    qualityVO.setVgfree8(itemVO.getVbfree8());
    qualityVO.setVgfree9(itemVO.getVbfree9());
    qualityVO.setVgfree10(itemVO.getVbfree10());
    qualityVO.setVgdef1(itemVO.getVbdef1());
    qualityVO.setVgdef2(itemVO.getVbdef2());
    qualityVO.setVgdef3(itemVO.getVbdef3());
    qualityVO.setVgdef4(itemVO.getVbdef4());
    qualityVO.setVgdef5(itemVO.getVbdef5());
    qualityVO.setVgdef6(itemVO.getVbdef6());
    qualityVO.setVgdef7(itemVO.getVbdef7());
    qualityVO.setVgdef8(itemVO.getVbdef8());
    qualityVO.setVgdef9(itemVO.getVbdef9());
    qualityVO.setVgdef10(itemVO.getVbdef10());
    qualityVO.setVgdef11(itemVO.getVbdef11());
    qualityVO.setVgdef12(itemVO.getVbdef12());
    qualityVO.setVgdef13(itemVO.getVbdef13());
    qualityVO.setVgdef14(itemVO.getVbdef14());
    qualityVO.setVgdef15(itemVO.getVbdef15());
    qualityVO.setVgdef16(itemVO.getVbdef16());
    qualityVO.setVgdef17(itemVO.getVbdef17());
    qualityVO.setVgdef18(itemVO.getVbdef18());
    qualityVO.setVgdef19(itemVO.getVbdef19());
    qualityVO.setVgdef20(itemVO.getVbdef20());
    qualityVO.setPk_wr_product_q(itemVO.getPk_wr_product());
    // qualityVO.setCgqualitylevelid("0001A71000000000353G");
    qualityVO.setStatus(VOStatus.NEW);
    WrQualityVO clone = (WrQualityVO) qualityVO.clone();
    clone.setNgastnum(calNassitNum(itemVO.getVbchangerate(),
      reworkcount));
    clone.setNgnum(reworkcount);
    clone.setFgprocessmethod(WrQualityProcessMethodEnum.DISCARDIN
      .toIntValue());
    itemVO.setQualityvos(new WrQualityVO[] { qualityVO, clone });
   }
  }
}
public static UFDouble calNassitNum(String rate, UFDouble nnum) {
  String[] splits = rate.split("/");
  UFDouble div = new UFDouble(splits[0]).div(new UFDouble(splits[1]));
  return nnum.div(div, 0);
}
/**
  * 单据交换服务
  */
private IPwrMaintainService getMaintainServce() {
  return NCLocator.getInstance().lookup(IPwrMaintainService.class);
}
protected BaseDAO getBaseDAO() {
  if (this.baseDAO == null) {
   this.baseDAO = new BaseDAO();
  }
  return this.baseDAO;
}
/**
  * 获取报告类型主键
  *
  * @param code
  * @param pk_group
  * @return
  * @throws BusinessException
  */
private String getVtrantypeId(String code, String pk_group)
   throws BusinessException {
  if (this.kv.containsKey(code)) {
   return kv.get(code);
  }
  StringBuffer sql = new StringBuffer();
  sql.append("select pk_billtypeid from  bd_billtype ");
  sql.append(" where ( istransaction = 'Y' and pk_group='"+pk_group+"' and nvl(islock, 'N')='N' ");
  sql.append("and   1=1  and parentbilltype='55A4'  and pk_group='"+pk_group+"' and pk_billtypecode = '"
    + code + "')");
  String pk_billtypeid = (String) NCLocator.getInstance()
    .lookup(iuapQueryBS.class)
    .executeQuery(sql.toString(), new ColumnProcessor());
  if (pk_billtypeid == null) {
   throw new BusinessException("NC不存在报告类型【" + code + "】,请维护!");
  }
  this.kv.put(code, pk_billtypeid);
  return pk_billtypeid;
}
}

TIM图片20180910170015.png
TIM图片20180910165857.png




如图,生成的生产报告在数据库中只有5条明细,为什么在界面就重复了


uec_xm7hS07x8X的头像 楼主
发表于 2018-9-10 17:07:33 | 显示全部楼层
@benbenxiong 有大佬没,求破
使用道具 举报

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们
联系我们
  • 电话:010-86393388
  • 邮件:udn@yonyou.com
  • 地址:北京市海淀区北清路68号
移动客户端下载
关注我们
  • 微信公众号:yonyouudn
  • 扫描右侧二维码关注我们
  • 专注企业互联网的技术社区
版权所有:用友网络科技股份有限公司82041 京ICP备05007539号-11 京公网网备安1101080209224 Powered by Discuz!
快速回复 返回列表 返回顶部