Search in sources :

Example 1 with ActFormTpl

use of com.github.qinyou.process.model.ActFormTpl in project my_curd by qinyou.

the class ActFormTplController method viewModel.

/**
 * 预览
 */
@Before(IdRequired.class)
public void viewModel() {
    String id = get("id");
    ActFormTpl formTpl = ActFormTpl.dao.findById(id);
    setAttr("tplRemark", formTpl.getRemark());
    setAttr("plugins", formTpl.getPlugins());
    setAttr("template", formTpl.getTemplate());
    render("process/actFormTpl_preview.ftl");
}
Also used : ActFormTpl(com.github.qinyou.process.model.ActFormTpl) Before(com.jfinal.aop.Before)

Example 2 with ActFormTpl

use of com.github.qinyou.process.model.ActFormTpl in project my_curd by qinyou.

the class ActFormTplController method addAction.

/**
 * 新增 action
 */
public void addAction() {
    UploadFile file = getFile();
    if (file == null) {
        renderFail("模板文件不可为空");
        return;
    }
    String extension = FilenameUtils.getExtension(file.getFileName());
    if (!"html".equalsIgnoreCase(extension)) {
        renderFail("模板文件必须是html文件");
        return;
    }
    String template = null;
    try {
        template = FileUtils.readFileToString(file.getFile(), "utf-8");
        FileUtils.deleteFile(file.getFile());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        renderFile("模板文件读取失败");
        return;
    }
    ActFormTpl actFormTpl = getBean(ActFormTpl.class, "");
    actFormTpl.setTemplate(template);
    ActFormTpl latestVersion = ActFormTpl.dao.findLatestByKey(actFormTpl.getFormKey());
    int version = 1;
    if (latestVersion != null) {
        version = latestVersion.getFormVersion() + 1;
    }
    actFormTpl.setId(actFormTpl.getFormKey() + ":" + version).setFormVersion(version).setCreater(WebUtils.getSessionUsername(this)).setCreateTime(new Date());
    if (actFormTpl.save()) {
        renderSuccess(ADD_SUCCESS);
    } else {
        renderFail(ADD_FAIL);
    }
}
Also used : UploadFile(com.jfinal.upload.UploadFile) ActFormTpl(com.github.qinyou.process.model.ActFormTpl) IOException(java.io.IOException) Date(java.util.Date)

Example 3 with ActFormTpl

use of com.github.qinyou.process.model.ActFormTpl in project my_curd by qinyou.

the class ActFormTplController method downloadHtml.

// 模板文件下载
@Before(IdRequired.class)
public void downloadHtml() {
    String id = get("id");
    ActFormTpl formTpl = ActFormTpl.dao.findById(id);
    if (formTpl == null) {
        renderFail("id 参数错误");
        return;
    }
    render(StringAsFileRender.me(formTpl.getTemplate()).fileName(formTpl.getFormKey() + "-v" + formTpl.getFormVersion() + ".html"));
}
Also used : ActFormTpl(com.github.qinyou.process.model.ActFormTpl) Before(com.jfinal.aop.Before)

Example 4 with ActFormTpl

use of com.github.qinyou.process.model.ActFormTpl in project my_curd by qinyou.

the class ActFormTplController method updateAction.

/**
 * 修改 action
 */
public void updateAction() {
    UploadFile file = getFile();
    String template = null;
    if (file != null) {
        String extension = FilenameUtils.getExtension(file.getFileName());
        if (!"html".equalsIgnoreCase(extension)) {
            renderFail("模板文件必须是html文件");
            return;
        }
        try {
            template = FileUtils.readFileToString(file.getFile(), "utf-8");
            FileUtils.deleteFile(file.getFile());
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            renderFile("模板文件读取失败");
            return;
        }
    }
    ActFormTpl actFormTpl = ActFormTpl.dao.findById(get("id"));
    if (actFormTpl == null) {
        renderFile("ID参数错误");
        return;
    }
    // formKey,formVersion 不可更新
    if (template != null) {
        actFormTpl.setTemplate(template);
    }
    actFormTpl.setState(get("state")).setRemark(get("remark")).setPlugins(get("plugins")).setUpdater(WebUtils.getSessionUsername(this)).setUpdateTime(new Date());
    if (actFormTpl.update()) {
        renderSuccess(UPDATE_SUCCESS);
    } else {
        renderFail(UPDATE_FAIL);
    }
}
Also used : UploadFile(com.jfinal.upload.UploadFile) ActFormTpl(com.github.qinyou.process.model.ActFormTpl) IOException(java.io.IOException) Date(java.util.Date)

Example 5 with ActFormTpl

use of com.github.qinyou.process.model.ActFormTpl in project my_curd by qinyou.

the class MyApplyController method newApply.

// 新建流程 表单页面
public void newApply() {
    // 流程定义key
    String processKey = get("processKey");
    if (StringUtils.isEmpty(processKey)) {
        renderFail("参数缺失");
        return;
    }
    set("test", get("test"));
    ProcessDefinition processDefinition = ActivitiUtils.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey(processKey).latestVersion().singleResult();
    if (processDefinition == null) {
        log.info("processDefinitionKey:{} latestVersion 不存在", processKey);
        renderFail("参数错误");
        return;
    }
    String startFormKey = ActivitiUtils.getFormService().getStartFormKey(processDefinition.getId());
    if (StringUtils.notEmpty(startFormKey)) {
        ActFormTpl formTpl = ActFormTpl.dao.findLatestActiveByKey(startFormKey);
        if (formTpl == null) {
            log.info("act_form_tpl fKey:{} latestVersion 不存在", startFormKey);
            renderFail("参数错误");
            return;
        }
        // 申请表单模板id
        setAttr("applyFormTplId", formTpl.getId());
        // 申请表单模板
        setAttr("applyFormTpl", formTpl.getTemplate());
        // 申请表单所引用的插件
        setAttr("applyFormTplPlugins", formTpl.getPlugins());
    }
    // 流程定义key
    setAttr("processKey", processKey);
    // 预设的申请名称 (流程定义名+申请人+日期)
    setAttr("applyFormTitle", processDefinition.getName() + "-" + WebUtils.getSysUser(this).getRealName() + "-" + new DateTime().toString("yyyy/MM/dd"));
    render("process/myApply_form.ftl");
}
Also used : ActFormTpl(com.github.qinyou.process.model.ActFormTpl) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) DateTime(org.joda.time.DateTime)

Aggregations

ActFormTpl (com.github.qinyou.process.model.ActFormTpl)9 Before (com.jfinal.aop.Before)3 UploadFile (com.jfinal.upload.UploadFile)2 IOException (java.io.IOException)2 Date (java.util.Date)2 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Task (org.activiti.engine.task.Task)1 DateTime (org.joda.time.DateTime)1