123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- package main
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/xuri/excelize/v2"
- util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
- "log"
- "net/http"
- )
- type EnvRequest struct {
- Names []string `json:"names"`
- }
- type EnvResponse struct {
- Code int `json:"code"`
- Msg string `json:"msg"`
- Data interface{} `json:"data"`
- }
- func main() {
- err := InitConfig()
- if err != nil {
- log.Println("配置文件 读取失败", err)
- return
- }
- readXlsx() //98家 央企名单
- InitMgo()
- //getCompanyTypes()
- updateXlsx()
- log.Println("数据处理完毕!")
- }
- // updateXlsx 更新xlsx 文件标签
- func updateXlsx() {
- filePath := GF.Env.File
- if filePath == "" {
- log.Println("文件路径为空")
- return
- }
- // 1. 读取 Excel(获取 A 列数据)
- f, err := excelize.OpenFile(filePath)
- if err != nil {
- log.Fatal("❌ 无法打开 Excel 文件:", err)
- }
- defer f.Close()
- //读取央企
- rows, err := f.GetRows(GF.Env.Sheet)
- if err != nil {
- log.Fatal("❌ 无法读取 Sheet1:", err)
- }
- for i := 1; i < len(rows); i++ {
- //project_name := rows[i][0] //项目名称
- name := rows[i][1] //企业名称
- res1 := getCompanyType(name)
- res2 := getMarketType(name)
- res3 := getTop(name)
- if res1 != "" {
- f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("D%v", i+1), res1)
- }
- if res2 != "" {
- f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("E%v", i+1), res2)
- }
- if res3 != "" {
- f.SetCellValue(GF.Env.Sheet, fmt.Sprintf("F%v", i+1), res3)
- }
- }
- f.Save()
- }
- // updateBidding 更新企业类型信息等
- func updateBidding() {
- sess := MgoB.GetMgoConn()
- defer MgoB.DestoryMongoConn(sess)
- log.Println("开始处理:", GF.MongoB.DB, GF.MongoB.Coll)
- queryMgo := sess.DB(GF.MongoB.DB).C(GF.MongoB.Coll).Find(nil).Select(nil).Iter()
- count := 0
- for tmp := make(map[string]interface{}); queryMgo.Next(tmp); count++ {
- if count%1000 == 0 {
- log.Println("current:", count, tmp["_id"], tmp["title"])
- }
- //中标单位
- name := util.ObjToString(tmp["s_winner"])
- if name == "" {
- continue
- }
- update := make(map[string]interface{}, 0)
- res1 := getCompanyType(name)
- res2 := getMarketType(name)
- res3 := getTop(name)
- if res1 != "" {
- update["company_type"] = res1
- }
- if res2 != "" {
- update["market_type"] = res2
- }
- if res3 != "" {
- update["top_name"] = res3
- }
- projectscope := util.ObjToString(tmp["projectscope"])
- biddingID := mongodb.BsonIdToSId(tmp["_id"])
- if projectscope == "" {
- project := getProject(biddingID)
- projectscope = util.ObjToString(project["projectscope"])
- if projectscope != "" {
- update["projectscope"] = projectscope
- }
- }
- // 需要更新
- if len(update) > 0 {
- MgoB.UpdateById(GF.MongoB.Coll, biddingID, map[string]interface{}{"$set": update})
- }
- }
- log.Println(GF.MongoB.DB, GF.MongoB.Coll, "数据处理完毕")
- }
- // getCompanyTypes 获取公司类型
- func getCompanyTypes() {
- r := gin.Default()
- //
- r.POST("/types", func(c *gin.Context) {
- var req EnvRequest
- if err := c.ShouldBindJSON(&req); err != nil {
- respon := EnvResponse{
- Code: 400,
- Msg: "请求参数无效",
- }
- c.JSON(http.StatusBadRequest, respon)
- return
- }
- //
- results := make([]map[string]interface{}, 0)
- for _, v := range req.Names {
- res1 := getCompanyType(v)
- res2 := getMarketType(v)
- res3 := getTop(v)
- dd := map[string]interface{}{
- "company_type": res1,
- "market_type": res2,
- "top_name": res3,
- "company_name": v,
- }
- results = append(results, dd)
- }
- respon := EnvResponse{
- Code: 200,
- Msg: "请求成功",
- Data: results,
- }
- c.JSON(http.StatusBadRequest, respon)
- return
- })
- // 启动服务
- r.Run(":8080")
- }
|