package com.jsowell.pile.service.impl;

import com.jsowell.common.enums.TitleTypeEnum;
import com.jsowell.common.util.DateUtils;
import com.jsowell.pile.domain.MemberInvoiceTitle;
import com.jsowell.pile.mapper.MemberInvoiceTitleMapper;
import com.jsowell.pile.service.IMemberInvoiceTitleService;
import com.jsowell.pile.vo.uniapp.InvoiceTitleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员发票抬头Service业务层处理
 *
 * @author jsowell
 * @date 2023-04-13
 */
@Service
public class MemberInvoiceTitleServiceImpl implements IMemberInvoiceTitleService {
	@Autowired
	private MemberInvoiceTitleMapper memberInvoiceTitleMapper;

	@Override
	public InvoiceTitleVO selectByTitleId(String titleId) {
		MemberInvoiceTitle memberInvoiceTitle = memberInvoiceTitleMapper.selectMemberInvoiceTitleById(Long.parseLong(titleId));
		if (memberInvoiceTitle == null) {
			return null;
		}
		return InvoiceTitleVO.builder()
				.titleId(memberInvoiceTitle.getId() + "")
				.titleName(memberInvoiceTitle.getName())
				.titleType(TitleTypeEnum.getLabel(memberInvoiceTitle.getTitleType()))
				.taxId(memberInvoiceTitle.getTaxId())
				.unitAddress(memberInvoiceTitle.getUnitAddress())
				.phoneNumber(memberInvoiceTitle.getPhoneNumber())
				.bankName(memberInvoiceTitle.getBankName())
				.bankAccountNumber(memberInvoiceTitle.getBankAccountNumber())
				.build();
	}

	/**
	 * 查询会员发票抬头
	 *
	 * @param id 会员发票抬头主键
	 * @return 会员发票抬头
	 */
	@Override
	public MemberInvoiceTitle selectMemberInvoiceTitleById(Long id) {
		return memberInvoiceTitleMapper.selectMemberInvoiceTitleById(id);
	}

	/**
	 * 查询会员发票抬头列表
	 *
	 * @param memberInvoiceTitle 会员发票抬头
	 * @return 会员发票抬头
	 */
	@Override
	public List<MemberInvoiceTitle> selectMemberInvoiceTitleList(MemberInvoiceTitle memberInvoiceTitle) {
		return memberInvoiceTitleMapper.selectMemberInvoiceTitleList(memberInvoiceTitle);
	}

	/**
	 * 新增会员发票抬头
	 *
	 * @param memberInvoiceTitle 会员发票抬头
	 * @return 结果
	 */
	@Override
	public int insertMemberInvoiceTitle(MemberInvoiceTitle memberInvoiceTitle) {
		return memberInvoiceTitleMapper.insertMemberInvoiceTitle(memberInvoiceTitle);
	}

	/**
	 * 修改会员发票抬头
	 *
	 * @param memberInvoiceTitle 会员发票抬头
	 * @return 结果
	 */
	@Override
	public int updateMemberInvoiceTitle(MemberInvoiceTitle memberInvoiceTitle) {
		memberInvoiceTitle.setUpdateTime(DateUtils.getNowDate());
		return memberInvoiceTitleMapper.updateMemberInvoiceTitle(memberInvoiceTitle);
	}

	/**
	 * 批量删除会员发票抬头
	 *
	 * @param ids 需要删除的会员发票抬头主键
	 * @return 结果
	 */
	@Override
	public int deleteMemberInvoiceTitleByIds(Long[] ids) {
		return memberInvoiceTitleMapper.deleteMemberInvoiceTitleByIds(ids);
	}

	/**
	 * 删除会员发票抬头信息
	 *
	 * @param id 会员发票抬头主键
	 * @return 结果
	 */
	@Override
	public int deleteMemberInvoiceTitleById(Long id) {
		return memberInvoiceTitleMapper.deleteMemberInvoiceTitleById(id);
	}
}
