Commit d61559f9 by mushishixian

初始化项目

parents
Homestead.yaml
Homestead.json
bom_server
/cmd/source/source
# ide
.idea
*.properties
*.iml
*.exe
/logs
/components
/storage/app
/storage/framework
/storage/logs
/.idea
/storage/debugbar
.DS_Store?
.DS_Store
cmd/cmd.exe
cmd/move/logs/
/cmd/dong/logs/*.log
/sh
## caipu-server
### v1.0.0
1. 上线功能xxx
# Owner
# Author
# Reviewer
# bom-server
## 项目简介
1.GO服务DEMO
2.运行命令
go run cmd/main.go -conf xxxx
package main
func main() {
}
package queue
\ No newline at end of file
[mysql]
username = root
password = root
host = 192.168.2.250
database = lie_scm_wms_sync
[rabbitmq]
url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
[api]
base = http://192.168.2.232:40001
[falcon]
push_url = http://192.168.1.237:1988/v1/push
[mysql]
username = YncsczUxxz
password = ztxaxpzto@y$%lstt
host = 172.18.137.34
database = liexin_scm_wms_sync
[rabbitmq]
url = "amqp://scmWms:Ptlxuut0lkx@172.18.137.33:5672/"
[api]
base = http://172.18.137.38:40001
out_store = http://172.18.137.38:40003
in_store = http://172.18.137.38:40004
erp_sync_base_data_status = http://172.18.137.20:6878/ormrpc/services/WSInventoryManagementFacade?wsdl
erp_sync_bill_status = http://172.18.137.20:6878/ormrpc/services/WSInventoryManagementFacade?wsdl
erp_login_status = http://172.18.137.20:6878/ormrpc/services/EASLogin?wsdl
[falcon]
push_url = http://172.18.137.35:1988/v1/push
[erp]
userName = WBYH
password = 123456
slnName = eas
dcName = SCM
language = L2
dbType = 1
authPattern = BaseDB
package common
import (
"crypto/md5"
"encoding/hex"
)
// Md5 md5()
func Md5(str string) string {
hash := md5.New()
hash.Write([]byte(str))
return hex.EncodeToString(hash.Sum(nil))
}
package common
const ErrorSendPhone = 18825159814
package common
type Response struct {
Errcode int
Errmsg string
Data interface{}
}
package dao
import (
"context"
"time"
"bom_server/internal/model"
"github.com/go-kratos/kratos/pkg/cache/memcache"
"github.com/go-kratos/kratos/pkg/cache/redis"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/go-kratos/kratos/pkg/database/sql"
"github.com/go-kratos/kratos/pkg/log"
xtime "github.com/go-kratos/kratos/pkg/time"
)
// Dao dao interface
type Dao interface {
Close()
Ping(ctx context.Context) (err error)
GetUserInfoByUserId(ctx context.Context,user_id int64) (r *model.Users,err error)
}
// dao dao.
type dao struct {
db *sql.DB
redis *redis.Pool
redisExpire int32
mc *memcache.Memcache
mcExpire int32
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
// New new a dao and return.
func New() (Dao) {
var (
dc struct {
Crm *sql.Config
}
rc struct {
Demo *redis.Config
DemoExpire xtime.Duration
}
mc struct {
Demo *memcache.Config
DemoExpire xtime.Duration
}
)
checkErr(paladin.Get("mysql.toml").UnmarshalTOML(&dc))
checkErr(paladin.Get("redis.toml").UnmarshalTOML(&rc))
checkErr(paladin.Get("memcache.toml").UnmarshalTOML(&mc))
return &dao{
// mysql
db: sql.NewMySQL(dc.Crm),
// redis
redis: redis.NewPool(rc.Demo),
redisExpire: int32(time.Duration(rc.DemoExpire) / time.Second),
// memcache
mc: memcache.New(mc.Demo),
mcExpire: int32(time.Duration(mc.DemoExpire) / time.Second),
}
}
// Close close the resource.
func (d *dao) Close() {
d.mc.Close()
d.redis.Close()
d.db.Close()
}
// Ping ping the resource.
func (d *dao) Ping(ctx context.Context) (err error) {
if err = d.pingMC(ctx); err != nil {
return
}
if err = d.pingRedis(ctx); err != nil {
return
}
return d.db.Ping(ctx)
}
func (d *dao) pingMC(ctx context.Context) (err error) {
if err = d.mc.Set(ctx, &memcache.Item{Key: "ping", Value: []byte("pong"), Expiration: 0}); err != nil {
log.Error("conn.Set(PING) error(%v)", err)
}
return
}
func (d *dao) pingRedis(ctx context.Context) (err error) {
conn := d.redis.Get(ctx)
defer conn.Close()
if _, err = conn.Do("SET", "ping", "pong"); err != nil {
log.Error("conn.Set(PING) error(%v)", err)
}
return
}
package dao
import (
"fmt"
"github.com/jmoiron/sqlx"
"log"
"bom_server/configs"
"sync"
)
var instance * sqlx.DB
var instanceCms * sqlx.DB
var instanceLiexin * sqlx.DB
var once sync.Once
var onceCms sync.Once
var onceLiexin sync.Once
func GetDb()(*sqlx.DB) {
once.Do(func() {
dbConfig := configs.GetDBOne()
db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil {
log.Fatalln(err)
}
instance = db
})
return instance
}
func GetCmsDb()(*sqlx.DB) {
onceCms.Do(func() {
dbConfig := configs.GetDBCms()
db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil {
log.Fatalln(err)
}
instanceCms = db
})
return instanceCms
}
func GetLiexinDb()(*sqlx.DB) {
onceLiexin.Do(func() {
dbConfig := configs.GetDBLiexin()
db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil {
log.Fatalln(err)
}
instanceLiexin = db
})
return instanceLiexin
}
\ No newline at end of file
package dao
import (
"context"
"bom_server/internal/model"
"github.com/go-kratos/kratos/pkg/database/sql"
"github.com/pkg/errors"
)
const (
_user_Info_One = "SELECT user_id FROM lie_user WHERE user_id=?"
)
//通过UID获取用户信息
func (d *dao) GetUserInfoByUserId(ctx context.Context, user_id int64) (r *model.Users, err error) {
var row *sql.Row
r = new(model.Users)
row = d.db.QueryRow(ctx, _user_Info_One, user_id)
if err = row.Scan(&r.User_id); err != nil {
if err == sql.ErrNoRows {
err = nil
r = nil
return
}
err = errors.WithStack(err)
return
}
return
}
package logic
import (
"bom_server/internal/dao"
"bom_server/internal/model"
"time"
)
const CheckCustomerExistSql = "SELECT customer_id FROM lie_customer WHERE binary erp_id = ?"
const CheckCustomerSyncStatusSql = "SELECT sync_status FROM lie_customer WHERE binary erp_id = ?"
const InsertCustomerSql = "Insert INTO `lie_customer` (`erp_client_code`,`name`,`erp_id`,`add_time`,`sync_status`) VALUES (?,?,?,?,?)"
const UpdateCustomerSql = "UPDATE `lie_customer` SET `erp_client_code` = ? , `name` = ? , `update_time` = ? WHERE binary `erp_id` = ?"
const DeleteCustomerSql = "UPDATE `lie_customer` SET `status` = ? , `update_time` = ? WHERE binary `erp_id` = ?"
const SyncCustomerSuccessSql = "UPDATE `lie_customer` SET sync_status = 1 , sync_time = ? WHERE binary erp_id = ?"
const SyncCustomerErpSuccessSql = "UPDATE `lie_customer` SET sync_erp_status = 1 , sync_time = ? WHERE binary erp_id = ?"
//修改同步到erp成功的状态
func SyncCustomerErpSuccess(erpId string) (err error) {
_, err = dao.GetDb().Exec(SyncCustomerErpSuccessSql, time.Now().Unix(), erpId)
return
}
//检查用户是否存在
func CheckCustomerExist(erpId string) (exist bool) {
var customerId int
dao.GetDb().QueryRowx(CheckCustomerExistSql, erpId).Scan(&customerId)
return customerId > 0
}
//获取后端同步状态
func CheckCustomerSyncStatus(erpId string) (status bool) {
var statusInt int
dao.GetDb().QueryRowx(CheckCustomerSyncStatusSql, erpId).Scan(&statusInt)
return statusInt > 0
}
//插入用户
func InsertCustomer(customer model.Customer) (err error) {
if !CheckCustomerExist(customer.ErpId) {
_, err = dao.GetDb().Exec(InsertCustomerSql, customer.ErpClientCode, customer.Name, customer.ErpId, time.Now().Unix(), 0)
}
return
}
//更新供应商
func UpdateCustomer(customer model.Customer) (err error) {
_, err = dao.GetDb().Exec(UpdateCustomerSql, customer.ErpClientCode, customer.Name, time.Now().Unix(), customer.ErpId)
if err != nil {
return
}
return nil
}
//删除供应商
func DeleteCustomer(customer model.Customer) (err error) {
_, err = dao.GetDb().Exec(DeleteCustomerSql, customer.Status, time.Now().Unix(), customer.ErpId)
return
}
//修改成功的同步状态
func SyncCustomerSuccess(erpId string) (err error) {
_, err = dao.GetDb().Exec(SyncCustomerSuccessSql, time.Now().Unix(), erpId)
return
}
package model
type Customer struct {
ErpClientCode string
Name string
ErpId string
AddTime int
SyncTime int
SyncStatus int
SyncErpStatus int
Status int
SyncError string
}
package model
// Kratos hello kratos.
type Users struct {
User_id int64 `json:"user_id"`
}
package service
import (
"encoding/json"
"fmt"
"github.com/imroc/req"
"net/http"
"net/url"
"bom_server/internal/common"
"strconv"
"time"
)
const APIMD5STR string = "fh6y5t4rr351d2c3bryi"
const APIDOMAIN string = "http://api.ichunt.com/msg/sendMessageByAuto"
const ADMINTEL int64 = 18825159814
func AdminErr(err error) {
if err != nil {
fmt.Println(err)
SendMessage(ADMINTEL, err.Error())
}
}
func SendMessage(mobile int64, content string) {
if mobile != 0 {
timeNow := time.Now().Unix()
requestContent, _ := json.Marshal(map[string]string{"content": content})
requestTel, _ := json.Marshal([]int64{mobile})
resp, err := http.PostForm(APIDOMAIN, url.Values{
"data": {string(requestContent)},
"touser": {string(requestTel)},
"keyword": {"register_nopay_notify"},
"k1": {strconv.FormatInt(int64(timeNow), 10)},
"k2": {common.Md5(common.Md5(strconv.FormatInt(int64(timeNow), 10)) + APIMD5STR)},
"is_ignore": {},
})
if err != nil {
fmt.Print(err)
}
defer resp.Body.Close()
}
}
type DingDingRequest struct {
MsgType string `json:"msgtype"`
Text map[string]string `json:"text"`
IsAtAll bool `json:"isAtAll"`
}
func SendDingTalkRobotToApi1(content string) {
fmt.Println(content)
}
func SendDingTalkRobotToApi(content string) {
var (
requestData DingDingRequest
apiUrl, token string
//resp *req.Resp
err error
)
content = "仓储同步告警 : " + content
requestData.MsgType = "text"
requestData.Text = map[string]string{
"content": content,
}
req.Debug = false
requestData.IsAtAll = false
token = "3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3"
apiUrl = "https://api.ichunt.com/public/dingtalkrobot?access_token=" + token
params := req.BodyJSON(requestData)
_, err = req.Post(apiUrl, params)
if err != nil {
fmt.Println(err)
}
}
package service
import (
"errors"
"github.com/beevik/etree"
"github.com/mushishixian/gosoap"
"bom_server/configs"
)
func LoginErp() (err error) {
soap, err := gosoap.SoapClient(configs.ErpLoginStatusApi)
if err != nil {
return
}
params := gosoap.ArrayParams{
{"userName", configs.ErpUserName},
{"password", configs.ErpPassword},
{"slnName", configs.ErpSlnName},
{"dcName", configs.ErpDcName},
{"language", configs.ErpLanguage},
{"dbType", configs.ErpDbType},
{"authPattern", configs.ErpAuthPattern},
}
res, err := soap.Call("login", params)
if err != nil {
return
}
doc := etree.NewDocument()
if err := doc.ReadFromBytes(res.Body); err != nil {
return err
}
root := doc.SelectElement("multiRef")
sessionId := root.SelectElement("sessionId").Text()
if sessionId != "" {
return
}
return errors.New(string(res.Body))
}
package service
import "fmt"
//错误日志
//错误类型
var ProGramErrType string = "default:"
//返回原声错误
func WriteErr(err error) {
if err != nil {
switch ProGramErrType {
default:
}
//屏幕打印,加上发送钉钉消息
fmt.Println(ProGramErrType+err.Error())
}
}
//返回详细错误
func WriteErrDetail(errString string) {
switch ProGramErrType {
default:
}
//屏幕打印,加上发送钉钉消息
fmt.Println(errString)
//SendMessage(ADMINTEL,ProGramErrType+errString)
}
\ No newline at end of file
package service
import (
"context"
"bom_server/internal/dao"
"bom_server/internal/model"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/pkg/errors"
)
// Service service.
type Service struct {
ac *paladin.Map
dao dao.Dao
}
// New new a service and return.
func New() (s *Service) {
var ac = new(paladin.TOML)
if err := paladin.Watch("application.toml", ac); err != nil {
panic(err)
}
s = &Service{
ac: ac,
dao: dao.New(),
}
return s
}
// Ping ping the resource.
func (s *Service) Ping(ctx context.Context) (err error) {
return s.dao.Ping(ctx)
}
// Close close the resource.
func (s *Service) Close() {
s.dao.Close()
}
//通过用户ID获取用户信息
func (s *Service) GetUserInfoByUserId(ctx context.Context, user_id int64) (res *model.Users, err error) {
if res, err = s.dao.GetUserInfoByUserId(ctx, user_id); err != nil {
err = errors.WithStack(err)
}
return
}
\ No newline at end of file
package main
func main() {
}
#!/bin/bash
cd /data2/gocode/bom_server
git pull origin master
rm ./sh/scm_wms_sync
rm ./sh/import_source
rm ./conf/config.ini
mv ./conf/config_production.ini ./conf/config.ini
go build -o ./sh/scm_wms_sync ./main.go
go build -o ./sh/import_source ./cmd/source/main.go
supervisorctl restart scm:bom_server
\ No newline at end of file
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