|
@@ -1,9 +1,29 @@
|
|
package com.iotechn.unimall.admin.api.user;
|
|
package com.iotechn.unimall.admin.api.user;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.ApiException;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.SdkClient;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.internal.util.FileItem;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.request.order.OrderDetailsGetRequest;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.request.order.OrderGoodsSendRequest;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.request.order.OrdersContentDecryptRequest;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.requestmodel.order.EncryptDTO;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.requestmodel.order.OrderDetailsGet;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.response.order.OrderDetailsGetResponse;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.response.order.OrderGoodsSendResponse;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.response.order.OrdersContentDecryptResponse;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.responsemodel.order.CryptUserInfo;
|
|
|
|
+import com.dangdang.openplatform.openapi.sdk.responsemodel.order.OrdersContentDecryptDTO;
|
|
import com.iotechn.unimall.data.domain.shop.ShopAccount;
|
|
import com.iotechn.unimall.data.domain.shop.ShopAccount;
|
|
import com.iotechn.unimall.data.domain.shop.ShopOrder;
|
|
import com.iotechn.unimall.data.domain.shop.ShopOrder;
|
|
|
|
+import com.iotechn.unimall.data.domain.shop.ShopTran;
|
|
|
|
+import com.iotechn.unimall.data.dto.shop.XmlObject.OrderDetail;
|
|
|
|
+import com.iotechn.unimall.data.dto.shop.XmlObject.SendGood;
|
|
|
|
+import com.iotechn.unimall.data.dto.shop.XmlObject.SendGoodsInfo;
|
|
import com.iotechn.unimall.data.mapper.shop.ShopAccountMapper;
|
|
import com.iotechn.unimall.data.mapper.shop.ShopAccountMapper;
|
|
import com.iotechn.unimall.data.mapper.shop.ShopOrderMapper;
|
|
import com.iotechn.unimall.data.mapper.shop.ShopOrderMapper;
|
|
|
|
+import com.iotechn.unimall.data.mapper.shop.ShopTranMapper;
|
|
|
|
+import com.iotechn.unimall.data.util.XMLUtil;
|
|
import org.apache.commons.httpclient.HttpClient;
|
|
import org.apache.commons.httpclient.HttpClient;
|
|
import org.apache.commons.httpclient.NameValuePair;
|
|
import org.apache.commons.httpclient.NameValuePair;
|
|
import org.apache.commons.httpclient.methods.GetMethod;
|
|
import org.apache.commons.httpclient.methods.GetMethod;
|
|
@@ -67,6 +87,8 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ShopOrderMapper shopOrderMapper;
|
|
private ShopOrderMapper shopOrderMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ShopTranMapper shopTranMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -146,71 +168,201 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
@Override
|
|
@Override
|
|
public String test(String param) throws Exception {
|
|
public String test(String param) throws Exception {
|
|
|
|
|
|
- List<ShopAccount> listAccount = shopAccountMapper.selectList(new EntityWrapper<ShopAccount>().eq("delete_flag",0));
|
|
|
|
- for (ShopAccount shopAccount:listAccount
|
|
|
|
- ) {
|
|
|
|
- flushCookie(shopAccount);
|
|
|
|
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
|
- HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=1&pageShow=9999&orderStatus=ShippedToReceipt");
|
|
|
|
- //这里可以设置请求参数,token等
|
|
|
|
- get.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
|
|
- get.addHeader("cookie",shopAccount.getFuziCookie());
|
|
|
|
|
|
+// Wrapper wrapper = new EntityWrapper();
|
|
|
|
+// wrapper.ne("order_status_name","卖家已发货");
|
|
|
|
+// wrapper.eq("dang_order_status","未发货");
|
|
|
|
+// List<ShopOrder> list = shopOrderMapper.selectList(wrapper);
|
|
|
|
+// for (ShopOrder shopOrder: list
|
|
|
|
+// ) {
|
|
|
|
+// ShopAccount shopAccount = shopAccountMapper.selectById(shopOrder.getAccountId());
|
|
|
|
+// flushCookie(shopAccount);
|
|
|
|
+// CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
|
+// HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/getOrderInfo/?orderId="+shopOrder.getOrderId());
|
|
|
|
+// try{
|
|
|
|
+// //这里可以设置请求参数,token等
|
|
|
|
+// get.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36");
|
|
|
|
+// get.addHeader("cookie",shopAccount.getFuziCookie());
|
|
|
|
+// HttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
|
+// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){//根据状态码处理
|
|
|
|
+// //返回字符串
|
|
|
|
+// String res = unicodeToString(EntityUtils.toString(response.getEntity(),"UTF-8"));
|
|
|
|
+// System.out.println(res);
|
|
|
|
+// JSONObject datas = JSONObject.parseObject(res);//转换成JSON格式
|
|
|
|
+// Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
|
|
+// ShopOrder data = JSONObject.parseObject(datas.get("data").toString(),ShopOrder.class);//"data"是根据返回值设定
|
|
|
|
+// ShopOrder tmp = new ShopOrder();
|
|
|
|
+// tmp.setOrderId(data.getOrderId());
|
|
|
|
+// tmp = shopOrderMapper.selectOne(tmp);
|
|
|
|
+// data.setAccountId(shopAccount.getId());
|
|
|
|
+// if(tmp == null){
|
|
|
|
+// data.setDangOrder(shopOrder.getOrderId());
|
|
|
|
+// data.setGmtCreate(new Date());
|
|
|
|
+// data.setGmtUpdate(new Date());
|
|
|
|
+// shopOrderMapper.insert(data);
|
|
|
|
+// }
|
|
|
|
+// else{
|
|
|
|
+// data.setDangOrder(shopOrder.getOrderId());
|
|
|
|
+// data.setGmtUpdate(new Date());
|
|
|
|
+// shopOrderMapper.update(data,new EntityWrapper<ShopOrder>().eq("order_id",tmp.getOrderId()));
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// } catch (IOException e) {
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// return "";
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+ Wrapper wrapper1 = new EntityWrapper();
|
|
|
|
+ wrapper1.eq("order_status_name","卖家已发货");
|
|
|
|
+ wrapper1.eq("dang_order_status","未发货");
|
|
|
|
+ List<ShopOrder> list1 = shopOrderMapper.selectList(wrapper1);
|
|
|
|
+ for (ShopOrder shopOrder: list1
|
|
|
|
+ ) {
|
|
|
|
+ ShopAccount shopAccount = shopAccountMapper.selectById(shopOrder.getAccountId());
|
|
|
|
+ dangOrderDeal(shopAccount,shopOrder);
|
|
|
|
+ }
|
|
|
|
+ return "";
|
|
|
|
|
|
- CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
|
- try{
|
|
|
|
|
|
+ }
|
|
|
|
+ public void dangOrderDeal(ShopAccount shopAccount, ShopOrder shopOrder) throws Exception {
|
|
|
|
+ try{
|
|
|
|
+ /**
|
|
|
|
+ * 获取一下店铺的所有静态参数
|
|
|
|
+ */
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
- if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){//根据状态码处理
|
|
|
|
- String strTmp= EntityUtils.toString(response.getEntity(),"UTF-8");
|
|
|
|
- //返回字符串
|
|
|
|
- String res = unicodeToString(strTmp);
|
|
|
|
- JSONObject datas = JSONObject.parseObject(res);//转换成JSON格式
|
|
|
|
- Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
|
|
- List<ShopOrder> data = JSONArray.parseArray(datas.get("data").toString(),ShopOrder.class);//"data"是根据返回值设定
|
|
|
|
- for (ShopOrder tmp: data
|
|
|
|
- ) {
|
|
|
|
- //正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串
|
|
|
|
- String regEx="[^0-9]+";
|
|
|
|
- Pattern pattern = Pattern.compile(regEx);
|
|
|
|
- //用定义好的正则表达式拆分字符串,把字符串中的数字留出来
|
|
|
|
- String[] cs = pattern.split(tmp.getRemarkText());
|
|
|
|
- String dangOrder = "";
|
|
|
|
- for (String str:cs
|
|
|
|
- ) {
|
|
|
|
- dangOrder += str;
|
|
|
|
- }
|
|
|
|
- tmp.setDangOrder(dangOrder);
|
|
|
|
- tmp.setAccountId(shopAccount.getId());
|
|
|
|
- Long time = Long.parseLong(tmp.getShippingTime());
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
- sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
- String time1 = sdf.format(new Date(time * 1000));
|
|
|
|
- tmp.setShippingTime(time1);
|
|
|
|
- tmp.setDeleteFlag(0);
|
|
|
|
- tmp.setGmtUpdate(new Date());
|
|
|
|
- tmp.setGmtCreate(new Date());
|
|
|
|
- ShopOrder tt = new ShopOrder();
|
|
|
|
- tt.setOrderId(tmp.getOrderId());
|
|
|
|
- tt = shopOrderMapper.selectOne(tt);
|
|
|
|
- if(tt == null){
|
|
|
|
- shopOrderMapper.insert(tmp);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ SdkClient sdkClient = new SdkClient(shopAccount.getDangAppKey(),shopAccount.getDangAppSecret(),shopAccount.getDangSession(),shopAccount.getDangVersion());
|
|
|
|
|
|
|
|
+ OrderDetailsGetRequest ss = new OrderDetailsGetRequest();
|
|
|
|
+ OrderDetailsGet orderDetailsGet = new OrderDetailsGet();
|
|
|
|
+ orderDetailsGet.setO(shopOrder.getDangOrder());
|
|
|
|
+ ss.setOrderDetailsGet(orderDetailsGet);
|
|
|
|
+ OrderDetailsGetResponse resultt = null;
|
|
|
|
+ try {
|
|
|
|
+ resultt = sdkClient.excute(ss);
|
|
|
|
+ if(resultt.getOrderID() == null){
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 从当当获取订单内应当有的所有图书
|
|
|
|
+ */
|
|
|
|
+ OrderDetailsGetRequest odgr = new OrderDetailsGetRequest();
|
|
|
|
+ OrderDetailsGet ogg = new OrderDetailsGet();
|
|
|
|
+ ogg.setO(shopOrder.getDangOrder());
|
|
|
|
+ odgr.setOrderDetailsGet(ogg);
|
|
|
|
+ OrderDetailsGetResponse odgrp = null;
|
|
|
|
+ try {
|
|
|
|
+ odgrp = sdkClient.excute(odgr);
|
|
|
|
+ } catch (ApiException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
- finally {
|
|
|
|
- response.close();
|
|
|
|
- httpClient.close();
|
|
|
|
|
|
+ SdkClient jiemi = new SdkClient(shopAccount.getDangAppKey(),shopAccount.getDangAppSecret(),shopAccount.getDangSession(),shopAccount.getDangVersion());
|
|
|
|
+ OrdersContentDecryptRequest ordersContentDecryptRequest=new OrdersContentDecryptRequest();
|
|
|
|
+
|
|
|
|
+ List<EncryptDTO> encryptVOS = new ArrayList<EncryptDTO>();
|
|
|
|
+
|
|
|
|
+ EncryptDTO encryptVO1 = new EncryptDTO();
|
|
|
|
+ encryptVO1.setO(resultt.getOrderID().toString());
|
|
|
|
+ encryptVO1.setEncrypt_content(resultt.getEncrypt_content());
|
|
|
|
+ encryptVOS.add(encryptVO1);
|
|
|
|
+
|
|
|
|
+ ordersContentDecryptRequest.setO_cryptStr(JSON.toJSONString(encryptVOS));
|
|
|
|
+ OrdersContentDecryptResponse ordersContentDecryptResponse = null;
|
|
|
|
+ try {
|
|
|
|
+ ordersContentDecryptResponse=jiemi.excute(ordersContentDecryptRequest);
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ List<OrdersContentDecryptDTO> data = ordersContentDecryptResponse.getData();
|
|
|
|
+ CryptUserInfo cryptUserInfo = data.get(0).getCryptUserInfo();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ OrderDetail o = (OrderDetail) XMLUtil.convertXmlStrToObject(OrderDetail.class, odgrp.getBody());
|
|
|
|
+ SendGoodsInfo sgi = new SendGoodsInfo();
|
|
|
|
+ sgi.setConsigneeAddr(cryptUserInfo.getConsigneeAddr());
|
|
|
|
+ sgi.setConsigneeMobileTel(cryptUserInfo.getConsigneeMobileTel());
|
|
|
|
+ sgi.setConsigneeTel(cryptUserInfo.getConsigneeTel());
|
|
|
|
+ sgi.setConsigneeName(cryptUserInfo.getConsigneeName());
|
|
|
|
+ o.setSendGoodsInfo(sgi);
|
|
|
|
+ List<com.iotechn.unimall.data.dto.shop.XmlObject.ItemInfo> itemInfo = o.getItemsList().getItemInfo();
|
|
|
|
+ /**
|
|
|
|
+ * 将多个图书拼接XML
|
|
|
|
+ */
|
|
|
|
+ String itemsStr = "";
|
|
|
|
+ for (com.iotechn.unimall.data.dto.shop.XmlObject.ItemInfo ii : itemInfo) {
|
|
|
|
+ Map<String, Object> hashMap = new HashMap<>();
|
|
|
|
+ hashMap.put("DANG_DANG_ITEM_ID", ii.getItemID());
|
|
|
|
+ hashMap.put("SHU_LIANG", ii.getOrderCount());
|
|
|
|
+ hashMap.put("PRODUCT_ID", ii.getProductItemId());
|
|
|
|
+ itemsStr += SendGood.processTemplate(SendGood.ONE_ITEM, hashMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 组成OrderInfo
|
|
|
|
+ */
|
|
|
|
+ Wrapper wrapper = new EntityWrapper();
|
|
|
|
+ wrapper.like("fuzi_name",shopOrder.getShippingComName());
|
|
|
|
+ List<ShopTran> list = shopTranMapper.selectList(wrapper);
|
|
|
|
+ if(list.size() == 0 ){
|
|
|
|
+ throw new Exception("物流公司不存在");
|
|
|
|
+ }
|
|
|
|
+ HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
|
|
+ stringObjectHashMap.put("DANG_DANG_ORDER", shopOrder.getDangOrder());
|
|
|
|
+ stringObjectHashMap.put("KUAI_DI_GONG_SI", list.get(0).getName());
|
|
|
|
+ stringObjectHashMap.put("KUAI_DI_BIANMA", list.get(0).getCode1());
|
|
|
|
+ stringObjectHashMap.put("KUAI_DI_GONG_SI_DIAN_HUA", list.get(0).getPhone());
|
|
|
|
+ stringObjectHashMap.put("KUAI_DI_DAN_HAO", shopOrder.getShipmentNum());
|
|
|
|
+ stringObjectHashMap.put("SEND_ITEMS", itemsStr);
|
|
|
|
+
|
|
|
|
+ String orderListStr = SendGood.processTemplate(SendGood.ONE_ORDER, stringObjectHashMap);
|
|
|
|
+ HashMap<String, Object> tmplHash = new HashMap<>();
|
|
|
|
+ tmplHash.put("SEND_TIME", dateFormat.format(new Date()));
|
|
|
|
+ tmplHash.put("ORDER_LIST", orderListStr);
|
|
|
|
+
|
|
|
|
+ String xmlFileStr = SendGood.processTemplate(SendGood.TMPL, tmplHash);
|
|
|
|
+ System.out.println(xmlFileStr);
|
|
|
|
+ PrintWriter out = null;
|
|
|
|
+ try {
|
|
|
|
+ out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("sendGoodNotPlat.xml"), "GBK")));
|
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ out.write(xmlFileStr);
|
|
|
|
+ out.close();
|
|
|
|
+ System.out.println("XML文件创建成功!");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发货!!
|
|
|
|
+ */
|
|
|
|
+ OrderGoodsSendRequest sendGoodsRequest = new OrderGoodsSendRequest();
|
|
|
|
+ sendGoodsRequest.setSendGoodsFile(new FileItem(new File("sendGoodNotPlat.xml")));
|
|
|
|
+ OrderGoodsSendResponse result = null;
|
|
|
|
+ try {
|
|
|
|
+ result = sdkClient.excute(sendGoodsRequest);
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ System.out.println(result.toString());
|
|
|
|
+ if(result.getResult().getOrdersList().get(0).getOrderOperCode() == 0 || result.getResult().getOrdersList().get(0).getOrderOperCode() == 605){
|
|
|
|
+ shopOrder.setDangOrderStatus("已发货");
|
|
|
|
+ shopOrderMapper.update(shopOrder,new EntityWrapper<ShopOrder>().eq("order_id",shopOrder.getOrderId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
|
|
- return "";
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
public void flushCookie(ShopAccount shopAccount){
|
|
public void flushCookie(ShopAccount shopAccount){
|
|
try{
|
|
try{
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|