package org.jeecg.modules.itdmFirstPage.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.itdmFirstPage.entity.ItdmTask;
import org.jeecg.modules.itdmFirstPage.service.IItdmTaskService;
import org.jeecg.modules.itdmFirstPage.vo.ItdmFirstPageVO;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.service.ISysRoleService;
import org.jeecg.modules.system.service.ISysUserRoleService;
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 javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Api(tags="...首页")
@RestController
@RequestMapping("/itdmFirstPage")
@Slf4j
public class itdmFirstPageController {

    @Autowired
    private IItdmTaskService taskService;
    @Autowired
    private ISysUserRoleService sysUserRoleService;
    @Autowired
    private ISysRoleService roleService;

    @ApiOperation(value="任务各种数量", notes="所有任务，待办，进行中，完成")
    @GetMapping(value = "/getFrstPageTaskNum")
    public ItdmFirstPageVO getFrstPageTaskNum(){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String realName = loginUser.getRealname(); // 登录人姓名
        String username = loginUser.getUsername(); // 登录账号
        System.out.println("realName:"+ realName+ "  username:"+ username);

        ItdmTask itdmTask = new ItdmTask();
        List<String> roles = new ArrayList<>();
        if(!username.equals("admin")){
            itdmTask.setTaskUser(realName);
        }

        QueryWrapper<ItdmTask> taskWrapper = new QueryWrapper<>(itdmTask);

        Long totalNum = taskService.count(taskWrapper);

        itdmTask.setTaskStatus(0);
        taskWrapper = new QueryWrapper<>(itdmTask);
        Long daibanNum = taskService.count(taskWrapper);

        itdmTask.setTaskStatus(1);
        taskWrapper = new QueryWrapper<>(itdmTask);
        Long jinxingNum = taskService.count(taskWrapper);

        itdmTask.setTaskStatus(2);
        taskWrapper = new QueryWrapper<>(itdmTask);
        Long wanchengNum =taskService.count(taskWrapper);

        ItdmFirstPageVO firstPageVO = new ItdmFirstPageVO();
        firstPageVO.setDaibanNum(daibanNum);
        firstPageVO.setJinxingNum(jinxingNum);
        firstPageVO.setWanchengNum(wanchengNum);
        firstPageVO.setTotalNum(totalNum);

        return firstPageVO;
    }


}
