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.FutureStocks;
import com.ruoyi.invest.domain.dto.FutureStocksDto;
import com.ruoyi.invest.domain.vo.FutureStocksVo;
import com.ruoyi.invest.mapper.FutureStocksMapper;
import com.ruoyi.invest.service.IFutureStocksService;
import org.springframework.stereotype.Service;

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

/**
 * 期货股票基本信息Service业务层处理
 *
 * @author tianyongbao
 * @date 2024-03-19
 */
@Service
public class FutureStocksServiceImpl implements IFutureStocksService
{
    @Resource
    private FutureStocksMapper futureStocksMapper;

    /**
     * 查询期货股票基本信息
     *
     * @param id 期货股票基本信息主键
     * @return 期货股票基本信息
     */
    @Override
    public FutureStocksVo selectFutureStocksById(Long id)
    {
        return futureStocksMapper.selectFutureStocksById(id);
    }

    /**
     * 查询期货股票基本信息列表
     *
     * @param futureStocksDto 期货股票基本信息
     * @return 期货股票基本信息
     */
    @Override
    public List<FutureStocksVo> selectFutureStocksList(FutureStocksDto futureStocksDto)
    {
        List<FutureStocksVo> futureStocksVoList= futureStocksMapper.selectFutureStocksList(futureStocksDto);
        //修改名称加卡号
        for (FutureStocksVo futureStocks : futureStocksVoList) {
            if(futureStocks.getCode()!=null){
                futureStocks.setNameCode(futureStocks.getName()+"（"+ futureStocks.getCode()+"）");
            }else {
                futureStocks.setNameCode(futureStocks.getName());
            }
            if(futureStocks.getBankName()!=null){
              futureStocks.setBankNameCode(futureStocks.getBankName()+"（"+ StringUtils.getLastNumberChars(4,futureStocks.getBankCode()+"）"));
            }
            if(futureStocks.getBankNameCode()!=null){
                futureStocks.setNameDebitNameCode(futureStocks.getName()+"（"+ futureStocks.getCode()+"）"+"-"+futureStocks.getBankNameCode());
            }else {
                futureStocks.setNameDebitNameCode(futureStocks.getName()+"（"+ futureStocks.getCode()+"）");
            }


        }
        return futureStocksVoList;
    }

    /**
     * 新增期货股票基本信息
     *
     * @param futureStocks 期货股票基本信息
     * @return 结果
     */
    @Override
    public int insertFutureStocks(FutureStocks futureStocks)
    {
        futureStocks.setCreateBy(SecurityUtils.getUsername());
        futureStocks.setCreateTime(DateUtils.getNowDate());
        futureStocks.setId(IdWorker.getId());
        return futureStocksMapper.insertFutureStocks(futureStocks);
    }

    /**
     * 修改期货股票基本信息
     *
     * @param futureStocks 期货股票基本信息
     * @return 结果
     */
    @Override
    public int updateFutureStocks(FutureStocks futureStocks)
    {
        futureStocks.setUpdateBy(SecurityUtils.getUsername());
        futureStocks.setUpdateTime(DateUtils.getNowDate());
        return futureStocksMapper.updateFutureStocks(futureStocks);
    }

    /**
     * 批量删除期货股票基本信息
     *
     * @param ids 需要删除的期货股票基本信息主键
     * @return 结果
     */
    @Override
    public int deleteFutureStocksByIds(Long[] ids)
    {
        return futureStocksMapper.removeFutureStocksByIds(ids);
    }

    /**
     * 删除期货股票基本信息信息
     *
     * @param id 期货股票基本信息主键
     * @return 结果
     */
    @Override
    public int deleteFutureStocksById(Long id)
    {
        return futureStocksMapper.removeFutureStocksById(id);
    }
}
