package com.siwei.rsmonitoring.controller;

import java.util.List;
import java.util.Set;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.common.core.constant.HttpStatus;
import com.siwei.common.core.utils.StringUtils;
import com.siwei.rsmonitoring.domain.vo.DataCountVo;
import com.siwei.rsmonitoring.service.ITDkjbxxYwypService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.siwei.rsmonitoring.domain.TDkjbxx;
import com.siwei.rsmonitoring.service.ITDkjbxxService;
import com.siwei.common.core.web.controller.BaseController;
import com.siwei.common.core.web.domain.AjaxResult;
import com.siwei.common.core.web.page.TableDataInfo;

/**
 * 地块基本信息（DKJBXX）Controller
 *
 * @author siwei
 * @date 2025-01-20
 */
@RestController
@RequestMapping("/dkjbxx")
public class TDkjbxxController extends BaseController {
    @Autowired
    private ITDkjbxxService tDkjbxxService;
    @Autowired
    private ITDkjbxxYwypService tDkjbxxYwypService;

    /**
     * 查询地块基本信息（DKJBXX）列表
     */
    //@RequiresPermissions("rsmonitoring:dkjbxx:list")
    @PostMapping("/list")
    public TableDataInfo list(
            @RequestBody TDkjbxx tDkjbxx) {
        Long xzq = null;
        if (StringUtils.isNotEmpty(tDkjbxx.getXzqdm())) {
            xzq = Long.parseLong(tDkjbxx.getXzqdm());
        }
        Set<String> xzqSet = tDkjbxxService.selectXzqdmUserList(xzq);
        tDkjbxx.setXzqdms(xzqSet);
        tDkjbxx.setXzqdm(null);

        // 设置分页参数
        PageHelper.startPage(tDkjbxx.getPageNum(), tDkjbxx.getPageSize());
        // 执行查询
        List<TDkjbxx> list = tDkjbxxService.selectTDkjbxxList(tDkjbxx);
        // 包装分页结果
        PageInfo<TDkjbxx> pageInfo = new PageInfo<>(list);

        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(list);
        rspData.setMsg("查询成功");
        rspData.setTotal(pageInfo.getTotal());
        return rspData;
    }

    /**
     * 获取地块基本信息（DKJBXX）详细信息
     */
    //@RequiresPermissions("rsmonitoring:dkjbxx:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tDkjbxxService.selectTDkjbxxById(id));
    }

    //@RequiresPermissions("rsmonitoring:dkjbxx:query")
    @GetMapping(value = "/ywyp/{id}")
    public AjaxResult getYwypInfo(@PathVariable("id") String id) {
        return success(tDkjbxxYwypService.selectTDkjbxxYwypById(id));
    }

    /**
     * 核查图斑数据汇总
     */
    @PostMapping("/hctb/count")
    public AjaxResult hctbCount(@RequestBody DataCountVo dataCountVo) {
        Long xzq = null;
        if (StringUtils.isNotEmpty(dataCountVo.getXzqdm())) {
            xzq = Long.parseLong(dataCountVo.getXzqdm());
        }
        Set<String> xzqSet = tDkjbxxService.selectXzqdmUserList(xzq);
        dataCountVo.setXzqdms(xzqSet);
        return success(tDkjbxxService.selectTDkjbxxCctbCount(dataCountVo));
    }
}
