Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
76254653
Commit
76254653
authored
Sep 29, 2018
by
feixiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dao Data生成
parent
965d4f1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
240 additions
and
0 deletions
+240
-0
src/Commands/ClassTemplate/Dao/ClassTemplate
+66
-0
src/Commands/ClassTemplate/Data/ClassTemplate
+29
-0
src/Commands/GenerateCommand
+145
-0
No files found.
src/Commands/ClassTemplate/Dao/ClassTemplate
0 → 100644
View file @
76254653
<?php
/**
* Created by PhpStorm.
* User: Argericy
* Date: 2018/7/23
* Time: 15:54
*/
namespace App\Models\Dao;
use App\Models\Entity\{entityName};
use Swoft\Bean\Annotation\Bean;
use Hdll\Services\Common\Exception\CommonException;
/**
* @Bean()
* Class {className}
* @package App\Models\Dao
*/
class {className}
{
public function create(array $info) : {entityName}
{
${entityName} = new {entityName}($info);
$res = ${entityName}->save()->getResult();
if ( $res === false ) {
throw new CommonException(["msg" => "数据库操作错误", "code" => 500]);
}
return ${entityName};
}
public function selectInfoByCondition($condition, $field)
{
return {entityName}::findAll($condition, ['fields' => $field])->getResult();
}
public function getInfoByCondition($condition, $field)
{
return {entityName}::findOne($condition, ['fields' => $field])->getResult();
}
/**
* 根据条件更新信息
* @param $condition
* @param $updateInfo
* @return mixed
*/
public function updateByCondition($condition, $updateInfo)
{
return {entityName}::updateAll($updateInfo, $condition)->getResult();
}
/**
* 更新一条记录
*
* @param $condition
* @param $updateInfo
* @return mixed
*/
public function updateOne($condition, $updateInfo)
{
return {entityName}::updateOne($updateInfo, $condition)->getResult();
}
}
\ No newline at end of file
src/Commands/ClassTemplate/Data/ClassTemplate
0 → 100644
View file @
76254653
<?php
/**
* Created by PhpStorm.
* User: Argericy
* Date: 2018/9/29
* Time: 11:35
*/
namespace App\Models\Data;
use App\Models\Dao\{daoName};
use Swoft\Bean\Annotation\Bean;
use Swoft\Bean\Annotation\Inject;
/**
* @Bean()
*
* Class {dataName}
* @package App\Models\Data
*/
class {dataName}
{
/**
* @Inject()
* @var {daoName}
*/
private ${daoName};
}
\ No newline at end of file
src/Commands/GenerateCommand
0 → 100644
View file @
76254653
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace App\Commands\Common;
use Swoft\Console\Bean\Annotation\Command;
use Swoft\Console\Bean\Annotation\Mapping;
use Swoft\Console\Input\Input;
use Swoft\Console\Output\Output;
use Swoft\Task\Task;
/**
* Test command
*
* @Command(coroutine=false)
*/
class GenerateCommand
{
/**
* this generate command
*
* @Usage
* generate:dao [options]
*
* @Options
* -n,--n the dao name
* -e, --e the entity name
*
* @Example
* php swoft generate:dao -e entityName [-n daoName]
*
* @param Input $input
* @param Output $output
*
* @Mapping("dao")
*/
public function Dao(Input $input, Output $output)
{
var_dump(alias('@commonCommands'));
$className = $input->getOpt('n');
$entityName = $input->getOpt('e');
$this->generateDao($output, $className, $entityName);
}
/**
* this generate command
*
* @Usage
* generate:all [options]
*
* @Options
* -n,--n the dao name
* -e, --e the entity name
*
* @Example
* php swoft generate:dao -e entityName [-n dataName] [--dao-name daoName]
*
* @param Input $input
* @param Output $output
*
* @Mapping("all")
*/
public function all(Input $input, Output $output)
{
$dataName = $input->getOpt('n');
$entityName = $input->getOpt('e');
$daoName = $input->getOpt('dao-name');
$appPath = alias('@app');
$dataName = empty($dataName)?$entityName.'Data':$dataName;
//generateDao
$daoName = empty($daoName)?$entityName.'Dao':$daoName;
$this->generateDao($output, $daoName, $entityName);
//generateData
$dataPath = $appPath.'/Models/Data/'.$dataName.'.php';
$templatePath = $appPath.'/Commands/Common/ClassTemplate/Data/ClassTemplate';
$content = file_get_contents($templatePath);
$content = str_replace('{dataName}', $dataName, $content);
$content = str_replace("{daoName}", $daoName, $content);
file_put_contents($dataPath, $content);
}
private function generateDao($output,$daoName, $entityName)
{
if ( empty($entityName) ) {
$output->writeln("the en option is required", true, true);
}
$daoName = empty($daoName)?$entityName.'Dao':$daoName;
$daoPath = alias("@app").'/Models/Dao/'.$daoName.'.php';
$templatePath = alias("@app").'/Commands/Common/ClassTemplate/Dao/ClassTemplate';
$content = file_get_contents($templatePath);
$content = str_replace("{className}", $daoName,$content);
$content = str_replace("{entityName}", $entityName, $content);
file_put_contents($daoPath,$content);
}
/**
* this task command
*
* @Usage
* test:{command} [arguments] [options]
*
* @Options
* -o,--o this is command option
*
* @Arguments
* arg this is argument
*
* @Example
* php swoft test:task
*
* @Mapping()
*/
public function task()
{
$result = Task::deliver('sync', 'console', ['console']);
var_dump($result);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment