前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >TienChin 渠道管理-渠道导入

TienChin 渠道管理-渠道导入

作者头像
BNTang
发布2023-10-12 14:48:26
1200
发布2023-10-12 14:48:26
举报
文章被收录于专栏:『学习与分享之旅』

ChannelController

代码语言:javascript
复制
@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

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

ChannelServiceImpl

代码语言:javascript
复制
@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 方法:

img
img
代码语言:javascript
复制
...

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

...

配置 MySQL 批量插入

代码语言:javascript
复制
# 批量插入
&rewriteBatchedStatements=true

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

img
img

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-09-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ChannelController
  • IChannelService
  • ChannelServiceImpl
  • 配置 MySQL 批量插入
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档