main.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. package main
  2. import (
  3. "bytes"
  4. "context"
  5. "database/sql"
  6. "fmt"
  7. "io/ioutil"
  8. "strings"
  9. "time"
  10. basedao "dashoo.cn/micro/app/dao/base"
  11. contractdao "dashoo.cn/micro/app/dao/contract"
  12. projao "dashoo.cn/micro/app/dao/proj"
  13. basemodel "dashoo.cn/micro/app/model/base"
  14. model "dashoo.cn/micro/app/model/contract"
  15. "github.com/gogf/gf/database/gdb"
  16. "github.com/gogf/gf/frame/g"
  17. "github.com/gogf/gf/util/gconv"
  18. "github.com/gogf/gf/os/gtime"
  19. "github.com/xuri/excelize/v2"
  20. )
  21. func main() {
  22. // contract()
  23. // product()
  24. // collectionplan()
  25. // collection()
  26. // dist()
  27. // prepareuser()
  28. // prepare()
  29. // fmt.Println(Usermap)
  30. // fmt.Println(MapProvince)
  31. // distContact()
  32. projectRelate()
  33. }
  34. func projectRelate() {
  35. projao := projao.NewProjBusinessDao("prod")
  36. contractdao := contractdao.NewCtrContractDao("prod")
  37. fileb, err := ioutil.ReadFile("/home/lai/项目关联.xlsx")
  38. if err != nil {
  39. panic(err)
  40. }
  41. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  42. if err != nil {
  43. panic(err)
  44. }
  45. coderow, err := e.GetRows("Sheet1")
  46. if err != nil {
  47. panic(err)
  48. }
  49. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  50. for rown, row := range coderow[1:] {
  51. projcode := strings.TrimSpace(row[0])
  52. contrcode := strings.TrimSpace(row[1])
  53. fmt.Println(rown, projcode, contrcode)
  54. nbo, err := projao.Where("nbo_code = ?", projcode).One()
  55. if err != nil {
  56. return err
  57. }
  58. if nbo == nil {
  59. return fmt.Errorf("项目不存在")
  60. }
  61. contract, err := contractdao.Where("contract_code = ?", contrcode).One()
  62. if err != nil {
  63. return err
  64. }
  65. if contract == nil {
  66. return fmt.Errorf("合同不存在")
  67. }
  68. _, err = tx.Update("ctr_contract", map[string]interface{}{
  69. "cust_id": nbo.CustId,
  70. "cust_name": nbo.CustName,
  71. "nbo_id": nbo.Id,
  72. "nbo_name": nbo.NboName,
  73. "is_big": nbo.IsBig,
  74. "product_line": nbo.ProductLine,
  75. "cust_province_id": nbo.CustProvinceId,
  76. "cust_province": nbo.CustProvince,
  77. "cust_city_id": nbo.CustCityId,
  78. "cust_city": nbo.CustCity,
  79. }, "contract_code = ?", contrcode)
  80. if err != nil {
  81. return err
  82. }
  83. }
  84. // return fmt.Errorf("测试")
  85. return nil
  86. })
  87. if txerr != nil {
  88. panic(txerr)
  89. }
  90. }
  91. func distContact() {
  92. dao := basedao.NewBaseDistributorDao("prod")
  93. distMap := map[string]*basemodel.BaseDistributor{}
  94. ent, err := dao.All()
  95. if err != nil {
  96. panic(err)
  97. }
  98. for _, i := range ent {
  99. distMap[i.DistName] = i
  100. }
  101. fmt.Println(distMap)
  102. fileb, err := ioutil.ReadFile("/home/lai/渠道信息联系方式.xlsx")
  103. if err != nil {
  104. panic(err)
  105. }
  106. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  107. if err != nil {
  108. panic(err)
  109. }
  110. contact, err := e.GetRows("Sheet1")
  111. if err != nil {
  112. panic(err)
  113. }
  114. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  115. for rown, row := range contact[1:] {
  116. distname := strings.TrimSpace(row[2])
  117. name := strings.TrimSpace(row[3])
  118. position := strings.TrimSpace(row[5])
  119. phone := strings.TrimSpace(row[6])
  120. email := strings.TrimSpace(row[7])
  121. wechat := strings.TrimSpace(row[8])
  122. business := strings.TrimSpace(row[9])
  123. fmt.Println(rown, distname, name, position, phone, email, wechat, business, distMap[distname].Id)
  124. p := basemodel.BaseDistributorContact{
  125. DistId: distMap[distname].Id,
  126. Name: name,
  127. Post: position,
  128. Phone: phone,
  129. Wechat: wechat,
  130. Mail: email,
  131. Honorific: "未知",
  132. Territory: business,
  133. Remark: "",
  134. CreatedBy: 1000,
  135. CreatedName: "dashoo",
  136. CreatedTime: gtime.Now(),
  137. UpdatedBy: 1000,
  138. UpdatedName: "dashoo",
  139. UpdatedTime: gtime.Now(),
  140. }
  141. _, err = tx.Insert("base_distributor_contact", p)
  142. if err != nil {
  143. return err
  144. }
  145. }
  146. // return fmt.Errorf("测试")
  147. return nil
  148. })
  149. if txerr != nil {
  150. panic(txerr)
  151. }
  152. }
  153. type User struct {
  154. Id int
  155. NickName string
  156. UserName string
  157. }
  158. var Usermap = map[string]User{}
  159. func prepareuser() {
  160. users := []User{}
  161. err := g.DB("prod").Table("sys_user").Structs(&users)
  162. if err != nil {
  163. panic(err)
  164. }
  165. for _, u := range users {
  166. Usermap[u.NickName] = u
  167. }
  168. }
  169. func dist() {
  170. prepare()
  171. prepareuser()
  172. var custtypMap = map[string]string{
  173. "医院": "10",
  174. "科研单位": "20",
  175. "高校": "30",
  176. "疾控": "40",
  177. "细胞公司": "50",
  178. "生物药企": "60",
  179. "其他": "90",
  180. }
  181. fileb, err := ioutil.ReadFile("/home/lai/渠道信息台账0523(1)(1).xlsx")
  182. if err != nil {
  183. panic(err)
  184. }
  185. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  186. if err != nil {
  187. panic(err)
  188. }
  189. proxy, err := e.GetRows("代理商列表详情")
  190. if err != nil {
  191. panic(err)
  192. }
  193. dist, err := e.GetRows("经销商列表详情")
  194. if err != nil {
  195. panic(err)
  196. }
  197. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  198. for rowtype, distlist := range [][][]string{dist, proxy} {
  199. distType := "10"
  200. if rowtype == 1 {
  201. distType = "20"
  202. }
  203. for rown, row := range distlist[2:] {
  204. createdStr := strings.TrimSpace(row[1])
  205. seller := strings.TrimSpace(row[2])
  206. name := strings.TrimSpace(row[3])
  207. province := strings.TrimSpace(row[4])
  208. var sellerNumStr string
  209. var product string
  210. var hisCust string
  211. var custTypStr string
  212. var proxydistrict string
  213. var startStr string
  214. var endStr string
  215. var business string
  216. var capitalStr string
  217. var register string
  218. if len(row) > 5 {
  219. business = strings.TrimSpace(row[5])
  220. capitalStr = strings.TrimSpace(row[6])
  221. register = strings.TrimSpace(row[7])
  222. if len(row) > 8 {
  223. sellerNumStr = strings.TrimSpace(row[8])
  224. if len(row) > 9 {
  225. product = strings.TrimSpace(row[9])
  226. if len(row) > 10 {
  227. hisCust = strings.TrimSpace(row[10])
  228. if len(row) > 11 {
  229. if distType == "10" {
  230. custTypStr = strings.TrimSpace(row[11])
  231. } else {
  232. // fmt.Println(row)
  233. proxydistrict = strings.TrimSpace(row[12])
  234. startStr = strings.TrimSpace(row[13])
  235. endStr = strings.TrimSpace(row[14])
  236. custTypStr = strings.TrimSpace(row[15])
  237. }
  238. }
  239. }
  240. }
  241. }
  242. }
  243. created, err := time.Parse("2006/01/02 15:04:05", createdStr)
  244. if err != nil {
  245. panic(fmt.Errorf("%s, %s", createdStr, err.Error()))
  246. }
  247. start, err := time.Parse("2006/01/02", startStr)
  248. if err != nil {
  249. if distType == "10" {
  250. start = time.Time{}
  251. } else {
  252. panic(fmt.Errorf("%s, %s", startStr, err.Error()))
  253. }
  254. }
  255. end, err := time.Parse("2006/01/02", endStr)
  256. if err != nil {
  257. if distType == "10" {
  258. start = time.Time{}
  259. } else {
  260. panic(fmt.Errorf("%s, %s", endStr, err.Error()))
  261. }
  262. }
  263. sellerNum := gconv.Int(sellerNumStr)
  264. capital := gconv.Float64(capitalStr)
  265. var custypes string
  266. if custTypStr == "" {
  267. custypes = ""
  268. } else {
  269. custTypeslice := strings.Split(custTypStr, ",")
  270. custypeslice := []string{}
  271. for _, t := range custTypeslice {
  272. if t == "企业" {
  273. continue
  274. }
  275. if t == "医疗" {
  276. continue
  277. }
  278. if t == "科研" {
  279. continue
  280. }
  281. if t == "细胞企业" {
  282. continue
  283. }
  284. if t == "生物药企、医院" {
  285. custypeslice = append(custypeslice, custtypMap["生物药企"])
  286. custypeslice = append(custypeslice, custtypMap["医院"])
  287. continue
  288. }
  289. if custtypMap[t] == "" {
  290. panic(t + ":custypeslice")
  291. }
  292. custypeslice = append(custypeslice, custtypMap[t])
  293. }
  294. custypes = strings.Join(custypeslice, ",")
  295. if Usermap[seller].Id == 0 {
  296. panic(seller + ":seller")
  297. }
  298. }
  299. fmt.Println(rown, distType, created, seller, name, province, MapProvince[province], business, capital, register, sellerNum, product, hisCust, custypes, proxydistrict, start, end)
  300. p := basemodel.BaseDistributor{
  301. DistCode: "",
  302. DistName: name,
  303. AbbrName: "",
  304. DistDesc: "",
  305. DistBoss: "",
  306. DistBossPhone: "",
  307. ProvinceId: MapProvince[province],
  308. ProvinceDesc: province,
  309. BusinessScope: business,
  310. BelongSaleId: Usermap[seller].Id,
  311. BelongSale: seller,
  312. Capital: capital,
  313. SaleNum: sellerNum,
  314. InvoiceHeader: "",
  315. DistType: distType,
  316. CustomerType: custypes,
  317. ExistedProduct: product,
  318. AssistantSaleId: "",
  319. AssistantSale: "",
  320. RegisterDistrict: register,
  321. HistoryCustomer: hisCust,
  322. ProxyStartTime: gtime.NewFromTime(start),
  323. ProxyEndTime: gtime.NewFromTime(end),
  324. ProxyDistrict: proxydistrict,
  325. ContractUrl: "",
  326. Remark: "",
  327. CreatedBy: 1000,
  328. CreatedName: "dashoo",
  329. CreatedTime: gtime.Now(),
  330. UpdatedBy: 1000,
  331. UpdatedName: "dashoo",
  332. UpdatedTime: gtime.Now(),
  333. }
  334. _, err = tx.Insert("base_distributor", p)
  335. if err != nil {
  336. return err
  337. }
  338. }
  339. }
  340. // return fmt.Errorf("测试")
  341. return nil
  342. })
  343. if txerr != nil {
  344. panic(txerr)
  345. }
  346. }
  347. func collection() {
  348. var typMap = map[string]string{
  349. "电汇": "10",
  350. "承兑": "20",
  351. "现金": "30",
  352. }
  353. var contractMap = map[string]*model.CtrContract{}
  354. fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
  355. if err != nil {
  356. panic(err)
  357. }
  358. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  359. if err != nil {
  360. panic(err)
  361. }
  362. rows2021_2023, err := e.GetRows("2021-2023年回款管理")
  363. if err != nil {
  364. panic(err)
  365. }
  366. rows2017_2020, err := e.GetRows("2017-2020年回款管理")
  367. if err != nil {
  368. panic(err)
  369. }
  370. rows := append(rows2021_2023[1:], rows2017_2020[1:]...)
  371. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  372. for rown, row := range rows {
  373. custname := strings.TrimSpace(row[0])
  374. contractcode := strings.TrimSpace(row[1])
  375. amountStr := strings.TrimSpace(row[2])
  376. typ := strings.TrimSpace(row[3])
  377. var ctimeStr string
  378. if len(row) > 5 {
  379. ctimeStr = strings.TrimSpace(row[5])
  380. }
  381. if ctimeStr == "" {
  382. ctimeStr = "0001/1/2"
  383. }
  384. ctime, err := time.Parse("2006/1/2", ctimeStr)
  385. if err != nil {
  386. ctime, err = time.Parse("01-02-06", ctimeStr)
  387. }
  388. if err != nil {
  389. ctime, err = time.Parse("2006.1.2", ctimeStr)
  390. }
  391. if err != nil {
  392. if ctimeStr == "" {
  393. ctime = time.Time{}
  394. } else {
  395. panic(fmt.Errorf("%s, %s", ctimeStr, err.Error()))
  396. }
  397. }
  398. amount := gconv.Float64(amountStr)
  399. fmt.Println(rown, custname, contractcode, amount, typ, ctime)
  400. if _, ok := contractMap[contractcode]; !ok {
  401. c := &model.CtrContract{}
  402. err := tx.GetStruct(c, "select * from ctr_contract where contract_code = ?", contractcode)
  403. if err != nil {
  404. fmt.Println(c.ContractCode)
  405. return err
  406. }
  407. contractMap[contractcode] = c
  408. }
  409. p := model.CtrContractCollection{
  410. PlanId: 0,
  411. CustId: 0,
  412. CustName: custname,
  413. ContractId: contractMap[contractcode].Id,
  414. ContractCode: contractMap[contractcode].ContractCode,
  415. CollectionDatetime: gtime.NewFromTime(ctime),
  416. CollectionAmount: amount,
  417. CollectionType: typMap[typ],
  418. ApproStatus: "20",
  419. ContractAmount: contractMap[contractcode].ContractAmount,
  420. Remark: "",
  421. CreatedBy: 1000,
  422. CreatedName: "dashoo",
  423. CreatedTime: gtime.Now(),
  424. UpdatedBy: 1000,
  425. UpdatedName: "dashoo",
  426. UpdatedTime: gtime.Now(),
  427. }
  428. _, err = tx.Insert("ctr_contract_collection", p)
  429. if err != nil {
  430. return err
  431. }
  432. }
  433. return nil
  434. // return fmt.Errorf("测试")
  435. })
  436. fmt.Println(contractMap)
  437. if txerr != nil {
  438. panic(txerr)
  439. }
  440. }
  441. func collectionplan() {
  442. var statusMap = map[string]string{
  443. "已回款": "30",
  444. "未回款": "10",
  445. }
  446. var contractMap = map[string]*model.CtrContract{}
  447. fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
  448. if err != nil {
  449. panic(err)
  450. }
  451. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  452. if err != nil {
  453. panic(err)
  454. }
  455. rows2021_2023, err := e.GetRows("2021-2023年回款计划")
  456. if err != nil {
  457. panic(err)
  458. }
  459. rows := rows2021_2023[1:]
  460. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  461. for rown, row := range rows {
  462. custname := strings.TrimSpace(row[0])
  463. contractcode := strings.TrimSpace(row[1])
  464. amountStr := strings.TrimSpace(row[2])
  465. status := strings.TrimSpace(row[3])
  466. planTimeStr := strings.TrimSpace(row[4])
  467. scaleStr := strings.TrimSpace(row[5])
  468. var criteria string
  469. if len(row) > 6 {
  470. criteria = strings.TrimSpace(row[6])
  471. }
  472. if planTimeStr == "" {
  473. planTimeStr = "0001/1/2"
  474. }
  475. planTime, err := time.Parse("2006/1/2", planTimeStr)
  476. if err != nil {
  477. planTime, err = time.Parse("01-02-06", planTimeStr)
  478. }
  479. if err != nil {
  480. if planTimeStr == "" {
  481. planTime = time.Time{}
  482. } else {
  483. panic(fmt.Errorf("%s, %s", planTimeStr, err.Error()))
  484. }
  485. }
  486. amount := gconv.Float64(amountStr)
  487. scale := gconv.Float64(strings.Replace(scaleStr, "%", "", -1))
  488. var CashedAmount float64
  489. if status == "已回款" {
  490. CashedAmount = amount
  491. }
  492. fmt.Println(rown, custname, contractcode, amount, status, scale, criteria)
  493. if _, ok := contractMap[contractcode]; !ok {
  494. c := &model.CtrContract{}
  495. err := tx.GetStruct(c, "select * from ctr_contract where contract_code = ?", contractcode)
  496. if err != nil {
  497. fmt.Println(c.ContractCode)
  498. return err
  499. }
  500. contractMap[contractcode] = c
  501. }
  502. p := model.CtrContractCollectionPlan{
  503. CustId: 0,
  504. CustName: custname,
  505. ContractId: contractMap[contractcode].Id,
  506. ContractCode: contractMap[contractcode].ContractCode,
  507. ContractStatus: statusMap[status],
  508. PlanAmount: amount,
  509. PlanDatetime: gtime.NewFromTime(planTime),
  510. PlanScale: scale,
  511. PlanCondition: criteria,
  512. CashedAmount: CashedAmount,
  513. CashedDatetime: nil,
  514. Remark: "",
  515. CreatedBy: 1000,
  516. CreatedName: "dashoo",
  517. CreatedTime: gtime.Now(),
  518. UpdatedBy: 1000,
  519. UpdatedName: "dashoo",
  520. UpdatedTime: gtime.Now(),
  521. }
  522. _, err = tx.Insert("ctr_contract_collection_plan", p)
  523. if err != nil {
  524. return err
  525. }
  526. }
  527. // return fmt.Errorf("测试")
  528. return nil
  529. })
  530. fmt.Println(contractMap)
  531. if txerr != nil {
  532. panic(txerr)
  533. }
  534. }
  535. func product() {
  536. var ProdClassMap = map[string]string{
  537. "BIOBANK": "10",
  538. "Biobank": "10",
  539. "CELLSOP": "20",
  540. "CellSOP": "20",
  541. "CellsSOP": "20",
  542. "LIMS": "30",
  543. "LIMS+基因": "30",
  544. "MCS": "60",
  545. "咨询服务": "70",
  546. "外购": "90",
  547. "智能硬件": "40",
  548. "液氮罐": "50",
  549. "设备": "",
  550. }
  551. var productMap = map[string]*basemodel.BaseProduct{}
  552. var contractMap = map[string]*model.CtrContract{}
  553. fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
  554. if err != nil {
  555. panic(err)
  556. }
  557. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  558. if err != nil {
  559. panic(err)
  560. }
  561. rows2021_2023, err := e.GetRows("2021-2023年产品信息")
  562. if err != nil {
  563. panic(err)
  564. }
  565. rows2017_2020, err := e.GetRows("2017-2020年产品信息")
  566. if err != nil {
  567. panic(err)
  568. }
  569. rows := append(rows2021_2023[1:], rows2017_2020[1:]...)
  570. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  571. for rown, row := range rows {
  572. contractcode := strings.TrimSpace(row[0])
  573. ProdClass := strings.TrimSpace(row[1])
  574. ProdName := strings.TrimSpace(row[2])
  575. ProdCode := strings.TrimSpace(row[3])
  576. priceStr := strings.TrimSpace(row[4])
  577. numStr := strings.TrimSpace(row[5])
  578. sumStr := strings.TrimSpace(row[6])
  579. var zhibaoStr string
  580. var maintainStr string
  581. var maintainTerm string
  582. var acceptTimeStr string
  583. if len(row) > 7 {
  584. zhibaoStr = strings.TrimSpace(row[7])
  585. if len(row) > 8 {
  586. maintainStr = strings.TrimSpace(row[8])
  587. if len(row) > 9 {
  588. maintainTerm = strings.TrimSpace(row[9])
  589. if len(row) > 10 {
  590. acceptTimeStr = strings.TrimSpace(row[10])
  591. }
  592. }
  593. }
  594. }
  595. acceptTime, err := time.Parse("2006/1/2", acceptTimeStr)
  596. if err != nil {
  597. acceptTime, err = time.Parse("01-02-06", acceptTimeStr)
  598. }
  599. if err != nil {
  600. acceptTime, err = time.Parse("2006年1月2日", acceptTimeStr)
  601. }
  602. if err != nil {
  603. if acceptTimeStr == "" {
  604. acceptTime = time.Time{}
  605. } else {
  606. panic(fmt.Errorf("%s, %s", acceptTimeStr, err.Error()))
  607. }
  608. }
  609. price := gconv.Float64(priceStr)
  610. num := gconv.Int(numStr)
  611. sum := gconv.Float64(sumStr)
  612. zhibao := gconv.Int(zhibaoStr)
  613. maintain := gconv.Int(maintainStr)
  614. fmt.Println(rown, contractcode, ProdClass, ProdName, ProdCode, price,
  615. num, sum, zhibao, maintain, maintainTerm, acceptTime)
  616. p := basemodel.BaseProduct{
  617. ProdCode: ProdCode,
  618. ProdName: ProdName,
  619. ProdClass: ProdClassMap[ProdClass],
  620. GuidPrice: 0,
  621. DistPrice: 0,
  622. AgentPrice: 0,
  623. MarketPrice: 0,
  624. Remark: "",
  625. CreatedBy: 1000,
  626. CreatedName: "dashoo",
  627. CreatedTime: gtime.Now(),
  628. UpdatedBy: 1000,
  629. UpdatedName: "dashoo",
  630. UpdatedTime: gtime.Now(),
  631. DeletedTime: gtime.Now(),
  632. }
  633. if _, ok := productMap[p.ProdName]; !ok {
  634. dbexistp := &basemodel.BaseProduct{}
  635. err := tx.GetStruct(dbexistp, "select * from base_product where prod_name = ?", p.ProdName)
  636. if err == sql.ErrNoRows {
  637. id, err := tx.InsertAndGetId("base_product", p)
  638. if err != nil {
  639. return err
  640. }
  641. p.Id = int(id)
  642. productMap[p.ProdName] = &p
  643. } else {
  644. if err != nil {
  645. return err
  646. }
  647. productMap[p.ProdName] = dbexistp
  648. }
  649. }
  650. if _, ok := contractMap[contractcode]; !ok {
  651. c := &model.CtrContract{}
  652. err := tx.GetStruct(c, "select * from ctr_contract where contract_code = ?", contractcode)
  653. if err != nil {
  654. fmt.Println(c.ContractCode)
  655. return err
  656. }
  657. contractMap[contractcode] = c
  658. }
  659. cp := model.CtrContractProduct{
  660. ContractId: contractMap[contractcode].Id,
  661. ContractCode: contractMap[contractcode].ContractCode,
  662. ProdId: productMap[p.ProdName].Id,
  663. ProdCode: productMap[p.ProdName].ProdCode,
  664. ProdName: productMap[p.ProdName].ProdName,
  665. ProdClass: productMap[p.ProdName].ProdClass,
  666. ProdNum: num,
  667. MaintTerm: 0,
  668. SugSalesPrice: 0,
  669. TranPrice: price,
  670. ContractPrive: contractMap[contractcode].ContractAmount,
  671. PurchaseCost: 0,
  672. DevCost: 0,
  673. MaintainCost: 0,
  674. DirectCost: 0,
  675. MaintainPeriod: zhibao * 365,
  676. WarrantPeriod: maintain * 365,
  677. MaintainStartTime: nil,
  678. MaintainRemark: maintainTerm,
  679. AcceptTime: gtime.NewFromTime(acceptTime),
  680. Remark: "",
  681. CreatedBy: 1000,
  682. CreatedName: "dashoo",
  683. CreatedTime: gtime.Now(),
  684. UpdatedBy: 1000,
  685. UpdatedName: "dashoo",
  686. UpdatedTime: gtime.Now(),
  687. }
  688. _, err = tx.Insert("ctr_contract_product", cp)
  689. if err != nil {
  690. return err
  691. }
  692. }
  693. // return fmt.Errorf("测试")
  694. return nil
  695. })
  696. fmt.Println(contractMap)
  697. fmt.Println(productMap)
  698. fmt.Println(ProdClassMap)
  699. if txerr != nil {
  700. panic(txerr)
  701. }
  702. }
  703. func contract() {
  704. prepare()
  705. contract := parse()
  706. fmt.Println(MapProductLine)
  707. txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
  708. _, err := tx.Insert("ctr_contract", contract)
  709. return err
  710. })
  711. if txerr != nil {
  712. panic(txerr)
  713. }
  714. }
  715. var MapProvince = map[string]int{}
  716. var MapCity = map[string]int{}
  717. var MapProductLine = map[string]string{
  718. "BIOBANK": "10",
  719. "CELLSOP": "20",
  720. "LIMS+基因": "30",
  721. "MCS": "60",
  722. "咨询服务": "70",
  723. "外购": "90",
  724. "智能硬件": "40",
  725. "石油": "80",
  726. }
  727. var Mapcontracttype = map[string]string{
  728. "销售合同": "XS",
  729. "技术合同": "JS",
  730. }
  731. var MapSignatoryType = map[string]string{
  732. "终端用户": "10",
  733. "经销商": "20",
  734. "代理商": "30",
  735. }
  736. func prepare() {
  737. dao := basedao.NewBaseDistrictDao("prod")
  738. province, err := dao.Where("dist_level = 1").All()
  739. if err != nil {
  740. panic(err)
  741. }
  742. for _, p := range province {
  743. MapProvince[p.DistName] = p.Id
  744. }
  745. city, err := dao.Where("dist_level = 2").All()
  746. if err != nil {
  747. panic(err)
  748. }
  749. for _, c := range city {
  750. MapCity[c.DistName] = c.Id
  751. }
  752. }
  753. func parse() []model.CtrContract {
  754. fileb, err := ioutil.ReadFile("/home/lai/OMS合同管理17-23合同信息0519(1).xlsx")
  755. if err != nil {
  756. panic(err)
  757. }
  758. e, err := excelize.OpenReader(bytes.NewBuffer(fileb))
  759. if err != nil {
  760. panic(err)
  761. }
  762. rows2021_2023, err := e.GetRows("2021-2023年合同基本信息")
  763. if err != nil {
  764. panic(err)
  765. }
  766. rows2017_2020, err := e.GetRows("2017-2020年合同基本信息")
  767. if err != nil {
  768. panic(err)
  769. }
  770. rows := append(rows2021_2023[1:], rows2017_2020[1:]...)
  771. contract := []model.CtrContract{}
  772. for rown, row := range rows {
  773. code := strings.TrimSpace(row[0])
  774. name := strings.TrimSpace(row[1])
  775. custname := strings.TrimSpace(row[2])
  776. nobname := strings.TrimSpace(row[3])
  777. province := strings.TrimSpace(row[4])
  778. city := strings.TrimSpace(row[5])
  779. amountstr := strings.TrimSpace(row[6])
  780. InchargeName := strings.TrimSpace(row[7])
  781. ContractType := strings.TrimSpace(row[8])
  782. ContractSignTimestr := strings.TrimSpace(row[9])
  783. ContractEndTimestr := strings.TrimSpace(row[10])
  784. SignatoryName := strings.TrimSpace(row[11])
  785. ProductLine := strings.TrimSpace(row[12])
  786. SignatoryUnit := strings.TrimSpace(row[13])
  787. SignatoryType := strings.TrimSpace(row[14])
  788. if ContractEndTimestr == "" {
  789. ContractEndTimestr = "0001/1/2"
  790. }
  791. if ContractSignTimestr == "" {
  792. ContractSignTimestr = "0001/1/2"
  793. }
  794. amount := gconv.Float64(amountstr)
  795. ContractSignTime, err := time.Parse("2006/1/2", ContractSignTimestr)
  796. if err != nil {
  797. ContractSignTime, err = time.Parse("01-02-06", ContractSignTimestr)
  798. }
  799. if err != nil {
  800. panic(fmt.Errorf("%s, %s", ContractSignTimestr, err.Error()))
  801. }
  802. ContractEndTime, err := time.Parse("2006/1/2", ContractEndTimestr)
  803. if err != nil {
  804. ContractEndTime, err = time.Parse("01-02-06", ContractEndTimestr)
  805. }
  806. if err != nil {
  807. panic(fmt.Errorf("%s, %s", ContractEndTimestr, err.Error()))
  808. }
  809. provinceId := MapProvince[province]
  810. cityId := MapCity[city]
  811. var DistributorName string
  812. if SignatoryType == "经销商" || SignatoryType == "代理商" {
  813. DistributorName = SignatoryUnit
  814. }
  815. fmt.Println(rown, code, name, custname, nobname, province, city,
  816. amount, InchargeName, ContractType, ContractSignTime,
  817. ContractEndTime, SignatoryName, ProductLine, SignatoryType)
  818. contract = append(contract, model.CtrContract{
  819. ContractCode: code,
  820. ContractName: name,
  821. CustId: 0,
  822. CustName: custname,
  823. ProductLine: MapProductLine[ProductLine],
  824. IsBig: "20",
  825. CustProvinceId: provinceId,
  826. CustProvince: province,
  827. CustCityId: cityId,
  828. CustCity: city,
  829. NboId: 0,
  830. NboName: nobname,
  831. ApproStatus: "30",
  832. ContractType: Mapcontracttype[ContractType],
  833. ContractAmount: amount,
  834. InvoiceAmount: 0,
  835. CollectedAmount: 0,
  836. ContractStartTime: gtime.NewFromTime(ContractSignTime),
  837. ContractEndTime: gtime.NewFromTime(ContractEndTime),
  838. ContractSignTime: gtime.NewFromTime(ContractSignTime),
  839. InchargeId: 0,
  840. InchargeName: InchargeName,
  841. SignatoryId: 0,
  842. SignatoryName: SignatoryName,
  843. SignatoryType: MapSignatoryType[SignatoryType],
  844. SignatoryUnit: SignatoryUnit,
  845. EarnestMoney: 0,
  846. CustSignatoryId: 0,
  847. CustSignatoryName: "",
  848. DistributorId: 0,
  849. DistributorName: DistributorName,
  850. ServiceFeeAgreement: "",
  851. Remark: "",
  852. CreatedBy: 1000,
  853. CreatedName: "dashoo",
  854. CreatedTime: gtime.Now(),
  855. UpdatedBy: 1000,
  856. UpdatedName: "dashoo",
  857. UpdatedTime: gtime.Now(),
  858. })
  859. }
  860. return contract
  861. }