ProdInOutServiceImpl.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.uas.eis.serviceImpl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.uas.eis.dao.BaseDao;
  5. import com.uas.eis.dao.SqlRowList;
  6. import com.uas.eis.service.ProdInOutService;
  7. import com.uas.eis.utils.BaseUtil;
  8. import com.uas.eis.utils.HmacUtils;
  9. import com.uas.eis.utils.HttpUtil;
  10. import com.uas.eis.utils.HttpUtil.Response;
  11. import com.uas.eis.utils.NumberUtil;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Service;
  14. import java.net.URLEncoder;
  15. import java.util.HashMap;
  16. import java.util.Map;
  17. @Service("prodInOutService")
  18. public class ProdInOutServiceImpl implements ProdInOutService {
  19. @Autowired
  20. private BaseDao baseDao;
  21. @Override
  22. public Map<String, Object> postProdInOut(int pi_id, String caller,String master) {
  23. Map<String, Object> modelMap = new HashMap<String, Object>();
  24. String inoutno = baseDao.getFieldValue("prodinout", "pi_inoutno", "pi_id=" + pi_id, String.class);
  25. String piClass = baseDao.getFieldValue("prodinout", "pi_class", "pi_id=" + pi_id, String.class);
  26. Object inorout = baseDao.getFieldDataByCondition("DOCUMENTSETUP", "ds_inorout", "DS_NAME='" + piClass + "'");
  27. HashMap<String, String> header = new HashMap<String, String>();
  28. Map<String, String> params = new HashMap<>();
  29. //时间戳
  30. String timestamp = String.valueOf(System.currentTimeMillis());
  31. //请求地址+时间戳+dataURL编码+master
  32. String urlMessage="https://uas.cicsc.com/ERP_T/scm/reserve/postProdInOut.action?_timestamp="+timestamp+"&master="+master+"&id="+pi_id+"&caller="+caller;
  33. //Hmac加密作为签名
  34. String Url=urlMessage+"&_signature="+HmacUtils.encode(urlMessage);
  35. try {
  36. header.put("referer",Url);
  37. Response response = HttpUtil.sendPostRequest(Url,header,params,false,null);
  38. String res = response.getResponseText();
  39. JSONObject jsonObject = JSON.parseObject(res);
  40. if (jsonObject.getString("exceptionInfo")!=null && jsonObject.getString("exceptionInfo")!=""){
  41. modelMap.put("success", false);
  42. modelMap.put("error",jsonObject.getString("exceptionInfo"));
  43. return modelMap;
  44. }
  45. if(!jsonObject.getBoolean("success")){
  46. modelMap.put("success", false);
  47. modelMap.put("error",piClass+"(inoutno)过账失败!");
  48. return modelMap;
  49. }
  50. modelMap.put("success", true);
  51. modelMap.put("error","");
  52. return modelMap;
  53. } catch (Exception e) {
  54. modelMap.put("success", false);
  55. modelMap.put("error",e.getMessage());
  56. return modelMap;
  57. }
  58. }
  59. public void dockingQtyDiff(int pi_id){
  60. SqlRowList rs = baseDao.queryForRowSet("select pi_id,pi_class,pi_type from prodinout where pi_id="+pi_id+" and nvl(pi_issendxx,0)<>0" +
  61. "and exists(select 1 from prodiodetail where pd_piid=pi_id and nvl(pd_inqty,0)<>nvl(pd_dockingactqty,0))");
  62. if (rs.next()) {
  63. String piclass=rs.getGeneralString("pi_class");
  64. if("采购验收单".equals(piclass)||"委外验收单".equals(piclass)){//需要更新来源已转数
  65. SqlRowList rs_detail = baseDao.queryForRowSet("select pd_ordercode ,pd_orderdetno " +
  66. " from prodiodetail " +
  67. " where pd_piid="+pi_id+" and nvl(pd_inqty,0)<>nvl(pd_dockingactqty,0) and nvl(pd_ordercode,' ')<>' ' " +
  68. " group by pd_ordercode,pd_orderdetno");
  69. while (rs_detail.next()){
  70. String ordercode=rs_detail.getGeneralString("pd_ordercode");
  71. int orderdetno=rs_detail.getGeneralInt("pd_orderdetno");
  72. if("采购验收单".equals(piclass)){
  73. Object qty = baseDao.getFieldDataByCondition("ProdIODetail",
  74. "sum(nvl(pd_inqty,0)-case when pd_status=99 then nvl(pd_outqty,0) else 0 end)", "pd_ordercode='"
  75. + ordercode+ "' and pd_orderdetno='" + orderdetno
  76. + "' and pd_piclass in ('采购验收单','采购验退单') AND pd_piid <>" + pi_id);
  77. Object tQty=baseDao.getFieldDataByCondition("ProdIODetail","sum(nvl(pd_dockingactqty,0))",
  78. "pd_ordercode='"+ ordercode + "' and pd_orderdetno='" + orderdetno
  79. + "' and pd_piid =" + pi_id);
  80. qty = qty == null ? 0 : qty;
  81. tQty = tQty == null ? 0 : tQty;
  82. SqlRowList rs_check = baseDao.queryForRowSet("select pd_code,pd_detno,pd_qty from purchasedetail" +
  83. " where pd_code ='"+ordercode+"' and pd_detno="+orderdetno+" and " +
  84. "pd_qty<"+ NumberUtil.add(Double.parseDouble(qty.toString()), Double.parseDouble(tQty.toString())));
  85. if(rs_check.next()){
  86. StringBuffer sb = new StringBuffer("按实际入库数量调整后会超出采购单可转数量],采购单号:").append(ordercode).append(",行号:")
  87. .append(orderdetno).append(",采购数量:").append(rs_check.getGeneralDouble("pd_qty")).append(",已转数量:")
  88. .append(qty).append(",本单实际数量:").append(tQty);
  89. BaseUtil.showError(sb.toString());
  90. }else{
  91. // 采购单
  92. baseDao.updateByCondition("PurchaseDetail", "pd_yqty=" + NumberUtil.add(Double.parseDouble(qty.toString()), Double.parseDouble(tQty.toString())),
  93. "pd_code='"+ordercode+"' and pd_detno="+orderdetno);
  94. baseDao.updateByCondition("PurchaseDetail", "pd_yqty=0",
  95. "NVL(pd_yqty,0)<=0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
  96. baseDao.updateByCondition("PurchaseDetail", "pd_status='AUDITED'",
  97. "NVL(pd_yqty,0)=0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
  98. baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'",
  99. "NVL(pd_yqty,0)=pd_qty AND NVL(pd_yqty,0) <> 0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
  100. baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'",
  101. "nvl(pd_yqty,0)<nvl(pd_qty,0) and nvl(pd_yqty,0)<>0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
  102. Integer puid = baseDao.queryForObject("select nvl(pd_puid,0) from PurchaseDetail where pd_code=? and pd_detno=?", Integer.class,
  103. ordercode,orderdetno);
  104. if (puid != null && puid > 0) {
  105. int count = baseDao.getCountByCondition("PurchaseDetail", "pd_puid=" + puid);
  106. int yCount = baseDao.getCountByCondition("PurchaseDetail", "pd_puid=" + puid
  107. + " and nvl(pd_acceptqty,0)=pd_qty");
  108. int xCount = baseDao
  109. .getCountByCondition("PurchaseDetail", "pd_puid=" + puid + " and nvl(pd_acceptqty,0)=0");
  110. String status = "PART2IN",name="部分入库";
  111. if (yCount == count) {
  112. status = "TURNIN";
  113. name="已入库";
  114. }
  115. if (xCount == count) {
  116. status = "";
  117. name="";
  118. }
  119. baseDao.updateByCondition("Purchase",
  120. "pu_turnstatuscode='" + status + "',pu_turnstatus='" + name + "'",
  121. "pu_id=" + puid);
  122. }
  123. }
  124. }else if("委外验收单".equals(piclass)){
  125. Object qty = baseDao.getFieldDataByCondition("ProdIODetail",
  126. "sum(nvl(pd_inqty,0)-case when pd_status=99 then nvl(pd_outqty,0) else 0 end)", "pd_ordercode='"
  127. + ordercode + "' and pd_piclass in ('委外验收单','委外验退单') AND pd_piid <>" + pi_id);
  128. Object tQty=baseDao.getFieldDataByCondition("ProdIODetail","sum(nvl(pd_dockingactqty,0))",
  129. "pd_ordercode='"+ ordercode + "' and pd_piid =" + pi_id);
  130. qty = qty == null ? 0 : qty;
  131. tQty = tQty == null ? 0 : tQty;
  132. baseDao.updateByCondition("make", " ma_tomadeqty="+NumberUtil.add(Double.parseDouble(qty.toString()), Double.parseDouble(tQty.toString())),
  133. "ma_code='"+ ordercode+ "'");
  134. }
  135. }
  136. }
  137. baseDao.execute("update prodiodetail set pd_inqty=pd_dockingactqty where pd_piid="+pi_id);
  138. }
  139. }
  140. }