|
|
@@ -0,0 +1,194 @@
|
|
|
+package com.uas.eis.serviceImpl;
|
|
|
+
|
|
|
+
|
|
|
+import com.taobao.api.DefaultTaobaoClient;
|
|
|
+import com.taobao.api.TaobaoClient;
|
|
|
+import com.taobao.api.request.AlibabaAscpLogisticsOfflineSendRequest;
|
|
|
+import com.taobao.api.response.AlibabaAscpLogisticsOfflineSendResponse;
|
|
|
+import com.uas.eis.core.config.SpObserver;
|
|
|
+import com.uas.eis.core.config.TaoBaoConfig;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dao.SqlRowList;
|
|
|
+import com.uas.eis.service.SaleOutService;
|
|
|
+import com.uas.eis.utils.StringUtil;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class SaleOutServiceImpl implements SaleOutService {
|
|
|
+ public static Logger logger = Logger.getLogger(SaleOutServiceImpl.class);
|
|
|
+ @Autowired
|
|
|
+ private TaoBaoConfig taoBaoConfig;
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * alibaba.ascp.logistics.offline.send( 自己联系物流发货 )
|
|
|
+ * 用户调用该接口可实现自己联系发货,使用该接口发货,交易订单状态会直接变成卖家已发货
|
|
|
+ * https://open.taobao.com/api.htm?docId=54934&docType=2&scopeId=23401
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> orderSend(String master, Integer id) {
|
|
|
+ Map<String, Object> retMap = new HashMap<String, Object>();
|
|
|
+ retMap.put("success", true);
|
|
|
+ logger.info(String.format("orderSend-Begin:master %s id %s", master, id));
|
|
|
+ SpObserver.putSp(master);
|
|
|
+ SqlRowList piMsg = baseDao.queryForRowSet("select pi_id,pi_inoutno,pi_logisticscompany,pi_logisticscode,pi_dockingstatus,cop_code, cop_name from PRODINOUT LEFT JOIN tb_logistics ON COP_NAME = pi_logisticscompany where pi_id = " + id + " and PI_CLASS = '出货单' ");
|
|
|
+ if (!piMsg.next()) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "单据不存在");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ if ("pi_dockingstatus".equals(piMsg.getGeneralString("对接成功"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "单据已对接。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ if (!StringUtil.hasText(piMsg.getGeneralString("pi_logisticscompany"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "请选择物流公司。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ if (!StringUtil.hasText(piMsg.getGeneralString("pi_logisticscode"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "请填入物流单号。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ SqlRowList checkOrder = baseDao.queryForRowSet("select wm_concat(pd_ordercode) ordercode from (" +
|
|
|
+ " select PD_ORDERCODE from PRODIODETAIL LEFT JOIN SALE ON SA_CODE = PD_ORDERCODE left join saledetail on sd_code = pd_ordercode and sd_detno = pd_orderdetno " +
|
|
|
+ " where pd_piid = " + id + " AND SA_REMARK = '淘宝自动抓取' and SA_TBOPENUID is not null and SD_OID>0 and nvl(pd_dockingstatus,' ') <> '对接成功' and not exists (select 1 from tbauthorization where tb_openuid = SA_TBOPENUID and validflag = 1 " +
|
|
|
+ " group by PD_ORDERCODE))");
|
|
|
+ if (checkOrder.next() && StringUtil.hasText(checkOrder.getGeneralString("ordercode"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "无有效session,请重新授权淘宝店铺。订单号: " + checkOrder.getGeneralString("ordercode"));
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, String> sessionMap = new HashMap<>();
|
|
|
+ SqlRowList sessionList = baseDao.queryForRowSet("select tb_code,tb_openuid from tbauthorization where validflag = 1");
|
|
|
+ if (sessionList.hasNext()) {
|
|
|
+ while (sessionList.next()) {
|
|
|
+ sessionMap.put(sessionList.getGeneralString("tb_openuid"), sessionList.getGeneralString("tb_code"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "无有效session,请重新授权淘宝店铺");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ SqlRowList orderRowList = baseDao.queryForRowSet("SELECT p.* FROM ( " +
|
|
|
+ " SELECT pd_dockingstatus,pd_ordercode,pd_orderdetno,sd_oid,sa_tbopenuid " +
|
|
|
+ " ,sum(pd_outqty) pd_outqty " +
|
|
|
+ " FROM PRODIODETAIL LEFT JOIN SALE ON SA_CODE = PD_ORDERCODE left join saledetail on sd_code = pd_ordercode and sd_detno = pd_orderdetno " +
|
|
|
+ " WHERE pd_piid = " + id + " AND SA_REMARK = '淘宝自动抓取' and SA_TBOPENUID is not null and SD_OID>0 and nvl(pd_dockingstatus,' ') <> '对接成功' " +
|
|
|
+ " group by pd_dockingstatus,pd_ordercode,pd_orderdetno,sd_oid,sa_tbopenuid " +
|
|
|
+ " order by min(pd_pdno) " +
|
|
|
+ ") P ");
|
|
|
+ if (orderRowList.hasNext()) {
|
|
|
+ List<Map<String, Object>> orderList = orderRowList.getResultList();
|
|
|
+ for (Map<String, Object> orderMap : orderList) {
|
|
|
+ //TODO 发起对接
|
|
|
+ baseDao.execute("update PRODIODETAIL set pd_dockingstatus='对接成功' where pd_piid = " + id + " and pd_ordercode = '" + orderMap.get("pd_ordercode") + "' and pd_orderdetno = " + orderMap.get("pd_orderdetno"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseDao.execute("update PRODINOUT set pi_dockingstatus='对接失败' where pi_id = " + id + " and exists (select 1 from PRODIODETAIL where pd_piid = pi_id and nvl(pd_dockingstatus,' ')='对接失败') ");
|
|
|
+ baseDao.execute("update PRODINOUT set pi_dockingstatus='已对接' where pi_id = " + id +
|
|
|
+ " and exists (select 1 from PRODIODETAIL LEFT JOIN SALE ON sa_code = pd_ordercode left join saledetail on sd_code = pd_ordercode and sd_detno = pd_orderdetno where pd_piid = pi_id AND SA_REMARK = '淘宝自动抓取' and SA_TBOPENUID is not null and SD_OID>0 ) " +
|
|
|
+ " and not exists (select 1 from PRODIODETAIL LEFT JOIN SALE ON sa_code = pd_ordercode left join saledetail on sd_code = pd_ordercode and sd_detno = pd_orderdetno where pd_piid = pi_id AND SA_REMARK = '淘宝自动抓取' and SA_TBOPENUID is not null and SD_OID>0 and nvl(pd_dockingstatus,' ') <> '对接成功' )");
|
|
|
+ logger.info(String.format("orderSend-End:master %s id %s", master, id));
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 修改物流公司和运单号
|
|
|
+ * alibaba.ascp.logistics.consign.modify( 修改物流公司和运单号 )
|
|
|
+ * https://open.taobao.com/api.htm?docId=65697&docType=2&scopeId=23401
|
|
|
+ * */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> modifyOrderLogistics(String master, Integer id) {
|
|
|
+ Map<String, Object> retMap = new HashMap<String, Object>();
|
|
|
+ retMap.put("success", true);
|
|
|
+ logger.info(String.format("modifyOrderLogistics-Begin:master %s id %s", master, id));
|
|
|
+ SpObserver.putSp(master);
|
|
|
+ SqlRowList piMsg = baseDao.queryForRowSet("select pi_id,pi_inoutno,pi_logisticscompany,pi_logisticscode,pi_dockingstatus from PRODINOUT where pi_id = " + id + " and PI_CLASS = '出货单' ");
|
|
|
+ if (!piMsg.next()) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "单据不存在");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ if (!StringUtil.hasText(piMsg.getGeneralString("pi_logisticscompany"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "请选择物流公司。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ if (!StringUtil.hasText(piMsg.getGeneralString("pi_logisticscode"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "请填入物流单号。");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ SqlRowList checkOrder = baseDao.queryForRowSet("select wm_concat(pd_ordercode) ordercode from (" +
|
|
|
+ " select PD_ORDERCODE from PRODIODETAIL LEFT JOIN SALE ON SA_CODE = PD_ORDERCODE left join saledetail on sd_code = pd_ordercode and sd_detno = pd_orderdetno " +
|
|
|
+ " where pd_piid = " + id + " AND SA_REMARK = '淘宝自动抓取' and SA_TBOPENUID is not null and SD_OID>0 and nvl(pd_dockingstatus,' ') <> '对接成功' and not exists (select 1 from tbauthorization where tb_openuid = SA_TBOPENUID and validflag = 1 " +
|
|
|
+ " group by PD_ORDERCODE))");
|
|
|
+ if (checkOrder.next() && StringUtil.hasText(checkOrder.getGeneralString("ordercode"))) {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "无有效session,请重新授权淘宝店铺。订单号: " + checkOrder.getGeneralString("ordercode"));
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ Map<String, String> sessionMap = new HashMap<>();
|
|
|
+ SqlRowList sessionList = baseDao.queryForRowSet("select tb_code,tb_openuid from tbauthorization where validflag = 1");
|
|
|
+ if (sessionList.hasNext()) {
|
|
|
+ while (sessionList.next()) {
|
|
|
+ sessionMap.put(sessionList.getGeneralString("tb_openuid"), sessionList.getGeneralString("tb_code"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ retMap.put("success", false);
|
|
|
+ retMap.put("message", "无有效session,请重新授权淘宝店铺");
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ logger.info(String.format("modifyOrderLogistics-End:master %s id %s", master, id));
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendToTB() {
|
|
|
+ String sessionKey = "";
|
|
|
+ TaobaoClient client = new DefaultTaobaoClient(taoBaoConfig.getServerUrl(), taoBaoConfig.getAppKey(), taoBaoConfig.getAppSecret());
|
|
|
+ AlibabaAscpLogisticsOfflineSendRequest req = new AlibabaAscpLogisticsOfflineSendRequest();
|
|
|
+ req.setSenderId(123456L);
|
|
|
+ req.setFeature("identCode=tid:aaa,bbb;machineCode=tid2:aaa;retailStoreId=12345;retailStoreType=STORE;instantMobilePhoneNumber=12345678910");
|
|
|
+ req.setTid("123");
|
|
|
+ req.setSubTid("1,2,3");
|
|
|
+ List<AlibabaAscpLogisticsOfflineSendRequest.TopConsignPkgRequest> list2 = new ArrayList<AlibabaAscpLogisticsOfflineSendRequest.TopConsignPkgRequest>();
|
|
|
+ AlibabaAscpLogisticsOfflineSendRequest.TopConsignPkgRequest obj3 = new AlibabaAscpLogisticsOfflineSendRequest.TopConsignPkgRequest();
|
|
|
+ list2.add(obj3);
|
|
|
+ obj3.setOutSid("123455");
|
|
|
+ obj3.setCompanyCode("POST");
|
|
|
+ List<AlibabaAscpLogisticsOfflineSendRequest.TopConsignGoodsRequest> list6 = new ArrayList<AlibabaAscpLogisticsOfflineSendRequest.TopConsignGoodsRequest>();
|
|
|
+ AlibabaAscpLogisticsOfflineSendRequest.TopConsignGoodsRequest obj7 = new AlibabaAscpLogisticsOfflineSendRequest.TopConsignGoodsRequest();
|
|
|
+ list6.add(obj7);
|
|
|
+ obj7.setSubTid("11111");
|
|
|
+ obj7.setCompItemId("100001");
|
|
|
+ obj7.setCompSkuId("100002");
|
|
|
+ obj7.setItemType(0L);
|
|
|
+ obj7.setNum(1L);
|
|
|
+// list4.setGoods(list6);
|
|
|
+ obj3.setSubOutSid("11112");
|
|
|
+ req.setConsignPkgs(list2);
|
|
|
+ req.setCancelId(123456L);
|
|
|
+ AlibabaAscpLogisticsOfflineSendRequest.ConsignStatusRequest obj8 = new AlibabaAscpLogisticsOfflineSendRequest.ConsignStatusRequest();
|
|
|
+ obj8.setSubTid("12345678");
|
|
|
+ obj8.setIsPartConsign(true);
|
|
|
+ List<AlibabaAscpLogisticsOfflineSendRequest.ConsignStatusRequest> consignStatus = new ArrayList<>();
|
|
|
+ consignStatus.add(obj8);
|
|
|
+ req.setConsignStatus(consignStatus);
|
|
|
+ req.setConsignType(1L);
|
|
|
+ AlibabaAscpLogisticsOfflineSendResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, sessionKey);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info("淘宝返回敏感信息失败," + e.getMessage());
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
+ }
|
|
|
+}
|