bsj 3 lat temu
rodzic
commit
c704aeded6
9 zmienionych plików z 258 dodań i 151 usunięć
  1. BIN
      __debug_bin.exe
  2. 3 3
      conf/app.ini
  3. 33 11
      routers/api/scheduled.go
  4. 200 129
      routers/api/upload.go
  5. 12 5
      routers/api/user.go
  6. 2 0
      routers/router.go
  7. BIN
      tmrgo
  8. BIN
      tmrgo.zip
  9. 8 3
      update.sql

BIN
__debug_bin.exe


+ 3 - 3
conf/app.ini

@@ -46,9 +46,9 @@ GRFDURL = http://120.48.30.31:88
 Type = mysql
 User = root
 #Password = root
-Host = 127.0.0.1:3309
-Name = tmrwatch
-Password = 123456
+Host = 127.0.0.1:3316
+Name = tmrwatch2
+Password = root
 #Password = root
 #Password = kptzhu@163.com
 #Host = 192.168.1.50:3326

+ 33 - 11
routers/api/scheduled.go

@@ -38,7 +38,7 @@ func CronScheduled(ctx context.Context) {
 		return
 	}
 
-	duetimecst, _ := time.ParseInLocation("15:04:05", "00:01:00", time.Local)
+	duetimecst, _ := time.ParseInLocation("15:04:05", "00:00:30", time.Local)
 	duetimecst1, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
 	spec := fmt.Sprintf("@every %v", duetimecst.Sub(duetimecst1))
 
@@ -519,21 +519,25 @@ func UpdatePush(ctx context.Context, tx *xorm.Session, auto bool, idList []strin
 				data, err := tx.SQL(item.Datasql, args...).Query().List()
 				if err != nil {
 					log.Println("UpdataPush-error-2: ", err)
-					return err
+					continue
 				}
 				if len(data) > 0 {
 					databyte, err := json.Marshal(data)
 					if err != nil {
 						log.Println("UpdataPush-error-3: ", err)
-						return err
+						continue
+					}
+					var method string
+					if item.Datatype == 4 {
+						method = "uploadnewdiliverdata"
 					}
-					UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)))
+					UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)), method)
 				}
 				if len(idList) > 0 {
 					_, err := tx.SQL(fmt.Sprintf(" update downloadedplan_log set status = 1  where id in (%s)", strings.Join(idList, ","))).Execute()
 					if err != nil {
 						log.Println("UpdataPush-error-4: ", err)
-						return err
+						continue
 					}
 				}
 			} else {
@@ -551,18 +555,19 @@ func UpdatePush(ctx context.Context, tx *xorm.Session, auto bool, idList []strin
 				data, err := tx.SQL(item.Datasql, args...).Query().List()
 				if err != nil {
 					log.Println("UpdataPush-error-5: ", err)
-					return err
+					// return err
 				}
 				if len(data) > 0 {
 					databyte, err := json.Marshal(data)
 					if err != nil {
 						log.Println("UpdataPush-error-6: ", err)
-						return err
+						// return err
+						continue
 					}
 					// d, err := OpenFile("a.txt")
 					// d.WriteString()
 					// UDPostPush(fmt.Sprintf(item.Package, string(databyte), len(data)), "application/json")
-					UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)))
+					UDPostPush1(fmt.Sprintf(item.Package, string(databyte), len(data)), "")
 				}
 			}
 		}
@@ -887,10 +892,11 @@ func wxPush(target []string, content []interface{}) {
 	fmt.Println("response Body:", string(body))
 }
 
-func UDPostPush1(data string) {
+func UDPostPush1(data, method string) {
+
 	url := "https://wdc.unidairy.cn/copartner_uploads/"
 	// 超时时间:5秒
-	fmt.Println(data)
+	// fmt.Println(data)
 	var jsonStr = []byte(data)
 	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
 
@@ -898,10 +904,26 @@ func UDPostPush1(data string) {
 	client := &http.Client{}
 	resp, err := client.Do(req)
 	if err != nil {
-		panic(err)
+		logs.Error(err)
 	}
 
 	defer resp.Body.Close()
 	body, _ := ioutil.ReadAll(resp.Body)
 	fmt.Println("response Body:", string(body))
+	fsion := gofasion.NewFasion(string(body))
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+	if fsion.Get("status").ValueStr() != "ok" {
+		_, err := tx.SQL(`update notice set status = 1  where content =  ? `, "downloadedplan_log").Execute()
+		if err != nil {
+			return
+		}
+	}
+	if method == "uploadnewdiliverdata" {
+		_, err = tx.SQL(` insert into log(method,status,data,date)values(?,?,?,now())`, method, fsion.Get("status").ValueStr(), data).Execute()
+		if err != nil {
+			return
+		}
+	}
+
 }

+ 200 - 129
routers/api/upload.go

@@ -5,14 +5,6 @@ import (
 	"encoding/hex"
 	"errors"
 	"fmt"
-	"github.com/axetroy/go-fs"
-	"github.com/gin-gonic/gin"
-	"../../pkg/app"
-	"../../pkg/e"
-	"../../pkg/logging"
-	"../../pkg/setting"
-	"../../routers/restful"
-	"github.com/nfnt/resize"
 	"image"
 	"image/gif"
 	"image/jpeg"
@@ -24,6 +16,17 @@ import (
 	"path"
 	"strconv"
 	"strings"
+
+	"../../pkg/app"
+	"../../pkg/e"
+	"../../pkg/logging"
+	"../../pkg/setting"
+	"../../routers/restful"
+	"github.com/astaxie/beego/logs"
+	"github.com/axetroy/go-fs"
+	"github.com/gin-gonic/gin"
+	"github.com/nfnt/resize"
+	"github.com/tealeg/xlsx"
 )
 
 // 支持的图片后缀名
@@ -46,12 +49,11 @@ Handler the parse error
 */
 func parseFormFail(context *gin.Context) {
 	context.JSON(http.StatusBadRequest, gin.H{
-		"msg" : "fail",
+		"msg":     "fail",
 		"message": "Can not parse form",
 	})
 }
 
-
 /**
 Upload file handler
 */
@@ -59,12 +61,12 @@ func UploadFile(context *gin.Context) {
 	appG := app.Gin{C: context}
 	dictId := context.Param("id")
 	dictName := context.Param("name")
-	logging.Info("UploadFile ",context.Keys,dictId,dictName)
+	logging.Info("UploadFile ", context.Keys, dictId, dictName)
 	var (
 		isSupportFile bool
-		maxUploadSize = setting.AppSetting.FileMaxSize  // 最大上传大小
+		maxUploadSize = setting.AppSetting.FileMaxSize   // 最大上传大小
 		allowTypes    = setting.AppSetting.FileAllowType // 可上传的文件类型
-		distPath      string                  // 最终的输出目录
+		distPath      string                             // 最终的输出目录
 		err           error
 		file          *multipart.FileHeader
 		src           multipart.File
@@ -114,14 +116,14 @@ func UploadFile(context *gin.Context) {
 	fileName := md5string + extname
 	// Destination
 
-	filePath := setting.CurrentPath+setting.AppSetting.FileSavePath+dictName+"/"
-	err = PathCheck(filePath)  //检查路径并创建
+	filePath := setting.CurrentPath + setting.AppSetting.FileSavePath + dictName + "/"
+	err = PathCheck(filePath) //检查路径并创建
 	if err != nil {
-		fmt.Println("PathCheck err",err)
+		fmt.Println("PathCheck err", err)
 	}
 	distPath = path.Join(filePath, fileName)
 	if dist, err = os.Create(distPath); err != nil {
-		fmt.Println("Create err",err)
+		fmt.Println("Create err", err)
 	}
 	defer dist.Close()
 	//distPath = setting.CurrentPath + setting.AppSetting.FileSavePath +"/"+ fileName
@@ -143,46 +145,46 @@ func UploadFile(context *gin.Context) {
 	params := context.Request.Form
 
 	if sqlname != "" {
-		sql, p := restful.GetSqlByNameDB(sqlname)//todo insertcustomdoc
-		if sql != ""{
+		sql, p := restful.GetSqlByNameDB(sqlname) //todo insertcustomdoc
+		if sql != "" {
 			s_params := make([]interface{}, 0)
-			paramslist := strings.Split(p,",")
+			paramslist := strings.Split(p, ",")
 
-			if len(paramslist)>0 && p!="" {
+			if len(paramslist) > 0 && p != "" {
 				for _, value := range paramslist {
-					fmt.Println("s_params value",s_params,value)
-					if (strings.ToLower(strings.Trim(value," "))=="username"){//picpath, picname, username, newpicname
+					fmt.Println("s_params value", s_params, value)
+					if strings.ToLower(strings.Trim(value, " ")) == "username" { //picpath, picname, username, newpicname
 						tempv := params.Get("jwt_username")
 						s_params = append(s_params, tempv)
-					}else if (strings.ToLower(strings.Trim(value," "))=="docname"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "docname" {
 						s_params = append(s_params, file.Filename)
-					}else if (strings.ToLower(strings.Trim(value," "))=="newdocname"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "newdocname" {
 						s_params = append(s_params, fileName)
-					}else if (strings.ToLower(strings.Trim(value," "))=="docpath"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "docpath" {
 						s_params = append(s_params, dictName) //
-					}else if (strings.ToLower(strings.Trim(value," "))=="dictid"){
-						s_params = append(s_params,dictId) //
-						fmt.Println("s_params",s_params,dictId)
-					}else if (strings.ToLower(strings.Trim(value," "))=="filesize"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "dictid" {
+						s_params = append(s_params, dictId) //
+						fmt.Println("s_params", s_params, dictId)
+					} else if strings.ToLower(strings.Trim(value, " ")) == "filesize" {
 						s_params = append(s_params, file.Size) //
-					}else{
-						s_params = append(s_params, params.Get(strings.Trim(value," ")))
+					} else {
+						s_params = append(s_params, params.Get(strings.Trim(value, " ")))
 					}
 				}
 			}
 			execresult, err = execDataBySql(sql, s_params)
-			if err != nil{
-				fmt.Println("execDataBySql err",err)
+			if err != nil {
+				fmt.Println("execDataBySql err", err)
 				appG.Response(http.StatusOK, e.ERROR, err.Error())
 			}
 		}
 	}
 	context.JSON(http.StatusOK, gin.H{
-		"hash":     md5string,
-		"filename": fileName,
-		"origin":   file.Filename,
-		"size":     file.Size,
-		"execresult":     execresult,
+		"hash":       md5string,
+		"filename":   fileName,
+		"origin":     file.Filename,
+		"size":       file.Size,
+		"execresult": execresult,
 	})
 
 }
@@ -191,10 +193,10 @@ func UploadFile(context *gin.Context) {
 Upload image handler
 */
 func UploaderImage(context *gin.Context) {
-	logging.Info("UploaderImage ",context.Keys)
+	logging.Info("UploaderImage ", context.Keys)
 	var (
 		maxUploadSize = setting.AppSetting.ImageMaxSize // 最大上传大小
-		distPath      string                 // 最终的输出目录
+		distPath      string                            // 最终的输出目录
 		err           error
 		file          *multipart.FileHeader
 		src           multipart.File
@@ -236,7 +238,6 @@ func UploaderImage(context *gin.Context) {
 
 	fileName := md5string + extname
 
-
 	//savePathDir := setting.CurrentPath+setting.AppSetting.ImageSavePath+fileName+"/"
 	//_,err = os.Stat(savePathDir)
 	//if err == nil {
@@ -249,14 +250,14 @@ func UploaderImage(context *gin.Context) {
 	//	}//目录不存在则创建
 	//}
 	// Destination
-	picPath := setting.CurrentPath+setting.AppSetting.ImageSavePath+sqlname+"/"
-	err = PathCheck(picPath)  //检查路径并创建
+	picPath := setting.CurrentPath + setting.AppSetting.ImageSavePath + sqlname + "/"
+	err = PathCheck(picPath) //检查路径并创建
 	if err != nil {
-		fmt.Println("PathCheck err",err)
+		fmt.Println("PathCheck err", err)
 	}
 	distPath = path.Join(picPath, fileName)
 	if dist, err = os.Create(distPath); err != nil {
-		fmt.Println("Create err",err)
+		fmt.Println("Create err", err)
 	}
 	defer dist.Close()
 
@@ -271,19 +272,19 @@ func UploaderImage(context *gin.Context) {
 
 	// 压缩缩略图
 	// 不管成功与否,都会进行下一步的返回
-	if _, err := thumbnailify(distPath,sqlname); err != nil {
-		logging.Error("thumbnailify_err",err)
-		picThumbnailPath := setting.CurrentPath+setting.AppSetting.ThumbnailSavePath+sqlname+"/"
+	if _, err := thumbnailify(distPath, sqlname); err != nil {
+		logging.Error("thumbnailify_err", err)
+		picThumbnailPath := setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + sqlname + "/"
 		println(picThumbnailPath)
-		err = PathCheck(picThumbnailPath)  //检查路径并创建
+		err = PathCheck(picThumbnailPath) //检查路径并创建
 		distThumbnailPath := path.Join(picThumbnailPath, fileName)
 		println(distThumbnailPath)
 		distThumbnail, err := os.Create(distThumbnailPath)
-		if  err != nil {
-			fmt.Println("CreateThumbnail err",err)
+		if err != nil {
+			fmt.Println("CreateThumbnail err", err)
 		}
 		srcThumbnail, err := file.Open()
-		if  err != nil {
+		if err != nil {
 			//
 		}
 		io.Copy(distThumbnail, srcThumbnail)
@@ -296,49 +297,48 @@ func UploaderImage(context *gin.Context) {
 
 	if sqlname != "" {
 		sql, p := restful.GetSqlByNameDB(sqlname)
-		if sql != ""{
+		if sql != "" {
 			s_params := make([]interface{}, 0)
-			paramslist := strings.Split(p,",")
-			if len(paramslist)>0 && p!="" {
+			paramslist := strings.Split(p, ",")
+			if len(paramslist) > 0 && p != "" {
 				for _, value := range paramslist {
-					if (strings.ToLower(strings.Trim(value," "))=="username"){//picpath, picname, username, newpicname
+					if strings.ToLower(strings.Trim(value, " ")) == "username" { //picpath, picname, username, newpicname
 						tempv := params.Get("jwt_username")
 						s_params = append(s_params, tempv)
-					}else if (strings.ToLower(strings.Trim(value," "))=="picname"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "picname" {
 						s_params = append(s_params, file.Filename)
-					}else if (strings.ToLower(strings.Trim(value," "))=="newpicname"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "newpicname" {
 						s_params = append(s_params, fileName)
-					}else if (strings.ToLower(strings.Trim(value," "))=="picpath"){
+					} else if strings.ToLower(strings.Trim(value, " ")) == "picpath" {
 						s_params = append(s_params, sqlname) //全路径加文件名
-					} else{
-						s_params = append(s_params, params.Get(strings.Trim(value," ")))
+					} else {
+						s_params = append(s_params, params.Get(strings.Trim(value, " ")))
 					}
 				}
 			}
 			execresult, err = execDataBySql(sql, s_params)
-			if err != nil{
-				fmt.Println("execDataBySql err",err)
+			if err != nil {
+				fmt.Println("execDataBySql err", err)
 			}
 		}
 	}
 	context.JSON(http.StatusOK, gin.H{
-		"hash":     md5string,
-		"filename": fileName,
-		"origin":   file.Filename,
-		"size":     file.Size,
-		"execresult":     execresult,
+		"hash":       md5string,
+		"filename":   fileName,
+		"origin":     file.Filename,
+		"size":       file.Size,
+		"execresult": execresult,
 	})
 }
 
-
 /**
 Upload image handler
 */
 func UploaderTmrImage(context *gin.Context) {
-	logging.Info("UploaderTmrImage ",context.Keys)
+	logging.Info("UploaderTmrImage ", context.Keys)
 	var (
 		maxUploadSize = setting.AppSetting.ImageMaxSize // 最大上传大小
-		distPath      string                 // 最终的输出目录
+		distPath      string                            // 最终的输出目录
 		err           error
 		file          *multipart.FileHeader
 		src           multipart.File
@@ -352,24 +352,23 @@ func UploaderTmrImage(context *gin.Context) {
 
 	pastureid := context.GetHeader("pastureid") //牧场id
 	projuctid := context.GetHeader("projuctid") // 主计划id
-	pfid := context.GetHeader("pfid")		// 配方id
-	optid := context.GetHeader("optid")	//子计划id
+	pfid := context.GetHeader("pfid")           // 配方id
+	optid := context.GetHeader("optid")         //子计划id
 	catchtime := context.GetHeader("catchtime") // 捕获时间
-	picclass := context.GetHeader("picclass") // 图片分类
-
+	picclass := context.GetHeader("picclass")   // 图片分类
 
 	extname := strings.ToLower(path.Ext(file.Filename))
 
 	if isImage(extname) == false {
 		context.JSON(http.StatusBadRequest, gin.H{
-			"msg" : "fail",
+			"msg":     "fail",
 			"message": "不支持的上传文件类型: " + extname,
 		})
 		return
 	}
 	if file.Size > int64(maxUploadSize) {
 		context.JSON(http.StatusBadRequest, gin.H{
-			"msg" : "fail",
+			"msg":     "fail",
 			"message": "上传文件太大, 最大文件大小限制为(byte): " + strconv.Itoa(int(maxUploadSize)),
 		})
 		return
@@ -388,7 +387,6 @@ func UploaderTmrImage(context *gin.Context) {
 
 	fileName := md5string + extname
 
-
 	//savePathDir := setting.CurrentPath+setting.AppSetting.ImageSavePath+fileName+"/"
 	//_,err = os.Stat(savePathDir)
 	//if err == nil {
@@ -401,14 +399,14 @@ func UploaderTmrImage(context *gin.Context) {
 	//	}//目录不存在则创建
 	//}
 	// Destination
-	picPath := setting.CurrentPath+setting.AppSetting.ImageSavePath+projuctid+"/"
-	err = PathCheck(picPath)  //检查路径并创建
+	picPath := setting.CurrentPath + setting.AppSetting.ImageSavePath + projuctid + "/"
+	err = PathCheck(picPath) //检查路径并创建
 	if err != nil {
-		fmt.Println("PathCheck err",err)
+		fmt.Println("PathCheck err", err)
 	}
 	distPath = path.Join(picPath, fileName)
 	if dist, err = os.Create(distPath); err != nil {
-		fmt.Println("Create err",err)
+		fmt.Println("Create err", err)
 	}
 	defer dist.Close()
 
@@ -423,19 +421,19 @@ func UploaderTmrImage(context *gin.Context) {
 
 	// 压缩缩略图
 	// 不管成功与否,都会进行下一步的返回
-	if _, err := thumbnailify(distPath,projuctid); err != nil {
-		logging.Error("thumbnailify_err",err)
-		picThumbnailPath := setting.CurrentPath+setting.AppSetting.ThumbnailSavePath+projuctid+"/"
+	if _, err := thumbnailify(distPath, projuctid); err != nil {
+		logging.Error("thumbnailify_err", err)
+		picThumbnailPath := setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + projuctid + "/"
 		println(picThumbnailPath)
-		err = PathCheck(picThumbnailPath)  //检查路径并创建
+		err = PathCheck(picThumbnailPath) //检查路径并创建
 		distThumbnailPath := path.Join(picThumbnailPath, fileName)
 		println(distThumbnailPath)
 		distThumbnail, err := os.Create(distThumbnailPath)
-		if  err != nil {
-			fmt.Println("CreateThumbnail err",err)
+		if err != nil {
+			fmt.Println("CreateThumbnail err", err)
 		}
 		srcThumbnail, err := file.Open()
-		if  err != nil {
+		if err != nil {
 			//
 		}
 		io.Copy(distThumbnail, srcThumbnail)
@@ -449,12 +447,12 @@ func UploaderTmrImage(context *gin.Context) {
 
 	if sqlname != "" {
 		sql, p := restful.GetSqlByNameDB(sqlname)
-		if sql != ""{
+		if sql != "" {
 			s_params := make([]interface{}, 0)
-			paramslist := strings.Split(p,",")
-			if len(paramslist)>0 && p!="" {
+			paramslist := strings.Split(p, ",")
+			if len(paramslist) > 0 && p != "" {
 				for _, value := range paramslist {
-					switch strings.ToLower(strings.Trim(value," ")) {
+					switch strings.ToLower(strings.Trim(value, " ")) {
 					case "username":
 						tempv := params.Get("jwt_username")
 						s_params = append(s_params, tempv)
@@ -477,23 +475,23 @@ func UploaderTmrImage(context *gin.Context) {
 					case "picclass":
 						s_params = append(s_params, picclass)
 					default:
-						s_params = append(s_params, params.Get(strings.Trim(value," ")))
+						s_params = append(s_params, params.Get(strings.Trim(value, " ")))
 					}
 				}
 			}
 			execresult, err = execDataBySql(sql, s_params)
-			if err != nil{
-				fmt.Println("execDataBySql err",err)
+			if err != nil {
+				fmt.Println("execDataBySql err", err)
 			}
 		}
 	}
 	context.JSON(http.StatusOK, gin.H{
-		"msg" : "ok",
-		"hash":     md5string,
-		"filename": fileName,
-		"origin":   file.Filename,
-		"size":     file.Size,
-		"execresult":     execresult,
+		"msg":        "ok",
+		"hash":       md5string,
+		"filename":   fileName,
+		"origin":     file.Filename,
+		"size":       file.Size,
+		"execresult": execresult,
 	})
 }
 
@@ -502,7 +500,7 @@ Get file raw
 */
 func GetFileRaw(context *gin.Context) {
 	filename := context.Param("filename")
-	logging.Info("GetFileRaw ",context.Keys,filename)
+	logging.Info("GetFileRaw ", context.Keys, filename)
 
 	filePath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, filename)
 	if isExistFile := fs.PathExists(filePath); isExistFile == false {
@@ -518,13 +516,13 @@ Download a file
 */
 func DownloadFile(context *gin.Context) {
 	filename := context.Param("filename")
-	logging.Info("DownloadFile ",context.Keys,filename)
+	logging.Info("DownloadFile ", context.Keys, filename)
 	eqpic, _ := restful.Engine.SQL("SELECT * FROM eq_doc where id = ? ", filename).QueryString()
 	if eqpic == nil {
 		http.NotFound(context.Writer, context.Request)
 		return
 	}
-	originFilePath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath,eqpic[0]["docpath"],eqpic[0]["newdocname"])
+	originFilePath := path.Join(setting.CurrentPath, setting.AppSetting.FileSavePath, eqpic[0]["docpath"], eqpic[0]["newdocname"])
 	if fs.PathExists(originFilePath) == false {
 		// if the path not found
 		http.NotFound(context.Writer, context.Request)
@@ -534,20 +532,19 @@ func DownloadFile(context *gin.Context) {
 
 }
 
-
 /**
 Get Origin image
 */
 func GetOriginImage(context *gin.Context) {
 	//appG := app.Gin{C: context}
 	filename := context.Param("filename")
-	logging.Info("GetOriginImage ",context.Keys,filename)
+	logging.Info("GetOriginImage ", context.Keys, filename)
 	eqpic, _ := restful.Engine.SQL("SELECT * FROM eq_pic where id = ? ", filename).QueryString()
 	if eqpic == nil {
 		http.NotFound(context.Writer, context.Request)
 		return
 	}
-	originImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath,eqpic[0]["picpath"],eqpic[0]["newpicname"])
+	originImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath, eqpic[0]["picpath"], eqpic[0]["newpicname"])
 	if fs.PathExists(originImagePath) == false {
 		// if the path not found
 		http.NotFound(context.Writer, context.Request)
@@ -562,13 +559,13 @@ Get thumbnail image
 */
 func GetThumbnailImage(context *gin.Context) {
 	filename := context.Param("filename")
-	logging.Info("GetThumbnailImage ",context.Keys,filename)
+	logging.Info("GetThumbnailImage ", context.Keys, filename)
 	eqpic, _ := restful.Engine.SQL("SELECT * FROM eq_pic where id = ? ", filename).QueryString()
 	if eqpic == nil {
 		http.NotFound(context.Writer, context.Request)
 		return
 	}
-	thumbnailImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ThumbnailSavePath,eqpic[0]["picpath"],eqpic[0]["newpicname"])
+	thumbnailImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ThumbnailSavePath, eqpic[0]["picpath"], eqpic[0]["newpicname"])
 	originImagePath := path.Join(setting.CurrentPath, setting.AppSetting.ImageSavePath, filename)
 
 	if fs.PathExists(thumbnailImagePath) == false {
@@ -587,17 +584,17 @@ func GetThumbnailImage(context *gin.Context) {
 /**
 Generate thumbnail
 */
-func thumbnailify(imagePath,subdirectory string) (outputPath string, err error) {
+func thumbnailify(imagePath, subdirectory string) (outputPath string, err error) {
 	var (
-		file     *os.File
-		img      image.Image
+		file *os.File
+		img  image.Image
 	)
 	Filename := strings.ToLower(path.Base(imagePath))
 	extname := strings.ToLower(path.Ext(imagePath))
-	outputPath = setting.CurrentPath + setting.AppSetting.ThumbnailSavePath +subdirectory+ "/" +  Filename
-	err = PathCheck(setting.CurrentPath + setting.AppSetting.ThumbnailSavePath +subdirectory)
-	if err !=nil{
-		fmt.Println("thumbnailify PathCheck err",err)
+	outputPath = setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + subdirectory + "/" + Filename
+	err = PathCheck(setting.CurrentPath + setting.AppSetting.ThumbnailSavePath + subdirectory)
+	if err != nil {
+		fmt.Println("thumbnailify PathCheck err", err)
 	}
 	// 读取文件
 	if file, err = os.Open(imagePath); err != nil {
@@ -627,7 +624,7 @@ func thumbnailify(imagePath,subdirectory string) (outputPath string, err error)
 		return
 	}
 
-	m := resize.Thumbnail(uint( setting.AppSetting.ThumbnailMaxWidth), uint(setting.AppSetting.ThumbnailMaxHeight), img, resize.Lanczos3)
+	m := resize.Thumbnail(uint(setting.AppSetting.ThumbnailMaxWidth), uint(setting.AppSetting.ThumbnailMaxHeight), img, resize.Lanczos3)
 
 	out, err := os.Create(outputPath)
 	if err != nil {
@@ -657,7 +654,7 @@ func thumbnailify(imagePath,subdirectory string) (outputPath string, err error)
 }
 
 func UploadFiles(c *gin.Context) {
-	logging.Info("UploadFiles ",c.Keys)
+	logging.Info("UploadFiles ", c.Keys)
 	appG := app.Gin{C: c}
 	err := c.Request.ParseMultipartForm(200000)
 	if err != nil {
@@ -696,16 +693,16 @@ func UploadFiles(c *gin.Context) {
 		appG.Response(http.StatusOK, e.SUCCESS, "upload successful \n")
 	}
 }
-func PathCheck(path string)(err error){
-	b,err :=PathExists(path)
-	if  err != nil {
-		fmt.Println("exist err",err)
+func PathCheck(path string) (err error) {
+	b, err := PathExists(path)
+	if err != nil {
+		fmt.Println("exist err", err)
 	}
-	if !b{
-		fmt.Println(path,"  目录不存在,重新创建")
+	if !b {
+		fmt.Println(path, "  目录不存在,重新创建")
 		err = os.Mkdir(path, 0777)
-		if  err != nil {
-			fmt.Println("Mkdir err",err)
+		if err != nil {
+			fmt.Println("Mkdir err", err)
 		}
 	}
 	return
@@ -719,4 +716,78 @@ func PathExists(path string) (bool, error) {
 		return false, nil
 	}
 	return false, err
-}
+}
+
+func GetBarfeedremainExcel(c *gin.Context) {
+
+	var file *xlsx.File
+	var sheet *xlsx.Sheet
+	var row *xlsx.Row
+	var cell *xlsx.Cell
+	style := xlsx.NewStyle()
+	style.ApplyBorder = true
+	border := *xlsx.NewBorder("thin", "thin", "thin", "thin")
+
+	style.Border = border
+
+	style.Font.Size = 11
+	style.Alignment = xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+		// ShrinkToFit: true,
+
+	}
+	style.ApplyBorder = true
+
+	file = xlsx.NewFile()
+	sheet, _ = file.AddSheet("Sheet1")
+	// row = sheet.AddRow()
+	// cell = row.AddCell()
+
+	row = sheet.AddRow()
+	cell = row.AddCell()
+	cell.Value = "栏舍名称"
+	// cell.Merge(0, 1)
+	cell.SetStyle(style)
+	cell = row.AddCell()
+
+	cell.SetValue("剩料量(kg)")
+	cell.SetStyle(style)
+	cell = row.AddCell()
+
+	cell.SetValue("班次(第一班,第二班,第三班)")
+	cell.SetStyle(style)
+	cell = row.AddCell()
+
+	cell.SetValue("收集时间")
+	cell.SetStyle(style)
+	cell = row.AddCell()
+
+	cell.SetValue("操作人")
+	cell.SetStyle(style)
+	cell = row.AddCell()
+
+	tx := restful.Engine.NewSession()
+	defer tx.Close()
+
+	dataList, err := tx.SQL(`select bname from bar  where pastureid = (select column_default  as pastureid   from    information_schema.COLUMNS 
+		WHERE table_name = 'recweight' AND table_schema = ? AND column_name = 'pastureid') order by sort ,id`, setting.DatabaseSetting.Name).Query().List()
+	if err != nil {
+		logs.Error("CronScheduled-error-1:", err)
+		return
+	}
+
+	for _, data := range dataList {
+		row = sheet.AddRow()
+		cell = row.AddCell()
+		cell.SetValue(data["bname"])
+		cell.SetStyle(style)
+	}
+
+	c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
+	c.Header("Content-Disposition", "attachment; filename="+"栏舍剩料记录导入模板.xlsx")
+	c.Header("Content-Transfer-Encoding", "binary")
+
+	_ = file.Write(c.Writer)
+}

+ 12 - 5
routers/api/user.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"strings"
 
 	"../../pkg/app"
 	"../../pkg/e"
@@ -171,18 +172,24 @@ func UserWXOpenIDBinding(c *gin.Context) {
 	dataByte, _ := ioutil.ReadAll(c.Request.Body)
 	fsion := gofasion.NewFasion(string(dataByte))
 	openid := fsion.Get("openid").ValueStr()
-	pastureid := fsion.Get("pastureid").ValueStr()
-	userid := fsion.Get("userid").ValueStr()
+	// pastureid := fsion.Get("pastureid").ValueStr()
+	userinfo := fsion.Get("userinfo").ValueStr()
 	tx := restful.Engine.NewSession()
 	defer tx.Close()
 
-	_, err := tx.SQL(` replace into user_wx(userid,pastureid,openid) VALUES (?,?,?)`, userid, pastureid, openid).Execute()
+	userlist := strings.Split(userinfo, ".")
+	if len(userlist) < 3 {
+		logs.Error("UserWXOpenIDBinding-error1:", nil)
+		appG.Response(http.StatusInternalServerError, e.ERROR, false)
+		return
+	}
+
+	_, err := tx.SQL(` replace into user_wx(userid,pastureid,openid,name) VALUES (?,(select  pastureid  from user where username = ?),?,?)`, userlist[1], userlist[1], openid, userlist[2]).Execute()
 	if err != nil {
-		logs.Error("UserWXOpenIDBinding-error1:", err)
+		logs.Error("UserWXOpenIDBinding-error2:", err)
 		appG.Response(http.StatusInternalServerError, e.ERROR, false)
 		return
 	}
 
-	fmt.Println(pastureid, userid, openid)
 	appG.Response(http.StatusOK, e.SUCCESS, true)
 }

+ 2 - 0
routers/router.go

@@ -177,6 +177,8 @@ func InitRouter() *gin.Engine {
 
 		apiV1.POST("/fpdimportexcel", api.FpdImportExcel)
 
+		apiV1.POST("/barfeedremain/excel", api.GetBarfeedremainExcel)
+
 	}
 
 	//不需要登录验证的接口

BIN
tmrgo


BIN
tmrgo.zip


+ 8 - 3
update.sql

@@ -137,6 +137,11 @@ pennsieve,dungsieve,dungscore,bodyscore
 
 
 
-
-
-        
+CREATE TABLE `log` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `method` varchar(255) DEFAULT NULL,
+  `status` varchar(255) DEFAULT NULL,
+  `data` longtext DEFAULT NULL,
+  `date` datetime DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;