lhj-tools 0.1.35 → 0.1.38

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acf5100c519b9b7580d251efae32f735575f9c827959517ca25cee51501f96ab
4
- data.tar.gz: eab05a25fd97bfc21902294ab0204eda81e25f85a29c01edd2b4c99c0563b3dc
3
+ metadata.gz: b4b7a07edf3348968838d40729cca25f41ba64ce15e201923d13d931590e7e97
4
+ data.tar.gz: 5c5ec0c49a7653d41c07dab04c2838f8b10e94bb986eb645e2eeb3c664a61536
5
5
  SHA512:
6
- metadata.gz: b35f861355ebc4bbc29a22e9c306c573e845d07a0642d9c795030fc86f93ea3c362ce857938f2fb352ca36b297db3df1cbe39d314787fef33461254cd98205e0
7
- data.tar.gz: '09797b52b0e1b82ce17fa386bd6c0f6f21ad5deb1aafd392a1c19cd0b2a2adcaf4b695453b51e8a9ee1ca64068ea4df1965d208ebc19404e572b1feb60329c9d'
6
+ metadata.gz: 672eee52600ff602c54aa7ae0a98e2dd418b33efac5b0ccbe3dc61ca47008a6af9eb7a124087437265b77663a5f0b92a87a4efef80d852fc38d93717afa66437
7
+ data.tar.gz: eac0a1544282d3e4826419fb5e7e8648c067d3664717630d89da95632eae0a69f3eee1931e9cee65d218bc7a33ac0da7dbb53615b1f8adbe06d0dd491a275a08
@@ -0,0 +1,34 @@
1
+ module Lhj
2
+ class Command
3
+ class CodeTemplate < Command
4
+ self.summary = '生成源码模板'
5
+ self.description = '生成的代码模板'
6
+
7
+ CODE_TEMPLATE_INDEX = [{ name: 'dispatch Source 模板', template: 'dispatch_source.erb' },
8
+ { name: '消息队列', template: 'message_query.erb' },
9
+ { name: '代码模板', template: 'test.erb' }].freeze
10
+
11
+ def initialize(argv)
12
+ @cli = HighLine.new
13
+ super
14
+ end
15
+
16
+ def handle
17
+ CODE_TEMPLATE_INDEX.each_index do |i|
18
+ puts "#{i}.#{CODE_TEMPLATE_INDEX[i][:name]}".yellow
19
+ end
20
+ idx = @cli.ask('请选择查看代码模板: '.green).strip.to_i
21
+ item = CODE_TEMPLATE_INDEX[idx]
22
+ template_name = item[:template]
23
+ template_str = render_template(template_name)
24
+ puts template_str
25
+ end
26
+
27
+ def render_template(template_name)
28
+ temp_str = File.read(File.join(File.dirname(__FILE__), 'template', template_name))
29
+ Lhj::ErbFormatter::Service.new(self).render_template(temp_str)
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ @implementation ODOrderTimerManager
2
+
3
+ + (instancetype)sharedInstance {
4
+ static dispatch_once_t onceToken;
5
+ static ODOrderTimerManager *instance = nil;
6
+ dispatch_once(&onceToken,^{
7
+ instance = [[ODOrderTimerManager alloc] init];
8
+ });
9
+ return instance;
10
+ }
11
+
12
+ - (void)calcOrderPay:(NSString *)orderId timeout:(NSInteger)timeout
13
+ {
14
+ self.leftTime = timeout;
15
+ self.orderId = orderId;
16
+ if(self.timer){
17
+ dispatch_source_cancel(self.timer);
18
+ }
19
+ if(timeout > 0){
20
+ self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0));
21
+ dispatch_source_set_timer(self.timer, DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC, 0);
22
+ __weak __typeof(self)weakSelf = self;
23
+ dispatch_source_set_event_handler(self.timer, ^{
24
+ if(weakSelf.leftTime <= 0){ //倒計時結束,關閉
25
+ [[NSNotificationCenter defaultCenter] postNotificationName:kOrderTimerFinishedNotification object:nil];
26
+ dispatch_source_cancel(weakSelf.timer);
27
+ }else{
28
+ [[NSNotificationCenter defaultCenter] postNotificationName:kOrderTimerProcessingNotification object:@(self.leftTime)];
29
+ weakSelf.leftTime--;
30
+ }
31
+ });
32
+ dispatch_resume(self.timer);
33
+ }
34
+ }
35
+
36
+ @end
@@ -0,0 +1,58 @@
1
+ - (void)handleWithBlock:(void (^)(AMGoodsSellingMessageModel *, void(^completion)(BOOL finished, AMGoodsSellingMessageModel *current)))block completion:(void (^)(AMGoodsSellingMessageModel *, void(^)(BOOL)))completion
2
+ {
3
+ dispatch_once(&onceMessageQueueManagerToken, ^{
4
+ [self processWithPreModel:nil block:block completion:completion];
5
+ });
6
+ }
7
+
8
+ - (void)processWithPreModel:(AMGoodsSellingMessageModel *)preModel block:(void (^)(AMGoodsSellingMessageModel *, void(^completion)(BOOL finished, AMGoodsSellingMessageModel *current)))block completion:(void (^)(AMGoodsSellingMessageModel *, void(^)(BOOL)))completion
9
+ {
10
+ AMGoodsSellingMessageModel *next = [self popModel];
11
+ if(next && block){
12
+ __weak __typeof(self)weakSelf = self;
13
+ if(preModel){
14
+ if(![next isEqual:preModel]){
15
+ next.animationType = AMMessageAnimationTypeReShowAndAnimation;
16
+ next.currentNum = MAX(1, [next.sellingNumber integerValue]);
17
+ }else{
18
+ next.animationType = AMMessageAnimationTypeAnimation;
19
+ NSInteger num = MAX(1, [next.sellingNumber integerValue]);
20
+ next.currentNum = preModel.currentNum + num;
21
+ }
22
+ }else{
23
+ next.animationType = AMMessageAnimationTypeShowAndAnimation;
24
+ next.currentNum = MAX(1, [next.sellingNumber integerValue]);
25
+ }
26
+ next.displayNumber = [NSString stringWithFormat:@"%ld", next.currentNum];
27
+ block(next, ^(BOOL finished, AMGoodsSellingMessageModel *current){
28
+ if(finished){
29
+ [weakSelf processWithPreModel:next block:block completion:completion];
30
+ }
31
+ });
32
+ }else{
33
+ if(completion){
34
+ completion(preModel, ^(BOOL finished){
35
+ onceMessageQueueManagerToken = 0;
36
+ });
37
+ }
38
+ }
39
+ }
40
+
41
+ -(void)beginProductSoldOutAnimation
42
+ {
43
+ __weak __typeof(self)weakSelf = self;
44
+ [[AMMessageQueueManager sharedInstance] handleWithBlock:^(AMGoodsSellingMessageModel * model, void (^ _Nonnull completion)(BOOL ,AMGoodsSellingMessageModel *)) {
45
+ if(model){
46
+ [weakSelf productSoldOutViewAnimation:model completion:^(BOOL finished, AMGoodsSellingMessageModel *current) {
47
+ completion(finished, current);
48
+ }];
49
+ }
50
+ } completion:^(AMGoodsSellingMessageModel *preModel, void (^ _Nonnull finishCallback)(BOOL)) {
51
+ NSInteger des = preModel ? preModel.dismissSec : 3;
52
+ [[AMMessageTimerManager sharedInstance] scheduledWithMessageType:AMCustomMessageTypeGoodsSelling timeout:des completion:^{
53
+ [weakSelf hideProductSoldOutView:^(BOOL finished) {
54
+ finishCallback(finished);
55
+ }];
56
+ }];
57
+ }];
58
+ }
File without changes
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'lhj/helper/oss_helper'
3
+ require 'highline'
3
4
 
4
5
  module Lhj
5
6
  class Command
@@ -7,42 +8,24 @@ module Lhj
7
8
  class Del < OSS
8
9
  self.summary = '删除OSS的key'
9
10
 
10
- self.arguments = [
11
- CLAide::Argument.new('--key=XX', true),
12
- CLAide::Argument.new('--type=XX', true)
13
- ]
14
-
15
- def self.options
16
- [
17
- %w[--key OSS对应的key],
18
- %w[--type OSS对应的类型]
19
- ]
20
- end
21
-
22
11
  def initialize(argv)
23
- @key = argv.option('key')
24
- @type = argv.option('type')
25
- super
26
- end
27
-
28
- def validate!
29
- help! '请输入key或者类型' unless @key || @type
12
+ @cli = HighLine.new
30
13
  super
31
14
  end
32
15
 
33
16
  def handle
34
- if @type
35
- objects = Lhj::OSS::Helper.instance.list
36
- objects.each do |o|
37
- if /#{@type}/ =~ o.key
38
- puts "成功删除#{o.key}"
39
- Lhj::OSS::Helper.instance.delete(o.key)
40
- end
41
- end
42
- else
43
- Lhj::OSS::Helper.instance.delete(@key)
17
+ objects = Lhj::OSS::Helper.instance.list
18
+ obj_keys = []
19
+ objects.each_with_index do |o, i|
20
+ obj_keys << o.key
21
+ puts "#{i}.#{o.key}".yellow
44
22
  end
23
+ idx = @cli.ask('请选择删除的key: '.green).strip.to_i
24
+ oss_key = obj_keys[idx]
25
+ puts "删除的key为:#{oss_key}".red
26
+ Lhj::OSS::Helper.instance.delete(oss_key)
45
27
  end
28
+
46
29
  end
47
30
  end
48
31
  end
@@ -0,0 +1,38 @@
1
+
2
+ # frozen_string_literal: true
3
+ require 'lhj/helper/oss_helper'
4
+ require 'highline'
5
+
6
+ module Lhj
7
+ class Command
8
+ class OSS < Command
9
+ class Download < OSS
10
+ self.summary = '下载OSS'
11
+
12
+ def initialize(argv)
13
+ @current_path = argv.shift_argument || Dir.pwd
14
+ @cli = HighLine.new
15
+ super
16
+ end
17
+
18
+ def handle
19
+ objects = Lhj::OSS::Helper.instance.list
20
+ obj_keys = []
21
+ objects.each_with_index do |o, i|
22
+ obj_keys << o.key
23
+ puts "#{i}.#{o.key}".yellow
24
+ end
25
+ idx = @cli.ask('请选择下载的序号: '.green).strip.to_i
26
+ oss_key = obj_keys[idx]
27
+ puts "下载的key为:#{oss_key}".yellow
28
+
29
+ file_key = oss_key.split('/').last
30
+ file = File.join(@current_path, file_key)
31
+ Lhj::OSS::Helper.instance.down_load(oss_key, file)
32
+ puts "下载文件到目录: #{file}\n".yellow
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -10,8 +10,8 @@ module Lhj
10
10
  def handle
11
11
  objects = Lhj::OSS::Helper.instance.list
12
12
  rows = []
13
- objects.each do |o|
14
- path = "#{Lhj::OSS::Helper.instance.url_path}/#{o.key}"
13
+ objects.each_with_index do |o, i|
14
+ path = "#{i}.#{Lhj::OSS::Helper.instance.url_path}/#{o.key}"
15
15
  rows << [path]
16
16
  end
17
17
  table = Terminal::Table.new title: 'OSS List', headings: ['URL'], rows: rows
@@ -1,50 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'lhj/helper/oss_helper'
4
+ require 'highline'
4
5
 
5
6
  module Lhj
6
7
  class Command
7
8
  class OSS < Command
8
9
  # OSS file upload
9
10
  class Upload < OSS
10
- self.summary = '上传文件'
11
+ self.summary = '上传文件(添加标签 --tag=XX)'
11
12
 
12
13
  self.arguments = [
13
- CLAide::Argument.new('type', false),
14
- CLAide::Argument.new('name', false),
15
14
  CLAide::Argument.new('tag', false)
16
15
  ]
17
16
 
18
17
  def self.options
19
18
  [
20
- %w[--type 文件类型],
21
- %w[--name 文件名],
22
19
  %w[--tag 标签]
23
20
  ]
24
21
  end
25
22
 
26
- def validate!
27
- super
28
- help! '类型或名字必须输入' unless @name || @type
29
- end
30
-
31
23
  def initialize(argv)
32
24
  @current_path = argv.shift_argument || Dir.pwd
33
- @type = argv.option('type')
34
- @name = argv.option('name')
35
25
  @tag = argv.option('tag')
26
+ @cli = HighLine.new
36
27
  super
37
28
  end
38
29
 
39
30
  def handle
40
- Dir.glob("#{@current_path}/*").each do |f|
41
- file_name = File.basename(f)
42
- if @name && /#{@name}/ =~ file_name
43
- upload(f, file_name)
44
- elsif @type && /#{@type}/ =~ file_name
45
- upload(f, file_name)
46
- end
31
+ file_list = []
32
+ file_name_list = []
33
+ Dir.glob("#{@current_path}/*").each_with_index do |f, i|
34
+ file_base_name = File.basename(f)
35
+ file_list << f
36
+ file_name_list << file_base_name
37
+ puts "#{i}.#{file_base_name}".yellow
47
38
  end
39
+ idx = @cli.ask('请选择上传文件序号: '.green).strip.to_i
40
+ puts "上传的文件名:#{file_name_list[idx]}".yellow
41
+ upload(file_list[idx], file_name_list[idx])
48
42
  end
49
43
 
50
44
  private
@@ -54,7 +48,7 @@ module Lhj
54
48
  oss_key = "#{@tag}/#{file_name}" if @tag
55
49
  Lhj::OSS::Helper.instance.upload(oss_key, file)
56
50
  url = Lhj::OSS::Helper.instance.object_url(oss_key)
57
- puts "云端上传成功:#{url}\n"
51
+ puts "云端上传成功:#{url}\n".yellow
58
52
  end
59
53
  end
60
54
  end
@@ -53,6 +53,8 @@ module Lhj
53
53
 
54
54
  def modify_file(file)
55
55
  File.chmod(0o644, file)
56
+ # arr = File.open(file, 'r+').readlines
57
+ # lines = arr.size
56
58
  str = file_string(file)
57
59
  File.open(file, 'w+') do |f|
58
60
  f.write(str)
@@ -26,7 +26,8 @@ module Lhj
26
26
  end
27
27
 
28
28
  def handler_files
29
- Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
29
+ search_type = @file_type.gsub('.', '')
30
+ Dir.glob("#{@current_path}/**/*.{#{search_type}}").each do |f|
30
31
  handler_file f
31
32
  end
32
33
  end
data/lib/lhj/command.rb CHANGED
@@ -17,7 +17,9 @@ module Lhj
17
17
  require 'lhj/command/oss/del'
18
18
  require 'lhj/command/oss/upload'
19
19
  require 'lhj/command/oss/list'
20
- require 'lhj/command/view'
20
+ require 'lhj/command/oss/download'
21
+ require 'lhj/command/code/view'
22
+ require 'lhj/command/code/code_template'
21
23
  require 'lhj/command/rename_image'
22
24
  require 'lhj/command/trans'
23
25
  require 'lhj/command/yapi'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.35"
5
+ VERSION = "0.1.38"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.35
4
+ version: 0.1.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-29 00:00:00.000000000 Z
11
+ date: 2022-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -294,6 +294,10 @@ files:
294
294
  - bin/lhj
295
295
  - lib/lhj/action/sh_helper.rb
296
296
  - lib/lhj/command.rb
297
+ - lib/lhj/command/code/code_template.rb
298
+ - lib/lhj/command/code/template/dispatch_source.erb
299
+ - lib/lhj/command/code/template/message_query.erb
300
+ - lib/lhj/command/code/view.rb
297
301
  - lib/lhj/command/config.rb
298
302
  - lib/lhj/command/config/info.rb
299
303
  - lib/lhj/command/duplicate_imageset.rb
@@ -308,6 +312,7 @@ files:
308
312
  - lib/lhj/command/local/micro_service.rb
309
313
  - lib/lhj/command/oss.rb
310
314
  - lib/lhj/command/oss/del.rb
315
+ - lib/lhj/command/oss/download.rb
311
316
  - lib/lhj/command/oss/list.rb
312
317
  - lib/lhj/command/oss/upload.rb
313
318
  - lib/lhj/command/pgyer_upload.rb
@@ -318,7 +323,6 @@ files:
318
323
  - lib/lhj/command/sync_pod_version.rb
319
324
  - lib/lhj/command/template.rb
320
325
  - lib/lhj/command/trans.rb
321
- - lib/lhj/command/view.rb
322
326
  - lib/lhj/command/yapi.rb
323
327
  - lib/lhj/command/yapi/formatters/base.rb
324
328
  - lib/lhj/command/yapi/formatters/command_context.rb