TienChin 渠道管理-渠道导入
  0nZj5jIUY2eL 2023年11月02日 46 0

ChannelController

@PostMapping("/importTemplate")
void importTemplate(HttpServletResponse response) {
    ExcelUtil<Channel> util = new ExcelUtil<>(Channel.class);
    util.importTemplateExcel(response, "渠道数据");
}

@Log(title = "渠道管理", businessType = BusinessType.IMPORT)
@PreAuthorize("hasPermission('tienchin:channel:import')")
@PostMapping("/importData")
AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
    ExcelUtil<Channel> util = new ExcelUtil<>(Channel.class);
    List<Channel> channelList = util.importExcel(file.getInputStream());
    return AjaxResult.success(iChannelService.importChannel(channelList, updateSupport));
}

IChannelService

/**
 * 导入渠道数据
 *
 * @param channelList   渠道数据列表
 * @param updateSupport 是否更新支持,如果已存在,则进行更新数据
 * @return {@code boolean} {@code true} 导入成功 {@code false} 导入失败
 */
boolean importChannel(List<Channel> channelList, boolean updateSupport);

ChannelServiceImpl

@Override
@Transactional(rollbackFor = Exception.class)
public boolean importChannel(List<Channel> channelList, boolean updateSupport) {
    String username = SecurityUtils.getUsername();
    LocalDateTime currentTime = LocalDateTime.now();

    List<Channel> channels = channelList
            .stream()
            .peek(channel -> {
                if (updateSupport) {
                    channel.setUpdateBy(username);
                    channel.setUpdateTime(currentTime);
                } else {
                    channel.setCreateBy(username);
                    channel.setCreateTime(currentTime);
                    channel.setChannelId(null);
                }
            }).collect(Collectors.toList());

    if (updateSupport) {
        return updateBatchById(channels);
    } else {
        return saveBatch(channels);
    }
}

!> 修复若依框架导入数据 Byte 类型数据报错的问题

更改 ReflectUtils.java 中的 invokeMethodByName 方法:

TienChin 渠道管理-渠道导入_数据

...

else if (cs[i] == Byte.class) {
    args[i] = Convert.toByte(args[i]);
}

...

配置 MySQL 批量插入

# 批量插入
&rewriteBatchedStatements=true

配置在 MySQL 的连接地址后面即可:

TienChin 渠道管理-渠道导入_List_02

因为 MyBatisPlus 当中的批量插入,并没有达到我的预料效果,所以我们需要进行配置,配置方式如上。



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
0nZj5jIUY2eL