浏览代码

一大波优化

周浩 8 年之前
父节点
当前提交
108b66200c

+ 4 - 0
hsweb-web-controller/pom.xml

@@ -41,5 +41,9 @@
             <artifactId>commons-fileupload</artifactId>
             <version>${commons.fileupload.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.hsweb</groupId>
+            <artifactId>hsweb-expands-compress</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 19 - 0
hsweb-web-controller/src/main/java/org/hsweb/web/controller/file/FileController.java

@@ -1,6 +1,10 @@
 package org.hsweb.web.controller.file;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import org.hsweb.commons.StringUtils;
+import org.hsweb.expands.compress.Compress;
+import org.hsweb.expands.compress.zip.ZIPWriter;
 import org.hsweb.web.bean.po.resource.Resources;
 import org.hsweb.web.core.authorize.annotation.Authorize;
 import org.hsweb.web.core.exception.NotFoundException;
@@ -64,6 +68,21 @@ public class FileController {
         mediaTypeMapper.put(".xml", MediaType.TEXT_XML_VALUE);
     }
 
+    /**
+     * 构建zip
+     */
+    @RequestMapping(value = "/download-zip/{name:.+}", method = {RequestMethod.POST})
+    public void downloadZip(@PathVariable("name") String name,
+                            @RequestParam("data") String dataStr,
+                            HttpServletResponse response) throws Exception {
+        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(name, "utf-8"));
+        ZIPWriter writer = Compress.zip();
+        List<Map<String, String>> data = (List) JSON.parseArray(dataStr, Map.class);
+        data.forEach(map -> writer.addTextFile(map.get("name"), map.get("text")));
+        writer.write(response.getOutputStream());
+    }
+
     /**
      * 下载文本
      */

+ 26 - 5
hsweb-web-controller/src/main/java/org/hsweb/web/controller/form/DynamicFormController.java

@@ -1,3 +1,19 @@
+/*
+ * Copyright 2015-2016 https://github.com/hs-web
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.hsweb.web.controller.form;
 
 import org.hsweb.web.bean.common.QueryParam;
@@ -5,6 +21,7 @@ import org.hsweb.web.bean.common.UpdateMapParam;
 import org.hsweb.web.bean.po.form.Form;
 import org.hsweb.web.core.authorize.annotation.Authorize;
 import org.hsweb.web.core.exception.BusinessException;
+import org.hsweb.web.core.exception.NotFoundException;
 import org.hsweb.web.core.logger.annotation.AccessLogger;
 import org.hsweb.web.core.message.ResponseMessage;
 import org.hsweb.web.service.form.DynamicFormService;
@@ -20,7 +37,9 @@ import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Created by zhouhao on 16-4-23.
+ * 动态表单管理控制器,用于操作动态表单以及对表单数据的增删改查和excel导入导出
+ *
+ * @author zhouhao
  */
 @RestController
 @RequestMapping(value = "/dyn-form")
@@ -38,16 +57,18 @@ public class DynamicFormController {
 
     @RequestMapping(value = "/deployed/{name}", method = RequestMethod.GET)
     @Authorize(expression = "#dynamicFormAuthorizeValidator.validate(#name,#user,#paramsMap,'R')")
-    public ResponseMessage deployed(@PathVariable("name") String name) throws Exception {
+    @AccessLogger("发布表单")
+    public ResponseMessage deployed(@PathVariable("name") String name) {
         return ResponseMessage.ok(formService.selectDeployed(name));
     }
 
     @RequestMapping(value = "/{name}/v/{version}", method = RequestMethod.GET)
     @Authorize(expression = "#dynamicFormAuthorizeValidator.validate(#name,#user,#paramsMap,'R')")
-    public ResponseMessage latest(@PathVariable(value = "name") String name,
-                                  @PathVariable(value = "version") Integer version) throws Exception {
+    @AccessLogger("根据版本获取表单")
+    public ResponseMessage selectByVersion(@PathVariable(value = "name") String name,
+                                           @PathVariable(value = "version") Integer version) {
         Form form = formService.selectByVersion(name, version);
-        if (form == null) throw new BusinessException("表单不存在", 404);
+        if (form == null) throw new NotFoundException("表单不存在");
         return ResponseMessage.ok(form);
     }
 

+ 3 - 2
hsweb-web-core/src/main/java/org/hsweb/web/core/session/siample/SimpleHttpSessionManager.java

@@ -10,6 +10,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import java.util.stream.Collectors;
 
 /**
@@ -20,12 +21,12 @@ public class SimpleHttpSessionManager extends AbstractHttpSessionManager {
     /**
      * httpSession存储器,sessionId:HttpSession
      */
-    private static final Map<String, HttpSession> sessionStorage = new ConcurrentHashMap<>();
+    private static final ConcurrentMap<String, HttpSession> sessionStorage = new ConcurrentHashMap<>();
 
     /**
      * 用户ID与session管理存储器,userId:HttpSession
      */
-    private static final Map<String, HttpSession> userSessionStorage = new ConcurrentHashMap<>();
+    private static final ConcurrentMap<String, HttpSession> userSessionStorage = new ConcurrentHashMap<>();
 
     @Override
     public Set<User> tryGetAllUser() {

+ 1 - 1
hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/mysql/user/UserMapper.xml

@@ -33,7 +33,7 @@
         <include refid="BasicMapper.buildDeleteSql"/>
     </delete>
 
-    <update id="updatePassword" parameterType="User">
+    <update id="updatePassword" parameterType="org.hsweb.web.bean.po.user.User">
         update s_user set password=#{password,jdbcType=VARCHAR} where u_id = #{id}
     </update>
 

+ 1 - 1
hsweb-web-dao-impl-mybatis/src/main/resources/org/hsweb/web/dao/impl/mybatis/mapper/oracle/user/UserMapper.xml

@@ -33,7 +33,7 @@
         <include refid="BasicMapper.buildDeleteSql"/>
     </delete>
 
-    <update id="updatePassword" parameterType="User">
+    <update id="updatePassword" parameterType="org.hsweb.web.bean.po.user.User">
         update s_user set password=#{password,jdbcType=VARCHAR} where u_id = #{id}
     </update>
 

+ 15 - 0
hsweb-web-service-impl-common/src/main/java/org/hsweb/web/service/impl/profile/UserProfileServiceImpl.java

@@ -1,5 +1,7 @@
 package org.hsweb.web.service.impl.profile;
 
+import org.hsweb.commons.MD5;
+import org.hsweb.web.bean.common.UpdateParam;
 import org.hsweb.web.bean.po.profile.UserProfile;
 import org.hsweb.web.dao.profile.UserProfileMapper;
 import org.hsweb.web.service.impl.AbstractServiceImpl;
@@ -22,5 +24,18 @@ public class UserProfileServiceImpl extends AbstractServiceImpl<UserProfile, Str
         return userProfileMapper;
     }
 
+    @Override
+    public int saveOrUpdate(UserProfile userProfile) {
+        UserProfile old = selectByUserIdAndType(userProfile.getUserId(), userProfile.getType());
+        if (null != old) {
+            return getMapper().update(UpdateParam.build(userProfile)
+                    .includes("content")
+                    .where("userId", userProfile.getUserId())
+                    .and("type", userProfile.getType()));
+        } else {
+            insert(userProfile);
+        }
+        return 1;
+    }
 
 }

+ 20 - 0
pom.xml

@@ -127,6 +127,26 @@
                 <artifactId>hsweb-expands-office</artifactId>
                 <version>${hsweb.expands.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.hsweb</groupId>
+                <artifactId>hsweb-expands-request</artifactId>
+                <version>${hsweb.expands.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.hsweb</groupId>
+                <artifactId>hsweb-expands-shell</artifactId>
+                <version>${hsweb.expands.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.hsweb</groupId>
+                <artifactId>hsweb-expands-compress</artifactId>
+                <version>${hsweb.expands.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.hsweb</groupId>
+                <artifactId>hsweb-expands-template</artifactId>
+                <version>${hsweb.expands.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.hsweb</groupId>
                 <artifactId>hsweb-easy-orm</artifactId>