1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.landtool.lanbase.modules.sys.controller;
 
import com.alibaba.fastjson.JSON;
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.utils.PageUtils;
import com.landtool.lanbase.common.utils.Query;
import com.landtool.lanbase.common.utils.Result;
import com.landtool.lanbase.modules.sys.service.SysGeneratorService;
 
import springfox.documentation.annotations.ApiIgnore;
 
import org.apache.commons.io.IOUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
 
/**
 * @author lanbase
 * @Description: TODO(代码生成器)
 * @date 2017-6-23 15:07
 */
@Controller
@RequestMapping("/sys/generator")
@ApiIgnore()
public class SysGeneratorController extends AbstractController{
 
    @Autowired
    private SysGeneratorService sysGeneratorService;
    
    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/list")
//    @RequiresPermissions("sys:generator:list")
//    @LogAction("查询")
    public Result list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<Map<String, Object>> list = sysGeneratorService.queryList(query);
        int total = sysGeneratorService.queryTotal(query);
        
        PageUtils pageUtil = new PageUtils(list, total, query.getLimit(), query.getPage());
        
        return Result.ok().put("page", pageUtil);
    }
    
    /**
     * 生成代码
     */
    @RequestMapping("/code")
    //@RequiresPermissions("sys:generator:code")
    public void code(HttpServletRequest request, HttpServletResponse response) throws IOException{
        String[] tableNames = new String[]{};
        String tables = request.getParameter("tables");
        tableNames = JSON.parseArray(tables).toArray(tableNames);
        
        byte[] data = sysGeneratorService.generatorCode(tableNames);
        
        response.reset();  
        response.setHeader("Content-Disposition", "attachment; filename=\"lanbase-generate-code.zip\"");
        response.addHeader("Content-Length", "" + data.length);  
        response.setContentType("application/octet-stream; charset=UTF-8");  
  
        IOUtils.write(data, response.getOutputStream());  
    }
 
}