package com.jsowell.pile.service.impl;

import com.jsowell.common.util.DateUtils;
import com.jsowell.pile.domain.PileFirmwareInfo;
import com.jsowell.pile.mapper.PileFirmwareInfoMapper;
import com.jsowell.pile.service.PileFirmwareInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 充电桩固件信息Service业务层处理
 *
 * @author jsowell
 * @date 2023-06-28
 */
@Service
public class PileFirmwareInfoServiceImpl implements PileFirmwareInfoService {
    @Autowired
    private PileFirmwareInfoMapper pileFirmwareInfoMapper;

    /**
     * 查询充电桩固件信息
     *
     * @param id 充电桩固件信息主键
     * @return 充电桩固件信息
     */
    @Override
    public PileFirmwareInfo selectPileFirmwareInfoById(Long id) {
        return pileFirmwareInfoMapper.selectPileFirmwareInfoById(id);
    }

    /**
     * 查询充电桩固件信息列表
     *
     * @param pileFirmwareInfo 充电桩固件信息
     * @return 充电桩固件信息
     */
    @Override
    public List<PileFirmwareInfo> selectPileFirmwareInfoList(PileFirmwareInfo pileFirmwareInfo) {
        return pileFirmwareInfoMapper.selectPileFirmwareInfoList(pileFirmwareInfo);
    }

    /**
     * 新增充电桩固件信息
     *
     * @param pileFirmwareInfo 充电桩固件信息
     * @return 结果 description
     */
    @Override
    public int insertPileFirmwareInfo(PileFirmwareInfo pileFirmwareInfo) {
        // pileFirmwareInfo.setCreateTime(DateUtils.getNowDate());
        String filePath = pileFirmwareInfo.getFilePath();
        // 两个斜杠 留一个
        filePath = filePath.replaceAll("//", "/");
        pileFirmwareInfo.setFilePath(filePath);
        return pileFirmwareInfoMapper.insertPileFirmwareInfo(pileFirmwareInfo);
    }

    public static void main(String[] args) {
        String filePath = "//4G_06.bin";
        // 两个斜杠 留一个
        filePath = filePath.replaceAll("//", "/");
        System.out.println(filePath);
    }

    /**
     * 修改充电桩固件信息
     *
     * @param pileFirmwareInfo 充电桩固件信息
     * @return 结果
     */
    @Override
    public int updatePileFirmwareInfo(PileFirmwareInfo pileFirmwareInfo) {
        pileFirmwareInfo.setUpdateTime(DateUtils.getNowDate());
        return pileFirmwareInfoMapper.updatePileFirmwareInfo(pileFirmwareInfo);
    }

    /**
     * 批量删除充电桩固件信息
     *
     * @param ids 需要删除的充电桩固件信息主键
     * @return 结果
     */
    @Override
    public int deletePileFirmwareInfoByIds(Long[] ids) {
        return pileFirmwareInfoMapper.deletePileFirmwareInfoByIds(ids);
    }

    /**
     * 删除充电桩固件信息信息
     *
     * @param id 充电桩固件信息主键
     * @return 结果
     */
    @Override
    public int deletePileFirmwareInfoById(Long id) {
        return pileFirmwareInfoMapper.deletePileFirmwareInfoById(id);
    }
}
