/*
 * Copyright [2022] [https://www.baiduc.com]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.baiduc.com
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.baiduc.com
 */
package vip.xiaonuo.hr.modular.baseemployeeinfo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;
import vip.xiaonuo.hr.modular.baseemployeeinfo.entity.HrBaseEmployeeInfo;
import vip.xiaonuo.hr.modular.baseemployeeinfo.entity.vo.*;
import vip.xiaonuo.hr.modular.baseemployeeinfo.param.*;
import vip.xiaonuo.hr.modular.baseemployeeinfo.service.HrBaseEmployeeInfoService;
import vip.xiaonuo.purchase.param.DongShiPurchaseParam;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;

/**
 * 人员明细控制器
 *
 * @author 余
 * @date  2024/11/14 15:02
 */
@Api(tags = "董事页面控制器")
@RestController
@Validated
public class DongShiEmployeeInfoController {

    @Resource
    private HrBaseEmployeeInfoService hrBaseEmployeeInfoService;

    @ApiOperation("指标卡")
    @PostMapping("/hr/dongShi/zhiBiao")
    public CommonResult<DongShiCountNum> zhiBiao(@Valid @RequestBody DongShiPurchaseParam dongShiPurchaseParam) {
     return    CommonResult.data(hrBaseEmployeeInfoService.zhiBiao(dongShiPurchaseParam));
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation("获取人员明细分页")
    @PostMapping("/hr/dongShi/yuanGongDetails")
    public CommonResult<Page<HrBaseEmployeeInfo>> details(@RequestBody DongShiPurchaseParam dongShiPurchaseParam) {
        return CommonResult.data(hrBaseEmployeeInfoService.details(dongShiPurchaseParam));
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation("获取员工支出明细")
    @PostMapping("/hr/dongShi/zhiChuDetails")
    public CommonResult<List<DongShiCountNum>> zhiChuDetails(@RequestBody DongShiPurchaseParam dongShiPurchaseParam) {
        return CommonResult.data(hrBaseEmployeeInfoService.zhiChuDetails(dongShiPurchaseParam));
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation("员工数量趋势")
    @PostMapping("/hr/dongShi/yuanGongNum")
    public CommonResult<List<DongShiCountNum>> yuanGongNum(@RequestBody DongShiPurchaseParam dongShiPurchaseParam) {
        return CommonResult.data(hrBaseEmployeeInfoService.yuanGongNum(dongShiPurchaseParam));
    }

    @ApiOperation("年龄性别分布")
    @PostMapping("/hr/dongShi/ageDis")
    public CommonResult<List<PerNumDongShi>> ageDis(@Valid @RequestBody EmployeeInfoEoucation employeeInfoEoucation) {
        String orgId = employeeInfoEoucation.getOrgId();
        long age22 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 18,24).eq("GENDER",0));
        long age22x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 18,24).eq("GENDER",1));
        long age30 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 25,30).eq("GENDER",0));
        long age30x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 25,30).eq("GENDER",1));
        long age40 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 31,40).eq("GENDER",0));
        long age40x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 31,40).eq("GENDER",1));
        long age45 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 41,45).eq("GENDER",0));
        long age45x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 41,45).eq("GENDER",1));
        long age55 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 46,55).eq("GENDER",0));
        long age55x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 46,55).eq("GENDER",1));
        long age65 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 55,65).eq("GENDER",0));
        long age65x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).eq("USER_TYPE",0).between("AGE", 55,54).eq("GENDER",1));
        long age66 = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).ge("AGE", 60).eq("GENDER",0));
        long age66x = hrBaseEmployeeInfoService.count(new QueryWrapper<HrBaseEmployeeInfo>().eq(StringUtils.isNotBlank(orgId),"ORG_ID", orgId).ge("AGE", 60).eq("GENDER",1));
        ArrayList<PerNumDongShi> perNums = new ArrayList<>();
        perNums.add(new PerNumDongShi("18-24岁",age22,age22x));
        perNums.add(new PerNumDongShi("25-30岁",age30,age30x));
        perNums.add(new PerNumDongShi("31-40岁",age40,age40x));
        perNums.add(new PerNumDongShi("41-45岁",age45,age45x));
        perNums.add(new PerNumDongShi("46-55岁",age55,age55x));
        perNums.add(new PerNumDongShi("56-65岁",age65,age65x));
        perNums.add(new PerNumDongShi("65岁以上",age66,age66x));
        return CommonResult.data(perNums);
    }


}
