From 2bc29dd266538e96f71fa8beb60a71a5d46f59ef Mon Sep 17 00:00:00 2001 From: wang0018 <1007152140@qq.com> Date: Fri, 6 Nov 2020 18:46:38 +0800 Subject: [PATCH] 11-6 --- .../com/ccsens/mt/api/ExcelController.java | 27 ++ .../java/com/ccsens/mt/bean/vo/CompeteVo.java | 7 + .../mt/persist/dao/CompeteCompanyDao.java | 16 + .../mt/persist/dao/CompetePlayerDao.java | 1 + .../persist/mapper/CompeteCompanyMapper.java | 1 + .../com/ccsens/mt/service/ExcelService.java | 276 ++++++++++++++++++ .../com/ccsens/mt/service/IExcelService.java | 20 ++ .../mapper_dao/CompeteCompanyDao.xml | 32 +- .../resources/mapper_dao/CompetePlayerDao.xml | 1 + 9 files changed, 379 insertions(+), 2 deletions(-) create mode 100644 mt/src/main/java/com/ccsens/mt/service/ExcelService.java create mode 100644 mt/src/main/java/com/ccsens/mt/service/IExcelService.java diff --git a/mt/src/main/java/com/ccsens/mt/api/ExcelController.java b/mt/src/main/java/com/ccsens/mt/api/ExcelController.java index e6cfadbb..b921afe6 100644 --- a/mt/src/main/java/com/ccsens/mt/api/ExcelController.java +++ b/mt/src/main/java/com/ccsens/mt/api/ExcelController.java @@ -3,6 +3,7 @@ package com.ccsens.mt.api; import com.ccsens.cloudutil.annotation.MustLogin; import com.ccsens.mt.bean.dto.CompeteDto; +import com.ccsens.mt.service.IExcelService; import com.ccsens.util.JsonResponse; import com.ccsens.util.bean.dto.QueryDto; import io.swagger.annotations.Api; @@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import java.io.IOException; /** @@ -25,6 +27,9 @@ import java.io.IOException; @RestController @RequestMapping("/down") public class ExcelController { + @Resource + private IExcelService excelService; + @MustLogin @ApiOperation(value = "报名表详情表(关联wps)", notes = "") @RequestMapping(value = "/enrollWPS", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @@ -33,4 +38,26 @@ public class ExcelController { // String enrollPlayInfoList= competeService.enrollPlayInfoWps(params); return JsonResponse.newInstance().ok(); } + + + @MustLogin + @ApiOperation(value = "大赛参赛队伍信息表", notes = "") + @RequestMapping(value = "/competitionTeamInformationTable", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public JsonResponse dasaiduiwuxinxiWPS(@ApiParam @Validated @RequestBody QueryDto params) throws IOException { + log.info("导出大赛参赛队伍信息表:{}",params); + String path = excelService.dasaiduiwuxinxiWPS(params); + return JsonResponse.newInstance().ok(path); + } + @MustLogin + @ApiOperation(value = "代表队名单", notes = "") + @RequestMapping(value = "/teamList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public JsonResponse teamList(@ApiParam @Validated @RequestBody QueryDto params) throws IOException { + log.info("导出代表队名单表:{}",params); + String path = excelService.iTeamListService(params); + return JsonResponse.newInstance().ok(path); + } + + + + } diff --git a/mt/src/main/java/com/ccsens/mt/bean/vo/CompeteVo.java b/mt/src/main/java/com/ccsens/mt/bean/vo/CompeteVo.java index 518ba17f..2c46dd01 100644 --- a/mt/src/main/java/com/ccsens/mt/bean/vo/CompeteVo.java +++ b/mt/src/main/java/com/ccsens/mt/bean/vo/CompeteVo.java @@ -44,6 +44,13 @@ public class CompeteVo { @ApiModelProperty("描述") private String groupDescription; } + @Data + @ApiModel + public static class CompeteC{ + @ApiModelProperty("参赛队伍") + private String cansaiduiName; + + } @Data @ApiModel("模糊查询参赛单位") diff --git a/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteCompanyDao.java b/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteCompanyDao.java index 9bc2d22d..c11211c6 100644 --- a/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteCompanyDao.java +++ b/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteCompanyDao.java @@ -1,6 +1,8 @@ package com.ccsens.mt.persist.dao; import com.ccsens.mt.bean.dto.ProvinceCompeteDto; +import com.ccsens.mt.bean.po.CompeteCoach; +import com.ccsens.mt.bean.po.CompeteCompany; import com.ccsens.mt.bean.vo.CompeteVo; import com.ccsens.mt.bean.vo.ProvinceCompeteVo; import com.ccsens.mt.persist.mapper.CompeteCompanyMapper; @@ -93,4 +95,18 @@ public interface CompeteCompanyDao extends CompeteCompanyMapper { * @return 返回详细信息 */ ProvinceCompeteVo.GetCoach getCoachInfo(@Param("coachId")Long coachId); + + /** + * 根据大赛id查看当前大赛所有队伍信息,以及联系人的信息 + * @param CompeteTimeId 大赛CompeteTimeId + * @return 返回参赛队伍详细信息 + */ + List selectByCompeteTimeId(Long CompeteTimeId); + + /** + * 根据查出来得大赛得单位的id查询教练和领队得信息 + * @param companyId 单位id + * @return + */ + List selectByCompanyId(@Param("companyId")Long companyId); } diff --git a/mt/src/main/java/com/ccsens/mt/persist/dao/CompetePlayerDao.java b/mt/src/main/java/com/ccsens/mt/persist/dao/CompetePlayerDao.java index 11e4b350..d703fdf5 100644 --- a/mt/src/main/java/com/ccsens/mt/persist/dao/CompetePlayerDao.java +++ b/mt/src/main/java/com/ccsens/mt/persist/dao/CompetePlayerDao.java @@ -1,5 +1,6 @@ package com.ccsens.mt.persist.dao; +import com.ccsens.mt.bean.po.CompetePlayer; import com.ccsens.mt.bean.vo.CompeteVo; import com.ccsens.mt.bean.vo.ProvinceCompeteVo; import com.ccsens.mt.persist.mapper.CompetePlayerMapper; diff --git a/mt/src/main/java/com/ccsens/mt/persist/mapper/CompeteCompanyMapper.java b/mt/src/main/java/com/ccsens/mt/persist/mapper/CompeteCompanyMapper.java index 08e677eb..485d5402 100644 --- a/mt/src/main/java/com/ccsens/mt/persist/mapper/CompeteCompanyMapper.java +++ b/mt/src/main/java/com/ccsens/mt/persist/mapper/CompeteCompanyMapper.java @@ -27,4 +27,5 @@ public interface CompeteCompanyMapper { int updateByPrimaryKeySelective(CompeteCompany record); int updateByPrimaryKey(CompeteCompany record); + } \ No newline at end of file diff --git a/mt/src/main/java/com/ccsens/mt/service/ExcelService.java b/mt/src/main/java/com/ccsens/mt/service/ExcelService.java new file mode 100644 index 00000000..27881b12 --- /dev/null +++ b/mt/src/main/java/com/ccsens/mt/service/ExcelService.java @@ -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 params) { + //这个里面包含联系人得信息 + List competeCompanyList= competeCompanyDao.selectByCompeteTimeId(params.getParam().getCompeteTimeId()); + List competeCoachList =new ArrayList(); + for (CompeteCompany com:competeCompanyList) { + //再根据单位id查询,领队和教练信息,返回list集合 + competeCoachList.addAll(competeCompanyDao.selectByCompanyId(com.getId())); + } + List> biao = new ArrayList<>(); + //先把联系人的都添加进去 + List 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 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 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 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 params) { + //查出所有的单位的id + List competeCompanyList= competeCompanyDao.selectByCompeteTimeId(params.getParam().getCompeteTimeId()); + List> biao = new ArrayList<>(); + List 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 jLandLD=competeCompanyDao.selectByCompanyId(com.getId()); + CompetePlayerExample competePlayerExample=new CompetePlayerExample(); + competePlayerExample.createCriteria().andCompanyIdEqualTo(com.getId()); + //运动员list + List competePlayerList = competePlayerMapper.selectByExample(competePlayerExample); + + List 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 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 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 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 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; + } +} diff --git a/mt/src/main/java/com/ccsens/mt/service/IExcelService.java b/mt/src/main/java/com/ccsens/mt/service/IExcelService.java new file mode 100644 index 00000000..60401c86 --- /dev/null +++ b/mt/src/main/java/com/ccsens/mt/service/IExcelService.java @@ -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 params); + + /** + *导出代表队名单 + * @param params + * @return + */ + String iTeamListService(QueryDto params); +} diff --git a/mt/src/main/resources/mapper_dao/CompeteCompanyDao.xml b/mt/src/main/resources/mapper_dao/CompeteCompanyDao.xml index 0cab33f8..93285868 100644 --- a/mt/src/main/resources/mapper_dao/CompeteCompanyDao.xml +++ b/mt/src/main/resources/mapper_dao/CompeteCompanyDao.xml @@ -41,7 +41,6 @@ and cc.rec_status = 0 limit 1 - - + + \ No newline at end of file diff --git a/mt/src/main/resources/mapper_dao/CompetePlayerDao.xml b/mt/src/main/resources/mapper_dao/CompetePlayerDao.xml index b5918284..831eebbb 100644 --- a/mt/src/main/resources/mapper_dao/CompetePlayerDao.xml +++ b/mt/src/main/resources/mapper_dao/CompetePlayerDao.xml @@ -189,4 +189,5 @@ id = #{playerId} and rec_status = 0 + \ No newline at end of file