package ${controllerPackage};
|
|
import java.util.Collection;
|
import java.util.Map;
|
import java.util.List;
|
import com.vci.starter.web.exception.VciBaseException;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import com.vci.starter.web.pagemodel.*;
|
import com.vci.starter.web.annotation.*;
|
import ${voPackage}.${className}VO;
|
import ${dtoPackage}.${className}DTO;
|
import ${servicePackage}.${className}ServiceI;
|
import org.springframework.stereotype.Controller;
|
import com.vci.starter.web.util.*;
|
#if(${hasExcel})
|
import javax.servlet.http.HttpServletResponse;
|
import org.springframework.web.multipart.MultipartFile;
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import org.apache.commons.io.IOUtils;
|
#end
|
|
|
/**
|
* ${comments}控制器
|
*
|
* @author ${author}
|
* @date ${datetime}
|
*/
|
@RestController
|
@RequestMapping("${controllerRequestMap}")
|
#if(${hasPermisssion})
|
@VciPermission(modelKey = "${classNameFristLowwer}")
|
#end
|
public class ${className}Controller {
|
/**
|
* ${comments} 服务
|
*/
|
@Autowired
|
private ${className}ServiceI ${classNameFristLowwer}Service;
|
|
#if(!${hasParentField})
|
/**
|
* ${comments}列表
|
* @param baseQueryObject 基础查询对象,包含查询条件,分页,排序等
|
* @return ${comments}显示对象列表
|
*/
|
@GetMapping("/grid${className}")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"VIEW","QUERY","ADVQUERY"},methodAlias = {"查看","查询","高级查询"},modelKey = {1,2,3})
|
#end
|
public DataGrid<${className}VO> grid${className}(BaseQueryObject baseQueryObject){
|
if(baseQueryObject == null){
|
baseQueryObject = new BaseQueryObject();
|
}
|
return ${classNameFristLowwer}Service.grid${className}(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
|
}
|
#else
|
/**
|
* ${comments}树
|
* @param treeQueryObject 树形查询对象
|
* @return ${comments}显示树
|
*/
|
@GetMapping("/tree${className}")
|
public List<Tree> tree${className}(TreeQueryObject treeQueryObject) {
|
return ${classNameFristLowwer}Service.tree${className}(treeQueryObject);
|
}
|
|
#end
|
/**
|
* 增加 ${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象
|
* @return 执行结果,success为true表示成功,msg是失败的提示信息,obj是添加完成后的显示对象
|
*/
|
@PostMapping( "/addSave")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"ADD"},methodAlias = {"添加"},modelKey = {4})
|
#end
|
public BaseResult<${className}VO> addSave(@RequestBody ${className}DTO ${classNameFristLowwer}DTO){
|
${className}VO ${classNameFristLowwer}VO = ${classNameFristLowwer}Service.addSave(${classNameFristLowwer}DTO);
|
return BaseResult.success(${classNameFristLowwer}VO);
|
}
|
|
/**
|
* 修改 ${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象
|
* @return 执行结果,success为true表示成功,msg是失败的提示信息,obj是添加完成后的显示对象
|
*/
|
@PutMapping("/editSave")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"EDIT"},methodAlias = {"修改"},modelKey = {5})
|
#end
|
public BaseResult<${className}VO> editSave(@RequestBody ${className}DTO ${classNameFristLowwer}DTO){
|
${className}VO ${classNameFristLowwer}VO = ${classNameFristLowwer}Service.editSave(${classNameFristLowwer}DTO);
|
return BaseResult.success(${classNameFristLowwer}VO);
|
}
|
|
#if(${hasParentField})
|
/**
|
* 检查 ${comments}是否删除
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,必须要有oid和ts属性
|
* @return 执行结果 success为true为可以删除,false表示有数据引用,obj为true表示有下级
|
*/
|
@PostMapping( "/checkIsCanDelete")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"DELETE"},methodAlias = {"删除"},modelKey = {6})
|
#end
|
public BaseResult checkIsCanDelete( ${className}DTO ${classNameFristLowwer}DTO) {
|
return ${classNameFristLowwer}Service.checkIsCanDelete(${classNameFristLowwer}DTO);
|
}
|
#end
|
|
/**
|
* 删除${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
|
* @return 删除结果反馈::success:成功,fail:失败
|
*/
|
@DeleteMapping( "/deleteData")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"DELETE"},methodAlias = {"删除"},modelKey = {6})
|
#end
|
public BaseResult del${className}( ${className}DTO ${classNameFristLowwer}DTO) {
|
return ${classNameFristLowwer}Service.delete${className}(${classNameFristLowwer}DTO);
|
}
|
|
/**
|
* 主键获取${comments}
|
* @param oid 主键
|
* @return ${comments}显示对象
|
*/
|
@GetMapping("/getObjectByOid")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"VIEW"},methodAlias = {"查看"},modelKey = {1})
|
#end
|
public BaseResult<${className}VO> getObjectByOid(String oid){
|
${className}VO ${classNameFristLowwer}VO = ${classNameFristLowwer}Service.getObjectByOid(oid);
|
return BaseResult.success(${classNameFristLowwer}VO);
|
}
|
|
/**
|
* 主键批量获取${comments}
|
* @param oids 主键,多个以逗号分隔,但是受性能影响,建议一次查询不超过10000个
|
* @return ${comments}显示对象
|
*/
|
@GetMapping("/listDataByOids")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"VIEW"},methodAlias = {"查看"},modelKey = {1})
|
#end
|
public BaseResult<${className}VO> list${className}ByOids(String oids){
|
Collection<${className}VO> voCollection = ${classNameFristLowwer}Service.list${className}ByOids(VciBaseUtil.str2List(oids));
|
BaseResult baseResult = BaseResult.success();
|
baseResult.setData(voCollection);
|
return baseResult;
|
}
|
|
#if(${hasEnable})
|
/**
|
* 启用${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
|
#if(${hasParentField})
|
* @param cascade 级联启用
|
#end
|
* @return 启用结果反馈::success:成功,fail:失败
|
*/
|
@PostMapping( "/enableData")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"ENABLE"},methodAlias = {"启用"},modelKey = {7})
|
#end
|
public BaseResult enable${className}( ${className}DTO ${classNameFristLowwer}DTO#if(${hasParentField}),boolean cascade #end) {
|
return ${classNameFristLowwer}Service.enable${className}(${classNameFristLowwer}DTO#if(${hasParentField}), cascade #end);
|
}
|
|
/**
|
* 停用${comments}
|
* @param ${classNameFristLowwer}DTO ${comments}数据传输对象,oid和ts需要传输
|
#if(${hasParentField})
|
* @param cascade 级联停用
|
#end
|
* @return 停用结果反馈::success:成功,fail:失败
|
*/
|
@PostMapping(value = "/disableData")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"DISABLE"},methodAlias = {"停用"},modelKey = {8})
|
#end
|
public BaseResult disable${className}( ${className}DTO ${classNameFristLowwer}DTO#if(${hasParentField}),boolean cascade #end) {
|
return ${classNameFristLowwer}Service.disable${className}(${classNameFristLowwer}DTO#if(${hasParentField}), cascade #end);
|
}
|
#end
|
|
#if(${hasExcel})
|
|
/**
|
* 导出的excel文件的名称
|
*/
|
public static final String EXPORT_TEMPLATE_SHOW_NAME = "${comments}.xls";
|
|
/**
|
* excel模板的文件
|
*/
|
public static final String EXPORT_TEMPLATE_FILE_NAME = "excelTemplate/${className}.xls";
|
|
/**
|
* 下载导入模板
|
* @param response 响应对象
|
* @param downloadUUID 下载需求,可以不传递
|
* @return 执行的结果
|
*/
|
@GetMapping("/downloadImportTemplate")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"IMPORT"},methodAlias = {"导入"},modelKey = {9})
|
#end
|
public BaseResult downloadImportTemplate(HttpServletResponse response,String downloadUUID){
|
//下载模板这个可以不校验downloadUUID
|
//1.拷贝文件到临时文件夹中
|
//2.可以根据实际情况,是否在下载导入模板时写入默认的值
|
//3.下载excel
|
String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + EXPORT_TEMPLATE_SHOW_NAME;
|
LocalFileUtil.copyFileInJar(EXPORT_TEMPLATE_FILE_NAME,excelFileName);
|
try {
|
ControllerUtil.writeFileToResponse(response,new File(excelFileName),EXPORT_TEMPLATE_SHOW_NAME,true);
|
} catch (FileNotFoundException e) {
|
return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_TEMPLATE_FILE_NOT_FOUND);
|
} catch (IOException e) {
|
return BaseResult.fail(FrameWorkLangCodeConstant.DOWNLOAD_FAIL,new String[]{LangBaseUtil.getErrorMsg(e)},e);
|
}
|
return BaseResult.successMsg(FrameWorkLangCodeConstant.DOWNLOAD_SUCCESS);
|
}
|
|
/**
|
* 导入 ${comments}
|
* @param file excel文件
|
* @param ${classNameFristLowwer}DTO 数据传输对象,作为导入的附加条件判断
|
* @return 执行的结果,success为true表示执行成功·
|
*/
|
@PostMapping( "/importData")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"IMPORT"},methodAlias = {"导入"},modelKey = {9})
|
#end
|
public BaseResult import${className}(MultipartFile file,${className}DTO ${classNameFristLowwer}DTO) {
|
BaseResult<?> baseResult = null;
|
InputStream ins = null;
|
try {
|
if (file != null && !file.isEmpty()) {
|
ins = file.getInputStream();
|
baseResult = ${classNameFristLowwer}Service.import${className}(ins,${classNameFristLowwer}DTO);
|
} else {
|
return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL);
|
}
|
}catch (IOException e){
|
throw new VciBaseException(e.getMessage(),new String[0],e);
|
}catch (Throwable e) {
|
throw e;
|
}finally {
|
IOUtils.closeQuietly(ins);
|
}
|
return baseResult;
|
}
|
|
/**
|
* 导出${comments}
|
* @param baseQueryObject 基础查询对象,包含查询条件,分页和排序
|
* @param response 相应对象
|
* @return 只有执行失败的时候返回结果才有效,msg是错误信息
|
*/
|
@PostMapping(value = "/exportData")
|
#if(${hasPermisssion})
|
@VciPermission(methodKey = {"EXPORT"},methodAlias = {"导出"},modelKey = {10})
|
#end
|
public void export${className}(BaseQueryObject baseQueryObject, HttpServletResponse response){
|
if(baseQueryObject == null){
|
baseQueryObject = new BaseQueryObject();
|
}
|
String excelFileName = ${classNameFristLowwer}Service.export${className}(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
|
try {
|
ControllerUtil.writeFileToResponse(response, excelFileName);
|
}catch (IOException e){
|
throw new VciBaseException(e.getMessage(),new String[0],e);
|
}catch (Throwable e){
|
throw e;
|
}
|
}
|
#end
|
|
#if(!${hasParentField})
|
/**
|
* 参照${comments}列表
|
* @param baseQueryObject 基础查询对象,包含查询条件,分页,排序等
|
* @return ${comments}显示对象列表,生效的内容
|
*/
|
@GetMapping("/refDataGrid")
|
#if(${hasPermisssion})
|
@VciReferPermission(referedKey = "${className}Refer")
|
#end
|
public DataGrid<${className}VO> refDataGrid${className}(BaseQueryObject baseQueryObject){
|
if(baseQueryObject == null){
|
baseQueryObject = new BaseQueryObject();
|
}
|
return ${classNameFristLowwer}Service.refDataGrid${className}(baseQueryObject.getConditionMap(),baseQueryObject.getPageHelper());
|
}
|
#else
|
/**
|
* 参照树 ${comments}
|
* @param treeQueryObject 树形查询对象
|
* @return ${comments}显示树
|
*/
|
@GetMapping("/referTree")
|
#if(${hasPermisssion})
|
@VciReferPermission(referedKey = "${className}ReferTree")
|
#end
|
public List<Tree> referTree(TreeQueryObject treeQueryObject) {
|
return ${classNameFristLowwer}Service.referTree(treeQueryObject);
|
}
|
#end
|
|
}
|