Koltin22.Takeout首页Retrofit请求数据(8)

HomeFragment.kt

package com.example.takeout.ui.fragment

import android.app.Fragment
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.takeout.R
import com.example.takeout.presenter.HomeFragmentPresenster
import com.example.takeout.ui.adapter.HomeRvAdapter
import com.heima.takeout.model.beans.Seller
import kotlinx.android.synthetic.main.fragment_home.*
import org.jetbrains.anko.find

class HomeFragment : Fragment() {
    lateinit var homeRvAdapter: HomeRvAdapter//延迟初始化
    lateinit var rvHome: RecyclerView
    lateinit var homeFragmentPresenster : HomeFragmentPresenster

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = View.inflate(activity, R.layout.fragment_home, null)
        rvHome = view.find<RecyclerView>(R.id.rv_home)
        //上下布局
        rvHome.layoutManager = LinearLayoutManager(activity)
        homeRvAdapter = HomeRvAdapter(activity)
        rvHome.adapter = homeRvAdapter
        homeFragmentPresenster= HomeFragmentPresenster(this)

        distance = 120.dp2px()
        return view
    }

    fun Int.dp2px(): Int {
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            toFloat(), resources.displayMetrics).toInt()

    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initData()
    }

    val datas: ArrayList<String> = ArrayList<String>()
    var sum: Int = 0
    var distance: Int = 0
    var alpha = 55
    private fun initData() {
        for (i in 0 until 100) {
            datas.add("我是商家:" + i)
        }
        homeFragmentPresenster.getHomeInfo()
        homeRvAdapter.setData(datas)
        //有数据可以滚动才可以监听滚动事件,设置标题的透明效果
        rvHome.setOnScrollListener(object : RecyclerView.OnScrollListener() {

            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                if (recyclerView != null) {
                    super.onScrollStateChanged(recyclerView, newState)
                }
            }

            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                if (recyclerView != null) {
                    super.onScrolled(recyclerView, dx, dy)
                }
                sum += dy
                if (sum > distance) {
                    alpha = 255
                } else {
                    alpha = sum * 200 / distance
                    alpha += 55
                }
                Log.e("home", "alpha:$alpha")
                ll_title_container.setBackgroundColor(Color.argb(alpha, 0x31, 0x90, 0xe8))
            }
        })
    }

    //所有的数据
//    val allList:ArrayList<Seller> = ArrayList()
//    fun onHomeSuccess(nearbySellers: List<Seller>, otherSellers: List<Seller>) {
//        allList.clear()
//        allList.addAll(nearbySellers)
//        allList.addAll(otherSellers)
//        homeRvAdapter.setData(allList)
//    }
    fun onHomeSuccess(){}

    fun onHomeFailed() {

    }

}

HomeFragmentPresenster.kt使用Retrofit请求网络的逻辑

package com.example.takeout.presenter

import android.util.Log
import com.example.takeout.model.net.MyCarBean
import com.example.takeout.model.net.TakeoutService
import com.example.takeout.ui.fragment.HomeFragment
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.heima.takeout.model.beans.Seller
import org.json.JSONObject
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


class HomeFragmentPresenster(val homeFragment: HomeFragment) {
    val takeoutService: TakeoutService

    init {
        val retrofit = Retrofit.Builder()
//            .baseUrl("https://mrobot.pcauto.com.cn/v2/cms/")
//            .baseUrl("https://baobab.kaiyanapp.com/")
            .baseUrl("http://127.0.0.1:8090/")
            .addConverterFactory(GsonConverterFactory.create())
            .build()

        takeoutService = retrofit.create(TakeoutService::class.java)
    }

    /**
     * 使用异步获取数据
     */
    fun getHomeInfo() {
        //TOTO:要异步访问
        val homeCall = takeoutService.getHomeInfo();
        takeoutService.getHomeInfo().enqueue(object: Callback<MyCarBean> {
            override fun onResponse(call: Call<MyCarBean>?, response: Response<MyCarBean>?) {
                //成功
                var myCarBean: MyCarBean? = response!!.body()
                var myCarBeanLists: List<MyCarBean.CarInfo> = myCarBean!!.data

                for (ca in myCarBeanLists){
                    Log.d("HomeFragmentPresenster", ca.title)
                }
            }
            override fun onFailure(call: Call<MyCarBean>?, t: Throwable?) {
                //失败
                Log.d("HomeFragmentPresenster", "onFailure=====" + t.toString())
            }
        })
        /*
        homeCall.enqueue(object : Callback<ResponseInfo> {
            override fun onResponse(call: Call<ResponseInfo>?, response: Response<ResponseInfo>?) {
                if (response == null) {
                    Log.d("HomeFragmentPresenster", "服务器没有成功返回=====")
                } else {
                    if (response.isSuccessful()) {
                        val responseInfo = response.body()
                        if (responseInfo.code.equals("0")) {
                            val json = responseInfo.data
//                            parserJson(json)
                        } else if (responseInfo.code.equals("-1")) {
                            //返回值和接口文档约定

                        }
                    } else {
                        Log.d("HomeFragmentPresenster", "服务器代码错误=====")
                    }
                }
            }


            override fun onFailure(call: Call<ResponseInfo>?, t: Throwable?) {
                Log.d("HomeFragmentPresenster", "onFailure=====")
            }
        })

         */

        //有数据,成功页面
        homeFragment.onHomeSuccess()

        //无数据,异常页面
        homeFragment.onHomeFailed()
    }

    /**
     * 解析数据
     */
    private fun parserJson(json: String?) {
        //解析数据
        val gson = Gson()
        var jsonObject = JSONObject(json)
        //附近的商家
        var nearby = jsonObject.getString("nearbySellerList")
        val nearbySellers: List<Seller> =
            gson.fromJson(nearby, object : TypeToken<List<Seller>>() {}.type)
        //其他的商家
        val other = jsonObject.getString("otherSellerList")
        val otherSellers: List<Seller> =
            gson.fromJson(other, object : TypeToken<List<Seller>>() {}.type)
        //TODO:刷新UI

        //有数据,成功页面
        if (nearbySellers.isNotEmpty() || otherSellers.isNotEmpty()) {
//            homeFragment.onHomeSuccess(nearbySellers, otherSellers)
            homeFragment.onHomeSuccess()
        } else {
            //无数据,异常页面
            homeFragment.onHomeFailed()
        }

    }
}

TakeoutService.kt

package com.example.takeout.model.net

import retrofit2.Call
import retrofit2.http.GET

interface TakeoutService {

//ex.    @GET("users/{user}/repos")
//ex.    fun listRepos(@Path("user") user: String): Call<List<Repo>>

    @GET("takeout?index=0")
    fun getHomeInfo(): Call<MyCarBean>

}

ResponseInfo.kt

package com.example.takeout.model.net

class MyCarBean(var data:List<CarInfo>) {
    class CarInfo(
        var articleType: String,
        var count: String,
        var downs: String,
        var firstImg: String,
        var id: String,
        var image: String,
        var mtime: String,
        var pubDate: String,
        var title: String,
        var ups: String,
        var url: String
    )
}

服务端代码的配置

TakeoutServlet.java

package cn.ldw.servlet;

import android.os.Environment;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TakeoutServlet extends BaseServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setStatus(HttpServletResponse.SC_OK);
        String path0 = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Apaches/takeout/takeInfors";

        String path = null;
        int index =  Integer.valueOf(req.getParameter("index"));
        if(index == 0){
            path = path0;
        }

        File file = new File(path);
        long length = file.length();
        resp.setContentLength((int) length);
        OutputStream out = resp.getOutputStream();
        FileInputStream stream = new FileInputStream(file);
        int count = -1;
        byte[] buffer = new byte[1024];
        while ((count = stream.read(buffer)) != -1) {
            out.write(buffer, 0, count);
            out.flush();
        }
        stream.close();
        out.close();
    }
}

请求的方式,打开应用以后可以在浏览器上直接输入下面的链接就可以看到所有的数据

http://127.0.0.1:8090/takeout?index=0

打印的数据如下

其中takeInfors数据如下:

{
	"total": 200,
	"pageNo": 1,
	"pageSize": 20,
	"data": [
		{
			"pcauto_author_Id": "lijiaming1",
			"count": 1,
			"editorInChargeId": "lijiaming1",
			"categoryFirst": "导购",
			"pcauto_series_name": "伊兰特",
			"id": "22606371",
			"pcauto_series_id": "2463",
			"title": "12万的中配值得考虑?实拍第七代伊兰特1.5L尊贵版",
			"pcauto_content_category2": "到店实拍",
			"pcauto_content_category1": "导购",
			"categorySec": "到店实拍",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-20",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "黎嘉铭",
			"pcauto_publish_time": 1603123862000,
			"pcauto_author_name": "lijiaming1",
			"mtime": 1603123862000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/19/g_22606371_1603074048374_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2260/22606371.html",
			"tag_2": "原创 黎嘉铭",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/19/22606371_001.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 2463,
				"serialName": "伊兰特"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "panxianyang",
			"count": 0,
			"editorInChargeId": "panxianyang",
			"categoryFirst": "导购",
			"pcauto_series_name": "传祺GS4",
			"id": "22611313",
			"pcauto_series_id": "11980",
			"title": "年轻人喜欢的车 传祺GS4对比荣威RX5 PLUS",
			"pcauto_content_category2": "对比导购",
			"pcauto_content_category1": "导购",
			"categorySec": "对比导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-20",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "潘现阳",
			"pcauto_publish_time": 1603123839000,
			"pcauto_author_name": "panxianyang",
			"mtime": 1603123839000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/19/g_22611313_1603111413126_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2261/22611313.html",
			"tag_2": "原创 潘现阳",
			"firstImg": "",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 11980,
				"serialName": "传祺GS4"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "lijiaming1",
			"count": 0,
			"editorInChargeId": "lijiaming1",
			"categoryFirst": "导购",
			"pcauto_series_name": "冒险家",
			"id": "8084667",
			"pcauto_series_id": "25099",
			"title": "美德间的较量 林肯冒险家对大众比途观L",
			"pcauto_content_category2": "对比导购",
			"pcauto_content_category1": "导购",
			"categorySec": "对比导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-20",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "黎嘉铭",
			"pcauto_publish_time": 1603123830000,
			"pcauto_author_name": "lijiaming1",
			"mtime": 1603123830000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/16/g_8084667_1602839413882_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/808/8084667.html",
			"tag_2": "原创 黎嘉铭",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/1604/26/8084667_1.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 25099,
				"serialName": "冒险家"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "liaoweikai",
			"count": 49,
			"editorInChargeId": "liaoweikai",
			"categoryFirst": "导购",
			"pcauto_series_name": "威兰达",
			"id": "22567013",
			"pcauto_series_id": "25490",
			"title": "四款销量王牌的紧凑型SUV 买哪台的低配版最划算?",
			"pcauto_content_category2": "海选导购",
			"pcauto_content_category1": "导购",
			"categorySec": "海选导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-17",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "廖炜凯",
			"pcauto_publish_time": 1602894275000,
			"pcauto_author_name": "liaoweikai",
			"mtime": 1602894275000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/17/g_22567013_1602889566722_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2256/22567013.html",
			"tag_2": "原创 廖炜凯",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/17/22567013_000.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 25490,
				"serialName": "威兰达"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "limingkai",
			"count": 153,
			"editorInChargeId": "limingkai",
			"categoryFirst": "导购",
			"pcauto_series_name": "坦克300",
			"id": "22561681",
			"pcauto_series_id": "26541",
			"title": "新老硬派对决 WEY坦克300对比北京BJ40",
			"pcauto_content_category2": "对比导购",
			"pcauto_content_category1": "导购",
			"categorySec": "对比导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-16",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "李明凯",
			"pcauto_publish_time": 1602845947000,
			"pcauto_author_name": "limingkai",
			"mtime": 1602845947000,
			"image": "http://img0.pcauto.com.cn/pcauto/2010/15/g_22561681_1602731873777_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2256/22561681.html",
			"tag_2": "原创 李明凯",
			"firstImg": "http://img.pcauto.com.cn/images/upload/upc/tx/auto5/2010/16/c0/235470294_1602781260797_800x600.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26541,
				"serialName": "坦克300"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "xiongruifeng",
			"count": 30,
			"editorInChargeId": "xiongruifeng",
			"categoryFirst": "导购",
			"pcauto_series_name": "高尔夫",
			"id": "22531371",
			"pcauto_series_id": "4437",
			"title": "顶配太贵?全面解析新一代大众高尔夫中配版",
			"pcauto_content_category2": "实拍解析",
			"pcauto_content_category1": "导购",
			"categorySec": "实拍解析",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-16",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "熊睿锋",
			"pcauto_publish_time": 1602828588000,
			"pcauto_author_name": "xiongruifeng",
			"mtime": 1602828588000,
			"image": "http://img0.pcauto.com.cn/pcauto/2010/16/g_22531371_1602827893295_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2253/22531371.html",
			"tag_2": "原创 熊睿锋",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/15/22531371_1.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 4437,
				"serialName": "高尔夫"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "zhengpengzhan",
			"count": 0,
			"editorInChargeId": "zhengpengzhan",
			"categoryFirst": "",
			"pcauto_series_name": "MINI JCW COUNTRYMAN",
			"id": "22351935",
			"pcauto_series_id": "12684",
			"title": "3色4驱5秒破百 实拍2021款MINI JCW COUNTRYMAN",
			"categorySec": "",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-16",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "郑鹏展",
			"pcauto_author_name": "zhengpengzhan",
			"pcauto_publish_time": 1602778271000,
			"mtime": 1602778271000,
			"image": "http://img0.pcauto.com.cn/pcauto/2010/04/g_22351935_1601794028775_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2235/22351935.html",
			"tag_2": "原创 郑鹏展",
			"firstImg": "http://img.pcauto.com.cn/images/upload/upc/tx/auto5/2010/04/c1/233833602_1601793917852_800x600.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 12684,
				"serialName": "MINI JCW COUNTRYMAN"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "zhangyan6",
			"count": 30,
			"editorInChargeId": "zhangyan6",
			"categoryFirst": "导购",
			"pcauto_series_name": "宝来",
			"id": "22566155",
			"pcauto_series_id": "3286",
			"title": "德味深入人心 不同网站编辑眼中的宝来",
			"pcauto_content_category2": "单车导购",
			"pcauto_content_category1": "导购",
			"categorySec": "单车导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-16",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "张岩",
			"pcauto_publish_time": 1602777613000,
			"pcauto_author_name": "zhangyan6",
			"mtime": 1602777613000,
			"image": "http://img0.pcauto.com.cn/pcauto/2010/15/g_22566155_1602773174933_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2256/22566155.html",
			"tag_2": "原创 张岩",
			"firstImg": "http://img.pcauto.com.cn/images/upload/upc/tx/auto5/2010/15/c24/235459479_1602773327582_800x600.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 3286,
				"serialName": "宝来"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "lizhe",
			"count": 60,
			"editorInChargeId": "lizhe",
			"categoryFirst": "导购",
			"pcauto_series_name": "LIFE",
			"id": "22566512",
			"pcauto_series_id": "26573",
			"title": "配置比飞度还厚道?静态体验东风本田LIFE",
			"pcauto_content_category2": "实拍解析",
			"pcauto_content_category1": "导购",
			"categorySec": "实拍解析",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-15",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "李喆",
			"pcauto_publish_time": 1602777435000,
			"pcauto_author_name": "lizhe",
			"mtime": 1602777435000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/15/g_22566512_1602776106674_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2256/22566512.html",
			"tag_2": "原创 李喆",
			"firstImg": "http://img.pcauto.com.cn/images/upload/upc/tx/auto5/2010/15/c24/235465623_1602776978772_800x600.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26573,
				"serialName": "LIFE"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "panhonghan",
			"count": 80,
			"editorInChargeId": "panhonghan",
			"categoryFirst": "导购",
			"pcauto_series_name": "哈弗H6",
			"id": "21806972",
			"pcauto_series_id": "4580",
			"title": "王牌对王牌 第三代哈弗H6对比本田CR-V",
			"pcauto_content_category2": "对比导购",
			"pcauto_content_category1": "导购",
			"categorySec": "对比导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-15",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "潘洪瀚",
			"pcauto_publish_time": 1602691936000,
			"pcauto_author_name": "panhonghan",
			"mtime": 1602691936000,
			"image": "https://img0.pcauto.com.cn/pcauto/2008/24/g_21806972_1598248995008_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2180/21806972.html",
			"tag_2": "原创 潘洪瀚",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2008/24/21806972_1.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 4580,
				"serialName": "哈弗H6"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "maxin1",
			"count": 1,
			"editorInChargeId": "maxin1",
			"categoryFirst": "新车",
			"pcauto_series_name": "途锐",
			"id": "22353334",
			"pcauto_series_id": "2383",
			"title": "颜值与性能兼备 大众途锐竞争力分析",
			"pcauto_content_category2": "新车解析",
			"pcauto_content_category1": "新车",
			"categorySec": "新车解析",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-15",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "马鑫-编辑",
			"pcauto_publish_time": 1602691936000,
			"pcauto_author_name": "maxin1",
			"mtime": 1602691936000,
			"image": "https://img0.pcauto.com.cn/pcauto/2009/30/g_22353334_1601436341295_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2235/22353334.html",
			"tag_2": "原创 马鑫",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2009/30/22353334_image007_thumb.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 2383,
				"serialName": "途锐"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "wangyue2",
			"count": 8,
			"editorInChargeId": "wangyue2",
			"categoryFirst": "导购",
			"pcauto_series_name": "上汽大通MAXUS V80",
			"id": "22531432",
			"pcauto_series_id": "7590",
			"title": "整体更贴近城市 实拍上汽大通V80 PLUS",
			"pcauto_content_category2": "实拍解析",
			"pcauto_content_category1": "导购",
			"categorySec": "实拍解析",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-14",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "王岳1",
			"pcauto_publish_time": 1602619528000,
			"pcauto_author_name": "wangyue2",
			"mtime": 1602619528000,
			"image": "http://img0.pcauto.com.cn/pcauto/2010/14/g_22531432_1602617751007_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2253/22531432.html",
			"tag_2": "原创 王岳",
			"firstImg": "http://img.pcauto.com.cn/images/upload/upc/tx/auto5/2010/14/c0/235190258_1602617914272_800x600.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 7590,
				"serialName": "上汽大通MAXUS V80"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "lijiaming1",
			"count": 28,
			"editorInChargeId": "lijiaming1",
			"categoryFirst": "导购",
			"pcauto_series_name": "五菱凯捷",
			"id": "22504173",
			"pcauto_series_id": "26411",
			"title": "12万的五菱能给您什么?了解完这5个亮点再下订",
			"pcauto_content_category2": "到店实拍",
			"pcauto_content_category1": "导购",
			"categorySec": "到店实拍",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-14",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "黎嘉铭",
			"pcauto_publish_time": 1602605433000,
			"pcauto_author_name": "lijiaming1",
			"mtime": 1602605433000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/12/g_22504173_1602515241486_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2250/22504173.html",
			"tag_2": "原创 黎嘉铭",
			"firstImg": "http://img.pcauto.com.cn/images/upload/upc/tx/auto5/2009/23/c10/232113290_1600841538753_800x600.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26411,
				"serialName": "五菱凯捷"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "hezhanpeng",
			"count": 47,
			"editorInChargeId": "hezhanpeng",
			"categoryFirst": "导购",
			"pcauto_series_name": "哈弗大狗",
			"id": "22529791",
			"pcauto_series_id": "26431",
			"title": "哈弗大狗哪款性价比最高?首推边牧版",
			"pcauto_content_category2": "单车导购",
			"pcauto_content_category1": "导购",
			"categorySec": "单车导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-13",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "何展鹏",
			"pcauto_publish_time": 1602587344000,
			"pcauto_author_name": "hezhanpeng",
			"mtime": 1602587344000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/13/g_22529791_1602585162981_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2252/22529791.html",
			"tag_2": "原创 何展鹏",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/13/22529791_1-3.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26431,
				"serialName": "哈弗大狗"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "panyumin",
			"count": 117,
			"editorInChargeId": "panyumin",
			"categoryFirst": "导购",
			"pcauto_series_name": "飞行家",
			"id": "22471811",
			"pcauto_series_id": "26461",
			"title": "谁才是真正的全能猛将?林肯飞行家对比途锐",
			"pcauto_content_category2": "对比导购",
			"pcauto_content_category1": "导购",
			"categorySec": "对比导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-13",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "潘宇民",
			"pcauto_publish_time": 1602551706000,
			"pcauto_author_name": "panyumin",
			"mtime": 1602551706000,
			"image": "http://img0.pcauto.com.cn/pcauto/2010/12/g_22471811_1602497693823_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2247/22471811.html",
			"tag_2": "",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/12/22471811_21_thumb.png",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26461,
				"serialName": "飞行家"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "sukancheng",
			"count": 38,
			"editorInChargeId": "sukancheng",
			"categoryFirst": "导购",
			"pcauto_series_name": "荣威iMAX8",
			"id": "22496691",
			"pcauto_series_id": "26445",
			"title": "不怒自威新实力 到店实拍荣威iMAX8",
			"pcauto_content_category2": "到店实拍",
			"pcauto_content_category1": "导购",
			"categorySec": "到店实拍",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-13",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "苏侃成",
			"pcauto_publish_time": 1602519032000,
			"pcauto_author_name": "sukancheng",
			"mtime": 1602519032000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/12/g_22496691_1602499839154_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2249/22496691.html",
			"tag_2": "原创 苏侃成",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/12/22496691_1.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26445,
				"serialName": "荣威iMAX8"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "huangzengjian",
			"count": 96,
			"editorInChargeId": "huangzengjian",
			"categoryFirst": "导购",
			"pcauto_series_name": "宋PLUS",
			"id": "22470312",
			"pcauto_series_id": "26405",
			"title": "新秀能否撼动老将? 宋PLUS对比长安CS75 PLUS",
			"pcauto_content_category2": "对比导购",
			"pcauto_content_category1": "导购",
			"categorySec": "对比导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-12",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "黄增鉴",
			"pcauto_publish_time": 1602496186000,
			"pcauto_author_name": "huangzengjian",
			"mtime": 1602496186000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/12/g_22470312_1602466102347_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2247/22470312.html",
			"tag_2": "原创 黄增鉴",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/10/22470312_0.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 26405,
				"serialName": "宋PLUS"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "yanggaoyu",
			"count": 23,
			"editorInChargeId": "yanggaoyu",
			"categoryFirst": "导购",
			"pcauto_series_name": "奥迪Q5L",
			"id": "22471651",
			"pcauto_series_id": "23054",
			"title": "优惠达7万元 等等党快来抄底奥迪Q5L",
			"pcauto_content_category2": "到店实拍",
			"pcauto_content_category1": "导购",
			"categorySec": "到店实拍",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-11",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "杨高宇",
			"pcauto_publish_time": 1602424809000,
			"pcauto_author_name": "yanggaoyu",
			"mtime": 1602424809000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/10/g_22471651_1602318485638_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2247/22471651.html",
			"tag_2": "原创 杨高宇",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/10/22471651_204729121_1587723231141.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 23054,
				"serialName": "奥迪Q5L"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "zhaoxinjie",
			"count": 24,
			"editorInChargeId": "zhaoxinjie",
			"categoryFirst": "导购",
			"pcauto_series_name": "探界者",
			"id": "22413731",
			"pcauto_series_id": "21013",
			"title": "推荐550T RS智能拓界版 新款探界者购车手册",
			"pcauto_content_category2": "单车导购",
			"pcauto_content_category1": "导购",
			"categorySec": "单车导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-11",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "赵信杰",
			"pcauto_publish_time": 1602380248000,
			"pcauto_author_name": "zhaoxinjie",
			"mtime": 1602380248000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/10/g_22413731_1602293382399_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2241/22413731.html",
			"tag_2": "原创 赵信杰",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/08/22413731_11.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 21013,
				"serialName": "探界者"
			},
			"articleType": "n"
		},
		{
			"pcauto_author_Id": "xuzhihang",
			"count": 8,
			"editorInChargeId": "xuzhihang",
			"categoryFirst": "导购",
			"pcauto_series_name": "宝马5系",
			"id": "22473811",
			"pcauto_series_id": "441",
			"title": "低配两款就够了 新宝马5系购车手册",
			"pcauto_content_category2": "单车导购",
			"pcauto_content_category1": "导购",
			"categorySec": "单车导购",
			"pcauto_content_type": "文章",
			"pubDate": "2020-10-11",
			"pcauto_content_source": "原创",
			"channelName": "导购",
			"editorInChargeName": "",
			"pcauto_publish_time": 1602360643000,
			"pcauto_author_name": "xuzhihang",
			"mtime": 1602360643000,
			"image": "https://img0.pcauto.com.cn/pcauto/2010/11/g_22473811_1602348695661_240x160.jpg",
			"url": "http://www.pcauto.com.cn/teach/2247/22473811.html",
			"tag_2": "原创 徐志杭",
			"firstImg": "http://img0.pcauto.com.cn/pcauto/2010/11/22473811_5.jpg",
			"downs": 0,
			"ups": 0,
			"serial": {
				"serialId": 441,
				"serialName": "宝马5系"
			},
			"articleType": "n"
		}
	]
}

 

下载方式:https://pan.quark.cn/s/a4b39357ea24 布线问题(分支限界算法)是计算机科学和电子工程领域中一个广为人知的议题,它主要探讨如何在印刷电路板上定位两个节点间最短的连接路径。 在这一议题中,电路板被构建为一个包含 n×m 个方格的矩阵,每个方格能够被界定为可通行或不可通行,其核心任务是定位从初始点到最终点的最短路径。 分支限界算法是处理布线问题的一种常用策略。 该算法与回溯法有相似之处,但存在差异,分支限界法仅需获取满足约束条件的一个最优路径,并按照广度优先或最小成本优先的原则来探索解空间树。 树 T 被构建为子集树或排列树,在探索过程中,每个节点仅被赋予一次成为扩展节点的机会,且会一次性生成其全部子节点。 针对布线问题的解决,队列式分支限界法可以被采用。 从起始位置 a 出发,将其设定为首个扩展节点,并将与该扩展节点相邻且可通行的方格加入至活跃节点队列中,将这些方格标记为 1,即从起始方格 a 到这些方格的距离为 1。 随后,从活跃节点队列中提取队首节点作为下一个扩展节点,并将与当前扩展节点相邻且未标记的方格标记为 2,随后将这些方格存入活跃节点队列。 这一过程将持续进行,直至算法探测到目标方格 b 或活跃节点队列为空。 在实现上述算法时,必须定义一个类 Position 来表征电路板上方格的位置,其成员 row 和 col 分别指示方格所在的行和列。 在方格位置上,布线能够沿右、下、左、上四个方向展开。 这四个方向的移动分别被记为 0、1、2、3。 下述表格中,offset[i].row 和 offset[i].col(i=0,1,2,3)分别提供了沿这四个方向前进 1 步相对于当前方格的相对位移。 在 Java 编程语言中,可以使用二维数组...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值