提交
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package io.v.nutz.meeting.controller.mobile;
|
||||
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.result.Result;
|
||||
import io.v.nutz.meeting.service.MeetingAuditService;
|
||||
import io.v.nutz.modules.models.Audit;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.nutz.dao.Dao;
|
||||
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 javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 会议手机端审核
|
||||
*/
|
||||
@IocBean
|
||||
@Slf4j
|
||||
@At("/mobile/meeting/audit")
|
||||
public class MMeetingAuditController {
|
||||
|
||||
@Inject
|
||||
private MeetingAuditService meetingAuditService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
/**
|
||||
* 跳转审核页面
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@At("")
|
||||
@Ok("beetl:/mobile/meeting/audit.html")
|
||||
@RequiresAuthentication
|
||||
public void index(HttpServletRequest request) {
|
||||
|
||||
}
|
||||
|
||||
@At("/pageData")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object pageData(PageForm pageForm,
|
||||
@Param(value = "typeId", required = false) String typeId,
|
||||
@Param(value = "meetingTime", required = false) Integer meetingTime) {
|
||||
|
||||
return meetingAuditService.myMeetingPageData(pageForm.getPageNumber(), pageForm.getPageSize(), pageForm.getSearchKeyword(), typeId, meetingTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会议提交了请假的人员
|
||||
* 这里需要根据当前登录用户去过滤他能审核的 are you ok?
|
||||
*/
|
||||
@At("/getLeaveUser")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object getLeaveUser(@Param(value = "meetingId", required = false) String meetingId,
|
||||
@Param(value = "moduleName", required = false) String moduleName,
|
||||
@Param(value = "auditType", required = false) String auditType) {
|
||||
if (StringUtils.isBlank(meetingId)) {
|
||||
log.error("getUserByLoginUser()参数为空");
|
||||
return Result.error("参数为空");
|
||||
}
|
||||
return meetingAuditService.getLeaveUser(meetingId, moduleName, auditType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会议审核
|
||||
*
|
||||
* @param tpuIds 审核记录Ids
|
||||
* @param audit 审核
|
||||
* @param isPass 是否通过
|
||||
* @return
|
||||
*/
|
||||
@At("/audit")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object audit(@Param("tpuIds") String[] tpuIds, Audit audit,
|
||||
@Param("isPass") boolean isPass) {
|
||||
meetingAuditService.audit(tpuIds, audit, isPass);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
package io.v.nutz.meeting.controller.mobile;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriodUser;
|
||||
import io.v.nutz.meeting.service.MeetingMineService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.mvc.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 会议手机端签到
|
||||
*/
|
||||
@IocBean
|
||||
@At("/mobile/meeting/mine")
|
||||
public class MMeetingMineController {
|
||||
|
||||
@Inject
|
||||
private MeetingMineService meetingMineService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
/**
|
||||
* 跳转签到页面
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
@At("/go_sign")
|
||||
@RequiresAuthentication
|
||||
@Ok("beetl:/mobile/meeting/sign_in.html")
|
||||
public void goSign(HttpServletRequest request) {
|
||||
}
|
||||
|
||||
@At("/myMeeting")
|
||||
@RequiresAuthentication
|
||||
@Ok("beetl:/mobile/meeting/myMeeting.html")
|
||||
public void myMeeting(HttpServletRequest request) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的会议
|
||||
*
|
||||
* @param pageForm 分页
|
||||
* @param tabNameIndex tab页下标
|
||||
* @return
|
||||
*/
|
||||
@At("/pageData")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object pageData(PageForm pageForm,
|
||||
@Param(value = "tabNameIndex", required = false) Integer tabNameIndex,
|
||||
@Param(value = "typeId", required = false) String typeId,
|
||||
@Param(value = "meetingTime", required = false) Integer meetingTime) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (StrUtil.isNotBlank(typeId)) {
|
||||
cnd.andEX("info.typeId", "=", typeId);
|
||||
}
|
||||
if (meetingTime != null) {
|
||||
if (meetingTime == 0) {
|
||||
cnd.andEX("info.startTime", ">=", DateUtil.getDateTime());
|
||||
} else {
|
||||
cnd.andEX("info.startTime", "<", DateUtil.getDateTime());
|
||||
}
|
||||
}
|
||||
switch (tabNameIndex) {
|
||||
case 1 -> cnd.and("mu.isJoin", "is", null);
|
||||
case 2 -> cnd.and("mu.isJoin", "=", 0);
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
|
||||
return meetingMineService.myMeetingPageData(pageForm, cnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的会议时间段信息
|
||||
*
|
||||
* @param meetingId
|
||||
* @return
|
||||
*/
|
||||
@At("/findMyMeetPeriod")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object findMyMeetPeriod(@Param("meetingId") String meetingId) {
|
||||
if (StrUtil.isBlank(meetingId)) {
|
||||
return Result.error("参数错误");
|
||||
}
|
||||
return meetingMineService.findMyMeetPeriod(meetingId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请假
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@At("/askForLeave")
|
||||
@POST
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object askForLeave(@Param("data") String meetingTimePeriodUsers) {
|
||||
//先清空,因为可能会涉及到修改
|
||||
/*org.nutz.dao.Chain clearChain = Chain.make("isJoin", null);
|
||||
clearChain.add("stateCode", null);
|
||||
clearChain.add("leaveReason", "");
|
||||
clearChain.add("auditIdList", null);
|
||||
Cnd clearCnd = Cnd.where("meetingId", "=", meetingId)
|
||||
.and("userId", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
dao.update(MeetingTimePeriodUser.class, clearChain, clearCnd);*/
|
||||
|
||||
List<MeetingTimePeriodUser> meetingTimePeriod = Json.fromJsonAsList(MeetingTimePeriodUser.class, meetingTimePeriodUsers);
|
||||
if (Lang.isEmpty(meetingTimePeriod)) {
|
||||
return null;
|
||||
}
|
||||
meetingMineService.askForLeave(meetingTimePeriod);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认参加会议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@At("/confirmMeeting")
|
||||
@POST
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object confirmMeeting(@Param("tpuIds") List<String> tpuIds) {
|
||||
meetingMineService.confirmMeeting(tpuIds);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param meetingId 会议id
|
||||
* @param mtpId 时间段id
|
||||
* @return
|
||||
*/
|
||||
@At("/getMeetingInfo")
|
||||
@GET
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object getMeetingInfo(@Param("meetingId") String meetingId, @Param("mtpId") String mtpId) {
|
||||
MeetingInfo meetingInfo = dao.fetch(MeetingInfo.class, meetingId);
|
||||
dao.fetchLinks(meetingInfo, "meetingTimePeriods", Cnd.NEW().asc("startTime"));
|
||||
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("meetingTimePeriodId", "=", mtpId);
|
||||
cnd.and("userId", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
MeetingTimePeriodUser mtPu = dao.fetch(MeetingTimePeriodUser.class, cnd);
|
||||
|
||||
if (Lang.isEmpty(meetingInfo)) {
|
||||
return Result.error("参数错误");
|
||||
}
|
||||
if (Lang.isEmpty(mtPu)) {
|
||||
return Result.error("你不是当前会议人员");
|
||||
}
|
||||
|
||||
return Map.of("meetingInfo", meetingInfo, "signInfo", mtPu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 签到
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@At("/signIn")
|
||||
@POST
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object signIn(@Param("mtpId") String mtpId) {
|
||||
if (StrUtil.isBlank(mtpId)) {
|
||||
return Result.error("参数错误");
|
||||
}
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("meetingTimePeriodId", "=", mtpId);
|
||||
cnd.and("userId", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
MeetingTimePeriodUser mtpu = dao.fetch(MeetingTimePeriodUser.class, cnd);
|
||||
if (Lang.isEmpty(mtpu)) {
|
||||
return Result.error("参数错误");
|
||||
}
|
||||
if (Lang.isNotEmpty(mtpu.getIsJoin()) && !mtpu.getIsJoin()) {
|
||||
return Result.error("您已请假,不能签到喔");
|
||||
}
|
||||
if (Lang.isNotEmpty(mtpu.getIsSignIn()) && mtpu.getIsSignIn()) {
|
||||
return Result.error("您已签到,不要重复签到喔");
|
||||
}
|
||||
meetingMineService.signIn(mtpu);
|
||||
return Result.success().addMsg("签到成功");
|
||||
}
|
||||
|
||||
@At
|
||||
@POST
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object cancelLeave(String id) {
|
||||
dao.update(MeetingTimePeriodUser.class, Chain.make("isJoin", null).add("leaveReason", null).add("stateCode", null)
|
||||
, Cnd.where("id", "=", id));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package io.v.nutz.meeting.controller.pc;
|
||||
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingUser;
|
||||
import io.v.nutz.meeting.service.MeetingManageService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.msgNotify.models.MsgNotify;
|
||||
import io.v.nutz.msgNotify.service.MsgNotifyService;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/meeting/manage")
|
||||
public class MeetingManageController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@Inject
|
||||
private MeetingManageService meetingManageService;
|
||||
|
||||
@Inject
|
||||
private MsgNotifyService msgNotifyService;
|
||||
|
||||
@At("/createMeeting")
|
||||
@Ok("beetl:/platform/meeting/manage/add.html")
|
||||
@RequiresPermissions("meeting.manage.add")
|
||||
public void createMeeting(HttpServletRequest request) {
|
||||
|
||||
}
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/meeting/index.html")
|
||||
@RequiresPermissions("meeting.manage.search")
|
||||
public void index(HttpServletRequest request) {
|
||||
|
||||
}
|
||||
|
||||
@At("/pageData")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.manage.search")
|
||||
public Object pageData(PageForm pageForm,
|
||||
@Param(value = "year", required = false) Integer year,
|
||||
@Param(value = "typeId", required = false) String typeId) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("YEAR(info.startTime)", "=", year);
|
||||
cnd.andEX("info.typeId", "=", typeId);
|
||||
return meetingManageService.pageData(pageForm, cnd);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加会议
|
||||
*
|
||||
* @param meetingInfo 会议信息
|
||||
* @return
|
||||
*/
|
||||
@At("/doAdd")
|
||||
@POST
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.manage.add")
|
||||
public Object doAdd(@Param("meetingInfo") MeetingInfo meetingInfo,
|
||||
@Param("msgNotify") MsgNotify msgNotify, String[] users) {
|
||||
|
||||
|
||||
NutMap nutMap = msgNotifyService.addMsgNotify(msgNotify, users);
|
||||
meetingInfo.setNotifyId(nutMap.getString("id"));
|
||||
List<String> userIdList = nutMap.getList("userIdList", String.class);
|
||||
List<MeetingUser> meetingUserList = new ArrayList<>();
|
||||
for (String id : userIdList) {
|
||||
MeetingUser meetingUser = new MeetingUser();
|
||||
meetingUser.setUserId(id);
|
||||
meetingUserList.add(meetingUser);
|
||||
}
|
||||
meetingInfo.setMeetingUserList(meetingUserList);
|
||||
|
||||
meetingManageService.doAdd(meetingInfo);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑会议
|
||||
*
|
||||
* @param meetingInfo 会议信息
|
||||
* @return
|
||||
*/
|
||||
@At("/doEdit")
|
||||
@POST
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.manage.add")
|
||||
public Object doEdit(@Param("meetingInfo") MeetingInfo meetingInfo,
|
||||
@Param("msgNotify") MsgNotify msgNotify, String[] users) {
|
||||
|
||||
NutMap msgMap = msgNotifyService.editMsgNotify(msgNotify, users);
|
||||
List<String> userIdList = msgMap.getList("userIdList", String.class);
|
||||
|
||||
// Cnd muCnd = Cnd.where("meetingId", "=", meetingInfo.getId());
|
||||
// List<MeetingUser> muList = dao.query(MeetingUser.class, muCnd);
|
||||
//
|
||||
// List<MeetingUser> meetingUserList = new ArrayList<>();
|
||||
// for (String userId : userIdList) {
|
||||
// MeetingUser insertMu = new MeetingUser();
|
||||
// Optional<MeetingUser> optionalMeetingUser = muList.stream().filter(v -> v.getUserId().equals(userId)).findFirst();
|
||||
// MeetingUser mu = optionalMeetingUser.orElse(null);
|
||||
// if (Lang.isNotEmpty(mu)) {
|
||||
// insertMu.setId(mu.getId());
|
||||
// }
|
||||
// insertMu.setMeetingId(meetingInfo.getId());
|
||||
// insertMu.setUserId(userId);
|
||||
// meetingUserList.add(insertMu);
|
||||
// }
|
||||
// meetingInfo.setMeetingUserList(meetingUserList);
|
||||
meetingManageService.doEdit(meetingInfo, userIdList);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions(value = {"meeting.manage.search", "meeting.manage.add"}, logical = Logical.OR)
|
||||
public Object findOne(String id) {
|
||||
return dao.fetchLinks(dao.fetch(MeetingInfo.class, id), "^meetingTimePeriods$", Cnd.NEW().asc("startTime"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会议
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.manage.search")
|
||||
public Object doDelete(String id) {
|
||||
meetingManageService.doDelete(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package io.v.nutz.meeting.controller.pc;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriod;
|
||||
import io.v.nutz.meeting.service.MeetingOnlineService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.util.ViTool;
|
||||
import io.v.nutz.web.commons.base.Globals;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/meeting/online")
|
||||
public class MeetingOnlineController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@Inject
|
||||
private MeetingOnlineService meetingOnlineService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/meeting/online.html")
|
||||
@RequiresPermissions("meeting.online")
|
||||
public void index(HttpServletRequest request) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param pageForm
|
||||
* @param year
|
||||
* @param typeId
|
||||
* @return
|
||||
*/
|
||||
@At("/pageData")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.online")
|
||||
public Object pageData(PageForm pageForm,
|
||||
@Param(value = "year", required = false) Integer year,
|
||||
@Param(value = "typeId", required = false) String typeId) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("YEAR(info.startTime)", "=", year);
|
||||
cnd.andEX("info.typeId", "=", typeId);
|
||||
return meetingOnlineService.pageData(pageForm, cnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出签字表
|
||||
*
|
||||
* @param timePeriodId
|
||||
* @param response
|
||||
*/
|
||||
@At("/exportSignature/?")
|
||||
@Ok("void")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public void exportSignature(@Param(value = "timePeriodId", required = false) String timePeriodId, HttpServletResponse response) {
|
||||
MeetingTimePeriod timePeriod = dao.fetch(MeetingTimePeriod.class, timePeriodId);
|
||||
MeetingInfo meetingInfo = dao.fetch(MeetingInfo.class, timePeriod.getMeetingId());
|
||||
String fileName = meetingInfo.getMeetingName() + "(" + timePeriod.getTimePeriodName() + ")签字表";
|
||||
|
||||
List<ExcelExportEntity> entityArrayList = new ArrayList<>();
|
||||
entityArrayList.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
entityArrayList.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
entityArrayList.add(new ExcelExportEntity("单位", "unitname", 20));
|
||||
entityArrayList.add(new ExcelExportEntity("分工会", "unionname", 20));
|
||||
entityArrayList.add(new ExcelExportEntity("角色", "roleName", 20));
|
||||
entityArrayList.add(new ExcelExportEntity("签字", "", 20));
|
||||
try {
|
||||
ViTool.excelResponse(response, fileName + ".xlsx");
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setTitle(timePeriod.getTimePeriodName() + "签字表");
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityArrayList, meetingOnlineService.exportSignature(timePeriodId));
|
||||
workbook.write(response.getOutputStream());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/generateQrCodeUrl")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object generateQrCodeUrl(@Param(value = "tpId", required = false) String tpId,
|
||||
@Param(value = "meetingId", required = false) String meetingId,
|
||||
HttpServletRequest request) {
|
||||
StringBuffer redirect = new StringBuffer();
|
||||
redirect.append(Globals.AppDomain);
|
||||
|
||||
redirect.append("/mobile/meeting/mine/go_sign?");
|
||||
redirect.append("mtpId=").append(tpId);
|
||||
redirect.append("&");
|
||||
redirect.append("meetingId=").append(meetingId);
|
||||
return redirect.toString();
|
||||
}
|
||||
|
||||
@At("/getRealTimeData/?")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.online")
|
||||
public Object getRealTimeData(String timePeriodId) {
|
||||
List<NutMap> signInUser = meetingOnlineService.getSignInUser(timePeriodId);
|
||||
List<Map<String, Object>> countData = meetingOnlineService.getRealTimeData(timePeriodId);
|
||||
return Map.of("countData", countData, "userData", signInUser);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package io.v.nutz.meeting.controller.pc;
|
||||
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.meeting.service.MeetingTypeService;
|
||||
import io.v.nutz.modules.models.AuditState;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
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.Daos;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/meeting/basic/type")
|
||||
public class MeetingTypeController {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@Inject
|
||||
private MeetingTypeService meetingTypeService;
|
||||
|
||||
@Inject
|
||||
private MeetingCommonService meetingCommonService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/meeting/basic/type.html")
|
||||
@RequiresPermissions("meeting.basic.type")
|
||||
public void index(HttpServletRequest request) {
|
||||
|
||||
}
|
||||
|
||||
@At("/findAll")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresAuthentication
|
||||
public Object findAll() {
|
||||
List<MeetingType> meetingTypeList = dao.query(MeetingType.class, Cnd.NEW().asc("sortNum"));
|
||||
dao.fetchLinks(meetingTypeList, "^auditStateList$");
|
||||
for (MeetingType meetingType : meetingTypeList) {
|
||||
meetingType.setAuditStateList(dao.query(AuditState.class, Cnd.where("meetingTypeId", "=", meetingType.getId()).and("module", "=", meetingType.getModuleName())));
|
||||
List<AuditState> auditStateList = meetingType.getAuditStateList();
|
||||
dao.fetchLinks(auditStateList, "^auditStateUserList$");
|
||||
}
|
||||
return meetingTypeList;
|
||||
}
|
||||
|
||||
@At("/doHandle")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.basic.type")
|
||||
public Object doHandle(@Param("data") String data) {
|
||||
MeetingType meetingType = Json.fromJson(MeetingType.class, data);
|
||||
|
||||
if (null == meetingType.getId()) {
|
||||
int typeCount = dao.count(MeetingType.class, Cnd.where("moduleName", "=", meetingType.getModuleName()));
|
||||
int count = dao.count(AuditState.class, Cnd.where("module", "=", meetingType.getModuleName()));
|
||||
if (typeCount > 0 || count > 0) {
|
||||
return Result.error("模块名称已存在,换一个试试");
|
||||
}
|
||||
meetingTypeService.add(meetingType);
|
||||
} else {
|
||||
meetingTypeService.edit(meetingType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.basic.type")
|
||||
public Object delete(Integer id) {
|
||||
MeetingType meetingType = dao.fetch(MeetingType.class, id);
|
||||
dao.clear(AuditState.class, Cnd.where("module", "=", meetingType.getModuleName()));
|
||||
dao.clear(MeetingType.class, Cnd.where("id", "=", id));
|
||||
return null;
|
||||
}
|
||||
|
||||
@At("/findUserList")
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.basic.type")
|
||||
public Object findUserList(@Param("keyWords") String[] keyWords) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
id,
|
||||
username,
|
||||
loginname,
|
||||
mobile,
|
||||
sex,
|
||||
unitname,
|
||||
unionname,
|
||||
unionid,
|
||||
unitid
|
||||
FROM
|
||||
`user`
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
for (String keyWord : keyWords) {
|
||||
seg.andLike("loginname", keyWord);
|
||||
seg.orLike("username", keyWord);
|
||||
}
|
||||
cnd.and(seg);
|
||||
sql.setCondition(cnd);
|
||||
return Daos.query(dao, sql.toString(), Sqls.callback.maps());
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.basic.type")
|
||||
public Object findMaxStateId() {
|
||||
return meetingTypeService.findMaxStateId();
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.basic.type")
|
||||
public Object checkStateId(@Param("stateId") Integer stateId, @Param("stateIndex") Integer stateIndex) {
|
||||
if (stateId == null) {
|
||||
return Result.error("参数错误");
|
||||
}
|
||||
int count = dao.count(AuditState.class, Cnd.where("stateId", "=", stateId));
|
||||
if (count == 0) {
|
||||
return Result.success().addData(stateId);
|
||||
} else {
|
||||
return Result.success(meetingTypeService.findMaxStateId() + 10 * stateIndex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package io.v.nutz.meeting.controller.pc.statistics;
|
||||
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.afterturn.easypoi.excel.export.ExcelExportService;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.meeting.service.MeetingBasicStatisticsService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.util.ViTool;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
@At("/meeting/statistics/basic")
|
||||
public class MeetingBasicStatisticsController {
|
||||
|
||||
@Inject
|
||||
private MeetingBasicStatisticsService meetingBasicStatisticsService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/meeting/statistics/basic.html")
|
||||
@RequiresPermissions("meeting.statistics.basic")
|
||||
public void index(HttpServletRequest request) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据会议id查询会议时间段及对应人数
|
||||
*
|
||||
* @param pageForm
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.statistics.basic")
|
||||
public Object pageData(PageForm pageForm,
|
||||
@Param(value = "meetingId", required = false) String meetingId,
|
||||
@Param(value = "meetingTime", required = false) String[] meetingTime,
|
||||
@Param(value = "typeId", required = false) String typeId) {
|
||||
return meetingBasicStatisticsService.pageData(pageForm, meetingId, meetingTime, typeId);
|
||||
}
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.statistics.basic")
|
||||
public Object getMeetingList(String[] meetingTime) {
|
||||
return meetingBasicStatisticsService.getMeetingList(meetingTime);
|
||||
}
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("meeting.statistics.basic")
|
||||
public Object getUserData(PageForm pageForm,
|
||||
@Param(value = "id", required = false) String id,
|
||||
@Param(value = "meetingId", required = false) String meetingId,
|
||||
@Param(value = "type", required = false) String type,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "unionId", required = false) String unionId) {
|
||||
return meetingBasicStatisticsService.getUserData(pageForm, id, meetingId, type, unitId, unionId);
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresAuthentication
|
||||
public void exportUser(@Param(value = "id", required = false) String id,
|
||||
@Param(value = "meetingId", required = false) String meetingId,
|
||||
HttpServletResponse response) {
|
||||
List<ExcelExportEntity> entityList = new ArrayList<>();
|
||||
entityList.add(new ExcelExportEntity("姓名", "userName", 20));
|
||||
entityList.add(new ExcelExportEntity("工号", "loginName", 20));
|
||||
entityList.add(new ExcelExportEntity("单位", "unitName", 30));
|
||||
entityList.add(new ExcelExportEntity("分工会", "unionName", 35));
|
||||
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
|
||||
MeetingInfo meetingInfo = dao.fetch(MeetingInfo.class, meetingId);
|
||||
MeetingType meetingType = dao.fetch(MeetingType.class, meetingInfo.getTypeId());
|
||||
String[] arr = null;
|
||||
if(List.of("teacherMeeting","gdh").contains(meetingType.getModuleName())) {
|
||||
arr = new String[]{"应到人数", "实到人数", "正式代表", "列席代表", "请假人数", "未到人数"};
|
||||
} else {
|
||||
arr = new String[]{"应到人数", "实到人数", "请假人数", "未到人数"};
|
||||
}
|
||||
for (String a : arr) {
|
||||
List<NutMap> userData = meetingBasicStatisticsService.getUserData(id, meetingId, a);
|
||||
ExcelExportService service = new ExcelExportService();
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setTitle(a);
|
||||
exportParams.setSheetName(a);
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
service.createSheetForMap(workbook, exportParams, entityList, userData);
|
||||
}
|
||||
try {
|
||||
ViTool.excelResponse(response, "人员列表.xlsx");
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import io.v.nutz.annontation.SelectEnum;
|
||||
|
||||
@SelectEnum
|
||||
public enum CustomAuditTypeEnum {
|
||||
|
||||
CLUB("CLUB", "审核本协会"),
|
||||
DW("DW", "审核本单位"),
|
||||
FGH("FGH", "审核本分工会"),
|
||||
TZ("TZ", "审核本代表团");
|
||||
|
||||
public String value;
|
||||
public String desc;
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
private CustomAuditTypeEnum(String value, String desc) {
|
||||
this.value = value;
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import io.v.nutz.annontation.SelectEnum;
|
||||
import io.v.nutz.base.utils.Roles;
|
||||
import io.v.nutz.base.utils.Vi;
|
||||
import io.v.nutz.sys.models.Sys_club_user;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.sys.models.Sys_user_role;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import io.v.nutz.util.ViResource;
|
||||
import lombok.Getter;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author JyuHsin
|
||||
* @Date 2023/3/30
|
||||
* @Description
|
||||
*/
|
||||
@Getter
|
||||
@SelectEnum
|
||||
public enum CustomAuditTypeHandle {
|
||||
|
||||
|
||||
DW(CustomAuditTypeEnum.DW.getValue()) {
|
||||
@Override
|
||||
public SqlExpressionGroup next(SqlExpressionGroup sqlExpressionGroup) {
|
||||
Sys_user user = dao.fetch(Sys_user.class, Cnd.where("id", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
sqlExpressionGroup.or("u.unitid", "in", user.getUnitid());
|
||||
return sqlExpressionGroup;
|
||||
}
|
||||
},
|
||||
FGH(CustomAuditTypeEnum.FGH.getValue()) {
|
||||
@Override
|
||||
public SqlExpressionGroup next(SqlExpressionGroup sqlExpressionGroup) {
|
||||
//查询当前登录用户管理的工会
|
||||
List<Sys_user_role> userRoles = dao.query(Sys_user_role.class, Cnd.where("userid", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
.and("roleid", "in", Lang.array(Roles.UNION_MANGER)));
|
||||
List<String> unionIds = userRoles.stream().map(Sys_user_role::getUnionid).collect(Collectors.toList());
|
||||
sqlExpressionGroup.or("u.unionid", "in", unionIds);
|
||||
return sqlExpressionGroup;
|
||||
}
|
||||
},
|
||||
CLUB(CustomAuditTypeEnum.CLUB.getValue()) {
|
||||
@Override
|
||||
public SqlExpressionGroup next(SqlExpressionGroup sqlExpressionGroup) {
|
||||
//查询当前登录用户管理的协会
|
||||
List<Sys_user_role> userRoles = dao.query(Sys_user_role.class, Cnd.where("userid", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
.and("roleid", "in", Lang.array(Roles.CLUB_FZR)));
|
||||
List<String> clubIds = userRoles.stream().map(Sys_user_role::getStid).collect(Collectors.toList());
|
||||
List<Sys_club_user> clubUsers = dao.query(Sys_club_user.class, Cnd.where("stid", "in", clubIds));
|
||||
if (Lang.isNotEmpty(clubUsers)) {
|
||||
sqlExpressionGroup.or("u.id", "in", clubUsers.stream().map(v -> v.getUserid()).collect(Collectors.toList()));
|
||||
}
|
||||
return sqlExpressionGroup;
|
||||
}
|
||||
},
|
||||
TZ(CustomAuditTypeEnum.TZ.getValue()) {
|
||||
@Override
|
||||
public SqlExpressionGroup next(SqlExpressionGroup sqlExpressionGroup) {
|
||||
String dbtId = vi.getLastDelegationId((String) ShiroUtil.getPrincipalProperty("id"));
|
||||
sqlExpressionGroup.or("u.id", "in", Sqls.createf("select DISTINCT dbid from jdh_db where dbtid = '%s'", dbtId));
|
||||
return sqlExpressionGroup;
|
||||
}
|
||||
};
|
||||
|
||||
private final String name;
|
||||
|
||||
public Dao dao = ViResource.ioc.getByType(Dao.class);
|
||||
public Vi vi = ViResource.ioc.getByType(Vi.class);
|
||||
|
||||
CustomAuditTypeHandle(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract SqlExpressionGroup next(SqlExpressionGroup sqlExpressionGroup);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Table
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class MeetingInfo {
|
||||
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String meetingName;
|
||||
|
||||
@Column
|
||||
@Comment("地点")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String location;
|
||||
|
||||
@Column
|
||||
@Comment("会议类型")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer typeId;
|
||||
|
||||
@Column
|
||||
@Comment("开始时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date startTime;
|
||||
|
||||
@Column
|
||||
@Comment("结束时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date endTime;
|
||||
|
||||
@Column
|
||||
@Comment("是否可以请假")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isCanLeave;
|
||||
|
||||
@Column
|
||||
@Comment("是否多次签到")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean manySign;
|
||||
|
||||
@Column
|
||||
@Comment("请假截至时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date leaveDeadline;
|
||||
|
||||
@Column
|
||||
@Comment("会议描述")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 2000)
|
||||
private String meetingDescription;
|
||||
|
||||
@Column
|
||||
@Comment("关联会议id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String notifyId;
|
||||
|
||||
/**
|
||||
* 会议时间段
|
||||
*/
|
||||
@Many(field = "meetingId")
|
||||
private List<MeetingTimePeriod> meetingTimePeriods;
|
||||
|
||||
/**
|
||||
* 会议参加人员
|
||||
*/
|
||||
@Many(field = "meetingId")
|
||||
private List<MeetingUser> meetingUserList;
|
||||
|
||||
/**
|
||||
* 消息对象
|
||||
*/
|
||||
// @One(field = "")
|
||||
// private MsgNotify msgNotify;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会议时间段
|
||||
*/
|
||||
@Table
|
||||
@Data
|
||||
@TableIndexes({
|
||||
@Index(name = "INDEX_MEETINGTIMEPERIOD_MEETING_ID", fields = {"meetingId"}, unique = false),})
|
||||
public class MeetingTimePeriod {
|
||||
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("会议id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String meetingId;
|
||||
|
||||
@Column
|
||||
@Comment("时间段会议名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
private String timePeriodName;
|
||||
|
||||
@Column
|
||||
@Comment("开始时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date startTime;
|
||||
|
||||
@Column
|
||||
@Comment("结束时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date endTime;
|
||||
|
||||
@Many(field = "meetingTimePeriodId")
|
||||
private List<MeetingTimePeriodUser> meetingTimePeriodUserList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Table
|
||||
@Data
|
||||
@TableIndexes({
|
||||
@Index(name = "INDEX_MEETINGTIMEPERIODUSER_MEETING_TIME_PERIOD_ID", fields = {"meetingTimePeriodId"}, unique = false),
|
||||
@Index(name = "INDEX_MEETINGTIMEPERIODUSER_MEETING_ID", fields = {"meetingId"}, unique = false)})
|
||||
public class MeetingTimePeriodUser {
|
||||
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("会议id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String meetingId;
|
||||
|
||||
@Column
|
||||
@Comment("会议时间段id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String meetingTimePeriodId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("用户id")
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否参加")
|
||||
private Boolean isJoin;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
@Comment("请假理由")
|
||||
private String leaveReason;
|
||||
|
||||
@Column
|
||||
@Comment("用户请假开始时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date userLeaveStartTime;
|
||||
|
||||
@Column
|
||||
@Comment("用户请假结束时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date userLeaveEndTime;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Comment("请假当前状态")
|
||||
private Integer stateCode;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否签到")
|
||||
private Boolean isSignIn;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
@Comment("签到时间")
|
||||
private Date signInDateTime;
|
||||
|
||||
/**
|
||||
* 审核记录
|
||||
*/
|
||||
@Column
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
@Comment("审核记录ID")
|
||||
private List<NutMap> auditIdList;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import io.v.nutz.modules.models.AuditState;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Table
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class MeetingType {
|
||||
|
||||
@Id
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
@Comment("名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String meetingTypeName;
|
||||
|
||||
@Column
|
||||
@Comment("模块名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String moduleName;
|
||||
|
||||
@Column
|
||||
@Comment("排序")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private int sortNum;
|
||||
|
||||
@Many(field = "meetingTypeId")
|
||||
private List<AuditState> auditStateList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package io.v.nutz.meeting.models;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参会人员表
|
||||
*/
|
||||
@Table
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class MeetingUser {
|
||||
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("会议ID")
|
||||
private String meetingId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Comment("用户id")
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否参加")
|
||||
private Boolean isJoin;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
@Comment("请假理由")
|
||||
private String leaveReason;
|
||||
|
||||
@Column
|
||||
@Comment("用户请假开始时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date userLeaveStartTime;
|
||||
|
||||
@Column
|
||||
@Comment("用户请假结束时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date userLeaveEndTime;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.INT)
|
||||
@Comment("请假当前状态")
|
||||
private Integer stateCode;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
@Comment("是否签到")
|
||||
private Boolean isSignIn;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
@Comment("签到时间")
|
||||
private Date signInDateTime;
|
||||
|
||||
/**
|
||||
* 审核记录
|
||||
*/
|
||||
@Column
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
@Comment("审核记录ID")
|
||||
private List<NutMap> auditIdList;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.modules.models.Audit;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会议审核接口
|
||||
*/
|
||||
public interface MeetingAuditService extends ViService {
|
||||
|
||||
/**
|
||||
* 会议审核分页数据
|
||||
*
|
||||
* @param pageNumber
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
Pagination myMeetingPageData(int pageNumber, int pageSize, String keySearchWord, String typeId, Integer meetingTime);
|
||||
|
||||
/**
|
||||
* 查询会议提交了请假的人员
|
||||
*
|
||||
* @param meetingId 会议id
|
||||
*/
|
||||
List<NutMap> getLeaveUser(String meetingId, String moduleName, String auditType);
|
||||
|
||||
|
||||
/**
|
||||
* 会议审核
|
||||
*
|
||||
* @param tpuIds 记录id
|
||||
* @param audit 审核对象
|
||||
* @param isPass isPass
|
||||
*/
|
||||
void audit(String[] tpuIds, Audit audit, boolean isPass);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会议基本统计service
|
||||
*/
|
||||
public interface MeetingBasicStatisticsService {
|
||||
|
||||
Pagination pageData(PageForm pageForm, String meetingId, String[] meetingTime, String typeId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据时间段查询会议列表
|
||||
*
|
||||
* @param meetingTime
|
||||
* @return
|
||||
*/
|
||||
Object getMeetingList(String[] meetingTime);
|
||||
|
||||
Object getUserData(PageForm pageForm, String id, String meetingId, String type, String unitId, String unionId);
|
||||
|
||||
List<NutMap> getUserData(String id, String meetingId, String type);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会议通用方法
|
||||
*/
|
||||
@IocBean
|
||||
public interface MeetingCommonService {
|
||||
|
||||
/**
|
||||
* 根据typeId查询所属模块名称
|
||||
*
|
||||
* @param typeId
|
||||
* @return
|
||||
*/
|
||||
String findModuleNameByTypeId(Integer typeId);
|
||||
|
||||
/**
|
||||
* 根据MeetId查询所属模块名称
|
||||
*
|
||||
* @param meetingId
|
||||
* @return
|
||||
*/
|
||||
String findModuleNameByMeetingId(String meetingId);
|
||||
|
||||
/**
|
||||
* 根据模块名称查找对应stateCode 最开始的那个
|
||||
*
|
||||
* @param moduleName
|
||||
* @return
|
||||
*/
|
||||
Integer findStartStateCodeByModuleName(String moduleName);
|
||||
|
||||
Integer findAfterStateCode(Integer stateCode, boolean isPass);
|
||||
|
||||
Integer findAfterStateCodeByModuleName(Integer stateCode, String moduleName);
|
||||
|
||||
/**
|
||||
* 根据会议id查询请假成功的code
|
||||
*
|
||||
* @param meetingId
|
||||
* @return
|
||||
*/
|
||||
Integer findSuccessStateCode(String meetingId);
|
||||
|
||||
/**
|
||||
* 获取当前用户关联哪些会议
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Object find();
|
||||
|
||||
/**
|
||||
* 查询当前登录用户能审核的状态Id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Integer> findStateIdForMeCanAudit();
|
||||
|
||||
List<NutMap> getNextAuditUser(Integer stateCode, String moduleName);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.dao.Cnd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会议管理service
|
||||
*/
|
||||
public interface MeetingManageService extends ViService<MeetingInfo> {
|
||||
|
||||
/**
|
||||
* 模块名字
|
||||
*/
|
||||
String MODULE_NAME = "";
|
||||
|
||||
/**
|
||||
* 分页数据
|
||||
*
|
||||
* @param pageForm
|
||||
* @param cnd
|
||||
* @return
|
||||
*/
|
||||
Pagination pageData(PageForm pageForm, Cnd cnd);
|
||||
|
||||
/**
|
||||
* 添加会议及审核流程
|
||||
*
|
||||
* @param meetingInfo 会议信息
|
||||
*/
|
||||
void doAdd(MeetingInfo meetingInfo);
|
||||
|
||||
/**
|
||||
* 编辑会议及审核流程
|
||||
*
|
||||
* @param meetingInfo 会议信息
|
||||
*/
|
||||
void doEdit(MeetingInfo meetingInfo, List<String> userIds);
|
||||
|
||||
/**
|
||||
* 删除会议
|
||||
*
|
||||
* @param id 会议id
|
||||
*/
|
||||
void doDelete(String id);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriodUser;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.dao.Cnd;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会议通用service
|
||||
*/
|
||||
public interface MeetingMineService extends ViService {
|
||||
|
||||
/**
|
||||
* 我的会议分页数据
|
||||
*
|
||||
* @param pageForm
|
||||
* @param cnd
|
||||
* @return
|
||||
*/
|
||||
Pagination myMeetingPageData(PageForm pageForm, Cnd cnd);
|
||||
|
||||
/**
|
||||
* 查询我的会议时间段
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Object> findMyMeetPeriod(String meetingId);
|
||||
|
||||
/**
|
||||
* 请假
|
||||
*
|
||||
* @param meetingId 会议id
|
||||
* @param tpuIds tpuId 不解释
|
||||
* @param leaveReason 请假理由
|
||||
*/
|
||||
void askForLeave(List<MeetingTimePeriodUser> meetingTimePeriodUsers);
|
||||
|
||||
/**
|
||||
* 参加会议确认
|
||||
*
|
||||
* @param tpuIds
|
||||
*/
|
||||
void confirmMeeting(List<String> tpuIds);
|
||||
|
||||
/**
|
||||
* 签到
|
||||
*
|
||||
* @param timePeriodUser
|
||||
*/
|
||||
void signIn(MeetingTimePeriodUser timePeriodUser);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface MeetingOnlineService extends ViService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param pageForm
|
||||
* @param cnd
|
||||
* @return
|
||||
*/
|
||||
Pagination pageData(PageForm pageForm, Cnd cnd);
|
||||
|
||||
/**
|
||||
* 导出签字表
|
||||
*
|
||||
* @param timePeriodId 时间段id
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> exportSignature(String timePeriodId);
|
||||
|
||||
/**
|
||||
* 在线数据
|
||||
*
|
||||
* @param timePeriodId
|
||||
* @return
|
||||
*/
|
||||
List<Map<String, Object>> getRealTimeData(String timePeriodId);
|
||||
|
||||
/**
|
||||
* 获取签到人员
|
||||
*
|
||||
* @param timePeriodId
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> getSignInUser(String timePeriodId);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.v.nutz.meeting.service;
|
||||
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.service.ViService;
|
||||
|
||||
/**
|
||||
* 会议类型 流程 service
|
||||
*/
|
||||
public interface MeetingTypeService extends ViService<MeetingType> {
|
||||
|
||||
/**
|
||||
* 找出最大的那行stateId
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int findMaxStateId();
|
||||
|
||||
void add(MeetingType meetingType);
|
||||
|
||||
void edit(MeetingType meetingType);
|
||||
|
||||
void delete(MeetingType meetingTyp);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.base.utils.Vi;
|
||||
import io.v.nutz.constant.AuditTypeEnum;
|
||||
import io.v.nutz.lang.Enum;
|
||||
import io.v.nutz.meeting.models.CustomAuditTypeHandle;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriodUser;
|
||||
import io.v.nutz.meeting.service.MeetingAuditService;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.modules.models.Audit;
|
||||
import io.v.nutz.modules.models.AuditState;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.dao.util.cri.Static;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingAuditServiceImpl extends ViServiceImpl implements MeetingAuditService {
|
||||
|
||||
@Inject
|
||||
private MeetingCommonService meetingCommonService;
|
||||
@Inject
|
||||
private Vi vi;
|
||||
|
||||
public MeetingAuditServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination myMeetingPageData(int pageNumber, int pageSize, String keySearchWord, String typeId, Integer meetingTime) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
info.*,
|
||||
type.meetingTypeName,
|
||||
type.moduleName,
|
||||
(select count(*) from meeting_time_period_user where meetingId=info.id and JSON_CONTAINS(auditIdList, JSON_OBJECT('auditUser', @userid))) as audit
|
||||
FROM
|
||||
meeting_info info
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
LEFT JOIN audit_state state ON state.module = type.moduleName
|
||||
$condition
|
||||
""").setParam("userid", ShiroUtil.getPrincipalProperty("id"));
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("info.isCanLeave", "=", 1);
|
||||
List<Integer> stateIdForMeCanAudit = meetingCommonService.findStateIdForMeCanAudit();
|
||||
cnd.and("state.stateId", "in", stateIdForMeCanAudit);
|
||||
if (StringUtils.isNotBlank(keySearchWord)) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("mi.meetingName", keySearchWord);
|
||||
seg.orLike("mi.location", keySearchWord);
|
||||
cnd.and(seg);
|
||||
}
|
||||
if (StrUtil.isNotBlank(typeId)) {
|
||||
cnd.andEX("info.typeId", "=", typeId);
|
||||
}
|
||||
if (meetingTime != null) {
|
||||
if (meetingTime == 0) {
|
||||
cnd.andEX("info.startTime", ">=", DateUtil.getDateTime());
|
||||
} else {
|
||||
cnd.andEX("info.startTime", "<", DateUtil.getDateTime());
|
||||
}
|
||||
}
|
||||
cnd.groupBy("info.id");
|
||||
cnd.desc("startTime");
|
||||
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = listPage(pageNumber, pageSize, sql);
|
||||
List<Object> list = pagination.getList();
|
||||
list.forEach(item -> {
|
||||
Record map = (Record) item;
|
||||
List<NutMap> canAuditUserByLoginUser = this.getCanAuditUserByLoginUser(map.getString("id"), stateIdForMeCanAudit);
|
||||
map.put("no_audit", canAuditUserByLoginUser.size());
|
||||
});
|
||||
return pagination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> getLeaveUser(String meetingId, String moduleName, String auditType) {
|
||||
Sql sqlMeeting = Sqls.create("""
|
||||
select
|
||||
id,
|
||||
startTime,
|
||||
endTime,
|
||||
timePeriodName
|
||||
from
|
||||
meeting_time_period
|
||||
$condition
|
||||
""");
|
||||
Cnd cndMeeting = Cnd.NEW();
|
||||
cndMeeting.and("meetingId", "=", meetingId);
|
||||
sqlMeeting.setCondition(cndMeeting);
|
||||
List<NutMap> meetingList = listMap(sqlMeeting);
|
||||
|
||||
List<NutMap> list = "canAudit".equals(auditType) ? this.getCanAuditUserByLoginUser(meetingId, meetingCommonService.findStateIdForMeCanAudit()) : this.getHasAuditUserByLoginUser(meetingId);
|
||||
|
||||
//将list分组
|
||||
LinkedHashMap<String, List<NutMap>> map = new LinkedHashMap<>();
|
||||
list.forEach(item -> {
|
||||
String meetingTimePeriodId = item.getString("meetingTimePeriodId");
|
||||
if (map.containsKey(meetingTimePeriodId)) {
|
||||
map.get(meetingTimePeriodId).add(item);
|
||||
} else {
|
||||
List<NutMap> listMap = new ArrayList<>();
|
||||
listMap.add(item);
|
||||
map.put(meetingTimePeriodId, listMap);
|
||||
}
|
||||
});
|
||||
|
||||
//汇总数据
|
||||
meetingList.forEach(item -> {
|
||||
String id = item.getString("id");
|
||||
item.put("users", map.get(id));
|
||||
});
|
||||
return meetingList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void audit(String[] tpuIds, Audit audit, boolean isPass) {
|
||||
dao().insert(audit);
|
||||
for (String tp_id : tpuIds) {
|
||||
MeetingTimePeriodUser periodUser = dao().fetch(MeetingTimePeriodUser.class, tp_id);
|
||||
Integer stateCode = periodUser.getStateCode();
|
||||
|
||||
Integer afterStateCode = meetingCommonService.findAfterStateCode(stateCode, isPass);
|
||||
periodUser.setStateCode(afterStateCode);
|
||||
|
||||
List<NutMap> auditIdList = periodUser.getAuditIdList();
|
||||
if (Lang.isEmpty(auditIdList)) {
|
||||
auditIdList = new ArrayList<>();
|
||||
}
|
||||
auditIdList.add(NutMap.NEW().addv("stateCode", stateCode).addv("auditId", audit.getId()).addv("auditUser", ShiroUtil.getPrincipalProperty("id")).addv("auditState", isPass));
|
||||
periodUser.setAuditIdList(auditIdList);
|
||||
|
||||
if (!isPass) {
|
||||
periodUser.setIsJoin(null);
|
||||
periodUser.setLeaveReason(null);
|
||||
}
|
||||
dao().update(periodUser);
|
||||
}
|
||||
}
|
||||
|
||||
/*根据当前登录用户获取可以审核的用户*/
|
||||
public List<NutMap> getCanAuditUserByLoginUser(String meetingId, List<Integer> stateIdForMeCanAudit) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
mu.*,
|
||||
u.username,
|
||||
u.loginname,
|
||||
u.sex,
|
||||
u.unionid,
|
||||
u.unitid,
|
||||
u.unitname,
|
||||
state.auditAfterType
|
||||
FROM
|
||||
meeting_time_period_user mu
|
||||
left join `user` u on mu.userId=u.id
|
||||
LEFT JOIN audit_state state on state.stateId = mu.stateCode
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("mu.meetingId", "=", meetingId);
|
||||
cnd.and("u.username", "is not", null);
|
||||
cnd.and("u.username", "!=", "");
|
||||
cnd.and("mu.stateCode", "in", Sqls.createf("SELECT stateId FROM audit_state_user WHERE userid = '%s'", ShiroUtil.getPrincipalProperty("id")));
|
||||
cnd.and("state.stateAuditType", "in", Lang.list(AuditTypeEnum.AUDIT.getValue()));
|
||||
|
||||
List<AuditState> audit = dao().query(AuditState.class, Cnd.where("stateId", "in", stateIdForMeCanAudit));
|
||||
SqlExpressionGroup sqlExpressionGroup = new SqlExpressionGroup();
|
||||
audit.forEach(v -> {
|
||||
if (StrUtil.isNotBlank(v.getAuditAfterType())) {
|
||||
CustomAuditTypeHandle instance = Enum.instance(CustomAuditTypeHandle.class, v.getAuditAfterType());
|
||||
if(instance != null) {
|
||||
instance.next(sqlExpressionGroup);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!sqlExpressionGroup.isEmpty()) {
|
||||
cnd.and(sqlExpressionGroup);
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
/*根据当前登录用户获取已经审核的用户*/
|
||||
public List<NutMap> getHasAuditUserByLoginUser(String meetingId) {
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
mu.*,
|
||||
u.username,
|
||||
u.loginname,
|
||||
u.unitname
|
||||
from
|
||||
meeting_time_period_user mu
|
||||
left join
|
||||
`user` u on mu.userid=u.id
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("meetingId", "=", meetingId);
|
||||
cnd.and(new Static("JSON_CONTAINS(auditIdList, JSON_OBJECT('auditUser', '" + ShiroUtil.getPrincipalProperty("id") + "'))"));
|
||||
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
list.forEach(item -> {
|
||||
List<NutMap> listMap = Json.fromJsonAsList(NutMap.class, item.getString("auditIdList"));
|
||||
Boolean auditState = false;
|
||||
for (NutMap map : listMap) {
|
||||
if (map.getString("auditUser").equals(ShiroUtil.getPrincipalProperty("id"))) {
|
||||
auditState = map.get("auditState") == null ? null : map.getBoolean("auditState");
|
||||
break;
|
||||
}
|
||||
}
|
||||
item.put("auditState", auditState);
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.base.utils.Roles;
|
||||
import io.v.nutz.jdh.model.cb.Jdh_jdhxx;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.meeting.service.MeetingBasicStatisticsService;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.workersCongress.model.WorkersCongressSession;
|
||||
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.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingBasicStatisticsServiceImpl extends ViServiceImpl implements MeetingBasicStatisticsService {
|
||||
|
||||
@Inject
|
||||
private MeetingCommonService meetingCommonService;
|
||||
|
||||
|
||||
public MeetingBasicStatisticsServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, String meetingId, String[] meetingTime, String typeId) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
info.* ,
|
||||
type.moduleName,
|
||||
type.meetingTypeName
|
||||
FROM
|
||||
meeting_info info
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
$condition
|
||||
""");
|
||||
if (meetingTime != null && meetingTime.length == 2) {
|
||||
cnd.and("info.startTime", ">=", meetingTime[0]);
|
||||
cnd.and("info.startTime", "<=", meetingTime[1]);
|
||||
}
|
||||
cnd.andEX("info.id", "=", meetingId);
|
||||
cnd.andEX("type.id", "=", typeId);
|
||||
cnd.desc("startTime");
|
||||
sql.setCondition(cnd);
|
||||
Pagination list = list(pageForm, sql);
|
||||
List<NutMap> listList = list.getList();
|
||||
//获取教代会最新届次
|
||||
Jdh_jdhxx jdh = dao().fetch(Jdh_jdhxx.class, Cnd.where("jdhkqzt", "=", 1).desc("jdhkqsj"));
|
||||
//获取教代会最新届次
|
||||
WorkersCongressSession gdh = dao().fetch(WorkersCongressSession.class, Cnd.where("startState", "=", 1).desc("startTime"));
|
||||
|
||||
listList.forEach(v -> {
|
||||
MeetingType meetingType = dao().fetch(MeetingType.class, v.getInt("typeId"));
|
||||
String successStateCode = meetingCommonService.findSuccessStateCode(v.getString("id")).toString();
|
||||
if ("teacherMeeting".equals(meetingType.getModuleName())) {
|
||||
Cnd cndChild = Cnd.NEW();
|
||||
Sql sqlChild = Sqls.create("""
|
||||
SELECT
|
||||
mtp.*,
|
||||
info.meetingName,
|
||||
type.meetingTypeName,
|
||||
count( mtpu.id ) AS total,
|
||||
sum( CASE WHEN mtpu.isJoin IS null OR (mtpu.isJoin is NOT null AND mtpu.stateCode != @successStateCode) THEN 1 ELSE 0 END ) AS joinNum,
|
||||
sum( CASE WHEN mtpu.isJoin = 0 AND mtpu.stateCode = @successStateCode THEN 1 ELSE 0 END ) AS notJoinNum,
|
||||
sum( CASE WHEN mtpu.isSignIn = 1 THEN 1 ELSE 0 END ) AS signJoinNum,
|
||||
sum( CASE WHEN (mtpu.isJoin IS null AND mtpu.isSignIn is null) OR (mtpu.isJoin is NOT null AND mtpu.stateCode !=@successStateCode AND mtpu.isSignIn is null) THEN 1 ELSE 0 END ) AS notJoinNullNum,
|
||||
sum( CASE WHEN (mtpu.isSignIn = 1) AND (d.roleid = @zsdb) AND d.jdhid = @jdhId THEN 1 ELSE 0 END) as zsdbNum,
|
||||
sum( CASE WHEN (mtpu.isSignIn = 1) AND (d.roleid = @lxdb) AND d.jdhid = @jdhId THEN 1 ELSE 0 END) as lxdbNum
|
||||
FROM
|
||||
meeting_time_period mtp
|
||||
LEFT JOIN meeting_info info ON mtp.meetingId = info.id
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
LEFT JOIN meeting_time_period_user mtpu ON mtpu.meetingTimePeriodId = mtp.id
|
||||
LEFT JOIN jdh_db d on d.dbid = mtpu.userId and jdhid=@jdhId
|
||||
$condition
|
||||
""").setParam("successStateCode", successStateCode)
|
||||
.setParam("zsdb", Roles.ZSDB)
|
||||
.setParam("lxdb", Roles.LXDB)
|
||||
.setParam("jdhId", jdh.getId());
|
||||
cndChild.and("mtp.meetingId", "=", v.getString("id"));
|
||||
cndChild.desc("mtp.startTime");
|
||||
cndChild.groupBy("mtp.id");
|
||||
sqlChild.setCondition(cndChild);
|
||||
List<NutMap> childList = listMap(sqlChild);
|
||||
v.put("meetingTimeData", childList);
|
||||
|
||||
}else if ("gdh".equals(meetingType.getModuleName())) {
|
||||
Cnd cndChild = Cnd.NEW();
|
||||
Sql sqlChild = Sqls.create("""
|
||||
SELECT
|
||||
mtp.*,
|
||||
info.meetingName,
|
||||
type.meetingTypeName,
|
||||
count( mtpu.id ) AS total,
|
||||
sum( CASE WHEN mtpu.isJoin IS null OR (mtpu.isJoin is NOT null AND mtpu.stateCode != @successStateCode) THEN 1 ELSE 0 END ) AS joinNum,
|
||||
sum( CASE WHEN mtpu.isJoin = 0 AND mtpu.stateCode = @successStateCode THEN 1 ELSE 0 END ) AS notJoinNum,
|
||||
sum( CASE WHEN mtpu.isSignIn = 1 THEN 1 ELSE 0 END ) AS signJoinNum,
|
||||
sum( CASE WHEN (mtpu.isJoin IS null AND mtpu.isSignIn is null) OR (mtpu.isJoin is NOT null AND mtpu.stateCode !=@successStateCode AND mtpu.isSignIn is null) THEN 1 ELSE 0 END ) AS notJoinNullNum,
|
||||
sum( CASE WHEN (mtpu.isSignIn = 1) AND (d.roleId = @zsdb) AND d.gdh_id = @gdhId THEN 1 ELSE 0 END) as zsdbNum,
|
||||
sum( CASE WHEN (mtpu.isSignIn = 1) AND (d.roleId = @lxdb) AND d.gdh_id = @gdhId THEN 1 ELSE 0 END) as lxdbNum
|
||||
FROM
|
||||
meeting_time_period mtp
|
||||
LEFT JOIN meeting_info info ON mtp.meetingId = info.id
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
LEFT JOIN meeting_time_period_user mtpu ON mtpu.meetingTimePeriodId = mtp.id
|
||||
LEFT JOIN workers_congress_representative d on d.userId = mtpu.userId and gdh_id=@gdhId
|
||||
$condition
|
||||
""").setParam("successStateCode", successStateCode)
|
||||
.setParam("zsdb", Roles.GDHDB)
|
||||
.setParam("lxdb", Roles.GDHLX)
|
||||
.setParam("gdhId", gdh.getId());
|
||||
cndChild.and("mtp.meetingId", "=", v.getString("id"));
|
||||
cndChild.desc("mtp.startTime");
|
||||
cndChild.groupBy("mtp.id");
|
||||
sqlChild.setCondition(cndChild);
|
||||
List<NutMap> childList = listMap(sqlChild);
|
||||
v.put("meetingTimeData", childList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMeetingList(String[] meetingTime) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (meetingTime != null && meetingTime.length == 2) {
|
||||
cnd.and("startTime", ">=", meetingTime[0]);
|
||||
cnd.and("startTime", "<=", meetingTime[1]);
|
||||
|
||||
}
|
||||
cnd.desc("startTime");
|
||||
return dao().query(MeetingInfo.class, cnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getUserData(PageForm pageForm, String id, String meetingId, String type, String unitId, String unionId) {
|
||||
String successStateCode = meetingCommonService.findSuccessStateCode(meetingId).toString();
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, meetingId);
|
||||
MeetingType meetingType = dao().fetch(MeetingType.class, meetingInfo.getTypeId());
|
||||
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
mtp.*,
|
||||
u.loginname AS loginName,
|
||||
u.username AS userName,
|
||||
u.unitname AS unitName,
|
||||
u.unionname AS unionName
|
||||
FROM
|
||||
meeting_time_period_user mtp
|
||||
LEFT JOIN `user` u ON mtp.userId = u.id
|
||||
$condition
|
||||
""");
|
||||
if (type.equals("notJoinNum")) {
|
||||
cnd.and("mtp.isJoin", "=", 0);
|
||||
} else if (type.equals("signJoinNum")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
} else if (type.equals("notJoinNullNum")) {
|
||||
cnd.and(new Static("(mtp.isJoin IS null AND mtp.isSignIn is null AND mtp.meetingTimePeriodId = '%s') OR (mtp.isJoin is NOT null AND mtp.stateCode !='%s' AND mtp.isSignIn is null AND mtp.meetingTimePeriodId = '%s')".formatted(id, successStateCode, id)));
|
||||
}
|
||||
if ("teacherMeeting".equals(meetingType.getModuleName())) {
|
||||
//获取教代会最新届次
|
||||
Jdh_jdhxx jdh = dao().fetch(Jdh_jdhxx.class, Cnd.where("jdhkqzt", "=", 1).desc("jdhkqsj"));
|
||||
if (type.equals("zsdbNum")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select dbid from jdh_db where jdhid='%s' and roleid='%s')".formatted(jdh.getId(), Roles.ZSDB)));
|
||||
} else if (type.equals("lxdbNum")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select dbid from jdh_db where jdhid='%s' and roleid='%s')".formatted(jdh.getId(), Roles.LXDB)));
|
||||
}
|
||||
} else if ("gdh".equals(meetingType.getModuleName())) {
|
||||
//获取教代会最新届次
|
||||
WorkersCongressSession jdh = dao().fetch(WorkersCongressSession.class, Cnd.where("startState", "=", 1).desc("startTime"));
|
||||
if (type.equals("zsdbNum")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select userId from workers_congress_representative where gdh_id='%s' and roleId='%s')".formatted(jdh.getId(), Roles.GDHDB)));
|
||||
} else if (type.equals("lxdbNum")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select userId from workers_congress_representative where gdh_id='%s' and roleId='%s')".formatted(jdh.getId(), Roles.GDHLX)));
|
||||
}
|
||||
}
|
||||
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
if (Strings.isNotBlank(pageForm.getSearchName()) && Strings.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.where().andLike(pageForm.getSearchName(), pageForm.getSearchKeyword());
|
||||
}
|
||||
cnd.and("mtp.meetingTimePeriodId", "=", id);
|
||||
cnd.desc("u.unitid");
|
||||
sql.setCondition(cnd);
|
||||
|
||||
return list(pageForm, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> getUserData(String id, String meetingId, String type) {
|
||||
String successStateCode = meetingCommonService.findSuccessStateCode(meetingId).toString();
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, meetingId);
|
||||
MeetingType meetingType = dao().fetch(MeetingType.class, meetingInfo.getTypeId());
|
||||
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
mtp.*,
|
||||
u.loginname AS loginName,
|
||||
u.username AS userName,
|
||||
u.unitname AS unitName,
|
||||
u.unionname AS unionName
|
||||
FROM
|
||||
meeting_time_period_user mtp
|
||||
LEFT JOIN `user` u ON mtp.userId = u.id
|
||||
$condition
|
||||
""");
|
||||
cnd.and("mtp.meetingTimePeriodId", "=", id);
|
||||
if (type.equals("请假人数")) {
|
||||
cnd.and("mtp.isJoin", "=", 0).and("mtp.stateCode", "=", successStateCode);
|
||||
} else if (type.equals("实到人数")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
} else if (type.equals("未到人数")) {
|
||||
cnd.and(new Static("(mtp.isJoin IS null AND mtp.isSignIn is null and mtp.meetingTimePeriodId ='%s') OR (mtp.isJoin is NOT null AND mtp.stateCode !='%s' AND mtp.isSignIn is null and mtp.meetingTimePeriodId ='%s')".formatted(id, successStateCode, id)));
|
||||
}
|
||||
if ("teacherMeeting".equals(meetingType.getModuleName())) {
|
||||
//获取教代会最新届次
|
||||
Jdh_jdhxx jdh = dao().fetch(Jdh_jdhxx.class, Cnd.where("jdhkqzt", "=", 1).desc("jdhkqsj"));
|
||||
if (type.equals("正式代表")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select dbid from jdh_db where jdhid='%s' and roleid='%s')".formatted(jdh.getId(), Roles.ZSDB)));
|
||||
} else if (type.equals("列席代表")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select dbid from jdh_db where jdhid='%s' and roleid='%s')".formatted(jdh.getId(), Roles.LXDB)));
|
||||
}
|
||||
} else if ("gdh".equals(meetingType.getModuleName())) {
|
||||
//获取教代会最新届次
|
||||
WorkersCongressSession jdh = dao().fetch(WorkersCongressSession.class, Cnd.where("startState", "=", 1).desc("startTime"));
|
||||
if (type.equals("正式代表")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select userId from workers_congress_representative where gdh_id='%s' and roleId='%s')".formatted(jdh.getId(), Roles.GDHDB)));
|
||||
} else if (type.equals("列席代表")) {
|
||||
cnd.and("mtp.isSignIn", "=", 1);
|
||||
cnd.and(new Static(" mtp.userId in (select userId from workers_congress_representative where gdh_id='%s' and roleId='%s')".formatted(jdh.getId(), Roles.GDHLX)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.utils.Roles;
|
||||
import io.v.nutz.base.utils.Vi;
|
||||
import io.v.nutz.constant.AuditTypeEnum;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.modules.models.AuditState;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingCommonServiceImpl extends ViServiceImpl implements MeetingCommonService {
|
||||
|
||||
@Inject
|
||||
private Vi vi;
|
||||
|
||||
public MeetingCommonServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findModuleNameByTypeId(Integer typeId) {
|
||||
MeetingType meetingType = dao().fetch(MeetingType.class, Cnd.where("id", "=", typeId));
|
||||
if (Lang.isNotEmpty(meetingType)) {
|
||||
return meetingType.getModuleName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String findModuleNameByMeetingId(String meetingId) {
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, meetingId);
|
||||
if (Lang.isNotEmpty(meetingInfo) && null != meetingInfo.getTypeId()) {
|
||||
return findModuleNameByTypeId(meetingInfo.getTypeId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer findStartStateCodeByModuleName(String moduleName) {
|
||||
List<AuditState> auditStateList = dao().query(AuditState.class, Cnd.where("module", "=", moduleName).asc("stateId"));
|
||||
Optional<Integer> minOptional = auditStateList.stream().map(v -> v.getStateId()).min(Comparator.comparingInt(a -> a)).stream().findFirst();
|
||||
return minOptional.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer findAfterStateCode(Integer stateCode, boolean isPass) {
|
||||
AuditState auditState = dao().fetch(AuditState.class, stateCode);
|
||||
return isPass ? auditState.getAfterPassStateId() : auditState.getAfterRejectStateId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer findSuccessStateCode(String meetingId) {
|
||||
String moduleName = findModuleNameByMeetingId(meetingId);
|
||||
Cnd cnd = Cnd.where("module", "=", moduleName).and("stateAuditType", "=", AuditTypeEnum.PROCESS_PASS.getValue());
|
||||
AuditState auditState = dao().fetch(AuditState.class, cnd);
|
||||
return auditState.getStateId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer findAfterStateCodeByModuleName(Integer stateCode, String moduleName) {
|
||||
AuditState auditState = dao().fetch(AuditState.class, Cnd.where("stateId", "=", stateCode));
|
||||
if (Lang.isNotEmpty(auditState)) {
|
||||
return auditState.getAfterStateId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object find() {
|
||||
List<MeetingType> typeList = dao().query(MeetingType.class, null);
|
||||
List<String> typeModuleNameList = typeList.stream().map(MeetingType::getModuleName).collect(Collectors.toList());
|
||||
|
||||
List<AuditState> auditStateList = dao().query(AuditState.class, Cnd.where("module", "in", typeModuleNameList));
|
||||
|
||||
for (AuditState state : auditStateList) {
|
||||
dao().fetchLinks(state, "auditStateUserList");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> findStateIdForMeCanAudit() {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("stateId", "in", Sqls.create("select stateId from audit_state_user where userId = @userid").setParam("userid", ShiroUtil.getPrincipalProperty("id")));
|
||||
List<AuditState> auditStateList = dao().query(AuditState.class, cnd);
|
||||
return auditStateList.stream().map(v -> v.getStateId()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/*根据状态码获取下一节点审核人*/
|
||||
@Override
|
||||
public List<NutMap> getNextAuditUser(Integer stateCode, String moduleName) {
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
au.userId as userId,
|
||||
u.username as userName,
|
||||
u.loginname as loginName,
|
||||
u.unitname as unitName,
|
||||
u.mobile as mobile
|
||||
from
|
||||
audit_state_user au
|
||||
left join
|
||||
`user` u on au.userid = u.id
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
|
||||
cnd.and("stateId", "=", stateCode);
|
||||
|
||||
if (StrUtil.isNotBlank(moduleName) && "teacherMeeting".equals(moduleName) && stateCode == 4910) {
|
||||
String jdhid = vi.getLastTeacherMeetingId();
|
||||
String dbtId = vi.getLastDelegationId(ShiroUtil.getPrincipalProperty("id").toString());
|
||||
cnd.and("userId", "in", Sqls.createf("select userid from sys_user_role where jdhid='%s' and roleid='%s' and dbtId='%s'", jdhid, Roles.DBT_TZ, dbtId));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
|
||||
return listMap(sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriod;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriodUser;
|
||||
import io.v.nutz.meeting.models.MeetingUser;
|
||||
import io.v.nutz.meeting.service.MeetingManageService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.msgNotify.models.MsgNotify;
|
||||
import io.v.nutz.msgNotify.models.MsgNotifyUser;
|
||||
import io.v.nutz.msgNotify.service.MsgNotifyService;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
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.SqlExpressionGroup;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingManageServiceImpl extends ViServiceImpl<MeetingInfo> implements MeetingManageService {
|
||||
|
||||
@Inject
|
||||
private MsgNotifyService msgNotifyService;
|
||||
|
||||
|
||||
public MeetingManageServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, Cnd cnd) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
info.*,
|
||||
type.meetingTypeName
|
||||
FROM
|
||||
meeting_info info
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
$condition
|
||||
""");
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("info.meetingName", pageForm.getSearchKeyword());
|
||||
seg.orLike("info.location", pageForm.getSearchKeyword());
|
||||
cnd.and(seg);
|
||||
}
|
||||
cnd.desc("info.startTime");
|
||||
sql.setCondition(cnd);
|
||||
return list(pageForm, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void doAdd(MeetingInfo meetingInfo) {
|
||||
dao().insertWith(meetingInfo, "^meetingUserList|meetingTimePeriods$");
|
||||
|
||||
insertMeetingTimePeriodUser(meetingInfo.getId(), meetingInfo.getMeetingTimePeriods(), meetingInfo.getMeetingUserList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入会议时间段 - 用户 数据
|
||||
*
|
||||
* @param meetingId 会议id
|
||||
* @param meetingTimePeriods 时间段
|
||||
* @param meetingUserList 人员
|
||||
*/
|
||||
private void insertMeetingTimePeriodUser(String meetingId, List<MeetingTimePeriod> meetingTimePeriods, List<MeetingUser> meetingUserList) {
|
||||
if (Lang.isNotEmpty(meetingTimePeriods) && Lang.isNotEmpty(meetingUserList)) {
|
||||
ArrayList<MeetingTimePeriodUser> insertList = new ArrayList<>();
|
||||
for (MeetingTimePeriod timePeriod : meetingTimePeriods) {
|
||||
for (MeetingUser meetingUser : meetingUserList) {
|
||||
MeetingTimePeriodUser timePeriodUser = new MeetingTimePeriodUser();
|
||||
timePeriodUser.setMeetingId(meetingId);
|
||||
timePeriodUser.setMeetingTimePeriodId(timePeriod.getId());
|
||||
timePeriodUser.setUserId(meetingUser.getUserId());
|
||||
insertList.add(timePeriodUser);
|
||||
}
|
||||
}
|
||||
dao().insert(insertList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void doEdit(MeetingInfo meetingInfo, List<String> userIds) {
|
||||
//原来的人
|
||||
List<MeetingUser> oldMus = dao().query(MeetingUser.class, Cnd.where("meetingId", "=", meetingInfo.getId()));
|
||||
List<String> oldMuIds = oldMus.stream().map(v -> v.getUserId()).collect(Collectors.toList());
|
||||
|
||||
//新增的人
|
||||
List<String> newMuIds = userIds.stream().filter(v -> !oldMuIds.contains(v)).collect(Collectors.toList());
|
||||
|
||||
|
||||
//新增的人
|
||||
// List<MeetingUser> newMus = dao().query(MeetingUser.class, Cnd.where("userid", "not in", userIds).and("meetingId","=",meetingInfo.getId()));
|
||||
// List<String> newMuIds = newMus.stream().map(v -> v.getUserId()).collect(Collectors.toList());
|
||||
|
||||
//新增的时间段
|
||||
List<MeetingTimePeriod> newTps = meetingInfo.getMeetingTimePeriods().stream().filter(v -> StrUtil.isBlank(v.getId())).collect(Collectors.toList());
|
||||
|
||||
//原来的用户
|
||||
// List<MeetingUser> oldMus = dao().query(MeetingUser.class, Cnd.where("meetingId", "=", meetingInfo.getId()));
|
||||
// List<String> oldMuIds = oldMus.stream().map(v -> v.getUserId()).collect(Collectors.toList());
|
||||
|
||||
dao().update(meetingInfo);
|
||||
|
||||
//删除改删得记录
|
||||
dao().clear(MeetingUser.class, Cnd.where("userid", "not in", userIds).and("meetingId", "=", meetingInfo.getId()));
|
||||
dao().clear(MeetingTimePeriodUser.class, Cnd.where("userid", "not in", userIds).and("meetingId", "=", meetingInfo.getId()));
|
||||
List<MeetingTimePeriod> meetingTimePeriods = meetingInfo.getMeetingTimePeriods();
|
||||
List<String> meetingTimePeriodIds = meetingTimePeriods.stream().map(v -> v.getId()).collect(Collectors.toList());
|
||||
dao().clear(MeetingTimePeriod.class, Cnd.where("id", "not in", meetingTimePeriodIds).and("meetingId", "=", meetingInfo.getId()));
|
||||
// dao().clear(MeetingTimePeriodUser.class, Cnd.where("meetingTimePeriodId", "not in", meetingTimePeriodIds));
|
||||
|
||||
dao().clear(MeetingUser.class, Cnd.where("meetingId", "=", meetingInfo.getId()));
|
||||
ArrayList<MeetingUser> insertMuList = new ArrayList<>();
|
||||
userIds.forEach(v -> {
|
||||
MeetingUser meetingUser = new MeetingUser();
|
||||
meetingUser.setMeetingId(meetingInfo.getId());
|
||||
meetingUser.setUserId(v);
|
||||
insertMuList.add(meetingUser);
|
||||
});
|
||||
dao().insert(insertMuList);
|
||||
|
||||
List<MeetingTimePeriod> mTps = meetingInfo.getMeetingTimePeriods();
|
||||
for (MeetingTimePeriod mTp : mTps) {
|
||||
if (StrUtil.isNotBlank(mTp.getId())) {
|
||||
dao().update(mTp);
|
||||
List<MeetingTimePeriodUser> mtpus = new ArrayList<>();
|
||||
if (Lang.isNotEmpty(newMuIds)) {
|
||||
//旧时间段 并且 有新增的人员
|
||||
for (String newMuId : newMuIds) {
|
||||
MeetingTimePeriodUser mtpu = new MeetingTimePeriodUser();
|
||||
mtpu.setMeetingId(meetingInfo.getId());
|
||||
mtpu.setUserId(newMuId);
|
||||
mtpu.setMeetingTimePeriodId(mTp.getId());
|
||||
mtpus.add(mtpu);
|
||||
}
|
||||
dao().insert(mtpus);
|
||||
} else {
|
||||
//旧时间段 并且 没有新增的人员 不用管
|
||||
}
|
||||
} else {
|
||||
//有新增的时间段
|
||||
mTp.setMeetingId(meetingInfo.getId());
|
||||
dao().insert(mTp);
|
||||
List<MeetingTimePeriodUser> mtpus = new ArrayList<>();
|
||||
for (String userId : userIds) {
|
||||
MeetingTimePeriodUser mtpu = new MeetingTimePeriodUser();
|
||||
mtpu.setMeetingId(meetingInfo.getId());
|
||||
mtpu.setUserId(userId);
|
||||
mtpu.setMeetingTimePeriodId(mTp.getId());
|
||||
mtpus.add(mtpu);
|
||||
}
|
||||
dao().insert(mtpus);
|
||||
|
||||
|
||||
/*if (Lang.isEmpty(newMus)) {
|
||||
//有新增的时间段 但是 没有新增的人员
|
||||
for (String oldMuUserId : oldMuIds) {
|
||||
MeetingTimePeriodUser mtpu = new MeetingTimePeriodUser();
|
||||
mtpu.setMeetingId(meetingInfo.getId());
|
||||
mtpu.setUserId(oldMuUserId);
|
||||
mtpu.setMeetingTimePeriodId(mTp.getId());
|
||||
mtpus.add(mtpu);
|
||||
}
|
||||
dao().insert(mtpus);
|
||||
} else {
|
||||
//有新增的时间段 并且 有新增的人员
|
||||
for (String userId : userIds) {
|
||||
MeetingTimePeriodUser mtpu = new MeetingTimePeriodUser();
|
||||
mtpu.setMeetingId(meetingInfo.getId());
|
||||
mtpu.setUserId(userId);
|
||||
mtpu.setMeetingTimePeriodId(mTp.getId());
|
||||
mtpus.add(mtpu);
|
||||
}
|
||||
dao().insert(mtpus);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// //更新会议
|
||||
// dao().update(meetingInfo);
|
||||
//
|
||||
// //新会议人员
|
||||
// List<MeetingUser> meetingUserList = meetingInfo.getMeetingUserList();
|
||||
// List<String> meetingUserIdList = meetingUserList.stream().map(MeetingUser::getId).collect(Collectors.toList());
|
||||
// //删除不在新会议人员里面的数据
|
||||
// dao().clear(MeetingUser.class, Cnd.where("id", "not in", meetingUserIdList));
|
||||
// //批量更新 效率更高
|
||||
// for (MeetingUser meetingUser : meetingUserList) {
|
||||
// meetingUser.setMeetingId(meetingInfo.getId());
|
||||
// }
|
||||
// dao().insertOrUpdate(meetingUserList);
|
||||
//
|
||||
//
|
||||
// //会议时间段
|
||||
// List<MeetingTimePeriod> meetingTimePeriods = meetingInfo.getMeetingTimePeriods();
|
||||
// List<String> meetingTimePeriodIds = meetingTimePeriods.stream().map(MeetingTimePeriod::getId).collect(Collectors.toList());
|
||||
// //删除会议时间段 - 用户 记录
|
||||
// dao().clear(MeetingTimePeriodUser.class, Cnd.where("meetingTimePeriodId", "not in", meetingTimePeriodIds));
|
||||
// dao().clear(MeetingTimePeriodUser.class, Cnd.where("userId", "not in", meetingUserList.stream().map(v -> v.getUserId()).collect(Collectors.toList())));
|
||||
//
|
||||
// //新增的时间段
|
||||
// List<MeetingTimePeriod> newTimePeriod = meetingInfo.getMeetingTimePeriods().stream().filter(v -> StrUtil.isBlank(v.getId())).collect(Collectors.toList());
|
||||
// insertMeetingTimePeriodUser(meetingInfo.getId(), newTimePeriod, meetingInfo.getMeetingUserList());
|
||||
//
|
||||
// //需要编辑的时间段
|
||||
// List<MeetingTimePeriod> editTimePeriod = meetingInfo.getMeetingTimePeriods().stream().filter(v -> StrUtil.isBlank(v.getId())).collect(Collectors.toList());
|
||||
// dao().update(editTimePeriod);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void doDelete(String id) {
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, id);
|
||||
dao().clear(MeetingUser.class, Cnd.where("meetingId", "=", id));
|
||||
dao().clear(MeetingTimePeriod.class, Cnd.where("meetingId", "=", id));
|
||||
dao().clear(MeetingTimePeriodUser.class, Cnd.where("meetingId", "=", id));
|
||||
dao().clear(MsgNotify.class, Cnd.where("id", "=", meetingInfo.getNotifyId()));
|
||||
dao().clear(MsgNotifyUser.class, Cnd.where("titleId", "=", meetingInfo.getNotifyId()));
|
||||
dao().delete(meetingInfo);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriodUser;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.meeting.service.MeetingMineService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.msgNotify.service.MsgNotifyService;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.nutz.dao.Chain;
|
||||
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.SqlExpressionGroup;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingMineServiceImpl extends ViServiceImpl implements MeetingMineService {
|
||||
|
||||
@Inject
|
||||
private MeetingCommonService meetingCommonService;
|
||||
|
||||
@Inject
|
||||
private MsgNotifyService msgNotifyService;
|
||||
|
||||
public MeetingMineServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination myMeetingPageData(PageForm pageForm, Cnd cnd) {
|
||||
String userId = (String) ShiroUtil.getPrincipalProperty("id");
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
info.*,
|
||||
type.meetingTypeName,
|
||||
mu.isJoin,
|
||||
state.stateName,
|
||||
state.stateColor,
|
||||
mu.stateCode,
|
||||
(select stateId from audit_state where module = type.moduleName order by stateId asc limit 1) firstState
|
||||
FROM
|
||||
meeting_info info
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
LEFT JOIN meeting_time_period_user mu ON mu.meetingId = info.id
|
||||
LEFT JOIN audit_state state on state.stateId = mu.stateCode
|
||||
$condition
|
||||
""");
|
||||
Sql userSql = Sqls.create("select meetingId from meeting_time_period_user where userId = @userId").setParam("userId", userId);
|
||||
cnd.and("info.id", "in", userSql);
|
||||
|
||||
cnd.and("mu.userid", "=", userId);
|
||||
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("meetingName", pageForm.getSearchKeyword());
|
||||
seg.orLike("location", pageForm.getSearchKeyword());
|
||||
cnd.and(seg);
|
||||
}
|
||||
|
||||
cnd.groupBy("info.id");
|
||||
cnd.desc("info.startTime");
|
||||
sql.setCondition(cnd);
|
||||
Pagination list = list(pageForm, sql);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> findMyMeetPeriod(String meetingId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tp.id AS tpid,
|
||||
tp.startTime,
|
||||
tp.endTime,
|
||||
tp.timePeriodName,
|
||||
tpu.*,
|
||||
tpu.id as tpuId,
|
||||
state.stateName,
|
||||
state.stateAuditType
|
||||
FROM
|
||||
meeting_time_period tp
|
||||
LEFT JOIN meeting_time_period_user tpu ON tpu.meetingTimePeriodId = tp.id
|
||||
LEFT JOIN audit_state state on state.stateId = tpu.stateCode
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("tp.meetingId", "=", meetingId);
|
||||
cnd.and("tpu.userId", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void askForLeave(List<MeetingTimePeriodUser> meetingTimePeriodUsers) {
|
||||
String moduleName = meetingCommonService.findModuleNameByMeetingId(meetingTimePeriodUsers.get(0).getMeetingId());
|
||||
Integer stateCode = meetingCommonService.findStartStateCodeByModuleName(moduleName);
|
||||
if (stateCode != null) {
|
||||
|
||||
meetingTimePeriodUsers.forEach(item -> {
|
||||
item.setIsJoin(false);
|
||||
item.setStateCode(stateCode);
|
||||
});
|
||||
dao().updateIgnoreNull(meetingTimePeriodUsers);
|
||||
|
||||
List<NutMap> userIdMap = meetingCommonService.getNextAuditUser(stateCode, moduleName);
|
||||
String userInfoStr = msgNotifyService.userData(userIdMap);
|
||||
|
||||
String meetingId = meetingTimePeriodUsers.get(0).getMeetingId();
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, meetingId);
|
||||
|
||||
String loginname = ShiroUtil.getPlatformUsername();
|
||||
String msgStr = String.format("%s针对%s提交了请假申请,请您审批!", loginname, meetingInfo.getMeetingName());
|
||||
//msgApi.sendSmsMsg(userInfoStr, msgStr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmMeeting(List<String> tpuIds) {
|
||||
// meetingUser.setIsJoin(true);
|
||||
// dao().updateIgnoreNull(meetingUser);
|
||||
Chain chain = Chain.make("isJoin", true);
|
||||
Cnd cnd = Cnd.where("id", "in", tpuIds);
|
||||
dao().update(MeetingTimePeriodUser.class, chain, cnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signIn(MeetingTimePeriodUser timePeriodUser) {
|
||||
timePeriodUser.setIsSignIn(true);
|
||||
timePeriodUser.setSignInDateTime(new Date());
|
||||
dao().updateIgnoreNull(timePeriodUser);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
import io.v.nutz.base.utils.Roles;
|
||||
import io.v.nutz.jdh.model.cb.Jdh_jdhxx;
|
||||
import io.v.nutz.jdh.model.db.Jdh_db;
|
||||
import io.v.nutz.meeting.models.MeetingInfo;
|
||||
import io.v.nutz.meeting.models.MeetingTimePeriod;
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.meeting.service.MeetingOnlineService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.msgNotify.models.MsgNotify;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.workersCongress.model.WorkersCongressRepresentative;
|
||||
import io.v.nutz.workersCongress.model.WorkersCongressSession;
|
||||
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.Daos;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingOnlineServiceImpl extends ViServiceImpl implements MeetingOnlineService {
|
||||
|
||||
@Inject
|
||||
private MeetingCommonService meetingCommonService;
|
||||
|
||||
public MeetingOnlineServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, Cnd cnd) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
info.*,
|
||||
type.meetingTypeName,
|
||||
type.moduleName,
|
||||
@qrCodeUrl as qrCodeUrl
|
||||
FROM
|
||||
meeting_info info
|
||||
LEFT JOIN meeting_type type ON type.id = info.typeId
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("qrCodeUrl", "");
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("info.meetingName", pageForm.getSearchKeyword());
|
||||
seg.orLike("info.location", pageForm.getSearchKeyword());
|
||||
cnd.and(seg);
|
||||
}
|
||||
cnd.desc("info.startTime");
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = list(pageForm, sql);
|
||||
List<NutMap> list = pagination.getList();
|
||||
for (NutMap map : list) {
|
||||
List<MeetingTimePeriod> timePeriods = dao().query(MeetingTimePeriod.class, Cnd.where("meetingId", "=", map.getString("id", "")).asc("startTime"));
|
||||
map.setv("timePeriods", timePeriods);
|
||||
}
|
||||
pagination.setList(list);
|
||||
return pagination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> exportSignature(String timePeriodId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.username,
|
||||
u.loginname,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
`meeting_time_period_user` tpu
|
||||
RIGHT JOIN `user` u ON u.id = tpu.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("tpu.meetingTimePeriodId", "=", timePeriodId);
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> map = listMap(sql);
|
||||
|
||||
MeetingTimePeriod period = dao().fetch(MeetingTimePeriod.class, timePeriodId);
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, period.getMeetingId());
|
||||
MeetingType meetingType = dao().fetch(MeetingType.class, meetingInfo.getTypeId());
|
||||
|
||||
|
||||
List<String> userIds = map.stream().map(m -> m.getString("loginname")).collect(Collectors.toList());
|
||||
List<NutMap> roleNameList=new ArrayList<>();
|
||||
//如果是教代会会议
|
||||
if (meetingType.getModuleName().equals("teacherMeeting")) {
|
||||
MsgNotify notify = dao().fetch(MsgNotify.class, meetingInfo.getNotifyId());
|
||||
Sql SqlRoleName = Sqls.create("""
|
||||
SELECT
|
||||
us.loginname,
|
||||
sr.`name`
|
||||
FROM
|
||||
`jdh_db` db
|
||||
LEFT JOIN sys_user us ON us.id=db.dbid
|
||||
LEFT JOIN sys_role sr ON sr.id = db.roleid
|
||||
where db.jdhid=@jdhid and us.loginname in (@userIds)
|
||||
""").setParam("jdhid", notify.getTeacherMeetingId()).setParam("userIds", userIds);
|
||||
roleNameList = listMap(SqlRoleName);
|
||||
|
||||
}else if (meetingType.getModuleName().equals("gdh")){
|
||||
MsgNotify notify = dao().fetch(MsgNotify.class, meetingInfo.getNotifyId());
|
||||
Sql SqlRoleName = Sqls.create("""
|
||||
SELECT
|
||||
us.loginname,
|
||||
sr.`name`
|
||||
FROM
|
||||
`workers_congress_representative` db
|
||||
LEFT JOIN sys_user us ON us.id = db.userId
|
||||
LEFT JOIN sys_role sr ON sr.id = db.roleId
|
||||
WHERE
|
||||
db.gdh_id = @jdhid and us.loginname in (@userIds)
|
||||
""").setParam("jdhid", notify.getTeacherMeetingId()).setParam("userIds", userIds);
|
||||
roleNameList = listMap(SqlRoleName);
|
||||
}
|
||||
|
||||
if (Lang.isNotEmpty(roleNameList)){
|
||||
List<NutMap> finalRoleNameList = roleNameList;
|
||||
map.forEach(m -> {
|
||||
NutMap roleNameMap = finalRoleNameList.stream().filter(r -> r.getString("loginname").equals(m.getString("loginname"))).findFirst().orElse(null);
|
||||
if (Lang.isNotEmpty(roleNameMap)) {
|
||||
m.setv("roleName", roleNameMap.getString("name"));
|
||||
} else {
|
||||
m.setv("roleName", null);
|
||||
}
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getRealTimeData(String timePeriodId) {
|
||||
MeetingTimePeriod timePeriod = dao().fetch(MeetingTimePeriod.class, timePeriodId);
|
||||
Integer stateCode = meetingCommonService.findSuccessStateCode(timePeriod.getMeetingId());
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
(select count(1) from meeting_time_period_user where meetingTimePeriodId = @timePeriodId) as shouldComeNumber,
|
||||
(select count(1) from meeting_time_period_user where meetingTimePeriodId = @timePeriodId and (isJoin is null or (isJoin is not null and stateCode != @stateCode)) and isSignIn is null) as actualComeNumber,
|
||||
(select count(1) from meeting_time_period_user where meetingTimePeriodId = @timePeriodId and isSignIn = 1) as signInNumber,
|
||||
(select count(1) from meeting_time_period_user where meetingTimePeriodId = @timePeriodId and isJoin = 0 and stateCode = @stateCode) as leaveNumber
|
||||
""");
|
||||
sql.setParam("stateCode", stateCode).setParam("timePeriodId", timePeriodId);
|
||||
NutMap dataMap = (NutMap) Daos.query(dao(), sql.toString(), Sqls.callback.map());
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
list.add(Map.of("label", "应到人数", "key", "shouldComeNumber", "value", dataMap.getInt("shouldComeNumber", 0)));
|
||||
list.add(Map.of("label", "未到人数", "key", "actualComeNumber", "value", dataMap.getInt("actualComeNumber", 0)));
|
||||
list.add(Map.of("label", "签到人数", "key", "signInNumber", "value", dataMap.getInt("signInNumber", 0)));
|
||||
|
||||
//如果是教代会,就查询签到的正式代表和列席代表各多少人
|
||||
MeetingInfo meetingInfo = dao().fetch(MeetingInfo.class, timePeriod.getMeetingId());
|
||||
MeetingType meetingType = dao().fetch(MeetingType.class, meetingInfo.getTypeId());
|
||||
if ("teacherMeeting".equals(meetingType.getModuleName())) {
|
||||
//获取教代会最新届次
|
||||
Jdh_jdhxx jdh = dao().fetch(Jdh_jdhxx.class, Cnd.where("jdhkqzt", "=", 1).desc("jdhkqsj"));
|
||||
//查询签到人员
|
||||
List<NutMap> signInUser = getSignInUser(timePeriodId);
|
||||
List<String> userList = signInUser.stream().map(o -> o.getString("userId")).collect(Collectors.toList());
|
||||
//查询代表
|
||||
List<Jdh_db> dbList = dao().query(Jdh_db.class, Cnd.where("jdhid", "=", jdh.getId()));
|
||||
long zsdb = dbList.stream().filter(o -> o.getRoleid().equals(Roles.ZSDB) && userList.contains(o.getDbid())).count();
|
||||
long lxdb = dbList.stream().filter(o -> o.getRoleid().equals(Roles.LXDB) && userList.contains(o.getDbid())).count();
|
||||
list.add(Map.of("label", "正式代表", "key", "zsdbNumber", "value", zsdb));
|
||||
list.add(Map.of("label", "列席代表", "key", "lxdbNumber", "value", lxdb));
|
||||
} else if ("gdh".equals(meetingType.getModuleName())) {
|
||||
//获取教代会最新届次
|
||||
WorkersCongressSession jdh = dao().fetch(WorkersCongressSession.class, Cnd.where("startState", "=", 1).desc("startTime"));
|
||||
//查询签到人员
|
||||
List<NutMap> signInUser = getSignInUser(timePeriodId);
|
||||
List<String> userList = signInUser.stream().map(o -> o.getString("userId")).collect(Collectors.toList());
|
||||
//查询代表
|
||||
List<WorkersCongressRepresentative> dbList = dao().query(WorkersCongressRepresentative.class, Cnd.where("gdh_id", "=", jdh.getId()));
|
||||
long zsdb = dbList.stream().filter(o -> o.getRoleId().equals(Roles.GDHDB) && userList.contains(o.getUserId())).count();
|
||||
long lxdb = dbList.stream().filter(o -> o.getRoleId().equals(Roles.GDHLX) && userList.contains(o.getUserId())).count();
|
||||
list.add(Map.of("label", "正式代表", "key", "zsdbNumber", "value", zsdb));
|
||||
list.add(Map.of("label", "列席代表", "key", "lxdbNumber", "value", lxdb));
|
||||
}
|
||||
list.add(Map.of("label", "请假人数", "key", "leaveNumber", "value", dataMap.getInt("leaveNumber", 0)));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> getSignInUser(String timePeriodId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
tpu.userId,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
tpu.signInDateTime
|
||||
FROM
|
||||
`meeting_time_period_user` tpu
|
||||
LEFT JOIN `user` u ON u.id = tpu.userId
|
||||
WHERE
|
||||
tpu.meetingTimePeriodId = @timePeriodId
|
||||
AND tpu.isSignIn = 1
|
||||
ORDER BY tpu.signInDateTime desc
|
||||
""");
|
||||
sql.setParam("timePeriodId", timePeriodId);
|
||||
return listMap(sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package io.v.nutz.meeting.service.impl;
|
||||
|
||||
import io.v.nutz.meeting.models.MeetingType;
|
||||
import io.v.nutz.meeting.service.MeetingCommonService;
|
||||
import io.v.nutz.meeting.service.MeetingTypeService;
|
||||
import io.v.nutz.modules.models.AuditState;
|
||||
import io.v.nutz.modules.models.AuditStateUser;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
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.Daos;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class MeetingTypeServiceImpl extends ViServiceImpl<MeetingType> implements MeetingTypeService {
|
||||
|
||||
@Inject
|
||||
private MeetingCommonService meetingCommonService;
|
||||
|
||||
public MeetingTypeServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int findMaxStateId() {
|
||||
return dao().func(AuditState.class, "max", "stateId");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模块名称查找stateId
|
||||
*
|
||||
* @param moduleName
|
||||
* @return
|
||||
*/
|
||||
private String[] findStateIdArray(String moduleName) {
|
||||
//查询该类型原来关联的stateId
|
||||
Sql stateSql = Sqls.create("select stateId from audit_state where module = @moduleName").setParam("moduleName", moduleName);
|
||||
return (String[]) Daos.query(dao(), stateSql.toString(), Sqls.callback.strs());
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加流程信息
|
||||
*
|
||||
* @param meetingType
|
||||
*/
|
||||
private void insertAuditInfo(MeetingType meetingType) {
|
||||
List<AuditState> auditStateList = meetingType.getAuditStateList();
|
||||
if (Lang.isNotEmpty(auditStateList)) {
|
||||
for (int i = 0; i < auditStateList.size(); i++) {
|
||||
AuditState state = auditStateList.get(i);
|
||||
state.setModule(meetingType.getModuleName());
|
||||
state.setMeetingTypeId(meetingType.getId());
|
||||
dao().insertWith(state, "^auditStateUserList$");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void add(MeetingType meetingType) {
|
||||
dao().insert(meetingType);
|
||||
insertAuditInfo(meetingType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void edit(MeetingType meetingType) {
|
||||
dao().update(meetingType);
|
||||
|
||||
//查询该类型原来关联的stateId
|
||||
String[] stateIdStr = findStateIdArray(meetingType.getModuleName());
|
||||
|
||||
//删除原来审核状态下的审核人员
|
||||
dao().clear(AuditStateUser.class, Cnd.where("stateId", "in", stateIdStr));
|
||||
//删除原来的审核状态
|
||||
dao().clear(AuditState.class, Cnd.where("stateId", "in", stateIdStr));
|
||||
|
||||
//添加新的审核流程
|
||||
insertAuditInfo(meetingType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void delete(MeetingType meetingType) {
|
||||
//查询该类型原来关联的stateId
|
||||
String[] stateIdStr = findStateIdArray(meetingType.getModuleName());
|
||||
|
||||
//删除原来审核状态下的审核人员
|
||||
dao().clear(AuditStateUser.class, Cnd.where("stateId", "in", stateIdStr));
|
||||
//删除原来的审核状态
|
||||
dao().clear(AuditState.class, Cnd.where("stateId", "in", stateIdStr));
|
||||
|
||||
dao().delete(meetingType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package io.v.nutz.meeting.ws;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.plugins.mvc.websocket.AbstractWsEndpoint;
|
||||
import org.nutz.plugins.mvc.websocket.NutWsConfigurator;
|
||||
import org.nutz.plugins.mvc.websocket.WsHandler;
|
||||
|
||||
import javax.websocket.EndpointConfig;
|
||||
import javax.websocket.Session;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
||||
@ServerEndpoint(value = "/websocket/meeting", configurator = NutWsConfigurator.class)
|
||||
@IocBean
|
||||
@Slf4j
|
||||
public class MeetingWebsocket extends AbstractWsEndpoint {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@Override
|
||||
public WsHandler createHandler(Session session, EndpointConfig config) {
|
||||
// 是的,返回你自己的实现类就可以了,需要每次新建哦
|
||||
return new MeetingWsHandler(dao);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package io.v.nutz.meeting.ws;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.Mvcs;
|
||||
import org.nutz.plugins.mvc.websocket.handler.AbstractWsHandler;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@Slf4j
|
||||
public class MeetingWsHandler extends AbstractWsHandler {
|
||||
|
||||
private Dao dao;
|
||||
|
||||
public MeetingWsHandler(Dao dao) {
|
||||
// 覆盖默认前缀
|
||||
super("");
|
||||
this.dao = dao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// 必须调用超类的init,除非直接实现WsHandler接口
|
||||
super.init();
|
||||
if (this.httpSession != null) {
|
||||
// 其他业务代码只需要从HttpSession取出wsid,即可调用AbstractWsEndpoint的api发送消息
|
||||
this.httpSession.setAttribute("wsid", session.getId());
|
||||
}
|
||||
|
||||
HttpServletRequest req = Mvcs.getReq();
|
||||
log.debug("req={}", req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对应js端的action名称,方法参数必须是NutMap哦
|
||||
* 通过endpoint可以发生给任何你想发生的对象, session就是当前WebSocket的会话.
|
||||
*
|
||||
* @param req
|
||||
*/
|
||||
public void getSignData(NutMap req) {
|
||||
NutMap resp = NutMap.NEW();
|
||||
resp.setv("?????", "?????????");
|
||||
endpoint.sendJson(session.getId(), resp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 这里不知道为什么拿不到httpsession
|
||||
*
|
||||
* @param httpSession
|
||||
*/
|
||||
@Override
|
||||
public void setHttpSession(HttpSession httpSession) {
|
||||
log.debug("http session = " + httpSession);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
|
||||
|
||||
package io.v.nutz.modules.models;
|
||||
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Table("audit_state")
|
||||
public class AuditState {
|
||||
@Column
|
||||
@Id(
|
||||
auto = false
|
||||
)
|
||||
@Comment("ID")
|
||||
@ColDefine(
|
||||
type = ColType.INT,
|
||||
width = 8
|
||||
)
|
||||
private Integer stateId;
|
||||
@Column
|
||||
@Comment("状态名")
|
||||
@ColDefine(
|
||||
type = ColType.VARCHAR,
|
||||
width = 50
|
||||
)
|
||||
private String stateName;
|
||||
@Column
|
||||
@Comment("强调色")
|
||||
@ColDefine(
|
||||
type = ColType.VARCHAR,
|
||||
width = 20
|
||||
)
|
||||
private String stateColor;
|
||||
@Column
|
||||
@Comment("隶属(***模块)")
|
||||
@ColDefine(
|
||||
type = ColType.VARCHAR,
|
||||
width = 50
|
||||
)
|
||||
private String module;
|
||||
@Column
|
||||
@Comment("下个审核节点代码")
|
||||
@ColDefine(
|
||||
type = ColType.INT,
|
||||
width = 8
|
||||
)
|
||||
private Integer afterStateId;
|
||||
@Column
|
||||
@Comment("通过下个审核节点代码")
|
||||
@ColDefine(
|
||||
type = ColType.INT,
|
||||
width = 8
|
||||
)
|
||||
private Integer afterPassStateId;
|
||||
@Column
|
||||
@Comment("拒绝后下个节点代码")
|
||||
@ColDefine(
|
||||
type = ColType.INT,
|
||||
width = 8
|
||||
)
|
||||
private Integer afterRejectStateId;
|
||||
@Column
|
||||
@Comment("会议类型id 属于那个会议类型的流程")
|
||||
@ColDefine(
|
||||
type = ColType.INT
|
||||
)
|
||||
private Integer meetingTypeId;
|
||||
@Column
|
||||
@Comment("会议审核类型")
|
||||
@ColDefine(
|
||||
type = ColType.VARCHAR
|
||||
)
|
||||
private String auditAfterType;
|
||||
@Column
|
||||
@Comment("审核节点类型")
|
||||
@ColDefine(
|
||||
type = ColType.INT
|
||||
)
|
||||
private Integer stateAuditType;
|
||||
@Column
|
||||
@Comment("审核人员匹配条件")
|
||||
@ColDefine(
|
||||
type = ColType.VARCHAR
|
||||
)
|
||||
private String matchCnd;
|
||||
@Many(
|
||||
field = "stateId"
|
||||
)
|
||||
private List<AuditStateUser> auditStateUserList;
|
||||
|
||||
public AuditState() {
|
||||
}
|
||||
|
||||
public Integer getStateId() {
|
||||
return this.stateId;
|
||||
}
|
||||
|
||||
public String getStateName() {
|
||||
return this.stateName;
|
||||
}
|
||||
|
||||
public String getStateColor() {
|
||||
return this.stateColor;
|
||||
}
|
||||
|
||||
public String getModule() {
|
||||
return this.module;
|
||||
}
|
||||
|
||||
public Integer getAfterStateId() {
|
||||
return this.afterStateId;
|
||||
}
|
||||
|
||||
public Integer getAfterPassStateId() {
|
||||
return this.afterPassStateId;
|
||||
}
|
||||
|
||||
public Integer getAfterRejectStateId() {
|
||||
return this.afterRejectStateId;
|
||||
}
|
||||
|
||||
public Integer getMeetingTypeId() {
|
||||
return this.meetingTypeId;
|
||||
}
|
||||
|
||||
public Integer getStateAuditType() {
|
||||
return this.stateAuditType;
|
||||
}
|
||||
|
||||
public String getMatchCnd() {
|
||||
return this.matchCnd;
|
||||
}
|
||||
|
||||
public List<AuditStateUser> getAuditStateUserList() {
|
||||
return this.auditStateUserList;
|
||||
}
|
||||
|
||||
public AuditState setStateId(Integer stateId) {
|
||||
this.stateId = stateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setStateName(String stateName) {
|
||||
this.stateName = stateName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setStateColor(String stateColor) {
|
||||
this.stateColor = stateColor;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setModule(String module) {
|
||||
this.module = module;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setAfterStateId(Integer afterStateId) {
|
||||
this.afterStateId = afterStateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setAfterPassStateId(Integer afterPassStateId) {
|
||||
this.afterPassStateId = afterPassStateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setAfterRejectStateId(Integer afterRejectStateId) {
|
||||
this.afterRejectStateId = afterRejectStateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setMeetingTypeId(Integer meetingTypeId) {
|
||||
this.meetingTypeId = meetingTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setStateAuditType(Integer stateAuditType) {
|
||||
this.stateAuditType = stateAuditType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAuditAfterType() {
|
||||
return auditAfterType;
|
||||
}
|
||||
|
||||
public void setAuditAfterType(String auditAfterType) {
|
||||
this.auditAfterType = auditAfterType;
|
||||
}
|
||||
|
||||
public AuditState setMatchCnd(String matchCnd) {
|
||||
this.matchCnd = matchCnd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditState setAuditStateUserList(List<AuditStateUser> auditStateUserList) {
|
||||
this.auditStateUserList = auditStateUserList;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,12 +4,13 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.service.QuestionAnswerRankingService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.sys.services.SysUnionService;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
@@ -40,6 +41,9 @@ public class QuestionAnswerRankingController {
|
||||
@Inject
|
||||
private SysUnionService sysUnionService;
|
||||
|
||||
@Inject
|
||||
private QuestionAnswerRankingService questionAnswerRankingService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/question/ranking.html")
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
@@ -49,96 +53,25 @@ public class QuestionAnswerRankingController {
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId",required = false) String questionId,
|
||||
@Param(value = "unionId",required = false) String unionId,
|
||||
@Param(value = "unitId",required = false) String unitId,
|
||||
@Param(value = "answerDate",required = false) String answerDate) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
MAX( score ) AS max_score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("qus.userId", "qus.answerDate");
|
||||
cnd.desc("qus.userId").desc("max_score");
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
return questionService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "answerDate", required = false) String answerDate) {
|
||||
Pagination pagination = questionAnswerRankingService.pageData(pageForm, questionId, unionId, unitId, answerDate);
|
||||
return pagination;
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
public void doExport(@Param(value = "questionId",required = false) String questionId,
|
||||
@Param(value = "unionId",required = false) String unionId,
|
||||
@Param(value = "unitId",required = false) String unitId,
|
||||
@Param(value = "answerDate",required = false) String answerDate, HttpServletResponse response) {
|
||||
public void doExport(@Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "answerDate", required = false) String answerDate, HttpServletResponse response) {
|
||||
try {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
MAX( score ) AS max_score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("qus.userId", "qus.answerDate");
|
||||
cnd.desc("qus.userId").desc("max_score");
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> dataList = questionService.listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "max_score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("答题日期", "answerDate", 20));
|
||||
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String(("得分名单.xlsx").getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, dataList);
|
||||
workbook.write(response.getOutputStream());
|
||||
|
||||
questionAnswerRankingService.exportXlsx(questionId, response.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -147,7 +80,7 @@ public class QuestionAnswerRankingController {
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.answer.ranking")
|
||||
public void doExportAll(@Param(value = "questionId",required = false) String questionId, HttpServletResponse response) {
|
||||
public void doExportAll(@Param(value = "questionId", required = false) String questionId, HttpServletResponse response) {
|
||||
try {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
package io.v.nutz.question.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.QuestionWinner;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.util.ViTool;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@At("/platform/question/answer/statistics")
|
||||
@IocBean
|
||||
@Ok("json:full")
|
||||
public class QuestionAnswerStatisticsController {
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/question/statistics.html")
|
||||
@RequiresPermissions("question.answer.statistics")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.answer.statistics")
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId) {
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
MAX( qus.score ) AS max_score,
|
||||
u.username,
|
||||
u.loginname,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.sex,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("qus.userId");
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
sql.setCondition(cnd);
|
||||
return questionService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
}
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.answer.statistics")
|
||||
public Object doRaffle(String questionId) {
|
||||
questionService.dao().clear(QuestionWinner.class, Cnd.where("questionId", "=", questionId));
|
||||
|
||||
Question question = questionService.fetch(questionId);
|
||||
Integer raffleScore = question.getRaffleScore();
|
||||
Integer raffleWinnerUserNum = question.getRaffleWinnerUserNum();
|
||||
|
||||
Sql sql = Sqls.create("SELECT userId FROM `question_user_score` where score >= @score order by RAND() limit @num");
|
||||
sql.setParam("score", raffleScore);
|
||||
sql.setParam("num", raffleWinnerUserNum);
|
||||
List<NutMap> list = questionService.listMap(sql);
|
||||
|
||||
List<String> userIds = list.stream().map(v -> v.getString("userId")).collect(Collectors.toList());
|
||||
|
||||
List<QuestionWinner> winners = new ArrayList<>();
|
||||
for (String userId : userIds) {
|
||||
QuestionWinner questionWinner = new QuestionWinner();
|
||||
questionWinner.setQuestionId(questionId);
|
||||
questionWinner.setUserId(userId);
|
||||
winners.add(questionWinner);
|
||||
}
|
||||
questionService.dao().insert(winners);
|
||||
return null;
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.answer.statistics")
|
||||
public void export(@Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
HttpServletResponse response) {
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
MAX( qus.score ) AS max_score,
|
||||
u.username,
|
||||
u.loginname,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.sex,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("qus.userId");
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = questionService.listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("得分", "max_score", 20));
|
||||
|
||||
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
||||
ViTool.excelResponse(response, "参加人员.xlsx");
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook work = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
work.write(outputStream);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,10 +51,10 @@ public class QuestionAnswerWinnerController {
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.answer.winners")
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "winDate", required = false) String winDate) {
|
||||
public Object pageData(PageForm pageForm, @Param(value = "questionId",required = false) String questionId,
|
||||
@Param(value = "unionId",required = false) String unionId,
|
||||
@Param(value = "unitId",required = false) String unitId,
|
||||
@Param(value = "winDate",required = false) String winDate) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.loginname,
|
||||
@@ -63,15 +63,13 @@ public class QuestionAnswerWinnerController {
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
qus.score
|
||||
DATE_FORMAT( qw.winDate, '%Y-%m-%d' ) as winDate,
|
||||
qw.score
|
||||
FROM
|
||||
question_winner qw
|
||||
LEFT JOIN `user` u ON u.id = qw.userId
|
||||
LEFT JOIN question_user_score qus on qus.userId = qw.userId and qus.questionId = @questionId
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("questionId", questionId);
|
||||
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
@@ -80,7 +78,6 @@ public class QuestionAnswerWinnerController {
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("u.loginname");
|
||||
cnd.desc("qw.winDate");
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = questionService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
@@ -98,33 +95,31 @@ public class QuestionAnswerWinnerController {
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.answer.winners")
|
||||
public void exportWinners(@Param(value = "questionId", required = false) String questionId,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "winDate", required = false) String winDate, HttpServletResponse response) {
|
||||
public void exportWinners(@Param(value = "questionId",required = false) String questionId,
|
||||
@Param(value = "unionId",required = false) String unionId,
|
||||
@Param(value = "unitId",required = false) String unitId,
|
||||
@Param(value = "winDate",required = false) String winDate, HttpServletResponse response) {
|
||||
try {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
qus.score
|
||||
SELECT
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
DATE_FORMAT( qw.winDate, '%Y-%m-%d' ) as winDate,
|
||||
qw.score
|
||||
FROM
|
||||
question_winner qw
|
||||
LEFT JOIN `user` u ON u.id = qw.userId
|
||||
LEFT JOIN question_user_score qus on qus.userId = qw.userId and qus.questionId = @questionId
|
||||
$condition
|
||||
""");
|
||||
sql.setParam("questionId", questionId);
|
||||
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qw.winDate", "=", winDate);
|
||||
cnd.and("qw.questionId", "=", questionId);
|
||||
cnd.groupBy("u.loginname");
|
||||
cnd.desc("qw.winDate");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> dataList = questionService.listMap(sql);
|
||||
@@ -136,9 +131,8 @@ public class QuestionAnswerWinnerController {
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("得分", "score", 20));
|
||||
// exportEntities.add(new ExcelExportEntity("中奖日期", "winDate", 20));
|
||||
// exportEntities.add(new ExcelExportEntity("抽奖分数(最高分)", "maxScore", 20));
|
||||
exportEntities.add(new ExcelExportEntity("中奖日期", "winDate", 20));
|
||||
exportEntities.add(new ExcelExportEntity("抽奖分数", "score", 20));
|
||||
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String(("中奖名单.xlsx").getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
@@ -154,7 +148,7 @@ public class QuestionAnswerWinnerController {
|
||||
@At
|
||||
@RequiresPermissions("question.answer.winners")
|
||||
public Object getQuestion(Integer year) {
|
||||
List<Question> list = questionService.query(Cnd.NEW().andEX("YEAR(qctime)", "=", year).and("qlx", "=", 2).and("isRaffle", "=", 1));
|
||||
List<Question> list = questionService.query(Cnd.NEW().andEX("YEAR(qctime)", "=", year).and("qlx", "=", 2).and("isRaffle","=",1));
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,23 @@ public class QuestionCakeController {
|
||||
un.unionName,
|
||||
(select count(1) from user where member = 1 and unionid = un.id) AS teacherSum,
|
||||
(
|
||||
select
|
||||
count(1)
|
||||
from
|
||||
activity_user_scope aus
|
||||
left join "user" u on u.id = aus.userId
|
||||
where
|
||||
groupId in (
|
||||
select
|
||||
activityUserScopeId
|
||||
from
|
||||
question
|
||||
where
|
||||
qid = @questionId
|
||||
)
|
||||
and u.unionId = un.id
|
||||
) as teacherSum,
|
||||
(
|
||||
SELECT
|
||||
count( DISTINCT r.userId )
|
||||
FROM
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.v.nutz.question.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import cn.wizzer.framework.page.Pagination;
|
||||
@@ -8,7 +9,7 @@ import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.*;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
@@ -23,8 +24,10 @@ import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -46,6 +49,7 @@ public class QuestionH5Controller {
|
||||
|
||||
@At("/list")
|
||||
@Ok("beetl:/mobile/question/list.html")
|
||||
@RequiresAuthentication
|
||||
public void list() {
|
||||
|
||||
}
|
||||
@@ -70,16 +74,11 @@ public class QuestionH5Controller {
|
||||
|
||||
@At("/answer/index")
|
||||
@Ok("beetl:/mobile/question/answer.html")
|
||||
@RequiresAuthentication
|
||||
public void answerIndex() {
|
||||
|
||||
}
|
||||
|
||||
@At("/answer/index_ctgu")
|
||||
@Ok("beetl:/mobile/question/answer_ctgu.html")
|
||||
public void answerIndex2() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 页面数据
|
||||
@@ -93,13 +92,12 @@ public class QuestionH5Controller {
|
||||
public Object pageData(PageForm pageForm, int status, int type) {
|
||||
Sql sql = Sqls.create("""
|
||||
select
|
||||
q.*,
|
||||
(select count(1) from question_issue where iqid = q.qid) as topicTotal
|
||||
from
|
||||
q.*
|
||||
from
|
||||
question q
|
||||
$condition
|
||||
""");
|
||||
// sql.setParam("today", DateUtil.today());
|
||||
sql.setParam("today", DateUtil.today());
|
||||
Cnd cnd = Cnd.NEW();
|
||||
long now = System.currentTimeMillis();
|
||||
if (status == 1) {
|
||||
@@ -133,171 +131,203 @@ public class QuestionH5Controller {
|
||||
/**
|
||||
* 问卷信息
|
||||
*
|
||||
* @param id id
|
||||
* @param id id
|
||||
* @param currentDate 日期
|
||||
* @param randomCount 轮数
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/questionInfo/{id}")
|
||||
public Object questionInfo(@PathVariable String id) {
|
||||
public Object questionInfo(@PathVariable String id,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = questionService.fetch(id);
|
||||
|
||||
Cnd issueCnd = Cnd.NEW();
|
||||
|
||||
//出题模式
|
||||
// mode==1 定时定题 直接查询
|
||||
// mode==2 先查询今天的随机题目有没有设置好 设置好了直接查询今天的题目 没有的话查询displayDate为null的题目然后取题目再设置时间进行查询
|
||||
Integer ctMode = question.getCtMode();
|
||||
if (ctMode == 2) {
|
||||
//单次出题的数量
|
||||
Integer ctNum = question.getCtNum();
|
||||
int todayIssueCount = dao.count(Question_issue.class, Cnd.where("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd"))
|
||||
.and("iqid", "=", id));
|
||||
if (todayIssueCount == 0) {
|
||||
Sql randIssueSql = Sqls.create("SELECT iid FROM question_issue WHERE iqid = @qid AND displayDate IS NULL ORDER BY RAND() LIMIT @ctNum");
|
||||
randIssueSql.setParam("qid", id);
|
||||
randIssueSql.setParam("ctNum", ctNum);
|
||||
String[] randIssueIds = (String[]) Daos.query(dao, randIssueSql.toString(), Sqls.callback.strs());
|
||||
dao.update(Question_issue.class, Chain.make("displayDate", new Date()), Cnd.where("iid", "in", randIssueIds));
|
||||
|
||||
if (ctMode == 1) {
|
||||
//定时定题
|
||||
|
||||
//判断传入的日期是否已经加入到表里
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate));
|
||||
if (Lang.isEmpty(randomIssue)) {
|
||||
Sql issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid AND displayDate = @displayDate");
|
||||
issueSql.setParam("qid", id);
|
||||
issueSql.setParam("displayDate", currentDate);
|
||||
dao.execute(issueSql);
|
||||
String[] randomIssueIds = (String[]) issueSql.getResult();
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(Arrays.asList(randomIssueIds));
|
||||
questionRandomIssue.setNum(null);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
questionRandomIssue.setDisplayDate(DateUtil.parseDate(currentDate));
|
||||
dao.insert(questionRandomIssue);
|
||||
issueCnd.and("iid", "in", randomIssueIds);
|
||||
} else {
|
||||
issueCnd.and("iid", "in", randomIssue.getIssueIds());
|
||||
}
|
||||
} else if (ctMode == 2) {
|
||||
//随机模式
|
||||
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
|
||||
//每次随机的题目数量
|
||||
Integer ranDomSingleIssueNum = question.getRanDomSingleIssueNum();
|
||||
//总共随机几次
|
||||
Integer ranDomSum = question.getRanDomSum();
|
||||
|
||||
if (betweenDay == 0) {
|
||||
//同一天 一天随机多次
|
||||
|
||||
if (randomCount != null) {
|
||||
QuestionRandomIssue randomIssues = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()).and("num", "=", randomCount));
|
||||
issueCnd.andEX("iid", "in", randomIssues.getIssueIds());
|
||||
} else {
|
||||
//用户的随机题目
|
||||
List<QuestionRandomIssue> randomIssues = dao.query(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
//查询已经随机但是并没有答题完成的题目
|
||||
List<String> notFinishIssueIds = randomIssues.stream().filter(v -> v.getIsFinish() != null && !v.getIsFinish()).findFirst().map(QuestionRandomIssue::getIssueIds).orElseGet(Collections::emptyList);
|
||||
|
||||
if (Lang.isNotEmpty(notFinishIssueIds)) {
|
||||
//就查询没答完的题目
|
||||
issueCnd.and("iid", "in", notFinishIssueIds);
|
||||
} else {
|
||||
//进行下一次随机 然后加入到随机题目表里
|
||||
//已经答了的题目
|
||||
List<String> hasAnswerIssueIds = randomIssues.stream().flatMap(v -> v.getIssueIds().stream()).collect(Collectors.toList());
|
||||
//已经随机几次了
|
||||
int maxAnswerNum = randomIssues.stream().mapToInt(QuestionRandomIssue::getNum).max().orElse(0);
|
||||
|
||||
Sql issueSql = null;
|
||||
if (maxAnswerNum == ranDomSum) {
|
||||
//随机完了 没有题目了 默认去最后一轮
|
||||
// issueCnd.andEX("iid", "in", hasAnswerIssueIds);
|
||||
List<String> lastRanDomIssueIds = randomIssues.stream().filter(v -> v.getNum() == maxAnswerNum).flatMap(v -> v.getIssueIds().stream()).collect(Collectors.toList());
|
||||
issueCnd.andEX("iid", "in", lastRanDomIssueIds);
|
||||
} else {
|
||||
if (maxAnswerNum == 0) {
|
||||
//从没有随即过
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid ORDER BY RAND() LIMIT @num");
|
||||
} else {
|
||||
//之前随机过
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid and iid not in (@issueIds) ORDER BY RAND() LIMIT @num");
|
||||
issueSql.setParam("issueIds", hasAnswerIssueIds);
|
||||
}
|
||||
issueSql.setParam("qid", id);
|
||||
issueSql.setParam("num", ranDomSingleIssueNum);
|
||||
dao.execute(issueSql);
|
||||
String[] randomIssueIds = (String[]) issueSql.getResult();
|
||||
|
||||
if (Lang.isNotEmpty(randomIssueIds)) {
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(Arrays.asList(randomIssueIds));
|
||||
questionRandomIssue.setNum(maxAnswerNum + 1);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
questionRandomIssue.setDisplayDate(DateUtil.parseDate(DateUtil.today()));
|
||||
dao.insert(questionRandomIssue);
|
||||
}
|
||||
//获取本次的随机题目
|
||||
issueCnd.andEX("iid", "in", randomIssueIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//不是一天 那就一天随机一次
|
||||
|
||||
//用户的随机题目记录
|
||||
List<QuestionRandomIssue> randomIssues = dao.query(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
//已经随机的题目
|
||||
List<String> hasRanDomIssueIds = randomIssues.stream().flatMap(v -> v.getIssueIds().stream()).collect(Collectors.toList());
|
||||
|
||||
//判断传入的日期是否已经加入到表里
|
||||
QuestionRandomIssue currentDateRandomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate));
|
||||
if (Lang.isEmpty(currentDateRandomIssue)) {
|
||||
Sql issueSql = null;
|
||||
if (Lang.isEmpty(hasRanDomIssueIds)) {
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid ORDER BY RAND() LIMIT @num");
|
||||
} else {
|
||||
//之前随机过
|
||||
issueSql = Sqls.queryString(" SELECT iid FROM `question_issue` where iqid = @qid and iid not in (@issueIds) ORDER BY RAND() LIMIT @num");
|
||||
issueSql.setParam("issueIds", hasRanDomIssueIds);
|
||||
}
|
||||
issueSql.setParam("num", ranDomSingleIssueNum);
|
||||
issueSql.setParam("qid", id);
|
||||
dao.execute(issueSql);
|
||||
String[] randomIssueIds = (String[]) issueSql.getResult();
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(Arrays.asList(randomIssueIds));
|
||||
questionRandomIssue.setNum(null);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
questionRandomIssue.setDisplayDate(DateUtil.parseDate(currentDate));
|
||||
dao.insert(questionRandomIssue);
|
||||
issueCnd.and("iid", "in", randomIssueIds);
|
||||
} else {
|
||||
issueCnd.and("iid", "in", currentDateRandomIssue.getIssueIds());
|
||||
}
|
||||
}
|
||||
} else if (ctMode == 3) {
|
||||
//常规模式
|
||||
//判断是否将题目加进去了
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", question.getQid()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
if (Lang.isEmpty(randomIssue)) {
|
||||
Sql issueSql = Sqls.create(" SELECT iid FROM `question_issue` where iqid = @qid");
|
||||
issueSql.setParam("qid", id);
|
||||
issueSql.setCallback(Sqls.callback.strList());
|
||||
dao.execute(issueSql);
|
||||
List<String> randomIssueIds = (List<String>) issueSql.getResult();
|
||||
Collections.shuffle(randomIssueIds);
|
||||
QuestionRandomIssue questionRandomIssue = new QuestionRandomIssue();
|
||||
questionRandomIssue.setQuestionId(id);
|
||||
questionRandomIssue.setUserId(ShiroUtil.getUserId());
|
||||
questionRandomIssue.setIssueIds(randomIssueIds);
|
||||
questionRandomIssue.setNum(null);
|
||||
questionRandomIssue.setIsFinish(false);
|
||||
dao.insert(questionRandomIssue);
|
||||
issueCnd.and("iid", "in", randomIssueIds);
|
||||
} else {
|
||||
issueCnd.and("iid", "in", randomIssue.getIssueIds());
|
||||
}
|
||||
// issueCnd.and("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
issueCnd.asc("ipxbh");
|
||||
// issueCnd.asc("ipxbh");
|
||||
questionService.fetchLinks(question, "issues", issueCnd);
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
questionService.fetchLinks(issue, "wors", Cnd.NEW().asc("wpxbh"));
|
||||
}
|
||||
|
||||
if (question.getDisruptingOrder()) {
|
||||
Collections.shuffle(question.getIssues());
|
||||
}
|
||||
|
||||
return Result.success(question);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存答案
|
||||
*
|
||||
* @param repliesArray 回复
|
||||
* @param repliesArray 答复记录
|
||||
* @param questionId 问卷ID
|
||||
* @param isSave 是否保存
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/saveAnswer")
|
||||
public Object saveAnswer(@Param("repliesArray") Question_reply[] repliesArray) {
|
||||
if (Lang.isNotEmpty(repliesArray)) {
|
||||
List<Question_reply> replies = Arrays.asList(repliesArray);
|
||||
if (Lang.isNotEmpty(replies)) {
|
||||
String qid = replies.get(0).getQid();
|
||||
questionService.dao().clear(Question_reply.class, Cnd.where("qid", "=", qid).and("userId", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
replies.forEach(v -> {
|
||||
v.setUserId(String.valueOf(ShiroUtil.getPrincipalProperty("id")));
|
||||
v.setRtime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
});
|
||||
questionService.insert(replies);
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
public Object saveAnswer(@Param("replies") Question_reply[] repliesArray, String questionId, Boolean isSave) {
|
||||
questionService.saveAnswer(repliesArray, questionId, isSave);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存答案 只针对答题模式
|
||||
*
|
||||
* @param replies 问题回复
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/saveAnswer2")
|
||||
public Object saveAnswer2(Question_reply[] replies) {
|
||||
if (Lang.isNotEmpty(replies)) {
|
||||
Arrays.asList(replies).forEach(v -> {
|
||||
v.setUserId(String.valueOf(ShiroUtil.getPrincipalProperty("id")));
|
||||
v.setRtime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
});
|
||||
questionService.insert(replies);
|
||||
insertQuestionAnswerScore(Arrays.asList(replies));
|
||||
insertQuestionAnswerScore2(Arrays.asList(replies));
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public void insertQuestionAnswerScore(List<Question_reply> replyList) {
|
||||
//用户id
|
||||
String userId = (String) ShiroUtil.getPrincipalProperty("id");
|
||||
//问卷id
|
||||
String questionId = replyList.get(0).getQid();
|
||||
//题目id
|
||||
String issueId = replyList.get(0).getIssueId();
|
||||
|
||||
Question_issue issue = dao.fetch(Question_issue.class, Cnd.where("iid", "=", issueId));
|
||||
Float fraction = issue.getFraction();
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT wid FROM question_wor qw WHERE qw.correct = 1 AND qw.wiid = @wiid
|
||||
""").setParam("wiid", issueId);
|
||||
//正确的选项
|
||||
Set<String> correctOptionIdList = new HashSet<>((List<String>) Daos.query(dao, sql.toString(), Sqls.callback.strList()));
|
||||
//用户选的选项
|
||||
Set<String> userSelectedOptionIdList = replyList.stream().map(v -> v.getRwid()).collect(Collectors.toSet());
|
||||
|
||||
int count = dao.count(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId).and("subjectId", "=", issueId).and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")).and("userId", "=", userId));
|
||||
|
||||
QuestionAnswerUserScore answerUserScore = new QuestionAnswerUserScore();
|
||||
answerUserScore.setQuestionId(questionId);
|
||||
answerUserScore.setSubjectId(issueId);
|
||||
answerUserScore.setUserId(userId);
|
||||
answerUserScore.setAnswerDate(new Date());
|
||||
answerUserScore.setAnswerNum(count + 1);
|
||||
|
||||
if (correctOptionIdList.equals(userSelectedOptionIdList)) {
|
||||
answerUserScore.setSubjectScore(fraction);
|
||||
} else {
|
||||
answerUserScore.setSubjectScore(0f);
|
||||
}
|
||||
dao.insert(answerUserScore);
|
||||
}
|
||||
|
||||
public void insertQuestionAnswerScore2(List<Question_reply> replyList) {
|
||||
//问卷id
|
||||
String questionId = replyList.get(0).getQid();
|
||||
//查询今天的题目
|
||||
List<Question_issue> todayIssues = dao.query(Question_issue.class, Cnd.where("displayDate", "=", DateUtil.today())
|
||||
.and("iqid", "=", questionId));
|
||||
if (todayIssues != null && todayIssues.size() > 0) {
|
||||
Set<String> todayIssueIds = todayIssues.stream().map(v -> v.getIid()).collect(Collectors.toSet());
|
||||
//判断今天的题目是否已答完
|
||||
List<Question_reply> replyIssues = dao.query(Question_reply.class, Cnd.where("userId", "=", ShiroUtil.getPrincipalProperty("id")).and("qid", "=", questionId));
|
||||
Set<String> replyIssueIds = replyIssues.stream().map(v -> v.getIssueId()).collect(Collectors.toSet());
|
||||
if (todayIssueIds.equals(replyIssueIds)) {
|
||||
//答完了 去看看今天有没有答过
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getPrincipalProperty("id")).and("answerDate", "=", DateUtil.today()));
|
||||
|
||||
// AtomicInteger sum = new AtomicInteger();
|
||||
AtomicReference<Float> sum = new AtomicReference<>(0f);
|
||||
|
||||
//每题的回答记录
|
||||
Map<String, List<Question_reply>> issueReplies = replyIssues.stream().collect(Collectors.groupingBy(v -> v.getIssueId()));
|
||||
|
||||
//查出选项信息
|
||||
dao.fetchLinks(todayIssues, "wors");
|
||||
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(x -> x.getRwid()).collect(Collectors.toSet());
|
||||
|
||||
Optional<Question_issue> issueOptional = todayIssues.stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
|
||||
//正确答案
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
// sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0f));
|
||||
sum.updateAndGet(v1 -> v1 + issueOptional.map(i -> i.getFraction()).orElse(0f));
|
||||
}
|
||||
});
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId((String) ShiroUtil.getPrincipalProperty("id"));
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
dao.insert(questionUserScore);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 答题信息
|
||||
@@ -306,8 +336,25 @@ public class QuestionH5Controller {
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/answerInfo/?")
|
||||
public Object answerInfo(String id) {
|
||||
List<Question_reply> replies = questionService.dao().query(Question_reply.class, Cnd.where("qid", "=", id).and("userId", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
public Object answerInfo(String id,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Cnd cnd = Cnd.where("qid", "=", id).and("userId", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
|
||||
Question question = dao.fetch(Question.class, id);
|
||||
if (question.getCtMode() == 1) {
|
||||
cnd.and("DATE(rtime)", "=", currentDate);
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
|
||||
} else {
|
||||
cnd.and("DATE(rtime)", "=", currentDate);
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
|
||||
}
|
||||
|
||||
List<Question_reply> replies = questionService.dao().query(Question_reply.class, cnd);
|
||||
return Result.success(replies);
|
||||
}
|
||||
|
||||
@@ -346,74 +393,156 @@ public class QuestionH5Controller {
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@At("/canAnswer")
|
||||
public Object canAnswer(String questionId) {
|
||||
/**
|
||||
* 判断用户是否答完
|
||||
*
|
||||
* @param questionId 问卷ID
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
public Object checkUserFinishAnswer(String questionId,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
if (question.getCtMode() == 3) {
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
} else if (question.getCtMode() == 2) {
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
|
||||
if (betweenDay == 0) {
|
||||
//同一天
|
||||
if (randomCount != null) {
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("num", "=", randomCount));
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
}
|
||||
return Result.success(false);
|
||||
} else {
|
||||
//不是同一天 判断今天是否答完就行了
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
//时间过了
|
||||
if (DateUtil.parseDate(currentDate).isBefore(DateUtil.parseDate(DateUtil.today()))) {
|
||||
return Result.success(true);
|
||||
}
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
}
|
||||
} else if (question.getCtMode() == 1) {
|
||||
QuestionRandomIssue randomIssue = dao.fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", currentDate));
|
||||
//时间过了
|
||||
if (DateUtil.parseDate(currentDate).isBefore(DateUtil.parseDate(DateUtil.today()))) {
|
||||
return Result.success(true);
|
||||
}
|
||||
return Result.success(randomIssue.getIsFinish());
|
||||
}
|
||||
return Result.success(false);
|
||||
}
|
||||
|
||||
@At
|
||||
public Object checkCanAnswerAgain(String questionId,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
if (question.getCanRepeatedAnswer()) {
|
||||
//0次则不限制
|
||||
if (question.getCanRepeatedAnswerNum() == 0) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
if (question.getCtMode() == 3) {
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success(count < question.getCanRepeatedAnswerNum());
|
||||
} else if (question.getCtMode() == 2) {
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay == 0) {
|
||||
return Result.success(false);
|
||||
} else {
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("answerDate", "=", DateUtil.today()));
|
||||
return Result.success(count < question.getCanRepeatedAnswerNum());
|
||||
}
|
||||
} else if (question.getCtMode() == 1) {
|
||||
int count = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("answerDate", "=", currentDate));
|
||||
//时间过了
|
||||
if (Lang.isNotEmpty(currentDate) && DateUtil.parseDate(currentDate).isBefore(DateUtil.parseDate(DateUtil.today()))) {
|
||||
return Result.success(false);
|
||||
}
|
||||
return Result.success(count < question.getCanRepeatedAnswerNum());
|
||||
}
|
||||
}
|
||||
return Result.success(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取得分
|
||||
*
|
||||
* @param questionId
|
||||
* @param currentDate
|
||||
* @param randomCount
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
public Object getScore(String questionId,
|
||||
@Param(required = false, value = "currentDate") String currentDate,
|
||||
@Param(required = false, value = "randomCount") Integer randomCount) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
|
||||
//每天的题目数量
|
||||
int issueCount = dao.count(Question_issue.class, Cnd.where("iqid", "=", questionId).and("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
if (question.getCtMode() == 1) {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate)
|
||||
.desc(question.getCalcScoreMode() == 1 ? "score" : "answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
} else if (question.getCtMode() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
|
||||
//当前最大答题次数
|
||||
int maxCount = dao.func(QuestionAnswerUserScore.class, "max", "answerNum", Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getPrincipalProperty("id")));
|
||||
|
||||
//最大答题次数已经答了多少题
|
||||
int answerIssue = dao.count(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getPrincipalProperty("id")).and("answerNum", "=", maxCount));
|
||||
|
||||
//今天的题目已经答了几次
|
||||
int todayMaxCount = dao.func(QuestionAnswerUserScore.class, "max", "answerNum",
|
||||
Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
.and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd"))
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
if (question.getAnswerTotalSum() != 0 && maxCount < question.getAnswerTotalSum()) {
|
||||
//今天的题目需要全部答完
|
||||
|
||||
// //今天所有的题目
|
||||
// int todayAllIssues = dao.count(Question_issue.class, Cnd.where("iqid", "=", questionId).and("displayDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
// //今天已经答了的题目
|
||||
// int todayHasAnswerIssues = dao.count(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
// .and("userId", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
// .and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd"))
|
||||
// .and("answerNum", "=", todayMaxCount)
|
||||
//
|
||||
// );
|
||||
|
||||
return Result.success(true);
|
||||
if (betweenDay == 0) {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
// .and("displayDate", "=", currentDate)
|
||||
.and("answerNum", "=", randomCount)
|
||||
.desc("answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
} else {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
.and("displayDate", "=", currentDate)
|
||||
.desc(question.getCalcScoreMode() == 1 ? "score" : "answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
QuestionUserScore userScore = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId())
|
||||
.desc(question.getCalcScoreMode() == 1 ? "score" : "answerNum"));
|
||||
return Result.success().addData(Optional.ofNullable(userScore).map(v -> v.getScore()).orElse(0));
|
||||
}
|
||||
|
||||
if (question.getQrkdcs() != 0 && question.getQrkdcs() > todayMaxCount) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
if (answerIssue < issueCount) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
return Result.success(false);
|
||||
|
||||
// return Result.success(answerIssue < issueCount || (question.getQrkdcs() > 0 && question.getQrkdcs() > todayMaxCount));
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@At("/todayMaxScore")
|
||||
public Object todayMaxScore(String questionId) {
|
||||
List<QuestionUserScore> userScores = dao.query(QuestionUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
.and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
|
||||
Map<Integer, Float> numScoreMap = userScores.stream().collect(Collectors.toMap(v -> v.getAnswerNum(), v -> v.getScore()));
|
||||
|
||||
// List<QuestionAnswerUserScore> list = dao.query(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId)
|
||||
// .and("userId", "=", ShiroUtil.getPrincipalProperty("id"))
|
||||
// .and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
//
|
||||
// Map<Integer, Integer> numScoreMap = list.stream().collect(Collectors.groupingBy(v -> v.getAnswerNum(), Collectors.summingInt(v -> v.getSubjectScore())));
|
||||
return Result.success(numScoreMap);
|
||||
/**
|
||||
* 获取用户已回答的轮数 针对单天随机
|
||||
*
|
||||
* @param questionId 问卷ID
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
public Object getUserHasAnswerRandomNum(String questionId) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
//判断是否为一天答题
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (question.getCtMode() == 2 && betweenDay == 0) {
|
||||
int count = dao.count(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId)
|
||||
.and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success().addData(count);
|
||||
}
|
||||
return Result.success().addData(0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,273 +0,0 @@
|
||||
package io.v.nutz.question.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.dao.CndPlus;
|
||||
import io.v.nutz.question.model.*;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
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.Daos;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 三峡答题
|
||||
*
|
||||
* @author jug
|
||||
* @date 2023/10/20
|
||||
*/
|
||||
@IocBean
|
||||
@At("/mobile/question/h5ctgu")
|
||||
@Ok("json:full")
|
||||
public class QuestionH5CtguController {
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@At("/score")
|
||||
@Ok("beetl:/mobile/question/ctgu_answer/score.html")
|
||||
public void score() {
|
||||
|
||||
}
|
||||
|
||||
@At("/answerSheet")
|
||||
@Ok("beetl:/mobile/question/ctgu_answer/answerSheet.html")
|
||||
public void answerSheet(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 问卷信息
|
||||
*
|
||||
* @param id id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/questionInfo/{id}")
|
||||
public Object questionInfo(@PathVariable String id) {
|
||||
Question question = questionService.fetch(id);
|
||||
dao.fetchLinks(question, "issues", Cnd.NEW().asc("ipxbh"));
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
questionService.fetchLinks(issue, "wors", Cnd.NEW().asc("wpxbh"));
|
||||
}
|
||||
// List<Question_issue> issues = question.getIssues();
|
||||
// Collections.shuffle(issues.subList(0,issues.size()));
|
||||
// Collections.shuffle(issues.subList(22,issues.size()));
|
||||
return Result.success(question);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存、提交答案
|
||||
*
|
||||
* @param replies
|
||||
* @param questionId
|
||||
* @param isSave
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Object saveAnswer(@Param("replies") NutMap[] replies, String questionId, Boolean isSave) {
|
||||
|
||||
dao.clear(Question_reply.class, Cnd.where("userId", "=", ShiroUtil.getUserId()).and("qid", "=", questionId));
|
||||
|
||||
List<Question_reply> replyList = new ArrayList<>();
|
||||
for (NutMap reply : replies) {
|
||||
for (String userSelect : reply.getList("userSelect", String.class)) {
|
||||
Question_reply questionReply = new Question_reply();
|
||||
questionReply.setRwid(userSelect);
|
||||
questionReply.setIssueId(reply.getString("issueId"));
|
||||
replyList.add(questionReply);
|
||||
}
|
||||
}
|
||||
|
||||
for (Question_reply questionReply : replyList) {
|
||||
questionReply.setQid(questionId);
|
||||
questionReply.setRtime(DateUtil.now());
|
||||
questionReply.setUserId(ShiroUtil.getUserId());
|
||||
questionReply.setSave(isSave);
|
||||
}
|
||||
|
||||
dao.insert(replyList);
|
||||
|
||||
if (!isSave) {
|
||||
//全部答完提交计算分数
|
||||
Sql answerSql = Sqls.create("SELECT count(DISTINCT issueId) as count FROM Question_reply WHERE qid=@questionId AND userId=@userId AND save=0");
|
||||
answerSql.setParam("questionId", questionId);
|
||||
answerSql.setParam("userId", ShiroUtil.getUserId());
|
||||
NutMap answerCountMap = (NutMap) Daos.query(dao, answerSql.toString(), Sqls.callback.map());
|
||||
int answerCount = answerCountMap.getInt("count", 0);
|
||||
|
||||
int issueCount = dao.count(Question_issue.class, Cnd.where("iqid", "=", questionId));
|
||||
|
||||
if (answerCount == issueCount) {
|
||||
insertQuestionAnswerScore2(null, questionId);
|
||||
}
|
||||
}
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 回答信息
|
||||
*
|
||||
* @param id
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At("/answerInfo/?")
|
||||
public Object answerInfo(String id) {
|
||||
List<Question_reply> replies = questionService.dao().query(Question_reply.class, Cnd.where("qid", "=", id).and("userId", "=", ShiroUtil.getUserId()));
|
||||
return Result.success(replies);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否答完
|
||||
*
|
||||
* @param questionId
|
||||
* @return {@link Object}
|
||||
*/
|
||||
@At
|
||||
public Object checkUserFinishAnswer(String questionId) {
|
||||
Sql answerSql = Sqls.create("SELECT count(DISTINCT issueId) as count FROM Question_reply WHERE qid=@questionId AND userId=@userId AND save=0");
|
||||
answerSql.setParam("questionId", questionId);
|
||||
answerSql.setParam("userId", ShiroUtil.getUserId());
|
||||
NutMap answerCountMap = (NutMap) Daos.query(dao, answerSql.toString(), Sqls.callback.map());
|
||||
int answerCount = answerCountMap.getInt("count", 0);
|
||||
|
||||
// int answerCount = dao.count(Question_reply.class, Cnd.where("userId", "=", ShiroUtil.getUserId()).and("qid", "=", questionId).and("save", "=", 0));
|
||||
int issueCount = dao.count(Question_issue.class, Cnd.where("iqid", "=", questionId));
|
||||
return Result.success(answerCount == issueCount);
|
||||
}
|
||||
|
||||
@At
|
||||
public Object getScore(String questionId) {
|
||||
int fullScore = dao.func(Question_issue.class, "sum", "fraction", Cnd.where("iqid", "=", questionId));
|
||||
|
||||
//历史最高分
|
||||
Integer maxScore = dao.func(QuestionUserScore.class, "max", "score", Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
//当前得分
|
||||
Float score = dao.fetch(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).desc("answerNum")).getScore();
|
||||
|
||||
//回答次数
|
||||
int answerCount = dao.count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
String qtitle = dao.fetch(Question.class, questionId).getQtitle();
|
||||
Sql sql = Sqls.create("select username,loginname,sex,unitname,unionname from `user` where id = @id").setParam("id", ShiroUtil.getUserId());
|
||||
NutMap userMap = (NutMap) Daos.query(dao, sql.toString(), Sqls.callback.map());
|
||||
|
||||
NutMap map = NutMap.NEW();
|
||||
map.put("maxScore", maxScore);
|
||||
map.put("score", score);
|
||||
map.put("title", qtitle);
|
||||
map.put("user", userMap);
|
||||
map.put("answerCount", answerCount);
|
||||
|
||||
double percentage = (double) score / fullScore * 100;
|
||||
String message;
|
||||
|
||||
if (percentage >= 90) {
|
||||
message = "你真棒!这是一个优秀的成绩!";
|
||||
} else if (percentage >= 80) {
|
||||
message = "不错哦!你取得了一个良好的成绩!";
|
||||
} else if (percentage >= 70) {
|
||||
message = "还不错,继续努力,你可以取得更好的成绩!";
|
||||
} else if (percentage >= 60) {
|
||||
message = "及格了,但还有进步的空间,请继续努力!";
|
||||
} else {
|
||||
message = "很遗憾,你没有及格,但别灰心,下次会更好的!";
|
||||
}
|
||||
|
||||
map.put("message", message);
|
||||
return Result.success(map);
|
||||
}
|
||||
|
||||
@At("/canAnswer")
|
||||
public Object canAnswer(String questionId) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
|
||||
//题目数量
|
||||
int issueCount = dao.count(Question_issue.class, Cnd.where("iqid", "=", questionId));
|
||||
|
||||
//当前最大答题次数
|
||||
int maxCount = dao.func(QuestionAnswerUserScore.class, "max", "answerNum", Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
//最大答题次数已经答了多少题
|
||||
int answerIssue = dao.count(QuestionAnswerUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("answerNum", "=", maxCount));
|
||||
|
||||
//今天的题目已经答了几次
|
||||
int todayMaxCount = dao.func(QuestionAnswerUserScore.class, "max", "answerNum", Cnd.where("questionId", "=", questionId).and("userId", "=", io.v.nutz.web.commons.utils.ShiroUtil.getPrincipalProperty("id")).and("answerDate", "=", DateUtil.format(new Date(), "yyyy-MM-dd")));
|
||||
|
||||
|
||||
if (question.getAnswerTotalSum() != 0 && maxCount < question.getAnswerTotalSum()) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
if (question.getQrkdcs() != 0 && question.getQrkdcs() > todayMaxCount) {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
if (answerIssue < issueCount) {
|
||||
return Result.success(true);
|
||||
}
|
||||
return Result.success(false);
|
||||
}
|
||||
|
||||
private void insertQuestionAnswerScore2(List<Question_reply> replyList, String questionId) {
|
||||
int answerNum = dao.func(QuestionUserScore.class, "max", "answerNum", Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
//查询题目及选项信息
|
||||
List<Question_issue> issues = dao.query(Question_issue.class, Cnd.where("iqid", "=", questionId));
|
||||
dao.fetchLinks(issues, "wors");
|
||||
|
||||
// AtomicReference<Float> score = new AtomicReference<>();
|
||||
AtomicReference<Float> score = new AtomicReference<>((float) 0);
|
||||
|
||||
|
||||
List<Question_reply> replyIssues = dao.query(Question_reply.class, Cnd.where("userId", "=", io.v.nutz.web.commons.utils.ShiroUtil.getPrincipalProperty("id")).and("qid", "=", questionId));
|
||||
|
||||
//每题的回答记录
|
||||
Map<String, List<Question_reply>> issueReplies = replyIssues.stream().collect(Collectors.groupingBy(v -> v.getIssueId()));
|
||||
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(x -> x.getRwid()).collect(Collectors.toSet());
|
||||
|
||||
//正确的选项
|
||||
Set<String> correctOptionIds = issues.stream().filter(x -> x.getIid().equals(k)).findFirst().map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(c -> c.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
//该题的分数
|
||||
double sum = issues.stream().filter(x -> x.getIid().equals(k)).mapToDouble(x -> x.getFraction() == null ? 0 : x.getFraction()).sum();
|
||||
// score.addAndGet(sum);
|
||||
score.updateAndGet(v1 -> (float) (v1 + sum));
|
||||
}
|
||||
});
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(answerNum + 1);
|
||||
questionUserScore.setScore(score.get());
|
||||
dao.insert(questionUserScore);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package io.v.nutz.question.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.utils.DateUtil;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
@@ -18,7 +19,7 @@ import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.sys.models.Sys_task;
|
||||
import io.v.nutz.sys.services.SysTaskService;
|
||||
import io.v.nutz.task.services.TaskPlatformService;
|
||||
import io.v.nutz.util.ShiroUtil;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
@@ -30,18 +31,18 @@ import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -98,6 +99,7 @@ public class QuestionMangeController {
|
||||
sql.setCondition(cnd);
|
||||
return Result.success().addData(questionService.listPage(pageForm.getPageNumber(), pageForm.getPageSize(), sql));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
@@ -114,8 +116,6 @@ public class QuestionMangeController {
|
||||
@RequiresPermissions("question.mange")
|
||||
public Object upStatus(String qid, Integer flag) {
|
||||
try {
|
||||
Assert.notBlank(qid);
|
||||
Assert.notNull(flag);
|
||||
dao.update(Question.class, Chain.make("qflag", flag), Cnd.where("qid", "=", qid));
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
@@ -131,13 +131,23 @@ public class QuestionMangeController {
|
||||
public Object doAdd(@Param("question") Question question) {
|
||||
try {
|
||||
question.setQflag(1);
|
||||
question.setQctime(DateUtil.getDate());
|
||||
question.setQctime(DateUtil.now());
|
||||
question.setQcreator(ShiroUtil.getPrincipalProperty("id").toString());
|
||||
|
||||
//这里要额外判断下随机模式下的答题天数
|
||||
if (question.getQlx() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay < 1) {
|
||||
//同一天
|
||||
question.setCanRepeatedAnswer(false);
|
||||
question.setCanRepeatedAnswerNum(null);
|
||||
}
|
||||
}
|
||||
|
||||
Question insert = questionService.insert(question);
|
||||
|
||||
int i = 1;
|
||||
|
||||
for (Question_issue issue : question.getIssues()) {
|
||||
issue.setIid(Strings.isNotBlank(issue.getIid()) ? issue.getIid() : R.UU32());
|
||||
issue.setIqid(insert.getQid());
|
||||
@@ -145,7 +155,6 @@ public class QuestionMangeController {
|
||||
if (question.getCtMode() == 2) {
|
||||
issue.setIpxbh(i);
|
||||
}
|
||||
|
||||
Question_issue issueInsert = questionIssueService.insert(issue);
|
||||
int j = 1;
|
||||
for (Question_wor wor : issue.getWors()) {
|
||||
@@ -157,9 +166,7 @@ public class QuestionMangeController {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
raffleTask(question.getQid());
|
||||
|
||||
// raffleTask(question.getQid());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -173,6 +180,17 @@ public class QuestionMangeController {
|
||||
@ViReturn
|
||||
@RequiresPermissions("question.mange")
|
||||
public Object doEdit(@Param("question") Question question) {
|
||||
//这里要额外判断下随机模式下的答题天数
|
||||
if (question.getQlx() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay < 1) {
|
||||
//同一天
|
||||
question.setCanRepeatedAnswer(false);
|
||||
question.setCanRepeatedAnswerNum(null);
|
||||
}
|
||||
}
|
||||
questionService.update(question);
|
||||
|
||||
List<Question_issue> oldIssues = dao.query(Question_issue.class, Cnd.where("iqid", "=", question.getQid()));
|
||||
@@ -182,11 +200,9 @@ public class QuestionMangeController {
|
||||
for (int i = 0; i < issues.size(); i++) {
|
||||
Question_issue issue = issues.get(i);
|
||||
issue.setIqid(question.getQid());
|
||||
// if (question.getCtMode() == 2) {
|
||||
issue.setIpxbh(i + 1);
|
||||
// }
|
||||
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
||||
System.out.println(Json.toJson(issue));
|
||||
if (question.getCtMode() == 2) {
|
||||
issue.setIpxbh(i + 1);
|
||||
}
|
||||
dao.insertOrUpdate(issue);
|
||||
List<Question_wor> wors = issue.getWors();
|
||||
for (int i1 = 0; i1 < wors.size(); i1++) {
|
||||
@@ -241,7 +257,7 @@ public class QuestionMangeController {
|
||||
|
||||
|
||||
/**
|
||||
* 删除文具按
|
||||
* 删除问卷
|
||||
*
|
||||
* @param qid qid
|
||||
* @return {@link Object}
|
||||
@@ -311,13 +327,23 @@ public class QuestionMangeController {
|
||||
@At("/modifyBasicInfo")
|
||||
@RequiresPermissions("question.mange")
|
||||
@ViReturn
|
||||
public Object modifyBasicInfo(Question question) {
|
||||
public Object modifyBasicInfo(@Param("question") Question question) {
|
||||
try {
|
||||
Assert.notNull(question);
|
||||
if (question.getQlx() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay < 1) {
|
||||
//同一天
|
||||
question.setCanRepeatedAnswer(false);
|
||||
question.setCanRepeatedAnswerNum(null);
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(question.getQid())) {
|
||||
dao.updateIgnoreNull(question);
|
||||
} else {
|
||||
question.setQctime(cn.hutool.core.date.DateUtil.today());
|
||||
question.setQctime(DateUtil.today());
|
||||
question.setQcreator(ShiroUtil.getUserId());
|
||||
question.setQflag(1);
|
||||
dao.insert(question);
|
||||
@@ -373,7 +399,7 @@ public class QuestionMangeController {
|
||||
Question_issue issue = issueList.get(i);
|
||||
issue.setIqid(questionId);
|
||||
// if (question.getCtMode() == 2) {
|
||||
issue.setIpxbh(i + 1);
|
||||
issue.setIpxbh(i + 1);
|
||||
// }
|
||||
dao.insertOrUpdate(issue);
|
||||
List<Question_wor> wors = issue.getWors();
|
||||
@@ -418,41 +444,41 @@ public class QuestionMangeController {
|
||||
* @param questionId 问题id
|
||||
*/
|
||||
private void raffleTask(String questionId) {
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
|
||||
//每天凌晨一点执行
|
||||
String cron = "0 0 1 * * ?";
|
||||
cron = "30 * * * * ? ";
|
||||
String cronData = Json.toJson(Map.of("questionId", questionId));
|
||||
//删除之前的任务再添加
|
||||
List<Sys_task> oldTasks = dao.query(Sys_task.class, Cnd.where("data", "like", "%" + questionId + "%"));
|
||||
for (Sys_task task : oldTasks) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
sysTaskService.delete(task.getId());
|
||||
}
|
||||
|
||||
String jobClass = "io.v.nutz.task.job.question.QuestionRaffleJob";
|
||||
Sys_task task = sysTaskService.fetch(Cnd.where("jobClass", "=", jobClass).and("data", "=", cronData));
|
||||
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
//需要抽奖
|
||||
if (question.getIsRaffle() != null && question.getIsRaffle()) {
|
||||
if (task != null) {
|
||||
|
||||
String dateFormat = "ss mm HH dd MM ? yyyy";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
|
||||
|
||||
List<Question.RaffleRule> raffleRules = question.getRaffleRule();
|
||||
for (Question.RaffleRule raffleRule : raffleRules) {
|
||||
Date raffleTime = raffleRule.getRaffleTime();
|
||||
String formatTimeStr = sdf.format(raffleTime);
|
||||
|
||||
NutMap raffleRuleMap = Lang.obj2nutmap(raffleRule);
|
||||
raffleRuleMap.put("questionId", questionId);
|
||||
|
||||
String cronData = Json.toJson(raffleRuleMap);
|
||||
|
||||
Sys_task task = new Sys_task();
|
||||
task.setName(HtmlUtil.cleanHtmlTag(question.getQtitle()) + "问卷调查抽奖任务");
|
||||
task.setCron(cron);
|
||||
sysTaskService.updateIgnoreNull(task);
|
||||
if (taskPlatformService.isExist(task.getId(), task.getId())) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
}
|
||||
} else {
|
||||
task = new Sys_task();
|
||||
task.setName(HtmlUtil.cleanHtmlTag(question.getQsm()) + "问卷调查抽奖任务");
|
||||
task.setJobClass(jobClass);
|
||||
task.setNote("问卷调查抽奖任务");
|
||||
task.setCron(cron);
|
||||
task.setCron(formatTimeStr);
|
||||
task.setData(cronData);
|
||||
task.setDisabled(false);
|
||||
sysTaskService.insert(task);
|
||||
}
|
||||
taskPlatformService.add(task.getId(), task.getId(), task.getJobClass(), task.getCron(),
|
||||
task.getNote(), task.getData());
|
||||
} else {
|
||||
if (task != null) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
sysTaskService.delete(task.getId());
|
||||
taskPlatformService.add(task.getId(), task.getId(), task.getJobClass(), task.getCron(),
|
||||
task.getNote(), task.getData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package io.v.nutz.question.controller;
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.base.utils.Html2Text;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
@@ -14,7 +12,6 @@ import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.sys.models.Sys_union;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
@@ -25,15 +22,12 @@ import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -75,17 +69,13 @@ public class QuestionPollAnalysisController {
|
||||
@Param("pageNumber") int pageNumber,
|
||||
@Param("pageSize") int pageSize) {
|
||||
try {
|
||||
Sql sql = Sqls.create("""
|
||||
select r.*,u.username,u.unionname,u.unitname,u.mobile from question_reply r left join `user` u on r.userId = u.id $condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("rwid", "=", wid);
|
||||
if (Strings.isNotBlank(searchKeyword)) {
|
||||
cnd.where().andLike("rval", searchKeyword);
|
||||
}
|
||||
cnd.desc("rtime");
|
||||
sql.setCondition(cnd);
|
||||
return Result.success().addData(questionReplyService.listPage(pageNumber, pageSize, sql));
|
||||
return Result.success().addData(questionReplyService.listPage(pageNumber, pageSize, cnd));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
@@ -166,7 +156,6 @@ public class QuestionPollAnalysisController {
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.pollAnalysis")
|
||||
public void doExport(@Param(value = "questionId",required = false) String questionId, HttpServletResponse response) {
|
||||
try {
|
||||
@@ -211,52 +200,6 @@ public class QuestionPollAnalysisController {
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("question.pollAnalysis")
|
||||
public void doExportByUnion(@Param(value = "questionId",required = false) String questionId, HttpServletResponse response) throws IOException {
|
||||
//查询所有工会
|
||||
List<Sys_union> unionList = questionService.dao().query(Sys_union.class, Cnd.NEW());
|
||||
//查询所有答复
|
||||
Sql sql = Sqls.create("""
|
||||
select r.*,u.unionId,u.username,u.mobile from question_reply r left join `user` u on r.userId = u.id where r.qid = @qid and unionId is not null
|
||||
""").setParam("qid", questionId);
|
||||
List<NutMap> replyList = questionService.listMap(sql);
|
||||
//查询所有题目
|
||||
List<Question_issue> issueList = questionService.dao().query(Question_issue.class, Cnd.where("iqid", "=", questionId).asc("ipxbh"));
|
||||
|
||||
//设置第一行
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("", "unionname", 30));
|
||||
for (int i = 0; i < issueList.size(); i++) {
|
||||
exportEntities.add(new ExcelExportEntity(HtmlUtil.cleanHtmlTag(issueList.get(i).getIname()), i + "", 30));
|
||||
}
|
||||
exportEntities.add(new ExcelExportEntity("填报人姓名", "username", 30));
|
||||
exportEntities.add(new ExcelExportEntity("填报人电话", "mobile", 30));
|
||||
|
||||
List<NutMap> result = new ArrayList<>();
|
||||
unionList.forEach(item -> {
|
||||
NutMap nutMap = new NutMap();
|
||||
nutMap.put("unionname", item.getUnionname());
|
||||
for (int i = 0; i < issueList.size(); i++) {
|
||||
int finalI = i;
|
||||
NutMap map = replyList.stream().filter(o -> o.getString("unionid").equals(item.getId()) && o.getString("issueId").equals(issueList.get(finalI).getIid())).findFirst().orElse(null);
|
||||
nutMap.put(i + "", map != null ? map.getString("rval") : "");
|
||||
nutMap.put("username", map != null ? map.getString("username") : "");
|
||||
nutMap.put("mobile", map != null ? map.getString("mobile") : "");
|
||||
}
|
||||
result.add(nutMap);
|
||||
});
|
||||
|
||||
Question question = questionService.fetch(questionId);
|
||||
String fileName = question.getQtitle() + "按分工会导出";
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xls").getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), exportEntities, result);
|
||||
workbook.write(response.getOutputStream());
|
||||
workbook.close();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ExportEntity {
|
||||
@Excel(name = "序号")
|
||||
|
||||
+20
-3
@@ -75,7 +75,24 @@ public class QuestionUnionIntentionalChoiceController {
|
||||
SELECT
|
||||
un.id unionId,
|
||||
un.unionName,
|
||||
(select count(1) from user where member = 1 and unionid = un.id) AS teacherSum,
|
||||
(select count(1) from "user" where member = 1 and unionid = un.id) AS teacherSum1,
|
||||
(
|
||||
select
|
||||
count(1)
|
||||
from
|
||||
activity_user_scope aus
|
||||
left join "user" u on u.id = aus.userId
|
||||
where
|
||||
groupId in (
|
||||
select
|
||||
activityUserScopeId
|
||||
from
|
||||
question
|
||||
where
|
||||
qid = @questionId
|
||||
)
|
||||
and u.unionId = un.id
|
||||
) as teacherSum,
|
||||
(
|
||||
SELECT
|
||||
count( DISTINCT r.userId )
|
||||
@@ -92,7 +109,7 @@ public class QuestionUnionIntentionalChoiceController {
|
||||
""").setParam("questionId", questionId);
|
||||
|
||||
CndPlus cndPlus = CndPlus.create();
|
||||
cndPlus.andExcludeEmpty("un.id", "=", unionId);
|
||||
cndPlus.andEX("un.id", "=", unionId);
|
||||
sql.setCondition(cndPlus);
|
||||
List<NutMap> unionList = questionService.listMap(sql);
|
||||
|
||||
@@ -253,7 +270,7 @@ public class QuestionUnionIntentionalChoiceController {
|
||||
$condition
|
||||
""").setParam("questionId", questionId);
|
||||
|
||||
cnd.andExcludeEmpty("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.groupBy("u.id");
|
||||
cnd.desc("u.unioncode");
|
||||
sql.setCondition(cnd);
|
||||
|
||||
@@ -4,6 +4,7 @@ import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -51,7 +52,7 @@ public class Question implements Serializable {
|
||||
|
||||
@Column
|
||||
@Comment("说明")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 2000)
|
||||
@ColDefine(customType = "text")
|
||||
private String qsm;
|
||||
|
||||
@Column
|
||||
@@ -69,11 +70,6 @@ public class Question implements Serializable {
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String qdtjssj;
|
||||
|
||||
@Column
|
||||
@Comment("活动时间内可答题总次数")
|
||||
@ColDefine(type = ColType.INT, width = 2)
|
||||
private Integer answerTotalSum;
|
||||
|
||||
@Many(field = "iqid")
|
||||
private List<Question_issue> issues;
|
||||
|
||||
@@ -100,16 +96,16 @@ public class Question implements Serializable {
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ctMode;
|
||||
|
||||
@Column
|
||||
@Comment("单次出题数量")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ctNum;
|
||||
|
||||
@Column
|
||||
@Comment("是否抽奖")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isRaffle;
|
||||
|
||||
@Column
|
||||
@Comment("抽奖时间")
|
||||
@ColDefine(type = ColType.DATETIME)
|
||||
private Date raffleTime;
|
||||
|
||||
@Column
|
||||
@Comment("多少分可以抽奖")
|
||||
@ColDefine(type = ColType.INT)
|
||||
@@ -120,5 +116,59 @@ public class Question implements Serializable {
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer raffleWinnerUserNum;
|
||||
|
||||
@Column
|
||||
@Comment("题目顺序打乱")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean disruptingOrder;
|
||||
|
||||
@Column
|
||||
@Comment("随机单次出题数量")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ranDomSingleIssueNum;
|
||||
|
||||
@Column
|
||||
@Comment("总共随机次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer ranDomSum;
|
||||
|
||||
@Column
|
||||
@Comment("是否多次答")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean canRepeatedAnswer;
|
||||
|
||||
@Column
|
||||
@Comment("多次答数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer canRepeatedAnswerNum;
|
||||
|
||||
@Column
|
||||
@Comment("得分统计(重复答题允许下 1.保存最高分 2.保存最新得分)")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer calcScoreMode;
|
||||
|
||||
@Column
|
||||
@Comment("抽奖规则")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<RaffleRule> raffleRule;
|
||||
|
||||
/**
|
||||
* 抽奖规则
|
||||
*/
|
||||
@Data
|
||||
public static class RaffleRule {
|
||||
//开始答题时间
|
||||
private Date startAnswerDate;
|
||||
|
||||
//结束答题时间
|
||||
private Date endAnswerDate;
|
||||
|
||||
//抽奖时间
|
||||
private Date raffleTime;
|
||||
|
||||
//抽奖分数
|
||||
private Integer raffleScore;
|
||||
|
||||
//抽奖人数
|
||||
private Integer raffleWinnerUserNum;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public class QuestionAnswerUserScore {
|
||||
|
||||
@Column
|
||||
@Comment("该题得分")
|
||||
@ColDefine(type = ColType.FLOAT)
|
||||
private Float subjectScore;
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer subjectScore;
|
||||
|
||||
@Column
|
||||
@Comment("用户id")
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package io.v.nutz.question.model;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Comment("问卷随机题目")
|
||||
@Table
|
||||
public class QuestionRandomIssue extends BaseModel {
|
||||
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("问卷的id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String questionId;
|
||||
|
||||
@Column
|
||||
@Comment("用户id")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@Comment("题目")
|
||||
@ColDefine(type = ColType.MYSQL_JSON)
|
||||
private List<String> issueIds;
|
||||
|
||||
@Column
|
||||
@Comment("回答次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer num;
|
||||
|
||||
@Column
|
||||
@Comment("是否回答完成")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isFinish;
|
||||
|
||||
@Column
|
||||
@Comment("显示日期")
|
||||
@ColDefine(type = ColType.DATE)
|
||||
private Date displayDate;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.v.nutz.question.model;
|
||||
|
||||
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;
|
||||
|
||||
@@ -12,9 +14,10 @@ import java.util.Date;
|
||||
* @author jug
|
||||
* @date 2023/06/20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Table
|
||||
public class QuestionUserScore {
|
||||
public class QuestionUserScore extends BaseModel {
|
||||
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@@ -28,8 +31,8 @@ public class QuestionUserScore {
|
||||
|
||||
@Column
|
||||
@Comment("得分")
|
||||
@ColDefine(type = ColType.FLOAT)
|
||||
private Float score;
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer score;
|
||||
|
||||
@Column
|
||||
@Comment("用户id")
|
||||
@@ -46,4 +49,13 @@ public class QuestionUserScore {
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer answerNum;
|
||||
|
||||
@Column
|
||||
@Comment("随机次数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer randomNum;
|
||||
|
||||
@Column
|
||||
@Comment("显示日期(只针对定时定题)")
|
||||
@ColDefine(type = ColType.DATE)
|
||||
private Date displayDate;
|
||||
}
|
||||
|
||||
@@ -37,4 +37,9 @@ public class QuestionWinner {
|
||||
@ColDefine(type = ColType.DATE)
|
||||
private Date winDate;
|
||||
|
||||
@Column
|
||||
@Comment("分数")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer score;
|
||||
|
||||
}
|
||||
|
||||
@@ -101,8 +101,8 @@ public class Question_issue implements Serializable {
|
||||
@Column
|
||||
@Comment("该题分数")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.FLOAT, width = 4, precision = 1)
|
||||
private Float fraction;
|
||||
@ColDefine(type = ColType.INT, width = 4)
|
||||
private Integer fraction;
|
||||
|
||||
@Column
|
||||
@Comment("显示日期")
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.integration.json4excel.annotation.J4EIgnore;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,4 +86,6 @@ public class Question_reply implements Serializable {
|
||||
|
||||
@One(field = "rwid", key = "wid")
|
||||
private Question_wor wor;
|
||||
|
||||
private List<String> userSelect;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package io.v.nutz.question.service;
|
||||
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.QuestionUserScore;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 得分
|
||||
*/
|
||||
public interface QuestionAnswerRankingService extends BaseService<QuestionUserScore> {
|
||||
|
||||
Pagination pageData(PageForm pageForm,
|
||||
String questionId,
|
||||
String unionId,
|
||||
String unitId,
|
||||
String answerDate);
|
||||
|
||||
void exportXlsx(String questionId, OutputStream os) throws IOException;
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.v.nutz.question.service;
|
||||
|
||||
|
||||
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_reply;
|
||||
import io.v.nutz.service.ViService;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.v.nutz.question.service;
|
||||
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_reply;
|
||||
import io.v.nutz.service.ViService;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
@@ -15,4 +16,29 @@ public interface QuestionService extends ViService<Question> {
|
||||
|
||||
NutMap getRankData(String qid);
|
||||
|
||||
|
||||
/**
|
||||
* 答题
|
||||
*
|
||||
* @param repliesArray 记录
|
||||
* @param questionId 问卷ID
|
||||
* @param isSave 是否保存
|
||||
*/
|
||||
void saveAnswer(Question_reply[] repliesArray, String questionId, Boolean isSave);
|
||||
|
||||
|
||||
/**
|
||||
* 是否同天 仅限随机
|
||||
* @param questionId 问卷ID
|
||||
* @return
|
||||
*/
|
||||
boolean isSameDay(String questionId);
|
||||
|
||||
/**
|
||||
* 是否同天 仅限随机
|
||||
* @param startTimeTs 开始时间
|
||||
* @param endTimeTs 结束时间
|
||||
* @return
|
||||
*/
|
||||
boolean isSameDay(long startTimeTs,long endTimeTs);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,422 @@
|
||||
package io.v.nutz.question.service.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.page.Pagination;
|
||||
import io.v.nutz.base.service.impl.BaseServiceImpl;
|
||||
import io.v.nutz.modules.models.PageForm;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.QuestionUserScore;
|
||||
import io.v.nutz.question.service.QuestionAnswerRankingService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class QuestionAnswerRankingServiceImpl extends BaseServiceImpl<QuestionUserScore> implements QuestionAnswerRankingService {
|
||||
public QuestionAnswerRankingServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, String questionId, String unionId, String unitId, String answerDate) {
|
||||
Question question = dao().fetch(Question.class, questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
GROUP_CONCAT( qus.answerNum, '(', qus.score, ')' ORDER BY qus.answerNum SEPARATOR ', ' ) AS everyRandomScore,
|
||||
sum( score ) AS score,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
} else {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND answerNum = max( qus.answerNum )\s
|
||||
AND questionId = qus.questionId
|
||||
) as lastAnswerNumScore,
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND score = max( qus.score )\s
|
||||
AND questionId = qus.questionId
|
||||
) as maxAnswerScore,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
qus.answerNum,
|
||||
max( qus.answerNum ),
|
||||
min( qus.answerNum ),
|
||||
qus.score,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
List<NutMap> list = pagination.getList();
|
||||
for (NutMap map : list) {
|
||||
map.put("score", map.getInt(question.getCalcScoreMode() == 1 ? "maxAnswerScore" : "lastAnswerNumScore"));
|
||||
}
|
||||
return pagination;
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.andEX("u.unionid", "=", unionId);
|
||||
cnd.andEX("u.unitid", "=", unitId);
|
||||
cnd.andEX("qus.answerDate", "=", answerDate);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(Cnd.exps("u.loginname", "like", "%" + pageForm.getSearchKeyword() + "%").or("u.username", "like", "%" + pageForm.getSearchKeyword() + "%"));
|
||||
}
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
return listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
}
|
||||
return new Pagination();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportXlsx(String questionId, OutputStream os) throws IOException {
|
||||
Question question = dao().fetch(Question.class, questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("答题日期", "answerDate", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
GROUP_CONCAT( qus.answerNum, '(', qus.score, ')' ORDER BY qus.answerNum SEPARATOR ', ' ) AS everyRandomScore,
|
||||
sum( score ) AS score,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("每轮分数", "everyRandomScore", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
|
||||
} else {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND answerNum = max( qus.answerNum )\s
|
||||
AND questionId = qus.questionId
|
||||
) as lastAnswerNumScore,
|
||||
(
|
||||
SELECT
|
||||
score\s
|
||||
FROM
|
||||
question_user_score\s
|
||||
WHERE
|
||||
userId = qus.userId\s
|
||||
AND answerDate = qus.answerDate\s
|
||||
AND score = max( qus.score )\s
|
||||
AND questionId = qus.questionId
|
||||
) as maxAnswerScore,
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) AS answerDate,
|
||||
qus.answerNum,
|
||||
max( qus.answerNum ),
|
||||
min( qus.answerNum ),
|
||||
qus.score,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile,
|
||||
q.ctMode,
|
||||
q.calcScoreMode
|
||||
FROM
|
||||
`question_user_score` qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
LEFT JOIN question q ON q.qid = qus.questionId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
for (NutMap map : list) {
|
||||
map.put("score", map.getInt(question.getCalcScoreMode() == 1 ? "maxAnswerScore" : "lastAnswerNumScore"));
|
||||
}
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
exportEntities.add(new ExcelExportEntity("答题日期", "answerDate", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
qus.userId,
|
||||
DATE_FORMAT( qus.answerDate, '%Y-%m-%d' ) as answerDate,
|
||||
qus.score,
|
||||
qus.answerNum,
|
||||
u.loginname,
|
||||
u.username,
|
||||
u.sex,
|
||||
u.unitname,
|
||||
u.unionname,
|
||||
u.mobile
|
||||
FROM
|
||||
question_user_score qus
|
||||
LEFT JOIN `user` u ON u.id = qus.userId
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("qus.questionId", "=", questionId);
|
||||
|
||||
cnd.groupBy("qus.answerDate", "qus.userId");
|
||||
cnd.asc("qus.answerDate").asc("u.unionid").asc("u.id");
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
cnd.and("qus.score", "in", Sqls.create("select max(score) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
cnd.and("qus.answerNum", "in", Sqls.create("select max(answerNum) from question_user_score where userId = qus.userId and questionId = qus.questionId and answerDate = qus.answerDate"));
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> exportEntities = new ArrayList<>();
|
||||
exportEntities.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
exportEntities.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属单位", "unitname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("所属工会", "unionname", 20));
|
||||
exportEntities.add(new ExcelExportEntity("联系方式", "mobile", 20));
|
||||
exportEntities.add(new ExcelExportEntity("分数", "score", 20));
|
||||
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, exportEntities, list);
|
||||
workbook.write(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class QuestionReplyServiceImpl extends ViServiceImpl<Question_reply> impl
|
||||
String wiid = questionWor.getWiid();
|
||||
|
||||
Question_issue subject = dao().fetch(Question_issue.class, Cnd.where("iid", "=", wiid));
|
||||
Float fraction = subject.getFraction();
|
||||
Integer fraction = subject.getFraction();
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
@@ -108,7 +108,7 @@ public class QuestionReplyServiceImpl extends ViServiceImpl<Question_reply> impl
|
||||
if (Arrays.equals(correctOptionIdArray, userSelectedOptionIdArray)) {
|
||||
answerUserScore.setSubjectScore(fraction);
|
||||
} else {
|
||||
answerUserScore.setSubjectScore(0f);
|
||||
answerUserScore.setSubjectScore(0);
|
||||
}
|
||||
dao().insert(answerUserScore);
|
||||
|
||||
|
||||
@@ -1,23 +1,33 @@
|
||||
package io.v.nutz.question.service.impl;
|
||||
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.Question_issue;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.v.nutz.question.model.*;
|
||||
import io.v.nutz.question.service.QuestionIssueService;
|
||||
import io.v.nutz.question.service.QuestionReplyService;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.question.service.QuestionWorService;
|
||||
import io.v.nutz.service.impl.ViServiceImpl;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.entity.Record;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = "Zgfw_question")
|
||||
public class QuestionServiceImpl extends ViServiceImpl<Question> implements QuestionService {
|
||||
@@ -81,4 +91,176 @@ public class QuestionServiceImpl extends ViServiceImpl<Question> implements Ques
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveAnswer(Question_reply[] repliesArray, String questionId, Boolean isSave) {
|
||||
//删除上一次的答题记录
|
||||
//此处需判断 如果是有分多天 随机多次就要按条件删除
|
||||
|
||||
//问卷信息包含题目选项
|
||||
Question question = getQuestion(questionId);
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
//删除今天的之前的答题记录
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("DATE(rtime)", "=", DateUtil.today()));
|
||||
} else if (question.getCtMode() == 2) {
|
||||
DateTime startTime = DateUtil.date(question.getStartTime());
|
||||
DateTime endTime = DateUtil.date(question.getEndTime());
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
if (betweenDay > 0) {
|
||||
//多天随机
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("DATE(rtime)", "=", DateUtil.today()));
|
||||
} else {
|
||||
//一天多次随机 删除保存的
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("DATE(rtime)", "=", DateUtil.today()).and("save", "=", 1));
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
dao().clear(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
}
|
||||
|
||||
List<Question_reply> replyList = new ArrayList<>();
|
||||
for (Question_reply reply : repliesArray) {
|
||||
if (Lang.isNotEmpty(reply.getUserSelect())) {
|
||||
for (String userSelect : reply.getUserSelect()) {
|
||||
Question_reply questionReply = new Question_reply();
|
||||
questionReply.setRwid(userSelect);
|
||||
questionReply.setIssueId(reply.getIssueId());
|
||||
questionReply.setUserId(ShiroUtil.getUserId());
|
||||
questionReply.setRtime(DateUtil.now());
|
||||
questionReply.setRwid(userSelect);
|
||||
questionReply.setQid(questionId);
|
||||
questionReply.setSave(isSave);
|
||||
replyList.add(questionReply);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
insert(replyList);
|
||||
|
||||
//判断是否提交 提交则计算此次分数
|
||||
|
||||
if (!isSave) {
|
||||
|
||||
//得分
|
||||
AtomicInteger sum = new AtomicInteger();
|
||||
|
||||
//常规模式计算全部题目的分数
|
||||
if (question.getCtMode() == 3) {
|
||||
//每题的回答记录
|
||||
List<Question_reply> replies = dao().query(Question_reply.class, Cnd.where("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("userId", "=", ShiroUtil.getUserId()));
|
||||
Map<String, List<Question_reply>> issueReplies = replies.stream().collect(Collectors.groupingBy(Question_reply::getIssueId));
|
||||
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(Question_reply::getRwid).collect(Collectors.toSet());
|
||||
//正确答案
|
||||
Optional<Question_issue> issueOptional = question.getIssues().stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
//查询之前的回答记录
|
||||
int count = dao().count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
dao().insert(questionUserScore);
|
||||
} else if (question.getCtMode() == 1) {
|
||||
//每题的回答记录
|
||||
QuestionRandomIssue randomIssue = dao().fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
List<String> issueIds = randomIssue.getIssueIds();
|
||||
List<Question_reply> replies = dao().query(Question_reply.class, Cnd.where("issueId", "in", issueIds).and("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
Map<String, List<Question_reply>> issueReplies = replies.stream().collect(Collectors.groupingBy(Question_reply::getIssueId));
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(Question_reply::getRwid).collect(Collectors.toSet());
|
||||
//正确答案
|
||||
Optional<Question_issue> issueOptional = question.getIssues().stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
//查询之前的回答记录
|
||||
int count = dao().count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
questionUserScore.setDisplayDate(DateUtil.parseDate(DateUtil.today()));
|
||||
dao().insert(questionUserScore);
|
||||
} else if (question.getCtMode() == 2) {
|
||||
|
||||
//每题的回答记录
|
||||
QuestionRandomIssue randomIssue = dao().fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()).desc("num"));
|
||||
List<String> issueIds = randomIssue.getIssueIds();
|
||||
List<Question_reply> replies = dao().query(Question_reply.class, Cnd.where("issueId", "in", issueIds).and("qid", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
Map<String, List<Question_reply>> issueReplies = replies.stream().collect(Collectors.groupingBy(Question_reply::getIssueId));
|
||||
issueReplies.forEach((k, v) -> {
|
||||
//用户回答的选项
|
||||
Set<String> userReplyOptionIds = v.stream().map(Question_reply::getRwid).collect(Collectors.toSet());
|
||||
//正确答案
|
||||
Optional<Question_issue> issueOptional = question.getIssues().stream().filter(x -> x.getIid().equals(k)).findFirst();
|
||||
Set<String> correctOptionIds = issueOptional.map(x -> x.getWors().stream().filter(c -> c.getCorrect() != null && c.getCorrect()).map(z -> z.getWid()).collect(Collectors.toSet())).orElse(null);
|
||||
if (userReplyOptionIds.equals(correctOptionIds)) {
|
||||
sum.addAndGet(issueOptional.map(i -> i.getFraction()).orElse(0));
|
||||
}
|
||||
});
|
||||
|
||||
//同一天
|
||||
//查询之前的回答记录
|
||||
int count = dao().count(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
|
||||
QuestionUserScore questionUserScore = new QuestionUserScore();
|
||||
questionUserScore.setQuestionId(questionId);
|
||||
questionUserScore.setUserId(ShiroUtil.getUserId());
|
||||
questionUserScore.setAnswerDate(new Date());
|
||||
questionUserScore.setAnswerNum(count + 1);
|
||||
questionUserScore.setScore(sum.get());
|
||||
questionUserScore.setDisplayDate(DateUtil.parseDate(DateUtil.today()));
|
||||
dao().insert(questionUserScore);
|
||||
}
|
||||
|
||||
//随机题库设为已完成
|
||||
if (question.getCtMode() == 3) {
|
||||
//常规模式下不需要判断次数
|
||||
dao().update(QuestionRandomIssue.class, Chain.make("isFinish", 1), Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()));
|
||||
} else if (question.getCtMode() == 1) {
|
||||
//定时定题需要加上日期的条件
|
||||
dao().update(QuestionRandomIssue.class, Chain.make("isFinish", 1), Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()));
|
||||
} else if (question.getCtMode() == 2) {
|
||||
//随机模式 要判断是否为同一天
|
||||
|
||||
QuestionRandomIssue randomIssue = dao().fetch(QuestionRandomIssue.class, Cnd.where("questionId", "=", questionId).and("userId", "=", ShiroUtil.getUserId()).and("displayDate", "=", DateUtil.today()).desc("num"));
|
||||
randomIssue.setIsFinish(true);
|
||||
dao().update(randomIssue, "isFinish");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameDay(String questionId) {
|
||||
Question question = dao().fetch(Question.class, questionId);
|
||||
return isSameDay(question.getStartTime(), question.getEndTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameDay(long startTimeTs, long endTimeTs) {
|
||||
DateTime startTime = DateUtil.date(startTimeTs);
|
||||
DateTime endTime = DateUtil.date(endTimeTs);
|
||||
long betweenDay = DateUtil.betweenDay(startTime, endTime, true);
|
||||
return betweenDay == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package io.v.nutz.task.question;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import io.v.nutz.question.model.Question;
|
||||
import io.v.nutz.question.model.QuestionUserScore;
|
||||
import io.v.nutz.question.model.QuestionWinner;
|
||||
import io.v.nutz.question.service.QuestionService;
|
||||
import io.v.nutz.sys.models.Sys_task;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 问卷抽奖定时任务
|
||||
*
|
||||
* @author jug
|
||||
* @date 2023/06/12
|
||||
*/
|
||||
@IocBean
|
||||
public class QuestionRaffleJob implements Job {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@Inject
|
||||
private QuestionService questionService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||
JobDataMap data = context.getJobDetail().getJobDataMap();
|
||||
DateTime startAnswerDate = DateUtil.parseDateTime(data.getString("startAnswerDate"));
|
||||
DateTime endAnswerDate = DateUtil.parseDateTime(data.getString("endAnswerDate"));
|
||||
DateTime raffleTime = DateUtil.parseDate(data.getString("raffleTime"));
|
||||
//抽奖分数
|
||||
int raffleScore = data.getInt("raffleScore");
|
||||
//中奖者人数
|
||||
int raffleWinnerUserNum = data.getInt("raffleWinnerUserNum");
|
||||
//问卷id
|
||||
String questionId = data.getString("questionId");
|
||||
|
||||
Question question = dao.fetch(Question.class, questionId);
|
||||
|
||||
|
||||
//已中奖的用户
|
||||
List<QuestionWinner> winners = dao.query(QuestionWinner.class, Cnd.where("questionId", "=", questionId));
|
||||
List<String> hasWinnUserIds = winners.stream().map(v -> v.getUserId()).collect(Collectors.toList());
|
||||
|
||||
//得分记录
|
||||
List<QuestionUserScore> questionUserScores = dao.query(QuestionUserScore.class, Cnd.where("questionId", "=", questionId).andEX("userId", "not in", hasWinnUserIds));
|
||||
|
||||
//抽奖规则时间范围内的记录
|
||||
List<QuestionUserScore> thisTimeQuestionUserScores = questionUserScores.stream().filter(s -> startAnswerDate.isBeforeOrEquals(DateUtil.date(s.getCreatedAt())) && endAnswerDate.isAfter(DateUtil.date(s.getCreatedAt()))).collect(Collectors.toList());
|
||||
|
||||
//本次中奖用户
|
||||
List<String> winnerUserIds = new ArrayList<>();
|
||||
|
||||
//每个用户的分数
|
||||
List<NutMap> userScoreMap = new ArrayList<>();
|
||||
|
||||
if (question.getCtMode() == 1) {
|
||||
Map<String, List<QuestionUserScore>> userScoreListMap = thisTimeQuestionUserScores.stream().collect(Collectors.groupingBy(v -> v.getUserId()));
|
||||
userScoreListMap.forEach((userId, v) -> {
|
||||
Map<Date, List<QuestionUserScore>> userDayScoreListMap = v.stream().collect(Collectors.groupingBy(x -> x.getAnswerDate()));
|
||||
AtomicInteger sumScore = new AtomicInteger();
|
||||
userDayScoreListMap.forEach((day, v1) -> {
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
int score = v1.stream().mapToInt(s -> s.getScore()).max().orElse(0);
|
||||
sumScore.addAndGet(score);
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
int maxAnswerNum = v1.stream().mapToInt(s -> s.getAnswerNum()).max().orElse(1);
|
||||
Integer score = v1.stream().filter(s -> s.getAnswerNum() == maxAnswerNum).findFirst().map(s -> s.getScore()).orElse(0);
|
||||
sumScore.addAndGet(score);
|
||||
}
|
||||
});
|
||||
userScoreMap.add(NutMap.NEW().addv("userId", userId).addv("score", sumScore.get()));
|
||||
});
|
||||
} else if (question.getCtMode() == 2) {
|
||||
if (questionService.isSameDay(question.getStartTime(), question.getEndTime())) {
|
||||
thisTimeQuestionUserScores.stream().collect(Collectors.groupingBy(v -> v.getUserId(), Collectors.summingInt(v -> v.getScore()))).forEach((k, v) -> {
|
||||
userScoreMap.add(NutMap.NEW().addv("userId", k).addv("score", v));
|
||||
});
|
||||
} else {
|
||||
Map<String, List<QuestionUserScore>> userScoreListMap = thisTimeQuestionUserScores.stream().collect(Collectors.groupingBy(v -> v.getUserId()));
|
||||
userScoreListMap.forEach((userId, v) -> {
|
||||
Map<Date, List<QuestionUserScore>> userDayScoreListMap = v.stream().collect(Collectors.groupingBy(x -> x.getAnswerDate()));
|
||||
AtomicInteger sumScore = new AtomicInteger();
|
||||
userDayScoreListMap.forEach((day, v1) -> {
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
int score = v1.stream().mapToInt(s -> s.getScore()).max().orElse(0);
|
||||
sumScore.addAndGet(score);
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
int maxAnswerNum = v1.stream().mapToInt(s -> s.getAnswerNum()).max().orElse(1);
|
||||
Integer score = v1.stream().filter(s -> s.getAnswerNum() == maxAnswerNum).findFirst().map(s -> s.getScore()).orElse(0);
|
||||
sumScore.addAndGet(score);
|
||||
}
|
||||
});
|
||||
userScoreMap.add(NutMap.NEW().addv("userId", userId).addv("score", sumScore.get()));
|
||||
});
|
||||
}
|
||||
} else if (question.getCtMode() == 3) {
|
||||
Map<String, List<QuestionUserScore>> userScoreListMap = thisTimeQuestionUserScores.stream().collect(Collectors.groupingBy(v -> v.getUserId()));
|
||||
userScoreListMap.forEach((userId, v) -> {
|
||||
AtomicInteger sumScore = new AtomicInteger();
|
||||
if (question.getCalcScoreMode() == 1) {
|
||||
int score = v.stream().mapToInt(s -> s.getScore()).max().orElse(0);
|
||||
sumScore.addAndGet(score);
|
||||
} else if (question.getCalcScoreMode() == 2) {
|
||||
int maxAnswerNum = v.stream().mapToInt(s -> s.getAnswerNum()).max().orElse(1);
|
||||
Integer score = v.stream().filter(s -> s.getAnswerNum() == maxAnswerNum).findFirst().map(s -> s.getScore()).orElse(0);
|
||||
sumScore.addAndGet(score);
|
||||
}
|
||||
userScoreMap.add(NutMap.NEW().addv("userId", userId).addv("score", sumScore.get()));
|
||||
});
|
||||
}
|
||||
|
||||
//待抽奖用户
|
||||
List<String> readyRaffleUserId = userScoreMap.stream().filter(x -> x.getInt("score") >= raffleScore).map(v -> v.getString("userId")).collect(Collectors.toList());
|
||||
|
||||
// 随机打乱用户ID列表
|
||||
Collections.shuffle(readyRaffleUserId);
|
||||
|
||||
if (readyRaffleUserId.size() >= raffleWinnerUserNum) {
|
||||
winnerUserIds = readyRaffleUserId.subList(0, raffleWinnerUserNum);
|
||||
} else {
|
||||
winnerUserIds = readyRaffleUserId.subList(0, readyRaffleUserId.size());
|
||||
}
|
||||
|
||||
List<QuestionWinner> questionWinners = winnerUserIds.stream().map(v -> {
|
||||
QuestionWinner winner = new QuestionWinner();
|
||||
winner.setQuestionId(questionId);
|
||||
winner.setUserId(v);
|
||||
winner.setWinDate(new Date());
|
||||
Integer score = userScoreMap.stream().filter(x -> x.getString("userId").equals(v)).findFirst().map(x -> x.getInt("score", 0)).orElse(0);
|
||||
winner.setScore(score);
|
||||
return winner;
|
||||
}).collect(Collectors.toList());
|
||||
dao.insert(questionWinners);
|
||||
|
||||
dao.update(Sys_task.class, Chain.make("disabled", 1), Cnd.where("data", "like", "%" + raffleTime + "%").and("data", "like", "%" + questionId + "%"));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user