diff --git a/mt/src/main/java/com/ccsens/mt/api/CompeteController.java b/mt/src/main/java/com/ccsens/mt/api/CompeteController.java index b1a21ff7..ea37039b 100644 --- a/mt/src/main/java/com/ccsens/mt/api/CompeteController.java +++ b/mt/src/main/java/com/ccsens/mt/api/CompeteController.java @@ -221,4 +221,6 @@ public class CompeteController { // return JsonResponse.newInstance().ok(playerList); // } + + } 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 b921afe6..5033b83c 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.ICompeteService; import com.ccsens.mt.service.IExcelService; import com.ccsens.util.JsonResponse; import com.ccsens.util.bean.dto.QueryDto; @@ -31,12 +32,31 @@ public class ExcelController { private IExcelService excelService; @MustLogin - @ApiOperation(value = "报名表详情表(关联wps)", notes = "") - @RequestMapping(value = "/enrollWPS", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) - public JsonResponse enrollPlayInfoWps(@ApiParam @Validated @RequestBody QueryDto params) throws IOException { - log.info("查询各个项目报名人员信息:{}",params); -// String enrollPlayInfoList= competeService.enrollPlayInfoWps(params); - return JsonResponse.newInstance().ok(); + @ApiOperation(value = "xxx大赛报名表", notes = "") + @RequestMapping(value = "/competeJoin", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public JsonResponse competeJoin(@ApiParam @Validated @RequestBody QueryDto params) throws IOException { + log.info("xxx大赛报名表:{}",params); + String path = excelService.competeJoin(params); + return JsonResponse.newInstance().ok(path); + } + + @MustLogin + @ApiOperation(value = "参赛人数统计表", notes = "") + @RequestMapping(value = "/competeJoinCount", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public JsonResponse competeJoinCount(@ApiParam @Validated @RequestBody QueryDto params) throws IOException { + log.info("参赛人数统计表:{}",params); + String path = excelService.competeJoinCount(params.getParam()); + return JsonResponse.newInstance().ok(path); + } + + + @MustLogin + @ApiOperation(value = "XXX比赛报名汇总表", notes = "") + @RequestMapping(value = "/competeAllCount", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public JsonResponse competeAllCount(@ApiParam @Validated @RequestBody QueryDto params) throws IOException { + log.info("XXX比赛报名汇总表:{}",params); + String path = excelService.competeAllCount(params.getParam()); + return JsonResponse.newInstance().ok(path); } diff --git a/mt/src/main/java/com/ccsens/mt/bean/vo/ProvinceCompeteVo.java b/mt/src/main/java/com/ccsens/mt/bean/vo/ProvinceCompeteVo.java index 62be8623..0c1c422a 100644 --- a/mt/src/main/java/com/ccsens/mt/bean/vo/ProvinceCompeteVo.java +++ b/mt/src/main/java/com/ccsens/mt/bean/vo/ProvinceCompeteVo.java @@ -29,6 +29,7 @@ public class ProvinceCompeteVo { private int projectNum; } + @Data @ApiModel("查找单位内的参赛选手列表") public static class PlayerByCompanyId{ diff --git a/mt/src/main/java/com/ccsens/mt/bean/vo/TableVo.java b/mt/src/main/java/com/ccsens/mt/bean/vo/TableVo.java new file mode 100644 index 00000000..9d921137 --- /dev/null +++ b/mt/src/main/java/com/ccsens/mt/bean/vo/TableVo.java @@ -0,0 +1,95 @@ +package com.ccsens.mt.bean.vo; + + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author li + */ +@Data +public class TableVo { + @Data + @ApiModel("XXXX大赛报名表") + public static class CompeteJoin{ + @ApiModelProperty("参赛项目") + private String competeProject; + @ApiModelProperty("组别") + private String competeGroup; + @ApiModelProperty("姓名") + private String name; + @ApiModelProperty("性别") + private String gender; + @ApiModelProperty("年龄") + private int age; + @ApiModelProperty("身份证号") + private String idCard; + @ApiModelProperty("身份证明") + private String idCardPromise; + @ApiModelProperty("一寸证件照") + private String picture; + @ApiModelProperty("学籍证明/俱乐部证明") + private String StudentPromise; + @ApiModelProperty("体检证明") + private String bodyTest; + @ApiModelProperty("人身意外伤害保险证明") + private String bodyProtect; + @ApiModelProperty("参赛队伍") + private String joinTeam; + } + + + @Data + @ApiModel("参赛人数统计表") + public static class CompeteOverview{ + @ApiModelProperty("参赛队伍名称") + private String companyName; + @ApiModelProperty("当前添加的教练的人数") + private int coachNum; + @ApiModelProperty("当前添加的领队的人数") + private int guideNum; + @ApiModelProperty("当前添加的参赛人员的人数") + private int playerNum; + @ApiModelProperty("队伍总人数") + private int sum; + } + + + @Data + @ApiModel("XXX比赛报名汇总表") + public static class CompeteAllCount{ + @ApiModelProperty("参赛项目") + private String projectName; + @ApiModelProperty("小学男子组") + private int primaryMale; + @ApiModelProperty("小学女子组") + private int primaryFemale; + @ApiModelProperty("小学混合组") + private int primary; + @ApiModelProperty("中学男子组") + private int middleMale; + @ApiModelProperty("中学女子组") + private int middleFemale; + @ApiModelProperty("中学混合组") + private int middle; + @ApiModelProperty("高职院校男子组") + private int highMale; + @ApiModelProperty("高职院校女子组") + private int highFemale; + @ApiModelProperty("高职院校混合组") + private int high; + @ApiModelProperty("本科院校男子组") + private int collegeMale; + @ApiModelProperty("本科院校女子组") + private int collegeFemale; + @ApiModelProperty("本科院校混合组") + private int college; + @ApiModelProperty("俱乐部男子组(14岁及以下)") + private int clubMale; + @ApiModelProperty("俱乐部女子组(14岁及以下)") + private int clubFemale; + @ApiModelProperty("俱乐部混合组(14岁及以下)") + private int club; + } +} diff --git a/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteEnrollDao.java b/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteEnrollDao.java index 55465a4d..9ed3e9bb 100644 --- a/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteEnrollDao.java +++ b/mt/src/main/java/com/ccsens/mt/persist/dao/CompeteEnrollDao.java @@ -1,5 +1,6 @@ package com.ccsens.mt.persist.dao; +import com.ccsens.mt.bean.po.CompeteProjectPlayer; import com.ccsens.mt.bean.vo.CompeteVo; import com.ccsens.mt.persist.mapper.CompetePlayerMapper; import org.apache.ibatis.annotations.Param; @@ -108,4 +109,11 @@ public interface CompeteEnrollDao extends CompetePlayerMapper { */ List getGroupIdNameFromGroup(@Param("type")long type); + /** + * 查询项目信息 + * @param projectId 团队id + * @return 单人项目选手信息 + */ + CompeteProjectPlayer getPlayerInfoSingle(@Param("project_id")long projectId); + } diff --git a/mt/src/main/java/com/ccsens/mt/service/CompeteService.java b/mt/src/main/java/com/ccsens/mt/service/CompeteService.java index 43146161..c6f2ca97 100644 --- a/mt/src/main/java/com/ccsens/mt/service/CompeteService.java +++ b/mt/src/main/java/com/ccsens/mt/service/CompeteService.java @@ -13,6 +13,7 @@ import com.ccsens.mt.bean.dto.CompeteDto; import com.ccsens.mt.bean.dto.LevelDto; import com.ccsens.mt.bean.po.*; import com.ccsens.mt.bean.vo.CompeteVo; +import com.ccsens.mt.bean.vo.TableVo; import com.ccsens.mt.persist.dao.CompeteEnrollDao; import com.ccsens.mt.persist.dao.CompetePlayerDao; import com.ccsens.mt.persist.dao.CompeteTeamDao; @@ -79,6 +80,8 @@ public class CompeteService implements ICompeteService { private CompeteEnrollDao competeEnrollDao; @Resource private TallFeignClient tallFeignClient; + @Resource + private CommonFileMapper commonFileMapper; /** * 查看第几届 @@ -109,7 +112,7 @@ public class CompeteService implements ICompeteService { // competeGroups.forEach(competeGroup -> { // CompeteProjectGroupExample competeProjectGroupExample = new CompeteProjectGroupExample(); // competeProjectGroupExample.createCriteria().andGroupIdEqualTo(competeGroup.getGroupId()).andProjectIdEqualTo(competeType.getProjectId()); -// if(competeProjectGroupMapper.countByExample(competeProjectGroupExample) == 0){ +// if(competeProjectGroupMapper.1ByExample(competeProjectGroupExample) == 0){ // competeGroups.remove(competeGroup); // } // }); @@ -892,6 +895,7 @@ public class CompeteService implements ICompeteService { return failPlayerInfoList; } + /** * 验证数据的正确性,存入数据库 */ @@ -1002,4 +1006,10 @@ public class CompeteService implements ICompeteService { } return true; } + + + + + + } \ 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 index 27881b12..f48a5bae 100644 --- a/mt/src/main/java/com/ccsens/mt/service/ExcelService.java +++ b/mt/src/main/java/com/ccsens/mt/service/ExcelService.java @@ -1,276 +1,666 @@ -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; - } -} +package com.ccsens.mt.service; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.lang.Snowflake; +import cn.hutool.core.util.IdcardUtil; +import cn.hutool.core.util.ObjectUtil; +import com.ccsens.cloudutil.feign.TallFeignClient; +import com.ccsens.mt.bean.dto.CompeteDto; +import com.ccsens.mt.bean.po.*; +import com.ccsens.mt.bean.vo.TableVo; +import com.ccsens.mt.persist.dao.*; +import com.ccsens.mt.persist.mapper.*; +import com.ccsens.util.PoiUtil; +import com.ccsens.util.PropUtil; +import com.ccsens.util.RedisUtil; +import com.ccsens.util.WebConstant; +import com.ccsens.util.bean.dto.QueryDto; +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.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +@Slf4j +@Service +@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) +public class ExcelService implements IExcelService { + @Resource + private CompeteCompanyDao competeCompanyDao; + @Resource + private CompeteTimeDao competeTimeDao; + + @Resource + private CompeteCompanyMapper competeCompanyMapper; + @Resource + private Snowflake snowflake; + @Resource + private CompeteTeamDao competeTeamDao; + @Resource + private CompetePlayerDao competePlayerDao; + @Resource + private CompeteTeamMemberMapper competeTeamMemberMapper; + @Resource + private CompeteProjectMapper competeProjectMapper; + @Resource + private CompeteProjectPlayerMapper competeProjectPlayerMapper; + @Resource + private CompeteGroupMapper competeGroupMapper; + + @Resource + CompeteCoachMapper competeCoachMapper; + + @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; + } + + + @Override + public String competeJoin(QueryDto params) throws IOException { + CompeteDto.CompeteTime competeTime = params.getParam(); + List competeJoinList = getCompeteJoin(competeTime); + String path = getExcelFilePathForCompeteJoin(competeJoinList); + return path; + } + + private List getCompeteJoin(CompeteDto.CompeteTime params) { + List competeJoinList = new ArrayList<>(); + Long competeTimeId = params.getCompeteTimeId(); + CompeteTime competeTime = competeTimeDao.selectByPrimaryKey(competeTimeId); + int type = competeTime.getType(); + Byte level = 2; + CompeteProjectExample competeProjectExample = new CompeteProjectExample(); + competeProjectExample.createCriteria().andTypeEqualTo((byte) type).andLevelEqualTo(level); + //获取参赛项目集合 + List competeProjectList = competeProjectMapper.selectByExample(competeProjectExample); + for (CompeteProject competeProject : competeProjectList) { + String projectName = competeProject.getName(); + if (competeProject.getTeam() == 0) { + //如果不是团队项目,查询该项目下报名人数集合 + CompeteProjectPlayerExample competeProjectPlayerExample = new CompeteProjectPlayerExample(); + competeProjectPlayerExample.createCriteria().andProjectIdEqualTo(competeProject.getId()); + List competeProjectPlayerList = competeProjectPlayerMapper.selectByExample(competeProjectPlayerExample); + for (CompeteProjectPlayer competeProjectPlayer : competeProjectPlayerList) { + //查询每个报名人的详细信息下 + CompetePlayer competePlayer = competePlayerDao.selectByPrimaryKey(competeProjectPlayer.getPlayerId()); + TableVo.CompeteJoin competeJoin = new TableVo.CompeteJoin(); + //姓名 + competeJoin.setName(competePlayer.getName()); + //身份证号 + competeJoin.setIdCard(competePlayer.getIdCard()); + //根据身份证获取选手年龄并赋值 + String idCard = competeJoin.getIdCard(); + int ageByIdCard = IdcardUtil.getAgeByIdCard(idCard); + competeJoin.setAge(ageByIdCard); + Byte gender = competePlayer.getGender(); + if (gender == 0) { + competeJoin.setGender("女"); + } else { + competeJoin.setGender("男"); + } + //查询单位,并赋值 + CompeteCompany competeCompany = competeCompanyMapper.selectByPrimaryKey(competePlayer.getCompanyId()); + if (ObjectUtil.isNotNull(competeCompany)) { + competeJoin.setJoinTeam(competeCompany.getName()); + } + //查询组别,并赋值 + CompeteGroup competeGroup = competeGroupMapper.selectByPrimaryKey(competePlayer.getCompeteGroupId()); + if (ObjectUtil.isNotNull(competeGroup)) { + competeJoin.setCompeteGroup(competePlayer.getName()); + } +// //身份证明查询,并赋值 +// CommonFile commonFile = commonFileMapper.selectByPrimaryKey(competePlayer.getIdCardFrontFile()); +// if (ObjectUtil.isNotNull(commonFile)) { +// competeJoin.setIdCardPromise(commonFile.getVisitLocation()); +// } +// //一寸证件照查询赋值 +// CommonFile commonFile1 = commonFileMapper.selectByPrimaryKey(competePlayer.getIdPhotoFile()); +// if (ObjectUtil.isNotNull(commonFile1)) { +// competeJoin.setPicture(commonFile1.getVisitLocation()); +// } +// //学籍证明/俱乐部证明 +// CommonFile commonFile2 = commonFileMapper.selectByPrimaryKey(competePlayer.getStudentRecordFile()); +// if (ObjectUtil.isNotNull(commonFile2)) { +// competeJoin.setStudentPromise(commonFile2.getVisitLocation()); +// } +// //体检证明 +// CommonFile commonFile3 = commonFileMapper.selectByPrimaryKey(competePlayer.getHealthRecordFile()); +// if (ObjectUtil.isNotNull(commonFile3)) { +// competeJoin.setBodyTest(commonFile3.getVisitLocation()); +// } +// //人身意外伤害保险证明 +// CommonFile commonFile4 = commonFileMapper.selectByPrimaryKey(competePlayer.getInsuranceRecordFile()); +// if (ObjectUtil.isNotNull(commonFile4)) { +// competeJoin.setBodyProtect(commonFile4.getVisitLocation()); +// } + //参赛项目名赋值 + competeJoin.setCompeteProject(projectName); + competeJoinList.add(competeJoin); + } + + } else { //团队项目 + //获取参赛队伍集合 + CompeteTeamExample competeTeamExample = new CompeteTeamExample(); + competeTeamExample.createCriteria().andProjectIdEqualTo(competeProject.getId()); + List competeTeamList = competeTeamDao.selectByExample(competeTeamExample); + for (CompeteTeam competeTeam : competeTeamList) { + //获取队伍下的成员集合 + CompeteTeamMemberExample competeTeamMemberExample = new CompeteTeamMemberExample(); + competeTeamMemberExample.createCriteria().andCompeteTeamIdEqualTo(competeTeam.getId()); + List competeTeamMemberList = competeTeamMemberMapper.selectByExample(competeTeamMemberExample); + for (CompeteTeamMember competeTeamMember : competeTeamMemberList) { + //查询成员详细信息 + CompetePlayer competePlayer = competePlayerDao.selectByPrimaryKey(competeTeamMember.getPlayerId()); + TableVo.CompeteJoin competeJoin = new TableVo.CompeteJoin(); + //姓名 + competeJoin.setName(competePlayer.getName()); + //身份证号 + competeJoin.setIdCard(competePlayer.getIdCard()); + //根据身份证获取选手年龄并赋值 + String idCard = competeJoin.getIdCard(); + int ageByIdCard = IdcardUtil.getAgeByIdCard(idCard); + competeJoin.setAge(ageByIdCard); + //性别 + Byte gender = competePlayer.getGender(); + if (gender == 0) { + competeJoin.setGender("女"); + } else { + competeJoin.setGender("男"); + } + + //查询单位,并赋值 + CompeteCompany competeCompany = competeCompanyMapper.selectByPrimaryKey(competePlayer.getCompanyId()); + if (ObjectUtil.isNotNull(competeCompany)) { + competeJoin.setJoinTeam(competeCompany.getName()); + } + //查询组别,并赋值 + CompeteGroup competeGroup = competeGroupMapper.selectByPrimaryKey(competePlayer.getCompeteGroupId()); + if (ObjectUtil.isNotNull(competeGroup)) { + competeJoin.setCompeteGroup(competePlayer.getName()); + } +// //身份证明查询,并赋值 +// CommonFile commonFile = commonFileMapper.selectByPrimaryKey(competePlayer.getIdCardFrontFile()); +// if (ObjectUtil.isNotNull(commonFile)){ +// competeJoin.setIdCardPromise(commonFile.getVisitLocation()); +// } +// //一寸证件照查询赋值 +// CommonFile commonFile1 = commonFileMapper.selectByPrimaryKey(competePlayer.getIdPhotoFile()); +// if (ObjectUtil.isNotNull(commonFile1)){ +// competeJoin.setPicture(commonFile1.getVisitLocation()); +// } +// //学籍证明/俱乐部证明 +// CommonFile commonFile2 = commonFileMapper.selectByPrimaryKey(competePlayer.getStudentRecordFile()); +// if (ObjectUtil.isNotNull(commonFile2)){ +// competeJoin.setStudentPromise(commonFile2.getVisitLocation()); +// } +// //体检证明 +// CommonFile commonFile3 = commonFileMapper.selectByPrimaryKey(competePlayer.getHealthRecordFile()); +// if (ObjectUtil.isNotNull(commonFile3)){ +// competeJoin.setBodyTest(commonFile3.getVisitLocation()); +// } +// //人身意外伤害保险证明 +// CommonFile commonFile4 = commonFileMapper.selectByPrimaryKey(competePlayer.getInsuranceRecordFile()); +// if (ObjectUtil.isNotNull(commonFile4)){ +// competeJoin.setBodyProtect(commonFile4.getVisitLocation()); +// } + //参赛项目名赋值 + competeJoin.setCompeteProject(projectName); + competeJoinList.add(competeJoin); + } + } + } + } + return competeJoinList; + } + + private String getExcelFilePathForCompeteJoin(List arrayList) throws IOException { + //创建excle表格对象 + List> list = new ArrayList<>(); + //创建行对象 + List title = new ArrayList<>(); + //给首行单元格赋值 + title.add(new PoiUtil.PoiUtilCell("序号")); + title.add(new PoiUtil.PoiUtilCell("参赛项目")); + title.add(new PoiUtil.PoiUtilCell("组别")); + title.add(new PoiUtil.PoiUtilCell("参赛队伍")); + title.add(new PoiUtil.PoiUtilCell("姓名")); + title.add(new PoiUtil.PoiUtilCell("性别")); + title.add(new PoiUtil.PoiUtilCell("年龄")); + title.add(new PoiUtil.PoiUtilCell("身份证号")); +// title.add(new PoiUtil.PoiUtilCell("身份证明")); +// title.add(new PoiUtil.PoiUtilCell("一寸证件照")); +// title.add(new PoiUtil.PoiUtilCell("学籍证明/俱乐部证明")); +// title.add(new PoiUtil.PoiUtilCell("体检证明")); +// title.add(new PoiUtil.PoiUtilCell("人身意外伤害保险证明")); + title.add(new PoiUtil.PoiUtilCell("备注")); + list.add(title); + //创建整个excel表格对象 + Workbook workbook = new XSSFWorkbook(); + int i = 1; + for (TableVo.CompeteJoin competeJoin : arrayList) { + //行对象 + List cells = new ArrayList<>(); + cells.add(new PoiUtil.PoiUtilCell(i + "", 1, 1, 300, 18)); + //单元格对象 + PoiUtil.PoiUtilCell poiUtilCel = new PoiUtil.PoiUtilCell(competeJoin.getCompeteProject()); + cells.add(poiUtilCel); + PoiUtil.PoiUtilCell poiUtilCell = new PoiUtil.PoiUtilCell(competeJoin.getCompeteGroup()); + cells.add(poiUtilCell); + PoiUtil.PoiUtilCell poiUtilCel2 = new PoiUtil.PoiUtilCell(competeJoin.getJoinTeam()); + cells.add(poiUtilCel2); + PoiUtil.PoiUtilCell poiUtilCel3 = new PoiUtil.PoiUtilCell(competeJoin.getName()); + cells.add(poiUtilCel3); + PoiUtil.PoiUtilCell poiUtilCel4 = new PoiUtil.PoiUtilCell(String.valueOf(competeJoin.getGender())); + cells.add(poiUtilCel4); + PoiUtil.PoiUtilCell poiUtilCel5 = new PoiUtil.PoiUtilCell(String.valueOf(competeJoin.getAge())); + cells.add(poiUtilCel5); + PoiUtil.PoiUtilCell poiUtilCel6 = new PoiUtil.PoiUtilCell(competeJoin.getIdCard()); + cells.add(poiUtilCel6); +// PoiUtil.PoiUtilCell poiUtilCel7 = new PoiUtil.PoiUtilCell(competeJoin.getIdCardPromise()); +// cells.add(poiUtilCel7); +// PoiUtil.PoiUtilCell poiUtilCel8 = new PoiUtil.PoiUtilCell(competeJoin.getPicture()); +// cells.add(poiUtilCel8); +// PoiUtil.PoiUtilCell poiUtilCel9 = new PoiUtil.PoiUtilCell(competeJoin.getStudentPromise()); +// cells.add(poiUtilCel9); +// PoiUtil.PoiUtilCell poiUtilCel10 = new PoiUtil.PoiUtilCell(competeJoin.getBodyTest()); +// cells.add(poiUtilCel10); +// PoiUtil.PoiUtilCell poiUtilCel11 = new PoiUtil.PoiUtilCell(competeJoin.getBodyProtect()); +// cells.add(poiUtilCel11); + list.add(cells); + i++; + } + //生成excel表格对象,并将数据放入 + Workbook wbs = PoiUtil.exportWB("报名表", list, workbook); + //8:关联金山在线文档 + String name = "XXXX大赛报名表" + ".xlsx"; + String filepath = "mt/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; + String path = PropUtil.path + filepath; +// String path = filepath; + File tmpFile = new File(path); + if (!tmpFile.getParentFile().exists()) { + tmpFile.getParentFile().mkdirs(); + } + //PropUtil.path获取配置文件中的path属性,拼接生成写入信息的文件名, + File file = new File(path); + OutputStream stream = new FileOutputStream(file); + wbs.write(stream); + stream.close(); + return path; + } + + + @Override + public String competeJoinCount(CompeteDto.CompeteTime params) throws IOException { + List competeOverviewList = competeJoinCountList(params); + String path = getExcelFilePathForCompeteJoinCount(competeOverviewList); + return path; + } + + private List competeJoinCountList(CompeteDto.CompeteTime params) { + CompeteCompanyExample competeCompanyExample = new CompeteCompanyExample(); + competeCompanyExample.createCriteria().andCompeteTimeIdEqualTo(params.getCompeteTimeId()); + //根据大赛id查公司集合 + List competeCompanyList = competeCompanyMapper.selectByExample(competeCompanyExample); + List competeOverview2List = new ArrayList<>(); + for (CompeteCompany competeCompany : competeCompanyList) { + //每个公司的教练数量 + int leader = 1; + int coach = 0; + CompeteCoachExample competeCoachExample = new CompeteCoachExample(); + competeCoachExample.createCriteria().andCompanyIdEqualTo(competeCompany.getId()).andIdentityEqualTo((byte) coach); + long count = competeCoachMapper.countByExample(competeCoachExample); + //每个公司的领队数量 + CompeteCoachExample competeCoachExample1 = new CompeteCoachExample(); + competeCoachExample1.createCriteria().andCompanyIdEqualTo(competeCompany.getId()).andIdentityEqualTo((byte) leader); + long count1 = competeCoachMapper.countByExample(competeCoachExample1); + //每个公司运动员人数 + CompetePlayerExample competePlayerExample2 = new CompetePlayerExample(); + competePlayerExample2.createCriteria().andCompanyIdEqualTo(competeCompany.getId()); + long count2 = competePlayerDao.countByExample(competePlayerExample2); + //总人数 + long sum = count + count1 + count2; + TableVo.CompeteOverview CompeteOverview2 = new TableVo.CompeteOverview(); + CompeteOverview2.setCompanyName(competeCompany.getName()); + CompeteOverview2.setCoachNum((int) count); + CompeteOverview2.setGuideNum((int) count1); + CompeteOverview2.setPlayerNum((int) count2); + CompeteOverview2.setSum((int) sum); + competeOverview2List.add(CompeteOverview2); + } + return competeOverview2List; + } + + + + private String getExcelFilePathForCompeteJoinCount(List arrayList) throws IOException { + //创建excle表格对象 + List> list = new ArrayList<>(); + //创建行对象 + List title = new ArrayList<>(); + //给首行单元格赋值 + title.add(new PoiUtil.PoiUtilCell("序号")); + title.add(new PoiUtil.PoiUtilCell("单位")); + title.add(new PoiUtil.PoiUtilCell("领队")); + title.add(new PoiUtil.PoiUtilCell("教练")); + title.add(new PoiUtil.PoiUtilCell("运动员")); + title.add(new PoiUtil.PoiUtilCell("总人数")); + list.add(title); + //创建整个excel表格对象 + Workbook workbook = new XSSFWorkbook(); + int i = 1; + for (TableVo.CompeteOverview competeOverview : arrayList) { + //行对象 + List cells = new ArrayList<>(); + cells.add(new PoiUtil.PoiUtilCell(i + "", 1, 1, 300, 18)); + //单元格对象 + PoiUtil.PoiUtilCell poiUtilCel = new PoiUtil.PoiUtilCell(competeOverview.getCompanyName()); + cells.add(poiUtilCel); + PoiUtil.PoiUtilCell poiUtilCell = new PoiUtil.PoiUtilCell(String.valueOf(competeOverview.getGuideNum())); + cells.add(poiUtilCell); + PoiUtil.PoiUtilCell poiUtilCel2 = new PoiUtil.PoiUtilCell(String.valueOf(competeOverview.getCoachNum())); + cells.add(poiUtilCel2); + PoiUtil.PoiUtilCell poiUtilCel3 = new PoiUtil.PoiUtilCell(String.valueOf(competeOverview.getPlayerNum())); + cells.add(poiUtilCel3); + PoiUtil.PoiUtilCell poiUtilCel4 = new PoiUtil.PoiUtilCell(String.valueOf(competeOverview.getSum())); + cells.add(poiUtilCel4); + list.add(cells); + i++; + } + //生成excel表格对象,并将数据放入 + Workbook wbs = PoiUtil.exportWB("参赛人数统计表", list, workbook); + //8:关联金山在线文档 + String name = "参赛人数统计表" + ".xlsx"; + String filepath = "mt/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; + String path = PropUtil.path + filepath; +// String path = filepath; + File tmpFile = new File(path); + if (!tmpFile.getParentFile().exists()) { + tmpFile.getParentFile().mkdirs(); + } + //PropUtil.path获取配置文件中的path属性,拼接生成写入信息的文件名, + File file = new File(path); + OutputStream stream = new FileOutputStream(file); + wbs.write(stream); + stream.close(); + return path; + } + + @Override + public String competeAllCount(CompeteDto.CompeteTime params) throws IOException { + return null; + } + + private List competeAllCountList(CompeteDto.CompeteTime params){ + //根据大赛查类型 + Long competeTimeId = params.getCompeteTimeId(); + CompeteTime competeTime = competeTimeDao.selectByPrimaryKey(competeTimeId); + int type = competeTime.getType(); + Byte level = 2; + CompeteProjectExample competeProjectExample = new CompeteProjectExample(); + competeProjectExample.createCriteria().andTypeEqualTo((byte) type).andLevelEqualTo(level); + //获取参赛项目集合 + List competeProjectList = competeProjectMapper.selectByExample(competeProjectExample); + CompeteGroupExample competeGroupExample = new CompeteGroupExample(); + competeGroupExample.createCriteria().andTypeEqualTo((byte) type); + //获取组别集合 + List competeGroupList = competeGroupMapper.selectByExample(competeGroupExample); + for (CompeteProject competeProject : competeProjectList){ + //若不是团队项目 + if (competeProject.getTeam() == 0){ + TableVo.CompeteAllCount competeAllCount = new TableVo.CompeteAllCount(); + //项目名赋值 + competeAllCount.setProjectName(competeProject.getName()); + //遍历组别集合 + int i = 0; + for(CompeteGroup competeGroup : competeGroupList){ + CompetePlayerExample competePlayerExample = new CompetePlayerExample(); + competePlayerExample.createCriteria().andCompeteGroupIdEqualTo(competeGroup.getId()); + //计算每个组别人数 + long count = competePlayerDao.countByExample(competePlayerExample); + } + } + } + return null; + } + + +} + diff --git a/mt/src/main/java/com/ccsens/mt/service/ICompeteService.java b/mt/src/main/java/com/ccsens/mt/service/ICompeteService.java index 206c18a0..84cf068a 100644 --- a/mt/src/main/java/com/ccsens/mt/service/ICompeteService.java +++ b/mt/src/main/java/com/ccsens/mt/service/ICompeteService.java @@ -147,6 +147,8 @@ public interface ICompeteService { * @return 返回失败的信息 */ List signupImport(String path) throws FileNotFoundException, Exception; + + } diff --git a/mt/src/main/java/com/ccsens/mt/service/IExcelService.java b/mt/src/main/java/com/ccsens/mt/service/IExcelService.java index 60401c86..23dc6648 100644 --- a/mt/src/main/java/com/ccsens/mt/service/IExcelService.java +++ b/mt/src/main/java/com/ccsens/mt/service/IExcelService.java @@ -1,20 +1,49 @@ -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); -} +package com.ccsens.mt.service; + +import com.ccsens.mt.bean.dto.CompeteDto; +import com.ccsens.util.bean.dto.QueryDto; +import com.ccsens.mt.bean.dto.CompeteDto; +import com.ccsens.util.bean.dto.QueryDto; + +import java.io.IOException; + +public interface IExcelService { + /** + * 导出大赛队伍信息表 + * @param params + * @return + */ + String dasaiduiwuxinxiWPS(QueryDto params); + + /** + *导出代表队名单 + * @param params + * @return + */ + String iTeamListService(QueryDto params); + + + /** + * XXXX大赛报名表 + * @param params 大赛id + * @return 返回失败的信息 + */ + String competeJoin(QueryDto params) throws IOException; + + + + /** + * XXXX大赛报名表 + * @param params 大赛id + * @return 返回失败的信息 + */ + String competeJoinCount(CompeteDto.CompeteTime params) throws IOException; + + + /** + * XXX比赛报名汇总表 + * @param params 大赛id + * @return 返回失败的信息 + */ + String competeAllCount(CompeteDto.CompeteTime params) throws IOException; +} diff --git a/mt/src/main/resources/mapper_dao/CompeteEnrollDao.xml b/mt/src/main/resources/mapper_dao/CompeteEnrollDao.xml index c3846e72..fe66d7eb 100644 --- a/mt/src/main/resources/mapper_dao/CompeteEnrollDao.xml +++ b/mt/src/main/resources/mapper_dao/CompeteEnrollDao.xml @@ -170,4 +170,11 @@ WHERE type = #{type} ORDER BY id + diff --git a/util/src/main/java/com/ccsens/util/PoiUtil.java b/util/src/main/java/com/ccsens/util/PoiUtil.java index d7c0cd44..3bbcb1c2 100644 --- a/util/src/main/java/com/ccsens/util/PoiUtil.java +++ b/util/src/main/java/com/ccsens/util/PoiUtil.java @@ -162,6 +162,9 @@ public class PoiUtil { List cells = rows.get(i); for (int j = 0; j < cells.size(); j++) { PoiUtilCell cell = cells.get(j); + if(ObjectUtil.isNull(cell)){ + continue; + } //查找当前单元格 Cell newCell = row.getCell(j); if(ObjectUtil.isNull(newCell)){