first commit
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.services.SysApiService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/24.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/api")
|
||||
public class SysApiController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysApiService sysApiService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/api/index.html")
|
||||
@SaCheckPermission("sys.manager.api")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.api.add")
|
||||
@SLog(tag = "新建密钥", msg = "应用名称:${name}")
|
||||
public Object addDo(@Param("name") String name, HttpServletRequest req) {
|
||||
try {
|
||||
sysApiService.createAppkey(name, SecurityUtil.getUserId());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.api.delete")
|
||||
@SLog(tag = "删除密钥", msg = "Appid:${appid}")
|
||||
public Object delete(String appid, HttpServletRequest req) {
|
||||
try {
|
||||
sysApiService.deleteAppkey(appid);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.api.edit")
|
||||
@SLog(tag = "启用密钥", msg = "Appid:${appid}")
|
||||
public Object enable(String appid, HttpServletRequest req) {
|
||||
try {
|
||||
sysApiService.updateAppkey(appid, false);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.api.edit")
|
||||
@SLog(tag = "禁用密钥", msg = "Appid:${appid}")
|
||||
public Object disable(String appid, HttpServletRequest req) {
|
||||
try {
|
||||
sysApiService.updateAppkey(appid, true);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.api")
|
||||
public Object data(@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(sysApiService.listPage(pageNumber, pageSize, cnd));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.models.Sys_config;
|
||||
import com.budwk.app.sys.services.SysConfigService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.integration.jedis.pubsub.PubSubService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/28.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/conf")
|
||||
public class SysConfController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysConfigService sysConfigService;
|
||||
@Inject
|
||||
private PubSubService pubSubService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/conf/index.html")
|
||||
@SaCheckPermission("sys.manager.conf")
|
||||
public void index() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.conf.add")
|
||||
@SLog(tag = "添加参数", msg = "${conf.configKey}:${conf.configValue}")
|
||||
public Object addDo(@Param("..") Sys_config conf) {
|
||||
try {
|
||||
conf.setCreatedBy(SecurityUtil.getUserId());
|
||||
if (sysConfigService.insert(conf) != null) {
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_config");
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.conf")
|
||||
public Object edit(String id) {
|
||||
try {
|
||||
return Result.success().addData(sysConfigService.fetch(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.conf.edit")
|
||||
@SLog(tag = "修改参数", msg = "${conf.configKey}:${conf.configValue}")
|
||||
public Object editDo(@Param("..") Sys_config conf) {
|
||||
try {
|
||||
conf.setUpdatedBy(SecurityUtil.getUserId());
|
||||
if (sysConfigService.updateIgnoreNull(conf) > 0) {
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_config");
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.conf.delete")
|
||||
@SLog(tag = "删除参数", msg = "参数:${configKey}")
|
||||
public Object delete(String configKey) {
|
||||
try {
|
||||
if (Strings.sBlank(configKey).startsWith("App")) {
|
||||
return Result.error("系统参数不可删除");
|
||||
}
|
||||
if (sysConfigService.delete(configKey) > 0) {
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_config");
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.conf")
|
||||
public Object data(@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(sysConfigService.listPage(pageNumber, pageSize, cnd));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
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.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/24.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/dict")
|
||||
public class SysDictController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/dict/index.html")
|
||||
@SaCheckPermission("sys.manager.dict")
|
||||
public Object index() {
|
||||
return sysDictService.query(Cnd.where("parentId", "=", "").or("parentId", "is", null).asc("location").asc("path"));
|
||||
}
|
||||
|
||||
|
||||
@At("/child")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object child(@Param("pid") String pid, HttpServletRequest req) {
|
||||
List<Sys_dict> list = new ArrayList<>();
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysDictService.query(cnd);
|
||||
for (Sys_dict sysDict : list) {
|
||||
if (sysDictService.count(Cnd.where("parentId", "=", sysDict.getId())) > 0) {
|
||||
sysDict.setHasChildren(true);
|
||||
}
|
||||
NutMap map = Lang.obj2nutmap(sysDict);
|
||||
map.addv("expanded", false);
|
||||
map.addv("children", new ArrayList<>());
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
}
|
||||
|
||||
@At("/tree")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object tree(@Param("pid") String pid, HttpServletRequest req) {
|
||||
try {
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
if (Strings.isBlank(pid)) {
|
||||
NutMap root = NutMap.NEW().addv("value", "root").addv("label", "不选择菜单").addv("leaf", true);
|
||||
treeList.add(root);
|
||||
}
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
List<Sys_dict> list = sysDictService.query(cnd);
|
||||
for (Sys_dict sysDict : list) {
|
||||
NutMap map = NutMap.NEW().addv("value", sysDict.getId()).addv("label", sysDict.getName());
|
||||
if (sysDict.isHasChildren()) {
|
||||
map.addv("children", new ArrayList<>());
|
||||
map.addv("leaf", false);
|
||||
} else {
|
||||
map.addv("leaf", true);
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict.add")
|
||||
@SLog(tag = "新建字典", msg = "字典名称:${args[0].name}")
|
||||
public Object addDo(@Param("..") Sys_dict dict, @Param(value = "parentId", df = "") String parentId, HttpServletRequest req) {
|
||||
try {
|
||||
if ("root".equals(parentId)) {
|
||||
parentId = "";
|
||||
}
|
||||
dict.setHasChildren(false);
|
||||
dict.setCreatedBy(SecurityUtil.getUserId());
|
||||
sysDictService.save(dict, parentId);
|
||||
sysDictService.clearCache();
|
||||
return Result.success("system.success");
|
||||
} catch (Exception e) {
|
||||
return Result.error("system.error");
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict")
|
||||
public Object edit(String id, HttpServletRequest req) {
|
||||
try {
|
||||
return Result.success().addData(sysDictService.fetch(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict.edit")
|
||||
@SLog(tag = "编辑字典", msg = "字典名称:${args[0].name}")
|
||||
public Object editDo(@Param("..") Sys_dict dict, @Param("parentId") String parentId, HttpServletRequest req) {
|
||||
try {
|
||||
dict.setUpdatedBy(SecurityUtil.getUserId());
|
||||
sysDictService.updateIgnoreNull(dict);
|
||||
sysDictService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict.delete")
|
||||
@SLog(tag = "删除字典", msg = "字典名称:${args[1].getAttribute('name')}")
|
||||
public Object delete(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_dict dict = sysDictService.fetch(id);
|
||||
req.setAttribute("name", dict.getName());
|
||||
sysDictService.deleteAndChild(dict);
|
||||
sysDictService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict.edit")
|
||||
@SLog(tag = "启用菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object enable(String menuId, HttpServletRequest req) {
|
||||
try {
|
||||
req.setAttribute("name", sysDictService.fetch(menuId).getName());
|
||||
sysDictService.update(org.nutz.dao.Chain.make("disabled", false), Cnd.where("id", "=", menuId));
|
||||
sysDictService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict.edit")
|
||||
@SLog(tag = "禁用菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object disable(String menuId, HttpServletRequest req) {
|
||||
try {
|
||||
req.setAttribute("name", sysDictService.fetch(menuId).getName());
|
||||
sysDictService.update(org.nutz.dao.Chain.make("disabled", true), Cnd.where("id", "=", menuId));
|
||||
sysDictService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/menuAll")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict")
|
||||
public Object menuAll(HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_dict> list = sysDictService.query(Cnd.NEW().asc("location").asc("path"));
|
||||
NutMap menuMap = NutMap.NEW();
|
||||
for (Sys_dict unit : list) {
|
||||
List<Sys_dict> list1 = menuMap.getList(unit.getParentId(), Sys_dict.class);
|
||||
if (list1 == null) {
|
||||
list1 = new ArrayList<>();
|
||||
}
|
||||
list1.add(unit);
|
||||
menuMap.put(unit.getParentId(), list1);
|
||||
}
|
||||
return Result.success().addData(getTree(menuMap, ""));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
private List<NutMap> getTree(NutMap menuMap, String pid) {
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
List<Sys_dict> subList = menuMap.getList(pid, Sys_dict.class);
|
||||
for (Sys_dict menu : subList) {
|
||||
NutMap map = Lang.obj2nutmap(menu);
|
||||
map.put("label", menu.getName());
|
||||
if (menu.isHasChildren() || (menuMap.get(menu.getId()) != null)) {
|
||||
map.put("children", getTree(menuMap, menu.getId()));
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return treeList;
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.dict.edit")
|
||||
public Object sortDo(@Param("ids") String ids, HttpServletRequest req) {
|
||||
try {
|
||||
String[] menuIds = StringUtils.split(ids, ",");
|
||||
int i = 0;
|
||||
sysDictService.execute(Sqls.create("update sys_dict set location=0"));
|
||||
for (String s : menuIds) {
|
||||
if (!Strings.isBlank(s)) {
|
||||
sysDictService.update(org.nutz.dao.Chain.make("location", i), Cnd.where("id", "=", s));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sysDictService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result dictOptions(String code) {
|
||||
return Result.success(sysDictService.getSubListByCode(code));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/23.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/home")
|
||||
public class SysHomeController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@At("")
|
||||
@Ok("re")
|
||||
@SaCheckLogin
|
||||
public String home(HttpSession session, HttpServletRequest req) {
|
||||
// if (StpUtil.hasRole("sysadmin")) {
|
||||
// return "beetl:/platform/sys/dashboard.html";
|
||||
// }
|
||||
return "beetl:/platform/sys/home.html";
|
||||
}
|
||||
|
||||
@At("/403")
|
||||
@Ok("re")
|
||||
public Object error403(HttpServletRequest req) {
|
||||
StpUtil.checkLogin();
|
||||
if (Strings.sNull(req.getAttribute("original_request_uri")).startsWith("/platform")) {
|
||||
return "beetl:/platform/sys/403.html";
|
||||
} else {
|
||||
return ">>:/error/404.html";
|
||||
}
|
||||
}
|
||||
|
||||
@At("/404")
|
||||
@Ok("re")
|
||||
public Object error404(HttpServletRequest req) {
|
||||
StpUtil.checkLogin();
|
||||
if (Strings.sNull(req.getAttribute("original_request_uri")).startsWith("/platform")) {
|
||||
return "beetl:/platform/sys/404.html";
|
||||
} else {
|
||||
return ">>:/error/404.html";
|
||||
}
|
||||
}
|
||||
|
||||
@At("/500")
|
||||
@Ok("re")
|
||||
public Object error500(HttpServletRequest req) {
|
||||
StpUtil.checkLogin();
|
||||
if (Strings.sNull(req.getAttribute("original_request_uri")).startsWith("/platform")) {
|
||||
return "beetl:/platform/sys/500.html";
|
||||
} else {
|
||||
return ">>:/error/500.html";
|
||||
}
|
||||
}
|
||||
|
||||
@At(value = {"/", "/index"}, top = true)
|
||||
@Ok(">>:/sysadmin")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.DateUtil;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.services.SysLogService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/29.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/log")
|
||||
public class SysLogController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysLogService sysLogService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/log/index.html")
|
||||
@SaCheckPermission("sys.manager.log")
|
||||
public void index(HttpServletRequest req) {
|
||||
req.setAttribute("today", DateUtil.getDate());
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.log")
|
||||
public Object data(@Param("searchDate") String searchDate, @Param("searchType") String searchType, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
String[] date = StringUtils.split(searchDate, ",");
|
||||
return Result.success().addData(sysLogService.data(date, searchType, pageOrderName, PageUtil.getOrder(pageOrderBy), pageNumber, pageSize));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.models.Sys_log;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.services.SysMsgService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.service.ValidateService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import com.budwk.app.web.commons.slog.SLogService;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
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.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Filters;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/22.
|
||||
*/
|
||||
@IocBean // 声明为Ioc容器中的一个Bean
|
||||
@At("/platform/login") // 整个模块的路径前缀
|
||||
@Ok("json:{locked:'password|createAt',ignoreNull:true}") // 忽略password和createAt属性,忽略空属性的json输出
|
||||
public class SysLoginController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
@Inject
|
||||
private SysUnitService sysUnitService;
|
||||
@Inject
|
||||
private SLogService sLogService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
@Inject
|
||||
private SysMsgService sysMsgService;
|
||||
@Inject
|
||||
private ValidateService validateService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/login.html")
|
||||
@Filters
|
||||
public void login(HttpServletRequest req, HttpSession session) {
|
||||
|
||||
}
|
||||
|
||||
@At("/noPermission")
|
||||
@Ok("beetl:/platform/sys/noPermission.html")
|
||||
@Filters
|
||||
public void noPermission() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@At("/doLogin")
|
||||
@Ok("json")
|
||||
public Object doLogin(@Param("username") String username,
|
||||
@Param("password") String password,
|
||||
@Param("platformKey") String captchaKey,
|
||||
@Param("platformCaptcha") String captchaCode,
|
||||
HttpServletRequest req, HttpSession session) {
|
||||
try {
|
||||
Sys_user user = null;
|
||||
sysUserService.checkLoginname(username);
|
||||
validateService.checkCode(captchaKey, captchaCode);
|
||||
user = sysUserService.loginByPassword(username, password);
|
||||
if (user == null) {
|
||||
throw new BaseException("用户登录失败");
|
||||
}
|
||||
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()));
|
||||
sysUserService.setLoginInfo(user.getId(), Lang.getIP(req));
|
||||
Sys_log sysLog = new Sys_log();
|
||||
sysLog.setType("info");
|
||||
sysLog.setTag("用户登陆");
|
||||
sysLog.setSrc(this.getClass().getName() + "#doLogin");
|
||||
sysLog.setMsg("成功登录系统!");
|
||||
sysLog.setIp(Lang.getIP(req));
|
||||
sysLog.setCreatedBy(user.getId());
|
||||
sysLog.setUsername(user.getUsername());
|
||||
sysLog.setLoginname(user.getLoginname());
|
||||
sLogService.async(sysLog);
|
||||
return Result.success("login.success");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At("/doSmsLogin")
|
||||
@Ok("json")
|
||||
public Object doSmsLogin(@Param("mobile") String mobile, @Param("code") String code, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_user user = null;
|
||||
sysUserService.checkMobile(mobile);
|
||||
validateService.checkSMSCode(mobile, code);
|
||||
user = sysUserService.loginByMobile(mobile);
|
||||
if (user == null) {
|
||||
throw new BaseException("用户登录失败");
|
||||
}
|
||||
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()));
|
||||
sysUserService.setLoginInfo(user.getId(), Lang.getIP(req));
|
||||
Sys_log sysLog = new Sys_log();
|
||||
sysLog.setType("info");
|
||||
sysLog.setTag("用户登陆");
|
||||
sysLog.setSrc(this.getClass().getName() + "#doLogin");
|
||||
sysLog.setMsg("成功登录系统!");
|
||||
sysLog.setIp(Lang.getIP(req));
|
||||
sysLog.setCreatedBy(user.getId());
|
||||
sysLog.setUsername(user.getUsername());
|
||||
sysLog.setLoginname(user.getLoginname());
|
||||
sLogService.async(sysLog);
|
||||
return Result.success("login.success");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退出系统
|
||||
*/
|
||||
@At
|
||||
@Ok(">>:/platform/login")
|
||||
public void logout(HttpSession session, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
StpUtil.logout();
|
||||
if (user != null) {
|
||||
Sys_log sysLog = new Sys_log();
|
||||
sysLog.setType("info");
|
||||
sysLog.setTag("用户登出");
|
||||
sysLog.setSrc(this.getClass().getName() + "#logout");
|
||||
sysLog.setMsg("成功退出系统!");
|
||||
sysLog.setIp(Lang.getIP(req));
|
||||
sysLog.setCreatedBy(user.getId());
|
||||
sysLog.setUsername(user.getUsername());
|
||||
sysLog.setLoginname(user.getLoginname());
|
||||
sLogService.async(sysLog);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.debug("Logout error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@At("/captcha")
|
||||
@Ok("json")
|
||||
public Object next() {
|
||||
return Result.success(validateService.getCaptcha());
|
||||
}
|
||||
|
||||
@At("/sendSmsCode")
|
||||
@Ok("json")
|
||||
public Object sendSmsCode(@Param("mobile") String mobile) {
|
||||
try {
|
||||
validateService.getSmsCode(mobile);
|
||||
return Result.success(NutMap.NEW().addv("key", RedisConstant.UCENTER_SMSCODE + mobile)).addMsg("发送成功");
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At("/doReg")
|
||||
@Ok("json")
|
||||
public Object doReg(@Param("mobile") String mobile, @Param("password") String password, @Param("code") String code, HttpServletRequest req) {
|
||||
try {
|
||||
int count = sysUserService.count(Cnd.where("loginname", "=", Strings.trim(mobile)));
|
||||
if (count > 0) {
|
||||
return Result.error("手机号已存在");
|
||||
}
|
||||
validateService.checkSMSCode(mobile, code);
|
||||
Sys_user user = new Sys_user();
|
||||
user.setLoginname(mobile);
|
||||
user.setUsername(mobile);
|
||||
user.setMobile(mobile);
|
||||
String salt = R.UU32();
|
||||
user.setSalt(salt);
|
||||
user.setPassword(PwdUtil.getPassword(password, salt));
|
||||
user.setLoginCount(0);
|
||||
user.setCreatedBy(SecurityUtil.getUserId());
|
||||
Sys_unit unit = sysUnitService.fetch(Cnd.where("unitcode", "=", Globals.MyConfig.getString("AppDefaultUserUnit")));
|
||||
if (unit != null) {
|
||||
user.setUnitId(unit.getId());
|
||||
user.setUnitPath(unit.getPath());
|
||||
}
|
||||
Sys_role role = sysRoleService.fetch(Cnd.where("code", "=", Globals.MyConfig.getString("AppDefaultUserRole")));
|
||||
sysUserService.insert(user);
|
||||
if (role != null)
|
||||
sysRoleService.insert("sys_user_role", Chain.make("roleId", role.getId()).add("userId", user.getId()));
|
||||
sysUserService.clearCache();
|
||||
return Result.success();
|
||||
} catch (BaseException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
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.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/28.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/menu")
|
||||
public class SysMenuController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/menu/index.html")
|
||||
@SaCheckPermission("sys.manager.menu")
|
||||
public void index(HttpServletRequest req) {
|
||||
}
|
||||
|
||||
@At("/child")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object child(@Param("pid") String pid, HttpServletRequest req) {
|
||||
List<Sys_menu> list = new ArrayList<>();
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and(Cnd.exps("parentId", "=", "").or("parentId", "is", null));
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysMenuService.query(cnd);
|
||||
for (Sys_menu menu : list) {
|
||||
if (sysMenuService.count(Cnd.where("parentId", "=", menu.getId())) > 0) {
|
||||
menu.setHasChildren(true);
|
||||
}
|
||||
NutMap map = Lang.obj2nutmap(menu);
|
||||
map.addv("expanded", false);
|
||||
map.addv("children", new ArrayList<>());
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
}
|
||||
|
||||
@At("/tree")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object tree(@Param("pid") String pid, HttpServletRequest req) {
|
||||
try {
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
if (Strings.isBlank(pid)) {
|
||||
NutMap root = NutMap.NEW().addv("value", "root").addv("label", "不选择菜单").addv("leaf", true);
|
||||
treeList.add(root);
|
||||
}
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and(Cnd.exps("parentId", "=", "").or("parentId", "is", null));
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.and("type", "=", "menu");
|
||||
cnd.asc("location").asc("path");
|
||||
List<Sys_menu> list = sysMenuService.query(cnd);
|
||||
for (Sys_menu menu : list) {
|
||||
NutMap map = NutMap.NEW().addv("value", menu.getId()).addv("label", menu.getName());
|
||||
if (menu.isHasChildren()) {
|
||||
map.addv("children", new ArrayList<>());
|
||||
map.addv("leaf", false);
|
||||
} else {
|
||||
map.addv("leaf", true);
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.add")
|
||||
@SLog(tag = "新建菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object addDo(@Param("..") NutMap nutMap, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_menu sysMenu = nutMap.getAs("menu", Sys_menu.class);
|
||||
List<NutMap> buttons = Json.fromJsonAsList(NutMap.class, nutMap.getString("buttons"));
|
||||
int num = sysMenuService.count(Cnd.where("permission", "=", sysMenu.getPermission().trim()));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
for (NutMap map : buttons) {
|
||||
num = sysMenuService.count(Cnd.where("permission", "=", map.getString("permission", "").trim()));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
}
|
||||
String parentId = sysMenu.getParentId();
|
||||
if ("root".equals(sysMenu.getParentId())) {
|
||||
parentId = "";
|
||||
}
|
||||
sysMenu.setHasChildren(false);
|
||||
sysMenu.setShowit(true);
|
||||
sysMenu.setCreatedBy(SecurityUtil.getUserId());
|
||||
sysMenuService.save(sysMenu, Strings.sNull(parentId), buttons);
|
||||
req.setAttribute("name", sysMenu.getName());
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
//编辑菜单,组装一下js表单数据
|
||||
@At("/editMenu/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu")
|
||||
public Object editMenu(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_menu menu = sysMenuService.fetch(id);
|
||||
NutMap map = Lang.obj2nutmap(menu);
|
||||
map.put("parentName", "无");
|
||||
map.put("children", "false");
|
||||
if (Strings.isNotBlank(menu.getParentId())) {
|
||||
map.put("parentName", sysMenuService.fetch(menu.getParentId()).getName());
|
||||
}
|
||||
List<Sys_menu> list = sysMenuService.query(Cnd.where("parentId", "=", id).and("type", "=", "data").asc("location").asc("path"));
|
||||
List<NutMap> buttons = new ArrayList<>();
|
||||
if (list != null && list.size() > 0) {
|
||||
map.put("children", "true");
|
||||
for (Sys_menu m : list) {
|
||||
buttons.add(NutMap.NEW().addv("key", m.getId()).addv("name", m.getName()).addv("permission", m.getPermission()));
|
||||
}
|
||||
}
|
||||
map.put("buttons", buttons);
|
||||
return Result.success().addData(map);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.edit")
|
||||
@SLog(tag = "修改菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object editMenuDo(@Param("..") NutMap nutMap, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_menu sysMenu = nutMap.getAs("menu", Sys_menu.class);
|
||||
List<NutMap> buttons = Json.fromJsonAsList(NutMap.class, nutMap.getString("buttons"));
|
||||
//如果权限标识不是自己的,并且被其他记录占用
|
||||
int num = sysMenuService.count(Cnd.where("permission", "=", sysMenu.getPermission().trim()).and("id", "<>", sysMenu.getId()));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
for (NutMap map : buttons) {
|
||||
num = sysMenuService.count(Cnd.where("permission", "=", map.getString("permission", "").trim()).and("id", "<>", map.getString("key", "")));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
}
|
||||
sysMenu.setHasChildren(false);
|
||||
sysMenu.setShowit(true);
|
||||
sysMenu.setUpdatedBy(SecurityUtil.getUserId());
|
||||
sysMenuService.edit(sysMenu, sysMenu.getParentId(), buttons);
|
||||
req.setAttribute("name", sysMenu.getName());
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/editData/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu")
|
||||
public Object editData(String id, HttpServletRequest req) {
|
||||
try {
|
||||
return Result.success().addData(sysMenuService.fetch(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.edit")
|
||||
@SLog(tag = "修改权限", msg = "权限名称:${args[0].name}")
|
||||
public Object editDataDo(@Param("..") Sys_menu menu, HttpServletRequest req) {
|
||||
try {
|
||||
int num = sysMenuService.count(Cnd.where("permission", "=", menu.getPermission().trim()).and("id", "<>", menu.getId()));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
sysMenuService.updateIgnoreNull(menu);
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.delete")
|
||||
@SLog(tag = "删除菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object delete(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_menu menu = sysMenuService.fetch(id);
|
||||
req.setAttribute("name", menu.getName());
|
||||
if (menu.getPath().startsWith("0001")) {
|
||||
return Result.error("system.not.allow");
|
||||
}
|
||||
sysMenuService.deleteAndChild(menu);
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.edit")
|
||||
@SLog(tag = "启用菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object enable(String menuId, HttpServletRequest req) {
|
||||
try {
|
||||
req.setAttribute("name", sysMenuService.fetch(menuId).getName());
|
||||
sysMenuService.update(org.nutz.dao.Chain.make("disabled", false), Cnd.where("id", "=", menuId));
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.edit")
|
||||
@SLog(tag = "禁用菜单", msg = "菜单名称:${args[1].getAttribute('name')}")
|
||||
public Object disable(String menuId, HttpServletRequest req) {
|
||||
try {
|
||||
req.setAttribute("name", sysMenuService.fetch(menuId).getName());
|
||||
sysMenuService.update(org.nutz.dao.Chain.make("disabled", true), Cnd.where("id", "=", menuId));
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/menuAll")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu")
|
||||
public Object menuAll(HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_menu> list = sysMenuService.query(Cnd.where("type", "=", "menu").asc("location").asc("path"));
|
||||
NutMap menuMap = NutMap.NEW();
|
||||
for (Sys_menu unit : list) {
|
||||
List<Sys_menu> list1 = menuMap.getList(unit.getParentId(), Sys_menu.class);
|
||||
if (list1 == null) {
|
||||
list1 = new ArrayList<>();
|
||||
}
|
||||
list1.add(unit);
|
||||
menuMap.put(unit.getParentId(), list1);
|
||||
}
|
||||
return Result.success().addData(getTree(menuMap, ""));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
private List<NutMap> getTree(NutMap menuMap, String pid) {
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
List<Sys_menu> subList = menuMap.getList(pid, Sys_menu.class);
|
||||
for (Sys_menu menu : subList) {
|
||||
NutMap map = Lang.obj2nutmap(menu);
|
||||
map.put("label", menu.getName());
|
||||
if (menu.isHasChildren() || (menuMap.get(menu.getId()) != null)) {
|
||||
map.put("children", getTree(menuMap, menu.getId()));
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return treeList;
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.menu.edit")
|
||||
public Object sortDo(@Param("ids") String ids, HttpServletRequest req) {
|
||||
try {
|
||||
String[] menuIds = StringUtils.split(ids, ",");
|
||||
int i = 0;
|
||||
sysMenuService.execute(Sqls.create("update sys_menu set location=0"));
|
||||
for (String s : menuIds) {
|
||||
if (!Strings.isBlank(s)) {
|
||||
sysMenuService.update(org.nutz.dao.Chain.make("location", i), Cnd.where("id", "=", s));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.models.Sys_msg;
|
||||
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.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
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.Times;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/sys/msg")
|
||||
public class SysMsgController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysMsgService sysMsgService;
|
||||
@Inject
|
||||
private SysMsgUserService sysMsgUserService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@At({"/", "/list/?"})
|
||||
@Ok("beetl:/platform/sys/msg/index.html")
|
||||
@SaCheckPermission("sys.manager.msg")
|
||||
public void index(String type, HttpServletRequest req) {
|
||||
req.setAttribute("type", Strings.isBlank(type) ? "all" : type);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.msg")
|
||||
public Object data(@Param("searchType") String searchType, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(searchType) && !"all".equals(searchType)) {
|
||||
cnd.and("type", "=", searchType);
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
List<Map> mapList = new ArrayList<>();
|
||||
Pagination pagination = sysMsgService.listPage(pageNumber, pageSize, cnd);
|
||||
for (Object msg : pagination.getList()) {
|
||||
NutMap map = Lang.obj2nutmap(msg);
|
||||
map.put("all_num", sysMsgUserService.count(Cnd.where("msgId", "=", map.get("id", ""))));
|
||||
map.put("unread_num", sysMsgUserService.count(Cnd.where("msgId", "=", map.get("id", "")).and("status", "=", 0)));
|
||||
mapList.add(map);
|
||||
}
|
||||
pagination.setList(mapList);
|
||||
return Result.success().addData(pagination);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.msg")
|
||||
public Object user_view_data(@Param("type") String type, @Param("id") String id, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
String sql = "SELECT a.loginname,a.username,a.mobile,a.email,a.disabled,a.unitid,b.name as unitname,c.status,c.readat FROM sys_user a,sys_unit b,sys_msg_user c WHERE a.unitid=b.id \n" +
|
||||
"and a.loginname=c.loginname and c.msgId='" + id + "' ";
|
||||
if (Strings.isNotBlank(type) && "unread".equals(type)) {
|
||||
sql += " and c.status=0 ";
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
sql += " order by a." + pageOrderName + " " + PageUtil.getOrder(pageOrderBy);
|
||||
}
|
||||
return Result.success().addData(sysMsgService.listPage(pageNumber, pageSize, Sqls.create(sql)));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/addDo")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.msg.add")
|
||||
@SLog(tag = "站内消息", msg = "${args[0].title}")
|
||||
public Object addDo(@Param("..") NutMap nutMap, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_msg sysMsg = nutMap.getAs("msg", Sys_msg.class);
|
||||
sysMsg.setNote(nutMap.getString("note", ""));
|
||||
sysMsg.setSendAt(Times.getTS());
|
||||
sysMsg.setCreatedBy(SecurityUtil.getUserId());
|
||||
String[] users = StringUtils.split(nutMap.getString("users", ""), ",");
|
||||
sysMsgService.saveMsg(sysMsg, users);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:{locked:'password|salt',ignoreNull:false}")
|
||||
@SaCheckPermission("sys.manager.user")
|
||||
public Object user_data(@Param("searchUnit") String searchUnit, @Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(searchName) && Strings.isNotBlank(searchKeyword)) {
|
||||
cnd.and(searchName, "like", "%" + searchKeyword + "%");
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(sysUserService.listPageLinks(pageNumber, pageSize, cnd, "unit"));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At({"/delete/?"})
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.msg.delete")
|
||||
@SLog(tag = "站内消息", msg = "站内信标题:${req.getAttribute('title')}")
|
||||
public Object delete(String id, HttpServletRequest req) {
|
||||
try {
|
||||
req.setAttribute("title", sysMsgService.fetch(id).getTitle());
|
||||
sysMsgService.deleteMsg(id);
|
||||
sysMsgUserService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.services.SysMsgService;
|
||||
import com.budwk.app.sys.services.SysMsgUserService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.Times;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/sys/msg/user")
|
||||
public class SysMsgUserController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysMsgUserService sysMsgUserService;
|
||||
@Inject
|
||||
private SysMsgService sysMsgService;
|
||||
|
||||
@At("/all")
|
||||
@Ok("beetl:/platform/sys/msg/user/indexAll.html")
|
||||
@SaCheckPermission("sys.msg.all")
|
||||
public void index(@Param("type") String type, HttpServletRequest req) {
|
||||
req.setAttribute("type", Strings.isBlank(type) ? "all" : type);
|
||||
}
|
||||
|
||||
@At("/read")
|
||||
@Ok("beetl:/platform/sys/msg/user/indexRead.html")
|
||||
@SaCheckPermission("sys.msg.read")
|
||||
public void read(@Param("type") String type, HttpServletRequest req) {
|
||||
req.setAttribute("type", Strings.isBlank(type) ? "all" : type);
|
||||
|
||||
}
|
||||
|
||||
@At("/unread")
|
||||
@Ok("beetl:/platform/sys/msg/user/indexUnread.html")
|
||||
@SaCheckPermission("sys.msg.unread")
|
||||
public void unread(@Param("type") String type, HttpServletRequest req) {
|
||||
req.setAttribute("type", Strings.isBlank(type) ? "all" : type);
|
||||
}
|
||||
|
||||
@At("/data/?")
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
public Object data(String status, @Param("searchType") String type, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(status) && "read".equals(status)) {
|
||||
cnd.and("a.status", "=", 1);
|
||||
}
|
||||
if (Strings.isNotBlank(status) && "unread".equals(status)) {
|
||||
cnd.and("a.status", "=", 0);
|
||||
}
|
||||
cnd.and("a.loginname", "=", SecurityUtil.getUserLoginname());
|
||||
cnd.and("a.delFlag", "=", false);
|
||||
cnd.desc("a.createdAt");
|
||||
if (Strings.isNotBlank(type) && !"all".equals(type)) {
|
||||
cnd.and("b.type", "=", type);
|
||||
}
|
||||
Sql sql = Sqls.create("SELECT b.type,b.title,b.sendat,a.* FROM sys_msg b LEFT JOIN sys_msg_user a ON b.id=a.msgid $condition");
|
||||
sql.setCondition(cnd);
|
||||
Sql sqlCount = Sqls.create("SELECT count(*) FROM sys_msg b LEFT JOIN sys_msg_user a ON b.id=a.msgid $condition");
|
||||
sqlCount.setCondition(cnd);
|
||||
return Result.success().addData(sysMsgService.listPage(pageNumber, pageSize, sql, sqlCount));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At({"/delete/?", "/delete"})
|
||||
@Ok("json")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
@SLog(tag = "站内消息", msg = "${req.getAttribute('id')}")
|
||||
public Object delete(String id, @Param("ids") String[] ids, HttpServletRequest req) {
|
||||
try {
|
||||
if (ids != null && ids.length > 0) {
|
||||
sysMsgUserService.update(Chain.make("delFlag", true)
|
||||
.add("updatedAt", System.currentTimeMillis())
|
||||
.add("updatedBy", SecurityUtil.getUserId()), Cnd.where("id", "in", ids).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
req.setAttribute("id", Arrays.toString(ids));
|
||||
} else {
|
||||
sysMsgUserService.update(Chain.make("delFlag", true)
|
||||
.add("updatedAt", System.currentTimeMillis())
|
||||
.add("updatedBy", SecurityUtil.getUserId()), Cnd.where("id", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
req.setAttribute("id", id);
|
||||
}
|
||||
sysMsgUserService.deleteCache(SecurityUtil.getUserLoginname());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object unread_num() {
|
||||
try {
|
||||
NutMap nutMap = NutMap.NEW();
|
||||
nutMap.put("system", sysMsgUserService.count(Sqls.create("SELECT count(*) from sys_msg a,sys_msg_user b WHERE a.id=b.msgId AND a.type='system' AND a.delFlag=false AND b.status=0 AND b.delFlag=false AND b.loginname=@loginname").setParam("loginname", SecurityUtil.getUserLoginname())));
|
||||
nutMap.put("user", sysMsgUserService.count(Sqls.create("SELECT count(*) from sys_msg a,sys_msg_user b WHERE a.id=b.msgId AND a.type='user' AND a.delFlag=false AND b.status=0 AND b.delFlag=false AND b.loginname=@loginname").setParam("loginname", SecurityUtil.getUserLoginname())));
|
||||
return Result.success().addData(nutMap);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/status/read")
|
||||
@Ok("json")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
@SLog(tag = "站内消息", msg = "${req.getAttribute('id')}")
|
||||
public Object read(@Param("ids") String[] ids, HttpServletRequest req) {
|
||||
try {
|
||||
sysMsgUserService.update(Chain.make("status", 1).add("readAt", Times.getTS())
|
||||
.add("createdAt", System.currentTimeMillis())
|
||||
.add("createdBy", SecurityUtil.getUserId()), Cnd.where("id", "in", ids).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
sysMsgUserService.deleteCache(SecurityUtil.getUserLoginname());
|
||||
req.setAttribute("id", Arrays.toString(ids));
|
||||
return Result.success("system.success");
|
||||
} catch (Exception e) {
|
||||
return Result.error("system.error");
|
||||
}
|
||||
}
|
||||
|
||||
@At("/status/readAll")
|
||||
@Ok("json")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
@SLog(tag = "站内消息", msg = "readAll")
|
||||
public Object readAll(HttpServletRequest req) {
|
||||
try {
|
||||
sysMsgUserService.update(Chain.make("status", 1).add("readAt", Times.getTS())
|
||||
.add("createdAt", System.currentTimeMillis()).add("createdBy", SecurityUtil.getUserId()), Cnd.where("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
sysMsgUserService.deleteCache(SecurityUtil.getUserLoginname());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/all/detail/?")
|
||||
@Ok("beetl:/platform/sys/msg/user/detailAll.html")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
public void allDetail(String id, HttpServletRequest req) {
|
||||
if (!Strings.isBlank(id)) {
|
||||
//判断用户是否是正常获取消息
|
||||
int num = sysMsgUserService.count(Cnd.where("msgid", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
if (num > 0) {
|
||||
req.setAttribute("obj", sysMsgService.fetch(id));
|
||||
sysMsgUserService.update(Chain.make("status", 1), Cnd.where("msgid", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
sysMsgUserService.deleteCache(SecurityUtil.getUserLoginname());
|
||||
} else {
|
||||
req.setAttribute("obj", null);
|
||||
}
|
||||
} else {
|
||||
req.setAttribute("obj", null);
|
||||
}
|
||||
}
|
||||
|
||||
@At("/read/detail/?")
|
||||
@Ok("beetl:/platform/sys/msg/user/detailRead.html")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
public void readDetail(String id, HttpServletRequest req) {
|
||||
if (!Strings.isBlank(id)) {
|
||||
//判断用户是否是正常获取消息
|
||||
int num = sysMsgUserService.count(Cnd.where("msgid", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
if (num > 0) {
|
||||
req.setAttribute("obj", sysMsgService.fetch(id));
|
||||
sysMsgUserService.update(Chain.make("status", 1), Cnd.where("msgid", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
sysMsgUserService.deleteCache(SecurityUtil.getUserLoginname());
|
||||
} else {
|
||||
req.setAttribute("obj", null);
|
||||
}
|
||||
} else {
|
||||
req.setAttribute("obj", null);
|
||||
}
|
||||
}
|
||||
|
||||
@At("/unread/detail/?")
|
||||
@Ok("beetl:/platform/sys/msg/user/detailUnread.html")
|
||||
@SaCheckPermission(value = {"sys.msg.all", "sys.msg.read", "sys.msg.unread"}, mode = SaMode.OR)
|
||||
public void unreadDetail(String id, HttpServletRequest req) {
|
||||
if (!Strings.isBlank(id)) {
|
||||
//判断用户是否是正常获取消息
|
||||
int num = sysMsgUserService.count(Cnd.where("msgid", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
if (num > 0) {
|
||||
req.setAttribute("obj", sysMsgService.fetch(id));
|
||||
sysMsgUserService.update(Chain.make("status", 1), Cnd.where("msgid", "=", id).and("loginname", "=", SecurityUtil.getUserLoginname()));
|
||||
sysMsgUserService.deleteCache(SecurityUtil.getUserLoginname());
|
||||
} else {
|
||||
req.setAttribute("obj", null);
|
||||
}
|
||||
} else {
|
||||
req.setAttribute("obj", null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
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.models.Sys_user;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/28.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/role")
|
||||
public class SysRoleController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysUnitService sysUnitService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/role/index.html")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public void index() {
|
||||
|
||||
}
|
||||
|
||||
@At("/tree")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object tree(@Param("pid") String pid, HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_unit> list = new ArrayList<>();
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
if (Strings.isBlank(pid)) {
|
||||
NutMap root = NutMap.NEW().addv("value", "root").addv("label", "不选择单位");
|
||||
treeList.add(root);
|
||||
|
||||
}
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
if (Strings.isBlank(pid)) {
|
||||
NutMap sys = NutMap.NEW().addv("value", "system").addv("label", "系统角色");
|
||||
treeList.add(sys);
|
||||
}
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
} else {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
if (user != null && Strings.isBlank(pid)) {
|
||||
list = sysUnitService.query(Cnd.where("id", "=", user.getUnitId()).asc("path"));
|
||||
} else {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
}
|
||||
}
|
||||
for (Sys_unit unit : list) {
|
||||
NutMap map = NutMap.NEW().addv("value", unit.getId()).addv("label", unit.getName());
|
||||
if (unit.isHasChildren()) {
|
||||
map.addv("children", new ArrayList<>());
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object data(@Param("searchUnit") String searchUnit, @Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
if ("system".equals(searchUnit)) {
|
||||
cnd.and("unitid", "=", "");
|
||||
} else if (Strings.isNotBlank(searchUnit)) {
|
||||
cnd.and("unitid", "=", searchUnit);
|
||||
}
|
||||
} else {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
if (Strings.isNotBlank(searchUnit)) {
|
||||
Sys_unit unit = sysUnitService.fetch(searchUnit);
|
||||
if (unit == null || !unit.getPath().startsWith(user.getUnit().getPath())) {
|
||||
//防止有人越级访问
|
||||
return Result.error("非法操作");
|
||||
} else
|
||||
cnd.and("unitid", "=", searchUnit);
|
||||
} else {
|
||||
cnd.and("unitid", "=", user.getUnitId());
|
||||
}
|
||||
}
|
||||
if (Strings.isNotBlank(searchName) && Strings.isNotBlank(searchKeyword)) {
|
||||
cnd.and(searchName, "like", "%" + searchKeyword + "%");
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(sysRoleService.listPageLinks(pageNumber, pageSize, cnd, "unit"));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.edit")
|
||||
@SLog(tag = "启用角色", msg = "角色名称:${args[1].getAttribute('name')}")
|
||||
public Object enable(String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_role role = sysRoleService.fetch(roleId);
|
||||
sysRoleService.update(org.nutz.dao.Chain.make("disabled", false), Cnd.where("id", "=", roleId));
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
req.setAttribute("name", role.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.edit")
|
||||
@SLog(tag = "禁用角色", msg = "角色名称:${args[1].getAttribute('name')}")
|
||||
public Object disable(String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_role role = sysRoleService.fetch(roleId);
|
||||
sysRoleService.update(org.nutz.dao.Chain.make("disabled", true), Cnd.where("id", "=", roleId));
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
req.setAttribute("name", role.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
//加载当前用户所拥有的所有权限菜单
|
||||
@At("/menuAll")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object menuAll(HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_menu> list;
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
list = sysMenuService.query(Cnd.orderBy().asc("location").asc("path"));
|
||||
} else {
|
||||
list = sysUserService.getMenusAndButtons(SecurityUtil.getUserId());
|
||||
}
|
||||
NutMap menuMap = NutMap.NEW();
|
||||
for (Sys_menu unit : list) {
|
||||
List<Sys_menu> list1 = menuMap.getList(unit.getParentId(), Sys_menu.class);
|
||||
if (list1 == null) {
|
||||
list1 = new ArrayList<>();
|
||||
}
|
||||
list1.add(unit);
|
||||
menuMap.put(unit.getParentId(), list1);
|
||||
}
|
||||
return Result.success().addData(getTree(menuMap, ""));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
//加载可分配的权限菜单
|
||||
@At("/menuRole/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object menuRole(String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_menu> hasList = sysRoleService.getMenusAndButtons(roleId);
|
||||
List<Sys_menu> list;
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
list = sysMenuService.query(Cnd.orderBy().asc("location").asc("path"));
|
||||
} else {
|
||||
list = sysUserService.getMenusAndButtons(SecurityUtil.getUserId());
|
||||
}
|
||||
NutMap menuMap = NutMap.NEW();
|
||||
for (Sys_menu unit : list) {
|
||||
List<Sys_menu> list1 = menuMap.getList(unit.getParentId(), Sys_menu.class);
|
||||
if (list1 == null) {
|
||||
list1 = new ArrayList<>();
|
||||
}
|
||||
list1.add(unit);
|
||||
menuMap.put(unit.getParentId(), list1);
|
||||
}
|
||||
List<String> cmenu = new ArrayList<>();
|
||||
for (Sys_menu menu : hasList) {
|
||||
cmenu.add(menu.getId());
|
||||
}
|
||||
return Result.success().addData(NutMap.NEW().addv("menu", getTree(menuMap, "")).addv("cmenu", cmenu));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
private List<NutMap> getTree(NutMap menuMap, String pid) {
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
List<Sys_menu> subList = menuMap.getList(pid, Sys_menu.class);
|
||||
for (Sys_menu menu : subList) {
|
||||
NutMap map = Lang.obj2nutmap(menu);
|
||||
map.put("label", menu.getName());
|
||||
if (menu.isHasChildren() || (menuMap.get(menu.getId()) != null)) {
|
||||
map.put("children", getTree(menuMap, menu.getId()));
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return treeList;
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.add")
|
||||
@SLog(tag = "添加角色", msg = "角色名称:${args[1].name}")
|
||||
public Object addDo(@Param("menuIds") String menuIds, @Param("..") Sys_role role, HttpServletRequest req) {
|
||||
try {
|
||||
int num = sysRoleService.count(Cnd.where("code", "=", role.getCode().trim()));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
String[] ids = StringUtils.split(menuIds, ",");
|
||||
if ("root".equals(role.getUnitid()) || "system".equals(role.getUnitid()))
|
||||
role.setUnitid("");
|
||||
role.setCreatedBy(SecurityUtil.getUserId());
|
||||
Sys_role r = sysRoleService.insert(role);
|
||||
if (r != null) {
|
||||
sysRoleService.saveMenu(ids, r.getId());
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
//查看角色拥有的权限
|
||||
@At("/menu/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object menu(String id, @Param("pid") String pid) {
|
||||
try {
|
||||
List<Sys_menu> list = sysRoleService.getRoleMenus(id, pid);
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
for (Sys_menu unit : list) {
|
||||
if (!unit.isHasChildren() && sysRoleService.hasChildren(id, unit.getId())) {
|
||||
unit.setHasChildren(true);
|
||||
}
|
||||
NutMap map = Lang.obj2nutmap(unit);
|
||||
map.addv("expanded", false);
|
||||
map.addv("children", new ArrayList<>());
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.delete")
|
||||
@SLog(tag = "删除角色", msg = "角色名称:${args[1].getAttribute('name')}")
|
||||
public Object delete(String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_role role = sysRoleService.fetch(roleId);
|
||||
if ("sysadmin".equals(role.getCode()) || "public".equals(role.getCode())) {
|
||||
return Result.error("system.not.allow");
|
||||
}
|
||||
sysRoleService.del(roleId);
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
req.setAttribute("name", role.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object edit(String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
return Result.success().addData(sysRoleService.fetch(roleId));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
//修改角色
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.edit")
|
||||
@SLog(tag = "修改角色", msg = "角色名称:${args[0].name}")
|
||||
public Object editDo(@Param("..") Sys_role role, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_role oldRole = sysRoleService.fetch(role.getId());
|
||||
if (oldRole != null && !Strings.sBlank(oldRole.getCode()).equalsIgnoreCase(role.getCode())) {
|
||||
int num = sysRoleService.count(Cnd.where("code", "=", role.getCode().trim()));
|
||||
if (num > 0) {
|
||||
return Result.error("sys.role.code");
|
||||
}
|
||||
}
|
||||
if ("root".equals(role.getUnitid()) || "system".equals(role.getUnitid()))
|
||||
role.setUnitid("");
|
||||
role.setUpdatedBy(SecurityUtil.getUserId());
|
||||
sysRoleService.updateIgnoreNull(role);
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.menu")
|
||||
@SLog(tag = "分配角色菜单", msg = "角色名称:${args[2].getAttribute('name')}")
|
||||
public Object menuDo(@Param("menuIds") String menuIds, @Param("roleId") String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
String[] ids = StringUtils.split(menuIds, ",");
|
||||
sysRoleService.saveMenu(ids, roleId);
|
||||
Sys_role role = sysRoleService.fetch(roleId);
|
||||
req.setAttribute("name", role.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object user(@Param("roleId") String roleId, @Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword,
|
||||
@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Sql sql = Sqls.create("SELECT a.*,c.name as unitname FROM sys_user a,sys_user_role b,sys_unit c WHERE a.unitid=c.id and a.id=b.userId and b.roleId=@roleId $s $o");
|
||||
sql.params().set("roleId", roleId);
|
||||
if (Strings.isNotBlank(searchName) && Strings.isNotBlank(searchKeyword)) {
|
||||
sql.vars().set("s", " and a." + searchName + " like '%" + searchKeyword + "%'");
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
sql.vars().set("o", " order by a." + pageOrderName + " " + PageUtil.getOrder(pageOrderBy));
|
||||
|
||||
}
|
||||
return Result.success().addData(sysUserService.listPage(pageNumber, pageSize, sql));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.role")
|
||||
public Object userSearch(@Param("query") String keyword, @Param("roleId") String roleId) {
|
||||
try {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
return Result.success().addData(sysRoleService.userSearch(roleId, keyword, StpUtil.hasRole("sysadmin"), user.getUnit()));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.user")
|
||||
@SLog(tag = "添加用户到角色", msg = "角色名称:${args[2].getAttribute('name')},用户ID:${args[0]}")
|
||||
public Object usersAdd(@Param("users") String users, @Param("roleId") String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
String[] ids = StringUtils.split(users, ",");
|
||||
for (String s : ids) {
|
||||
sysRoleService.insert("sys_user_role", org.nutz.dao.Chain.make("roleId", roleId).add("userId", s));
|
||||
}
|
||||
Sys_role role = sysRoleService.fetch(roleId);
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
req.setAttribute("name", role.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.role.user")
|
||||
@SLog(tag = "从角色中移除用户", msg = "角色名称:${args[2].getAttribute('name')},用户ID:${args[0]}")
|
||||
public Object usersDel(@Param("users") String users, @Param("roleId") String roleId, HttpServletRequest req) {
|
||||
try {
|
||||
String superadminId = sysUserService.fetch(Cnd.where("loginname", "=", "superadmin")).getId();
|
||||
String sysadminRoleid = sysRoleService.fetch(Cnd.where("code", "=", "sysadmin")).getId();
|
||||
String[] ids = StringUtils.split(users, ",");
|
||||
if (Lang.contains(ids, superadminId) && roleId.equals(sysadminRoleid)) {
|
||||
return Result.error("超级管理员不能从[系统管理员]角色里删除");
|
||||
}
|
||||
sysRoleService.clear("sys_user_role", Cnd.where("userId", "in", ids).and("roleId", "=", roleId));
|
||||
Sys_role role = sysRoleService.fetch(roleId);
|
||||
sysRoleService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
req.setAttribute("name", role.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.models.Sys_route;
|
||||
import com.budwk.app.sys.services.SysRouteService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.integration.jedis.pubsub.PubSubService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/sys/route")
|
||||
public class SysRouteController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysRouteService routeService;
|
||||
@Inject
|
||||
private PubSubService pubSubService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/route/index.html")
|
||||
@SaCheckPermission("sys.manager.route")
|
||||
public void index() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.route")
|
||||
public Object data(@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(routeService.listPage(pageNumber, pageSize, cnd));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SLog(tag = "新建路由", msg = "URL:${args[0].url}")
|
||||
@SaCheckPermission("sys.manager.route.add")
|
||||
public Object addDo(@Param("..") Sys_route route, HttpServletRequest req) {
|
||||
try {
|
||||
route.setCreatedBy(SecurityUtil.getUserId());
|
||||
routeService.insert(route);
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_route");
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.route")
|
||||
public Object edit(String id) {
|
||||
try {
|
||||
return Result.success().addData(routeService.fetch(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SLog(tag = "修改路由", msg = "URL:${args[0].url}")
|
||||
@SaCheckPermission("sys.manager.route.edit")
|
||||
public Object editDo(@Param("..") Sys_route route, HttpServletRequest req) {
|
||||
try {
|
||||
route.setUpdatedBy(SecurityUtil.getUserId());
|
||||
routeService.updateIgnoreNull(route);
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_route");
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SLog(tag = "删除路由", msg = "路由ID:${args[0]}")
|
||||
@SaCheckPermission("sys.manager.route.delete")
|
||||
public Object delete(String id, HttpServletRequest req) {
|
||||
try {
|
||||
routeService.delete(id);
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_route");
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.route.edit")
|
||||
@SLog(tag = "启用路由", msg = "URL:${args[1].getAttribute('url')}")
|
||||
public Object enable(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_route route = routeService.fetch(id);
|
||||
req.setAttribute("url", route.getUrl());
|
||||
routeService.update(Chain.make("disabled", false), Cnd.where("id", "=", id));
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_route");
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.route.edit")
|
||||
@SLog(tag = "禁用路由", msg = "URL:${args[1].getAttribute('name')}")
|
||||
public Object disable(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_route route = routeService.fetch(id);
|
||||
req.setAttribute("url", route.getUrl());
|
||||
routeService.update(Chain.make("disabled", true), Cnd.where("id", "=", id));
|
||||
pubSubService.fire(RedisConstant.PLATFORM_REDIS_PREFIX + "web:platform", "sys_route");
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.sys.models.Sys_task;
|
||||
import com.budwk.app.sys.services.SysTaskService;
|
||||
import com.budwk.app.task.services.TaskPlatformService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
;
|
||||
|
||||
@IocBean
|
||||
@At("/platform/sys/task")
|
||||
public class SysTaskController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysTaskService sysTaskService;
|
||||
@Inject
|
||||
private TaskPlatformService taskPlatformService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/task/index.html")
|
||||
@SaCheckPermission("sys.manager.task")
|
||||
public void index() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("beetl:/platform/sys/task/cron.html")
|
||||
@SaCheckPermission("sys.manager.task")
|
||||
public void cron() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.task")
|
||||
public Object cronExp(@Param("cron") String cron) {
|
||||
try {
|
||||
return Result.success().addData(taskPlatformService.getCronExeTimes(cron));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@SaCheckPermission("sys.manager.task")
|
||||
public Object data(@Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(sysTaskService.listPage(pageNumber, pageSize, cnd));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SLog(tag = "新建任务", msg = "任务名称:${args[0].name}")
|
||||
@SaCheckPermission("sys.manager.task.add")
|
||||
public Object addDo(@Param("..") Sys_task task, HttpServletRequest req) {
|
||||
try {
|
||||
task.setCreatedBy(SecurityUtil.getUserId());
|
||||
Sys_task sysTask = sysTaskService.insert(task);
|
||||
taskPlatformService.add(sysTask.getId(), sysTask.getId(), sysTask.getJobClass(), sysTask.getCron(),
|
||||
sysTask.getNote(), sysTask.getData());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.task")
|
||||
public Object edit(String id) {
|
||||
try {
|
||||
return Result.success().addData(sysTaskService.fetch(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SLog(tag = "修改任务", msg = "任务名称:${args[0].name}")
|
||||
@SaCheckPermission("sys.manager.task.edit")
|
||||
public Object editDo(@Param("..") Sys_task task, HttpServletRequest req) {
|
||||
try {
|
||||
task.setUpdatedBy(SecurityUtil.getUserId());
|
||||
sysTaskService.updateIgnoreNull(task);
|
||||
if (taskPlatformService.isExist(task.getId(), task.getId())) {
|
||||
taskPlatformService.delete(task.getId(), task.getId());
|
||||
}
|
||||
if (!task.isDisabled()) {
|
||||
taskPlatformService.add(task.getId(), task.getId(), task.getJobClass(), task.getCron(),
|
||||
task.getNote(), task.getData());
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SLog(tag = "删除任务", msg = "任务名称:${args[1].getAttribute('name')}")
|
||||
@SaCheckPermission("sys.manager.task.delete")
|
||||
public Object delete(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_task sysTask = sysTaskService.fetch(id);
|
||||
try {
|
||||
if (taskPlatformService.isExist(sysTask.getId(), sysTask.getId())) {
|
||||
taskPlatformService.delete(sysTask.getId(), sysTask.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
sysTaskService.delete(id);
|
||||
req.setAttribute("name", sysTask.getName());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.task.edit")
|
||||
@SLog(tag = "启用任务", msg = "任务名:${args[1].getAttribute('name')}")
|
||||
public Object enable(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_task sysTask = sysTaskService.fetch(id);
|
||||
req.setAttribute("name", sysTask.getName());
|
||||
sysTaskService.update(org.nutz.dao.Chain.make("disabled", false), Cnd.where("id", "=", id));
|
||||
if (!taskPlatformService.isExist(sysTask.getId(), sysTask.getId())) {
|
||||
taskPlatformService.add(sysTask.getId(), sysTask.getId(), sysTask.getJobClass(), sysTask.getCron(),
|
||||
sysTask.getNote(), sysTask.getData());
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.task.edit")
|
||||
@SLog(tag = "禁用任务", msg = "任务名:${args[1].getAttribute('name')}")
|
||||
public Object disable(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_task sysTask = sysTaskService.fetch(id);
|
||||
req.setAttribute("name", sysTask.getName());
|
||||
sysTaskService.update(org.nutz.dao.Chain.make("disabled", true), Cnd.where("id", "=", id));
|
||||
if (taskPlatformService.isExist(sysTask.getId(), sysTask.getId())) {
|
||||
taskPlatformService.delete(sysTask.getId(), sysTask.getId());
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.models.Sys_user_role;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/24.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/unit")
|
||||
public class SysUnitController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysUnitService sysUnitService;
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/unit/index.html")
|
||||
@SaCheckPermission("sys.manager.unit")
|
||||
public void index() {
|
||||
|
||||
}
|
||||
|
||||
@At("/child")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object child(@Param("pid") String pid, HttpServletRequest req) {
|
||||
List<Sys_unit> list = new ArrayList<>();
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
} else {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
if (user != null && Strings.isBlank(pid)) {
|
||||
list = sysUnitService.query(Cnd.where("id", "=", user.getUnitId()).asc("path"));
|
||||
} else {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
}
|
||||
}
|
||||
for (Sys_unit unit : list) {
|
||||
NutMap map = Lang.obj2nutmap(unit);
|
||||
map.addv("expanded", false);
|
||||
map.addv("children", new ArrayList<>());
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
}
|
||||
|
||||
|
||||
@At("/tree")
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object tree(@Param("pid") String pid, HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_unit> list = new ArrayList<>();
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
if (Strings.isBlank(pid)) {
|
||||
NutMap root = NutMap.NEW().addv("value", "root").addv("label", "不选择单位").addv("leaf", true);
|
||||
treeList.add(root);
|
||||
}
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
} else {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
if (user != null && Strings.isBlank(pid)) {
|
||||
list = sysUnitService.query(Cnd.where("id", "=", user.getUnitId()).asc("path"));
|
||||
} else {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (Strings.isBlank(pid)) {
|
||||
cnd.and("parentId", "=", "").or("parentId", "is", null);
|
||||
} else {
|
||||
cnd.and("parentId", "=", pid);
|
||||
}
|
||||
cnd.asc("location").asc("path");
|
||||
list = sysUnitService.query(cnd);
|
||||
}
|
||||
}
|
||||
for (Sys_unit unit : list) {
|
||||
NutMap map = NutMap.NEW().addv("value", unit.getId()).addv("label", unit.getName());
|
||||
if (unit.isHasChildren()) {
|
||||
map.addv("children", new ArrayList<>());
|
||||
map.addv("leaf", false);
|
||||
} else {
|
||||
map.addv("leaf", true);
|
||||
}
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.unit.add")
|
||||
@SLog(tag = "新建单位", msg = "单位名称:${args[0].name}")
|
||||
public Object addDo(@Param("..") Sys_unit unit, @Param("parentId") String parentId, @Param(value = "roleTableData") String roleTableData) {
|
||||
try {
|
||||
if ("root".equals(parentId)) {
|
||||
parentId = "";
|
||||
}
|
||||
unit.setCreatedBy(SecurityUtil.getUserId());
|
||||
sysUnitService.save(unit, parentId);
|
||||
if (ObjectUtil.isNotEmpty(roleTableData)) {
|
||||
Sys_role sysRole = sysUnitService.dao().fetch(Sys_role.class, Cnd.where("code", "=", "unitAdmin"));
|
||||
List<Sys_user_role> userRoleList = Json.fromJsonAsList(Sys_user_role.class, roleTableData);
|
||||
userRoleList.forEach(sys_user_role -> {
|
||||
sys_user_role.setUnitId(unit.getId());
|
||||
sys_user_role.setRoleId(sysRole.getId());
|
||||
});
|
||||
sysUnitService.insert(userRoleList);
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.unit")
|
||||
public Object edit(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_unit unit = sysUnitService.fetch(id);
|
||||
return Result.success().addData(unit);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.unit.edit")
|
||||
@SLog(tag = "编辑单位", msg = "单位名称:${args[0].name}")
|
||||
public Object editDo(@Param("..") Sys_unit unit, @Param("roleTableData") String roleTableData) {
|
||||
try {
|
||||
sysUnitService.dao().clear(Sys_user_role.class, Cnd.where("unitId", "=", unit.getId()));
|
||||
if (ObjectUtil.isNotEmpty(roleTableData)) {
|
||||
Sys_role sysRole = sysUnitService.dao().fetch(Sys_role.class, Cnd.where("code", "=", "unitAdmin"));
|
||||
List<Sys_user_role> userRoleList = Json.fromJsonAsList(Sys_user_role.class, roleTableData);
|
||||
userRoleList.forEach(sys_user_role -> {
|
||||
sys_user_role.setUnitId(unit.getId());
|
||||
sys_user_role.setRoleId(sysRole.getId());
|
||||
});
|
||||
sysUnitService.insert(userRoleList);
|
||||
}
|
||||
unit.setUpdatedBy(SecurityUtil.getUserId());
|
||||
sysUnitService.updateIgnoreNull(unit);
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.unit.delete")
|
||||
@SLog(tag = "删除单位", msg = "单位名称:${args[1].getAttribute('name')}")
|
||||
public Object delete(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_unit unit = sysUnitService.fetch(id);
|
||||
req.setAttribute("name", unit.getName());
|
||||
/* if ("0001".equals(unit.getPath())) {
|
||||
return Result.error("system.not.allow");
|
||||
}*/
|
||||
sysRoleService.dao().clear(Sys_user_role.class, Cnd.where("unitId", "=", unit.getId()));
|
||||
sysUnitService.deleteAndChild(unit);
|
||||
sysMenuService.clearCache();
|
||||
sysUserService.clearCache();
|
||||
sysRoleService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result listUnion(String unionId) {
|
||||
List<Sys_unit> unitList = sysUnitService.dao().query(Sys_unit.class,
|
||||
Cnd.where("LENGTH(path)", "=", 4).andEX("id", "=", unionId).and("isEnable", "=", 1).asc("path"));
|
||||
return Result.success(unitList);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result listUnit(String unionId) {
|
||||
List<Sys_unit> unitList = sysUnitService.dao().query(Sys_unit.class,
|
||||
Cnd.where("isThisSchoolUnit", "is", true).andEX("parentId", "=", unionId).and("isEnable", "=", 1).asc("location"));
|
||||
return Result.success(unitList);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result getRoleOption() {
|
||||
List<Sys_role> roleList = sysUnitService.dao().query(Sys_role.class,
|
||||
Cnd.where("code", "in", List.of("unitAdmin", "twoUnitAdmin")).asc("code"));
|
||||
return Result.success(roleList);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result getUserOption(String unitId) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.id userId,
|
||||
u.username userName,
|
||||
it.`name` unitName,
|
||||
(SELECT COUNT(*)
|
||||
FROM sys_user_role
|
||||
WHERE userId = u.id AND unitId = @unitId) AS disabled
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_unit it ON it.id = u.unitId
|
||||
WHERE u.unitId = @unitId
|
||||
""").setParam("unitId", unitId);
|
||||
List<NutMap> map = sysUnitService.listMap(sql);
|
||||
return Result.success(map);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result getRoleTableData(String unitId) {
|
||||
List<Sys_user_role> userRoleList = sysUnitService.dao().query(Sys_user_role.class, Cnd.where("unitId", "=", unitId));
|
||||
return Result.success(userRoleList);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Result doIsEnable(@Param("id") String id, Boolean isEnable) {
|
||||
if (StrUtil.isEmpty(id)) {
|
||||
return Result.error("参数错误");
|
||||
}
|
||||
sysUnitService.update(Chain.make("isEnable", isEnable), Cnd.where("id", "=", id));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
package com.budwk.app.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.base.utils.PageUtil;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import com.budwk.app.web.commons.auth.utils.SecurityUtil;
|
||||
import com.budwk.app.web.commons.base.Globals;
|
||||
import com.budwk.app.web.commons.slog.annotation.SLog;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.integration.json4excel.J4E;
|
||||
import org.nutz.integration.json4excel.J4EColumn;
|
||||
import org.nutz.integration.json4excel.J4EConf;
|
||||
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.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/23.
|
||||
*/
|
||||
@IocBean
|
||||
@At("/platform/sys/user")
|
||||
public class SysUserController {
|
||||
private static final Log log = Logs.get();
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
@Inject
|
||||
private SysMenuService sysMenuService;
|
||||
@Inject
|
||||
private SysUnitService sysUnitService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/user/index.html")
|
||||
@SaCheckPermission("sys.manager.user")
|
||||
public void index() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.add")
|
||||
@SLog(tag = "新建用户", msg = "用户名:${user.loginname}")
|
||||
public Object addDo(@Param("..") Sys_user user, HttpServletRequest req) {
|
||||
try {
|
||||
if (Strings.isNotBlank(user.getLoginname())) {
|
||||
int num = sysUserService.count(Cnd.where("loginname", "=", Strings.trim(user.getLoginname())));
|
||||
if (num > 0) {
|
||||
return Result.error("用户名已存在!");
|
||||
}
|
||||
}
|
||||
if (Strings.isNotBlank(user.getMobile())) {
|
||||
int num = sysUserService.count(Cnd.where("mobile", "=", Strings.trim(user.getMobile())));
|
||||
if (num > 0) {
|
||||
return Result.error("手机号已存在!");
|
||||
}
|
||||
}
|
||||
if (Strings.isNotBlank(user.getEmail())) {
|
||||
int num = sysUserService.count(Cnd.where("email", "=", Strings.trim(user.getEmail())));
|
||||
if (num > 0) {
|
||||
return Result.error("邮箱已存在!");
|
||||
}
|
||||
}
|
||||
String salt = R.UU32();
|
||||
user.setSalt(salt);
|
||||
user.setPassword(PwdUtil.getPassword(user.getPassword(), salt));
|
||||
user.setLoginCount(0);
|
||||
// user.setUnitPath(sysUnitService.fetch(user.getUnitId()).getPath());
|
||||
sysUserService.insert(user);
|
||||
sysUserService.clearCache();
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/edit/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user")
|
||||
public Object edit(String id) {
|
||||
try {
|
||||
return Result.success().addData(sysUserService.fetchLinks(sysUserService.fetch(id), "unit"));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.edit")
|
||||
@SLog(tag = "修改用户", msg = "用户名:${user.loginname}")
|
||||
public Object editDo(@Param("..") Sys_user user, HttpServletRequest req) {
|
||||
try {
|
||||
sysUserService.updateIgnoreNull(user);
|
||||
sysUserService.deleteCache(user.getId());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/resetPwd/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.edit")
|
||||
@SLog(tag = "重置密码", msg = "用户名:${args[1].getAttribute('loginname')}")
|
||||
public Object resetPwd(String id, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_user user = sysUserService.fetch(id);
|
||||
String salt = R.UU32();
|
||||
String pwd = R.captchaNumber(6);
|
||||
String hashedPasswordBase64 = PwdUtil.getPassword(pwd, salt);
|
||||
sysUserService.update(Chain.make("salt", salt).add("password", hashedPasswordBase64), Cnd.where("id", "=", id));
|
||||
sysUserService.deleteCache(user.getId());
|
||||
req.setAttribute("loginname", user.getLoginname());
|
||||
return Result.success().addData(pwd);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.delete")
|
||||
@SLog(tag = "删除用户", msg = "用户名:${args[1].getAttribute('loginname')}")
|
||||
public Object delete(String userId, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_user user = sysUserService.fetch(userId);
|
||||
if ("superadmin".equals(user.getLoginname())) {
|
||||
return Result.error("system.not.allow");
|
||||
}
|
||||
sysUserService.deleteById(userId);
|
||||
sysUserService.deleteCache(user.getId());
|
||||
req.setAttribute("loginname", user.getLoginname());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/delete")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.delete")
|
||||
@SLog(tag = "批量删除用户", msg = "用户ID:${args[1].getAttribute('ids')}")
|
||||
public Object deletes(@Param("ids") String[] userIds, HttpServletRequest req) {
|
||||
try {
|
||||
Sys_user user = sysUserService.fetch(Cnd.where("loginname", "=", "superadmin"));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : userIds) {
|
||||
if (s.equals(user.getId())) {
|
||||
return Result.error("system.not.allow");
|
||||
}
|
||||
sb.append(s).append(",");
|
||||
}
|
||||
sysUserService.deleteByIds(userIds);
|
||||
sysUserService.clearCache();
|
||||
req.setAttribute("ids", sb.toString());
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/enable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.edit")
|
||||
@SLog(tag = "启用用户", msg = "用户名:${args[1].getAttribute('loginname')}")
|
||||
public Object enable(String userId, HttpServletRequest req) {
|
||||
try {
|
||||
req.setAttribute("loginname", sysUserService.fetch(userId).getLoginname());
|
||||
sysUserService.update(Chain.make("disabled", false), Cnd.where("id", "=", userId));
|
||||
sysUserService.deleteCache(userId);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/disable/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user.edit")
|
||||
@SLog(tag = "禁用用户", msg = "用户名:${req.getAttribute('loginname')}")
|
||||
public Object disable(String userId, HttpServletRequest req) {
|
||||
try {
|
||||
String loginname = sysUserService.fetch(userId).getLoginname();
|
||||
if ("superadmin".equals(loginname)) {
|
||||
return Result.error("system.not.allow");
|
||||
}
|
||||
req.setAttribute("loginname", loginname);
|
||||
sysUserService.update(Chain.make("disabled", true), Cnd.where("id", "=", userId));
|
||||
sysUserService.deleteCache(userId);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At("/menu/?")
|
||||
@Ok("json")
|
||||
@SaCheckPermission("sys.manager.user")
|
||||
public Object menu(String id, @Param("pid") String pid, HttpServletRequest req) {
|
||||
try {
|
||||
List<Sys_menu> list = sysUserService.getRoleMenus(id, pid);
|
||||
List<NutMap> treeList = new ArrayList<>();
|
||||
for (Sys_menu unit : list) {
|
||||
if (!unit.isHasChildren() && sysUserService.hasChildren(id, unit.getId())) {
|
||||
unit.setHasChildren(true);
|
||||
}
|
||||
NutMap map = Lang.obj2nutmap(unit);
|
||||
map.addv("expanded", false);
|
||||
map.addv("children", new ArrayList<>());
|
||||
treeList.add(map);
|
||||
}
|
||||
return Result.success().addData(treeList);
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:{locked:'password|salt',ignoreNull:false}")
|
||||
@SaCheckPermission("sys.manager.user")
|
||||
public Object data(@Param("searchUnit") String searchUnit, @Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy) {
|
||||
try {
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
if (Strings.isNotBlank(searchUnit)) {
|
||||
cnd.and("unitid", "=", searchUnit);
|
||||
}
|
||||
} else {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
if (Strings.isNotBlank(searchUnit)) {
|
||||
Sys_unit unit = sysUnitService.fetch(searchUnit);
|
||||
if (unit == null || !unit.getPath().startsWith(user.getUnit().getPath())) {
|
||||
//防止有人越级访问
|
||||
return Result.error("非法操作");
|
||||
} else
|
||||
cnd.and("unitId", "=", searchUnit);
|
||||
} else {
|
||||
cnd.and("unitId", "=", user.getUnitId());
|
||||
}
|
||||
}
|
||||
if (Strings.isNotBlank(searchName) && Strings.isNotBlank(searchKeyword)) {
|
||||
cnd.and(searchName, "like", "%" + searchKeyword + "%");
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
return Result.success().addData(sysUserService.listPageLinks(pageNumber, pageSize, cnd, "unit"));
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@SaCheckPermission("sys.manager.user")
|
||||
public void export(@Param("searchUnit") String searchUnit, @Param("searchName") String searchName, @Param("searchKeyword") String searchKeyword, @Param("pageOrderName") String pageOrderName, @Param("pageOrderBy") String pageOrderBy, HttpServletResponse response) {
|
||||
try {
|
||||
J4EConf j4eConf = J4EConf.from(Sys_user.class);
|
||||
List<J4EColumn> jcols = j4eConf.getColumns();
|
||||
for (J4EColumn j4eColumn : jcols) {
|
||||
if ("createdBy".equals(j4eColumn.getFieldName()) || "createdAt".equals(j4eColumn.getFieldName()) || "delFlag".equals(j4eColumn.getFieldName())) {
|
||||
j4eColumn.setIgnore(true);
|
||||
}
|
||||
}
|
||||
Cnd cnd = Cnd.NEW();
|
||||
if (StpUtil.hasRole("sysadmin")) {
|
||||
if (Strings.isNotBlank(searchUnit)) {
|
||||
cnd.and("unitid", "=", searchUnit);
|
||||
}
|
||||
} else {
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
if (Strings.isNotBlank(searchUnit)) {
|
||||
Sys_unit unit = sysUnitService.fetch(searchUnit);
|
||||
if (unit == null || !unit.getPath().startsWith(user.getUnit().getPath())) {
|
||||
//防止有人越级访问
|
||||
throw Lang.makeThrow("非法操作");
|
||||
} else
|
||||
cnd.and("unitId", "=", searchUnit);
|
||||
} else {
|
||||
cnd.and("unitId", "=", user.getUnitId());
|
||||
}
|
||||
}
|
||||
if (Strings.isNotBlank(searchName) && Strings.isNotBlank(searchKeyword)) {
|
||||
cnd.and(searchName, "like", "%" + searchKeyword + "%");
|
||||
}
|
||||
if (Strings.isNotBlank(pageOrderName) && Strings.isNotBlank(pageOrderBy)) {
|
||||
cnd.orderBy(pageOrderName, PageUtil.getOrder(pageOrderBy));
|
||||
}
|
||||
OutputStream out = response.getOutputStream();
|
||||
response.setHeader("content-type", "application/shlnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("content-disposition", "attachment; filename=" + new String("用户信息".getBytes(), "ISO-8859-1") + ".xls");
|
||||
J4E.toExcel(out, sysUserService.query(cnd, "unit"), j4eConf);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("beetl:/platform/sys/user/pass.html")
|
||||
@SaCheckLogin
|
||||
public void pass() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("beetl:/platform/sys/user/info.html")
|
||||
@SaCheckLogin
|
||||
public void info(HttpServletRequest req) {
|
||||
Sys_user user = sysUserService.fetch(SecurityUtil.getUserId());
|
||||
req.setAttribute("user", user);
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("beetl:/platform/sys/user/custom.html")
|
||||
@SaCheckLogin
|
||||
public void custom() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("beetl:/platform/sys/user/mode.html")
|
||||
@SaCheckLogin
|
||||
public void mode() {
|
||||
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object doChangePassword(@Param("oldPassword") String oldPassword, @Param("newPassword") String newPassword, HttpServletRequest req) {
|
||||
if ("superadmin".equals(SecurityUtil.getUserLoginname()) && Globals.MyConfig.getBoolean("AppDemoEnv")) {
|
||||
return Result.error("演示环境,不予操作");
|
||||
}
|
||||
Sys_user user = sysUserService.getUserById(SecurityUtil.getUserId());
|
||||
String old = PwdUtil.getPassword(oldPassword, user.getSalt());
|
||||
if (old.equals(user.getPassword())) {
|
||||
String salt = R.UU32();
|
||||
String hashedPasswordBase64 = PwdUtil.getPassword(newPassword, salt);
|
||||
user.setSalt(salt);
|
||||
user.setPassword(hashedPasswordBase64);
|
||||
sysUserService.update(Chain.make("salt", salt).add("password", hashedPasswordBase64), Cnd.where("id", "=", user.getId()));
|
||||
sysUserService.deleteCache(user.getId());
|
||||
return Result.success("修改成功");
|
||||
} else {
|
||||
return Result.error("旧密码错误");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json")
|
||||
@SaCheckLogin
|
||||
public Object doChangeInfo(@Param("username") String username, @Param("mobile") String mobile, @Param("email") String email, HttpServletRequest req) {
|
||||
if ("superadmin".equals(SecurityUtil.getUserLoginname()) && Globals.MyConfig.getBoolean("AppDemoEnv")) {
|
||||
return Result.error("演示环境,不予操作");
|
||||
}
|
||||
sysUserService.update(Chain.make("username", username).add("mobile", mobile).add("email", email), Cnd.where("id", "=", SecurityUtil.getUserId()));
|
||||
sysUserService.deleteCache(SecurityUtil.getUserId());
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("client_user")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
@Comment("手机端用户")
|
||||
public class Client_user extends BaseModel implements Serializable {
|
||||
|
||||
@Id
|
||||
@Comment("ID")
|
||||
private Long id;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
@Comment("姓名")
|
||||
private String userName;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 1)
|
||||
@Comment("性别")
|
||||
private String sex;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 11)
|
||||
@Comment("手机号")
|
||||
private String mobile;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
@Comment("openId")
|
||||
private String openId;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* API密钥管理
|
||||
* Created by wizzer on 2019/2/26.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_api")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_api extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String appid;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String appkey;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 应用管理--配置文件表
|
||||
* Created by wizzer on 2019/2/27.
|
||||
*/
|
||||
@Table("sys_app_conf")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_app_conf extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Prev(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("实例名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String confName;
|
||||
|
||||
@Column
|
||||
@Comment("版本号")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String confVersion;
|
||||
|
||||
@Column
|
||||
@Comment("配置内容")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String confData;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
@One(field = "createdBy")
|
||||
private Sys_user user;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getConfName() {
|
||||
return confName;
|
||||
}
|
||||
|
||||
public void setConfName(String confName) {
|
||||
this.confName = confName;
|
||||
}
|
||||
|
||||
public String getConfVersion() {
|
||||
return confVersion;
|
||||
}
|
||||
|
||||
public void setConfVersion(String confVersion) {
|
||||
this.confVersion = confVersion;
|
||||
}
|
||||
|
||||
public String getConfData() {
|
||||
return confData;
|
||||
}
|
||||
|
||||
public void setConfData(String confData) {
|
||||
this.confData = confData;
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public Sys_user getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(Sys_user user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 应用管理--应用实例表
|
||||
* Created by wizzer on 2019/2/27.
|
||||
*/
|
||||
@Data
|
||||
@Table("sys_app_list")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_app_list extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Prev(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("实例名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String appName;
|
||||
|
||||
@Column
|
||||
@Comment("版本号")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String appVersion;
|
||||
|
||||
@Column
|
||||
@Comment("文件大小")
|
||||
private Long fileSize;
|
||||
|
||||
@Column
|
||||
@Comment("文件路径")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String filePath;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
@One(field = "createdBy")
|
||||
private Sys_user user;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 应用管理--推送任务表
|
||||
* Created by wizzer on 2019/2/27.
|
||||
*/
|
||||
@Data
|
||||
@Table("sys_app_task")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_app_task extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@Prev(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("实例名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Comment("执行动作")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String action;
|
||||
|
||||
@Column
|
||||
@Comment("APP版本")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String appVersion;
|
||||
|
||||
@Column
|
||||
@Comment("配置版本")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String confVersion;
|
||||
|
||||
@Column
|
||||
@Comment("进程ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String processId;
|
||||
|
||||
@Column
|
||||
@Comment("推送主机")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String hostName;//主机名 如果是推送给全部主机则为多条
|
||||
|
||||
@Column
|
||||
@Comment("主机IP")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String hostAddress;//只为展示用
|
||||
|
||||
@Column
|
||||
@Comment("推送状态")
|
||||
@ColDefine(type = ColType.INT, width = 1)
|
||||
private Integer status;//0-待执行,1-执行中,2-执行成功,3-执行失败,4-撤销任务
|
||||
|
||||
@Column
|
||||
@Comment("反馈时间")
|
||||
private Long pushAt;
|
||||
|
||||
@Column
|
||||
@Comment("反馈结果")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String pushResult;
|
||||
|
||||
@One(field = "createdBy")
|
||||
private Sys_user user;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_config")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_config extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Name
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String configKey;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String configValue;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String note;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.DB;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_dict")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
@TableIndexes({@Index(name = "INDEX_SYS_DICT_PATH", fields = {"path"}, unique = true)})
|
||||
public class Sys_dict extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("父级ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String parentId;
|
||||
|
||||
@Column
|
||||
@Comment("树路径")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String path;
|
||||
|
||||
@Column
|
||||
@Comment("名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Comment("机构编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
private String code;
|
||||
|
||||
@Column
|
||||
@Comment("启用状态")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
@Column
|
||||
@Comment("排序字段")
|
||||
@Prev({
|
||||
@SQL(db= DB.MYSQL,value = "SELECT IFNULL(MAX(location),0)+1 FROM sys_dict"),
|
||||
@SQL(db= DB.ORACLE,value = "SELECT COALESCE(MAX(location),0)+1 FROM sys_dict")
|
||||
})
|
||||
private Integer location;
|
||||
|
||||
@Column
|
||||
@Comment("有子节点")
|
||||
private boolean hasChildren;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_log_${month}")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_log extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("操作人姓名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String username;
|
||||
|
||||
@Column
|
||||
@Comment("操作人用户名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String loginname;
|
||||
|
||||
@Column
|
||||
@Comment("日志类型")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
private String type;
|
||||
|
||||
@Column
|
||||
@Comment("日志标识")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String tag;
|
||||
|
||||
@Column
|
||||
@Comment("执行类")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String src;
|
||||
|
||||
@Column
|
||||
@Comment("来源IP")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String ip;
|
||||
|
||||
@Column
|
||||
@Comment("日志内容")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String msg;
|
||||
|
||||
@Column
|
||||
@Comment("请求结果")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String param;
|
||||
|
||||
@Column
|
||||
@Comment("执行结果")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String result;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.DB;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_menu")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
@TableIndexes({@Index(name = "INDEX_SYS_MENU_PATH", fields = {"path"}, unique = true), @Index(name = "INDEX_SYS_MENU_PREM", fields = {"permission"}, unique = true)})
|
||||
public class Sys_menu extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("父级ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String parentId;
|
||||
|
||||
@Column
|
||||
@Comment("树路径")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String path;
|
||||
|
||||
@Column
|
||||
@Comment("菜单名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Comment("菜单别名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String aliasName;
|
||||
|
||||
@Column
|
||||
@Comment("资源类型")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 10)
|
||||
private String type;
|
||||
|
||||
@Column
|
||||
@Comment("菜单链接")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String href;
|
||||
|
||||
@Column
|
||||
@Comment("打开方式")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String target;
|
||||
|
||||
@Column
|
||||
@Comment("菜单图标")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String icon;
|
||||
|
||||
@Column
|
||||
@Comment("是否显示")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean showit;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
@Column
|
||||
@Comment("权限标识")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String permission;
|
||||
|
||||
@Column
|
||||
@Comment("菜单介绍")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String note;
|
||||
|
||||
@Column
|
||||
@Comment("排序字段")
|
||||
@Prev({
|
||||
@SQL(db= DB.MYSQL,value = "SELECT IFNULL(MAX(location),0)+1 FROM sys_menu"),
|
||||
@SQL(db= DB.ORACLE,value = "SELECT COALESCE(MAX(location),0)+1 FROM sys_menu")
|
||||
})
|
||||
private Integer location;
|
||||
|
||||
@Column
|
||||
@Comment("有子节点")
|
||||
private boolean hasChildren;
|
||||
|
||||
private List<Sys_menu> buttons;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2018/6/29.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_msg")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_msg extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("消息类型")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String type;
|
||||
|
||||
@Column
|
||||
@Comment("消息标题")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String title;
|
||||
|
||||
@Column
|
||||
@Comment("消息内容")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String note;
|
||||
|
||||
@Column
|
||||
@Comment("消息URL")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String url;
|
||||
|
||||
@Column
|
||||
@Comment("发送时间")
|
||||
//Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
|
||||
private Long sendAt;
|
||||
|
||||
@Many(field = "msgId")
|
||||
private List<Sys_msg_user> userList;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2018/6/29.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_msg_user")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_msg_user extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("消息ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String msgId;
|
||||
|
||||
@Column
|
||||
@Comment("用户名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 120)
|
||||
private String loginname;
|
||||
|
||||
@Column
|
||||
@Comment("消息状态")
|
||||
@ColDefine(type = ColType.INT)
|
||||
private int status;//0--未读 1--已读
|
||||
|
||||
@Column
|
||||
@Comment("读取时间")
|
||||
//Long不要用ColDefine定义,兼容oracle/mysql,支持2038年以后的时间戳
|
||||
private Long readAt;
|
||||
|
||||
@One(field = "msgId")
|
||||
private Sys_msg msg;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_role")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
@TableIndexes({@Index(name = "INDEX_SYS_ROLE_CODE", fields = {"code"}, unique = true)})
|
||||
public class Sys_role extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String code;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String aliasName;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String unitid;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String note;
|
||||
|
||||
@One(field = "unitid")
|
||||
public Sys_unit unit;
|
||||
|
||||
@ManyMany(from = "roleId", relation = "sys_role_menu", to = "menuId")
|
||||
protected List<Sys_menu> menus;
|
||||
|
||||
@ManyMany(from = "roleId", relation = "sys_user_role", to = "userId")
|
||||
private List<Sys_user> users;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Wizzer on 2016/7/31.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_route")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_route extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("原始路径")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String url;
|
||||
|
||||
@Column
|
||||
@Comment("跳转路径")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String toUrl;
|
||||
|
||||
@Column
|
||||
@Comment("转发类型")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 10)
|
||||
private String type;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Wizzer on 2016/7/30.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_task")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
public class Sys_task extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("任务名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Comment("执行类")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String jobClass;
|
||||
|
||||
@Column
|
||||
@Comment("任务说明")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String note;
|
||||
|
||||
@Column
|
||||
@Comment("定时规则")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String cron;
|
||||
|
||||
@Column
|
||||
@Comment("执行参数")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String data;
|
||||
|
||||
@Column
|
||||
@Comment("执行时间")
|
||||
private Long exeAt;
|
||||
|
||||
@Column
|
||||
@Comment("执行结果")
|
||||
@ColDefine(type = ColType.TEXT)
|
||||
private String exeResult;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.DB;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_unit")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
@TableIndexes({@Index(name = "INDEX_SYS_UNIT_PATH", fields = {"path"}, unique = true),
|
||||
@Index(name = "INDEX_SYS_UNIT_UNITCODE", fields = {"unitcode"}, unique = true)
|
||||
})
|
||||
public class Sys_unit extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(els = {@EL("uuid()")})
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("父级ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String parentId;
|
||||
|
||||
@Column
|
||||
@Comment("树路径")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String path;
|
||||
|
||||
@Column
|
||||
@Comment("单位名称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String name;
|
||||
|
||||
@Column
|
||||
@Comment("单位别名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String aliasName;
|
||||
|
||||
@Column
|
||||
@Comment("机构编码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String unitcode;
|
||||
|
||||
@Column
|
||||
@Comment("单位介绍")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String note;
|
||||
|
||||
@Column
|
||||
@Comment("单位地址")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String address;
|
||||
|
||||
@Column
|
||||
@Comment("联系电话")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 20)
|
||||
private String telephone;
|
||||
|
||||
@Column
|
||||
@Comment("单位邮箱")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String email;
|
||||
|
||||
@Column
|
||||
@Comment("单位网站")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String website;
|
||||
|
||||
@Column
|
||||
@Comment("排序字段")
|
||||
@Prev({
|
||||
@SQL(db = DB.MYSQL, value = "SELECT IFNULL(MAX(location),0)+1 FROM sys_unit"),
|
||||
@SQL(db = DB.ORACLE, value = "SELECT COALESCE(MAX(location),0)+1 FROM sys_unit")
|
||||
})
|
||||
private Integer location;
|
||||
|
||||
@Column
|
||||
@Comment("有子节点")
|
||||
private boolean hasChildren;
|
||||
|
||||
@Column
|
||||
@Comment("单位logo")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String logo;
|
||||
|
||||
@Column
|
||||
@Comment("是否本校单位")
|
||||
@Default("0")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isThisSchoolUnit;
|
||||
|
||||
@Column
|
||||
@Comment("是否启用")
|
||||
@Default("1")
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private Boolean isEnable;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.*;
|
||||
import org.nutz.dao.interceptor.annotation.PrevInsert;
|
||||
import org.nutz.integration.json4excel.annotation.J4EIgnore;
|
||||
import org.nutz.integration.json4excel.annotation.J4EName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/21.
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_user")
|
||||
@TableMeta("{'mysql-charset':'utf8mb4'}")
|
||||
@J4EName("用户数据")
|
||||
@TableIndexes({@Index(name = "INDEX_SYS_USER_LOGINNAMAE", fields = {"loginname"}, unique = true)})
|
||||
public class Sys_user extends BaseModel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Column
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
@Comment("用户名")
|
||||
@J4EName("用户名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 120)
|
||||
private String loginname;
|
||||
|
||||
@Column
|
||||
@Comment("密码")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String password;// transient 修饰符可让此字段不在对象里显示
|
||||
|
||||
@Column
|
||||
@Comment("密码盐")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String salt;
|
||||
|
||||
@Column
|
||||
@Comment("姓名")
|
||||
@J4EName("姓名")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String username;
|
||||
|
||||
@Column
|
||||
@Comment("头像")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String avatar;
|
||||
|
||||
@Column
|
||||
@Comment("是否在线")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean userOnline;
|
||||
|
||||
@Column
|
||||
@Comment("是否禁用")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.BOOLEAN)
|
||||
private boolean disabled;
|
||||
|
||||
@Column
|
||||
@Comment("电子邮箱")
|
||||
@J4EName("电子邮箱")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String email;
|
||||
|
||||
@Column
|
||||
@Comment("手机号码")
|
||||
@J4EName("手机号码")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String mobile;
|
||||
|
||||
@Column
|
||||
@Comment("创建时间")
|
||||
@J4EIgnore
|
||||
@PrevInsert(now = true)
|
||||
private Long createAt;
|
||||
|
||||
@Column
|
||||
@Comment("登陆时间")
|
||||
@J4EIgnore
|
||||
private Long loginAt;
|
||||
|
||||
@Column
|
||||
@Comment("登陆IP")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 255)
|
||||
private String loginIp;
|
||||
|
||||
@Column
|
||||
@Comment("登陆次数")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.INT)
|
||||
private Integer loginCount;
|
||||
|
||||
@Column
|
||||
@Comment("登陆SessionId")
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
private String loginSessionId;
|
||||
|
||||
@Column
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String unitId;
|
||||
|
||||
@Column
|
||||
@J4EIgnore
|
||||
@ColDefine(type = ColType.VARCHAR, width = 100)
|
||||
private String unitPath;
|
||||
|
||||
@One(field = "unitId")
|
||||
@J4EIgnore
|
||||
private Sys_unit unit;
|
||||
|
||||
@ManyMany(from = "userId", relation = "sys_user_role", to = "roleId")
|
||||
@J4EIgnore
|
||||
private List<Sys_role> roles;
|
||||
|
||||
@ManyMany(from = "userId", relation = "sys_user_unit", to = "unitId")
|
||||
@J4EIgnore
|
||||
protected List<Sys_unit> units;
|
||||
|
||||
@J4EIgnore
|
||||
protected List<Sys_menu> menus;
|
||||
|
||||
@J4EIgnore
|
||||
protected List<Sys_menu> firstMenus;
|
||||
|
||||
@J4EIgnore
|
||||
protected Map<String, List<Sys_menu>> secondMenus;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.budwk.app.sys.models;
|
||||
|
||||
import com.budwk.app.base.model.BaseModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.nutz.dao.entity.annotation.ColDefine;
|
||||
import org.nutz.dao.entity.annotation.ColType;
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @ClassName Sys_role_user
|
||||
* @Description TODO
|
||||
* @Author zhf
|
||||
* @Date 2025/3/18 上午10:11
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table("sys_user_role")
|
||||
public class Sys_user_role extends BaseModel implements Serializable {
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String roleId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String userId;
|
||||
|
||||
@Column
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String unitId;
|
||||
|
||||
|
||||
}
|
||||
@@ -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,17 @@
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
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
|
||||
*/
|
||||
void deleteAndChild(Sys_dict dict);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
void clearCache();
|
||||
}
|
||||
@@ -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,56 @@
|
||||
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);
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*
|
||||
* @param menu
|
||||
* @param pid
|
||||
*/
|
||||
void edit(Sys_menu menu, String pid, List<NutMap> datas);
|
||||
|
||||
/**
|
||||
* 级联删除菜单
|
||||
*
|
||||
* @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,67 @@
|
||||
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
|
||||
*/
|
||||
Sys_msg saveMsg(Sys_msg sysMsg, String[] users);
|
||||
|
||||
/**
|
||||
* 删除消息及消息用户表数据
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
@@ -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,105 @@
|
||||
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_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);
|
||||
|
||||
/**
|
||||
* 通过角色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);
|
||||
/**
|
||||
* 通过角色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);
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
*/
|
||||
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,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,197 @@
|
||||
package com.budwk.app.sys.services;
|
||||
|
||||
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
|
||||
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);
|
||||
|
||||
/**
|
||||
* 通过用户ID获取菜单及权限
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getMenusAndButtons(String userId);
|
||||
|
||||
/**
|
||||
* 通过用户ID获取菜单
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getDatas(String userId);
|
||||
|
||||
/**
|
||||
* 绑定菜单到用户
|
||||
*
|
||||
* @param user
|
||||
*/
|
||||
Sys_user fillMenu(Sys_user user);
|
||||
|
||||
/**
|
||||
* 通过用户ID获取菜单
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<Sys_menu> getMenus(String userId);
|
||||
|
||||
/**
|
||||
* 通过用户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;
|
||||
|
||||
/**
|
||||
* 检查用户是否存在
|
||||
*
|
||||
* @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
|
||||
* @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 loginname 用户名
|
||||
* @param password 新密码
|
||||
* @throws BaseException
|
||||
*/
|
||||
void setPwdByLoginname(String loginname, String password) throws BaseException;
|
||||
|
||||
/**
|
||||
* 通过用户ID重置密码
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @param password 新密码
|
||||
* @throws BaseException
|
||||
*/
|
||||
void setPwdById(String id, String password) throws BaseException;
|
||||
|
||||
/**
|
||||
* 设置用户自定义样式
|
||||
*
|
||||
* @param id 用户ID
|
||||
* @param themeConfig 样式内容
|
||||
*/
|
||||
void setThemeConfig(String id, String themeConfig);
|
||||
|
||||
/**
|
||||
* 更新用户登录信息
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param ip IP地址
|
||||
*/
|
||||
void setLoginInfo(String userId, String ip);
|
||||
}
|
||||
@@ -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,24 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
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 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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
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())).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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 级联删除单位
|
||||
*
|
||||
* @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,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,152 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.sys.services.SysMenuService;
|
||||
import com.budwk.app.sys.services.SysRoleService;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
*
|
||||
* @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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 级联删除菜单
|
||||
*
|
||||
* @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,250 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import com.budwk.app.base.page.Pagination;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_msg;
|
||||
import com.budwk.app.sys.models.Sys_msg_user;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.services.SysMsgService;
|
||||
import com.budwk.app.sys.services.SysMsgUserService;
|
||||
import com.budwk.app.sys.services.SysUserService;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.integration.jedis.JedisAgent;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.integration.jedis.pubsub.PubSubService;
|
||||
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.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import redis.clients.jedis.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@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;
|
||||
|
||||
private static NutMap typeMap = NutMap.NEW().addv("system", "系统消息").addv("user", "用户消息");
|
||||
|
||||
public Sys_msg saveMsg(Sys_msg sysMsg, String[] users) {
|
||||
Sys_msg dbMsg = this.insert(sysMsg);
|
||||
if (dbMsg != null) {
|
||||
if ("user".equals(dbMsg.getType()) && users != null) {
|
||||
for (String loginname : users) {
|
||||
Sys_msg_user sys_msg_user = new Sys_msg_user();
|
||||
sys_msg_user.setMsgId(dbMsg.getId());
|
||||
sys_msg_user.setStatus(0);
|
||||
sys_msg_user.setLoginname(loginname);
|
||||
sysMsgUserService.insert(sys_msg_user);
|
||||
}
|
||||
}
|
||||
if ("system".equals(dbMsg.getType())) {
|
||||
Cnd cnd = Cnd.where("disabled", "=", false).and("delFlag", "=", false);
|
||||
int total = sysUserService.count(cnd);
|
||||
int size = 1000;
|
||||
Pagination pagination = new Pagination();
|
||||
pagination.setTotalCount(total);
|
||||
pagination.setPageSize(size);
|
||||
for (int i = 1; i <= pagination.getTotalPage(); i++) {
|
||||
Pagination pagination2 = sysUserService.listPage(i, size, cnd);
|
||||
for (Object sysUser : pagination2.getList()) {
|
||||
Sys_user user = (Sys_user) sysUser;
|
||||
Sys_msg_user sys_msg_user = new Sys_msg_user();
|
||||
sys_msg_user.setMsgId(dbMsg.getId());
|
||||
sys_msg_user.setStatus(0);
|
||||
sys_msg_user.setLoginname(user.getLoginname());
|
||||
sysMsgUserService.insert(sys_msg_user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sysMsgUserService.clearCache();
|
||||
notify(dbMsg, users);
|
||||
return dbMsg;
|
||||
}
|
||||
|
||||
public void deleteMsg(String id) {
|
||||
this.vDelete(id);
|
||||
sysMsgUserService.vDelete(Cnd.where("msgId", "=", id));
|
||||
sysMsgUserService.clearCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void notify(Sys_msg innerMsg, String rooms[]) {
|
||||
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);
|
||||
}
|
||||
} 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);//最新3条消息列表 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMsg(String loginname, String title, String body, String sender) {
|
||||
Sys_msg sysMsg = new Sys_msg();
|
||||
sysMsg.setTitle(title);
|
||||
sysMsg.setNote(body);
|
||||
sysMsg.setSendAt(Times.getTS());
|
||||
sysMsg.setCreatedBy(sender);
|
||||
this.saveMsg(sysMsg, new String[]{loginname});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
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 org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
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,206 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
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);
|
||||
}
|
||||
|
||||
@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.isDisabled()) {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
@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,71 @@
|
||||
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_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();
|
||||
}
|
||||
unit.setPath(getSubPath("sys_unit", "path", path));
|
||||
unit.setParentId(pid);
|
||||
dao().insert(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().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,351 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.lang.tree.TreeNode;
|
||||
import cn.hutool.core.lang.tree.TreeUtil;
|
||||
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.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
import com.budwk.app.sys.models.Sys_role;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
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.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.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.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 java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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;
|
||||
|
||||
@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> menus = getMenus(user.getId());
|
||||
user.setMenus(menus);
|
||||
//计算左侧菜单
|
||||
List<Sys_menu> firstMenus = new ArrayList<>();
|
||||
Map<String, List<Sys_menu>> secondMenus = new HashMap<>();
|
||||
for (Sys_menu menu : user.getMenus()) {
|
||||
if (menu.getPath().length() > 4) {
|
||||
List<Sys_menu> s = secondMenus.get(getParentPath(menu.getPath()));
|
||||
if (s == null) s = new ArrayList<>();
|
||||
s.add(menu);
|
||||
secondMenus.put(getParentPath(menu.getPath()), s);
|
||||
} else if (menu.getPath().length() == 4) {
|
||||
firstMenus.add(menu);
|
||||
}
|
||||
}
|
||||
user.setFirstMenus(firstMenus);
|
||||
user.setSecondMenus(secondMenus);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户按钮权限
|
||||
*
|
||||
* @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 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("用户不存在");
|
||||
}
|
||||
if (user.isDisabled()) {
|
||||
throw new BaseException("用户被禁用");
|
||||
}
|
||||
String hashedPassword = PwdUtil.getPassword(passowrd, user.getSalt());
|
||||
if (!Strings.sNull(hashedPassword).equalsIgnoreCase(user.getPassword())) {
|
||||
throw new BaseException("密码不正确");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
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("用户不存在");
|
||||
}
|
||||
if (user.isDisabled()) {
|
||||
throw new BaseException("用户被禁用");
|
||||
}
|
||||
user = this.fetchLinks(user, "unit");
|
||||
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
|
||||
@CacheResult(cacheKey = "${userId}_getUserAndMenuById")
|
||||
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);
|
||||
user = this.fillMenu(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPwdByLoginname(String loginname, String password) throws BaseException {
|
||||
Sys_user user = this.fetch(Cnd.where("loginname", "=", loginname));
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
String salt = R.UU32();
|
||||
this.update(Chain.make("salt", salt).add("password", PwdUtil.getPassword(password, salt)),
|
||||
Cnd.where("loginname", "=", loginname));
|
||||
this.deleteCache(user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPwdById(String id, String password) throws BaseException {
|
||||
Sys_user user = this.fetch(id);
|
||||
if (user == null) {
|
||||
throw new BaseException("用户不存在");
|
||||
}
|
||||
String salt = R.UU32();
|
||||
this.update(Chain.make("salt", salt).add("password", PwdUtil.getPassword(password, salt)),
|
||||
Cnd.where("id", "=", id));
|
||||
this.deleteCache(user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setThemeConfig(String id, String themeConfig) {
|
||||
this.update(Chain.make("themeConfig", themeConfig), Cnd.where("id", "=", id));
|
||||
this.deleteCache(id);// 清一下缓存
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user