use of com.jfinal.aop.Before in project my_curd by qinyou.
the class SysUserController method updateAction.
/**
* update action
*/
@Before(Tx.class)
public void updateAction() {
SysUser sysUser = getBean(SysUser.class, "");
// 防止恶意修改用户名
String sql = "select count(1) as c from sys_user where username = ?";
if (SysUser.dao.findFirst(sql, sysUser.getUsername()).getLong("c") != 1) {
renderFail(UPDATE_FAIL);
return;
}
sysUser.setUpdater(WebUtils.getSessionUsername(this)).setUpdateTime(new Date());
sysUser.update();
// 更新用户组织机构
sql = "delete from sys_user_org where sysUserId = ?";
Db.delete(sql, sysUser.getId());
String[] orgIds = getParaValues("orgIds");
for (String orgId : orgIds) {
if (StringUtils.isEmpty(orgId)) {
continue;
}
new SysUserOrg().setSysUserId(sysUser.getId()).setSysOrgId(orgId).save();
}
renderSuccess(UPDATE_SUCCESS);
}
use of com.jfinal.aop.Before in project my_curd by qinyou.
the class SysUserController method addAction.
/**
* add action
*/
@Before(Tx.class)
public void addAction() {
SysUser sysUser = getBean(SysUser.class, "");
String sql = "select count(1) as c from sys_user where username = ?";
if (sysUser.dao().findFirst(sql).getLong("c") > 0L) {
renderFail(ADD_FAIL + ", 该用户名已存在");
}
sysUser.setId(IdUtils.id()).setCreater(WebUtils.getSessionUsername(this)).setCreateTime(new Date()).setUserState("0");
sysUser.setPassword(HashKit.sha1(DEFAULT_PWD));
sysUser.save();
String[] orgIds = getParaValues("orgIds");
for (String orgId : orgIds) {
if (StringUtils.isEmpty(orgId)) {
continue;
}
new SysUserOrg().setSysUserId(sysUser.getId()).setSysOrgId(orgId).save();
}
renderSuccess(ADD_SUCCESS);
}
use of com.jfinal.aop.Before in project my_curd by qinyou.
the class SysVisitLogController method exportExcel.
/**
* 导出excel
*/
@RequirePermission("sysVisitLog:export")
@Before(SearchSql.class)
public void exportExcel() {
String where = getAttr(Constant.SEARCH_SQL);
if (SysVisitLog.dao.findCountByWhere(where) > 50000) {
setAttr("msg", "一次导出数据不可大于 5W 条,请修改查询条件。");
render("common/card.ftl");
return;
}
// 测试大数据量导出
List<SysVisitLog> list = SysVisitLog.dao.findByWhere(where);
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("访问日志", "访问日志"), SysVisitLog.class, list);
render(ExcelRender.me(workbook).fileName("访问日志.xls"));
}
use of com.jfinal.aop.Before in project my_curd by qinyou.
the class SysRoleController method updateMenus.
// 更新角色 相关菜单
@Before(Tx.class)
public void updateMenus() {
String roleId = get("roleId");
String menuIds = get("menuIds");
if (StringUtils.isEmpty(roleId)) {
renderFail("roleId 参数不可为空.");
return;
}
// 删除 角色原有菜单
String sql = "delete from sys_role_menu where sysRoleId = ?";
Db.update(sql, roleId);
// 防止保存 非叶子菜单(没有具体的controller)
menuIds = menuIds.replace(",", "','");
sql = "select GROUP_CONCAT(id) as menuIds from sys_menu where url !='/' and id in ('" + menuIds + "')";
Record record = Db.findFirst(sql);
if (record == null || StringUtils.isEmpty(record.getStr("menuIds"))) {
renderFail("授权失败");
return;
}
menuIds = record.getStr("menuIds");
// 添加 角色新菜单
if (StringUtils.notEmpty(menuIds)) {
String[] menuIdAry = menuIds.split(",");
for (String menuId : menuIdAry) {
SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setSysRoleId(roleId).setSysMenuId(menuId).setCreater(WebUtils.getSessionUsername(this)).setCreateTime(new Date()).save();
}
}
renderSuccess("授权成功");
}
use of com.jfinal.aop.Before in project my_curd by qinyou.
the class ExStaffController method addAction.
/**
* 新增 action
*/
@Before(Tx.class)
public void addAction() {
// 新增主表
ExStaff exStaff = getBean(ExStaff.class, "exStaff");
exStaff.setId(IdUtils.id()).setCreater(WebUtils.getSessionUsername(this)).setCreateTime(new Date()).save();
// 新增 子表
List<ExStaffEducation> exStaffEducations = getBeans(ExStaffEducation.class, "exStaffEducation");
exStaffEducations.forEach(item -> item.setId(IdUtils.id()).setExStaffId(exStaff.getId()).setCreateTime(new Date()).setCreater(WebUtils.getSessionUsername(this)));
Db.batchSave(exStaffEducations, exStaffEducations.size());
List<ExStaffExperience> exStaffExperiences = getBeans(ExStaffExperience.class, "exStaffExperience");
exStaffExperiences.forEach(item -> item.setId(IdUtils.id()).setExStaffId(exStaff.getId()).setCreateTime(new Date()).setCreater(WebUtils.getSessionUsername(this)));
Db.batchSave(exStaffExperiences, exStaffExperiences.size());
List<ExStaffFamily> exStaffFamilys = getBeans(ExStaffFamily.class, "exStaffFamily");
exStaffFamilys.forEach(item -> item.setId(IdUtils.id()).setExStaffId(exStaff.getId()).setCreateTime(new Date()).setCreater(WebUtils.getSessionUsername(this)));
Db.batchSave(exStaffFamilys, exStaffFamilys.size());
renderSuccess(ADD_SUCCESS);
}
Aggregations