新增邀请用户导出功能

This commit is contained in:
liaozetao
2023-08-12 14:22:04 +08:00
parent 30c276f850
commit cb11d13068
6 changed files with 227 additions and 28 deletions

View File

@@ -28,7 +28,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.ServletWebRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
@@ -113,4 +115,12 @@ public class FlowTeamSettlementInfoController extends BaseController {
return workbook;
}
@GetMapping("export")
public void export(Long groupId,
String teamId,
HttpServletRequest request,
HttpServletResponse response) {
flowTeamSettlementBizService.export(groupId, teamId, new ServletWebRequest(request, response));
}
}

View File

@@ -12,23 +12,28 @@
<h1 id="itemTitle"></h1>
</section>
<div id="toolbar">
<div class="col-sm-12">
<label for="query-groupSelector" class="col-sm-3 control-label">选择查询团队:</label>
<div class="col-sm-3">
<select name="query-teamSelector" onchange="initTeamSelector(this.options[this.selectedIndex].value, this.name)"
id="query-groupSelector" class="form-control" data-btn-class="btn-warning">
</select>
<form id="searchForm" action="/admin/flowteamSettlement/export" method="get" target="_blank">
<div class="col-sm-12">
<label for="query-groupSelector" class="col-sm-3 control-label">选择查询团队:</label>
<div class="col-sm-3">
<select name="query-teamSelector" onchange="initTeamSelector(this.options[this.selectedIndex].value, this.name)"
id="query-groupSelector" class="form-control" data-btn-class="btn-warning">
</select>
</div>
<label for="query-teamSelector" class="col-sm-3 control-label">选择查询小组:</label>
<div class="col-sm-3">
<select name="teamSelector" id="query-teamSelector" class="form-control" data-btn-class="btn-warning">
</select>
</div>
</div>
<label for="query-teamSelector" class="col-sm-3 control-label">选择查询小组:</label>
<div class="col-sm-3">
<select name="teamSelector" id="query-teamSelector" class="form-control" data-btn-class="btn-warning">
</select>
</div>
</div>
</form>
<div class="col-sm-12">
<button id="btnSearch" class="btn btn-default">
<i class="glyphicon glyphicon-search"></i>查询
</button>
<button id="btnExport" class="btn btn-default">
<i class="glyphicon glyphicon-Export"></i>导出
</button>
</div>
</div>
</div>
@@ -260,6 +265,10 @@
}
}
//导出功能
$("#btnExport").on('click',function () {
$("#searchForm").submit();
});
});
</script>

View File

@@ -10,27 +10,32 @@
*/
package com.accompany.business.service.flow;
import com.accompany.common.utils.DateTimeUtil;
import com.xuanyin.flowteam.mapper.FlowTeamSettlementInfoMapper;
import com.xuanyin.flowteam.model.FlowTeamInfo;
import com.xuanyin.flowteam.model.FlowTeamSettlementInfo;
import com.xuanyin.flowteam.dto.FlowTeamSettlementDetail;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.StringUtils;
import com.accompany.core.exception.ServiceException;
import com.accompany.core.service.common.JedisLockService;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.converters.date.DateDateConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuanyin.flowteam.service.FlowTeamGroupService;
import com.xuanyin.flowteam.dto.FlowTeamSettlementDetail;
import com.xuanyin.flowteam.dto.FlowTeamSettlementInfoExportDto;
import com.xuanyin.flowteam.mapper.FlowTeamSettlementInfoMapper;
import com.xuanyin.flowteam.mapper.FlowTeamSettlementInfoMapperExpand;
import com.xuanyin.flowteam.model.FlowTeamInfo;
import com.xuanyin.flowteam.model.FlowTeamSettlementInfo;
import com.xuanyin.flowteam.service.FlowTeamInfoService;
import com.xuanyin.flowteam.service.FlowTeamSettlementInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.context.request.ServletWebRequest;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
@@ -41,12 +46,15 @@ import java.util.stream.Collectors;
* @author H1
* @date [2021/11/11]
*/
@Slf4j
@Service
public class FlowTeamSettlementBizService {
@Autowired
private FlowTeamSettlementInfoMapper flowTeamSettlementInfoMapper;
@Autowired
private FlowTeamSettlementInfoMapperExpand flowTeamSettlementInfoMapperExpand;
@Autowired
private FlowTeamSettlementInfoService flowTeamSettlementInfoService;
@Autowired
private JedisLockService jedisLockService;
@@ -73,7 +81,7 @@ public class FlowTeamSettlementBizService {
// String month = DateTimeUtil.convertDate(now, DateTimeUtil.DEFAULT_DATE_PATTERN_YEAR_MONTH);
// List<FlowTeamSettlementInfo> currMonthSettlementInfo = flowTeamSettlementInfoMapper.listFlowTeamSettlementInfo(teamId, false, month);
List < FlowTeamSettlementInfo > flowTeamSettlementInfos =
List<FlowTeamSettlementInfo> flowTeamSettlementInfos =
flowTeamSettlementInfoMapper.listFlowTeamSettlementInfoV2(teamIdList, null, null);
// 数据组合返回
@@ -101,6 +109,7 @@ public class FlowTeamSettlementBizService {
/**
* 获取小组某月结算详情
*
* @param teamId
* @param month
* @param erbanNo
@@ -122,13 +131,14 @@ public class FlowTeamSettlementBizService {
/**
* 获取小组某月结算详情V2 (按照用户进行分组统总)
*
* @param teamId
* @param month
* @param erbanNo
* @return
*/
public PageInfo<FlowTeamSettlementDetail> listFlowTeamSettleDetailGroupByUser(String teamId, String month, String erbanNo,
Integer page, Integer pageSize) {
Integer page, Integer pageSize) {
if (StringUtils.isBlank(teamId) || StringUtils.isBlank(month)) {
return new PageInfo<>();
}
@@ -178,6 +188,7 @@ public class FlowTeamSettlementBizService {
/**
* 处理没有数据的月份
*
* @param withoutDataMonth
* @return
*/
@@ -199,17 +210,17 @@ public class FlowTeamSettlementBizService {
/**
* 获取最近12个月
*/
private static String[] getLast12Months(){
private static String[] getLast12Months() {
String[] last12Months = new String[12];
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)+1); //要先+1,才能把本月的算进去
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1); //要先+1,才能把本月的算进去
for(int i=0; i<12; i++){
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)-1); //逐次往前推1个月
for (int i = 0; i < 12; i++) {
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); //逐次往前推1个月
last12Months[11-i] = cal.get(Calendar.YEAR)+ "-" + fillZero((cal.get(Calendar.MONTH)+1));
last12Months[11 - i] = cal.get(Calendar.YEAR) + "-" + fillZero((cal.get(Calendar.MONTH) + 1));
}
return last12Months;
}
@@ -217,13 +228,34 @@ public class FlowTeamSettlementBizService {
/**
* 格式化月份
*/
private static String fillZero(int i){
private static String fillZero(int i) {
String month = "";
if(i<10){
if (i < 10) {
month = "0" + i;
}else{
} else {
month = String.valueOf(i);
}
return month;
}
public void export(Long groupId, String teamId, ServletWebRequest servletWebRequest) {
List<FlowTeamSettlementInfoExportDto> datas = flowTeamSettlementInfoMapperExpand.settlementExport(groupId, teamId);
DateDateConverter dateDateConverter = new DateDateConverter();
if (servletWebRequest.getResponse() != null) {
try {
//这里注意 有同学反应使用swagger 会导致各种问题请直接用浏览器或者用postman
servletWebRequest.getResponse().setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
servletWebRequest.getResponse().setCharacterEncoding("utf-8");
//这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
String fileName = URLEncoder.encode("邀请用户", "UTF-8").replaceAll("\\+", "%20");
servletWebRequest.getResponse().setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(servletWebRequest.getResponse().getOutputStream(), FlowTeamSettlementInfoExportDto.class)
.registerConverter(dateDateConverter)
.sheet("邀请用户")
.doWrite(datas);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
}

View File

@@ -0,0 +1,77 @@
package com.xuanyin.flowteam.dto;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.converters.date.DateDateConverter;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author: liaozetao
* @date: 2023/8/12 13:59
* @description:
*/
@Data
public class FlowTeamSettlementInfoExportDto {
/**
* ID
*/
@ExcelProperty("ID")
private String erBanNo;
/**
* 注册时间
*/
@ExcelProperty(value = "注册时间", converter = DateDateConverter.class)
private Date signUpTime;
/**
* 被邀请时间
*/
@ExcelProperty(value = "被邀请时间", converter = DateDateConverter.class)
private Date inviteTime;
/**
* 首充时间
*/
@ExcelProperty(value = "首充时间", converter = DateDateConverter.class)
private Date firstChargeTime;
/**
* 从被邀请时间起算首次充值时间
*/
@ExcelProperty("从被邀请时间起算首次充值时间")
private Integer diffTimeNum;
/**
* 首次充值金额
*/
@ExcelProperty("首次充值金额")
private BigDecimal firstChargeAmount;
/**
* 首次获得转赠钻石时间
*/
@ExcelProperty(value = "首次获得转赠钻石时间", converter = DateDateConverter.class)
private Date firstGiveTime;
/**
* 首次获得转赠钻石金额
*/
@ExcelProperty("首次获得转赠钻石金额")
private BigDecimal diamondAmount;
/**
* 从被邀请起截止到目前的充值
*/
@ExcelProperty("从被邀请起截止到目前的充值")
private BigDecimal totalChargeAmount;
/**
* 从被邀请起截止到目前转赠的钻石流水
*/
@ExcelProperty("从被邀请起截止到目前转赠的钻石流水")
private BigDecimal totalDiamondAmount;
}

View File

@@ -0,0 +1,23 @@
package com.xuanyin.flowteam.mapper;
import com.xuanyin.flowteam.dto.FlowTeamSettlementInfoExportDto;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author: liaozetao
* @date: 2023/8/12 13:50
* @description:
*/
public interface FlowTeamSettlementInfoMapperExpand {
/**
* 导出
*
* @param groupId
* @param teamId
* @return
*/
List<FlowTeamSettlementInfoExportDto> settlementExport(@Param("groupId") Long groupId, @Param("teamId") String teamId);
}

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xuanyin.flowteam.mapper.FlowTeamSettlementInfoMapperExpand">
<select id="settlementExport" resultType="com.xuanyin.flowteam.dto.FlowTeamSettlementInfoExportDto">
select
u.erban_no as erBanNo,
a.sign_time as signUpTime,
u.create_time as inviteTime,
cr1.first_charge_time as firstChargeTime,
datediff(cr1.first_charge_time, u.create_time) as diffTimeNum,
(cr2.amount / 100) as firstChargeAmount,
dgh1.first_give_time as firstGiveTime,
(dgh2.diamond_num / 1000) as diamondAmount,
((select sum(cr.amount) from charge_record as cr where cr.uid = u.uid and cr.charge_status = 2 and
cr.create_time between u.create_time and now()) / 100) as totalChargeAmount,
((select sum(dgh.diamond_num) from diamond_give_history as dgh where dgh.to_uid = u.uid and dgh.create_time
between u.create_time and now()) / 1000) as totalDiamondAmount
from users as u
inner join account as a on a.uid = u.uid
left join (
select cr.uid, min(cr.create_time) as first_charge_time from charge_record as cr where cr.charge_status = 2
group by cr.uid
) as cr1 on cr1.uid = u.uid
left join charge_record as cr2 on cr2.uid = cr1.uid and cr2.create_time = cr1.first_charge_time and
cr2.charge_status = 2
left join (
select dgh.to_uid, min(dgh.create_time) as first_give_time from diamond_give_history as dgh group by dgh.to_uid
) as dgh1 on dgh1.to_uid = u.uid
left join diamond_give_history as dgh2 on dgh2.to_uid = dgh1.to_uid and dgh2.create_time = dgh1.first_give_time
where u.invite_code is not null
and u.invite_code in (
select
ftmic.invite_code
from flow_team_info as fti
inner join flow_team_member as ftm on ftm.team_id = fti.team_id
inner join flow_team_member_invite_code as ftmic on ftmic.member_id = ftm.member_id
where
fti.`status` = 1
and ftm.member_status = 1
<if test="groupId != null">
and fti.group_id = #{groupId}
</if>
<if test="teamId != null and teamId != ''">
and fti.team_id = #{teamId}
</if>
);
</select>
</mapper>