diff --git a/src/main/java/io/v/nutz/mobile/trainEducation/MTrainEducationController.java b/src/main/java/io/v/nutz/mobile/trainEducation/MTrainEducationController.java index 0f87bac..2ada83c 100644 --- a/src/main/java/io/v/nutz/mobile/trainEducation/MTrainEducationController.java +++ b/src/main/java/io/v/nutz/mobile/trainEducation/MTrainEducationController.java @@ -1,5 +1,7 @@ package io.v.nutz.mobile.trainEducation; +import cn.hutool.core.date.DateUtil; +import cn.wizzer.framework.base.Result; import io.v.nutz.annontation.ViReturn; import io.v.nutz.base.service.BaseService; import io.v.nutz.trainEducation.models.TrainEduVideo; @@ -20,6 +22,8 @@ import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; import org.nutz.mvc.annotation.Param; +import java.util.Date; + @IocBean @At("/mobile/trainEducation") @Ok("json:full") @@ -70,6 +74,7 @@ public class MTrainEducationController { $condition """); Cnd cnd = Cnd.NEW(); + cnd.and("tea.disabled", "=", 0); cnd.and(new Static("tea.id = (select albumId from train_edu_video order by createdAt desc LIMIT 0,1)")); sql.setCondition(cnd); sql.setCallback(Sqls.callback.map()); @@ -103,6 +108,7 @@ public class MTrainEducationController { $condition """); Cnd cnd = Cnd.NEW(); + cnd.and("tea.disabled","=",0); cnd.andEX("tea.typeId", "=", typeId); cnd.groupBy("tea.id"); sql.setCondition(cnd); @@ -182,28 +188,40 @@ public class MTrainEducationController { @Param(value = "albumId", required = false) String albumId, @Param(value = "currentTime", required = false) long currentTime) { String userId = (String) ShiroUtil.getPrincipalProperty("id"); - TrainEduVideo video = dao.fetch(TrainEduVideo.class, Cnd.where("id", "=", videoId)); - TrainEduVideoWatchRecord thisVideoRecord = dao.fetch(TrainEduVideoWatchRecord.class, Cnd.where("userId", "=", userId).and("videoId", "=", videoId)); + TrainEduVideo video = dao.fetch(TrainEduVideo.class, videoId); +// if (video.getEveryDayMaxWatchNum() != null && video.getEveryDayMaxWatchNum() > 0) { +// //限制了每天的观看次数 +// //查询今天的观看次数 +// int count = dao.count(TrainEduVideoWatchRecord.class, Cnd.where("userId", "=", userId).and("videoId", "=", videoId).and("watchTime", "=", DateUtil.today())); +// if (count == video.getEveryDayMaxWatchNum()) { +// return Result.error("每天最多只能打卡学习" + video.getEveryDayMaxWatchNum() + "次,明天再来吧!"); +// } +// } - if(Lang.isNotEmpty(thisVideoRecord) && thisVideoRecord.getFinish()){ - //已看完的就不要更改了 - return null; + //继续判断是否有未看完的记录 + Cnd cnd = Cnd.where("userId", "=", userId).and("videoId", "=", videoId).and("finish", "=", 0); + if (video.getEveryDayMaxWatchNum() != null && video.getEveryDayMaxWatchNum() > 0) { + cnd.and("watchTime", "=", DateUtil.today()); } - if (Lang.isEmpty(thisVideoRecord)) { + TrainEduVideoWatchRecord notWatchFinishRecord = dao.fetch(TrainEduVideoWatchRecord.class, cnd); + if (Lang.isNotEmpty(notWatchFinishRecord)) { + //做更新 + notWatchFinishRecord.setFinish(video.getFileDuration() == currentTime); + notWatchFinishRecord.setWatchDuration(currentTime); + dao.update(notWatchFinishRecord, "finish|watchDuration"); + } else { + //新插入一条 TrainEduVideoWatchRecord videoWatchRecord = new TrainEduVideoWatchRecord(); videoWatchRecord.setVideoId(videoId); videoWatchRecord.setWatchDuration(currentTime); videoWatchRecord.setAlbumId(albumId); videoWatchRecord.setUserId((String) ShiroUtil.getPrincipalProperty("id")); videoWatchRecord.setFinish(video.getFileDuration() == currentTime); + videoWatchRecord.setWatchTime(new Date()); dao.insert(videoWatchRecord); - } else { - Chain updateChain = Chain.make("watchDuration", currentTime); - updateChain.add("finish", video.getFileDuration() == currentTime ? 1 : 0); - Cnd cnd = Cnd.where("userId", "=", userId).and("videoId", "=", videoId); - dao.update(TrainEduVideoWatchRecord.class, updateChain, cnd); } + return null; } diff --git a/src/main/java/io/v/nutz/trainEducation/controller/statistics/TrainEduStatisticsVideoController.java b/src/main/java/io/v/nutz/trainEducation/controller/statistics/TrainEduStatisticsVideoController.java index 4a321ee..4ad2e50 100644 --- a/src/main/java/io/v/nutz/trainEducation/controller/statistics/TrainEduStatisticsVideoController.java +++ b/src/main/java/io/v/nutz/trainEducation/controller/statistics/TrainEduStatisticsVideoController.java @@ -1,7 +1,7 @@ package io.v.nutz.trainEducation.controller.statistics; -import cn.wizzer.framework.page.Pagination; import io.v.nutz.annontation.ViReturn; +import io.v.nutz.base.page.Pagination; import io.v.nutz.base.service.BaseService; import io.v.nutz.base.utils.Vi; import io.v.nutz.modules.models.PageForm; @@ -12,11 +12,13 @@ import org.nutz.dao.Cnd; import org.nutz.dao.Dao; import org.nutz.dao.Sqls; import org.nutz.dao.sql.Sql; +import org.nutz.dao.util.cri.Static; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; import org.nutz.mvc.annotation.Param; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -44,26 +46,53 @@ public class TrainEduStatisticsVideoController { @At @ViReturn @RequiresPermissions("trainEdu.statistics.video") - public Object pageData() { + public Object pageData(String albumId, PageForm pageForm) { +// Sql sql = Sqls.create(""" +// SELECT +// tea.*, +// tet.typeName, +// ( SELECT sum( fileDuration ) FROM train_edu_video WHERE albumId = tea.id ) AS sumDuration, +// ( SELECT count( DISTINCT ( userid )) FROM train_edu_video_watch_record WHERE albumId = tea.id ) AS studyNum +// FROM +// train_edu_album tea +// LEFT JOIN train_edu_type tet ON tet.id = tea.typeId\s +// $condition +// """); +// Cnd cnd = Cnd.NEW(); +// if (!ShiroUtil.hasAnyRoles("sysadmin, A06")) { +// cnd.and("tea.createType", "=", 1).and("tea.unionId", "=", Vi.getUnionId()); +// } +// sql.setCondition(cnd); +// List list = baseService.listMap(sql); +// Pagination pagination = new Pagination(); +// pagination.setList(list); +// return pagination; + Sql sql = Sqls.create(""" SELECT - tea.*, - tet.typeName, - ( SELECT sum( fileDuration ) FROM train_edu_video WHERE albumId = tea.id ) AS sumDuration, - ( SELECT count( DISTINCT ( userid )) FROM train_edu_video_watch_record WHERE albumId = tea.id ) AS studyNum + u.username, + u.loginname, + u.unitname, + u.unionname, + ( + SELECT + SUM(IF( cnt > 2, 2, cnt )) AS count + FROM + ( SELECT watchTime, COUNT( 1 ) AS cnt FROM train_edu_video_watch_record where userId = tevwr.userId and albumId = tevwr.albumId GROUP BY watchTime ) AS subquery + ) as watchCount + FROM - train_edu_album tea - LEFT JOIN train_edu_type tet ON tet.id = tea.typeId\s + `train_edu_video_watch_record` tevwr + LEFT JOIN train_edu_album tea on tea.id = tevwr.albumId + LEFT JOIN `user` u ON u.id = tevwr.userId $condition """); Cnd cnd = Cnd.NEW(); - if(!ShiroUtil.hasAnyRoles("sysadmin, A06")) { - cnd.and("tea.createType", "=", 1).and("tea.unionId", "=", Vi.getUnionId()); - } + cnd.and("tevwr.albumId", "=", albumId); + cnd.and(new Static("IF(tea.createType = 1, u.unionId = tea.unionId , 1=1)")); + cnd.groupBy("tevwr.userId"); sql.setCondition(cnd); - List list = baseService.listMap(sql); - Pagination pagination = new Pagination(); - pagination.setList(list); + Pagination pagination = baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); return pagination; } @@ -86,7 +115,13 @@ public class TrainEduStatisticsVideoController { u.loginname, u.unitname, u.unionname, - sum( tevwr.watchDuration ) AS studyDuration + ( + SELECT + SUM(IF( cnt > 2, 2, cnt )) AS count + FROM + ( SELECT watchTime, COUNT( 1 ) AS cnt FROM train_edu_video_watch_record where userId = tevwr.userId and albumId = tevwr.albumId GROUP BY watchTime ) AS subquery + ) as watchCount + FROM `train_edu_video_watch_record` tevwr LEFT JOIN train_edu_album tea on tea.id = tevwr.albumId diff --git a/src/main/java/io/v/nutz/trainEducation/models/TrainEduAlbum.java b/src/main/java/io/v/nutz/trainEducation/models/TrainEduAlbum.java index 6082670..52a285c 100644 --- a/src/main/java/io/v/nutz/trainEducation/models/TrainEduAlbum.java +++ b/src/main/java/io/v/nutz/trainEducation/models/TrainEduAlbum.java @@ -57,4 +57,9 @@ public class TrainEduAlbum { @Comment("单位id") private String unitId; + @Column + @ColDefine(type = ColType.BOOLEAN) + @Comment("是否禁用") + private Boolean disabled; + } diff --git a/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideo.java b/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideo.java index c3c8a94..4dfeab7 100644 --- a/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideo.java +++ b/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideo.java @@ -9,6 +9,7 @@ import org.nutz.dao.interceptor.annotation.PrevInsert; @EqualsAndHashCode(callSuper = true) @Table @Data +@Comment("教育培训视频") public class TrainEduVideo extends BaseModel { @Name @@ -43,12 +44,12 @@ public class TrainEduVideo extends BaseModel { @Column @ColDefine(type = ColType.INT) @Comment("排序编号") - private int sortNo; + private Integer sortNo; @Column @Comment("是否禁用") @ColDefine(type = ColType.BOOLEAN) - private boolean disabled; + private Boolean disabled; @Column @Comment("视频大小") @@ -59,4 +60,9 @@ public class TrainEduVideo extends BaseModel { @Comment("视频时常") private Long fileDuration; + @Column + @Comment("每天最多观看次数") + @ColDefine(type = ColType.INT) + private Integer everyDayMaxWatchNum; + } diff --git a/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideoWatchRecord.java b/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideoWatchRecord.java index 93edb39..d62e8b6 100644 --- a/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideoWatchRecord.java +++ b/src/main/java/io/v/nutz/trainEducation/models/TrainEduVideoWatchRecord.java @@ -1,14 +1,25 @@ package io.v.nutz.trainEducation.models; +import io.v.nutz.base.model.BaseModel; import lombok.Data; +import lombok.EqualsAndHashCode; import org.nutz.dao.entity.annotation.*; +import org.nutz.dao.interceptor.annotation.PrevInsert; + +import java.util.Date; /** * 视频播放记录 */ +@EqualsAndHashCode(callSuper = true) @Table @Data -public class TrainEduVideoWatchRecord { +@Comment("教育培训学习记录") +public class TrainEduVideoWatchRecord extends BaseModel { + + @Name + @PrevInsert(uu32 = true) + private String id; @Column @ColDefine(type = ColType.VARCHAR, width = 32) @@ -34,4 +45,9 @@ public class TrainEduVideoWatchRecord { @Comment("是否看完") private Boolean finish; + @Column + @ColDefine(type = ColType.DATE) + @Comment("观看日期") + private Date watchTime; + } diff --git a/src/main/resources/views/mobile/trainEducation/videoPage.html b/src/main/resources/views/mobile/trainEducation/videoPage.html index 3f78067..7d8427b 100644 --- a/src/main/resources/views/mobile/trainEducation/videoPage.html +++ b/src/main/resources/views/mobile/trainEducation/videoPage.html @@ -75,6 +75,10 @@ layout("/mobile/platform.html"){ word-break: break-all; } + .myWatchRecord{ + font-size: 14px; + } + @@ -135,7 +139,7 @@ layout("/mobile/platform.html"){ - {{getWatchStatus(o)}} + @@ -143,10 +147,45 @@ layout("/mobile/platform.html"){ + + + + + + 视频 + + {{i+1}}. + + + {{o.title}} + + + + + 本视频在活动结束时每天最多只会统计 + {{o.everyDayMaxWatchNum}} + 次完整观看记录,您可以无限制的观看。 + + + + + {{moment(k).format('YYYY年MM月DD日')}} + + + 观看次数 + {{v.length}} + + + + + + + + - - 结束本次学习 + + 上传学习记录 @@ -176,6 +215,9 @@ layout("/mobile/platform.html"){ } }, + + computed: {}, + methods: { async getVideoInfo() { const {data} = await $.get('/mobile/trainEducation/getVideoList', {albumId: this.albumId}) @@ -197,7 +239,6 @@ layout("/mobile/platform.html"){ return } - this.currentVideo = o const playVideo_ = (time = 0) => { @@ -223,9 +264,10 @@ layout("/mobile/platform.html"){ const v = this.watchRecordList.find(v => v.videoId === o.id) if (v && v.finish) { - this.$modal.confirm('本视频您已学习完成,是否重新观看,不会影响到完成的学习记录').then(() => { - playVideo_(0) - }) + playVideo_(0) + // this.$modal.confirm('本视频您已学习完成,是否重新观看,不会影响到完成的学习记录').then(() => { + // playVideo_(0) + // }) } else if (v && !v.finish) { playVideo_(v.watchDuration) } else { @@ -235,10 +277,10 @@ layout("/mobile/platform.html"){ playEnd() { this.player.on('ended', async () => { - const v = this.watchRecordList.find(v => v.videoId === this.currentVideo.id) - if (v.finish) { - return - } + // const v = this.watchRecordList.find(v => v.videoId === this.currentVideo.id) + // if (v.finish) { + // return + // } const loading = this.$toast.loading({ duration: 0, @@ -253,14 +295,6 @@ layout("/mobile/platform.html"){ setTimeout(() => { loading.clear() }, 2000) - - // this.addWatchRecord() - // this.getMyWatchRecord() - // const currentIndex = this.videoList.findIndex(v => v.id === this.currentVideo.id) - // const nextVideo = this.videoList[currentIndex + 1] - // if (nextVideo) { - // this.playVideo(nextVideo) - // } }) }, @@ -272,19 +306,23 @@ layout("/mobile/platform.html"){ albumId: this.currentVideo.albumId } const resp = await $.post('/mobile/trainEducation/addWatchRecord', params) - this.getMyWatchRecord() - return resp + if (resp.code === 0) { + this.getMyWatchRecord() + return resp + } else { + this.$modal.msgError(resp.msg) + } }, //监听页面关闭 隐藏 - watchPage() { - document.addEventListener('visibilitychange', () => { - if (document.visibilityState === 'hidden') { - if (this.player && this.currentVideo) { - this.addWatchRecord() - } - } - }) - }, + // watchPage() { + // document.addEventListener('visibilitychange', () => { + // if (document.visibilityState === 'hidden') { + // if (this.player && this.currentVideo) { + // this.addWatchRecord() + // } + // } + // }) + // }, async getMyWatchRecord() { const {data} = await $.get('/mobile/trainEducation/getMyWatchRecord') this.watchRecordList = data @@ -310,10 +348,10 @@ layout("/mobile/platform.html"){ endLearn() { const v = this.watchRecordList.find(v => v.videoId === this.currentVideo.id) console.log(v) - if (v && v.finish) { - this.$modal.msg('本视频您已学习完成,无需重复上传') - return - } + // if (v && v.finish) { + // this.$modal.msg('本视频您已学习完成,无需重复上传') + // return + // } this.$modal.confirm('您是否要结束本视频学习?').then(() => { //暂停 @@ -336,7 +374,7 @@ layout("/mobile/platform.html"){ }, created() { - this.watchPage() + // this.watchPage() const id = this.GetQueryString("id") if (id) { this.albumId = id diff --git a/src/main/resources/views/platform/trainEdu/album.html b/src/main/resources/views/platform/trainEdu/album.html index ef54013..541a924 100644 --- a/src/main/resources/views/platform/trainEdu/album.html +++ b/src/main/resources/views/platform/trainEdu/album.html @@ -113,12 +113,16 @@ layout("/layouts/platform.html"){ 分工会 校工会 + + 否 + 是 + - 查看 - 编辑 - 删除 + 查看 + 编辑 + 删除 @@ -128,7 +132,7 @@ layout("/layouts/platform.html"){ + > @@ -165,6 +169,17 @@ layout("/layouts/platform.html"){ + + + + + + 确定 取消 @@ -231,6 +246,7 @@ layout("/layouts/platform.html"){ {prop: 'videoCount', label: '视频数量'}, {prop: 'typeName', label: '专辑类型'}, {prop: 'createType', label: '创建类型'}, + {prop: 'disabled', label: '是否开启'} ], rules: { title: [{required: true, message: '请输入标题', trigger: ['change', 'blur']}], diff --git a/src/main/resources/views/platform/trainEdu/statistics/video.html b/src/main/resources/views/platform/trainEdu/statistics/video.html index 2495131..6bbd49a 100644 --- a/src/main/resources/views/platform/trainEdu/statistics/video.html +++ b/src/main/resources/views/platform/trainEdu/statistics/video.html @@ -5,6 +5,33 @@ layout("/layouts/platform.html"){ + + + + + + + + + + + + + + + + + + 搜索 + + + @@ -23,68 +50,75 @@ layout("/layouts/platform.html"){ {{(row.sumDuration / 60 / 60).toFixed(2) + 'h'}} - - - 查看具体学习情况 - - + + + + + + - - - - - {{ scope.$index + (viewPageForm.pageNumber - 1) * viewPageForm.pageSize + 1 }} - - - - - {{(row.studyDuration / 60 / 60).toFixed(2) + 'h'}} - - - + + + + + + + + + + + + + + + + + + + + + - - {viewPageForm.pageNumber=val;viewPageData()}" - :current-page="viewPageForm.pageNumber" - :page-size="viewPageForm.pageSize" - layout="total, sizes, prev, pager, next" - :total="viewPageForm.totalCount"> - - + + + + + + + + + - + \ No newline at end of file +#--> diff --git a/src/main/resources/views/platform/trainEdu/video.html b/src/main/resources/views/platform/trainEdu/video.html index 22854c6..4a202f1 100644 --- a/src/main/resources/views/platform/trainEdu/video.html +++ b/src/main/resources/views/platform/trainEdu/video.html @@ -101,7 +101,7 @@ layout("/layouts/platform.html"){ - + @@ -136,6 +136,10 @@ layout("/layouts/platform.html"){ + + + +