package com.bjtdba.userCenter.service.impl;

import com.bjtdba.entity.userCenter.UserAddress;
import com.bjtdba.userCenter.dao.UserAddressDao;
import com.bjtdba.userCenter.service.UserAddressService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户地址表(UserAddress)表服务实现类
 *
 * @author makejava
 * @since 2022-10-17 10:57:58
 */
@Service("userAddressService")
public class UserAddressServiceImpl implements UserAddressService {
    @Resource
    private UserAddressDao userAddressDao;

    /**
     * 通过ID查询单条数据
     *
     * @param addressId 主键
     * @return 实例对象
     */
    @Override
    public UserAddress queryById(Integer addressId) {
        return this.userAddressDao.queryById(addressId);
    }

    /**
     * 分页查询
     *
     * @param userAddress 筛选条件
     * @return 查询结果
     */

//    public Page<UserAddress> queryByPage(UserAddress userAddress, PageRequest pageRequest) {
//        long total = this.userAddressDao.count(userAddress);
//        return new PageImpl<>(this.userAddressDao.queryAllByLimit(userAddress, pageRequest), pageRequest, total);
//    }
    @Override
    public List<UserAddress> queryListByObj(UserAddress userAddress){
        return userAddressDao.queryAllByLimit(userAddress);
    }

    /**
     * 新增数据
     *
     * @param userAddress 实例对象
     * @return 实例对象
     */
    @Override
    public UserAddress insert(UserAddress userAddress) {
        this.userAddressDao.insert(userAddress);
        return userAddress;
    }

    /**
     * 修改数据
     *
     * @param userAddress 实例对象
     * @return 实例对象
     */
    @Override
    public UserAddress update(UserAddress userAddress) {
        this.userAddressDao.update(userAddress);
        return this.queryById(userAddress.getAddressId());
    }

    /**
     * 通过主键删除数据
     *
     * @param addressId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer addressId) {
        return this.userAddressDao.deleteById(addressId) > 0;
    }
}
