package com.ruoyi.invest.service.impl;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.IdWorker;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.invest.domain.PosMachine;
import com.ruoyi.invest.domain.dto.PosMachineDto;
import com.ruoyi.invest.domain.vo.PosMachineVo;
import com.ruoyi.invest.mapper.PosMachineMapper;
import com.ruoyi.invest.service.IPosMachineService;
import org.springframework.stereotype.Service;

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

/**
 * pos机信息Service业务层处理
 *
 * @author tianyongbao
 * @date 2024-03-18
 */
@Service
public class PosMachineServiceImpl implements IPosMachineService
{
    @Resource
    private PosMachineMapper posMachineMapper;

    /**
     * 查询pos机信息
     *
     * @param id pos机信息主键
     * @return pos机信息
     */
    @Override
    public PosMachineVo selectPosMachineById(Long id)
    {
        return posMachineMapper.selectPosMachineById(id);
    }

    /**
     * 查询pos机信息列表
     *
     * @param posMachineDto pos机信息
     * @return pos机信息
     */
    @Override
    public List<PosMachineVo> selectPosMachineList(PosMachineDto posMachineDto)
    {
        List<PosMachineVo> posMachineVoList= posMachineMapper.selectPosMachineList(posMachineDto);
        //修改名称加卡号
        for (PosMachineVo posMachine : posMachineVoList) {
            posMachine.setBankNameCode(posMachine.getBankName()+"（"+ StringUtils.getLastNumberChars(4,posMachine.getBankCode()+"）"));
            posMachine.setNameMerchantName(posMachine.getName()+"-"+ posMachine.getMerchantName()+"-"+posMachine.getBankName()+"（"+ StringUtils.getLastNumberChars(4,posMachine.getBankCode()+"）"));
        }
        return posMachineVoList;
    }

    /**
     * 新增pos机信息
     *
     * @param posMachine pos机信息
     * @return 结果
     */
    @Override
    public int insertPosMachine(PosMachine posMachine)
    {
        posMachine.setCreateBy(SecurityUtils.getUsername());
        posMachine.setCreateTime(DateUtils.getNowDate());
        posMachine.setId(IdWorker.getId());
        return posMachineMapper.insertPosMachine(posMachine);
    }

    /**
     * 修改pos机信息
     *
     * @param posMachine pos机信息
     * @return 结果
     */
    @Override
    public int updatePosMachine(PosMachine posMachine)
    {
        posMachine.setUpdateBy(SecurityUtils.getUsername());
        posMachine.setUpdateTime(DateUtils.getNowDate());
        return posMachineMapper.updatePosMachine(posMachine);
    }

    /**
     * 批量删除pos机信息
     *
     * @param ids 需要删除的pos机信息主键
     * @return 结果
     */
    @Override
    public int deletePosMachineByIds(Long[] ids)
    {
        return posMachineMapper.removePosMachineByIds(ids);
    }

    /**
     * 删除pos机信息信息
     *
     * @param id pos机信息主键
     * @return 结果
     */
    @Override
    public int deletePosMachineById(Long id)
    {
        return posMachineMapper.removePosMachineById(id);
    }
}
