|
@@ -1,21 +1,27 @@
|
1
|
1
|
package main
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
|
- "context"
|
|
4
|
+
|
5
|
5
|
"fmt"
|
6
|
|
- "gdyb/models"
|
|
6
|
+
|
7
|
7
|
_ "gdyb/routers"
|
8
|
|
-
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+ "gdyb/service"
|
9
|
15
|
"github.com/astaxie/beego"
|
10
|
|
- "github.com/qiniu/api.v7/auth/qbox"
|
11
|
|
- "github.com/qiniu/api.v7/storage"
|
|
16
|
+
|
|
17
|
+
|
12
|
18
|
"os"
|
13
|
|
- "strconv"
|
14
|
|
- "time"
|
|
19
|
+
|
|
20
|
+
|
15
|
21
|
)
|
16
|
22
|
|
17
|
23
|
func init() {
|
18
|
|
-
|
|
24
|
+ service.ConnectDB()
|
19
|
25
|
|
20
|
26
|
|
21
|
27
|
|
|
@@ -784,75 +790,75 @@ type ResultSeventeen struct {
|
784
|
790
|
|
785
|
791
|
|
786
|
792
|
|
787
|
|
-func CreateLog(miConfig models.MedicalInsuranceOrgConfig) {
|
788
|
|
- Mkdir(miConfig.OrgName + "日志")
|
789
|
|
-
|
790
|
|
- month := time.Unix(1557042972, 0).Format("1")
|
791
|
|
- year := time.Now().Format("2006")
|
792
|
|
- month = time.Now().Format("01")
|
793
|
|
- day := time.Now().Format("02")
|
794
|
|
- file := strconv.FormatInt(miConfig.UserOrgId, 10) + "_" + year + month + day + "_log"
|
795
|
|
- file_name := file + ".txt"
|
796
|
|
- file_path := miConfig.OrgName + "日志" + "/" + file_name
|
797
|
|
- exist, _ := PathExists(file_path)
|
798
|
|
- if exist {
|
799
|
|
- fmt.Println("存在")
|
800
|
|
- f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
|
801
|
|
- if err != nil {
|
802
|
|
- fmt.Println("read fail")
|
803
|
|
- }
|
804
|
|
- content := "\r\r\r"
|
805
|
|
- n, _ := f.Seek(0, 2)
|
806
|
|
- _, err = f.WriteAt([]byte(content), n)
|
807
|
|
-
|
808
|
|
- } else {
|
809
|
|
- fmt.Println("文件不存在,创建文件")
|
810
|
|
- f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
|
811
|
|
- defer f.Close()
|
812
|
|
- if err != nil {
|
813
|
|
- } else {
|
814
|
|
- _, err = f.Write([]byte("记录日志"))
|
815
|
|
- }
|
816
|
|
- }
|
817
|
|
-
|
818
|
|
-}
|
819
|
|
-
|
820
|
|
-func UploadLog(miConfig models.MedicalInsuranceOrgConfig) {
|
821
|
|
-
|
822
|
|
- nTime := time.Now()
|
823
|
|
- yesTime := nTime.AddDate(0, 0, -1)
|
824
|
|
- file_key := strconv.FormatInt(miConfig.UserOrgId, 10) + "_" + yesTime.Format("20060102") + "_log.txt"
|
825
|
|
- mac := qbox.NewMac(beego.AppConfig.String("qiniu_accesskey"), beego.AppConfig.String("qiniu_secretkey"))
|
826
|
|
- cfg := storage.Config{
|
827
|
|
-
|
828
|
|
- UseHTTPS: true,
|
829
|
|
- }
|
830
|
|
-
|
831
|
|
-
|
832
|
|
-
|
833
|
|
- bucketManager := storage.NewBucketManager(mac, &cfg)
|
834
|
|
- bucket := beego.AppConfig.String("qiniu_bucket")
|
835
|
|
- key := file_key
|
836
|
|
- file, sErr := bucketManager.Stat(bucket, key)
|
837
|
|
- fmt.Println(file)
|
838
|
|
- fmt.Println(sErr)
|
839
|
|
- fmt.Println(miConfig.OrgName + "日志" + "/" + file_key)
|
840
|
|
-
|
841
|
|
- if sErr != nil {
|
842
|
|
- fmt.Println("七牛云上文件不存在,上传到七牛云")
|
843
|
|
-
|
844
|
|
- exist, _ := PathExists(miConfig.OrgName + "日志" + "/" + file_key)
|
845
|
|
- if exist {
|
846
|
|
- upload_qiniu(miConfig.OrgName+"日志"+"/"+file_key, file_key)
|
847
|
|
- } else {
|
848
|
|
- fmt.Println("本地文件不存在")
|
849
|
|
-
|
850
|
|
- }
|
851
|
|
- } else {
|
852
|
|
- fmt.Println("七牛云文件存在")
|
853
|
|
- }
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
854
|
825
|
|
855
|
|
-}
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
856
|
862
|
func Mkdir(dir string) {
|
857
|
863
|
|
858
|
864
|
exist, err := PathExists(dir)
|
|
@@ -882,39 +888,40 @@ func PathExists(path string) (bool, error) {
|
882
|
888
|
}
|
883
|
889
|
return false, err
|
884
|
890
|
}
|
885
|
|
-func upload_qiniu(filePath string, keys string) {
|
886
|
|
- key := keys
|
887
|
|
-
|
888
|
|
- putPolicy := storage.PutPolicy{
|
889
|
|
- Scope: beego.AppConfig.String("qiniu_bucket"),
|
890
|
|
- }
|
891
|
|
- mac := qbox.NewMac(beego.AppConfig.String("qiniu_accesskey"), beego.AppConfig.String("qiniu_secretkey"))
|
892
|
|
- upToken := putPolicy.UploadToken(mac)
|
893
|
|
- cfg := storage.Config{}
|
894
|
|
-
|
895
|
|
-
|
896
|
|
-
|
897
|
|
-
|
898
|
|
-
|
899
|
|
-
|
900
|
|
-
|
901
|
|
-
|
902
|
|
- cfg.Zone = &storage.ZoneHuadong
|
903
|
|
-
|
904
|
|
- cfg.UseHTTPS = false
|
905
|
|
-
|
906
|
|
- cfg.UseCdnDomains = false
|
907
|
|
-
|
908
|
|
- formUploader := storage.NewFormUploader(&cfg)
|
909
|
|
- ret := storage.PutRet{}
|
910
|
|
-
|
911
|
|
- putExtra := storage.PutExtra{
|
912
|
|
- Params: map[string]string{},
|
913
|
|
- }
|
914
|
|
- err := formUploader.PutFile(context.Background(), &ret, upToken, key, filePath, &putExtra)
|
915
|
|
- if err != nil {
|
916
|
|
- fmt.Println(err)
|
917
|
|
- return
|
918
|
|
- }
|
919
|
|
- fmt.Println(ret.Key, ret.Hash)
|
920
|
|
-}
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|