!13 代码合并

Merge pull request !13 from MAC/develop
This commit is contained in:
MAC 2021-03-07 14:28:45 +08:00 committed by Gitee
commit 6035f03f03
27 changed files with 513 additions and 18 deletions

View File

@ -18,7 +18,7 @@
</p>
<p align="center">
<a href="http://fileos.qiwenshare.com/" target="_blank">在线演示环境</a> &nbsp;|
<a href="http://pan.qiwenshare.com/" target="_blank">在线演示环境</a> &nbsp;|
<a href="https://www.qiwenshare.com/essay/detail/169" target="_blank">安装指导</a>&nbsp;|
<a href="https://www.qiwenshare.com/essay/detail/324" target="_blank">更新日志</a>
</p>

View File

@ -0,0 +1,24 @@
package com.qiwenshare.common.util;
import java.util.Random;
public class RandomUtil {
public static String getStringRandom(int length) {
String val = "";
Random random = new Random();
//参数length表示生成几位随机数
for(int i = 0; i < length; i++) {
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
//输出字母还是数字
if("char".equalsIgnoreCase(charOrNum)){
//输出是大写字母还是小写字母
int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
val += (char)(random.nextInt(26) + temp);
}else if("num".equalsIgnoreCase(charOrNum)) {
val += String.valueOf(random.nextInt(10));
}
}
return val;
}
}

View File

@ -0,0 +1,9 @@
package com.qiwenshare.file.api;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
public interface IShareFileService extends IService<ShareFile> {
}

View File

@ -0,0 +1,14 @@
package com.qiwenshare.file.api;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qiwenshare.file.domain.RecoveryFile;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
import com.qiwenshare.file.vo.share.ShareFileListVO;
import java.util.List;
public interface IShareService extends IService<Share> {
void batchInsertShareFile(List<ShareFile> shareFiles);
List<ShareFileListVO> selectShareFileListByBatchNum(Share share);
}

View File

@ -22,6 +22,7 @@ import com.qiwenshare.file.vo.file.FileListVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -203,7 +204,7 @@ public class FileController {
}
UserBean sessionUserBean = userService.getUserBeanByToken(token);
List<UserFile> userFiles = JSON.parseArray(batchDeleteFileDto.getFiles(), UserFile.class);
DigestUtils.md5Hex("data");
for (UserFile userFile : userFiles) {
String uuid = UUID.randomUUID().toString();
userFile.setDeleteBatchNum(uuid);

View File

@ -0,0 +1,131 @@
package com.qiwenshare.file.controller;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qiwenshare.common.cbb.DateUtil;
import com.qiwenshare.common.cbb.RestResult;
import com.qiwenshare.common.util.RandomUtil;
import com.qiwenshare.file.anno.MyLog;
import com.qiwenshare.file.api.IShareService;
import com.qiwenshare.file.api.IUserService;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
import com.qiwenshare.file.domain.UserBean;
import com.qiwenshare.file.dto.sharefile.*;
import com.qiwenshare.file.vo.share.ShareFileListVO;
import com.qiwenshare.file.vo.share.ShareFileVO;
import com.qiwenshare.file.vo.share.ShareTypeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Tag(name = "share", description = "该接口为文件分享接口")
@RestController
@Slf4j
@RequestMapping("/share")
public class ShareController {
public static final String CURRENT_MODULE = "文件分享";
@Resource
IUserService userService;
@Resource
IShareService shareService;
@Operation(summary = "分享文件", description = "分享文件统一接口", tags = {"share"})
@PostMapping(value = "/sharefile")
@MyLog(operation = "分享文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<ShareFileVO> shareFile(ShareFileDTO shareSecretDTO, @RequestHeader("token") String token) {
ShareFileVO shareSecretVO = new ShareFileVO();
UserBean sessionUserBean = userService.getUserBeanByToken(token);
String extractionCode = RandomUtil.getStringRandom(6);
String uuid = UUID.randomUUID().toString();
Share share = new Share();
BeanUtil.copyProperties(sessionUserBean, share);
share.setShareTime(DateUtil.getCurrentTime());
share.setUserId(sessionUserBean.getUserId());
share.setShareStatus(0);
share.setExtractionCode(extractionCode);
share.setShareBatchNum(uuid);
shareService.save(share);
List<ShareFile> fileList = JSON.parseArray(shareSecretDTO.getFiles(), ShareFile.class);
fileList.forEach(p->p.setShareBatchNum(uuid.replace("-", "")));
shareService.batchInsertShareFile(fileList);
shareSecretVO.setShareBatchNum(uuid.replace("-", ""));
return RestResult.success().data(shareSecretVO);
}
@Operation(summary = "分享列表", description = "分享列表", tags = {"share"})
@GetMapping(value = "/sharefileList")
@ResponseBody
public RestResult<List<ShareFileListVO>> shareFileListBySecret(ShareFileListBySecretDTO shareFileListBySecretDTO) {
log.info(JSON.toJSONString(shareFileListBySecretDTO));
Share share = new Share();
share.setShareBatchNum(shareFileListBySecretDTO.getShareBatchNum());
List<ShareFileListVO> list = shareService.selectShareFileListByBatchNum(share);
return RestResult.success().data(list);
}
@Operation(summary = "分享类型", description = "可用此接口判断是否需要提取码", tags = {"share"})
@GetMapping(value = "/sharetype")
@ResponseBody
public RestResult<ShareTypeVO> shareType(ShareTypeDTO shareTypeDTO) {
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Share::getShareBatchNum, shareTypeDTO.getShareBatchNum());
Share share = shareService.getOne(lambdaQueryWrapper);
ShareTypeVO shareTypeVO = new ShareTypeVO();
shareTypeVO.setShareType(share.getShareType());
return RestResult.success().data(shareTypeVO);
}
@Operation(summary = "校验提取码", description = "校验提取码", tags = {"share"})
@GetMapping(value = "/checkextractioncode")
@ResponseBody
public RestResult<String> checkExtractionCode(CheckExtractionCodeDTO checkExtractionCodeDTO) {
// log.info(JSON.toJSONString(shareFileListBySecretDTO));
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Share::getShareBatchNum, checkExtractionCodeDTO.getShareBatchNum())
.eq(Share::getExtractionCode, checkExtractionCodeDTO.getExtractionCode());
List<Share> list = shareService.list(lambdaQueryWrapper);
if (list.isEmpty()) {
return RestResult.fail().message("校验失败");
} else {
return RestResult.success();
}
}
@Operation(summary = "校验过期时间", description = "校验过期时间", tags = {"share"})
@GetMapping(value = "/checkendtime")
@ResponseBody
public RestResult<String> checkEndTime(CheckEndTimeDTO checkEndTimeDTO) {
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Share::getShareBatchNum, checkEndTimeDTO.getShareBatchNum());
Share share = shareService.getOne(lambdaQueryWrapper);
String endTime = share.getEndTime();
Date endTimeDate = null;
try {
endTimeDate = DateUtil.getDateByFormatString(endTime, "yyyy-MM-dd HH:mm:ss");
} catch (ParseException e) {
log.error("日期解析失败:{}" , e);
}
if (new Date().after(endTimeDate)) {
return RestResult.fail().message("分享已过期");
} else {
return RestResult.success();
}
}
}

View File

@ -69,7 +69,7 @@ public class UserController {
@MyLog(operation = "用户登录", module = CURRENT_MODULE)
@ResponseBody
public RestResult<UserLoginVo> userLogin(
@Parameter(description = "登录用户名") String username,
@Parameter(description = "登录手机号") String username,
@Parameter(description = "登录密码") String password) {
RestResult<UserLoginVo> restResult = new RestResult<UserLoginVo>();
UserBean saveUserBean = userService.findUserInfoByTelephone(username);

View File

@ -0,0 +1,26 @@
package com.qiwenshare.file.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import javax.persistence.*;
@Data
@Table(name = "share")
@Entity
@TableName("share")
public class Share {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@TableId(type = IdType.AUTO)
private Long shareId;
private Long userId;
private String shareTime;
private String endTime;
private String extractionCode;
private String shareBatchNum;
private Integer shareType;//0公共1私密2好友
private Integer shareStatus;//0正常1已失效2已撤销
}

View File

@ -0,0 +1,22 @@
package com.qiwenshare.file.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import javax.persistence.*;
@Data
@Table(name = "sharefile")
@Entity
@TableName("sharefile")
public class ShareFile {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@TableId(type = IdType.AUTO)
private Long shareFileId;
private String shareBatchNum;
private Long userFileId;
}

View File

@ -9,7 +9,7 @@ import javax.persistence.*;
@Data
@Table(name = "userfile", uniqueConstraints = {
@UniqueConstraint(name = "fileindex", columnNames = {"fileName", "filePath", "extendName"})})
@UniqueConstraint(name = "fileindex", columnNames = {"fileName", "filePath", "extendName", "deleteFlag"})})
@Entity
@TableName("userfile")
public class UserFile {

View File

@ -0,0 +1,12 @@
package com.qiwenshare.file.dto.sharefile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "校验过期时间DTO",required = true)
public class CheckEndTimeDTO {
@Schema(description="批次号")
private String shareBatchNum;
}

View File

@ -0,0 +1,17 @@
package com.qiwenshare.file.dto.sharefile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "校验提取码DTO",required = true)
public class CheckExtractionCodeDTO {
@Schema(description="批次号")
private String shareBatchNum;
@Schema(description="提取码")
private String extractionCode;
}

View File

@ -0,0 +1,21 @@
package com.qiwenshare.file.dto.sharefile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "分享文件DTO",required = true)
public class ShareFileDTO {
@Schema(description="文件集合")
private String files;
@Schema(description = "过期日期", example="2020-05-23 22:10:33")
private String endTime;
@Schema(description = "分享类型", example="0公共分享1私密分享2好友分享")
private Integer shareType;
@Schema(description = "备注", example="")
private String remarks;
}

View File

@ -0,0 +1,17 @@
package com.qiwenshare.file.dto.sharefile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "分享列表DTO",required = true)
public class ShareFileListBySecretDTO {
@Schema(description="批次号")
private String shareBatchNum;
@Schema(description="提取码")
private String extractionCode;
}

View File

@ -0,0 +1,14 @@
package com.qiwenshare.file.dto.sharefile;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "分享类型DTO",required = true)
public class ShareTypeDTO {
@Schema(description="批次号")
private String shareBatchNum;
}

View File

@ -8,7 +8,5 @@ import com.qiwenshare.file.domain.OperationLogBean;
import java.util.List;
public interface OperationLogMapper extends BaseMapper<OperationLogBean> {
List<OperationLogBean> selectOperationLog();
void insertOperationLog(OperationLogBean operationlogBean);
}

View File

@ -0,0 +1,8 @@
package com.qiwenshare.file.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
public interface ShareFileMapper extends BaseMapper<ShareFile> {
}

View File

@ -0,0 +1,14 @@
package com.qiwenshare.file.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiwenshare.file.domain.FileBean;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
import com.qiwenshare.file.vo.share.ShareFileListVO;
import java.util.List;
public interface ShareMapper extends BaseMapper<Share> {
void batchInsertShareFile(List<ShareFile> shareFiles);
List<ShareFileListVO> selectShareFileListByBatchNum(Share share);
}

View File

@ -28,13 +28,13 @@ public class OperationLogService extends ServiceImpl<OperationLogMapper, Operat
@Override
public List<OperationLogBean> selectOperationLog() {
List<OperationLogBean> result = operationLogMapper.selectOperationLog();
List<OperationLogBean> result = operationLogMapper.selectList(null);
return result;
}
@Override
public void insertOperationLog(OperationLogBean operationlogBean) {
operationLogMapper.insertOperationLog(operationlogBean);
operationLogMapper.insert(operationlogBean);
}

View File

@ -0,0 +1,17 @@
package com.qiwenshare.file.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiwenshare.file.api.IShareFileService;
import com.qiwenshare.file.api.IShareService;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
import com.qiwenshare.file.mapper.ShareFileMapper;
import com.qiwenshare.file.mapper.ShareMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ShareFileService extends ServiceImpl<ShareFileMapper, ShareFile> implements IShareFileService {
}

View File

@ -0,0 +1,31 @@
package com.qiwenshare.file.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiwenshare.file.api.IShareService;
import com.qiwenshare.file.domain.RecoveryFile;
import com.qiwenshare.file.domain.Share;
import com.qiwenshare.file.domain.ShareFile;
import com.qiwenshare.file.mapper.RecoveryFileMapper;
import com.qiwenshare.file.mapper.ShareMapper;
import com.qiwenshare.file.vo.share.ShareFileListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Service
public class ShareService extends ServiceImpl<ShareMapper, Share> implements IShareService {
@Resource
ShareMapper shareMapper;
@Override
public void batchInsertShareFile(List<ShareFile> shareFiles) {
shareMapper.batchInsertShareFile(shareFiles);
}
@Override
public List<ShareFileListVO> selectShareFileListByBatchNum(Share share) {
return shareMapper.selectShareFileListByBatchNum(share);
}
}

View File

@ -0,0 +1,43 @@
package com.qiwenshare.file.vo.share;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description="分享文件列表VO")
@Data
public class ShareFileListVO {
@Schema(description="文件id")
private Long fileId;
@Schema(description="文件时间戳姓名")
private String timeStampName;
@Schema(description="文件url")
private String fileUrl;
@Schema(description="文件大小")
private Long fileSize;
@Schema(description="是否sso存储")
private Integer isOSS;
//
// private Long userFileId;
//
// private Long userId;
@Schema(description="文件名")
private String fileName;
@Schema(description="文件路径")
private String filePath;
@Schema(description="文件扩展名")
private String extendName;
@Schema(description="是否是目录 0-否, 1-是")
private Integer isDir;
@Schema(description="上传时间")
private String uploadTime;
//
// private Long shareId;
//
// private String shareTime;
// private String endTime;
// private String extractionCode;
// private String shareBatchNum;
// private Integer shareType;//0公共1私密2好友
// private Integer shareStatus;//0正常1已失效2已撤销
}

View File

@ -0,0 +1,13 @@
package com.qiwenshare.file.vo.share;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description="分享文件VO")
public class ShareFileVO {
@Schema(description="批次号")
private String shareBatchNum;
@Schema(description = "提取编码")
private String extractionCode;
}

View File

@ -0,0 +1,11 @@
package com.qiwenshare.file.vo.share;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description="分享类型VO")
public class ShareTypeVO {
@Schema(description="0公共1私密2好友")
private Integer shareType;
}

View File

@ -6,14 +6,5 @@
<mapper namespace="com.qiwenshare.file.mapper.OperationLogMapper">
<select id="selectOperationLog" resultType="com.qiwenshare.file.domain.OperationLogBean">
SELECT * FROM operationLog
</select>
<insert id="insertOperationLog" parameterType="com.qiwenshare.file.domain.OperationLogBean" useGeneratedKeys="true"
keyProperty="operationLogId">
INSERT INTO operationLog (operation, userId, terminal, result, detail, source, time, logLevel)
VALUES (#{operation}, #{userId}, #{terminal}, #{result}, #{detail}, #{source}, #{time}, #{logLevel});
</insert>
</mapper>

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qiwenshare.file.mapper.ShareMapper">
<insert id="batchInsertShareFile" parameterType="java.util.List">
INSERT ignore INTO sharefile (shareBatchNum, userFileId)
VALUES
<foreach collection="list" item="file" index="index" separator=",">
(#{file.shareBatchNum}, #{file.userFileId})
</foreach>
</insert>
<select id="selectShareFileListByBatchNum" parameterType="com.qiwenshare.file.domain.Share" resultType="com.qiwenshare.file.vo.share.ShareFileListVO">
select * from sharefile a
left join userfile b on b.userFileId = a.userFileId
left join file c on c.fileId = b.fileId
where a.shareBatchNum = #{shareBatchNum}
</select>
<!-- <update id="updateFile" parameterType="java">-->
<!-- <choose>-->
<!-- <when test="isDir == 1">-->
<!-- UPDATE file SET filename=#{fileName}, uploadTime = #{uploadTime}-->
<!-- where fileId = #{fileId};-->
<!-- UPDATE file SET filepath=REPLACE(filepath, #{oldFilePath}, #{filePath}) WHERE filepath LIKE N'${oldFilePath}%';-->
<!-- </when>-->
<!-- <otherwise>-->
<!-- update file-->
<!-- <set>-->
<!-- <if test="fileName != null">-->
<!-- fileName = #{fileName},-->
<!-- </if>-->
<!-- <if test="uploadTime != null">-->
<!-- uploadTime = #{uploadTime},-->
<!-- </if>-->
<!-- <if test="fileUrl != null">-->
<!-- fileUrl = #{fileUrl},-->
<!-- </if>-->
<!-- </set>-->
<!-- where fileId = #{fileId}-->
<!-- </otherwise>-->
<!-- </choose>-->
<!-- </update>-->
</mapper>

View File

@ -1,4 +1,4 @@
set settingDir=file-common/src/main/resources/conf/settings.xml
mvn install -s %settingDir%
mvn clean install -s %settingDir%
pause