Commit a6aa2bb2 by mushishixian

完善修复客户导入逻辑

parent 474a76e6
package customer
import (
"fmt"
"github.com/imroc/req"
"github.com/tealeg/xlsx"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
"scm_server/internal/model"
)
//导入委托方的信息(excel导入)
func Imports() {
var (
excelFileName string
xlFile *xlsx.File
err error
customer model.Customer
)
excelFileName = "./cmd/source/data/customer.xlsx"
xlFile, err = xlsx.OpenFile(excelFileName)
if err != nil {
fmt.Printf("open failed: %s\n", err)
}
//循环遍历数据
for _, sheet := range xlFile.Sheets {
for key, row := range sheet.Rows {
if key == 0 {
continue
}
customer.ErpId = row.Cells[0].String()
customer.ErpClientCode = row.Cells[1].String()
customer.Name = row.Cells[2].String()
//存在的记录跳过
if logic.CheckCustomerExist(customer.ErpId) {
continue
}
if err = logic.InsertCustomer(customer); err != nil {
fmt.Println(err)
break
}
//插入成功后还要去请求后端接口同步数据
SyncCustomerData(customer)
}
}
}
//同步数据
func SyncCustomerData(customer model.Customer) bool {
var (
resp *req.Resp
url string
respData common.Response
err error
)
param := req.Param{
"erp_client_sn": customer.ErpClientCode,
"customer_name": customer.Name,
"erp_customer_id": customer.ErpId,
"admin_name": "系统",
"admin_id": 1,
}
url = configs.BasicApiUrl + "/basic/api/ApiInsertCustomerInfo"
req.Debug = true
resp, err = req.Post(url, param)
if err != nil {
logSyncErrorToDataBase(customer.ErpId, err.Error())
return false
}
if err = resp.ToJSON(&respData); err != nil {
logSyncErrorToDataBase(customer.ErpId, err.Error())
return false
}
if respData.Errcode != 101100 {
logSyncErrorToDataBase(customer.ErpId, respData.Errmsg)
return false
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(customer.ErpId); err != nil {
fmt.Println(err)
}
}
func logSyncErrorToDataBase(erpId, syncError string) {
var err error
//请求失败的话,将原因存起来
if err = logic.WriteCustomerSyncError(erpId, syncError); err != nil {
//写数据失败,记录到日志
fmt.Println(err)
}
}
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq" "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/mushishixian/gosoap" "github.com/mushishixian/gosoap"
"github.com/pkg/errors" "github.com/pkg/errors"
"scm_server/cmd/queue/sync_audit_status/product"
"scm_server/configs" "scm_server/configs"
"scm_server/internal/logic" "scm_server/internal/logic"
"scm_server/internal/model" "scm_server/internal/model"
...@@ -26,7 +25,7 @@ type QueueAuditStatus struct { ...@@ -26,7 +25,7 @@ type QueueAuditStatus struct {
} }
func init() { func init() {
product.SyncErpStatus("in_store", "+7fvorsZSAevQCJ7ujsbLMBZJbY=") //product.SyncErpStatus("in_store", "+7fvorsZSAevQCJ7ujsbLMBZJbY=")
log.Init(nil) log.Init(nil)
} }
......
...@@ -51,8 +51,8 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -51,8 +51,8 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
//判断操作类型 //判断操作类型
switch message.Type { switch message.Type {
case "save": case "save":
//先去查询是否存在,不存在才去插入,已经存在即是修改 //先去查询是否存在已经同步完成的记录
if logic.CheckCustomerExist(customer.ErpId) { if logic.CheckCustomerSyncStatus(customer.ErpId) {
operateType = "update" operateType = "update"
if err = logic.UpdateCustomer(customer); err != nil { if err = logic.UpdateCustomer(customer); err != nil {
goto ERR goto ERR
...@@ -76,7 +76,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -76,7 +76,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR goto ERR
} }
default: default:
err = errors.New("同步客户出现不存在的操作类型" + operateType) err = errors.New("同步客户出现不存在的操作类型 : " + operateType)
goto ERR goto ERR
} }
//操作成功后还要去请求后端接口同步数据 //操作成功后还要去请求后端接口同步数据
......
...@@ -18,11 +18,11 @@ func main() { ...@@ -18,11 +18,11 @@ func main() {
// }, // },
//} //}
message = map[string]interface{}{ message = map[string]interface{}{
"type": "save", "type": "delete",
"data": map[string]string{ "data": map[string]string{
"FID": "Bg/8bD0XRdayeQFMFsSgY6gYZf0=111", "FID": "Dd3D2Z6NRHClK+vLy4+g8qgYZf0=",
"FNUMBER": "WT00013", "FNUMBER": "WT00021",
"CFNAME": "深圳市肯特尔科技有限公司", "CFNAME": "深圳市深之和电子有限公司",
}, },
} }
data, err := json.Marshal(message) data, err := json.Marshal(message)
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
const CheckCustomerExistSql = "SELECT customer_id FROM lie_customer WHERE erp_id = ?" const CheckCustomerExistSql = "SELECT customer_id FROM lie_customer WHERE erp_id = ?"
const CheckCustomerSyncStatusSql = "SELECT status FROM lie_customer WHERE erp_id = ?" const CheckCustomerSyncStatusSql = "SELECT sync_status FROM lie_customer WHERE erp_id = ?"
const InsertCustomerSql = "Insert INTO `lie_customer` (`erp_client_code`,`name`,`erp_id`,`add_time`,`sync_status`) VALUES (?,?,?,?,?)" const InsertCustomerSql = "Insert INTO `lie_customer` (`erp_client_code`,`name`,`erp_id`,`add_time`,`sync_status`) VALUES (?,?,?,?,?)"
...@@ -16,8 +16,6 @@ const UpdateCustomerSql = "UPDATE `lie_customer` SET `erp_client_code` = ? , `na ...@@ -16,8 +16,6 @@ const UpdateCustomerSql = "UPDATE `lie_customer` SET `erp_client_code` = ? , `na
const DeleteCustomerSql = "UPDATE `lie_customer` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?" const DeleteCustomerSql = "UPDATE `lie_customer` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const WriteCustomerSyncErrorSql = "UPDATE `lie_customer` SET sync_error = ? WHERE erp_id = ?"
const SyncCustomerSuccessSql = "UPDATE `lie_customer` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?" const SyncCustomerSuccessSql = "UPDATE `lie_customer` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
//检查用户是否存在 //检查用户是否存在
...@@ -30,17 +28,16 @@ func CheckCustomerExist(erpId string) (exist bool) { ...@@ -30,17 +28,16 @@ func CheckCustomerExist(erpId string) (exist bool) {
//获取后端同步状态 //获取后端同步状态
func CheckCustomerSyncStatus(erpId string) (status bool) { func CheckCustomerSyncStatus(erpId string) (status bool) {
var statusInt int var statusInt int
dao.GetDb().QueryRow(CheckCustomerSyncStatusSql, erpId).Scan(&statusInt) dao.GetDb().QueryRowx(CheckCustomerSyncStatusSql, erpId).Scan(&statusInt)
return statusInt > 0 return statusInt > 0
} }
//插入用户 //插入用户
func InsertCustomer(customer model.Customer) (err error) { func InsertCustomer(customer model.Customer) (err error) {
_, err = dao.GetDb().Exec(InsertCustomerSql, customer.ErpClientCode, customer.Name, customer.ErpId, time.Now().Unix(), 0) if !CheckCustomerExist(customer.ErpId) {
if err != nil { _, err = dao.GetDb().Exec(InsertCustomerSql, customer.ErpClientCode, customer.Name, customer.ErpId, time.Now().Unix(), 0)
return
} }
return nil return
} }
//更新供应商 //更新供应商
...@@ -58,12 +55,6 @@ func DeleteCustomer(customer model.Customer) (err error) { ...@@ -58,12 +55,6 @@ func DeleteCustomer(customer model.Customer) (err error) {
return return
} }
//写入同步失败的原因
func WriteCustomerSyncError(erpId, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteCustomerSyncErrorSql, syncError, erpId)
return
}
//修改成功的同步状态 //修改成功的同步状态
func SyncCustomerSuccess(erpId string) (err error) { func SyncCustomerSuccess(erpId string) (err error) {
_, err = dao.GetDb().Exec(SyncCustomerSuccessSql, time.Now().Unix(), erpId) _, err = dao.GetDb().Exec(SyncCustomerSuccessSql, time.Now().Unix(), erpId)
......
...@@ -14,8 +14,6 @@ const UpdateGoodsSql = "UPDATE `lie_goods` SET `goods_name` = ? , `goods_cn_name ...@@ -14,8 +14,6 @@ const UpdateGoodsSql = "UPDATE `lie_goods` SET `goods_name` = ? , `goods_cn_name
const DeleteGoodsSql = "UPDATE `lie_goods` SET `status` = ? , `update_time` = ? 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 = ?"
const SyncGoodsSuccessSql = "UPDATE `lie_goods` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?" const SyncGoodsSuccessSql = "UPDATE `lie_goods` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
const SyncGoodsSuccessWithStatusSql = "UPDATE `lie_goods` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?" const SyncGoodsSuccessWithStatusSql = "UPDATE `lie_goods` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?"
...@@ -49,12 +47,6 @@ func DeleteGoods(goods model.Goods) (err error) { ...@@ -49,12 +47,6 @@ func DeleteGoods(goods model.Goods) (err error) {
return return
} }
//写入同步失败的原因
func WriteGoodsSyncError(erpId string, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteGoodsSyncErrorSql, syncError, erpId)
return
}
//修改成功的同步状态 //修改成功的同步状态
func SyncGoodsSuccess(erpId string, isDelete bool) (err error) { func SyncGoodsSuccess(erpId string, isDelete bool) (err error) {
//不是删除,不需要修改状态 //不是删除,不需要修改状态
......
...@@ -55,7 +55,7 @@ func SendDingTalkRobotToApi(content string) { ...@@ -55,7 +55,7 @@ func SendDingTalkRobotToApi(content string) {
var ( var (
requestData DingDingRequest requestData DingDingRequest
apiUrl, token string apiUrl, token string
resp *req.Resp //resp *req.Resp
err error err error
) )
content = "仓储同步告警 : " + content content = "仓储同步告警 : " + content
...@@ -68,9 +68,8 @@ func SendDingTalkRobotToApi(content string) { ...@@ -68,9 +68,8 @@ func SendDingTalkRobotToApi(content string) {
token = "3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3" token = "3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3"
apiUrl = "https://api.ichunt.com/public/dingtalkrobot?access_token=" + token apiUrl = "https://api.ichunt.com/public/dingtalkrobot?access_token=" + token
params := req.BodyJSON(requestData) params := req.BodyJSON(requestData)
resp, err = req.Post(apiUrl, params) _, err = req.Post(apiUrl, params)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
fmt.Println(resp)
} }
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