package com.sundot.airport.item.service.portrait;

import cn.hutool.core.util.ObjectUtil;
import com.sundot.airport.common.domain.portrait.BaseModuleIndicatorResult;
import com.sundot.airport.common.domain.portrait.IndicatorCalculateParams;
import com.sundot.airport.common.enums.portrait.IndicatorType;
import com.sundot.airport.common.enums.portrait.UserType;
import com.sundot.airport.common.service.portrait.Indicator;
import com.sundot.airport.item.domain.portrait.ItemSeizureModuleIndicatorResult;
import com.sundot.airport.item.domain.portrait.SeizureStats;
import com.sundot.airport.item.service.IItemSeizureStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 故意隐匿查获数量指标实现类
 * 个人：周期内数量
 * 组织：周期内总量
 */
@Component
public class WillfulConcealmentCountIndicator implements Indicator<Object> {

    @Autowired
    private IItemSeizureStatsService itemSeizureStatsService;

    private Object value;

    @Override
    public String getName() {
        return IndicatorType.WILLFUL_CONCEALMENT_COUNT.getCode();
    }

    @Override
    public Object getValue() {
        return value;
    }

    @Override
    public void calculate(IndicatorCalculateParams params) {
        Long userId = params.getUserId();
        UserType userType = params.getUserType();
        Long deptId = params.getDeptId();

        // 默认查询最近91天的数据
        Date endTime = params.getEndTime();
        Date startTime = params.getStartTime();


        if (UserType.PERSONAL.equals(userType)) {
            // 个人：周期内数量
            this.value = itemSeizureStatsService.getPersonalWillfulConcealmentCount(userId, startTime, endTime);
        } else if (UserType.TEAM.equals(userType)) {
            // 班组：周期内总量
            this.value = itemSeizureStatsService.getTeamWillfulConcealmentCount(deptId, startTime, endTime);
        } else if (UserType.DEPARTMENT.equals(userType)) {
            // 科室：周期内总量
            this.value = itemSeizureStatsService.getDepartmentWillfulConcealmentCount(deptId, startTime, endTime);
        } else if (UserType.BRIGADE.equals(userType)) {
            // 大队：周期内总量
            this.value = itemSeizureStatsService.getBrigadeWillfulConcealmentCount(deptId, startTime, endTime);
        } else if (UserType.STATION.equals(userType)) {
            // 站点：周期内总量
            this.value = itemSeizureStatsService.getStationWillfulConcealmentCount(deptId, startTime, endTime);
        } else {
            // 默认使用班组查询
            this.value = itemSeizureStatsService.getTeamWillfulConcealmentCount(deptId, startTime, endTime);
        }
    }

    @Override
    public void setResult(BaseModuleIndicatorResult result) {
        if (result instanceof ItemSeizureModuleIndicatorResult) {
            ItemSeizureModuleIndicatorResult itemResult = (ItemSeizureModuleIndicatorResult) result;
            itemResult.setWillfulConcealmentCount(this.value);
        }
    }
}