小程序添加资料下载功能
This commit is contained in:
+4
-20
@@ -34,30 +34,14 @@ public class PayFileDownloadRecord implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "文件id")
|
||||
private java.lang.String fileId;
|
||||
/**文件名称*/
|
||||
@Excel(name = "文件名称", width = 15)
|
||||
@ApiModelProperty(value = "文件名称")
|
||||
private java.lang.String fileName;
|
||||
/**文件目录*/
|
||||
@Excel(name = "目录层级", width = 15)
|
||||
@ApiModelProperty(value = "目录层级")
|
||||
private java.lang.String filePath;
|
||||
/**企业名称*/
|
||||
@Excel(name = "企业名称", width = 15)
|
||||
@ApiModelProperty(value = "企业名称")
|
||||
private java.lang.String companyName;
|
||||
/**下载用户名称*/
|
||||
@Excel(name = "下载用户名称", width = 15)
|
||||
@ApiModelProperty(value = "下载用户名称")
|
||||
private java.lang.String downloadName;
|
||||
|
||||
@ApiModelProperty(value = "会议名称")
|
||||
private java.lang.String meetingName;
|
||||
/**用户id*/
|
||||
@Excel(name = "用户id", width = 15)
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private java.lang.String userId;
|
||||
/**创建人*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private java.lang.String createBy;
|
||||
/**创建时间*/
|
||||
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd")
|
||||
@Excel(name = "下载时间", width = 15,exportFormat = "yyyy-MM-dd")
|
||||
|
||||
@@ -112,4 +112,9 @@ public class PayProjectCommon {
|
||||
* 当前登录人是否可以操作(1为可操作,2为不可操作)
|
||||
*/
|
||||
public final static Integer CHECKOUT_OPERATION2 = 2;
|
||||
|
||||
/**
|
||||
* 文件下载次数上线
|
||||
*/
|
||||
public final static Integer DOWNLOAD_COUNT = 5;
|
||||
}
|
||||
|
||||
+27
-5
@@ -11,16 +11,26 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.PasswordUtil;
|
||||
import com.jero.common.util.ValidUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.company.entity.PayContactsManagement;
|
||||
import com.jero.company.service.IPayContactsManagementService;
|
||||
import com.jero.data.entity.PayFileDownloadRecord;
|
||||
import com.jero.data.service.IPayFileDownloadRecordService;
|
||||
import com.jero.meeting.entity.PayMeeting;
|
||||
import com.jero.meeting.service.IPayMeetingService;
|
||||
import com.jero.modules.message.handle.impl.EmailSendMsgHandle;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.project.common.PayProjectCommon;
|
||||
@@ -58,8 +68,6 @@ public class PayWorkingGroupDataFileController extends JeroController<PayWorking
|
||||
@Resource
|
||||
private IPayWorkingGroupDataFileService payWorkingGroupDataFileService;
|
||||
@Resource
|
||||
private Environment env;
|
||||
@Resource
|
||||
private IOSSFileService iossFileService;
|
||||
@Value("${jero.path.upload}")
|
||||
private String upLoadPath;
|
||||
@@ -67,9 +75,9 @@ public class PayWorkingGroupDataFileController extends JeroController<PayWorking
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param payWorkingGroupDataFile
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param payWorkingGroupDataFile 资料列表
|
||||
* @param pageNo 起始页
|
||||
* @param pageSize 条数
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@@ -208,6 +216,20 @@ public class PayWorkingGroupDataFileController extends JeroController<PayWorking
|
||||
return Result.OK(payWorkingGroupDataFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序-资料下载
|
||||
*
|
||||
* @param fileId 文件id
|
||||
* @param userId 用户id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="小程序-资料下载", notes="小程序-资料下载")
|
||||
@GetMapping(value = "/wxDownloadFile")
|
||||
public Result<?> wxDownloadFile(@RequestParam(name="fileId") String fileId,@RequestParam(name="userId") String userId) {
|
||||
payWorkingGroupDataFileService.wxDownloadFile(fileId,userId);
|
||||
return Result.OK("发送成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
|
||||
+10
@@ -32,5 +32,15 @@ public interface IPayWorkingGroupDataFileService extends IService<PayWorkingGrou
|
||||
* @Exception
|
||||
*/
|
||||
List<PayWorkingGroupDataFile> queryList(String projectId,Integer projectType);
|
||||
/**
|
||||
* @Description 资料下载
|
||||
* @Author lqt
|
||||
* @Date 2021/10/13
|
||||
* @Param fileId 文件id
|
||||
* @Param userId 用户id
|
||||
* @Return
|
||||
* @Exception
|
||||
*/
|
||||
void wxDownloadFile(String fileId,String userId);
|
||||
|
||||
}
|
||||
|
||||
+94
-4
@@ -1,20 +1,37 @@
|
||||
package com.jero.project.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.PasswordUtil;
|
||||
import com.jero.company.entity.PayContactsManagement;
|
||||
import com.jero.company.service.IPayContactsManagementService;
|
||||
import com.jero.data.entity.PayFileDownloadRecord;
|
||||
import com.jero.data.service.IPayFileDownloadRecordService;
|
||||
import com.jero.meeting.entity.PayMeeting;
|
||||
import com.jero.meeting.service.IPayMeetingService;
|
||||
import com.jero.modules.message.handle.impl.EmailSendMsgHandle;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.project.common.PayProjectCommon;
|
||||
import com.jero.project.entity.PayWorkingGroupDataFile;
|
||||
import com.jero.project.entity.PayWorkingGroupDistributionRecord;
|
||||
import com.jero.project.mapper.PayWorkingGroupDataFileMapper;
|
||||
import com.jero.project.service.IPayWorkingGroupDataFileService;
|
||||
import com.jero.project.service.IPayWorkingGroupDistributionRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
@@ -28,6 +45,18 @@ public class PayWorkingGroupDataFileServiceImpl extends ServiceImpl<PayWorkingGr
|
||||
|
||||
@Resource
|
||||
private PayWorkingGroupDataFileMapper payWorkingGroupDataFileMapper;
|
||||
@Resource
|
||||
private IPayContactsManagementService payContactsManagementService;
|
||||
@Resource
|
||||
private IOSSFileService iossFileService;
|
||||
@Resource
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Resource
|
||||
private IPayFileDownloadRecordService payFileDownloadRecordService;
|
||||
@Resource
|
||||
private Environment env;
|
||||
@Resource
|
||||
private IPayMeetingService payMeetingService;
|
||||
|
||||
@Override
|
||||
public IPage<PayWorkingGroupDataFile> queryPageList(IPage<PayWorkingGroupDataFile> page, PayWorkingGroupDataFile payWorkingGroupDataFile) {
|
||||
@@ -38,4 +67,65 @@ public class PayWorkingGroupDataFileServiceImpl extends ServiceImpl<PayWorkingGr
|
||||
public List<PayWorkingGroupDataFile> queryList(String projectId,Integer projectType) {
|
||||
return payWorkingGroupDataFileMapper.queryList(projectId,projectType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void wxDownloadFile(String fileId, String userId) {
|
||||
PayContactsManagement payContactsManagement = payContactsManagementService.getById(userId);
|
||||
if(Objects.isNull(payContactsManagement)){
|
||||
throw new JeroBootException("用户不存在!");
|
||||
}
|
||||
// 验证文件是否为会议
|
||||
LambdaQueryWrapper<PayMeeting> queryPayMeeting = new LambdaQueryWrapper<>();
|
||||
queryPayMeeting.like(PayMeeting::getMeetingData,fileId);
|
||||
List<PayMeeting> listPayMeeting = payMeetingService.list(queryPayMeeting);
|
||||
// 验证会议文件下载次数是否达到上线
|
||||
if(!CollectionUtils.isEmpty(listPayMeeting)){
|
||||
LambdaQueryWrapper<PayFileDownloadRecord> queryPayFileDownloadRecord = new LambdaQueryWrapper<>();
|
||||
queryPayFileDownloadRecord.eq(PayFileDownloadRecord::getUserId,userId);
|
||||
queryPayFileDownloadRecord.eq(PayFileDownloadRecord::getFileId,fileId);
|
||||
int count = payFileDownloadRecordService.count(queryPayFileDownloadRecord);
|
||||
if(count >= PayProjectCommon.DOWNLOAD_COUNT){
|
||||
throw new JeroBootException("文件下载次数已达上线!");
|
||||
}
|
||||
}
|
||||
OSSFile byId = iossFileService.getById(fileId);
|
||||
if(Objects.isNull(byId)){
|
||||
throw new JeroBootException("没有找到文件!");
|
||||
}
|
||||
String path = env.getProperty("jero.path.upload") + File.separator;
|
||||
List<String> listFile = new ArrayList<>();
|
||||
// 文件路径
|
||||
String url = byId.getUrl();
|
||||
listFile.add(path + url);
|
||||
if(StringUtils.isEmpty(payContactsManagement.getEmail())){
|
||||
throw new JeroBootException("用户邮箱不能为空!");
|
||||
}
|
||||
try {
|
||||
// 发送人为管理员
|
||||
LoginUser loginUser = sysBaseAPI.getUserByName("admin");
|
||||
String fromEmail = loginUser.getEmail();
|
||||
String fromEmailPassword = loginUser.getEmailPassword();
|
||||
String fromEmailNew = PasswordUtil.decrypt(fromEmail);
|
||||
String fromEmailPasswordNew = PasswordUtil.decrypt(fromEmailPassword);
|
||||
EmailSendMsgHandle emailHandle = new EmailSendMsgHandle(fromEmailNew,fromEmailPasswordNew);
|
||||
String email = PasswordUtil.decrypt(payContactsManagement.getEmail());
|
||||
emailHandle.SendMsgAndFile(email,"","",listFile);
|
||||
}catch (Exception e){
|
||||
log.error("邮件发送异常",e);
|
||||
throw new JeroBootException("邮件发送失败!");
|
||||
}
|
||||
|
||||
// 添加下载记录
|
||||
PayFileDownloadRecord payFileDownloadRecord = new PayFileDownloadRecord();
|
||||
payFileDownloadRecord.setFileId(byId.getId());
|
||||
payFileDownloadRecord.setUserId(userId);
|
||||
payFileDownloadRecordService.save(payFileDownloadRecord);
|
||||
// 更新文件下载次数
|
||||
Integer downloadNumber = Objects.isNull(byId.getDownloadNumber()) ? 1 : byId.getDownloadNumber();
|
||||
LambdaUpdateWrapper<OSSFile> updateOSSFile = new LambdaUpdateWrapper<>();
|
||||
updateOSSFile.eq(OSSFile::getId,byId.getId());
|
||||
updateOSSFile.set(OSSFile::getDownloadNumber,downloadNumber);
|
||||
iossFileService.update(updateOSSFile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user