first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.sys.models.Sys_api;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
|
||||
public interface SysApiService extends BaseService<Sys_api> {
|
||||
/**
|
||||
* 创建密钥
|
||||
*/
|
||||
void createAppkey(String name, String userId) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除密钥
|
||||
*/
|
||||
void deleteAppkey(String appid) throws Exception;
|
||||
|
||||
/**
|
||||
* 启用禁用
|
||||
*/
|
||||
void updateAppkey(String appid, boolean disabled) throws Exception;
|
||||
|
||||
/**
|
||||
* 通过appid获取appkey
|
||||
*
|
||||
* @param appid appid
|
||||
* @return Sys_api
|
||||
*/
|
||||
String getAppkey(String appid);
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param appid appid
|
||||
*/
|
||||
void deleteCache(String appid);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_app_conf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysAppConfService extends BaseService<Sys_app_conf> {
|
||||
List<String> getConfNameList();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_app_list;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysAppListService extends BaseService<Sys_app_list> {
|
||||
List<String> getAppNameList();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_app_task;
|
||||
|
||||
public interface SysAppTaskService extends BaseService<Sys_app_task> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.sys.models.Sys_config;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/23.
|
||||
*/
|
||||
public interface SysConfigService extends BaseService<Sys_config> {
|
||||
/**
|
||||
* 查询所有数据
|
||||
* @return
|
||||
*/
|
||||
List<Sys_config> getAllList();
|
||||
|
||||
Sys_config getValueByKey(String key);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_user_source;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SysDataUserPullService extends BaseService<Sys_user_source> {
|
||||
|
||||
/**
|
||||
* 从信息中心拉取数据
|
||||
*/
|
||||
Date pull();
|
||||
|
||||
/**
|
||||
* 拉取人员博士后的信息
|
||||
*/
|
||||
Map<String, Date> pullPostDoctoral();
|
||||
|
||||
/**
|
||||
* 获取下拉框数据(单位、在职状态、人事编制、人员类型)
|
||||
*/
|
||||
NutMap searchOptions();
|
||||
|
||||
/**
|
||||
* 获取数据源拉取时间列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<NutMap> pullTimeOptions();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.sys.param.SysDataUserUpdateParam;
|
||||
|
||||
/**
|
||||
* 信息中心数据更新
|
||||
*/
|
||||
public interface SysDataUserUpdateService {
|
||||
String update(SysDataUserUpdateParam updateParam);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SysDictService extends BaseService<Sys_dict> {
|
||||
/**
|
||||
* 通过code获取名称
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
String getNameByCode(String code);
|
||||
|
||||
/**
|
||||
* 通过ID获取名称
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
String getNameById(String id);
|
||||
|
||||
/**
|
||||
* 通过树PATH获取子级
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
List<Sys_dict> getSubListByPath(String path);
|
||||
|
||||
/**
|
||||
* 通过ID获取子级
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<Sys_dict> getSubListById(String id);
|
||||
|
||||
/**
|
||||
* 通过code获取子级
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
List<Sys_dict> getSubListByCode(String code);
|
||||
|
||||
/**
|
||||
* 通过树PATH获取子级
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
Map getSubMapByPath(String path);
|
||||
|
||||
/**
|
||||
* 通过ID获取子级
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Map getSubMapById(String id);
|
||||
|
||||
/**
|
||||
* 通过code获取子级
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
Map getSubMapByCode(String code);
|
||||
|
||||
/**
|
||||
* 保存数据字典
|
||||
*
|
||||
* @param dict
|
||||
* @param pid
|
||||
*/
|
||||
void save(Sys_dict dict, String pid);
|
||||
|
||||
/**
|
||||
* 保存数据字典
|
||||
*
|
||||
* @param dict dict
|
||||
* @param parentCode parentCode
|
||||
*/
|
||||
void saveByParentCode(Sys_dict dict, String parentCode);
|
||||
|
||||
/**
|
||||
* 级联删除数据
|
||||
*
|
||||
* @param dict
|
||||
*/
|
||||
void deleteAndChild(Sys_dict dict);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_file;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件Service接口
|
||||
**/
|
||||
public interface SysFileService extends BaseService<Sys_file> {
|
||||
|
||||
/**
|
||||
* 文件上传,返回文件id
|
||||
*/
|
||||
String uploadReturnId(String engine, TempFile file);
|
||||
|
||||
/**
|
||||
* 文件上传,返回文件Url
|
||||
*/
|
||||
String uploadReturnUrl(String engine, TempFile file);
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
Pagination page(Sys_file file);
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
List<Sys_file> list();
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
void download(String id, HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param id
|
||||
* @throws IOException
|
||||
*/
|
||||
byte[] download(String id) throws IOException;
|
||||
|
||||
/**
|
||||
* 转换为PDF
|
||||
*/
|
||||
void convertPDF(String id, HttpServletRequest request, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
void delete(List<String> id);
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
Sys_file detail(String id);
|
||||
|
||||
/**
|
||||
* 预览详情
|
||||
*/
|
||||
List<Sys_file> previewFileData(String[] ids);
|
||||
|
||||
/**
|
||||
* 转换为HTML
|
||||
*/
|
||||
String convertHtml(TempFile file);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
|
||||
public interface SysHomeActivityService extends BaseService<Sys_home_activity> {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
|
||||
public interface SysHomeConvert {
|
||||
|
||||
Sys_home_activity covertToSysHomeActivity();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.base.page.datatable.DataTableColumn;
|
||||
import com.budwk.app.base.page.datatable.DataTableOrder;
|
||||
import com.budwk.app.sys.models.Sys_log;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
public interface SysLogService extends BaseService<Sys_log> {
|
||||
/**
|
||||
* 快速插入日志
|
||||
*
|
||||
* @param syslog
|
||||
*/
|
||||
void fastInsertSysLog(Sys_log syslog);
|
||||
|
||||
/**
|
||||
* 分表查询数据
|
||||
*
|
||||
* @param tableName
|
||||
* @param length
|
||||
* @param start
|
||||
* @param draw
|
||||
* @param orders
|
||||
* @param columns
|
||||
* @param cnd
|
||||
* @param linkName
|
||||
* @return
|
||||
*/
|
||||
NutMap logData(String tableName, int length, int start, int draw, List<DataTableOrder> orders, List<DataTableColumn> columns, Cnd cnd, String linkName);
|
||||
|
||||
/**
|
||||
* 查询日期
|
||||
*
|
||||
* @param tablaeName 分表名称
|
||||
* @param pageNumber 页码
|
||||
* @param pageSize 页大小
|
||||
* @param cnd 查询条件
|
||||
* @return
|
||||
*/
|
||||
Pagination data(String tablaeName, int pageNumber, int pageSize, Cnd cnd);
|
||||
|
||||
/**
|
||||
* 多月日志条件查询
|
||||
*
|
||||
* @param date 时间范围
|
||||
* @param type 日志类型
|
||||
* @param pageOrderName 排序字段名称
|
||||
* @param pageOrderBy 排序方式
|
||||
* @param pageNumber 页码
|
||||
* @param pageSize 页大小
|
||||
* @return
|
||||
*/
|
||||
Pagination data(String[] date, String type, String pageOrderName, String pageOrderBy, int pageNumber, int pageSize);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
public interface SysMenuService extends BaseService<Sys_menu> {
|
||||
/**
|
||||
* 保存菜单
|
||||
*
|
||||
* @param menu
|
||||
* @param pid
|
||||
*/
|
||||
void save(Sys_menu menu, String pid, List<NutMap> datas);
|
||||
|
||||
|
||||
void savePlus(Sys_menu menu, String pid, List<Sys_menu> permissions);
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*
|
||||
* @param menu
|
||||
* @param pid
|
||||
*/
|
||||
void edit(Sys_menu menu, String pid, List<NutMap> datas);
|
||||
|
||||
void editPlus(Sys_menu menu, String pid, List<Sys_menu> permissions);
|
||||
|
||||
/**
|
||||
* 级联删除菜单
|
||||
*
|
||||
* @param menu
|
||||
*/
|
||||
void deleteAndChild(Sys_menu menu);
|
||||
|
||||
/**
|
||||
* 获取左侧菜单
|
||||
*
|
||||
* @param href
|
||||
* @return
|
||||
*/
|
||||
Sys_menu getLeftMenu(String href);
|
||||
|
||||
/**
|
||||
* 获取左侧菜单路径
|
||||
*
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
Sys_menu getLeftPathMenu(List<String> list);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_msg;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysMsgService extends BaseService<Sys_msg> {
|
||||
/**
|
||||
* 保存信息同时发送
|
||||
*
|
||||
* @param sysMsg 消息体
|
||||
* @param users 接收人
|
||||
* @param isExternal 是否发送到外部消息(学校通讯平台)
|
||||
*/
|
||||
Sys_msg saveMsg(Sys_msg sysMsg, String[] users, boolean isExternal);
|
||||
|
||||
/**
|
||||
* 删除消息及消息用户表数据
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void deleteMsg(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 通知客户端弹窗
|
||||
*
|
||||
* @param innerMsg
|
||||
* @param rooms
|
||||
*/
|
||||
void notify(Sys_msg innerMsg, String rooms[]);
|
||||
|
||||
/**
|
||||
* 通知客户端有新消息及消息数量
|
||||
*
|
||||
* @param room 用户名
|
||||
* @param size
|
||||
* @param list
|
||||
*/
|
||||
void innerMsg(String room, int size, List<NutMap> list);
|
||||
|
||||
/**
|
||||
* 获取某用户的未读消息数量及列表
|
||||
*
|
||||
* @param loginname 用户名
|
||||
*/
|
||||
void getMsg(String loginname);
|
||||
|
||||
/**
|
||||
* 通知下线
|
||||
*
|
||||
* @param loginname 用户名
|
||||
* @param httpSessionId
|
||||
*/
|
||||
void offline(String loginname, String httpSessionId);
|
||||
|
||||
/**
|
||||
* 向用户发送站内消息
|
||||
*
|
||||
* @param loginname 用户名
|
||||
* @param title 标题
|
||||
* @param body 内容
|
||||
* @param sender 发送者
|
||||
*/
|
||||
void sendMsg(String loginname, String title, String body, String sender);
|
||||
|
||||
/**
|
||||
* 向用户发送站内消息
|
||||
*
|
||||
* @param loginNames 用户名
|
||||
* @param title 标题
|
||||
* @param body 内容
|
||||
* @param sender 发送者
|
||||
*/
|
||||
void sendMsg(List<String> loginNames, String title, String body, String sender);
|
||||
|
||||
/**
|
||||
* 向用户发送站内消息
|
||||
*
|
||||
* @param loginNames 工号
|
||||
* @param title 标题
|
||||
* @param body 内容
|
||||
* @param sender 发送者
|
||||
*/
|
||||
void sendMsgInSys(List<String> loginNames, String title, String body, String sender);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_msg_user;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysMsgUserService extends BaseService<Sys_msg_user> {
|
||||
|
||||
/**
|
||||
* 获取未读消息数量
|
||||
*
|
||||
* @param loginname
|
||||
* @return
|
||||
*/
|
||||
int getUnreadNum(String loginname);
|
||||
|
||||
/**
|
||||
* 获取未读消息列表
|
||||
*
|
||||
* @param loginname
|
||||
* @param pageNumber
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
List<Sys_msg_user> getUnreadList(String loginname, int pageNumber, int pageSize);
|
||||
|
||||
/**
|
||||
* 删除用户缓存
|
||||
*
|
||||
* @param loginname
|
||||
*/
|
||||
void deleteCache(String loginname);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_msg_user;
|
||||
import com.budwk.app.sys.param.SysMsgSummaryPageForm;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public interface SysMsgUserSummaryService extends BaseService<Sys_msg_user> {
|
||||
|
||||
void exportMultipleAsZip(SysMsgSummaryPageForm pageForm, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 单个导出
|
||||
* @param id
|
||||
* @param response
|
||||
*/
|
||||
void exportSingleAsZip(String id, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 单个导出
|
||||
* @param id
|
||||
* @param byteArrayOutputStream
|
||||
*/
|
||||
void exportSingleAsFolder(String id, ByteArrayOutputStream byteArrayOutputStream);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_office_template;
|
||||
|
||||
public interface SysOfficeTemplateService extends BaseService<Sys_office_template> {
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
public interface SysRoleService extends BaseService<Sys_role> {
|
||||
/**
|
||||
* 获取角色权限
|
||||
*
|
||||
* @param role 角色对象
|
||||
* @return
|
||||
*/
|
||||
List<String> getPermissionList(Sys_role role);
|
||||
|
||||
/**
|
||||
* 通过角色ID获取菜单及数据权限
|
||||
*
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getMenusAndButtons(String roleId);
|
||||
|
||||
List<Sys_menu> getMenusAndButtons(String roleId, String platform);
|
||||
|
||||
/**
|
||||
* 通过角色ID获取菜单数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getDatas(String roleId);
|
||||
|
||||
/**
|
||||
* 获取所有菜单数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getDatas();
|
||||
|
||||
/**
|
||||
* 通过角色获取权限标识符
|
||||
*
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
List<String> getPermissionNameList(Sys_role role);
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
*
|
||||
* @param roleid
|
||||
*/
|
||||
void del(String roleid);
|
||||
|
||||
/**
|
||||
* 批量删除角色
|
||||
*
|
||||
* @param roleids
|
||||
*/
|
||||
void del(String[] roleids);
|
||||
|
||||
/**
|
||||
* 保存菜单数据
|
||||
*
|
||||
* @param menuIds
|
||||
* @param roleId
|
||||
*/
|
||||
void saveMenu(String[] menuIds, String roleId);
|
||||
|
||||
void saveMenu(String[] menuIds, String roleId, String platform);
|
||||
|
||||
/**
|
||||
* 通过角色ID和菜单父ID获取下级权限菜单
|
||||
*
|
||||
* @param roleId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getRoleMenus(String roleId, String pid);
|
||||
|
||||
/**
|
||||
* 判断角色是否有下级数据权限
|
||||
*
|
||||
* @param roleId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
boolean hasChildren(String roleId, String pid);
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
*
|
||||
* @param roleId
|
||||
* @param keyword
|
||||
* @param isAdmin
|
||||
* @param sysUnit
|
||||
* @return
|
||||
*/
|
||||
Pagination userSearch(String roleId, String keyword, boolean isAdmin, Sys_unit sysUnit);
|
||||
|
||||
/**
|
||||
* 根据code获取角色
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
Sys_role getByCode(String code);
|
||||
|
||||
Sys_role getByCode(RoleConstant roleConstant);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_route;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/23.
|
||||
*/
|
||||
public interface SysRouteService extends BaseService<Sys_route> {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_task;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
public interface SysTaskService extends BaseService<Sys_task> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_union;
|
||||
import com.budwk.app.sys.models.Sys_union_group;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
public interface SysUnionGroupService extends BaseService<Sys_union_group> {
|
||||
|
||||
void insert(Sys_union_group group);
|
||||
|
||||
void update(Sys_union_group group);
|
||||
|
||||
void deleteById(String id);
|
||||
|
||||
/**
|
||||
* 查询非组长的成员
|
||||
* @param unionId 分工会id
|
||||
* @param keyword 关键字
|
||||
*/
|
||||
List<NutMap> listNotLeader(String unionId, String keyword);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param pageForm 分页
|
||||
* @param unionId 分工会id
|
||||
* @return
|
||||
*/
|
||||
Pagination pageData(PageForm pageForm, String unionId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_union;
|
||||
|
||||
public interface SysUnionService extends BaseService<Sys_union> {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
public interface SysUnitService extends BaseService<Sys_unit> {
|
||||
/**
|
||||
* 保存单位
|
||||
*
|
||||
* @param unit
|
||||
* @param pid
|
||||
*/
|
||||
void save(Sys_unit unit, String pid);
|
||||
|
||||
/**
|
||||
* 级联删除单位及单位下用户
|
||||
*
|
||||
* @param unit
|
||||
*/
|
||||
void deleteAndChild(Sys_unit unit);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
|
||||
import com.budwk.app.base.enums.LoginType;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.exception.UnknownAccountException;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
public interface SysUserService extends BaseService<Sys_user> {
|
||||
/**
|
||||
* 获取用户权限标识
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<String> getPermissionList(String userId);
|
||||
|
||||
/**
|
||||
* 查询用户的角色
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
List<String> getRoleCodeList(Sys_user user);
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的菜单
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getMenus(String userId);
|
||||
|
||||
/**
|
||||
* 通过用户ID获取菜单及权限
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getMenusAndButtons(String userId);
|
||||
|
||||
List<Sys_menu> getMenusAndButtons(String userId, String platform);
|
||||
|
||||
/**
|
||||
* 通过用户ID获取菜单
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getDatas(String userId);
|
||||
|
||||
/**
|
||||
* 绑定菜单到用户
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
Sys_user fillMenu(Sys_user user);
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
void deleteById(String userId);
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
*
|
||||
* @param userIds
|
||||
*/
|
||||
void deleteByIds(String[] userIds);
|
||||
|
||||
/**
|
||||
* 通过用户ID和菜单父ID获取下级权限菜单
|
||||
*
|
||||
* @param userId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getRoleMenus(String userId, String pid);
|
||||
|
||||
/**
|
||||
* 判断用户是否有下级数据权限
|
||||
*
|
||||
* @param userId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
boolean hasChildren(String userId, String pid);
|
||||
|
||||
/**
|
||||
* 清除一个用户的缓存
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
void deleteCache(String userId);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
|
||||
/**
|
||||
* 检查用户是否存在
|
||||
*
|
||||
* @param loginname 用户名
|
||||
*/
|
||||
void checkLoginname(String loginname) throws BaseException;
|
||||
|
||||
/**
|
||||
* 检查第三方平台用户名是否存在系统中
|
||||
* 同上区别是这个会抛出UnknownAccountException
|
||||
*/
|
||||
void checkThirdPlatformLoginName(String loginname) throws UnknownAccountException;
|
||||
|
||||
/**
|
||||
* 检查用户是否存在
|
||||
*
|
||||
* @param mobile 手机号码
|
||||
*/
|
||||
void checkMobile(String mobile) throws BaseException;
|
||||
|
||||
/**
|
||||
* 通过用户名和密码获取用户信息
|
||||
*
|
||||
* @param loginname 用户名
|
||||
* @param passowrd 密码
|
||||
* @return
|
||||
* @throws BaseException
|
||||
*/
|
||||
Sys_user loginByPassword(String loginname, String passowrd) throws BaseException;
|
||||
|
||||
/**
|
||||
* 通过短信验证码登录
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @return
|
||||
* @throws BaseException
|
||||
*/
|
||||
Sys_user loginByMobile(String mobile) throws BaseException;
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户信息
|
||||
* @param loginname
|
||||
* @return
|
||||
*/
|
||||
Sys_user loginByLoginName(String loginname);
|
||||
|
||||
/**
|
||||
* 通过用户名获取用户信息
|
||||
*
|
||||
* @param loginname 用户名
|
||||
* @return
|
||||
* @throws BaseException
|
||||
*/
|
||||
Sys_user getUserByLoginname(String loginname) throws BaseException;
|
||||
|
||||
/**
|
||||
* 通过用户ID获取用户信息
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @return
|
||||
* @throws BaseException
|
||||
*/
|
||||
Sys_user getUserById(String id) throws BaseException;
|
||||
|
||||
/**
|
||||
* 获取登录用户及菜单信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return
|
||||
*/
|
||||
Sys_user getUserAndMenuById(String userId);
|
||||
|
||||
/**
|
||||
* 更新用户登录信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param ip IP地址
|
||||
*/
|
||||
void setLoginInfo(String userId, String ip);
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param user 用户
|
||||
* @param loginType 登录类型
|
||||
* @param request 请求
|
||||
* @return 跳转地址
|
||||
*/
|
||||
String loginPlus(Sys_user user, LoginType loginType, HttpServletRequest request);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_api;
|
||||
import com.budwk.app.sys.services.SysApiService;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemove;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_api",isHash = true)
|
||||
public class SysApiServiceImpl extends BaseServiceImpl<Sys_api> implements SysApiService {
|
||||
public SysApiServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
private String getAppid() {
|
||||
String appid = R.sg(16).next().replaceAll("_", "z");
|
||||
if (this.count(Cnd.where("appid", "=", appid)) > 0) {
|
||||
return getAppid();
|
||||
}
|
||||
return appid;
|
||||
}
|
||||
|
||||
public void createAppkey(String name, String userId) throws Exception {
|
||||
String appid = getAppid();
|
||||
Sys_api sysApi = new Sys_api();
|
||||
sysApi.setName(name);
|
||||
sysApi.setDisabled(false);
|
||||
sysApi.setAppid(appid);
|
||||
sysApi.setAppkey(R.sg(30).next().replaceAll("_", "z"));
|
||||
sysApi.setCreatedBy(userId);
|
||||
sysApi.setCreatedAt(System.currentTimeMillis());
|
||||
this.insert(sysApi);
|
||||
this.getAppkey(appid);//调用生成缓存
|
||||
}
|
||||
|
||||
public void deleteAppkey(String appid) throws Exception {
|
||||
this.delete(appid);
|
||||
this.deleteCache(appid);
|
||||
}
|
||||
|
||||
public void updateAppkey(String appid, boolean disabled) throws Exception {
|
||||
this.update(Chain.make("disabled", disabled), Cnd.where("appid", "=", appid));
|
||||
this.deleteCache(appid);
|
||||
this.getAppkey(appid);//调用生成缓存
|
||||
}
|
||||
|
||||
//注意这个cacheKey 是和 web-api 对应一致的,便于直接从redis取值,而不用依赖sys模块
|
||||
@CacheResult(cacheKey = "${appid}_appkey")
|
||||
public String getAppkey(String appid) {
|
||||
Sys_api sysApi = this.fetch(Cnd.where("appid", "=", appid).and("disabled", "=", false));
|
||||
if (sysApi != null) {
|
||||
return sysApi.getAppkey();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@CacheRemove(cacheKey = "${appid}_*")
|
||||
//可以通过el表达式加 * 通配符来批量删除一批缓存
|
||||
public void deleteCache(String appid) {
|
||||
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_app_conf;
|
||||
import com.budwk.app.sys.services.SysAppConfService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2019/2/27.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysAppConfServiceImpl extends BaseServiceImpl<Sys_app_conf> implements SysAppConfService {
|
||||
public SysAppConfServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
public List<String> getConfNameList() {
|
||||
Sql sql = Sqls.create("SELECT DISTINCT confName FROM sys_app_conf");
|
||||
sql.setCallback(Sqls.callback.strs());
|
||||
this.dao().execute(sql);
|
||||
return sql.getList(String.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_app_list;
|
||||
import com.budwk.app.sys.services.SysAppListService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2019/2/27.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysAppListServiceImpl extends BaseServiceImpl<Sys_app_list> implements SysAppListService {
|
||||
public SysAppListServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
public List<String> getAppNameList() {
|
||||
Sql sql = Sqls.create("SELECT DISTINCT appName FROM sys_app_list");
|
||||
sql.setCallback(Sqls.callback.strs());
|
||||
this.dao().execute(sql);
|
||||
return sql.getList(String.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_app_task;
|
||||
import com.budwk.app.sys.services.SysAppTaskService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2019/2/27.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysAppTaskServiceImpl extends BaseServiceImpl<Sys_app_task> implements SysAppTaskService {
|
||||
public SysAppTaskServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_config;
|
||||
import com.budwk.app.sys.services.SysConfigService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/23.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysConfigServiceImpl extends BaseServiceImpl<Sys_config> implements SysConfigService {
|
||||
public SysConfigServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
public List<Sys_config> getAllList() {
|
||||
return this.query(Cnd.where("delFlag", "=", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_config getValueByKey(String key) {
|
||||
Sys_config sys_config = fetch(key);
|
||||
if (Lang.isEmpty(sys_config)) {
|
||||
throw new BaseException("系统参数{}键不存在", key);
|
||||
}
|
||||
return sys_config;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,500 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateField;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.thread.AsyncUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.event.user.SysUserEvent;
|
||||
import com.budwk.app.base.event.user.SysUserPublisher;
|
||||
import com.budwk.app.base.utils.ConditionGroupUtil;
|
||||
import com.budwk.app.base.utils.ManyAddOrRenewUtil;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.annotation.DataCenterColumn;
|
||||
import com.budwk.app.sys.models.*;
|
||||
import com.budwk.app.sys.param.SysDataUserUpdateParam;
|
||||
import com.budwk.app.sys.services.SysDataUserUpdateService;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.zhgh.staffmanage.member.constant.MemberChangeOrigin;
|
||||
import com.budwk.app.zhgh.staffmanage.member.constant.MemberChangeType;
|
||||
import com.budwk.app.zhgh.staffmanage.member.service.MemberManageService;
|
||||
import com.budwk.app.zhgh.staffmanage.specialstaff.model.SpecialStaff;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.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 org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.Mvcs;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 全量更新系统用户数据
|
||||
*/
|
||||
@Slf4j
|
||||
@IocBean
|
||||
public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private ThreadPoolTaskExecutor executorService;
|
||||
|
||||
/**
|
||||
* 字段映射类,用于缓存反射结果
|
||||
*/
|
||||
private static class FieldMapping {
|
||||
final Field field;
|
||||
final String key;
|
||||
final String name;
|
||||
|
||||
FieldMapping(Field field, DataCenterColumn annotation) {
|
||||
this.field = field;
|
||||
this.key = annotation.key();
|
||||
this.name = annotation.name();
|
||||
field.setAccessible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段映射缓存
|
||||
*/
|
||||
private static List<FieldMapping> fieldMappings;
|
||||
|
||||
/**
|
||||
* 获取带有DataCenterColumn注解的字段映射,使用懒加载模式
|
||||
*
|
||||
* @return 字段映射列表
|
||||
*/
|
||||
private static List<FieldMapping> getFieldMappings() {
|
||||
if (fieldMappings == null) {
|
||||
synchronized (SysDataUserAllUpdateServiceImpl.class) {
|
||||
if (fieldMappings == null) {
|
||||
List<FieldMapping> mappings = new ArrayList<>();
|
||||
// 使用HuTool的反射工具获取所有字段,包括继承的字段
|
||||
Field[] fields = cn.hutool.core.util.ReflectUtil.getFields(Sys_user.class);
|
||||
for (Field field : fields) {
|
||||
DataCenterColumn annotation = field.getAnnotation(DataCenterColumn.class);
|
||||
if (annotation != null) {
|
||||
mappings.add(new FieldMapping(field, annotation));
|
||||
}
|
||||
}
|
||||
fieldMappings = mappings;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fieldMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户是否符合会员条件
|
||||
*
|
||||
* @param userState 用户状态
|
||||
* @param preparedBy 聘用方式
|
||||
* @param postDoctoralJoinDate 博士后进站时间
|
||||
* @return 是否符合会员条件
|
||||
*/
|
||||
private boolean checkMembershipEligibility(String userState, String preparedBy, Date postDoctoralJoinDate) {
|
||||
// 博士后单独判断:只要进站时间在两年内就是会员
|
||||
if ("博士后".equals(preparedBy)) {
|
||||
if (postDoctoralJoinDate != null) {
|
||||
Date twoYearsAgo = DateUtil.offset(DateUtil.date(), DateField.YEAR, -2).toJdkDate();
|
||||
return postDoctoralJoinDate.after(twoYearsAgo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 其他人员需要判断在岗状态和聘用方式
|
||||
if (!"在岗".equals(userState)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断聘用方式
|
||||
Set<String> memberPreparedByTypes = new HashSet<>(Arrays.asList("新人事代理", "校聘合同制", "事业编制"));
|
||||
return memberPreparedByTypes.contains(preparedBy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量更新用户数据
|
||||
*
|
||||
* @param updateParam 更新参数
|
||||
* @return 更新结果描述
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public String update(SysDataUserUpdateParam updateParam) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("开始全量更新用户数据");
|
||||
|
||||
// 获取角色信息
|
||||
Sys_role publicRole = sysRoleService.getByCode(RoleConstant.PUBLIC);
|
||||
Sys_role memberRole = sysRoleService.getByCode(RoleConstant.MEMBER);
|
||||
|
||||
// 查询数据源
|
||||
Cnd cnd = Cnd.where(Sys_user_source::getPullTime, "=", updateParam.getPullTime());
|
||||
|
||||
// 处理复杂条件
|
||||
if (updateParam.getConditionGroup() != null) {
|
||||
cnd = ConditionGroupUtil.applyConditionGroup(cnd, updateParam.getConditionGroup());
|
||||
}
|
||||
|
||||
List<Sys_user_source> sources = dao.query(Sys_user_source.class, cnd.groupBy("loginname"));
|
||||
log.info("符合条件的数据源记录数: {}", sources.size());
|
||||
|
||||
// 查询系统用户
|
||||
List<Sys_user> sysUsers = dao.query(Sys_user.class, Cnd.NEW().groupBy("loginname"));
|
||||
Map<String, Sys_user> userMap = sysUsers.stream().collect(Collectors.toMap(Sys_user::getLoginname, sysUser -> sysUser));
|
||||
|
||||
// 准备数据集合
|
||||
List<Sys_user> needDoUpdateList = new ArrayList<>();
|
||||
List<Sys_user> needInitUserList = new ArrayList<>();
|
||||
List<Sys_user_history> histories = new ArrayList<>();
|
||||
List<String> addMemberUserIds = Collections.synchronizedList(new ArrayList<>());
|
||||
List<String> removeMemberUserIds = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
// 处理每条数据
|
||||
for (Sys_user_source source : sources) {
|
||||
Sys_user user = userMap.get(source.getLoginname());
|
||||
|
||||
// 创建用户对象
|
||||
Sys_user u = new Sys_user();
|
||||
BeanUtils.copyProperties(source, u);
|
||||
|
||||
if (user == null) {
|
||||
// 新增用户,初始化数据
|
||||
String salt = R.UU32();
|
||||
u.setSalt(salt);
|
||||
u.setPassword(PwdUtil.getPassword(PwdUtil.generate(12), salt));
|
||||
|
||||
// 检查是否符合会员条件
|
||||
boolean shouldBeMember = checkMembershipEligibility(
|
||||
source.getUserState(),
|
||||
source.getPreparedBy(),
|
||||
source.getPostDoctoralJoinDate()
|
||||
);
|
||||
|
||||
if (shouldBeMember) {
|
||||
u.setMember(true);
|
||||
addMemberUserIds.add(u.getId());
|
||||
} else {
|
||||
u.setMember(false);
|
||||
}
|
||||
|
||||
needInitUserList.add(u);
|
||||
} else {
|
||||
// 修改现有用户
|
||||
u.setId(user.getId());
|
||||
|
||||
// 检查会员资格
|
||||
boolean shouldBeMember = checkMembershipEligibility(
|
||||
source.getUserState(),
|
||||
source.getPreparedBy(),
|
||||
source.getPostDoctoralJoinDate()
|
||||
);
|
||||
|
||||
// 更新会员状态
|
||||
boolean currentIsMember = user.getMember() != null && user.getMember();
|
||||
|
||||
if (shouldBeMember && !currentIsMember) {
|
||||
// 添加会员
|
||||
u.setMember(true);
|
||||
addMemberUserIds.add(user.getId());
|
||||
} else if (!shouldBeMember && currentIsMember) {
|
||||
// 移除会员
|
||||
u.setMember(false);
|
||||
removeMemberUserIds.add(user.getId());
|
||||
}
|
||||
|
||||
needDoUpdateList.add(u);
|
||||
}
|
||||
|
||||
// 创建历史记录
|
||||
Sys_user_history history = createHistory(source, user);
|
||||
if (Lang.isNotEmpty(history)) {
|
||||
if (user != null) {
|
||||
histories.add(history);
|
||||
} else if (Lang.isNotEmpty(history.getChangeTypes()) && history.getChangeTypes().contains(MemberChangeType.NEW.name())) {
|
||||
histories.add(history);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用CompletableFuture处理并行任务
|
||||
List<CompletableFuture<Void>> updateTasks = new ArrayList<>();
|
||||
|
||||
// 1. 新增用户 - 使用批量处理
|
||||
if (Lang.isNotEmpty(needInitUserList)) {
|
||||
CompletableFuture<Void> insertTask = CompletableFuture.runAsync(() -> {
|
||||
log.info("新增用户: {} 个", needInitUserList.size());
|
||||
// 分批处理,每批200条
|
||||
List<List<Sys_user>> batches = ListUtil.split(needInitUserList, 500);
|
||||
batches.forEach(batch -> {
|
||||
try {
|
||||
dao.fastInsert(batch);
|
||||
} catch (Exception e) {
|
||||
log.error("批量新增用户异常", e);
|
||||
}
|
||||
});
|
||||
}, executorService);
|
||||
updateTasks.add(insertTask);
|
||||
|
||||
// 异步处理公共角色分配
|
||||
if (!needInitUserList.isEmpty()) {
|
||||
CompletableFuture<Void> roleTask = CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
log.info("为新用户分配公共角色");
|
||||
List<Sys_user_role> roleList = needInitUserList.stream().map(item -> {
|
||||
Sys_user_role userRole = new Sys_user_role();
|
||||
userRole.setRoleId(publicRole.getId());
|
||||
userRole.setUserId(item.getId());
|
||||
return userRole;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (!roleList.isEmpty()) {
|
||||
// 分批处理角色分配
|
||||
List<List<Sys_user_role>> roleBatches = ListUtil.split(roleList, 500);
|
||||
roleBatches.forEach(batch -> {
|
||||
try {
|
||||
dao.fastInsert(batch);
|
||||
} catch (Exception e) {
|
||||
log.error("批量分配角色异常", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("分配公共角色异常", e);
|
||||
}
|
||||
}, executorService);
|
||||
// 不等待角色分配完成
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 更新现有用户 - 使用批量处理
|
||||
if (Lang.isNotEmpty(needDoUpdateList)) {
|
||||
CompletableFuture<Void> updateTask = CompletableFuture.runAsync(() -> {
|
||||
log.info("更新用户: {} 个", needDoUpdateList.size());
|
||||
// 分批处理,每批200条
|
||||
List<List<Sys_user>> batches = ListUtil.split(needDoUpdateList, 500);
|
||||
batches.forEach(batch -> {
|
||||
try {
|
||||
dao.updateIgnoreNull(batch);
|
||||
} catch (Exception e) {
|
||||
log.error("批量更新用户异常", e);
|
||||
}
|
||||
});
|
||||
}, executorService);
|
||||
updateTasks.add(updateTask);
|
||||
}
|
||||
|
||||
// 等待用户数据更新完成
|
||||
try {
|
||||
// 设置超时时间,避免无限等待
|
||||
CompletableFuture.allOf(updateTasks.toArray(new CompletableFuture[0]))
|
||||
.get(5, TimeUnit.MINUTES);
|
||||
} catch (TimeoutException e) {
|
||||
log.warn("更新用户数据超时");
|
||||
return "更新超时,请检查数据处理情况";
|
||||
} catch (Exception e) {
|
||||
log.error("更新用户数据异常", e);
|
||||
return "更新失败: " + e.getMessage();
|
||||
}
|
||||
|
||||
// 3. 异步添加历史记录 - 不等待完成
|
||||
if (Lang.isNotEmpty(histories)) {
|
||||
executorService.execute(() -> {
|
||||
log.info("添加历史记录: {} 条", histories.size());
|
||||
// 分批处理历史记录
|
||||
List<List<Sys_user_history>> batches = ListUtil.split(histories, 500);
|
||||
batches.forEach(batch -> {
|
||||
try {
|
||||
dao.fastInsert(batch);
|
||||
} catch (Exception e) {
|
||||
log.error("批量添加历史记录异常", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 异步添加会员角色 - 不等待完成
|
||||
if (Lang.isNotEmpty(addMemberUserIds)) {
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
log.info("添加会员角色: {} 个", addMemberUserIds.size());
|
||||
List<Sys_user_role> roleList = addMemberUserIds.stream().map(id -> {
|
||||
Sys_user_role userRole = new Sys_user_role();
|
||||
userRole.setRoleId(memberRole.getId());
|
||||
userRole.setUserId(id);
|
||||
return userRole;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (!roleList.isEmpty()) {
|
||||
// 分批处理角色分配
|
||||
List<List<Sys_user_role>> batches = ListUtil.split(roleList, 500);
|
||||
batches.forEach(batch -> {
|
||||
try {
|
||||
dao.fastInsert(batch);
|
||||
} catch (Exception e) {
|
||||
log.error("批量添加会员角色异常", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("添加会员角色异常", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 异步移除会员角色 - 不等待完成
|
||||
if (Lang.isNotEmpty(removeMemberUserIds)) {
|
||||
executorService.execute(() -> {
|
||||
try {
|
||||
log.info("移除会员角色: {} 个", removeMemberUserIds.size());
|
||||
// 批量处理,避免IN子句过长
|
||||
List<List<String>> batches = ListUtil.split(removeMemberUserIds, 500);
|
||||
for (List<String> batch : batches) {
|
||||
try {
|
||||
dao.update(Sys_user.class, Chain.make("member", false), Cnd.where("id", "in", batch));
|
||||
dao.clear(Sys_user_role.class, Cnd.where("userId", "in", batch).and("roleId", "=", memberRole.getId()));
|
||||
} catch (Exception e) {
|
||||
log.error("批量移除会员角色异常", e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("移除会员角色异常", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("全量更新用户数据完成,耗时: {} 毫秒", (endTime - startTime));
|
||||
|
||||
return "更新完成: 新增用户 " + needInitUserList.size() + " 个, 更新用户 " + needDoUpdateList.size()
|
||||
+ " 个, 待添加会员 " + addMemberUserIds.size() + " 个, 待移除会员 " + removeMemberUserIds.size() + " 个";
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建变更的历史数据
|
||||
*
|
||||
* @param source 数据源用户
|
||||
* @param user 系统用户
|
||||
* @return 历史记录
|
||||
*/
|
||||
private Sys_user_history createHistory(Sys_user_source source, Sys_user user) {
|
||||
List<String> changeTypes = new ArrayList<>();
|
||||
List<NutMap> changeList = new ArrayList<>();
|
||||
|
||||
// 初始化历史记录
|
||||
Sys_user_history history = new Sys_user_history();
|
||||
BeanUtil.copyProperties(source, history);
|
||||
history.setId(R.UU32());
|
||||
history.setChangeTime(DateUtil.date());
|
||||
history.setChangeOrigin(MemberChangeOrigin.SYSTEM.name());
|
||||
|
||||
// 新用户直接返回NEW类型
|
||||
if (user == null) {
|
||||
changeTypes.add(MemberChangeType.NEW.name());
|
||||
history.setChangeTypes(changeTypes);
|
||||
return history;
|
||||
}
|
||||
|
||||
// 遍历带有DataCenterColumn注解的字段进行比较
|
||||
for (FieldMapping mapping : getFieldMappings()) {
|
||||
try {
|
||||
Object sourceValue = mapping.field.get(source);
|
||||
Object userValue = mapping.field.get(user);
|
||||
|
||||
// 如果值不相等,记录变更
|
||||
if (!ObjectUtil.equals(sourceValue, userValue)) {
|
||||
NutMap change = NutMap.NEW();
|
||||
change.put("name", mapping.name);
|
||||
change.put("field", mapping.field.getName());
|
||||
change.put("value", userValue == null ? "" : userValue.toString());
|
||||
change.put("newValue", sourceValue == null ? "" : sourceValue.toString());
|
||||
changeList.add(change);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("字段比较失败: {}", mapping.field.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有任何字段变更,添加基本信息变更类型
|
||||
if (!changeList.isEmpty()) {
|
||||
changeTypes.add(MemberChangeType.BASIC_CHANGE.name());
|
||||
}
|
||||
|
||||
// 特殊字段变更处理
|
||||
// 1. 会员状态变更
|
||||
// if (!ObjectUtil.equals(user.getMember(), source.getMember())) {
|
||||
// if (source.getMember()) {
|
||||
// changeTypes.add(MemberChangeType.RESTORE.name());
|
||||
// } else {
|
||||
// changeTypes.add(MemberChangeType.WITHDRAWAL.name());
|
||||
// }
|
||||
// }
|
||||
|
||||
// 2. 单位变更
|
||||
if (!ObjectUtil.equals(user.getUnitId(), source.getUnitId())) {
|
||||
changeTypes.add(MemberChangeType.UNIT_CHANGE.name());
|
||||
NutMap change = NutMap.NEW();
|
||||
change.put("name", "单位");
|
||||
change.put("field", "unitId");
|
||||
change.put("value", user.getUnitId());
|
||||
change.put("newValue", source.getUnitId());
|
||||
changeList.add(change);
|
||||
}
|
||||
|
||||
// 如果没有任何变更,返回null
|
||||
if (changeTypes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 生成变更信息描述
|
||||
String changeInfos = changeList.stream()
|
||||
.map(v -> v.getString("name") + ":" +
|
||||
HtmlUtil.cleanHtmlTag(v.getString("value")) + "→" +
|
||||
HtmlUtil.cleanHtmlTag(v.getString("newValue")))
|
||||
.collect(Collectors.joining(";"));
|
||||
|
||||
// 设置历史记录信息
|
||||
history.setChangeTypes(changeTypes);
|
||||
history.setChangeInfos(changeList);
|
||||
history.setChangeInfosStr(changeInfos);
|
||||
|
||||
return history;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.thread.AsyncUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.utils.ConditionGroupUtil;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.models.*;
|
||||
import com.budwk.app.sys.param.SysDataUserUpdateParam;
|
||||
import com.budwk.app.sys.services.SysDataUserUpdateService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
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.random.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* 增量更新系统用户数据
|
||||
*/
|
||||
@IocBean
|
||||
public class SysDataUserIncrUpdateServiceImpl implements SysDataUserUpdateService {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Override
|
||||
public String update(SysDataUserUpdateParam updateParam) {
|
||||
// 基本SQL查询
|
||||
Cnd cnd = Cnd.where("pullTime", "=", updateParam.getPullTime())
|
||||
.and("loginname", "NOT IN", Sqls.create("SELECT loginname FROM sys_user"));
|
||||
|
||||
// 处理复杂条件
|
||||
if (updateParam.getConditionGroup() != null) {
|
||||
cnd = ConditionGroupUtil.applyConditionGroup(cnd, updateParam.getConditionGroup());
|
||||
}
|
||||
|
||||
cnd.groupBy("loginname");
|
||||
|
||||
// 执行查询
|
||||
List<Sys_user_source> userSources = dao.query(Sys_user_source.class, cnd);
|
||||
|
||||
//加入到系统用户表
|
||||
List<Sys_user> sysUsers = BeanUtil.copyToList(userSources, Sys_user.class);
|
||||
for (Sys_user sysUser : sysUsers) {
|
||||
//重新设置
|
||||
sysUser.setId(R.UU32());
|
||||
String salt = R.UU32();
|
||||
sysUser.setSalt(salt);
|
||||
// 随机密码
|
||||
String pwd = PwdUtil.generate(12);
|
||||
sysUser.setPassword(PwdUtil.getPassword(pwd, salt));
|
||||
sysUser.setLoginCount(0);
|
||||
|
||||
// 检查是否符合会员条件
|
||||
// 1. 用户状态为"在岗"
|
||||
if ("在岗".equals(sysUser.getUserState())) {
|
||||
// 2. 检查聘用方式条件
|
||||
List<String> membershipQualifyingPreparedBy = Arrays.asList("新人事代理", "校聘合同制", "事业编制");
|
||||
|
||||
// 第一种情况:聘用方式在指定列表中
|
||||
boolean isQualifiedByPreparedBy = membershipQualifyingPreparedBy.contains(sysUser.getPreparedBy());
|
||||
|
||||
// 第二种情况:聘用方式是博士后,且进站时间不超过两年
|
||||
boolean isQualifiedPostdoc = false;
|
||||
if ("博士后".equals(sysUser.getPreparedBy()) && sysUser.getPostDoctoralJoinDate() != null) {
|
||||
Calendar twoYearsAgo = Calendar.getInstance();
|
||||
twoYearsAgo.add(Calendar.YEAR, -2);
|
||||
Date twoYearsAgoDate = twoYearsAgo.getTime();
|
||||
isQualifiedPostdoc = sysUser.getPostDoctoralJoinDate().after(twoYearsAgoDate);
|
||||
}
|
||||
|
||||
// 如果满足任一条件,设置为会员
|
||||
if (isQualifiedByPreparedBy || isQualifiedPostdoc) {
|
||||
sysUser.setMember(true);
|
||||
} else {
|
||||
sysUser.setMember(false);
|
||||
}
|
||||
} else {
|
||||
sysUser.setMember(false);
|
||||
}
|
||||
}
|
||||
|
||||
List<List<Sys_user>> splitSysUsers = ListUtil.split(sysUsers, 500);
|
||||
List<CompletableFuture<List<Sys_user>>> splitSysUsersFutures = splitSysUsers.stream().map(v -> CompletableFuture.supplyAsync(() -> dao.fastInsert(v))).toList();
|
||||
//等待任务全部完成
|
||||
AsyncUtil.waitAll(CompletableFuture.allOf(splitSysUsersFutures.toArray(new CompletableFuture[0])));
|
||||
|
||||
Sys_role publicRole = sysRoleService.getByCode(RoleConstant.PUBLIC);
|
||||
|
||||
//添加公共角色
|
||||
List<Sys_user_role> sysUserRoles = sysUsers.stream().map(user -> {
|
||||
Sys_user_role sysUserRole = new Sys_user_role();
|
||||
sysUserRole.setUserId(user.getId());
|
||||
sysUserRole.setRoleId(publicRole.getId());
|
||||
return sysUserRole;
|
||||
}).toList();
|
||||
ThreadUtil.execAsync(() -> {
|
||||
dao.insert(sysUserRoles);
|
||||
});
|
||||
sysRoleService.clearCache();
|
||||
|
||||
//比较单位数据
|
||||
List<Sys_unit> sysUnits = dao.query(Sys_unit.class, Cnd.where(Sys_unit::getUnitLevel, "=", 2));
|
||||
List<String> sysUnitIds = sysUnits.stream().map(Sys_unit::getId).toList();
|
||||
|
||||
//信息中心的数据 转为单位代码 ->单位名称 map
|
||||
var unitIdNameMap = userSources.stream()
|
||||
.filter(v -> StrUtil.isAllNotBlank(v.getUnitId(), v.getUnitName()))
|
||||
.collect(java.util.stream.Collectors.toMap(
|
||||
Sys_user_source::getUnitId,
|
||||
Sys_user_source::getUnitName,
|
||||
(existingValue, newValue) -> newValue));
|
||||
|
||||
//需要新增的单位
|
||||
List<Sys_unit> insertUnits = unitIdNameMap.entrySet().stream()
|
||||
.filter(entry -> !sysUnitIds.contains(entry.getKey()))
|
||||
.map(entry -> {
|
||||
Sys_unit sysUnit = new Sys_unit();
|
||||
sysUnit.setId(entry.getKey());
|
||||
sysUnit.setName(entry.getValue());
|
||||
sysUnit.setParentId("1");
|
||||
sysUnit.setUnitLevel(2);
|
||||
return sysUnit;
|
||||
}).toList();
|
||||
ThreadUtil.execAsync(() -> {
|
||||
dao.insert(insertUnits);
|
||||
});
|
||||
|
||||
// 计算设置为会员的人数
|
||||
long memberCount = sysUsers.stream().filter(Sys_user::getMember).count();
|
||||
|
||||
return StrUtil.format("增量更新成功,本次更新新入职老师{}人,新增单位{}个,设置为会员{}人。", sysUsers.size(), insertUnits.size(), memberCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.annotation.DataCenterColumn;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.models.Sys_user_source;
|
||||
import com.budwk.app.sys.services.SysDataUserPullService;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
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.util.NutMap;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@Slf4j
|
||||
public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source> implements SysDataUserPullService {
|
||||
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
public SysDataUserPullServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段映射类,用于缓存反射结果
|
||||
*/
|
||||
private static class FieldMapping {
|
||||
final Field field;
|
||||
final String key;
|
||||
|
||||
FieldMapping(Field field, String key) {
|
||||
this.field = field;
|
||||
this.key = key;
|
||||
field.setAccessible(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段映射缓存
|
||||
*/
|
||||
private static List<FieldMapping> fieldMappings;
|
||||
|
||||
/**
|
||||
* 获取字段映射,使用懒加载模式
|
||||
*/
|
||||
private static List<FieldMapping> getFieldMappings() {
|
||||
if (fieldMappings == null) {
|
||||
synchronized (SysDataUserPullServiceImpl.class) {
|
||||
if (fieldMappings == null) {
|
||||
List<FieldMapping> mappings = new ArrayList<>();
|
||||
Field[] fields = Sys_user.class.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
DataCenterColumn annotation = field.getAnnotation(DataCenterColumn.class);
|
||||
if (annotation != null) {
|
||||
mappings.add(new FieldMapping(field, annotation.key()));
|
||||
}
|
||||
}
|
||||
fieldMappings = mappings;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fieldMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date pull() {
|
||||
try {
|
||||
// 博士后进站日期数据
|
||||
Map<String, Date> doctoralData = pullPostDoctoral();
|
||||
|
||||
Date nowDate = new Date();
|
||||
String appId = "1926887238437818370";
|
||||
String secret = "32df31fcf4fc43f9a647ee1f47134f36";
|
||||
|
||||
List<JSONObject> rawDataList = new ArrayList<>();
|
||||
int skip = 0;
|
||||
int totalCount = 0;
|
||||
boolean firstRequest = true;
|
||||
do {
|
||||
long ts = System.currentTimeMillis();
|
||||
String sign = Base64.encode(DigestUtil.md5Hex(appId + secret + ts, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0026");
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("appId", appId);
|
||||
httpRequest.header("timestamp", String.valueOf(ts));
|
||||
httpRequest.header("sign", sign);
|
||||
|
||||
HashMap<String, Object> reqBody = new HashMap<>();
|
||||
reqBody.put("$count", true);
|
||||
reqBody.put("$skip", skip);
|
||||
reqBody.put("$top", 1000);
|
||||
// reqBody.put("$filter", "yrfsmc eq '事业编制' or yrfsmc eq '校聘合同制' or yrfsmc eq '新人事代理' or yrfsmc eq '博士后' or yrfsmc eq '劳动合同'");
|
||||
|
||||
httpRequest.body(JSONUtil.toJsonStr(reqBody));
|
||||
String resBody = httpRequest.execute().body();
|
||||
|
||||
JSONObject entries = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (firstRequest) {
|
||||
totalCount = entries.getInt("@odata.count", 0);
|
||||
firstRequest = false;
|
||||
}
|
||||
|
||||
JSONArray value = entries.getJSONArray("value");
|
||||
|
||||
if (!value.isEmpty()) {
|
||||
// 先收集所有原始数据
|
||||
List<JSONObject> currentBatch = value.stream().map(v -> (JSONObject) v).toList();
|
||||
rawDataList.addAll(currentBatch);
|
||||
skip += currentBatch.size();
|
||||
log.info("数据拉取进度: {}/{}", rawDataList.size(), totalCount);
|
||||
} else {
|
||||
log.warn("当前批次未获取到数据,skip={}", skip);
|
||||
break;
|
||||
}
|
||||
} while (skip < totalCount);
|
||||
|
||||
// 赋值
|
||||
List<Sys_user_source> latestSourceList = rawDataList.stream().map(raw -> {
|
||||
Sys_user_source sysUser = new Sys_user_source();
|
||||
|
||||
// 使用缓存的字段映射
|
||||
for (FieldMapping mapping : getFieldMappings()) {
|
||||
try {
|
||||
// 根据字段类型设置值
|
||||
if (mapping.field.getType() == String.class) {
|
||||
// 特殊处理性别字段
|
||||
if (mapping.field.getName().equals("sex")) {
|
||||
String xbmc = raw.getStr(mapping.key);
|
||||
mapping.field.set(sysUser, StrUtil.equals("男性", xbmc) ? "男" : StrUtil.equals("女性", xbmc) ? "女" : null);
|
||||
} else {
|
||||
mapping.field.set(sysUser, raw.getStr(mapping.key));
|
||||
}
|
||||
} else if (mapping.field.getType() == Date.class) {
|
||||
mapping.field.set(sysUser, raw.getDate(mapping.key));
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("设置字段值失败: {}", mapping.field.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置博士后的进站日期
|
||||
if (doctoralData.containsKey(sysUser.getLoginname())) {
|
||||
sysUser.setPostDoctoralJoinDate(doctoralData.get(sysUser.getLoginname()));
|
||||
}
|
||||
|
||||
// 设置单位相关信息
|
||||
sysUser.setUnitName(raw.getStr("dwmc"));
|
||||
sysUser.setUnitId(raw.getStr("dwdm"));
|
||||
sysUser.setPullTime(nowDate);
|
||||
return sysUser;
|
||||
}).toList();
|
||||
|
||||
log.info("--------------------");
|
||||
// 插入到数据库
|
||||
dao().insert(latestSourceList);
|
||||
|
||||
return nowDate;
|
||||
} catch (Exception e) {
|
||||
throw new BaseException("数据拉取失败,{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
private void updateDict(List<Sys_user_source> userSources) {
|
||||
//判断是否要更新在职状态字典
|
||||
List<String> sourceUserStates = userSources.stream().map(Sys_user::getUserState).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
//判断是否要更新学历字典
|
||||
List<String> sourceEducations = userSources.stream().map(Sys_user::getEducation).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
//判断是否要更新学位字典
|
||||
List<String> sourceAcademicDegrees = userSources.stream().map(Sys_user::getAcademicDegree).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
//判断是否要更新教职工类别字典
|
||||
List<String> personTypes = userSources.stream().map(Sys_user::getPersonType).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
//判断是否要更新身份类型字典
|
||||
List<String> sourceIdentityTypes = userSources.stream().map(Sys_user::getIdentityType).filter(StrUtil::isNotBlank).distinct().toList();
|
||||
|
||||
//系统在职状态字典
|
||||
List<Sys_dict> sysUserStates = sysDictService.getSubListByCode("USER_STATE");
|
||||
//系统学历字典
|
||||
List<Sys_dict> sysEducations = sysDictService.getSubListByCode("USER_EDUCATION");
|
||||
//系统学位字典
|
||||
List<Sys_dict> sysAcademicDegrees = sysDictService.getSubListByCode("USER_ACADEMIC_DEGREE");
|
||||
//系统教职工类别字典
|
||||
List<Sys_dict> sysStaffTypes = sysDictService.getSubListByCode("USER_STAFF_TYPE");
|
||||
//系统身份类型字典
|
||||
List<Sys_dict> sysIdentityTypes = sysDictService.getSubListByCode("USER_IDENTITY_TYPE");
|
||||
|
||||
//系统中不存在的就插入
|
||||
List<Sys_dict> insertUserStates = sourceUserStates.stream().filter(state -> sysUserStates.stream().noneMatch(dict -> dict.getCode().equals(state))).map(state -> {
|
||||
Sys_dict dict = new Sys_dict();
|
||||
dict.setCode(state);
|
||||
dict.setName(state);
|
||||
return dict;
|
||||
}).toList();
|
||||
|
||||
List<Sys_dict> insertEducations = sourceEducations.stream().filter(education -> sysEducations.stream().noneMatch(dict -> dict.getCode().equals(education))).map(education -> {
|
||||
Sys_dict dict = new Sys_dict();
|
||||
dict.setCode(education);
|
||||
dict.setName(education);
|
||||
return dict;
|
||||
}).toList();
|
||||
|
||||
List<Sys_dict> insertAcademicDegrees = sourceAcademicDegrees.stream().filter(academicDegree -> sysAcademicDegrees.stream().noneMatch(dict -> dict.getCode().equals(academicDegree))).map(academicDegree -> {
|
||||
Sys_dict dict = new Sys_dict();
|
||||
dict.setCode(academicDegree);
|
||||
dict.setName(academicDegree);
|
||||
return dict;
|
||||
}).toList();
|
||||
|
||||
for (Sys_dict dict : insertUserStates) {
|
||||
sysDictService.saveByParentCode(dict, "USER_STATE");
|
||||
}
|
||||
for (Sys_dict dict : insertEducations) {
|
||||
sysDictService.saveByParentCode(dict, "USER_EDUCATION");
|
||||
}
|
||||
for (Sys_dict dict : insertAcademicDegrees) {
|
||||
sysDictService.saveByParentCode(dict, "USER_ACADEMIC_DEGREE");
|
||||
}
|
||||
sysDictService.clearCache();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Date> pullPostDoctoral() {
|
||||
String appId = "1926887238437818370";
|
||||
String secret = "32df31fcf4fc43f9a647ee1f47134f36";
|
||||
|
||||
List<JSONObject> allUsers = new ArrayList<>();
|
||||
int skip = 0;
|
||||
int totalCount = 0;
|
||||
boolean firstRequest = true;
|
||||
|
||||
do {
|
||||
long ts = System.currentTimeMillis();
|
||||
String sign = Base64.encode(DigestUtil.md5Hex(appId + secret + ts, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0040");
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("appId", appId);
|
||||
httpRequest.header("timestamp", String.valueOf(ts));
|
||||
httpRequest.header("sign", sign);
|
||||
|
||||
HashMap<String, Object> reqBody = new HashMap<>();
|
||||
reqBody.put("$count", true);
|
||||
reqBody.put("$skip", skip);
|
||||
reqBody.put("$top", 1000);
|
||||
|
||||
httpRequest.body(JSONUtil.toJsonStr(reqBody));
|
||||
String resBody = httpRequest.execute().body();
|
||||
|
||||
JSONObject entries = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (firstRequest) {
|
||||
totalCount = entries.getInt("@odata.count", 0);
|
||||
firstRequest = false;
|
||||
}
|
||||
|
||||
JSONArray value = entries.getJSONArray("value");
|
||||
|
||||
if (!value.isEmpty()) {
|
||||
List<JSONObject> list = value.stream().map(item -> (JSONObject) item).toList();
|
||||
allUsers.addAll(list);
|
||||
skip += list.size();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
} while (skip < totalCount);
|
||||
|
||||
Map<String, Date> data = allUsers.stream().filter(v -> v.getStr("进站日期") != null).collect(Collectors.toMap(v -> v.getStr("教职工号"), v -> v.getDate("进站日期")));
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public NutMap searchOptions() {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
unitName,
|
||||
userState,
|
||||
preparedBy,
|
||||
personType
|
||||
FROM
|
||||
sys_user_source
|
||||
GROUP BY
|
||||
unitName,
|
||||
userState,
|
||||
preparedBy,
|
||||
personType
|
||||
""");
|
||||
List<NutMap> list = listMap(sql);
|
||||
List<String> unitNames = list.stream().map(user -> user.getString("unitName")).distinct().toList();
|
||||
List<String> userStates = list.stream().map(user -> user.getString("userState")).distinct().toList();
|
||||
List<String> preparedBys = list.stream().map(user -> user.getString("preparedBy")).distinct().toList();
|
||||
List<String> personTypes = list.stream().map(user -> user.getString("personType")).distinct().toList();
|
||||
|
||||
return NutMap.NEW()
|
||||
.addv("unitNames", unitNames)
|
||||
.addv("userStates", userStates)
|
||||
.addv("preparedBys", preparedBys)
|
||||
.addv("personTypes", personTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> pullTimeOptions() {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
pullTime pullTime,
|
||||
count( 1 ) num
|
||||
FROM
|
||||
sys_user_source
|
||||
WHERE
|
||||
pullTime IS NOT NULL
|
||||
GROUP BY
|
||||
pullTime
|
||||
ORDER BY
|
||||
pullTime DESC
|
||||
LIMIT 10
|
||||
""");
|
||||
return listMap(sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
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.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_dict", isHash = true)
|
||||
public class SysDictServiceImpl extends BaseServiceImpl<Sys_dict> implements SysDictService {
|
||||
public SysDictServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过code获取name
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public String getNameByCode(String code) {
|
||||
Sys_dict dict = this.fetch(Cnd.where("code", "=", code));
|
||||
return dict == null ? "" : dict.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取name
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public String getNameById(String id) {
|
||||
Sys_dict dict = this.fetch(id);
|
||||
return dict == null ? "" : dict.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过树path获取下级列表
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public List<Sys_dict> getSubListByPath(String path) {
|
||||
return this.query(Cnd.where("path", "like", Strings.sNull(path) + "____").asc("location"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过父id获取下级列表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public List<Sys_dict> getSubListById(String id) {
|
||||
return this.query(Cnd.where("parentId", "=", Strings.sNull(id)).asc("location"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过code获取下级列表
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public List<Sys_dict> getSubListByCode(String code) {
|
||||
Sys_dict dict = this.fetch(Cnd.where("code", "=", code));
|
||||
return dict == null ? new ArrayList<>() : this.query(Cnd.where("parentId", "=", Strings.sNull(dict.getId())).and("disabled", "=", false).asc("location"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过path获取下级map
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public Map getSubMapByPath(String path) {
|
||||
return this.getMap(Sqls.create("select code,name from sys_dict where path like @path order by location asc").setParam("path", path + "____"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id获取下级map
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public Map getSubMapById(String id) {
|
||||
return this.getMap(Sqls.create("select code,name from sys_dict where parentId = @id order by location asc").setParam("id", id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过code获取下级map
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public Map getSubMapByCode(String code) {
|
||||
Sys_dict dict = this.fetch(Cnd.where("code", "=", code));
|
||||
return dict == null ? new HashMap() : this.getMap(Sqls.create("select code,name from sys_dict where parentId = @id order by location asc").setParam("id", dict.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增字典
|
||||
*
|
||||
* @param dict
|
||||
* @param pid
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void save(Sys_dict dict, String pid) {
|
||||
String path = "";
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
Sys_dict pp = this.fetch(pid);
|
||||
path = pp.getPath();
|
||||
}
|
||||
dict.setPath(getSubPath("sys_dict", "path", path));
|
||||
dict.setParentId(pid);
|
||||
dao().insert(dict);
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
this.update(Chain.make("hasChildren", true), Cnd.where("id", "=", pid));
|
||||
}
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveByParentCode(Sys_dict dict, String parentCode) {
|
||||
Sys_dict parentDict = fetch(Cnd.where("code", "=", parentCode));
|
||||
if (ObjectUtil.isEmpty(parentDict)) {
|
||||
throw new BaseException("父编码为{}的字典不存在", parentCode);
|
||||
}
|
||||
save(dict, parentDict.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 级联删除单位
|
||||
*
|
||||
* @param dict
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteAndChild(Sys_dict dict) {
|
||||
dao().execute(Sqls.create("delete from sys_dict where path like @path").setParam("path", dict.getPath() + "%"));
|
||||
if (!Strings.isEmpty(dict.getParentId())) {
|
||||
int count = count(Cnd.where("parentId", "=", dict.getParentId()));
|
||||
if (count < 1) {
|
||||
dao().execute(Sqls.create("update sys_dict set hasChildren=0 where id=@pid").setParam("pid", dict.getParentId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.ContentType;
|
||||
import com.aspose.words.*;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.base.utils.OfficePlusUtil;
|
||||
import com.budwk.app.sys.enums.SysFileEngineTypeEnum;
|
||||
import com.budwk.app.sys.models.Sys_file;
|
||||
import com.budwk.app.sys.services.SysFileService;
|
||||
import com.budwk.app.sys.utils.SysFileLocalUtil;
|
||||
import com.budwk.app.sys.utils.SysFileMinIoUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Slf4j
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysFileServiceImpl extends BaseServiceImpl<Sys_file> implements SysFileService {
|
||||
|
||||
static String IMG_BASE64_PATTERN = "<img\\s+[^>]*src\\s*=\\s*['\"](data:image/[^'\"]+;base64,[^'\"]+)['\"][^>]*>";
|
||||
|
||||
public SysFileServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadReturnId(String engine, TempFile file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadReturnUrl(String engine, TempFile file) {
|
||||
return this.storageFile(engine, file, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination page(Sys_file file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sys_file> list() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Sys_file sys_file = this.fetch(id);
|
||||
if (ObjectUtil.isEmpty(sys_file)) {
|
||||
sendErrorResponse(response, "文件记录不存在");
|
||||
return;
|
||||
}
|
||||
if (sys_file.getEngine().equals(SysFileEngineTypeEnum.LOCAL.getValue())) {
|
||||
File file = FileUtil.file(sys_file.getStoragePath());
|
||||
if (!FileUtil.exist(file)) {
|
||||
sendErrorResponse(response, "找不到存储的文件");
|
||||
return;
|
||||
}
|
||||
CommonDownloadUtil.download(sys_file.getName(), IoUtil.readBytes(FileUtil.getInputStream(file)), response);
|
||||
} else if (sys_file.getEngine().equals(SysFileEngineTypeEnum.MINIO.getValue())) {
|
||||
byte[] bytes = SysFileMinIoUtil.getFileBytes(sys_file.getBucket(), sys_file.getStoragePath());
|
||||
CommonDownloadUtil.download(sys_file.getName(), bytes, response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] download(String id) throws IOException {
|
||||
Sys_file sys_file = this.fetch(id);
|
||||
if (ObjectUtil.isEmpty(sys_file)) {
|
||||
throw new IOException("文件记录不存在");
|
||||
}
|
||||
if (sys_file.getEngine().equals(SysFileEngineTypeEnum.LOCAL.getValue())) {
|
||||
File file = FileUtil.file(sys_file.getStoragePath());
|
||||
if (!FileUtil.exist(file)) {
|
||||
throw new IOException("找不到存储的文件");
|
||||
}
|
||||
// CommonDownloadUtil.download(sys_file.getName(), IoUtil.readBytes(FileUtil.getInputStream(file)), response);
|
||||
} else if (sys_file.getEngine().equals(SysFileEngineTypeEnum.MINIO.getValue())) {
|
||||
return SysFileMinIoUtil.getFileBytes(sys_file.getBucket(), sys_file.getStoragePath());
|
||||
}
|
||||
throw new IOException("不支持的储存引擎");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertPDF(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
Sys_file sys_file = this.fetch(id);
|
||||
if (ObjectUtil.isEmpty(sys_file)) {
|
||||
sendErrorResponse(response, "文件记录不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sys_file.getEngine().equals(SysFileEngineTypeEnum.LOCAL.getValue())) {
|
||||
File file = FileUtil.file(sys_file.getStoragePath());
|
||||
if (!FileUtil.exist(file)) {
|
||||
sendErrorResponse(response, "找不到存储的文件");
|
||||
return;
|
||||
}
|
||||
File tempFile = File.createTempFile("file_convert", ".pdf");
|
||||
OfficePlusUtil.convert(sys_file.getStoragePath(), tempFile.getPath());
|
||||
CommonDownloadUtil.download(sys_file.getName(), IoUtil.readBytes(FileUtil.getInputStream(tempFile)), response);
|
||||
//删除临时文件
|
||||
FileUtil.del(tempFile.toPath());
|
||||
} else if (sys_file.getEngine().equals(SysFileEngineTypeEnum.MINIO.getValue())) {
|
||||
byte[] bytes = SysFileMinIoUtil.getFileBytes(sys_file.getBucket(), sys_file.getStoragePath());
|
||||
File sourceFile = File.createTempFile("file_convert_origin", "." + sys_file.getSuffix());
|
||||
Files.write(sourceFile.toPath(), bytes, StandardOpenOption.WRITE);
|
||||
File pdfFile = File.createTempFile("file_convert", ".pdf");
|
||||
OfficePlusUtil.convert(sourceFile.getPath(), pdfFile.getPath());
|
||||
CommonDownloadUtil.download(sys_file.getName(), IoUtil.readBytes(FileUtil.getInputStream(pdfFile)), response);
|
||||
//删除临时文件
|
||||
FileUtil.del(sourceFile);
|
||||
FileUtil.del(pdfFile.toPath());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_file detail(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sys_file> previewFileData(String[] ids) {
|
||||
List<Sys_file> files = query(Cnd.where(Sys_file::getId, "in", ids).or("downloadPath", "in", ids));
|
||||
return files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertHtml(TempFile file) {
|
||||
try {
|
||||
Document doc = new Document(file.getInputStream());
|
||||
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
|
||||
if (shape.hasImage()) {
|
||||
ImageSize imageSize = shape.getImageData().getImageSize();
|
||||
shape.setWidth(imageSize.getWidthPoints());
|
||||
shape.setHeight(imageSize.getHeightPoints());
|
||||
}
|
||||
}
|
||||
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
|
||||
saveOptions.setExportImagesAsBase64(true);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
doc.save(bos, saveOptions);
|
||||
String htmlContent = Jsoup.parse(bos.toString()).body().html();
|
||||
|
||||
Pattern pattern = Pattern.compile(IMG_BASE64_PATTERN, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(htmlContent);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String srcValue = matcher.group(1);
|
||||
String[] parts = srcValue.split(";base64,");
|
||||
String base64Content = parts[1];
|
||||
|
||||
try{
|
||||
//转为在线地址 base64很喜欢被信息中心拦截
|
||||
byte[] imageBytes = Base64.getDecoder().decode(base64Content);
|
||||
String imgUrl = storageFile(SysFileEngineTypeEnum.MINIO.getValue(), genFileKey(R.UU32(), R.UU32() + ".png"), imageBytes, false);
|
||||
String replacement = "<img src=\"" + imgUrl + "\">";
|
||||
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
|
||||
}catch (Exception e){
|
||||
matcher.appendReplacement(sb, Matcher.quoteReplacement("<img src=>"));
|
||||
}
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
log.error("文件转换HTML异常", e);
|
||||
throw new BaseException("文件读取失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储文件
|
||||
**/
|
||||
private String storageFile(String engine, TempFile file, boolean returnFileId) {
|
||||
// 如果引擎为空,默认使用本地
|
||||
if (ObjectUtil.isEmpty(engine)) {
|
||||
engine = SysFileEngineTypeEnum.LOCAL.getValue();
|
||||
}
|
||||
|
||||
// 生成id
|
||||
String fileId = R.UU32();
|
||||
|
||||
// 存储桶名称
|
||||
String bucketName = null;
|
||||
|
||||
// 定义存储的url,本地文件返回文件实际路径,其他引擎返回网络地址
|
||||
String storageUrl = null;
|
||||
|
||||
// 根据引擎类型执行不同方法
|
||||
if (engine.equals(SysFileEngineTypeEnum.LOCAL.getValue())) {
|
||||
// 使用固定名称defaultBucketName
|
||||
bucketName = "defaultBucketName";
|
||||
storageUrl = SysFileLocalUtil.storageFileWithReturnUrl(bucketName, genFileKey(fileId, file.getSubmittedFileName()), file.getFile());
|
||||
} else if (engine.equals(SysFileEngineTypeEnum.MINIO.getValue())) {
|
||||
// 使用MINIO默认配置的bucketName
|
||||
bucketName = SysFileMinIoUtil.getDefaultBucketName();
|
||||
storageUrl = SysFileMinIoUtil.storageFileWithReturnUrl(bucketName, genFileKey(fileId, file.getSubmittedFileName()), file);
|
||||
} else {
|
||||
throw new BaseException("不支持的文件引擎:{}", engine);
|
||||
}
|
||||
|
||||
// 将文件信息保存到数据库
|
||||
Sys_file sys_file = new Sys_file();
|
||||
|
||||
// 设置文件id
|
||||
sys_file.setId(fileId);
|
||||
|
||||
// 设置存储引擎类型
|
||||
sys_file.setEngine(engine);
|
||||
sys_file.setBucket(bucketName);
|
||||
sys_file.setName(file.getSubmittedFileName());
|
||||
String suffix = ObjectUtil.isNotEmpty(file.getSubmittedFileName()) ? StrUtil.subAfter(file.getSubmittedFileName(),
|
||||
StrUtil.DOT, true) : null;
|
||||
sys_file.setSuffix(suffix);
|
||||
sys_file.setSizeKb(Convert.toStr(NumberUtil.div(new BigDecimal(file.getSize()), BigDecimal.valueOf(1024))
|
||||
.setScale(0, RoundingMode.HALF_UP)));
|
||||
sys_file.setSizeInfo(FileUtil.readableFileSize(file.getSize()));
|
||||
sys_file.setObjName(ObjectUtil.isNotEmpty(sys_file.getSuffix()) ? fileId + StrUtil.DOT + sys_file.getSuffix() : null);
|
||||
// 如果是图片,则压缩生成缩略图
|
||||
if (ObjectUtil.isNotEmpty(suffix)) {
|
||||
if (isPic(suffix)) {
|
||||
try {
|
||||
sys_file.setThumbnail(ImgUtil.toBase64DataUri(ImgUtil.scale(ImgUtil.toImage(file.getInputStream().readAllBytes()),
|
||||
100, 100, null), suffix));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 存储路径
|
||||
sys_file.setStoragePath(storageUrl);
|
||||
|
||||
// 定义下载地址
|
||||
String downloadUrl;
|
||||
|
||||
downloadUrl = "/platform/sys/file/download?id=" + fileId;
|
||||
sys_file.setDownloadPath(downloadUrl);
|
||||
|
||||
insert(sys_file);
|
||||
|
||||
// 如果是返回id则返回文件id // 否则返回下载地址
|
||||
if (returnFileId) {
|
||||
return fileId;
|
||||
} else {
|
||||
return downloadUrl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储文件
|
||||
*/
|
||||
private String storageFile(String engine, String fileName, byte[] bytes, boolean returnFileId) {
|
||||
// 如果引擎为空,默认使用本地
|
||||
if (ObjectUtil.isEmpty(engine)) {
|
||||
engine = SysFileEngineTypeEnum.LOCAL.getValue();
|
||||
}
|
||||
|
||||
String fileId = R.UU32();
|
||||
String bucketName = null;
|
||||
String storageUrl = null;
|
||||
// 根据引擎类型执行不同方法
|
||||
if (engine.equals(SysFileEngineTypeEnum.LOCAL.getValue())) {
|
||||
// 使用固定名称defaultBucketName
|
||||
bucketName = "defaultBucketName";
|
||||
storageUrl = SysFileLocalUtil.storageFileWithReturnUrl(bucketName, genFileKey(fileId, fileName), bytes);
|
||||
} else if (engine.equals(SysFileEngineTypeEnum.MINIO.getValue())) {
|
||||
// 使用MINIO默认配置的bucketName
|
||||
bucketName = SysFileMinIoUtil.getDefaultBucketName();
|
||||
storageUrl = SysFileMinIoUtil.storageFileWithReturnUrl(bucketName, genFileKey(fileId, fileName), bytes);
|
||||
} else {
|
||||
throw new BaseException("不支持的文件引擎:{}", engine);
|
||||
}
|
||||
|
||||
// 将文件信息保存到数据库
|
||||
Sys_file sys_file = new Sys_file();
|
||||
sys_file.setId(fileId);
|
||||
sys_file.setEngine(engine);
|
||||
sys_file.setBucket(bucketName);
|
||||
sys_file.setName(fileName);
|
||||
String suffix = ObjectUtil.isNotEmpty(fileName) ? StrUtil.subAfter(fileName, StrUtil.DOT, true) : null;
|
||||
sys_file.setSuffix(suffix);
|
||||
// sys_file.setSizeKb(Convert.toStr(NumberUtil.div(new BigDecimal(file.getSize()), BigDecimal.valueOf(1024))
|
||||
// .setScale(0, RoundingMode.HALF_UP)));
|
||||
// sys_file.setSizeInfo(FileUtil.readableFileSize(file.getSize()));
|
||||
sys_file.setObjName(ObjectUtil.isNotEmpty(sys_file.getSuffix()) ? fileId + StrUtil.DOT + sys_file.getSuffix() : null);
|
||||
// 如果是图片,则压缩生成缩略图
|
||||
if (ObjectUtil.isNotEmpty(suffix)) {
|
||||
if (isPic(suffix)) {
|
||||
try {
|
||||
sys_file.setThumbnail(ImgUtil.toBase64DataUri(ImgUtil.scale(ImgUtil.toImage(bytes),
|
||||
100, 100, null), suffix));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 存储路径
|
||||
sys_file.setStoragePath(storageUrl);
|
||||
// 定义下载地址
|
||||
String downloadUrl;
|
||||
downloadUrl = "/platform/sys/file/download?id=" + fileId;
|
||||
sys_file.setDownloadPath(downloadUrl);
|
||||
insert(sys_file);
|
||||
// 如果是返回id则返回文件id // 否则返回下载地址
|
||||
if (returnFileId) {
|
||||
return fileId;
|
||||
} else {
|
||||
return downloadUrl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成文件的key,格式如 2021/10/11/1377109572375810050.docx
|
||||
**/
|
||||
public String genFileKey(String fileId, String originalFileName) {
|
||||
|
||||
// 获取文件原始名称
|
||||
// String originalFileName = file.getSubmittedFileName();
|
||||
|
||||
// 获取文件后缀
|
||||
String fileSuffix = FileUtil.getSuffix(originalFileName);
|
||||
|
||||
// 生成文件的对象名称,格式如:1377109572375810050.docx
|
||||
String fileObjectName = fileId + StrUtil.DOT + fileSuffix;
|
||||
|
||||
// 获取日期文件夹,格式如,2021/10/11/
|
||||
String dateFolderPath = DateUtil.thisYear() + StrUtil.SLASH +
|
||||
(DateUtil.thisMonth() + 1) + StrUtil.SLASH +
|
||||
DateUtil.thisDayOfMonth() + StrUtil.SLASH;
|
||||
|
||||
// 返回
|
||||
return dateFolderPath + fileObjectName;
|
||||
}
|
||||
|
||||
private static boolean isPic(String fileSuffix) {
|
||||
fileSuffix = fileSuffix.toLowerCase();
|
||||
return ImgUtil.IMAGE_TYPE_GIF.equals(fileSuffix)
|
||||
|| ImgUtil.IMAGE_TYPE_JPG.equals(fileSuffix)
|
||||
|| ImgUtil.IMAGE_TYPE_JPEG.equals(fileSuffix)
|
||||
|| ImgUtil.IMAGE_TYPE_BMP.equals(fileSuffix)
|
||||
|| ImgUtil.IMAGE_TYPE_PNG.equals(fileSuffix)
|
||||
|| ImgUtil.IMAGE_TYPE_PSD.equals(fileSuffix);
|
||||
}
|
||||
|
||||
private void sendErrorResponse(HttpServletResponse response, String message) throws IOException {
|
||||
response.setCharacterEncoding(CharsetUtil.UTF_8);
|
||||
response.setContentType(ContentType.JSON.toString());
|
||||
response.getWriter().write(Json.toJson(Result.error(message)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.services.SysHomeActivityService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysHomeActivityServiceImpl extends BaseServiceImpl<Sys_home_activity> implements SysHomeActivityService {
|
||||
|
||||
public SysHomeActivityServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.sys.services.SysLogService;
|
||||
import com.budwk.app.base.page.datatable.DataTableColumn;
|
||||
import com.budwk.app.base.page.datatable.DataTableOrder;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_log;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.pager.Pager;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.Times;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysLogServiceImpl extends BaseServiceImpl<Sys_log> implements SysLogService {
|
||||
public SysLogServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按月分表的dao实例
|
||||
*/
|
||||
protected Map<String, Dao> ymDaos = new HashMap<String, Dao>();
|
||||
|
||||
/**
|
||||
* 获取按月分表的Dao实例,即当前日期的dao实例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Dao logDao() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String key = String.format("%d%02d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1);
|
||||
return logDao(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取特定月份的Dao实例
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Dao logDao(String key) {
|
||||
Dao dao = ymDaos.get(key);
|
||||
if (dao == null) {
|
||||
synchronized (this) {
|
||||
dao = ymDaos.get(key);
|
||||
if (dao == null) {
|
||||
dao = Daos.ext(this.dao(), key);
|
||||
dao.create(Sys_log.class, false);
|
||||
ymDaos.put(key, dao);
|
||||
try {
|
||||
Daos.migration(dao, Sys_log.class, true, false);
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dao;
|
||||
}
|
||||
|
||||
@Async
|
||||
public void fastInsertSysLog(Sys_log syslog) {
|
||||
logDao().insert(syslog);
|
||||
}
|
||||
|
||||
public NutMap logData(String tableName, int length, int start, int draw, List<DataTableOrder> orders, List<DataTableColumn> columns, Cnd cnd, String linkName) {
|
||||
if (logDao(tableName).exists(Sys_log.class)) {
|
||||
SysLogService sysLogService2 = new SysLogServiceImpl(logDao(tableName));
|
||||
return sysLogService2.data(length, start, draw, orders, columns, cnd, null);
|
||||
} else
|
||||
return this.data(length, start, draw, orders, columns, cnd, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询日期
|
||||
*
|
||||
* @param tablaeName 分表名称
|
||||
* @param pageNumber 页码
|
||||
* @param pageSize 页大小
|
||||
* @param cnd 查询条件
|
||||
* @return
|
||||
*/
|
||||
public Pagination data(String tablaeName, int pageNumber, int pageSize, Cnd cnd) {
|
||||
Pager pager = this.logDao(tablaeName).createPager(pageNumber, pageSize);
|
||||
List<Sys_log> list = this.logDao(tablaeName).query(this.getEntityClass(), cnd, pager);
|
||||
pager.setRecordCount(this.logDao(tablaeName).count(this.getEntityClass(), cnd));
|
||||
return new Pagination(pageNumber, pageSize, pager.getRecordCount(), list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多月日志条件查询
|
||||
*
|
||||
* @param date 时间范围
|
||||
* @param type 日志类型
|
||||
* @param pageOrderName 排序字段名称
|
||||
* @param pageOrderBy 排序方式
|
||||
* @param pageNumber 页码
|
||||
* @param pageSize 页大小
|
||||
* @return
|
||||
*/
|
||||
public Pagination data(String[] date, String type, String pageOrderName, String pageOrderBy, int pageNumber, int pageSize) {
|
||||
String tableName = Times.format("yyyyMM", new Date());
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("select sl.* from (");
|
||||
if (date == null || date.length == 0) {
|
||||
stringBuilder.append(" select * from sys_log_" + tableName);
|
||||
if (Strings.isNotBlank(type)) {
|
||||
stringBuilder.append(" where type='" + type + "'");
|
||||
}
|
||||
} else {
|
||||
int m1 = NumberUtils.toInt(Times.format("yyyyMM", Times.D(date[0])));
|
||||
int m2 = NumberUtils.toInt(Times.format("yyyyMM", Times.D(date[1])));
|
||||
if (m1 == m2) {
|
||||
stringBuilder.append(" select * from sys_log_" + m1 + " where 1=1 ");
|
||||
if (Strings.isNotBlank(type)) {
|
||||
stringBuilder.append(" and type='" + type + "'");
|
||||
}
|
||||
stringBuilder.append(" and createdAt>=" + Times.d2TS(Times.D(date[0])));
|
||||
stringBuilder.append(" and createdAt<=" + Times.d2TS(Times.D(date[1])));
|
||||
} else {
|
||||
for (int i = m1; i < m2 + 1; i++) {
|
||||
if (this.dao().exists("sys_log_" + i)) {
|
||||
stringBuilder.append(" select * from sys_log_" + i + " where 1=1 ");
|
||||
if (Strings.isNotBlank(type)) {
|
||||
stringBuilder.append(" and type='" + type + "'");
|
||||
}
|
||||
stringBuilder.append(" and createdAt>=" + Times.d2TS(Times.D(date[0])));
|
||||
stringBuilder.append(" and createdAt<=" + Times.d2TS(Times.D(date[1])));
|
||||
if (i < m2) {
|
||||
stringBuilder.append(" UNION ALL ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stringBuilder.append(")sl ");
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
stringBuilder.append(" order by sl." + pageOrderName + " " + pageOrderBy);
|
||||
}
|
||||
return this.listPage(pageNumber, pageSize, Sqls.create(stringBuilder.toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
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.ioc.aop.Aop;
|
||||
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.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_menu", isHash = true)
|
||||
public class SysMenuServiceImpl extends BaseServiceImpl<Sys_menu> implements SysMenuService {
|
||||
public SysMenuServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
*
|
||||
* @param menu
|
||||
* @param pid
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void save(Sys_menu menu, String pid, List<NutMap> datas) {
|
||||
String path = "";
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
Sys_menu pp = this.fetch(pid);
|
||||
path = pp.getPath();
|
||||
} else pid = "";
|
||||
menu.setPath(getSubPath("sys_menu", "path", path));
|
||||
menu.setParentId(pid);
|
||||
dao().insert(menu);
|
||||
if (!Strings.isEmpty(pid) && "menu".equals(menu.getType())) {
|
||||
this.update(Chain.make("hasChildren", true), Cnd.where("id", "=", pid));
|
||||
}
|
||||
if (datas != null) {
|
||||
for (NutMap map : datas) {
|
||||
Sys_menu m = new Sys_menu();
|
||||
m.setParentId(menu.getId());
|
||||
m.setHasChildren(false);
|
||||
m.setShowit(false);
|
||||
m.setLocation(0);
|
||||
m.setType("data");
|
||||
m.setPermission(map.getString("permission", ""));
|
||||
m.setName(map.getString("name", ""));
|
||||
m.setPath(getSubPath("sys_menu", "path", menu.getPath()));
|
||||
m.setCreatedBy(menu.getCreatedBy());
|
||||
if (Strings.isNotBlank(m.getPermission()))
|
||||
dao().insert(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void savePlus(Sys_menu menu, String pid, List<Sys_menu> permissions) {
|
||||
String path = "";
|
||||
if (StrUtil.isNotBlank(pid)) {
|
||||
Sys_menu pp = this.fetch(pid);
|
||||
path = pp.getPath();
|
||||
}
|
||||
menu.setPath(getSubPath("sys_menu", "path", path));
|
||||
menu.setParentId(pid);
|
||||
dao().insert(menu);
|
||||
|
||||
//如果是菜单,则设置父菜单有子菜单
|
||||
if (Strings.isNotBlank(pid) && "menu".equals(menu.getType())) {
|
||||
this.update(Chain.make("hasChildren", true), Cnd.where("id", "=", pid));
|
||||
}
|
||||
|
||||
//插入权限
|
||||
if (permissions != null && permissions.size() > 0) {
|
||||
for (Sys_menu m : permissions) {
|
||||
m.setParentId(menu.getId());
|
||||
m.setHasChildren(false);
|
||||
m.setShowit(false);
|
||||
m.setLocation(0);
|
||||
m.setType("data");
|
||||
m.setPermission(m.getPermission());
|
||||
m.setName(m.getName());
|
||||
m.setPlatform(menu.getPlatform());
|
||||
m.setPath(getSubPath("sys_menu", "path", menu.getPath()));
|
||||
m.setCreatedBy(menu.getCreatedBy());
|
||||
if (StrUtil.isNotBlank(m.getPermission())) {
|
||||
dao().insert(m);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
clear(Cnd.where(Sys_menu::getParentId, "=", menu.getId()).and(Sys_menu::getType, "=", "data"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*
|
||||
* @param menu
|
||||
* @param pid
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void edit(Sys_menu menu, String pid, List<NutMap> datas) {
|
||||
this.updateIgnoreNull(menu);
|
||||
if (datas == null || datas.size() == 0) {
|
||||
//如果子权限是空,那就清空咯
|
||||
this.clear(Cnd.where("type", "=", "data").and("parentId", "=", menu.getId()));
|
||||
} else {
|
||||
List<String> notInIds = new ArrayList<>();
|
||||
for (NutMap map : datas) {
|
||||
String id = map.getString("key", "");
|
||||
Sys_menu d = this.fetch(id);
|
||||
if (d != null) {
|
||||
d.setPermission(map.getString("permission", ""));
|
||||
d.setName(map.getString("name", ""));
|
||||
this.updateIgnoreNull(d);
|
||||
notInIds.add(d.getId());
|
||||
} else {
|
||||
Sys_menu m = new Sys_menu();
|
||||
m.setParentId(menu.getId());
|
||||
m.setHasChildren(false);
|
||||
m.setShowit(false);
|
||||
m.setLocation(0);
|
||||
m.setType("data");
|
||||
m.setPermission(map.getString("permission", ""));
|
||||
m.setName(map.getString("name", ""));
|
||||
m.setPath(getSubPath("sys_menu", "path", menu.getPath()));
|
||||
m.setCreatedBy(menu.getCreatedBy());
|
||||
if (Strings.isNotBlank(m.getPermission()))
|
||||
this.insert(m);
|
||||
notInIds.add(m.getId());
|
||||
}
|
||||
}
|
||||
if (notInIds.size() > 0) {
|
||||
//删除不在提交表单里的权限数据,注意查询条件,别把子菜单给删了
|
||||
this.clear(Cnd.where("id", "not in", notInIds).and("type", "=", "data").and("parentId", "=", menu.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void editPlus(Sys_menu menu, String pid, List<Sys_menu> buttons) {
|
||||
this.updateIgnoreNull(menu);
|
||||
if (ObjectUtil.isEmpty(buttons)) {
|
||||
//如果子权限是空,那就清空咯
|
||||
this.clear(Cnd.where(Sys_menu::getType, "=", "data").and(Sys_menu::getParentId, "=", menu.getId()));
|
||||
} else {
|
||||
List<String> notInIds = new ArrayList<>();
|
||||
for (Sys_menu button : buttons) {
|
||||
Sys_menu d = fetch(StrUtil.blankToDefault(button.getId(), ""));
|
||||
if (d != null) {
|
||||
d.setPermission(button.getPermission());
|
||||
d.setName(button.getName());
|
||||
d.setPlatform(menu.getPlatform());
|
||||
this.updateIgnoreNull(d);
|
||||
notInIds.add(d.getId());
|
||||
} else {
|
||||
Sys_menu m = new Sys_menu();
|
||||
m.setParentId(menu.getId());
|
||||
m.setHasChildren(false);
|
||||
m.setShowit(false);
|
||||
m.setLocation(0);
|
||||
m.setType("data");
|
||||
m.setPermission(button.getPermission());
|
||||
m.setPlatform(menu.getPlatform());
|
||||
m.setName(button.getName());
|
||||
m.setPath(getSubPath("sys_menu", "path", menu.getPath()));
|
||||
m.setCreatedBy(menu.getCreatedBy());
|
||||
if (Strings.isNotBlank(m.getPermission())) {
|
||||
this.insert(m);
|
||||
}
|
||||
notInIds.add(m.getId());
|
||||
}
|
||||
}
|
||||
if (notInIds.size() > 0) {
|
||||
//删除不在提交表单里的权限数据,注意查询条件,别把子菜单给删了
|
||||
this.clear(Cnd.where("id", "not in", notInIds).and("type", "=", "data").and("parentId", "=", menu.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 级联删除菜单
|
||||
*
|
||||
* @param menu
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteAndChild(Sys_menu menu) {
|
||||
dao().execute(Sqls.create("delete from sys_menu where path like @path").setParam("path", menu.getPath() + "%"));
|
||||
dao().execute(Sqls.create("delete from sys_role_menu where menuId=@id or menuId in(SELECT id FROM sys_menu WHERE path like @path)").setParam("id", menu.getId()).setParam("path", menu.getPath() + "%"));
|
||||
if (!Strings.isEmpty(menu.getParentId())) {
|
||||
int count = count(Cnd.where("parentId", "=", menu.getParentId()));
|
||||
if (count < 1) {
|
||||
dao().execute(Sqls.create("update sys_menu set hasChildren=false where id=@pid").setParam("pid", menu.getParentId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CacheResult
|
||||
public Sys_menu getLeftMenu(String href) {
|
||||
return this.fetch(Cnd.where("href", "=", href));
|
||||
}
|
||||
|
||||
@CacheResult
|
||||
public Sys_menu getLeftPathMenu(List<String> list) {
|
||||
return this.fetch(Cnd.where("href", "in", list).desc("href").desc("path"));
|
||||
}
|
||||
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
sysRoleService.clearCache();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.base.sms.SmsService;
|
||||
import com.budwk.app.base.utils.ManyAddOrRenewUtil;
|
||||
import com.budwk.app.sys.models.Sys_msg;
|
||||
import com.budwk.app.sys.models.Sys_msg_user;
|
||||
import com.budwk.app.sys.services.SysMsgService;
|
||||
import com.budwk.app.sys.services.SysMsgUserService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.sys.views.View_user;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.FieldFilter;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.integration.jedis.JedisAgent;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.integration.jedis.pubsub.PubSubService;
|
||||
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.json.JsonFormat;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.Times;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import redis.clients.jedis.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysMsgServiceImpl extends BaseServiceImpl<Sys_msg> implements SysMsgService {
|
||||
public SysMsgServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysMsgUserService sysMsgUserService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
@Inject
|
||||
private JedisAgent jedisAgent;
|
||||
@Inject
|
||||
private PubSubService pubSubService;
|
||||
@Inject
|
||||
private ManyAddOrRenewUtil manyAddOrRenewUtil;
|
||||
@Inject
|
||||
private SmsService smsService;
|
||||
|
||||
private static NutMap typeMap = NutMap.NEW().addv("system", "系统消息").addv("user", "用户消息");
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Sys_msg saveMsg(Sys_msg sysMsg, String[] users, boolean isExternal) {
|
||||
this.insert(sysMsg);
|
||||
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.groupBy("loginname");
|
||||
FieldFilter fieldFilter = FieldFilter.create(View_user.class, "loginname|username|unitId|unitName|unionId|unionName");
|
||||
if ("user".equals(sysMsg.getType())) {
|
||||
cnd.and(View_user::getLoginname, "in", users);
|
||||
}
|
||||
List<View_user> viewUsers = Daos.ext(dao(), fieldFilter).query(View_user.class, cnd);
|
||||
List<Sys_msg_user> list = new CopyOnWriteArrayList<>();
|
||||
for (View_user viewUser : viewUsers) {
|
||||
Sys_msg_user sys_msg_user = new Sys_msg_user();
|
||||
sys_msg_user.setId(R.UU32());
|
||||
sys_msg_user.setMsgId(sysMsg.getId());
|
||||
sys_msg_user.setStatus(0);
|
||||
sys_msg_user.setLoginname(viewUser.getLoginname());
|
||||
sys_msg_user.setUserName(viewUser.getUsername());
|
||||
sys_msg_user.setUnitId(viewUser.getUnitId());
|
||||
sys_msg_user.setUnitName(viewUser.getUnitName());
|
||||
sys_msg_user.setUnionId(viewUser.getUnionId());
|
||||
sys_msg_user.setUnionName(viewUser.getUnionName());
|
||||
list.add(sys_msg_user);
|
||||
}
|
||||
dao().fastInsert(list);
|
||||
sysMsgUserService.clearCache();
|
||||
|
||||
List<String> loginNames = viewUsers.stream().map(View_user::getLoginname).distinct().toList();
|
||||
//发送站内消息
|
||||
ThreadUtil.execute(() -> {
|
||||
for (String loginName : loginNames) {
|
||||
getMsg(loginName);
|
||||
}
|
||||
});
|
||||
|
||||
//发送学校平台消息
|
||||
// for (String loginName : loginNames) {
|
||||
// smsService.send(loginName, sysMsg.getTitle(), sysMsg.getNote());
|
||||
// }
|
||||
ThreadUtil.execute(() -> {
|
||||
smsService.massSend(loginNames, sysMsg.getTitle(), HtmlUtil.cleanHtmlTag(StrUtil.blankToDefault(sysMsg.getNote(),"")), sysMsg.getUrl());
|
||||
});
|
||||
|
||||
return sysMsg;
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteMsg(String id) {
|
||||
this.delete(id);
|
||||
List<Sys_msg_user> msgUsers = sysMsgUserService.query(Cnd.where(Sys_msg_user::getMsgId, "=", id));
|
||||
sysMsgUserService.clear(Cnd.where("msgId", "=", id));
|
||||
sysMsgUserService.clearCache();
|
||||
for (Sys_msg_user msgUser : msgUsers) {
|
||||
getMsg(msgUser.getLoginname());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void notify(Sys_msg innerMsg, String rooms[]) {
|
||||
// if ("system".equals(innerMsg.getType())) {
|
||||
//
|
||||
// }else if("user".equals(innerMsg.getType())){
|
||||
// for (String room : rooms) {
|
||||
// getMsg(room);
|
||||
// }
|
||||
// }
|
||||
|
||||
// String url = "/platform/sys/msg/user/all";
|
||||
// if (Strings.isNotBlank(innerMsg.getUrl())) {
|
||||
// url = innerMsg.getUrl();
|
||||
// }
|
||||
// NutMap map = new NutMap();
|
||||
// map.put("action", "notify");
|
||||
// map.put("title", "您有新的消息");
|
||||
// map.put("body", innerMsg.getTitle());
|
||||
// map.put("url", url);
|
||||
// String msg = Json.toJson(map, JsonFormat.compact());
|
||||
// if ("system".equals(innerMsg.getType())) {//系统消息发送给所有在线用户
|
||||
// if (jedisAgent.isClusterMode()) {
|
||||
// JedisCluster jedisCluster = jedisAgent.getJedisClusterWrapper().getJedisCluster();
|
||||
// for (JedisPool pool : jedisCluster.getClusterNodes().values()) {
|
||||
// try (Jedis jedis = pool.getResource()) {
|
||||
// ScanParams match = new ScanParams().match(RedisConstant.REDIS_KEY_WSROOM + "*");
|
||||
// ScanResult<String> scan = null;
|
||||
// do {
|
||||
// scan = jedis.scan(scan == null ? ScanParams.SCAN_POINTER_START : scan.getStringCursor(), match);
|
||||
// for (String room : scan.getResult()) {
|
||||
// pubSubService.fire(room, msg);
|
||||
// getMsg(room.split(":")[2]);
|
||||
// }
|
||||
// } while (!scan.isCompleteIteration());
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// ScanParams match = new ScanParams().match(RedisConstant.REDIS_KEY_WSROOM + "*");
|
||||
// ScanResult<String> scan = null;
|
||||
// do {
|
||||
// scan = redisService.scan(scan == null ? ScanParams.SCAN_POINTER_START : scan.getStringCursor(), match);
|
||||
// for (String room : scan.getResult()) {
|
||||
// pubSubService.fire(room, msg);
|
||||
// getMsg(room.split(":")[2]);
|
||||
// }
|
||||
// } while (!scan.isCompleteIteration());
|
||||
// }
|
||||
// } else if ("user".equals(innerMsg.getType())) {//用户消息发送给指定在线用户
|
||||
// for (String room : rooms) {
|
||||
// getMsg(room);
|
||||
// if (jedisAgent.isClusterMode()) {
|
||||
// JedisCluster jedisCluster = jedisAgent.getJedisClusterWrapper().getJedisCluster();
|
||||
// for (JedisPool pool : jedisCluster.getClusterNodes().values()) {
|
||||
// try (Jedis jedis = pool.getResource()) {
|
||||
// ScanParams match = new ScanParams().match(RedisConstant.REDIS_KEY_WSROOM + room + ":*");
|
||||
// ScanResult<String> scan = null;
|
||||
// do {
|
||||
// scan = jedis.scan(scan == null ? ScanParams.SCAN_POINTER_START : scan.getStringCursor(), match);
|
||||
// for (String key : scan.getResult()) {
|
||||
// pubSubService.fire(key, msg);
|
||||
// }
|
||||
// } while (!scan.isCompleteIteration());
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// ScanParams match = new ScanParams().match(RedisConstant.REDIS_KEY_WSROOM + room + ":*");
|
||||
// ScanResult<String> scan = null;
|
||||
// do {
|
||||
// scan = redisService.scan(scan == null ? ScanParams.SCAN_POINTER_START : scan.getStringCursor(), match);
|
||||
// for (String key : scan.getResult()) {
|
||||
// pubSubService.fire(key, msg);
|
||||
// getMsg(room.split(":")[2]);
|
||||
// }
|
||||
// } while (!scan.isCompleteIteration());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void innerMsg(String room, int size, List<NutMap> list) {
|
||||
NutMap map = new NutMap();
|
||||
map.put("action", "innerMsg");
|
||||
map.put("size", size);//未读消息数
|
||||
map.put("list", list);//最新5条消息列表 type--系统消息/用户消息 title--标题 time--时间戳
|
||||
String msg = Json.toJson(map, JsonFormat.compact());
|
||||
log.debug("msg::::" + msg);
|
||||
if (jedisAgent.isClusterMode()) {
|
||||
JedisCluster jedisCluster = jedisAgent.getJedisClusterWrapper().getJedisCluster();
|
||||
for (JedisPool pool : jedisCluster.getClusterNodes().values()) {
|
||||
try (Jedis jedis = pool.getResource()) {
|
||||
ScanParams match = new ScanParams().match(RedisConstant.REDIS_KEY_WSROOM + room + ":*");
|
||||
ScanResult<String> scan = null;
|
||||
do {
|
||||
scan = jedis.scan(scan == null ? ScanParams.SCAN_POINTER_START : scan.getStringCursor(), match);
|
||||
for (String key : scan.getResult()) {
|
||||
pubSubService.fire(key, msg);
|
||||
}
|
||||
} while (!scan.isCompleteIteration());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ScanParams match = new ScanParams().match(RedisConstant.REDIS_KEY_WSROOM + room + ":*");
|
||||
ScanResult<String> scan = null;
|
||||
do {
|
||||
scan = redisService.scan(scan == null ? ScanParams.SCAN_POINTER_START : scan.getStringCursor(), match);
|
||||
for (String key : scan.getResult()) {
|
||||
pubSubService.fire(key, msg);
|
||||
}
|
||||
} while (!scan.isCompleteIteration());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取某用户的未读消息数量及列表
|
||||
*
|
||||
* @param loginname 用户名
|
||||
*/
|
||||
@Override
|
||||
// @Async
|
||||
public void getMsg(String loginname) {
|
||||
try {
|
||||
//通过用户名查询未读消息
|
||||
int size = sysMsgUserService.getUnreadNum(loginname);
|
||||
List<Sys_msg_user> list = sysMsgUserService.getUnreadList(loginname, 1, 5);
|
||||
List<NutMap> mapList = new ArrayList<>();
|
||||
for (Sys_msg_user msgUser : list) {
|
||||
String url = "/platform/sys/msg/user/all/detail/" + msgUser.getMsgId();
|
||||
if (Strings.isNotBlank(msgUser.getMsg().getUrl())) {
|
||||
url = msgUser.getMsg().getUrl();
|
||||
}
|
||||
mapList.add(NutMap.NEW()
|
||||
.addv("msgId", msgUser.getMsgId())
|
||||
.addv("type", typeMap.getString(msgUser.getMsg().getType()))
|
||||
.addv("title", msgUser.getMsg().getTitle())
|
||||
.addv("url", url)
|
||||
.addv("time", Times.format("yyyy-MM-dd HH:mm", Times.D(1000 * msgUser.getMsg().getSendAt()))));
|
||||
}
|
||||
innerMsg(loginname, size, mapList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void offline(String room, String userToken) {
|
||||
NutMap map = new NutMap();
|
||||
map.put("action", "offline");
|
||||
String msg = Json.toJson(map, JsonFormat.compact());
|
||||
try {
|
||||
room = RedisConstant.REDIS_KEY_WSROOM + room + ":" + userToken;
|
||||
log.debugf("offline room(name=%s)", room);
|
||||
pubSubService.fire(room, msg);
|
||||
redisService.expire(room, 60 * 3);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg(String loginname, String title, String body, String sender) {
|
||||
sendMsg(List.of(loginname), title, body, SecurityUtil.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg(List<String> loginNames, String title, String body, String sender) {
|
||||
Sys_msg sysMsg = new Sys_msg();
|
||||
sysMsg.setTitle(title);
|
||||
sysMsg.setNote(body);
|
||||
sysMsg.setSendType("hide");
|
||||
sysMsg.setType("user");
|
||||
sysMsg.setSendAt(Times.getTS());
|
||||
sysMsg.setCreatedBy(sender);
|
||||
this.saveMsg(sysMsg, loginNames.toArray(new String[]{}), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsgInSys(List<String> loginNames, String title, String body, String sender) {
|
||||
Sys_msg sysMsg = new Sys_msg();
|
||||
sysMsg.setTitle(title);
|
||||
sysMsg.setNote(body);
|
||||
sysMsg.setSendType("hide");
|
||||
sysMsg.setType("user");
|
||||
sysMsg.setSendAt(Times.getTS());
|
||||
sysMsg.setCreatedBy(sender);
|
||||
this.saveMsg(sysMsg, loginNames.toArray(new String[]{}), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_msg_user;
|
||||
import com.budwk.app.sys.services.SysMsgUserService;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.pager.Pager;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemove;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_msg_user",isHash = true)
|
||||
public class SysMsgUserServiceImpl extends BaseServiceImpl<Sys_msg_user> implements SysMsgUserService {
|
||||
public SysMsgUserServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读消息数量
|
||||
*
|
||||
* @param loginname
|
||||
* @return
|
||||
*/
|
||||
// @CacheResult(cacheKey = "${args[0]}_getUnreadNum")
|
||||
public int getUnreadNum(String loginname) {
|
||||
int size = this.count(Cnd.where("delFlag", "=", false).and("loginname", "=", loginname)
|
||||
.and("status", "=", 0));
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未读消息列表
|
||||
*
|
||||
* @param loginname
|
||||
* @param pageNumber
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
// @CacheResult(cacheKey = "${args[0]}_getUnreadList", ignoreNull = true)
|
||||
public List<Sys_msg_user> getUnreadList(String loginname, int pageNumber, int pageSize) {
|
||||
return this.query(Cnd.where("delFlag", "=", false).and("loginname", "=", loginname).and("status", "=", 0)
|
||||
.desc("createdAt"), "msg", Cnd.orderBy().desc("sendAt"), new Pager().setPageNumber(pageNumber).setPageSize(pageSize));
|
||||
}
|
||||
|
||||
@CacheRemove(cacheKey = "${args[0]}_*")
|
||||
//可以通过el表达式加 * 通配符来批量删除一批缓存
|
||||
public void deleteCache(String loginname) {
|
||||
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.base.utils.CommonDownloadUtil;
|
||||
import com.budwk.app.base.utils.SysOfficeTemplateUtil;
|
||||
import com.budwk.app.sys.models.Sys_msg;
|
||||
import com.budwk.app.sys.models.Sys_msg_user;
|
||||
import com.budwk.app.sys.param.SysMsgSummaryPageForm;
|
||||
import com.budwk.app.sys.services.SysMsgUserSummaryService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
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 javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysMsgUserSummaryServiceImpl extends BaseServiceImpl<Sys_msg_user> implements SysMsgUserSummaryService {
|
||||
|
||||
@Inject
|
||||
private SysOfficeTemplateUtil sysOfficeTemplateUtil;
|
||||
|
||||
public SysMsgUserSummaryServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportMultipleAsZip(SysMsgSummaryPageForm pageForm, HttpServletResponse response) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
Sys_msg msg = dao().fetch(Sys_msg.class, pageForm.getMsgId());
|
||||
String msgTitle = Optional.ofNullable(msg).map(Sys_msg::getTitle).orElse("");
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
mu.*,
|
||||
m.needBack,
|
||||
m.title
|
||||
FROM
|
||||
sys_msg_user mu
|
||||
LEFT JOIN sys_msg m ON m.id = mu.msgId
|
||||
$condition
|
||||
""");
|
||||
cnd.and("mu.msgId", "=", pageForm.getMsgId());
|
||||
// cnd.and("m.createdBy", "=", SecurityUtil.getUserId());
|
||||
cnd.andEX("mu.unionId", "=", pageForm.getUnionId());
|
||||
cnd.andEX("mu.unitId", "=", pageForm.getUnitId());
|
||||
cnd.andEX("mu.status", "=", pageForm.getReadStatus());
|
||||
if (Strings.isNotBlank(pageForm.getSearchName()) && Strings.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.and(pageForm.getSearchName(), "like", "%" + pageForm.getSearchKeyword() + "%");
|
||||
}
|
||||
cnd.asc("mu.status").asc("mu.unionId");
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> list = listMap(sql);
|
||||
|
||||
try {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ZipOutputStream zos = new ZipOutputStream(bos);
|
||||
for (NutMap row : list) {
|
||||
try {
|
||||
String folderName = row.getString("unionName") + row.getString("userName") + "反馈";
|
||||
//新增一个文件夹
|
||||
zos.putNextEntry(new ZipEntry(folderName + "/"));
|
||||
//把附件加到文件夹中
|
||||
String backFilesStr = row.getString("backFiles");
|
||||
if (StrUtil.isNotBlank(backFilesStr)) {
|
||||
List<JSONObject> backFiles = Json.fromJsonAsList(JSONObject.class,backFilesStr);
|
||||
for (JSONObject file : backFiles) {
|
||||
String url = file.getStr("url");
|
||||
byte[] bytes = sysOfficeTemplateUtil.getFileBytesByUrl(url);
|
||||
zos.putNextEntry(new ZipEntry(folderName + "/" + file.getStr("name")));
|
||||
zos.write(bytes);
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
zos.close();
|
||||
CommonDownloadUtil.download(msgTitle + "反馈压缩包.zip", bos.toByteArray(), response);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportSingleAsZip(String id, HttpServletResponse response) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportSingleAsFolder(String id, ByteArrayOutputStream byteArrayOutputStream) {
|
||||
Sys_msg_user msgUser = dao().fetch(Sys_msg_user.class, id);
|
||||
List<JSONObject> backFiles = msgUser.getBackFiles();
|
||||
|
||||
for (JSONObject file : backFiles) {
|
||||
String url = file.getStr("url");
|
||||
byte[] bytes = sysOfficeTemplateUtil.getFileBytesByUrl(url);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_office_template;
|
||||
import com.budwk.app.sys.services.SysOfficeTemplateService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysOfficeTemplateServiceImpl extends BaseServiceImpl<Sys_office_template> implements SysOfficeTemplateService {
|
||||
|
||||
public SysOfficeTemplateServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.*;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_role", isHash = true)
|
||||
public class SysRoleServiceImpl extends BaseServiceImpl<Sys_role> implements SysRoleService {
|
||||
public SysRoleServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Override
|
||||
public List<String> getPermissionList(Sys_role role) {
|
||||
this.fetchLinks(role, "menus", Cnd.where("disabled", "=", false));
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (Sys_menu menu : role.getMenus()) {
|
||||
if (!Strings.isEmpty(menu.getPermission())) {
|
||||
list.add(menu.getPermission());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@CacheResult
|
||||
public List<Sys_menu> getMenusAndButtons(String roleId) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and" +
|
||||
" b.roleId=@roleId and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("roleId", roleId);
|
||||
sql.params().set("f", false);
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sys_menu> getMenusAndButtons(String roleId, String platform) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and" +
|
||||
" b.roleId=@roleId and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("roleId", roleId);
|
||||
sql.params().set("f", false);
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
@CacheResult
|
||||
public List<Sys_menu> getDatas(String roleId) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and" +
|
||||
" b.roleId=@roleId and a.type='data' and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("roleId", roleId);
|
||||
sql.params().set("f", false);
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
@CacheResult
|
||||
public List<Sys_menu> getDatas() {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and a.type='data' order by a.location ASC,a.path asc");
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询权限
|
||||
*
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
//如果传参是对象,那么要取字符串做为cacheKey值,因为对象的标识是变动的
|
||||
@CacheResult(cacheKey = "${args[0].id}_getPermissionNameList")
|
||||
public List<String> getPermissionNameList(Sys_role role) {
|
||||
dao().fetchLinks(role, "menus");
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (Sys_menu menu : role.getMenus()) {
|
||||
if (!Strings.isEmpty(menu.getPermission()) && !menu.getDisabled()) {
|
||||
list.add(menu.getPermission());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void del(String roleid) {
|
||||
this.dao().clear("sys_user_role", Cnd.where("roleId", "=", roleid));
|
||||
this.dao().clear("sys_role_menu", Cnd.where("roleId", "=", roleid));
|
||||
this.delete(roleid);
|
||||
}
|
||||
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void del(String[] roleids) {
|
||||
this.dao().clear("sys_user_role", Cnd.where("roleId", "in", roleids));
|
||||
this.dao().clear("sys_role_menu", Cnd.where("roleId", "in", roleids));
|
||||
this.delete(roleids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存菜单数据
|
||||
*
|
||||
* @param menuIds
|
||||
* @param roleId
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveMenu(String[] menuIds, String roleId) {
|
||||
this.clear("sys_role_menu", Cnd.where("roleId", "=", roleId));
|
||||
for (String s : menuIds) {
|
||||
this.insert("sys_role_menu", Chain.make("roleId", roleId).add("menuId", s));
|
||||
// Sys_menu menu = sysMenuService.fetch(s);
|
||||
//要把上级菜单插入关联表
|
||||
// for (int i = 4; i < menu.getPath().length(); i = i + 4) {
|
||||
// Sys_menu tMenu = sysMenuService.fetch(Cnd.where("path", "=", menu.getPath().substring(0, i)));
|
||||
// int c = this.count("sys_role_menu", Cnd.where("roleId", "=", roleId).and("menuId", "=", tMenu.getId()));
|
||||
// if (c == 0) {
|
||||
// this.insert("sys_role_menu", Chain.make("roleId", roleId).add("menuId", tMenu.getId()));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
this.clearCache();
|
||||
sysUserService.clearCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveMenu(String[] menuIds, String roleId, String platform) {
|
||||
//只清除对应平台的即可
|
||||
Sql sql = Sqls.queryString("""
|
||||
SELECT
|
||||
rm.menuId
|
||||
FROM
|
||||
`sys_role_menu` rm
|
||||
WHERE
|
||||
rm.roleId = @roleId
|
||||
AND rm.menuId IN (
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
sys_menu
|
||||
WHERE
|
||||
platform = @platform)
|
||||
""");
|
||||
sql.setParam("platform", platform);
|
||||
sql.setParam("roleId", roleId);
|
||||
execute(sql);
|
||||
List<String> deleteMenuIds = sql.getList(String.class);
|
||||
System.out.println(deleteMenuIds);
|
||||
if (ObjectUtil.isNotEmpty(deleteMenuIds)) {
|
||||
this.clear("sys_role_menu", Cnd.where("roleId", "=", roleId).and("menuId", "in", deleteMenuIds));
|
||||
}
|
||||
|
||||
for (String s : menuIds) {
|
||||
this.insert("sys_role_menu", Chain.make("roleId", roleId).add("menuId", s));
|
||||
}
|
||||
this.clearCache();
|
||||
sysUserService.clearCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param roleId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public List<Sys_menu> getRoleMenus(String roleId, String pid) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and " +
|
||||
"$m and b.roleId=@roleId and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("roleId", roleId);
|
||||
sql.params().set("f", false);
|
||||
if (Strings.isNotBlank(pid)) {
|
||||
sql.vars().set("m", "a.parentId='" + pid + "'");
|
||||
} else {
|
||||
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
|
||||
}
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param roleId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
@CacheResult
|
||||
public boolean hasChildren(String roleId, String pid) {
|
||||
Sql sql = Sqls.create("select count(*) from sys_menu a,sys_role_menu b where a.id=b.menuId and " +
|
||||
"$m and b.roleId=@roleId and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("roleId", roleId);
|
||||
sql.params().set("f", false);
|
||||
if (Strings.isNotBlank(pid)) {
|
||||
sql.vars().set("m", "a.parentId='" + pid + "'");
|
||||
} else {
|
||||
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
|
||||
}
|
||||
return sysMenuService.count(sql) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
*
|
||||
* @param roleId
|
||||
* @param keyword
|
||||
* @param isAdmin
|
||||
* @param sysUnit
|
||||
* @return
|
||||
*/
|
||||
public Pagination userSearch(String roleId, String keyword, boolean isAdmin, Sys_unit sysUnit) {
|
||||
Sql sql;
|
||||
if (DB.ORACLE.name().equals(this.dao().getJdbcExpert().getDatabaseType()) || DB.DM.name().equals(this.dao().getJdbcExpert().getDatabaseType())) {
|
||||
//拼接字符串兼容oracle
|
||||
sql = Sqls.create("SELECT a.id AS VALUE,a.loginname||'('||a.username||')' AS label,a.disabled,a.unitid,b.name as unitname FROM sys_user a,sys_unit b WHERE a.unitid=b.id and a.id NOT IN(SELECT b.userId FROM sys_user_role b WHERE b.roleId=@roleId) $s1 $s2 order by a.createdAt desc");
|
||||
} else {
|
||||
sql = Sqls.create("SELECT a.id AS VALUE,CONCAT(a.loginname,'(',a.username,')') AS label,a.disabled,a.unitid,b.name as unitname FROM sys_user a,sys_unit b WHERE a.unitid=b.id and a.id NOT IN(SELECT b.userId FROM sys_user_role b WHERE b.roleId=@roleId) $s1 $s2 order by a.createdAt desc");
|
||||
}
|
||||
sql.params().set("roleId", roleId);
|
||||
if (!isAdmin) {
|
||||
//非超级管理员只可查询本单位及下级单位用户
|
||||
String menuPath = sysUnit.getPath();
|
||||
sql.vars().set("s1", " and b.path like '" + menuPath + "%'");
|
||||
}
|
||||
if (Strings.isNotBlank(keyword)) {
|
||||
sql.vars().set("s2", " and (a.loginname like '%" + keyword + "%' or a.username like '%" + keyword + "%')");
|
||||
}
|
||||
return this.listPage(1, 10, sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_role getByCode(String code) {
|
||||
Assert.notBlank(code);
|
||||
Sys_role role = fetch(Cnd.where("code", "=", code));
|
||||
if (ObjectUtil.isEmpty(role)) {
|
||||
throw new BaseException("没有找到code为{}的角色,请检查!!!", code);
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_role getByCode(RoleConstant roleConstant) {
|
||||
return getByCode(roleConstant.name());
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_route;
|
||||
import com.budwk.app.sys.services.SysRouteService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/23.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysRouteServiceImpl extends BaseServiceImpl<Sys_route> implements SysRouteService {
|
||||
public SysRouteServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_task;
|
||||
import com.budwk.app.sys.services.SysTaskService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysTaskServiceImpl extends BaseServiceImpl<Sys_task> implements SysTaskService {
|
||||
public SysTaskServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.param.PageForm;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_union_group;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUnionGroupService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
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.util.NutMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysUnionGroupServiceImpl extends BaseServiceImpl<Sys_union_group> implements SysUnionGroupService {
|
||||
|
||||
public SysUnionGroupServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void insert(Sys_union_group group) {
|
||||
int count = dao().count(Sys_union_group.class, Cnd.where(Sys_union_group::getCode, "=", group.getCode()));
|
||||
if (count > 0) {
|
||||
throw new BaseException("小组编码已存在");
|
||||
}
|
||||
dao().insert(group);
|
||||
grantRole(group.getId(), group.getLeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void update(Sys_union_group group) {
|
||||
int count = dao().count(Sys_union_group.class, Cnd.where(Sys_union_group::getCode, "=", group.getCode())
|
||||
.and(Sys_union_group::getId, "!=", group.getId()));
|
||||
if (count > 0) {
|
||||
throw new BaseException("小组编码已存在");
|
||||
}
|
||||
dao().updateIgnoreNull(group);
|
||||
grantRole(group.getId(), group.getLeader());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteById(String id) {
|
||||
dao().delete(Sys_union_group.class, id);
|
||||
// 删除小组组长
|
||||
Sys_role unionGroupRole = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_GROUP_LEADER.name());
|
||||
deleteUserRole(id, unionGroupRole.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NutMap> listNotLeader(String unionId, String keyword) {
|
||||
Sql sql = Sqls.create("select id,loginname,username,unitName from vw_user $condition limit 0,10");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("unionId", "=", unionId);
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("username", keyword);
|
||||
seg.orLike("loginname", keyword);
|
||||
cnd.and(seg);
|
||||
sql.setCondition(cnd);
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pagination pageData(PageForm pageForm, String unionId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
t1.*,
|
||||
t2.username AS leaderUserName,
|
||||
t2.mobile AS leaderMobile
|
||||
FROM
|
||||
sys_union_group t1
|
||||
LEFT JOIN sys_user t2 ON t2.id = t1.leader
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
cnd.and("t1.unionId", "=", unionId);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
cnd.where().andLike("t1.name", pageForm.getSearchKeyword());
|
||||
}
|
||||
cnd.asc("t1.code");
|
||||
sql.setCondition(cnd);
|
||||
Pagination pagination = listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
return pagination;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除小组组长权限
|
||||
*
|
||||
* @param groupId 小组id
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
private void deleteUserRole(String groupId, String roleId) {
|
||||
dao().clear(Sys_user_role.class, Cnd.where(Sys_user_role::getUnionGroupId, "=", groupId)
|
||||
.and(Sys_user_role::getRoleId, "=", roleId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配小组组长权限
|
||||
*
|
||||
* @param groupId 小组id
|
||||
* @param groupLeader 组长id
|
||||
*/
|
||||
private void grantRole(String groupId, String groupLeader) {
|
||||
// 小组长权限
|
||||
Sys_role unionGroupRole = sysRoleService.getByCode(RoleConstant.BRANCH_UNION_GROUP_LEADER.name());
|
||||
deleteUserRole(groupId, unionGroupRole.getId());
|
||||
|
||||
Sys_user_role userRole = new Sys_user_role();
|
||||
userRole.setRoleId(unionGroupRole.getId());
|
||||
userRole.setUnionGroupId(groupId);
|
||||
userRole.setUserId(groupLeader);
|
||||
dao().insert(userRole);
|
||||
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_union;
|
||||
import com.budwk.app.sys.services.SysUnionService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysUnionServiceImpl extends BaseServiceImpl<Sys_union> implements SysUnionService {
|
||||
public SysUnionServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
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.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_unit",isHash = true)
|
||||
public class SysUnitServiceImpl extends BaseServiceImpl<Sys_unit> implements SysUnitService {
|
||||
public SysUnitServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单位
|
||||
*
|
||||
* @param unit
|
||||
* @param pid
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void save(Sys_unit unit, String pid) {
|
||||
String path = "";
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
Sys_unit pp = this.fetch(pid);
|
||||
path = pp.getPath();
|
||||
}
|
||||
if(StrUtil.isNotBlank(path)) {
|
||||
unit.setPath(getSubPath("sys_unit", "path", path));
|
||||
}
|
||||
unit.setId(unit.getUnitcode());
|
||||
unit.setParentId(pid);
|
||||
dao().fastInsert(unit);
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
this.update(Chain.make("hasChildren", true), Cnd.where("id", "=", pid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 级联删除单位
|
||||
*
|
||||
* @param unit
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteAndChild(Sys_unit unit) {
|
||||
dao().delete(unit);
|
||||
dao().execute(Sqls.create("delete from sys_unit where path like @path").setParam("path", unit.getPath() + "%"));
|
||||
dao().execute(Sqls.create("delete from sys_user_unit where unitId=@id or unitId in(SELECT id FROM sys_unit WHERE path like @path)").setParam("id", unit.getId()).setParam("path", unit.getPath() + "%"));
|
||||
dao().execute(Sqls.create("delete from sys_role where unitid=@id or unitid in(SELECT id FROM sys_unit WHERE path like @path)").setParam("id", unit.getId()).setParam("path", unit.getPath() + "%"));
|
||||
if (!Strings.isEmpty(unit.getParentId())) {
|
||||
int count = count(Cnd.where("parentId", "=", unit.getParentId()));
|
||||
if (count < 1) {
|
||||
dao().execute(Sqls.create("update sys_unit set hasChildren=0 where id=@pid").setParam("pid", unit.getParentId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.codec.Base64Decoder;
|
||||
import cn.hutool.core.codec.Base64Encoder;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.enums.LoginType;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.exception.UnknownAccountException;
|
||||
import com.budwk.app.base.interceptor.sLog.SLogService;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.models.*;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
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.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.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemove;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@IocBean(args = {"refer:dao"})
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "sys_user", isHash = false, cacheLiveTime = 3600)
|
||||
public class SysUserServiceImpl extends BaseServiceImpl<Sys_user> implements SysUserService {
|
||||
public SysUserServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SLogService sLogService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
@Override
|
||||
@CacheResult(cacheKey = "${userId}_getPermissionList")
|
||||
public List<String> getPermissionList(String userId) {
|
||||
Sys_user user = this.fetch(userId);
|
||||
if (user == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
this.fetchLinks(user, "roles");
|
||||
if (user.getRoles() == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> permissionList = new ArrayList<String>();
|
||||
for (Sys_role role : user.getRoles()) {
|
||||
if (!role.isDisabled()) {
|
||||
permissionList.addAll(sysRoleService.getPermissionList(role));
|
||||
}
|
||||
}
|
||||
// 追加public公共角色权限
|
||||
permissionList.addAll(sysRoleService.getPermissionList(sysRoleService.fetch(Cnd.where("code", "=", "public"))));
|
||||
return permissionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户角色code列表
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@CacheResult(cacheKey = "${user.id}_getRoleCodeList")
|
||||
public List<String> getRoleCodeList(Sys_user user) {
|
||||
dao().fetchLinks(user, "roles");
|
||||
List<String> roleNameList = new ArrayList<String>();
|
||||
for (Sys_role role : user.getRoles()) {
|
||||
if (!role.isDisabled()) roleNameList.add(role.getCode());
|
||||
}
|
||||
return roleNameList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户菜单
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
//如果传参是对象,那么要取字符串做为cacheKey值,因为对象的标识是变动的
|
||||
// @CacheResult(cacheKey = "${user.id}_fillMenu")
|
||||
public Sys_user fillMenu(Sys_user user) {
|
||||
List<Sys_menu> allMenus = getMenus(user.getId());
|
||||
user.setMenus(allMenus);
|
||||
|
||||
//pc端菜单
|
||||
List<Sys_menu> pcMenus = allMenus.stream().filter(menu -> menu.getPlatform().equals("PC")).toList();
|
||||
//h5端菜单
|
||||
List<Sys_menu> h5Menus = allMenus.stream().filter(menu -> menu.getPlatform().equals("H5")).toList();
|
||||
|
||||
//所有的模块
|
||||
Set<String> allModuleIds = allMenus.stream().map(Sys_menu::getModuleId).collect(Collectors.toSet());
|
||||
//找出pc端的模块
|
||||
Set<String> pcModuleIds = pcMenus.stream().map(Sys_menu::getModuleId).collect(Collectors.toSet());
|
||||
//找出h5端的模块
|
||||
Set<String> h5ModuleIds = h5Menus.stream().map(Sys_menu::getModuleId).collect(Collectors.toSet());
|
||||
|
||||
//查询用户拥有的模块
|
||||
List<Sys_module> userModules = dao().query(Sys_module.class, Cnd.where("id", "in", allModuleIds.toArray()).asc(Sys_module::getSortNum));
|
||||
|
||||
//设置pc菜单到模块
|
||||
if (Lang.isNotEmpty(pcModuleIds)) {
|
||||
//用户的pc端模块
|
||||
List<Sys_module> pcModules = userModules.stream().filter(module -> pcModuleIds.contains(module.getId())).toList();
|
||||
//pc菜单转为树结构
|
||||
List<Sys_menu> pcTreeMenus = Sys_menu.createTreeMenus(pcMenus, null);
|
||||
for (Sys_module pcModule : pcModules) {
|
||||
pcModule.setMenus(pcTreeMenus.stream().filter(menu -> menu.getModuleId().equals(pcModule.getId())).collect(Collectors.toList()));
|
||||
}
|
||||
user.setPcModuleMenus(pcModules);
|
||||
}
|
||||
|
||||
//设置h5菜单到模块
|
||||
if (Lang.isNotEmpty(h5ModuleIds)) {
|
||||
//用户的h5端模块
|
||||
List<Sys_module> h5Modules = userModules.stream().filter(module -> h5ModuleIds.contains(module.getId())).toList();
|
||||
List<Sys_menu> h5TreeMenus = Sys_menu.createTreeMenus(h5Menus, null);
|
||||
for (Sys_module h5Module : h5Modules) {
|
||||
h5Module.setMenus(h5TreeMenus.stream().filter(menu -> menu.getModuleId().equals(h5Module.getId())).collect(Collectors.toList()));
|
||||
}
|
||||
user.setH5ModuleMenus(h5Modules);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户菜单权限
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
// @CacheResult(cacheKey = "${userId}_getMenus")
|
||||
public List<Sys_menu> getMenus(String userId) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and " + " b.roleId in(select c.roleId from sys_user_role c,sys_role d where c.roleId=d.id and c.userId=@userId and d.disabled=@f) and a.disabled=@f and a.showit=@t and a.type='menu' order by a.location ASC,a.path asc");
|
||||
sql.params().set("userId", userId);
|
||||
sql.params().set("f", false);
|
||||
sql.params().set("t", true);
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户菜单和按钮权限
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
// @CacheResult(cacheKey = "${userId}_getMenusAndButtons")
|
||||
public List<Sys_menu> getMenusAndButtons(String userId) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and " + " b.roleId in(select c.roleId from sys_user_role c,sys_role d where c.roleId=d.id and c.userId=@userId and d.disabled=@f) and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("userId", userId);
|
||||
sql.params().set("f", false);
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Sys_menu> getMenusAndButtons(String userId, String platform) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户按钮权限
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@CacheResult(cacheKey = "${userId}_getDatas")
|
||||
public List<Sys_menu> getDatas(String userId) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and " + " b.roleId in(select c.roleId from sys_user_role c,sys_role d where c.roleId=d.id and c.userId=@userId and d.disabled=@f) and a.disabled=@f and a.type='data' order by a.location ASC,a.path asc");
|
||||
sql.params().set("userId", userId);
|
||||
sql.params().set("f", false);
|
||||
return sysMenuService.listEntity(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个用户
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteById(String userId) {
|
||||
dao().clear("sys_user_unit", Cnd.where("userId", "=", userId));
|
||||
dao().clear("sys_user_role", Cnd.where("userId", "=", userId));
|
||||
dao().clear("sys_user", Cnd.where("id", "=", userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
*
|
||||
* @param userIds
|
||||
*/
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void deleteByIds(String[] userIds) {
|
||||
dao().clear("sys_user_unit", Cnd.where("userId", "in", userIds));
|
||||
dao().clear("sys_user_role", Cnd.where("userId", "in", userIds));
|
||||
dao().clear("sys_user", Cnd.where("id", "in", userIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
@CacheResult(cacheKey = "${userId}_${pid}_getRoleMenus")
|
||||
public List<Sys_menu> getRoleMenus(String userId, String pid) {
|
||||
Sql sql = Sqls.create("select distinct a.* from sys_menu a,sys_role_menu b where a.id=b.menuId and " + "$m and b.roleId in(select c.roleId from sys_user_role c,sys_role d where c.roleId=d.id and c.userId=@userId and d.disabled=@f) and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("userId", userId);
|
||||
sql.params().set("f", false);
|
||||
if (Strings.isNotBlank(pid)) {
|
||||
sql.vars().set("m", "a.parentId='" + pid + "'");
|
||||
} else {
|
||||
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
|
||||
}
|
||||
return sysMenuService.listEntity(sql);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @param pid
|
||||
* @return
|
||||
*/
|
||||
@CacheResult(cacheKey = "${userId}_${pid}_hasChildren")
|
||||
public boolean hasChildren(String userId, String pid) {
|
||||
Sql sql = Sqls.create("select count(*) from sys_menu a,sys_role_menu b where a.id=b.menuId and " + "$m and b.roleId in(select c.roleId from sys_user_role c,sys_role d where c.roleId=d.id and c.userId=@userId and d.disabled=@f) and a.disabled=@f order by a.location ASC,a.path asc");
|
||||
sql.params().set("userId", userId);
|
||||
sql.params().set("f", false);
|
||||
if (Strings.isNotBlank(pid)) {
|
||||
sql.vars().set("m", "a.parentId='" + pid + "'");
|
||||
} else {
|
||||
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
|
||||
}
|
||||
return sysMenuService.count(sql) > 0;
|
||||
}
|
||||
|
||||
@CacheRemove(cacheKey = "${userId}_*")
|
||||
//可以通过el表达式加 * 通配符来批量删除一批缓存
|
||||
public void deleteCache(String userId) {
|
||||
|
||||
}
|
||||
|
||||
@CacheRemoveAll
|
||||
public void clearCache() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoginname(String loginname) throws BaseException {
|
||||
if (this.count(Cnd.where("loginname", "=", loginname)) < 1) {
|
||||
throw new BaseException("用户名不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkThirdPlatformLoginName(String loginname) throws UnknownAccountException {
|
||||
if (this.count(Cnd.where("loginname", "=", loginname)) < 1) {
|
||||
throw new UnknownAccountException(loginname + "用户名不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkMobile(String mobile) throws BaseException {
|
||||
if (this.count(Cnd.where("mobile", "=", mobile)) < 1) {
|
||||
throw new BaseException("手机号不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_user loginByPassword(String loginname, String passowrd) throws BaseException {
|
||||
Sys_user user = this.fetch(Cnd.where("loginname", "=", loginname));
|
||||
if (user == null) {
|
||||
// throw new BaseException("用户不存在");
|
||||
// 防止暴力破解
|
||||
throw new BaseException("用户名或者密码不正确");
|
||||
}
|
||||
if (user.isDisabled()) {
|
||||
throw new BaseException("用户被禁用");
|
||||
}
|
||||
// base64解码密码
|
||||
String decodePwd = Base64Decoder.decodeStr(passowrd);
|
||||
String hashedPassword = PwdUtil.getPassword(decodePwd, user.getSalt());
|
||||
if (!Strings.sNull(hashedPassword).equalsIgnoreCase(user.getPassword())) {
|
||||
// throw new BaseException("用户名或者密码不正确");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
if (Lang.isNotEmpty(user.getUnit()) && StrUtil.isNotBlank(user.getUnit().getUnionId())) {
|
||||
Sys_union union = dao().fetch(Sys_union.class, user.getUnit().getUnionId());
|
||||
user.setUnion(union);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_user loginByMobile(String mobile) throws BaseException {
|
||||
Sys_user user = this.fetch(Cnd.where("mobile", "=", mobile));
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_user loginByLoginName(String loginname) {
|
||||
Sys_user user = this.fetch(Cnd.where("loginname", "=", loginname));
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
if (Lang.isNotEmpty(user.getUnit()) && StrUtil.isNotBlank(user.getUnit().getUnionId())) {
|
||||
Sys_union union = dao().fetch(Sys_union.class, user.getUnit().getUnionId());
|
||||
user.setUnion(union);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
// 这里不能用缓存,因为没有 userId 没法用前缀清除,会造成缓存清除不干净
|
||||
@Override
|
||||
public Sys_user getUserByLoginname(String loginname) throws BaseException {
|
||||
Sys_user user = this.fetch(Cnd.where("loginname", "=", loginname));
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheResult(cacheKey = "${userId}_getUserById")
|
||||
public Sys_user getUserById(String userId) throws BaseException {
|
||||
Sys_user user = this.fetch(userId);
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sys_user getUserAndMenuById(String userId) throws BaseException {
|
||||
Sys_user user = this.fetch(userId);
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
user = this.fetchLinks(user, null);
|
||||
if (Lang.isNotEmpty(user.getUnit()) && StrUtil.isNotBlank(user.getUnit().getUnionId())) {
|
||||
Sys_union union = dao().fetch(Sys_union.class, user.getUnit().getUnionId());
|
||||
user.setUnion(union);
|
||||
}
|
||||
user = this.fillMenu(user);
|
||||
user.setPermissions(this.getPermissionList(userId));
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoginInfo(String userId, String ip) {
|
||||
this.update(Chain.make("loginIp", ip).add("loginAt", System.currentTimeMillis()).addSpecial("loginCount", "+1"), Cnd.where("id", "=", userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loginPlus(Sys_user user, LoginType loginType, HttpServletRequest request) {
|
||||
String wxOpenId = request.getParameter("wxOpenId");
|
||||
|
||||
StpUtil.login(user.getId());
|
||||
StpUtil.checkLogin();
|
||||
StpUtil.getSession(true).set("loginname", Strings.sNull(user.getLoginname())).set("username", Strings.sNull(user.getUsername())).set("unitId", Strings.sNull(user.getUnitId())).set("unitPath", Strings.sNull(user.getUnitPath())).set("unionId", ObjectUtil.isEmpty(user.getUnion()) ? "" : user.getUnion().getId());
|
||||
Sys_log sysLog = new Sys_log();
|
||||
sysLog.setType("info");
|
||||
sysLog.setTag("用户登陆");
|
||||
if (StrUtil.isNotBlank(wxOpenId)) {
|
||||
sysLog.setMsg("登录方式:" + loginType.getValue() + "成功登录系统!");
|
||||
} else {
|
||||
sysLog.setMsg("登录方式:" + LoginType.WECHAT.getValue() + loginType.getValue() + ",登录账号:");
|
||||
}
|
||||
sysLog.setIp(Lang.getIP(request));
|
||||
sysLog.setCreatedBy(user.getId());
|
||||
sysLog.setUsername(user.getUsername());
|
||||
sysLog.setLoginname(user.getLoginname());
|
||||
sLogService.async(sysLog);
|
||||
|
||||
// 清除登录锁
|
||||
redisService.del(RedisConstant.USER_LOGIN_LOCK_PREFIX + user.getLoginname());
|
||||
|
||||
// 微信登录
|
||||
if (StrUtil.isNotBlank(wxOpenId)) {
|
||||
dao().update(Sys_user.class, Chain.make("wxOpenId", wxOpenId), Cnd.where("id", "=", user.getId()));
|
||||
}
|
||||
|
||||
String redirect = request.getParameter("redirect");
|
||||
if (StrUtil.isNotBlank(redirect)) {
|
||||
return Globals.AppDomain + redirect;
|
||||
} else {
|
||||
return Globals.AppDomain + "/platform/home";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user