package com.ruoyi.web.controller.workTecket;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.JWTUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.doubledefense.dto.DangerStatisticsDTO;
import com.ruoyi.system.domain.AppLogin;
import com.ruoyi.system.dto.ContractorUserDTO;
import com.ruoyi.system.service.IAppLoginService;
import com.ruoyi.system.service.IContractorUserService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.worktecket.dto.WorkTicketAreaWorkStatisticsPCDTO;
import com.ruoyi.worktecket.dto.WorkTicketStatisticsPCDTO;
import com.ruoyi.worktecket.service.IWorkTicketBasicDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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.RestController;

import java.util.List;
import java.util.Objects;

@Api(tags = "PC首页统计-作业票统计")
@RestController
@RequestMapping("/pc/workticket/homepage")
@Slf4j
public class WorkTecketHomePageController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IAppLoginService appLoginService;
    @Autowired
    private IContractorUserService contractorUserService;
    @Autowired
    private IWorkTicketBasicDataService workTicketBasicDataService;



    @ApiOperation("PC首页-企业信息-生产区域统计")
    @GetMapping("/sysAreaStatistics")
    public AjaxResult sysAreaStatistics() {
        String companyCode = SecurityUtils.getUserCompanyCode();


        Integer count = workTicketBasicDataService.workTicketAreaWorkCountStatistics(companyCode);

        return AjaxResult.success(count);
    }


    @ApiOperation("PC首页-企业信息-生产区域-统计区域下作业分布列表")
    @GetMapping("/workTicketAreaWorkStatistics")
    public AjaxResult workTicketAreaWorkStatistics() {

        LoginUser loginUser = getLoginUser();
        String companyCode = loginUser.getCompanyCode();


        List<WorkTicketAreaWorkStatisticsPCDTO> dataList = workTicketBasicDataService.workTicketAreaWorkStatistics(companyCode);

        return AjaxResult.success(dataList);
    }


    @ApiOperation("企业信息-生产区域：区域作业票情况统计")
    @GetMapping("/workTicketAreaStatistics")
    public AjaxResult workTicketAreaStatistics() {

        LoginUser loginUser = getLoginUser();
        String companyCode = loginUser.getCompanyCode();


        List<WorkTicketStatisticsPCDTO> dataList = workTicketBasicDataService.workTicketTypeStatistics(companyCode);

        return AjaxResult.success(dataList);
    }


    @ApiOperation("作业票")
    @GetMapping("/workTicketTypeStatistics")
    public AjaxResult workTicketTypeStatistics() {
       /* //用户昵称
        String nickName = null;
        //用户类型：1内部，2承包商
        if ("1".equals(JWTUtil.getAppUserType())) {
            //设置人员姓名
            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(JWTUtil.getPCUserId()));
            if (Objects.nonNull(sysUser)) {
                nickName = sysUser.getNickName();
            }
        } else {
            AppLogin appLogin = appLoginService.selectAppLoginById(JWTUtil.getUserId());
            if (Objects.nonNull(appLogin)) {
                ContractorUserDTO contractorUserDTO = contractorUserService.selectContractorUserById(appLogin.getContractorUserId());
                if (Objects.nonNull(contractorUserDTO)) {
                    nickName = contractorUserDTO.getCompellation();
                }
            }
        }*/

        LoginUser loginUser = getLoginUser();
        String companyCode = loginUser.getCompanyCode();
//        WorkTicketStatisticsPCDTO ss = new WorkTicketStatisticsPCDTO();


        List<WorkTicketStatisticsPCDTO> dataList = workTicketBasicDataService.workTicketTypeStatistics(companyCode);

        return AjaxResult.success(dataList);
    }
}
