9 changed files with 379 additions and 2 deletions
@ -0,0 +1,276 @@ |
|||
package com.ccsens.mt.service; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import com.ccsens.mt.bean.dto.CompeteDto; |
|||
import com.ccsens.mt.bean.po.*; |
|||
import com.ccsens.mt.persist.dao.CompeteCompanyDao; |
|||
import com.ccsens.mt.persist.dao.CompeteTimeDao; |
|||
import com.ccsens.mt.persist.mapper.CompeteCompanyMapper; |
|||
import com.ccsens.mt.persist.mapper.CompetePlayerMapper; |
|||
import com.ccsens.util.PoiUtil; |
|||
import com.ccsens.util.PropUtil; |
|||
import com.ccsens.util.WebConstant; |
|||
import com.ccsens.util.bean.dto.QueryDto; |
|||
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.aspectj.lang.annotation.Pointcut; |
|||
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.IOException; |
|||
import java.io.OutputStream; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Slf4j |
|||
@Service |
|||
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
|||
public class ExcelService implements IExcelService { |
|||
@Resource |
|||
private CompeteCompanyDao competeCompanyDao; |
|||
@Resource |
|||
private CompeteTimeDao competeTimeDao; |
|||
|
|||
@Resource |
|||
private CompetePlayerMapper competePlayerMapper; |
|||
|
|||
@Override |
|||
public String dasaiduiwuxinxiWPS(QueryDto<CompeteDto.CompeteTime> params) { |
|||
//这个里面包含联系人得信息
|
|||
List<CompeteCompany> competeCompanyList= competeCompanyDao.selectByCompeteTimeId(params.getParam().getCompeteTimeId()); |
|||
List<CompeteCoach> competeCoachList =new ArrayList<CompeteCoach>(); |
|||
for (CompeteCompany com:competeCompanyList) { |
|||
//再根据单位id查询,领队和教练信息,返回list集合
|
|||
competeCoachList.addAll(competeCompanyDao.selectByCompanyId(com.getId())); |
|||
} |
|||
List<List<PoiUtil.PoiUtilCell>> biao = new ArrayList<>(); |
|||
//先把联系人的都添加进去
|
|||
List<PoiUtil.PoiUtilCell> biaotou=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell biaotouName=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 8, 1, null, null); |
|||
biaotouName.setValue(competeTimeDao.selectByPrimaryKey(params.getParam().getCompeteTimeId()).getName()); |
|||
biaotou.add(biaotouName); |
|||
biao.add(biaotou); |
|||
List<PoiUtil.PoiUtilCell> hangTou=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell xuhaoTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
xuhaoTou.setValue("序号"); |
|||
hangTou.add(xuhaoTou); |
|||
PoiUtil.PoiUtilCell cansaiduiwuTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
cansaiduiwuTou.setValue("参赛队伍"); |
|||
hangTou.add(cansaiduiwuTou); |
|||
PoiUtil.PoiUtilCell lianxirenTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
lianxirenTou.setValue("联系人/领队/教练"); |
|||
hangTou.add(lianxirenTou); |
|||
PoiUtil.PoiUtilCell nameTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
nameTou.setValue("姓名"); |
|||
hangTou.add(nameTou); |
|||
PoiUtil.PoiUtilCell sexTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
sexTou.setValue("性别"); |
|||
hangTou.add(sexTou); |
|||
PoiUtil.PoiUtilCell lianxifangshiTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
lianxifangshiTou.setValue("联系方式"); |
|||
hangTou.add(lianxifangshiTou); |
|||
PoiUtil.PoiUtilCell shenfenzhengTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
shenfenzhengTou.setValue("身份证号"); |
|||
hangTou.add(shenfenzhengTou); |
|||
PoiUtil.PoiUtilCell beizhuTou=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
beizhuTou.setValue("备注"); |
|||
hangTou.add(beizhuTou); |
|||
biao.add(hangTou); |
|||
int i=1; |
|||
for(CompeteCompany competeCompany:competeCompanyList){ |
|||
List<PoiUtil.PoiUtilCell> hang=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell xuhao=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
xuhao.setValue(String.valueOf(i++)); |
|||
hang.add(xuhao); |
|||
PoiUtil.PoiUtilCell cansaiduiwu=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
cansaiduiwu.setValue(competeCompany.getName()); |
|||
hang.add(cansaiduiwu); |
|||
PoiUtil.PoiUtilCell renyuanleibei=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
renyuanleibei.setValue("联系人"); |
|||
hang.add(renyuanleibei); |
|||
PoiUtil.PoiUtilCell name=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
name.setValue(competeCompany.getContactsName()); |
|||
hang.add(name); |
|||
PoiUtil.PoiUtilCell sex=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
sex.setValue("/"); |
|||
hang.add(sex); |
|||
PoiUtil.PoiUtilCell pho=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
pho.setValue(String.valueOf(competeCompany.getContactsPhone())); |
|||
hang.add(pho); |
|||
PoiUtil.PoiUtilCell idCardNum=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
idCardNum.setValue("/"); |
|||
hang.add(idCardNum); |
|||
PoiUtil.PoiUtilCell beizhu=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
beizhu.setValue("无"); |
|||
hang.add(beizhu); |
|||
biao.add(hang); |
|||
for (CompeteCoach competeCoach:competeCoachList){ |
|||
if(competeCoach.getCompanyId().equals(competeCompany.getId())){ |
|||
List<PoiUtil.PoiUtilCell> hanghou=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell xuhaoCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
xuhaoCach.setValue(String.valueOf(i++)); |
|||
hanghou.add(xuhaoCach); |
|||
PoiUtil.PoiUtilCell cansaiduiwuCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
cansaiduiwuCach.setValue(competeCompany.getName()); |
|||
hanghou.add(cansaiduiwuCach); |
|||
PoiUtil.PoiUtilCell renyuanleibeiCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
if (competeCoach.getIdentity().equals((byte) 0)){ |
|||
renyuanleibeiCach.setValue("领队"); |
|||
}else { |
|||
renyuanleibeiCach.setValue("教练"); |
|||
} |
|||
hanghou.add(renyuanleibeiCach); |
|||
PoiUtil.PoiUtilCell nameCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
nameCach.setValue(competeCoach.getName()); |
|||
hanghou.add(nameCach); |
|||
PoiUtil.PoiUtilCell sexCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
sexCach.setValue(competeCoach.getGender().equals((byte) 0)?"女":"男"); |
|||
hanghou.add(sexCach); |
|||
PoiUtil.PoiUtilCell phoCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
phoCach.setValue(String.valueOf(competeCoach.getPhone())); |
|||
hanghou.add(phoCach); |
|||
PoiUtil.PoiUtilCell idCardNumCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
idCardNumCach.setValue(String.valueOf(competeCoach.getIdPhoto())); |
|||
hanghou.add(idCardNumCach); |
|||
PoiUtil.PoiUtilCell beizhuCach=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1, null, null); |
|||
beizhuCach.setValue("无"); |
|||
hanghou.add(beizhuCach); |
|||
biao.add(hanghou); |
|||
} |
|||
} |
|||
} |
|||
Workbook workbook = new XSSFWorkbook(); |
|||
PoiUtil.exportWB("参赛队伍信息表",biao,workbook); |
|||
//String name = "跳绳比赛报名人数统计表" + ".xlsx";
|
|||
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; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public String iTeamListService(QueryDto<CompeteDto.CompeteTime> params) { |
|||
//查出所有的单位的id
|
|||
List<CompeteCompany> competeCompanyList= competeCompanyDao.selectByCompeteTimeId(params.getParam().getCompeteTimeId()); |
|||
List<List<PoiUtil.PoiUtilCell>> biao = new ArrayList<>(); |
|||
List<PoiUtil.PoiUtilCell> biaoti=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell biaotouName=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 2, 1, null, null); |
|||
biaotouName.setValue("代表队名单"); |
|||
biaoti.add(biaotouName); |
|||
biao.add(biaoti); |
|||
for (CompeteCompany com:competeCompanyList) { |
|||
//查出教练和领队的list
|
|||
List<CompeteCoach> jLandLD=competeCompanyDao.selectByCompanyId(com.getId()); |
|||
CompetePlayerExample competePlayerExample=new CompetePlayerExample(); |
|||
competePlayerExample.createCriteria().andCompanyIdEqualTo(com.getId()); |
|||
//运动员list
|
|||
List<CompetePlayer> competePlayerList = competePlayerMapper.selectByExample(competePlayerExample); |
|||
|
|||
List<PoiUtil.PoiUtilCell> daibiaodui=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell daibiaoduiName=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 2, 1, null, null); |
|||
daibiaoduiName.setValue(com.getName()); |
|||
daibiaodui.add(daibiaoduiName); |
|||
biao.add(daibiaodui); |
|||
//领队和教练
|
|||
List<PoiUtil.PoiUtilCell> lingduiList=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell lingdui=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|||
lingdui.setValue("领 队:"); |
|||
lingduiList.add(lingdui); |
|||
biao.add(lingduiList); |
|||
StringBuffer lingduiName=new StringBuffer(""); |
|||
StringBuffer jiaolianName=new StringBuffer(""); |
|||
jLandLD.forEach(jLD->{ |
|||
if (jLD.getIdentity().equals((byte) 0)) { |
|||
lingduiName.append(jLD.getName()+'、'); |
|||
} else { |
|||
jiaolianName.append(jLD.getName()+'、'); |
|||
} |
|||
}); |
|||
if(lingduiName.length()>0){ |
|||
lingduiName.deleteCharAt(lingduiName.length() - 1) ; |
|||
} |
|||
if(jiaolianName.length()>0){ |
|||
jiaolianName.deleteCharAt(jiaolianName.length() - 1) ; |
|||
} |
|||
PoiUtil.PoiUtilCell lingduiNameHang=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|||
lingduiNameHang.setValue(String.valueOf(lingduiName)); |
|||
lingduiList.add(lingduiNameHang); |
|||
|
|||
biao.add(lingduiList); |
|||
List<PoiUtil.PoiUtilCell> jiaolianList=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell jiaoling=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|||
jiaoling.setValue("教 练:"); |
|||
jiaolianList.add(jiaoling); |
|||
PoiUtil.PoiUtilCell jiaolianHang= new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|||
jiaolianHang.setValue(String.valueOf(jiaolianName)); |
|||
jiaolianList.add(jiaolianHang); |
|||
biao.add(jiaolianList); |
|||
|
|||
//再放运动员
|
|||
StringBuffer yDYLN=new StringBuffer(""); |
|||
competePlayerList.forEach(cpL->{ |
|||
yDYLN.append(cpL.getName()); |
|||
yDYLN.append("("); |
|||
yDYLN.append(cpL.getGender().equals((byte) 0)?"女":"男"); |
|||
yDYLN.append(")、"); |
|||
}); |
|||
if (yDYLN.length()>0){ |
|||
yDYLN.deleteCharAt(yDYLN.length()-1); |
|||
} |
|||
|
|||
List<PoiUtil.PoiUtilCell> yundongyuanList=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell yuandongyuan=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|||
yuandongyuan.setValue("运动员"); |
|||
yundongyuanList.add(yuandongyuan); |
|||
PoiUtil.PoiUtilCell yuandongyuanName=new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 1, 1); |
|||
yuandongyuanName.setValue(String.valueOf(yDYLN)); |
|||
yundongyuanList.add(yuandongyuanName); |
|||
biao.add(yundongyuanList); |
|||
biao.add(yundongyuanList); |
|||
List<PoiUtil.PoiUtilCell> entryList=new ArrayList<>(); |
|||
PoiUtil.PoiUtilCell enter= new PoiUtil.PoiUtilCell(WebConstant.CELL_NULL, 2, 1); |
|||
entryList.add(enter); |
|||
biao.add(entryList); |
|||
} |
|||
biao.remove(biaoti.size()-1); |
|||
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; |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
package com.ccsens.mt.service; |
|||
|
|||
import com.ccsens.mt.bean.dto.CompeteDto; |
|||
import com.ccsens.util.bean.dto.QueryDto; |
|||
|
|||
public interface IExcelService { |
|||
/** |
|||
* 导出大赛队伍信息表 |
|||
* @param params |
|||
* @return |
|||
*/ |
|||
String dasaiduiwuxinxiWPS(QueryDto<CompeteDto.CompeteTime> params); |
|||
|
|||
/** |
|||
*导出代表队名单 |
|||
* @param params |
|||
* @return |
|||
*/ |
|||
String iTeamListService(QueryDto<CompeteDto.CompeteTime> params); |
|||
} |
Loading…
Reference in new issue