刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package jnpf.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PaginationVO;
import jnpf.constant.MsgCode;
import jnpf.entity.FileEntity;
import jnpf.mapper.FileMapper;
import jnpf.model.YozoFileParams;
import jnpf.model.YozoParams;
import jnpf.service.YozoService;
import jnpf.utils.SplicingUrlUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
 
/**
 * @author JNPF
 */
@Service
@RequiredArgsConstructor
public class YozoServiceImpl implements YozoService {
 
    
    private final FileMapper fileMapper;
 
    public static final String F_FILE_VERSION = "F_FileVersion";
 
    @Override
    public String getPreviewUrl(YozoFileParams params) {
        return SplicingUrlUtil.getPreviewUrl(params);
    }
 
    @Override
    public ActionResult<Object>saveFileId(String fileVersionId, String fileId, String fileName) {
 
        FileEntity fileEntity =new FileEntity();
        fileEntity.setId(fileId);
        fileEntity.setFileName(fileName);
        fileEntity.setFileVersionId(fileVersionId);
        fileEntity.setType("create");
 
        fileMapper.insert(fileEntity);
 
        return ActionResult.success(MsgCode.SU001.get());
    }
 
    @Override
    public FileEntity selectByName(String fileNa) {
        QueryWrapper<FileEntity> wrapper =new QueryWrapper<>();
        wrapper.eq("F_FileName",fileNa);
        return fileMapper.selectOne(wrapper);
    }
 
    @Override
    public ActionResult<Object>saveFileIdByHttp(String fileVersionId, String fileId, String fileUrl) {
        String fileName = "";
        String url="";
        String name="";
        try {
             url = URLDecoder.decode(fileUrl, "UTF-8");
             if (url.contains("/")){
                 fileName = url.substring(url.lastIndexOf("/") + 1);
             }else {
                 fileName = url.substring(url.lastIndexOf("\\") + 1);
             }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //同一url文件数
        QueryWrapper<FileEntity> wrapper =new QueryWrapper<>();
        wrapper.eq("F_Url",url);
        Integer total = 0;
        if (total==0){
            name=fileName;
        }else{
            String t =total.toString();
            name= fileName+"(" + t +")";
        }
        FileEntity fileEntity =new FileEntity();
        fileEntity.setType(url.contains("http") ? "http" : "local");
        fileEntity.setFileVersionId(fileVersionId );
        fileEntity.setId(fileId);
        fileEntity.setFileName(name);
        fileEntity.setUrl(url);
        fileMapper.insert(fileEntity);
        return ActionResult.success(MsgCode.SU001.get());
    }
 
    @Override
    public ActionResult<Object>deleteFileByVersionId(String versionId) {
        QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(F_FILE_VERSION,versionId);
        int i = fileMapper.delete(wrapper);
        if (i==1){
            return ActionResult.success(MsgCode.SU003.get());
        }
            return ActionResult.fail(MsgCode.FA003.get());
    }
 
    @Override
    public FileEntity selectByVersionId(String fileVersionId) {
        QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(F_FILE_VERSION,fileVersionId);
        return fileMapper.selectOne(wrapper);
    }
 
    @Override
    public ActionResult<Object>deleteBatch(String[] versions) {
        for (String version : versions){
            QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
            wrapper.eq(F_FILE_VERSION,version);
            int i = fileMapper.delete(wrapper);
            if (i==0){
                return ActionResult.fail(MsgCode.FA045.get(version));
            }
        }
        return ActionResult.success(MsgCode.SU003.get());
 
    }
 
    @Override
    public void editFileVersion(String oldFileId, String newFileId) {
        UpdateWrapper<FileEntity> wrapper = new UpdateWrapper<>();
        wrapper.eq(F_FILE_VERSION,oldFileId);
        FileEntity fileEntity =new FileEntity();
        fileEntity.setFileVersionId(newFileId);
        fileEntity.setOldFileVersionId(oldFileId);
        fileMapper.update(fileEntity,wrapper);
    }
 
    @Override
    public List<FileEntity> getAllList(PaginationVO pageModel) {
        Page<FileEntity> page = new Page<>(pageModel.getCurrentPage(), pageModel.getPageSize());
        IPage<FileEntity> iPage = fileMapper.selectPage(page,null);
        return iPage.getRecords();
    }
 
 
}