|
|
@@ -1,23 +1,21 @@
|
|
|
package shop.alien.job.store;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import shop.alien.config.redis.BaseRedisService;
|
|
|
-import shop.alien.entity.store.*;
|
|
|
+import shop.alien.entity.result.R;
|
|
|
+import shop.alien.entity.store.StoreMembershipCard;
|
|
|
+import shop.alien.entity.store.StoreMembershipCardOrder;
|
|
|
+import shop.alien.entity.store.vo.AccountLogoutCompleteResultVo;
|
|
|
import shop.alien.job.feign.AlienStoreFeign;
|
|
|
-import shop.alien.mapper.*;
|
|
|
-import shop.alien.util.common.constant.CouponStatusEnum;
|
|
|
-import shop.alien.util.common.constant.DiscountCouponEnum;
|
|
|
-import shop.alien.util.type.LifeNoticeUtil;
|
|
|
+import shop.alien.mapper.StoreMembershipCardMapper;
|
|
|
+import shop.alien.mapper.StoreMembershipCardOrderMapper;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
@@ -44,40 +42,12 @@ public class StoreMembershipCardJob {
|
|
|
private final static String MEMBERSHIP_CARD_BYE_TYPE_HALF_YEAR = "2";
|
|
|
//会员卡购买类型-年卡
|
|
|
private final static String MEMBERSHIP_CARD_BYE_TYPE_YEAR = "3";
|
|
|
- // 商家账号注销:0-未注销,1-已注销,2-注销冷静期
|
|
|
- private final static Integer LOGOUT_FLAG_DONE = StoreUser.LOGOUT_FLAG_DONE;
|
|
|
- private final static Integer LOGOUT_FLAG_COOLING = StoreUser.LOGOUT_FLAG_COOLING;
|
|
|
- private static final String LOGOUT_DISPLAY_NAME = "已注销";
|
|
|
- private static final int LOGOUT_COOLING_DAYS = 7;
|
|
|
-
|
|
|
private final StoreMembershipCardMapper storeMembershipCardMapper;
|
|
|
|
|
|
private final StoreMembershipCardOrderMapper storeMembershipCardOrderMapper;
|
|
|
|
|
|
- private final StoreUserMapper storeUserMapper;
|
|
|
-
|
|
|
- private final StoreInfoMapper storeInfoMapper;
|
|
|
-
|
|
|
- private final BaseRedisService baseRedisService;
|
|
|
-
|
|
|
- private final LifeUserMapper lifeUserMapper;
|
|
|
-
|
|
|
- private final LifeFansMapper lifeFansMapper;
|
|
|
-
|
|
|
- private final LawyerUserMapper lawyerUserMapper;
|
|
|
-
|
|
|
- private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
-
|
|
|
- private final LifeNoticeUtil lifeNoticeUtil;
|
|
|
-
|
|
|
private final AlienStoreFeign alienStoreFeign;
|
|
|
|
|
|
- private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
|
-
|
|
|
- private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
|
-
|
|
|
- private final LifeCouponMapper lifeCouponMapper;
|
|
|
-
|
|
|
/**
|
|
|
* 会员卡状态及会员卡订单状态变更任务
|
|
|
*/
|
|
|
@@ -141,222 +111,19 @@ public class StoreMembershipCardJob {
|
|
|
*/
|
|
|
@XxlJob("cancellationOfBusinessJob")
|
|
|
public void cancellationOfBusinessJob() {
|
|
|
- log.info("处理已申请注销超过7天的商家、用户与律师: " + new Date());
|
|
|
- int successCount = 0;
|
|
|
- int failCount = 0;
|
|
|
-
|
|
|
- // 获取处于注销冷静期的商家用户(含旧数据 logout_flag=1 且 status=-1)
|
|
|
- List<StoreUser> storeUsers = storeUserMapper.selectList(new LambdaQueryWrapper<StoreUser>()
|
|
|
- .and(w -> w.eq(StoreUser::getLogoutFlag, LOGOUT_FLAG_COOLING)
|
|
|
- .or(o -> o.eq(StoreUser::getLogoutFlag, LOGOUT_FLAG_DONE).eq(StoreUser::getStatus, -1))));
|
|
|
- for (StoreUser storeUser : storeUsers) {
|
|
|
- try {
|
|
|
- if (null != storeUser.getLogoutTime()) {
|
|
|
- if (isLogoutCoolingExpired(storeUser.getLogoutTime())) {
|
|
|
- log.info("商家账号冷静期结束,更新注销标记为已注销: userId={}, phone={}, logoutTime={}",
|
|
|
- storeUser.getId(), storeUser.getPhone(), storeUser.getLogoutTime());
|
|
|
- storeUser.setLogoutFlag(LOGOUT_FLAG_DONE);
|
|
|
- storeUser.setName(LOGOUT_DISPLAY_NAME);
|
|
|
- storeUser.setNickName(LOGOUT_DISPLAY_NAME);
|
|
|
- storeUser.setHeadImg(null);
|
|
|
- storeUserMapper.updateById(storeUser);
|
|
|
- successCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failCount++;
|
|
|
- log.error("商家账号注销状态更新失败: userId={}, phone={}, error={}",
|
|
|
- storeUser.getId(), storeUser.getPhone(), e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取全部申请注销的店铺
|
|
|
- List<StoreInfo> storeInfos = storeInfoMapper.selectList(new LambdaQueryWrapper<StoreInfo>().eq(StoreInfo::getLogoutFlag, LOGOUT_FLAG_DONE));
|
|
|
- for (StoreInfo storeInfo : storeInfos) {
|
|
|
- try {
|
|
|
- if (null != storeInfo.getLogoutTime()) {
|
|
|
- // 获取申请注销时间
|
|
|
- Date logoutTime = storeInfo.getLogoutTime();
|
|
|
- // 获取申请注销 7 天后的时间(与通知一致)
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(logoutTime);
|
|
|
- calendar.add(Calendar.DAY_OF_YEAR, 7);
|
|
|
- Date sevenDay = calendar.getTime();
|
|
|
- // 获取当前时间
|
|
|
- Date date = new Date();
|
|
|
- if (date.compareTo(sevenDay) >= 0) {
|
|
|
- log.info("开始删除已注销超过7天的店铺: storeId={}, storeName={}, logoutTime={}",
|
|
|
- storeInfo.getId(), storeInfo.getStoreName(), logoutTime);
|
|
|
-
|
|
|
- invalidateStoreCoupons(storeInfo.getId());
|
|
|
-
|
|
|
- // 先清理关联的商户用户注销状态,确保可以重新入驻
|
|
|
- List<StoreUser> relatedStoreUsers = storeUserMapper.selectList(
|
|
|
- new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, storeInfo.getId()));
|
|
|
- int deletedUsers = 0;
|
|
|
- int deletedFans = 0;
|
|
|
-
|
|
|
- for (StoreUser storeUser : relatedStoreUsers) {
|
|
|
- try {
|
|
|
- // 清理注销标记和时间,允许重新入驻
|
|
|
- storeUser.setLogoutFlag(0);
|
|
|
- storeUser.setLogoutTime(null);
|
|
|
- storeUser.setStoreId(null); // 解除店铺绑定
|
|
|
- storeUserMapper.updateById(storeUser);
|
|
|
- deletedUsers++;
|
|
|
- log.info("清理商户用户注销状态: userId={}, phone={}", storeUser.getId(), storeUser.getPhone());
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("清理商户用户注销状态失败: userId={}, phone={}, error={}",
|
|
|
- storeUser.getId(), storeUser.getPhone(), e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 清理粉丝关系
|
|
|
- for (StoreUser storeUser : relatedStoreUsers) {
|
|
|
- try {
|
|
|
- if (storeUser.getPhone() != null) {
|
|
|
- LambdaQueryWrapper<LifeFans> queryWrapper = new LambdaQueryWrapper<LifeFans>()
|
|
|
- .eq(LifeFans::getDeleteFlag, 0)
|
|
|
- .and(w -> w
|
|
|
- .nested(n -> n.eq(LifeFans::getFollowedUserType, 2)
|
|
|
- .eq(LifeFans::getFollowedRefId, storeUser.getId()))
|
|
|
- .or()
|
|
|
- .nested(n -> n.eq(LifeFans::getFansUserType, 2)
|
|
|
- .eq(LifeFans::getFansRefId, storeUser.getId())));
|
|
|
- int deleted = lifeFansMapper.delete(queryWrapper);
|
|
|
- deletedFans += deleted;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("清理粉丝关系失败: userId={}, phone={}, error={}",
|
|
|
- storeUser.getId(), storeUser.getPhone(), e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 清理Redis地理位置(通过Feign调用)
|
|
|
- try {
|
|
|
- alienStoreFeign.delMer(Boolean.TRUE, storeInfo.getId().toString());
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("清理Redis地理位置失败: storeId={}, error={}", storeInfo.getId(), e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 最后删除店铺记录
|
|
|
- storeInfoMapper.deleteById(storeInfo.getId());
|
|
|
- successCount++;
|
|
|
- log.info("店铺删除完成: storeId={}, deletedUsers={}, deletedFans={}",
|
|
|
- storeInfo.getId(), deletedUsers, deletedFans);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failCount++;
|
|
|
- log.error("删除店铺失败: storeId={}, storeName={}, error={}",
|
|
|
- storeInfo.getId(), storeInfo.getStoreName(), e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 获取处于注销冷静期的 C 端用户
|
|
|
- List<LifeUser> lifeUsers = lifeUserMapper.selectList(
|
|
|
- new LambdaQueryWrapper<LifeUser>().eq(LifeUser::getLogoutFlag, LifeUser.LOGOUT_FLAG_COOLING));
|
|
|
- for (LifeUser lifeUser : lifeUsers) {
|
|
|
- try {
|
|
|
- if (null != lifeUser.getLogoutTime()) {
|
|
|
- if (isLogoutCoolingExpired(lifeUser.getLogoutTime())) {
|
|
|
- lifeUserMapper.update(null, new LambdaUpdateWrapper<LifeUser>()
|
|
|
- .eq(LifeUser::getId, lifeUser.getId())
|
|
|
- .set(LifeUser::getLogoutFlag, LifeUser.LOGOUT_FLAG_DONE)
|
|
|
- .set(LifeUser::getDeleteFlag, 1)
|
|
|
- .set(LifeUser::getUserName, LOGOUT_DISPLAY_NAME)
|
|
|
- .set(LifeUser::getUserImage, null));
|
|
|
- successCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failCount++;
|
|
|
- log.error("C端用户注销状态更新失败: userId={}, phone={}, error={}",
|
|
|
- lifeUser.getId(), lifeUser.getUserPhone(), e.getMessage(), e);
|
|
|
+ log.info("处理已申请注销超过7天的商家、用户与律师: {}", new Date());
|
|
|
+ try {
|
|
|
+ R<AccountLogoutCompleteResultVo> result = alienStoreFeign.completeAccountLogoutCooling();
|
|
|
+ if (result != null && result.getData() != null) {
|
|
|
+ AccountLogoutCompleteResultVo data = result.getData();
|
|
|
+ log.info("注销冷静期到期处理完成: success={}, fail={}, skipped={}, details={}",
|
|
|
+ data.getSuccessCount(), data.getFailCount(), data.getSkippedCount(), data.getDetails());
|
|
|
+ } else {
|
|
|
+ log.warn("注销冷静期到期处理返回为空: {}", result);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("注销冷静期到期处理失败", e);
|
|
|
+ throw e;
|
|
|
}
|
|
|
-
|
|
|
- // 获取处于注销冷静期的律师用户
|
|
|
- List<LawyerUser> lawyerUsers = lawyerUserMapper.selectList(new LambdaQueryWrapper<LawyerUser>()
|
|
|
- .eq(LawyerUser::getLogoutFlag, LawyerUser.LOGOUT_FLAG_COOLING)
|
|
|
- .eq(LawyerUser::getDeleteFlag, 0));
|
|
|
- for (LawyerUser lawyerUser : lawyerUsers) {
|
|
|
- try {
|
|
|
- if (lawyerUser.getLogoutTime() != null) {
|
|
|
- if (isLogoutCoolingExpired(lawyerUser.getLogoutTime())) {
|
|
|
- log.info("律师账号冷静期结束,更新注销标记为已注销: lawyerId={}, phone={}, logoutTime={}",
|
|
|
- lawyerUser.getId(), lawyerUser.getPhone(), lawyerUser.getLogoutTime());
|
|
|
- lawyerUserMapper.update(null, new LambdaUpdateWrapper<LawyerUser>()
|
|
|
- .eq(LawyerUser::getId, lawyerUser.getId())
|
|
|
- .set(LawyerUser::getLogoutFlag, LawyerUser.LOGOUT_FLAG_DONE)
|
|
|
- .set(LawyerUser::getName, LOGOUT_DISPLAY_NAME)
|
|
|
- .set(LawyerUser::getNickName, LOGOUT_DISPLAY_NAME)
|
|
|
- .set(LawyerUser::getHeadImg, null)
|
|
|
- .set(LawyerUser::getOrderReceivingStatus, 0)
|
|
|
- .set(LawyerUser::getIsOnline, 0)
|
|
|
- .set(LawyerUser::getIsRecommended, 0)
|
|
|
- .set(LawyerUser::getLastOnlineTime, new Date()));
|
|
|
- successCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failCount++;
|
|
|
- log.error("律师账号注销状态更新失败: lawyerId={}, phone={}, error={}",
|
|
|
- lawyerUser.getId(), lawyerUser.getPhone(), e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("定时任务执行完成: 成功={}, 失败={}", successCount, failCount);
|
|
|
- }
|
|
|
-
|
|
|
- private static boolean isLogoutCoolingExpired(Date logoutTime) {
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(logoutTime);
|
|
|
- calendar.add(Calendar.DAY_OF_YEAR, LOGOUT_COOLING_DAYS);
|
|
|
- return new Date().compareTo(calendar.getTime()) >= 0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 店铺注销冷静期结束:将该店铺赠出/发行的优惠券全部置为已失效
|
|
|
- */
|
|
|
- private void invalidateStoreCoupons(Integer storeId) {
|
|
|
- if (storeId == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- String storeIdStr = String.valueOf(storeId);
|
|
|
- int voidedUserCouponStatus = Integer.parseInt(DiscountCouponEnum.HAVE_BEEN_VOIDED.getValue());
|
|
|
-
|
|
|
- lifeDiscountCouponMapper.update(null, new LambdaUpdateWrapper<LifeDiscountCoupon>()
|
|
|
- .eq(LifeDiscountCoupon::getStoreId, storeIdStr)
|
|
|
- .set(LifeDiscountCoupon::getCouponStatus, LifeDiscountCoupon.COUPON_STATUS_INVALID)
|
|
|
- .set(LifeDiscountCoupon::getGetStatus, 0));
|
|
|
-
|
|
|
- List<LifeDiscountCoupon> storeCoupons = lifeDiscountCouponMapper.selectList(
|
|
|
- new LambdaQueryWrapper<LifeDiscountCoupon>().eq(LifeDiscountCoupon::getStoreId, storeIdStr));
|
|
|
- if (!storeCoupons.isEmpty()) {
|
|
|
- List<Integer> couponIds = storeCoupons.stream().map(LifeDiscountCoupon::getId).collect(Collectors.toList());
|
|
|
- lifeDiscountCouponUserMapper.update(null, new LambdaUpdateWrapper<LifeDiscountCouponUser>()
|
|
|
- .in(LifeDiscountCouponUser::getCouponId, couponIds)
|
|
|
- .eq(LifeDiscountCouponUser::getStatus, Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()))
|
|
|
- .set(LifeDiscountCouponUser::getStatus, voidedUserCouponStatus));
|
|
|
- }
|
|
|
-
|
|
|
- lifeCouponMapper.update(null, new LambdaUpdateWrapper<LifeCoupon>()
|
|
|
- .eq(LifeCoupon::getStoreId, storeIdStr)
|
|
|
- .notIn(LifeCoupon::getStatus, CouponStatusEnum.ENDED.getCode(), CouponStatusEnum.INVALID.getCode())
|
|
|
- .set(LifeCoupon::getStatus, CouponStatusEnum.INVALID.getCode()));
|
|
|
-
|
|
|
- List<LifeCoupon> storeVouchers = lifeCouponMapper.selectList(
|
|
|
- new LambdaQueryWrapper<LifeCoupon>().eq(LifeCoupon::getStoreId, storeIdStr));
|
|
|
- if (!storeVouchers.isEmpty()) {
|
|
|
- List<String> voucherIds = storeVouchers.stream().map(LifeCoupon::getId).collect(Collectors.toList());
|
|
|
- lifeDiscountCouponUserMapper.update(null, new LambdaUpdateWrapper<LifeDiscountCouponUser>()
|
|
|
- .in(LifeDiscountCouponUser::getVoucherId, voucherIds)
|
|
|
- .eq(LifeDiscountCouponUser::getStatus, Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()))
|
|
|
- .set(LifeDiscountCouponUser::getStatus, voidedUserCouponStatus));
|
|
|
- }
|
|
|
-
|
|
|
- log.info("店铺优惠券已失效处理完成: storeId={}, templateCount={}, voucherCount={}",
|
|
|
- storeId, storeCoupons.size(), storeVouchers.size());
|
|
|
}
|
|
|
}
|