package org.jeecg.modules.stm.common.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 lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;

import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.stm.common.service.IStCommonService;
import org.jeecg.modules.stm.common.vo.DutyVo;
import org.jeecg.modules.stm.common.vo.QueryVo;
import org.jeecg.modules.stm.common.vo.StMenuVo;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysUserService;
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 jakarta.servlet.http.HttpServletRequest;


import java.util.Map;

/**
 * @Author: yzh
 * @Date 2023/4/2 18:18
 * @Description:
 */
  
@RestController
@RequestMapping("/stm.common/action")
@Slf4j
public class StCommonController {

    @Autowired
    private IStCommonService iStCommonService;

    @Autowired
    private ISysDepartService iSysDepartService;

    @Autowired
    private ISysUserService iSysUserService;

    @GetMapping(value = "/listDepart")
    public Result<IPage<SysDepart>> queryDepartPageList(SysDepart sysDepart,
                                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                        HttpServletRequest req) {
        QueryWrapper<SysDepart> queryWrapper = QueryGenerator.initQueryWrapper(sysDepart, req.getParameterMap());
        Page<SysDepart> page = new Page<SysDepart>(pageNo, pageSize);
        IPage<SysDepart> pageList = iSysDepartService.page(page,queryWrapper);
        return Result.OK(pageList);
    }


    @GetMapping(value = "/listUser")
    public Result<IPage<SysUser>> queryUserPageList(SysUser sysUser,
                                                    @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                    @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(sysUser, req.getParameterMap());
        Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
        IPage<SysUser> pageList = iSysUserService.page(page,queryWrapper);
        return Result.OK(pageList);
    }


    @GetMapping(value = "/statistics")
    public Result<Map<String, StMenuVo>> statistics(HttpServletRequest req) {
        Map<String,StMenuVo> stMenuVoMap = iStCommonService.statistics();
        return Result.OK(stMenuVoMap);
    }

    @GetMapping(value = "/statistics_project")
    public Result<Map<String,StMenuVo>> statisticsProject(HttpServletRequest req) {
        Map<String,StMenuVo> stMenuVoMap = iStCommonService.statisticsProject();
        return Result.OK(stMenuVoMap);
    }

    @GetMapping(value = "/statisticsByCaNo")
    public Result<Map<String,Long>> statisticsByCaNo(@RequestParam("caNo")String caNo){
        Map<String,Long> map = iStCommonService.statisticsByCaNo(caNo);
        return Result.OK(map);
    }

    @GetMapping(value = "/statisticsByComplianceNo")
    public Result<Map<String,Long>> statisticsByComplianceNo(@RequestParam("complianeNo")String complianeNo){
        Map<String,Long> map = iStCommonService.statisticsByComplianceNo(complianeNo);
        return Result.OK(map);
    }


      
    @GetMapping(value = "/list")
    public Result<IPage<QueryVo>> queryPageList(QueryVo queryVo,
                                                @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                HttpServletRequest req) {
        Page<QueryVo> page = new Page<QueryVo>(pageNo, pageSize);
        queryVo.setNames();
        IPage<QueryVo> pageList = iStCommonService.queryCommonByPage(page,queryVo);
        //queryAllLibData
        return Result.OK(pageList);
    }


      
    @GetMapping(value = "/listDuty")
    public Result<IPage<DutyVo>> queryDutyPageList(DutyVo queryVo,
                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                   HttpServletRequest req) {
        Page<DutyVo> page = new Page<DutyVo>(pageNo, pageSize);
        IPage<DutyVo> pageList = iStCommonService.queryDutyVoByPage(page,queryVo);
        return Result.OK(pageList);
    }
}



