一大波优化,完善部分注释

This commit is contained in:
zhouhao
2016-08-11 16:48:52 +08:00
parent fca8ac38e8
commit 409dca4e70
55 changed files with 1154 additions and 671 deletions

View File

@@ -2,6 +2,7 @@ package org.hsweb.web.controller;
import org.hsweb.web.core.exception.BusinessException;
import org.hsweb.web.core.message.ResponseMessage;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;

View File

@@ -9,5 +9,4 @@ import java.util.Map;
*/
public interface DynamicFormAuthorizeValidator {
boolean validate(String formName, User user,Map<String,Object> params, String... actions);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,10 @@
package org.hsweb.web.controller;
import com.alibaba.fastjson.JSON;
import org.hsweb.web.core.authorize.annotation.Authorize;
import org.hsweb.commons.ClassUtils;
import org.hsweb.web.bean.common.QueryParam;
import org.hsweb.web.bean.po.GenericPo;
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;
@@ -29,11 +30,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.hsweb.commons.ClassUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 通用控制器,此控制器实现了通用的增删改查功能
@@ -134,7 +132,7 @@ public abstract class GenericController<PO, PK> {
@AccessLogger("新增")
@Authorize(action = "C")
@ResponseStatus(HttpStatus.CREATED)
public ResponseMessage add(@RequestBody(required = true) PO object) {
public ResponseMessage add(@RequestBody PO object) {
PK pk = getService().insert(object);
return ResponseMessage.created(pk);
}
@@ -167,7 +165,7 @@ public abstract class GenericController<PO, PK> {
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
@AccessLogger("修改")
@Authorize(action = "U")
public ResponseMessage update(@PathVariable("id") PK id, @RequestBody(required = true) PO object) {
public ResponseMessage update(@PathVariable("id") PK id, @RequestBody PO object) {
PO old = getService().selectByPk(id);
assertFound(old, "data is not found!");
if (object instanceof GenericPo) {
@@ -187,7 +185,7 @@ public abstract class GenericController<PO, PK> {
@RequestMapping(method = RequestMethod.PUT)
@AccessLogger("批量修改")
@Authorize(action = "U")
public ResponseMessage update(@RequestBody(required = true) String json) {
public ResponseMessage update(@RequestBody String json) {
int number;
if (json.startsWith("[")) {
number = getService().update(JSON.parseArray(json, getPOType()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web/
* Copyright 2015-2016 http://hsweb.me/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
package org.hsweb.web.controller.form;
import org.hsweb.ezorm.meta.FieldMetaData;
import org.hsweb.ezorm.meta.TableMetaData;
import org.hsweb.ezorm.meta.expand.OptionConverter;
import org.hsweb.web.bean.common.QueryParam;
import org.hsweb.web.bean.common.UpdateMapParam;
import org.hsweb.web.bean.po.form.Form;
@@ -28,6 +31,7 @@ import org.hsweb.web.core.message.ResponseMessage;
import org.hsweb.web.service.form.DynamicFormService;
import org.hsweb.web.service.form.FormService;
import org.hsweb.web.service.resource.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -125,6 +129,24 @@ public class DynamicFormController {
.onlyData();
}
/**
* 根据表单名称和查询参数,查询表单的数据数量
*
* @param name 表单名称
* @param param 查询参数{@link QueryParam}
* @return 查询结果
* @throws SQLException 执行查询sql错误
* @throws NotFoundException 表单不存在或在未发布
*/
@RequestMapping(value = "/{name}/total", method = RequestMethod.GET)
@AccessLogger("查看数据数量")
@Authorize(expression = "#dynamicFormAuthorizeValidator.validate(#name,#user,#paramsMap,'R')")
public ResponseMessage total(@PathVariable("name") String name,
QueryParam param) throws SQLException {
return ResponseMessage.ok(dynamicFormService.total(name, param));
}
/**
* 根据表单名和主键值查询数据
*
@@ -251,4 +273,40 @@ public class DynamicFormController {
return ResponseMessage.ok(result);
}
/**
* 数据字典映射:将指定的数据映射为数据字典对应的数据。<br>
* 如: 表单{name}的字段{field}的字典配置为 [{"男":"1"},{"女":"0"}];<br>
* 传入参数type=1,data=男,得到结果 {data:"1"}。传入参数 type!=1,data=1.得到结果{data:"男"}
*
* @param name 表单名称
* @param field 字段
* @param data 要映射的数据
* @param type 映射的类型 1或其他值当为1时将key映射为value其他则将value映射为key。
* @return 映射结果
* @throws NotFoundException 表单或字段不存在
*/
@RequestMapping(value = "/{name}/{field}/{type}/{data:.+}")
@AccessLogger("数据字典映射")
@Authorize
public ResponseMessage mapperOption(@PathVariable("name") String name,
@PathVariable("field") String field,
@PathVariable("data") String data,
@PathVariable("type") String type) {
try {
TableMetaData metaData = dynamicFormService.getDefaultDatabase().getTable(name).getMeta();
FieldMetaData fieldMetaData = metaData.findFieldByName(field);
if (fieldMetaData == null) throw new NullPointerException();
OptionConverter converter = fieldMetaData.getOptionConverter();
if (converter == null) return ResponseMessage.ok(data);
switch (type) {
case "1":
return ResponseMessage.ok(converter.converterData(data));
default:
return ResponseMessage.ok(converter.converterValue(data));
}
} catch (NullPointerException e) {
throw new NotFoundException("字段不存在");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,8 +110,7 @@ public class AuthorizeController {
@Authorize
public ResponseMessage onlineInfo() {
return ResponseMessage.ok(httpSessionManager.tryGetAllUser())
.include(User.class, "id", "username", "name", "phone", "email")
.exclude(User.class, "password");
.include(User.class, "id", "username", "name", "phone", "email");
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 https://github.com/hs-web
* Copyright 2015-2016 http://hsweb.me
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -34,7 +34,6 @@ public class UserController extends GenericController<User, String> {
}
@Override
@AccessLogger("获取列表")
public ResponseMessage list(QueryParam param) {
param.excludes("password");
return super.list(param)
@@ -43,7 +42,6 @@ public class UserController extends GenericController<User, String> {
}
@Override
@AccessLogger("获取用户详情")
public ResponseMessage info(@PathVariable("id") String id) {
return super.info(id).exclude(User.class, "password", "modules");
}
@@ -57,8 +55,8 @@ public class UserController extends GenericController<User, String> {
}
@AccessLogger("启用")
@Authorize(action = "enable")
@RequestMapping(value = "/{id}/enable", method = RequestMethod.PUT)
@Authorize(action = "enable")
public ResponseMessage enable(@PathVariable("id") String id) {
getService().enableUser(id);
return ResponseMessage.ok();

View File

@@ -1,3 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.hsweb.web.controller.ControllerAutoConfiguration