@ -1,8 +1,10 @@
package com.ccsens.mt.service ;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.lang.Snowflake ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.ccsens.mt.bean.dto.CompeteDto ;
import com.ccsens.mt.bean.po.* ;
import com.ccsens.mt.bean.vo.CompeteVo ;
@ -10,16 +12,20 @@ import com.ccsens.mt.persist.dao.CompetePlayerDao;
import com.ccsens.mt.persist.dao.CompeteTeamDao ;
import com.ccsens.mt.persist.dao.CompeteTimeDao ;
import com.ccsens.mt.persist.mapper.* ;
import com.ccsens.util.CodeEnum ;
import com.ccsens.util.StringUtil ;
import com.ccsens.util.* ;
import com.ccsens.util.bean.dto.QueryDto ;
import com.ccsens.util.exception.BaseException ;
import lombok.extern.slf4j.Slf4j ;
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 javax.annotation.Resource ;
import java.io.File ;
import java.io.FileOutputStream ;
import java.io.OutputStream ;
import java.util.ArrayList ;
import java.util.List ;
@ -220,12 +226,12 @@ public class DepartmentService implements IDepartmentService{
project . getSecondProjects ( ) . forEach ( secondProject - > {
if ( secondProject . getTeam ( ) = = 0 ) {
//不是团队比赛
secondProject . setManName ( competePlayerDao . getMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 0 ) ) ;
secondProject . setWomanName ( competePlayerDao . getMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 1 ) ) ;
secondProject . setManName ( competePlayerDao . getMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 1 ) ) ;
secondProject . setWomanName ( competePlayerDao . getMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 0 ) ) ;
secondProject . setMixedName ( competePlayerDao . getMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 2 ) ) ;
} else {
secondProject . setManName ( competePlayerDao . getTeamMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 0 ) ) ;
secondProject . setWomanName ( competePlayerDao . getTeamMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 1 ) ) ;
secondProject . setManName ( competePlayerDao . getTeamMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 1 ) ) ;
secondProject . setWomanName ( competePlayerDao . getTeamMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 0 ) ) ;
secondProject . setMixedName ( competePlayerDao . getTeamMemberNamesByProjectId ( companyId , secondProject . getCompeteProjectId ( ) , 2 ) ) ;
}
} ) ;
@ -236,4 +242,208 @@ public class DepartmentService implements IDepartmentService{
}
return departmentInfo ;
}
/ * *
* 导出报名信息表
* /
@Override
public String exportExcel ( CompeteDto . CompeteType competeType ) {
// CompeteDto.CompeteType competeType = params.getParam();
Workbook wb = new XSSFWorkbook ( ) ;
String path = null ;
//查找所有院系信息
CompeteCompanyExample companyExample = new CompeteCompanyExample ( ) ;
companyExample . createCriteria ( ) . andTypeEqualTo ( ( byte ) competeType . getType ( ) ) ;
List < CompeteCompany > companyList = competeCompanyMapper . selectByExample ( companyExample ) ;
log . info ( "查询所有院系:{}" , companyList ) ;
if ( CollectionUtil . isNotEmpty ( companyList ) ) {
for ( CompeteCompany company : companyList ) {
CompeteVo . DepartmentInfo departmentInfo = getDepartmentInfo ( company . getId ( ) , competeType . getType ( ) ) ;
log . info ( "查询院系的报名详细信息:{}" , departmentInfo ) ;
if ( ObjectUtil . isNotNull ( departmentInfo ) ) {
//生成写入的数据
List < List < PoiUtil . PoiUtilCell > > list = generatePoiUtilCell ( departmentInfo ) ;
//写入excel
try {
path = writeExcel ( wb , departmentInfo . getName ( ) , list ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
}
}
}
return path ;
}
private List < List < PoiUtil . PoiUtilCell > > generatePoiUtilCell ( CompeteVo . DepartmentInfo departmentInfo ) {
List < List < PoiUtil . PoiUtilCell > > list = new ArrayList < > ( ) ;
//标题
List < PoiUtil . PoiUtilCell > title = new ArrayList < > ( ) ;
title . add ( new PoiUtil . PoiUtilCell ( departmentInfo . getName ( ) , 3 , 1 ) ) ;
list . add ( title ) ;
//表头
List < PoiUtil . PoiUtilCell > header = new ArrayList < > ( ) ;
header . add ( new PoiUtil . PoiUtilCell ( "比赛项目" ) ) ;
header . add ( new PoiUtil . PoiUtilCell ( "分组" ) ) ;
header . add ( new PoiUtil . PoiUtilCell ( "参赛人员" ) ) ;
list . add ( header ) ;
if ( CollectionUtil . isNotEmpty ( departmentInfo . getDepartmentProjects ( ) ) ) {
departmentInfo . getDepartmentProjects ( ) . forEach ( departmentProject - > {
if ( CollectionUtil . isNotEmpty ( departmentProject . getSecondProjects ( ) ) ) {
for ( int i = 0 ; i < departmentProject . getSecondProjects ( ) . size ( ) ; i + + ) {
int secondRows = 0 ;
CompeteVo . DepartmentSecondProject secondProject = departmentProject . getSecondProjects ( ) . get ( i ) ;
List < PoiUtil . PoiUtilCell > project = new ArrayList < > ( ) ;
project . add ( new PoiUtil . PoiUtilCell ( departmentProject . getParentProjectName ( ) + ":" + secondProject . getCompeteProjectName ( ) ) ) ;
list . add ( project ) ;
if ( secondProject . getTeam ( ) = = 0 ) {
if ( ObjectUtil . isNotNull ( secondProject . getManName ( ) ) ) {
secondRows + + ;
project . add ( new PoiUtil . PoiUtilCell ( "男子组" ) ) ;
project . add ( new PoiUtil . PoiUtilCell ( secondProject . getManName ( ) ) ) ;
if ( ObjectUtil . isNotNull ( secondProject . getWomanName ( ) ) ) {
secondRows + + ;
List < PoiUtil . PoiUtilCell > group = new ArrayList < > ( ) ;
group . add ( new PoiUtil . PoiUtilCell ( ) ) ;
group . add ( new PoiUtil . PoiUtilCell ( "女子组" ) ) ;
group . add ( new PoiUtil . PoiUtilCell ( secondProject . getWomanName ( ) ) ) ;
list . add ( group ) ;
}
if ( ObjectUtil . isNotNull ( secondProject . getMixedName ( ) ) ) {
secondRows + + ;
List < PoiUtil . PoiUtilCell > group = new ArrayList < > ( ) ;
group . add ( new PoiUtil . PoiUtilCell ( ) ) ;
group . add ( new PoiUtil . PoiUtilCell ( "男女混合组" ) ) ;
group . add ( new PoiUtil . PoiUtilCell ( secondProject . getMixedName ( ) ) ) ;
list . add ( group ) ;
}
} else if ( ObjectUtil . isNotNull ( secondProject . getWomanName ( ) ) ) {
secondRows + + ;
project . add ( new PoiUtil . PoiUtilCell ( "女子组" ) ) ;
project . add ( new PoiUtil . PoiUtilCell ( secondProject . getWomanName ( ) ) ) ;
if ( ObjectUtil . isNotNull ( secondProject . getMixedName ( ) ) ) {
secondRows + + ;
List < PoiUtil . PoiUtilCell > group = new ArrayList < > ( ) ;
group . add ( new PoiUtil . PoiUtilCell ( ) ) ;
group . add ( new PoiUtil . PoiUtilCell ( "男女混合组" ) ) ;
group . add ( new PoiUtil . PoiUtilCell ( secondProject . getMixedName ( ) ) ) ;
list . add ( group ) ;
}
} else if ( ObjectUtil . isNotNull ( secondProject . getMixedName ( ) ) ) {
secondRows + + ;
project . add ( new PoiUtil . PoiUtilCell ( "男女混合组" ) ) ;
project . add ( new PoiUtil . PoiUtilCell ( secondProject . getMixedName ( ) ) ) ;
}
} else {
secondRows + + ;
project . add ( new PoiUtil . PoiUtilCell ( ) ) ;
String playerNames = secondProject . getManName ( ) = = null ? "" : secondProject . getManName ( ) ;
if ( StrUtil . isNotEmpty ( playerNames ) & & StrUtil . isNotEmpty ( secondProject . getWomanName ( ) ) ) {
playerNames + = "、" + secondProject . getWomanName ( ) ;
} else {
playerNames + = secondProject . getWomanName ( ) = = null ? "" : secondProject . getWomanName ( ) ;
}
if ( StrUtil . isNotEmpty ( playerNames ) & & StrUtil . isNotEmpty ( secondProject . getMixedName ( ) ) ) {
playerNames + = "、" + secondProject . getMixedName ( ) ;
} else {
playerNames + = secondProject . getMixedName ( ) = = null ? "" : secondProject . getMixedName ( ) ;
}
project . add ( new PoiUtil . PoiUtilCell ( playerNames ) ) ;
}
// if(ObjectUtil.isNotNull(secondProject.getManName())) {
// secondRows++;
// project.add(new PoiUtil.PoiUtilCell("男子组"));
// project.add(new PoiUtil.PoiUtilCell(secondProject.getManName()));
// if(ObjectUtil.isNotNull(secondProject.getWomanName())) {
// secondRows++;
// List<PoiUtil.PoiUtilCell> group = new ArrayList<>();
// group.add(new PoiUtil.PoiUtilCell());
// group.add(new PoiUtil.PoiUtilCell("女子组"));
// group.add(new PoiUtil.PoiUtilCell(secondProject.getWomanName()));
// list.add(group);
// }
// if(ObjectUtil.isNotNull(secondProject.getMixedName())) {
// secondRows++;
// List<PoiUtil.PoiUtilCell> group = new ArrayList<>();
// group.add(new PoiUtil.PoiUtilCell());
// group.add(new PoiUtil.PoiUtilCell("男女混合组"));
// group.add(new PoiUtil.PoiUtilCell(secondProject.getMixedName()));
// list.add(group);
// }
// }else if(ObjectUtil.isNotNull(secondProject.getWomanName())){
// secondRows++;
// project.add(new PoiUtil.PoiUtilCell("女子组"));
// project.add(new PoiUtil.PoiUtilCell(secondProject.getWomanName()));
// if(ObjectUtil.isNotNull(secondProject.getMixedName())) {
// secondRows++;
// List<PoiUtil.PoiUtilCell> group = new ArrayList<>();
// group.add(new PoiUtil.PoiUtilCell());
// group.add(new PoiUtil.PoiUtilCell("男女混合组"));
// group.add(new PoiUtil.PoiUtilCell(secondProject.getMixedName()));
// list.add(group);
// }
// }else if(ObjectUtil.isNotNull(secondProject.getMixedName())){
// secondRows++;
// project.add(new PoiUtil.PoiUtilCell("男女混合组"));
// project.add(new PoiUtil.PoiUtilCell(secondProject.getMixedName()));
// }
PoiUtil . PoiUtilCell poiUtilCell = project . get ( 0 ) ;
poiUtilCell . setRowspan ( secondRows ) ;
}
}
} ) ;
}
List < PoiUtil . PoiUtilCell > blank = new ArrayList < > ( ) ;
blank . add ( new PoiUtil . PoiUtilCell ( "" , 3 , 1 ) ) ;
list . add ( blank ) ;
//领队裁判等信息
if ( CollectionUtil . isNotEmpty ( departmentInfo . getDepartmentRoles ( ) ) ) {
List < PoiUtil . PoiUtilCell > role1 = new ArrayList < > ( ) ;
List < PoiUtil . PoiUtilCell > role2 = new ArrayList < > ( ) ;
List < PoiUtil . PoiUtilCell > role3 = new ArrayList < > ( ) ;
departmentInfo . getDepartmentRoles ( ) . forEach ( departmentRole - > {
if ( departmentRole . getRole ( ) = = 0 ) {
role1 . add ( new PoiUtil . PoiUtilCell ( "领队" , 1 , 1 , 666 , 28 ) ) ;
role1 . add ( new PoiUtil . PoiUtilCell ( "姓名:" + departmentRole . getName ( ) ) ) ;
role1 . add ( new PoiUtil . PoiUtilCell ( "手机号:" + departmentRole . getPhone ( ) , 1 , 1 , 666 , 42 ) ) ;
}
if ( departmentRole . getRole ( ) = = 1 ) {
role2 . add ( new PoiUtil . PoiUtilCell ( "裁判" , 1 , 1 , 666 , 28 ) ) ;
role2 . add ( new PoiUtil . PoiUtilCell ( "姓名:" + departmentRole . getName ( ) ) ) ;
role2 . add ( new PoiUtil . PoiUtilCell ( "手机号:" + departmentRole . getPhone ( ) , 1 , 1 , 666 , 42 ) ) ;
}
if ( departmentRole . getRole ( ) = = 2 ) {
role3 . add ( new PoiUtil . PoiUtilCell ( "填表人" , 1 , 1 , 666 , 28 ) ) ;
role3 . add ( new PoiUtil . PoiUtilCell ( "姓名:" + departmentRole . getName ( ) ) ) ;
role3 . add ( new PoiUtil . PoiUtilCell ( "手机号:" + departmentRole . getPhone ( ) , 1 , 1 , 666 , 42 ) ) ;
}
} ) ;
list . add ( role1 ) ;
list . add ( role2 ) ;
list . add ( role3 ) ;
}
return list ;
}
private String writeExcel ( Workbook wb , String sheetName , List < List < PoiUtil . PoiUtilCell > > list ) throws Exception {
PoiUtil . exportWB ( sheetName , list , wb ) ;
//生成文件
String fileName = "department/" + DateUtil . today ( ) + "/" + System . currentTimeMillis ( ) + ".xlsx" ;
String path = PropUtil . path + File . separator + fileName ;
File tmpFile = new File ( path ) ;
if ( ! tmpFile . getParentFile ( ) . exists ( ) ) {
boolean mkdirs = tmpFile . getParentFile ( ) . mkdirs ( ) ;
}
OutputStream stream = new FileOutputStream ( tmpFile ) ;
wb . write ( stream ) ;
stream . close ( ) ;
return PropUtil . imgDomain + fileName ;
}
}