Skip to content

Commit

Permalink
update: for 5.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizzercn committed Mar 30, 2019
1 parent 217e550 commit 1da4dd8
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 104 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ https://wizzer.cn/donation 捐赠者列表
我们有强大的后援 —— Nutz 社区支持 https://nutz.cn 及 Nutz 使用手册 https://nutzam.com/core/nutz_preface.html

### QQ交流群
* 1群: 68428921 (已满)
* 1群: 68428921
* 2群: 24457628

# 版本说明
Expand Down Expand Up @@ -87,22 +87,27 @@ https://wizzer.cn/donation 捐赠者列表

### 分布式事务

*   涉及分布式的NB模块 pom.xml 添加
*   业务走过的链路所有NB模块, pom.xml 添加
```xml
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-fescar</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-dubbo-alibaba</artifactId>
<version>${fescar.version}</version>
</dependency>
```
*   涉及分布式的NB模块,配置文件中添加
*   业务走过的链路所有NB模块, 配置文件中添加
```text
fescar.enabled=true
# applicationId 无需设置,会自动获取
# applicationId 在本项目中会自动获取无需赋值
# fescar.applicationId=
fescar.txServiceGroup=wk_nb_tx_group
fescar.txServiceGroup=my_test_tx_group
```
*   下载并启动 [fescar服务端](https://github.com/alibaba/fescar/releases)
*   业务方法上加上注解 `@GlobalTransactional(timeoutMills = 300000, name = "dubbo-demo-tx")` 即可
*   业务方法上加上注解 `@GlobalTransactional` 即可,可选参数 `timeoutMills = 300000, name = "my_test_tx_group"`
*   与本地事务注解 `@Aop(TransAop.READ_COMMITTED)` 不冲突
*   业务方法内不要加 try catch (与本地事务注解一样)要让异常抛出来事务才能工作
*   分布式事务不是越多越好,可以在核心业务如交易环节增加,建议实现乐观锁来预防脏数据产生
Expand Down
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cn.wizzer</groupId>
<artifactId>wk-parent</artifactId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
<modules>
<module>wk-framework</module>
<module>wk-app</module>
Expand All @@ -16,15 +16,16 @@
<name>NutzWk-NB</name>

<properties>
<nutzboot.version>2.3.3-SNAPSHOT</nutzboot.version>
<nutz.version>1.r.68-SNAPSHOT</nutz.version>
<nutzboot.version>2.3.3.v20190329</nutzboot.version>
<nutz.version>1.r.68.v20190329</nutz.version>
<zkclient.version>0.11</zkclient.version>
<mysql-connector-java.version>5.1.47</mysql-connector-java.version>
<jaxb-api.version>2.3.1</jaxb-api.version>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.2.3</logback.version>
<!-- dubbo 及 sentinel 中netty版本保持一致 -->
<netty.version>4.1.34.Final</netty.version>
<fescar.version>0.4.1</fescar.version>
<docker.image.prefix>nutzwk</docker.image.prefix>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion wk-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wk-parent</artifactId>
<groupId>cn.wizzer</groupId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion wk-app/wk-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wk-app</artifactId>
<groupId>cn.wizzer.app</groupId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public interface SysRoleService extends BaseService<Sys_role> {
*/
void del(String[] roleids);

/**
* 保存菜单数据
* @param menuIds
* @param roleId
*/
void saveMenu(String[] menuIds,String roleId);
/**
* 通过角色ID和菜单父ID获取下级权限菜单
*
Expand Down
4 changes: 2 additions & 2 deletions wk-app/wk-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wk-app</artifactId>
<groupId>cn.wizzer.app</groupId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>cn.wizzer.app</groupId>
<artifactId>wk-code-generator-nb</artifactId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion wk-app/wk-nb-service-cms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wk-app</artifactId>
<groupId>cn.wizzer.app</groupId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ logback.exts.loglevel.heartbeat=10
# 详见 https://github.com/Wizzercn/PythonWk
logback.exts.deploy.enabled=false
#为应用管理提供支持,部署根路径
logback.exts.deploy.root=C://data/nutzwk
logback.exts.deploy.root=C://data/nutzwk

#fescar分布式事务,使用说明见 README
fescar.enabled=false
fescar.txServiceGroup=my_test_tx_group
2 changes: 1 addition & 1 deletion wk-app/wk-nb-service-sys/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wk-app</artifactId>
<groupId>cn.wizzer.app</groupId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import cn.wizzer.app.sys.modules.models.Sys_menu;
import cn.wizzer.app.sys.modules.models.Sys_role;
import cn.wizzer.app.sys.modules.models.Sys_unit;
import cn.wizzer.app.sys.modules.services.SysMenuService;
import cn.wizzer.app.sys.modules.services.SysRoleService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import cn.wizzer.framework.page.Pagination;
import com.alibaba.dubbo.config.annotation.Service;
import org.nutz.aop.interceptor.async.Async;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.DB;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.entity.Entity;
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;
Expand All @@ -34,18 +33,16 @@ public class SysRoleServiceImpl extends BaseServiceImpl<Sys_role> implements Sys
public SysRoleServiceImpl(Dao dao) {
super(dao);
}
@Inject
private SysMenuService sysMenuService;

@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);
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);
}

@CacheResult
Expand All @@ -54,21 +51,13 @@ public List<Sys_menu> getDatas(String roleId) {
" 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);
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
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");
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);
}

/**
Expand All @@ -91,19 +80,44 @@ public List<String> getPermissionNameList(Sys_role role) {
}

@Aop(TransAop.READ_COMMITTED)
@Async
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)
@Async
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)
@Async
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()));
}
}
}
}

/**
* @param roleId
* @param pid
Expand All @@ -120,11 +134,7 @@ public List<Sys_menu> getRoleMenus(String roleId, String pid) {
} else {
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
}
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);
}

/**
Expand All @@ -143,9 +153,7 @@ public boolean hasChildren(String roleId, String pid) {
} else {
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
}
sql.setCallback(Sqls.callback.integer());
dao().execute(sql);
return sql.getInt() > 0;
return sysMenuService.count(sql) > 0;
}

/**
Expand All @@ -159,7 +167,7 @@ public boolean hasChildren(String roleId, String pid) {
*/
public Pagination userSearch(String roleId, String keyword, boolean isAdmin, Sys_unit sysUnit) {
Sql sql;
if (DB.ORACLE.name().equals(this.dao().getJdbcExpert().getDatabaseType())) {
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.opAt desc");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public List<Sys_menu> getMenus(String userId) {
sql.params().set("userId", userId);
sql.params().set("f", false);
sql.params().set("t", true);
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);
}

/**
Expand All @@ -120,11 +116,7 @@ public List<Sys_menu> getMenusAndButtons(String userId) {
" 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);
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);
}

/**
Expand All @@ -139,11 +131,7 @@ public List<Sys_menu> getDatas(String userId) {
" 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);
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);
}

/**
Expand Down Expand Up @@ -186,11 +174,8 @@ public List<Sys_menu> getRoleMenus(String userId, String pid) {
} else {
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
}
Entity<Sys_menu> entity = dao().getEntity(Sys_menu.class);
sql.setEntity(entity);
sql.setCallback(Sqls.callback.entities());
dao().execute(sql);
return sql.getList(Sys_menu.class);
return sysMenuService.listEntity(sql);

}

/**
Expand All @@ -209,9 +194,7 @@ public boolean hasChildren(String userId, String pid) {
} else {
sql.vars().set("m", "(a.parentId='' or a.parentId is null)");
}
sql.setCallback(Sqls.callback.integer());
dao().execute(sql);
return sql.getInt() > 0;
return sysMenuService.count(sql) > 0;
}

@CacheRemove(cacheKey = "${args[0]}_*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ logback.exts.loglevel.heartbeat=10
# 详见 https://github.com/Wizzercn/PythonWk
logback.exts.deploy.enabled=false
#为应用管理提供支持,部署根路径
logback.exts.deploy.root=C://data/nutzwk
logback.exts.deploy.root=C://data/nutzwk

#fescar分布式事务,使用说明见 README
fescar.enabled=false
fescar.txServiceGroup=my_test_tx_group
2 changes: 1 addition & 1 deletion wk-app/wk-nb-service-wx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wk-app</artifactId>
<groupId>cn.wizzer.app</groupId>
<version>5.2.2-SNAPSHOT</version>
<version>5.2.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ logback.exts.loglevel.heartbeat=10
# 详见 https://github.com/Wizzercn/PythonWk
logback.exts.deploy.enabled=false
#为应用管理提供支持,部署根路径
logback.exts.deploy.root=C://data/nutzwk
logback.exts.deploy.root=C://data/nutzwk

#fescar分布式事务,使用说明见 README
fescar.enabled=false
fescar.txServiceGroup=my_test_tx_group
Loading

0 comments on commit 1da4dd8

Please sign in to comment.