Skip to content

Commit

Permalink
up: update some for json to dto code
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 4, 2021
1 parent 432f556 commit 770fe34
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 101 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Kite is a tool for help development.
**Required:**

- git
- php 7.4+
- php 8.0+
- composer

### Install by script
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ PHP编写的,方便本地开发和使用的个人CLI工具应用。
**系统环境依赖**

- git
- php 7.4+
- php 8.0+
- composer

> TIP: 支持windows 10
**脚本安装**
**脚本安装(推荐)**

> file: [install.sh](./install.sh)
```bash
curl https://raw.githubusercontent.com/inhere/kite/master/install.sh | bash
```

**手动安装**
**手动安装(推荐)**

```bash
cd ~
Expand Down
19 changes: 13 additions & 6 deletions app/Console/Controller/JsonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
use Toolkit\PFlag\FlagsParser;
use Toolkit\Stdlib\Arr;
use Toolkit\Stdlib\Helper\JsonHelper;
use Toolkit\Stdlib\OS;
use function gettype;
use function is_file;
use function is_scalar;
use function json_decode;
use function str_contains;
use function trim;
use const JSON_THROW_ON_ERROR;

/**
* Class DemoController
Expand Down Expand Up @@ -307,8 +309,11 @@ public function toClassCommand(FlagsParser $fs, Output $output): void

$comments = [];
if (str_contains($json, '//')) {
$p = TextParser::newWithParser($json, new Json5LineParser());
$p->parse();
$p = TextParser::newWithParser($json, new Json5LineParser())
->withConfig(function (TextParser $p) {
$p->headerSep = "\n//###\n";
})
->parse();

$comments = $p->getStringMap('field', 'comment');
// $output->aList($comments);
Expand Down Expand Up @@ -340,15 +345,17 @@ public function toClassCommand(FlagsParser $fs, Output $output): void
//
// }

$settings = [];
$settings = [
'user' => OS::getUserName(),
];
$tplVars = [
'settings' => $settings,
'fields' => $fields,
'ctx' => $settings,
'fields' => $fields,
];
$contents = $tplEng->apply($tplVars);

$output->colored('------------------ Generated Codes -------------------');
$output->writeRaw($contents);
$output->success('Complete');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Plugin/AbstractPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function getInfo(): array
/**
* @return array
*/
public function getOptions(): array
final public function getOptions(): array
{
return $this->options();
}
Expand Down
11 changes: 11 additions & 0 deletions app/Lib/Parser/Text/TextParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ public function withText(string $text): self
return $this;
}

/**
* @param Closure $fn
*
* @return TextParser
*/
public function withConfig(Closure $fn): self
{
$fn($this);
return $this;
}

/**
* @param callable $lineFilter
*
Expand Down
12 changes: 0 additions & 12 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,3 @@ chmod a+x bin/kite
# link bin file to ENV path
ln -s "$PWD"/bin/htu /usr/local/bin/htu
ln -s "$PWD"/bin/kite /usr/local/bin/kite

# gen completion script
#kite --auto-completion \
# --shell-env "$SHELL" \
# --gen-file ~/.oh-my-zsh/completions/_kite \
# --tpl-file resource/templates/completion/zsh.tpl

# gen oh-my-zsh plugin script
#kite --auto-completion \
# --shell-env "$SHELL" \
# --gen-file ~/.oh-my-zsh/custom/plugins/kite/kite.plugin.zsh \
# --tpl-file resource/templates/completion/zsh.plugin.tpl
20 changes: 3 additions & 17 deletions resource/templates/dto-class/java-data-dto.tpl
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
package com.kezhilian.wzl.service.provider.order.dto;
package {= ctx.pkgName | default:org.example.entity};

import com.alibaba.fastjson.annotation.JSONField;
// import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
* @author inhere
* @author {= ctx.user | default:inhere}
*/
@Data
public class PayQueryReqDTO {
/**
* 店铺id
*/
@NotNull
@Min(1)
private Long sid;
/**
* 订单号
*/
@NotBlank
private String orderno;
/**
* 发起支付后得到的三方支付单号
*/
@NotBlank
@JSONField(name = "payOrderno")
private String payOrderno;
}
52 changes: 2 additions & 50 deletions resource/templates/dto-class/java-entity-dto.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kezhilian.wzl.service.order.entity;
package {= ctx.pkgName | default:org.example.entity};

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
Expand All @@ -21,55 +21,7 @@ public class OrderLog implements Serializable {
private Integer id;
/**
* 店铺SID
*/
@TableField(value = "sid")
private Integer sid;
/**
* 订单用户ID
*/
@TableField(value = "uid")
private Integer uid;
/**
* 订单ID
*/
@TableField(value = "order_id")
private Integer orderId;
/**
* 订单编号
*/
@TableField(value = "orderno")
private String orderno;
/**
* 日志类型,1=用户下单
*/
@TableField(value = "type")
private Byte type;
/**
* 日志描述
*/
@TableField(value = "message")
private String message;
/**
* 时间
*/
@TableField(value = "ctime")
private Integer ctime;
/**
* 日志标识
*/
@TableField(value = "code")
private String code;
/**
* 日志内容
* 内容
*/
@TableField(value = "content")
private String content;
Expand Down
14 changes: 3 additions & 11 deletions resource/templates/dto-class/php-data-dto.tpl
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
<?php declare(strict_types=1);

namespace {= };
namespace {= ctx.namespace | default:YourNamespace};

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
* @author inhere
* @author {= ctx.user | default:inhere}
*/
@Data
public class PayQueryReqDTO {
/**
* 店铺id
*/
@NotNull
@Min(1)
private Long sid;
class {= ctx.className | default:YourClass} {
/**
* 订单号
Expand Down
11 changes: 11 additions & 0 deletions script/gen-kite-auto-completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# gen oh-my-zsh plugin script
kite --auto-completion \
--shell-env "$SHELL" \
--gen-file ~/.oh-my-zsh/custom/plugins/kite/kite.plugin.zsh \
--tpl-file resource/templates/completion/zsh.plugin.tpl

# gen completion script
#kite --auto-completion \
# --shell-env "$SHELL" \
# --gen-file ~/.oh-my-zsh/completions/_kite \
# --tpl-file resource/templates/completion/zsh.tpl

0 comments on commit 770fe34

Please sign in to comment.