package org.jeecg.modules.bussMapQuery.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.aspect.annotation.AutoLog;
/*import org.jeecg.modules.gdgl.gdxm.entity.GdDkxx;
import org.jeecg.modules.gdgl.gdxm.entity.GdXm;
import org.jeecg.modules.gdgl.gdxm.service.IGdDkxxService;
import org.jeecg.modules.gdgl.gdxm.service.IGdXmService;
import org.jeecg.modules.zdgl.xmjbxx.entity.ZdDkxxb;
import org.jeecg.modules.zdgl.xmjbxx.entity.ZdXmjbxx;
import org.jeecg.modules.zdgl.xmjbxx.service.IZdDkxxbService;
import org.jeecg.modules.zdgl.xmjbxx.service.IZdXmjbxxService;*/
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/bussMapQueryController")
@Slf4j
public class BussMapQueryConrtroller {

    /*本模块取消，业务查询根据通用配置进行sql查询，不在跟业务关联*/

   /* @Autowired
    private IZdXmjbxxService zdXmjbxxService;
    @Autowired
    private IZdDkxxbService zdDkxxbService;
    @Autowired
    private IGdXmService gdXmService;
    @Autowired
    private IGdDkxxService gdDkxxService;
    @Autowired
    private CommonAPI commonAPI;


    @AutoLog(value = "征地信息查询")
    @ApiOperation(value="征地信息查询", notes="征地信息查询")
    @GetMapping(value = "/queryByZdInfo")
    public Result<?> queryByZdInfo(@RequestParam(name = "queryInfo", required = true) String queryInfo,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        List<QueryRecord> queryRecords = new ArrayList<>();

        LambdaQueryWrapper<ZdXmjbxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(ZdXmjbxx::getXmmc, queryInfo);
        List<ZdXmjbxx> zdXmjbxxList = zdXmjbxxService.list(queryWrapper);
        if(zdXmjbxxList.size()>0){
            for(int i=0;i<zdXmjbxxList.size();i++){
                ZdXmjbxx zdXmjbxx = zdXmjbxxList.get(i);
                String xmid = zdXmjbxx.getId();
                String xmmc = zdXmjbxx.getXmmc();
                LambdaQueryWrapper<ZdDkxxb> zdDkxxbQueryWrapper = new LambdaQueryWrapper<>();
                zdDkxxbQueryWrapper.eq(ZdDkxxb::getXmid,xmid);
                List<ZdDkxxb> zdDkxxbList = zdDkxxbService.list(zdDkxxbQueryWrapper);
                if(zdDkxxbList.size()>0){
                    for(int j=0;j<zdDkxxbList.size();j++){
                        ZdDkxxb zdDkxxb = zdDkxxbList.get(j);
                        QueryRecord queryRecord = new QueryRecord();
                        queryRecord.setId(zdDkxxb.getId().toString());
                        queryRecord.setName(xmmc);
                        queryRecord.setLayerName("征地");
                        queryRecord.setOtherInfo(zdDkxxb.getDkmc());
                        queryRecord.setGeoinfo(zdDkxxb.getWkt());
                        queryRecords.add(queryRecord);
                    }
                }
            }
        }

        QueryResult queryResult = new QueryResult();
        queryResult.setRecords(getListpaging(queryRecords,pageNo,pageSize));
        queryResult.setCurrent(pageNo);
        queryResult.setSize(pageSize);
        queryResult.setTotal(queryRecords.size());
        return Result.OK(queryResult);
    }

    @AutoLog(value = "供地信息查询")
    @ApiOperation(value="供地信息查询", notes="供地信息查询")
    @GetMapping(value = "/queryByGdInfo")
    public Result<?> queryByGdInfo(@RequestParam(name = "queryInfo", required = true) String queryInfo,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        List<QueryRecord> queryRecords = new ArrayList<>();

        LambdaQueryWrapper<GdXm> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(GdXm::getXmMc, queryInfo);
        List<GdXm> gdXmList = gdXmService.list(queryWrapper);
        if(gdXmList.size()>0){
            for(int i=0;i<gdXmList.size();i++){
                GdXm gdXm = gdXmList.get(i);
                String xmid = gdXm.getId();
                String xmmc = gdXm.getXmMc();
                LambdaQueryWrapper<GdDkxx> gdDkxxQueryWrapper = new LambdaQueryWrapper<>();
                gdDkxxQueryWrapper.eq(GdDkxx::getXmid,xmid);
                List<GdDkxx> gdDkxxList = gdDkxxService.list(gdDkxxQueryWrapper);
                if(gdDkxxList.size()>0){
                    for(int j=0;j<gdDkxxList.size();j++){
                        GdDkxx gdDkxx = gdDkxxList.get(j);
                        QueryRecord queryRecord = new QueryRecord();
                        queryRecord.setId(gdDkxx.getId().toString());
                        queryRecord.setName(xmmc);
                        queryRecord.setLayerName("供地");
                        queryRecord.setOtherInfo(gdDkxx.getDkmc());
                        queryRecord.setGeoinfo(gdDkxx.getWkt());
                        queryRecords.add(queryRecord);
                    }
                }
            }
        }

        QueryResult queryResult = new QueryResult();
        queryResult.setRecords(getListpaging(queryRecords,pageNo,pageSize));
        queryResult.setCurrent(pageNo);
        queryResult.setSize(pageSize);
        queryResult.setTotal(queryRecords.size());
        return Result.OK(queryResult);
    }

    private static List getListpaging(List list, int pageNo, int pageSize){
        if(list == null || list.size() <= 0){
            return new ArrayList<>(0);
        }
        //开始下标
        int startIndex = (pageNo - 1) * pageSize;
        //结束下标 subList()方法不包含结束下标的元素
        int endIndex = pageNo * pageSize;
        //list总条数
        int total = list.size();
        //总页数
        int pageCount = 0;
        //通过取余决定是否给总页数加1
        int num = total % pageSize;
        if (num == 0) {
            pageCount = total / pageSize;
        } else {
            pageCount = total / pageSize + 1;
        }
        //如果当前页是最后一页的话 要包含集合的最后一条数据，因为sublist方法本身结束的下标是不包含当前元素的
        if (pageNo == pageCount) {
            endIndex = total;
        }
        return list.subList(startIndex, endIndex);
    }*/
}
