ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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 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
public class YozoServiceImpl implements YozoService {
 
    @Autowired
    private FileMapper fileMapper;
 
    @Override
    public String getPreviewUrl(YozoFileParams params) {
        StringBuilder paramsUrl = new StringBuilder();
        if (!StringUtils.isEmpty(params.getNoCache())) {
            paramsUrl.append("&noCache=" + params.getNoCache());
        }
        if (!StringUtils.isEmpty(params.getWatermark())) {
            paramsUrl.append("&watermark=" + params.getWatermark());
        }
        if (!StringUtils.isEmpty(params.getIsCopy())) {
            paramsUrl.append("&isCopy=" + params.getIsCopy());
        }
        if (!StringUtils.isEmpty(params.getPageStart())) {
            paramsUrl.append("&pageStart=" + params.getPageStart());
        }
        if (!StringUtils.isEmpty(params.getPageEnd())) {
            paramsUrl.append("&pageEnd=" + params.getPageEnd());
        }
        if (!StringUtils.isEmpty(params.getType())) {
            paramsUrl.append("&type=" + params.getType());
        }
        String s = paramsUrl.toString();
        String previewUrl= YozoParams.DOMAIN+"?k=" + YozoParams.DOMAIN_KEY + "&url=" + params.getUrl() + s;
        return previewUrl;
    }
 
    @Override
    public ActionResult 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);
        FileEntity fileEntity = fileMapper.selectOne(wrapper);
        return fileEntity;
    }
 
    @Override
    public ActionResult 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 deleteFileByVersionId(String versionId) {
        QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("F_FileVersion",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_FileVersion",fileVersionId);
        FileEntity fileEntity = fileMapper.selectOne(wrapper);
        return fileEntity;
    }
 
    @Override
    public ActionResult deleteBatch(String[] versions) {
        for (String version : versions){
            QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("F_FileVersion",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_FileVersion",oldFileId);
        FileEntity fileEntity =new FileEntity();
        fileEntity.setFileVersionId(newFileId);
        fileEntity.setOldFileVersionId(oldFileId);
        fileMapper.update(fileEntity,wrapper);
    }
 
    @Override
    public List<FileEntity> getAllList(PaginationVO pageModel) {
        Page page = new Page(pageModel.getCurrentPage(),pageModel.getPageSize());
        IPage<FileEntity> iPage = fileMapper.selectPage(page,null);
        return iPage.getRecords();
    }
 
 
}