|
|
@ -1,24 +1,39 @@ |
|
|
|
package com.qs.cost.module.service; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.qs.cost.common.consts.ApiUrlConst; |
|
|
|
import com.qs.cost.common.dto.HttpResult; |
|
|
|
import com.qs.cost.common.dto.R; |
|
|
|
import com.qs.cost.common.utils.DateUtil; |
|
|
|
import com.qs.cost.common.utils.HttpUtil; |
|
|
|
import com.qs.cost.common.utils.JsonUtil; |
|
|
|
import com.qs.cost.common.utils.SecureUtil; |
|
|
|
import com.qs.cost.common.utils.*; |
|
|
|
import com.qs.cost.module.domain.GetListEntity; |
|
|
|
import com.qs.cost.module.domain.LzOrder; |
|
|
|
import com.qs.cost.module.domain.LzResponseLog; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author YenHex |
|
|
|
* @since 2022/7/6 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
public class JiaJinService { |
|
|
|
|
|
|
|
public static final String lzyunli = "lzyunli"; |
|
|
|
@Autowired LzResponseLogService responseLogService; |
|
|
|
@Autowired LzOrderService lzOrderService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 请求量子app获取订单 |
|
|
|
* @param page |
|
|
|
*/ |
|
|
|
public void query(Integer page){ |
|
|
|
if(page==null){ |
|
|
|
page = 1; |
|
|
@ -28,7 +43,7 @@ public class JiaJinService { |
|
|
|
String date = DateUtil.formatDate(now,DateUtil.FORMAT_SIMPLE_DATE2)+"-"+DateUtil.formatDate(lastMonth,DateUtil.FORMAT_SIMPLE_DATE2); |
|
|
|
String pageSize = "10"; |
|
|
|
String params = "date="+date+"&page="+page+"&page_size="+pageSize; |
|
|
|
String signParam = lzyunli + params + lzyunli; |
|
|
|
String signParam = ApiUrlConst.lzyunli + params + ApiUrlConst.lzyunli; |
|
|
|
String sign = SecureUtil.md5(signParam); |
|
|
|
params = params+"&sign="+sign; |
|
|
|
String url = "http://wsapp6.lzyunli.com/index.php/getOrder?"+params; |
|
|
@ -36,6 +51,50 @@ public class JiaJinService { |
|
|
|
if(httpResult.getCode()==200){ |
|
|
|
String json = httpResult.getData(); |
|
|
|
GetListEntity getListEntity = JsonUtil.jsonToPojo(json,GetListEntity.class); |
|
|
|
if(getListEntity==null){ |
|
|
|
return; |
|
|
|
} |
|
|
|
//保存请求json
|
|
|
|
LzResponseLog responseLog = new LzResponseLog(); |
|
|
|
responseLog.setJson(json); |
|
|
|
responseLogService.save(responseLog); |
|
|
|
GetListEntity.OtherEntity otherEntity = getListEntity.getOther(); |
|
|
|
//解析请求json,并保存订单到数据库
|
|
|
|
for (GetListEntity.OrderEntity orderEntity : getListEntity.getList()) { |
|
|
|
LzOrder lzOrder = new LzOrder(); |
|
|
|
lzOrder.setOrderNo(orderEntity.getOrderNo()); |
|
|
|
lzOrder.setOrderAmount(orderEntity.getOrderAmount()); |
|
|
|
lzOrder.setShippingFare(orderEntity.getShippingFare()); |
|
|
|
lzOrder.setConsignee(orderEntity.getConsignee()); |
|
|
|
lzOrder.setConsigneeMobile(orderEntity.getConsigneeMobile()); |
|
|
|
lzOrder.setProvinces(orderEntity.getProvinces()); |
|
|
|
lzOrder.setDetailedAddress(orderEntity.getDetailedAddress()); |
|
|
|
lzOrder.setSaleType(otherEntity.getSalesType()); |
|
|
|
lzOrder.setSaleDept(otherEntity.getSalesClass()); |
|
|
|
lzOrder.setSaleMan(otherEntity.getSalesMan()); |
|
|
|
String itemJson = orderEntity.getItems().toString(); |
|
|
|
lzOrder.setItems(itemJson); |
|
|
|
lzOrder.setCheckStatus(0); |
|
|
|
List<GetListEntity.ItemEntity> items = JsonUtil.jsonToList(itemJson,GetListEntity.ItemEntity.class); |
|
|
|
if(items!=null&&items.size()>0){ |
|
|
|
for (GetListEntity.ItemEntity item : items) { |
|
|
|
if(StringUtil.isEmpty(item.getInvCode())){ |
|
|
|
lzOrder.setCheckStatus(1); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}else { |
|
|
|
lzOrder.setCheckStatus(2); |
|
|
|
} |
|
|
|
try { |
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|
|
|
LocalDateTime orderCreateTime = LocalDateTime.parse(orderEntity.getCreateTime(),df); |
|
|
|
lzOrder.setOrderCreateTime(orderCreateTime); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(e.getMessage()); |
|
|
|
} |
|
|
|
lzOrderService.save(lzOrder); |
|
|
|
} |
|
|
|
Integer pageCount = getListEntity.getPageCount(); |
|
|
|
if(pageCount!=null&&pageCount.equals(page)){ |
|
|
|
return; |
|
|
@ -46,13 +105,49 @@ public class JiaJinService { |
|
|
|
System.out.println(); |
|
|
|
} |
|
|
|
|
|
|
|
public void task(){ |
|
|
|
//获取未同步订单,调用U8服务
|
|
|
|
LambdaQueryWrapper<LzOrder> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(LzOrder::getStatus,0); |
|
|
|
lqw.eq(LzOrder::getCheckStatus,0); |
|
|
|
List<LzOrder> orders = lzOrderService.list(lqw); |
|
|
|
for (LzOrder order : orders) { |
|
|
|
//TODO 发起U8服务中台
|
|
|
|
|
|
|
|
order.setStatus(1); |
|
|
|
order.setUpdateTime(LocalDateTime.now()); |
|
|
|
} |
|
|
|
lzOrderService.updateBatchById(orders); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* U8中台回调接口 |
|
|
|
* @param orderNos |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public R<?> callback(String orderNos){ |
|
|
|
public R<?> callback(){ |
|
|
|
//
|
|
|
|
|
|
|
|
//接收U8请求
|
|
|
|
String orderNo = ""; |
|
|
|
LambdaQueryWrapper<LzOrder> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(LzOrder::getOrderNo,orderNo); |
|
|
|
LzOrder lzOrder = lzOrderService.getOne(lqw,false); |
|
|
|
//发送量子App更新订单状态
|
|
|
|
String params = "orderNos="+orderNo; |
|
|
|
String signParam = ApiUrlConst.lzyunli + params + ApiUrlConst.lzyunli; |
|
|
|
String sign = SecureUtil.md5(signParam); |
|
|
|
String url = "http://wsapp6.lzyunli.com/index.php/upOrder"; |
|
|
|
Map<String, Object> paramMap = new HashMap<>(10); |
|
|
|
paramMap.put("orderNos",orderNo); |
|
|
|
paramMap.put("sign",sign); |
|
|
|
HttpResult httpResult = HttpUtil.post(url,paramMap); |
|
|
|
lzOrder.setCallBackStatus(2); |
|
|
|
if(httpResult.getCode()==200){ |
|
|
|
if(httpResult.getData().contains("true")){ |
|
|
|
lzOrder.setCheckStatus(1); |
|
|
|
} |
|
|
|
} |
|
|
|
lzOrderService.updateById(lzOrder); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|