| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941 |
- package main
- import (
- "bytes"
- "context"
- "database/sql"
- "fmt"
- "io/ioutil"
- "strings"
- "time"
- basedao "dashoo.cn/micro/app/dao/base"
- contractdao "dashoo.cn/micro/app/dao/contract"
- projao "dashoo.cn/micro/app/dao/proj"
- basemodel "dashoo.cn/micro/app/model/base"
- model "dashoo.cn/micro/app/model/contract"
- "github.com/gogf/gf/database/gdb"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gconv"
- "github.com/gogf/gf/os/gtime"
- "github.com/xuri/excelize/v2"
- )
- func main() {
- // contract()
- // product()
- // collectionplan()
- // collection()
- // dist()
- // prepareuser()
- // prepare()
- // fmt.Println(Usermap)
- // fmt.Println(MapProvince)
- // distContact()
- projectRelate()
- }
- func projectRelate() {
- projao := projao.NewProjBusinessDao("prod")
- contractdao := contractdao.NewCtrContractDao("prod")
- fileb, err := ioutil.ReadFile("/home/lai/项目关联.xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- coderow, err := e.GetRows("Sheet1")
- if err != nil {
- panic(err)
- }
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for rown, row := range coderow[1:] {
- projcode := strings.TrimSpace(row[0])
- contrcode := strings.TrimSpace(row[1])
- fmt.Println(rown, projcode, contrcode)
- nbo, err := projao.Where("nbo_code = ?", projcode).One()
- if err != nil {
- return err
- }
- if nbo == nil {
- return fmt.Errorf("项目不存在")
- }
- contract, err := contractdao.Where("contract_code = ?", contrcode).One()
- if err != nil {
- return err
- }
- if contract == nil {
- return fmt.Errorf("合同不存在")
- }
- _, err = tx.Update("ctr_contract", map[string]interface{}{
- "cust_id": nbo.CustId,
- "cust_name": nbo.CustName,
- "nbo_id": nbo.Id,
- "nbo_name": nbo.NboName,
- "is_big": nbo.IsBig,
- "product_line": nbo.ProductLine,
- "cust_province_id": nbo.CustProvinceId,
- "cust_province": nbo.CustProvince,
- "cust_city_id": nbo.CustCityId,
- "cust_city": nbo.CustCity,
- }, "contract_code = ?", contrcode)
- if err != nil {
- return err
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- if txerr != nil {
- panic(txerr)
- }
- }
- func distContact() {
- dao := basedao.NewBaseDistributorDao("prod")
- distMap := map[string]*basemodel.BaseDistributor{}
- ent, err := dao.All()
- if err != nil {
- panic(err)
- }
- for _, i := range ent {
- distMap[i.DistName] = i
- }
- fmt.Println(distMap)
- fileb, err := ioutil.ReadFile("/home/lai/渠道信息联系方式.xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- contact, err := e.GetRows("Sheet1")
- if err != nil {
- panic(err)
- }
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for rown, row := range contact[1:] {
- distname := strings.TrimSpace(row[2])
- name := strings.TrimSpace(row[3])
- position := strings.TrimSpace(row[5])
- phone := strings.TrimSpace(row[6])
- email := strings.TrimSpace(row[7])
- wechat := strings.TrimSpace(row[8])
- business := strings.TrimSpace(row[9])
- fmt.Println(rown, distname, name, position, phone, email, wechat, business, distMap[distname].Id)
- p := basemodel.BaseDistributorContact{
- DistId: distMap[distname].Id,
- Name: name,
- Post: position,
- Phone: phone,
- Wechat: wechat,
- Mail: email,
- Honorific: "未知",
- Territory: business,
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- }
- _, err = tx.Insert("base_distributor_contact", p)
- if err != nil {
- return err
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- if txerr != nil {
- panic(txerr)
- }
- }
- type User struct {
- Id int
- NickName string
- UserName string
- }
- var Usermap = map[string]User{}
- func prepareuser() {
- users := []User{}
- err := g.DB("prod").Table("sys_user").Structs(&users)
- if err != nil {
- panic(err)
- }
- for _, u := range users {
- Usermap[u.NickName] = u
- }
- }
- func dist() {
- prepare()
- prepareuser()
- var custtypMap = map[string]string{
- "医院": "10",
- "科研单位": "20",
- "高校": "30",
- "疾控": "40",
- "细胞公司": "50",
- "生物药企": "60",
- "其他": "90",
- }
- fileb, err := ioutil.ReadFile("/home/lai/渠道信息台账0523(1)(1).xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- proxy, err := e.GetRows("代理商列表详情")
- if err != nil {
- panic(err)
- }
- dist, err := e.GetRows("经销商列表详情")
- if err != nil {
- panic(err)
- }
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for rowtype, distlist := range [][][]string{dist, proxy} {
- distType := "10"
- if rowtype == 1 {
- distType = "20"
- }
- for rown, row := range distlist[2:] {
- createdStr := strings.TrimSpace(row[1])
- seller := strings.TrimSpace(row[2])
- name := strings.TrimSpace(row[3])
- province := strings.TrimSpace(row[4])
- var sellerNumStr string
- var product string
- var hisCust string
- var custTypStr string
- var proxydistrict string
- var startStr string
- var endStr string
- var business string
- var capitalStr string
- var register string
- if len(row) > 5 {
- business = strings.TrimSpace(row[5])
- capitalStr = strings.TrimSpace(row[6])
- register = strings.TrimSpace(row[7])
- if len(row) > 8 {
- sellerNumStr = strings.TrimSpace(row[8])
- if len(row) > 9 {
- product = strings.TrimSpace(row[9])
- if len(row) > 10 {
- hisCust = strings.TrimSpace(row[10])
- if len(row) > 11 {
- if distType == "10" {
- custTypStr = strings.TrimSpace(row[11])
- } else {
- // fmt.Println(row)
- proxydistrict = strings.TrimSpace(row[12])
- startStr = strings.TrimSpace(row[13])
- endStr = strings.TrimSpace(row[14])
- custTypStr = strings.TrimSpace(row[15])
- }
- }
- }
- }
- }
- }
- created, err := time.Parse("2006/01/02 15:04:05", createdStr)
- if err != nil {
- panic(fmt.Errorf("%s, %s", createdStr, err.Error()))
- }
- start, err := time.Parse("2006/01/02", startStr)
- if err != nil {
- if distType == "10" {
- start = time.Time{}
- } else {
- panic(fmt.Errorf("%s, %s", startStr, err.Error()))
- }
- }
- end, err := time.Parse("2006/01/02", endStr)
- if err != nil {
- if distType == "10" {
- start = time.Time{}
- } else {
- panic(fmt.Errorf("%s, %s", endStr, err.Error()))
- }
- }
- sellerNum := gconv.Int(sellerNumStr)
- capital := gconv.Float64(capitalStr)
- var custypes string
- if custTypStr == "" {
- custypes = ""
- } else {
- custTypeslice := strings.Split(custTypStr, ",")
- custypeslice := []string{}
- for _, t := range custTypeslice {
- if t == "企业" {
- continue
- }
- if t == "医疗" {
- continue
- }
- if t == "科研" {
- continue
- }
- if t == "细胞企业" {
- continue
- }
- if t == "生物药企、医院" {
- custypeslice = append(custypeslice, custtypMap["生物药企"])
- custypeslice = append(custypeslice, custtypMap["医院"])
- continue
- }
- if custtypMap[t] == "" {
- panic(t + ":custypeslice")
- }
- custypeslice = append(custypeslice, custtypMap[t])
- }
- custypes = strings.Join(custypeslice, ",")
- if Usermap[seller].Id == 0 {
- panic(seller + ":seller")
- }
- }
- fmt.Println(rown, distType, created, seller, name, province, MapProvince[province], business, capital, register, sellerNum, product, hisCust, custypes, proxydistrict, start, end)
- p := basemodel.BaseDistributor{
- DistCode: "",
- DistName: name,
- AbbrName: "",
- DistDesc: "",
- DistBoss: "",
- DistBossPhone: "",
- ProvinceId: MapProvince[province],
- ProvinceDesc: province,
- BusinessScope: business,
- BelongSaleId: Usermap[seller].Id,
- BelongSale: seller,
- Capital: capital,
- SaleNum: sellerNum,
- InvoiceHeader: "",
- DistType: distType,
- CustomerType: custypes,
- ExistedProduct: product,
- AssistantSaleId: "",
- AssistantSale: "",
- RegisterDistrict: register,
- HistoryCustomer: hisCust,
- ProxyStartTime: gtime.NewFromTime(start),
- ProxyEndTime: gtime.NewFromTime(end),
- ProxyDistrict: proxydistrict,
- ContractUrl: "",
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- }
- _, err = tx.Insert("base_distributor", p)
- if err != nil {
- return err
- }
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- if txerr != nil {
- panic(txerr)
- }
- }
- func collection() {
- var typMap = map[string]string{
- "电汇": "10",
- "承兑": "20",
- "现金": "30",
- }
- var contractMap = map[string]*model.CtrContract{}
- fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- rows2021_2023, err := e.GetRows("2021-2023年回款管理")
- if err != nil {
- panic(err)
- }
- rows2017_2020, err := e.GetRows("2017-2020年回款管理")
- if err != nil {
- panic(err)
- }
- rows := append(rows2021_2023[1:], rows2017_2020[1:]...)
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for rown, row := range rows {
- custname := strings.TrimSpace(row[0])
- contractcode := strings.TrimSpace(row[1])
- amountStr := strings.TrimSpace(row[2])
- typ := strings.TrimSpace(row[3])
- var ctimeStr string
- if len(row) > 5 {
- ctimeStr = strings.TrimSpace(row[5])
- }
- if ctimeStr == "" {
- ctimeStr = "0001/1/2"
- }
- ctime, err := time.Parse("2006/1/2", ctimeStr)
- if err != nil {
- ctime, err = time.Parse("01-02-06", ctimeStr)
- }
- if err != nil {
- ctime, err = time.Parse("2006.1.2", ctimeStr)
- }
- if err != nil {
- if ctimeStr == "" {
- ctime = time.Time{}
- } else {
- panic(fmt.Errorf("%s, %s", ctimeStr, err.Error()))
- }
- }
- amount := gconv.Float64(amountStr)
- fmt.Println(rown, custname, contractcode, amount, typ, ctime)
- if _, ok := contractMap[contractcode]; !ok {
- c := &model.CtrContract{}
- err := tx.GetStruct(c, "select * from ctr_contract where contract_code = ?", contractcode)
- if err != nil {
- fmt.Println(c.ContractCode)
- return err
- }
- contractMap[contractcode] = c
- }
- p := model.CtrContractCollection{
- PlanId: 0,
- CustId: 0,
- CustName: custname,
- ContractId: contractMap[contractcode].Id,
- ContractCode: contractMap[contractcode].ContractCode,
- CollectionDatetime: gtime.NewFromTime(ctime),
- CollectionAmount: amount,
- CollectionType: typMap[typ],
- ApproStatus: "20",
- ContractAmount: contractMap[contractcode].ContractAmount,
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- }
- _, err = tx.Insert("ctr_contract_collection", p)
- if err != nil {
- return err
- }
- }
- return nil
- // return fmt.Errorf("测试")
- })
- fmt.Println(contractMap)
- if txerr != nil {
- panic(txerr)
- }
- }
- func collectionplan() {
- var statusMap = map[string]string{
- "已回款": "30",
- "未回款": "10",
- }
- var contractMap = map[string]*model.CtrContract{}
- fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- rows2021_2023, err := e.GetRows("2021-2023年回款计划")
- if err != nil {
- panic(err)
- }
- rows := rows2021_2023[1:]
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for rown, row := range rows {
- custname := strings.TrimSpace(row[0])
- contractcode := strings.TrimSpace(row[1])
- amountStr := strings.TrimSpace(row[2])
- status := strings.TrimSpace(row[3])
- planTimeStr := strings.TrimSpace(row[4])
- scaleStr := strings.TrimSpace(row[5])
- var criteria string
- if len(row) > 6 {
- criteria = strings.TrimSpace(row[6])
- }
- if planTimeStr == "" {
- planTimeStr = "0001/1/2"
- }
- planTime, err := time.Parse("2006/1/2", planTimeStr)
- if err != nil {
- planTime, err = time.Parse("01-02-06", planTimeStr)
- }
- if err != nil {
- if planTimeStr == "" {
- planTime = time.Time{}
- } else {
- panic(fmt.Errorf("%s, %s", planTimeStr, err.Error()))
- }
- }
- amount := gconv.Float64(amountStr)
- scale := gconv.Float64(strings.Replace(scaleStr, "%", "", -1))
- var CashedAmount float64
- if status == "已回款" {
- CashedAmount = amount
- }
- fmt.Println(rown, custname, contractcode, amount, status, scale, criteria)
- if _, ok := contractMap[contractcode]; !ok {
- c := &model.CtrContract{}
- err := tx.GetStruct(c, "select * from ctr_contract where contract_code = ?", contractcode)
- if err != nil {
- fmt.Println(c.ContractCode)
- return err
- }
- contractMap[contractcode] = c
- }
- p := model.CtrContractCollectionPlan{
- CustId: 0,
- CustName: custname,
- ContractId: contractMap[contractcode].Id,
- ContractCode: contractMap[contractcode].ContractCode,
- ContractStatus: statusMap[status],
- PlanAmount: amount,
- PlanDatetime: gtime.NewFromTime(planTime),
- PlanScale: scale,
- PlanCondition: criteria,
- CashedAmount: CashedAmount,
- CashedDatetime: nil,
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- }
- _, err = tx.Insert("ctr_contract_collection_plan", p)
- if err != nil {
- return err
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- fmt.Println(contractMap)
- if txerr != nil {
- panic(txerr)
- }
- }
- func product() {
- var ProdClassMap = map[string]string{
- "BIOBANK": "10",
- "Biobank": "10",
- "CELLSOP": "20",
- "CellSOP": "20",
- "CellsSOP": "20",
- "LIMS": "30",
- "LIMS+基因": "30",
- "MCS": "60",
- "咨询服务": "70",
- "外购": "90",
- "智能硬件": "40",
- "液氮罐": "50",
- "设备": "",
- }
- var productMap = map[string]*basemodel.BaseProduct{}
- var contractMap = map[string]*model.CtrContract{}
- fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- rows2021_2023, err := e.GetRows("2021-2023年产品信息")
- if err != nil {
- panic(err)
- }
- rows2017_2020, err := e.GetRows("2017-2020年产品信息")
- if err != nil {
- panic(err)
- }
- rows := append(rows2021_2023[1:], rows2017_2020[1:]...)
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for rown, row := range rows {
- contractcode := strings.TrimSpace(row[0])
- ProdClass := strings.TrimSpace(row[1])
- ProdName := strings.TrimSpace(row[2])
- ProdCode := strings.TrimSpace(row[3])
- priceStr := strings.TrimSpace(row[4])
- numStr := strings.TrimSpace(row[5])
- sumStr := strings.TrimSpace(row[6])
- var zhibaoStr string
- var maintainStr string
- var maintainTerm string
- var acceptTimeStr string
- if len(row) > 7 {
- zhibaoStr = strings.TrimSpace(row[7])
- if len(row) > 8 {
- maintainStr = strings.TrimSpace(row[8])
- if len(row) > 9 {
- maintainTerm = strings.TrimSpace(row[9])
- if len(row) > 10 {
- acceptTimeStr = strings.TrimSpace(row[10])
- }
- }
- }
- }
- acceptTime, err := time.Parse("2006/1/2", acceptTimeStr)
- if err != nil {
- acceptTime, err = time.Parse("01-02-06", acceptTimeStr)
- }
- if err != nil {
- acceptTime, err = time.Parse("2006年1月2日", acceptTimeStr)
- }
- if err != nil {
- if acceptTimeStr == "" {
- acceptTime = time.Time{}
- } else {
- panic(fmt.Errorf("%s, %s", acceptTimeStr, err.Error()))
- }
- }
- price := gconv.Float64(priceStr)
- num := gconv.Int(numStr)
- sum := gconv.Float64(sumStr)
- zhibao := gconv.Int(zhibaoStr)
- maintain := gconv.Int(maintainStr)
- fmt.Println(rown, contractcode, ProdClass, ProdName, ProdCode, price,
- num, sum, zhibao, maintain, maintainTerm, acceptTime)
- p := basemodel.BaseProduct{
- ProdCode: ProdCode,
- ProdName: ProdName,
- ProdClass: ProdClassMap[ProdClass],
- GuidPrice: 0,
- DistPrice: 0,
- AgentPrice: 0,
- MarketPrice: 0,
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- DeletedTime: gtime.Now(),
- }
- if _, ok := productMap[p.ProdName]; !ok {
- dbexistp := &basemodel.BaseProduct{}
- err := tx.GetStruct(dbexistp, "select * from base_product where prod_name = ?", p.ProdName)
- if err == sql.ErrNoRows {
- id, err := tx.InsertAndGetId("base_product", p)
- if err != nil {
- return err
- }
- p.Id = int(id)
- productMap[p.ProdName] = &p
- } else {
- if err != nil {
- return err
- }
- productMap[p.ProdName] = dbexistp
- }
- }
- if _, ok := contractMap[contractcode]; !ok {
- c := &model.CtrContract{}
- err := tx.GetStruct(c, "select * from ctr_contract where contract_code = ?", contractcode)
- if err != nil {
- fmt.Println(c.ContractCode)
- return err
- }
- contractMap[contractcode] = c
- }
- cp := model.CtrContractProduct{
- ContractId: contractMap[contractcode].Id,
- ContractCode: contractMap[contractcode].ContractCode,
- ProdId: productMap[p.ProdName].Id,
- ProdCode: productMap[p.ProdName].ProdCode,
- ProdName: productMap[p.ProdName].ProdName,
- ProdClass: productMap[p.ProdName].ProdClass,
- ProdNum: num,
- MaintTerm: 0,
- SugSalesPrice: 0,
- TranPrice: price,
- ContractPrive: contractMap[contractcode].ContractAmount,
- PurchaseCost: 0,
- DevCost: 0,
- MaintainCost: 0,
- DirectCost: 0,
- MaintainPeriod: zhibao * 365,
- WarrantPeriod: maintain * 365,
- MaintainStartTime: nil,
- MaintainRemark: maintainTerm,
- AcceptTime: gtime.NewFromTime(acceptTime),
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- }
- _, err = tx.Insert("ctr_contract_product", cp)
- if err != nil {
- return err
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- fmt.Println(contractMap)
- fmt.Println(productMap)
- fmt.Println(ProdClassMap)
- if txerr != nil {
- panic(txerr)
- }
- }
- func contract() {
- prepare()
- contract := parse()
- fmt.Println(MapProductLine)
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- _, err := tx.Insert("ctr_contract", contract)
- return err
- })
- if txerr != nil {
- panic(txerr)
- }
- }
- var MapProvince = map[string]int{}
- var MapCity = map[string]int{}
- var MapProductLine = map[string]string{
- "BIOBANK": "10",
- "CELLSOP": "20",
- "LIMS+基因": "30",
- "MCS": "60",
- "咨询服务": "70",
- "外购": "90",
- "智能硬件": "40",
- "石油": "80",
- }
- var Mapcontracttype = map[string]string{
- "销售合同": "XS",
- "技术合同": "JS",
- }
- var MapSignatoryType = map[string]string{
- "终端用户": "10",
- "经销商": "20",
- "代理商": "30",
- }
- func prepare() {
- dao := basedao.NewBaseDistrictDao("prod")
- province, err := dao.Where("dist_level = 1").All()
- if err != nil {
- panic(err)
- }
- for _, p := range province {
- MapProvince[p.DistName] = p.Id
- }
- city, err := dao.Where("dist_level = 2").All()
- if err != nil {
- panic(err)
- }
- for _, c := range city {
- MapCity[c.DistName] = c.Id
- }
- }
- func parse() []model.CtrContract {
- fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
- if err != nil {
- panic(err)
- }
- e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
- if err != nil {
- panic(err)
- }
- rows2021_2023, err := e.GetRows("2021-2023年合同基本信息")
- if err != nil {
- panic(err)
- }
- rows2017_2020, err := e.GetRows("2017-2020年合同基本信息")
- if err != nil {
- panic(err)
- }
- rows := append(rows2021_2023[1:], rows2017_2020[1:]...)
- contract := []model.CtrContract{}
- for rown, row := range rows {
- code := strings.TrimSpace(row[0])
- name := strings.TrimSpace(row[1])
- custname := strings.TrimSpace(row[2])
- nobname := strings.TrimSpace(row[3])
- province := strings.TrimSpace(row[4])
- city := strings.TrimSpace(row[5])
- amountstr := strings.TrimSpace(row[6])
- InchargeName := strings.TrimSpace(row[7])
- ContractType := strings.TrimSpace(row[8])
- ContractSignTimestr := strings.TrimSpace(row[9])
- ContractEndTimestr := strings.TrimSpace(row[10])
- SignatoryName := strings.TrimSpace(row[11])
- ProductLine := strings.TrimSpace(row[12])
- SignatoryUnit := strings.TrimSpace(row[13])
- SignatoryType := strings.TrimSpace(row[14])
- if ContractEndTimestr == "" {
- ContractEndTimestr = "0001/1/2"
- }
- if ContractSignTimestr == "" {
- ContractSignTimestr = "0001/1/2"
- }
- amount := gconv.Float64(amountstr)
- ContractSignTime, err := time.Parse("2006/1/2", ContractSignTimestr)
- if err != nil {
- ContractSignTime, err = time.Parse("01-02-06", ContractSignTimestr)
- }
- if err != nil {
- panic(fmt.Errorf("%s, %s", ContractSignTimestr, err.Error()))
- }
- ContractEndTime, err := time.Parse("2006/1/2", ContractEndTimestr)
- if err != nil {
- ContractEndTime, err = time.Parse("01-02-06", ContractEndTimestr)
- }
- if err != nil {
- panic(fmt.Errorf("%s, %s", ContractEndTimestr, err.Error()))
- }
- provinceId := MapProvince[province]
- cityId := MapCity[city]
- var DistributorName string
- if SignatoryType == "经销商" || SignatoryType == "代理商" {
- DistributorName = SignatoryUnit
- }
- fmt.Println(rown, code, name, custname, nobname, province, city,
- amount, InchargeName, ContractType, ContractSignTime,
- ContractEndTime, SignatoryName, ProductLine, SignatoryType)
- contract = append(contract, model.CtrContract{
- ContractCode: code,
- ContractName: name,
- CustId: 0,
- CustName: custname,
- ProductLine: MapProductLine[ProductLine],
- IsBig: "20",
- CustProvinceId: provinceId,
- CustProvince: province,
- CustCityId: cityId,
- CustCity: city,
- NboId: 0,
- NboName: nobname,
- ApproStatus: "30",
- ContractType: Mapcontracttype[ContractType],
- ContractAmount: amount,
- InvoiceAmount: 0,
- CollectedAmount: 0,
- ContractStartTime: gtime.NewFromTime(ContractSignTime),
- ContractEndTime: gtime.NewFromTime(ContractEndTime),
- ContractSignTime: gtime.NewFromTime(ContractSignTime),
- InchargeId: 0,
- InchargeName: InchargeName,
- SignatoryId: 0,
- SignatoryName: SignatoryName,
- SignatoryType: MapSignatoryType[SignatoryType],
- SignatoryUnit: SignatoryUnit,
- EarnestMoney: 0,
- CustSignatoryId: 0,
- CustSignatoryName: "",
- DistributorId: 0,
- DistributorName: DistributorName,
- ServiceFeeAgreement: "",
- Remark: "",
- CreatedBy: 1000,
- CreatedName: "dashoo",
- CreatedTime: gtime.Now(),
- UpdatedBy: 1000,
- UpdatedName: "dashoo",
- UpdatedTime: gtime.Now(),
- })
- }
- return contract
- }
|