4 changed files with 35 additions and 33 deletions
@ -1,34 +1,54 @@ |
|||||
package com.elink.esua.epdc.async; |
package com.elink.esua.epdc.async; |
||||
|
|
||||
|
import cn.afterturn.easypoi.excel.ExcelImportUtil; |
||||
|
import cn.afterturn.easypoi.excel.entity.ImportParams; |
||||
|
import com.alibaba.fastjson.JSON; |
||||
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
||||
|
import com.elink.esua.epdc.config.StreamUtils; |
||||
import com.elink.esua.epdc.dto.PartyMembersDTO; |
import com.elink.esua.epdc.dto.PartyMembersDTO; |
||||
import com.elink.esua.epdc.entity.PartyMembersEntity; |
import com.elink.esua.epdc.entity.PartyMembersEntity; |
||||
|
import com.elink.esua.epdc.excel.PartyMembersExcel; |
||||
import com.elink.esua.epdc.service.PartyMembersService; |
import com.elink.esua.epdc.service.PartyMembersService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.scheduling.annotation.Async; |
import org.springframework.scheduling.annotation.Async; |
||||
import org.springframework.stereotype.Component; |
import org.springframework.stereotype.Component; |
||||
|
import org.springframework.web.multipart.MultipartFile; |
||||
|
|
||||
|
import java.io.File; |
||||
import java.util.List; |
import java.util.List; |
||||
|
|
||||
|
|
||||
/** |
/** |
||||
* @author: qushutong |
* @author: qushutong |
||||
* @Date: 2019/10/24 16:00 |
* @Date: 2019/10/24 16:00 |
||||
* @Description: 党员导入异步 |
* @Description: 党员导入异步 |
||||
*/ |
*/ |
||||
@Component |
@Component |
||||
public class PartyTask { |
public class PartyTask { |
||||
|
|
||||
|
@Autowired |
||||
private PartyMembersService partyMembersService; |
private PartyMembersService partyMembersService; |
||||
|
|
||||
/*** |
/*** |
||||
* 批量插入党员 |
* 批量插入党员 |
||||
* @param list |
* @param file |
||||
* @return void |
* @return void |
||||
* @author qushutong |
* @author qushutong |
||||
* @date 2019/10/24 16:02 |
* @date 2019/10/24 16:02 |
||||
*/ |
*/ |
||||
@Async |
@Async |
||||
public void insertPartyList(List< PartyMembersDTO > list){ |
public void insertPartyList(MultipartFile file) { |
||||
partyMembersService.saveList(list); |
File f = StreamUtils.conversionFile(file); |
||||
|
ImportParams importParams = new ImportParams(); |
||||
|
try { |
||||
|
List<PartyMembersExcel> partyList = ExcelImportUtil.importExcel(f, PartyMembersExcel.class, importParams); |
||||
|
partyMembersService.saveList(partyList); |
||||
|
for (PartyMembersExcel partyMembers : partyList) { |
||||
|
System.out.println("从Excel导入数据到数据库的详细为 :{}" + JSON.toJSONString(partyMembers)); |
||||
|
} |
||||
|
System.out.println("从Excel导入数据一共 {} 行 " + partyList.size()); |
||||
|
} catch (Exception e1) { |
||||
|
throw new RuntimeException("导入失败:{}" + e1.getMessage()); |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue