package com.cyl.manager.oth.service;

import java.util.Arrays;
import java.util.List;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyl.manager.oth.domain.entity.SalesAddressInfo;
import com.cyl.manager.oth.domain.query.SalesAddressInfoQuery;
import com.cyl.manager.oth.mapper.SalesAddressInfoMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 退货地址信息Service业务层处理
 *
 *
 * @author zcc
 */
@Service
public class SalesAddressInfoService {
    @Autowired
    private SalesAddressInfoMapper salesAddressInfoMapper;

    /**
     * 查询退货地址信息
     *
     * @param id 退货地址信息主键
     * @return 退货地址信息
     */
    public SalesAddressInfo selectById(Long id) {
        return salesAddressInfoMapper.selectById(id);
    }

    /**
     * 查询退货地址信息列表
     *
     * @param query 查询条件
     * @param page 分页条件
     * @return 退货地址信息
     */
    public List<SalesAddressInfo> selectList(SalesAddressInfoQuery query, Pageable page) {
        if (page != null) {
            PageHelper.startPage(page.getPageNumber() + 1, page.getPageSize());
        }
        QueryWrapper<SalesAddressInfo> qw = new QueryWrapper<>();
        return salesAddressInfoMapper.selectList(qw);
    }

    /**
     * 新增退货地址信息
     *
     * @param salesAddressInfo 退货地址信息
     * @return 结果
     */
    public int insert(SalesAddressInfo salesAddressInfo) {
        salesAddressInfo.setCreateTime(LocalDateTime.now());
        return salesAddressInfoMapper.insert(salesAddressInfo);
    }

    /**
     * 修改退货地址信息
     *
     * @param salesAddressInfo 退货地址信息
     * @return 结果
     */
    public int update(SalesAddressInfo salesAddressInfo) {
        return salesAddressInfoMapper.updateById(salesAddressInfo);
    }

    /**
     * 批量删除退货地址信息
     *
     * @param ids 需要删除的退货地址信息主键
     * @return 结果
     */
    public int deleteByIds(Long[] ids) {
        return salesAddressInfoMapper.updateDelFlagByIds(ids);
    }

    /**
     * 删除退货地址信息信息
     *
     * @param id 退货地址信息主键
     * @return 结果
     */
    public int deleteById(Long id) {
        Long[] ids = {id};
        return salesAddressInfoMapper.updateDelFlagByIds(ids);
    }
}