Search in sources :

Example 1 with ActiveRecordException

use of com.jfinal.plugin.activerecord.ActiveRecordException in project my_curd by qinyou.

the class SysOrgController method deleteAction.

/**
 * 1: 删除当前结构和子组织机构
 * 2: 当前机构和子组织机构的 人员 orgId 设置为null
 */
@Before(Tx.class)
public void deleteAction() {
    Integer id = getParaToInt("id");
    try {
        Record record = Db.findFirst("select getChildLst(?,'sys_org') as childrenIds ", id);
        // 子、孙 id
        String childrenIds = record.getStr("childrenIds");
        String deleteSql = "delete from sys_org where  id  in (" + childrenIds + ")";
        Db.update(deleteSql);
        String updateSql = "update sys_user set org_id = null where  org_id in (" + childrenIds + ")";
        Db.update(updateSql);
        renderText(Constant.DELETE_SUCCESS);
    } catch (ActiveRecordException e) {
        renderText(Constant.DELETE_FAIL);
    }
}
Also used : Record(com.jfinal.plugin.activerecord.Record) ActiveRecordException(com.jfinal.plugin.activerecord.ActiveRecordException) Before(com.jfinal.aop.Before)

Example 2 with ActiveRecordException

use of com.jfinal.plugin.activerecord.ActiveRecordException in project my_curd by qinyou.

the class SysUserController method giveRole.

/**
 * 用户赋予角色
 */
@Before(Tx.class)
public void giveRole() {
    String userId = getPara("userId");
    String roleIdstr = getPara("roleIds");
    try {
        String deleteSql = "delete from  sys_user_role where user_id = ?";
        Db.update(deleteSql, userId);
        String[] roleIds = roleIdstr.split(";");
        for (int i = 0; i < roleIds.length; i++) {
            SysUserRole sysUserRole = new SysUserRole();
            sysUserRole.setUserId(userId);
            sysUserRole.setRoleId(Integer.parseInt(roleIds[i]));
            sysUserRole.save();
        }
        renderText("赋予角色成功");
    } catch (ActiveRecordException e) {
        e.printStackTrace();
        renderText("赋予角色失败");
    }
}
Also used : ActiveRecordException(com.jfinal.plugin.activerecord.ActiveRecordException) SysUserRole(com.hxkj.system.model.SysUserRole) Before(com.jfinal.aop.Before)

Example 3 with ActiveRecordException

use of com.jfinal.plugin.activerecord.ActiveRecordException in project my_curd by qinyou.

the class sysOplogController method deleteAction.

@Before(Tx.class)
public void deleteAction() {
    String ids = getPara("ids");
    ids = "'" + ids.replace(",", "','") + "'";
    try {
        String deleteSql = "delete from sys_oplog where id  in ( " + ids + " ) ";
        Db.update(deleteSql);
        renderText(Constant.DELETE_SUCCESS);
    } catch (ActiveRecordException e) {
        renderText(Constant.DELETE_FAIL);
    }
}
Also used : ToolString(com.hxkj.common.util.ToolString) ActiveRecordException(com.jfinal.plugin.activerecord.ActiveRecordException) Before(com.jfinal.aop.Before)

Example 4 with ActiveRecordException

use of com.jfinal.plugin.activerecord.ActiveRecordException in project my_curd by qinyou.

the class SysMenuController method deleteAction.

@Before(Tx.class)
public void deleteAction() {
    Integer id = getParaToInt("id");
    try {
        Record record = Db.findFirst("select getChildLst(?,'sys_menu') as childrenIds ", id);
        // 子、孙 id
        String childrenIds = record.getStr("childrenIds");
        // 删除相应 角色菜单
        String deleteSql = "delete from sys_menu where id in (" + childrenIds + ")";
        Db.update(deleteSql);
        // 删除角色菜单关联数据
        deleteSql = "delete from sys_role_menu where menu_id in (" + childrenIds + ") ";
        Db.update(deleteSql);
        renderText(Constant.DELETE_SUCCESS);
    } catch (ActiveRecordException e) {
        e.printStackTrace();
        renderText(Constant.DELETE_FAIL);
    }
}
Also used : Record(com.jfinal.plugin.activerecord.Record) ActiveRecordException(com.jfinal.plugin.activerecord.ActiveRecordException) Before(com.jfinal.aop.Before)

Example 5 with ActiveRecordException

use of com.jfinal.plugin.activerecord.ActiveRecordException in project my_curd by qinyou.

the class SysRoleController method givePermission.

/**
 * 用户赋权限
 */
@Before(Tx.class)
public void givePermission() {
    Integer roleId = getParaToInt("roleId");
    String permissIds = getPara("permissIds");
    try {
        String deleteSql = "delete from  sys_role_menu where role_id = ?";
        Db.update(deleteSql, roleId);
        if (StrKit.notBlank(permissIds)) {
            String[] menuIds = permissIds.split(";");
            for (int i = 0; i < menuIds.length; i++) {
                SysRoleMenu sysRoleMenu = new SysRoleMenu();
                sysRoleMenu.setRoleId(roleId);
                sysRoleMenu.setMenuId(Integer.parseInt(menuIds[i]));
                sysRoleMenu.save();
            }
        }
        renderText("赋权成功");
    } catch (ActiveRecordException e) {
        e.printStackTrace();
        renderText("赋权失败");
    }
}
Also used : ActiveRecordException(com.jfinal.plugin.activerecord.ActiveRecordException) SysRoleMenu(com.hxkj.system.model.SysRoleMenu) Before(com.jfinal.aop.Before)

Aggregations

ActiveRecordException (com.jfinal.plugin.activerecord.ActiveRecordException)7 Before (com.jfinal.aop.Before)5 Record (com.jfinal.plugin.activerecord.Record)2 ToolString (com.hxkj.common.util.ToolString)1 SysRoleMenu (com.hxkj.system.model.SysRoleMenu)1 SysUserRole (com.hxkj.system.model.SysUserRole)1 TypeConverter (com.jfinal.core.converter.TypeConverter)1 Config (com.jfinal.plugin.activerecord.Config)1 Model (com.jfinal.plugin.activerecord.Model)1 NestedTransactionHelpException (com.jfinal.plugin.activerecord.NestedTransactionHelpException)1 Table (com.jfinal.plugin.activerecord.Table)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1