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

import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.system.vo.SysDepartModel;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.zrzyqc.gzvhb.entity.QcSsgqzysytdqkGzv;
import org.jeecg.modules.zrzyqc.gzvhb.service.IQcSsgqzysytdqkGzvService;
import org.jeecg.modules.zrzyqc.qyxx.entity.QcQyxx;
import org.jeecg.modules.zrzyqc.qyxx.entity.XzdxVO;
import org.jeecg.modules.zrzyqc.qyxx.service.IQcQyxxService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.zrzyqc.util.ChangeNumber;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

/**
 * @Description: 用地单位信息
 * @Author: jeecg-boot
 * @Date: 2022-07-08
 * @Version: V1.0
 */
@Api(tags = "用地单位信息")
@RestController
@RequestMapping("/qcsb.qyxx/qcQyxx")
@Slf4j
public class QcQyxxController extends JeecgController<QcQyxx, IQcQyxxService> {
    @Autowired
    private IQcQyxxService qcQyxxService;
    @Value("${jeecg.path.upload}")
    private String upLoadPath;
    @Autowired
    private IQcSsgqzysytdqkGzvService qcSsgqzysytdqkGzvService;
    /**
     * 查询添加的年份列表,倒叙
     *
     * @param sugb
     * @return 年份数组
     */
    @AutoLog(value = "查询入库的年份组合")
    @ApiOperation(value = "查询入库的年份组合", notes = "查询入库的年份组合")
    @GetMapping(value = "/queryYears")
    public Result<List<String>> queryYears() {
        List years = qcQyxxService.queryYears();
        return Result.OK(years);
    }

    /**
     * 分页列表查询
     *
     * @param qcQyxx
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用地单位信息-分页列表查询")
    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/list")
    @PermissionData(pageComponent = "qcsb/qyxx/QcQyxxList")
    public Result<IPage<QcQyxx>> queryPageList(QcQyxx qcQyxx,
                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                               HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        queryWrapper.likeRight("org_code", "A04");
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询
     *
     * @param qcQyxx
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用地单位信息-分页列表查询")
    @ApiOperation(value = "机关事业单位用地单位信息-分页列表查询", notes = "机关事业单位用地单位信息-分页列表查询")
    @GetMapping(value = "/list5")
    @PermissionData(pageComponent = "sydwqcsb/sydwxx/QcQyxxList")
    public Result<IPage<QcQyxx>> queryPageList5(QcQyxx qcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        queryWrapper.likeRight("org_code", "A03");
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询
     *
     * @param qcQyxx
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用地单位信息-分页列表查询")
    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/listBygly")
    public Result<IPage<QcQyxx>> queryPageListGly(QcQyxx qcQyxx,
                                                  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                  HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        queryWrapper.likeRight("sys_org_code", "A04");
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        // 生成一级单位名称
        List<QcQyxx> records = pageList.getRecords();
        List<QcQyxx> firstOrgNames = qcSsgqzysytdqkGzvService.getFirstOrgNamesQyxx(records);
        pageList.setRecords(firstOrgNames);
        return Result.OK(pageList);
    }

    /**
     * 分页列表查询
     *
     * @param qcQyxx
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "用地单位信息-分页列表查询")
    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/listByglyy")
    public Result<IPage<QcQyxx>> queryPageListGly2(QcQyxx qcQyxx,
                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                   HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        queryWrapper.likeRight("sys_org_code", "A03");
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/list1")
    public Result<IPage<QcQyxx>> queryPageList1(QcQyxx qcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        List<Integer> sbzts = new ArrayList<>();
        sbzts.add(1);
        sbzts.add(2);
        queryWrapper.in("sfsb", sbzts);
        queryWrapper.likeRight("org_code", "A04");
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/list7")
    public Result<IPage<QcQyxx>> queryPageList7(QcQyxx qcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        List<Integer> sbzts = new ArrayList<>();
        sbzts.add(1);
        sbzts.add(2);
        queryWrapper.in("sfsb", sbzts);
        queryWrapper.likeRight("org_code", "A03");
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/list2")
    public Result<IPage<QcQyxx>> queryPageList2(QcQyxx qcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        List<Integer> sbzts = new ArrayList<>();
        sbzts.add(3);
        sbzts.add(4);
        queryWrapper.in("sfsb", sbzts);
        queryWrapper.likeRight("org_code", "A04");
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "用地单位信息-分页列表查询", notes = "用地单位信息-分页列表查询")
    @GetMapping(value = "/list8")
    public Result<IPage<QcQyxx>> queryPageList8(QcQyxx qcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, req.getParameterMap());
        queryWrapper.likeRight("org_code", "A03");
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        List<Integer> sbzts = new ArrayList<>();
        sbzts.add(3);
        sbzts.add(4);
        queryWrapper.in("sfsb", sbzts);
        queryWrapper.likeRight("org_code", "A03");
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "省属国企占有使用土地情况调查-审核错误退回分页列表查询", notes = "省属国企占有使用土地情况调查-审核错误退回分页列表查询")
    @GetMapping(value = "/list4")
    @PermissionData(pageComponent = "qcsb/qyxx/QcQyxxList4")
    public Result<IPage<QcQyxx>> queryPageList4(QcQyxx QcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(QcQyxx, req.getParameterMap());
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String orgCode = sysUser.getOrgCode();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        for (String s : rolesByUsername) {
            if (s.equals("sbyh")) {
                queryWrapper.eq("sfsb", 4);
            } else {
                queryWrapper.eq("sfsb", 4);
            }
        }
        queryWrapper.likeRight("org_code", "A04");
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @ApiOperation(value = "省属国企占有使用土地情况调查-审核错误退回分页列表查询", notes = "省属国企占有使用土地情况调查-审核错误退回分页列表查询")
    @GetMapping(value = "/list6")
    @PermissionData(pageComponent = "sydwqcsb/sydwxx/QcQyxxList4")
    public Result<IPage<QcQyxx>> queryPageList6(QcQyxx QcQyxx,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(QcQyxx, req.getParameterMap());
        Page<QcQyxx> page = new Page<QcQyxx>(pageNo, pageSize);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String orgCode = sysUser.getOrgCode();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        for (String s : rolesByUsername) {
            if (s.equals("jgsbyh")) {

                queryWrapper.eq("sfsb", 4);
            } else {
                queryWrapper.eq("sfsb", 4);
            }
        }
        queryWrapper.likeRight("org_code", "A03");
        IPage<QcQyxx> pageList = qcQyxxService.page(page, queryWrapper);
        return Result.OK(pageList);
    }


    /**
     * 获取当前用户的密码修改日志
     */
    @GetMapping(value = "/getPWDlog")
    public Result<String> getPWDlog() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        Integer logs = qcQyxxService.getPWDlog(sysUser.getUsername());
        if (logs.intValue() > 0) {
            return Result.OK("已修改");
        } else {
            return Result.OK("未修改");
        }

    }

    /**
     * 添加
     *
     * @param qcQyxx
     * @return
     */
    @AutoLog(value = "用地单位信息-添加")
    @ApiOperation(value = "用地单位信息-添加", notes = "用地单位信息-添加")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody QcQyxx qcQyxx) {
        if (qcQyxx.getQybm() == null) {
            String orgcode = qcQyxx.getOrgCode();
            ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
            SysDepartModel departModel = api.selectAllById(api.getDepartIdsByOrgCode(orgcode));
            if (orgcode.substring(0, 3).equals("A04")) {
                String zgsjbString = "";
                String yjqybm = orgcode.substring(4, 6);
                Integer zgsjb = Integer.parseInt(departModel.getOrgType()) - 1;
                if (zgsjb == 1) {
                    qcQyxx.setQybm(yjqybm);
                } else {
                    if (zgsjb < 10) {
                        zgsjbString = "0" + zgsjb.toString();
                    } else {
                        zgsjbString = zgsjb.toString();
                    }
                    qcQyxx.setQybm(yjqybm + "-" + zgsjbString);
                }
            } else {
                qcQyxx.setQybm("无");
            }
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("qymc", qcQyxx.getQymc());
        QcQyxx qyxx = qcQyxxService.getOne(queryWrapper);
        //判断是否存在企业信息，防止重复保存
        if (qyxx != null) {
            return Result.error("已存在改企业信息！");
        } else {
            qcQyxxService.save(qcQyxx);
            return Result.OK("添加成功！");
        }
    }

    @AutoLog(value = "用地单位信息是否上报")
    @ApiOperation(value = "用地单位信息是否上报", notes = "用地单位信息是否上报")
    @GetMapping(value = "/sfsb")
    public Result<String> sfshz(String id) {
        qcQyxxService.upSfsb(id);
        return Result.OK("提交成功!");
    }

    @AutoLog(value = "用地单位信息是否审核")
    @ApiOperation(value = "用地单位信息是否审核", notes = "用地单位信息是否审核")
    @GetMapping(value = "/sfsh")
    public Result<String> sfsh(String id) {
        QcQyxx qk = new QcQyxx();
        qk = qcQyxxService.getById(id);
        if (qk.getSfsb() == 1) {
            qk.setSfsb(2);
            qcQyxxService.saveOrUpdate(qk);
        }
        return Result.OK("审核中!");
    }

    @AutoLog(value = "用地单位信息是否审核")
    @ApiOperation(value = "用地单位信息是否审核", notes = "用地单位信息是否审核")
    @PostMapping(value = "/selectById")
    public Result<?> selectById(String id) {

        QcQyxx qcQyxx = qcQyxxService.getById(id);

        return Result.OK(qcQyxx);
    }

    @AutoLog(value = "用地单位信息是否可以撤回")
    @ApiOperation(value = "用地单位信息是否可以撤回", notes = "用地单位信息是否可以撤回")
    @GetMapping(value = "/sfch")
    public Result<String> sfch(String id) {
        QcQyxx qc = new QcQyxx();
        qc = qcQyxxService.getById(id);
        if (qc.getSfsb() == 1) {
            qc.setSfsb(0);
            qcQyxxService.saveOrUpdate(qc);
            return Result.OK("撤回成功!");
        }
        return Result.error("无法撤回！");

    }

    @AutoLog(value = "用地单位信息审核结果")
    @ApiOperation(value = "用地单位信息审核结果", notes = "用地单位信息审核结果")
    @GetMapping(value = "/wcsh")
    public Result<String> wcsh(String id) {
        QcQyxx qc = new QcQyxx();
        qc = qcQyxxService.getById(id);
        if (qc.getShzt() != null) {
            if (qc.getShzt().equals("通过")) {
                qc.setSfsb(3);
                String sjdwdm = qc.getSjdwdm();
                System.out.println(sjdwdm);
                String org_code = qc.getSysOrgCode();
                if (org_code.length() > 6) {
                    qcQyxxService.updatePid(sjdwdm, org_code);
                }
            } else if (qc.getShzt().equals("不通过")) {
                qc.setSfsb(4);
            }
            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            String username = sysUser.getUsername();
            qc.setShren(username);
            Date date = new Date();
            qc.setShrq(date);
            qcQyxxService.saveOrUpdate(qc);
            return Result.OK("完成审核!");
        } else {
            return Result.error("请先进行审核！");
        }

    }

    @AutoLog(value = "用地单位信息审核结果")
    @ApiOperation(value = "用地单位信息审核结果", notes = "用地单位信息审核结果")
    @GetMapping(value = "/hfysh")
    public Result<String> hfysh(String id) {
        QcQyxx qc = new QcQyxx();
        qc = qcQyxxService.getById(id);
        qc.setSfsb(3);
        qc.setShzt("通过");

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String username = sysUser.getUsername();
        qc.setShren(username);
        Date date = new Date();
        qc.setShsj(date);
        qcQyxxService.saveOrUpdate(qc);
        return Result.OK("恢复为已审核!");

    }

    @AutoLog(value = "用地单位信息重新上报")
    @ApiOperation(value = "用地单位信息重新上报", notes = "用地单位信息重新上报")
    @GetMapping(value = "/cxsb")
    public Result<String> cxsb(String id) {
        QcQyxx qk = new QcQyxx();
        qk = qcQyxxService.getById(id);
        if (qk.getSfsb() == 4) {
            qk.setSfsb(0);
            qcQyxxService.saveOrUpdate(qk);
        }
        return Result.OK("审核中!");
    }

    /**
     * 编辑
     *
     * @param qcQyxx
     * @return
     */
    @AutoLog(value = "用地单位信息-编辑")
    @ApiOperation(value = "用地单位信息-编辑", notes = "用地单位信息-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody QcQyxx qcQyxx) {
        qcQyxxService.updateById(qcQyxx);
        if (qcQyxx.getSfsb() == 1) {
            this.sfsh(qcQyxx.getId());
        }
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "用地单位信息-通过id删除")
    @ApiOperation(value = "用地单位信息-通过id删除", notes = "用地单位信息-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        qcQyxxService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "用地单位信息-批量删除")
    @ApiOperation(value = "用地单位信息-批量删除", notes = "用地单位信息-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.qcQyxxService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "用地单位信息-通过id查询")
    @ApiOperation(value = "用地单位信息-通过id查询", notes = "用地单位信息-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<QcQyxx> queryById(@RequestParam(name = "id", required = true) String id) {
        QcQyxx qcQyxx = qcQyxxService.getById(id);
        if (qcQyxx == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(qcQyxx);
    }

    /**
     * @return
     */
    //@AutoLog(value = "用地单位信息-通过id查询")
    @ApiOperation(value = "用地单位信息-通过id查询", notes = "用地单位信息-通过id查询")
    @GetMapping(value = "/getNumber")
    public Result<?> getNumber() {
        ArrayList<Long> list = new ArrayList<>();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<QcQyxx> queryWrapper = new LambdaQueryWrapper();
        LambdaQueryWrapper<QcSsgqzysytdqkGzv> queryWrapper1 = new LambdaQueryWrapper();
        queryWrapper.eq(QcQyxx::getSysOrgCode, sysUser.getOrgCode());
        queryWrapper.eq(QcQyxx::getSfsb, 4);
        queryWrapper1.eq(QcSsgqzysytdqkGzv::getSysOrgCode, sysUser.getOrgCode());
        queryWrapper1.eq(QcSsgqzysytdqkGzv::getSfsb, 4);
        long count = qcQyxxService.count(queryWrapper);
        long count1 = qcSsgqzysytdqkGzvService.count(queryWrapper1);
        list.add(count);//退回单位信息
        list.add(count1);//退回地块信息

        return Result.OK(list);
    }

    /**
     * 查询用地单位是否已填报
     *
     * @param
     * @return
     */
    //@AutoLog(value = "用地单位信息-通过id查询")
    @ApiOperation(value = "查询用地单位是否已填报", notes = "查询用地单位是否已填报")
    @GetMapping(value = "/queryByUsername")
    public Result<QcQyxx> queryByUsername() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<QcQyxx> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(QcQyxx::getSysOrgCode, sysUser.getOrgCode());
        QcQyxx one = qcQyxxService.getOne(queryWrapper);
        return Result.OK(one);
    }

    /**
     * 返回登录企业基本信息
     *
     * @param
     * @return
     */
    //@AutoLog(value = "用地单位信息-通过id查询")
    @ApiOperation(value = "用地单位信息-通过id查询", notes = "用地单位信息-通过id查询")
    @GetMapping(value = "/queryQyjbxx")
    public Result<QcQyxx> queryQyjbxx() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String orgcode = sysUser.getOrgCode();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        SysDepartModel departModel = api.selectAllById(api.getDepartIdsByOrgCode(orgcode));
        QcQyxx qcQyxx = new QcQyxx();
        qcQyxx.setOrgType(departModel.getOrgType());
        qcQyxx.setOrgCode(orgcode);
        qcQyxx.setQymc(departModel.getDepartName());
        return Result.OK(qcQyxx);
    }

    /**
     * 首页数据-下发任务数、有效登录数、上报地块数
     *
     * @return
     */
    @ApiOperation(value = "省属企业:首页数据-下发任务数、有效登录数", notes = "首页数据-下发任务数、有效登录数")
    @GetMapping(value = "/rwdls")
    public Result<List> rwdls() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        ArrayList list = new ArrayList();
        String username = sysUser.getUsername();
        String orgCode = sysUser.getOrgCode();
        String selectqyxx = qcQyxxService.selectqyxx(); //下发任务数
        String yxdls = qcQyxxService.yxdls();
        String sbdks = null;
        String yhjs = null;
        String sbdkmj = null;      //上报地块面积
        XzdxVO xzdx=new XzdxVO();  //闲置低效
        for (String s : rolesByUsername) {
            if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                yhjs = "shyh";
                sbdks = qcQyxxService.sbdksAdmin();
                sbdkmj = qcQyxxService.sbdksMjAdmin();
                xzdx=qcQyxxService.getXzdx("");
                break;
            } else {
                yhjs = "sbyh";
                sbdks = qcQyxxService.sbdks(username);
                sbdkmj = qcQyxxService.sbdksMj(username);
                xzdx=qcQyxxService.getXzdx(username);
            }
        }
        //企业数量、上报地块企业数、地块数量、地块面积、闲置地块数、闲置地块面积
        list.add(selectqyxx);  //下发任务数
        list.add(yxdls);       //有效登录数
        list.add(sbdks);       //上报地块数
        list.add(yhjs);        //用戶角色
        list.add(ChangeNumber.ChangeString(sbdkmj));   //上报地块面积
        list.add(xzdx.getXzdxNum());
        list.add(xzdx.getXzdxArea());
        String message="下发任务数,有效登录数,上报地块数,用戶角色,省属上报面积,闲置地块数、闲置地块面积";
        return Result.OK(message,list);
    }

    /**
     * 首页数据-事业单位下发任务数、有效登录数、上报地块数
     *
     * @return
     */

    @ApiOperation(value = "省直单位:首页数据-下发任务数、有效登录数", notes = "首页数据-下发任务数、有效登录数")
    @GetMapping(value = "/sydw")
    public Result<List> sydw() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        ArrayList list = new ArrayList();
        String selectqyxx = qcQyxxService.selectdwxx();
        String yxdls = qcQyxxService.sydwyxdls();
        String sbdks = null;
        String yhjs = null;
        String wsh = null;
        String szsbMj = null;
        String szwshMj = null;
        XzdxVO xzdx=new XzdxVO();  //闲置低效
        for (String s : rolesByUsername) {
            if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                yhjs = "shyh";
                sbdks = qcQyxxService.sydwsbdksAdmin();
                //wsh = qcQyxxService.sydwwshAdmin();
                szsbMj = qcQyxxService.sydwwshAdminMj();
                //szwshMj = qcQyxxService.sydwwshAdminWshMj();
                xzdx=qcQyxxService.getXzdxSz();
                break;
            }
        }
        //企业数量、上报地块企业数、地块数量、地块面积、闲置地块数、闲置地块面积
        list.add(selectqyxx);//下发任务数
        list.add(yxdls);//有效登录数
        list.add(sbdks);//上报地块数
        //list.add(wsh);//未审核
        list.add(yhjs);//用戶角色
        list.add(ChangeNumber.ChangeString(szsbMj));//省直上报面积
        //list.add(ChangeNumber.ChangeString(szwshMj));//省直未审核面积
        list.add(xzdx.getXzdxNum());
        list.add(xzdx.getXzdxArea());
        String message="下发任务数,有效登录数,上报地块数,用戶角色,省直上报面积,闲置地块数、闲置地块面积";
        return Result.OK(message,list);
    }

    /**
     * 首页-审核状态
     *
     * @return
     */
    //@AutoLog(value = "首页-审核状态")
    @ApiOperation(value = "首页-审核状态", notes = "首页-审核状态")
    @GetMapping(value = "/shzt")
    public Result<List> shzt() {
        ArrayList list = new ArrayList();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        String username = sysUser.getUsername();
        String tgsh = null;
        String wsh = null;
        String btgsh = null;
        String shz = null;
        for (String s : rolesByUsername) {
            if (s.equals("sbyh") || s.equals("jgsbyh")) {
                tgsh = qcQyxxService.tgsh(username);
                btgsh = qcQyxxService.btgsh(username);
                wsh = qcQyxxService.wsh(username);
                shz = qcQyxxService.shzsl(username);
            } else if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                tgsh = qcQyxxService.tgshAdmin();
                btgsh = qcQyxxService.btgshAdmin();
                wsh = qcQyxxService.wshAdmin();
                shz = qcQyxxService.shzslAdmin();
                break;
            }
        }
        list.add(tgsh);
        list.add(btgsh);
        list.add(wsh);
        list.add(shz);
        return Result.OK(list);
    }

    /**
     * 首页-事业单位饼图
     *
     * @return
     */
    //@AutoLog(value = "首页-审核状态")
    @ApiOperation(value = "首页-审核状态", notes = "首页-审核状态")
    @GetMapping(value = "/sydwshzt")
    public Result<List> sydwshzt() {
        ArrayList list = new ArrayList();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        String username = sysUser.getUsername();
        String tgsh = null;
        String wsh = null;
        String btgsh = null;
        String shz = null;
        for (String s : rolesByUsername) {
            if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                tgsh = qcQyxxService.sydwtgshAdmin();
                btgsh = qcQyxxService.sydwbtgshAdmin();
                wsh = qcQyxxService.sydwwshAdmin();
                shz = qcQyxxService.sydwshzslAdmin();
                break;
            }
        }
        list.add(tgsh);
        list.add(btgsh);
        list.add(wsh);
        list.add(shz);
        return Result.OK(list);
    }

    /**
     * 判断登陆人
     *
     * @return
     */
    //@AutoLog(value = "判断登陆人")
    @ApiOperation(value = "判断登陆人", notes = "判断登陆人")
    @GetMapping(value = "/dlr")
    public Result<?> dlr() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        String dlr = null;
        for (String s : rolesByUsername) {
            if (s.equals("gzw")) {
                dlr = "gzw";
                break;
            } else if ((s.equals("shyh") || s.equals("xfzx") || s.equals("sjzh"))) {
                dlr = "shyh";
                break;
            } else {
                dlr = "sbyh";
            }
        }
        return Result.OK(dlr);
    }

    /**
     * 首页-当前上报数
     *
     * @return
     */
    //@AutoLog(value = "首页-当前上报数")
    @ApiOperation(value = "首页-审核通过,退回数", notes = "首页-审核通过，退回数")
    @GetMapping(value = "/dqsbs")
    public Result<List> dqsbs() {
        ArrayList list = new ArrayList();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        String username = sysUser.getUsername();
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        String tgsh = qcQyxxService.tgsh(username);
        String cwth = qcQyxxService.cwth(username);
        String yhjs = null;
        String shmj = qcQyxxService.shmj(username);
        String shmj_not = qcQyxxService.shmj_not(username);
        for (String s : rolesByUsername) {
            if (s.equals("sbyh")) {
                yhjs = "sbyh";
            } else if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                yhjs = "shyh";
                break;
            }
        }
        if (shmj == null) {
            shmj = "0";
        }
        if (shmj_not == null) {
            shmj_not = "0";
        }
        list.add(tgsh);
        list.add(cwth);
        list.add(yhjs);
        list.add(shmj);  //审核通过
        list.add(shmj_not); //审核不通过
        return Result.OK(list);
    }

    /**
     * 首页-未审核数量
     *  0-未上报
     *  1-已上报待审核
     *  2-审核中
     *  3-已审核
     *  4-错误退回
     */
    //@AutoLog(value = "首页-未审核数量")
    @ApiOperation(value = "首页-省属未审核数量", notes = "首页-省属未审核数量")
    @GetMapping(value = "/wshsl")
    public Result<String> wshsl() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        String username = sysUser.getUsername();
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        String wshsl = "";
        String wshslMJ = "";
        for (String s : rolesByUsername) {
            // shyh->审核用户 gzv->国资委  xfzx->修复中心 sjzh->省级账户
            if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                //返回省属
                wshsl = qcQyxxService.wshslAdmin();
                wshslMJ = qcQyxxService.wshslAdminMJ();
                break;
                //sbyh ->企业上报用户  jgsbyh->机关上报用户
            } else if (s.equals("sbyh") || s.equals("jgsbyh")) {
                //返回本用户下
                wshsl = qcQyxxService.wshsl(username);
                wshslMJ = qcQyxxService.wshslMJ(username);
            }
        }
        if (wshsl == null) {
            wshsl = "0";
        }
        if (wshslMJ == null) {
            wshslMJ = "0";
        }
        return Result.OK(wshsl + "|" + ChangeNumber.ChangeString(wshslMJ));
    }

    /**
     * 首页-审核中数量
     *
     * @return
     */
    //@AutoLog(value = "首页-未审核数量")
    @ApiOperation(value = "首页-未审核数量", notes = "首页-审核中数量")
    @GetMapping(value = "/shzsl")
    public Result<String> shzsl() {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        ISysBaseAPI api = (ISysBaseAPI) SpringContextUtils.getBean("sysBaseApiImpl");
        String username = sysUser.getUsername();
        List<String> rolesByUsername = api.getRolesByUsername(sysUser.getUsername());
        String wshsl = null;
        for (String s : rolesByUsername) {
            if (s.equals("shyh") || s.equals("gzw") || s.equals("xfzx") || s.equals("sjzh")) {
                wshsl = qcQyxxService.shzslAdmin();
                break;
            } else if (s.equals("sbyh")) {
                wshsl = qcQyxxService.shzsl(username);
            }
        }

        return Result.OK(wshsl);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param qcQyxx
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, QcQyxx qcQyxx) {
        // Step.1 组装查询条件
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<QcQyxx> pageList = service.list(queryWrapper.likeRight("org_code", "A04"));
        List<QcQyxx> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "用地单位信息");
        mv.addObject(NormalExcelConstants.CLASS, QcQyxx.class);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams("用地单位信息" + "报表", "导出人:" + sysUser.getRealname(), "用地单位信息");
        exportParams.setImageBasePath(upLoadPath);
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /**
     * 导出excel
     *
     * @param request
     * @param qcQyxx
     */
    @RequestMapping(value = "/exportXls2")
    @PermissionData(pageComponent = "sydwqcsb/sydwxx/QcQyxxList")
    public ModelAndView exportXls2(HttpServletRequest request, QcQyxx qcQyxx) {
        // Step.1 组装查询条件
        QueryWrapper<QcQyxx> queryWrapper = QueryGenerator.initQueryWrapper(qcQyxx, request.getParameterMap());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        // Step.2 获取导出数据
        List<QcQyxx> pageList = service.list(queryWrapper.likeRight("org_code", "A03"));
        List<QcQyxx> exportList = null;

        // 过滤选中数据
        String selections = request.getParameter("selections");
        if (oConvertUtils.isNotEmpty(selections)) {
            List<String> selectionList = Arrays.asList(selections.split(","));
            exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
        } else {
            exportList = pageList;
        }
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, "事业单位信息");
        mv.addObject(NormalExcelConstants.CLASS, QcQyxx.class);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams("事业单位信息" + "报表", "导出人:" + sysUser.getRealname(), "事业单位信息");
        exportParams.setImageBasePath(upLoadPath);
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, QcQyxx.class);
    }

    /*----------------------------------------------统计开始处------------------------------------------------*/

    /**
     * 统计-上报地块面积
     *
     * @return
     */
    @ApiOperation(value = "统计-上报地块面积", notes = "统计-上报地块面积")
    @GetMapping(value = "/sbdkmj")
    public Result<?> sbdkmj() {
        //省属地块面积
        QueryWrapper queryWrapper = new QueryWrapper<>();
        //省直地块面积
        QueryWrapper queryWrapperBysz = new QueryWrapper<>();
        //省属闲置低效面积
        QueryWrapper queryWrapperBydxss = new QueryWrapper<>();
        //省直闲置低效面积
        QueryWrapper queryWrapperBydxsz = new QueryWrapper<>();
        //已审核省属企业数量
        QueryWrapper ssQysl = new QueryWrapper<>();
        //上报地块企业数量
        QueryWrapper sbdkQysl = new QueryWrapper<>();
        //已审核省直单位
        QueryWrapper szQysl = new QueryWrapper<>();
        //上报地块单位数量
        QueryWrapper ssDwsl = new QueryWrapper<>();
        //SELECT sum(CAST(sjzytdmj AS DECIMAL(10,2)))*0.0015 as  SUMSS,count(SJZYTDMJ) as  COUNTDK from qc_ssgqzysytdqk_gzv where sfsb=3 and sys_org_code like 'A04%'
        queryWrapper.select("sum(CAST(sjzytdmj AS DECIMAL(10,2)))*0.0015 as  \"SUMSS\",count(SJZYTDMJ) as  \"COUNTDK\"");
        queryWrapper.eq("SFSB", 3);
        queryWrapper.likeRight("SYS_ORG_CODE", "A04");
        Map<String, Object> map = qcSsgqzysytdqkGzvService.getMap(queryWrapper);

        //转亩
        queryWrapperBysz.select("sum(SJZYTDMJ) as  \"sumsz\",count(SJZYTDMJ) as  \"countdk\"").likeRight("SYS_ORG_CODE", "A03");
        queryWrapperBysz.eq("SFSB", 3);
        map.put("SUMSZ", Double.parseDouble(qcSsgqzysytdqkGzvService.getMap(queryWrapperBysz).get("sumsz").toString()) * 0.0015);
        map.put("COUNTDKBYSZ", qcSsgqzysytdqkGzvService.getMap(queryWrapperBysz).get("countdk").toString());

        //省属闲置地效
        queryWrapperBydxss.select("sum(CAST(sjzytdmj AS DECIMAL(10,2)))*0.0015 as \"sumssxzdx\",count(SJZYTDMJ) as  \"countdk\"");
        queryWrapperBydxss.eq("SFSB", 3);
        queryWrapperBydxss.eq("TDSYXZ", "闲置低效土地");
        queryWrapperBydxss.likeRight("SYS_ORG_CODE", "A04");
        map.put("SUMSSXZDX", qcSsgqzysytdqkGzvService.getMap(queryWrapperBydxss).get("sumssxzdx"));
        map.put("COUNTDKBYSSXZDX", qcSsgqzysytdqkGzvService.getMap(queryWrapperBydxss).get("countdk"));

        queryWrapperBydxsz.select("sum(SJZYTDMJ) as \"sumszxzdx\",count(SJZYTDMJ) as  \"countdk\"");
        queryWrapperBydxsz.eq("SFSB", 3);
        queryWrapperBydxsz.eq("TDSYXZ", "闲置低效土地");
        queryWrapperBydxsz.likeRight("SYS_ORG_CODE", "A03");
        map.put("SUMSZXZDX", Double.parseDouble(qcSsgqzysytdqkGzvService.getMap(queryWrapperBydxsz).get("sumszxzdx").toString()) * 0.0015);
        map.put("COUNTDKBYSZXZDX", qcSsgqzysytdqkGzvService.getMap(queryWrapperBydxsz).get("countdk").toString());

        //已审核
        ssQysl.select("count(SYS_ORG_CODE) as  \"ssQysl\"");
        ssQysl.eq("SFSB", 3);
        ssQysl.likeRight("SYS_ORG_CODE", "A04");
        map.put("SSQYSL", qcQyxxService.getMap(ssQysl).get("ssQysl").toString());

        sbdkQysl.select(" count(DISTINCT(SYS_ORG_CODE)) as \"sbdkQysl\"");
        sbdkQysl.eq("SFSB", 3);
        sbdkQysl.likeRight("SYS_ORG_CODE", "A04");
        map.put("SBDKQYSL", qcSsgqzysytdqkGzvService.getMap(sbdkQysl).get("sbdkQysl"));

        szQysl.select("count(SYS_ORG_CODE) as  \"szQysl\"");
        szQysl.eq("SFSB", 3);
        szQysl.likeRight("SYS_ORG_CODE", "A03");
        map.put("SZQYSL", qcQyxxService.getMap(szQysl).get("szQysl").toString());

        ssDwsl.select(" count(DISTINCT(SYS_ORG_CODE)) as \"ssDwsl\"");
        ssDwsl.eq("SFSB", 3);
        ssDwsl.likeRight("SYS_ORG_CODE", "A03");
        map.put("SSDWSL", qcSsgqzysytdqkGzvService.getMap(ssDwsl).get("ssDwsl"));
        /*上报地块面积*/
        return Result.OK(map);
    }

    /**
     * 统计-上报地块面积
     *
     * @return
     */
    @ApiOperation(value = "统计-上报地块面积", notes = "统计-上报地块面积")
    @GetMapping(value = "/xzqhtj")
    public Result<?> xzqhtj() {


        return Result.OK("null");
    }


    /**
     * 统计-土地获取方式占比按照地块
     *
     * @return
     */
    @ApiOperation(value = "统计-土地获取方式占比", notes = "统计-土地获取方式占比")
    @GetMapping(value = "/tdhqfs")
    public Result<?> tdhqfs(@RequestParam(name = "xzqh") String xzqh) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(xzqh)) {
            queryWrapper.likeRight("XZQH", xzqh);
        }
        Map<String, Object> resultMap = new HashMap<>();
        queryWrapper.select("count(syqsyfs) as \"value\",SYQSYFS as \"name\"");
        queryWrapper.groupBy("SYQSYFS");
        queryWrapper.likeRight("SYS_ORG_CODE", "A04");
        queryWrapper.eq("SFSB", 3);
        List list = qcSsgqzysytdqkGzvService.listMaps(queryWrapper);
        Collections.reverse(list);
        return Result.OK(list);
    }

    /**
     * 统计-土地获取方式占比按照面积
     *
     * @return
     */
    @ApiOperation(value = "统计-土地获取方式占比按照面积", notes = "统计-土地获取方式占比按照面积")
    @GetMapping(value = "/tdhqfsArea")
    public Result<?> tdhqfsArea(@RequestParam(name = "xzqh") String xzqh) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(xzqh)) {
            queryWrapper.likeRight("XZQH", xzqh);
        }
        Map<String, Object> resultMap = new HashMap<>();
        queryWrapper.select("sum(CAST(sjzytdmj AS DECIMAL(10,2))) as \"value\",SYQSYFS as \"name\"");
        queryWrapper.groupBy("SYQSYFS");
        queryWrapper.likeRight("SYS_ORG_CODE", "A04");
        queryWrapper.eq("SFSB", 3);
        List list = qcSsgqzysytdqkGzvService.listMaps(queryWrapper);
        //其它类放后面
        Collections.reverse(list);
        return Result.OK(list);
    }


    /**
     * 统计-土地获取方式占比省直
     *
     * @return
     */
    @ApiOperation(value = "统计-土地获取方式占比省直", notes = "统计-土地获取方式占比省直")
    @GetMapping(value = "/tdhqfssz")
    public Result<?> tdhqfssz(@RequestParam(name = "xzqh") String xzqh) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(xzqh)) {
            queryWrapper.likeRight("XZQH", xzqh);
        }
        Map<String, Object> resultMap = new HashMap<>();
        queryWrapper.select("count(syqsyfs) as \"value\",SYQSYFS as \"name\"");
        queryWrapper.groupBy("SYQSYFS");
        queryWrapper.likeRight("SYS_ORG_CODE", "A03");
        queryWrapper.gt("SFSB", 1);
        List list = qcSsgqzysytdqkGzvService.listMaps(queryWrapper);
        Collections.reverse(list);
        return Result.OK(list);
    }

    /**
     * 统计-权证登记比例省直
     *
     * @return
     */
    @ApiOperation(value = "统计-权证登记比例省直", notes = "统计-权证登记比例省直")
    @GetMapping(value = "/qzdjblss")
    public Result<?> qzdjblss(@RequestParam(name = "xzqh") String xzqh) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(xzqh)) {
            queryWrapper.likeRight("XZQH", xzqh);
        }
        Map<String, Object> resultMap = new HashMap<>();
        int sum = 0;
        queryWrapper.select("count(zslx) as \"value\",ZSLX as \"name\"");
        //queryWrapper.gt("SFSB", 1);
        queryWrapper.groupBy("zslx");
        queryWrapper.likeRight("SYS_ORG_CODE", "A03");
        List<HashMap<String, Object>> list = qcSsgqzysytdqkGzvService.listMaps(queryWrapper);
        return getResult(sum, list);
    }

    @NotNull
    private Result<?> getResult(int sum, List<HashMap<String, Object>> list) {
        int conut = 0;
        List<HashMap<String, String>> result = new ArrayList<>();
        HashMap<String, String> Maps = new HashMap<>();
        HashMap<String, String> Map = new HashMap<>();
        for (HashMap<String, Object> map : list) {

            if (map.get("name").equals("无") || map.get("name").equals("无权属证明材料") || map.get("name").equals("文件合同等权属证明材料")) {
                conut = conut + Integer.valueOf(map.get("value").toString());
            } else {
                sum = sum + Integer.valueOf(map.get("value").toString());
            }
        }
        Map.put("name", "无证");
        Map.put("value", String.valueOf(conut));
        Maps.put("name", "有证");
        Maps.put("value", String.valueOf(sum));
        result.add(Maps);
        result.add(Map);
        return Result.OK(result);
    }

    /**
     * 统计-土地使用现状占比
     *
     * @return
     */
    @ApiOperation(value = "统计-土地使用现状占比", notes = "统计-土地使用现状占比")
    @GetMapping(value = "/tdsyxzzb")
    public Result<?> tdsyxzzb(@RequestParam(name = "xzqh") String xzqh) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(xzqh)) {
            queryWrapper.likeRight("XZQH", xzqh);
        }
        Map<String, Object> resultMap = new HashMap<>();
        int sum = 0;
        queryWrapper.select("count(TDSYXZ) as \"value\",TDSYXZ as \"name\"");
        queryWrapper.eq("SFSB", 3);
        queryWrapper.groupBy("TDSYXZ");
        queryWrapper.likeRight("SYS_ORG_CODE", "A04");
        List<HashMap<String, Object>> list = qcSsgqzysytdqkGzvService.listMaps(queryWrapper);
        return Result.OK(list);
    }

    /**
     * 统计-权证登记比例省属
     *
     * @return
     */
    @ApiOperation(value = "统计-权证登记比例省属", notes = "统计-权证登记比例省属")
    @GetMapping(value = "/qzdjblsz")
    public Result<?> qzdjblsz(@RequestParam(name = "xzqh") String xzqh) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(xzqh)) {
            queryWrapper.likeRight("XZQH", xzqh);
        }
        Map<String, Object> resultMap = new HashMap<>();
        queryWrapper.select("count(wjlx) as \"value\",wjlx as \"name\"");
        queryWrapper.groupBy("wjlx");
        queryWrapper.likeRight("SYS_ORG_CODE", "A04");
//        queryWrapper.eq("SFSB", 3);
        List<HashMap<String, Object>> list = qcSsgqzysytdqkGzvService.listMaps(queryWrapper);
        int sum = 0;
        return getResult2(sum, list);
    }

    @NotNull
    private Result<?> getResult2(int sum, List<HashMap<String, Object>> list) {
        List<HashMap<String, String>> result = new ArrayList<>();
        HashMap<String, String> Maps = new HashMap<>();
        for (HashMap<String, Object> map : list) {
            HashMap<String, String> Map = new HashMap<>();
            if (map.get("name").equals("证书")) {
                Map.put("name", "有证");
                Map.put("value", map.get("value").toString());
                result.add(Map);
            } else if (map.get("name").equals("待核实")) {
                Map.put("name", "待核实");
                Map.put("value", map.get("value").toString());
                result.add(Map);
            }else{
                sum = sum + Integer.valueOf(map.get("value").toString());
            }
        }
        Maps.put("name", "无证");
        Maps.put("value", String.valueOf(sum));
        result.add(Maps);
        return Result.OK(result);
    }

    /**
     * 统计-实际用途统计省直
     *
     * @return
     */
    @ApiOperation(value = "统计-实际用途统计省直", notes = "统计-实际用途统计省直")
    @GetMapping(value = "/sjyttjsz")
    public Result<?> sjyttjsz(@RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> list = qcQyxxService.sjyttjsz(xzqh);
        Collections.reverse(list);
        return getResult(list);
    }

    /**
     * 统计-一级单位用地面积汇总
     *
     * @return
     */
    @ApiOperation(value = "统计-一级单位用地面积汇总", notes = "统计-一级单位用地面积汇总")
    @GetMapping(value = "/yjdwmjhz")
    public Result<?> yjdwmjhz(@RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> list = qcQyxxService.yjdwhz(xzqh);
        return getResult(list);
    }

    @NotNull
    private Result<?> getResult(List<HashMap<String, Object>> list) {
        List names = new ArrayList<>();
        List values = new ArrayList<>();
        List codes = new ArrayList<>();
        Map<String, Object> res = new HashMap<>();
        for (HashMap<String, Object> map : list) {
            names.add(map.get("name"));
            values.add(map.get("value"));
            codes.add(map.get("code"));
        }
        res.put("name", names);
        res.put("value", values);
        res.put("code", codes);
        return Result.OK(res);
    }

    /**
     * 统计-实际用途统计省属
     *
     * @return
     */
    @ApiOperation(value = "统计-实际用途统计省属", notes = "统计-实际用途统计省属")
    @GetMapping(value = "/sjyttjss")
    public Result<?> sjyttjss(@RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> list = qcQyxxService.sjyttjss(xzqh);
        return getResult(list);
    }

    /**
     * 统计-省直地图统计
     *
     * @return
     */
    @ApiOperation(value = "统计-省直地图统计", notes = "统计-省直地图统计")
    @GetMapping(value = "/szdtdktj")
    public Result<?> szdtdktj() {
        List<HashMap<String, Object>> list = qcQyxxService.dtdktj("A03");
        return Result.OK(list);
    }

    /**
     * 统计-省直地图统计
     *
     * @return
     */
    @ApiOperation(value = "统计-省属地图统计", notes = "统计-省属地图统计")
    @GetMapping(value = "/ssdtdktj")
    public Result<?> ssdtdktj() {
        List<HashMap<String, Object>> list = qcQyxxService.dtdktj("A04");
        return Result.OK(list);
    }

    /**
     * 统计-地图县区统计
     *
     * @return
     */
    @ApiOperation(value = "统计-省属地图统计", notes = "统计-省属地图统计")
    @GetMapping(value = "/dtdktjSQByxq")
    public Result<?> dtdktjSQByxq(@RequestParam(name = "orgCode") String orgCode, @RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> list = qcQyxxService.dtdktjByxq(orgCode, xzqh);
        return Result.OK(list);
    }

    /**
     * 统计-地图县区统计
     *
     * @return
     */
    @ApiOperation(value = "统计-省属地图统计", notes = "统计-省属地图统计")
    @GetMapping(value = "/dtdktjSZByxq")
    public Result<?> dtdktjSZByxq(@RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> list = qcQyxxService.dtdktjByxq("A04", xzqh);
        return Result.OK(list);
    }

    /**
     * 统计-省属实际占用土地面积统计
     *
     * @return
     */
    @ApiOperation(value = "统计-省属实际占用土地面积统计", notes = "统计-省属实际占用土地面积统计")
    @GetMapping(value = "/sszytdmjtj")
    public Result<?> sszytdmjtj(@RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> ssdkmj;
        if (StringUtils.isNotBlank(xzqh)) {
            ssdkmj = qcQyxxService.ssdkmjbyqx(xzqh);
        } else {
            ssdkmj = qcQyxxService.ssdkmj();
        }
        return getSszytdResult(ssdkmj);
    }

    @NotNull
    private Result<?> getSszytdResult(List<HashMap<String, Object>> ssdkmj) {
        List names = new ArrayList<>();
        List values = new ArrayList<>();
        List values2 = new ArrayList<>();
        Map<String, Object> res = new HashMap<>();
        for (HashMap<String, Object> map : ssdkmj) {
            names.add(map.get("name"));
            values.add(map.get("value"));
            values2.add(map.get("value2"));
        }
        res.put("name", names);
        res.put("value", values);
        res.put("value2", values2);
        return Result.OK(res);
    }

    /**
     * 统计-省直实际占用土地面积统计
     *
     * @return
     */
    @ApiOperation(value = "统计-省直实际占用土地面积统计", notes = "统计-省直实际占用土地面积统计")
    @GetMapping(value = "/szzytdmjtj")
    public Result<?> szzytdmjtj(@RequestParam(name = "xzqh") String xzqh) {
        List<HashMap<String, Object>> ssdkmj;
        if (StringUtils.isNotBlank(xzqh)) {
            ssdkmj = qcQyxxService.szdkmjByqx(xzqh);
        } else {
            ssdkmj = qcQyxxService.szdkmj();
        }
        return getSszytdResult(ssdkmj);
    }

    /**
     * 省直————统计企业自用，出租数量
     *
     * @return
     */
    @AutoLog(value = "省直-统计企业自用，出租数量")
    @ApiOperation(value = "省直-统计企业自用，出租数量", notes = "省直-统计企业自用，出租数量")
    @GetMapping(value = "/szqyzy")
    public Result<?> szqyzy() {
        List resultMap = new ArrayList();
        QueryWrapper queryWrapper = new QueryWrapper<>();

        queryWrapper.select("count(CZCJQK) as \"value\"");
        queryWrapper.likeRight("SYS_ORG_CODE", "A03");
        queryWrapper.eq("SFSB", 3);
        queryWrapper.eq("CZCJQK", "出租");
        Map map = qcSsgqzysytdqkGzvService.getMap(queryWrapper);

        QueryWrapper queryWrapper1 = new QueryWrapper<>();

        queryWrapper1.select("count(CZCJQK) as \"value\"");
        queryWrapper1.likeRight("SYS_ORG_CODE", "A03");
        queryWrapper1.eq("SFSB", 3);
        queryWrapper1.eq("CZCJQK", "无");
        Map map1 = qcSsgqzysytdqkGzvService.getMap(queryWrapper1);

        QueryWrapper queryWrapper2 = new QueryWrapper<>();

        queryWrapper2.select("count(SYS_ORG_CODE) as \"value\"");
        queryWrapper2.likeRight("SYS_ORG_CODE", "A03");
        queryWrapper2.eq("SFSB", 3);
        queryWrapper2.eq("tdsyxz", "闲置低效土地");
        Map map2 = qcSsgqzysytdqkGzvService.getMap(queryWrapper2);
        QueryWrapper queryWrapper3 = new QueryWrapper<>();

        queryWrapper3.select("count(SYS_ORG_CODE) as \"value\"");
        queryWrapper3.likeRight("SYS_ORG_CODE", "A03");
        queryWrapper3.eq("SFSB", 3);
        Map map3 = qcSsgqzysytdqkGzvService.getMap(queryWrapper3);
        //出租
        resultMap.add(map);
        //企业自用
        resultMap.add(map1);
        //闲置低效数量
        resultMap.add(map2);
        //总地块数量
        resultMap.add(map3);
        return Result.OK(resultMap);
    }

}
