/*
 * Author: wangjian
 * 生成ServiceImpl
 */
package com.tofly.gpsboot.service.paln.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.gpsboot.common.system.FileTableEnum;
import com.tofly.gpsboot.mapper.plan.LeakRecordMapper;
import com.tofly.gpsboot.service.comm.IFileInfoService;
import com.tofly.gpsboot.service.paln.LeakRecordService;
import com.tofly.pojo.plan.LeakRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 探漏记录表
 *
 * @author admin
 * @date Tue Oct 26 00:00:00 CST 2021
 */
@Service("leakRecordService")
public class LeakRecordServiceImpl extends ServiceImpl<LeakRecordMapper, LeakRecord> implements LeakRecordService {
    @Autowired
    private IFileInfoService iFileInfoService;
    @Value("${xrty.ftp.leakRecord}")
    private String leakRecordFilePath;
    @Override
    public boolean savaLeakRecordInfo(List<MultipartFile> leakSourceFile, List<MultipartFile> excavationFile, LeakRecord leakRecord) {
        StringBuilder leakSourceFileStr = new StringBuilder("");
        StringBuilder excavationFileStr = new StringBuilder("");
        // 判断当前是否有文件,则存入返回文件id
        if (null != leakSourceFile && leakSourceFile.size() > 0) {
            leakSourceFileStr = iFileInfoService.saveFileList(leakSourceFile, leakRecordFilePath, FileTableEnum.TF_YMPN_LEAK_RECORD_W.getTableName());

        }
        if (!StringUtils.isEmpty(leakSourceFileStr.toString())) {
            leakRecord.setLeakSourceFileId(leakSourceFileStr.toString());
        }
        if (null != excavationFile && excavationFile.size() > 0) {
            excavationFileStr = iFileInfoService.saveFileList(excavationFile, leakRecordFilePath, FileTableEnum.TF_YMPN_LEAK_RECORD_W.getTableName());

        }
        if (!StringUtils.isEmpty(excavationFileStr.toString())) {
            leakRecord.setExcavationFileId(excavationFileStr.toString());
        }

        return this.save(leakRecord);
    }
}
