20154 月27
Nutz 集成Activiti5.17.0 [03]扩展用户、组使用自己的数据表
首先值得一提的是,taskService.createTaskQuery().taskCandidateOrAssigned(userId) 方法有bug,不会调用重写的工厂类,请使用taskService.createTaskQuery().taskCandidateUser(userId)方法。
CustomGroupEntityManager
/** * 分组工厂类 * Created by wizzer on 15-4-27. */ @IocBean public class CustomGroupEntityManager extends GroupEntityManager { Dao dao= Mvcs.getIoc().get(Dao.class); private final Log log = Logs.get(); @Override public List<Group> findGroupsByUser(String userId) { Sql sql = Sqls.create("SELECT a.* FROM sys_role a,sys_user_role b WHERE a.id=b.roleid AND b.userid=@c"); sql.params().set("c", userId); sql.setCallback(Sqls.callback.maps()); dao.execute(sql); List<Map> list=sql.getList(Map.class); List<Group> groupList=new ArrayList<Group>(); for (Map m:list){ GroupEntity group=new GroupEntity(); group.setId(Strings.sNull(m.get("id"))); group.setName(Strings.sNull(m.get("name"))); group.setType("assignment"); group.setRevision(1); groupList.add(group); } return groupList; } }
CustomGroupEntityManagerFactory
/** * 分组接口类 * Created by wizzer on 15-4-27. */ @IocBean public class CustomGroupEntityManagerFactory implements SessionFactory { private GroupEntityManager groupEntityManager; public void setGroupEntityManager(GroupEntityManager groupEntityManager) { this.groupEntityManager = groupEntityManager; } @Override public Class<?> getSessionType() { return GroupIdentityManager.class; } @Override public Session openSession() { return groupEntityManager; } }
CustomUserEntityManager
/** * 用户工厂类 * Created by wizzer on 15-4-24. */ @IocBean public class CustomUserEntityManager extends UserEntityManager { Dao dao= Mvcs.getIoc().get(Dao.class); private final Log log = Logs.get(); @Override public User findUserById(String userId) { log.info("findUserById:::::::::::::::::::::::::::::::"+userId); UserEntity userEntity = new UserEntity(); Sys_user sysUser = dao.fetch(Sys_user.class, Cnd.where("uid", "=", userId)); userEntity.setId(userId); userEntity.setFirstName(sysUser.getRealname()); userEntity.setEmail(sysUser.getEmail()); userEntity.setRevision(1); return userEntity; } @Override public List<Group> findGroupsByUser(String userId) { // TODO Auto-generated method stub log.info("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); Sql sql = Sqls.create("SELECT a.* FROM sys_role a,sys_user_role b WHERE a.id=b.roleid AND b.userid=@c"); sql.params().set("c", userId); sql.setCallback(Sqls.callback.maps()); dao.execute(sql); List<Map> list=sql.getList(Map.class); List<Group> groupList=new ArrayList<Group>(); for (Map m:list){ GroupEntity group=new GroupEntity(); group.setId(Strings.sNull(m.get("id"))); group.setName(Strings.sNull(m.get("name"))); group.setType("assignment"); group.setRevision(1); groupList.add(group); } return groupList; } }
CustomUserEntityManagerFactory
/** * 用户接口类 * Created by wizzer on 15-4-24. */ @IocBean public class CustomUserEntityManagerFactory implements SessionFactory { private UserEntityManager userEntityManager; public void setUserEntityManager(UserEntityManager userEntityManager) { this.userEntityManager = userEntityManager; } @Override public Class<?> getSessionType() { return UserIdentityManager.class; } @Override public Session openSession() { return userEntityManager; } }
Nutz 集成Activiti5.17.0 [01]初始化activiti
在初始化activiti时追加代码:
List<SessionFactory> list=new ArrayList<SessionFactory>(); CustomGroupEntityManagerFactory customGroupManagerFactory=new CustomGroupEntityManagerFactory(); customGroupManagerFactory.setGroupEntityManager(new CustomGroupEntityManager()); CustomUserEntityManagerFactory customUserEntityManagerFactory=new CustomUserEntityManagerFactory(); customUserEntityManagerFactory.setUserEntityManager(new CustomUserEntityManager()); list.add(customGroupManagerFactory); list.add(customUserEntityManagerFactory); processEngineConfiguration.setCustomSessionFactories(list);
本文地址:https://wizzer.cn/archives/3131 , 转载请保留.