package io.v.nutz.msgNotify; import cn.hutool.core.util.ArrayUtil; import io.v.nutz.annontation.ViReturn; import io.v.nutz.base.service.BaseService; import io.v.nutz.base.utils.DateUtil; 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.AsyncService; import org.apache.shiro.authz.annotation.RequiresAuthentication; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.nutz.dao.Chain; import org.nutz.dao.Cnd; 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 org.nutz.mvc.annotation.At; import org.nutz.mvc.annotation.Ok; import org.nutz.trans.Trans; import java.util.Arrays; import java.util.List; /** * @author zhf * @date 2022/3/21 17:13 * @description */ @At("/platform/msgNotifyTitle/list") @Ok("json:full") @IocBean @RequiresAuthentication public class MsgNotifyTitleController { @Inject private BaseService baseService; @Inject private MsgNotifyService msgNotifyService; @At("") @Ok("beetl:platform/msgNotify/msgNotifyTitle.html") @RequiresPermissions("msgNotifyTitle.list") public void index() { } @At @ViReturn @RequiresAuthentication public Object pageData(PageForm pageForm, String[] dateRange, String[] sendTypes, String title) { Cnd cnd = Cnd.NEW(); Sql sql = Sqls.create(""" SELECT mn.*, jdh.jdhallname FROM `msg_notify` mn LEFT JOIN jdh_jdhxx jdh ON jdh.id = mn.teacherMeetingId $condition """); if (Strings.isNotBlank(title)) { cnd.where().andLike("mn.title", title); } if (sendTypes != null && ArrayUtil.contains(sendTypes, "msg")) { cnd.and(new Static("JSON_CONTAINS(mn.sendTypes,JSON_QUOTE( 'msg' ))")); } if (sendTypes != null && ArrayUtil.contains(sendTypes, "WeChat")) { cnd.and(new Static("JSON_CONTAINS(mn.sendTypes,JSON_QUOTE( 'WeChat' ))")); } if (dateRange != null && dateRange.length == 2) { cnd.and("mn.CreateTime", ">=", dateRange[0]); cnd.and("mn.CreateTime", "<=", dateRange[1]); } cnd.asc("mn.hold"); cnd.desc("mn.CreateTime"); sql.setCondition(cnd); return baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); } @At @ViReturn @RequiresAuthentication public Object doDelete(String TitleId) { Trans.exec(() -> { baseService.dao().clear(MsgNotify.class, Cnd.where("id", "=", TitleId)); baseService.dao().clear(MsgNotifyUser.class, Cnd.where("titleId", "=", TitleId)); }); return null; } @Inject private AsyncService asyncService; @At @ViReturn @RequiresAuthentication public Object doSend(String id, String[] sendTypes, String content) { MsgNotify msgNotify = baseService.dao().fetch(MsgNotify.class, id); List msgNotifyUser = msgNotifyService.getMsgNotifyUser(id); List userData = msgNotifyService.userData(msgNotifyUser); msgNotifyService.sendMsg(Arrays.asList(sendTypes), userData, content); if (!msgNotify.isHold()){ baseService.dao().update(MsgNotify.class, Chain.make("hold", true) .add("sendTime", DateUtil.getDateTime()), Cnd.where("id", "=", id)); } return null; } /* @At @ViReturn public Object getMeetingByMsgId(String id) { return baseService.dao().fetch(MeetingInfo.class, Cnd.where("notifyId", "=", id)); } */ }