Forráskód Böngészése

完善表单管理

周浩 9 éve
szülő
commit
e432ee38a9

+ 7 - 3
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/FromDeployContextLoaderListener.java

@@ -3,22 +3,26 @@ package org.hsweb.web.service.impl;
 import org.hsweb.web.bean.common.QueryParam;
 import org.hsweb.web.service.form.DynamicFormService;
 import org.hsweb.web.service.form.FormService;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ApplicationListener;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 
 @Component
-public class FromDeployContextLoaderListener implements ApplicationListener {
-
+public class FromDeployContextLoaderListener implements ApplicationListener<ContextRefreshedEvent> {
     @Resource
     private FormService formService;
     @Resource
     private DynamicFormService dynamicFormService;
 
     @Override
-    public void onApplicationEvent(ApplicationEvent event) {
+    public void onApplicationEvent(ContextRefreshedEvent event) {
+        if (event.getApplicationContext().getParent() != null) return;
         QueryParam param = new QueryParam();
         param.where("using", 1);
         try {

+ 21 - 1
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/form/FormServiceImpl.java

@@ -138,6 +138,8 @@ public class FormServiceImpl extends AbstractServiceImpl<Form, String> implement
     @Caching(evict = {
             @CacheEvict(value = {CACHE_KEY + ".deploy"},
                     key = "'form.deploy.'+target.selectByPk(#formId).getName()+'.html'"),
+            @CacheEvict(value = {CACHE_KEY + ".deploy"},
+                    key = "'form.deploy.'+target.selectByPk(#formId).getName()"),
             @CacheEvict(value = {CACHE_KEY},
                     key = "'form.using.'+target.selectByPk(#formId).getName()")
     })
@@ -165,6 +167,14 @@ public class FormServiceImpl extends AbstractServiceImpl<Form, String> implement
 
     @Override
     @Transactional(rollbackFor = Throwable.class)
+    @Caching(evict = {
+            @CacheEvict(value = {CACHE_KEY + ".deploy"},
+                    key = "'form.deploy.'+target.selectByPk(#formId).getName()+'.html'"),
+            @CacheEvict(value = {CACHE_KEY + ".deploy"},
+                    key = "'form.deploy.'+target.selectByPk(#formId).getName()"),
+            @CacheEvict(value = {CACHE_KEY},
+                    key = "'form.using.'+target.selectByPk(#formId).getName()")
+    })
     public void unDeploy(String formId) throws Exception {
         Form old = this.selectByPk(formId);
         Assert.notNull(old, "表单不存在");
@@ -183,10 +193,20 @@ public class FormServiceImpl extends AbstractServiceImpl<Form, String> implement
         return formParser.parseHtml(JSON.parseObject(history.getChangeAfter(), Form.class));
     }
 
+    @Override
+    @Cacheable(value = CACHE_KEY + ".deploy", key = "'form.deploy.'+#name")
+    public Form selectDeployed(String name) throws Exception {
+        Form using = selectUsing(name);
+        assertNotNull(using, "表单不存在或未部署");
+        History history = historyService.selectLastHistoryByType("form.deploy." + name);
+        assertNotNull(history, "表单不存在或未部署");
+        return JSON.parseObject(history.getChangeAfter(), Form.class);
+    }
+
     @Override
     public String createViewHtml(String formId) throws Exception {
         Form form = this.selectByPk(formId);
-        Assert.notNull(form, "表单不存在");
+        assertNotNull(form, "表单不存在");
         return formParser.parseHtml(form);
     }
 

+ 3 - 0
hsweb-web-service-interface/src/main/java/org/hsweb/web/service/form/FormService.java

@@ -70,6 +70,8 @@ public interface FormService extends GenericService<Form, String> {
      */
     String createDeployHtml(String name) throws Exception;
 
+    Form selectDeployed(String name) throws Exception;
+
     /**
      * 根据表单名称,获取最新版本的表单
      *
@@ -100,6 +102,7 @@ public interface FormService extends GenericService<Form, String> {
 
     /**
      * 查询当前正在使用的表单
+     *
      * @param name 正在使用的表单名称
      * @return 表单对象。没有则返回null
      * @throws Exception