|
@@ -1,4 +1,5 @@
|
|
package com.iotechn.unimall.admin.api.user;
|
|
package com.iotechn.unimall.admin.api.user;
|
|
|
|
+
|
|
import com.alibaba.fastjson.JSON;
|
|
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.ApiException;
|
|
@@ -14,6 +15,7 @@ import com.dangdang.openplatform.openapi.sdk.response.order.OrderGoodsSendRespon
|
|
import com.dangdang.openplatform.openapi.sdk.response.order.OrdersContentDecryptResponse;
|
|
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.CryptUserInfo;
|
|
import com.dangdang.openplatform.openapi.sdk.responsemodel.order.OrdersContentDecryptDTO;
|
|
import com.dangdang.openplatform.openapi.sdk.responsemodel.order.OrdersContentDecryptDTO;
|
|
|
|
+import com.iotechn.unimall.admin.AdminCheckQuartz;
|
|
import com.iotechn.unimall.data.domain.shop.ShopAccount;
|
|
import com.iotechn.unimall.data.domain.shop.ShopAccount;
|
|
import com.iotechn.unimall.data.domain.shop.ShopLog;
|
|
import com.iotechn.unimall.data.domain.shop.ShopLog;
|
|
import com.iotechn.unimall.data.domain.shop.ShopOrder;
|
|
import com.iotechn.unimall.data.domain.shop.ShopOrder;
|
|
@@ -68,6 +70,8 @@ import java.net.URL;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@@ -97,18 +101,18 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Boolean addUser(Long adminId, UserDO user) throws ServiceException {
|
|
public Boolean addUser(Long adminId, UserDO user) throws ServiceException {
|
|
- if (user == null){
|
|
|
|
|
|
+ if (user == null) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
}
|
|
}
|
|
- if(user.getPhone() == null){
|
|
|
|
|
|
+ if (user.getPhone() == null) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
}
|
|
}
|
|
- if(userMapper.selectCount(new EntityWrapper<UserDO>().eq("phone",user.getPhone())) > 0){
|
|
|
|
|
|
+ if (userMapper.selectCount(new EntityWrapper<UserDO>().eq("phone", user.getPhone())) > 0) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_PHONE_ALREADY_EXIST);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_PHONE_ALREADY_EXIST);
|
|
}
|
|
}
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
user.setId(null);
|
|
user.setId(null);
|
|
- user.setPassword(Md5Crypt.md5Crypt(user.getPassword().getBytes(), "$1$" + user.getPhone().substring(0,7)));
|
|
|
|
|
|
+ user.setPassword(Md5Crypt.md5Crypt(user.getPassword().getBytes(), "$1$" + user.getPhone().substring(0, 7)));
|
|
user.setGmtCreate(now);
|
|
user.setGmtCreate(now);
|
|
user.setGmtUpdate(now);
|
|
user.setGmtUpdate(now);
|
|
return userMapper.insert(user) > 0;
|
|
return userMapper.insert(user) > 0;
|
|
@@ -119,88 +123,93 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
public Boolean deleteUser(Long adminId, Long id, String nickname) throws ServiceException {
|
|
public Boolean deleteUser(Long adminId, Long id, String nickname) throws ServiceException {
|
|
return userMapper.delete(new EntityWrapper<UserDO>()
|
|
return userMapper.delete(new EntityWrapper<UserDO>()
|
|
.eq("id", id)
|
|
.eq("id", id)
|
|
- .eq("nickname",nickname)) > 0;
|
|
|
|
|
|
+ .eq("nickname", nickname)) > 0;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Boolean updateUser(Long adminId, UserDO user) throws ServiceException {
|
|
public Boolean updateUser(Long adminId, UserDO user) throws ServiceException {
|
|
- if (user == null || user.getId() == null){
|
|
|
|
|
|
+ if (user == null || user.getId() == null) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
}
|
|
}
|
|
- if(user.getPhone() == null){
|
|
|
|
|
|
+ if (user.getPhone() == null) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
}
|
|
}
|
|
- if(userMapper.selectCount(new EntityWrapper<UserDO>().eq("phone",user.getPhone()).notIn("id",user.getId())) > 0){
|
|
|
|
|
|
+ if (userMapper.selectCount(new EntityWrapper<UserDO>().eq("phone", user.getPhone()).notIn("id", user.getId())) > 0) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_PHONE_ALREADY_EXIST);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_PHONE_ALREADY_EXIST);
|
|
}
|
|
}
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
user.setGmtUpdate(now);
|
|
user.setGmtUpdate(now);
|
|
- UserDO userDO = userMapper.selectById(user.getId());
|
|
|
|
- if(userDO.getPassword().equals(user.getPassword())){
|
|
|
|
|
|
+ UserDO userDO = userMapper.selectById(user.getId());
|
|
|
|
+ if (userDO.getPassword().equals(user.getPassword())) {
|
|
return userMapper.updateById(user) > 0;
|
|
return userMapper.updateById(user) > 0;
|
|
}
|
|
}
|
|
- if(user.getPassword() != null) {
|
|
|
|
|
|
+ if (user.getPassword() != null) {
|
|
user.setPassword(Md5Crypt.md5Crypt(user.getPassword().getBytes(), "$1$" + user.getPhone().substring(0, 7)));
|
|
user.setPassword(Md5Crypt.md5Crypt(user.getPassword().getBytes(), "$1$" + user.getPhone().substring(0, 7)));
|
|
}
|
|
}
|
|
return userMapper.updateById(user) > 0;
|
|
return userMapper.updateById(user) > 0;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Boolean updateStatus(Long adminId, Long userId,Integer status) throws ServiceException {
|
|
|
|
- if(userId == null || status == null || (status != 0 && status != 1)){
|
|
|
|
|
|
+ public Boolean updateStatus(Long adminId, Long userId, Integer status) throws ServiceException {
|
|
|
|
+ if (userId == null || status == null || (status != 0 && status != 1)) {
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
throw new AdminServiceException(ExceptionDefinition.USER_INFORMATION_MISSING);
|
|
}
|
|
}
|
|
UserDO userDO = new UserDO();
|
|
UserDO userDO = new UserDO();
|
|
userDO.setId(userId);
|
|
userDO.setId(userId);
|
|
userDO.setStatus(status);
|
|
userDO.setStatus(status);
|
|
userDO.setGmtUpdate(new Date());
|
|
userDO.setGmtUpdate(new Date());
|
|
- if(userMapper.updateById(userDO) > 0){
|
|
|
|
|
|
+ if (userMapper.updateById(userDO) > 0) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Page<UserDO> getUser(Long adminId, Long id, String nickname, Integer level, Integer gender, Integer status,Integer pageNo,Integer limit) throws ServiceException {
|
|
|
|
- Integer count = userMapper. countUser(id,nickname,level,gender,status);
|
|
|
|
- List<UserDO> userDOList = userMapper.getUserList(id,nickname,level,gender,status,limit*(pageNo-1),limit);
|
|
|
|
- Page<UserDO> page = new Page<UserDO>(userDOList,pageNo,limit,count);
|
|
|
|
|
|
+ public Page<UserDO> getUser(Long adminId, Long id, String nickname, Integer level, Integer gender, Integer status, Integer pageNo, Integer limit) throws ServiceException {
|
|
|
|
+ Integer count = userMapper.countUser(id, nickname, level, gender, status);
|
|
|
|
+ List<UserDO> userDOList = userMapper.getUserList(id, nickname, level, gender, status, limit * (pageNo - 1), limit);
|
|
|
|
+ Page<UserDO> page = new Page<UserDO>(userDOList, pageNo, limit, count);
|
|
return page;
|
|
return page;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String test(String param,String param1) throws Exception {
|
|
|
|
- try{
|
|
|
|
- List<ShopOrder> shopOrders = shopOrderMapper.selectList(new EntityWrapper<ShopOrder>()
|
|
|
|
- .eq("dang_order_status","未发货")
|
|
|
|
- .eq("account_id",param)
|
|
|
|
- .eq("order_status_name","卖家已发货"));
|
|
|
|
- for (ShopOrder qqq:shopOrders
|
|
|
|
- ) {
|
|
|
|
- ShopAccount shopAccount = shopAccountMapper.selectById(qqq.getAccountId());
|
|
|
|
- dangOrderDeal(shopAccount,qqq);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- catch (Exception e) {
|
|
|
|
- ShopLog shopLog = new ShopLog();
|
|
|
|
- shopLog.setGmtCreate(new Date());
|
|
|
|
- shopLog.setTitle("同步定时任务异常");
|
|
|
|
- shopLog.setContent(e.getMessage());
|
|
|
|
- shopLogMapper.insert(shopLog);
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
|
|
+ public String test(String param, String param1) throws Exception {
|
|
|
|
+ ExecutorService pool = Executors.newFixedThreadPool(2);
|
|
|
|
+ ThreadPool threadPool = new ThreadPool(1);
|
|
|
|
+ pool.execute(threadPool);
|
|
|
|
+ pool.shutdown();
|
|
|
|
+// try{
|
|
|
|
+// List<ShopOrder> shopOrders = shopOrderMapper.selectList(new EntityWrapper<ShopOrder>()
|
|
|
|
+// .eq("dang_order_status","未发货")
|
|
|
|
+//// .eq("account_id",param)
|
|
|
|
+// .eq("order_status_name","卖家已发货"));
|
|
|
|
+// for (ShopOrder qqq:shopOrders
|
|
|
|
+// ) {
|
|
|
|
+// ShopAccount shopAccount = shopAccountMapper.selectById(qqq.getAccountId());
|
|
|
|
+// dangOrderDeal(shopAccount,qqq);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// catch (Exception e) {
|
|
|
|
+// ShopLog shopLog = new ShopLog();
|
|
|
|
+// shopLog.setGmtCreate(new Date());
|
|
|
|
+// shopLog.setTitle("同步定时任务异常");
|
|
|
|
+// shopLog.setContent(e.getMessage());
|
|
|
|
+// shopLogMapper.insert(shopLog);
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// }
|
|
return "";
|
|
return "";
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
public void dangOrderDeal(ShopAccount shopAccount, ShopOrder shopOrder) throws Exception {
|
|
public void dangOrderDeal(ShopAccount shopAccount, ShopOrder shopOrder) throws Exception {
|
|
- try{
|
|
|
|
|
|
+ try {
|
|
/**
|
|
/**
|
|
* 获取一下店铺的所有静态参数
|
|
* 获取一下店铺的所有静态参数
|
|
*/
|
|
*/
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
- SdkClient sdkClient = new SdkClient(shopAccount.getDangAppKey(),shopAccount.getDangAppSecret(),shopAccount.getDangSession(),shopAccount.getDangVersion());
|
|
|
|
|
|
+ SdkClient sdkClient = new SdkClient(shopAccount.getDangAppKey(), shopAccount.getDangAppSecret(), shopAccount.getDangSession(), shopAccount.getDangVersion());
|
|
|
|
|
|
OrderDetailsGetRequest ss = new OrderDetailsGetRequest();
|
|
OrderDetailsGetRequest ss = new OrderDetailsGetRequest();
|
|
OrderDetailsGet orderDetailsGet = new OrderDetailsGet();
|
|
OrderDetailsGet orderDetailsGet = new OrderDetailsGet();
|
|
@@ -209,11 +218,11 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
OrderDetailsGetResponse resultt = null;
|
|
OrderDetailsGetResponse resultt = null;
|
|
try {
|
|
try {
|
|
resultt = sdkClient.excute(ss);
|
|
resultt = sdkClient.excute(ss);
|
|
- if(resultt.getOrderID() == null){
|
|
|
|
|
|
+ if (resultt.getOrderID() == null) {
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setTitle("当当订单编号错误");
|
|
shopLog.setTitle("当当订单编号错误");
|
|
- shopLog.setContent("店铺:"+shopAccount.getDangName()+",孔网订单:"+shopOrder.getOrderId()+",当当订单:"+shopOrder.getDangOrder());
|
|
|
|
|
|
+ shopLog.setContent("店铺:" + shopAccount.getDangName() + ",孔网订单:" + shopOrder.getOrderId() + ",当当订单:" + shopOrder.getDangOrder());
|
|
shopLogMapper.insert(shopLog);
|
|
shopLogMapper.insert(shopLog);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -234,8 +243,8 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
} catch (ApiException e) {
|
|
} catch (ApiException e) {
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
- SdkClient jiemi = new SdkClient(shopAccount.getDangAppKey(),shopAccount.getDangAppSecret(),shopAccount.getDangSession(),shopAccount.getDangVersion());
|
|
|
|
- OrdersContentDecryptRequest ordersContentDecryptRequest=new OrdersContentDecryptRequest();
|
|
|
|
|
|
+ SdkClient jiemi = new SdkClient(shopAccount.getDangAppKey(), shopAccount.getDangAppSecret(), shopAccount.getDangSession(), shopAccount.getDangVersion());
|
|
|
|
+ OrdersContentDecryptRequest ordersContentDecryptRequest = new OrdersContentDecryptRequest();
|
|
|
|
|
|
List<EncryptDTO> encryptVOS = new ArrayList<EncryptDTO>();
|
|
List<EncryptDTO> encryptVOS = new ArrayList<EncryptDTO>();
|
|
|
|
|
|
@@ -247,7 +256,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
ordersContentDecryptRequest.setO_cryptStr(JSON.toJSONString(encryptVOS));
|
|
ordersContentDecryptRequest.setO_cryptStr(JSON.toJSONString(encryptVOS));
|
|
OrdersContentDecryptResponse ordersContentDecryptResponse = null;
|
|
OrdersContentDecryptResponse ordersContentDecryptResponse = null;
|
|
try {
|
|
try {
|
|
- ordersContentDecryptResponse=jiemi.excute(ordersContentDecryptRequest);
|
|
|
|
|
|
+ ordersContentDecryptResponse = jiemi.excute(ordersContentDecryptRequest);
|
|
} catch (ApiException e) {
|
|
} catch (ApiException e) {
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
@@ -255,7 +264,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
CryptUserInfo cryptUserInfo = data.get(0).getCryptUserInfo();
|
|
CryptUserInfo cryptUserInfo = data.get(0).getCryptUserInfo();
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
OrderDetail o = (OrderDetail) XMLUtil.convertXmlStrToObject(OrderDetail.class, odgrp.getBody());
|
|
OrderDetail o = (OrderDetail) XMLUtil.convertXmlStrToObject(OrderDetail.class, odgrp.getBody());
|
|
SendGoodsInfo sgi = new SendGoodsInfo();
|
|
SendGoodsInfo sgi = new SendGoodsInfo();
|
|
sgi.setConsigneeAddr(cryptUserInfo.getConsigneeAddr());
|
|
sgi.setConsigneeAddr(cryptUserInfo.getConsigneeAddr());
|
|
@@ -281,19 +289,18 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
* 组成OrderInfo
|
|
* 组成OrderInfo
|
|
*/
|
|
*/
|
|
Wrapper wrapper = new EntityWrapper();
|
|
Wrapper wrapper = new EntityWrapper();
|
|
- wrapper.like("fuzi_name",shopOrder.getShippingComName());
|
|
|
|
- wrapper.eq("delete_flag",0);
|
|
|
|
|
|
+ wrapper.like("fuzi_name", shopOrder.getShippingComName());
|
|
|
|
+ wrapper.eq("delete_flag", 0);
|
|
List<ShopTran> list = shopTranMapper.selectList(wrapper);
|
|
List<ShopTran> list = shopTranMapper.selectList(wrapper);
|
|
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
|
|
stringObjectHashMap.put("DANG_DANG_ORDER", shopOrder.getDangOrder());
|
|
stringObjectHashMap.put("DANG_DANG_ORDER", shopOrder.getDangOrder());
|
|
- if(list.size() == 0 ){
|
|
|
|
|
|
+ if (list.size() == 0) {
|
|
// throw new Exception("物流公司不存在");
|
|
// throw new Exception("物流公司不存在");
|
|
System.out.println("物流公司不存在");
|
|
System.out.println("物流公司不存在");
|
|
stringObjectHashMap.put("KUAI_DI_GONG_SI", "99999");
|
|
stringObjectHashMap.put("KUAI_DI_GONG_SI", "99999");
|
|
stringObjectHashMap.put("KUAI_DI_BIANMA", "99999");
|
|
stringObjectHashMap.put("KUAI_DI_BIANMA", "99999");
|
|
stringObjectHashMap.put("KUAI_DI_GONG_SI_DIAN_HUA", "99999");
|
|
stringObjectHashMap.put("KUAI_DI_GONG_SI_DIAN_HUA", "99999");
|
|
- }
|
|
|
|
- else{
|
|
|
|
|
|
+ } else {
|
|
stringObjectHashMap.put("KUAI_DI_GONG_SI", list.get(0).getName());
|
|
stringObjectHashMap.put("KUAI_DI_GONG_SI", list.get(0).getName());
|
|
stringObjectHashMap.put("KUAI_DI_BIANMA", list.get(0).getCode1());
|
|
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_GONG_SI_DIAN_HUA", list.get(0).getPhone());
|
|
@@ -311,7 +318,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
PrintWriter out = null;
|
|
PrintWriter out = null;
|
|
try {
|
|
try {
|
|
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("sendGoodNotPlat.xml"), "GBK")));
|
|
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("sendGoodNotPlat.xml"), "GBK")));
|
|
- }catch (Exception e) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
out.write(xmlFileStr);
|
|
out.write(xmlFileStr);
|
|
@@ -331,24 +338,22 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
throw e;
|
|
throw e;
|
|
}
|
|
}
|
|
System.out.println(result.toString());
|
|
System.out.println(result.toString());
|
|
- if(result.getResult().getOrdersList().get(0).getOrderOperCode() == 0 || result.getResult().getOrdersList().get(0).getOrderOperCode() == 605){
|
|
|
|
|
|
+ if (result.getResult().getOrdersList().get(0).getOrderOperCode() == 0 || result.getResult().getOrdersList().get(0).getOrderOperCode() == 605) {
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setTitle("当当订单发货成功");
|
|
shopLog.setTitle("当当订单发货成功");
|
|
- shopLog.setContent("店铺:"+shopAccount.getDangName()+",孔网订单:"+shopOrder.getOrderId()+",当当订单:"+shopOrder.getDangOrder());
|
|
|
|
|
|
+ shopLog.setContent("店铺:" + shopAccount.getDangName() + ",孔网订单:" + shopOrder.getOrderId() + ",当当订单:" + shopOrder.getDangOrder());
|
|
shopLogMapper.insert(shopLog);
|
|
shopLogMapper.insert(shopLog);
|
|
shopOrder.setDangOrderStatus("已发货");
|
|
shopOrder.setDangOrderStatus("已发货");
|
|
- shopOrderMapper.update(shopOrder,new EntityWrapper<ShopOrder>().eq("order_id",shopOrder.getOrderId()));
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
|
|
+ shopOrderMapper.update(shopOrder, new EntityWrapper<ShopOrder>().eq("order_id", shopOrder.getOrderId()));
|
|
|
|
+ } else {
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setTitle("当当订单发货失败");
|
|
shopLog.setTitle("当当订单发货失败");
|
|
- shopLog.setContent("店铺:"+shopAccount.getDangName()+",孔网订单:"+shopOrder.getOrderId()+",当当订单:"+shopOrder.getDangOrder()+",快递:"+shopOrder.getShippingComName());
|
|
|
|
|
|
+ shopLog.setContent("店铺:" + shopAccount.getDangName() + ",孔网订单:" + shopOrder.getOrderId() + ",当当订单:" + shopOrder.getDangOrder() + ",快递:" + shopOrder.getShippingComName());
|
|
shopLogMapper.insert(shopLog);
|
|
shopLogMapper.insert(shopLog);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
@@ -358,39 +363,38 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- public void flushCookie(ShopAccount shopAccount){
|
|
|
|
- try{
|
|
|
|
|
|
+
|
|
|
|
+ public void flushCookie(ShopAccount shopAccount) {
|
|
|
|
+ try {
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
HttpGet getMethod = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=1&pageShow=30");
|
|
HttpGet getMethod = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=1&pageShow=30");
|
|
getMethod.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");
|
|
getMethod.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");
|
|
- getMethod.addHeader("cookie",shopAccount.getFuziCookie());
|
|
|
|
|
|
+ getMethod.addHeader("cookie", shopAccount.getFuziCookie());
|
|
|
|
|
|
httpClient.execute(getMethod);
|
|
httpClient.execute(getMethod);
|
|
CloseableHttpResponse response = httpClient.execute(getMethod);//执行获取响应
|
|
CloseableHttpResponse response = httpClient.execute(getMethod);//执行获取响应
|
|
- try{
|
|
|
|
|
|
+ try {
|
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {//根据状态码处理
|
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {//根据状态码处理
|
|
- String strTmp= EntityUtils.toString(response.getEntity(),"UTF-8");
|
|
|
|
|
|
+ String strTmp = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
JSONObject datas = JSONObject.parseObject(strTmp);//转换成JSON格式
|
|
JSONObject datas = JSONObject.parseObject(strTmp);//转换成JSON格式
|
|
Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
Boolean status = (Boolean) datas.get("status");//获取返回数据状态,get获取的字段需要根据提供的返回值去获取
|
|
- if(status){
|
|
|
|
|
|
+ if (status) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
throw e;
|
|
throw e;
|
|
- }
|
|
|
|
- finally {
|
|
|
|
|
|
+ } finally {
|
|
response.close();
|
|
response.close();
|
|
httpClient.close();
|
|
httpClient.close();
|
|
}
|
|
}
|
|
|
|
|
|
- System.out.println("原cookies = "+shopAccount.getFuziCookie());
|
|
|
|
|
|
+ System.out.println("原cookies = " + shopAccount.getFuziCookie());
|
|
|
|
|
|
// 登陆 Url
|
|
// 登陆 Url
|
|
String loginUrl = "https://login.kongfz.com/Pc/Login/account";
|
|
String loginUrl = "https://login.kongfz.com/Pc/Login/account";
|
|
- BasicCookieStore store= new BasicCookieStore();
|
|
|
|
- httpClient =HttpClients.custom().setDefaultCookieStore(store).build();
|
|
|
|
|
|
+ BasicCookieStore store = new BasicCookieStore();
|
|
|
|
+ httpClient = HttpClients.custom().setDefaultCookieStore(store).build();
|
|
// 模拟登陆,按实际服务器端要求选用 Post 或 Get 请求方式
|
|
// 模拟登陆,按实际服务器端要求选用 Post 或 Get 请求方式
|
|
HttpPost httpPost = new HttpPost(loginUrl);
|
|
HttpPost httpPost = new HttpPost(loginUrl);
|
|
|
|
|
|
@@ -407,13 +411,13 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
|
|
|
|
// 执行请求操作,并拿到结果(同步阻塞)
|
|
// 执行请求操作,并拿到结果(同步阻塞)
|
|
response = httpClient.execute(httpPost);
|
|
response = httpClient.execute(httpPost);
|
|
- if(response.getStatusLine().getStatusCode() == 302){
|
|
|
|
|
|
+ if (response.getStatusLine().getStatusCode() == 302) {
|
|
List<org.apache.http.cookie.Cookie> cookielist = store.getCookies();
|
|
List<org.apache.http.cookie.Cookie> cookielist = store.getCookies();
|
|
String nCookie = "";
|
|
String nCookie = "";
|
|
- for(org.apache.http.cookie.Cookie cookie: cookielist){
|
|
|
|
- String name=cookie.getName();
|
|
|
|
- String value=cookie.getValue();
|
|
|
|
- nCookie += name + "="+value+";";
|
|
|
|
|
|
+ for (org.apache.http.cookie.Cookie cookie : cookielist) {
|
|
|
|
+ String name = cookie.getName();
|
|
|
|
+ String value = cookie.getValue();
|
|
|
|
+ nCookie += name + "=" + value + ";";
|
|
}
|
|
}
|
|
System.out.println("nCookie:" + nCookie);
|
|
System.out.println("nCookie:" + nCookie);
|
|
shopAccount.setFuziCookie(nCookie);
|
|
shopAccount.setFuziCookie(nCookie);
|
|
@@ -421,10 +425,9 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setTitle("更新cookie成功");
|
|
shopLog.setTitle("更新cookie成功");
|
|
- shopLog.setContent("账号:"+shopAccount.getFuziAccount()+",cookie:"+nCookie);
|
|
|
|
|
|
+ shopLog.setContent("账号:" + shopAccount.getFuziAccount() + ",cookie:" + nCookie);
|
|
shopLogMapper.insert(shopLog);
|
|
shopLogMapper.insert(shopLog);
|
|
- }
|
|
|
|
- else{
|
|
|
|
|
|
+ } else {
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setTitle("更新cookie失败");
|
|
shopLog.setTitle("更新cookie失败");
|
|
@@ -434,7 +437,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
// 释放链接
|
|
// 释放链接
|
|
response.close();
|
|
response.close();
|
|
|
|
|
|
- }catch (Exception e) {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
ShopLog shopLog = new ShopLog();
|
|
ShopLog shopLog = new ShopLog();
|
|
shopLog.setGmtCreate(new Date());
|
|
shopLog.setGmtCreate(new Date());
|
|
@@ -449,8 +452,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
/**
|
|
/**
|
|
* Unicode转 汉字字符串
|
|
* Unicode转 汉字字符串
|
|
*
|
|
*
|
|
- * @param str
|
|
|
|
- * \u6728
|
|
|
|
|
|
+ * @param str \u6728
|
|
* @return '木' 26408
|
|
* @return '木' 26408
|
|
*/
|
|
*/
|
|
public static String unicodeToString(String str) {
|
|
public static String unicodeToString(String str) {
|
|
@@ -469,6 +471,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
}
|
|
}
|
|
return str;
|
|
return str;
|
|
}
|
|
}
|
|
|
|
+
|
|
public static Response postData(String url, Headers headers, RequestBody body) {
|
|
public static Response postData(String url, Headers headers, RequestBody body) {
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
OkHttpClient client = new OkHttpClient().newBuilder()
|
|
.build();
|
|
.build();
|
|
@@ -486,4 +489,226 @@ public class AdminUserServiceImpl implements AdminUserService {
|
|
}
|
|
}
|
|
return response;
|
|
return response;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ class ThreadPool implements Runnable {
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 创建步骤如下:
|
|
|
|
+ * 1,定义Runnable接口的实现类,或者定义(继承Runnable接口的类)的实现类,并且实现run方法,这个方法是线程执行体
|
|
|
|
+ * 2,创建一个自定义线程个数的线程池
|
|
|
|
+ * 3,实例化Runnable接口的实现类
|
|
|
|
+ * 4,将3步的实例,作为线程池实例的execute方法的command参数,开启线程
|
|
|
|
+ * 5,关闭线程池
|
|
|
|
+ *
|
|
|
|
+ * 调用示例:
|
|
|
|
+ * ExecutorService pool = Executors.newFixedThreadPool(2);
|
|
|
|
+ * ThreadPool threadPool = new ThreadPool("AA");
|
|
|
|
+ * ThreadPool threadPoo2 = new ThreadPool("BB");
|
|
|
|
+ * pool.execute(threadPool);
|
|
|
|
+ * pool.execute(threadPoo2);
|
|
|
|
+ * pool.shutdown();
|
|
|
|
+ *
|
|
|
|
+ * 说明:
|
|
|
|
+ * 示例中创建的是2个线程的线程池
|
|
|
|
+ * execute方法是开启线程方法,实参要求是实现Runnable的类。所以,继承Thread类的子类也可以以线程池的方式开启线程
|
|
|
|
+ *
|
|
|
|
+ * */
|
|
|
|
+ public Integer flag;
|
|
|
|
+ public ThreadPool(Integer flag) {
|
|
|
|
+ this.flag = flag;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void run() {
|
|
|
|
+ if(flag == 1){
|
|
|
|
+ doSomething1();
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ doSomething2();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 需要处理的任务
|
|
|
|
+ * */
|
|
|
|
+ private void doSomething1() {
|
|
|
|
+ try{
|
|
|
|
+ List<ShopAccount> list = shopAccountMapper.selectList(new EntityWrapper<>());
|
|
|
|
+ for (ShopAccount shopAccount:list
|
|
|
|
+ ) {
|
|
|
|
+ flushCookie(shopAccount);
|
|
|
|
+ List<ShopOrder> shopOrders = shopOrderMapper.selectList(new EntityWrapper<ShopOrder>()
|
|
|
|
+ .eq("dang_order_status","未发货")
|
|
|
|
+ .eq("account_id",shopAccount.getId())
|
|
|
|
+ .eq("order_status_name","卖家已发货"));
|
|
|
|
+ for (ShopOrder qqq:shopOrders
|
|
|
|
+ ) {
|
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
|
+ HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=1&pageShow=9999&orderId="+qqq.getOrderId());
|
|
|
|
+ //这里可以设置请求参数,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());
|
|
|
|
+ get.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
|
|
|
+ CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
|
+ try{
|
|
|
|
+
|
|
|
|
+ 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
|
|
|
|
+ ) {
|
|
|
|
+ if(dangOrder.length()>= 11 || str.equals("*")){
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ 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());
|
|
|
|
+ if(tmp.getShippingComName().equals("快递包裹")||tmp.getShippingComName().equals("挂号印刷品")){
|
|
|
|
+ tmp.setShippingComName("中国邮政");
|
|
|
|
+ }
|
|
|
|
+ ShopOrder tt = new ShopOrder();
|
|
|
|
+ tt.setOrderId(tmp.getOrderId());
|
|
|
|
+ tt = shopOrderMapper.selectOne(tt);
|
|
|
|
+ if(tt == null){
|
|
|
|
+ shopOrderMapper.insert(tmp);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(!tt.getDangOrder().equals(tmp.getDangOrder())||!tt.getShippingComName().equals(tmp.getShippingComName())){
|
|
|
|
+ shopOrderMapper.update(tmp,new EntityWrapper<ShopOrder>().eq("order_id",tt.getOrderId()));
|
|
|
|
+ }
|
|
|
|
+ dangOrderDeal(shopAccount,qqq);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw e;
|
|
|
|
+ }
|
|
|
|
+ finally {
|
|
|
|
+ response.close();
|
|
|
|
+ httpClient.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e) {
|
|
|
|
+ ShopLog shopLog = new ShopLog();
|
|
|
|
+ shopLog.setGmtCreate(new Date());
|
|
|
|
+ shopLog.setTitle("同步定时任务异常");
|
|
|
|
+ shopLog.setContent(e.getMessage());
|
|
|
|
+ shopLogMapper.insert(shopLog);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ private void doSomething2() {
|
|
|
|
+ try{
|
|
|
|
+ List<ShopAccount> list = shopAccountMapper.selectList(new EntityWrapper<>());
|
|
|
|
+ for (ShopAccount shopAccount:list
|
|
|
|
+ ) {
|
|
|
|
+ flushCookie(shopAccount);
|
|
|
|
+ for (int i = 1; i <= 5; i++) {
|
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
|
+ HttpGet get = new HttpGet("https://shop.kongfz.com/buyer/order/index/?pageCurr=" + i + "&pageShow=300&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());
|
|
|
|
+
|
|
|
|
+ CloseableHttpResponse response = httpClient.execute(get);//执行获取响应
|
|
|
|
+ try {
|
|
|
|
+ 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"是根据返回值设定
|
|
|
|
+ if (data.size() == 0) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ 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
|
|
|
|
+ ) {
|
|
|
|
+ if (dangOrder.length() >= 11 || str.equals("*")) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ 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());
|
|
|
|
+ if (tmp.getShippingComName().equals("快递包裹") || tmp.getShippingComName().equals("挂号印刷品")) {
|
|
|
|
+ tmp.setShippingComName("中国邮政");
|
|
|
|
+ }
|
|
|
|
+ ShopOrder tt = new ShopOrder();
|
|
|
|
+ tt.setOrderId(tmp.getOrderId());
|
|
|
|
+ tt = shopOrderMapper.selectOne(tt);
|
|
|
|
+ if (tt == null) {
|
|
|
|
+ shopOrderMapper.insert(tmp);
|
|
|
|
+ } else {
|
|
|
|
+ if (tt.getDangOrderStatus().equals("未发货") && !tt.getDangOrder().equals(tmp.getDangOrder())) {
|
|
|
|
+ shopOrderMapper.update(tmp, new EntityWrapper<ShopOrder>().eq("order_id", tt.getOrderId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw e;
|
|
|
|
+ } finally {
|
|
|
|
+ response.close();
|
|
|
|
+ httpClient.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e){
|
|
|
|
+ ShopLog shopLog = new ShopLog();
|
|
|
|
+ shopLog.setGmtCreate(new Date());
|
|
|
|
+ shopLog.setTitle("爬取定时任务异常");
|
|
|
|
+ shopLog.setContent(e.getMessage());
|
|
|
|
+ shopLogMapper.insert(shopLog);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|