一大波优化

This commit is contained in:
周浩
2016-07-07 18:31:25 +08:00
parent f3b3fceba3
commit 108b66200c
8 changed files with 89 additions and 9 deletions

View File

@@ -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());
}
/**
* 下载文本
*/

View File

@@ -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);
}