package com.sysu.admin.controller.crop;

import com.sysu.admin.MarkApplication;
import com.sysu.admin.api.base.BaseTest;
import com.sysu.admin.controller.city.District;
import com.sysu.admin.controller.city.DistrictRepository;
import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.transaction.Transactional;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MarkApplication.class)
public class CropLandControllerTest extends BaseTest {
    @Autowired
    CropLandController cropLandController;
    @Autowired
    CropLandService cityLandService;
    @Autowired
    DistrictRepository districtRepository;
    @Test
    @Transactional
    public void saveTest(){
        QCropLand qCropLand = QCropLand.cropLand;
        List<CropLand>  landList = cityLandService.findAll(qCropLand.centerPoint.isNull());
        System.out.println("landList load finnish");
        int size = landList.size();
        for(CropLand bean : landList){
            bean.getCenterPoint().setSRID(4326);
            District district = districtRepository.findByPoint(bean.getCenterPoint());
            if(district != null){
                cityLandService.setCity(bean, district);
                System.out.println("剩余:" + (--size));
            }
        }
        cityLandService.saveAll(landList);
    }
}