|
|
@ -22,15 +22,14 @@ import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
|
|
import com.ibeetl.admin.console.web.dto.DictExcelImportData;
|
|
|
|
import com.ibeetl.admin.console.web.dto.DictExcelImportData;
|
|
|
|
import com.ibeetl.admin.console.web.query.UserQuery;
|
|
|
|
import com.ibeetl.admin.console.web.query.UserQuery;
|
|
|
@ -39,6 +38,7 @@ import ${basePackage}.entity.*;
|
|
|
|
import ${basePackage}.service.*;
|
|
|
|
import ${basePackage}.service.*;
|
|
|
|
import ${basePackage}.web.query.*;
|
|
|
|
import ${basePackage}.web.query.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
@ -52,12 +52,14 @@ import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* ${entity.displayName} ${entity.comment} 接口
|
|
|
|
* ${entity.displayName} ${entity.comment} 接口
|
|
|
|
* 切记不要对非线程安全的静态变量进行写操作
|
|
|
|
* 切记不要对非线程安全的静态变量进行写操作
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
\@Controller
|
|
|
|
\@RestController
|
|
|
|
public class ${entity.name}Controller{
|
|
|
|
public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
private final Log log = LogFactory.getLog(this.getClass());
|
|
|
|
private final Log log = LogFactory.getLog(this.getClass());
|
|
|
@ -66,15 +68,13 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
@var service=entity.code+"Service";
|
|
|
|
@var service=entity.code+"Service";
|
|
|
|
|
|
|
|
|
|
|
|
\@Autowired private ${entity.name}Service ${service};
|
|
|
|
\@Resource private ${entity.name}Service ${service};
|
|
|
|
|
|
|
|
|
|
|
|
\@Autowired
|
|
|
|
\@Resource FileService fileService;
|
|
|
|
FileService fileService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 前端接口 */
|
|
|
|
/* 前端接口 */
|
|
|
|
|
|
|
|
|
|
|
|
\@PostMapping(API + "/getPageList.do")
|
|
|
|
\@PostMapping(API + "/getPageList.do")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<PageQuery> getPageList(${entity.name}Query condition,\@SCoreUser CoreUser coreUser){
|
|
|
|
public JsonResult<PageQuery> getPageList(${entity.name}Query condition,\@SCoreUser CoreUser coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
@ -87,7 +87,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(API + "/getInfo.do")
|
|
|
|
\@GetMapping(API + "/getInfo.do")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<${entity.name}>getInfo(${entity.name}Query param,\@SCoreUser CoreUser coreUser) {
|
|
|
|
public JsonResult<${entity.name}>getInfo(${entity.name}Query param,\@SCoreUser CoreUser coreUser) {
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
@ -99,7 +98,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(API + "/getList.do")
|
|
|
|
\@GetMapping(API + "/getList.do")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<List<${entity.name}>>getList(${entity.name}Query param,\@SCoreUser CoreUser coreUser) {
|
|
|
|
public JsonResult<List<${entity.name}>>getList(${entity.name}Query param,\@SCoreUser CoreUser coreUser) {
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
@ -114,7 +112,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(MODEL + "/index.do")
|
|
|
|
\@GetMapping(MODEL + "/index.do")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public ModelAndView index() {
|
|
|
|
public ModelAndView index() {
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/${entity.code}/index.html") ;
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/${entity.code}/index.html") ;
|
|
|
|
view.addObject("search", ${entity.name}Query.class.getName());
|
|
|
|
view.addObject("search", ${entity.name}Query.class.getName());
|
|
|
@ -123,7 +120,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(MODEL + "/edit.do")
|
|
|
|
\@GetMapping(MODEL + "/edit.do")
|
|
|
|
\@Function("${entity.code}.edit")
|
|
|
|
\@Function("${entity.code}.edit")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public ModelAndView edit(${entity.idAttribute.javaType} ${entity.idAttribute.name}) {
|
|
|
|
public ModelAndView edit(${entity.idAttribute.javaType} ${entity.idAttribute.name}) {
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/${entity.code}/edit.html");
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/${entity.code}/edit.html");
|
|
|
|
${entity.name} ${entity.code} = ${service}.queryById(${entity.idAttribute.name});
|
|
|
|
${entity.name} ${entity.code} = ${service}.queryById(${entity.idAttribute.name});
|
|
|
@ -133,7 +129,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(MODEL + "/add.do")
|
|
|
|
\@GetMapping(MODEL + "/add.do")
|
|
|
|
\@Function("${entity.code}.add")
|
|
|
|
\@Function("${entity.code}.add")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public ModelAndView add(${entity.idAttribute.javaType} ${entity.idAttribute.name}) {
|
|
|
|
public ModelAndView add(${entity.idAttribute.javaType} ${entity.idAttribute.name}) {
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/${entity.code}/add.html");
|
|
|
|
ModelAndView view = new ModelAndView("/jlw/${entity.code}/add.html");
|
|
|
|
if(null != ${entity.idAttribute.name}){
|
|
|
|
if(null != ${entity.idAttribute.name}){
|
|
|
@ -149,7 +144,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@PostMapping(MODEL + "/list.json")
|
|
|
|
\@PostMapping(MODEL + "/list.json")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<PageQuery> list(${entity.name}Query condition){
|
|
|
|
public JsonResult<PageQuery> list(${entity.name}Query condition){
|
|
|
|
PageQuery page = condition.getPageQuery();
|
|
|
|
PageQuery page = condition.getPageQuery();
|
|
|
|
${service}.queryByCondition(page);
|
|
|
|
${service}.queryByCondition(page);
|
|
|
@ -158,20 +152,19 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@PostMapping(MODEL + "/addAll.json")
|
|
|
|
\@PostMapping(MODEL + "/addAll.json")
|
|
|
|
\@Function("${entity.code}.add")
|
|
|
|
\@Function("${entity.code}.add")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult addAll(${entity.name}Query ${entity.code}Query,\@SCoreUser CoreUser coreUser){
|
|
|
|
public JsonResult addAll(${entity.name}Query ${entity.code}Query,\@SCoreUser CoreUser coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
@if(entity.existAddTime){
|
|
|
|
@if(entity.existAddTime){
|
|
|
|
${entity.code}Query.set${upperFirst(entity.addTime)}(new Date());
|
|
|
|
${entity.code}Query.set${upperFirst(entity.addTime)}(new Date());
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(entity.existUserId){
|
|
|
|
@if(entity.existUserId){
|
|
|
|
${entity.code}Query.setUserId(coreUser.getId());
|
|
|
|
${entity.code}Query.setUserId(coreUser.getId());
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(entity.existOrgId){
|
|
|
|
@if(entity.existOrgId){
|
|
|
|
${entity.code}Query.setOrgId(coreUser.getOrgId());
|
|
|
|
${entity.code}Query.setOrgId(coreUser.getOrgId());
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
String msg = ${service}.addAll(${entity.code}Query);
|
|
|
|
String msg = ${service}.addAll(${entity.code}Query);
|
|
|
|
if (StringUtils.isBlank(msg)) {
|
|
|
|
if (StringUtils.isBlank(msg)) {
|
|
|
|
return JsonResult.success();
|
|
|
|
return JsonResult.success();
|
|
|
@ -183,49 +176,47 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@PostMapping(MODEL + "/add.json")
|
|
|
|
\@PostMapping(MODEL + "/add.json")
|
|
|
|
\@Function("${entity.code}.add")
|
|
|
|
\@Function("${entity.code}.add")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult add(\@Validated(ValidateConfig.ADD.class) ${entity.name}Query ${entity.code}Query, BindingResult result,\@SCoreUser CoreUser coreUser){
|
|
|
|
public JsonResult add(\@Validated(ValidateConfig.ADD.class) ${entity.name}Query ${entity.code}Query, BindingResult result,\@SCoreUser CoreUser coreUser){
|
|
|
|
if(result.hasErrors()){
|
|
|
|
if(result.hasErrors()){
|
|
|
|
return JsonResult.failMessage(result);
|
|
|
|
return JsonResult.failMessage(result);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
@if(entity.existAddTime){
|
|
|
|
@if(entity.existAddTime){
|
|
|
|
${entity.code}Query.set${upperFirst(entity.addTime)}(new Date());
|
|
|
|
${entity.code}Query.set${upperFirst(entity.addTime)}(new Date());
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(entity.existUserId){
|
|
|
|
@if(entity.existUserId){
|
|
|
|
${entity.code}Query.setUserId(coreUser.getId());
|
|
|
|
${entity.code}Query.setUserId(coreUser.getId());
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(entity.existOrgId){
|
|
|
|
@if(entity.existOrgId){
|
|
|
|
${entity.code}Query.setOrgId(coreUser.getOrgId());
|
|
|
|
${entity.code}Query.setOrgId(coreUser.getOrgId());
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(null != entity.status){
|
|
|
|
@if(null != entity.status){
|
|
|
|
@for(attr in attrs) {
|
|
|
|
@for(attr in attrs) {
|
|
|
|
@if(null != attr.isStatus) {
|
|
|
|
@if(null != attr.isStatus) {
|
|
|
|
if(null == ${entity.code}Query.get${upperFirst(attr.name)}()){
|
|
|
|
if(null == ${entity.code}Query.get${upperFirst(attr.name)}()){
|
|
|
|
${entity.code}Query.set${upperFirst(attr.name)}(1);
|
|
|
|
${entity.code}Query.set${upperFirst(attr.name)}(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
|
|
|
|
return ${service}.add(${entity.code}Query);
|
|
|
|
return ${service}.add(${entity.code}Query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
\@PostMapping(MODEL + "/edit.json")
|
|
|
|
\@PostMapping(MODEL + "/edit.json")
|
|
|
|
\@Function("${entity.code}.edit")
|
|
|
|
\@Function("${entity.code}.edit")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<String> update(\@Validated(ValidateConfig.UPDATE.class) ${entity.name}Query ${entity.code}Query, BindingResult result) {
|
|
|
|
public JsonResult<String> update(\@Validated(ValidateConfig.UPDATE.class) ${entity.name}Query ${entity.code}Query, BindingResult result) {
|
|
|
|
if(result.hasErrors()){
|
|
|
|
if(result.hasErrors()){
|
|
|
|
return JsonResult.failMessage(result);
|
|
|
|
return JsonResult.failMessage(result);
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
@if(entity.existAddTime){
|
|
|
|
@if(entity.existAddTime){
|
|
|
|
${entity.code}Query.set${upperFirst(entity.addTime)}(null);
|
|
|
|
${entity.code}Query.set${upperFirst(entity.addTime)}(null);
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(entity.existUserId){
|
|
|
|
@if(entity.existUserId){
|
|
|
|
${entity.code}Query.setUserId(null);
|
|
|
|
${entity.code}Query.setUserId(null);
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@if(entity.existOrgId){
|
|
|
|
@if(entity.existOrgId){
|
|
|
|
${entity.code}Query.setOrgId(null);
|
|
|
|
${entity.code}Query.setOrgId(null);
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
String msg = ${service}.edit(${entity.code}Query);
|
|
|
|
String msg = ${service}.edit(${entity.code}Query);
|
|
|
|
if (StringUtils.isBlank(msg)) {
|
|
|
|
if (StringUtils.isBlank(msg)) {
|
|
|
|
return JsonResult.success();
|
|
|
|
return JsonResult.success();
|
|
|
@ -238,7 +229,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(MODEL + "/view.json")
|
|
|
|
\@GetMapping(MODEL + "/view.json")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<${entity.name}>queryInfo(${entity.idAttribute.javaType} ${entity.idAttribute.name}) {
|
|
|
|
public JsonResult<${entity.name}>queryInfo(${entity.idAttribute.javaType} ${entity.idAttribute.name}) {
|
|
|
|
${entity.name} ${entity.code} = ${service}.queryById( ${entity.idAttribute.name});
|
|
|
|
${entity.name} ${entity.code} = ${service}.queryById( ${entity.idAttribute.name});
|
|
|
|
return JsonResult.success(${entity.code});
|
|
|
|
return JsonResult.success(${entity.code});
|
|
|
@ -246,7 +236,6 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
\@GetMapping(MODEL + "/getValues.json")
|
|
|
|
\@GetMapping(MODEL + "/getValues.json")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@Function("${entity.code}.query")
|
|
|
|
\@ResponseBody
|
|
|
|
|
|
|
|
public JsonResult<List<${entity.name}>>getValues(${entity.name}Query param) {
|
|
|
|
public JsonResult<List<${entity.name}>>getValues(${entity.name}Query param) {
|
|
|
|
List<${entity.name}>list = ${service}.getValuesByQuery(param);
|
|
|
|
List<${entity.name}>list = ${service}.getValuesByQuery(param);
|
|
|
|
return JsonResult.success(list);
|
|
|
|
return JsonResult.success(list);
|
|
|
@ -263,212 +252,208 @@ public class ${entity.name}Controller{
|
|
|
|
|
|
|
|
|
|
|
|
@if(entity.includeExcel){
|
|
|
|
@if(entity.includeExcel){
|
|
|
|
|
|
|
|
|
|
|
|
//下载模板信息
|
|
|
|
//下载模板信息
|
|
|
|
\@GetMapping(MODEL + "/downloadTemplate.json")
|
|
|
|
\@GetMapping(MODEL + "/downloadTemplate.json")
|
|
|
|
\@ResponseBody
|
|
|
|
public void download(HttpServletRequest request,HttpServletResponse response,\@SCoreUser CoreUser coreUser) {
|
|
|
|
public void download(HttpServletRequest request,HttpServletResponse response,\@SCoreUser CoreUser coreUser) {
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
XSSFWorkbook workbook = null;
|
|
|
|
InputStream is = null;
|
|
|
|
InputStream is = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//TODO 改导入模板名字
|
|
|
|
//TODO 改导入模板名字
|
|
|
|
is = new FileInputStream(getFile.p + File.separator +"filesystem"+ File.separator +"template"+ File.separator+ "导入模板.xlsx");
|
|
|
|
is = new FileInputStream(getFile.p + File.separator +"filesystem"+ File.separator +"template"+ File.separator+ "导入模板.xlsx");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
workbook = new XSSFWorkbook(is);
|
|
|
|
workbook = new XSSFWorkbook(is);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if(null != is){
|
|
|
|
if(null != is){
|
|
|
|
is.close();
|
|
|
|
is.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}catch (Exception e){
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
//八进制输出流
|
|
|
|
//八进制输出流
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
|
|
|
|
|
|
|
//这后面可以设置导出Excel的名称,此例中名为template.xls
|
|
|
|
//这后面可以设置导出Excel的名称,此例中名为template.xls
|
|
|
|
String fileName = ToolUtils.web2fileName(request,"${entity.code}Template(" + TimeTool.getNowTime("YMD") + ").xlsx");
|
|
|
|
String fileName = ToolUtils.web2fileName(request,"${entity.code}Template(" + TimeTool.getNowTime("YMD") + ").xlsx");
|
|
|
|
|
|
|
|
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename="+fileName);
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename="+fileName);
|
|
|
|
|
|
|
|
|
|
|
|
//刷新缓冲
|
|
|
|
//刷新缓冲
|
|
|
|
response.flushBuffer();
|
|
|
|
response.flushBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
//workbook将Excel写入到response的输出流中,供页面下载
|
|
|
|
//workbook将Excel写入到response的输出流中,供页面下载
|
|
|
|
workbook.write(response.getOutputStream());
|
|
|
|
workbook.write(response.getOutputStream());
|
|
|
|
}catch (Exception e){
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (null != workbook) {
|
|
|
|
if (null != workbook) {
|
|
|
|
workbook.close();
|
|
|
|
workbook.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
response.getOutputStream().close();
|
|
|
|
response.getOutputStream().close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) { }
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//导入模板信息
|
|
|
|
//导入模板信息
|
|
|
|
\@PostMapping(MODEL + "/importTemplate.json")
|
|
|
|
\@PostMapping(MODEL + "/importTemplate.json")
|
|
|
|
\@Function("${entity.code}.importTemplate")
|
|
|
|
\@Function("${entity.code}.importTemplate")
|
|
|
|
\@ResponseBody
|
|
|
|
public JsonResult importTemplate(\@RFile List<FileEntity> fileEntityList,\@SCoreUser CoreUser coreUser) {
|
|
|
|
public JsonResult importTemplate(\@RFile List<FileEntity> fileEntityList,\@SCoreUser CoreUser coreUser) {
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
return JsonResult.failMessage("请登录后再操作");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Long>list=new ArrayList<>();
|
|
|
|
List<Long>list=new ArrayList<>();
|
|
|
|
JsonResult jsonResult = ${entity.code}Service.importTemplate(fileEntityList,list,coreUser);
|
|
|
|
JsonResult jsonResult = ${entity.code}Service.importTemplate(fileEntityList,list,coreUser);
|
|
|
|
if(list.size()>0){
|
|
|
|
if(list.size()>0){
|
|
|
|
${entity.code}Service.deleteByList(list);
|
|
|
|
${entity.code}Service.deleteByList(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsonResult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return jsonResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//导出信息
|
|
|
|
//导出信息
|
|
|
|
\@GetMapping(MODEL + "/excel/export.json")
|
|
|
|
\@GetMapping(MODEL + "/excel/export.json")
|
|
|
|
\@Function("${entity.code}.exportDocument")
|
|
|
|
\@Function("${entity.code}.exportDocument")
|
|
|
|
\@ResponseBody
|
|
|
|
public void export(HttpServletRequest request,HttpServletResponse response,${entity.name}Query ${entity.code}Query,\@SCoreUser CoreUser coreUser) {
|
|
|
|
public void export(HttpServletRequest request,HttpServletResponse response,${entity.name}Query ${entity.code}Query,\@SCoreUser CoreUser coreUser) {
|
|
|
|
if(null == coreUser){
|
|
|
|
if(null == coreUser){
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HSSFWorkbook workbook = null;
|
|
|
|
HSSFWorkbook workbook = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//表头数据
|
|
|
|
//表头数据
|
|
|
|
String[] header = {
|
|
|
|
String[] header = {
|
|
|
|
|
|
|
|
@for(attr in attrs) {
|
|
|
|
@for(attr in attrs) {
|
|
|
|
@if(!attr.isId && !attr.isOrgId && !attr.isUserId) {
|
|
|
|
@if(!attr.isId && !attr.isOrgId && !attr.isUserId) {
|
|
|
|
@if(attrLP.last){
|
|
|
|
@if(attrLP.last){
|
|
|
|
"${attr.comment}"
|
|
|
|
"${attr.comment}"
|
|
|
|
@}else{
|
|
|
|
@}else{
|
|
|
|
"${attr.comment}",
|
|
|
|
"${attr.comment}",
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
String[] headerCode = {
|
|
|
|
String[] headerCode = {
|
|
|
|
@for(attr in attrs) {
|
|
|
|
@for(attr in attrs) {
|
|
|
|
@if(!attr.isId && !attr.isOrgId && !attr.isUserId) {
|
|
|
|
@if(!attr.isId && !attr.isOrgId && !attr.isUserId) {
|
|
|
|
@if(attrLP.last){
|
|
|
|
@if(attrLP.last){
|
|
|
|
"${attr.name}"
|
|
|
|
"${attr.name}"
|
|
|
|
@}else{
|
|
|
|
@}else{
|
|
|
|
"${attr.name}",
|
|
|
|
"${attr.name}",
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
@}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//数据内容
|
|
|
|
//数据内容
|
|
|
|
List<Map<String, Object>> mapList = ${entity.code}Service.getExcelValues(${entity.code}Query);
|
|
|
|
List<Map<String, Object>> mapList = ${entity.code}Service.getExcelValues(${entity.code}Query);
|
|
|
|
|
|
|
|
|
|
|
|
//内容宽度
|
|
|
|
//内容宽度
|
|
|
|
Map<String, Object> widthMap = mapList.get(0);
|
|
|
|
Map<String, Object> widthMap = mapList.get(0);
|
|
|
|
mapList.remove(0);
|
|
|
|
mapList.remove(0);
|
|
|
|
|
|
|
|
|
|
|
|
//声明一个工作簿
|
|
|
|
//声明一个工作簿
|
|
|
|
workbook = new HSSFWorkbook();
|
|
|
|
workbook = new HSSFWorkbook();
|
|
|
|
|
|
|
|
|
|
|
|
//生成一个表格,设置表格名称为"Sheet1"
|
|
|
|
//生成一个表格,设置表格名称为"Sheet1"
|
|
|
|
HSSFSheet sheet = workbook.createSheet("Sheet1");
|
|
|
|
HSSFSheet sheet = workbook.createSheet("Sheet1");
|
|
|
|
|
|
|
|
|
|
|
|
//冻结表头
|
|
|
|
//冻结表头
|
|
|
|
sheet.createFreezePane(0, 1, 0, 1);
|
|
|
|
sheet.createFreezePane(0, 1, 0, 1);
|
|
|
|
|
|
|
|
|
|
|
|
//设置默认列宽度为5个字节
|
|
|
|
//设置默认列宽度为5个字节
|
|
|
|
sheet.setDefaultColumnWidth(5);
|
|
|
|
sheet.setDefaultColumnWidth(5);
|
|
|
|
|
|
|
|
|
|
|
|
//创建第一行表头
|
|
|
|
//创建第一行表头
|
|
|
|
HSSFRow headRow = sheet.createRow(0);
|
|
|
|
HSSFRow headRow = sheet.createRow(0);
|
|
|
|
|
|
|
|
|
|
|
|
//头部样式
|
|
|
|
//头部样式
|
|
|
|
HSSFCellStyle headerStyle = workbook.createCellStyle();
|
|
|
|
HSSFCellStyle headerStyle = workbook.createCellStyle();
|
|
|
|
//垂直居中
|
|
|
|
//垂直居中
|
|
|
|
headerStyle.setVerticalAlignment(headerStyle.getVerticalAlignmentEnum().CENTER);
|
|
|
|
headerStyle.setVerticalAlignment(headerStyle.getVerticalAlignmentEnum().CENTER);
|
|
|
|
//水平居中
|
|
|
|
//水平居中
|
|
|
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
|
|
|
|
|
|
|
//单元格样式
|
|
|
|
//单元格样式
|
|
|
|
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
|
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
|
|
|
//垂直居中
|
|
|
|
//垂直居中
|
|
|
|
cellStyle.setVerticalAlignment(cellStyle.getVerticalAlignmentEnum().CENTER);
|
|
|
|
cellStyle.setVerticalAlignment(cellStyle.getVerticalAlignmentEnum().CENTER);
|
|
|
|
//水平居左
|
|
|
|
//水平居左
|
|
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
//自动换行
|
|
|
|
//自动换行
|
|
|
|
cellStyle.setWrapText(true);
|
|
|
|
cellStyle.setWrapText(true);
|
|
|
|
|
|
|
|
|
|
|
|
//遍历添加表头
|
|
|
|
//遍历添加表头
|
|
|
|
for (int i = 0; i < header.length; i++) {
|
|
|
|
for (int i = 0; i < header.length; i++) {
|
|
|
|
|
|
|
|
|
|
|
|
//设置表格特定的列宽度
|
|
|
|
//设置表格特定的列宽度
|
|
|
|
if (null != widthMap.get(headerCode[i])) {
|
|
|
|
if (null != widthMap.get(headerCode[i])) {
|
|
|
|
String width = widthMap.get(headerCode[i]).toString().split("\\.")[0];
|
|
|
|
String width = widthMap.get(headerCode[i]).toString().split("\\.")[0];
|
|
|
|
Integer w = Integer.parseInt(width) > header[i].length()*3?Integer.parseInt(width):header[i].length()*3;
|
|
|
|
Integer w = Integer.parseInt(width) > header[i].length()*3?Integer.parseInt(width):header[i].length()*3;
|
|
|
|
sheet.setColumnWidth(i, w * 190);
|
|
|
|
sheet.setColumnWidth(i, w * 190);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//创建一个单元格
|
|
|
|
//创建一个单元格
|
|
|
|
HSSFCell cell = headRow.createCell(i);
|
|
|
|
HSSFCell cell = headRow.createCell(i);
|
|
|
|
|
|
|
|
|
|
|
|
//创建一个内容对象
|
|
|
|
//创建一个内容对象
|
|
|
|
HSSFRichTextString text = new HSSFRichTextString(header[i]);
|
|
|
|
HSSFRichTextString text = new HSSFRichTextString(header[i]);
|
|
|
|
|
|
|
|
|
|
|
|
//将内容对象的文字内容写入到单元格中
|
|
|
|
//将内容对象的文字内容写入到单元格中
|
|
|
|
cell.setCellValue(text);
|
|
|
|
cell.setCellValue(text);
|
|
|
|
|
|
|
|
|
|
|
|
//设置样式
|
|
|
|
//设置样式
|
|
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
cell.setCellStyle(headerStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//遍历结果集,把内容加入表格
|
|
|
|
//遍历结果集,把内容加入表格
|
|
|
|
for (int i = 0; i < mapList.size(); i++) {
|
|
|
|
for (int i = 0; i < mapList.size(); i++) {
|
|
|
|
HSSFRow row = sheet.createRow(i + 1);
|
|
|
|
HSSFRow row = sheet.createRow(i + 1);
|
|
|
|
|
|
|
|
|
|
|
|
row.setHeight((short) (50*10));
|
|
|
|
row.setHeight((short) (50*10));
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = mapList.get(i);
|
|
|
|
Map<String, Object> map = mapList.get(i);
|
|
|
|
for (int j = 0; j < headerCode.length; j++) {
|
|
|
|
for (int j = 0; j < headerCode.length; j++) {
|
|
|
|
HSSFCell cell = row.createCell(j);
|
|
|
|
HSSFCell cell = row.createCell(j);
|
|
|
|
cell.setCellStyle(cellStyle);
|
|
|
|
cell.setCellStyle(cellStyle);
|
|
|
|
HSSFRichTextString text = new HSSFRichTextString(null != map.get(headerCode[j]) ? map.get(headerCode[j]).toString() : " ");
|
|
|
|
HSSFRichTextString text = new HSSFRichTextString(null != map.get(headerCode[j]) ? map.get(headerCode[j]).toString() : " ");
|
|
|
|
cell.setCellValue(text);
|
|
|
|
cell.setCellValue(text);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
//准备将Excel的输出流通过response输出到页面下载
|
|
|
|
//八进制输出流
|
|
|
|
//八进制输出流
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
response.setContentType("application/octet-stream");
|
|
|
|
|
|
|
|
|
|
|
|
//这后面可以设置导出Excel的名称,此例中名为student.xls
|
|
|
|
//这后面可以设置导出Excel的名称,此例中名为student.xls
|
|
|
|
String fileName = ToolUtils.web2fileName(request,"${entity.code}(" + TimeTool.getNowTime("YMD") + ").xls");
|
|
|
|
String fileName = ToolUtils.web2fileName(request,"${entity.code}(" + TimeTool.getNowTime("YMD") + ").xls");
|
|
|
|
|
|
|
|
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename="+fileName);
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename="+fileName);
|
|
|
|
|
|
|
|
|
|
|
|
//刷新缓冲
|
|
|
|
//刷新缓冲
|
|
|
|
response.flushBuffer();
|
|
|
|
response.flushBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
//workbook将Excel写入到response的输出流中,供页面下载
|
|
|
|
//workbook将Excel写入到response的输出流中,供页面下载
|
|
|
|
workbook.write(response.getOutputStream());
|
|
|
|
workbook.write(response.getOutputStream());
|
|
|
|
}catch (Exception e){
|
|
|
|
}catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (null != workbook) {
|
|
|
|
if (null != workbook) {
|
|
|
|
workbook.close();
|
|
|
|
workbook.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
if (null != response && null != response.getOutputStream()) {
|
|
|
|
response.getOutputStream().close();
|
|
|
|
response.getOutputStream().close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) { }
|
|
|
|
} catch (Exception e) { }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@}
|
|
|
|
|
|
|
|
|
|
|
|
@}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|