FileServiceImpl.java 1.53 KB
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.tiptimes.service.impl;

import com.tiptimes.dao.FileDao;
import com.tiptimes.model.File;
import com.tiptimes.service.FileService;
import com.tiptimes.util.DATEUtil;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class FileServiceImpl implements FileService {
    @Autowired
    private FileDao fileDao;

    public FileServiceImpl() {
    }

    public File selectFileByFileID(String fileID) {
        List<File> file_list = this.fileDao.listFileByFileID(fileID);
        return file_list.size() == 0 ? null : (File)file_list.get(0);
    }

    @Transactional
    public void saveFile(File file) {
        this.fileDao.saveFile(file);
    }

    @Transactional
    public String updateFile(String id, String name) {
        if (!"".equals(id.trim())) {
            List<String> file_name_list = this.fileDao.listFileNameByFileID(id);
            if (file_name_list.size() != 0) {
                String file_name = ((String)file_name_list.get(0)).substring(((String)file_name_list.get(0)).lastIndexOf(".") + 1, ((String)file_name_list.get(0)).length());
                this.fileDao.updateFile(id, name + DATEUtil.getNewDateYMD() + "." + file_name);
                return name + DATEUtil.getNewDateYMD() + "." + file_name;
            }
        }

        return "";
    }
}