Commit 3cdaf462 by 庞善天

拉取美团订单数据

1 parent 4ecebf68
Showing 22 changed files with 1158 additions and 0 deletions
...@@ -63,5 +63,21 @@ ...@@ -63,5 +63,21 @@
<groupId>org.oreframework.boot</groupId> <groupId>org.oreframework.boot</groupId>
<artifactId>ore-boot-starter-elasticjob</artifactId> <artifactId>ore-boot-starter-elasticjob</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.7</version>
</dependency>
<dependency>
<groupId>com.meituan.sqt</groupId>
<artifactId>open-platform-sdk</artifactId>
<version>1.0.48</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.constant;
/**
* @Title MeiTuanOrderConstants
* @author pangst
* @date 2026/2/10 10:10
* @version V1.0
**/
public class MeiTuanOrderConstants {
public static final Long entId = 56637L;
public static final String accessKey = "F6TZVPM1XEDE-TK";
public static final String secretKey = "J2LoHiu8O26vDxkwsVWzRw==";
public static final String orderUrl = "https://bep-openapi.meituan.com/api/sqt/open/order/queryList";
public static final String orderDetailUrl = "https://bep-openapi.meituan.com/api/sqt/open/order/queryDetail";
public static final String reportDetailUrl = "https://bep-openapi.meituan.com/api/sqt/open/report/v1/queryDetail";
public static final String realDetailUrl = "https://bep-openapi.meituan.com/api/sqt/open/repast/applyDetail/pageQuery";
public static final String userDetailUrl = "https://bep-openapi.meituan.com/api/sqt/open/staff/batch/query";
public static final String deptUrl = "https://bep-openapi.meituan.com/api/sqt/open/org/batch/query";
public static final String DEFAULT_CREATE_BY = "system";
}
package cn.com.glsx.dj.staff.job;
import cn.com.glsx.dj.staff.request.meituan.MtOrderResult;
import cn.com.glsx.dj.staff.service.common.MeiTuanOrderManager;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
/**
* @Title: MeiTuanOrderJob
* @Description: 每天凌晨1点定时任务获取前一天的美团订单数据
* @Author pangst
* @Date 2025/02/09
**/
@Service
@Slf4j
@ElasticJobConf(name = "MeiTuanOrderJob", cron = "0 0 1 * * ?", description = "每天凌晨1点定时任务获取前一天的美团订单数据", overwrite = false)
public class MeiTuanOrderJob implements SimpleJob {
@Autowired
private MeiTuanOrderManager meiTuanOrderManager;
@Override
public void execute(ShardingContext shardingContext) {
log.info("每天凌晨1点定时任务获取前一天的美团订单数据开始");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 获取昨天的时间
LocalDate yesterday = LocalDate.now().minusDays(1);
LocalDateTime dayStart = yesterday.atStartOfDay();
LocalDateTime dayEnd = yesterday.atTime(23, 59, 59);
long minUpdateTime = dayStart.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long maxUpdateTime = dayEnd.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
try {
List<MtOrderResult> mtOrderResults = meiTuanOrderManager.obtainOrderList(minUpdateTime, maxUpdateTime);
log.info("mtOrderResults Size:{}", mtOrderResults.size());
// todo 帮我入库到 dj_car_life_staff_meituan_order 表里面
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("每天凌晨1点定时任务获取前一天的美团订单数据任务结束");
}
public static void main(String[] args) {
log.info("每天凌晨1点定时任务获取前一天的美团订单数据开始");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 获取昨天的时间
LocalDate yesterday = LocalDate.now().minusDays(1);
LocalDateTime dayStart = yesterday.atStartOfDay();
LocalDateTime dayEnd = yesterday.atTime(23, 59, 59);
long minUpdateTime = dayStart.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
long maxUpdateTime = dayEnd.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
try {
MeiTuanOrderManager mtMapper = new MeiTuanOrderManager();
List<MtOrderResult> mtOrderResults = mtMapper.obtainOrderList(minUpdateTime, maxUpdateTime);
log.info("mtOrderResults Size:{}", mtOrderResults.size());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
log.info("每天凌晨1点定时任务获取前一天的美团订单数据任务结束");
}
}
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 住客信息
*/
@Data
public class ApplyExceedInfo {
private Integer isExceed;
private String exceedAmount;
private String exceedReason;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 酒店住宿详情信息
*/
@Data
public class AptInfo {
private String checkinTime;
private String checkoutTime;
private String actualCheckinTime;
private String lastCancelTime;
private String hotelStar;
private Long brandId;
private String brandName;
private Integer hotelGroupId;
private String hotelGroupName;
private String breakfast;
private String cityName;
private String cityId;
private String provinceName;
private String provinceId;
private Long poiId;
private String poiName;
private String poiAddress;
private Long goodsId;
private String roomName;
private String partnerName;
private String partnerType;
private String hotelRating;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 住客信息
*/
@Data
public class GuestInfo {
private Integer personType;
private Long personId;
private Integer guestType;
private String guestName;
private String guestPhone;
private String guestEmail;
private Boolean isVip;
private Integer roomIndexId;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 酒店订单基础信息
*/
@Data
public class HotelBaseInfo {
private Integer orderStatus;
private String orderAmount;
private Integer invoiceType;
private Boolean isAgreement;
private Boolean isReceptionInvoice;
private Boolean isOverseal;
private Integer hotelPayType;
private String currency;
private String expressAmount;
private Integer roomCount;
private Integer roomNightCount;
private String createTime;
private String modifyTime;
private String riskAmount;
private String avgNightAmount;
private String invoiceSubject;
private Boolean isVip;
private String bookType;
private Integer cancelRuleType;
private String lastTimeCST;
private String bookSucTime;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
import java.util.List;
/**
* 酒店订单详情主对象
*/
@Data
public class HotelOrderDetail {
private HotelBaseInfo hotelBaseInfo;
private AptInfo aptInfo;
private List<GuestInfo> guestList;
private List<RoomNightInfo> roomNightList;
private List<Object> appealList;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@Data
public class MtOrderResult {
/**
* 美团企业版订单ID
*/
private Long sqtBizOrderId;
/**
* 业务原始订单ID
*/
private String origOrderId;
/**
* 支付状态,10:未支付,20:已支付,31:部分退款,32:全额退款
*/
private Integer payStatus;
/**
* 下单员工美团侧员工ID
*/
private Long staffId;
/**
* 员工名称
*/
private String staffName;
/**
* 员工手机号
*/
private String staffPhone;
/**
* 消费城市编码
*/
private String expenseCityId;
/**
* 消费城市名称
*/
private String expenseCityName;
/**
* 订单金额,单位元,精确到小数点后两位
*/
private BigDecimal orderAmount;
/**
* 总支付金额,单位元,精确到小数点后两位
*/
private BigDecimal totalPayAmount;
/**
* 总退款金额,单位元,精确到小数点后两位
*/
private BigDecimal totalRefundAmount;
/**
* 实际支付金额,单位元,精确到小数点后两位
*/
private BigDecimal totalRealAmount;
/**
* 下单时间,格式:yyyy-MM-dd HH:mm:ss
*/
private Date createTime;
/**
* 更新时间,格式:yyyy-MM-dd HH:mm:ss
*/
private Date updateTime;
/**
* 美团企业版用餐申请单号
*/
private String applyNo;
/**
* 美团企业版用餐申请事由
*/
private String realReason;
/**
* 下单场景编码 1-商务宴请 3-商务差旅
*/
private Integer sceneType;
/**
* 下单场景名称
*/
private String sceneTypeName;
/**
* 美团侧部门编码路径 0-128-483
*/
private String orgIdPath;
/**
* 美团侧部门名称路径 美团-XX事业部-XX
*/
private String orgNamePath;
/**
* 美团侧直属部门id
*/
private Long directOrgId;
/**
* 美团侧直属部门名称
*/
private String directOrgName;
/**
* 直属上级美团企业版员工ID
*/
private Long parentStaffId;
/**
* 直属上级美团企业版员工电话
*/
private String parentStaffPhone;
/**
* 店铺id
*/
private Long shopId;
/**
* 店铺名称
*/
private String shopName;
/**
* 店铺地址
*/
private String shopAddress;
/**
* 消费数量:餐饮消费人次、差旅入住天数
*/
private Integer consumeCount;
/**
* 平均消费金额:人均消费金额、平均每天房价 单位:元,精确到小数点后两位
*/
private BigDecimal avgConsumeAmount;
/**
* 餐饮标准 单位:元,精确到小数点后两位
*/
private BigDecimal standardAmount;
/**
* 是否超标 0:未超标,1:超标
*/
private Integer isExceed;
/**
* 超标金额 单位:元,精确到小数点后两位
*/
private BigDecimal exceedAmount;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@Data
public class OrderOriginInfoResult {
/**
* 支付
*/
private String entPayAmountSum;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@Data
public class ParentStaffOrderResult {
/**
* 美团企业版订单ID
*/
private Long sqtBizOrderId;
/**
* 下单员工美团侧员工ID
*/
private Long staffId;
/**
* 员工名称
*/
private String staffName;
/**
* 员工手机号
*/
private String staffPhone;
/**
* 直属上级美团企业版员工ID
*/
private Long parentStaffId;
/**
* 直属上级美团企业版员工电话
*/
private String parentStaffPhone;
/**
* 推送内容
*/
private String pushContent;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
import java.util.Date;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@Data
public class PushOrderResult {
/**
* 美团企业版订单ID
*/
private Long sqtBizOrderId;
/**
* 下单员工美团侧员工ID
*/
private Long staffId;
/**
* 员工名称
*/
private String staffName;
/**
* 员工手机号
*/
private String staffPhone;
/**
* 推送对象 1-员工 2-员工上级 3-HR 4-部门总 5-公司总
*/
private Integer pushObject;
/**
* 推送周期:1-按天 2-按月
*/
private Integer pushPeriod;
/**
* 下单时间,格式:yyyy-MM-dd HH:mm:ss
*/
private Date createTime;
/**
* 更新时间,格式:yyyy-MM-dd HH:mm:ss
*/
private Date updateTime;
/**
* 推送内容
*/
private String pushContent;
/**
* 推送状态 0-失败 1-成功
*/
private Integer pushStatus;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import com.meituan.sqt.annotation.ApiMeta;
import com.meituan.sqt.request.in.BaseApiRequest;
import com.meituan.sqt.utils.JsonUtil;
import java.util.List;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@ApiMeta(
apiName = "用餐申请详情查询接口",
path = "/repast/applyDetail/pageQuery",
connectTimeout = 5000,
socketTimeout = 5000
)
public class RealDetailQueryRequest extends BaseApiRequest<RealDetailQueryResult> {
/**
* 美团企业版申请单号列表
*/
private List<String> applyNoList;
/**
* 员工id
*/
private Long submitStaffId;
/**
* 最小订单支付时间,13位时间戳,需要与最大订单支付时间结合使用,可以实现支付时间的区间查询
*/
private Long minCreatedTime;
/**
* 最大订单支付时间,13位时间戳,需要与最小订单支付时间结合使用,可以实现支付时间的区间查询
*/
private Long maxCreatedTime;
public Long getMinCreatedTime() {
return minCreatedTime;
}
public void setMinCreatedTime(Long minCreatedTime) {
this.minCreatedTime = minCreatedTime;
}
public Long getMaxCreatedTime() {
return maxCreatedTime;
}
public void setMaxCreatedTime(Long maxCreatedTime) {
this.maxCreatedTime = maxCreatedTime;
}
public List<String> getApplyNoList() {
return applyNoList;
}
public void setApplyNoList(List<String> applyNoList) {
this.applyNoList = applyNoList;
}
public Long getSubmitStaffId() {
return submitStaffId;
}
public void setSubmitStaffId(Long submitStaffId) {
this.submitStaffId = submitStaffId;
}
@Override
public RealDetailQueryResult deserializeResponse(String data) {
return JsonUtil.json2Object(data, RealDetailQueryResult.class);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
import java.util.List;
/**
* 用餐申请详情主对象
*/
@Data
public class RealDetailQueryResult {
private List<RepastApplyInfo> applyList;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 申请单数据信息
*/
@Data
public class RepastApplyInfo {
private String applyNo;
private String externalApplyNo;
private String reason;
private Integer planPersonCount;
private String predictAmount;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import com.meituan.sqt.annotation.ApiMeta;
import com.meituan.sqt.request.in.BaseApiRequest;
import com.meituan.sqt.utils.JsonUtil;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@ApiMeta(
apiName = "消费报备详情查询接口",
path = "/report/v1/queryDetail",
connectTimeout = 5000,
socketTimeout = 5000
)
public class ReportDetailQueryRequest extends BaseApiRequest<ReportDetailQueryResult> {
/**
* 商企通订单ID
*/
private Long sqtBizOrderId;
public Long getSqtBizOrderId() {
return sqtBizOrderId;
}
public void setSqtBizOrderId(Long sqtBizOrderId) {
this.sqtBizOrderId = sqtBizOrderId;
}
@Override
public ReportDetailQueryResult deserializeResponse(String data) {
return JsonUtil.json2Object(data, ReportDetailQueryResult.class);
}
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 报备详情主对象
*/
@Data
public class ReportDetailQueryResult {
private ReportInfo reportInfo;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 住客信息
*/
@Data
public class ReportInfo {
private Integer numOfConsumer;
private String personAvgAmount;
private ApplyExceedInfo applyExceedInfo;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 房晚价格信息
*/
@Data
public class RoomNightInfo {
private String bizDay;
private Integer roomIndexId;
private Integer breakfastNum;
private String roomNightPrice;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* @author pangst
* @date 2026/02/10 20:22
* @description
*/
@Data
public class StaffOrderResult {
/**
* 美团企业版订单ID
*/
private Long sqtBizOrderId;
/**
* 下单员工美团侧员工ID
*/
private Long staffId;
/**
* 员工名称
*/
private String staffName;
/**
* 员工手机号
*/
private String staffPhone;
/**
* 直属上级美团企业版员工ID
*/
private Long parentStaffId;
/**
* 直属上级美团企业版员工电话
*/
private String parentStaffPhone;
/**
* 推送内容
*/
private String pushContent;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.request.meituan;
import lombok.Data;
/**
* 住客信息
*/
@Data
public class StaffUniqueMarkInfo {
private Long staffId;
private String staffIdentifier;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.staff.service.common;
import cn.com.glsx.dj.staff.constant.MeiTuanOrderConstants;
import cn.com.glsx.dj.staff.request.meituan.*;
import com.meituan.sqt.client.SqtClient;
import com.meituan.sqt.enums.ResponseStatusEnum;
import com.meituan.sqt.exception.MtSqtException;
import com.meituan.sqt.request.in.order.OrderDetailQueryRequest;
import com.meituan.sqt.request.in.order.OrderListQueryRequest;
import com.meituan.sqt.request.in.staff.StaffQueryRequest;
import com.meituan.sqt.response.in.BaseApiResponse;
import com.meituan.sqt.response.in.order.OrderDetailQueryResult;
import com.meituan.sqt.response.in.order.OrderListQueryResult;
import com.meituan.sqt.response.in.staff.StaffQueryResultItem;
import com.meituan.sqt.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
@Slf4j
public class MeiTuanOrderManager {
private static SqtClient sqtClient = null;
static {
sqtClient = new SqtClient.Builder()
.setEntId(MeiTuanOrderConstants.entId)
.setAccessKey(MeiTuanOrderConstants.accessKey)
.setSecretKey(MeiTuanOrderConstants.secretKey)
.build();
}
/**
* 订单列表查询
* @throws MtSqtException
*/
public List<MtOrderResult> obtainOrderList(Long minUpdateTime, Long maxUpdateTime) throws MtSqtException, ParseException {
log.info("获取订单列表...");
List<MtOrderResult> mtOrderList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
OrderListQueryRequest orderListRequest = new OrderListQueryRequest();
orderListRequest.setTs(System.currentTimeMillis());
orderListRequest.setEntId(sqtClient.getEntId());
orderListRequest.setMinUpdateTime(minUpdateTime);
orderListRequest.setMaxUpdateTime(maxUpdateTime);
// 分页拉取数据
Integer pageNum = 1;
Integer pageSize = 100;
boolean hasMore = true;
while (hasMore) {
log.info("pageNum:{}",pageNum);
orderListRequest.setPageNum(pageNum);
orderListRequest.setPageSize(pageSize);
BaseApiResponse<OrderListQueryResult> response = sqtClient.invokeApi(MeiTuanOrderConstants.orderUrl, orderListRequest, null, null);
if (response!=null){
// 4. 获取结果
if(Objects.equals(ResponseStatusEnum.SUCCESS.getCode(), response.getStatus())) {
// 4.1 成功,获取订单列表查询结果
OrderListQueryResult realData = response.getRealData();
if (realData!=null && !CollectionUtils.isEmpty(realData.getOrderList())){
List<OrderListQueryResult.OrderListItem> orderList = realData.getOrderList();
log.info("pullOrderList:{}",orderList.size());
for (OrderListQueryResult.OrderListItem orderItem : orderList) {
// 支付状态不匹配 直接返回 (只要已支付和部分退款的单,未支付和全部退款直接返回)
Integer payStatus = orderItem.getPayStatus();
if (payStatus==null || payStatus==10 || payStatus==32){
continue;
}
// 实际支付金额 必须大于0
String totalRealAmount = orderItem.getTotalRealAmount();
if (StringUtils.isEmpty(totalRealAmount) || new BigDecimal(totalRealAmount).compareTo(BigDecimal.ZERO) <= 0){
continue;
}
// 赋值基础信息
MtOrderResult mtOrderResult = new MtOrderResult();
mtOrderResult.setSqtBizOrderId(orderItem.getSqtBizOrderId());
mtOrderResult.setOrigOrderId(orderItem.getOrigOrderId());
mtOrderResult.setPayStatus(orderItem.getPayStatus());
mtOrderResult.setStaffId(orderItem.getStaffId());
mtOrderResult.setStaffName(orderItem.getStaffName());
mtOrderResult.setStaffPhone(orderItem.getStaffPhone());
mtOrderResult.setExpenseCityId(orderItem.getExpenseCityId());
mtOrderResult.setExpenseCityName(orderItem.getExpenseCityName());
// 赋值金额
if (!StringUtils.isEmpty(orderItem.getOrderAmount())){
mtOrderResult.setOrderAmount(new BigDecimal(orderItem.getOrderAmount()));
}
if (!StringUtils.isEmpty(orderItem.getTotalPayAmount())){
mtOrderResult.setTotalPayAmount(new BigDecimal(orderItem.getTotalPayAmount()));
}
if (!StringUtils.isEmpty(orderItem.getTotalRefundAmount())){
mtOrderResult.setTotalRefundAmount(new BigDecimal(orderItem.getTotalRefundAmount()));
}
if (!StringUtils.isEmpty(orderItem.getTotalRealAmount())){
mtOrderResult.setTotalRealAmount(new BigDecimal(orderItem.getTotalRealAmount()));
}
// 赋值时间
if (!StringUtils.isEmpty(orderItem.getCreateTime())){
Date createTime = sdf.parse(orderItem.getCreateTime());
mtOrderResult.setCreateTime(createTime);
}
if (!StringUtils.isEmpty(orderItem.getUpdateTime())){
Date updateTime = sdf.parse(orderItem.getUpdateTime());
mtOrderResult.setUpdateTime(updateTime);
}
// 赋值员工上级
obtainUserDetail(mtOrderResult);
// 获取订单详情信息
obtainOrderDetail(mtOrderResult);
// 下单场景 只要 1-商务宴请 3-商务差旅
Integer sceneType = mtOrderResult.getSceneType();
if (sceneType==null || (sceneType!=1 && sceneType!=3)){
continue;
}
// 商务宴请 赋值用餐申请单号和申请事由
if (sceneType==1){
if (!CollectionUtils.isEmpty(orderItem.getApplyList())){
for (OrderListQueryResult.OrderListItem.ApplyInfo applyInfo : orderItem.getApplyList()) {
if (applyInfo.getApplyType()==2){
String applyNo = applyInfo.getApplyNo();
mtOrderResult.setApplyNo(applyNo);
obtainRealReason(mtOrderResult);
break;
}
}
}
}
mtOrderList.add(mtOrderResult);
}
// 判断是否还有下一页:当前页条数小于pageSize则结束
hasMore = orderList.size() >= pageSize;
} else {
hasMore = false;
}
} else {
// 处理请求失败场景 打印日志 拉取数据失败
hasMore = false;
}
} else {
hasMore = false;
}
pageNum++;
}
return mtOrderList;
}
/**
* 获取员工详情
* @throws MtSqtException
*/
public void obtainUserDetail(MtOrderResult mtOrderResult) throws MtSqtException {
StaffQueryRequest staffQueryRequest = new StaffQueryRequest();
staffQueryRequest.setTs(System.currentTimeMillis());
staffQueryRequest.setEntId(sqtClient.getEntId());
staffQueryRequest.setStaffIdList(Arrays.asList(mtOrderResult.getStaffId()));
BaseApiResponse<List<StaffQueryResultItem>> response = sqtClient.invokeApi(MeiTuanOrderConstants.userDetailUrl, staffQueryRequest, null, null);
if (response != null) {
// 4. 获取请求结果
if(Objects.equals(ResponseStatusEnum.SUCCESS.getCode(), response.getStatus())) {
// 4.1 请求成功,获取员工查询结果
List<StaffQueryResultItem> resultItemList = response.getRealData();
if (!CollectionUtils.isEmpty(resultItemList)){
StaffQueryResultItem staffItem = resultItemList.get(0);
mtOrderResult.setParentStaffId(staffItem.getParentStaffId());
mtOrderResult.setParentStaffPhone(staffItem.getParentStaffIdentifier());
}
} else {
// 处理请求失败场景
// 访问频率过高
if (ResponseStatusEnum.HIGH_FREQUENCY_ACCESS.getCode().intValue() == response.getStatus()) {
log.info("获取员工详情访问频率过高");
}
// 访问次数超过配额
if (ResponseStatusEnum.EXCEED_ACCESS_NUMBER.getCode().intValue() == response.getStatus()) {
}
// 其它失败场景
}
}
}
/**
* 获取用餐申请事由
* @return
* @throws MtSqtException
*/
public void obtainRealReason(MtOrderResult mtOrderResult) throws MtSqtException {
RealDetailQueryRequest realDetailRequest = new RealDetailQueryRequest();
realDetailRequest.setTs(System.currentTimeMillis());
realDetailRequest.setEntId(sqtClient.getEntId());
realDetailRequest.setSubmitStaffId(mtOrderResult.getStaffId());
realDetailRequest.setApplyNoList(Arrays.asList(mtOrderResult.getApplyNo()));
BaseApiResponse<RealDetailQueryResult> response = sqtClient.invokeApi(MeiTuanOrderConstants.realDetailUrl, realDetailRequest, null, null);
if (response!=null){
// 4. 获取结果
if(Objects.equals(ResponseStatusEnum.SUCCESS.getCode(), response.getStatus())) {
// 4.1 成功,获取用餐申请列表查询结果
RealDetailQueryResult realData = response.getRealData();
if (realData!=null && !CollectionUtils.isEmpty(realData.getApplyList())){
String realReason = realData.getApplyList().get(0).getReason();
mtOrderResult.setRealReason(realReason);
}
} else {
// 处理请求失败场景 打印日志 获取用餐事由失败
// 处理请求失败场景
// 访问频率过高
if (ResponseStatusEnum.HIGH_FREQUENCY_ACCESS.getCode().intValue() == response.getStatus()) {
log.info("获取用餐申请事由访问频率过高");
}
// 访问次数超过配额
if (ResponseStatusEnum.EXCEED_ACCESS_NUMBER.getCode().intValue() == response.getStatus()) {
}
// 其它失败场景
}
}
}
/**
* 获取订单详情
* @throws MtSqtException
*/
public void obtainOrderDetail(MtOrderResult mtOrderResult) throws MtSqtException {
OrderDetailQueryRequest orderDetailRequest = new OrderDetailQueryRequest();
orderDetailRequest.setTs(System.currentTimeMillis());
orderDetailRequest.setEntId(sqtClient.getEntId());
orderDetailRequest.setSqtBizOrderId(mtOrderResult.getSqtBizOrderId());
BaseApiResponse<OrderDetailQueryResult> response = sqtClient.invokeApi(MeiTuanOrderConstants.orderDetailUrl, orderDetailRequest, null, null);
if (response!=null){
// 4. 获取结果
if(Objects.equals(ResponseStatusEnum.SUCCESS.getCode(), response.getStatus())) {
// 4.1 成功,获取订单详情查询结果
OrderDetailQueryResult realData = response.getRealData();
if (realData!=null){
// 赋值下单场景
OrderDetailQueryResult.OrderBaseInfo baseInfo = realData.getBaseInfo();
if (baseInfo!=null){
mtOrderResult.setSceneType(baseInfo.getSceneType());
mtOrderResult.setSceneTypeName(baseInfo.getSceneTypeName());
}
// 赋值员工部门
OrderDetailQueryResult.StaffInfo staffInfo = realData.getStaffInfo();
if (staffInfo!=null && !CollectionUtils.isEmpty(staffInfo.getStaffOrgInfo())){
for (OrderDetailQueryResult.StaffInfo.StaffOrgInfo staffOrgInfo : staffInfo.getStaffOrgInfo()) {
String orgIdPath = staffOrgInfo.getOrgIdPath();
String orgNamePath = staffOrgInfo.getOrgNamePath();
mtOrderResult.setOrgIdPath(orgIdPath);
mtOrderResult.setOrgNamePath(orgNamePath);
if (!StringUtils.isEmpty(orgIdPath)){
if (orgIdPath.contains("-")){
String lastOrgId = orgIdPath.substring(orgIdPath.lastIndexOf("-") + 1).trim();
mtOrderResult.setDirectOrgId(Long.valueOf(lastOrgId));
}else {
mtOrderResult.setDirectOrgId(Long.valueOf(orgIdPath));
}
}
if (!StringUtils.isEmpty(orgNamePath)){
if (orgNamePath.contains("-")){
String lastOrgName = orgNamePath.substring(orgNamePath.lastIndexOf("-") + 1).trim();
mtOrderResult.setDirectOrgName(lastOrgName);
}else {
mtOrderResult.setDirectOrgName(orgNamePath);
}
}
break;
}
}
// 赋值店铺信息
OrderDetailQueryResult.ShopInfo shopInfo = realData.getShopInfo();
if (shopInfo!=null){
mtOrderResult.setShopId(shopInfo.getShopId());
mtOrderResult.setShopName(shopInfo.getShopName());
mtOrderResult.setShopAddress(shopInfo.getShopAddress());
}
// 赋值消费人次 和 差旅入住天数
Integer sceneType = mtOrderResult.getSceneType();
if (sceneType!=null && sceneType==1){
// 商务宴请 获取报备信息 从而获取消费人数 和 人均消费金额
obtainReportDetail(mtOrderResult);
}
if (sceneType!=null && sceneType==3){
// 商务差旅 获取酒店入住天数
String origOrderInfo = realData.getOrigOrderInfo();
if (!StringUtils.isEmpty(origOrderInfo)){
HotelOrderDetail hotelOrderDetail = JsonUtil.json2Object(origOrderInfo, HotelOrderDetail.class);
if (hotelOrderDetail!=null){
HotelBaseInfo hotelBaseInfo = hotelOrderDetail.getHotelBaseInfo();
if (hotelBaseInfo!=null){
Integer roomCount = hotelBaseInfo.getRoomNightCount();
mtOrderResult.setConsumeCount(roomCount);
String avgNightAmount = hotelBaseInfo.getAvgNightAmount();
if (!StringUtils.isEmpty(avgNightAmount)){
mtOrderResult.setAvgConsumeAmount(new BigDecimal(avgNightAmount));
}
}
}
}
}
// 赋值是否超标
OrderDetailQueryResult.ControlInfo controlInfo = realData.getControlInfo();
if (controlInfo!=null && !CollectionUtils.isEmpty(controlInfo.getQuotaExceedLimitInfoList())){
List<OrderDetailQueryResult.ControlInfo.QuotaExceedLimitInfo> quotaExceedLimitInfoList = controlInfo.getQuotaExceedLimitInfoList();
for (OrderDetailQueryResult.ControlInfo.QuotaExceedLimitInfo quotaExceedLimitInfo : quotaExceedLimitInfoList) {
if ("avgPersonExceed".equals(quotaExceedLimitInfo.getQuotaCode())){
Integer isExceed = quotaExceedLimitInfo.getIsExceed();
if (isExceed==1){
mtOrderResult.setIsExceed(isExceed);
String exceedAmount = quotaExceedLimitInfo.getExceedAmount();
if (!StringUtils.isEmpty(exceedAmount)){
mtOrderResult.setExceedAmount(new BigDecimal(exceedAmount));
// 赋值餐饮标准
if (mtOrderResult.getAvgConsumeAmount()!=null){
mtOrderResult.setStandardAmount(mtOrderResult.getAvgConsumeAmount().subtract(mtOrderResult.getExceedAmount()));
}
}
}
break;
}
}
}
}
} else {
// 处理请求失败场景 打印日志 获取用餐事由失败
// 访问频率过高
if (ResponseStatusEnum.HIGH_FREQUENCY_ACCESS.getCode().intValue() == response.getStatus()) {
log.info("获取订单详情访问频率过高");
}
// 访问次数超过配额
if (ResponseStatusEnum.EXCEED_ACCESS_NUMBER.getCode().intValue() == response.getStatus()) {
}
// 其它失败场景
}
}
}
/**
* 报备详情查询
* 获取消费人数 和 人均消费金额
* @throws MtSqtException
*/
public void obtainReportDetail(MtOrderResult mtOrderResult) throws MtSqtException {
ReportDetailQueryRequest reportDetailRequest = new ReportDetailQueryRequest();
reportDetailRequest.setTs(System.currentTimeMillis());
reportDetailRequest.setEntId(sqtClient.getEntId());
reportDetailRequest.setSqtBizOrderId(mtOrderResult.getSqtBizOrderId());
BaseApiResponse<ReportDetailQueryResult> response = sqtClient.invokeApi(MeiTuanOrderConstants.reportDetailUrl, reportDetailRequest, null, null);
if (response!=null){
// 4. 获取结果
if(Objects.equals(ResponseStatusEnum.SUCCESS.getCode(), response.getStatus())) {
// 4.1 成功,获取订单列表查询结果
ReportDetailQueryResult realData = response.getRealData();
if (realData!=null && realData.getReportInfo()!=null){
ReportInfo reportInfo = realData.getReportInfo();
mtOrderResult.setConsumeCount(reportInfo.getNumOfConsumer());
String personAvgAmount = reportInfo.getPersonAvgAmount();
if (!StringUtils.isEmpty(personAvgAmount)){
mtOrderResult.setAvgConsumeAmount(new BigDecimal(personAvgAmount));
}
}
} else {
// 处理请求失败场景 打印日志 获取用餐事由失败
// 访问频率过高
if (ResponseStatusEnum.HIGH_FREQUENCY_ACCESS.getCode().intValue() == response.getStatus()) {
log.info("获取报备详情访问频率过高");
}
// 访问次数超过配额
if (ResponseStatusEnum.EXCEED_ACCESS_NUMBER.getCode().intValue() == response.getStatus()) {
}
// 其它失败场景
}
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!