Commit 9c318fad by wang

增加同步erp

parent fa5f2cdb
......@@ -31,3 +31,4 @@ cmd.exe~
/cmd/http
/resources
/cmd/test
/cmd/cron/mqtest
\ No newline at end of file
......@@ -28,7 +28,7 @@ func main() {
//flag.StringVar(&taskName, "taskName", "supplierMerge", "任务名称")
//flag.Parse()
service.NewErpService().SyncErp()
service.NewServiceSupplier().MappingHandle(4)
//service.NewServiceLy().Merger()//联营sku整合
return
switch taskName {
......@@ -58,6 +58,11 @@ func main() {
return
service.NewServiceLy().Merger()//联营sku整合
break
case "erpSkuMerge":
fmt.Println("erpSku整合")
return
service.NewErpService().SyncErp()
break
}
//fmt.Println("啥也没执行")
//service.NewServiceSupplier().MergerCriteria()//标准供应商处理
......
[xorm]
ShowSQL = true
ShowSQL = false
[pool_class]
user_name = root
......
3629,深圳市弘安盛电子有限公司,深圳市弘安盛电子有限公司,D0000724,韦燕,代理,
3858,福州新拓电子有限公司,福州新拓电子有限公司,D0000383,王秋,代理,
4831,深圳市信宏泰电子有限公司,深圳市信宏泰电子有限公司,0030000018,朱玉嘉,代理,
1612,深圳视创盈科技有限公司,深圳视创盈科技有限公司,M0001606,王秋,贸易商,
2884,深圳市恒迪通电子有限公司,深圳市恒迪通电子有限公司,M0000913,韦燕,贸易商,
6988,深圳市立创电子商务有限公司,深圳市立创电子商务有限公司,M0000203,朱玉嘉,分销商/平台,
......@@ -4,13 +4,17 @@ import (
"encoding/json"
"fmt"
"github.com/gogf/gf/util/gconv"
"go_supplier_task/pkg/common"
syncLog "go_supplier_task/pkg/logger/sync"
"go_supplier_task/pkg/mq"
//"go_supplier_task/pkg/mq"
"go_supplier_task/pkg/mysql"
"strings"
)
var ErpTaskName ="[同步到erp]"
type ErpService struct {
ServiceCommonSupplier
}
var CurrencyMapping =map[int]interface{}{
......@@ -25,6 +29,18 @@ var StatusMapping=map[int]interface{}{
2:"1",
-2:"2",
}
var SupplierGroup =map[int]interface{}{
1 : "D",
2 : "M",
3 : "P",
4 : "Y",
5 : "A",
6 : "O",
0 : "E",
}
func NewErpService() *ErpService{
......@@ -65,6 +81,7 @@ func (this *ErpService) SyncErp() {
func (this *ErpService) pushErp(poolSupplierEntity *PoolSupplierEntity) {
defer panic("测试:执行一个就退出")
/**
{"name":"深圳市朋友有限責任公司",
"shortName":"朋友",
......@@ -89,9 +106,22 @@ func (this *ErpService) pushErp(poolSupplierEntity *PoolSupplierEntity) {
personName:=this.GetPersonNames(poolSupplierEntity)
pushErpData["personName"]=personName
pushErpData["address"]=poolSupplierEntity.SupplierAddress
bytes,_:=json.Marshal(pushErpData)
fmt.Println(string(bytes))
has,contactInfo:=this.GetContact(poolSupplierEntity.SupplierId)
if(!has){
common.PrintStdout().Printf("supplierID:%d,没有找到对应的contact 数据",poolSupplierEntity.SupplierId)
}
pushErpData["contactPerson"]=contactInfo["supplier_consignee"]
pushErpData["phone"]=contactInfo["supplier_telephone"]
pushErpData["groupNumber"]=gconv.String(SupplierGroup[poolSupplierEntity.SupplierGroup])
bytes,err:=json.Marshal(pushErpData)
if(err!=nil){
syncLog.SyncInsertLog("erp_merger", ErpTaskName+"同步erp数据 json.Marshal 出错,err:"+err.Error())
panic(nil)
}
fmt.Println(string(bytes))
mq.PushMsg("supplier_sync",string(bytes))
//fmt.Println(poolSupplierEntity)
}
......@@ -99,20 +129,25 @@ func (this *ErpService) pushErp(poolSupplierEntity *PoolSupplierEntity) {
/*
待续
*/
func (this *ErpService) GetContact(poolSupplierEntity *PoolSupplierEntity) {
func (this *ErpService) GetContact(supplierId int64) ( bool, map[string]string ){
dbSpu := mysql.Conn("supp") //spu实例化链接
sql := " SELECT t.supplier_consignee,t.supplier_telephone,t.supplier_mobile from lie_supplier_channel c INNER JOIN lie_supplier_contact t on c.supplier_id=t.supplier_id where c.supplier_id = ? order by t.contact_id limit 1"
res, err := dbSpu.QueryString(sql, poolSupplierEntity.SupplierId)
sql:="SELECT supplier_consignee,supplier_telephone,supplier_mobile from lie_supplier_contact where supplier_id=? order by contact_id LIMIT 1"
res, err := dbSpu.QueryString(sql, supplierId)
if err != nil {
syncLog.SyncInsertLog("erp_merger", ErpTaskName+"查询lie_supplier_contact出错,err:"+err.Error())
panic(nil)
}
fmt.Println(res)
}
if(len(res)>0){
return true,res[0]
}else{
return false,res[0]
}
}
func (this *ErpService)GetPersonNames(poolSupplierEntity *PoolSupplierEntity)[]string{
poolSupplierEntity.ChannelUid="1366,1363"
//poolSupplierEntity.ChannelUid="1366,1363"
adminIds:=strings.Split(poolSupplierEntity.ChannelUid, ",")
codeIds:=make([]interface{},0)
for _,id:=range adminIds {
......
......@@ -3,6 +3,7 @@ package service
import (
"fmt"
dmysql "github.com/go-sql-driver/mysql"
"github.com/gogf/gf/util/gconv"
"github.com/syyongx/php2go"
"go_supplier_task/pkg/common"
syncLog "go_supplier_task/pkg/logger/sync"
......@@ -12,6 +13,17 @@ import (
var TaskName string
var SupplierGroupCn =map[string]interface{}{
"代理商" : 1,
"贸易商" : 2,
"方案商IDH/IDM" : 3,
"原厂" : 4,
"分销商/平台" : 5,
"FEMS/OEM/ODM" : 6,
}
/**
映射处理
*/
......@@ -24,16 +36,21 @@ func (this *ServiceSupplier)MappingHandle(MappingType int) {
common.PrintStdout().Printf("[整合联营数据]开始\n")
csvPath=this.getResourcesPath()+"/lySupplier.csv"
break
case 2://金蝶erp
TaskName="[整合ERP映射]"
common.PrintStdout().Printf("[整合金蝶erp]开始\n")
csvPath=this.getResourcesPath()+"/erpSupplier.csv"
case 2://金蝶erp自营
TaskName="[整合ERP自营映射]"
common.PrintStdout().Printf("[整合ERP自营映射]开始\n")
csvPath=this.getResourcesPath()+"/erpSupplierZy.csv"
break
case 3://自营
TaskName="[整合自营映射]"
common.PrintStdout().Printf("[整合自营]开始\n")
csvPath=this.getResourcesPath()+"/zySupplier.csv"
break
case 4://金蝶erp联营
TaskName="[整合ERP联营映射]"
common.PrintStdout().Printf("[整合ERP联营映射]开始\n")
csvPath=this.getResourcesPath()+"/erpSupplierLy.csv"
break
default:
panic(fmt.Sprintf("来源类型出错%d",MappingType))
}
......@@ -50,7 +67,7 @@ func (this *ServiceSupplier)MappingHandle(MappingType int) {
purchaseNames=append(purchaseNames,OldSupplier["purchaseName"])
}
}
dbSuplierInfo:=this.GetStatus2SupplierInfo(groupName,purchaseNames)
dbSuplierInfo:=this.GetStatus2SupplierInfo(groupName,purchaseNames,data[0]["class"])
//mappingSupplierS:=make([]SupplierMappingEntity,0)
for _,OldSupplier:=range data{
......@@ -65,6 +82,7 @@ func (this *ServiceSupplier)MappingHandle(MappingType int) {
//mappingSupplierS=append(mappingSupplierS,NewMapping)
this.InsertMapping(NewMapping)
}
// panic("测试:执行一组就退出")//测试执行一个就退出
}
}
......@@ -72,9 +90,9 @@ func (this *ServiceSupplier)MappingHandle(MappingType int) {
/**
获取指定 supplierName 的供应商详情(状态是2的,is_type=0的),没有就新增
@purchaseNames 采购员s(excel 一个标准供应商有多个供应商,可能每个供应商都有采购员),用作新增供应商修改采购商
@groupName 分组名称
*/
func (this *ServiceSupplier) GetStatus2SupplierInfo(supplierName string,purchaseNames []interface{}) PoolSupplierEntity {
func (this *ServiceSupplier) GetStatus2SupplierInfo(supplierName string,purchaseNames []interface{},groupName string) PoolSupplierEntity {
//todo 如果没有就新增,然后返回
dbSpu:= mysql.Conn("supp") //spu实例化链接
poolSupplierEntity:=PoolSupplierEntity{}
......@@ -115,6 +133,8 @@ func (this *ServiceSupplier) GetStatus2SupplierInfo(supplierName string,purchase
channelUidString=php2go.Implode(",",channelUidS)
poolSupplierEntity.ChannelUid=channelUidString
//end
poolSupplierEntity.SupplierGroup= gconv.Int(SupplierGroupCn[groupName])
//修改
_,err= dbSpu.Table("lie_supplier_channel").Where("supplier_id=?",poolSupplierEntity.SupplierId).Update(&poolSupplierEntity)
if(err!=nil){
......@@ -141,7 +161,7 @@ func (this *ServiceSupplier) InsertMapping(SupplierInfoOne SupplierMappingEntity
UNIQUE KEY `source_name_unique` (`old_supplier_name`,`source`)
*/
if(mysqlErr.Number==1062 && strings.Contains(mysqlErr.Message,"source_name_unique")){//
errMsg:=fmt.Sprintf(TaskName+"[插入映射]出错:excel有重复的映射关系 type:%d,标准名称:%s,标准ID:%d,errmsg:%s",SupplierInfoOne.Source,SupplierInfoOne.SupplierName,SupplierInfoOne.SupplierId,err.Error())
errMsg:=fmt.Sprintf(TaskName+"[插入映射]出错:跳过:有重复的映射关系 type:%d,标准名称:%s,标准ID:%d,errmsg:%s",SupplierInfoOne.Source,SupplierInfoOne.SupplierName,SupplierInfoOne.SupplierId,err.Error())
syncLog.SyncInsertLog("mapping_insert",errMsg,syncLog.LogLevelFatal)
return
//不退出进程
......
......@@ -82,6 +82,7 @@ func (this *ServiceSupplier)MergerCriteria() {
}else{
common.PrintStdout().Printf("[整合标准数据]标准供应商:"+groupName+" 组内没有对应联营供应商数据")
}
//panic("执行一组就退出")
}
}
......@@ -93,6 +94,7 @@ func (this *ServiceSupplier)MergerCriteria() {
*/
func (this *ServiceSupplier) updateSupplier(supplierEntity PoolSupplierEntity) {
dbSpu:= mysql.Conn("supp") //spu实例化链接
_,err:= dbSpu.Table("lie_supplier_channel").Where("supplier_id=?",supplierEntity.SupplierId).Update(supplierEntity)
if(err!=nil){
......
......@@ -22,7 +22,7 @@ type PoolSupplierEntity struct {
Currency int `json:"currency" `//币种
TaxNumber string `json:"tax_number" `//币种
SupplierAddress string `json:"supplier_address" `//币种
SupplierGroup int `json:"supplier_group" `//分组
UpdateTime int `json:"update_time" xorm:"updated"`
}
......@@ -93,9 +93,10 @@ func (this *ServiceCommonSupplier) getCsvRes(csvPath string) (newData map[string
0:"sn",
1:"oldName",
2:"newName",
3:"time",
4:"canal",
5:"purchaseName",
3:"canal",
4:"purchaseName",
5:"class",
6:"time",
}
for _, OneData := range res {
......@@ -125,7 +126,7 @@ func (this *ServiceCommonSupplier) getCsvData(csvPath string) (res [][]string,er
r:=csv.NewReader(decoder.NewReader(file))//以jbk读取文件
res,err=r.ReadAll()
if(err!=nil){
return res,fmt.Errorf("csv ReadAll出错:path:"+csvPath+err.Error())
return res,fmt.Errorf("csv ReadAll出错:path:"+csvPath+",err:"+err.Error())
}
//res=append(res[0:],res[1:]...)
......
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