15年软件开发经验 只做源码定制 互联网+定制化解决方案

15年软件开发经验,只做源码定制!

原创设计 定制开发

满足您的个性化需求

当前位置:首页 后端开发 java

ruoyi实现表格文件上传及下载

侯永亮| 发布于 2022-07-09 15:20:28| 494阅读| 0点赞| 0评论
举报

ruoyi实现上传下载

前端

/** 导出按钮操作 */
handleExport() {
this.download('manage/task/export', {
...this.queryParams
}, `task_${new Date().getTime()}.xlsx`)
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = "台账导入";
this.upload.open = true;
},
/** 下载模板操作 */
importTemplate() {
this.download('manage/task/importTemplate', {
}, `user_template_${new Date().getTime()}.xlsx`)
},

// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
this.$alert("
" + response.msg + "
", "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
},
// 提交上传文件
submitFileForm(e) {
this.$refs.upload.submit();
console.log(this.upload.url + '?updateSupport=' + this.upload.updateSupport)

}


后端:

做service接口

实现接口:

@Override
public String importUser(List manageTaskVoList, boolean updateSupport, String operName)
{
if (StringUtils.isNull(manageTaskVoList) || manageTaskVoList.size() == 0) {
throw new ServiceException("导入用户数据不能为空!");
}

int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
// String password = configService.selectConfigByKey("sys.user.initPassword");
for (ManageTaskVo manageTaskVo : manageTaskVoList)
{
ManageTask m = new ManageTask();
BeanUtils.copyProperties(manageTaskVo,m);

String s = manageTaskVo.getPipelineNum() + "-" + manageTaskVo.getPipelineNum() + "-" + manageTaskVo.getCraterNum();
String realUserName = manageTaskVo.getRealUserName();
if (realUserName!=null&&realUserName!=""){
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("nick_name",realUserName);
SysUserVo realOne = userService.getOne(wrapper);
if (realOne!=null) m.setRealUserId(realOne.getUserId());
}
String leaderUserName = manageTaskVo.getLeaderUserName();
if (leaderUserName!=null&&leaderUserName!=""){
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("nick_name",leaderUserName);
SysUserVo leaderOne = userService.getOne(wrapper);
if (leaderOne!=null) m.setLeaderUserId(leaderOne.getUserId());
}

try
{
// 验证是否存在这个用户
ManageTask manageTask = manageTaskMapper.selectById(manageTaskVo.getTaskId());

if (StringUtils.isNull(manageTask))//不存在
{
if (m.getTaskStatus()==2)
m.setEndDate(new Date());
m.setTaskId(null);
manageTaskMapper.insert(m);
successNum++;
successMsg.append("
"
+ successNum + "" + s + " 导入成功");
}
else if (updateSupport)//存在---true 覆盖
{
if (m.getTaskStatus()==2 && manageTask.getEndDate()==null)
m.setEndDate(new Date());
manageTaskMapper.updateById(m);
successNum++;
successMsg.append("
"
+ successNum + "" + s + " 更新成功");
}
else //存在
{
failureNum++;
failureMsg.append("
"
+ failureNum + "" + s + " 已存在");
}
}
catch (Exception e)
{
failureNum++;
String msg = "
"
+ failureNum + "" + s + " 导入失败:";
failureMsg.append(msg + e.getMessage());
}
}
if (failureNum > 0)
{
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new ServiceException(failureMsg.toString());
}
else
{
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}



0

0条评论

别默默看啦~登录/注册一起参与讨论吧~

热门标签

侯永亮
微信扫一扫立即咨询
账号登录|扫码登录

立即注册 |忘记密码?

欢迎注册

已有账号马上登录

重置密码

扫码绑定微信
微信扫一扫

绑定手机号

分享到-微信

举报

  • 举报类型:

  • 举报描述:

您好,当前积分不足。

在线客服
拨打电话
17330196230 13230981129
顶部