瀏覽代碼

合同同步

baishaojie 1 年之前
父節點
當前提交
704942d0ed
共有 5 個文件被更改,包括 83 次插入120 次删除
  1. 42 29
      apiserver/routers/api/db.go
  2. 38 15
      apiserver/service/contract.go
  3. 1 74
      apiserver/service/job.go
  4. 2 2
      cmd/main.go
  5. 二進制
      cmd/sh/eqserver

+ 42 - 29
apiserver/routers/api/db.go

@@ -3497,38 +3497,51 @@ func GetWaterAndElectricity(context *gin.Context) {
 	dataByte, _ := ioutil.ReadAll(context.Request.Body)
 	fsion := gofasion.NewFasion(string(dataByte))
 	//filename := context.Param("filename")
-	sqlnamestr := fsion.Get("name").ValueStr()
+	//sqlnamestr := parammap.Get("name").ValueStr()
 	pastureName := fsion.Get("pastureId").ValueStr()
 	//pastureName := fsion.Get("pasture").ValueStr()
 	//date := fsion.Get("date").ValueStr()
-	parammap := fsion.Get("parammaps")
-	logging.Info("DownloadMailReport ", context.Keys, sqlnamestr, pastureName)
+	//parammap := fsion.Get("parammaps")
+	//logging.Info("DownloadMailReport ", context.Keys, sqlnamestr, pastureName)
+	parammap := make(map[string]string, 0)
+	//layout := "2006-01-02"
+	//date, err := time.Parse(layout, "2023-06-01")
+	//if err != nil {
+	//	fmt.Println(err)
+	//}
+
+	//获取当月第一天
+	//firstOfMonth := time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, date.Location())
+	//fmt.Println("当月第一天:", firstOfMonth)
+
+	//获取下个月第一天,然后减去一天即为当月最后一天
+	//nextMonth := firstOfMonth.AddDate(0, 1, 0)
+	//lastOfMonth := nextMonth.AddDate(0, 0, -1)
+
+	//parammap["startTime"] = firstOfMonth.Format("2006-01-02")
+	//parammap["endTime"] = lastOfMonth.Format("2006-01-02")
+	parammap["startTime"] = fsion.Get("startTime").ValueStr()
+	parammap["endTime"] = fsion.Get("endTime").ValueStr()
+	//if fsion.Get("pastureId").ValueStr() == "现代牧业" {
+	//	parammap["pastureId"] = ""
+	//} else {
+	parammap["pastureId"] = fsion.Get("pastureId").ValueStr()
+	//}
+
 	sqlnamesDepartment := []string{}
-	///"维修费","水费","电费","柴油费","水量","电量","柴油用量"
 	if pastureName == "现代牧业" {
 		sqlnamesDepartment = []string{
-			"getChooseWaterPrice",
-			"getChooseElectricityPrice",
-			"getChooseMonthiolPrice"}
+			"getChooseMonthWater",
+			"getChooseMonthElectricity",
+			"getChooseMonthOilT"}
 	} else {
 		sqlnamesDepartment = []string{
-			"getChooseWaterPriceByPasture",
-			"getChooseElectricityPriceByPasture",
-			"getChooseMonthiolPriceByPasture"}
+			"getChooseMonthWaterByPasture",
+			"getChooseMonthElectricityByPasture",
+			"getChooseMonthOilTByPasture"}
 	}
 
-	//if pastureId == "现代牧业" {
-	//	sqlnames = []string{"getChooseEqMonthBudgetListSumAll", "getChooseMonthWX", "getChooseWaterPrice", "getChooseElectricityPrice", "getChooseMonthiolPrice",
-	//		"getChooseMonthWater", "getChooseMonthElectricity", "getChooseMonthOilT", "getLgnitionChargePrice", "getChooseBiomassPrice", "getChooseGasolinePrice",
-	//		"getChooseCoalPrice"}
-	//} else {
-	//	sqlnames = []string{"getChooseEqMonthBudgetListSumAllByPasture", "getChooseMonthWXByPasture", "getChooseWaterPriceByPasture", "getChooseElectricityPriceByPasture", "getChooseMonthiolPriceByPasture",
-	//		"getChooseMonthWaterByPasture", "getChooseMonthElectricityByPasture", "getChooseMonthOilTByPasture", "getLgnitionChargePriceByPasture", "getChooseBiomassPriceByPasture", "getChooseGasolinePriceByPasture",
-	//		"getChooseCoalPriceByPasture"}
-	//}
-
 	respMapList := make([]map[string]string, 0)
-
 	for _, sqlname := range sqlnamesDepartment {
 		valuesMap, err := restful.MapStr("SELECT sqlstr,params FROM apisql WHERE sqlname = ? AND ENABLE>0 ", sqlname)
 		//parammap := make(map[string]interface{}, 0)
@@ -3537,11 +3550,11 @@ func GetWaterAndElectricity(context *gin.Context) {
 		paramslist := strings.Split(valuesMap["params"], ",")
 		if len(paramslist) > 0 && valuesMap["params"] != "" {
 			for _, value := range paramslist {
-				if value == "pastureId" && parammap.Get("pastureId").ValueStr() == "" {
+				if value == "pastureId" && parammap["pastureId"] == "" {
 					s_params = append(s_params, "现代牧业")
 					continue
 				}
-				s_params = append(s_params, parammap.Get(strings.Trim(value, " ")).ValueStr())
+				s_params = append(s_params, parammap[strings.Trim(value, " ")])
 			}
 		}
 		values, err := restful.MapStrList(valuesMap["sqlstr"], s_params...)
@@ -3553,13 +3566,13 @@ func GetWaterAndElectricity(context *gin.Context) {
 				for _, item := range respMapList {
 					if item["pastureName"] == v["pastureName"] {
 						exist = true
-						if sqlname == "getChooseWaterPrice" || sqlname == "getChooseWaterPriceByPasture" {
+						if sqlname == "getChooseMonthWater" || sqlname == "getChooseMonthWaterByPasture" {
 							item["waterOneCowSumPrice"] = v["oneCowSumPrice"]
 							item["waterSumPrice"] = v["sumPrice"]
-						} else if sqlname == "getChooseElectricityPrice" || sqlname == "getChooseElectricityPriceByPasture" {
+						} else if sqlname == "getChooseMonthElectricity" || sqlname == "getChooseMonthElectricityByPasture" {
 							item["electricityOneCowSumPrice"] = v["oneCowSumPrice"]
 							item["electricitySumPrice"] = v["sumPrice"]
-						} else if sqlname == "getChooseMonthiolPrice" || sqlname == "getChooseMonthiolPriceByPasture" {
+						} else if sqlname == "getChooseMonthOilT" || sqlname == "getChooseMonthOilTByPasture" {
 							item["monthiolOneCowSumPrice"] = v["oneCowSumPrice"]
 							item["monthiolSumPrice"] = v["sumPrice"]
 						}
@@ -3569,13 +3582,13 @@ func GetWaterAndElectricity(context *gin.Context) {
 				if !exist {
 					respMap := make(map[string]string, 0)
 					respMap["pastureName"] = v["pastureName"]
-					if sqlname == "getChooseWaterPrice" || sqlname == "getChooseWaterPriceByPasture" {
+					if sqlname == "getChooseMonthWater" || sqlname == "getChooseMonthWaterByPasture" {
 						respMap["waterOneCowSumPrice"] = v["oneCowSumPrice"]
 						respMap["waterSumPrice"] = v["sumPrice"]
-					} else if sqlname == "getChooseElectricityPrice" || sqlname == "getChooseElectricityPriceByPasture" {
+					} else if sqlname == "getChooseMonthElectricity" || sqlname == "getChooseMonthElectricityByPasture" {
 						respMap["electricityOneCowSumPrice"] = v["oneCowSumPrice"]
 						respMap["electricitySumPrice"] = v["sumPrice"]
-					} else if sqlname == "getChooseMonthiolPrice" || sqlname == "getChooseMonthiolPriceByPasture" {
+					} else if sqlname == "getChooseMonthOilT" || sqlname == "getChooseMonthOilTByPasture" {
 						respMap["monthiolOneCowSumPrice"] = v["oneCowSumPrice"]
 						respMap["monthiolSumPrice"] = v["sumPrice"]
 					}

+ 38 - 15
apiserver/service/contract.go

@@ -122,7 +122,10 @@ func AutoContractToASP() {
 	bigContractData := GetBigContractData()
 	ContractCodeMap := make(map[string][]*model.PastureBigcontract, 0)
 	errDataList := make(map[string][]*model.ContractSapErr, 0)
-	contractInfoList := make([]*ContractInfo, 0)
+
+	errBigContract := make([]*model.BigContract, 0)
+	errContract := make([]*model.Contract, 0)
+
 	for _, bigContract := range bigContractData {
 		contractCode := bigContract.ContractCode
 		if bigContract.SHStatus != 7 {
@@ -157,7 +160,7 @@ func AutoContractToASP() {
 		}
 
 		if _, ok := ContractCodeMap[contractCode]; ok {
-
+			contractInfoList := make([]*ContractInfo, 0)
 			for _, pastureBigContract := range ContractCodeMap[contractCode] {
 				// 获取合同相关数据集合
 				contractInfo := GetContractInfo(bigContract, pastureBigContract)
@@ -166,15 +169,24 @@ func AutoContractToASP() {
 				}
 
 				// 发送数据至SAP
-				errData := PushContractDataToSAP(bigContract, contractInfo, contractCode)
+				errData, bigContracts, contracts := PushContractDataToSAP(bigContract, contractInfo, contractCode)
 				for _, data := range errData {
 					errDataList[contractCode] = append(errDataList[contractCode], data...)
 				}
 				contractInfoList = append(contractInfoList, contractInfo)
-				//go func(bigContract *model.BigContract, contractInfo *ContractInfo) {
-				//}(bigContract, contractInfo)
-				//ContractCodeMap[contractCode] = append(ContractCodeMap[contractCode], pastureBigContract)
+				errBigContract = append(errBigContract, bigContracts...)
+				errContract = append(errContract, contracts...)
+			}
+			for _, contractInfo := range contractInfoList {
+				for _, c := range contractInfo.Contract {
+					if c.IsToSap == 0 {
+						if err := s.d.DB.Table("contract").Where("id = ?", c.ID).Update("isToSap", 1).Error; err != nil {
+							log.Errorf("AutoContractToASP SQLUpdate Error:%v", err)
+						}
+					}
+				}
 			}
+
 		}
 	}
 	now := time.Now()
@@ -185,13 +197,14 @@ func AutoContractToASP() {
 		}
 	}
 
-	for _, contractInfo := range contractInfoList {
-		for _, c := range contractInfo.Contract {
-			if c.IsToSap == 0 {
-				if err := s.d.DB.Table("contract").Where("id = ?", c.ID).Update("isToSap", 1).Error; err != nil {
-					log.Errorf("AutoContractToASP SQLUpdate Error:%v", err)
-				}
-			}
+	for _, item := range errBigContract {
+		if err := s.d.DB.Debug().Table(new(model.BigContract).TableName()).Where("id =  ? ", item.ID).Update("isToSap", 0).Error; err != nil {
+			log.Errorf("AutoContractToASP SQLUpdate Error:%v", err)
+		}
+	}
+	for _, c := range errContract {
+		if err := s.d.DB.Table("contract").Where("id = ?", c.ID).Update("isToSap", 0).Error; err != nil {
+			log.Errorf("AutoContractToASP SQLUpdate Error:%v", err)
 		}
 	}
 
@@ -199,8 +212,11 @@ func AutoContractToASP() {
 }
 
 // PushContractDataToSAP 同步数据给SAP
-func PushContractDataToSAP(bigContract *model.BigContract, contractInfo *ContractInfo, contractCode string) map[string][]*model.ContractSapErr {
+func PushContractDataToSAP(bigContract *model.BigContract, contractInfo *ContractInfo, contractCode string) (map[string][]*model.ContractSapErr, []*model.BigContract, []*model.Contract) {
 	errMap := make(map[string][]*model.ContractSapErr, 0)
+	errBigContract := make([]*model.BigContract, 0)
+	errContract := make([]*model.Contract, 0)
+
 	for _, contract := range contractInfo.Contract {
 		if contract.IsToSap == 1 {
 			continue
@@ -285,8 +301,15 @@ func PushContractDataToSAP(bigContract *model.BigContract, contractInfo *Contrac
 				ContractCode:  contractCode,
 			})
 		}
+		if rp.Dest.Status == "" {
+			errContract = append(errContract, contract)
+		}
+	}
+
+	if len(errContract) > 0 {
+		errBigContract = append(errBigContract, bigContract)
 	}
-	return errMap
+	return errMap, errBigContract, errContract
 }
 
 func RemoveRepeatedElement1(arr []string) (newArr []string) {

+ 1 - 74
apiserver/service/job.go

@@ -23,27 +23,7 @@ func SapJobInit() {
 		AutoSrmReturnOrderJob()
 	})
 	c.Start()
-	/*
-		var t time.Time
-		t = time.Now()
-		var code string
-		pastureList := make([]*model.Pasture, 0)
-		err := s.d.DB.Table("pasture").Where("vendor = 1").Find(&pastureList)
-		fmt.Println(err)
-		i := -120
-		for {
-			fmt.Println(i, t.AddDate(0, 0, i))
-			for _, pasture := range pastureList {
-				//s.SapSupplier(t, pasture.CompanyCode, pasture.ID)
-				s.SapAsset(t.AddDate(0, 0, i), code, pasture.CompanyCode)
-			}
 
-			if t.AddDate(0, 0, i).Format("2006-01-02") == "2023-05-24" {
-				break
-			}
-			i++
-		}
-	*/
 	c1 := cron.New()
 	c1.AddFunc("0 50 23 * * ?", func() {
 		fmt.Println(time.Now())
@@ -82,23 +62,6 @@ func SapJobInit() {
 		s.d.DB.Exec(`call wxmsg()`)
 	})
 
-	//i := -10
-	//for {
-	//	now := time.Now().AddDate(0, 0, i).Format("2006-01-02")
-	//	fmt.Println(now)
-	//	cownum_sqlserver.SyncCownum(s.sqlserver, s.d, now)
-	//	if now == "2023-05-09" {
-	//		break
-	//	}
-	//	i++
-	//}
-
-	//pastureList := make([]*model.Pasture, 0)
-	//s.d.DB.Table("pasture").Where("vendor = 1 ").Where("factory_code  != '' ").Where("factory_code  is not null ").Find(&pastureList)
-	//for _, item := range pastureList {
-	//	AutoFeeQuery(item.FactoryCode, item.ID)
-	//}
-
 	c1.AddFunc("0 10 16 * * ?", func() {
 		cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -1).Format("2006-01-02"))
 
@@ -110,43 +73,7 @@ func SapJobInit() {
 
 	})
 
-	//type aa struct {
-	//	Request string `json:"request" gorm:"column:request"`
-	//}
-	//list := make([]*aa, 0)
-	//s.d.DB.Raw("SELECT * FROM `eq`.`sapapilog` WHERE `name` LIKE '%MM018%'  group by request ").Find(&list)
-	//listMap := make(map[string]string, 0)
-	//for _, item := range list {
-	//	var obj map[string]interface{}
-	//	err := json.Unmarshal([]byte(item.Request), &obj)
-	//	if err != nil {
-	//		panic(err)
-	//	}
-	//
-	//	code, ok := obj["DATA"].(map[string]interface{})["Code"].(string)
-	//	if !ok {
-	//		panic("Code not found or not a string")
-	//	}
-	//
-	//	//var code string
-	//	//fmt.Println(code)
-	//	if strings.Contains(code, "-") {
-	//		contractCodeSlice := strings.Split(code, "-")
-	//		code = contractCodeSlice[0]
-	//	}
-	//	listMap[code] = code
-	//}
-	////fmt.Println(listMap)
-
-	//for _, code := range list1 {
-	//	//	//list1 = append(list1, item)
-	//	//	fmt.Println(item)
-	//	s.d.DB.Exec(`update  bigcontract set isToSap = 0  where  contractCode like ?`, "%"+code+"%")
-	//	//	s.d.DB.Exec(`update contract set isToSap = 0   where bigid in(select id from  bigcontract  where contractCode like ? )   and  enable = 1`, "%"+item+"%")
-	//}
-	//fmt.Println(list1)
-	//AutoContractToASP()
-	timeLocalSub, _ := time.ParseInLocation("15:04:05", "00:15:00", time.Local)
+	timeLocalSub, _ := time.ParseInLocation("15:04:05", "00:30:00", time.Local)
 	timeLocal, _ := time.ParseInLocation("15:04:05", "00:00:00", time.Local)
 	c1.AddFunc(fmt.Sprintf("@every %v", timeLocalSub.Sub(timeLocal)), func() {
 		AutoContractToASP()

+ 2 - 2
cmd/main.go

@@ -37,8 +37,8 @@ import (
 // @BasePath /
 func main() {
 	var path string
-	path = "./"
-	//path = "D:/catering/eam-go/cmd/"
+	//path = "./"
+	path = "D:/catering/eam-go/cmd/"
 	flag.Parse()
 	setting.Setup(path)
 	dao.Setup()

二進制
cmd/sh/eqserver