Эх сурвалжийг харах

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_task into zcx_advisory

xingzai 4 жил өмнө
parent
commit
8cc6bbfdbc

+ 8 - 0
models/report.go

@@ -50,3 +50,11 @@ func DeleteReportSaveLog()  {
 	startDateTime:=time.Now().AddDate(0,-3,0).Format(utils.FormatDateTime)
 	fmt.Println(startDateTime)
 }
+
+func EditReportContentHtml(reportId int, content string) (err error) {
+	o := orm.NewOrm()
+	o.Using("rddp")
+	sql := ` UPDATE report SET content=?,modify_time=NOW() WHERE id=? `
+	_, err = o.Raw(sql, content, reportId).Exec()
+	return
+}

+ 1 - 1
models/users.go

@@ -13,7 +13,7 @@ type HongzeUsers struct {
 }
 
 func GetHongzeUsers() (items []*HongzeUsers, err error) {
-	sql := `select wu.real_name,c.company_name,left(wu.mobile, 11) as mobile ,if(wu.open_id is null,'否','是') as is_register,if(c.type in (1),'是','否') as user_type
+	sql := `select wu.real_name,c.company_name,left(wu.mobile, 11) as mobile ,if(wu.open_id='','否','是') as is_register,if(c.type in (1),'是','否') as user_type
 	from wx_user wu
 	inner join company c on c.company_id = wu.company_id
 	where c.company_id <> 1 and c.company_id <> 16

+ 27 - 32
services/company.go

@@ -47,17 +47,16 @@ func ImportCompany() {
 		rows := sheet.MaxRow
 		for i := 0; i < rows; i++ {
 			if i > 2 {
-				row := sheet.Row(i)
-				cells := row.Cells
-				realName := cells[1].String()
+				row, _ := sheet.Row(i)
+				realName := row.GetCell(1).String()
 				realName = strings.Trim(realName, " ")
 				realName = strings.Replace(realName, " ", "", -1)
 
-				mobile := cells[2].String()
+				mobile := row.GetCell(2).String()
 				mobile = strings.Trim(mobile, " ")
 				mobile = strings.Replace(mobile, " ", "", -1)
 				fmt.Println(mobile)
-				companyName := cells[6].String()
+				companyName := row.GetCell(6).String()
 				fmt.Println(companyName)
 				companyName = strings.Trim(companyName, " ")
 				companyName = strings.Replace(companyName, " ", "", -1)
@@ -161,18 +160,16 @@ func ImportCompanyUsers() {
 		rows := sheet.MaxRow
 		for i := 0; i < rows; i++ {
 			if i > 2 {
-				row := sheet.Row(i)
-				cells := row.Cells
-
-				realName := cells[1].String()
+				row, _ := sheet.Row(i)
+				realName := row.GetCell(1).String()
 				realName = strings.Trim(realName, " ")
 				realName = strings.Replace(realName, " ", "", -1)
 
-				mobile := cells[2].String()
+				mobile := row.GetCell(2).String()
 				mobile = strings.Trim(mobile, " ")
 				mobile = strings.Replace(mobile, " ", "", -1)
 
-				email := cells[5].String()
+				email := row.GetCell(5).String()
 				email = strings.Trim(email, " ")
 				email = strings.Replace(email, " ", "", -1)
 				fmt.Println(mobile)
@@ -223,18 +220,16 @@ func ImportCompanyCreditCode() {
 		rows := sheet.MaxRow
 		for i := 0; i < rows; i++ {
 			if i > 2 {
-				row := sheet.Row(i)
-				cells := row.Cells
-
-				companyName := cells[0].String()
+				row, _ := sheet.Row(i)
+				companyName := row.GetCell(0).String()
 				companyName = strings.Trim(companyName, " ")
 				companyName = strings.Replace(companyName, " ", "", -1)
 
-				creditCode := cells[4].String()
+				creditCode := row.GetCell(4).String()
 				creditCode = strings.Trim(creditCode, " ")
 				creditCode = strings.Replace(creditCode, " ", "", -1)
 
-				industryName := cells[5].String()
+				industryName := row.GetCell(5).String()
 				industryName = strings.Trim(industryName, " ")
 				industryName = strings.Replace(industryName, " ", "", -1)
 
@@ -246,30 +241,30 @@ func ImportCompanyCreditCode() {
 				if companyItem == nil {
 					fmt.Println("companyItem is nil")
 				}
-				count,err:=models.GetCompanyCountByCreditCode(creditCode)
-				if err!=nil {
-					fmt.Println("GetCompanyCountByCreditCode Err:"+err.Error())
+				count, err := models.GetCompanyCountByCreditCode(creditCode)
+				if err != nil {
+					fmt.Println("GetCompanyCountByCreditCode Err:" + err.Error())
 					continue
 				}
-				if count>0 {
+				if count > 0 {
 					fmt.Println("creditCode exist")
 					continue
-				}else{
-					industryItem,err:=models.GetCompanyIndustryByName(industryName)
-					if err!=nil {
-						fmt.Println("GetCompanyIndustryByName Err:"+err.Error())
+				} else {
+					industryItem, err := models.GetCompanyIndustryByName(industryName)
+					if err != nil {
+						fmt.Println("GetCompanyIndustryByName Err:" + err.Error())
 						return
 					}
-					fmt.Println(industryItem.IndustryId,industryItem.IndustryName)
+					fmt.Println(industryItem.IndustryId, industryItem.IndustryName)
 
-					err=models.ModifyCompanyCreditCode(companyItem.CompanyId,creditCode)
-					if err!=nil {
-						fmt.Println("Err:"+err.Error())
+					err = models.ModifyCompanyCreditCode(companyItem.CompanyId, creditCode)
+					if err != nil {
+						fmt.Println("Err:" + err.Error())
 						return
 					}
-					err=models.ModifyCompanyIndustry(industryItem.IndustryId,companyItem.CompanyId,industryName)
-					if err!=nil {
-						fmt.Println("Err:"+err.Error())
+					err = models.ModifyCompanyIndustry(industryItem.IndustryId, companyItem.CompanyId, industryName)
+					if err != nil {
+						fmt.Println("Err:" + err.Error())
 						return
 					}
 				}

+ 12 - 13
services/data_source_longzhong.go

@@ -56,18 +56,17 @@ func GetLongZhongTargetInfoByExcel() {
 		//maxCol := v.MaxCol
 		fmt.Println(classifyName, maxRow)
 		for i := 0; i < maxRow; i++ {
-			row := v.Row(i)
+			row, _ := v.Row(i)
 			longzhongClassify := ""
 			if i > 0 {
-				cells := row.Cells
-				longzhongClassifyNew := cells[0].String()
+				longzhongClassifyNew := row.GetCell(0).String()
 				if longzhongClassifyNew != "" {
 					longzhongClassify = longzhongClassifyNew
 				}
-				secName := cells[1].Value
-				frequency := cells[2].Value
-				LongzhongId := cells[3].Value
-				remark := cells[4].String()
+				secName := row.GetCell(1).Value
+				frequency := row.GetCell(2).Value
+				LongzhongId := row.GetCell(3).Value
+				remark := row.GetCell(4).String()
 				item := new(models.DataSourceLongzhong)
 				item.ClassifyId = classifyId
 				item.ClassifyName = classifyName
@@ -582,7 +581,7 @@ func LzExportExcel() {
 			if len(dataList) <= 0 {
 				for n := 0; n < dataMax; n++ {
 					rowIndex := 5 + n
-					row := sheetNew.Row(rowIndex)
+					row, _ := sheetNew.Row(rowIndex)
 					row.AddCell()
 					row.AddCell()
 					row.AddCell()
@@ -591,7 +590,7 @@ func LzExportExcel() {
 				endRowIndex := 0
 				for rk, dv := range dataList {
 					rowIndex := 5 + rk
-					row := sheetNew.Row(rowIndex)
+					row, _ := sheetNew.Row(rowIndex)
 					row.AddCell().SetValue(dv.Dt)
 					row.AddCell().SetFloat(dv.Close)
 					row.AddCell()
@@ -601,7 +600,7 @@ func LzExportExcel() {
 					dataLen := dataMax - len(dataList)
 					for n := 0; n < dataLen; n++ {
 						rowIndex := (endRowIndex + 1) + n
-						row := sheetNew.Row(rowIndex)
+						row, _ := sheetNew.Row(rowIndex)
 						row.AddCell()
 						row.AddCell()
 						row.AddCell()
@@ -891,7 +890,7 @@ func LzPriceExportExcel() {
 			if len(dataList) <= 0 {
 				for n := 0; n < dataMax; n++ {
 					rowIndex := 8 + n
-					row := sheetNew.Row(rowIndex)
+					row,_:= sheetNew.Row(rowIndex)
 					row.AddCell()
 					row.AddCell()
 					row.AddCell()
@@ -902,7 +901,7 @@ func LzPriceExportExcel() {
 				endRowIndex := 0
 				for rk, dv := range dataList {
 					rowIndex := 8 + rk
-					row := sheetNew.Row(rowIndex)
+					row,_:= sheetNew.Row(rowIndex)
 					row.AddCell().SetValue(dv.PriceDate)
 					row.AddCell().SetFloat(dv.Price)
 					row.AddCell().SetFloat(dv.LowPrice)
@@ -915,7 +914,7 @@ func LzPriceExportExcel() {
 					dataLen := dataMax - len(dataList)
 					for n := 0; n < dataLen; n++ {
 						rowIndex := (endRowIndex + 1) + n
-						row := sheetNew.Row(rowIndex)
+						row,_:= sheetNew.Row(rowIndex)
 						row.AddCell()
 						row.AddCell()
 						row.AddCell()

+ 58 - 65
services/report.go

@@ -6,7 +6,9 @@ import (
 	"hongze/hongze_task/models"
 	"hongze/hongze_task/utils"
 	"html"
+	"os"
 	"strings"
+	"time"
 )
 
 func FixReportContentSub() {
@@ -47,71 +49,62 @@ func FixReportContentSub() {
 		}
 	}
 }
-//
-//func FixReportCount() {
-//	var err error
-//	defer func() {
-//		if err != nil {
-//			fmt.Println("err:", err.Error())
-//		}
-//	}()
-//	list, err := models.GetReportLimit()
-//	if err != nil {
-//		return
-//	}
-//	for _, v := range list {
-//		content := v.Content
-//		contentHtml := html.UnescapeString(content)
-//		doc, err := goquery.NewDocumentFromReader(strings.NewReader(contentHtml))
-//		if err != nil {
-//			fmt.Println("line 70:"+err.Error())
-//			return
-//		}
-//		isModify := false
-//		doc.Find("img").Each(func(i int, img *goquery.Selection) {
-//			imgContent, srcExist := img.Attr("src")
-//			if srcExist {
-//				if strings.Contains(imgContent, "data:image/png;base64,") {
-//					contentBase64 := imgContent
-//					contentBase64 = strings.Replace(contentBase64, "data:image/png;base64,", "", -1)
-//					dateDir := time.Now().Format("20060102")
-//					uploadDir := "./" + dateDir
-//					err = os.MkdirAll(uploadDir, 777)
-//					if err != nil {
-//						return
-//					}
-//					randStr := utils.GetRandStringNoSpecialChar(28)
-//					fileName := randStr + ".png"
-//					fpath := uploadDir + "/" + fileName
-//					utils.SaveBase64ToFile(contentBase64, fpath)
-//					if err != nil {
-//						return
-//					}
-//					//上传到阿里云
-//					resourceUrl, err := services.UploadAliyun(fileName, fpath)
-//					if err != nil {
-//						return
-//					}
-//					img.SetAttr("src", resourceUrl)
-//					isModify = true
-//				}
-//			}
-//		})
-//		contentHtml, _ = doc.Html()
-//		fmt.Println(contentHtml)
-//		fmt.Println("isModify", isModify)
-//		if isModify {
-//			contentHtml, _ = doc.Html()
-//			contentSub, err := services.GetReportContentSub(contentHtml)
-//			if err != nil {
-//				utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
-//			}
-//			contentHtml = html.EscapeString(contentHtml)
-//			contentSub = html.EscapeString(contentSub)
-//			err = models.EditReportContent(v.Id, contentHtml, contentSub)
-//		}
-//	}
-//}
+
+func FixReportCount() {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err.Error())
+		}
+	}()
+	list, err := models.GetReportLimit()
+	if err != nil {
+		return
+	}
+	for _, v := range list {
+		content := v.Content
+		contentHtml := html.UnescapeString(content)
+		doc, err := goquery.NewDocumentFromReader(strings.NewReader(contentHtml))
+		if err != nil {
+			fmt.Println("line 70:"+err.Error())
+			return
+		}
+		isModify := false
+		doc.Find("img").Each(func(i int, img *goquery.Selection) {
+			imgContent, srcExist := img.Attr("src")
+			if srcExist {
+				if strings.Contains(imgContent, "data:image/png;base64,") {
+					contentBase64 := imgContent
+					contentBase64 = strings.Replace(contentBase64, "data:image/png;base64,", "", -1)
+					dateDir := time.Now().Format("20060102")
+					uploadDir := "./" + dateDir
+					err = os.MkdirAll(uploadDir, 777)
+					if err != nil {
+						return
+					}
+					randStr := utils.GetRandStringNoSpecialChar(28)
+					fileName := randStr + ".png"
+					fpath := uploadDir + "/" + fileName
+					utils.SaveBase64ToFile(contentBase64, fpath)
+					if err != nil {
+						return
+					}
+					//上传到阿里云
+					resourceUrl, err := UploadAliyun(fileName, fpath)
+					if err != nil {
+						return
+					}
+					img.SetAttr("src", resourceUrl)
+					isModify = true
+				}
+			}
+		})
+		contentHtml, _ = doc.Html()
+		fmt.Println(contentHtml)
+		fmt.Println("isModify", isModify)
+		err = models.EditReportContentHtml(v.Id, contentHtml)
+	}
+}
 
 func DeleteReportSaveLog()(err error) {
 	fmt.Println("start")

+ 2 - 1
services/task.go

@@ -76,7 +76,8 @@ func TaskTest(){
 
 func Task123() {
 	fmt.Println("start")
-	FreeViewerDetail()
+	//FreeViewerDetail()
+	HongzeUsers()
 	fmt.Println("end")
 	return
 }