浏览代码

合同同步 调整

baishaojie 1 年之前
父节点
当前提交
aaae80dbe6
共有 6 个文件被更改,包括 46 次插入24 次删除
  1. 16 4
      apiserver/service/contract.go
  2. 10 14
      apiserver/service/job.go
  3. 6 2
      apiserver/service/order.go
  4. 2 2
      cmd/main.go
  5. 二进制
      cmd/sh/eqserver
  6. 12 2
      pkg/util/mail.go

+ 16 - 4
apiserver/service/contract.go

@@ -47,10 +47,10 @@ func GetBigContractData() []*model.BigContract {
 	}
 
 	for _, item := range bigContractData {
-		if item.SHStatus == 7 && item.SHtype == 3 && item.CGChargedate.UnixNano() > time.Now().AddDate(0, 0, -1).UnixNano() {
+		if item.SHStatus == 7 && item.SHtype == 3 && item.CGChargedate.UnixNano() > time.Now().AddDate(0, 0, -5).UnixNano() {
 			contractCodeSlice := strings.Split(item.ContractCode, "-")
 			contractCode := contractCodeSlice[0]
-			s.d.DB.Exec(`update contract  set isToSap = 0 where enable = 1 and bigid in(select id from bigContract where like ? )`, "%"+contractCode+"%")
+			s.d.DB.Exec(`update contract  set isToSap = 0 where enable = 1 and bigid in(select id from bigContract  where contractCode like ? )`, "%"+contractCode+"%")
 		}
 	}
 
@@ -177,11 +177,23 @@ func AutoContractToASP() {
 				errBigContract = append(errBigContract, bigContracts...)
 				errContract = append(errContract, contracts...)
 			}
+
+			var idList []int
 			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)
+						exist := false
+						for _, id := range idList {
+							if id == c.ID {
+								exist = true
+								break
+							}
+						}
+						if !exist {
+							idList = append(idList, c.ID)
+							if err := s.d.DB.Table("contract").Where("id = ?", c.ID).Update("isToSap", 1).Error; err != nil {
+								log.Errorf("AutoContractToASP SQLUpdate Error:%v", err)
+							}
 						}
 					}
 				}

+ 10 - 14
apiserver/service/job.go

@@ -62,20 +62,7 @@ func SapJobInit() {
 		s.d.DB.Exec(`call wxmsg()`)
 	})
 
-	c1.AddFunc("0 10 16 * * ?", func() {
-		cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -1).Format("2006-01-02"))
-
-		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)
-		}
-
-	})
-
-	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() {
+	c1.AddFunc("0 37 23 * * ?", func() {
 		AutoContractToASP()
 	})
 
@@ -91,6 +78,15 @@ func SapJobInit() {
 		}
 	})
 
+	c1.AddFunc("0 10 16 * * ?", func() {
+		cownum_sqlserver.SyncCownum(s.sqlserver, s.d, time.Now().AddDate(0, 0, -4).Format("2006-01-02"))
+		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.Start()
 }
 

+ 6 - 2
apiserver/service/order.go

@@ -460,14 +460,18 @@ func SrmOrder(p *model.BigBuyDetail, IsReturn string) {
 	rbyte, _ := json.Marshal([]interface{}{r.Data})
 	fmt.Println(string(rbyte))
 	saplog := new(model.SapLog)
+	saplog.Url = r.Url
+	saplog.Param = string(rbyte)
+	saplog.Name = "srm采购订单"
 	if e := s.SyncSrm(r, rp, rbyte); e != nil {
+		saplog.MsgText = e.Error()
 		s.d.DB.Create(saplog)
 		log.Errorf("sap buy order error: %v", e)
 		p.SapStatus = 3
 	} else {
+		saplog.MsgText = rp.Message
 		s.d.DB.Create(saplog)
 		if rp.Success {
-			// log.Infof("buy order success :eq=%s,sap=%s", rp.Data.EqNumber, rp.Data.SapNumber)
 			p.SapStatus = 1
 			p.SapNumber = rp.Code
 		} else {
@@ -871,9 +875,9 @@ func SrmReturnOrder(p *model.BigRefunddetail, isReturn string) {
 		log.Errorf("sap buy order error: %v", e)
 		p.SapStatus = 3
 	} else {
+		saplog.MsgText = rp.Message
 		s.d.DB.Create(saplog)
 		if rp.Success {
-			// log.Infof("buy order success :eq=%s,sap=%s", rp.Data.EqNumber, rp.Data.SapNumber)
 			p.SapStatus = 1
 			p.SapNumber = rp.Code
 		} else {

+ 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


+ 12 - 2
pkg/util/mail.go

@@ -2448,8 +2448,13 @@ func DownloadEquipment(parammaps string) (string, error) {
 				}
 				//value := []interface{}{columns[z], v["pastureName"], "全厂区", v["monthBudget"], v["monthLimit"], v["qmonthBudget"], v["sumPrice"],
 				//	v["asave"], v["realReason"], v["oneCowBudget"], v["oneCowLimit"], v["oneCowQmonthBudget"], v["oneCowSumPrice"], v["oneCowAsave"]}
+				s := v["realReason"]
+				if index := strings.Index(s, "."); index != -1 && len(s)-index-1 >= 2 {
+					s = s[:index+3]
+				}
+
 				value := []interface{}{columnName, v["pastureName"], "全厂区", v["monthBudget"], v["sumPrice"],
-					v["asave"], v["realReason"], v["oneCowSumPrice"]}
+					v["asave"], s, v["oneCowSumPrice"]}
 				for a, b := range value {
 					f.SetCellValue("设备指标", letters[a]+strconv.Itoa(i+xx+3), b)
 				}
@@ -2521,8 +2526,13 @@ func DownloadEquipment(parammaps string) (string, error) {
 				//}
 				//value := []interface{}{v["sort"], v["pastureName"], v["deptname"], v["monthBudget"], v["monthLimit"], v["qmonthBudget"], v["sumPrice"],
 				//	v["asave"], v["realReason"], v["oneCowBudget"], v["oneCowLimit"], v["oneCowQmonthBudget"], v["oneCowSumPrice"], v["oneCowAsave"]}
+
+				s := v["realReason"]
+				if index := strings.Index(s, "."); index != -1 && len(s)-index-1 >= 2 {
+					s = s[:index+3]
+				}
 				value := []interface{}{v["sort"], v["pastureName"], v["deptname"], v["monthBudget"], v["sumPrice"],
-					v["asave"], v["realReason"], v["oneCowSumPrice"]}
+					v["asave"], s, v["oneCowSumPrice"]}
 				for a, b := range value {
 					f.SetCellValue(columnss[z], letters[a]+strconv.Itoa(i+3), b)
 				}