| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package com.uas.eis.serviceImpl;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.uas.eis.dao.BaseDao;
- import com.uas.eis.dao.SqlRowList;
- import com.uas.eis.service.ProdInOutService;
- import com.uas.eis.utils.BaseUtil;
- import com.uas.eis.utils.HmacUtils;
- import com.uas.eis.utils.HttpUtil;
- import com.uas.eis.utils.HttpUtil.Response;
- import com.uas.eis.utils.NumberUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.net.URLEncoder;
- import java.util.HashMap;
- import java.util.Map;
- @Service("prodInOutService")
- public class ProdInOutServiceImpl implements ProdInOutService {
- @Autowired
- private BaseDao baseDao;
- @Override
- public Map<String, Object> postProdInOut(int pi_id, String caller,String master) {
- Map<String, Object> modelMap = new HashMap<String, Object>();
- String inoutno = baseDao.getFieldValue("prodinout", "pi_inoutno", "pi_id=" + pi_id, String.class);
- String piClass = baseDao.getFieldValue("prodinout", "pi_class", "pi_id=" + pi_id, String.class);
- Object inorout = baseDao.getFieldDataByCondition("DOCUMENTSETUP", "ds_inorout", "DS_NAME='" + piClass + "'");
- HashMap<String, String> header = new HashMap<String, String>();
- Map<String, String> params = new HashMap<>();
- //时间戳
- String timestamp = String.valueOf(System.currentTimeMillis());
- //请求地址+时间戳+dataURL编码+master
- String urlMessage="https://uas.cicsc.com/ERP_T/scm/reserve/postProdInOut.action?_timestamp="+timestamp+"&master="+master+"&id="+pi_id+"&caller="+caller;
- //Hmac加密作为签名
- String Url=urlMessage+"&_signature="+HmacUtils.encode(urlMessage);
- try {
- header.put("referer",Url);
- Response response = HttpUtil.sendPostRequest(Url,header,params,false,null);
- String res = response.getResponseText();
- JSONObject jsonObject = JSON.parseObject(res);
- if (jsonObject.getString("exceptionInfo")!=null && jsonObject.getString("exceptionInfo")!=""){
- modelMap.put("success", false);
- modelMap.put("error",jsonObject.getString("exceptionInfo"));
- return modelMap;
- }
- if(!jsonObject.getBoolean("success")){
- modelMap.put("success", false);
- modelMap.put("error",piClass+"(inoutno)过账失败!");
- return modelMap;
- }
- modelMap.put("success", true);
- modelMap.put("error","");
- return modelMap;
- } catch (Exception e) {
- modelMap.put("success", false);
- modelMap.put("error",e.getMessage());
- return modelMap;
- }
- }
- public void dockingQtyDiff(int pi_id){
- SqlRowList rs = baseDao.queryForRowSet("select pi_id,pi_class,pi_type from prodinout where pi_id="+pi_id+" and nvl(pi_issendxx,0)<>0" +
- "and exists(select 1 from prodiodetail where pd_piid=pi_id and nvl(pd_inqty,0)<>nvl(pd_dockingactqty,0))");
- if (rs.next()) {
- String piclass=rs.getGeneralString("pi_class");
- if("采购验收单".equals(piclass)||"委外验收单".equals(piclass)){//需要更新来源已转数
- SqlRowList rs_detail = baseDao.queryForRowSet("select pd_ordercode ,pd_orderdetno " +
- " from prodiodetail " +
- " where pd_piid="+pi_id+" and nvl(pd_inqty,0)<>nvl(pd_dockingactqty,0) and nvl(pd_ordercode,' ')<>' ' " +
- " group by pd_ordercode,pd_orderdetno");
- while (rs_detail.next()){
- String ordercode=rs_detail.getGeneralString("pd_ordercode");
- int orderdetno=rs_detail.getGeneralInt("pd_orderdetno");
- if("采购验收单".equals(piclass)){
- Object qty = baseDao.getFieldDataByCondition("ProdIODetail",
- "sum(nvl(pd_inqty,0)-case when pd_status=99 then nvl(pd_outqty,0) else 0 end)", "pd_ordercode='"
- + ordercode+ "' and pd_orderdetno='" + orderdetno
- + "' and pd_piclass in ('采购验收单','采购验退单') AND pd_piid <>" + pi_id);
- Object tQty=baseDao.getFieldDataByCondition("ProdIODetail","sum(nvl(pd_dockingactqty,0))",
- "pd_ordercode='"+ ordercode + "' and pd_orderdetno='" + orderdetno
- + "' and pd_piid =" + pi_id);
- qty = qty == null ? 0 : qty;
- tQty = tQty == null ? 0 : tQty;
- SqlRowList rs_check = baseDao.queryForRowSet("select pd_code,pd_detno,pd_qty from purchasedetail" +
- " where pd_code ='"+ordercode+"' and pd_detno="+orderdetno+" and " +
- "pd_qty<"+ NumberUtil.add(Double.parseDouble(qty.toString()), Double.parseDouble(tQty.toString())));
- if(rs_check.next()){
- StringBuffer sb = new StringBuffer("按实际入库数量调整后会超出采购单可转数量],采购单号:").append(ordercode).append(",行号:")
- .append(orderdetno).append(",采购数量:").append(rs_check.getGeneralDouble("pd_qty")).append(",已转数量:")
- .append(qty).append(",本单实际数量:").append(tQty);
- BaseUtil.showError(sb.toString());
- }else{
- // 采购单
- baseDao.updateByCondition("PurchaseDetail", "pd_yqty=" + NumberUtil.add(Double.parseDouble(qty.toString()), Double.parseDouble(tQty.toString())),
- "pd_code='"+ordercode+"' and pd_detno="+orderdetno);
- baseDao.updateByCondition("PurchaseDetail", "pd_yqty=0",
- "NVL(pd_yqty,0)<=0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
- baseDao.updateByCondition("PurchaseDetail", "pd_status='AUDITED'",
- "NVL(pd_yqty,0)=0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
- baseDao.updateByCondition("PurchaseDetail", "pd_status='TURNIN'",
- "NVL(pd_yqty,0)=pd_qty AND NVL(pd_yqty,0) <> 0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
- baseDao.updateByCondition("PurchaseDetail", "pd_status='PART2IN'",
- "nvl(pd_yqty,0)<nvl(pd_qty,0) and nvl(pd_yqty,0)<>0 and pd_code='"+ordercode+"' and pd_detno="+orderdetno);
- Integer puid = baseDao.queryForObject("select nvl(pd_puid,0) from PurchaseDetail where pd_code=? and pd_detno=?", Integer.class,
- ordercode,orderdetno);
- if (puid != null && puid > 0) {
- int count = baseDao.getCountByCondition("PurchaseDetail", "pd_puid=" + puid);
- int yCount = baseDao.getCountByCondition("PurchaseDetail", "pd_puid=" + puid
- + " and nvl(pd_acceptqty,0)=pd_qty");
- int xCount = baseDao
- .getCountByCondition("PurchaseDetail", "pd_puid=" + puid + " and nvl(pd_acceptqty,0)=0");
- String status = "PART2IN",name="部分入库";
- if (yCount == count) {
- status = "TURNIN";
- name="已入库";
- }
- if (xCount == count) {
- status = "";
- name="";
- }
- baseDao.updateByCondition("Purchase",
- "pu_turnstatuscode='" + status + "',pu_turnstatus='" + name + "'",
- "pu_id=" + puid);
- }
- }
- }else if("委外验收单".equals(piclass)){
- Object qty = baseDao.getFieldDataByCondition("ProdIODetail",
- "sum(nvl(pd_inqty,0)-case when pd_status=99 then nvl(pd_outqty,0) else 0 end)", "pd_ordercode='"
- + ordercode + "' and pd_piclass in ('委外验收单','委外验退单') AND pd_piid <>" + pi_id);
- Object tQty=baseDao.getFieldDataByCondition("ProdIODetail","sum(nvl(pd_dockingactqty,0))",
- "pd_ordercode='"+ ordercode + "' and pd_piid =" + pi_id);
- qty = qty == null ? 0 : qty;
- tQty = tQty == null ? 0 : tQty;
- baseDao.updateByCondition("make", " ma_tomadeqty="+NumberUtil.add(Double.parseDouble(qty.toString()), Double.parseDouble(tQty.toString())),
- "ma_code='"+ ordercode+ "'");
- }
- }
- }
- baseDao.execute("update prodiodetail set pd_inqty=pd_dockingactqty where pd_piid="+pi_id);
- }
- }
- }
|