|
|
@ -1,12 +1,20 @@ |
|
|
|
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.config.StreamUtils; |
|
|
|
import com.elink.esua.epdc.dto.PartyMembersDTO; |
|
|
|
import com.elink.esua.epdc.entity.PartyMembersEntity; |
|
|
|
import com.elink.esua.epdc.excel.PartyMembersExcel; |
|
|
|
import com.elink.esua.epdc.service.PartyMembersService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
@ -18,17 +26,29 @@ import java.util.List; |
|
|
|
@Component |
|
|
|
public class PartyTask { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PartyMembersService partyMembersService; |
|
|
|
|
|
|
|
/*** |
|
|
|
* 批量插入党员 |
|
|
|
* @param list |
|
|
|
* @param file |
|
|
|
* @return void |
|
|
|
* @author qushutong |
|
|
|
* @date 2019/10/24 16:02 |
|
|
|
*/ |
|
|
|
@Async |
|
|
|
public void insertPartyList(List< PartyMembersDTO > list){ |
|
|
|
partyMembersService.saveList(list); |
|
|
|
public void insertPartyList(MultipartFile file) { |
|
|
|
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()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|