【update】修改生成器模板模板

This commit is contained in:
mzc5649
2021-04-09 10:45:59 +08:00
parent 12db30f308
commit 944487d74f
4 changed files with 338 additions and 213 deletions
@@ -1,180 +1,193 @@
package ${bussiPackage}.${entityPackage}.controller; package ${bussiPackage}.${entityPackage}.controller;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.jero.common.api.vo.Result; import com.jero.common.api.vo.Result;
import com.jero.common.system.query.QueryGenerator; import com.jero.common.system.query.QueryGenerator;
import com.jero.common.util.oConvertUtils; import com.jero.common.util.oConvertUtils;
import ${bussiPackage}.${entityPackage}.entity.${entityName}; import ${bussiPackage}.${entityPackage}.entity.${entityName};
import ${bussiPackage}.${entityPackage}.service.I${entityName}Service; import ${bussiPackage}.${entityPackage}.service.I${entityName}Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.jero.common.system.base.controller.JeroController; import com.jero.common.system.base.controller.JeroController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import com.jero.common.aspect.annotation.AutoLog; import com.jero.common.aspect.annotation.AutoLog;
<#assign bpm_flag=false> <#assign bpm_flag=false>
<#list originalColumns as po> <#list originalColumns as po>
<#if po.fieldDbName=='bpm_status'> <#if po.fieldDbName=='bpm_status'>
<#assign bpm_flag=true> <#assign bpm_flag=true>
</#if> </#if>
</#list> </#list>
/** /**
* @Description: ${tableVo.ftlDescription} * @Description: ${tableVo.ftlDescription}
* @Author: jero-boot * @Author: jero-boot
* @Date: ${.now?string["yyyy-MM-dd"]} * @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0 * @Version: V1.0
*/ */
@Api(tags="${tableVo.ftlDescription}") @Api(tags="${tableVo.ftlDescription}")
@RestController @RestController
@RequestMapping("/${entityPackage}/${entityName?uncap_first}") @RequestMapping("/${entityPackage}/${entityName?uncap_first}")
@Slf4j @Slf4j
public class ${entityName}Controller extends JeroController<${entityName}, I${entityName}Service> { public class ${entityName}Controller extends JeroController<${entityName}, I${entityName}Service> {
@Autowired @Autowired
private I${entityName}Service ${entityName?uncap_first}Service; private I${entityName}Service ${entityName?uncap_first}Service;
/** /**
* 分页列表查询 * 分页列表查询
* *
* @param ${entityName?uncap_first} * @param ${entityName?uncap_first}
* @param pageNo * @param pageNo
* @param pageSize * @param pageSize
* @param req * @param req
* @return * @return
*/ */
@AutoLog(value = "${tableVo.ftlDescription}-分页列表查询") @AutoLog(value = "${tableVo.ftlDescription}-分页列表查询")
@ApiOperation(value="${tableVo.ftlDescription}-分页列表查询", notes="${tableVo.ftlDescription}-分页列表查询") @ApiOperation(value="${tableVo.ftlDescription}-分页列表查询", notes="${tableVo.ftlDescription}-分页列表查询")
@GetMapping(value = "/list") @GetMapping(value = "/page")
public Result<?> queryPageList(${entityName} ${entityName?uncap_first}, public Result<?> queryPageList(${entityName} ${entityName?uncap_first},
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) { HttpServletRequest req) {
QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first}, req.getParameterMap()); QueryWrapper<${entityName}> queryWrapper = QueryGenerator.initQueryWrapper(${entityName?uncap_first}, req.getParameterMap());
Page<${entityName}> page = new Page<${entityName}>(pageNo, pageSize); Page<${entityName}> page = new Page<${entityName}>(pageNo, pageSize);
IPage<${entityName}> pageList = ${entityName?uncap_first}Service.page(page, queryWrapper); IPage<${entityName}> pageList = ${entityName?uncap_first}Service.page(page, queryWrapper);
return Result.OK(pageList); return Result.OK(pageList);
} }
/** /**
* 添加 * 列表查询
* *
* @param ${entityName?uncap_first} * @return
* @return */
*/ @AutoLog(value = "${tableVo.ftlDescription}-列表查询")
@AutoLog(value = "${tableVo.ftlDescription}-添加") @ApiOperation(value="${tableVo.ftlDescription}-列表查询", notes="${tableVo.ftlDescription}-列表查询")
@ApiOperation(value="${tableVo.ftlDescription}-添加", notes="${tableVo.ftlDescription}-添加") @GetMapping(value = "/list")
@PostMapping(value = "/add") public Result<List<${entityName}>> queryList() {
public Result<?> add(@RequestBody ${entityName} ${entityName?uncap_first}) { List<?> list = ${entityName?uncap_first}Service.queryList();
<#if bpm_flag> return Result.OK(list);
${entityName?uncap_first}.setBpmStatus("1"); }
</#if>
${entityName?uncap_first}Service.save(${entityName?uncap_first}); /**
return Result.OK("添加成功!"); * 添加
} *
* @param ${entityName?uncap_first}
/** * @return
* 编辑 */
* @AutoLog(value = "${tableVo.ftlDescription}-添加")
* @param ${entityName?uncap_first} @ApiOperation(value="${tableVo.ftlDescription}-添加", notes="${tableVo.ftlDescription}-添加")
* @return @PostMapping(value = "/add")
*/ public Result<?> add(@RequestBody ${entityName} ${entityName?uncap_first}) {
@AutoLog(value = "${tableVo.ftlDescription}-编辑") <#if bpm_flag>
@ApiOperation(value="${tableVo.ftlDescription}-编辑", notes="${tableVo.ftlDescription}-编辑") ${entityName?uncap_first}.setBpmStatus("1");
@PutMapping(value = "/edit") </#if>
public Result<?> edit(@RequestBody ${entityName} ${entityName?uncap_first}) { ${entityName?uncap_first}Service.add(${entityName?uncap_first});
${entityName?uncap_first}Service.updateById(${entityName?uncap_first}); return Result.OK("添加成功!");
return Result.OK("编辑成功!"); }
}
/**
/** * 编辑
* 通过id删除 *
* * @param ${entityName?uncap_first}
* @param id * @return
* @return */
*/ @AutoLog(value = "${tableVo.ftlDescription}-编辑")
@AutoLog(value = "${tableVo.ftlDescription}-通过id删除") @ApiOperation(value="${tableVo.ftlDescription}-编辑", notes="${tableVo.ftlDescription}-编辑")
@ApiOperation(value="${tableVo.ftlDescription}-通过id删除", notes="${tableVo.ftlDescription}-通过id删除") @PutMapping(value = "/edit")
@DeleteMapping(value = "/delete") public Result<?> edit(@RequestBody ${entityName} ${entityName?uncap_first}) {
public Result<?> delete(@RequestParam(name="id",required=true) String id) { ${entityName?uncap_first}Service.editById(${entityName?uncap_first});
${entityName?uncap_first}Service.removeById(id); return Result.OK("编辑成功!");
return Result.OK("删除成功!"); }
}
/**
/** * 通过id删除
* 批量删除 *
* * @param id
* @param ids * @return
* @return */
*/ @AutoLog(value = "${tableVo.ftlDescription}-通过id删除")
@AutoLog(value = "${tableVo.ftlDescription}-批量删除") @ApiOperation(value="${tableVo.ftlDescription}-通过id删除", notes="${tableVo.ftlDescription}-通过id删除")
@ApiOperation(value="${tableVo.ftlDescription}-批量删除", notes="${tableVo.ftlDescription}-批量删除") @DeleteMapping(value = "/delete")
@DeleteMapping(value = "/deleteBatch") public Result<?> delete(@RequestParam(name="id",required=true) String id) {
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) { ${entityName?uncap_first}Service.deleteById(id);
this.${entityName?uncap_first}Service.removeByIds(Arrays.asList(ids.split(","))); return Result.OK("删除成功!");
return Result.OK("批量删除成功!"); }
}
/**
/** * 批量删除
* 通过id查询 *
* * @param ids
* @param id * @return
* @return */
*/ @AutoLog(value = "${tableVo.ftlDescription}-批量删除")
@AutoLog(value = "${tableVo.ftlDescription}-通过id查询") @ApiOperation(value="${tableVo.ftlDescription}-批量删除", notes="${tableVo.ftlDescription}-批量删除")
@ApiOperation(value="${tableVo.ftlDescription}-通过id查询", notes="${tableVo.ftlDescription}-通过id查询") @DeleteMapping(value = "/deleteBatch")
@GetMapping(value = "/queryById") public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
public Result<?> queryById(@RequestParam(name="id",required=true) String id) { this.${entityName?uncap_first}Service.deleteByIds(Arrays.asList(ids.split(",")));
${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.getById(id); return Result.OK("批量删除成功!");
if(${entityName?uncap_first}==null) { }
return Result.error("未找到对应数据");
} /**
return Result.OK(${entityName?uncap_first}); * 通过id查询
} *
* @param id
/** * @return
* 导出excel */
* @AutoLog(value = "${tableVo.ftlDescription}-通过id查询")
* @param request @ApiOperation(value="${tableVo.ftlDescription}-通过id查询", notes="${tableVo.ftlDescription}-通过id查询")
* @param ${entityName?uncap_first} @GetMapping(value = "/queryById")
*/ public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
@RequestMapping(value = "/exportXls") ${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.queryById(id);
public ModelAndView exportXls(HttpServletRequest request, ${entityName} ${entityName?uncap_first}) { if(${entityName?uncap_first}==null) {
return super.exportXls(request, ${entityName?uncap_first}, ${entityName}.class, "${tableVo.ftlDescription}"); return Result.error("未找到对应数据");
} }
return Result.OK(${entityName?uncap_first});
/** }
* 通过excel导入数据
* /**
* @param request * 导出excel
* @param response *
* @return * @param request
*/ * @param ${entityName?uncap_first}
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) */
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { @RequestMapping(value = "/exportXls")
return super.importExcel(request, response, ${entityName}.class); public ModelAndView exportXls(HttpServletRequest request, ${entityName} ${entityName?uncap_first}) {
} return super.exportXls(request, ${entityName?uncap_first}, ${entityName}.class, "${tableVo.ftlDescription}");
}
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, ${entityName}.class);
}
}
@@ -1,14 +1,61 @@
package ${bussiPackage}.${entityPackage}.service; package ${bussiPackage}.${entityPackage}.service;
import ${bussiPackage}.${entityPackage}.entity.${entityName}; import ${bussiPackage}.${entityPackage}.entity.${entityName};
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @Description: ${tableVo.ftlDescription} /**
* @Author: jero-boot * @Description: ${tableVo.ftlDescription}
* @Date: ${.now?string["yyyy-MM-dd"]} * @Author: jero-boot
* @Version: V1.0 * @Date: ${.now?string["yyyy-MM-dd"]}
*/ * @Version: V1.0
public interface I${entityName}Service extends IService<${entityName}> { */
public interface I${entityName}Service extends IService<${entityName}> {
}
/**
* 保存
*
* @param ${entityName?uncap_first}
* @return
*/
void add(${entityName} ${entityName?uncap_first});
/**
* 更新
*
* @param ${entityName?uncap_first}
* @return
*/
void editById(${entityName} ${entityName?uncap_first});
/**
* 通过id删除
*
* @param id
* @return
*/
void deleteById(String id);
/**
* 批量删除
*
* @param ids
* @return
*/
void deleteByIds(List<String> ids);
/**
* 通过id查询
*
* @param id
* @return
*/
${entityName} queryById(String id);
/**
* 列表查询
*
* @return
*/
List<${entityName}> queryList();
}
@@ -1,19 +1,83 @@
package ${bussiPackage}.${entityPackage}.service.impl; package ${bussiPackage}.${entityPackage}.service.impl;
import ${bussiPackage}.${entityPackage}.entity.${entityName}; import ${bussiPackage}.${entityPackage}.entity.${entityName};
import ${bussiPackage}.${entityPackage}.mapper.${entityName}Mapper; import ${bussiPackage}.${entityPackage}.mapper.${entityName}Mapper;
import ${bussiPackage}.${entityPackage}.service.I${entityName}Service; import ${bussiPackage}.${entityPackage}.service.I${entityName}Service;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/** /**
* @Description: ${tableVo.ftlDescription} * @Description: ${tableVo.ftlDescription}
* @Author: jero-boot * @Author: jero-boot
* @Date: ${.now?string["yyyy-MM-dd"]} * @Date: ${.now?string["yyyy-MM-dd"]}
* @Version: V1.0 * @Version: V1.0
*/ */
@Service @Service
public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, ${entityName}> implements I${entityName}Service { public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, ${entityName}> implements I${entityName}Service {
} /**
* 保存
*
* @param ${entityName?uncap_first}
* @return
*/
@Override
void add(${entityName} ${entityName?uncap_first}) {
save(${entityName?uncap_first});
}
/**
* 更新
*
* @param ${entityName?uncap_first}
* @return
*/
@Override
void editById(${entityName} ${entityName?uncap_first}) {
updateById(${entityName?uncap_first});
}
/**
* 通过id删除
*
* @param id
* @return
*/
@Override
void deleteById(String id) {
removeById(id);
}
/**
* 批量删除
*
* @param ids
* @return
*/
@Override
void deleteByIds(List<String> ids) {
removeByIds(ids);
}
/**
* 通过id查询
*
* @param id
* @return
*/
@Override
${entityName} queryById(String id) {
return getById(id);
}
/**
* 列表查询
*
* @return
*/
@Override
List<${entityName}> queryList() {
return list();
}
}
@@ -2,6 +2,7 @@ package ${bussiPackage}.${entityPackage}.service;
import ${bussiPackage}.${entityPackage}.entity.${entityName}; import ${bussiPackage}.${entityPackage}.entity.${entityName};
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/** /**
* @Description: ${tableVo.ftlDescription} * @Description: ${tableVo.ftlDescription}