package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.fire.domain.DemLawStatistics;
import com.usky.fire.mapper.DemLawStatisticsMapper;
import com.usky.fire.service.DemLawStatisticsService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 行政执法统计总表 服务实现类
 * </p>
 *
 * @author JCB
 * @since 2022-10-13
 */
@Service
public class DemLawStatisticsServiceImpl extends AbstractCrudService<DemLawStatisticsMapper, DemLawStatistics> implements DemLawStatisticsService {

    @Override
    public Map<String, Object> lawStatistics(Date startTime, Date endTime) {
        QueryWrapper<DemLawStatistics> query = Wrappers.query();
//        query.select("COALESCE(sum(inspect_company)) as `检查家次(家)`", "COALESCE(sum( fire_hazard)) as `发现隐患(起)`",
//                "COALESCE(sum(rectificate_fire_hazard)) as `整改隐患(起)`", "COALESCE(sum(penalty_amount)) as `处罚金额(万元)`",
//                "COALESCE(sum(correction_notice)) as `责令整改(份)`", "COALESCE(sum(punishment_decision)) as `处罚决定书(份)`",
//                "COALESCE(sum(order_three_stops)) as `责令三停(家)`", "COALESCE(sum(temporary_seizure)) as `临时查封(份)`")
//                .eq("delete_flag", 0)
//                .between("chg_time", startTime, endTime);
        query.select("COALESCE(sum(inspect_company)) as `检查家次(家)`", "COALESCE(sum( fire_hazard)) as `发现隐患(起)`",
                "COALESCE(sum(rectificate_fire_hazard)) as `整改隐患(起)`", "COALESCE(sum(penalty_amount)) as `处罚金额(万元)`",
                "COALESCE(sum(order_three_stops)) as `责令三停(家)`")
                .eq("delete_flag", 0)
                .between("chg_time", startTime, endTime);
        List<Map<String, Object>> list = this.listMaps(query);
        Map<String, Object> map = new HashMap<>();
        map.put("检查家次(家)",0);
        map.put("发现隐患(起)",0);
        map.put("整改隐患(起)",0);
        map.put("处罚金额(万元)",0);
//        map.put("责令整改(份)",0);
//        map.put("处罚决定书(份)",0);
        map.put("责令三停(家)",0);
//        map.put("临时查封(份)",0);
        if (CollectionUtils.isNotEmpty(list)){
            if (CollectionUtils.isNotEmpty(list.get(0))){
                return list.get(0);
            }else {
                return map;
            }
        }else {
            return map;
        }
    }

}
