doum
6 小时以前 ab8d7d27e2cb284a020fa6c1411e20f6a10ba20c
经销商管理
已添加1个文件
已修改3个文件
96 ■■■■■ 文件已修改
server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmmall_service/src/main/resources/templates/controller.vm 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmmall_service/src/main/resources/templates/db.vm 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/dmmall_admin/src/main/java/com/doumee/api/BaseController.java
@@ -3,11 +3,14 @@
import com.doumee.config.Jwt.JwtTokenUtil;
import com.doumee.core.model.LoginUserInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
 * Controller基类
@@ -47,5 +50,19 @@
        return obj != null ? (Integer) obj : null;
    }
    public List<Integer> getIdList(String ids){
        if(StringUtils.isBlank(ids)){
            return null;
        }
        String [] idArray = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String id : idArray) {
            try {
                idList.add(Integer.valueOf(id));
            }catch (Exception e){
}
        }
        return idList;
    }
}
server/dmmall_service/src/main/java/com/doumee/core/utils/CodeGenerator.java
@@ -17,17 +17,41 @@
// æ¼”示例子,执行 main æ–¹æ³•控制台输入模块表名回车自动生成对应项目目录中
public class CodeGenerator {
public static  String packName ="com.doumee";
    // è®¾ç½®è¾“出目录
    public static String rootFileDir = "D:/code/idea/initCode/";
    public static  String outputDirEntity =rootFileDir+"src/main/java/com/doumee/dao/business/model/"; // è¾“出的代码文件夹路径
    public static  String outputDirMapper = rootFileDir+"src/main/java/com/doumee/dao/business/"; // è¾“出的代码文件夹路径
    public static  String outputDirService =rootFileDir+"src/main/java/com/doumee/service/business/"; // è¾“出的代码文件夹路径
    public static  String outputDirServiceImpl = rootFileDir+"src/main/java/com/doumee/service/business/impl/"; // è¾“出的代码文件夹路径
    public static  String outputDirController =rootFileDir+"src/main/java/com/doumee/api/business/"; // è¾“出的代码文件夹路径
    public static  String outputDirDb =rootFileDir+"db/"; // è¾“出的代码文件夹路径
    public static void main(String[] args) {
        // é…ç½®æ•°æ®åº“连接
        String url = "jdbc:mysql://192.168.0.211:3306/dmmall_full";
        String username = "root";
        String password = "Doumee@168";
        String database = "dmmall_full";
        String tableName = "car_driver";
        List<String> tables = new ArrayList<>();
        tables.add("member");
        tables.add("labels");
        tables.add("goods");
        tables.add("goodsorder");
        tables.add("integral");
        for(String tableName : tables){
        // èŽ·å–è¡¨ä¿¡æ¯å¹¶ç”Ÿæˆä»£ç 
            try {
                System.out.println(tableName+"===================生成开始===================");
        Map<String, Object> tableInfo = getTableInfo(url, username, password, database, tableName);
        generateCode(tableInfo);
                System.out.println(tableName+"===================生成结束===================");
            }catch (Exception e){
                System.err.println(tableName+"===================生成异常==================="+e.getMessage());
    }
        }
    }
    public static Map<String, Object> getTableInfo(String url, String username, String password, String database, String tableName) {
        Map<String, Object> map = new HashMap<>();
@@ -117,42 +141,22 @@
        String tableComment = (String) tableInfo.get("tableComment");
        List<Map<String, String>> columns = (List<Map<String, String>>) tableInfo.get("columns");
        String templateDir = "D:\\code\\idea\\doumee_code\\server\\src\\main\\resources\\templates"; // æ¨¡æ¿æ–‡ä»¶çš„路径
        Properties p = new Properties();
        // æŒ‡å®šæ¨¡æ¿çš„加载位置
        p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, templateDir);
        // æŒ‡å®šè¾“入编码
        p.setProperty(VelocityEngine.INPUT_ENCODING, "UTF-8");
        p.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
        p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
        p.setProperty("velocimacro.library", "macro_library.vm"); // è®¾ç½®å®åº“文件名
        p.setProperty("velocimacro.library.autoreload", "true"); // å…è®¸è‡ªåŠ¨é‡æ–°åŠ è½½å®åº“
        p.setProperty("velocimacro.permissions.allow.inline.to.replace.global", "true"); // å…è®¸å†…联宏替换全局宏
        p.setProperty("velocimacro.library", "/templates/macro_library.vm"); // è®¾ç½®å®åº“文件名
        p.setProperty("velocimacro.library.autoreload", "true"); // å…è®¸è‡ªåŠ¨é‡æ–°åŠ è½½å®åº“
        // è®¾ç½® Velocity é…ç½®
        VelocityEngine velocityEngine = new VelocityEngine();
        velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        velocityEngine.init();
        // é…ç½®æ¨¡æ¿ç›®å½•
        // è®¾ç½®è¾“出目录
        String outputDir = "D:\\code\\idea\\doumee_code\\server\\src\\main\\java\\com\\testcom"; // è¾“出的代码文件夹路径
        String baseName = entityName.substring(0, 1).toUpperCase() + entityName.substring(1);
        // åˆ›å»º Velocity ä¸Šä¸‹æ–‡
        Map<String,String> pack = new HashMap<>();
        pack.put("Base",packName);
        pack.put("Entity",packName+".dao.businees.model");
        pack.put("Controller",packName+".api.businees");
        pack.put("Mapper",packName+".dao.businees");
        pack.put("Service",packName+".service.businees");
        pack.put("ServiceImpl",packName+".service.businees.impl");
        pack.put("Entity",packName+".dao.business.model");
        pack.put("Controller",packName+".api.business");
        pack.put("Mapper",packName+".dao.business");
        pack.put("Service",packName+".service.business");
        pack.put("ServiceImpl",packName+".service.business.impl");
        VelocityContext context = new VelocityContext();
        context.put("package",pack); // è®¾ç½®åŒ…路径
        context.put("entityName", baseName);
@@ -164,19 +168,20 @@
        context.put("nowDate", DateUtil.getPlusTime2(new Date()));
        // ç”Ÿæˆ Entity æ–‡ä»¶
        generateFile(velocityEngine, context,  "entity.vm", baseName, outputDir + "/dao/businees/model/" , ".java");
        generateFile(velocityEngine, context,  "entity.vm", baseName, outputDirEntity  , ".java");
        // ç”Ÿæˆ Mapper æ–‡ä»¶
        generateFile(velocityEngine, context,  "mapper.vm",  baseName, outputDir + "/dao/businees/" , "Mapper.java");
        generateFile(velocityEngine, context,  "mapper.vm",  baseName, outputDirMapper , "Mapper.java");
        // ç”Ÿæˆ Service æŽ¥å£æ–‡ä»¶
        generateFile(velocityEngine, context,  "service.vm",  baseName, outputDir + "/service/businees/" , "Service.java");
        generateFile(velocityEngine, context,  "service.vm",  baseName, outputDirService  , "Service.java");
        // ç”Ÿæˆ ServiceImpl æ–‡ä»¶
        generateFile(velocityEngine, context,  "serviceImpl.vm",  baseName, outputDir + "/service/businees/impl/" , "ServiceImpl.java");
        generateFile(velocityEngine, context,  "serviceImpl.vm",  baseName, outputDirServiceImpl + "" , "ServiceImpl.java");
        // ç”Ÿæˆ Controller æ–‡ä»¶
        generateFile(velocityEngine, context,  "controller.vm",  baseName, outputDir + "/api/businees/", "Controller.java");
        generateFile(velocityEngine, context,  "controller.vm",  baseName, outputDirController  , "Controller.java");
        generateFile(velocityEngine, context,  "db.vm",  baseName, outputDirDb  , "Permissions.sql");
    }
    private static void generateFile(VelocityEngine velocityEngine, VelocityContext context,  String templateName, String baseName,String outputFilePath,String endName)  {
@@ -190,6 +195,8 @@
        // åˆ›å»ºæ–‡ä»¶è¾“出流
        try{
            System.out.println(outputFilePath+baseName+endName+"===================生成开始===================");
            File f = new File(outputFilePath+baseName+endName);
            if(f.isFile()){
                f.delete();
@@ -200,7 +207,9 @@
            template.merge(context, writer);
            writer.flush();
            writer.close();
            System.out.println(outputFilePath+baseName+endName+"===================生成结束===================");
        } catch (IOException e) {
            System.err.println(outputFilePath+baseName+endName+"===================生成异常===================");
            e.printStackTrace();
        }
    }
server/dmmall_service/src/main/resources/templates/controller.vm
@@ -73,7 +73,7 @@
    @PostMapping("/exportExcel")
    @RequiresPermissions("business:${entityNameLowerFull}:exportExcel")
    public void exportExcel (@RequestBody PageWrap<${entityName}> pageWrap, HttpServletResponse response) {
        ExcelExporter.build(${entityName}.class).export(${entityNameLower}Service.findPage(pageWrap).getRecords(), "月台_作业操作历史表", response);
        ExcelExporter.build(${entityName}.class).export(${entityNameLower}Service.findPage(pageWrap).getRecords(), "${tableComment}", response);
    }
    @ApiOperation("根据ID查询")
server/dmmall_service/src/main/resources/templates/db.vm
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,6 @@
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:create', '新建${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:delete', '删除${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:update', '修改${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:query', '查询${tableComment}', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);
INSERT INTO `SYSTEM_PERMISSION`(`CODE`, `NAME`, `REMARK`, `FIXED`, `CREATE_USER`, `CREATE_TIME`, `UPDATE_USER`, `UPDATE_TIME`, `DELETED`) VALUES ('business:${entityNameLowerFull}:exportExcel', '导出${tableComment}(Excel)', '', 0, 1, CURRENT_TIMESTAMP, NULL, NULL, 0);