fix bug
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+50
-15
@@ -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
|
||||
|
||||
@@ -57,4 +57,9 @@ public class TrainEduAlbum {
|
||||
@Comment("单位id")
|
||||
private String unitId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否禁用")
|
||||
private Boolean disabled;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user