|
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.IdcardUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import com.ccsens.mt.bean.dto.CompeteDto; |
|
|
|
import com.ccsens.mt.bean.po.*; |
|
|
|
import com.ccsens.mt.bean.vo.CompeteExcelVo; |
|
|
|
import com.ccsens.mt.bean.vo.TableVo; |
|
|
|
import com.ccsens.mt.persist.dao.*; |
|
|
|
import com.ccsens.mt.persist.mapper.*; |
|
|
@ -16,18 +17,21 @@ import com.ccsens.util.WebConstant; |
|
|
|
import com.ccsens.util.bean.dto.QueryDto; |
|
|
|
import com.ccsens.util.exception.BaseException; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections.map.HashedMap; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
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 org.springframework.util.unit.DataUnit; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
@ -52,6 +56,8 @@ public class ExcelService implements IExcelService { |
|
|
|
@Resource |
|
|
|
private CompeteGroupMapper competeGroupMapper; |
|
|
|
@Resource |
|
|
|
private CompeteProjectConfigMapper competeProjectConfigMapper; |
|
|
|
@Resource |
|
|
|
private CommonFileMapper commonFileMapper; |
|
|
|
@Resource |
|
|
|
private IProvinceService provinceService; |
|
|
@ -632,6 +638,184 @@ public class ExcelService implements IExcelService { |
|
|
|
return path; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导出出场顺序表 |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String iCompetitionOrderService(QueryDto<CompeteDto.CompeteTime> params) { |
|
|
|
List<CompeteExcelVo.AllProject> competeProjectList= competeCompanyDao.selectProjectByType(params.getParam().getCompeteTimeId()); |
|
|
|
for (int i=0;i<competeProjectList.size();i++){ |
|
|
|
CompeteExcelVo.AllProject competeProject=competeProjectList.get(i); |
|
|
|
SimpleDateFormat start=new SimpleDateFormat("HH:mm"); |
|
|
|
SimpleDateFormat end=new SimpleDateFormat("HH:mm"); |
|
|
|
SimpleDateFormat date=new SimpleDateFormat("MM-dd a"); |
|
|
|
String startStr=start.format(new Date(competeProject.getStartTime())); |
|
|
|
competeProject.setStartTimeStr(startStr); |
|
|
|
|
|
|
|
String endStr=end.format(new Date(competeProject.getEndTime())); |
|
|
|
competeProject.setEndTimeStr(endStr); |
|
|
|
String year=date.format(new Date(competeProject.getStartTime())); |
|
|
|
competeProject.setYear(year); |
|
|
|
int siteNum=competeProject.getSiteNum(); |
|
|
|
competeProject.setSiteNum(siteNum); |
|
|
|
int size; |
|
|
|
if(competeProject.getTeam().equals((byte) 0)){ |
|
|
|
List<CompeteExcelVo.TeamOrderPlayer> singleOrderPlayerList=competePlayerDao.selectSinglePlayerByProjectId(competeProject.getId()); |
|
|
|
size = singleOrderPlayerList.stream().mapToInt(singleOrderPlayer -> singleOrderPlayer.getCompanyNameList().size()).sum(); |
|
|
|
competeProject.setProjectList(singleOrderPlayerList); |
|
|
|
}else { |
|
|
|
List<CompeteExcelVo.TeamOrderPlayer> teamOrderPlayerList= competeTeamDao.selectTeamMemberByProjectId(competeProject.getId()); |
|
|
|
size = teamOrderPlayerList.stream().mapToInt(teamOrderPlayer -> teamOrderPlayer.getCompanyNameList().size()).sum(); |
|
|
|
competeProject.setProjectList(teamOrderPlayerList); |
|
|
|
} |
|
|
|
competeProject.setSize(size); |
|
|
|
} |
|
|
|
String dasia=competeTimeDao.selectByPrimaryKey(params.getParam().getCompeteTimeId()).getName(); |
|
|
|
//创建excle表格对象
|
|
|
|
List<List<PoiUtil.PoiUtilCell>> biao = new ArrayList<>(); |
|
|
|
List<PoiUtil.PoiUtilCell> one = new ArrayList<>(); |
|
|
|
PoiUtil.PoiUtilCell yuandongyuan=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 6, 1); |
|
|
|
yuandongyuan.setValue(dasia+"出场顺序表"); |
|
|
|
one.add(yuandongyuan); |
|
|
|
biao.add(one); |
|
|
|
|
|
|
|
|
|
|
|
for (int j=0 ;j<competeProjectList.size();j++){ |
|
|
|
List<PoiUtil.PoiUtilCell> three = new ArrayList<>(); |
|
|
|
PoiUtil.PoiUtilCell threeDate=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 6, 1); |
|
|
|
if(j==0){ |
|
|
|
threeDate.setValue(competeProjectList.get(j).getYear()); |
|
|
|
three.add(threeDate); |
|
|
|
biao.add(three); |
|
|
|
List<PoiUtil.PoiUtilCell> two = new ArrayList<>(); |
|
|
|
PoiUtil.PoiUtilCell two1=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two1.setValue("时间"); |
|
|
|
PoiUtil.PoiUtilCell two2=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two2.setValue("项目"); |
|
|
|
PoiUtil.PoiUtilCell two3=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two3.setValue("组别"); |
|
|
|
PoiUtil.PoiUtilCell two4=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two4.setValue("场次/场地"); |
|
|
|
PoiUtil.PoiUtilCell two5=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two5.setValue("参赛单位"); |
|
|
|
PoiUtil.PoiUtilCell two6=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two6.setValue("参赛人员"); |
|
|
|
two.add(two1); |
|
|
|
two.add(two2); |
|
|
|
two.add(two3); |
|
|
|
two.add(two4); |
|
|
|
two.add(two5); |
|
|
|
two.add(two6); |
|
|
|
biao.add(two); |
|
|
|
}else{ |
|
|
|
if (!competeProjectList.get(j).getYear().equals(competeProjectList.get(j-1).getYear())){ |
|
|
|
threeDate.setValue(competeProjectList.get(j).getYear()); |
|
|
|
three.add(threeDate); |
|
|
|
biao.add(three); |
|
|
|
List<PoiUtil.PoiUtilCell> two = new ArrayList<>(); |
|
|
|
PoiUtil.PoiUtilCell two1=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two1.setValue("时间"); |
|
|
|
PoiUtil.PoiUtilCell two2=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two2.setValue("项目"); |
|
|
|
PoiUtil.PoiUtilCell two3=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two3.setValue("组别"); |
|
|
|
PoiUtil.PoiUtilCell two4=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two4.setValue("场次/场地"); |
|
|
|
PoiUtil.PoiUtilCell two5=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two5.setValue("参赛单位"); |
|
|
|
PoiUtil.PoiUtilCell two6=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
two6.setValue("参赛人员"); |
|
|
|
two.add(two1); |
|
|
|
two.add(two2); |
|
|
|
two.add(two3); |
|
|
|
two.add(two4); |
|
|
|
two.add(two5); |
|
|
|
two.add(two6); |
|
|
|
biao.add(two); |
|
|
|
} |
|
|
|
} |
|
|
|
//m行循环 是16次 k 是组次数得循环 4 次 n是组里面得循环
|
|
|
|
for(int k=0,m=0,n=0;m<competeProjectList.get(j).getSize();m++){ |
|
|
|
//代表一行
|
|
|
|
List<PoiUtil.PoiUtilCell> four = new ArrayList<>(); |
|
|
|
if(m==0){ |
|
|
|
PoiUtil.PoiUtilCell fourOne=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, competeProjectList.get(j).getSize()); |
|
|
|
fourOne.setValue(competeProjectList.get(j).getStartTimeStr()+"-"+competeProjectList.get(j).getEndTimeStr()); |
|
|
|
four.add(fourOne); |
|
|
|
PoiUtil.PoiUtilCell fourTwo=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, competeProjectList.get(j).getSize()); |
|
|
|
fourTwo.setValue(competeProjectList.get(j).getProjectName()); |
|
|
|
four.add(fourTwo); |
|
|
|
}else { |
|
|
|
four.add(new PoiUtil.PoiUtilCell()); |
|
|
|
four.add(new PoiUtil.PoiUtilCell()); |
|
|
|
} |
|
|
|
|
|
|
|
PoiUtil.PoiUtilCell fourThree=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, competeProjectList.get(j).getProjectList().get(k).getCompanyNameList().size()); |
|
|
|
if(n>0){ |
|
|
|
fourThree=new PoiUtil.PoiUtilCell(); |
|
|
|
}else { |
|
|
|
fourThree.setValue(competeProjectList.get(j).getProjectList().get(k++).getGroupName()); |
|
|
|
n++; |
|
|
|
} |
|
|
|
if(n==competeProjectList.get(j).getProjectList().get(k-1).getCompanyNameList().size()){ |
|
|
|
n=0; |
|
|
|
//k++
|
|
|
|
} |
|
|
|
four.add(fourThree); |
|
|
|
|
|
|
|
PoiUtil.PoiUtilCell fourFour=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
int x=competeProjectList.get(j).getTeam(); |
|
|
|
if(x<=0){ |
|
|
|
x=2; |
|
|
|
} |
|
|
|
if((m+1)%x==0){ |
|
|
|
fourFour.setValue(""+((m+1)/x)+"--"+x); |
|
|
|
}else { |
|
|
|
fourFour.setValue(""+((m+1)/x+1)+"--"+((m+1)%x)); |
|
|
|
} |
|
|
|
four.add(fourFour); |
|
|
|
PoiUtil.PoiUtilCell fourFive=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
if(n==0){ |
|
|
|
log.info("j:{}, k:{}, n:{}", j,k,n); |
|
|
|
fourFive.setValue(competeProjectList.get(j).getProjectList().get(k-1).getCompanyNameList().get(n).getCompanyName()); |
|
|
|
}else { |
|
|
|
fourFive.setValue(competeProjectList.get(j).getProjectList().get(k-1).getCompanyNameList().get(n-1).getCompanyName()); |
|
|
|
} |
|
|
|
four.add(fourFive); |
|
|
|
PoiUtil.PoiUtilCell fourSix=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|
|
|
if(n==0){ |
|
|
|
fourSix.setValue(competeProjectList.get(j).getProjectList().get(k-1).getCompanyNameList().get(n).getPlayerNames()); |
|
|
|
}else { |
|
|
|
fourSix.setValue(competeProjectList.get(j).getProjectList().get(k-1).getCompanyNameList().get(n-1).getPlayerNames()); |
|
|
|
} |
|
|
|
four.add(fourSix); |
|
|
|
biao.add(four); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Workbook workbook = new XSSFWorkbook(); |
|
|
|
PoiUtil.exportWB("出场顺序",biao,workbook); |
|
|
|
String filepath = "mt/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
String path = PropUtil.path + filepath; |
|
|
|
String path1="C:/d/"+filepath;//本地的路径
|
|
|
|
File tmpFile = new File(path); |
|
|
|
if (!tmpFile.getParentFile().exists()) { |
|
|
|
tmpFile.getParentFile().mkdirs(); |
|
|
|
} |
|
|
|
File file = new File(path); |
|
|
|
try { |
|
|
|
OutputStream outputStream = new FileOutputStream(file); |
|
|
|
workbook.write(outputStream); |
|
|
|
outputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return PropUtil.domain + "file/download/know?path="+path; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private List<TableVo.CompeteAllCount> competeAllCountList(CompeteDto.CompeteTime params){
|
|
|
|
// //根据大赛查类型
|
|
|
|
// Long competeTimeId = params.getCompeteTimeId();
|
|
|
|