| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003 |
- 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()
- // updateclloect()
- // updateContractIncharge()
- }
- func updateContractIncharge() {
- prepareuser()
- contractdao := contractdao.NewCtrContractDao("prod")
- contract, err := contractdao.All()
- if err != nil {
- panic(err)
- }
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for _, c := range contract {
- if c.InchargeId != 0 {
- continue
- }
- if Usermap[c.InchargeName].Id == 0 {
- panic(c.InchargeName + ":seller")
- }
- _, err = tx.Update("ctr_contract",
- map[string]interface{}{
- "incharge_id": Usermap[c.InchargeName].Id,
- }, "id = ?", c.Id)
- if err != nil {
- return err
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- if txerr != nil {
- panic(txerr)
- }
- }
- func updateclloect() {
- contractdao := contractdao.NewCtrContractDao("prod")
- contract, err := contractdao.All()
- if err != nil {
- panic(err)
- }
- txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
- for _, c := range contract {
- v, err := tx.GetValue("select sum(collection_amount) from ctr_contract_collection where contract_id=? and appro_status='20' and deleted_time is null", c.Id)
- if err != nil {
- return err
- }
- amount := v.Float64()
- _, err = tx.Update("ctr_contract",
- map[string]interface{}{
- "collected_amount": amount,
- }, "id = ?", c.Id)
- if err != nil {
- return err
- }
- }
- // return fmt.Errorf("测试")
- return nil
- })
- if txerr != nil {
- panic(txerr)
- }
- }
- 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
- }
|