package org.jeecg.modules.zrzyqc.dkjz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.zrzyqc.gzvhb.entity.QcSsgqzysytdqkGzv;
import org.jeecg.modules.zrzyqc.gzvhb.model.ResultCount;
import org.jeecg.modules.zrzyqc.gzvhb.service.IQcSsgqzysytdqkGzvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: qc_ssgqzysytdqk_gzv
 * @Author: jeecg-boot
 * @Date: 2024-11-22
 * @Version: V1.0
 */
@Api(tags = "qc_ssgqzysytdqk_gzv")
@RestController
@RequestMapping("/com/qcSsgqzysytdqkGzv")
@Slf4j
public class DkjzController extends JeecgController<QcSsgqzysytdqkGzv, IQcSsgqzysytdqkGzvService> {
    @Autowired
    private IQcSsgqzysytdqkGzvService qcSsgqzysytdqkGzvService;

    /**
     * 分页列表查询
     *
     * @param qcSsgqzysytdqkGzv
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "qc_ssgqzysytdqk_gzv-分页列表查询")
    @ApiOperation(value = "qc_ssgqzysytdqk_gzv-分页列表查询", notes = "qc_ssgqzysytdqk_gzv-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<QcSsgqzysytdqkGzv>> queryPageList(QcSsgqzysytdqkGzv qcSsgqzysytdqkGzv,
                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                          HttpServletRequest req) {
        if (qcSsgqzysytdqkGzv.getXzqh() != null) {
            if (qcSsgqzysytdqkGzv.getXzqh().equals("370000*")) {
                qcSsgqzysytdqkGzv.setXzqh("37*");
            }
        }
        QueryWrapper<QcSsgqzysytdqkGzv> queryWrapper = QueryGenerator.initQueryWrapper(qcSsgqzysytdqkGzv, req.getParameterMap());
        if (qcSsgqzysytdqkGzv.getCreateBy() != null) {
            queryWrapper.like("create_by", qcSsgqzysytdqkGzv.getCreateBy());
        }
        getQueryWrapper(qcSsgqzysytdqkGzv, queryWrapper);
        Page<QcSsgqzysytdqkGzv> page = new Page<QcSsgqzysytdqkGzv>(pageNo, pageSize);
        IPage<QcSsgqzysytdqkGzv> pageList = qcSsgqzysytdqkGzvService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "查询地块数量和面积", notes = "查询地块数量和面积")
    @GetMapping(value = "/listQueryMoney")
    public Result<ResultCount> queryPageListByglyyCount(QcSsgqzysytdqkGzv qcSsgqzysytdqkGzv, HttpServletRequest req) {
        if (qcSsgqzysytdqkGzv.getXzqh() != null) {
            if (qcSsgqzysytdqkGzv.getXzqh().equals("370000*")) {
                qcSsgqzysytdqkGzv.setXzqh("37*");
            }
        }
        QueryWrapper<QcSsgqzysytdqkGzv> queryWrapper = QueryGenerator.initQueryWrapper(qcSsgqzysytdqkGzv, req.getParameterMap());
        if (qcSsgqzysytdqkGzv.getCreateBy() != null) {
            queryWrapper.like("create_by", qcSsgqzysytdqkGzv.getCreateBy());
        }
        getQueryWrapper(qcSsgqzysytdqkGzv, queryWrapper);
        ResultCount resultCount = qcSsgqzysytdqkGzvService.queryResultCountMoney(queryWrapper);
        if (resultCount == null) {
            resultCount = new ResultCount();
            resultCount.setAreaDk(0.0);
            resultCount.setCountDk(0);
        }
        return Result.OK(resultCount);
    }

    /**
     * 统一解析参数
     *
     * @param qcSsgqzysytdqkGzv
     * @param queryWrapper
     */
    public void getQueryWrapper(QcSsgqzysytdqkGzv qcSsgqzysytdqkGzv, QueryWrapper<QcSsgqzysytdqkGzv> queryWrapper) {
//        if (qcSsgqzysytdqkGzv.getXzqh().equals("370000")){
//            queryWrapper.likeRight("xzqh","37");
//        }
    }
}
