336 lines
12 KiB
Java
336 lines
12 KiB
Java
package io.v.nutz.msgNotify;
|
|
|
|
import io.v.nutz.activity.services.ActivityBasicScopeService;
|
|
import io.v.nutz.annontation.ViReturn;
|
|
import io.v.nutz.base.service.BaseService;
|
|
import io.v.nutz.base.utils.DateUtil;
|
|
import io.v.nutz.dao.CndPlus;
|
|
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.sys.models.Sys_role;
|
|
import io.v.nutz.sys.models.User;
|
|
import io.v.nutz.util.ShiroUtil;
|
|
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.ioc.loader.annotation.Inject;
|
|
import org.nutz.ioc.loader.annotation.IocBean;
|
|
import org.nutz.json.Json;
|
|
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 org.nutz.trans.Trans;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author zhf
|
|
* @date 2022/3/18 15:08
|
|
* @description
|
|
*/
|
|
@At("/platform/msgNotify/send")
|
|
@Ok("json:full")
|
|
@IocBean
|
|
@RequiresAuthentication
|
|
public class MsgNotifyController {
|
|
|
|
private String JDHXT = "aca4d14498c145ceb5b24ed70776aae2";
|
|
private String HYXT = "669fa50ffc754077bdf11bd9ab6ec9c8";
|
|
private String TAXT = "733d7266652740a3aeac9da97ab5eeca";
|
|
|
|
@At("")
|
|
@Ok("beetl:platform/msgNotify/send.html")
|
|
@RequiresPermissions("msgNotify.send")
|
|
public void index() {
|
|
}
|
|
|
|
@Inject
|
|
private BaseService baseService;
|
|
|
|
@Inject
|
|
private Dao dao;
|
|
|
|
|
|
@Inject
|
|
private MsgNotifyService msgNotifyService;
|
|
|
|
@Inject
|
|
private ActivityBasicScopeService activityBasicScopeService;
|
|
|
|
|
|
@At
|
|
@ViReturn
|
|
public Object findOne(String id) {
|
|
return dao.fetch(MsgNotify.class, id);
|
|
}
|
|
|
|
@At
|
|
@ViReturn
|
|
@RequiresAuthentication
|
|
public Object getUsersByTitleId(Integer pageNumber, Integer pageSize, String id, String type) {
|
|
Cnd cnd = Cnd.NEW();
|
|
Sql sql = Sqls.create("""
|
|
SELECT
|
|
u.id,
|
|
u.username userName,
|
|
u.loginname loginName,
|
|
u.unitid,
|
|
u.unitname unitName,
|
|
u.mobile,
|
|
u.unionname unionName
|
|
FROM
|
|
msg_notify_user mnu
|
|
LEFT JOIN `user` u ON u.id = mnu.userid
|
|
$condition
|
|
""");
|
|
cnd.and("mnu.titleId", "=", id);
|
|
sql.setCondition(cnd);
|
|
if (!type.equals("user")) {
|
|
return baseService.listPageMap(pageNumber, pageSize, sql);
|
|
} else {
|
|
return baseService.listMap(sql);
|
|
}
|
|
}
|
|
|
|
@At
|
|
@ViReturn
|
|
@RequiresAuthentication
|
|
public Object pageData(PageForm pageForm, String[] users) {
|
|
|
|
Sql sql = Sqls.create("""
|
|
SELECT
|
|
id,
|
|
username userName,
|
|
loginname loginName,
|
|
unitid,
|
|
unitname unitName,
|
|
mobile,
|
|
unionname unionName
|
|
from user
|
|
$condition
|
|
""");
|
|
CndPlus cnd = CndPlus.create();
|
|
cnd.andExcludeEmpty("member", "=", 1);
|
|
if (users.length > 0) {
|
|
cnd.andExcludeEmpty("id", "not in", users);
|
|
}
|
|
if (Strings.isNotBlank(pageForm.getSearchName()) && Strings.isNotBlank(pageForm.getSearchKeyword())) {
|
|
cnd.where().andLike(pageForm.getSearchName(), pageForm.getSearchKeyword());
|
|
}
|
|
sql.setCondition(cnd);
|
|
return baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
|
}
|
|
|
|
|
|
@At
|
|
@ViReturn
|
|
@RequiresAuthentication
|
|
public Object doAdd(boolean flag, @Param("msgNotify") String msgNotifyData, String[] users) {
|
|
Trans.exec(() -> {
|
|
MsgNotify msgNotify = Json.fromJson(MsgNotify.class, msgNotifyData);
|
|
msgNotify.setHold(flag);
|
|
msgNotify.setCreateTime(DateUtil.getDateTime());
|
|
dao.insert(msgNotify);
|
|
|
|
|
|
MsgNotifyUser msgNotifyUser = new MsgNotifyUser();
|
|
msgNotifyUser.setSendUser(ShiroUtil.getUserId());
|
|
|
|
if (msgNotify.getType() != null && msgNotify.getType().equals("system")) {
|
|
List<NutMap> list = msgNotifyService.getUserByRoleIds(msgNotify.getModule(), msgNotify.getTeacherMeetingId(), msgNotify.getRoleIds());
|
|
List<String> userData = msgNotifyService.userData(list);
|
|
if (flag) {
|
|
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
|
|
|
|
}
|
|
list.forEach(v -> {
|
|
if (flag) {
|
|
msgNotify.setSendTime(DateUtil.getDateTime());
|
|
|
|
}
|
|
msgNotifyUser.setUserId(v.getString("id"));
|
|
msgNotifyUser.setTitleId(msgNotify.getId());
|
|
dao.insert(msgNotifyUser);
|
|
|
|
});
|
|
|
|
} else if (msgNotify.getType() != null && msgNotify.getType().equals("user")) {
|
|
if (flag) {
|
|
List<User> user = dao.query(User.class, Cnd.where("id", "in", users));
|
|
List<String> objectUserData = msgNotifyService.ObjectUserData(user);
|
|
msgNotifyService.sendMsg(msgNotify.getSendTypes(), objectUserData, msgNotify.getContent());
|
|
}
|
|
for (String u : users) {
|
|
if (flag) {
|
|
// Sys_user user = dao.fetch(Sys_user.class, Cnd.where("id", "=", u));
|
|
// msgNotifyService.sendMsg(msgNotify.getSendTypes(), null, user, msgNotify.getContent());
|
|
msgNotify.setSendTime(DateUtil.getDateTime());
|
|
}
|
|
msgNotifyUser.setUserId(u);
|
|
msgNotifyUser.setTitleId(msgNotify.getId());
|
|
dao.insert(msgNotifyUser);
|
|
}
|
|
} else {
|
|
List<NutMap> userScopes = msgNotifyService.getUserScopes(msgNotify.getActivityGroupId());
|
|
List<String> userData = msgNotifyService.userData(userScopes);
|
|
if (flag) {
|
|
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
|
|
|
|
}
|
|
userScopes.forEach(v -> {
|
|
if (flag) {
|
|
// msgNotifyService.sendMsg(msgNotify.getSendTypes(), v, null, msgNotify.getContent());
|
|
msgNotify.setSendTime(DateUtil.getDateTime());
|
|
}
|
|
msgNotifyUser.setUserId(v.getString("id"));
|
|
msgNotifyUser.setTitleId(msgNotify.getId());
|
|
dao.insert(msgNotifyUser);
|
|
});
|
|
}
|
|
});
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
@At
|
|
@ViReturn
|
|
@RequiresAuthentication
|
|
public Object doEdit(boolean flag, @Param("msgNotify") String msgNotifyData, String[] users) {
|
|
MsgNotify msgNotify = Json.fromJson(MsgNotify.class, msgNotifyData);
|
|
|
|
Trans.exec(() -> {
|
|
baseService.dao().clear(MsgNotifyUser.class, Cnd.where("titleId", "=", msgNotify.getId()));
|
|
List<NutMap> list = new ArrayList<>();
|
|
if (msgNotify.getRoleIds() != null) {
|
|
list = msgNotifyService.getUserByRoleIds(msgNotify.getModule(), msgNotify.getTeacherMeetingId(), msgNotify.getRoleIds());
|
|
}
|
|
|
|
MsgNotifyUser msgNotifyUser = new MsgNotifyUser();
|
|
msgNotifyUser.setSendUser(ShiroUtil.getUserId());
|
|
if (msgNotify.getType() != null && msgNotify.getType().equals("system")) {
|
|
msgNotify.setHold(flag ? true : false);
|
|
|
|
if (flag) {
|
|
List<String> userData = msgNotifyService.userData(list);
|
|
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
|
|
|
|
}
|
|
list.forEach(v -> {
|
|
if (flag) {
|
|
// msgNotifyService.sendMsg(msgNotify.getSendTypes(), v, null, msgNotify.getContent());
|
|
msgNotify.setSendTime(DateUtil.getDateTime());
|
|
}
|
|
msgNotifyUser.setUserId(v.getString("id"));
|
|
msgNotifyUser.setTitleId(msgNotify.getId());
|
|
dao.insert(msgNotifyUser);
|
|
});
|
|
} else if (msgNotify.getType() != null && msgNotify.getType().equals("user")) {
|
|
if (flag) {
|
|
List<User> user = dao.query(User.class, Cnd.where("id", "in", users));
|
|
List<String> objectUserData = msgNotifyService.ObjectUserData(user);
|
|
msgNotifyService.sendMsg(msgNotify.getSendTypes(), objectUserData, msgNotify.getContent());
|
|
|
|
}
|
|
msgNotify.setHold(flag ? true : false);
|
|
for (String u : users) {
|
|
if (flag) {
|
|
// User user = dao.fetch(User.class, Cnd.where("id", "=", u));
|
|
// msgNotifyService.sendMsg(msgNotify.getSendTypes(), null, user, msgNotify.getContent());
|
|
msgNotify.setSendTime(DateUtil.getDateTime());
|
|
}
|
|
msgNotifyUser.setUserId(u);
|
|
msgNotifyUser.setTitleId(msgNotify.getId());
|
|
dao.insert(msgNotifyUser);
|
|
}
|
|
} else {
|
|
Sql sql = Sqls.create("""
|
|
SELECT
|
|
u.id,
|
|
u.username userName,
|
|
u.loginname loginName,
|
|
u.unitid,
|
|
u.unitname unitName,
|
|
u.mobile,
|
|
u.unionname unionName
|
|
FROM
|
|
`activity_user_scope` aus
|
|
LEFT JOIN `user` u ON u.id = aus.userId
|
|
where aus.groupId=@groupId
|
|
""").setParam("groupId", msgNotify.getActivityGroupId());
|
|
List<NutMap> userScopes = activityBasicScopeService.listMap(sql);
|
|
msgNotify.setHold(flag ? true : false);
|
|
List<String> userData = msgNotifyService.userData(userScopes);
|
|
if (flag) {
|
|
msgNotifyService.sendMsg(msgNotify.getSendTypes(), userData, msgNotify.getContent());
|
|
|
|
}
|
|
userScopes.forEach(v -> {
|
|
if (flag) {
|
|
// msgNotifyService.sendMsg(msgNotify.getSendTypes(), v, null, msgNotify.getContent());
|
|
msgNotify.setSendTime(DateUtil.getDateTime());
|
|
}
|
|
msgNotifyUser.setUserId(v.getString("id"));
|
|
msgNotifyUser.setTitleId(msgNotify.getId());
|
|
dao.insert(msgNotifyUser);
|
|
});
|
|
}
|
|
});
|
|
baseService.updateIgnoreNull(msgNotify);
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
@At
|
|
@ViReturn
|
|
@RequiresAuthentication
|
|
public Object getUserByRoleId(String searchKeyword, String searchName, Integer pageNumber, Integer pageSize, String[] roleIds, String module, String teacherMeetingId) {
|
|
Cnd cnd = Cnd.NEW();
|
|
Sql sql = Sqls.create("""
|
|
SELECT
|
|
u.id,
|
|
u.username userName,
|
|
u.loginname loginName,
|
|
u.unitid,
|
|
u.unitname unitName,
|
|
u.mobile,
|
|
u.unionname unionName
|
|
FROM
|
|
sys_user_role sur
|
|
RIGHT JOIN `user` u ON u.id = sur.userid
|
|
$condition
|
|
""");
|
|
if (module.equals(TAXT) || module.equals(JDHXT)) {
|
|
cnd.and("sur.jdhid", "=", teacherMeetingId);
|
|
}
|
|
|
|
if (Strings.isNotBlank(searchName) && Strings.isNotBlank(searchKeyword)) {
|
|
cnd.where().andLike(searchName, searchKeyword);
|
|
}
|
|
if (roleIds.length > 0) {
|
|
cnd.and("sur.roleId", "in", roleIds);
|
|
}
|
|
cnd.groupBy("sur.userId");
|
|
sql.setCondition(cnd);
|
|
return baseService.listPageMap(pageNumber, pageSize, sql);
|
|
}
|
|
|
|
@At
|
|
@ViReturn
|
|
@RequiresAuthentication
|
|
public Object getRoleListByMenuId(String menuId) {
|
|
return dao.query(Sys_role.class, Cnd.where("system_name", "=", menuId).desc("code"));
|
|
|
|
}
|
|
|
|
}
|