Commit d62fbed9 by mushishixian

完善普通的增删改

parent c034f2e2
......@@ -8,28 +8,29 @@ import (
func main() {
//soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl")
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
//soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl")
if err != nil {
log.Fatalf("SoapClient error: %s", err)
}
//(userName, password, slnName, dcName, language, dbType, authPattern)
//("WBYH", "123456", "eas", "demo", "L2", 1, "BaseDB")
//params := gosoap.Params{
// "userName": "WBYH",
// "password": "123456",
// "slnName": "eas",
// "dcName": "demo",
// "language": "L2",
// "dbType": 1,
// "authPattern": "BaseDB",
//}
params:=gosoap.Params{
"json":`{"FType":"material", "FID":"ET9WHFzYagYZf0="}`,
params := gosoap.Params{
"userName": "WBYH",
"password": "123456",
"slnName": "eas",
"dcName": "demo",
"language": "L2",
"dbType": 1,
"authPattern": "BaseDB",
}
//params:=gosoap.Params{
// "json":`{"FType":"material", "FID":"ET9WHFzYagYZf0="}`,
//}
err = soap.Call("synRewriteErpBaseDataStatus", params)
//err = soap.Call("synRewriteErpBaseDataStatus", params)
err = soap.Call("login", params)
if err != nil {
log.Fatalf("Call error: %s", err)
}
......
......@@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
......@@ -68,9 +69,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
}
case "delete":
operateType = "delete"
goods.Status = 0
if logic.CheckGoodsExist(goods.ErpId) {
//如果存在,才进行删除
if err = logic.DeleteGoods(goods.ErpId); err != nil {
if err = logic.DeleteGoods(goods); err != nil {
goto ERR
}
} else {
......@@ -85,7 +87,8 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
if err = SyncGoodsData(operateType, goods); err != nil {
goto ERR
}
fmt.Println("同步成功")
fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("goods", goods.ErpId)
return nil
ERR:
//不存在的erp_id不去操作对应的数据库
......@@ -140,7 +143,7 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
} else if operate == "insert" {
url = configs.BasicApiUrl + "/basic/api/ApiInsertGoodsInfo"
} else {
url = configs.BasicApiUrl + "/basic/api/ApiDeleteGoodsInfo"
url = configs.BasicApiUrl + "/basic/api/ApiUpdateGoodsStatus"
}
req.Debug = false
if operate == "update" || operate == "insert" {
......@@ -159,7 +162,6 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
return
}
} else {
url = configs.BasicApiUrl + "/basic/api/ApiUpdateGoodsStatus"
//删除,软删除
param := req.Param{
"status": 0,
......
......@@ -9,12 +9,12 @@ import (
func main() {
message := make(map[string]interface{})
message = map[string]interface{}{
"type": "save",
"type": "delete",
"data": map[string]string{
"FID": "Z8eVSzSLRXKa7ET9WHFzYagYZf0171=",
"FID": "Z8eVSzSLRXKa7ET9WHFzYagYZf01721=",
"FGoods": "WT0050333",
"FBrand": "深圳市鼎驰达电子有限公司",
"FModel": "",
"FModel": "XXX",
},
}
data, err := json.Marshal(message)
......
......@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"scm_server/internal/logic"
)
type RecvPro struct {
......@@ -21,6 +22,7 @@ func init() {
}
func (t *RecvPro) Consumer(dataByte []byte) error {
fmt.Println(string(dataByte))
var (
err error
message QueueStatus
......@@ -30,10 +32,14 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
//得到message以后,去请求金蝶的接口
fmt.Println("请求金蝶接口")
return nil
//如果失败了,记录到表,并且发送钉钉消息
ERR:
fmt.Println(err)
if err = logic.InsertSyncStatusLog(message.SyncName, message.ErpId, "err.Error()"); err != nil {
fmt.Println(err)
}
return nil
}
......
package main
package product
import (
"encoding/json"
......@@ -6,15 +6,15 @@ import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
)
func main() {
func SyncErpStatus(syncName string, ErpId string) {
message := make(map[string]interface{})
message = map[string]interface{}{
"SyncName": "supplier",
"SyncName": syncName,
"Status": 1,
"ErpId": "test123456",
"ErpId": ErpId,
}
data,err := json.Marshal(message)
if err!=nil {
data, err := json.Marshal(message)
if err != nil {
fmt.Println(err)
}
body := string(data)
......
......@@ -65,9 +65,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
}
case "delete":
operateType = "delete"
supplier.Status = 0
if logic.CheckSupplierExist(supplier.ErpId) {
//如果存在,才进行删除
if err = logic.DeleteSupplier(supplier.ErpId); err != nil {
if err = logic.DeleteSupplier(supplier); err != nil {
goto ERR
}
} else {
......@@ -135,7 +136,7 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
} else if operate == "insert" {
url = configs.BasicApiUrl + "/basic/api/ApiInsertSupplierInfo"
} else {
url = configs.BasicApiUrl + "/basic/api/ApiDeleteSupplierInfo"
url = configs.BasicApiUrl + "/basic/api/ApiUpdateSupplierStatus"
}
req.Debug = false
if operate == "update" || operate == "insert" {
......@@ -154,9 +155,28 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
} else {
param = req.Param{
"erp_supplier_id": supplier.ErpId,
"admin_name": "系统",
"admin_id": 1,
"status": 0,
}
//删除
resp, err = req.Post(url, param)
if err != nil {
return
}
if err = resp.ToJSON(&respData); err != nil {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(supplier.ErpId); err != nil {
return
}
}
return
}
......
......@@ -9,7 +9,7 @@ import (
func main() {
message := make(map[string]interface{})
message = map[string]interface{}{
"type": "save",
"type": "delete",
"data": map[string]string{
"FID": "Z8eVSzSLRXKa7ET9WHFzYagYZf017ff=",
"FNUMBER": "WT0050333",
......
package main
import "scm_server/cmd/source/supplier"
import "scm_server/cmd/source/goods"
func main() {
//forever := make(chan bool)
//go supplier.Import()
supplier.Import()
//supplier.Import()
//<-forever
//customer.Import()
//goods.Import()
goods.Import()
}
......@@ -12,7 +12,7 @@ const InsertGoodsSql = "INSERT INTO `lie_goods` (`goods_name`,`goods_cn_name`,`b
const UpdateGoodsSql = "UPDATE `lie_goods` SET `goods_name` = ? , `goods_cn_name` = ? , `brand_name` = ? , `update_time` = ? WHERE `erp_id` = ?"
const DeleteGoodsSql = "DELETE FROM `lie_goods` WHERE `erp_id` = ?"
const DeleteGoodsSql = "UPDATE `lie_goods` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const WriteGoodsSyncErrorSql = "UPDATE `lie_goods` SET sync_error = ? WHERE goods_id = ?"
......@@ -44,8 +44,8 @@ func UpdateGoods(goods model.Goods) (err error) {
}
//删除供应商
func DeleteGoods(erpId string) (err error) {
_, err = dao.GetDb().Exec(DeleteGoodsSql, erpId)
func DeleteGoods(goods model.Goods) (err error) {
_, err = dao.GetDb().Exec(DeleteGoodsSql, goods.Status, time.Now().Unix(), goods.ErpId)
return
}
......
......@@ -12,7 +12,7 @@ const InsertSupplierSql = "Insert INTO `lie_supplier` (`erp_supplier_code`,`name
const UpdateSupplierSql = "UPDATE `lie_supplier` SET `erp_supplier_code` = ? , `name` = ? , `update_time` = ? WHERE `erp_id` = ?"
const DeleteSupplierSql = "DELETE FROM `lie_supplier` WHERE `erp_id` = ?"
const DeleteSupplierSql = "UPDATE `lie_supplier` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const WriteSupplierSyncErrorSql = "UPDATE `lie_supplier` SET sync_time = ? , sync_status = ? , sync_error = ? WHERE erp_id = ?"
......@@ -28,24 +28,18 @@ func CheckSupplierExist(erpId string) (exist bool) {
//插入供应商
func InsertSupplier(supplier model.Supplier) (err error) {
_, err = dao.GetDb().Exec(InsertSupplierSql, supplier.ErpSupplierCode, supplier.Name, supplier.ErpId, time.Now().Unix(), 0)
if err != nil {
return
}
return nil
}
//更新供应商
func UpdateSupplier(supplier model.Supplier) (err error) {
_, err = dao.GetDb().Exec(UpdateSupplierSql, supplier.ErpSupplierCode, supplier.Name, time.Now().Unix(), supplier.ErpId)
if err != nil {
return
}
return nil
}
//删除供应商
func DeleteSupplier(erpId string) (err error) {
_, err = dao.GetDb().Exec(DeleteSupplierSql, erpId)
func DeleteSupplier(supplier model.Supplier) (err error) {
_, err = dao.GetDb().Exec(DeleteSupplierSql, supplier.Status, time.Now().Unix(), supplier.ErpId)
return
}
......
package logic
import (
"scm_server/internal/dao"
"time"
)
//插入金蝶同步状态错误信息
const InsertSyncStatusLogSql = "Insert Into `lie_sync_status_log` ( `sync_name` , `unique_id` , `error_msg` , `add_time` ) Value (?,?,?,?)"
func InsertSyncStatusLog(syncName, uniqueId, errMsg string) (err error) {
_, err = dao.GetDb().Exec(InsertSyncStatusLogSql, syncName, uniqueId, errMsg, time.Now().Unix())
return
}
......@@ -9,4 +9,5 @@ type Goods struct {
SyncTime int
SyncStatus int
SyncError string
Status int
}
......@@ -8,4 +8,5 @@ type Supplier struct {
SyncTime int
SyncStatus int
SyncError string
Status int
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment