2024-05-27 14:36:47 +08:00
|
|
|
|
package com.ruoyi.system.task;
|
|
|
|
|
|
2024-06-05 18:12:19 +08:00
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
2024-07-29 10:01:17 +08:00
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
2024-05-31 15:11:26 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
2024-08-28 21:43:56 +08:00
|
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
2024-10-07 09:51:22 +08:00
|
|
|
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
2024-08-30 17:51:58 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
2024-09-02 17:16:26 +08:00
|
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.constant.ServiceConstants;
|
2024-06-05 18:12:19 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.entity.AsUser;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
2024-06-05 18:12:19 +08:00
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
2024-08-28 21:43:56 +08:00
|
|
|
|
import com.ruoyi.common.utils.CommonUtil;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
2024-10-07 09:51:22 +08:00
|
|
|
|
import com.ruoyi.common.utils.SendAliSmsUtil;
|
|
|
|
|
import com.ruoyi.common.utils.SendSmsVo;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import com.ruoyi.common.utils.http.HttpUtils;
|
2024-07-29 10:01:17 +08:00
|
|
|
|
import com.ruoyi.common.utils.map.GeoUtils;
|
2024-08-28 21:43:56 +08:00
|
|
|
|
import com.ruoyi.common.utils.map.GpsCoordinateUtils;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import com.ruoyi.common.utils.onenet.CreateDeviceVo;
|
|
|
|
|
import com.ruoyi.common.utils.onenet.DeviceInfo;
|
2024-08-28 21:43:56 +08:00
|
|
|
|
import com.ruoyi.common.utils.onenet.LogEntry;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import com.ruoyi.common.utils.onenet.Token;
|
2024-07-08 14:18:58 +08:00
|
|
|
|
import com.ruoyi.common.utils.uuid.IdUtils;
|
2024-06-05 18:12:19 +08:00
|
|
|
|
import com.ruoyi.system.domain.*;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import com.ruoyi.system.domain.vo.AsDeviceVO;
|
2024-10-04 16:07:44 +08:00
|
|
|
|
import com.ruoyi.system.domain.vo.SelfReconciliationVO;
|
2024-08-21 17:22:14 +08:00
|
|
|
|
import com.ruoyi.system.mapper.*;
|
2024-06-05 18:12:19 +08:00
|
|
|
|
import com.ruoyi.system.service.*;
|
|
|
|
|
import com.wechat.pay.java.service.refund.model.Refund;
|
2024-10-04 16:07:44 +08:00
|
|
|
|
import lombok.SneakyThrows;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-08-28 21:43:56 +08:00
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import org.springframework.stereotype.Component;
|
2024-06-05 18:12:19 +08:00
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
|
2024-06-03 21:13:59 +08:00
|
|
|
|
import javax.annotation.PostConstruct;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import javax.annotation.Resource;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import java.io.UnsupportedEncodingException;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import java.math.BigDecimal;
|
2024-08-28 21:43:56 +08:00
|
|
|
|
import java.math.RoundingMode;
|
2024-09-27 17:28:47 +08:00
|
|
|
|
import java.security.InvalidKeyException;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
2024-10-04 16:07:44 +08:00
|
|
|
|
import java.text.SimpleDateFormat;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
2024-08-29 15:18:01 +08:00
|
|
|
|
import java.util.*;
|
2024-06-05 09:16:59 +08:00
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2024-05-28 16:55:38 +08:00
|
|
|
|
import java.util.stream.IntStream;
|
2024-05-27 14:36:47 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 定时任务调度测试
|
|
|
|
|
*
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component("etTask")
|
|
|
|
|
public class EtTask {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private EtOrderMapper etOrderMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IEtOperatingAreaService etOperatingAreaService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private SysUserMapper userMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IEtDividendDetailService dividendDetailService;
|
|
|
|
|
|
2024-06-05 09:16:59 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private ScheduledExecutorService scheduledExecutorService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IEtOrderService etOrderService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AsDeviceMapper asDeviceMapper;
|
|
|
|
|
|
2024-06-05 18:12:19 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private IWxPayService wxPayService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IEtRefundService etRefundService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AsUserMapper asUserMapper;
|
|
|
|
|
|
2024-08-21 17:22:14 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private EtLocationLogMapper etLocationLogMapper;
|
|
|
|
|
|
2024-08-30 17:51:58 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private IAsDeviceService deviceService;
|
|
|
|
|
|
2024-08-28 21:43:56 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
private IEtModelService etModelService;
|
|
|
|
|
|
2024-10-07 09:51:22 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private EtModelMapper etModelMapper;
|
|
|
|
|
|
2024-09-04 08:43:06 +08:00
|
|
|
|
@Resource
|
2024-09-03 15:54:11 +08:00
|
|
|
|
private EtCouponClaimLogMapper etCouponClaimLogMapper;
|
|
|
|
|
|
2024-10-04 16:07:44 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private EtCapitalFlowMapper etCapitalFlowMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private EtReconciliationMapper etReconciliationMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private EtChannelService smEtChannelService;
|
|
|
|
|
|
2024-10-07 09:51:22 +08:00
|
|
|
|
@Resource
|
|
|
|
|
private EtModelRuleMapper etModelRuleMapper;
|
|
|
|
|
|
2024-09-27 17:28:47 +08:00
|
|
|
|
@Value(value = "${iot.deviceUrl}")
|
|
|
|
|
private String deviceUrl;
|
|
|
|
|
|
|
|
|
|
@Value(value = "${iot.productId}")
|
|
|
|
|
private String productId;
|
|
|
|
|
|
2024-10-07 09:51:22 +08:00
|
|
|
|
@Value("${aliyun.accessKeyId}")
|
|
|
|
|
private String accessKeyId;
|
|
|
|
|
|
|
|
|
|
@Value("${aliyun.accessKeySecret}")
|
|
|
|
|
private String accessKeySecret;
|
|
|
|
|
|
|
|
|
|
@Value("${aliyun.signName}")
|
|
|
|
|
private String signName;
|
|
|
|
|
|
|
|
|
|
@Value("${aliyun.templateCode}")
|
|
|
|
|
private String templateCode;
|
|
|
|
|
|
2024-08-28 21:43:56 +08:00
|
|
|
|
|
2024-06-03 21:13:59 +08:00
|
|
|
|
/**
|
2024-06-05 09:16:59 +08:00
|
|
|
|
* 1.启动时判断是否有未取消预约的订单
|
|
|
|
|
* 2.判断已完成的订单未退还押金的
|
2024-06-05 18:12:19 +08:00
|
|
|
|
* 3.启动时判断是否分账
|
2024-06-03 21:13:59 +08:00
|
|
|
|
*/
|
2024-06-05 18:12:19 +08:00
|
|
|
|
@Transactional
|
2024-06-18 16:11:26 +08:00
|
|
|
|
@PostConstruct
|
2024-06-03 21:13:59 +08:00
|
|
|
|
public void init() {
|
2024-06-05 18:12:19 +08:00
|
|
|
|
log.info("=========================启动业务处理=========================");
|
|
|
|
|
log.info("=========================开始=========================");
|
|
|
|
|
/** 1.启动时判断是否有未取消预约的订单*/
|
2024-08-15 20:34:29 +08:00
|
|
|
|
// uncancelledAppointmentHandle();
|
2024-06-05 18:12:19 +08:00
|
|
|
|
|
|
|
|
|
/** 2.判断已完成的订单未退还押金的(根据et_refund表中的refund_result结果判断是否已经退款) */
|
|
|
|
|
/** ①找出所有已完成的订单 status=4 type = 1 r.refund_result IS NULL
|
|
|
|
|
* ②根据用户查询最后一次押金充值记录
|
|
|
|
|
*/
|
|
|
|
|
List<EtOrder> orders = etOrderMapper.selectUserListFinishOrder();
|
2024-06-18 17:11:55 +08:00
|
|
|
|
log.info("已完成的订单未退还押金的的订单 = " + JSON.toJSONString(orders));
|
2024-06-05 18:12:19 +08:00
|
|
|
|
for(EtOrder order:orders){
|
2024-09-04 08:43:06 +08:00
|
|
|
|
// EtFeeRule rule = etFeeRuleService.selectEtFeeRuleByRuleIdIncludeDelete(order.getRuleId());
|
|
|
|
|
// if(ObjectUtil.isNull(rule)){
|
|
|
|
|
// throw new ServiceException("骑行订单:【"+order.getOrderNo()+"】未找到该套餐【"+order.getRuleId()+"】");
|
|
|
|
|
// }
|
2024-06-05 18:12:19 +08:00
|
|
|
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
|
|
|
|
AsUser asUser = asUserMapper.selectUserById(order.getUserId());
|
2024-09-04 08:43:06 +08:00
|
|
|
|
Integer autoRefundDeposit = order.getAutoRefundDeposit();
|
2024-06-05 18:12:19 +08:00
|
|
|
|
|
|
|
|
|
// 根据用户查询最后一次押金充值订单
|
|
|
|
|
EtOrder etOrder = new EtOrder();
|
|
|
|
|
etOrder.setUserId(order.getUserId());
|
|
|
|
|
etOrder.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
|
|
|
|
|
etOrder.setType(ServiceConstants.ORDER_TYPE_DEPOSIT);
|
|
|
|
|
etOrder.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
|
|
|
|
List<EtOrder> etOrders = etOrderMapper.selectEtOrderList(etOrder);
|
|
|
|
|
if (etOrders.size() > 0 || ObjectUtil.isNotNull(etOrders) ) {
|
|
|
|
|
Optional<EtOrder> latestOrderOptional = etOrders.stream()
|
|
|
|
|
.max(Comparator.comparing(EtOrder::getPayTime));
|
|
|
|
|
if (latestOrderOptional.isPresent()) {
|
|
|
|
|
EtOrder lastOrder = latestOrderOptional.get();
|
|
|
|
|
log.info("【系统启动】用户【{}】最后一次押金充值订单 : " + JSON.toJSONString(lastOrder),asUser.getUserId());
|
|
|
|
|
if(lastOrder.getTotalFee().compareTo(new BigDecimal(area.getDeposit()))!=0){
|
|
|
|
|
log.info("【系统启动】最后一次押金充值记录 金额与押金不一致,订单押金:【{}】,区域押金:【{}】",lastOrder.getTotalFee(),area.getDeposit());
|
|
|
|
|
}else{
|
|
|
|
|
// 根据最新的订单号,查询是否有退款记录
|
2024-07-08 14:18:58 +08:00
|
|
|
|
List<EtRefund> etRefunds = etRefundService.selectEtRefundByOrderNo(lastOrder.getOrderNo());
|
|
|
|
|
if(etRefunds.size() == 1){
|
|
|
|
|
EtRefund etRefund = etRefunds.get(0);
|
|
|
|
|
// 没有退款记录,发起退款
|
|
|
|
|
if(ObjectUtil.isNull(etRefund)){
|
|
|
|
|
// 根据订单支付时间 autoRefundDeposit个小时后退押金
|
|
|
|
|
String reason = autoRefundDeposit + "个小时后自动退押金";
|
|
|
|
|
Date payTime = order.getPayTime();
|
|
|
|
|
Date refundDepositTime = DateUtils.getTimeAfterXHours(payTime, autoRefundDeposit);
|
|
|
|
|
Date nowDate = DateUtils.getNowDate();
|
|
|
|
|
if (nowDate.after(refundDepositTime)) {
|
|
|
|
|
log.info("【系统启动】用户【{}】押金充值订单【{}】已过期,开始自动退押金",asUser.getUserId(),lastOrder.getOrderNo());
|
2024-06-05 18:12:19 +08:00
|
|
|
|
refundDeposit(asUser, lastOrder, reason);
|
2024-07-08 14:18:58 +08:00
|
|
|
|
}else{
|
|
|
|
|
int timeDifferenceInMinutes = DateUtils.timeDifferenceInMinutes(payTime, nowDate);
|
|
|
|
|
int i = autoRefundDeposit * 60;
|
|
|
|
|
int delay = i - timeDifferenceInMinutes;
|
|
|
|
|
log.info("【系统启动】用户【{}】押金充值订单【{}】未过期,【{}】分钟后退押金",asUser.getUserId(),lastOrder.getOrderNo(),delay);
|
|
|
|
|
scheduledExecutorService.schedule(() -> {
|
|
|
|
|
refundDeposit(asUser, lastOrder, reason);
|
|
|
|
|
}, delay, TimeUnit.MINUTES);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
// 有退款记录,判断是否成功
|
|
|
|
|
if(!Constants.SUCCESS2.equals(etRefund.getRefundResult())){
|
|
|
|
|
log.info("【系统启动】押金退款未成功回调,退款单号:【{}】",etRefund.getRefundNo());
|
|
|
|
|
// 根据退款单号查询退款信息
|
2024-09-14 15:45:45 +08:00
|
|
|
|
Refund refund = wxPayService.queryByOutRefundNo(etRefund.getRefundNo());
|
2024-07-08 14:18:58 +08:00
|
|
|
|
if(ObjectUtil.isNotNull(refund) && Constants.SUCCESS2.equals(refund.getStatus().name())){
|
|
|
|
|
// 更新退款记录
|
|
|
|
|
etRefund.setRefundResult(Constants.SUCCESS2);
|
|
|
|
|
etRefund.setUpdateTime(new Date());
|
|
|
|
|
etRefundService.updateEtRefund(etRefund);
|
|
|
|
|
log.info("【系统启动】更新押金退款回调成功,退款单号:【{}】",refund.getOutRefundNo());
|
|
|
|
|
}
|
2024-06-05 18:12:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-08 14:18:58 +08:00
|
|
|
|
|
2024-06-05 18:12:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 3.启动时判断是否分账(根据订单号查询分账明细表是否有记录来判断是否分账) */
|
|
|
|
|
/** ①找出所有已完成的骑行订单 status=4 type = 1 r.refund_result IS NULL
|
|
|
|
|
* ②根据订单号查询分账明细表是否有记录
|
|
|
|
|
* 有记录则已经分账过
|
|
|
|
|
* 没值代表还未分账
|
|
|
|
|
* 判断是否已过分账时间
|
|
|
|
|
* 未过,计算出多少小时后分账
|
|
|
|
|
* 已过,直接分账(记录分账明细表)
|
|
|
|
|
*/
|
|
|
|
|
// 查询所有待分账的订单
|
2024-08-14 10:54:13 +08:00
|
|
|
|
// List<EtOrder> needDividendOrders = etOrderMapper.selectNeedDividendOrder();
|
|
|
|
|
// for(EtOrder order: needDividendOrders){
|
|
|
|
|
// log.info("【系统启动】待分账订单:【{}】",order.getOrderNo());
|
|
|
|
|
// EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
|
|
|
|
// if(dividendDetailService.isDividendComputedByOrderNo(order.getOrderNo())){
|
|
|
|
|
// log.info("订单【{}】已经分账",order.getOrderNo());
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// log.info("【系统启动】骑行订单【{}】未分账,开始分账",order.getOrderNo());
|
|
|
|
|
// Date payTime = order.getPayTime();
|
|
|
|
|
// Date dividendTime = DateUtils.getTimeAfterXHours(payTime, 24);//分账时间
|
|
|
|
|
// Date nowDate = DateUtils.getNowDate();
|
|
|
|
|
// if (nowDate.after(dividendTime)) {
|
|
|
|
|
// log.info("【系统启动】骑行订单【{}】已过分账时间,开始分账",order.getOrderNo());
|
|
|
|
|
// // 请求分账处理
|
|
|
|
|
// Transaction transaction = wxPayService.queryOrderByOutTradeNo(order.getOrderNo());
|
|
|
|
|
//// if (callbackService.dividendHandle(transaction.getTransactionId(), order, area)) break;
|
|
|
|
|
// }else{
|
|
|
|
|
// int timeDifferenceInHours = DateUtils.timeDifferenceInHours(payTime, nowDate);
|
|
|
|
|
// int delay = 24 - timeDifferenceInHours;
|
|
|
|
|
// log.info("【系统启动】骑行订单【{}】未过分账时间,【{}】小时后开始分账",order.getOrderNo(),delay);
|
|
|
|
|
// // 24小时后发起分账
|
|
|
|
|
//// scheduledExecutorService.schedule(() -> {
|
|
|
|
|
//// // 请求分账处理
|
|
|
|
|
//// Transaction transaction = wxPayService.queryOrderByOutTradeNo(order.getOrderNo());
|
|
|
|
|
//// if (callbackService.dividendHandle(transaction.getTransactionId(), order, area)) return;
|
|
|
|
|
//// }, delay , TimeUnit.HOURS);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// log.info("=========================结束=========================");
|
2024-06-05 18:12:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refundDeposit(AsUser asUser, EtOrder lastOrder, String reason) {
|
2024-07-08 14:18:58 +08:00
|
|
|
|
String outRefundNo = IdUtils.getOrderNo("ref");
|
2024-06-05 18:12:19 +08:00
|
|
|
|
lastOrder.setReason(reason);
|
2024-07-08 14:18:58 +08:00
|
|
|
|
EtRefund refund1= etOrderService.createRefund(lastOrder, lastOrder.getTotalFee(), null, null, null, null, outRefundNo,ServiceConstants.REFUND_TYPE_DEPOSIT);
|
2024-06-05 18:12:19 +08:00
|
|
|
|
if(etRefundService.insertEtRefund(refund1)>0){
|
|
|
|
|
log.info("【自动退款】保存退款对象成功");
|
|
|
|
|
// 新增资金流水记录
|
2024-07-08 14:18:58 +08:00
|
|
|
|
// callbackService.capitalFlowRecords(lastOrder,ServiceConstants.FLOW_TYPE_DISBURSE,ServiceConstants.ORDER_TYPE_DEPOSIT_REFUND);
|
2024-06-05 18:12:19 +08:00
|
|
|
|
// 更新用户信息,清除缓存
|
|
|
|
|
asUser.setBalance(BigDecimal.ZERO);
|
|
|
|
|
int updateUser = asUserMapper.updateUser(asUser);
|
|
|
|
|
if(updateUser>0){
|
2024-06-25 09:25:38 +08:00
|
|
|
|
// Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.APP_LOGIN_TOKEN_KEY + "*");
|
|
|
|
|
// redisCache.deleteObject(keys);
|
2024-06-05 18:12:19 +08:00
|
|
|
|
log.info("【系统启动】退还押金,更新用户余额成功!");
|
|
|
|
|
}
|
2024-09-13 20:27:36 +08:00
|
|
|
|
wxPayService.refund(lastOrder, reason, lastOrder.getTotalFee(),outRefundNo);
|
2024-06-05 18:12:19 +08:00
|
|
|
|
log.info("=================【系统启动】退还押金定时任务结束!!!==================");
|
|
|
|
|
}else{
|
|
|
|
|
throw new ServiceException("【系统启动】保存退款对象失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void uncancelledAppointmentHandle() {
|
2024-06-05 09:16:59 +08:00
|
|
|
|
List<EtOrder> orders= etOrderMapper.selectAppointmentUnfinished();
|
|
|
|
|
log.info("预约未完成的订单 = " + JSON.toJSONString(orders));
|
|
|
|
|
for (EtOrder order:orders) {
|
|
|
|
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order.getAreaId());
|
|
|
|
|
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(order.getSn());
|
|
|
|
|
Date appointmentEndTime = DateUtils.getTimeAfterXMinutes(order.getAppointmentStartTime(), area.getTimeoutMinutes());//预约结束时间
|
|
|
|
|
int timeDifferenceInSeconds = DateUtils.timeDifferenceInSeconds(appointmentEndTime, order.getAppointmentStartTime());//(超时时间-开始时间)的秒数
|
|
|
|
|
int differenceInSeconds = DateUtils.timeDifferenceInSeconds(new Date(), order.getAppointmentStartTime());//(当前时间-开始时间)的秒数
|
|
|
|
|
int delay = timeDifferenceInSeconds - differenceInSeconds;
|
|
|
|
|
log.info("【定时取消预约】延迟:【{}】秒", delay);
|
|
|
|
|
//定时取消预约
|
|
|
|
|
scheduledExecutorService.schedule(() -> {
|
|
|
|
|
log.error("【车辆超时预约】系统自动取消");
|
|
|
|
|
EtOrder order1 = etOrderService.selectEtOrderByOrderNo(order.getOrderNo());
|
|
|
|
|
log.info("【定时取消预约】重新获取订单信息:{}",JSON.toJSON(order1));
|
|
|
|
|
if(order1.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_PAID)){//已支付订单,跳过
|
|
|
|
|
log.error("【车辆超时预约】订单已支付,跳过");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
log.error("【车辆超时预约】订单未支付,系统自动处理");
|
|
|
|
|
//未支付 订单更新最后预约时间,并结束订单,做超出预约时间标记
|
|
|
|
|
order.setStatus(ServiceConstants.ORDER_STATUS_CANCEL_APPOINTMENT);
|
|
|
|
|
order.setAppointmentEndTime(new Date());
|
|
|
|
|
order.setAppointmentTimeout("1");
|
|
|
|
|
//计算预约费
|
|
|
|
|
BigDecimal appointmentServiceFee = area.getAppointmentServiceFee();
|
|
|
|
|
BigDecimal fee = appointmentServiceFee.multiply(new BigDecimal(area.getTimeoutMinutes()).divide(new BigDecimal(10)));
|
|
|
|
|
order.setAppointmentFee(fee);
|
|
|
|
|
order.setTotalFee(fee);
|
2024-06-19 19:31:59 +08:00
|
|
|
|
order.setPayFee(fee);
|
2024-06-05 09:16:59 +08:00
|
|
|
|
int update = etOrderService.updateEtOrder(order);
|
|
|
|
|
if(update==0){
|
|
|
|
|
throw new ServiceException("【车辆超时预约】:更新订单状态失败");
|
|
|
|
|
}
|
|
|
|
|
// 改变车辆状态
|
|
|
|
|
asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);
|
|
|
|
|
asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN);
|
|
|
|
|
int device = asDeviceMapper.updateAsDevice(asDevice);
|
|
|
|
|
if(device==0){
|
|
|
|
|
log.error("【车辆超时预约】更新车辆状态失败");
|
|
|
|
|
throw new ServiceException("【车辆超时预约】更新车辆状态失败");
|
|
|
|
|
}
|
|
|
|
|
}, delay, TimeUnit.SECONDS);
|
|
|
|
|
}
|
2024-06-03 21:13:59 +08:00
|
|
|
|
}
|
2024-05-27 14:36:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* 每天凌晨0点5分执行,计算分账结果
|
|
|
|
|
* cron: 0 5 0 * * ?
|
|
|
|
|
*/
|
|
|
|
|
public void computeDividend()
|
|
|
|
|
{
|
|
|
|
|
log.info("每天凌晨0点5分执行,计算分账结果");
|
|
|
|
|
// 获取昨天的订单,2024-05-26 00:00:00 -- 2024-05-26 23:59:59
|
|
|
|
|
// 获取昨天日期格式: yyyy-MM-dd
|
|
|
|
|
|
|
|
|
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
String formattedYesterday = yesterday.format(formatter);
|
|
|
|
|
log.info("获取昨天日期 = " + formattedYesterday);
|
|
|
|
|
|
|
|
|
|
//判断该日期是否已经计算过分账结果
|
|
|
|
|
if(dividendDetailService.isDividendComputed(LocalDate.now().format(formatter))){
|
|
|
|
|
log.info("该日期已经计算过分账结果");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String startDateStr = formattedYesterday + " "+ Constants.DATE_FORMAT_START_PEREND;
|
|
|
|
|
String endDateStr = formattedYesterday + " " +Constants.DATE_FORMAT_END_PEREND;
|
|
|
|
|
|
|
|
|
|
EtOrder order = new EtOrder();
|
|
|
|
|
order.setStartTime(startDateStr);
|
|
|
|
|
order.setEndTime(endDateStr);
|
|
|
|
|
order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
|
|
|
|
|
order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
2024-05-28 16:55:38 +08:00
|
|
|
|
order.setType(ServiceConstants.ORDER_TYPE_RIDING);
|
2024-05-27 14:36:47 +08:00
|
|
|
|
List<EtOrder> orderListByDate = etOrderMapper.selectEtOrderList(order);
|
|
|
|
|
for(EtOrder order1:orderListByDate){
|
|
|
|
|
EtDividendDetail etDividendDetail = new EtDividendDetail();
|
|
|
|
|
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(order1.getAreaId());
|
|
|
|
|
|
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
|
|
sysUser.setUserType("03");
|
|
|
|
|
sysUser.setAreaId(area.getAreaId());
|
|
|
|
|
List<SysUser> sysUsers = userMapper.selectUserList(sysUser);
|
|
|
|
|
for(SysUser user : sysUsers){
|
|
|
|
|
etDividendDetail.setAreaId(area.getAreaId());
|
|
|
|
|
etDividendDetail.setPartnerId(user.getUserId());
|
|
|
|
|
etDividendDetail.setOrderNo(order1.getOrderNo());
|
|
|
|
|
etDividendDetail.setTotalAmount(order1.getTotalFee());
|
|
|
|
|
etDividendDetail.setCreateTime(DateUtils.getNowDate());
|
2024-05-28 16:55:38 +08:00
|
|
|
|
etDividendDetail.setDividendProportion(user.getDividendProportion());
|
2024-05-31 15:11:26 +08:00
|
|
|
|
String dividendItem = user.getDividendItem();
|
|
|
|
|
// todo 分账金额是骑行费,还是调度费,看分账项目 分账项目:1-骑行费(骑行费+预约费);2-调度费(调度费+管理费)
|
|
|
|
|
BigDecimal dividendAmount = BigDecimal.ZERO;
|
|
|
|
|
if(dividendItem.contains("1")){
|
|
|
|
|
dividendAmount.add(order1.getRidingFee().add(order1.getAppointmentFee()));//1-骑行费(骑行费+预约费)
|
|
|
|
|
}else if(dividendItem.contains("2")){
|
2024-06-26 14:57:34 +08:00
|
|
|
|
dividendAmount.add(order1.getManageFee().add(order1.getManageFee()));//2-调度费(调度费+停车点外调度费)
|
2024-05-31 15:11:26 +08:00
|
|
|
|
}
|
|
|
|
|
BigDecimal divide = new BigDecimal(user.getDividendProportion()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
etDividendDetail.setDividendAmount(dividendAmount.multiply(divide));
|
|
|
|
|
etDividendDetail.setDividendItem(dividendItem);
|
|
|
|
|
log.info("保存分账明细 === " + JSON.toJSONString(etDividendDetail));
|
2024-05-27 14:36:47 +08:00
|
|
|
|
int i = dividendDetailService.insertEtDividendDetail(etDividendDetail);
|
|
|
|
|
if(i==0){
|
|
|
|
|
throw new ServiceException("保存分账明细失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 16:55:38 +08:00
|
|
|
|
int totalDividendProportion = IntStream.of(sysUsers.stream()
|
|
|
|
|
.mapToInt(SysUser::getDividendProportion)
|
|
|
|
|
.toArray())
|
|
|
|
|
.sum();
|
|
|
|
|
//算运营商自己的分账
|
|
|
|
|
etDividendDetail.setAreaId(area.getAreaId());
|
|
|
|
|
etDividendDetail.setPartnerId(0L);
|
|
|
|
|
etDividendDetail.setOrderNo(order1.getOrderNo());
|
|
|
|
|
etDividendDetail.setTotalAmount(order1.getTotalFee());
|
|
|
|
|
etDividendDetail.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
etDividendDetail.setDividendAmount(order1.getTotalFee().multiply(new BigDecimal(100-totalDividendProportion).divide(new BigDecimal(100),2, BigDecimal.ROUND_HALF_UP)));
|
|
|
|
|
etDividendDetail.setDividendProportion(100-totalDividendProportion);
|
|
|
|
|
etDividendDetail.setDividendItem("运营商");
|
|
|
|
|
int i = dividendDetailService.insertEtDividendDetail(etDividendDetail);
|
|
|
|
|
if(i==0){
|
|
|
|
|
throw new ServiceException("保存分账明细失败");
|
|
|
|
|
}
|
2024-05-27 14:36:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 10:01:17 +08:00
|
|
|
|
/**
|
2024-08-30 17:51:58 +08:00
|
|
|
|
* 开始骑行未结束的订单,1分钟算一次距离
|
2024-07-29 10:01:17 +08:00
|
|
|
|
* cron: 0 5 0 * * ?
|
|
|
|
|
*/
|
|
|
|
|
public void computeDistance(){
|
|
|
|
|
log.info("-------------------【定时任务】计算订单距离开始-------------------");
|
|
|
|
|
EtOrder order = new EtOrder();
|
|
|
|
|
order.setType("1");
|
|
|
|
|
order.setStatus(ServiceConstants.ORDER_STATUS_RIDING);
|
|
|
|
|
List<EtOrder> orders = etOrderService.selectEtOrderList(order);
|
|
|
|
|
for(EtOrder etOrder:orders){
|
2024-08-30 17:51:58 +08:00
|
|
|
|
String endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getNowDate());
|
|
|
|
|
String startTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, etOrder.getUnlockTime());
|
|
|
|
|
String tripRouteStr = deviceService.trajectory(etOrder.getSn(), startTime, endTime);
|
2024-07-29 10:01:17 +08:00
|
|
|
|
if(StrUtil.isNotBlank(tripRouteStr)){
|
|
|
|
|
double[][] doubles = GeoUtils.parseJsonTrack(tripRouteStr);
|
|
|
|
|
double v = GeoUtils.calculateTotalDistance(doubles);
|
2024-09-16 14:14:46 +08:00
|
|
|
|
EtOrder etOrder1 = new EtOrder();
|
|
|
|
|
etOrder1.setOrderId(etOrder.getOrderId());
|
|
|
|
|
etOrder1.setDistance((int)Math.round(v));
|
|
|
|
|
int updateEtOrder = etOrderService.updateEtOrder(etOrder1);
|
2024-07-29 10:01:17 +08:00
|
|
|
|
if(updateEtOrder>0){
|
|
|
|
|
log.info("【定时任务】计算订单距离成功:【orderNo="+etOrder.getOrderNo()+"】");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 17:22:14 +08:00
|
|
|
|
/**
|
|
|
|
|
* 一个星期删除一次onenet心跳日志
|
|
|
|
|
* cron: 0 5 0 * * ?
|
|
|
|
|
*
|
|
|
|
|
* DELETE FROM et_location_log
|
|
|
|
|
* WHERE create_time < NOW() - INTERVAL 7 DAY;
|
|
|
|
|
*/
|
|
|
|
|
public void deleteLocationLog(){
|
|
|
|
|
log.info("-------------------【定时任务】删除onenet心跳日志-------------------");
|
|
|
|
|
etLocationLogMapper.deleteLocationLogByCreateTime();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-30 17:51:58 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 车辆与订单状态同步
|
|
|
|
|
* 1. 如果有正在骑行中的订单,车辆的状态是待骑行的,改成临时锁车,不发命令
|
|
|
|
|
* 2. 如果车辆状态是骑行中或临时锁车,查询订单没有订单,则修改车辆状态为待骑行
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void stausSynchronization(){
|
|
|
|
|
log.info("-------------------【定时任务】车辆与订单状态同步-------------------");
|
|
|
|
|
// 当前有骑行中的订单
|
|
|
|
|
List<EtOrder> orders = etOrderService.getCurrentOrderList();
|
|
|
|
|
for (EtOrder order:orders) {
|
|
|
|
|
AsDevice device = asDeviceMapper.selectAsDeviceBySn(order.getSn());
|
|
|
|
|
if(ObjectUtil.isNotNull(device) && device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_NORMAL)){
|
|
|
|
|
AsDevice device1 = new AsDevice();
|
|
|
|
|
device1.setSn(device.getSn());
|
|
|
|
|
device1.setStatus(ServiceConstants.VEHICLE_STATUS_TEMPORARILY_LOCK);
|
|
|
|
|
device1.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
|
|
|
|
|
int i = asDeviceMapper.updateAsDeviceBySn(device1);
|
|
|
|
|
if(i>0){
|
|
|
|
|
log.info("【定时任务】车辆状态修改为临时锁车:【sn="+device.getSn()+"】");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. 如果车辆状态是骑行中或临时锁车,查询当前没有订单,则修改车辆状态为待骑行
|
|
|
|
|
QueryWrapper<AsDevice> wrapper = new QueryWrapper<>();
|
|
|
|
|
wrapper.in("status", "3","4"); // 设备状态正常
|
|
|
|
|
// 查询所有设备
|
|
|
|
|
List<AsDevice> allDevices = asDeviceMapper.selectList(wrapper);
|
|
|
|
|
for(AsDevice device:allDevices){
|
2024-08-31 16:08:15 +08:00
|
|
|
|
if(ObjectUtil.isNotNull(etOrderService.getCurrentOrder2(device.getSn()))){
|
2024-08-30 17:51:58 +08:00
|
|
|
|
continue;
|
|
|
|
|
}else{
|
|
|
|
|
AsDevice device1 = new AsDevice();
|
|
|
|
|
device1.setSn(device.getSn());
|
|
|
|
|
device1.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL);
|
|
|
|
|
device1.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE);
|
|
|
|
|
int i = asDeviceMapper.updateAsDeviceBySn(device1);
|
|
|
|
|
if(i>0){
|
|
|
|
|
log.info("【定时任务】车辆状态修改为待骑行:【sn="+device.getSn()+"】");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:47:44 +08:00
|
|
|
|
// 写一个定时,如果车辆是骑行中,没有现在骑行中的订单,则关闭车辆
|
|
|
|
|
/**
|
|
|
|
|
* 自动押金抵扣
|
|
|
|
|
* 写一个定时任务处理所有的 7天前待支付的订单用押金抵扣,如果已经退押金的直接改成结束订单
|
|
|
|
|
* 1. 查询所有待支付的订单,根据还车时间7天前的订单
|
|
|
|
|
* 2. 如果订单金额是0,直接结束订单,修改订单状态为已支付
|
|
|
|
|
* 3. 查询用户是否还有未退款的押金,如果有,则进行押金抵扣,如果没有,则结束订单
|
|
|
|
|
*/
|
|
|
|
|
public void autoDeduction(){
|
|
|
|
|
log.info("-------------------【定时任务】自动押金抵扣-------------------");
|
|
|
|
|
/** 1. 查询所有待支付的订单,根据还车时间7天前的订单 */
|
|
|
|
|
List<EtOrder> orders = etOrderMapper.selectToBePaidEtOrderList();
|
|
|
|
|
if(ObjectUtil.isNotNull(orders) && orders.size()>0){
|
|
|
|
|
for(EtOrder order:orders){
|
|
|
|
|
if(order.getTotalFee().compareTo(BigDecimal.ZERO) == 0){
|
|
|
|
|
// 结束订单,修改订单状态为已支付
|
|
|
|
|
updateOrderPaid(order);
|
|
|
|
|
}else{
|
|
|
|
|
etOrderService.deduction(order);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-02 10:55:31 +08:00
|
|
|
|
/**
|
|
|
|
|
* 押金抵扣不成功的修复
|
|
|
|
|
* 1. 找出所有押金抵扣不成功的订单
|
|
|
|
|
* 2. 将状态改成已结束
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void deductionErrorOrder(){
|
|
|
|
|
log.info("-------------------【定时任务】押金抵扣不成功的修复---开始----------------");
|
|
|
|
|
List<EtOrder> orders = etOrderMapper.deductionErrorOrderList();
|
|
|
|
|
for (EtOrder order:orders) {
|
|
|
|
|
EtOrder order1 = new EtOrder();
|
|
|
|
|
order1.setOrderId(order.getOrderId());
|
|
|
|
|
order1.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
|
|
|
|
order1.setMark("押金抵扣修复,订单已结束");
|
|
|
|
|
etOrderMapper.updateEtOrder(order1);
|
|
|
|
|
}
|
|
|
|
|
log.info("-------------------【定时任务】押金抵扣不成功的修复---结束----------------");
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 16:47:44 +08:00
|
|
|
|
/** 更新订单为已支付*/
|
|
|
|
|
private void updateOrderPaid(EtOrder order) {
|
2024-09-16 14:14:46 +08:00
|
|
|
|
EtOrder order1 = new EtOrder();
|
|
|
|
|
order1.setOrderId(order.getOrderId());
|
|
|
|
|
order1.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID);
|
|
|
|
|
order1.setPayTime(DateUtils.getNowDate());
|
|
|
|
|
order1.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END);
|
|
|
|
|
order1.setPayType(ServiceConstants.PAY_TYPE_YJ);
|
|
|
|
|
order1.setMark("超过7天系统自动押金抵扣");
|
|
|
|
|
order1.setDepositDeduction(ServiceConstants.IS_DEPOSIT_DEDUCTION);
|
|
|
|
|
int updateEtOrder = etOrderMapper.updateEtOrder(order1);
|
2024-08-28 16:47:44 +08:00
|
|
|
|
if(updateEtOrder == 0){
|
|
|
|
|
throw new ServiceException("押金抵扣失败,更新骑行订单失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 如果还有未退款的押金,如果有,则进行押金抵扣 */
|
|
|
|
|
private void autoDeductionHandle(EtOrder order){
|
|
|
|
|
// select * from et_order o
|
|
|
|
|
// where o.status ='4' and o.paid = '1' and o.type = 1 and o.is_test = '0'
|
|
|
|
|
// GROUP BY o.user_id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-08-28 21:43:56 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2024-08-29 15:18:01 +08:00
|
|
|
|
* 更新设备的定位和电压 10秒一次
|
|
|
|
|
* cron: 0 10 0 * * ?
|
2024-08-28 21:43:56 +08:00
|
|
|
|
*/
|
2024-08-29 15:18:01 +08:00
|
|
|
|
public void updateLocation10(){
|
|
|
|
|
log.info("-------------------【定时任务10秒一次】更新设备的定位和电压-----开始--------------");
|
2024-09-02 08:54:03 +08:00
|
|
|
|
// 记录开始时间
|
|
|
|
|
long startTime = System.nanoTime();
|
2024-08-29 15:18:01 +08:00
|
|
|
|
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("redis缓存中的数据:" + JSON.toJSONString(keys));
|
2024-08-29 15:18:01 +08:00
|
|
|
|
for(String key:keys){
|
|
|
|
|
String msg = redisCache.getCacheObject(key);
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("redis缓存中的数据:{}", msg);
|
2024-08-28 21:43:56 +08:00
|
|
|
|
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry));
|
2024-08-28 21:43:56 +08:00
|
|
|
|
LogEntry.LocationValue value = logEntry.getValue();
|
|
|
|
|
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
|
2024-12-13 17:07:36 +08:00
|
|
|
|
if(ObjectUtil.isNotNull(device) && !isRepeatMsg(msg,logEntry.getDevName())){
|
2025-01-21 23:51:50 +08:00
|
|
|
|
if(ServiceConstants.LOCK_STATUS_OPEN.equals(device.getLockStatus())){
|
2024-09-03 17:25:46 +08:00
|
|
|
|
updateLocationHandle(msg, logEntry, value, device);
|
|
|
|
|
}
|
2024-08-28 21:43:56 +08:00
|
|
|
|
}
|
2024-08-29 15:18:01 +08:00
|
|
|
|
}
|
2024-09-02 08:54:03 +08:00
|
|
|
|
// 计算执行时间(以毫秒为单位)
|
|
|
|
|
long duration = (System.nanoTime() - startTime) / 1_000_000;
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 17:25:46 +08:00
|
|
|
|
private boolean isRepeatMsg(String msg,String mac){
|
|
|
|
|
// 获取最后一条消息
|
|
|
|
|
String lastMsg = etLocationLogMapper.getLastMsg(mac);
|
|
|
|
|
if(ObjectUtil.isNotNull(lastMsg) && msg.equals(lastMsg)){
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 15:18:01 +08:00
|
|
|
|
/**
|
|
|
|
|
* 更新设备的定位和电压 5分钟一次
|
|
|
|
|
* cron: 0 20 0 * * ?
|
|
|
|
|
*/
|
|
|
|
|
public void updateLocation300(){
|
|
|
|
|
log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压-----开始--------------");
|
2024-09-02 08:54:03 +08:00
|
|
|
|
// 记录开始时间
|
|
|
|
|
long startTime = System.nanoTime();
|
2024-08-29 15:18:01 +08:00
|
|
|
|
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("redis缓存中的数据:{}", JSON.toJSONString(keys));
|
2024-08-29 15:18:01 +08:00
|
|
|
|
for(String key:keys){
|
|
|
|
|
String msg = redisCache.getCacheObject(key);
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("redis缓存中的数据:{}", msg);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry));
|
2024-08-29 15:18:01 +08:00
|
|
|
|
LogEntry.LocationValue value = logEntry.getValue();
|
|
|
|
|
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
|
2024-12-13 17:07:36 +08:00
|
|
|
|
if(ObjectUtil.isNotNull(device) && ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())){
|
2024-08-29 15:18:01 +08:00
|
|
|
|
updateLocationHandle(msg, logEntry, value, device);
|
2024-08-28 21:43:56 +08:00
|
|
|
|
}
|
2024-08-29 15:18:01 +08:00
|
|
|
|
}
|
2024-09-02 08:54:03 +08:00
|
|
|
|
// 计算执行时间(以毫秒为单位)
|
|
|
|
|
long duration = (System.nanoTime() - startTime) / 1_000_000;
|
2024-12-13 17:07:36 +08:00
|
|
|
|
// log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateLocationHandle(String msg, LogEntry logEntry, LogEntry.LocationValue value, AsDevice device) {
|
|
|
|
|
// 坐标转换 WGS84 转 GCJ02
|
|
|
|
|
double[] doubles = coordinateConvert(value);
|
2024-12-13 17:07:36 +08:00
|
|
|
|
BigDecimal lon = BigDecimal.valueOf(doubles[1]).setScale(8, RoundingMode.HALF_UP);
|
|
|
|
|
BigDecimal lat = BigDecimal.valueOf(doubles[0]).setScale(8, RoundingMode.HALF_UP);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
|
2024-09-02 08:54:03 +08:00
|
|
|
|
asynchronousSaveLog(msg, logEntry.getAt(), logEntry.getDevName(), lon, lat, device);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
|
2025-01-21 23:51:50 +08:00
|
|
|
|
AsDevice updateDevice = new AsDevice();
|
|
|
|
|
updateDevice.setDeviceId(device.getDeviceId());
|
2024-12-13 17:07:36 +08:00
|
|
|
|
BigDecimal voltage = new BigDecimal(value.getBat());
|
|
|
|
|
if(voltage.compareTo(new BigDecimal(100)) > 0){
|
|
|
|
|
voltage = voltage.divide(new BigDecimal(10));
|
|
|
|
|
}
|
2025-01-21 23:51:50 +08:00
|
|
|
|
updateDevice.setVoltage(voltage.toString());//电压
|
2024-12-13 17:07:36 +08:00
|
|
|
|
if(ObjectUtil.isNotNull(device.getModelId())){
|
|
|
|
|
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
|
|
|
|
|
if(ObjectUtil.isNotNull(model)){
|
|
|
|
|
Integer remainingMileage = 0;
|
|
|
|
|
if(StrUtil.isNotBlank(device.getVoltage())){
|
|
|
|
|
remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
|
|
|
|
|
}
|
|
|
|
|
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
|
2025-01-21 23:51:50 +08:00
|
|
|
|
updateDevice.setRemainingMileage(remainingMileage);
|
|
|
|
|
updateDevice.setRemainingPower(electricQuantity.toString());
|
2024-12-13 17:07:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-21 23:51:50 +08:00
|
|
|
|
updateDevice.setLastTime(DateUtils.getNowDate());
|
|
|
|
|
updateDevice.setSignalStrength(value.getCsq());
|
|
|
|
|
updateDevice.setQuality(value.getQ());
|
2024-08-29 15:18:01 +08:00
|
|
|
|
if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){
|
2025-01-21 23:51:50 +08:00
|
|
|
|
updateDevice.setLatitude(lat.toString());
|
|
|
|
|
updateDevice.setLongitude(lon.toString());
|
|
|
|
|
updateDevice.setLastLocationTime(new Date(logEntry.getAt()));
|
|
|
|
|
updateDevice.setGps("1");
|
2024-08-29 15:18:01 +08:00
|
|
|
|
// 信号强度
|
2025-01-21 23:51:50 +08:00
|
|
|
|
updateDevice.setSatellites(value.getS());
|
2024-08-29 15:18:01 +08:00
|
|
|
|
}else{
|
2025-01-21 23:51:50 +08:00
|
|
|
|
updateDevice.setGps("0");
|
|
|
|
|
updateDevice.setSatellites(0);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
}
|
2025-01-21 23:51:50 +08:00
|
|
|
|
int i = deviceService.updateLocation(updateDevice);
|
2024-08-29 15:18:01 +08:00
|
|
|
|
if(i>0){
|
2024-12-13 17:07:36 +08:00
|
|
|
|
log.info("===============更新设备信息成功===========>{}", logEntry.getDevName());
|
2024-08-28 21:43:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 异步保存定位
|
|
|
|
|
*/
|
|
|
|
|
private void asynchronousSaveLog(String msg, long at,String mac,BigDecimal lon,BigDecimal lat,AsDevice device){
|
|
|
|
|
//异步保存定位
|
|
|
|
|
scheduledExecutorService.schedule(() -> {
|
|
|
|
|
EtLocationLog etLocationLog = new EtLocationLog();
|
|
|
|
|
etLocationLog.setOnenetMsg(msg);
|
|
|
|
|
etLocationLog.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
etLocationLog.setLongitude(lon.toString());
|
|
|
|
|
etLocationLog.setLatitude(lat.toString());
|
|
|
|
|
etLocationLog.setMac(mac);
|
|
|
|
|
etLocationLog.setAt(new Date(at));
|
|
|
|
|
etLocationLog.setStatus(device.getStatus());
|
|
|
|
|
etLocationLog.setLockStatus(device.getLockStatus());
|
|
|
|
|
etLocationLogMapper.insertEtLocationLog(etLocationLog);
|
|
|
|
|
}, 0, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 坐标转换 */
|
|
|
|
|
@NotNull
|
|
|
|
|
private double[] coordinateConvert(LogEntry.LocationValue value) {
|
|
|
|
|
BigDecimal lon = new BigDecimal(value.getLon());
|
|
|
|
|
BigDecimal lat = new BigDecimal(value.getLat());
|
2024-12-13 17:07:36 +08:00
|
|
|
|
if(lon.compareTo(new BigDecimal(1000)) < 0 ){
|
|
|
|
|
return GpsCoordinateUtils.calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
|
|
|
|
|
}
|
2024-08-28 21:43:56 +08:00
|
|
|
|
// log.info("WGS84经纬度(未计算):" + lon + "---" + lat);
|
|
|
|
|
// 除以100
|
|
|
|
|
lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);
|
|
|
|
|
lat = lat.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);
|
|
|
|
|
// log.info("WGS84经纬度(除以100后):" + lon + "---" + lat);
|
|
|
|
|
// 取出lon中后面的小数点
|
|
|
|
|
String[] lonStr = getDecimalPart(lon);
|
|
|
|
|
String[] latStr = getDecimalPart(lat);
|
|
|
|
|
// log.info("WGS84经纬度(截取小数点):" + lonStr[0] + "---" + lonStr[1] + "---"+ latStr[0]+"---"+ latStr[1]);
|
|
|
|
|
// 再将结果乘以5/3
|
|
|
|
|
String lon2 = "0."+ lonStr[1];
|
|
|
|
|
String lat2 = "0."+ latStr[1];
|
|
|
|
|
BigDecimal lons = new BigDecimal(lon2).multiply(new BigDecimal(5).divide(new BigDecimal(3), 8, RoundingMode.HALF_UP));
|
|
|
|
|
BigDecimal lats = new BigDecimal(lat2).multiply(new BigDecimal(5).divide(new BigDecimal(3), 8, RoundingMode.HALF_UP));
|
|
|
|
|
BigDecimal lo = new BigDecimal(lonStr[0]).add(lons);
|
|
|
|
|
BigDecimal la = new BigDecimal(latStr[0]).add(lats);
|
|
|
|
|
// log.info("WGS84经纬度(计算后):" + lo + "---" + la);
|
|
|
|
|
lo = lo.setScale(8, RoundingMode.HALF_UP);
|
|
|
|
|
la = la.setScale(8, RoundingMode.HALF_UP);
|
|
|
|
|
// log.info("WGS84经纬度(保留8为小数):" + lo + "---" + la);
|
|
|
|
|
double[] doubles = GpsCoordinateUtils.calWGS84toGCJ02(la.doubleValue(), lo.doubleValue());
|
|
|
|
|
return doubles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String[] getDecimalPart(BigDecimal number) {
|
|
|
|
|
// 将BigDecimal转换为字符串
|
|
|
|
|
String numberStr = number.toPlainString();
|
|
|
|
|
|
|
|
|
|
// 找到小数点的位置
|
|
|
|
|
int indexOfDecimal = numberStr.indexOf(".");
|
|
|
|
|
|
|
|
|
|
// 初始化结果数组
|
|
|
|
|
String[] parts = new String[2];
|
|
|
|
|
|
|
|
|
|
// 如果有小数点
|
|
|
|
|
if (indexOfDecimal >= 0) {
|
|
|
|
|
parts[0] = numberStr.substring(0, indexOfDecimal); // 整数部分
|
|
|
|
|
parts[1] = numberStr.substring(indexOfDecimal + 1); // 小数部分
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有小数点,整数部分为整个字符串,小数部分为空
|
|
|
|
|
parts[0] = numberStr;
|
|
|
|
|
parts[1] = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parts;
|
|
|
|
|
}
|
2024-09-03 15:54:11 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断优惠券是否过期
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void couponIsExpires(){
|
|
|
|
|
log.info("-------------------【定时任务】判断优惠券是否过期---开始----------------");
|
|
|
|
|
EtCouponUserLog etCouponUserLog = new EtCouponUserLog();
|
|
|
|
|
etCouponUserLog.setStatus(ServiceConstants.COUPON_STATUS_UNUSED);
|
|
|
|
|
List<EtCouponUserLog> couponUserLogs = etCouponClaimLogMapper.selectEtCouponClaimLogList(etCouponUserLog);
|
|
|
|
|
// 获取当前时间
|
|
|
|
|
Date currentTime = new Date();
|
|
|
|
|
for(EtCouponUserLog couponLog :couponUserLogs){
|
|
|
|
|
// 获取优惠券的过期时间
|
|
|
|
|
Date expirationTime = couponLog.getExpirationTime();
|
|
|
|
|
// 判断优惠券是否过期
|
|
|
|
|
if (expirationTime != null && expirationTime.before(currentTime)) {
|
|
|
|
|
// 如果过期,更新状态为已过期
|
|
|
|
|
couponLog.setStatus(ServiceConstants.COUPON_STATUS_EXPIRED);
|
|
|
|
|
// 更新到数据库
|
|
|
|
|
int result = etCouponClaimLogMapper.updateEtCouponClaimLog(couponLog);
|
|
|
|
|
if (result > 0) {
|
2024-09-03 15:57:22 +08:00
|
|
|
|
log.info("优惠券ID: {} 已过期,状态已更新为:已过期", couponLog.getCouponId());
|
2024-09-03 15:54:11 +08:00
|
|
|
|
} else {
|
|
|
|
|
log.warn("优惠券ID: {} 更新状态失败", couponLog.getCouponId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("-------------------【定时任务】判断优惠券是否过期---结束----------------");
|
|
|
|
|
}
|
2024-09-27 15:23:10 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2024-09-27 17:28:47 +08:00
|
|
|
|
* 更新设备的在线状态
|
2024-09-27 15:23:10 +08:00
|
|
|
|
*
|
|
|
|
|
*/
|
2024-09-27 17:28:47 +08:00
|
|
|
|
public void updateDeviceOnlineStatus(){
|
|
|
|
|
log.info("-------------------【定时任务】更新设备的在线状态---开始----------------");
|
|
|
|
|
List<AsDeviceVO> deviceVOS = asDeviceMapper.selectAllDevice();
|
|
|
|
|
for(AsDeviceVO deviceVO : deviceVOS){
|
|
|
|
|
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
|
|
|
|
|
createDeviceVo.setDevice_name(deviceVO.getMac());
|
|
|
|
|
createDeviceVo.setProduct_id(productId);
|
|
|
|
|
try {
|
|
|
|
|
String param = "device_name=" + deviceVO.getMac() + "&product_id=" + productId;
|
|
|
|
|
String sendUrl = deviceUrl+"/detail" + "?"+param;
|
|
|
|
|
String result = HttpUtils.sendGetWithToken(sendUrl,null, Token.getToken());
|
|
|
|
|
log.info("【定时--更新设备的在线状态】===>IOT请求调用结果:【{}】",result);
|
|
|
|
|
DeviceInfo deviceInfo = JSON.parseObject(result, DeviceInfo.class);
|
|
|
|
|
int onlineStatus = Integer.parseInt(deviceVO.getOnlineStatus());
|
|
|
|
|
if(deviceInfo.getCode() != 0){
|
|
|
|
|
log.info("【定时--更新设备的在线状态】===>IOT请求调用失败");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
int onenetStatus = deviceInfo.getData().getStatus();
|
|
|
|
|
if(onenetStatus != onlineStatus ){
|
|
|
|
|
AsDevice device = new AsDevice();
|
|
|
|
|
device.setMac(deviceVO.getMac());
|
2024-10-30 16:28:18 +08:00
|
|
|
|
if(onenetStatus!=2){
|
|
|
|
|
device.setOnlineStatus(onenetStatus+"");
|
|
|
|
|
}
|
2024-09-27 17:28:47 +08:00
|
|
|
|
int i = asDeviceMapper.updateAsDeviceByMac(device);
|
|
|
|
|
log.info("【定时--更新设备的在线状态】===>更新设备状态结果:【{}】",i);
|
|
|
|
|
}
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InvalidKeyException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-27 15:23:10 +08:00
|
|
|
|
}
|
2024-10-04 16:07:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 平台对账
|
|
|
|
|
* */
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
public void selfReconciliation(String timeStart, String timeEnd, String areaId) {
|
|
|
|
|
long aLong = 0;
|
|
|
|
|
if(StrUtil.isNotBlank(areaId)){
|
|
|
|
|
aLong = Long.parseLong(areaId);
|
|
|
|
|
}
|
2024-10-07 09:51:22 +08:00
|
|
|
|
if(StrUtil.isBlank(timeStart) || StrUtil.isBlank(timeEnd)){
|
|
|
|
|
// 默认取昨天的时间
|
|
|
|
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
timeStart = yesterday.format(formatter);
|
|
|
|
|
timeEnd = yesterday.format(formatter);
|
|
|
|
|
}
|
|
|
|
|
List<ChannelVO> channelVOS = smEtChannelService.selectSmChannelList(new ChannelQuery());
|
|
|
|
|
for (ChannelVO channel:channelVOS) {
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
int limit = DateUtils.differentDaysByMillisecond(timeStart, timeEnd) + 1;
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
calendar.setTime(dateFormat.parse(timeEnd));
|
|
|
|
|
for (int i = 0; i < limit; i++) {
|
|
|
|
|
String formattedDate = dateFormat.format(calendar.getTime());
|
|
|
|
|
String startDateStr = formattedDate + " " + Constants.DATE_FORMAT_START_PEREND;
|
|
|
|
|
String endDateStr = formattedDate + " " + Constants.DATE_FORMAT_END_PEREND;
|
|
|
|
|
/** 总收入*/
|
|
|
|
|
SelfReconciliationVO selfReconciliationVO = buildSelfReconciliation(startDateStr,endDateStr, formattedDate,aLong,channel.getChannelId());
|
|
|
|
|
// 保存
|
|
|
|
|
saveRecon(formattedDate, selfReconciliationVO,channel.getChannelId());
|
|
|
|
|
calendar.add(Calendar.DATE, -1);
|
2024-10-04 16:07:44 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SelfReconciliationVO buildSelfReconciliation(String startDateStr, String endDateStr, String formattedDate, Long aLong, Long channelId) {
|
|
|
|
|
SelfReconciliationVO selfReconciliationVO = new SelfReconciliationVO();
|
|
|
|
|
selfReconciliationVO.setDay(formattedDate);
|
|
|
|
|
BigDecimal totalFlowAmount = defaultIfNull(etOrderMapper.getTotalPaidFee(startDateStr, endDateStr, aLong,channelId),BigDecimal.ZERO);// 骑行订单收入 29835.51
|
|
|
|
|
BigDecimal totalAmount = defaultIfNull(etCapitalFlowMapper.getOrderPaidAmount(startDateStr, endDateStr, aLong,channelId),BigDecimal.ZERO);// 骑行订单收入 4712.51
|
|
|
|
|
BigDecimal deductionAmount = defaultIfNull(etOrderMapper.getDepositDeductionAmount(startDateStr, endDateStr, aLong,channelId),BigDecimal.ZERO);// 押金抵扣金额 538
|
|
|
|
|
BigDecimal depositAmount = defaultIfNull(etOrderMapper.getDepositAmount(startDateStr, endDateStr, aLong,channelId),BigDecimal.ZERO);// 押金收入 25123
|
|
|
|
|
BigDecimal handlingFee = etCapitalFlowMapper.getHandlingFee2(startDateStr, endDateStr, null, aLong,channelId);//手续费,扣除掉退款部分的
|
|
|
|
|
BigDecimal platformServiceFee = etCapitalFlowMapper.getServiceFee2(startDateStr, endDateStr, null,aLong,channelId);//平台服务费 ,扣除掉退款部分的
|
|
|
|
|
|
|
|
|
|
selfReconciliationVO.setOrderPaid(totalAmount);
|
|
|
|
|
selfReconciliationVO.setTotalFlowAmount(totalFlowAmount);
|
|
|
|
|
selfReconciliationVO.setDeductionAmount(deductionAmount);
|
|
|
|
|
selfReconciliationVO.setDepositPaid(depositAmount);
|
|
|
|
|
selfReconciliationVO.setHandlingCharge(handlingFee);
|
|
|
|
|
selfReconciliationVO.setPlatformServiceFee(platformServiceFee);
|
|
|
|
|
|
|
|
|
|
/** 总支出*/
|
|
|
|
|
BigDecimal orderRefund = defaultIfNull(etOrderMapper.getRefundFee2(startDateStr, endDateStr, null, aLong,channelId), BigDecimal.ZERO);//订单退款
|
|
|
|
|
BigDecimal depositRefundFee = defaultIfNull(etOrderMapper.getDepositRefundFee(startDateStr, endDateStr, null, aLong,channelId), BigDecimal.ZERO);//押金退款 24795 25386
|
|
|
|
|
// depositChange 等于depositAmount减去deductionAmount减去depositRefundFee
|
|
|
|
|
selfReconciliationVO.setDepositChange(depositAmount.subtract(deductionAmount).subtract(depositRefundFee));
|
|
|
|
|
// 统计所有用户今日账变 进账
|
|
|
|
|
BigDecimal userReceipts = defaultIfNull(etCapitalFlowMapper.getAllUserReceipts(startDateStr, endDateStr, aLong,channelId),BigDecimal.ZERO);
|
|
|
|
|
|
|
|
|
|
selfReconciliationVO.setOrderRefund(orderRefund);
|
|
|
|
|
selfReconciliationVO.setDepositRefund(depositRefundFee);
|
|
|
|
|
BigDecimal depositBalance = depositAmount.subtract(depositRefundFee).subtract(deductionAmount);
|
|
|
|
|
selfReconciliationVO.setDepositBalance(depositBalance);
|
|
|
|
|
selfReconciliationVO.setUserReceipts(userReceipts);
|
|
|
|
|
// 结算金额等于totalFlowAmount减去orderRefund减去depositRefundFee
|
|
|
|
|
selfReconciliationVO.setSettlementAmount(totalFlowAmount.subtract(orderRefund).subtract(depositRefundFee));
|
|
|
|
|
return selfReconciliationVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveRecon(String formattedDate,SelfReconciliationVO selfReconciliationVO,Long channelId) {
|
|
|
|
|
EtReconciliation etReconciliation = new EtReconciliation();
|
|
|
|
|
etReconciliation.setDay(formattedDate);
|
|
|
|
|
etReconciliation.setTotalAmount(selfReconciliationVO.getTotalFlowAmount());
|
|
|
|
|
etReconciliation.setHandlingCharge(selfReconciliationVO.getHandlingCharge());
|
|
|
|
|
etReconciliation.setPlatformServiceFee(selfReconciliationVO.getPlatformServiceFee());
|
|
|
|
|
etReconciliation.setDepositPaid(selfReconciliationVO.getDepositPaid());
|
|
|
|
|
etReconciliation.setOrderPaid(selfReconciliationVO.getOrderPaid());
|
2024-10-10 10:29:26 +08:00
|
|
|
|
etReconciliation.setOrderRefund(selfReconciliationVO.getOrderRefund());
|
|
|
|
|
etReconciliation.setOrderSurplus(selfReconciliationVO.getOrderPaid().subtract(selfReconciliationVO.getOrderRefund()).add(selfReconciliationVO.getDeductionAmount()));
|
|
|
|
|
etReconciliation.setDepositSurplus(selfReconciliationVO.getDepositChange());
|
2024-10-04 16:07:44 +08:00
|
|
|
|
etReconciliation.setDepositRefund(selfReconciliationVO.getDepositRefund());
|
|
|
|
|
etReconciliation.setDeductionAmount(selfReconciliationVO.getDeductionAmount());
|
|
|
|
|
etReconciliation.setUserReceipts(selfReconciliationVO.getUserReceipts());
|
|
|
|
|
etReconciliation.setSettlementAmount(selfReconciliationVO.getSettlementAmount());
|
|
|
|
|
etReconciliation.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
etReconciliation.setPayChannel(channelId);
|
|
|
|
|
int i1 = etReconciliationMapper.insertEtReconciliation(etReconciliation);
|
|
|
|
|
log.info("【平台对账】保存对账数据结果:【{}】",i1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private BigDecimal defaultIfNull(BigDecimal value, BigDecimal defaultValue) {
|
|
|
|
|
return value != null ? value : defaultValue;
|
|
|
|
|
}
|
2024-10-07 09:51:22 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 如果发现车型没有关联收费模式则发短信提示
|
|
|
|
|
* */
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
public void sendMsgtips() {
|
|
|
|
|
List<EtModel> etModels = etModelMapper.selectNotRuleModelList();
|
|
|
|
|
for (EtModel etModel :etModels){
|
|
|
|
|
QueryWrapper<EtModelRule> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("model_id", etModel.getModelId()); // 设备状态正常
|
|
|
|
|
Integer integer = etModelRuleMapper.selectCount(queryWrapper);
|
|
|
|
|
if(integer == 0){
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.put("name",etModel.getModelId());
|
|
|
|
|
SendSmsVo sendSmsVo = new SendSmsVo();
|
|
|
|
|
sendSmsVo.setMobile("18650502300");
|
|
|
|
|
sendSmsVo.setTemplateCode(templateCode);
|
|
|
|
|
sendSmsVo.setParam(jsonObject.toJSONString());
|
|
|
|
|
sendSmsVo.setSignName(signName);
|
|
|
|
|
SendSmsResponse response = SendAliSmsUtil.sendVerifyCode(accessKeyId,accessKeySecret,sendSmsVo);
|
|
|
|
|
log.info("【发送短信】发送短信结果:【{}】",response.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 14:36:47 +08:00
|
|
|
|
}
|