|
@@ -5,14 +5,19 @@ import (
|
5
|
5
|
"XT_New/models"
|
6
|
6
|
"XT_New/service"
|
7
|
7
|
"XT_New/utils"
|
|
8
|
+ "archive/zip"
|
8
|
9
|
"bytes"
|
9
|
10
|
"encoding/json"
|
10
|
11
|
"fmt"
|
11
|
12
|
"github.com/astaxie/beego"
|
12
|
13
|
"github.com/jinzhu/gorm"
|
|
14
|
+ "github.com/shopspring/decimal"
|
|
15
|
+ "io"
|
13
|
16
|
"io/ioutil"
|
14
|
17
|
"math/rand"
|
15
|
18
|
"net/http"
|
|
19
|
+ "os"
|
|
20
|
+ "path/filepath"
|
16
|
21
|
"reflect"
|
17
|
22
|
"strconv"
|
18
|
23
|
"strings"
|
|
@@ -51,6 +56,9 @@ func HisManagerApiRegistRouters() {
|
51
|
56
|
beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
|
52
|
57
|
beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
|
53
|
58
|
|
|
59
|
+ beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
|
|
60
|
+ beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
|
|
61
|
+
|
54
|
62
|
beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
|
55
|
63
|
|
56
|
64
|
beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
|
|
@@ -1238,6 +1246,39 @@ type ResultSeven struct {
|
1238
|
1246
|
Signtype interface{} `json:"signtype"`
|
1239
|
1247
|
WarnMsg interface{} `json:"warn_msg"`
|
1240
|
1248
|
}
|
|
1249
|
+
|
|
1250
|
+type ResultEight struct {
|
|
1251
|
+ Cainfo string `json:"cainfo"`
|
|
1252
|
+ ErrMsg string `json:"err_msg"`
|
|
1253
|
+ InfRefmsgid string `json:"inf_refmsgid"`
|
|
1254
|
+ Infcode int64 `json:"infcode"`
|
|
1255
|
+ Output struct {
|
|
1256
|
+ Stmtinfo struct {
|
|
1257
|
+ SetlOptins string `json:"setl_optins"`
|
|
1258
|
+ StmtRslt string `json:"stmt_rslt"`
|
|
1259
|
+ StmtRsltDscr string `json:"stmt_rslt_dscr"`
|
|
1260
|
+ } `json:"stmtinfo"`
|
|
1261
|
+ } `json:"output"`
|
|
1262
|
+ RefmsgTime string `json:"refmsg_time"`
|
|
1263
|
+ RespondTime string `json:"respond_time"`
|
|
1264
|
+ Signtype interface{} `json:"signtype"`
|
|
1265
|
+ WarnMsg interface{} `json:"warn_msg"`
|
|
1266
|
+}
|
|
1267
|
+
|
|
1268
|
+type ResultNine struct {
|
|
1269
|
+ Cainfo string `json:"cainfo"`
|
|
1270
|
+ ErrMsg string `json:"err_msg"`
|
|
1271
|
+ InfRefmsgid string `json:"inf_refmsgid"`
|
|
1272
|
+ Infcode int64 `json:"infcode"`
|
|
1273
|
+ Output struct {
|
|
1274
|
+ FileQuryNo string `json:"file_qury_no"`
|
|
1275
|
+ } `json:"output"`
|
|
1276
|
+ RefmsgTime string `json:"refmsg_time"`
|
|
1277
|
+ RespondTime string `json:"respond_time"`
|
|
1278
|
+ Signtype interface{} `json:"signtype"`
|
|
1279
|
+ WarnMsg interface{} `json:"warn_msg"`
|
|
1280
|
+}
|
|
1281
|
+
|
1241
|
1282
|
type Custom struct {
|
1242
|
1283
|
DetItemFeeSumamt string
|
1243
|
1284
|
Cut string
|
|
@@ -1650,6 +1691,7 @@ func (c *HisApiController) GetUploadInfo() {
|
1650
|
1691
|
FoundPrice: found_price,
|
1651
|
1692
|
MedicalInsurancePrice: medical_insurance_price,
|
1652
|
1693
|
PrivatePrice: private_price,
|
|
1694
|
+ IsMedicineInsurance: 1,
|
1653
|
1695
|
}
|
1654
|
1696
|
err = service.CreateOrder(order)
|
1655
|
1697
|
if err != nil {
|
|
@@ -2021,10 +2063,10 @@ func (c *HisApiController) Refund() {
|
2021
|
2063
|
recordDateTime := theTime.Unix()
|
2022
|
2064
|
|
2023
|
2065
|
his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
|
2024
|
|
- miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
|
2025
|
2066
|
patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
|
2026
|
2067
|
order, _ := service.GetHisOrderByID(order_id)
|
2027
|
2068
|
|
|
2069
|
+ miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
|
2028
|
2070
|
config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
|
2029
|
2071
|
if config.IsOpen == 1 { //对接了医保,走医保流程
|
2030
|
2072
|
api := "http://127.0.0.1:9531/" + "gdyb/nine?psn_no=" + his.PsnNo +
|
|
@@ -2095,6 +2137,228 @@ func (c *HisApiController) Refund() {
|
2095
|
2137
|
}
|
2096
|
2138
|
}
|
2097
|
2139
|
|
|
2140
|
+func (c *HisApiController) GetCheckAccount() {
|
|
2141
|
+ start_time := c.GetString("start_time")
|
|
2142
|
+ end_time := c.GetString("end_time")
|
|
2143
|
+ insutype := c.GetString("insutype")
|
|
2144
|
+ clr_type := c.GetString("clr_type")
|
|
2145
|
+
|
|
2146
|
+ adminUser := c.GetAdminUserInfo()
|
|
2147
|
+ miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
|
|
2148
|
+ config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
|
|
2149
|
+
|
|
2150
|
+ timeLayout := "2006-01-02"
|
|
2151
|
+ loc, _ := time.LoadLocation("Local")
|
|
2152
|
+ startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
2153
|
+ endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
|
|
2154
|
+ orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
|
|
2155
|
+
|
|
2156
|
+ decimal.DivisionPrecision = 2
|
|
2157
|
+ var medfee_sumamt float64
|
|
2158
|
+ var acct_pay float64
|
|
2159
|
+ var fund_pay_sumamt float64
|
|
2160
|
+ fixmedins_setl_cnt := int64(len(orders))
|
|
2161
|
+
|
|
2162
|
+ for _, item := range orders {
|
|
2163
|
+ medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
|
|
2164
|
+ acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
|
|
2165
|
+ fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
|
|
2166
|
+ }
|
|
2167
|
+
|
|
2168
|
+ if config.IsOpen == 1 {
|
|
2169
|
+ api := "http://127.0.0.1:9532/" + "gdyb/ten?insutype=" + insutype +
|
|
2170
|
+ "&clr_type=" + clr_type +
|
|
2171
|
+ "&setl_optins=" + miConfig.OrgName +
|
|
2172
|
+ "&stmt_begndate=" + start_time +
|
|
2173
|
+ "&stm_enddate=" + end_time +
|
|
2174
|
+ "&medfee_sumamt=" + fmt.Sprintf("%2f", medfee_sumamt) +
|
|
2175
|
+ "&fund_pay_sumamt=" + fmt.Sprintf("%2f", fund_pay_sumamt) +
|
|
2176
|
+ "&acct_pay=" + fmt.Sprintf("%2f", acct_pay) +
|
|
2177
|
+ "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
|
|
2178
|
+ "&fixmedins_code=" + miConfig.Code +
|
|
2179
|
+ "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
|
|
2180
|
+ "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
|
|
2181
|
+ "&secret_key=" + miConfig.SecretKey +
|
|
2182
|
+ "&org_name=" + miConfig.OrgName +
|
|
2183
|
+ "&doctor="
|
|
2184
|
+
|
|
2185
|
+ resp, requestErr := http.Get(api)
|
|
2186
|
+ if requestErr != nil {
|
|
2187
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2188
|
+ return
|
|
2189
|
+ }
|
|
2190
|
+ body, ioErr := ioutil.ReadAll(resp.Body)
|
|
2191
|
+ if ioErr != nil {
|
|
2192
|
+ utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
|
|
2193
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2194
|
+ return
|
|
2195
|
+ }
|
|
2196
|
+ var respJSON map[string]interface{}
|
|
2197
|
+ if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
|
|
2198
|
+ utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
|
|
2199
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2200
|
+ return
|
|
2201
|
+ }
|
|
2202
|
+ respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
|
|
2203
|
+ userJSONBytes, _ := json.Marshal(respJSON)
|
|
2204
|
+
|
|
2205
|
+ var res ResultEight
|
|
2206
|
+ if err := json.Unmarshal(userJSONBytes, &res); err != nil {
|
|
2207
|
+ utils.ErrorLog("解析失败:%v", err)
|
|
2208
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2209
|
+ return
|
|
2210
|
+ }
|
|
2211
|
+ if res.Infcode == 0 {
|
|
2212
|
+ c.ServeSuccessJSON(map[string]interface{}{
|
|
2213
|
+ "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
|
|
2214
|
+ "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
|
|
2215
|
+ })
|
|
2216
|
+ } else {
|
|
2217
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2218
|
+ }
|
|
2219
|
+ }
|
|
2220
|
+}
|
|
2221
|
+func (c *HisApiController) GetCheckDetailAccount() {
|
|
2222
|
+ start_time := c.GetString("start_time")
|
|
2223
|
+ end_time := c.GetString("end_time")
|
|
2224
|
+
|
|
2225
|
+ adminUser := c.GetAdminUserInfo()
|
|
2226
|
+ miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
|
|
2227
|
+ config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
|
|
2228
|
+
|
|
2229
|
+ timeLayout := "2006-01-02"
|
|
2230
|
+ loc, _ := time.LoadLocation("Local")
|
|
2231
|
+ startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
|
|
2232
|
+ endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
|
|
2233
|
+ orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
|
|
2234
|
+
|
|
2235
|
+ Mkdir(miConfig.OrgName)
|
|
2236
|
+ file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
|
|
2237
|
+ file_name := file + ".txt"
|
|
2238
|
+ zip_name := file + ".zip"
|
|
2239
|
+ zip_path := miConfig.OrgName + "/" + zip_name
|
|
2240
|
+ file_path := miConfig.OrgName + "/" + file_name
|
|
2241
|
+
|
|
2242
|
+ decimal.DivisionPrecision = 2
|
|
2243
|
+ var medfee_sumamt float64
|
|
2244
|
+ var psn_cash_pay float64
|
|
2245
|
+ var fund_pay_sumamt float64
|
|
2246
|
+ fixmedins_setl_cnt := int64(len(orders))
|
|
2247
|
+
|
|
2248
|
+ for _, item := range orders {
|
|
2249
|
+ medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
|
|
2250
|
+ psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
|
|
2251
|
+ fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
|
|
2252
|
+ }
|
|
2253
|
+
|
|
2254
|
+ f, err := os.Create(miConfig.OrgName + "/" + file_name)
|
|
2255
|
+ defer f.Close()
|
|
2256
|
+ if err != nil {
|
|
2257
|
+ fmt.Println(err.Error())
|
|
2258
|
+ } else {
|
|
2259
|
+ for _, item := range orders {
|
|
2260
|
+ var refd_setl_flag string
|
|
2261
|
+ if item.OrderStatus == 2 {
|
|
2262
|
+ refd_setl_flag = "0"
|
|
2263
|
+ }
|
|
2264
|
+ if item.OrderStatus == 3 {
|
|
2265
|
+ refd_setl_flag = "1"
|
|
2266
|
+ }
|
|
2267
|
+ var str string
|
|
2268
|
+ str = item.SetlId + " " +
|
|
2269
|
+ item.MdtrtId + " " +
|
|
2270
|
+ item.PsnNo + " " +
|
|
2271
|
+ fmt.Sprintf("%2f", item.MedfeeSumamt) + " " +
|
|
2272
|
+ fmt.Sprintf("%2f", item.FundPaySumamt) + " " +
|
|
2273
|
+ fmt.Sprintf("%2f", item.AcctPay) + " " + refd_setl_flag + "\n"
|
|
2274
|
+ _, err = f.Write([]byte(str))
|
|
2275
|
+ }
|
|
2276
|
+
|
|
2277
|
+ }
|
|
2278
|
+ Zip(file_path, zip_path)
|
|
2279
|
+ if config.IsOpen == 1 {
|
|
2280
|
+ api := "http://127.0.0.1:9532/" + "gdyb/eleven?" +
|
|
2281
|
+ "file_byte=" + string(ReadFile(zip_path)) +
|
|
2282
|
+ "&file_name=" + zip_name +
|
|
2283
|
+ "&fixmedins_code=" + miConfig.Code +
|
|
2284
|
+ "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
|
|
2285
|
+ "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
|
|
2286
|
+ "&secret_key=" + miConfig.SecretKey +
|
|
2287
|
+ "&org_name=" + miConfig.OrgName +
|
|
2288
|
+ "&doctor="
|
|
2289
|
+
|
|
2290
|
+ resp, requestErr := http.Get(api)
|
|
2291
|
+ if requestErr != nil {
|
|
2292
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2293
|
+ return
|
|
2294
|
+ }
|
|
2295
|
+ body, ioErr := ioutil.ReadAll(resp.Body)
|
|
2296
|
+ if ioErr != nil {
|
|
2297
|
+ utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
|
|
2298
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2299
|
+ return
|
|
2300
|
+ }
|
|
2301
|
+ var respJSON map[string]interface{}
|
|
2302
|
+ if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
|
|
2303
|
+ utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
|
|
2304
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2305
|
+ return
|
|
2306
|
+ }
|
|
2307
|
+ respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
|
|
2308
|
+ userJSONBytes, _ := json.Marshal(respJSON)
|
|
2309
|
+
|
|
2310
|
+ var res ResultNine
|
|
2311
|
+ if err := json.Unmarshal(userJSONBytes, &res); err != nil {
|
|
2312
|
+ utils.ErrorLog("解析失败:%v", err)
|
|
2313
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2314
|
+ return
|
|
2315
|
+ }
|
|
2316
|
+ if res.Infcode == 0 {
|
|
2317
|
+
|
|
2318
|
+ api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
|
|
2319
|
+ "file_qury_no=" + res.Output.FileQuryNo +
|
|
2320
|
+ "&setl_optins=" + miConfig.OrgName +
|
|
2321
|
+ "&stmt_begndate=" + start_time +
|
|
2322
|
+ "&stm_enddate=" + end_time +
|
|
2323
|
+ "&medfee_sumamt=" + fmt.Sprintf("%2f", medfee_sumamt) +
|
|
2324
|
+ "&fund_pay_sumamt=" + fmt.Sprintf("%2f", fund_pay_sumamt) +
|
|
2325
|
+ "&cash_payamt=" + fmt.Sprintf("%2f", psn_cash_pay) +
|
|
2326
|
+ "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
|
|
2327
|
+ "&fixmedins_code=" + miConfig.Code +
|
|
2328
|
+ "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
|
|
2329
|
+ "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
|
|
2330
|
+ "&secret_key=" + miConfig.SecretKey +
|
|
2331
|
+ "&org_name=" + miConfig.OrgName +
|
|
2332
|
+ "&doctor="
|
|
2333
|
+
|
|
2334
|
+ resp, requestErr := http.Get(api)
|
|
2335
|
+ if requestErr != nil {
|
|
2336
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2337
|
+ return
|
|
2338
|
+ }
|
|
2339
|
+ body, ioErr := ioutil.ReadAll(resp.Body)
|
|
2340
|
+ if ioErr != nil {
|
|
2341
|
+ utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
|
|
2342
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2343
|
+ return
|
|
2344
|
+ }
|
|
2345
|
+ var respJSON map[string]interface{}
|
|
2346
|
+ if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
|
|
2347
|
+ utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
|
|
2348
|
+ c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
2349
|
+ return
|
|
2350
|
+ }
|
|
2351
|
+ respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
|
|
2352
|
+ userJSONBytes, _ := json.Marshal(respJSON)
|
|
2353
|
+ fmt.Println(respJSON)
|
|
2354
|
+ fmt.Println(userJSONBytes)
|
|
2355
|
+
|
|
2356
|
+ } else {
|
|
2357
|
+
|
|
2358
|
+ }
|
|
2359
|
+ }
|
|
2360
|
+}
|
|
2361
|
+
|
2098
|
2362
|
func (this *HisApiController) AdditionalCharge() {
|
2099
|
2363
|
|
2100
|
2364
|
dataBody := make(map[string]interface{}, 0)
|
|
@@ -2229,3 +2493,100 @@ func (this *DialysisApiController) GetCallHisPrescription() {
|
2229
|
2493
|
return
|
2230
|
2494
|
}
|
2231
|
2495
|
}
|
|
2496
|
+
|
|
2497
|
+func PathExists(path string) (bool, error) {
|
|
2498
|
+ _, err := os.Stat(path)
|
|
2499
|
+ if err == nil {
|
|
2500
|
+ return true, nil
|
|
2501
|
+ }
|
|
2502
|
+ if os.IsNotExist(err) {
|
|
2503
|
+ return false, nil
|
|
2504
|
+ }
|
|
2505
|
+ return false, err
|
|
2506
|
+}
|
|
2507
|
+
|
|
2508
|
+//创建文件夹
|
|
2509
|
+func Mkdir(dir string) {
|
|
2510
|
+ // 创建文件夹
|
|
2511
|
+ exist, err := PathExists(dir)
|
|
2512
|
+ if err != nil {
|
|
2513
|
+ fmt.Println(err.Error())
|
|
2514
|
+ } else {
|
|
2515
|
+ if exist {
|
|
2516
|
+ fmt.Println(dir + "文件夹已存在!")
|
|
2517
|
+ } else {
|
|
2518
|
+ // 文件夹名称,权限
|
|
2519
|
+ err := os.Mkdir(dir, os.ModePerm)
|
|
2520
|
+ if err != nil {
|
|
2521
|
+ fmt.Println(dir+"文件夹创建失败:", err.Error())
|
|
2522
|
+ } else {
|
|
2523
|
+ fmt.Println(dir + "文件夹创建成功!")
|
|
2524
|
+ }
|
|
2525
|
+ }
|
|
2526
|
+ }
|
|
2527
|
+}
|
|
2528
|
+
|
|
2529
|
+//压缩文件
|
|
2530
|
+func Zip(srcFile string, destZip string) error {
|
|
2531
|
+ zipfile, err := os.Create(destZip)
|
|
2532
|
+ if err != nil {
|
|
2533
|
+ return err
|
|
2534
|
+ }
|
|
2535
|
+ defer zipfile.Close()
|
|
2536
|
+
|
|
2537
|
+ archive := zip.NewWriter(zipfile)
|
|
2538
|
+ defer archive.Close()
|
|
2539
|
+
|
|
2540
|
+ filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
|
|
2541
|
+ if err != nil {
|
|
2542
|
+ return err
|
|
2543
|
+ }
|
|
2544
|
+
|
|
2545
|
+ header, err := zip.FileInfoHeader(info)
|
|
2546
|
+ if err != nil {
|
|
2547
|
+ return err
|
|
2548
|
+ }
|
|
2549
|
+
|
|
2550
|
+ header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
|
|
2551
|
+ // header.Name = path
|
|
2552
|
+ if info.IsDir() {
|
|
2553
|
+ header.Name += "/"
|
|
2554
|
+ } else {
|
|
2555
|
+ header.Method = zip.Deflate
|
|
2556
|
+ }
|
|
2557
|
+
|
|
2558
|
+ writer, err := archive.CreateHeader(header)
|
|
2559
|
+ if err != nil {
|
|
2560
|
+ return err
|
|
2561
|
+ }
|
|
2562
|
+
|
|
2563
|
+ if !info.IsDir() {
|
|
2564
|
+ file, err := os.Open(path)
|
|
2565
|
+ if err != nil {
|
|
2566
|
+ return err
|
|
2567
|
+ }
|
|
2568
|
+ defer file.Close()
|
|
2569
|
+ _, err = io.Copy(writer, file)
|
|
2570
|
+ }
|
|
2571
|
+ return err
|
|
2572
|
+ })
|
|
2573
|
+
|
|
2574
|
+ return err
|
|
2575
|
+}
|
|
2576
|
+
|
|
2577
|
+func ReadFile(filePath string) []byte {
|
|
2578
|
+ f, err := os.Open(filePath)
|
|
2579
|
+ if err != nil {
|
|
2580
|
+ fmt.Println("read file fail", err)
|
|
2581
|
+ return nil
|
|
2582
|
+ }
|
|
2583
|
+ defer f.Close()
|
|
2584
|
+
|
|
2585
|
+ fd, err := ioutil.ReadAll(f)
|
|
2586
|
+ if err != nil {
|
|
2587
|
+ fmt.Println("read to fd fail", err)
|
|
2588
|
+ return nil
|
|
2589
|
+ }
|
|
2590
|
+
|
|
2591
|
+ return fd
|
|
2592
|
+}
|