文件共享初始化
This commit is contained in:
parent
c004a06da5
commit
a04db90747
@ -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> {
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
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 java.util.List;
|
||||
|
||||
public interface IShareService extends IService<Share> {
|
||||
void batchInsertShareFile(List<ShareFile> shareFiles);
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qiwenshare.common.cbb.DateUtil;
|
||||
import com.qiwenshare.common.cbb.RestResult;
|
||||
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.domain.UserFile;
|
||||
import com.qiwenshare.file.dto.sharefile.CheckExtractionCodeDTO;
|
||||
import com.qiwenshare.file.dto.sharefile.ShareFileListBySecretDTO;
|
||||
import com.qiwenshare.file.dto.sharefile.ShareSecretDTO;
|
||||
import com.qiwenshare.file.service.ShareService;
|
||||
import com.qiwenshare.file.service.UserService;
|
||||
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.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 = "/sharesecret")
|
||||
@MyLog(operation = "私密分享", module = CURRENT_MODULE)
|
||||
@ResponseBody
|
||||
public RestResult shareSecret(ShareSecretDTO shareSecretDTO, @RequestHeader("token") String token) {
|
||||
UserBean sessionUserBean = userService.getUserBeanByToken(token);
|
||||
Share share = new Share();
|
||||
BeanUtil.copyProperties(sessionUserBean, share);
|
||||
share.setShareTime(DateUtil.getCurrentTime());
|
||||
share.setUserId(sessionUserBean.getUserId());
|
||||
share.setShareStatus(0);
|
||||
shareService.save(share);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
List<ShareFile> fileList = JSON.parseArray(shareSecretDTO.getFiles(), ShareFile.class);
|
||||
fileList.forEach(p->p.setShareBatchNum("S@#" + uuid.replace("-", "")));
|
||||
shareService.batchInsertShareFile(fileList);
|
||||
return RestResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "分享列表", description = "分享列表", tags = {"share"})
|
||||
@GetMapping(value = "/sharefileList")
|
||||
@ResponseBody
|
||||
public RestResult shareFileListBySecret(ShareFileListBySecretDTO shareFileListBySecretDTO) {
|
||||
log.info(JSON.toJSONString(shareFileListBySecretDTO));
|
||||
LambdaQueryWrapper<Share> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(Share::getShareBatchNum, shareFileListBySecretDTO.getShareBatchNum());
|
||||
List<Share> list = shareService.list(lambdaQueryWrapper);
|
||||
return RestResult.success().data(list.get(0));
|
||||
}
|
||||
|
||||
@Operation(summary = "校验提取码", description = "校验提取码", tags = {"share"})
|
||||
@GetMapping(value = "/checkextractioncode")
|
||||
@ResponseBody
|
||||
public RestResult 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
26
file-web/src/main/java/com/qiwenshare/file/domain/Share.java
Normal file
26
file-web/src/main/java/com/qiwenshare/file/domain/Share.java
Normal 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 isNeedExtractionCode;//0不需要,1需要
|
||||
private Integer shareStatus;//0正常,1已失效,2已撤销
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
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 ShareSecretDTO {
|
||||
@Schema(description="文件集合")
|
||||
private String files;
|
||||
@Schema(description = "过期日期", example="2020-05-23 22:10:33")
|
||||
private String endTime;
|
||||
@Schema(description = "是否需要提取码", example="1-需要/0-不需要")
|
||||
private Integer isNeedExtractionCode;
|
||||
@Schema(description = "提取码", example="asFwe3")
|
||||
private Integer extractionCode;
|
||||
@Schema(description = "备注", example="")
|
||||
private String remarks;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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> {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
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 java.util.List;
|
||||
|
||||
public interface ShareMapper extends BaseMapper<Share> {
|
||||
void batchInsertShareFile(List<ShareFile> shareFiles);
|
||||
}
|
@ -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 {
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
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 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);
|
||||
}
|
||||
}
|
54
file-web/src/main/resources/mybatis/mapper/ShareMapper.xml
Normal file
54
file-web/src/main/resources/mybatis/mapper/ShareMapper.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<?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>
|
||||
|
||||
|
||||
|
||||
<!-- <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>
|
Loading…
Reference in New Issue
Block a user