package com.ruoyi.mall.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mall.mapper.MallRegionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallMeetAddressMapper;
import com.ruoyi.mall.domain.MallMeetAddress;
import com.ruoyi.mall.service.IMallMeetAddressService;

import javax.annotation.Resource;

/**
 * 接货地址Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-15
 */
@Service
public class MallMeetAddressServiceImpl implements IMallMeetAddressService
{
    @Resource
    private MallMeetAddressMapper mallMeetAddressMapper;
    @Resource
    private MallRegionMapper mallRegionMapper;

    /**
     * 查询接货地址
     *
     * @param meetId 接货地址主键
     * @return 接货地址
     */
    @Override
    public MallMeetAddress selectMallMeetAddressByMeetId(Long meetId)
    {
        return mallMeetAddressMapper.selectMallMeetAddressByMeetId(meetId);
    }

    /**
     * 查询接货地址列表
     *
     * @param mallMeetAddress 接货地址
     * @return 接货地址
     */
    @Override
    public List<MallMeetAddress> selectMallMeetAddressList(MallMeetAddress mallMeetAddress)
    {
        return mallMeetAddressMapper.selectMallMeetAddressList(mallMeetAddress);
    }

    /**
     * 新增接货地址
     *
     * @param mallMeetAddress 接货地址
     * @return 结果
     */
    @Override
    public int insertMallMeetAddress(MallMeetAddress mallMeetAddress)
    {
        Integer provinceId = mallRegionMapper.getRegionIdByRegionName(mallMeetAddress.getProvinceName(), null);
        mallMeetAddress.setProvinceId(provinceId);
        Integer cityId = mallRegionMapper.getRegionIdByRegionName(mallMeetAddress.getCityName(), provinceId);
        mallMeetAddress.setCityId(cityId);
        Integer areaId = mallRegionMapper.getRegionIdByRegionName(mallMeetAddress.getAreaName(), cityId);
        mallMeetAddress.setAreaId(areaId);

        mallMeetAddress.setCreateAt(DateUtils.getTime());
        return mallMeetAddressMapper.insertMallMeetAddress(mallMeetAddress);
    }

    /**
     * 修改接货地址
     *
     * @param mallMeetAddress 接货地址
     * @return 结果
     */
    @Override
    public int updateMallMeetAddress(MallMeetAddress mallMeetAddress)
    {
        Integer provinceId = mallRegionMapper.getRegionIdByRegionName(mallMeetAddress.getProvinceName(), null);
        mallMeetAddress.setProvinceId(provinceId);
        Integer cityId = mallRegionMapper.getRegionIdByRegionName(mallMeetAddress.getCityName(), provinceId);
        mallMeetAddress.setCityId(cityId);
        Integer areaId = mallRegionMapper.getRegionIdByRegionName(mallMeetAddress.getAreaName(), cityId);
        mallMeetAddress.setAreaId(areaId);

        mallMeetAddress.setUpdateAt(DateUtils.getTime());
        return mallMeetAddressMapper.updateMallMeetAddress(mallMeetAddress);
    }

    /**
     * 批量删除接货地址
     *
     * @param meetIds 需要删除的接货地址主键
     * @return 结果
     */
    @Override
    public int deleteMallMeetAddressByMeetIds(Long[] meetIds)
    {
        return mallMeetAddressMapper.deleteMallMeetAddressByMeetIds(meetIds);
    }

    /**
     * 删除接货地址信息
     *
     * @param meetId 接货地址主键
     * @return 结果
     */
    @Override
    public int deleteMallMeetAddressByMeetId(Long meetId)
    {
        return mallMeetAddressMapper.deleteMallMeetAddressByMeetId(meetId);
    }

    /**
     * 查询接货地址
     *
     * @param params areaId 区县ID
     * @return 商品集合
     */
    @Override
    public List<Map<String, Object>> getMeetAddressList(Map<String, Object> params) {
        return mallMeetAddressMapper.getMeetAddressList(params);
    }
}
