package com.yijia.station.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.yijia.station.domain.StationPic;
import com.yijia.station.mapper.StationPicMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yijia.station.mapper.StationPayMapper;
import com.yijia.station.domain.StationPay;
import com.yijia.station.service.IStationPayService;

/**
 * 油站支付设置Service业务层处理
 *
 * @author yijia
 * @date 2020-12-10
 */
@Service
public class StationPayServiceImpl implements IStationPayService
{
    @Autowired
    private StationPayMapper stationPayMapper;
    @Autowired
    private StationPicMapper stationPicMapper;

    /**
     * 查询油站支付设置
     *
     * @param payId 油站支付设置ID
     * @return 油站支付设置
     */
    @Override
    public StationPay selectStationPayById(Long payId)
    {
        return stationPayMapper.selectStationPayById(payId);
    }

    /**
     * 查询油站支付设置列表
     *
     * @param stationPay 油站支付设置
     * @return 油站支付设置
     */
    @Override
    public List<StationPay> selectStationPayList(StationPay stationPay)
    {
        return stationPayMapper.selectStationPayList(stationPay);
    }

    /**
     * 新增油站支付设置
     *
     * @param stationPay 油站支付设置
     * @return 结果
     */
    @Override
    public int insertStationPay(StationPay stationPay)
    {
        int i=0;
        List<StationPic> list= stationPay.getImgFileList();
        i =stationPayMapper.insertStationPay(stationPay);
        if(stationPay.getImgFileList()!=null && stationPay.getImgFileList().size()>0){
            for(StationPic pic :list){
                pic.setParentId(stationPay.getPayId());
                pic.setStationId(stationPay.getStationId());
                pic.setStationName(stationPay.getStationName());
                stationPicMapper.insertStationPic(pic);
            }
        }
        return i;
    }

    /**
     * 修改油站支付设置
     *
     * @param stationPay 油站支付设置
     * @return 结果
     */
    @Override
    public int updateStationPay(StationPay stationPay)
    {
        System.out.println("打印支付对象"+ JSON.toJSONString(stationPay));
        int i=0;
        List<StationPic> list= stationPay.getImgFileList();
        i =stationPayMapper.updateStationPay(stationPay);
        //先删除图片
        StationPic stationPic =new StationPic();
        stationPic.setParentId(stationPay.getPayId());
        stationPicMapper.deleteStationPay(stationPic);
        if(stationPay.getImgFileList()!=null && stationPay.getImgFileList().size()>0){
            for(StationPic pic :list){
                pic.setParentId(stationPay.getPayId());
                pic.setStationId(stationPay.getStationId());
                pic.setStationName(stationPay.getStationName());
                stationPicMapper.insertStationPic(pic);
                System.out.println("打印上传图片对象"+ JSON.toJSONString(pic));
            }
        }
        return i;
    }

    /**
     * 批量删除油站支付设置
     *
     * @param payIds 需要删除的油站支付设置ID
     * @return 结果
     */
    @Override
    public int deleteStationPayByIds(Long[] payIds)
    {
        return stationPayMapper.deleteStationPayByIds(payIds);
    }

    /**
     * 删除油站支付设置信息
     *
     * @param payId 油站支付设置ID
     * @return 结果
     */
    @Override
    public int deleteStationPayById(Long payId)
    {
        return stationPayMapper.deleteStationPayById(payId);
    }

    @Override
    public StationPay selectStationPayOne(StationPay stationPay) {
        StationPay pay=new StationPay();
        List<StationPay>  list= stationPayMapper.selectStationPayList(stationPay);
         if(list!=null && list.size()>0){
            pay.setPayId(list.get(0).getPayId());
            pay.setStationId(list.get(0).getStationId());
            pay.setStationName(list.get(0).getStationName());
            pay.setCardEnabledFlag(list.get(0).getCardEnabledFlag());
            pay.setWsPrintFlag(list.get(0).getWsPrintFlag());
            pay.setPrintSetting(list.get(0).getPrintSetting());
            pay.setDiscountSetting(list.get(0).getDiscountSetting());
            pay.setNotice(list.get(0).getNotice());
            pay.setIntegralPrintFlag(list.get(0).getIntegralPrintFlag());
            pay.setIntegralFlag(list.get(0).getIntegralFlag());
            StationPic stationPic =new StationPic();
            stationPic.setStationId(pay.getStationId());
            stationPic.setParentId(pay.getPayId());
             List<StationPic> stationPicList =stationPicMapper.selectStationPicList(stationPic);
            if(stationPicList!=null && stationPicList.size()>0){
                pay.setImgFileList(stationPicList);
            }else{
                pay.setImgFileList(stationPicList);
            }
        }
        return pay;
    }
}
