package com.tourguide.modules.user.mapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.tourguide.modules.user.entity.GuideUser;
|
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Update;
|
|
import java.math.BigDecimal;
|
|
public interface GuideUserMapper extends BaseMapper<GuideUser> {
|
@Update("UPDATE guide_user SET username = #{username}, mobile = NULL, certificate_no = NULL, " +
|
"id_card_no = NULL, id_card_front_url = NULL, id_card_back_url = NULL, status = 3, " +
|
"auto_disable_whitelisted = 0, auto_disabled = 0, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND deleted = 0")
|
int cancelAccount(@Param("guideId") Long guideId, @Param("username") String username);
|
|
@Update("UPDATE guide_user SET username = #{username}, mobile = NULL, certificate_no = NULL, " +
|
"id_card_no = NULL, id_card_front_url = NULL, id_card_back_url = NULL, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND status = 3 AND deleted = 0")
|
int anonymizeCancelledGuide(@Param("guideId") Long guideId, @Param("username") String username);
|
|
@Update("UPDATE guide_user SET id_card_no = NULL, id_card_front_url = NULL, " +
|
"id_card_back_url = NULL, certificate_no = NULL, updated_at = NOW() " +
|
"WHERE id_card_no = #{idCardNo} AND status = 3 AND deleted = 0")
|
int clearCancelledIdentityByIdCard(@Param("idCardNo") String idCardNo);
|
|
@Update("UPDATE guide_user SET id_card_no = NULL, id_card_front_url = NULL, " +
|
"id_card_back_url = NULL, certificate_no = NULL, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND status = 2 AND deleted = 0")
|
int releasePendingIdentity(@Param("guideId") Long guideId);
|
|
@Update("UPDATE guide_user SET id_card_no = NULL, id_card_front_url = NULL, " +
|
"id_card_back_url = NULL, certificate_no = NULL, updated_at = NOW() " +
|
"WHERE id_card_no = #{idCardNo} AND status = 2 AND deleted = 0")
|
int clearPendingIdentityByIdCard(@Param("idCardNo") String idCardNo);
|
|
@Select("SELECT * FROM guide_user WHERE id = #{guideId} AND deleted = 0 FOR UPDATE")
|
GuideUser selectForUpdate(@Param("guideId") Long guideId);
|
|
@Select("SELECT COALESCE(balance, 0) FROM guide_user WHERE id = #{guideId} AND deleted = 0")
|
BigDecimal selectBalance(@Param("guideId") Long guideId);
|
|
@Update("UPDATE guide_user SET balance = balance + #{amount}, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND deleted = 0")
|
int increaseBalance(@Param("guideId") Long guideId, @Param("amount") BigDecimal amount);
|
|
@Update("UPDATE guide_user SET balance = balance - #{amount}, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND deleted = 0 AND balance >= #{amount}")
|
int decreaseBalance(@Param("guideId") Long guideId, @Param("amount") BigDecimal amount);
|
|
@Update("UPDATE guide_user SET balance = COALESCE(balance, 0) - #{amount}, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND deleted = 0")
|
int decreaseBalanceForRefund(@Param("guideId") Long guideId, @Param("amount") BigDecimal amount);
|
|
@Update("UPDATE guide_user SET accepted_order_count = accepted_order_count + 1, " +
|
"current_month_order_count = current_month_order_count + 1, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND deleted = 0 AND status = 1")
|
int incrementAcceptedOrderCount(Long guideId);
|
|
@Update("UPDATE guide_user SET status = 0, auto_disabled = 1, updated_at = NOW() " +
|
"WHERE id = #{guideId} AND deleted = 0 AND status = 1 " +
|
"AND COALESCE(auto_disable_whitelisted, 0) = 0 " +
|
"AND accepted_order_count >= #{orderThreshold} " +
|
"AND rating > 0 AND rating <= #{ratingThreshold}")
|
int autoDisableIfEligible(@Param("guideId") Long guideId,
|
@Param("orderThreshold") Integer orderThreshold,
|
@Param("ratingThreshold") BigDecimal ratingThreshold);
|
|
@Update("UPDATE guide_user SET status = 1, auto_disabled = 0, updated_at = NOW() " +
|
"WHERE deleted = 0 AND status = 0 AND auto_disabled = 1 " +
|
"AND (COALESCE(auto_disable_whitelisted, 0) = 1 " +
|
"OR COALESCE(accepted_order_count, 0) < #{orderThreshold} " +
|
"OR COALESCE(rating, 0) <= 0 OR rating > #{ratingThreshold})")
|
int restoreAutoDisabledGuidesNoLongerEligible(@Param("orderThreshold") Integer orderThreshold,
|
@Param("ratingThreshold") BigDecimal ratingThreshold);
|
}
|