package service import ( "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/encrypt" "fmt" "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/db" "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/internal/config" "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/pb" "log" "strings" ) const ( DATA_SUPERMARKET = "data_supermarket" ) type DataSmt struct { } // 列表数据 func (d *DataSmt) List(searchValue, dataType string, pageNum, pageSize int64) *pb.DatasmtRespList { result := pb.DatasmtRespList{} //包含字段说明 fieldIllustrate := []*pb.Field{} fieldIllustrateMap := map[string]string{} for _, v := range config.C.DataSmt.FieldIllustrate { fieldIllustrate = append(fieldIllustrate, &pb.Field{ Code: v.Code, Name: v.Name, Describe: v.Describe, }) fieldIllustrateMap[v.Code] = v.Name } result.FieldIllustrate = fieldIllustrate if pageSize == 0 { pageSize = 40 } //数据查询 data := &[]map[string]interface{}{} querySql := "select id,name,data_type,format,clear_status from %s where %s ORDER BY serial_number limit %v ,%v " queryStrArr := []string{ " status=1 ", } if searchValue != "" { queryStrArr = append(queryStrArr, " name LIKE '%"+searchValue+"%' ") } if dataType != "" { queryStrArr = append(queryStrArr, fmt.Sprintf(" data_type = '%s' ", dataType)) } querySql = fmt.Sprintf(querySql, DATA_SUPERMARKET, strings.Join(queryStrArr, " and "), (pageNum-1)*pageSize, pageSize) log.Println("querySql", querySql) data = db.Mysql_BaseService.SelectBySql(querySql) if data != nil && len(*data) > 0 { //数据处理 dataList := []*pb.DatasmtList{} for _, v := range *data { dataList = append(dataList, &pb.DatasmtList{ Id: encrypt.SE.Encode2Hex(common.InterfaceToStr(v["id"])), Name: common.InterfaceToStr(v["name"]), DataType: fieldIllustrateMap[common.InterfaceToStr(v["data_type"])], Format: common.InterfaceToStr(v["format"]), ClearStatus: common.InterfaceToStr(v["clear_status"]), }) } result.List = dataList } //总数查询 countQuerySql := "select count(id) from %s where %s " countQuerySql = fmt.Sprintf(countQuerySql, DATA_SUPERMARKET, strings.Join(queryStrArr, " and ")) count := db.Mysql_BaseService.CountBySql(countQuerySql) result.PageCount = count //热搜词处理 hotKeySql := fmt.Sprintf("select keyword from %s where status=1 ORDER BY serial_number LIMIT 0,8", DATA_SUPERMARKET) log.Println("querySql", hotKeySql) hotData := db.Mysql_BaseService.SelectBySql(hotKeySql) hotKeyArr := []string{} for _, m := range *hotData { hotKeyArr = append(hotKeyArr, common.InterfaceToStr(m["keyword"])) } result.HotKeys = hotKeyArr result.DataTypeStr = fieldIllustrateMap[dataType] return &result } // 详情 func (d *DataSmt) Detail(id string) *pb.DatasmtRespDetail { result := &pb.DatasmtRespDetail{} querySql := fmt.Sprintf("select id,name,data_type,format,clear_status,data_example,introduce,keyword from %s where id =%s", DATA_SUPERMARKET, id) data := db.Mysql_BaseService.SelectBySql(querySql) if data != nil && len(*data) > 0 { //数据处理 v := (*data)[0] dataType := common.InterfaceToStr(v["data_type"]) result = &pb.DatasmtRespDetail{ Name: common.InterfaceToStr(v["name"]), DataType: common.InterfaceToStr(v["data_type"]), Format: common.InterfaceToStr(v["format"]), ClearStatus: common.InterfaceToStr(v["clear_status"]), DataExample: common.InterfaceToStr(v["data_example"]), Introduce: common.InterfaceToStr(v["introduce"]), Keyword: common.InterfaceToStr(v["keyword"]), } for _, v := range config.C.DataSmt.FieldIllustrate { if dataType == v.Code { result.FieldIllustrate = &pb.Field{ Code: v.Code, Name: v.Name, Describe: v.Describe, } } } } return result }