You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
10 KiB
Java
169 lines
10 KiB
Java
package com.glxp.udi.admin.thread;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.glxp.udi.admin.common.res.BaseResponse;
|
|
import com.glxp.udi.admin.constant.SystemParamConstant;
|
|
import com.glxp.udi.admin.dao.info.ScheduledDao;
|
|
import com.glxp.udi.admin.entity.info.PlatformEntity;
|
|
import com.glxp.udi.admin.entity.info.ScheduledEntity;
|
|
import com.glxp.udi.admin.entity.inout.OrderDetailEntity;
|
|
import com.glxp.udi.admin.entity.inout.OrderEntity;
|
|
import com.glxp.udi.admin.entity.inout.UnitMaintainEntity;
|
|
import com.glxp.udi.admin.entity.inout.WarehouseEntity;
|
|
import com.glxp.udi.admin.entity.param.SystemParamConfigEntity;
|
|
import com.glxp.udi.admin.mongo.service.OrderDetailService;
|
|
import com.glxp.udi.admin.mongo.service.OrderService;
|
|
import com.glxp.udi.admin.mongo.service.WarehouseService;
|
|
import com.glxp.udi.admin.req.inout.FilterOrderDetailRequest;
|
|
import com.glxp.udi.admin.req.inout.PostUdimsOrderDetailRequest;
|
|
import com.glxp.udi.admin.req.inout.PostUdimsOrderRequest;
|
|
import com.glxp.udi.admin.req.inout.WarehouseQueryRequest;
|
|
import com.glxp.udi.admin.req.udidl.ScheduledRequest;
|
|
import com.glxp.udi.admin.service.info.PlatformService;
|
|
import com.glxp.udi.admin.service.inout.UnitMaintainService;
|
|
import com.glxp.udi.admin.service.param.SystemParamConfigService;
|
|
import com.glxp.udi.admin.service.param.SystemParamCustomerConfigService;
|
|
import com.glxp.udi.admin.util.HttpClient;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
|
import org.springframework.scheduling.support.CronTrigger;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
/**
|
|
* 自动提交已完成单据到自助平台
|
|
*/
|
|
@Slf4j
|
|
@Component
|
|
@EnableScheduling
|
|
public class SubmitOrderToSpmsTask implements SchedulingConfigurer {
|
|
|
|
@Resource
|
|
private ScheduledDao scheduledDao;
|
|
@Resource
|
|
private OrderService orderService;
|
|
@Resource
|
|
private UnitMaintainService unitMaintainService;
|
|
@Resource
|
|
private SystemParamConfigService systemParamConfigService;
|
|
@Resource
|
|
private SystemParamCustomerConfigService systemParamCustomerConfigService;
|
|
@Resource
|
|
private WarehouseService warehouseService;
|
|
@Resource
|
|
private OrderDetailService orderDetailService;
|
|
@Resource
|
|
private PlatformService platformService;
|
|
|
|
@Override
|
|
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
|
taskRegistrar.addTriggerTask(this::process, triggerContext -> {
|
|
ScheduledRequest scheduledRequest = new ScheduledRequest();
|
|
scheduledRequest.setCronName("submitOrderToSpmsTask");
|
|
ScheduledEntity scheduled = scheduledDao.findScheduled(scheduledRequest);
|
|
String cron = scheduled.getCron();
|
|
if (StrUtil.isBlank(cron)) {
|
|
log.error("cron is null");
|
|
}
|
|
return new CronTrigger(cron).nextExecutionTime(triggerContext);
|
|
});
|
|
}
|
|
|
|
private void process() {
|
|
SystemParamConfigEntity supplement_order_interval = systemParamConfigService.selectByParamKey(SystemParamConstant.SUPPLEMENT_ORDER_INTERVAL);
|
|
if (!"0".equals(supplement_order_interval.getParamValue())) {
|
|
log.info("开始扫描自动提交到自助平台的单据数据");
|
|
//查询已经绑定自助平台的往来单位
|
|
List<UnitMaintainEntity> unitMaintainEntities = unitMaintainService.getboundUnitMaintains();
|
|
if (CollUtil.isNotEmpty(unitMaintainEntities)) {
|
|
List<UnitMaintainEntity> concurrentList = new CopyOnWriteArrayList<>(unitMaintainEntities);
|
|
concurrentList.parallelStream().forEach(unitMaintainEntity -> {
|
|
//查询此用户是否开启了自动提交到对应平台
|
|
SystemParamConfigEntity systemParamConfigEntity = systemParamCustomerConfigService.getParamByKey(SystemParamConstant.IS_AUTO_SUBMIT_TO_SPMS, Long.valueOf(unitMaintainEntity.getCustomerId()));
|
|
if (null != systemParamConfigEntity && systemParamConfigEntity.getParamValue().equals("1")) {
|
|
//查询此用户未提交到自助平台且单据类型匹配的数据
|
|
List<OrderEntity> orderEntities = orderService.findWaitUploadOrders(unitMaintainEntity);
|
|
if (CollUtil.isNotEmpty(orderEntities)) {
|
|
//构造参数
|
|
PostUdimsOrderRequest postUdimsOrderRequest = new PostUdimsOrderRequest();
|
|
List<PostUdimsOrderRequest.OrderBean> orderBeans = new ArrayList<>();
|
|
for (OrderEntity orderEntity : orderEntities) {
|
|
PostUdimsOrderRequest.OrderBean orderBean = new PostUdimsOrderRequest.OrderBean();
|
|
BeanUtil.copyProperties(orderEntity, orderBean);
|
|
orderBean.setAction(unitMaintainEntity.getTargetAction());
|
|
WarehouseQueryRequest warehouseQueryRequest = new WarehouseQueryRequest();
|
|
warehouseQueryRequest.setOrderId(orderEntity.getOrderId());
|
|
List<WarehouseEntity> warehouseEntities = warehouseService.filterWarehouse(warehouseQueryRequest);
|
|
List<PostUdimsOrderRequest.OrderBean.CodeBean> codeBeans = new ArrayList<>();
|
|
warehouseEntities.forEach(data -> {
|
|
PostUdimsOrderRequest.OrderBean.CodeBean codeBean = new PostUdimsOrderRequest.OrderBean.CodeBean();
|
|
BeanUtils.copyProperties(data, codeBean);
|
|
codeBeans.add(codeBean);
|
|
});
|
|
//查询单据详情
|
|
FilterOrderDetailRequest filterOrderDetailRequest = new FilterOrderDetailRequest();
|
|
filterOrderDetailRequest.setOrderId(orderBean.getOrderId());
|
|
//单据详情
|
|
List<OrderDetailEntity> erpOrderEntities = orderDetailService.filterOrderDetails(filterOrderDetailRequest);
|
|
if (CollUtil.isNotEmpty(erpOrderEntities)) {
|
|
List<PostUdimsOrderDetailRequest> orderDetails = new ArrayList<>();
|
|
for (OrderDetailEntity orderDetailEntity : erpOrderEntities) {
|
|
PostUdimsOrderDetailRequest orderDetail = new PostUdimsOrderDetailRequest();
|
|
orderDetail.setUuidFk(orderDetailEntity.getUuidFk());
|
|
orderDetail.setFirstSalesInvNo(orderDetailEntity.getFirstSalesInvNo());
|
|
orderDetail.setSecSalesInvNo(orderDetailEntity.getSecSalesInvNo());
|
|
orderDetail.setPrice(orderDetailEntity.getPrice());
|
|
orderDetail.setInvoiceDate(orderDetailEntity.getInvoiceDate());
|
|
orderDetail.setSecSalesListNo(orderDetailEntity.getSecSalesListNo());
|
|
orderDetail.setBatchNo(orderDetailEntity.getBatchNo());
|
|
orderDetails.add(orderDetail);
|
|
}
|
|
orderBean.setOrderDetails(orderDetails);
|
|
}
|
|
orderBean.setCodes(codeBeans);
|
|
orderBeans.add(orderBean);
|
|
}
|
|
postUdimsOrderRequest.setOrderBeans(orderBeans);
|
|
|
|
PlatformEntity platformEntity = platformService.get(unitMaintainEntity.getPlatformId());
|
|
postUdimsOrderRequest.setOrderBeans(orderBeans);
|
|
log.info("提交单据到自助平台,单据数据:{}", JSONUtil.toJsonStr(postUdimsOrderRequest));
|
|
String response =
|
|
HttpClient.uCloudPostSmp(platformEntity.getHost() + "/warehouse/inout/postOrdersUdims",
|
|
postUdimsOrderRequest, unitMaintainEntity.getApiKey(), unitMaintainEntity.getSecretKey());
|
|
log.info("自助平台响应结果:{}", response);
|
|
BaseResponse baseResponse =
|
|
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
|
|
});
|
|
if (baseResponse.getCode() == 20000) {
|
|
log.info("自动上传单据成功," + unitMaintainEntity.getName() + "上传单据数量为 " + orderEntities.size());
|
|
for (OrderEntity orderEntity : orderEntities) {
|
|
log.info("修改单号为:{} 的上传状态", orderEntity.getOrderId());
|
|
orderEntity.setUploadStatus("1");
|
|
orderService.updateOrder(orderEntity);
|
|
}
|
|
} else {
|
|
log.error("自动上传单据到自助平台异常,响应结果:{}", response);
|
|
log.error("平台信息:{}", JSONUtil.toJsonStr(platformEntity));
|
|
log.error("往来单位信息:{}", JSONUtil.toJsonStr(unitMaintainEntity));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|