Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d2b68a202 | ||
|
|
144e2ffb25 | ||
|
|
0a1c3c436e | ||
|
|
8c6be6f487 | ||
|
|
915d474fea | ||
|
|
0cfaa799f5 |
8
README.md
Normal file
8
README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
go语言工具类
|
||||
|
||||
####
|
||||
进行安装
|
||||
~~~
|
||||
go get github.com/ayflying/utility_go
|
||||
~~~
|
||||
|
||||
29
cmd/make.go
29
cmd/make.go
@@ -24,8 +24,9 @@ var (
|
||||
{Name: "id", Short: "i", Brief: "活动id"},
|
||||
{Name: "name", Short: "n", Brief: "服务文件名"},
|
||||
},
|
||||
Examples: "make -m act -i 1: 创建活动1的接口与服务文件 \n" +
|
||||
"make -m logic -n test: 创建test的服务文件",
|
||||
Examples: "make -m act -i 1: 创建活动1的接口与服务文件 \n" +
|
||||
"make -m logic -n test: 创建test的服务文件 \n" +
|
||||
"make -m config -n test: 创建配置文件",
|
||||
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
|
||||
|
||||
//g.Dump(parser.GetOptAll(), parser.GetArgAll())
|
||||
@@ -46,6 +47,12 @@ var (
|
||||
return
|
||||
}
|
||||
err = this.Logic(name)
|
||||
case "config":
|
||||
var name = parser.GetOpt("name").String()
|
||||
if name == "" {
|
||||
return
|
||||
}
|
||||
err = this.Config(name)
|
||||
}
|
||||
|
||||
return
|
||||
@@ -84,7 +91,7 @@ func (c *cMake) Logic(name string) (err error) {
|
||||
//生成文件不覆盖
|
||||
if !gfile.Exists(filePath) {
|
||||
//fileStr := gfile.GetContents("./make/logic")
|
||||
get, _ := fs.ReadFile(ConfigFiles, "make/act")
|
||||
get, _ := fs.ReadFile(ConfigFiles, "make/logic")
|
||||
fileStr := string(get)
|
||||
fileStr = gstr.Replace(fileStr, "{package}", name)
|
||||
fileStr = gstr.Replace(fileStr, "{name}", gstr.CaseCamel(name))
|
||||
@@ -93,3 +100,19 @@ func (c *cMake) Logic(name string) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *cMake) Config(name string) (err error) {
|
||||
var filePath = fmt.Sprintf("utility/config/%s.go", name)
|
||||
//生成文件不覆盖
|
||||
if !gfile.Exists(filePath) {
|
||||
get, _ := fs.ReadFile(ConfigFiles, "make/config")
|
||||
fileStr := string(get)
|
||||
fileStr = gstr.Replace(fileStr, "{name}", gstr.CaseCamel(name))
|
||||
fileStr = gstr.Replace(fileStr, "{cfg}", gstr.CaseCamel(name))
|
||||
fileStr = gstr.Replace(fileStr, "{mod}", gstr.CaseCamelLower(name))
|
||||
fileStr = gstr.Replace(fileStr, "{file}", name)
|
||||
err = gfile.PutContents(filePath, fileStr)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
51
cmd/make/config
Normal file
51
cmd/make/config
Normal file
@@ -0,0 +1,51 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/ayflying/utility_go"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type {cfg}Cfg struct {
|
||||
Id int32 `json:"id" dc:"编号"`
|
||||
}
|
||||
|
||||
type {mod}Mod struct {
|
||||
once sync.Once
|
||||
lock sync.Mutex
|
||||
cfgArr []*{cfg}Cfg
|
||||
cfgMap map[int32]*{cfg}Cfg
|
||||
}
|
||||
|
||||
var {name} = &{mod}Mod{}
|
||||
|
||||
func (c *{mod}Mod) Load(_cfg ...string) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.cfgArr = make([]*{cfg}Cfg, 0)
|
||||
data, err := utility_go.Config.GetFile("{file}")
|
||||
err = data.Scan(&c.cfgArr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.cfgMap = make(map[int32]*{cfg}Cfg)
|
||||
for _, v := range c.cfgArr {
|
||||
c.cfgMap[v.Id] = v
|
||||
}
|
||||
}
|
||||
|
||||
func (c *{mod}Mod) List() []*{cfg}Cfg {
|
||||
var list = make([]*{cfg}Cfg, len(c.cfgArr))
|
||||
for k, v := range c.cfgArr {
|
||||
list[k] = c.Get(v.Id)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (c *{mod}Mod) Get(id int32) *{cfg}Cfg {
|
||||
if data, ok := c.cfgMap[id]; ok {
|
||||
return gutil.Copy(data).(*{cfg}Cfg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -16,6 +16,10 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
shadiao = []string{",", ":"}
|
||||
)
|
||||
|
||||
type FileItem struct {
|
||||
Name string `json:"name" dc:"配置文件名"`
|
||||
Filename string `json:"filename" dc:"文件名"`
|
||||
@@ -131,14 +135,16 @@ func (s *Excel) sliceFormat(list []interface{}, Slice map[string]string) []inter
|
||||
list[k2].(g.Map)[k3] = []string{}
|
||||
continue
|
||||
}
|
||||
|
||||
var parts []string
|
||||
//断言是否成功
|
||||
if get, ok := v3.(string); !ok {
|
||||
//g.Log().Errorf(gctx.New(), "当前类型断言失败:%v", v3)
|
||||
parts = []string{gconv.String(v3)}
|
||||
continue
|
||||
|
||||
} else {
|
||||
for _, v := range shadiao {
|
||||
get = strings.ReplaceAll(get, v, "|")
|
||||
}
|
||||
parts = strings.Split(get, "|") // 分割字符串
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ func Excel2Slice(filePath string, _sheet ...string) [][]string {
|
||||
|
||||
// 字符串转道具类型
|
||||
func Spilt2Item(str string) (result [][]int64) {
|
||||
var shadiao = []string{","}
|
||||
for _, v := range shadiao {
|
||||
str = strings.ReplaceAll(str, v, "|")
|
||||
//parts = append(parts, strings.Split(str, v)...) // 分割字符串
|
||||
|
||||
@@ -19,13 +19,13 @@ func (m *timeMod) Load() {
|
||||
// 获取本周的开始时间
|
||||
func (m *timeMod) StartOfWeek(t time.Time) time.Time {
|
||||
start := gtime.New().AddDate(0, 0, -int(t.Weekday()-1)).Time
|
||||
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.UTC().Location())
|
||||
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location())
|
||||
return start
|
||||
}
|
||||
|
||||
func (m *timeMod) StartOfWeekV2(t time.Time) time.Time {
|
||||
start := t.AddDate(0, 0, -int(t.Weekday()-1))
|
||||
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.UTC().Location())
|
||||
start = time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, start.Location())
|
||||
return start
|
||||
}
|
||||
|
||||
@@ -59,15 +59,14 @@ func (m *timeMod) GetDayPass(startTime time.Time, t ...time.Time) int {
|
||||
month := startTime.Month()
|
||||
day := startTime.Day()
|
||||
// 构建一天的开始时间
|
||||
startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.UTC().Location())
|
||||
|
||||
startTime = time.Date(year, month, day, 0, 0, 0, 0, startTime.Location())
|
||||
//如果为空,使用当前时间
|
||||
endTime := time.Now()
|
||||
if len(t) > 0 {
|
||||
endTime = t[0]
|
||||
}
|
||||
//计算过去了多少天
|
||||
dayPass := int(endTime.Sub(startTime).Hours() / 24)
|
||||
dayPass := int(endTime.UTC().Sub(startTime.UTC()).Hours() / 24)
|
||||
return dayPass
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ func (m *timeMod) GetDayZeroTime(currentTime time.Time, day int) time.Time {
|
||||
// 加上指定天数的时间
|
||||
threeDaysLater := currentTime.AddDate(0, 0, day)
|
||||
// 调整时间为0点
|
||||
zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 0, 0, 0, 0, threeDaysLater.UTC().Location())
|
||||
zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 0, 0, 0, 0, threeDaysLater.Location())
|
||||
return zeroTime
|
||||
}
|
||||
|
||||
@@ -108,7 +107,7 @@ func (m *timeMod) GetEndTime(startTime time.Time, _day ...int) time.Time {
|
||||
// 加上指定天数的时间
|
||||
threeDaysLater := startTime.AddDate(0, 0, day)
|
||||
// 调整时间为0点
|
||||
zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 23, 59, 59, 0, threeDaysLater.UTC().Location())
|
||||
zeroTime := time.Date(threeDaysLater.Year(), threeDaysLater.Month(), threeDaysLater.Day(), 23, 59, 59, 0, threeDaysLater.Location())
|
||||
return zeroTime
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user