|
|
@@ -1,530 +0,0 @@
|
|
|
-package shop.alien.store.task;
|
|
|
-
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import shop.alien.entity.second.SecondGoods;
|
|
|
-import shop.alien.entity.second.SecondTradeRecord;
|
|
|
-import shop.alien.entity.store.*;
|
|
|
-import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
-import shop.alien.mapper.*;
|
|
|
-import shop.alien.mapper.second.SecondGoodsMapper;
|
|
|
-import shop.alien.mapper.second.SecondTradeRecordMapper;
|
|
|
-import shop.alien.store.config.BaseRedisService;
|
|
|
-import shop.alien.store.config.WebSocketProcess;
|
|
|
-import shop.alien.store.service.*;
|
|
|
-import shop.alien.store.util.ali.AliApi;
|
|
|
-import shop.alien.util.common.AlipayTradeRefund;
|
|
|
-import shop.alien.util.common.DateUtils;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneId;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@Component
|
|
|
-@RequiredArgsConstructor
|
|
|
-public class ScheduledTask {
|
|
|
-
|
|
|
- private final LifeCouponMapper lifeCouponMapper;
|
|
|
-
|
|
|
- private final LifeUserOrderMapper lifeUserOrderMapper;
|
|
|
-
|
|
|
- private final AlipayTradeRefund alipayTradeRefund;
|
|
|
-
|
|
|
- private final StoreIncomeDetailsRecordService storeIncomeDetailsRecordService;
|
|
|
-
|
|
|
- private final StoreCashOutRecordService storeCashOutRecordService;
|
|
|
-
|
|
|
- private final StoreUserService storeUserService;
|
|
|
-
|
|
|
- private final AliApi aliApi;
|
|
|
-
|
|
|
- private final LifeReverseGroupBuyingService lifeReverseGroupBuyingService;
|
|
|
-
|
|
|
- private final LifeMessageMapper lifeMessageMapper;
|
|
|
-
|
|
|
- private final LifeUserService lifeUserService;
|
|
|
-
|
|
|
- private final SecondTradeRecordMapper secondTradeRecordMapper;
|
|
|
-
|
|
|
- private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
-
|
|
|
- private final LifeUserMapper lifeUserMapper;
|
|
|
-
|
|
|
- private final SecondGoodsMapper secondGoodsMapper;
|
|
|
-
|
|
|
- private final WebSocketProcess webSocketProcess;
|
|
|
-
|
|
|
- private final BaseRedisService baseRedisService;
|
|
|
-
|
|
|
-// @Scheduled(cron = "0 */10 * * * ?")
|
|
|
- public void sendDiscountCouponRemind() {
|
|
|
- //查询
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-// @Scheduled(cron = "0 */10 * * * ?")
|
|
|
- // 该方法用于定时更新生活优惠券(LifeCoupon)的状态
|
|
|
- public void quanStatusUpdateTask() {
|
|
|
- //执行修改代金券状态
|
|
|
- System.out.println("执行修改代金券状态 ===>");
|
|
|
- // 获取当前时间
|
|
|
- Date now = new Date();
|
|
|
- // 创建一个 Calendar 实例,用于对日期进行操作
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- // 将 Calendar 的时间设置为当前时间
|
|
|
- calendar.setTime(now);
|
|
|
- // 将 Calendar 的小时设置为 0
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- // 将 Calendar 的分钟设置为 0
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- // 将 Calendar 的秒设置为 0
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- // 将 Calendar 的毫秒设置为 0
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- // 获取处理后的时间,即当前日期的零点
|
|
|
- now = calendar.getTime();
|
|
|
-
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于查询生活优惠券,这里实际上主要用于查询操作
|
|
|
- LambdaUpdateWrapper<LifeCoupon> selectWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 创建一个集合,用于存储要查询的优惠券状态值
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- // 待审核
|
|
|
- ids.add(0);
|
|
|
- // 进行中
|
|
|
- ids.add(1);
|
|
|
- // 已暂停
|
|
|
- ids.add(2);
|
|
|
- // 设置查询条件,查询状态为 0、1 或 2 的生活优惠券
|
|
|
- selectWrapper.in(LifeCoupon::getStatus, ids);
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeCoupon> jinxingzhongList = lifeCouponMapper.selectList(selectWrapper);
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!jinxingzhongList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeCoupon quan : jinxingzhongList) {
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndDate();
|
|
|
- // 比较当前日期(零点)和优惠券的结束日期,如果当前日期大于结束日期 将状态变成已结束
|
|
|
- if (now.compareTo(endTime) > 0) {
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeCoupon> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper.eq(LifeCoupon::getId, quan.getId())
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 3
|
|
|
- .set(LifeCoupon::getStatus, 3);
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- lifeCouponMapper.update(null, updateWrapper);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 创建另一个 LambdaUpdateWrapper 用于查询状态为 0 的生活优惠券
|
|
|
- LambdaUpdateWrapper<LifeCoupon> selectWrapper2 = new LambdaUpdateWrapper<>();
|
|
|
- // 设置查询条件,查询状态为 0 的生活优惠券
|
|
|
- selectWrapper2.eq(LifeCoupon::getStatus, 0);
|
|
|
- // 调用 lifeCouponMapper 的 selectList 方法,根据上述条件查询生活优惠券列表
|
|
|
- List<LifeCoupon> weikaishiList = lifeCouponMapper.selectList(selectWrapper2);
|
|
|
- // 判断查询结果列表是否不为空
|
|
|
- if (!weikaishiList.isEmpty()) {
|
|
|
- // 遍历查询到的生活优惠券列表
|
|
|
- for (LifeCoupon quan : weikaishiList) {
|
|
|
- // 获取当前优惠券的开始日期
|
|
|
- Date startTime = quan.getStartDate();
|
|
|
- // 获取当前优惠券的结束日期
|
|
|
- Date endTime = quan.getEndDate();
|
|
|
- // 判断当前日期(零点)是否在优惠券的开始日期和结束日期之间 将待使用变成进行中
|
|
|
- if (now.compareTo(startTime) >= 0 && now.compareTo(endTime) <= 0) {
|
|
|
- // 创建一个 LambdaUpdateWrapper 用于更新生活优惠券的状态
|
|
|
- LambdaUpdateWrapper<LifeCoupon> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- // 设置更新条件,根据优惠券的 ID 进行更新
|
|
|
- updateWrapper.eq(LifeCoupon::getId, quan.getId())
|
|
|
- // 设置要更新的字段,将优惠券的状态更新为 1
|
|
|
- .set(LifeCoupon::getStatus, 1);
|
|
|
- // 调用 lifeCouponMapper 的 update 方法,根据上述条件更新优惠券的状态
|
|
|
- lifeCouponMapper.update(null, updateWrapper);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-// @Scheduled(cron = "0 */10 * * * ?")
|
|
|
- public void orderStatusUpdateTask() {
|
|
|
- Date now = new Date();
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(now);
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- now = calendar.getTime();
|
|
|
- LambdaUpdateWrapper<LifeUserOrder> selectWrapper = new LambdaUpdateWrapper<>();
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- ids.add(0);
|
|
|
- ids.add(3);
|
|
|
- selectWrapper.in(LifeUserOrder::getStatus, ids);
|
|
|
- List<LifeUserOrder> orderList = lifeUserOrderMapper.selectList(selectWrapper);
|
|
|
- if (!orderList.isEmpty()) {
|
|
|
- for (LifeUserOrder order : orderList) {
|
|
|
- Date payTime = order.getPayTime();
|
|
|
- LifeCoupon quan = lifeCouponMapper.selectById(order.getQuanId());
|
|
|
- calendar.setTime(payTime);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, quan.getExpirationDate());
|
|
|
- Date guoqiDate = calendar.getTime();
|
|
|
- Date endDate = quan.getEndDate();
|
|
|
- if (now.compareTo(guoqiDate) > 0 || now.compareTo(endDate) > 0) {
|
|
|
- String result = alipayTradeRefund.processRefund(order.getOrderNo(), order.getFinalPrice(), "过期自动退");
|
|
|
- if (result.equals("调用成功")) {
|
|
|
- LambdaUpdateWrapper<LifeUserOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(LifeUserOrder::getId, order.getId()).set(LifeUserOrder::getStatus, 4).set(LifeUserOrder::getRefundTime, new Date());
|
|
|
- lifeUserOrderMapper.update(null, updateWrapper);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 自动转账
|
|
|
- * 一分钟执行一次
|
|
|
- */
|
|
|
-// @Scheduled(cron = "0 */1 * * * ?")
|
|
|
- public void autoTransferAccounts() {
|
|
|
- //获取已到账期
|
|
|
- LambdaQueryWrapper<StoreIncomeDetailsRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.lt(StoreIncomeDetailsRecord::getCreatedTime, DateUtils.calcDays(new Date(), -28)).isNull(StoreIncomeDetailsRecord::getCashOutId);
|
|
|
- List<StoreIncomeDetailsRecord> list = storeIncomeDetailsRecordService.list(wrapper);
|
|
|
- // 根据 storeId 分组
|
|
|
- Map<Integer, List<StoreIncomeDetailsRecord>> groupedByStoreId = list.stream()
|
|
|
- .collect(Collectors.groupingBy(StoreIncomeDetailsRecord::getStoreId));
|
|
|
- //获取账户余额
|
|
|
- List<Integer> storeIds = new ArrayList<>();
|
|
|
- Map<Integer, Integer> storeMoney = new HashMap<>();
|
|
|
- Map<Integer, Integer> storeCommission = new HashMap<>();
|
|
|
- groupedByStoreId.forEach((storeId, records) -> {
|
|
|
- storeIds.add(storeId);
|
|
|
- // 对每个 storeId 对应的 records 进行处理
|
|
|
- int money = 0;
|
|
|
- int commission = 0;
|
|
|
- for (StoreIncomeDetailsRecord record : records) {
|
|
|
- money += record.getMoney() - record.getCommission();
|
|
|
- commission += record.getCommission();
|
|
|
- }
|
|
|
- storeMoney.put(storeId, money);
|
|
|
- storeCommission.put(storeId, commission);
|
|
|
- });
|
|
|
- List<StoreUser> storeUserList = storeUserService.list(new LambdaUpdateWrapper<StoreUser>().in(StoreUser::getStoreId, storeIds));
|
|
|
- //转账
|
|
|
- storeMoney.forEach((storeId, money) -> {
|
|
|
- if (money < 10) {
|
|
|
- log.info("账户已到账期金额小于最小转账金额, 用户id: {},金额: {}", storeId, money);
|
|
|
- } else {
|
|
|
- List<StoreUser> userList = storeUserList.stream()
|
|
|
- .filter(storeUser -> storeUser.getStoreId().equals(storeId))
|
|
|
- .collect(Collectors.toList());
|
|
|
- if (!userList.isEmpty()) {
|
|
|
- StoreUser filteredUsers = userList.get(0);
|
|
|
- StoreAliPayLog pay = aliApi.pay(filteredUsers.getName(), filteredUsers.getIdCard(), filteredUsers.getPhone(), new BigDecimal(money).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString());
|
|
|
- if (null == pay) {
|
|
|
- log.error("支付宝转账失败, 用户: {},金额: {}", filteredUsers.getPhone(), money);
|
|
|
- } else {
|
|
|
- StoreCashOutRecord storeCashOutRecord = new StoreCashOutRecord();
|
|
|
- //转账记录表
|
|
|
- storeCashOutRecord.setStoreId(storeId)
|
|
|
- .setMoney(money)
|
|
|
- .setCommission(storeCommission.get(storeId))
|
|
|
- .setCashOutType(1)
|
|
|
- .setOrderNo(pay.getOutBizNo())
|
|
|
- .setAliOrderNo(pay.getOrderId())
|
|
|
- .setIncomeStartTime(groupedByStoreId.get(storeId).get(0).getCreatedTime())
|
|
|
- .setIncomeEndTime(groupedByStoreId.get(storeId).get(groupedByStoreId.get(storeId).size() - 1).getCreatedTime())
|
|
|
- .setPaymentDate(new Date());
|
|
|
- storeCashOutRecordService.save(storeCashOutRecord);
|
|
|
- list.forEach(record -> {
|
|
|
- if (record.getStoreId().equals(storeId)) {
|
|
|
- record.setCashOutId(storeCashOutRecord.getId());
|
|
|
- }
|
|
|
- });
|
|
|
- //减少金额
|
|
|
- filteredUsers.setMoney(filteredUsers.getMoney() - money);
|
|
|
- storeUserService.updateById(filteredUsers);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- //增加记录
|
|
|
- storeIncomeDetailsRecordService.saveOrUpdateBatch(list);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 反向团购订单自动退款
|
|
|
- */
|
|
|
-// @Scheduled(cron = "0 * * * * ?")
|
|
|
- public void reverseGroupOrder() {
|
|
|
- LambdaQueryWrapper<LifeReverseGroupBuying> wrapper = new LambdaQueryWrapper<>();
|
|
|
- //状态, 0:待审核, 1:未通过, 2:已通过, 3:待接单, 4:未接单(已截止), 5:待使用, 6:已完成, 7:已退款
|
|
|
- wrapper.eq(LifeReverseGroupBuying::getStatus, 4);
|
|
|
- List<LifeReverseGroupBuying> list = lifeReverseGroupBuyingService.list();
|
|
|
- for (LifeReverseGroupBuying lifeReverseGroupBuying : list) {
|
|
|
- //竞价结束
|
|
|
- if (DateUtils.dateCompare(new Date(), lifeReverseGroupBuying.getBiddingEndTime())) {
|
|
|
- LifeUserOrder lifeUserOrder = lifeUserOrderMapper.selectById(lifeReverseGroupBuying.getOrderId());
|
|
|
- String s = alipayTradeRefund.processRefund(lifeUserOrder.getOrderNo(), new BigDecimal(lifeReverseGroupBuying.getGroupMoney()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).toString(), "用户反向团购, 未有商家接单");
|
|
|
- if (s.contains("成功")) {
|
|
|
- //修改状态
|
|
|
- lifeReverseGroupBuying.setStatus(7);
|
|
|
- lifeReverseGroupBuyingService.updateById(lifeReverseGroupBuying);
|
|
|
- } else {
|
|
|
- LifeUser lifeUser = lifeUserService.getById(lifeUserOrder.getUserId());
|
|
|
- LifeMessage lifeMessage = new LifeMessage();
|
|
|
- lifeMessage.setSenderName("system");
|
|
|
- if (lifeUser != null) {
|
|
|
- lifeMessage.setReceiverId("user_" + lifeUser.getUserPhone());
|
|
|
- lifeMessage.setContent("你有一笔反向团购退款失败, 请联系管理员");
|
|
|
- lifeMessage.setType("2");
|
|
|
- lifeMessageMapper.insert(lifeMessage);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 二手交易平台 - 交易时间前的十分钟和十五分钟之间 给买家和卖家发送通知提醒
|
|
|
- */
|
|
|
-// @Scheduled(cron = "0 * * * * ?")
|
|
|
- public void secondTradeRemind() throws Exception {
|
|
|
- LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
|
|
-
|
|
|
- // 查询所有待交易
|
|
|
- LambdaQueryWrapper<SecondTradeRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(SecondTradeRecord::getTradeStatus, 3);
|
|
|
- List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(wrapper);
|
|
|
-
|
|
|
- for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
- // 十分钟前
|
|
|
- LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().minusMinutes(10).withSecond(0).withNano(0);
|
|
|
- // 交易时间的十分钟前
|
|
|
- if (now.isEqual(tenMinutesAgo)) {
|
|
|
- LifeUser buyer = lifeUserMapper.selectById(tradeRecord.getBuyerId());
|
|
|
- LifeUser seller = lifeUserMapper.selectById(tradeRecord.getSellerId());
|
|
|
-
|
|
|
- String buyerPhoneId = null == buyer ? "" : "user_" + buyer.getUserPhone();
|
|
|
- String sellerPhoneId = null == seller ? "" : "user_" + seller.getUserPhone();
|
|
|
-
|
|
|
- // 封装交易信息
|
|
|
- JSONObject message = new JSONObject();
|
|
|
- message.put("tradeId", tradeRecord.getId());
|
|
|
- message.put("transactionAmount", tradeRecord.getTransactionAmount());
|
|
|
- message.put("transactionLatitudeLongitude", tradeRecord.getTransactionLatitudeLongitude());
|
|
|
- message.put("transactionLatitudeLongitudeAddress", tradeRecord.getTransactionLatitudeLongitudeAddress());
|
|
|
- message.put("transactionLocation", tradeRecord.getTransactionLocation());
|
|
|
- message.put("transactionTime", tradeRecord.getTransactionTime());
|
|
|
- message.put("tradeStatus", tradeRecord.getTradeStatus());
|
|
|
-
|
|
|
- // 给买家发送消息
|
|
|
- LifeMessage lifeMessage = new LifeMessage();
|
|
|
- lifeMessage.setSenderId(sellerPhoneId);
|
|
|
- lifeMessage.setReceiverId(buyerPhoneId);
|
|
|
- lifeMessage.setContent(message.toJSONString());
|
|
|
- lifeMessage.setType("5");
|
|
|
- lifeMessageMapper.insert(lifeMessage);
|
|
|
-
|
|
|
- // 给买家推送消息
|
|
|
- WebSocketVo websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId(sellerPhoneId);
|
|
|
- websocketVo.setReceiverId(buyerPhoneId);
|
|
|
- websocketVo.setCategory("message");
|
|
|
- websocketVo.setType("5");
|
|
|
- websocketVo.setText(message.toJSONString());
|
|
|
- websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- webSocketProcess.sendMessage(buyerPhoneId, JSONObject.from(websocketVo).toJSONString());
|
|
|
-
|
|
|
- // 给买家发送通知
|
|
|
- LifeNotice lifeNotice = new LifeNotice();
|
|
|
- lifeNotice.setSenderId("system");
|
|
|
- lifeNotice.setReceiverId(buyerPhoneId);
|
|
|
- lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("商品交易签到");
|
|
|
- lifeNotice.setNoticeType(1);
|
|
|
- // 封装通知信息
|
|
|
- JSONObject noticeMessage = new JSONObject();
|
|
|
- noticeMessage.put("tradeId", tradeRecord.getId());
|
|
|
- noticeMessage.put("otherSideUserId", tradeRecord.getSellerId());
|
|
|
- noticeMessage.put("otherSidePhoneId", sellerPhoneId);
|
|
|
- noticeMessage.put("otherSideName", null == seller ? "" : seller.getUserName());
|
|
|
- noticeMessage.put("otherSideImage", null == seller ? "" : seller.getUserImage());
|
|
|
- noticeMessage.put("message", "您有一笔交易即将开始, 请及时前往查看");
|
|
|
- lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
- lifeNoticeMapper.insert(lifeNotice);
|
|
|
-
|
|
|
- // 给买家推送通知
|
|
|
- websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId("system");
|
|
|
- websocketVo.setReceiverId(buyerPhoneId);
|
|
|
- websocketVo.setCategory("notice");
|
|
|
- websocketVo.setNoticeType("1");
|
|
|
- websocketVo.setType("5");
|
|
|
- websocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
- websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- webSocketProcess.sendMessage(buyerPhoneId, JSONObject.from(websocketVo).toJSONString());
|
|
|
-
|
|
|
- // 给卖家发送消息
|
|
|
- lifeMessage = new LifeMessage();
|
|
|
- lifeMessage.setSenderId(buyerPhoneId);
|
|
|
- lifeMessage.setReceiverId(sellerPhoneId);
|
|
|
- lifeMessage.setContent(message.toJSONString());
|
|
|
- lifeMessage.setType("5");
|
|
|
- lifeMessageMapper.insert(lifeMessage);
|
|
|
-
|
|
|
- // 给卖家推送消息
|
|
|
- websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId(buyerPhoneId);
|
|
|
- websocketVo.setReceiverId(sellerPhoneId);
|
|
|
- websocketVo.setCategory("message");
|
|
|
- websocketVo.setType("5");
|
|
|
- websocketVo.setText(message.toJSONString());
|
|
|
- websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- webSocketProcess.sendMessage(sellerPhoneId, JSONObject.from(websocketVo).toJSONString());
|
|
|
-
|
|
|
- // 给卖家发送通知
|
|
|
- lifeNotice = new LifeNotice();
|
|
|
- lifeNotice.setSenderId("system");
|
|
|
- lifeNotice.setReceiverId(sellerPhoneId);
|
|
|
- lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("商品交易签到");
|
|
|
- lifeNotice.setNoticeType(1);
|
|
|
- // 封装通知信息
|
|
|
- noticeMessage = new JSONObject();
|
|
|
- noticeMessage.put("tradeId", tradeRecord.getId());
|
|
|
- noticeMessage.put("otherSideUserId", tradeRecord.getBuyerId());
|
|
|
- noticeMessage.put("otherSidePhoneId", buyerPhoneId);
|
|
|
- noticeMessage.put("otherSideName", null == buyer ? "" : buyer.getUserName());
|
|
|
- noticeMessage.put("otherSideImage", null == buyer ? "" : buyer.getUserImage());
|
|
|
- noticeMessage.put("message", "您有一笔交易即将开始, 请及时前往查看");
|
|
|
- lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
- lifeNoticeMapper.insert(lifeNotice);
|
|
|
-
|
|
|
- // 给卖家推送通知
|
|
|
- websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId("system");
|
|
|
- websocketVo.setReceiverId(sellerPhoneId);
|
|
|
- websocketVo.setCategory("notice");
|
|
|
- websocketVo.setNoticeType("1");
|
|
|
- websocketVo.setType("5");
|
|
|
- websocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
- websocketVo.setMessageId(lifeMessage.getId());
|
|
|
- webSocketProcess.sendMessage(sellerPhoneId, JSONObject.from(websocketVo).toJSONString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 二手交易平台 - 到达交易时间时,给买家和卖家发送交易确认提醒
|
|
|
- */
|
|
|
-// @Scheduled(cron = "0 * * * * ?")
|
|
|
- public void secondTradeConfirm() throws Exception {
|
|
|
- LocalDateTime now = LocalDateTime.now().withSecond(0).withNano(0);
|
|
|
-
|
|
|
- // 查询所有待交易
|
|
|
- LambdaQueryWrapper<SecondTradeRecord> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(SecondTradeRecord::getTradeStatus, 3);
|
|
|
- List<SecondTradeRecord> tradeRecordList = secondTradeRecordMapper.selectList(wrapper);
|
|
|
-
|
|
|
- for (SecondTradeRecord tradeRecord : tradeRecordList) {
|
|
|
- LocalDateTime tenMinutesAgo = tradeRecord.getTransactionTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().withSecond(0).withNano(0);
|
|
|
- // 交易时间的十分钟前
|
|
|
- if (now.isEqual(tenMinutesAgo)) {
|
|
|
- LifeUser buyer = lifeUserMapper.selectById(tradeRecord.getBuyerId());
|
|
|
- LifeUser seller = lifeUserMapper.selectById(tradeRecord.getSellerId());
|
|
|
- SecondGoods goods = secondGoodsMapper.selectById(tradeRecord.getGoodsId());
|
|
|
-
|
|
|
- String buyerPhoneId = null == buyer ? "" : "user_" + buyer.getUserPhone();
|
|
|
- String sellerPhoneId = null == seller ? "" : "user_" + seller.getUserPhone();
|
|
|
-
|
|
|
- // 给买家发送通知
|
|
|
- LifeNotice lifeNotice = new LifeNotice();
|
|
|
- lifeNotice.setSenderId("system");
|
|
|
- lifeNotice.setReceiverId(buyerPhoneId);
|
|
|
- lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("商品是否交易成功");
|
|
|
- lifeNotice.setNoticeType(1);
|
|
|
- // 封装通知信息
|
|
|
- JSONObject noticeMessage = new JSONObject();
|
|
|
- noticeMessage.put("goodsId", goods.getId());
|
|
|
- noticeMessage.put("goodsHomeImage", goods.getHomeImage());
|
|
|
- noticeMessage.put("goodsTitle", goods.getTitle());
|
|
|
- noticeMessage.put("tradeId", tradeRecord.getId());
|
|
|
- noticeMessage.put("transactionAmount", tradeRecord.getTransactionAmount());
|
|
|
- noticeMessage.put("transactionLatitudeLongitude", tradeRecord.getTransactionLatitudeLongitude());
|
|
|
- noticeMessage.put("transactionLatitudeLongitudeAddress", tradeRecord.getTransactionLatitudeLongitudeAddress());
|
|
|
- noticeMessage.put("transactionLocation", tradeRecord.getTransactionLocation());
|
|
|
- noticeMessage.put("transactionTime", tradeRecord.getTransactionTime());
|
|
|
- noticeMessage.put("tradeStatus", tradeRecord.getTradeStatus());
|
|
|
- noticeMessage.put("message", "您有一笔交易已完成, 请前往确认");
|
|
|
- lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
- lifeNoticeMapper.insert(lifeNotice);
|
|
|
-
|
|
|
- // 给买家推送通知
|
|
|
- WebSocketVo websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId("system");
|
|
|
- websocketVo.setReceiverId(buyerPhoneId);
|
|
|
- websocketVo.setCategory("notice");
|
|
|
- websocketVo.setNoticeType("1");
|
|
|
- websocketVo.setType("5");
|
|
|
- websocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
- webSocketProcess.sendMessage(buyerPhoneId, JSONObject.from(websocketVo).toJSONString());
|
|
|
-
|
|
|
- // 给卖家发送通知
|
|
|
- lifeNotice = new LifeNotice();
|
|
|
- lifeNotice.setSenderId("system");
|
|
|
- lifeNotice.setReceiverId(sellerPhoneId);
|
|
|
- lifeNotice.setBusinessId(tradeRecord.getId());
|
|
|
- lifeNotice.setTitle("商品是否交易成功");
|
|
|
- lifeNotice.setNoticeType(1);
|
|
|
- lifeNotice.setContext(noticeMessage.toJSONString());
|
|
|
- lifeNoticeMapper.insert(lifeNotice);
|
|
|
-
|
|
|
- // 给卖家推送通知
|
|
|
- websocketVo = new WebSocketVo();
|
|
|
- websocketVo.setSenderId("system");
|
|
|
- websocketVo.setReceiverId(sellerPhoneId);
|
|
|
- websocketVo.setCategory("notice");
|
|
|
- websocketVo.setNoticeType("1");
|
|
|
- websocketVo.setType("5");
|
|
|
- websocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
- webSocketProcess.sendMessage(buyerPhoneId, JSONObject.from(websocketVo).toJSONString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 二手交易平台 - 每分钟从redis中读取已读的消息id 并将数据库设为已读
|
|
|
- */
|
|
|
-// @Scheduled(cron = "0 * * * * ?")
|
|
|
- public void readMessage() {
|
|
|
- try {
|
|
|
- if (CollectionUtil.isEmpty(baseRedisService.getList("readMessageIdKey"))) return;
|
|
|
-
|
|
|
- List<String> dataList = baseRedisService.popBatchFromList("readMessageIdKey");
|
|
|
- if (CollectionUtil.isNotEmpty(dataList)) {
|
|
|
- LambdaUpdateWrapper<LifeMessage> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.in(LifeMessage::getId, dataList)
|
|
|
- .set(LifeMessage::getIsRead, 1);
|
|
|
- lifeMessageMapper.update(null, wrapper);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("ScheduledTask.readMessage Error Mgs={}", e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-}
|