From 5e23fddccd769584a3821919391cd029b3c5cbc2 Mon Sep 17 00:00:00 2001 From: zhenghaoyu Date: Thu, 1 Jun 2023 18:13:14 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E6=8B=89=E5=8F=96?= =?UTF-8?q?=E8=AF=97=E5=B0=BC=E6=9B=BC=E6=95=B0=E6=8D=AE=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/CustomerException.java | 41 ++++++++++++++ .../springblade/common/utils/CommonUtil.java | 24 +++++++++ .../com/logpm/factory/FactoryApplication.java | 3 +- .../factory/jobhandler/FactoryXxlJob.java | 54 ++++++++++++++++--- .../factory/snm/mapper/OrderLogMapper.java | 1 + .../factory/snm/mapper/OrderLogMapper.xml | 4 ++ .../factory/snm/service/IOrderLogService.java | 2 + .../factory/snm/service/IOrderService.java | 5 +- .../snm/service/impl/OrderLogServiceImpl.java | 5 ++ .../snm/service/impl/OrderServiceImpl.java | 17 +++--- 10 files changed, 133 insertions(+), 23 deletions(-) create mode 100644 blade-biz-common/src/main/java/org/springblade/common/exception/CustomerException.java diff --git a/blade-biz-common/src/main/java/org/springblade/common/exception/CustomerException.java b/blade-biz-common/src/main/java/org/springblade/common/exception/CustomerException.java new file mode 100644 index 000000000..99e91ac76 --- /dev/null +++ b/blade-biz-common/src/main/java/org/springblade/common/exception/CustomerException.java @@ -0,0 +1,41 @@ +package org.springblade.common.exception; + +/** + * +*类说明: 自定义异常 +* +* @author zhy +* @date 2023年6月1日 + */ +public class CustomerException extends RuntimeException { + /** + * + */ + private static final long serialVersionUID = 1L; + + public Integer code; + + public String message; + + public CustomerException() { + }; + + public CustomerException(String message) { + this(); + this.message = message; + } + + public CustomerException(Integer code, String message) { + this(); + this.message = message; + this.code = code; + } + @Override + public String toString() { + return "CustomerException{" + + "code=" + code + + ", message='" + message + '\'' + + '}'; + } +} + diff --git a/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java b/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java index c9e65ab7f..550295f28 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java +++ b/blade-biz-common/src/main/java/org/springblade/common/utils/CommonUtil.java @@ -19,8 +19,10 @@ package org.springblade.common.utils; import lombok.extern.log4j.Log4j2; import org.springframework.util.StringUtils; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.TimeZone; /** * 通用工具类 @@ -40,5 +42,27 @@ public class CommonUtil { return parse; } + public static boolean checkDateFormat(String time,String format){ + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format); + try{ + LocalDate.parse(time,formatter); + }catch(Exception e){ + return false; + } + return true; + } + + + public static String datoLongToString(Long dateTime,String format,String timeZone){ + if (StringUtils.isEmpty(timeZone)) { + timeZone = "Asia/Shanghai"; + } + if (dateTime != null) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone)); + return simpleDateFormat.format(dateTime); + } + return null; + } } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java index c6ed8056c..24579a781 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java @@ -16,7 +16,6 @@ */ package com.logpm.factory; -import org.springblade.common.constant.LauncherConstant; import org.springblade.common.constant.ModuleNameConstant; import org.springblade.core.cloud.client.BladeCloudApplication; import org.springblade.core.launch.BladeApplication; @@ -30,7 +29,7 @@ import org.springblade.core.launch.BladeApplication; public class FactoryApplication { public static void main(String[] args) { - BladeApplication.run(ModuleNameConstant.APPLICATION_FACTORY_NAME, FactoryApplication.class, args); + BladeApplication.run(ModuleNameConstant.APPLICATION_FACTORY_NAME+"-zhy", FactoryApplication.class, args); } } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java index 8aa923e7c..122130ee7 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/jobhandler/FactoryXxlJob.java @@ -1,7 +1,7 @@ package com.logpm.factory.jobhandler; import cn.hutool.core.util.ObjectUtil; -import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.logpm.factory.snm.dto.GroupByPackagesDTO; import com.logpm.factory.snm.entity.OrderLogEntity; @@ -18,16 +18,21 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; +import net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.common.constant.LogpmDataStatusEnum; import org.springblade.common.constant.PackagesTypeEnum; +import org.springblade.common.exception.CustomerException; import org.springblade.common.utils.CommonUtil; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -69,20 +74,57 @@ public class FactoryXxlJob { @XxlJob("factoryJobHandler") public ReturnT factoryJobHandler(String param) throws Exception { // 获取当前时间 - LocalDate date ; + LocalDate date = LocalDate.now(); List ls = stationlinenumService.lambdaQuery().eq(StationlinenumEntity::getIsDeleted, 0).eq(StationlinenumEntity::getStatus, LogpmDataStatusEnum.OPEN.getValue()).list(); if (!ObjectUtils.isEmpty(ls)) { - if(StringUtils.isNotBlank(param)){ - date = LocalDate.parse(param); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + String startTime; + String endTime; + int type = 1; + if (StringUtils.isNotBlank(param)){ + String[] split = param.split("/"); + if(split.length == 2){ + startTime = split[0]; + endTime = split[1]; + }else{ + throw new CustomerException(401,"参数传入有误!"); + } + //判断时间格式是否正确 + boolean flagStart = CommonUtil.checkDateFormat(startTime,"yyyy-MM-dd HH:mm:ss"); + boolean flagEnd = CommonUtil.checkDateFormat(endTime,"yyyy-MM-dd HH:mm:ss"); + if(!flagStart || !flagEnd){ + throw new CustomerException(401,"参数传入有误!"); + } + //设置类型为2手动 + type = 2; }else{ - date = LocalDate.now(); + //如果参数传入为空就用当前时间作为结束时间,上一次拉取的最后一条数的结束时间为本次的开始时间 + endTime = LocalDateTime.now().format(formatter); + //获取最后一条数据 + OrderLogEntity lastOne = orderLogService.selectOrderLogLastOne(); + if (Objects.isNull(lastOne)){ + //如果为空就暂时还没有拉取过的数据就用当天的0点为开始时间 + Long zeroTime = LocalDate.now() + .atStartOfDay(ZoneOffset.ofHours(8)) + .toInstant() + .toEpochMilli(); + startTime = CommonUtil.datoLongToString(zeroTime, "yyyy-MM-dd HH:mm:ss", null); + }else{ + //如果不为空则开始时间为上一条数据的结束时间 + String reqArgs = lastOne.getReqArgs(); + JSONObject jsonObject = JSONObject.parseObject(reqArgs); + startTime = jsonObject.getJSONObject("data").getString("dispatch_time_end"); + } } + //查询配置站点 + int finalType = type; ls.forEach(stationlinenumEntity -> { // 根据站点id和当前时间调用service 请求对方接口获取数据插入到我们的数据库 XxlJobLogger.log("站点线路编号{}", stationlinenumEntity.getLogisticsLineNumber()); - orderService.synOrderByLineNumData(stationlinenumEntity.getLogisticsLineNumber(), date); + orderService.synOrderByLineNumData(stationlinenumEntity.getLogisticsLineNumber(), startTime,endTime, finalType); }); } return ReturnT.SUCCESS; diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.java index bc3ecb458..518ff8ac3 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.java @@ -40,4 +40,5 @@ public interface OrderLogMapper extends BaseMapper { List selectOrderLogPage(IPage page, OrderLogVO orderLog); + OrderLogEntity selectOrderLogLastOne(); } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.xml b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.xml index 15bb974e9..bc6f41da1 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.xml +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/mapper/OrderLogMapper.xml @@ -23,4 +23,8 @@ + + diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderLogService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderLogService.java index 72a41c7bf..da5770c5f 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderLogService.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderLogService.java @@ -39,4 +39,6 @@ public interface IOrderLogService extends BaseService { IPage selectOrderLogPage(IPage page, OrderLogVO orderLog); + OrderLogEntity selectOrderLogLastOne(); + } diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderService.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderService.java index 5c6d2b7f3..2d9081461 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderService.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/IOrderService.java @@ -1,10 +1,8 @@ package com.logpm.factory.snm.service; import com.logpm.factory.snm.entity.OrderLogEntity; -import com.logpm.factory.snm.entity.StationOrderEntity; import com.logpm.factory.snm.vo.response.ResponseBaseVo; -import java.time.LocalDate; import java.util.List; import java.util.Map; @@ -18,10 +16,9 @@ public interface IOrderService { * 获取数据 * * @param lineNum - * @param date * @return */ - ResponseBaseVo synOrderByLineNumData(String lineNum, LocalDate date); + ResponseBaseVo synOrderByLineNumData(String lineNum, String startTime,String endTime,Integer type); /** * 解析数据 diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/OrderLogServiceImpl.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/OrderLogServiceImpl.java index a43405e59..fe75f3ae0 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/OrderLogServiceImpl.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/snm/service/impl/OrderLogServiceImpl.java @@ -38,5 +38,10 @@ public class OrderLogServiceImpl extends BaseServiceImpl requestVo = new RequestVo(); requestVo.setMethod("snimay.crm.externalinterface.logistics.get"); @@ -64,8 +59,8 @@ public class OrderServiceImpl implements IOrderService { Date now = new Date(); requestLineNumberVo.setLogistics_line_number(lineNum); - requestLineNumberVo.setDispatch_time_start(dayDate); - requestLineNumberVo.setDispatch_time_end(dayDate); + requestLineNumberVo.setDispatch_time_start(startTime); + requestLineNumberVo.setDispatch_time_end(endTime); SystemSign systemSign = new SystemSign(); systemSign.setTimestamp(now.getTime()); systemSign.setPublicKey(factorySnmdataProperties.getPublicKey()); @@ -94,7 +89,7 @@ public class OrderServiceImpl implements IOrderService { OrderLogEntity orderLogEntity = new OrderLogEntity(); orderLogEntity.setReqArgs(userStr); - orderLogEntity.setType(1); + orderLogEntity.setType(type); orderLogEntity.setResBody(JSONUtil.toJsonStr(responseStationOrderVo)); orderLogService.save(orderLogEntity); logger.info(">>>>>>>>>>>>>> 数据保存orderLogService{}", orderLogService); From 56bc783f58286b6a09baf1f294cf171fe06e96e4 Mon Sep 17 00:00:00 2001 From: caoyizhong <1270296080@qq.com> Date: Thu, 1 Jun 2023 18:14:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E6=95=B4=E5=90=88?= =?UTF-8?q?=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/BasicdataStorageServicesEntity.java | 13 +++++++++++++ .../entity/BasicdataSupportValueEntity.java | 5 +++++ .../mapper/BasicdataStorageServicesMapper.xml | 1 + 3 files changed, 19 insertions(+) diff --git a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataStorageServicesEntity.java b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataStorageServicesEntity.java index 67c755c16..59514f90a 100644 --- a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataStorageServicesEntity.java +++ b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataStorageServicesEntity.java @@ -16,6 +16,7 @@ */ package com.logpm.basicdata.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import io.swagger.annotations.ApiModel; @@ -66,6 +67,11 @@ public class BasicdataStorageServicesEntity extends TenantEntity { */ @ApiModelProperty(value = "门店ID") private Long shopId; + /** + * 区分类型 + */ + @ApiModelProperty(value = "区分类型") + private Long distinguish; /** * 发货单位 */ @@ -77,4 +83,11 @@ public class BasicdataStorageServicesEntity extends TenantEntity { @ApiModelProperty(value = "服务仓库") private String warehouseService; + /** + * 门店ID + */ + @ApiModelProperty(value = "门店ID") + @TableField(exist = false) + private String shopIds; + } diff --git a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataSupportValueEntity.java b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataSupportValueEntity.java index b5cf7fe5a..7427992f2 100644 --- a/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataSupportValueEntity.java +++ b/blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataSupportValueEntity.java @@ -41,6 +41,11 @@ public class BasicdataSupportValueEntity extends TenantEntity { */ @ApiModelProperty(value = "收货用户名称") private String userName; + /** + * 价格区间 + */ + @ApiModelProperty(value = "价格区间") + private String priceRange; /** * 保费率 */ diff --git a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataStorageServicesMapper.xml b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataStorageServicesMapper.xml index 0d245238a..2e2cb8707 100644 --- a/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataStorageServicesMapper.xml +++ b/blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/mapper/BasicdataStorageServicesMapper.xml @@ -18,6 +18,7 @@ lbss.is_deleted = 0 and lbs.store_name like concat('%',#{param.shopId},'%') + and lbss.shop_id = #{param.shopIds} and lbsc.linkman like concat('%',#{param.forwardingUnit} ,'%') and lbss.warehouse_service like concat('%',#{param.warehouseService},'%') From d42188cc18ce3d4665e810db20d6cd380036af2e Mon Sep 17 00:00:00 2001 From: zhenghaoyu Date: Thu, 1 Jun 2023 18:15:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?1.=E4=BB=A3=E7=A0=81=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/logpm/factory/FactoryApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java b/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java index 24579a781..d5181a390 100644 --- a/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java +++ b/blade-service/logpm-factory/src/main/java/com/logpm/factory/FactoryApplication.java @@ -29,7 +29,7 @@ import org.springblade.core.launch.BladeApplication; public class FactoryApplication { public static void main(String[] args) { - BladeApplication.run(ModuleNameConstant.APPLICATION_FACTORY_NAME+"-zhy", FactoryApplication.class, args); + BladeApplication.run(ModuleNameConstant.APPLICATION_FACTORY_NAME, FactoryApplication.class, args); } }