package com.fuyuanshen.equipment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fuyuanshen.common.core.utils.MapstructUtils;
import com.fuyuanshen.equipment.domain.UserApp;
import com.fuyuanshen.equipment.domain.bo.UserAppBo;
import com.fuyuanshen.equipment.enums.AppUserTypeEnum;
import com.fuyuanshen.equipment.mapper.UserAppMapper;
import com.fuyuanshen.equipment.service.AppUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;

/**
 * Service业务层处理
 *
 * @author Lion Li
 * @date 2025-06-27
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class UserAppServiceImpl implements AppUserService {

    private final UserAppMapper userAppMapper;


    /**
     * 修改APP用户信息
     *
     * @param bo APP用户信息
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(UserAppBo bo) {
        UserApp update = MapstructUtils.convert(bo, UserApp.class);
        return userAppMapper.updateById(update) > 0;
    }


    /**
     * 查询小程序用户信息
     *
     * @param phoneNumber
     * @return
     */
    @Override
    public UserApp getMpUser(Long phoneNumber) {
        QueryWrapper<UserApp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phonenumber", phoneNumber);
        queryWrapper.eq("user_type", AppUserTypeEnum.XCX_USER.getCode());
        return userAppMapper.selectOne(queryWrapper);
    }

    @Override
    public UserApp loadUserByUsername(String username) {
        QueryWrapper<UserApp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", username);
        queryWrapper.eq("user_type", AppUserTypeEnum.XCX_USER.getCode());
        return userAppMapper.selectOne(queryWrapper);
    }


    /**
     * 新增小程序用户信息
     *
     * @param userApp
     * @return
     */
    @Override
    public void saveMpUser(UserApp userApp) {
        userAppMapper.insert(userApp);
    }


}
