| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package jnpf.service.impl;
- import jnpf.base.service.SuperServiceImpl;
- 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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import jnpf.constant.MsgCode;
- import jnpf.entity.FileEntity;
- import jnpf.base.ActionResult;
- import jnpf.base.vo.PaginationVO;
- import jnpf.mapper.FileMapper;
- import jnpf.model.YozoFileParams;
- import jnpf.service.YozoService;
- import jnpf.utils.SplicingUrlUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.io.UnsupportedEncodingException;
- import java.net.URLDecoder;
- import java.util.List;
- /**
- *
- *
- * @author JNPF开发平台组
- * @version V3.1.0
- * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
- * @date 2021/5/13
- */
- @Service
- public class YozoServiceImpl extends SuperServiceImpl<FileMapper,FileEntity> implements YozoService {
- @Autowired
- private FileMapper fileMapper;
- @Override
- public String getPreviewUrl(YozoFileParams params) {
- String previewUrl = SplicingUrlUtil.getPreviewUrl(params);
- 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");
- this.save(fileEntity);
- return ActionResult.success(MsgCode.SU001.get());
- }
- @Override
- public FileEntity selectByName(String fileNa) {
- QueryWrapper<FileEntity> wrapper = new QueryWrapper<>();
- wrapper.lambda().eq(FileEntity::getFileName,fileNa);
- return this.getOne(wrapper);
- }
- @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);
- Long total = fileMapper.selectCount(wrapper);
- 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();
- }
- }
|