-- =================================================
-- 代码生成平台测试数据
-- 使用方式：
-- 1. 先导入 sql/db.sql
-- 2. 再导入本文件：mysql -uroot -p ry < sql/generator_test_data.sql
-- 3. 登录 admin/admin123，进入「代码生成平台 -> 项目管理」
-- 4. 打开「演示生成项目」，可直接预览/下载 backend、admin_frontend、frontend 三类项目
-- =================================================

SET FOREIGN_KEY_CHECKS = 0;

-- 清理同一批测试数据，方便重复导入
DELETE FROM sys_project_structure WHERE template_id IN (9001, 9002, 9003) OR node_id BETWEEN 900100 AND 900399;
DELETE FROM sys_code_snippet_module WHERE snippet_id BETWEEN 9001 AND 9099;
DELETE FROM sys_code_snippet WHERE snippet_id BETWEEN 9001 AND 9099;
DELETE FROM sys_project_template WHERE project_id = 9001 OR template_id IN (9001, 9002, 9003);
DELETE FROM sys_project_table WHERE project_id = 9001 OR table_id = 9001;
DELETE FROM gen_table_project_rel WHERE project_id = 9001 OR table_id = 9001;
DELETE FROM sys_project_module WHERE project_id = 9001 OR module_id = 9001;
DELETE FROM sys_template_file WHERE template_id IN (9001, 9002, 9003) OR template_file_id BETWEEN 900100 AND 900399;
DELETE FROM sys_template WHERE template_id IN (9001, 9002, 9003);
DELETE FROM gen_table_column WHERE table_id = 9001 OR column_id BETWEEN 900100 AND 900199;
DELETE FROM gen_table WHERE table_id = 9001;
DELETE FROM gen_project WHERE project_id = 9001;
DELETE FROM sys_module WHERE module_id = 9001;
DROP TABLE IF EXISTS demo_product;

-- 示例业务表：不是生成逻辑必须项，但方便和 gen_table 元数据对照
CREATE TABLE demo_product (
  product_id bigint(20) NOT NULL AUTO_INCREMENT COMMENT '商品ID',
  product_name varchar(100) NOT NULL COMMENT '商品名称',
  product_code varchar(64) NOT NULL COMMENT '商品编码',
  price decimal(10,2) DEFAULT 0.00 COMMENT '商品价格',
  status char(1) DEFAULT '0' COMMENT '状态',
  create_time datetime DEFAULT NULL COMMENT '创建时间',
  remark varchar(500) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (product_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='演示商品表';

INSERT INTO demo_product (product_id, product_name, product_code, price, status, create_time, remark) VALUES
(1, '测试商品A', 'DEMO-A', 19.90, '0', sysdate(), '用于代码生成预览'),
(2, '测试商品B', 'DEMO-B', 29.90, '0', sysdate(), '用于代码生成下载');

-- 测试项目
INSERT INTO gen_project (project_id, project_name, project_file_name, package_name, version, project_desc, author, front_framework, back_framework, status, create_by, create_time, remark) VALUES
(9001, '演示生成项目', 'demo-generated-app', 'com.example.demo', '1.0.0', '代码生成平台测试项目，可直接预览和下载生成结果', 'Codex', 'Vue2 + Element UI', 'Spring Boot + MyBatis', '0', 'admin', sysdate(), '测试数据，可重复导入');

-- 测试功能模块，用于验证代码片段按项目模块生效
INSERT INTO sys_module (module_id, module_name, module_alias, module_desc, status, del_flag, create_by, create_time, remark) VALUES
(9001, '审计增强', 'audit', '演示代码片段模块，给 Controller 注入 ping 方法', '0', '0', 'admin', sysdate(), '测试数据');

INSERT INTO sys_project_module (id, project_id, module_id, status, create_by, create_time, remark) VALUES
(9001, 9001, 9001, '0', 'admin', sysdate(), '演示项目启用审计增强模块');

-- 示例生成表元数据
INSERT INTO gen_table (table_id, table_name, table_comment, class_name, tpl_category, tpl_web_type, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, remark, create_table_sql) VALUES
(9001, 'demo_product', '演示商品', 'DemoProduct', 'crud', 'element-ui', 'com.example.demo', 'demo', 'product', '演示商品', 'Codex', '0', '/', '{"parentMenuId":"3"}', 'admin', sysdate(), '测试数据',
'CREATE TABLE `demo_product` (
  `product_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ''商品ID'',
  `product_name` varchar(100) NOT NULL COMMENT ''商品名称'',
  `product_code` varchar(64) NOT NULL COMMENT ''商品编码'',
  `price` decimal(10,2) DEFAULT 0.00 COMMENT ''商品价格'',
  `status` char(1) DEFAULT ''0'' COMMENT ''状态'',
  `create_time` datetime DEFAULT NULL COMMENT ''创建时间'',
  `remark` varchar(500) DEFAULT NULL COMMENT ''备注'',
  PRIMARY KEY (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=''演示商品表'';');

INSERT INTO gen_table_column (column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time) VALUES
(900101, 9001, 'product_id', '商品ID', 'bigint(20)', 'Long', 'productId', '1', '1', '1', '0', '0', '0', '0', 'EQ', 'input', '', 1, 'admin', sysdate()),
(900102, 9001, 'product_name', '商品名称', 'varchar(100)', 'String', 'productName', '0', '0', '1', '1', '1', '1', '1', 'LIKE', 'input', '', 2, 'admin', sysdate()),
(900103, 9001, 'product_code', '商品编码', 'varchar(64)', 'String', 'productCode', '0', '0', '1', '1', '1', '1', '1', 'LIKE', 'input', '', 3, 'admin', sysdate()),
(900104, 9001, 'price', '商品价格', 'decimal(10,2)', 'BigDecimal', 'price', '0', '0', '0', '1', '1', '1', '0', 'EQ', 'input', '', 4, 'admin', sysdate()),
(900105, 9001, 'status', '状态', 'char(1)', 'String', 'status', '0', '0', '0', '1', '1', '1', '1', 'EQ', 'select', 'sys_normal_disable', 5, 'admin', sysdate()),
(900106, 9001, 'create_time', '创建时间', 'datetime', 'Date', 'createTime', '0', '0', '0', '0', '0', '1', '1', 'BETWEEN', 'datetime', '', 6, 'admin', sysdate()),
(900107, 9001, 'remark', '备注', 'varchar(500)', 'String', 'remark', '0', '0', '0', '1', '1', '0', '0', 'EQ', 'textarea', '', 7, 'admin', sysdate());

INSERT INTO sys_project_table (id, table_id, project_id) VALUES
(9001, 9001, 9001);

INSERT INTO gen_table_project_rel (id, table_id, project_id) VALUES
(9001, 9001, 9001);

-- 三类模板
INSERT INTO sys_template (template_id, template_name, template_path, template_desc, template_type, template_status, create_by, create_time, remark) VALUES
(9001, '测试后端模板', '/test/backend', '生成 Spring Boot + MyBatis 后端项目骨架', 'backend', 0, 'admin', sysdate(), '测试模板'),
(9002, '测试后台前端模板', '/test/admin_frontend', '生成后台前端 API 和列表页骨架', 'admin_frontend', 0, 'admin', sysdate(), '测试模板'),
(9003, '测试前台前端模板', '/test/frontend', '生成最小前台前端项目骨架', 'frontend', 0, 'admin', sysdate(), '测试模板');

INSERT INTO sys_project_template (id, project_id, template_id, template_type) VALUES
(9001, 9001, 9001, 'backend'),
(9002, 9001, 9002, 'admin_frontend'),
(9003, 9001, 9003, 'frontend');

-- 后端模板文件
INSERT INTO sys_template_file (template_file_id, template_id, file_name, module_id, file_path, file_content, create_by, create_time) VALUES
(900101, 9001, 'pom.xml.vm', NULL, 'pom.xml.vm',
'<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>${packageName}</groupId>
  <artifactId>${projectFileName}</artifactId>
  <version>1.0.0</version>
  <name>${projectName}</name>
</project>
', 'admin', sysdate()),
(900102, 9001, 'application.yml.vm', NULL, 'application.yml.vm',
'server:
  port: 8080
spring:
  application:
    name: ${projectFileName}
', 'admin', sysdate()),
(900103, 9001, 'README.md.vm', NULL, 'README.md.vm',
'# ${projectName}

包名：`${packageName}`

## 建表 SQL

```sql
${createTableSql}
```
', 'admin', sysdate()),
(900104, 9001, 'entity.java.vm', NULL, 'entity.java.vm',
'package ${packageName}.domain;

import java.math.BigDecimal;
import java.util.Date;

/**
 * ${functionName}实体
 */
public class ${ClassName} {
#foreach($column in $columns)
    /** ${column.columnComment} */
    private ${column.javaType} ${column.javaField};

#end
#foreach($column in $columns)
    public ${column.javaType} get${column.capJavaField}() {
        return ${column.javaField};
    }

    public void set${column.capJavaField}(${column.javaType} ${column.javaField}) {
        this.${column.javaField} = ${column.javaField};
    }

#end
}
', 'admin', sysdate()),
(900105, 9001, 'mapper.java.vm', NULL, 'mapper.java.vm',
'package ${packageName}.mapper;

import java.util.List;
import ${packageName}.domain.${ClassName};

public interface ${ClassName}Mapper {
    List<${ClassName}> select${ClassName}List(${ClassName} ${className});
}
', 'admin', sysdate()),
(900106, 9001, 'service.java.vm', NULL, 'service.java.vm',
'package ${packageName}.service;

import java.util.List;
import ${packageName}.domain.${ClassName};

public interface I${ClassName}Service {
    List<${ClassName}> select${ClassName}List(${ClassName} ${className});
}
', 'admin', sysdate()),
(900107, 9001, 'serviceImpl.java.vm', NULL, 'serviceImpl.java.vm',
'package ${packageName}.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import ${packageName}.domain.${ClassName};
import ${packageName}.mapper.${ClassName}Mapper;
import ${packageName}.service.I${ClassName}Service;

@Service
public class ${ClassName}ServiceImpl implements I${ClassName}Service {
    @Resource
    private ${ClassName}Mapper ${className}Mapper;

    @Override
    public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) {
        return ${className}Mapper.select${ClassName}List(${className});
    }
}
', 'admin', sysdate()),
(900108, 9001, 'controller.java.vm', NULL, 'controller.java.vm',
'package ${packageName}.controller;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;

@RestController
@RequestMapping("/${moduleName}/${businessName}")
public class ${ClassName}Controller {
    @Resource
    private I${ClassName}Service ${className}Service;

    @GetMapping("/list")
    public List<${ClassName}> list(${ClassName} query) {
        return ${className}Service.select${ClassName}List(query);
    }

$!controllerExtraMethods
}
', 'admin', sysdate()),
(900109, 9001, 'mapper.xml.vm', NULL, 'mapper.xml.vm',
'<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
    <select id="select${ClassName}List" resultType="${packageName}.domain.${ClassName}">
        select
#foreach($column in $columns)
            ${column.columnName}#if($foreach.hasNext),#end
#end
        from ${tableName}
    </select>
</mapper>
', 'admin', sysdate());

-- 后台前端模板文件
INSERT INTO sys_template_file (template_file_id, template_id, file_name, module_id, file_path, file_content, create_by, create_time) VALUES
(900201, 9002, 'package.json.vm', NULL, 'package.json.vm',
'{
  "name": "${projectFileName}-admin",
  "version": "1.0.0",
  "scripts": {
    "dev": "vue-cli-service serve"
  }
}
', 'admin', sysdate()),
(900202, 9002, 'api.js.vm', NULL, 'api.js.vm',
'import request from "@/utils/request"

export function list${ClassName}(query) {
  return request({
    url: "/${moduleName}/${businessName}/list",
    method: "get",
    params: query
  })
}
', 'admin', sysdate()),
(900203, 9002, 'index.vue.vm', NULL, 'index.vue.vm',
'<template>
  <div class="app-container">
    <el-table :data="list">
#foreach($column in $columns)
#if($column.isList == "1")
      <el-table-column label="${column.columnComment}" prop="${column.javaField}" />
#end
#end
    </el-table>
  </div>
</template>

<script>
import { list${ClassName} } from "@/api/${moduleName}/${businessName}"

export default {
  name: "${ClassName}",
  data() {
    return {
      list: []
    }
  },
  created() {
    list${ClassName}({}).then(res => {
      this.list = res.rows || res.data || []
    })
  }
}
</script>
', 'admin', sysdate());

-- 前台前端模板文件
INSERT INTO sys_template_file (template_file_id, template_id, file_name, module_id, file_path, file_content, create_by, create_time) VALUES
(900301, 9003, 'package.json.vm', NULL, 'package.json.vm',
'{
  "name": "${projectFileName}-web",
  "version": "1.0.0",
  "scripts": {
    "dev": "vite --host 0.0.0.0"
  }
}
', 'admin', sysdate()),
(900302, 9003, 'README.md.vm', NULL, 'README.md.vm',
'# ${projectName} 前台演示

这是代码生成平台的 frontend 类型测试模板。
', 'admin', sysdate()),
(900303, 9003, 'index.html.vm', NULL, 'index.html.vm',
'<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <title>${projectName}</title>
</head>
<body>
  <main id="app">
    <h1>${projectName}</h1>
    <p>Generated by RuoYi-Vue code generator.</p>
  </main>
</body>
</html>
', 'admin', sysdate());

-- 代码片段：只对 demo_product + controller.java.vm 生效
INSERT INTO sys_code_snippet (snippet_id, module_id, snippet_content, insert_point, template_file_name, relation_table_name, status, del_flag, create_by, create_time, remark) VALUES
(9001, 9001,
'    @GetMapping("/ping")
    public String ping() {
        return "demo-product-ok";
    }',
'controllerExtraMethods', 'controller.java.vm', 'demo_product', '0', '0', 'admin', sysdate(), '演示 Controller 插入点');

INSERT INTO sys_code_snippet_module (snippet_id, module_id) VALUES
(9001, 9001);

-- 后端项目结构
INSERT INTO sys_project_structure (node_id, parent_id, node_name, node_type, module, template_id, table_id, category, sort_order, status, create_by, create_time, update_by, update_time) VALUES
(900100, 0, '{projectName}', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900101, 900100, 'pom.xml', 'file', NULL, 9001, -1, 'pom.xml.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900102, 900100, 'README.md', 'file', NULL, 9001, -1, 'README.md.vm', 2, '0', 'admin', sysdate(), '', NULL),
(900103, 900100, 'src', 'folder', NULL, 9001, NULL, NULL, 3, '0', 'admin', sysdate(), '', NULL),
(900104, 900103, 'main', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900105, 900104, 'java', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900106, 900105, 'com', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900107, 900106, 'example', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900108, 900107, 'demo', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900109, 900108, 'domain', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900110, 900108, 'mapper', 'folder', NULL, 9001, NULL, NULL, 2, '0', 'admin', sysdate(), '', NULL),
(900111, 900108, 'service', 'folder', NULL, 9001, NULL, NULL, 3, '0', 'admin', sysdate(), '', NULL),
(900112, 900111, 'impl', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900113, 900108, 'controller', 'folder', NULL, 9001, NULL, NULL, 4, '0', 'admin', sysdate(), '', NULL),
(900114, 900104, 'resources', 'folder', NULL, 9001, NULL, NULL, 2, '0', 'admin', sysdate(), '', NULL),
(900115, 900114, 'mapper', 'folder', NULL, 9001, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900116, 900114, 'application.yml', 'file', NULL, 9001, -1, 'application.yml.vm', 2, '0', 'admin', sysdate(), '', NULL),
(900117, 900109, '{ClassName}.java', 'file', NULL, 9001, 0, 'entity.java.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900118, 900110, '{ClassName}Mapper.java', 'file', NULL, 9001, 0, 'mapper.java.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900119, 900111, 'I{ClassName}Service.java', 'file', NULL, 9001, 0, 'service.java.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900120, 900112, '{ClassName}ServiceImpl.java', 'file', NULL, 9001, 0, 'serviceImpl.java.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900121, 900113, '{ClassName}Controller.java', 'file', NULL, 9001, 0, 'controller.java.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900122, 900115, '{ClassName}Mapper.xml', 'file', NULL, 9001, 0, 'mapper.xml.vm', 1, '0', 'admin', sysdate(), '', NULL);

-- 后台前端项目结构
INSERT INTO sys_project_structure (node_id, parent_id, node_name, node_type, module, template_id, table_id, category, sort_order, status, create_by, create_time, update_by, update_time) VALUES
(900200, 0, '{projectName}-admin', 'folder', NULL, 9002, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900201, 900200, 'package.json', 'file', NULL, 9002, -1, 'package.json.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900202, 900200, 'src', 'folder', NULL, 9002, NULL, NULL, 2, '0', 'admin', sysdate(), '', NULL),
(900203, 900202, 'api', 'folder', NULL, 9002, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900204, 900203, 'demo', 'folder', NULL, 9002, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900205, 900202, 'views', 'folder', NULL, 9002, NULL, NULL, 2, '0', 'admin', sysdate(), '', NULL),
(900206, 900205, 'demo', 'folder', NULL, 9002, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900207, 900206, '{businessName}', 'folder', NULL, 9002, 0, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900208, 900204, '{businessName}.js', 'file', NULL, 9002, 0, 'api.js.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900209, 900207, 'index.vue', 'file', NULL, 9002, 0, 'index.vue.vm', 1, '0', 'admin', sysdate(), '', NULL);

-- 前台前端项目结构
INSERT INTO sys_project_structure (node_id, parent_id, node_name, node_type, module, template_id, table_id, category, sort_order, status, create_by, create_time, update_by, update_time) VALUES
(900300, 0, '{projectName}-web', 'folder', NULL, 9003, NULL, NULL, 1, '0', 'admin', sysdate(), '', NULL),
(900301, 900300, 'package.json', 'file', NULL, 9003, -1, 'package.json.vm', 1, '0', 'admin', sysdate(), '', NULL),
(900302, 900300, 'README.md', 'file', NULL, 9003, -1, 'README.md.vm', 2, '0', 'admin', sysdate(), '', NULL),
(900303, 900300, 'index.html', 'file', NULL, 9003, -1, 'index.html.vm', 3, '0', 'admin', sysdate(), '', NULL);

SET FOREIGN_KEY_CHECKS = 1;
