package com.sundot.airport.ledger.service.impl;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.sundot.airport.common.core.domain.entity.SysDictData;
import com.sundot.airport.common.utils.DateUtils;
import com.sundot.airport.common.utils.DictUtils;
import com.sundot.airport.ledger.domain.LedgerUnsafeEvent;
import com.sundot.airport.ledger.domain.vo.CountQueryReqVO;
import com.sundot.airport.ledger.domain.vo.UnsafeItemVO;
import com.sundot.airport.ledger.domain.vo.UnsafePositionVO;
import com.sundot.airport.ledger.domain.vo.UnsafeTypeVO;
import com.sundot.airport.ledger.mapper.LedgerUnsafeEventMapper;
import com.sundot.airport.ledger.service.ILedgerUnsafeEventService;
import com.sundot.airport.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 不安全事件记录Service实现
 */
@Service
public class LedgerUnsafeEventServiceImpl extends ServiceImpl<LedgerUnsafeEventMapper, LedgerUnsafeEvent> implements ILedgerUnsafeEventService {

    @Autowired
    private LedgerUnsafeEventMapper mapper;
    @Autowired
    private ISysDictDataService dictDataService;

    @Override
    public List<LedgerUnsafeEvent> selectList(LedgerUnsafeEvent query) {
        return mapper.selectList(query);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchInsert(List<LedgerUnsafeEvent> list) {
        list.forEach(item -> item.setCreateTime(DateUtils.getNowDate()));
        saveBatch(list);
        return list.size();
    }

    /**
     * 功能描述：不安全事件物品分布
     *
     * @param countQueryReq 查询参数
     * @return List<UnsafeItemVO>
     * @method countSeizureStatsItem
     * @author PanHu Sun
     * @date 2026/5/20 16:41
     */
    @Override
    public List<UnsafeItemVO> countSeizureStatsItem(CountQueryReqVO countQueryReq) {
        // 无数据自动返回空数组，符合需求
        return this.baseMapper.countSeizureStatsItem(countQueryReq);
    }

    /**
     * 功能描述：countSeizureStatsType
     *
     * @param countQueryReq 查询参数
     * @return List<UnsafeTypeVO>
     * @method countSeizureStatsType
     * @author PanHu Sun
     * @date 2026/5/20 17:09
     */
    @Override
    public List<UnsafeTypeVO> countSeizureStatsType(CountQueryReqVO countQueryReq) {
        List<UnsafeTypeVO> unsafeTypeList = this.baseMapper.countSeizureStatsType(countQueryReq);
        return CollUtil.emptyIfNull(unsafeTypeList);
    }

    /**
     * 功能描述：不安全事件岗位分布
     *
     * @param countQueryReq 查询参数
     * @return List<UnsafePositionVO>
     * @method countSeizureStatsPost
     * @author PanHu Sun
     * @date 2026/5/20 17:20
     */
    @Override
    public List<UnsafePositionVO> countSeizureStatsPost(CountQueryReqVO countQueryReq) {
        return this.baseMapper.countSeizureStatsPost(countQueryReq);
    }
}
