package com.fjhx.service.maintain.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.entity.maintain.MaintainRecords;
import com.fjhx.mapper.maintain.MaintainRecordsMapper;
import com.fjhx.params.maintain.MaintainRecordsVo;
import com.fjhx.service.maintain.MaintainRecordsService;
import com.fjhx.utils.FileClientUtil;
import com.fjhx.utils.WrapperUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 维护记录 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-11-02
 */
@Service
public class MaintainRecordsServiceImpl extends ServiceImpl<MaintainRecordsMapper, MaintainRecords> implements MaintainRecordsService {

    @Override
    public Page<MaintainRecords> getPage(Map<String, String> condition) {

        QueryWrapper<MaintainRecords> wrapper = Wrappers.query();

        WrapperUtil.init(condition, wrapper)
                .keyword("deviceName", "maintainUser", "id")
                .createTimeDesc();

        return page(condition, wrapper);
    }

    @Override
    public void add(MaintainRecordsVo maintainRecordsVo) {
        save(maintainRecordsVo);
        FileClientUtil.bindingFile(maintainRecordsVo.getId(), maintainRecordsVo.getFileInfoList());
    }

    @Override
    public void edit(MaintainRecordsVo maintainRecordsVo) {
        updateById(maintainRecordsVo);
        FileClientUtil.againBindingFile(maintainRecordsVo.getId(), maintainRecordsVo.getFileInfoList());
    }

    @Override
    public void delete(MaintainRecordsVo maintainRecordsVo) {
        removeById(maintainRecordsVo.getId());
        FileClientUtil.relieveBindingFile(maintainRecordsVo.getId());
    }

}
