10 changed files with 147 additions and 19 deletions
@ -0,0 +1,14 @@ |
|||||
|
package com.ccsens.mt.service; |
||||
|
|
||||
|
import com.ccsens.mt.bean.vo.CompeteExcelVo; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface IImportService { |
||||
|
/** |
||||
|
* 导入总决赛人员表 |
||||
|
* @param path 总决赛表 |
||||
|
* @return 返回失败的信息 |
||||
|
*/ |
||||
|
List<CompeteExcelVo.ErrorPlayer> importFinal(String path) throws Exception; |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
package com.ccsens.mt.service; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import cn.hutool.core.util.StrUtil; |
||||
|
import com.ccsens.mt.bean.po.CompeteCompany; |
||||
|
import com.ccsens.mt.bean.vo.CompeteExcelVo; |
||||
|
import com.ccsens.mt.persist.dao.CompeteCompanyDao; |
||||
|
import com.ccsens.util.ExcelUtil; |
||||
|
import com.ccsens.util.StringUtil; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Propagation; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.io.FileInputStream; |
||||
|
import java.io.InputStream; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author 逗 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
||||
|
public class ImportService implements IImportService{ |
||||
|
@Resource |
||||
|
private CompeteCompanyDao competeCompanyDao; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public List<CompeteExcelVo.ErrorPlayer> importFinal(String path) throws Exception{ |
||||
|
List<CompeteExcelVo.ErrorPlayer> errorPlayers = new ArrayList<>(); |
||||
|
|
||||
|
//获取excel表格
|
||||
|
InputStream is = new FileInputStream(path); |
||||
|
XSSFWorkbook wb = new XSSFWorkbook(is); |
||||
|
//获取每个sheet信息
|
||||
|
for (int i = 0; i < wb.getNumberOfSheets(); i++) { |
||||
|
int type = 7; |
||||
|
XSSFSheet sheet = wb.getSheetAt(i); |
||||
|
if(ObjectUtil.isNotNull(sheet)) { |
||||
|
String sheetName = sheet.getSheetName(); |
||||
|
if (StrUtil.isNotBlank(sheetName)) { |
||||
|
if ("运城站入围名单".equals(sheetName)) { |
||||
|
type = 5; |
||||
|
} else if ("临汾站入围名单".equals(sheetName)) { |
||||
|
type = 4; |
||||
|
} else if ("太原站入围名单".equals(sheetName)) { |
||||
|
type = 6; |
||||
|
} |
||||
|
} |
||||
|
//读取sheet内的信息
|
||||
|
readSheet(sheet,type,errorPlayers); |
||||
|
} |
||||
|
} |
||||
|
return errorPlayers; |
||||
|
} |
||||
|
|
||||
|
private void readSheet(XSSFSheet sheet, int type, List<CompeteExcelVo.ErrorPlayer> errorPlayers) { |
||||
|
for (int i = 1; i < sheet.getLastRowNum(); i++) { |
||||
|
//参赛单位
|
||||
|
String companyCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
||||
|
//参赛项目
|
||||
|
String projectCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
||||
|
//组别
|
||||
|
String groupCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
||||
|
//选手姓名
|
||||
|
String playerCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
||||
|
String[] playerNames = new String[]{playerCell}; |
||||
|
if(StrUtil.isNotBlank(playerCell)){ |
||||
|
playerNames = playerCell.split("、"); |
||||
|
} |
||||
|
//查找参赛单位
|
||||
|
List<CompeteCompany> company = competeCompanyDao.getCompanyByNameAndType(companyCell,playerNames[0],projectCell,type); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,5 +1,5 @@ |
|||||
spring: |
spring: |
||||
profiles: |
profiles: |
||||
active: test |
active: dev |
||||
include: util-test,common |
include: util-dev,common |
||||
|
|
||||
|
|||||
Loading…
Reference in new issue