|
- package ${packageName}.controller;
-
- import java.util.List;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.PutMapping;
- import org.springframework.web.bind.annotation.DeleteMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.enums.BusinessType;
- import ${packageName}.domain.${ClassName};
- import ${packageName}.service.I${ClassName}Service;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- #if($table.crud || $table.sub)
- import com.ruoyi.common.core.page.TableDataInfo;
- #elseif($table.tree)
- #end
-
- /**
- * ${functionName}Controller
- *
- * @author ${author}
- * @date ${datetime}
- */
- @RestController
- @RequestMapping("/${moduleName}/${businessName}")
- public class ${ClassName}Controller extends BaseController
- {
- @Autowired
- private I${ClassName}Service ${className}Service;
-
- /**
- * 查询${functionName}列表
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
- @GetMapping("/list")
- #if($table.crud || $table.sub)
- public TableDataInfo list(${ClassName} ${className})
- {
- startPage();
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- return getDataTable(list);
- }
- #elseif($table.tree)
- public AjaxResult list(${ClassName} ${className})
- {
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- return success(list);
- }
- #end
-
-
- /**
- * 导出${functionName}列表
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
- @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- public void export(HttpServletResponse response, ${ClassName} ${className})
- {
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
- util.exportExcel(response, list, "${functionName}数据");
- }
-
- /**
- * ${functionName}导入模板
- */
- @PostMapping("/importTemplate")
- public void importTemplate(HttpServletResponse response) {
- ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
- util.importTemplateExcel(response, "${functionName}数据");
- }
-
- /**
- * ${functionName}导入
- */
- @Log(title = "${functionName}", businessType = BusinessType.IMPORT)
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:import')")
- @PostMapping("/importData")
- public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
- ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
- List<${ClassName}> list = util.importExcel(file.getInputStream(), 0);
- String message = ${className}Service.import${ClassName}(list, updateSupport, getUsername());
- return AjaxResult.success(message);
- }
-
- /**
- * 获取${functionName}详细信息
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
- @GetMapping(value = "/{${pkColumn.javaField}}")
- public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
- {
- return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
- }
-
- /**
- * 获取${functionName}详细信息,翻译字典
- */
- @GetMapping(value = "/detail/{${pkColumn.javaField}}")
- public AjaxResult detail(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
- {
- ${ClassName} detail = ${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
- TranslateUtils.translate(detail, false);
- return success(detail);
- }
-
- /**
- * 新增${functionName}
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
- @Log(title = "${functionName}", businessType = BusinessType.INSERT)
- @PostMapping("/add")
- public AjaxResult add(@RequestBody ${ClassName} ${className})
- {
- return toAjax(${className}Service.insert${ClassName}(${className}));
- }
-
- /**
- * 修改${functionName}
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
- @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
- @PostMapping("/update")
- public AjaxResult edit(@RequestBody ${ClassName} ${className})
- {
- return toAjax(${className}Service.update${ClassName}(${className}));
- }
-
- /**
- * 删除${functionName}
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
- @Log(title = "${functionName}", businessType = BusinessType.DELETE)
- @GetMapping("/delete/{${pkColumn.javaField}s}")
- public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
- {
- return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
- }
-
- /**
- * 打印${functionName}
- */
- @PreAuthorize("@ss.hasPermi('${permissionPrefix}:print')")
- @Log(title = "${functionName}", businessType = BusinessType.PRINT)
- @GetMapping("/print")
- public void printPdf(${ClassName} ${className}, HttpServletResponse response) throws Exception{
-
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- TranslateUtils.translateList(list, false);
-
- PdfProperty pdf = new PdfProperty();
- pdf.setTitle("${functionName}");
- //pdf.setRowHeight(20f);
-
- ShoulderItem shoulder = new ShoulderItem();
- shoulder.setLeftItem("编制单位:");
- shoulder.setCenterItem("日期:" );
- shoulder.setRightItem("单位:");
- pdf.setShoulder(shoulder);
-
- float[] columnWidth = new float[]{20, 40, 10, 10, 10, 10};
- pdf.setColumnWidth(columnWidth);
- String[] header = new String[]{"A列", "B列", "C列", "D列", "E列", "F列"};
- pdf.setHeader(header);
- int[] aligns = new int[]{0, 0, 1, 1, 2, 2};
- pdf.setAligns(aligns);
-
- List<String[]> contentList = Lists.newArrayList();
- list.forEach(a ->{
- String[] str = new String[6];
- str[0] = "";
- str[1] = "";
- str[2] = "";
- str[3] = "";
- str[4] = "";
- str[5] = "";
- contentList.add(str);
- });
- pdf.setContentList(contentList);
-
- PageSet ps = new PageSet();
- ps.setPaperWidth(595.0f);
- ps.setPaperHeight(842.0f);
- ps.setPrintDirection("1");
- ps.setTableTotalWidth(520);
- ps.setMarginLeft(50);
- ps.setMarginRight(50);
- ps.setMarginTop(50);
- ps.setMarginBottom(50);
- pdf.setPageSet(ps);
-
- PdfUtils.initPdf(response, pdf);
- }
- }
|