Преглед изворни кода

中铁二局的数据字典的创立

ChenWuJie пре 4 година
родитељ
комит
c66b059f63

+ 54 - 0
app/Http/Controllers/Admin/CommonController.php

xqd
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 陈武杰
+ * Date: 2021/1/24
+ * Time: 14:31
+ */
+
+namespace App\Http\Controllers\Admin;
+
+
+class CommonController
+{
+    public function doc()
+    {
+        $database = env('DB_DATABASE');
+        $prefix = '';
+        $exclude_tables = "'admin_access','admin_menus','admin_operate_logs','admin_roles','admin_user_resets','admin_users'
+                          ,'base_area','base_attachments','base_dictionary'
+                          ,'oauth_access_tokens','oauth_auth_codes','oauth_clients','oauth_personal_access_clients','oauth_refresh_tokens'
+                          ,'migrations','cache'
+                          ";
+
+        $sql = "select TABLE_NAME name,TABLE_COMMENT comment from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='".$database."' and TABLE_NAME not in (".$exclude_tables.")";
+        $tables = \DB::select($sql);
+        $map1 = $map2 = [];
+        $i = round(count($tables)/2);
+        foreach ($tables as $k => $v) {
+            $name = str_replace($prefix, '', $v->name);
+            if ($k >= $i) {
+                $map1[$v->name] = $name.'('.$v->comment.')';
+            }
+            else {
+                $map2[$v->name] = $name.'('.$v->comment.')';
+            }
+        }
+
+        $data1 = [];
+        foreach ($map1 as $k => $v){
+            $sql = "select COLUMN_NAME name, DATA_TYPE type, COLUMN_COMMENT comment from INFORMATION_SCHEMA.COLUMNS where table_schema = '".$database."' AND table_name = '".$k."'";
+            $comment = \DB::select($sql);
+            $data1[$v] = $comment;
+        }
+
+        $data2 = [];
+        foreach ($map2 as $k => $v){
+            $sql = "select COLUMN_NAME name, DATA_TYPE type, COLUMN_COMMENT comment from INFORMATION_SCHEMA.COLUMNS where table_schema = '".$database."' AND table_name = '".$k."'";
+            $comment = \DB::select($sql);
+            $data2[$v] = $comment;
+        }
+
+        return view('doc', ['data1' => $data1, 'data2' => $data2]);
+    }
+}

+ 2 - 0
app/Providers/AppServiceProvider.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Providers;
 
+use Illuminate\Support\Facades\Schema;
 use Illuminate\Support\ServiceProvider;
 
 class AppServiceProvider extends ServiceProvider
@@ -14,6 +15,7 @@ class AppServiceProvider extends ServiceProvider
     public function boot()
     {
         //
+        Schema::defaultStringLength(191);
     }
 
     /**

+ 106 - 0
database/migrations/2021_01_24_100701_add_all_devices_table_comment.php

xqd
@@ -0,0 +1,106 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\DB;
+
+class AddAllDevicesTableComment extends Migration
+{
+    public function boot()
+    {
+        Schema::defaultStringLength(191);
+    }
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        //inner_devices表
+        Schema::table('inner_devices', function (Blueprint $table) {
+            $table->string('device_name_id')->comment('设备名称编号')->change();
+            $table->string('quantity')->comment('数量')->change();
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('project_id')->comment('项目名称id')->change();
+            $table->string('work_point_id')->comment('工点id')->change();
+        });
+        DB::statement("ALTER TABLE `inner_devices` comment '内部设备表'");
+
+        //order_devices 租赁设备表
+        Schema::table('order_devices', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('order_id')->comment('订单id')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('project_id')->comment('项目名称id')->change();
+            $table->string('device_id')->comment('设备类型id')->change();
+            $table->string('inner_device_id')->comment('内部设备id')->change();
+            $table->string('spec_id')->comment('设备类型id')->change();
+            $table->string('device_name_id')->comment('设备名称编号')->change();
+            $table->string('quantity')->comment('数量')->change();
+            $table->string('price')->comment('单价 单位:分')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+            $table->string('start_date')->comment('租赁开始时间')->change();
+            $table->string('end_date')->comment('租赁结束时间')->change();
+        });
+        DB::statement("ALTER TABLE `order_devices` comment '租赁设备表'");
+
+
+        //devices表
+        Schema::table('devices', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('设备类型名称')->change();
+            $table->string('sort')->comment('排序等级')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `devices` comment '设备类型表'");
+
+
+        //device_names表
+        Schema::table('device_names', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('设备名称')->change();
+            $table->string('sort')->comment('排序等级')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `device_names` comment '设备名称表'");
+
+
+        //repair_devices 表
+        Schema::table('repair_devices', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('project_id')->comment('项目id')->change();
+            $table->string('work_point_id')->comment('工点id')->change();
+            $table->string('inner_device_id')->comment('内部设备id')->change();
+            $table->string('money')->comment('维修总金额')->change();
+            $table->string('reason')->comment('维修原因')->change();
+            $table->string('day')->comment('维修日期')->change();
+            $table->string('remark')->comment('备注')->change();
+            $table->string('start_date')->comment('开始时间')->change();
+            $table->string('end_date')->comment('结束时间')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+
+        });
+        DB::statement("ALTER TABLE `repair_devices` comment '维修记录表'");
+
+
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 69 - 0
database/migrations/2021_01_24_113828_add_all_user_table_comment.php

xqd
@@ -0,0 +1,69 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddAllUserTableComment extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        //users 表
+        Schema::table('users', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('role_id')->comment('角色id')->change();
+            $table->string('phone')->comment('联系电话')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('password')->comment('密码')->change();
+            $table->string('open_id')->comment('微信open_id')->change();
+            $table->string('union_id')->comment('微信union_id')->change();
+            $table->string('nickname')->comment('昵称')->change();
+            $table->string('avatar')->comment('头像')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+
+        });
+        DB::statement("ALTER TABLE `users` comment '用户表'");
+
+        //user_resets 表
+        Schema::table('user_resets', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('phone')->comment('联系电话')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+
+        });
+        DB::statement("ALTER TABLE `user_resets` comment '用户密码重置记录表'");
+
+        //user_auths 表
+        Schema::table('user_auths', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('phone')->comment('联系电话')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('project_id')->comment('项目id')->change();
+            $table->string('project_role_id')->comment('项目申请的角色id')->change();
+            $table->string('remark')->comment('备注')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `user_auths` comment '用户授权表'");
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 87 - 0
database/migrations/2021_01_24_134009_add_all_project_table_comment.php

xqd
@@ -0,0 +1,87 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddAllProjectTableComment extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        //project_roles 表
+        Schema::table('project_roles', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('level')->comment('级别')->change();
+        });
+        DB::statement("ALTER TABLE `project_roles` comment '项目角色表'");
+
+        //project_role_rights 表
+        Schema::table('project_role_rights', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('right_id')->comment('权限id')->change();
+            $table->string('project_role_id')->comment('项目角色id')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `project_role_rights` comment '项目角色权限管理表'");
+
+        //rights 表
+        Schema::table('rights', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('key')->comment('键')->change();
+            $table->string('sort')->comment('排序等级')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `rights` comment '权限表'");
+
+        //project_users 表
+        Schema::table('project_users', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('project_id')->comment('项目id')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('project_role_id')->comment('项目角色id')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `project_users` comment '项目用户表'");
+
+        //projects 表
+        Schema::table('projects', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('项目名称')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `projects` comment '项目表'");
+
+        //work_points 表
+        Schema::table('work_points', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('项目名称')->change();
+            $table->string('project_id')->comment('项目id')->change();
+            $table->string('status')->comment('状态')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `work_points` comment '工点管理表'");
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 72 - 0
database/migrations/2021_01_24_141328_add_all_order_table_comment.php

xqd
@@ -0,0 +1,72 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddAllOrderTableComment extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        //orders 表
+        Schema::table('orders', function (Blueprint $table) {
+            $table->string('work_point_id')->comment('工点id')->change();
+            $table->string('remark')->comment('备注')->change();
+            $table->string('status')->comment('状态')->change();
+            $table->string('order_number')->comment('订单号')->change();
+            $table->string('project_id')->comment('项目id')->change();
+            $table->string('user_id')->comment('用户id')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `orders` comment '订单表'");
+
+        //specs 表
+        Schema::table('specs', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('device_name_id')->comment('设备名称id')->change();
+            $table->string('device_id')->comment('设备id')->change();
+            $table->string('sort')->comment('排序等级')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `specs` comment '设备规格表'");
+
+        //roles 表
+        Schema::table('roles', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('key')->comment('键名')->change();
+            $table->string('sort')->comment('排序等级')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `roles` comment '角色表'");
+
+        //rent_types 表
+        Schema::table('rent_types', function (Blueprint $table) {
+            $table->string('id')->comment('自增id')->change();
+            $table->string('name')->comment('名称')->change();
+            $table->string('sort')->comment('排序等级')->change();
+            $table->string('created_at')->comment('创建时间')->change();
+            $table->string('updated_at')->comment('更新时间')->change();
+        });
+        DB::statement("ALTER TABLE `rent_types` comment '租赁类型表'");
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+}

+ 80 - 0
resources/views/doc.blade.php

xqd
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>部分数据表字典</title>
+    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">
+</head>
+
+<body style="font-size: 15px; margin: 25px;">
+<div style="text-align: center"><h1>部分数据表字典</h1></div>
+<div class="row">
+    <div class="col-sm-6">
+        <?php foreach ($data1 as $k => $v){ ?>
+        <div class="ibox float-e-margins">
+            <div class="ibox-title">
+                <h2 style="margin-top: -5px;">{{$k}}</h2>
+            </div>
+            <div class="ibox-content">
+
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th>字段名</th>
+                        <th>字段类型</th>
+                        <th>字段注释</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <?php foreach ($v as $vv){ ?>
+                    <tr>
+                        <td>{{$vv->name}}</td>
+                        <td>{{$vv->type}}</td>
+                        <td>{{$vv->comment}}</td>
+                    </tr>
+                    <?php }?>
+                    </tbody>
+                </table>
+
+            </div>
+        </div>
+        <?php }?>
+    </div>
+
+    <div class="col-sm-6">
+        <?php foreach ($data2 as $k => $v){ ?>
+        <div class="ibox float-e-margins">
+            <div class="ibox-title">
+                <h2 style="margin-top: -5px;">{{$k}}</h2>
+            </div>
+            <div class="ibox-content">
+
+                <table class="table table-bordered">
+                    <thead>
+                    <tr>
+                        <th>字段名</th>
+                        <th>字段类型</th>
+                        <th>字段注释</th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <?php foreach ($v as $vv){ ?>
+                    <tr>
+                        <td>{{$vv->name}}</td>
+                        <td>{{$vv->type}}</td>
+                        <td>{{$vv->comment}}</td>
+                    </tr>
+                    <?php }?>
+                    </tbody>
+                </table>
+
+            </div>
+        </div>
+        <?php }?>
+    </div>
+</div>
+</body>
+
+</html>

+ 1 - 0
routes/admin.php

xqd
@@ -12,6 +12,7 @@
 */
 //
 Route::get('test', 'TestController@index');
+Route::get('doc', 'CommonController@doc');
 Route::get('login', 'Auth\LoginController@showLoginForm')->name('admin.login');
 Route::post('login','Auth\LoginController@login');
 Route::get('logout', 'Auth\LoginController@logout');