|
|
@ -1,10 +1,15 @@ |
|
|
|
package com.ccsens.mt.service; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.ccsens.mt.bean.po.CompeteCompany; |
|
|
|
import com.ccsens.mt.bean.po.CompetePlayer; |
|
|
|
import com.ccsens.mt.bean.vo.CompeteExcelVo; |
|
|
|
import com.ccsens.mt.persist.dao.CompeteCompanyDao; |
|
|
|
import com.ccsens.mt.persist.dao.CompetePlayerDao; |
|
|
|
import com.ccsens.util.ExcelUtil; |
|
|
|
import com.ccsens.util.StringUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
@ -18,7 +23,9 @@ import javax.annotation.Resource; |
|
|
|
import java.io.FileInputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author 逗 |
|
|
@ -29,6 +36,10 @@ import java.util.List; |
|
|
|
public class ImportService implements IImportService{ |
|
|
|
@Resource |
|
|
|
private CompeteCompanyDao competeCompanyDao; |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
@Resource |
|
|
|
private CompetePlayerDao competePlayerDao; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -61,21 +72,55 @@ public class ImportService implements IImportService{ |
|
|
|
} |
|
|
|
|
|
|
|
private void readSheet(XSSFSheet sheet, int type, List<CompeteExcelVo.ErrorPlayer> errorPlayers) { |
|
|
|
Map<String,CompeteCompany> companyMap = new HashMap<>(); |
|
|
|
Map<String,CompetePlayer> playerMap = new HashMap<>(); |
|
|
|
for (int i = 1; i < sheet.getLastRowNum(); i++) { |
|
|
|
//参赛单位
|
|
|
|
String companyCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
|
|
|
String companyCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(2))); |
|
|
|
//参赛项目
|
|
|
|
String projectCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
|
|
|
//组别
|
|
|
|
String groupCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
|
|
|
String groupCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(1))); |
|
|
|
//选手姓名
|
|
|
|
String playerCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(0))); |
|
|
|
String playerCell = StringUtil.replaceStrSpace(ExcelUtil.getCellValue(sheet.getRow(i).getCell(3))); |
|
|
|
String[] playerNames = new String[]{playerCell}; |
|
|
|
if(StrUtil.isNotBlank(playerCell)){ |
|
|
|
playerNames = playerCell.split("、"); |
|
|
|
} |
|
|
|
//查找参赛单位
|
|
|
|
List<CompeteCompany> company = competeCompanyDao.getCompanyByNameAndType(companyCell,playerNames[0],projectCell,type); |
|
|
|
if (!companyMap.containsKey(companyCell)){ |
|
|
|
List<CompeteCompany> company = competeCompanyDao.getCompanyByNameAndType(companyCell,playerNames[0],projectCell,type); |
|
|
|
if (CollectionUtil.isNotEmpty(company)){ |
|
|
|
//查看是该单位是否已经进决赛
|
|
|
|
List<CompeteCompany> companyByNameAndType = competeCompanyDao.getCompanyByNameAndType(companyCell, playerNames[0], projectCell, 7); |
|
|
|
if (CollectionUtil.isEmpty(companyByNameAndType)){ |
|
|
|
//复制参赛单位到决赛
|
|
|
|
CompeteCompany newCompany = new CompeteCompany(); |
|
|
|
BeanUtil.copyProperties(company.get(0),newCompany); |
|
|
|
newCompany.setId(snowflake.nextId()); |
|
|
|
newCompany.setType((byte)7); |
|
|
|
newCompany.setCompeteTimeId(7L); |
|
|
|
competeCompanyDao.insertSelective(newCompany); |
|
|
|
companyMap.put(companyCell,newCompany); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
CompeteExcelVo.ErrorPlayer errorPlayer = new CompeteExcelVo.ErrorPlayer(); |
|
|
|
errorPlayer.setSheetName(companyCell); |
|
|
|
errorPlayer.setRowNum(i); |
|
|
|
errorPlayer.setRemark("未查找原参赛单位"); |
|
|
|
errorPlayers.add(errorPlayer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//添加选手信息
|
|
|
|
List<CompetePlayer> playerList = competePlayerDao.getPlayerByNameAndCompany(playerCell,companyMap.get(companyCell).getId()); |
|
|
|
if (CollectionUtil.isNotEmpty(playerList)){ |
|
|
|
CompetePlayer newPlayer = new CompetePlayer(); |
|
|
|
BeanUtil.copyProperties(playerList.get(0),newPlayer); |
|
|
|
newPlayer.setId(snowflake.nextId()); |
|
|
|
newPlayer.setCompanyId(companyMap.get(companyCell).getId()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|