Commit a5c844a9 by 孙龙

up

parent a294cfe9
......@@ -10,6 +10,7 @@ erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=3966b80b7e56
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=087c11504fb541d004507f06285da88c2501fc1a4ecacd0216b9da964aa65518"
bomCreateBom="https://oapi.dingtalk.com/robot/send?access_token=0fc661fcbb51d312780c0245986363a38c788c50c2e652e7f250df4f393ae938"
fk_company="https://oapi.dingtalk.com/robot/send?access_token=231bee055924688720f72a0f6e413439d273d8613590cb3a5f174c3867722958"
orderProTrack_hook="https://oapi.dingtalk.com/robot/send?access_token=bd9c05935df3b68a0baa1b97b8680f2ecd71fb4242392fde610285fdd9b5fa1b"
[Api_domain]
......
......@@ -10,6 +10,7 @@ erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=ba4ed87924ee
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=09333ef25d736b34268fff237d58a4f27c7d33b01be37aa5c0c30acf5a7356e4"
bomCreateBom="https://oapi.dingtalk.com/robot/send?access_token=64d1d9d89d51aa66fe5cbbfe5cbdd7595202d43e255fab28adcbe60a9bd5f11d"
fk_company="https://oapi.dingtalk.com/robot/send?access_token=231bee055924688720f72a0f6e413439d273d8613590cb3a5f174c3867722958"
orderProTrack_hook="https://oapi.dingtalk.com/robot/send?access_token=bd9c05935df3b68a0baa1b97b8680f2ecd71fb4242392fde610285fdd9b5fa1b"
[Api_domain]
api_url="http://api.ichunt.com/"
......
package orderTrack
import (
"errors"
"fmt"
"go-queue-server/dal/db"
"go-queue-server/util"
)
var ORDER_TRACK_STATUS_CN map[int64]string
func init(){
ORDER_TRACK_STATUS_CN = make(map[int64]string,0)
ORDER_TRACK_STATUS_CN[10] = "等待销售审核"
ORDER_TRACK_STATUS_CN[20] = "等待采购"
ORDER_TRACK_STATUS_CN[21] = "等待采购确认 "
ORDER_TRACK_STATUS_CN[25] = "同步ERP失败"
ORDER_TRACK_STATUS_CN[30] = "同步ERP失败"
ORDER_TRACK_STATUS_CN[40] = "等待供应商发货"
ORDER_TRACK_STATUS_CN[41] = "已下单自营"
ORDER_TRACK_STATUS_CN[50] = "供应商发货成功"
ORDER_TRACK_STATUS_CN[51] = "金谷已发货"
ORDER_TRACK_STATUS_CN[60] = "交易完成"
ORDER_TRACK_STATUS_CN[70] = "香港收货成功"
ORDER_TRACK_STATUS_CN[80] = "香港发货成功"
ORDER_TRACK_STATUS_CN[90] = "深圳已到货"
ORDER_TRACK_STATUS_CN[100] = "等待仓库发货"
ORDER_TRACK_STATUS_CN[110] = "交易完成"
ORDER_TRACK_STATUS_CN[122] = "已退款"
ORDER_TRACK_STATUS_CN[125] = "已取消"
}
type OrderTrack struct {
RBMQTYPE string `json:"RBMQTYPE"`//消息类型 默认sczz 生产追踪
BIZDATE string `json:"BIZDATE"`//日期
MSG string `json:"MSG"`//消息内容
CREATOR string `json:"CREATOR"`//创建人
ORDERENTRYID string `json:"ORDERENTRYID"`//erp明细分录id
ERPORDERID string `json:"ERPORDERID"`//订单关联的erpid
ORDERID int64 `json:"ORDERID"`//订单id
STATUS int64 `json:"STATUS"`//状态
}
type OrderTrackList []*OrderTrack
type OrderItems struct {
OrderId int64 `json:"order_id" db:"order_id"`
RecId int64 `json:"rec_id" db:"rec_id"`
}
func InsertData(trackList OrderTrackList) error{
var (
err error
create_time int64
status_cn string
ok bool
)
for _,data := range trackList{
orderItems := &OrderItems{}
err = db.DB.Get(orderItems,"SELECT order_id,rec_id FROM lie_order_items WHERE erp_rec_id = ?",data.ORDERENTRYID)
if err != nil{
fmt.Println(err)
return errors.New(fmt.Sprintf("没有找到该明细的信息 %d",data.ORDERENTRYID))
}
create_time = util.ParseTimestrToTimestamp(data.BIZDATE,5)
if status_cn,ok = ORDER_TRACK_STATUS_CN[data.STATUS];!ok {
status_cn = ""
}
sql := " INSERT INTO lie_order_items_tracking (rec_id,order_id,status,msg,status_cn,create_name,create_time) VALUES(?,?,?,?,?,?,?)"
_,err :=db.DB.Exec(sql, orderItems.RecId,orderItems.OrderId,data.STATUS,data.MSG,status_cn,data.CREATOR,create_time)
if err != nil{
return err
}
}
return nil
}
\ No newline at end of file
package handle
import (
"github.com/tidwall/gjson"
"go-queue-server/dal/order/orderTrack"
)
func InsertOrderItemsTracking(msg string) (err error){
var (
orderTrackHandle *orderTrack.OrderTrack
orderTrackList orderTrack.OrderTrackList
)
//fmt.Println(msg)
//设置recover,recover只能放在defer后面使用
defer func() {
if err := recover(); err != nil { //产生了panic异常
return
}
}() //别忘了(), 调用此匿名函数
msgList := gjson.Parse(msg).Array()
orderTrackList = make([]*orderTrack.OrderTrack,0)
for i:=0;i<len(msgList);i++{
orderTrackHandle = &orderTrack.OrderTrack{}
orderTrackHandle.RBMQTYPE = msgList[i].Get("RBMQTYPE").String()
orderTrackHandle.BIZDATE = msgList[i].Get("BIZDATE").String()
orderTrackHandle.MSG = msgList[i].Get("MSG").String()
orderTrackHandle.CREATOR = msgList[i].Get("CREATOR").String()
orderTrackHandle.ORDERENTRYID = msgList[i].Get("ORDERENTRYID").String()
orderTrackHandle.ERPORDERID = msgList[i].Get("ERPORDERID").String()
orderTrackHandle.ORDERID = msgList[i].Get("ORDERID").Int()
orderTrackHandle.STATUS = msgList[i].Get("STATUS").Int()
orderTrackList = append(orderTrackList,orderTrackHandle)
}
err = orderTrack.InsertData(orderTrackList)
return nil
}
package main
import (
"flag"
"fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/order/order_track/handle"
"go-queue-server/util"
"go-queue-server/util/ding"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
logger.Info(string(dataByte))
//fmt.Println(string(dataByte))
err := handle.InsertOrderItemsTracking(string(dataByte))
return err
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(err error,dataByte []byte) error {
logger.Error("任务处理失败了,我要进入db日志库了")
logger.Error("任务处理失败了,发送钉钉消息通知主人")
logger.Error(string(dataByte))
logger.Error("错误原因:%s",err)
ding.Send(
util.Configs.Ding_msg.OrderProTrackWebhook,
"@所有人 订单明细生产追踪告警:\n",
fmt.Sprintf("失败原因:%s \n %s",err,string(dataByte)) ,
make([]string,0),
false,
)
return nil
}
var ConfigDir string
var LogDir string
// 解析命令行参数
func initArgs() {
// worker -config ./worker.json
// worker -h
flag.StringVar(&ConfigDir, "configDir", "./config/", "配置文件")
flag.StringVar(&LogDir, "logDir", "./log/", "日志目录")
flag.Parse()
}
func initDb(action string,dns string) (err error) {
err = db.CreateDB(action,dns)
if err != nil {
fmt.Println(err)
panic(err)
return
}
return
}
func main(){
initArgs()
//初始化配置文件
util.Init(ConfigDir)
//
logConfig := make(map[string]string)
logConfig["log_path"] = LogDir+"order_track/"
logConfig["log_chan_size"] = "1000"
logger.InitLogger("file",logConfig)
logger.Init()
//初始化db
initDb("Init",util.Configs.Liexin_databases.Dns)
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
"ichunt_order_product_track",
"",
"",
util.Configs.Rabbitmq_yaohaoyou.Type,
util.Configs.Rabbitmq_yaohaoyou.Dns,
},t,1)
}
\ No newline at end of file
package util
import "time"
func ParseTimestrToTimestamp(time_str string, flag int) int64 {
var t int64
loc, _ := time.LoadLocation("Local")
if flag == 1 {
t1, _ := time.ParseInLocation("2006.01.02 15:04:05", time_str, loc)
t = t1.Unix()
} else if flag == 2 {
t1, _ := time.ParseInLocation("2006-01-02 15:04", time_str, loc)
t = t1.Unix()
} else if flag == 3 {
t1, _ := time.ParseInLocation("2006-01-02", time_str, loc)
t = t1.Unix()
} else if flag == 4 {
t1, _ := time.ParseInLocation("2006.01.02", time_str, loc)
t = t1.Unix()
} else {
t1, _ := time.ParseInLocation("2006-01-02 15:04:05", time_str, loc)
t = t1.Unix()
}
return t
}
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