上传excel,比对后批量修改(临时表)

  • 大概思路
  • 具体思路
  • 控制层 SpringMVC
  • mapper层(Dao层)
  • service层 SysUploadService
    • 实现类 SysUploadServiceimpl
  • mybatis 层的sql语句

大概思路

  1. 读取excel信息
  2. 将该数据保存在临时表中
  3. 比对临时表与客户表的数据,得出结果
  4. 根据比对结果批量修改客户表数据
  5. 将比对不成功的结果导出
  6. 删除临时表

具体思路

  1. 获取excel信息 List<List< Object>> listob = UploadExcelUtil.ExcelOfUpload(request, response);
  2. 将listob 对象转换为List< TemporaryClient> listofTemporaryClient_1 对象
  3. 批量导入listofTemporaryClient_1 数据进临时表temporary_client
  4. 将临时表(temporary_client)中的客户姓名,手机号与客户表(client)中的客户姓名,手机号相匹配,再加上客户表中的created_time小于等于临时表中的check_time。将比对后的结果查询出来为listofTemporaryClient
  5. 根据上面比对的结果listofTemporaryClient,根据c_id批量修改数据库里的checkTime,state=1
  6. 查询出在临时表中比对不成功的数据listofTemporaryClient_2
  7. 删除临时表里的数据
  8. 导出listofTemporaryClient_2的数据,方便管理查询

控制层 SpringMVC

@RequestMapping(value = "BankDataUpload.do", produces = "application/text; charset=utf-8")public void BankDataUpload(HttpServletRequest request, HttpServletResponse response){List<TemporaryClient> list=new ArrayList<TemporaryClient>();try {list = sysUploadServiceimpl.BankDataUpload(request, response); } catch (Exception e) {e.printStackTrace();}try {ExportExcel<TemporaryClient> ee = new ExportExcel<TemporaryClient>();String[] headers = { "申请日期", "核准日期", "客户称谓", "手机号码"};String fileName = "比对失败的表格";ee.exportExcel(headers, list, fileName, response);} catch (Exception e) {System.out.println("导出excel表异常");}   }

mapper层(Dao层)

与数据库操作有关,插入临时表,比对数据,批量修改客户表,找出比对不成功的数据,删除临时表

    //将数据批量插入临时表TemporaryClientint insertListofTemporaryClient(List<TemporaryClient> listofTemporaryClient_1);//找出临时表与client表中关联的数据,即成功的数据List<TemporaryClient> TrueByTemporaryClient(Integer  gid);//根据比对出来的c_id,check_time修改客户状态为status=1;boolean UpdateTemporaryClient(@Param("listofTemporaryClient")List<TemporaryClient> listofTemporaryClient);//找出临时表与client表中不关联的数据,即修改失败的数据,导出excel表List<TemporaryClient> FalseByTemporaryClient(@Param("listofTemporaryClient")List<TemporaryClient> listofTemporaryClient);//删除临时表boolean deleteTemporaryClient();

service层 SysUploadService

     // 上传银行数据List<TemporaryClient> BankDataUpload(HttpServletRequest request, HttpServletResponse response) throws Exception;

实现类 SysUploadServiceimpl

 public List<TemporaryClient> BankDataUpload(HttpServletRequest request, HttpServletResponse response)throws Exception {   // 1、获取excel信息  List<List< Object>> listobList<List<Object>> listob = UploadExcelUtil.ExcelOfUpload(request, response);List<TemporaryClient> listofTemporaryClient_1 = new ArrayList<TemporaryClient>();List<TemporaryClient> listofTemporaryClient_2 = new ArrayList<TemporaryClient>();// 商品map<商品名称,商品id>List<Goodsmanage> listgoodsmanage = dao.getGoodsName();Map<String, Integer> mapofgid = UploadExcelUtil.getMapOfGoodmanessage(listgoodsmanage);//2、将listob 对象转换为List< TemporaryClient>  listofTemporaryClient_1 对象List<TemporaryClient> listofTemporaryClient_1 = new ArrayList<TemporaryClient>();List<TemporaryClient> listofTemporaryClient_2 = new ArrayList<TemporaryClient>();   Integer g_id = 0;for (int i = 0; i < listob.size(); i++) {try {List<Object> lo = listob.get(i);TemporaryClient temporary = new TemporaryClient();temporary.setCreatedTime(String.valueOf(lo.get(0)).substring(0, 10));temporary.setCheckTime(String.valueOf(lo.get(1)).substring(0, 10));temporary.setCname(String.valueOf(lo.get(2)));temporary.setCtel(String.valueOf(lo.get(3)));if (g_id == 0) {g_id = mapofgid.get(String.valueOf(lo.get(4)));}temporary.setGid(g_id);listofTemporaryClient_1.add(temporary);} catch (Exception e) {System.out.println("----Excel表出现异常 _____行数 " + i);e.printStackTrace();}}List<TemporaryClient> listofTemporaryClient = new ArrayList<TemporaryClient>();try {// 批量插入银行数据,做为临时表int num = dao.insertListofTemporaryClient(listofTemporaryClient_1);System.out.println("导入数据数量" + num);// 临时表与client表比对,得出c_id ,check_time,tem_idlistofTemporaryClient = dao.TrueByTemporaryClient(g_id);System.out.println("-----比对成功,比对的数量为______" + listofTemporaryClient.size());if(!listofTemporaryClient.isEmpty()){boolean Result = dao.UpdateTemporaryClient(listofTemporaryClient);System.out.println("修改结果为------" + Result);listofTemporaryClient_2 = dao.FalseByTemporaryClient(listofTemporaryClient);System.out.println("------比对失败的数量为——————" + listofTemporaryClient_2.size()); }else if(listofTemporaryClient.isEmpty()){System.out.println("比对失败,结果为空");return listofTemporaryClient_1;}     } catch(BadSqlGrammarException e){System.out.println("比对数据为空,不能修改");e.printStackTrace();}catch (Exception e) {e.printStackTrace();}finally {boolean Re = dao.deleteTemporaryClient();System.out.println("删除临时表---" + Re);  }return listofTemporaryClient_2;}

mybatis 层的sql语句

  1. 将excel里的数据转换成List< TemporaryClient> listofTemporaryClient_1, 批量插入临时表,采用foreach批量插入数据库。
 <!-- 批量插入银行数据,做为临时表 --><insert id="insertListofTemporaryClient" parameterType="java.util.List" useGeneratedKeys="false">insert into temporary_client( created_time,check_time,c_name,c_tel,g_id)values<foreach collection="list" item="item" index="index" separator=",">(#{item.createdTime},#{item.checkTime},#{item.cname},#{item.ctel},#{item.gid})</foreach>   </insert>
  1. 将临时表(temporary_client)中的客户姓名,手机号与客户表(client)中的客户姓名,手机号相匹配,再加上客户表中的created_time小于等于临时表中的check_time。
   <select id="TrueByTemporaryClient" resultType="cn.sys.entity.TemporaryClient">select DISTINCT  c.c_id as cid,tm.check_time as checkTime,tm.tem_id as temId from temporary_client tm , client c  where   c.g_id=#{gid}  and c.state =0  and  tm.check_time >=c.created_timeand  REPLACE(c.c_tel,SUBSTR(c.c_tel FROM 4 FOR 4),"****")=tm.c_tel and  LEFT(c.c_name,1)=left(tm.c_name,1)</select>
  1. 根据上面比对的结果,根据c_id批量修改数据库里的checkTime,state=1
    <update id="UpdateTemporaryClient" parameterType="java.util.List">update client<trim prefix="set" suffixOverrides=","><trim prefix="state =case" suffix="end," ><foreach collection="listofTemporaryClient" item="i" index="index">when c_id=#{i.cid} then 1</foreach></trim>            <trim prefix="check_time =case" suffix="end,"><foreach collection="listofTemporaryClient" item="i" index="index">                     when c_id=#{i.cid} then #{i.checkTime}                   </foreach></trim></trim>where<foreach collection="listofTemporaryClient" separator="or" item="i" index="index" >c_id=#{i.cid}</foreach>    </update>
  1. 查询出在临时表中比对不成功的数据,tem_id not in (),导出该数据的excel形式,方便管理查询
    <select id="FalseByTemporaryClient"  resultType="cn.sys.entity.TemporaryClient">SELECT created_time as createdTime ,check_time as checkTime,c_name as cname,c_tel as ctel from temporary_client where tem_id not in<foreach collection="listofTemporaryClient"  item="i"  open="(" separator="," close=")" >#{i.temId}</foreach></select>
  1. 删除临时表里的数据
   <delete id="deleteTemporaryClient" parameterType="cn.sys.entity.TemporaryClient" >DELETE from temporary_client</delete>

上传excel,比对后批量修改(临时表)(三)相关推荐

  1. Jquery+SpringMVC实现上传Excel文件,并批量导入

    1.前端代码 function alertUploadFile(){ //创建表单var formData = new FormData();var file = $("#upload&qu ...

  2. Django框架(上传Excel文件并读取)

    博主今天整理下Django框架中上传Excel文件并读取 博主是要在管理平台中新增用例的维护功能,想着通过上传Excel文件来展示用例,下面是项目的路径图: 首先先建数据库模型 model.py 可以 ...

  3. 服务器上传excel文件并读取数据,asp.net上传Excel文件并读取数据的实现方法

    前言 本文主要给大家介绍了关于asp.net上传Excel文件并读取数据的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 实现如下: 前台代码:使用服务端控件实现上传 服务端 ...

  4. java上传excel以及解析

    一.前言 在写管理后台的需求的时候,经常会用到上传excel的功能,需要我们解析Excel的内容,导入数据等. 二.上传 上传到文件服务器,文件服务有相关的上传接口,需要我们调用API上传. @Pos ...

  5. php上传查询excel到mysql_PHP上传Excel文件导入数据到MySQL数据库示例

    PHP上传Excel文件导入数据到MySQL数据库示例2020-06-20 00:34:11 最近在做Excel文件导入数据到数据库.网站如果想支持批量插入数据,可以制作一个上传Excel文件,导入里 ...

  6. php 上传excel到mysql_PHP上传Excel文件导入数据到MySQL数据库示例

    最近在做Excel文件导入数据到数据库.网站如果想支持批量插入数据,可以制作一个上传Excel文件,导入里面的数据内容到MySQL数据库的小程序. 要用到的工具: ThinkPHP:轻量级国产PHP开 ...

  7. 使用ocupload和POI一键上传Excel并解析导入数据库

    使用的工具如下:  JQuery ocupload jquery.ocupload-1.1.2.js Apache POI poi-3.9.jar 如果是Maven项目添加依赖如下: <depe ...

  8. laravel-admin / Dcat admin 上传Excel并导入数据到数据库

    准备工作 安装maatwebsite/excel composer require maatwebsite/excel laravel-admin 效果图 创建按钮 $grid->tools(f ...

  9. Vue导入上传Excel

    对Excel的数据进行上传首先需要使用xlsx 此文章的上传方式为手动上传(数据解析可在前端进行,也可交由后端处理) 安装插件 npm install xlsx 引入 import XLSX from ...

最新文章

  1. 买个云服务器有啥用_如何用阿里云轻量应用服务器配置一个WordPress网站?
  2. Linux基础操作优化
  3. 一种通过U盘热插拔的升级方法
  4. etc的常见算法_谈常用的几个机器学习算法,学懂算法也可以这么简单!
  5. Cacti迁移RRA数据迁移脚本
  6. SpringBoot获取配置文件常量值
  7. 95.91p30.space\/index.php,关于 ThinkPHP6 分页样式的定制及点击下一页搜索条件丢失的解决方法...
  8. 小米4391人获1.749亿股股票的激励
  9. 【报告分享】中国零售业公私域运营手册暨实施指引.pdf(附下载链接)
  10. Style Report 培训开始啦!!
  11. Deepgreen DB 是什么(含Deepgreen和Greenplum下载地址)
  12. 直播软件视频流怎样测试,手把手教你,如何用视频号直播推流!
  13. 室内声场计算机模拟的声线跟踪法和虚声源法,计算机声场模拟软件ODEON及其应用lowbar;彭庆 - 范文中心...
  14. Ubuntu 12.04 安装离线词典
  15. 微信公众平台注册流程
  16. Cannot determine archive format of /tmp/pip-req-build-
  17. amazon aws 亚马逊云服务概述
  18. (杂谈)如何在AMD官网下载旧版的驱动
  19. Twitter新任80后印度裔CEO,为啥是他?
  20. Android软件开发实例:用客户端写博客

热门文章

  1. 抽象类与接口概念及代码实例
  2. 《工程硕士英语》(武汉理工大学)MOOC慕课习题答案
  3. 英特尔:苹果不断施压促成笔记本续航翻倍
  4. PyTorch——自注意力(self-attention)机制实现(代码详解)
  5. 可转债交易系统日内短线战法股债联动自定义
  6. 学校书法室要选择怎样的数字化智慧书法教室
  7. C++中const的理解
  8. 祈福英文学校2021年高考成绩查询,「祈福英语实验学校(中学)」2021届高三港澳台学子送考小记...
  9. Vue实战——使用代理服务器解决跨域问题——No‘Access-Control-Allow-Origin‘ header is present on the requested resource
  10. spring的一些常用接口