parent
a3cb6feba6
commit
109c09876e
@ -0,0 +1,90 @@
|
||||
package ${basePackage}.action.ajax.system;
|
||||
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ${basePackage}.frame.excel.WSheet;
|
||||
import ${basePackage}.frame.utils.LogUtil;
|
||||
import ${basePackage}.frame.auth.LocalData;
|
||||
import ${basePackage}.frame.base.ErrorType;
|
||||
import ${basePackage}.frame.utils.MapperUtil;
|
||||
import ${basePackage}.frame.base.BaseResponse;
|
||||
import ${basePackage}.frame.utils.ResponseUtil;
|
||||
import ${basePackage}.frame.utils.ValidationUtil;
|
||||
import ${basePackage}.frame.excel.exception.ReadErrorException;
|
||||
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
|
||||
import ${basePackage}.module.system.ent.Resource;
|
||||
import ${basePackage}.module.system.mgr.ResourceManager;
|
||||
import ${basePackage}.module.system.req.*;
|
||||
import ${basePackage}.module.system.rsp.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class ResourceAjax{
|
||||
|
||||
@Autowired
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
public ResourceCreateResponse create(ResourceCreateRequest request) {
|
||||
return resourceManager.create(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceDeleteResponse delete(ResourceDeleteRequest request) {
|
||||
return resourceManager.delete(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceUpdateResponse update(ResourceUpdateRequest request) {
|
||||
return resourceManager.update(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceFindResponse find(ResourceFindRequest request) {
|
||||
return resourceManager.find(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceGetResponse get(ResourceGetRequest request) {
|
||||
return resourceManager.get(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public Object template(){
|
||||
return ResponseUtil.apply(new WSheet<>(Resource.class));
|
||||
}
|
||||
|
||||
public Object exports(TreeNode jsonParam) {
|
||||
ResourceFindRequest request = MapperUtil.toJava(jsonParam, ResourceFindRequest.class);
|
||||
ResourceFindResponse response = resourceManager.find(request, LocalData.getToken());
|
||||
if (response.hasError()) {
|
||||
return response;
|
||||
} else if (response.getTotalCount() == 0) {
|
||||
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
|
||||
return response;
|
||||
}
|
||||
return ResponseUtil.apply(new WSheet<>(response.getResult()));
|
||||
}
|
||||
|
||||
public Object imports(MultipartFile file) {
|
||||
BaseResponse baseResponse = new BaseResponse();
|
||||
try {
|
||||
WSheet<Resource> sheet = new WSheet<>(file.getBytes(), Resource.class, new WSheet.Validator<Resource>() {
|
||||
@Override
|
||||
public List<String> validate(Resource o) {
|
||||
ResourceCreateRequest request = MapperUtil.map(o, ResourceCreateRequest.class);
|
||||
return ValidationUtil.validate(request);
|
||||
}
|
||||
});
|
||||
|
||||
if (sheet.hasError()) {
|
||||
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
||||
} else {
|
||||
return baseResponse;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.dumpException(e);
|
||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
|
||||
} catch (TemplateNotMatchException | ReadErrorException e) {
|
||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
|
||||
}
|
||||
return baseResponse;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package ${basePackage}.action.ajax.system;
|
||||
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ${basePackage}.frame.excel.WSheet;
|
||||
import ${basePackage}.frame.utils.LogUtil;
|
||||
import ${basePackage}.frame.auth.LocalData;
|
||||
import ${basePackage}.frame.base.ErrorType;
|
||||
import ${basePackage}.frame.utils.MapperUtil;
|
||||
import ${basePackage}.frame.base.BaseResponse;
|
||||
import ${basePackage}.frame.utils.ResponseUtil;
|
||||
import ${basePackage}.frame.utils.ValidationUtil;
|
||||
import ${basePackage}.frame.excel.exception.ReadErrorException;
|
||||
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
|
||||
import ${basePackage}.module.system.ent.Tokens;
|
||||
import ${basePackage}.module.system.mgr.TokensManager;
|
||||
import ${basePackage}.module.system.req.*;
|
||||
import ${basePackage}.module.system.rsp.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class TokensAjax{
|
||||
|
||||
@Autowired
|
||||
private TokensManager tokensManager;
|
||||
|
||||
public TokensCreateResponse create(TokensCreateRequest request) {
|
||||
return tokensManager.create(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensDeleteResponse delete(TokensDeleteRequest request) {
|
||||
return tokensManager.delete(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensUpdateResponse update(TokensUpdateRequest request) {
|
||||
return tokensManager.update(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensFindResponse find(TokensFindRequest request) {
|
||||
return tokensManager.find(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensGetResponse get(TokensGetRequest request) {
|
||||
return tokensManager.get(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public Object template(){
|
||||
return ResponseUtil.apply(new WSheet<>(Tokens.class));
|
||||
}
|
||||
|
||||
public Object exports(TreeNode jsonParam) {
|
||||
TokensFindRequest request = MapperUtil.toJava(jsonParam, TokensFindRequest.class);
|
||||
TokensFindResponse response = tokensManager.find(request, LocalData.getToken());
|
||||
if (response.hasError()) {
|
||||
return response;
|
||||
} else if (response.getTotalCount() == 0) {
|
||||
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
|
||||
return response;
|
||||
}
|
||||
return ResponseUtil.apply(new WSheet<>(response.getResult()));
|
||||
}
|
||||
|
||||
public Object imports(MultipartFile file) {
|
||||
BaseResponse baseResponse = new BaseResponse();
|
||||
try {
|
||||
WSheet<Tokens> sheet = new WSheet<>(file.getBytes(), Tokens.class, new WSheet.Validator<Tokens>() {
|
||||
@Override
|
||||
public List<String> validate(Tokens o) {
|
||||
TokensCreateRequest request = MapperUtil.map(o, TokensCreateRequest.class);
|
||||
return ValidationUtil.validate(request);
|
||||
}
|
||||
});
|
||||
|
||||
if (sheet.hasError()) {
|
||||
return ResponseUtil.apply(sheet.getBytes(), sheet.getName() + "-检查.xlsx");
|
||||
} else {
|
||||
return baseResponse;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.dumpException(e);
|
||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
|
||||
} catch (TemplateNotMatchException | ReadErrorException e) {
|
||||
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
|
||||
}
|
||||
return baseResponse;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package ${basePackage}.action.api.system;
|
||||
|
||||
import ${basePackage}.frame.auth.LocalData;
|
||||
import ${basePackage}.module.system.mgr.ResourceManager;
|
||||
import ${basePackage}.module.system.req.*;
|
||||
import ${basePackage}.module.system.rsp.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class ResourceApi{
|
||||
|
||||
@Autowired
|
||||
private ResourceManager resourceManager;
|
||||
|
||||
public ResourceCreateResponse create(ResourceCreateRequest request) {
|
||||
return resourceManager.create(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceDeleteResponse delete(ResourceDeleteRequest request) {
|
||||
return resourceManager.delete(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceUpdateResponse update(ResourceUpdateRequest request) {
|
||||
return resourceManager.update(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceFindResponse find(ResourceFindRequest request) {
|
||||
return resourceManager.find(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public ResourceGetResponse get(ResourceGetRequest request) {
|
||||
return resourceManager.get(request, LocalData.getToken());
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package ${basePackage}.action.api.system;
|
||||
|
||||
import ${basePackage}.frame.auth.LocalData;
|
||||
import ${basePackage}.module.system.mgr.TokensManager;
|
||||
import ${basePackage}.module.system.req.*;
|
||||
import ${basePackage}.module.system.rsp.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class TokensApi{
|
||||
|
||||
@Autowired
|
||||
private TokensManager tokensManager;
|
||||
|
||||
public TokensCreateResponse create(TokensCreateRequest request) {
|
||||
return tokensManager.create(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensDeleteResponse delete(TokensDeleteRequest request) {
|
||||
return tokensManager.delete(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensUpdateResponse update(TokensUpdateRequest request) {
|
||||
return tokensManager.update(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensFindResponse find(TokensFindRequest request) {
|
||||
return tokensManager.find(request, LocalData.getToken());
|
||||
}
|
||||
|
||||
public TokensGetResponse get(TokensGetRequest request) {
|
||||
return tokensManager.get(request, LocalData.getToken());
|
||||
}
|
||||
}
|
Loading…
Reference in new issue