• TienChin 渠道管理-渠道导入


    ChannelController

    1. @PostMapping("/importTemplate")
    2. void importTemplate(HttpServletResponse response) {
    3. ExcelUtil util = new ExcelUtil<>(Channel.class);
    4. util.importTemplateExcel(response, "渠道数据");
    5. }
    6. @Log(title = "渠道管理", businessType = BusinessType.IMPORT)
    7. @PreAuthorize("hasPermission('tienchin:channel:import')")
    8. @PostMapping("/importData")
    9. AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
    10. ExcelUtil util = new ExcelUtil<>(Channel.class);
    11. List channelList = util.importExcel(file.getInputStream());
    12. return AjaxResult.success(iChannelService.importChannel(channelList, updateSupport));
    13. }

    IChannelService

    1. /**
    2. * 导入渠道数据
    3. *
    4. * @param channelList 渠道数据列表
    5. * @param updateSupport 是否更新支持,如果已存在,则进行更新数据
    6. * @return {@code boolean} {@code true} 导入成功 {@code false} 导入失败
    7. */
    8. boolean importChannel(List channelList, boolean updateSupport);

    ChannelServiceImpl

    1. @Override
    2. @Transactional(rollbackFor = Exception.class)
    3. public boolean importChannel(List channelList, boolean updateSupport) {
    4. String username = SecurityUtils.getUsername();
    5. LocalDateTime currentTime = LocalDateTime.now();
    6. List channels = channelList
    7. .stream()
    8. .peek(channel -> {
    9. if (updateSupport) {
    10. channel.setUpdateBy(username);
    11. channel.setUpdateTime(currentTime);
    12. } else {
    13. channel.setCreateBy(username);
    14. channel.setCreateTime(currentTime);
    15. channel.setChannelId(null);
    16. }
    17. }).collect(Collectors.toList());
    18. if (updateSupport) {
    19. return updateBatchById(channels);
    20. } else {
    21. return saveBatch(channels);
    22. }
    23. }

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

    更改 ReflectUtils.java 中的 invokeMethodByName 方法:

    img

    1. ...
    2. else if (cs[i] == Byte.class) {
    3. args[i] = Convert.toByte(args[i]);
    4. }
    5. ...

    配置 MySQL 批量插入

    1. # 批量插入
    2. &rewriteBatchedStatements=true

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

    img

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

  • 相关阅读:
    配置高+超级省,148元工业级Cortex-A55核心板不限量发售!
    06_ElasticSearch:索引和文档的CURD
    Kudu知识点
    解决Spring子事务新开事务REQUIRES_NEW仍被主事务回滚问题
    java 使用bc库封装ASN1结构案例
    远程桌面访问MATLAB 2018B,提示License Manger Error -103,终极解决方案
    渗透测试-xml注入以及xxe漏洞
    docker入门加实战—docker数据卷
    使用Docker+Jenkin自动化流水线
    一些银行相关暑期找实习记录
  • 原文地址:https://blog.csdn.net/XiaohuihuiHuiYi/article/details/132983593