package com.jsowell.pile.service.impl;

import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.MemberBasicInfo;
import com.jsowell.pile.domain.PileStationWhitelist;
import com.jsowell.pile.mapper.PileStationWhitelistMapper;
import com.jsowell.pile.service.IMemberBasicInfoService;
import com.jsowell.pile.service.IPileStationWhitelistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 站点白名单Service业务层处理
 *
 * @author jsowell
 * @date 2023-04-19
 */
@Service
public class PileStationWhitelistServiceImpl implements IPileStationWhitelistService {
	@Autowired
	private PileStationWhitelistMapper pileStationWhitelistMapper;

	@Autowired
	private IMemberBasicInfoService memberBasicInfoService;

	/**
	 * 查询站点白名单
	 *
	 * @param id 站点白名单主键
	 * @return 站点白名单
	 */
	@Override
	public PileStationWhitelist selectPileStationWhitelistById(Long id) {
		return pileStationWhitelistMapper.selectPileStationWhitelistById(id);
	}

	/**
	 * 查询站点白名单列表
	 *
	 * @param pileStationWhitelist 站点白名单
	 * @return 站点白名单
	 */
	@Override
	public List<PileStationWhitelist> selectPileStationWhitelistList(PileStationWhitelist pileStationWhitelist) {
		return pileStationWhitelistMapper.selectPileStationWhitelistList(pileStationWhitelist);
	}

	/**
	 * 新增站点白名单
	 *
	 * @param pileStationWhitelist 站点白名单
	 * @return 结果
	 */
	@Override
	public int insertPileStationWhitelist(PileStationWhitelist pileStationWhitelist) {
		// pileStationWhitelist.setCreateTime(DateUtils.getNowDate());
		if (StringUtils.isBlank(pileStationWhitelist.getMobileNumber())) {
			return 0;
		}
		MemberBasicInfo info = memberBasicInfoService.selectInfoByMobileNumber(pileStationWhitelist.getMobileNumber());
		if (info == null) {
			return 0;
		}
		pileStationWhitelist.setMemberId(info.getMemberId());
		return pileStationWhitelistMapper.insertPileStationWhitelist(pileStationWhitelist);
	}

	/**
	 * 修改站点白名单
	 *
	 * @param pileStationWhitelist 站点白名单
	 * @return 结果
	 */
	@Override
	public int updatePileStationWhitelist(PileStationWhitelist pileStationWhitelist) {
		pileStationWhitelist.setUpdateTime(DateUtils.getNowDate());
		return pileStationWhitelistMapper.updatePileStationWhitelist(pileStationWhitelist);
	}

	/**
	 * 批量删除站点白名单
	 *
	 * @param ids 需要删除的站点白名单主键
	 * @return 结果
	 */
	@Override
	public int deletePileStationWhitelistByIds(Long[] ids) {
		return pileStationWhitelistMapper.deletePileStationWhitelistByIds(ids);
	}

	/**
	 * 删除站点白名单信息
	 *
	 * @param id 站点白名单主键
	 * @return 结果
	 */
	@Override
	public int deletePileStationWhitelistById(Long id) {
		return pileStationWhitelistMapper.deletePileStationWhitelistById(id);
	}

	@Override
	public PileStationWhitelist queryWhitelistByMemberId(String stationId, String memberId) {
		if (StringUtils.isBlank(stationId) || StringUtils.isBlank(memberId)) {
			return null;
		}
		return pileStationWhitelistMapper.queryWhitelistByMemberId(stationId, memberId);
	}
}
