package com.ruoyi.app.controller.doubleDefense;

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.utils.JWTUtil;
import com.ruoyi.doubledefense.dto.DangerStatisticsDTO;
import com.ruoyi.doubledefense.service.IDangerService;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.Objects;

/**
 * APP首页统计
 */
@Api(tags = "APP首页统计-隐患排查")
@RestController
@RequestMapping("/app/danger/homepage")
public class DangerHomePageAppController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IAppLoginService appLoginService;
    @Autowired
    private IContractorUserService contractorUserService;
    @Autowired
    private IDangerService dangerService;

    @ApiOperation("隐患排查")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "type", value = "审核类型：1驳回，2通过", dataType = "Integer", dataTypeClass = Integer.class),
//            @ApiImplicitParam(name = "dangerId", value = "隐患主键", dataType = "String", dataTypeClass = String.class),
//            @ApiImplicitParam(name = "remark", value = "备注：驳回原因或审核通过备注", dataType = "String", dataTypeClass = String.class)
//    })
    @GetMapping("/dangerStatistics")
    public AjaxResult dangerStatistics() {
        /*
        //用户昵称
        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();
                }
            }
        }
        */
        DangerStatisticsDTO dangerStatistics =dangerService.dangerStatistics();
        return AjaxResult.success(dangerStatistics);
//        return AjaxResult.success("接口待开发……【" + nickName + "】");
    }
/*


SELECT
	COUNT(id) AS dangerTotal,
	SUM(IF(danger_status = 10, 1, 0)) AS CHECK_PENDING_待审核,
	SUM(IF(danger_status = 20, 1, 0)) AS UNCLAIMED_认领中,
	SUM(IF(danger_status = 30, 1, 0)) AS RECTIFICATION_整改中,
	SUM(IF(danger_status = 40, 1, 0)) AS WAIT_FOR_ACCEPTANCE_待验收,
	SUM(IF(danger_status = 50, 1, 0)) AS COMPLETED_已验收,
	SUM(IF(danger_status = 60, 1, 0)) AS CANCELED_已取消
FROM tb_danger
WHERE is_del = 0



总数            dangerTotal
完成比例整数     completeRatio
待审核          checkPendingCount
认领中          unclaimedCount
整改中          rectificationCount
待验收          waitForAcceptanceCount
已验收          completedCount
已取消          canceledCount



 */

}
