Browse Source

11-11 20:12

tiaosheng
wang0018 5 years ago
parent
commit
61aac0c3f7
  1. 9
      mt/src/main/java/com/ccsens/mt/api/ExcelController.java
  2. 62
      mt/src/main/java/com/ccsens/mt/bean/vo/CompeteExcelVo.java
  3. 3
      mt/src/main/java/com/ccsens/mt/persist/dao/CompeteCompanyDao.java
  4. 5
      mt/src/main/java/com/ccsens/mt/persist/dao/CompetePlayerDao.java
  5. 3
      mt/src/main/java/com/ccsens/mt/persist/dao/CompeteTeamDao.java
  6. 188
      mt/src/main/java/com/ccsens/mt/service/ExcelService.java
  7. 2
      mt/src/main/java/com/ccsens/mt/service/IExcelService.java
  8. 4
      mt/src/main/resources/application.yml
  9. 28
      mt/src/main/resources/mapper_dao/CompeteCompanyDao.xml
  10. 38
      mt/src/main/resources/mapper_dao/CompetePlayerDao.xml
  11. 31
      mt/src/main/resources/mapper_dao/CompeteTeamDao.xml
  12. 8
      util/src/test/java/com/ccsens/util/OtherTest.java

9
mt/src/main/java/com/ccsens/mt/api/ExcelController.java

@ -78,7 +78,14 @@ public class ExcelController {
return JsonResponse.newInstance().ok(path);
}
@MustLogin
@ApiOperation(value = "比赛出场顺序", notes = "")
@RequestMapping(value = "/competitionOrder", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<String> competitionOrder(@ApiParam @Validated @RequestBody QueryDto<CompeteDto.CompeteTime> params) throws IOException {
log.info("导出比赛出场顺序:{}",params);
String path = excelService.iCompetitionOrderService(params);
return JsonResponse.newInstance().ok(path);
}
}

62
mt/src/main/java/com/ccsens/mt/bean/vo/CompeteExcelVo.java

@ -0,0 +1,62 @@
package com.ccsens.mt.bean.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import java.util.List;
@Data
public class CompeteExcelVo {
@Data
@ApiModel("顺序表")
public static class TeamOrderPlayer {
@ApiModelProperty("组别id")
private String groupId;
@ApiModelProperty("组别名")
private String groupName;
@ApiModelProperty("单位信息")
private List<TeamOrderPlayerList> companyNameList;
}
@Data
@ApiModel("顺序表")
public static class TeamOrderPlayerList {
@ApiModelProperty("团队id")
private Long teamId;
@ApiModelProperty("单位名称")
private String companyName;
@ApiModelProperty("团队选手名字")
private String playerNames;
}
@Data
@ApiModel("所有项目")
public static class AllProject{
@ApiModelProperty("项目id")
private Long id;
@ApiModelProperty("项目名字")
private String projectName;
@ApiModelProperty("开始时间Long")
private Long startTime;
@ApiModelProperty("开始时间Str")
private String startTimeStr;
@ApiModelProperty("结束时间Long")
private Long endTime;
@ApiModelProperty("结束时间Str")
private String endTimeStr;
@ApiModelProperty("组别大小")
private int size;
@ApiModelProperty("是否为团队项目,0不是 1是")
private Byte team;
@ApiModelProperty("项目场地数量")
private int siteNum;
@ApiModelProperty("项目信息")
private List<TeamOrderPlayer> projectList;
@ApiModelProperty("月/日 上/下午")
private String year;
}
}

3
mt/src/main/java/com/ccsens/mt/persist/dao/CompeteCompanyDao.java

@ -3,6 +3,7 @@ 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.CompeteExcelVo;
import com.ccsens.mt.bean.vo.CompeteVo;
import com.ccsens.mt.bean.vo.ProvinceCompeteVo;
import com.ccsens.mt.persist.mapper.CompeteCompanyMapper;
@ -140,4 +141,6 @@ public interface CompeteCompanyDao extends CompeteCompanyMapper {
*/
int getTeamNumByPlayerIdAndGroup(@Param("competeTimeId")Long competeTimeId, @Param("playerId")Long playerId, @Param("projectId")Long projectId,
@Param("companyId")Long companyId, @Param("gender")int gender, @Param("groupRemark")int groupRemark);
List<CompeteExcelVo.AllProject> selectProjectByType(Long id);
}

5
mt/src/main/java/com/ccsens/mt/persist/dao/CompetePlayerDao.java

@ -1,6 +1,8 @@
package com.ccsens.mt.persist.dao;
import com.ccsens.mt.bean.po.CompeteGroup;
import com.ccsens.mt.bean.po.CompetePlayer;
import com.ccsens.mt.bean.vo.CompeteExcelVo;
import com.ccsens.mt.bean.vo.CompeteVo;
import com.ccsens.mt.bean.vo.ProvinceCompeteVo;
import com.ccsens.mt.bean.vo.TableVo;
@ -73,4 +75,7 @@ public interface CompetePlayerDao extends CompetePlayerMapper {
List<TableVo.CompeteAllCount> getTeamJoinNumByType(@Param("timeId")Long timeId);
List<Integer> getTeamJoinNumByProjectId(@Param("projectId")Long projectId);
CompeteGroup selectBySexAndRemark(int gender, int groupRemark);
List<CompeteExcelVo.TeamOrderPlayer> selectSinglePlayerByProjectId(Long id);
}

3
mt/src/main/java/com/ccsens/mt/persist/dao/CompeteTeamDao.java

@ -1,5 +1,6 @@
package com.ccsens.mt.persist.dao;
import com.ccsens.mt.bean.vo.CompeteExcelVo;
import com.ccsens.mt.bean.vo.CompeteVo;
import com.ccsens.mt.persist.mapper.CompeteTeamMapper;
import org.apache.ibatis.annotations.Param;
@ -80,4 +81,6 @@ public interface CompeteTeamDao extends CompeteTeamMapper {
* @return
*/
List<CompeteVo.PlayerInfoByProject> getPlayerByProjectId(@Param("competeProjectId")Long competeProjectId, @Param("competeTimeId")Long competeTimeId);
List<CompeteExcelVo.TeamOrderPlayer> selectTeamMemberByProjectId(Long id);
}

188
mt/src/main/java/com/ccsens/mt/service/ExcelService.java

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

2
mt/src/main/java/com/ccsens/mt/service/IExcelService.java

@ -46,4 +46,6 @@ public interface IExcelService {
* @return 返回失败的信息
*/
String competeAllCount(CompeteDto.CompeteTime params) throws IOException;
String iCompetitionOrderService(QueryDto<CompeteDto.CompeteTime> params);
}

4
mt/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: test
include: common, util-test
active: dev
include: common, util-dev

28
mt/src/main/resources/mapper_dao/CompeteCompanyDao.xml

@ -15,7 +15,14 @@
<result column="memberMax" property="memberMax"/>
</collection>
</resultMap>
<resultMap id="projectMes" type="com.ccsens.mt.bean.vo.CompeteExcelVo$AllProject">
<id column="id" property="id"/>
<result column="team" property="team"/>
<result column="projectName" property="projectName" />
<result column="startTime" property="startTime" />
<result column="endTime" property="endTime" />
<result column="siteNum" property="siteNum" />
</resultMap>
<resultMap id="group_player" type="com.ccsens.mt.bean.vo.ProvinceCompeteVo$GroupAndPlayer">
<id column="groupId" property="groupId"/>
<result column="groupName" property="groupName"/>
@ -339,5 +346,22 @@
and t.rec_status = 0
and m.rec_status = 0
</select>
<select id="selectProjectByType" resultMap="projectMes">
select
tcp.id as id,
tcp.name as projectName,
tcp.team as team,
tcpc.start_time as startTime,
tcpc.end_time as endTime,
tcpc.site_num as siteNum
FROM t_compete_project tcp
left JOIN t_compete_time tct on tcp.type=tct.type
left JOIN t_compete_project_config tcpc on tcpc.project_id=tcp.id
where
tct.id=#{id} and
tcp.rec_status=0 and
tcpc.rec_status=0 and
tct.rec_status=0
ORDER BY tcpc.start_time
</select>
</mapper>

38
mt/src/main/resources/mapper_dao/CompetePlayerDao.xml

@ -30,7 +30,15 @@
<collection property="nums" ofType="Integer" column="projectId" select="getTeamJoinNumByProjectId">
</collection>
</resultMap>
<resultMap id="singleOrderPlayer" type="com.ccsens.mt.bean.vo.CompeteExcelVo$TeamOrderPlayer">
<id column="groupId" property="groupId" />
<result column="groupName" property="groupName" />
<collection property="companyNameList" ofType="com.ccsens.mt.bean.vo.CompeteExcelVo$TeamOrderPlayerList">
<id column="companyId" property="teamId"/>
<result column="companyName" property="companyName"/>
<result column="playerName" property="playerNames"/>
</collection>
</resultMap>
<select id="getInfo" resultType="com.ccsens.mt.bean.vo.CompeteVo$GetPlayerInfo">
SELECT
p.id AS playerId,
@ -264,4 +272,32 @@
and g.rec_status in (0,1)
ORDER BY g.sequence
</select>
<select id="selectBySexAndRemark" resultType="com.ccsens.mt.bean.po.CompeteGroup">
SELECT
tcg.`group_name` as groupName
FROM
t_compete_group tcg
WHERE
tcg.`sex`=#{sex}
and tcg.`group_remark`=#{remark}
</select>
<select id="selectSinglePlayerByProjectId" resultMap="singleOrderPlayer">
select
tcg.id as groupId,
tcg.group_name as groupName,
tcc.id as companyId,
tcc.name as companyName,
tcp.name as playerName
FROM
t_compete_project_player tcpp
LEFT JOIN t_compete_player tcp on tcp.id=tcpp.player_id
LEFT JOIN t_compete_company tcc on tcp.company_id=tcc.id
LEFT JOIN t_compete_group tcg on tcg.id=tcp.compete_group_id
WHERE
tcpp.project_id=#{id}
and tcpp.rec_status=0
and tcp.rec_status=0
and tcc.rec_status=0
and tcg.rec_status=0
</select>
</mapper>

31
mt/src/main/resources/mapper_dao/CompeteTeamDao.xml

@ -14,7 +14,15 @@
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
</resultMap>
<resultMap id="teamOrderPlayer" type="com.ccsens.mt.bean.vo.CompeteExcelVo$TeamOrderPlayer">
<id column="groupId" property="groupId" />
<result column="groupName" property="groupName" />
<collection property="companyNameList" ofType="com.ccsens.mt.bean.vo.CompeteExcelVo$TeamOrderPlayerList">
<id column="teamId" property="teamId"/>
<result column="companyName" property="companyName"/>
<result column="playerNames" property="playerNames"/>
</collection>
</resultMap>
<resultMap id="getTeamByProjectId" type="com.ccsens.mt.bean.vo.CompeteVo$TeamInfoByProject">
<id column="teamId" property="teamId" />
<result column="creatorId" property="creatorId" />
@ -251,4 +259,25 @@
and pp.rec_status = 0
and p.rec_status = 0
</select>
<select id="selectTeamMemberByProjectId" resultMap="teamOrderPlayer">
SELECT
tcg.id as groupId,
tct.id as teamId,
tcg.group_name as groupName,
tcc.`name` as companyName,
GROUP_CONCAT(tcp.`name` separator '、') as playerNames
FROM
`t_compete_team` tct
LEFT JOIN `t_compete_team_member` tctm ON tct.id = tctm.compete_team_id
LEFT JOIN t_compete_group tcg ON tct.gender_group = tcg.sex
AND tct.group_remark = tcg.group_remark
left JOIN t_compete_player tcp on tcp.id=tctm.player_id
left join t_compete_company tcc on tct.company_id=tcc.id
WHERE
tct.project_id = #{projectId}
AND tct.rec_status = 0
AND tctm.rec_status = 0
AND tcg.rec_status =0
</select>
</mapper>

8
util/src/test/java/com/ccsens/util/OtherTest.java

@ -9,6 +9,8 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
@Slf4j
public class OtherTest {
@ -36,5 +38,11 @@ public class OtherTest {
System.out.println(file1);
ImageUtil.scale(file1,file2,2);
}
@Test
public void func3(){
SimpleDateFormat sdf2 = new SimpleDateFormat("MM-dd a");
String sd2 = sdf2.format(new Date(1605074997152L));
System.out.println(sd2);
}
}

Loading…
Cancel
Save