package shop.alien.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import shop.alien.entity.store.LawyerUser;
import shop.alien.entity.store.vo.LawyerUserVo;

import java.util.List;

/**
 * <p>
 * 律师用户 Mapper 接口
 * </p>
 *
 * @author system
 * @since 2025-01-XX
 */
@Mapper
public interface LawyerUserMapper extends BaseMapper<LawyerUser> {


@Update("<script>" +
        "UPDATE lawyer_user " +
        "<set>" +
        "<if test='firmId != null'>firm_id = #{firmId},</if>" +
        "<if test='phone != null'>phone = #{phone},</if>" +
        "<if test='name != null'>name = #{name},</if>" +
        "<if test='idCard != null'>id_card = #{idCard},</if>" +
        "<if test='password != null'>password = #{password},</if>" +
        "<if test='payPassword != null'>pay_password = #{payPassword},</if>" +
        "<if test='money != null'>money = #{money},</if>" +
        "<if test='status != null'>status = #{status},</if>" +
        "<if test='passType != null'>pass_type = #{passType},</if>" +
        "<if test='deleteFlag != null'>delete_flag = #{deleteFlag},</if>" +
        "<if test='createdTime != null'>created_time = #{createdTime},</if>" +
        "<if test='createdUserId != null'>created_user_id = #{createdUserId},</if>" +
        "<if test='updatedTime != null'>updated_time = #{updatedTime},</if>" +
        "<if test='updatedUserId != null'>updated_user_id = #{updatedUserId},</if>" +
        "<if test='logoutFlag != null'>logout_flag = #{logoutFlag},</if>" +
        "<if test='logoutReason != null'>logout_reason = #{logoutReason},</if>" +
        "<if test='logoutTime != null'>logout_time = #{logoutTime},</if>" +
        "<if test='logoutCode != null'>logout_code = #{logoutCode},</if>" +
        "<if test='nickName != null'>nick_name = #{nickName},</if>" +
        "<if test='accountBlurb != null'>account_blurb = #{accountBlurb},</if>" +
        "<if test='headImg != null'>head_img = #{headImg},</if>" +
        "<if test='alipayAccount != null'>alipay_account = #{alipayAccount},</if>" +
        "<if test='lawyerCertificateNo != null'>lawyer_certificate_no = #{lawyerCertificateNo},</if>" +
        "<if test='lawFirm != null'>law_firm = #{lawFirm},</if>" +
        "<if test='practiceYears != null'>practice_years = #{practiceYears},</if>" +
        "<if test='practiceStartDate != null'>practice_start_date = #{practiceStartDate},</if>" +
        "<if test='specialtyFields != null'>specialty_fields = #{specialtyFields},</if>" +
        "<if test='certificationStatus != null'>certification_status = #{certificationStatus},</if>" +
        "<if test='certificationFailReason != null'>certification_fail_reason = #{certificationFailReason},</if>" +
        "<if test='certificationTime != null'>certification_time = #{certificationTime},</if>" +
        "<if test='certificationReviewerId != null'>certification_reviewer_id = #{certificationReviewerId},</if>" +
        "<if test='certificateImage != null'>certificate_image = #{certificateImage},</if>" +
        "<if test='idCardFrontImage != null'>id_card_front_image = #{idCardFrontImage},</if>" +
        "<if test='idCardBackImage != null'>id_card_back_image = #{idCardBackImage},</if>" +
        "<if test='serviceScore != null'>service_score = #{serviceScore},</if>" +
        "<if test='serviceCount != null'>service_count = #{serviceCount},</if>" +
        "<if test='goodReviewCount != null'>good_review_count = #{goodReviewCount},</if>" +
        "<if test='mediumReviewCount != null'>medium_review_count = #{mediumReviewCount},</if>" +
        "<if test='badReviewCount != null'>bad_review_count = #{badReviewCount},</if>" +
        "<if test='consultationFee != null'>consultation_fee = #{consultationFee},</if>" +
        "<if test='agencyFee != null'>agency_fee = #{agencyFee},</if>" +
        "<if test='province != null'>province = #{province},</if>" +
        "<if test='city != null'>city = #{city},</if>" +
        "<if test='district != null'>district = #{district},</if>" +
        "<if test='address != null'>address = #{address},</if>" +
        "<if test='email != null'>email = #{email},</if>" +
        "<if test='gender != null'>gender = #{gender},</if>" +
        "<if test='birthday != null'>birthday = #{birthday},</if>" +
        "<if test='personalIntroduction != null'>personal_introduction = #{personalIntroduction},</if>" +
        "<if test='educationBackground != null'>education_background = #{educationBackground},</if>" +
        "<if test='workExperience != null'>work_experience = #{workExperience},</if>" +
        "<if test='expertiseCases != null'>expertise_cases = #{expertiseCases},</if>" +
        "<if test='isOnline != null'>is_online = #{isOnline},</if>" +
        "<if test='lastOnlineTime != null'>last_online_time = #{lastOnlineTime},</if>" +
        "<if test='isRecommended != null'>is_recommended = #{isRecommended},</if>" +
        "<if test='recommendSort != null'>recommend_sort = #{recommendSort},</if>" +
        "<if test='orderReceivingStatus != null'>order_receiving_status = #{orderReceivingStatus},</if>" +
        "<if test='lawyerExpertiseAreaId != null'>lawyer_expertise_area_id = #{lawyerExpertiseAreaId},</if>" +
        "<if test='commissionRate != null'>commission_rate = #{commissionRate},</if>" +
        "<if test='paymentNum != null'>payment_num = #{paymentNum},</if>" +
        "</set>" +
        "WHERE id = #{id}" +
        "</script>")
Integer updateLawyerUser(LawyerUser user);



   @Select("<script>" +
           "SELECT " +
           "user.id, " +
           "user.phone, " +
           "user.`name`, " +
           "user.firm_id, " +
           "user.head_img, " +
           "user.personal_introduction, " +
           "user.order_receiving_status, " +
           "user.practice_start_date, " +
           "user.charge_minute, " +
           "user.minute_num, " +
           "user.charge_time, " +
           "user.time_num, " +
           "user.certificate_image, " +
           "firm.firm_name AS firmName, " +
           "firmTwo.payment_account AS paymentNum, " +
           "firmTwo.address AS address, " +
           "GROUP_CONCAT(area.problem_scenario_id SEPARATOR ',') AS problemScenarioId, " +
           "GROUP_CONCAT(a.name SEPARATOR ',') AS scenarioNames, " +
           "(SELECT GROUP_CONCAT(id SEPARATOR ',') FROM lawyer_legal_problem_scenario WHERE level = 1) AS firstLevelScenarioId, " +
           "(SELECT GROUP_CONCAT(name SEPARATOR ',') FROM lawyer_legal_problem_scenario WHERE level = 1) AS firstLevelScenario " +
           "FROM lawyer_user user " +
           "LEFT JOIN law_firm firm ON firm.id = user.firm_id " +
           "LEFT JOIN law_firm_payment firmTwo ON firmTwo.firm_id = user.firm_id " +
           "LEFT JOIN lawyer_service_area area ON area.lawyer_user_id = user.id " +
           "LEFT JOIN lawyer_legal_problem_scenario a ON a.id = area.problem_scenario_id " +
           "<where>" +
           "<if test='lawyerId != null'>user.id = #{lawyerId} AND </if>" +
           "firm.delete_flag = 0 AND " +
           "user.delete_flag = 0 AND " +
           "area.delete_flag = 0 AND " +
           "a.delete_flag = 0" +
           "</where>" +
           "GROUP BY " +
           "user.id" +
           "</script>")
   LawyerUserVo selectInfo(@Param("lawyerId") Integer lawyerId);

   List<LawyerUserVo> selectLawyerUserList(@Param("name") String name,
                                          @Param("phone") String phone,
                                          @Param("firmId") Integer firmId,
                                          @Param("startTime") String startTime,
                                           @Param("endTime") String endTime);
   
   Long selectLawyerUserListCount(@Param("name") String name,
                                  @Param("phone") String phone,
                                  @Param("firmId") Integer firmId,
                                  @Param("createdTimeStart") String createdTimeStart);

}

