Search in sources :

Example 26 with Before

use of com.jfinal.aop.Before in project my_curd by qinyou.

the class ExStaffController method updateAction.

/**
 * 修改 action
 */
@SuppressWarnings("Duplicates")
@Before(Tx.class)
public void updateAction() {
    // 修改 主表
    ExStaff exStaff = getBean(ExStaff.class, "exStaff");
    exStaff.setUpdater(WebUtils.getSessionUsername(this)).setUpdateTime(new Date()).update();
    // 新增或修改 子表
    List<ExStaffEducation> exStaffEducations = getBeans(ExStaffEducation.class, "exStaffEducation");
    exStaffEducations.forEach(item -> {
        item.setExStaffId(exStaff.getId());
        if (StringUtils.isEmpty(item.getId())) {
            item.setId(IdUtils.id()).setCreateTime(new Date()).setCreater(WebUtils.getSessionUsername(this)).save();
        } else {
            item.setUpdateTime(new Date()).setUpdater(WebUtils.getSessionUsername(this)).update();
        }
    });
    List<ExStaffExperience> exStaffExperiences = getBeans(ExStaffExperience.class, "exStaffExperience");
    exStaffExperiences.forEach(item -> {
        item.setExStaffId(exStaff.getId());
        if (StringUtils.isEmpty(item.getId())) {
            item.setId(IdUtils.id()).setCreateTime(new Date()).setCreater(WebUtils.getSessionUsername(this)).save();
        } else {
            item.setUpdateTime(new Date()).setUpdater(WebUtils.getSessionUsername(this)).update();
        }
    });
    List<ExStaffFamily> exStaffFamilys = getBeans(ExStaffFamily.class, "exStaffFamily");
    exStaffFamilys.forEach(item -> {
        item.setExStaffId(exStaff.getId());
        if (StringUtils.isEmpty(item.getId())) {
            item.setId(IdUtils.id()).setCreateTime(new Date()).setCreater(WebUtils.getSessionUsername(this)).save();
        } else {
            item.setUpdateTime(new Date()).setUpdater(WebUtils.getSessionUsername(this)).update();
        }
    });
    renderSuccess(UPDATE_SUCCESS);
}
Also used : ExStaffFamily(com.github.qinyou.example.model.ExStaffFamily) ExStaff(com.github.qinyou.example.model.ExStaff) ExStaffExperience(com.github.qinyou.example.model.ExStaffExperience) ExStaffEducation(com.github.qinyou.example.model.ExStaffEducation) Date(java.util.Date) Before(com.jfinal.aop.Before)

Example 27 with Before

use of com.jfinal.aop.Before in project my_curd by qinyou.

the class ExSingleTableController method importExcel.

/**
 * 导入excel
 */
@Before(Tx.class)
public void importExcel() {
    UploadFile uploadFile = getFile();
    if (uploadFile == null) {
        renderFail("上传文件不可为空");
        return;
    }
    if (!FilenameUtils.getExtension(uploadFile.getFileName()).equals("xls")) {
        FileUtils.deleteFile(uploadFile.getFile());
        renderFail("上传文件后缀必须是xls");
        return;
    }
    List<ExSingleTable> list;
    try {
        ImportParams params = new ImportParams();
        params.setTitleRows(1);
        params.setHeadRows(1);
        list = ExcelImportUtil.importExcel(uploadFile.getFile(), ExSingleTable.class, params);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        FileUtils.deleteFile(uploadFile.getFile());
        renderFail("模板文件格式错误");
        return;
    }
    for (ExSingleTable exSingleTable : list) {
        System.out.println(exSingleTable);
        System.out.println();
        exSingleTable.setId(IdUtils.id()).setCreater(WebUtils.getSessionUsername(this)).setCreateTime(new Date()).save();
    }
    FileUtils.deleteFile(uploadFile.getFile());
    renderSuccess(IMPORT_SUCCESS);
}
Also used : UploadFile(com.jfinal.upload.UploadFile) ImportParams(cn.afterturn.easypoi.excel.entity.ImportParams) ExSingleTable(com.github.qinyou.example.model.ExSingleTable) Date(java.util.Date) Before(com.jfinal.aop.Before)

Example 28 with Before

use of com.jfinal.aop.Before in project my_curd by qinyou.

the class ExSingleTableController method exportExcel.

/**
 * 导出excel
 */
@Before(SearchSql.class)
public void exportExcel() {
    String where = getAttr(Constant.SEARCH_SQL);
    if (ExSingleTable.dao.findCountByWhere(where) > 50000) {
        setAttr("msg", "一次导出数据不可大于 5W 条,请修改查询条件。");
        render("common/card.ftl");
        return;
    }
    List<ExSingleTable> list = ExSingleTable.dao.findByWhere(where);
    Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("例子单表结构", "例子单表结构"), ExSingleTable.class, list);
    render(ExcelRender.me(workbook).fileName("例子单表结构.xls"));
}
Also used : ExportParams(cn.afterturn.easypoi.excel.entity.ExportParams) ExSingleTable(com.github.qinyou.example.model.ExSingleTable) Workbook(org.apache.poi.ss.usermodel.Workbook) Before(com.jfinal.aop.Before)

Example 29 with Before

use of com.jfinal.aop.Before in project my_curd by qinyou.

the class SysChangePasswordController method changePwdAction.

@Before(Tx.class)
public void changePwdAction() {
    SysUser curUser = getSessionUser();
    String oldPassword = getPara("oldPwd");
    String newPassword = getPara("newPwd");
    oldPassword = HashKit.sha1(oldPassword);
    SysUser sysUser = SysUser.dao.findByUsernameAndPassword(curUser.getUsername(), oldPassword);
    if (sysUser == null) {
        renderText("旧密码错误!");
        return;
    }
    if (sysUser.getDisabled().equals("1")) {
        renderText("用户被禁用,无法修改密码!");
        return;
    }
    newPassword = HashKit.sha1(newPassword);
    sysUser.setPassword(newPassword);
    boolean updateFlag = sysUser.update();
    // 添加操作日志
    addOpLog(oldPassword + " 修改为新密码:" + newPassword);
    if (updateFlag) {
        renderText("修改密码成功");
    } else {
        renderText("修改密码失败");
    }
}
Also used : SysUser(com.hxkj.system.model.SysUser) Before(com.jfinal.aop.Before)

Example 30 with Before

use of com.jfinal.aop.Before 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)

Aggregations

Before (com.jfinal.aop.Before)53 Date (java.util.Date)11 ActiveRecordException (com.jfinal.plugin.activerecord.ActiveRecordException)5 Record (com.jfinal.plugin.activerecord.Record)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 ToolString (com.hxkj.common.util.ToolString)4 ExportParams (cn.afterturn.easypoi.excel.entity.ExportParams)3 ExcelRdException (com.fruit.manage.util.excelRd.ExcelRdException)3 ActFormTpl (com.github.qinyou.process.model.ActFormTpl)3 SysOplog (com.hxkj.system.model.SysOplog)3 SysUser (com.hxkj.system.model.SysUser)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 RepositoryService (org.activiti.engine.RepositoryService)3 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)3 Model (org.activiti.engine.repository.Model)3 DateTime (org.joda.time.DateTime)3