first commit

This commit is contained in:
zhaoxinyu
2024-04-10 15:19:47 +08:00
commit f857065a3a
2884 changed files with 683559 additions and 0 deletions
@@ -0,0 +1,335 @@
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());
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));
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());
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) {
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));
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);
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)) {
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"));
}
}
@@ -0,0 +1,114 @@
package io.v.nutz.msgNotify;
import cn.hutool.core.util.ArrayUtil;
import io.v.nutz.annontation.ViReturn;
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.service.ViService;
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.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.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
/**
* @author zhf
* @date 2022/3/21 14:18
* @description
*/
@At("/platform/msgNotify/sendList")
@Ok("json:full")
@IocBean
@RequiresAuthentication
public class MsgNotifyListController {
@At("")
@Ok("beetl:platform/msgNotify/sendList.html")
@RequiresPermissions("msgNotify.sendList")
public void index() {
}
@Inject
private ViService<MsgNotifyUser> notifyViService;
@At
@ViReturn
@RequiresAuthentication
public Object pageData(PageForm pageForm, String titleId, String[] dateRange, String unitId, String unionId, String[] sendTypes) {
Cnd cnd = Cnd.NEW();
Sql sql = Sqls.create("""
SELECT
u.username,
u.loginname,
u.unionname,
u.unitname,
mnu.*,
mn.title,
mn.activityGroupId,
mn.module,
mn.teacherMeetingId,
mn.type,
mn.roleIds,
mn.sendTypes,
mn.content,
mn.sendTime,
mn.hold
FROM
`msg_notify_user` mnu
LEFT JOIN `user` u ON u.id = mnu.userId
LEFT JOIN msg_notify mn ON mn.id = mnu.titleId
$condition
""");
cnd.andEX("u.unionid", "=", unionId);
cnd.andEX("u.unitid", "=", unitId);
cnd.andEX("mn.hold", "=", 1);
cnd.andEX("mn.id", "=", titleId);
if (!ShiroUtil.hasRole("sysadmin")) {
cnd.and("mnu.userId", "=", ShiroUtil.getUserId());
}
if (Strings.isNotBlank(pageForm.getSearchName()) && Strings.isNotBlank(pageForm.getSearchKeyword())) {
cnd.where().andLike(pageForm.getSearchName(), pageForm.getSearchKeyword());
}
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.sendTime", ">=", dateRange[0]);
cnd.and("mn.sendTime", "<=", dateRange[1]);
}
cnd.desc("mn.sendTime");
cnd.desc("u.unitname");
sql.setCondition(cnd);
return notifyViService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
}
@At
@ViReturn
@RequiresAuthentication
public Object getTitleList(String[] dateRange) {
Cnd cnd = Cnd.NEW();
if (dateRange != null && dateRange.length == 2) {
cnd.and("CreateTime", ">=", dateRange[0]);
cnd.and("CreateTime", "<=", dateRange[1]);
}
return notifyViService.dao().query(MsgNotify.class, cnd);
}
}
@@ -0,0 +1,127 @@
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) {
List<NutMap> msgNotifyUser = msgNotifyService.getMsgNotifyUser(id);
String userData = msgNotifyService.userData(msgNotifyUser);
msgNotifyService.sendMsg(Arrays.asList(sendTypes), userData, content);
msgNotifyUser.forEach(v -> {
baseService.dao().update(MsgNotify.class, Chain.make("hold", true).add("sendTime", DateUtil.getDateTime()), Cnd.where("id", "=", v.getString("titleId")));
});
return null;
}
/*
@At
@ViReturn
public Object getMeetingByMsgId(String id) {
return baseService.dao().fetch(MeetingInfo.class, Cnd.where("notifyId", "=", id));
}
*/
}
@@ -0,0 +1,84 @@
package io.v.nutz.msgNotify.models;
import lombok.Data;
import lombok.experimental.Accessors;
import org.nutz.dao.entity.annotation.*;
import java.util.List;
/**
* @author zhf
* @date 2022/3/21 16:24
* @description
*/
@Data
@Table()
@Accessors(chain = true)
public class MsgNotify {
@Column
@Name
@Comment("id")
@ColDefine(type = ColType.VARCHAR, width = 32)
@Prev(els = {@EL("uuid()")})
private String id;
@Column
@Comment("发送标题")
@ColDefine(type = ColType.VARCHAR, width = 30)
private String title;
@Column
@Comment("发送对象")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String activityGroupId;
@Column
@Comment("发送所属模块")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String module;
@Column
@Comment("发送所属教代会")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String teacherMeetingId;
@Column
@Comment("发送对象")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String type;
@Column
@Comment("发送角色")
@ColDefine(type = ColType.MYSQL_JSON)
private List<String> roleIds;
@Column
@Comment("发送方式")
@ColDefine(type = ColType.MYSQL_JSON)
private List<String> sendTypes;
@Column
@Comment("发送内容")
@ColDefine(type = ColType.VARCHAR, width = 1000)
private String content;
@Column
@Comment("创建时间")
@ColDefine(type = ColType.VARCHAR, width = 1000)
private String CreateTime;
@Column
@Comment("发送时间")
@ColDefine(type = ColType.VARCHAR, width = 1000)
private String sendTime;
@Column
@Comment("是否保存")
@ColDefine(type = ColType.BOOLEAN)
private boolean hold;
}
@@ -0,0 +1,46 @@
package io.v.nutz.msgNotify.models;
import lombok.Data;
import lombok.experimental.Accessors;
import org.nutz.dao.entity.annotation.*;
/**
* @author zhf
* @date 2022/3/21 10:13
* @description
*/
@Data
@Table()
@Accessors(chain = true)
public class MsgNotifyUser {
@Column
@Name
@Comment("id")
@ColDefine(type = ColType.VARCHAR, width = 32)
@Prev(els = {@EL("uuid()")})
private String id;
@Column
@Comment("发送用户ID")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String userId;
@Column
@Comment("发送人")
@ColDefine(type = ColType.VARCHAR, width = 50)
private String sendUser;
@Column
@Comment("标题id")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String titleId;
}
@@ -0,0 +1,74 @@
package io.v.nutz.msgNotify.service;
import io.v.nutz.msgNotify.models.MsgNotify;
import io.v.nutz.msgNotify.models.MsgNotifyUser;
import io.v.nutz.sys.models.User;
import org.nutz.lang.util.NutMap;
import java.util.List;
/**
* @author zhf
* @date 2022/3/23 10:14
* @description
*/
public interface MsgNotifyService {
/**
* 添加消息 及 返回发送人员
*
* @param msgNotify
* @return
*/
NutMap addMsgNotify(MsgNotify msgNotify, String[] users);
/**
* 编辑
*
* @param msgNotify
* @param users
* @return
*/
NutMap editMsgNotify(MsgNotify msgNotify, String[] users);
String userData(NutMap v);
String userData(User user);
String ObjectUserData(List<User> userList);
String userData(List<NutMap> userListMap);
/**
* 根据条件发送短信
*
* @param sendTypes
* @param userData
* @param content
*/
void sendMsg(List<String> sendTypes, String userData, String content);
/**
* 查询活动设置人员
*
* @param activityGroupId
* @return
*/
List<NutMap> getUserScopes(String activityGroupId);
/**
* 查询发送人员,根据消息记录id
*
* @param id
* @return
*/
List<NutMap> getMsgNotifyUser(String id);
List<NutMap> getUserByRoleIds(String module, String teacherMeetingId, List<String> roleIds);
List<MsgNotifyUser> addMsgNotifyUser(MsgNotify msgNotify, String[] users);
}
@@ -0,0 +1,242 @@
package io.v.nutz.msgNotify.service.impl;
import io.v.nutz.base.utils.DateUtil;
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 io.v.nutz.sys.models.User;
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.dao.util.Daos;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author zhf
* @date 2022/3/23 10:14
* @description
*/
@IocBean(args = {"refer:dao"})
public class MsgNotifyServiceImpl extends ViServiceImpl<MsgNotify> implements MsgNotifyService {
public MsgNotifyServiceImpl(Dao dao) {
super(dao);
}
@Override
public NutMap editMsgNotify(MsgNotify msgNotify, String[] users) {
dao().updateIgnoreNull(msgNotify);
dao().clear(MsgNotifyUser.class, Cnd.where("titleId", "=", msgNotify.getId()));
List<MsgNotifyUser> msgNotifyUserList = addMsgNotifyUser(msgNotify, users);
return NutMap.NEW().addv("id", msgNotify.getId()).addv("userIdList", msgNotifyUserList.stream().map(MsgNotifyUser::getUserId).collect(Collectors.toList()));
}
@Override
public NutMap addMsgNotify(MsgNotify msgNotify, String[] users) {
msgNotify.setHold(false);
msgNotify.setCreateTime(DateUtil.getDateTime());
dao().insert(msgNotify);
List<MsgNotifyUser> msgNotifyUserList = addMsgNotifyUser(msgNotify, users);
return NutMap.NEW().addv("id", msgNotify.getId()).addv("userIdList", msgNotifyUserList.stream().map(MsgNotifyUser::getUserId).collect(Collectors.toList()));
}
/**
* List<String> list = new ArrayList<>();
* list.add(v.getString("userName"));
* list.add(v.getString("loginName"));
* list.add(v.getString("unitId"));
* list.add(v.getString("unitName"));
* list.add(v.getString("mobile") != null ? v.getString("mobile") : "");
*
* @param v
* @return
*/
@Override
public String userData(NutMap v) {
List<String> list = new ArrayList<>();
list.add(v.getString("userName"));
list.add(v.getString("loginName"));
list.add(v.getString("unitId"));
list.add(v.getString("unitName"));
list.add(v.getString("mobile") != null ? v.getString("mobile") : "");
list.add("");
list.add("");
String collect = list.stream().collect(Collectors.joining("|"));
return collect;
}
@Override
public String userData(User user) {
List<String> list = new ArrayList<>();
list.add(user.getUsername());
list.add(user.getLoginname());
list.add(user.getUnitid());
list.add("");
list.add(user.getMobile() != null ? user.getMobile() : "");
list.add("");
list.add("");
String collect = list.stream().collect(Collectors.joining("|"));
return collect;
}
@Override
public String ObjectUserData(List<User> userList) {
List<String> recievePersonInfo = new ArrayList<>();
for (User user : userList) {
recievePersonInfo.add(userData(user));
}
return String.join("^@^", recievePersonInfo);
}
@Override
public String userData(List<NutMap> userList) {
List<String> recievePersonInfo = new ArrayList<>();
for (NutMap map : userList) {
recievePersonInfo.add(userData(map));
}
return String.join("^@^", recievePersonInfo);
}
/**
* 根据条件发送短信
*
* @param sendTypes
* @param userData
* @param content
*/
public void sendMsg(List<String> sendTypes, String userData, String content) {
new Thread() {
@Override
public void run() {
if (sendTypes.contains("msg")) {
}
if (sendTypes.contains("WeChat")) {
}
}
}.start();
}
/**
* 查询活动设置人员
*
* @param activityGroupId
* @return
*/
@Override
public List<NutMap> getUserScopes(String activityGroupId) {
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", activityGroupId);
return (List<NutMap>) Daos.query(dao(), sql.toString(), Sqls.callback.maps());
}
/**
* 查询发送人员,根据消息记录id
*
* @param id
* @return
*/
public List<NutMap> getMsgNotifyUser(String id) {
Sql sql = Sqls.create("""
SELECT
u.id,
u.username userName,
u.loginname loginName,
u.unitid,
u.unitname unitName,
u.mobile,
u.unionname unionName,
mnu.*
FROM
msg_notify_user mnu
LEFT JOIN `user` u ON u.id = mnu.userid
WHERE mnu.titleId=@titleId
""").setParam("titleId", id);
return (List<NutMap>) Daos.query(dao(), sql.toString(), Sqls.callback.maps());
}
public List<NutMap> getUserByRoleIds(String module, String teacherMeetingId, List<String> roleIds) {
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("jdh")) {
cnd.and("sur.jdhid", "=", teacherMeetingId);
}
cnd.and("sur.roleId", "in", roleIds);
cnd.groupBy("sur.userId");
sql.setCondition(cnd);
return (List<NutMap>) Daos.query(dao(), sql.toString(), Sqls.callback.maps());
}
public List<MsgNotifyUser> addMsgNotifyUser(MsgNotify msgNotify, String[] users) {
List<MsgNotifyUser> msgNotifyUserList = new ArrayList<>();
if (msgNotify.getType() != null && msgNotify.getType().equals("system")) {
List<NutMap> list = this.getUserByRoleIds(msgNotify.getModule(), msgNotify.getTeacherMeetingId(), msgNotify.getRoleIds());
for (NutMap v : list) {
MsgNotifyUser msgNotifyUser = new MsgNotifyUser();
msgNotifyUser.setSendUser(ShiroUtil.getUserId());
msgNotifyUser.setUserId(v.getString("id"));
msgNotifyUser.setTitleId(msgNotify.getId());
msgNotifyUserList.add(msgNotifyUser);
}
} else if (msgNotify.getType() != null && msgNotify.getType().equals("user")) {
for (String u : users) {
MsgNotifyUser msgNotifyUser = new MsgNotifyUser();
msgNotifyUser.setUserId(u);
msgNotifyUser.setTitleId(msgNotify.getId());
msgNotifyUserList.add(msgNotifyUser);
}
} else {
List<NutMap> userScopes = this.getUserScopes(msgNotify.getActivityGroupId());
for (NutMap v : userScopes) {
MsgNotifyUser msgNotifyUser = new MsgNotifyUser();
msgNotifyUser.setSendUser(ShiroUtil.getUserId());
msgNotifyUser.setUserId(v.getString("id"));
msgNotifyUser.setTitleId(msgNotify.getId());
msgNotifyUserList.add(msgNotifyUser);
}
}
dao().insert(msgNotifyUserList);
return msgNotifyUserList;
}
}