直播记录加上营养师、时间范围筛选,导出功能,进粉、导粉、直播时长统计

This commit is contained in:
xiezhijun
2021-08-24 18:09:07 +08:00
parent ec4f96dc7c
commit 38ba732152
8 changed files with 350 additions and 28 deletions

View File

@ -1,9 +1,13 @@
package com.stdiet.web.controller.custom;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.stdiet.common.utils.DateUtils;
import com.stdiet.common.utils.NumberUtils;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.custom.domain.SysLiveSchedulFanRecord;
import org.springframework.security.access.prepost.PreAuthorize;
@ -36,11 +40,30 @@ public class SysLiveSchedulController extends BaseController
*/
@PreAuthorize("@ss.hasPermi('custom:liveSchedul:list')")
@GetMapping("/list")
public TableDataInfo list(SysLiveSchedul sysLiveSchedul)
public AjaxResult list(SysLiveSchedul sysLiveSchedul)
{
startPage();
List<SysLiveSchedul> list = sysLiveSchedulService.selectSysLiveSchedulList(sysLiveSchedul);
return getDataTable(list);
int totalImportNum = 0;
int totalAddFanNum = 0;
double totalLiveTime = 0;
if(list != null && list.size() > 0){
//查询总共导粉量
totalImportNum = sysLiveSchedulService.getTotalImportFanNumByLiveSchedul(sysLiveSchedul);
//查询总共进粉量
totalAddFanNum = sysLiveSchedulService.getTotalAddFanNumByLiveSchedul(sysLiveSchedul);
//查询总直播时长(小时)
totalLiveTime = NumberUtils.getNumberByRoundHalfUp(sysLiveSchedulService.getLiveTotalTimeByLiveSchedul(sysLiveSchedul)/60.0,2).doubleValue();
}
Map<String, Object> result = new HashMap<>();
result.put("tableDataInfo", getDataTable(list));
result.put("totalImportNum", totalImportNum);
result.put("totalAddFanNum", totalAddFanNum);
result.put("totalLiveTime", totalLiveTime);
return AjaxResult.success(result);
}
/**
@ -52,6 +75,29 @@ public class SysLiveSchedulController extends BaseController
public AjaxResult export(SysLiveSchedul sysLiveSchedul)
{
List<SysLiveSchedul> list = sysLiveSchedulService.selectSysLiveSchedulList(sysLiveSchedul);
for (SysLiveSchedul live : list) {
live.setImportFanSize(0);
if(live.getWxAccountList() != null && live.getWxAccountList().size() > 0){
for (Map<String,Object> map : live.getWxAccountList()
) {
live.setImportFanSize(live.getImportFanSize() + (map.containsKey("fanNum") ? ((BigDecimal) map.get("fanNum")).intValue() : 0));
}
}
live.setAddFanSize(live.getAddFanList() != null ? live.getAddFanList().size() : 0);
String liveTimeStr = "";
if(live.getLiveStartTime() != null){
liveTimeStr = DateUtils.getHourMinuteByDate(live.getLiveStartTime());
}
if(live.getLiveEndTime() != null){
liveTimeStr += "-" + DateUtils.getHourMinuteByDate(live.getLiveEndTime());
}
live.setLiveStartTimeString(liveTimeStr);
//计算直播时长
if(live.getLiveStartTime() != null && live.getLiveEndTime() != null){
double t = (live.getLiveEndTime().getTime() - live.getLiveStartTime().getTime())/1000.0/60/60;
live.setLiveTotalHour(t > 0 ? NumberUtils.getNumberByRoundHalfUp(t,2) : new BigDecimal(0));
}
}
ExcelUtil<SysLiveSchedul> util = new ExcelUtil<SysLiveSchedul>(SysLiveSchedul.class);
return util.exportExcel(list, "liveSchedul");
}

View File

@ -28,6 +28,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
private static String[] parsePatterns = {
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
@ -231,4 +233,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
public static Date getLastMinuteDate(Date date){
return new Date(dateToDate(date).getTime()+(24 * 60 * 60 * 1000 - 1000));
}
/**
* 获取日期的小时和分钟
* @param date
* @return
*/
public static String getHourMinuteByDate(Date date){
String dateStr = DateFormatUtils.format(date, YYYY_MM_DD_HH_MM);
return dateStr.substring(dateStr.length()-5);
}
}

View File

@ -1,5 +1,6 @@
package com.stdiet.custom.domain;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -24,44 +25,38 @@ public class SysLiveSchedul extends BaseEntity
private Long id;
/** 直播间序号 */
@Excel(name = "直播间序号")
private Integer liveRoom;
/** 排班日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "排班日期", width = 30, dateFormat = "yyyy-MM-dd")
@Excel(name = "直播日期", width = 30, dateFormat = "yyyy-MM-dd", sort = 1)
private Date liveSchedulDate;
/** 直播开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Excel(name = "直播开始时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date liveStartTime;
@Excel(name = "直播时间", width = 30, sort = 3)
private String liveStartTimeString;
/** 直播结束时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
@Excel(name = "直播结束时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date liveEndTime;
/** 直播营养师 */
@Excel(name = "直播营养师")
private Long liveNutritionistId;
/** 直播运营 */
@Excel(name = "直播运营")
private Long liveOperatorId;
/** 直播策划 */
@Excel(name = "直播策划")
private Long livePlannerId;
/** 微信账号管理的进粉渠道 */
@Excel(name = "微信账号管理的进粉渠道")
private Integer fanChannel;
/** 直播状态0未开播 1已开播 2已下播 */
@Excel(name = "直播状态0未开播 1已开播 2已下播")
@Excel(name = "直播状态", readConverterExp="0=未开播,1=已开播,2=已下播",sort = 4)
private Long liveStatus;
/** 删除标识默认0 */
@ -71,19 +66,33 @@ public class SysLiveSchedul extends BaseEntity
private Long wxAccountId;
//直播间名称
@Excel(name = "直播间", sort = 2)
private String liveRoomName;
@Excel(name = "直播营养师", sort = 5)
private String liveNutritionistName;
private String livePlannerName;
private String liveOperatorName;
@Excel(name = "所属账号",sort = 6)
private String fanChannelName;
//导粉情况
private List<Map<String,Object>> wxAccountList;
//导粉数量
@Excel(name = "导粉数量",sort = 7,isStatistics = true,cellType = Excel.ColumnType.NUMERIC)
private Integer importFanSize;
//进粉情况
private List<Map<String,Object>> addFanList;
//进粉数量
@Excel(name = "进粉数量",sort = 8, isStatistics=true,cellType = Excel.ColumnType.NUMERIC)
private Integer addFanSize;
@Excel(name = "直播时长",sort = 9, isStatistics=true,cellType = Excel.ColumnType.NUMERIC)
private BigDecimal liveTotalHour;
}

View File

@ -96,4 +96,25 @@ public interface SysLiveSchedulMapper
* @return
*/
public SysLiveSchedul getLiveSchedulByTime(SysLiveSchedul sysLiveSchedul);
/**
* 查询导粉总量
* @param sysLiveSchedul
* @return
*/
int getTotalImportFanNumByLiveSchedul(SysLiveSchedul sysLiveSchedul);
/**
* 查询总进粉量
* @param sysLiveSchedul
* @return
*/
int getTotalAddFanNumByLiveSchedul(SysLiveSchedul sysLiveSchedul);
/**
* 查询总直播时长
* @param sysLiveSchedul
* @return
*/
int getLiveTotalTimeByLiveSchedul(SysLiveSchedul sysLiveSchedul);
}

View File

@ -113,4 +113,25 @@ public interface ISysLiveSchedulService
* @return
*/
int delLiveSchedulFanRecord(Long id);
/**
* 查询导粉总量
* @param sysLiveSchedul
* @return
*/
int getTotalImportFanNumByLiveSchedul(SysLiveSchedul sysLiveSchedul);
/**
* 查询总进粉量
* @param sysLiveSchedul
* @return
*/
int getTotalAddFanNumByLiveSchedul(SysLiveSchedul sysLiveSchedul);
/**
* 查询总直播时长
* @param sysLiveSchedul
* @return
*/
int getLiveTotalTimeByLiveSchedul(SysLiveSchedul sysLiveSchedul);
}

View File

@ -216,4 +216,31 @@ public class SysLiveSchedulServiceImpl implements ISysLiveSchedulService
public int delLiveSchedulFanRecord(Long id){
return sysLiveSchedulFanRecordMapper.deleteSysLiveSchedulFanRecordById(id);
}
/**
* 查询导粉总量
* @param sysLiveSchedul
* @return
*/
public int getTotalImportFanNumByLiveSchedul(SysLiveSchedul sysLiveSchedul){
return sysLiveSchedulMapper.getTotalImportFanNumByLiveSchedul(sysLiveSchedul);
}
/**
* 查询总进粉量
* @param sysLiveSchedul
* @return
*/
public int getTotalAddFanNumByLiveSchedul(SysLiveSchedul sysLiveSchedul){
return sysLiveSchedulMapper.getTotalAddFanNumByLiveSchedul(sysLiveSchedul);
}
/**
* 查询总直播时长
* @param sysLiveSchedul
* @return
*/
public int getLiveTotalTimeByLiveSchedul(SysLiveSchedul sysLiveSchedul){
return sysLiveSchedulMapper.getLiveTotalTimeByLiveSchedul(sysLiveSchedul);
}
}

View File

@ -67,8 +67,11 @@
left join sys_user su_plan on su_plan.user_id = slc.live_planner_id and su_plan.del_flag = 0
left join sys_user su_operator on su_operator.user_id = slc.live_operator_id and su_operator.del_flag = 0
where slc.del_flag = 0
<if test="liveSchedulDate != null">
and date_format(slc.live_schedul_date,'%y%m%d') = date_format(#{liveSchedulDate},'%y%m%d')
<if test="liveStartTime != null and liveEndTime != null">
and (
date_format(slc.live_schedul_date,'%y%m%d') >= date_format(#{liveStartTime},'%y%m%d')
and date_format(#{liveEndTime},'%y%m%d') >= date_format(slc.live_schedul_date,'%y%m%d')
)
</if>
<if test="liveRoom != null">
and slc.live_room = #{liveRoom}
@ -76,9 +79,10 @@
<if test="fanChannel != null">
and slc.fan_channel = #{fanChannel}
</if>
<!--<if test="wxAccountId != null">
and slc.fan_channel = (SELECT swd.account_id FROM sys_wx_distribution AS swd where swd.wechat_account = #{wxAccountId} and swd.del_flag = 0 limit 1)
</if>-->
<if test="liveNutritionistId != null">
and slc.live_nutritionist_id = #{liveNutritionistId}
</if>
order by slc.live_schedul_date desc,slc.live_start_time desc ,slc.live_room asc
</select>
@ -175,6 +179,31 @@
group by w.wx_account,su.nick_name
</select>
<!-- 查询直播列表中导粉总数量 -->
<select id="getTotalImportFanNumByLiveSchedul" parameterType="SysLiveSchedul" resultType="int">
SELECT ifnull(sum(wa.import_fan_num),0) as fanNum from sys_import_fan_record as fc
left join sys_import_fan_wx_account as wa on wa.import_fan_record_id = fc.id and wa.del_flag = 0
where fc.del_flag = 0 and fc.import_fan_live in (
select slc.id from sys_live_schedul slc
where slc.del_flag = 0
<if test="liveStartTime != null and liveEndTime != null">
and (
date_format(slc.live_schedul_date,'%y%m%d') >= date_format(#{liveStartTime},'%y%m%d')
and date_format(#{liveEndTime},'%y%m%d') >= date_format(slc.live_schedul_date,'%y%m%d')
)
</if>
<if test="liveRoom != null">
and slc.live_room = #{liveRoom}
</if>
<if test="fanChannel != null">
and slc.fan_channel = #{fanChannel}
</if>
<if test="liveNutritionistId != null">
and slc.live_nutritionist_id = #{liveNutritionistId}
</if>
)
</select>
<!-- 查询直播时间范围是否重叠 -->
<select id="getLiveSchedulByLiveTime" parameterType="SysLiveSchedul" resultMap="SysLiveSchedulResultSigle">
select
@ -234,4 +263,52 @@
where fr.del_flag = 0 and fr.live_schedul_id = #{id} order by fr.create_time desc
</select>
<!-- 查询总进粉量 -->
<select id="getTotalAddFanNumByLiveSchedul" parameterType="SysLiveSchedul" resultType="int">
select
count(fr.id)
from sys_live_schedul_fan_record as fr
where fr.del_flag = 0 and fr.live_schedul_id in
(
select slc.id from sys_live_schedul slc
where slc.del_flag = 0
<if test="liveStartTime != null and liveEndTime != null">
and (
date_format(slc.live_schedul_date,'%y%m%d') >= date_format(#{liveStartTime},'%y%m%d')
and date_format(#{liveEndTime},'%y%m%d') >= date_format(slc.live_schedul_date,'%y%m%d')
)
</if>
<if test="liveRoom != null">
and slc.live_room = #{liveRoom}
</if>
<if test="fanChannel != null">
and slc.fan_channel = #{fanChannel}
</if>
<if test="liveNutritionistId != null">
and slc.live_nutritionist_id = #{liveNutritionistId}
</if>
)
</select>
<!-- 查询总直播时长(分钟) -->
<select id="getLiveTotalTimeByLiveSchedul" parameterType="SysLiveSchedul" resultType="int">
select ifnull(sum(TIMESTAMPDIFF(minute,slc.live_start_time,slc.live_end_time)),0) from sys_live_schedul as slc
where slc.del_flag = 0 and slc.live_start_time is not null and slc.live_end_time is not null
<if test="liveStartTime != null and liveEndTime != null">
and (
date_format(slc.live_schedul_date,'%y%m%d') >= date_format(#{liveStartTime},'%y%m%d')
and date_format(#{liveEndTime},'%y%m%d') >= date_format(slc.live_schedul_date,'%y%m%d')
)
</if>
<if test="liveRoom != null">
and slc.live_room = #{liveRoom}
</if>
<if test="fanChannel != null">
and slc.fan_channel = #{fanChannel}
</if>
<if test="liveNutritionistId != null">
and slc.live_nutritionist_id = #{liveNutritionistId}
</if>
</select>
</mapper>

View File

@ -2,13 +2,27 @@
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="直播日期" prop="liveSchedulDate">
<el-date-picker clearable size="small" style="width: 200px"
<!--<el-date-picker clearable size="small" style="width: 200px"
v-model="queryParams.liveSchedulDate"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择直播日期">
</el-date-picker>-->
<el-date-picker
v-model="liveDateScope"
type="daterange"
range-separator=""
start-placeholder="开始日期"
end-placeholder="结束日期"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
:picker-options="liveDatePickerOptions"
>
</el-date-picker>
</el-form-item>
<el-form-item label="直播间" prop="liveRoom">
<el-select
v-model="queryParams.liveRoom"
@ -41,6 +55,22 @@
/>
</el-select>
</el-form-item>
<el-form-item label="营养师" prop="liveNutritionistId">
<el-select
v-model="queryParams.liveNutritionistId"
placeholder="请选择营养师"
clearable
filterable
size="small"
>
<el-option
v-for="dict in nutritionistIdOptions.slice(1)"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
/>
</el-select>
</el-form-item>
<!--<el-form-item label="微信号" prop="wxAccountId">
<el-select
v-model="queryParams.wxAccountId"
@ -105,7 +135,7 @@
>一键复制上次记录</el-button>
</el-col>
<!--<el-col :span="1.5">
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
@ -113,7 +143,7 @@
@click="handleExport"
v-hasPermi="['custom:liveSchedul:export']"
>导出</el-button>
</el-col>-->
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
@ -142,7 +172,7 @@
<el-table-column label="所属账号" align="center" prop="fanChannelName" />
<el-table-column label="导粉情况" align="center" prop="wxAccountList">
<template slot-scope="scope">
<span style="margin-right:10px">{{scope.row.wxAccountList.length}}</span>
<span style="margin-right:10px">{{getTotalImportFanNum(scope.row.wxAccountList)}}</span>
<el-popover
placement="left"
width="370"
@ -241,7 +271,12 @@
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
:layout="'total, slot, sizes, prev, pager, next, jumper'"
>
<span class="totalSpan">总导粉量{{totalImportNum}}</span>
<span class="totalSpan">总进粉量{{totalAddFanNum}}</span>
<span class="totalSpan" style="margin-right:10px">总直播时长{{totalLiveTime}}小时</span>
</pagination>
<!-- 添加或修改直播排班对话框 -->
<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
@ -487,9 +522,10 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
liveSchedulDate: nowDate,
liveSchedulDate: null,
liveRoom: null,
fanChannel: null,
liveNutritionistId: null,
wxAccountId: null
},
// 表单参数
@ -523,7 +559,21 @@ export default {
},
//记录当前添加或编辑进粉记录对应直播记录的ID
addOrEditSchedulId: null,
//直播范围查询
liveDateScope: [nowDate, nowDate],
//总导粉量
totalImportNum: null,
//总进粉量
totalAddFanNum: null,
//总直播时长
totalLiveTime: null,
liveDatePickerOptions: {
disabledDate(time) {
return time.getTime() > dayjs()
},
}
};
},
components:{
@ -556,8 +606,10 @@ export default {
/** 查询直播排班列表 */
getList() {
this.loading = true;
this.queryParams.liveStartTime = this.liveDateScope && this.liveDateScope.length > 0 ? this.liveDateScope[0] : null;
this.queryParams.liveEndTime = this.liveDateScope && this.liveDateScope.length > 0 ? this.liveDateScope[1] : null;
listLiveSchedul(this.queryParams).then(response => {
this.liveSchedulList = response.rows;
this.liveSchedulList = response.data.tableDataInfo.rows;
if(this.liveSchedulList != null && this.liveSchedulList.length > 0){
this.liveSchedulList.forEach((item,index) => {
item.status = (item.liveStatus == 0 || item.liveStatus == 2) ? false : true;
@ -566,7 +618,14 @@ export default {
item.addFanVisible = this.addOrEditSchedulId == item.id;
});
}
this.total = response.total;
//总导粉量
this.totalImportNum = response.data.totalImportNum;
//总进粉量
this.totalAddFanNum = response.data.totalAddFanNum;
//总直播时长
this.totalLiveTime = response.data.totalLiveTime;
this.total = response.data.tableDataInfo.total;
this.loading = false;
this.addOrEditSchedulId = null;
});
@ -700,6 +759,37 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
this.queryParams.liveStartTime = this.liveDateScope && this.liveDateScope.length > 0 ? this.liveDateScope[0] : null;
this.queryParams.liveEndTime = this.liveDateScope && this.liveDateScope.length > 0 ? this.liveDateScope[1] : null;
let fileName = '';
if(this.queryParams.liveStartTime != null && this.queryParams.liveEndTime != null){
if(this.queryParams.liveStartTime != this.queryParams.liveEndTime){
fileName += this.queryParams.liveStartTime + "至" + this.queryParams.liveEndTime;
}else{
fileName += this.queryParams.liveStartTime;
}
}
if(this.queryParams.liveRoom && this.queryParams.liveRoom != null){
let liveType = this.liveTypeOptions.find(
(opt) => opt.dictValue == this.queryParams.liveRoom
);
console.log(liveType);
fileName += liveType ? liveType.dictLabel : "";
}
if(this.queryParams.fanChannel && this.queryParams.fanChannel != null){
let channel = this.fanChanneloptions.find(
(opt) => opt.dictValue == this.queryParams.fanChannel
);
fileName += channel ? channel.dictLabel : "";
}
if(this.queryParams.liveNutritionistId && this.queryParams.liveNutritionistId != null){
let nutritionist = this.nutritionistIdOptions.find(
(opt) => opt.dictValue == this.queryParams.liveNutritionistId
);
fileName += nutritionist ? nutritionist.dictLabel : "";
}
fileName += "直播记录.xlsx"
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有直播排班数据项?', "警告", {
confirmButtonText: "确定",
@ -708,7 +798,7 @@ export default {
}).then(function() {
return exportLiveSchedul(queryParams);
}).then(response => {
this.download(response.msg);
this.download(response.msg, fileName);
}).catch(function() {});
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
@ -804,7 +894,26 @@ export default {
if(this.liveSchedulList != null && this.liveSchedulList.length > 0 && id != null){
return this.liveSchedulList.find((opt) => opt.id === id);
}
},
getTotalImportFanNum(list){
if(!list || list == null || list.length == 0){
return 0;
}
let num = 0;
list.forEach((item,index) => {
num += item.fanNum;
});
return num;
}
}
};
</script>
<style lang="scss" scoped>
.totalSpan{
margin-left: 10px;
color: #606266;
font-weight: normal;
font-size:13px;
}
</style>