Skip to content

Commit

Permalink
自动复制日报
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Feb 23, 2020
1 parent 1ab36f1 commit b71cdc6
Show file tree
Hide file tree
Showing 18 changed files with 1,164 additions and 827 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ _testmain.go
*.prof

attachment
database
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/engineercms.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# API v1.0.3

## Feb, 2020

- 安装go,修改GOPATH,GOBIN
- 安装git
- 安装goland
- go get一系列的包
- 安装gcc,mingw,x86_64-posix-seh
- casbin reset到1.9.1,xorm-adapter reset到19年5月23的一个版本9b17d80119c

## Nov, 2019

+ 采用bootstrap fileinput来实现上传excel到服务端,解析后和规范标准库进行比对,将规范号填入excel,供用户下载。
Expand Down
5 changes: 5 additions & 0 deletions conf/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ httpport = 8088
#####服务模式:dev开发模式/prod专业模式
runmode = dev

#####日报清空,前多少行和列保留,固定只保留第一个sheet
# sheetkeep = 1
rowkeep = 2
colkeep = 3

#####设置session####
sessionon = true
SessionName = hotqinsessionid
Expand Down
74 changes: 60 additions & 14 deletions controllers/onlyoffice.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (

"github.com/astaxie/beego/httplib"
"github.com/astaxie/beego/logs"
"github.com/tealeg/xlsx"

)

type OnlyController struct {
Expand Down Expand Up @@ -112,6 +114,42 @@ type Rolepermission struct {
Permission string `json:"role"`
}

func copyEmptyXlsx(dst string, src string) (err error) {
rowkeep, _ := beego.AppConfig.Int("rowkeep")
colkeep, _ := beego.AppConfig.Int("colkeep")
logs.Info(rowkeep, colkeep)
xlfile, err := xlsx.OpenFile(src)
if err != nil {
return err
}
// 只保留第一个sheet
xlfile.Sheets = xlfile.Sheets[:1]
sheet := xlfile.Sheets[0]
// 修改sheet名
nowTime := time.Now()
nowTimeStr := nowTime.Format("0102")
sheet.Name = nowTimeStr

for rowIndex, row := range sheet.Rows {
if rowIndex < rowkeep {
continue
}
for cellIndex, cell := range row.Cells {
if cellIndex < colkeep {
continue
}
logs.Info(rowIndex, cellIndex, cell.Value)
cell.Value = ""
}
}
err = xlfile.Save(dst)
if err != nil {
return err
}
return nil
}


//文档管理页面
func (c *OnlyController) Get() {
//取得客户端用户名
Expand All @@ -132,25 +170,34 @@ func (c *OnlyController) Get() {

nowTime := time.Now()
todayDate := nowTime.Format("20060102")
yesTime := nowTime.AddDate(0, 0, -1)
yesDate := yesTime.Format("20060102")
//yesTime := nowTime.AddDate(0, 0, -1)
//yesDate := yesTime.Format("20060102")
var yesDate string = ""

// 上一个日报的日期,用正则搜索
yesRegex, _ := regexp.Compile(`20\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])`)

var todayDoc string = ""
var yesDoc string = ""
var ext string = ""

for _, w := range docs {
logs.Info(w.Title)
}
for _, w := range docs {
if strings.Contains(w.Title, todayDate) {
todayDoc = w.Title
} else if strings.Contains(w.Title, yesDate) {
break
}
if yesDate == "" && yesRegex.FindString(w.Title) != "" {
yesDate = yesRegex.FindString(w.Title)
yesDoc = w.Title
Attachments, err := models.GetOnlyAttachments(w.Id)
if err != nil {
beego.Error(err)
}
ext = path.Ext(Attachments[0].FileName)
beego.Info(ext)
break
}
}

Expand Down Expand Up @@ -183,14 +230,22 @@ func (c *OnlyController) Get() {

destination, _ := os.Create(todayDoc)
defer destination.Close()
_, _ = io.Copy(destination, source)

err = copyEmptyXlsx(todayDoc, yesfilepath)
if err != nil {
logs.Info(err)
_, _ = io.Copy(destination, source)
} else {
logs.Info("copy empty succeed")
}
}
}

c.Data["IsOnlyOffice"] = true
c.TplName = "onlyoffice/docs.tpl"
}

// 这里的函数才获取文档列表
func (c *OnlyController) GetData() {
//1.取得客户端用户名
var err error
Expand Down Expand Up @@ -314,8 +369,6 @@ func (c *OnlyController) GetData() {
Docxslice = append(Docxslice, docxarr...)
}
linkarr[0].Docxlink = Docxslice
// linkarr[0].Xlsxlink = Xlsxslice
// linkarr[0].Pptxlink = Pptxslice
Docxslice = make([]DocxLink, 0) //再把slice置0
//无权限的不显示
//如果permission=4,则不赋值给link
Expand Down Expand Up @@ -560,12 +613,8 @@ func (c *OnlyController) OnlyOffice() {
beego.Error(err)
}
if matched == true {
// beego.Info("移动端~")
// c.TplName = "onlyoffice/onlyoffice.tpl"
c.Data["Type"] = "mobile"
} else {
// beego.Info("电脑端!")
// c.TplName = "onlyoffice/onlyoffice.tpl"
c.Data["Type"] = "desktop"
}
c.TplName = "onlyoffice/onlyoffice.tpl"
Expand All @@ -574,9 +623,6 @@ func (c *OnlyController) OnlyOffice() {
//cms中查阅office
func (c *OnlyController) OfficeView() {
//设置响应头——没有作用
// c.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") //允许访问所有域
// c.Ctx.ResponseWriter.Header().Add("Access-Control-Allow-Headers", "Content-Type") //header的类型
// c.Ctx.ResponseWriter.Header().Set("content-type", "application/json") //返回数据格式是json
id := c.Ctx.Input.Param(":id")
//pid转成64为
idNum, err := strconv.ParseInt(id, 10, 64)
Expand Down
Binary file modified database/engineer.db
Binary file not shown.
2 changes: 1 addition & 1 deletion lastupdate.tmp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"/Users/zhaijy/golang/golib/src/github.com/3xxx/engineercms/controllers":1580980335449009306}
{"/Users/zhaijy/golang/golib/src/github.com/3xxx/engineercms/controllers":1580980335449009306,"D:\\golib\\src\\github.com\\3xxx\\engineercms\\controllers":1582471205047892800}
12 changes: 12 additions & 0 deletions log/engineercms.info.log
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
2020/02/06 00:23:42.202 [I] [login.go:233] admin login 成功
2020/02/06 16:24:20.172 [I] [login.go:233] admin login 成功
2020/02/06 17:11:39.947 [I] [login.go:233] admin login 成功
2020/02/23 14:20:50.343 [I] [login.go:233] admin login 成功
2020/02/23 15:25:12.679 [I] [login.go:233] admin login 成功
2020/02/23 15:30:41.369 [I] [login.go:233] admin login 成功
2020/02/23 15:47:16.569 [I] [login.go:233] admin login 成功
2020/02/23 15:52:54.809 [I] [login.go:233] admin login 成功
2020/02/23 16:33:42.554 [I] [login.go:233] admin login 成功
2020/02/23 22:41:57.780 [I] [login.go:233] admin login 成功
2020/02/23 22:49:04.889 [I] [login.go:233] admin login 成功
2020/02/23 22:51:50.325 [I] [login.go:233] admin login 成功
2020/02/23 23:15:13.787 [I] [login.go:233] admin login 成功
2020/02/23 23:17:35.170 [I] [login.go:233] admin login 成功
2020/02/23 23:20:33.569 [I] [login.go:233] admin login 成功
12 changes: 12 additions & 0 deletions log/engineercms.log
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
2020/02/06 00:23:42.202 [I] [login.go:233] admin login 成功
2020/02/06 16:24:20.172 [I] [login.go:233] admin login 成功
2020/02/06 17:11:39.947 [I] [login.go:233] admin login 成功
2020/02/23 14:20:50.343 [I] [login.go:233] admin login 成功
2020/02/23 15:25:12.679 [I] [login.go:233] admin login 成功
2020/02/23 15:30:41.369 [I] [login.go:233] admin login 成功
2020/02/23 15:47:16.569 [I] [login.go:233] admin login 成功
2020/02/23 15:52:54.809 [I] [login.go:233] admin login 成功
2020/02/23 16:33:42.554 [I] [login.go:233] admin login 成功
2020/02/23 22:41:57.780 [I] [login.go:233] admin login 成功
2020/02/23 22:49:04.889 [I] [login.go:233] admin login 成功
2020/02/23 22:51:50.325 [I] [login.go:233] admin login 成功
2020/02/23 23:15:13.787 [I] [login.go:233] admin login 成功
2020/02/23 23:17:35.170 [I] [login.go:233] admin login 成功
2020/02/23 23:20:33.569 [I] [login.go:233] admin login 成功
5 changes: 1 addition & 4 deletions models/OnlyofficeModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ func init() {
func GetDocs() (docs []*OnlyOffice, err error) {
o := orm.NewOrm()
qs := o.QueryTable("OnlyOffice")
_, err = qs.All(&docs)
if err != nil {
return docs, err
}
_, err = qs.OrderBy("-updated").All(&docs)
return docs, err
}

Expand Down
Loading

0 comments on commit b71cdc6

Please sign in to comment.