package com.example.web.mapper; import com.example.web.annotation.DataSource; import com.example.web.dto.ManagerAuthInfo; import com.example.web.dto.UserProductCartDTO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Update; import java.time.LocalDateTime; import java.util.List; @Mapper @DataSource("wechat") public interface UsersMapper { // 获取用户基本信息 UserProductCartDTO getUserBasicInfo(@Param("userId") String userId); // 获取卖家的产品信息 List getSellerProducts(@Param("sellerId") String sellerId); // 销售端:获取买家的购物车信息(公海需求) List getBuyerCartItems(@Param("userId") String userId); /** * 销售端:获取所有买家用户的基本信息(类型为buyer和both) */ List getAllUserBasicInfo(); // 销售端:根据手机号查询买家用户 UserProductCartDTO selectByPhone(@Param("phoneNumber") String phoneNumber); // 新增:根据用户ID精确查询用户 UserProductCartDTO selectByUserId(@Param("userId") String userId); // 新增:更新公海需求信息 int updateProduct( @Param("sellerId") String sellerId, @Param("productId") String productId, @Param("product") UserProductCartDTO.ProductInfo product ); /** * 根据手机号更新用户信息 */ int updateByPhone(UserProductCartDTO user); /** * 更新卖家产品信息 */ int updateProductBySellerId( @Param("sellerId") String sellerId, @Param("productName") String productName, @Param("variety") String variety, @Param("specification") String specification, @Param("quantity") Integer quantity, @Param("grossWeight") String grossWeight, @Param("yolk") String yolk ); /** * 销售端:更新买家购物车信息 - 更新第一个购物车项(向后兼容) */ int updateCartItemByBuyerId( @Param("buyerId") String buyerId, @Param("productId") String productId, @Param("productName") String productName, @Param("specification") String specification, @Param("quantity") Integer quantity, @Param("grossWeight") String grossWeight, @Param("yolk") String yolk ); /** * 更新用户联系人信息 - 更新第一个联系人(向后兼容) */ int updateContactsByUserId( @Param("userId") String userId, @Param("wechat") String wechat, @Param("account") String account, @Param("accountNumber") String accountNumber, @Param("bank") String bank, @Param("address") String address ); /** * 获取用户联系人信息 - 获取第一个联系人(向后兼容) */ List getUserContacts(@Param("userId") String userId); /** * 更新或插入联系人信息 */ int updateOrInsertContact( @Param("userId") String userId, @Param("contactId") String contactId, @Param("wechat") String wechat, @Param("account") String account, @Param("accountNumber") String accountNumber, @Param("bank") String bank, @Param("address") String address ); /** * 更新或插入购物车项 */ int updateOrInsertCartItem( @Param("userId") String userId, @Param("cartItemId") String cartItemId, @Param("productId") String productId, @Param("productName") String productName, @Param("specification") String specification, @Param("quantity") Integer quantity, @Param("grossWeight") String grossWeight, @Param("yolk") String yolk ); /** * 更新特定联系人信息 - 一对多逻辑新增 */ int updateSpecificContact( @Param("userId") String userId, @Param("contactId") String contactId, @Param("wechat") String wechat, @Param("account") String account, @Param("accountNumber") String accountNumber, @Param("bank") String bank, @Param("address") String address ); /** * 更新特定购物车项信息 - 一对多逻辑新增 */ int updateSpecificCartItem( @Param("userId") String userId, @Param("cartItemId") String cartItemId, @Param("productId") String productId, @Param("productName") String productName, @Param("specification") String specification, @Param("quantity") Integer quantity, @Param("grossWeight") String grossWeight, @Param("yolk") String yolk ); /** * 获取用户所有联系人 - 一对多逻辑新增 */ List getUserAllContacts(@Param("userId") String userId); /** * 获取用户所有购物车项 - 一对多逻辑新增 */ List getUserAllCartItems(@Param("userId") String userId); // 联系人信息内部类 - 用于一对多查询 class ContactInfo { private String contactId; private String userId; private String wechat; private String account; private String accountNumber; private String bank; private String address; public String getContactId() { return contactId; } public void setContactId(String contactId) { this.contactId = contactId; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getWechat() { return wechat; } public void setWechat(String wechat) { this.wechat = wechat; } public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getAccountNumber() { return accountNumber; } public void setAccountNumber(String accountNumber) { this.accountNumber = accountNumber; } public String getBank() { return bank; } public void setBank(String bank) { this.bank = bank; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } } // 购物车项内部类 - 用于一对多查询 class CartItem { private String cartItemId; private String userId; private String productId; private String productName; private String specification; private Integer quantity; private String grossWeight; private String yolk; public String getCartItemId() { return cartItemId; } public void setCartItemId(String cartItemId) { this.cartItemId = cartItemId; } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getProductId() { return productId; } public void setProductId(String productId) { this.productId = productId; } public String getProductName() { return productName; } public void setProductName(String productName) { this.productName = productName; } public String getSpecification() { return specification; } public void setSpecification(String specification) { this.specification = specification; } public Integer getQuantity() { return quantity; } public void setQuantity(Integer quantity) { this.quantity = quantity; } public String getGrossWeight() { return grossWeight; } public void setGrossWeight(String grossWeight) { this.grossWeight = grossWeight; } public String getYolk() { return yolk; } public void setYolk(String yolk) { this.yolk = yolk; } } /** * 根据产品ID精确更新产品信息 */ int updateProductByProductId( @Param("productId") String productId, @Param("productName") String productName, @Param("variety") String variety, @Param("specification") String specification, @Param("quantity") Integer quantity, @Param("grossWeight") String grossWeight, @Param("yolk") String yolk ); // 在 SupplyUsersMapper.java 中添加以下方法 /** * 查询超过指定时间的未分级客户 */ List findUnclassifiedCustomersOlderThan(LocalDateTime thresholdTime); /** * 查询超过指定时间的组织公海池客户 */ List findOrganizationSeaPoolsCustomersOlderThan(LocalDateTime thresholdTime); /** * 更新客户等级 */ @Update("UPDATE users SET level = #{level}, updated_at = #{updateTime} WHERE user_id = #{userId}") boolean updateCustomerLevel(@Param("userId") String userId, @Param("level") String level, @Param("updateTime") LocalDateTime updateTime); // 🔥 新增:查询最近回流的客户 List findRecentlyRecycledCustomers(@Param("sinceTime") LocalDateTime sinceTime); // 新增:直接查询有权限的客户列表(支持分页) List getAuthorizedCustomers(@Param("authInfo") ManagerAuthInfo authInfo, @Param("limit") int limit, @Param("offset") int offset); /** * 根据认证信息获取有权限的用户ID列表 */ List getAuthorizedUserIds(@Param("authInfo") ManagerAuthInfo authInfo); // 获取授权客户总数 int getAuthorizedCustomersCount(@Param("authInfo") ManagerAuthInfo authInfo); /** * 根据手机号和权限查询用户 */ UserProductCartDTO selectByPhoneWithAuth(@Param("phoneNumber") String phoneNumber, @Param("authInfo") ManagerAuthInfo authInfo); // 🔥 新增:批量查询用户联系人信息 List getUserContactsByUserIds(@Param("userIds") List userIds); // 🔥 新增:批量查询用户购物车信息 List getBuyerCartItemsByUserIds(@Param("userIds") List userIds); // 🔥 新增:批量查询用户购物车信息(兼容旧方法名) List getCartItemsByUserIds(@Param("userIds") List userIds); // 🔥 新增:批量查询用户基本信息 List getUserBasicInfoByUserIds(@Param("userIds") List userIds); // 🔥 新增:更新用户通知状态 @Update("UPDATE users SET notice = #{notice} WHERE userId = #{userId}") int updateNotice(@Param("userId") String userId, @Param("notice") String notice); }