package com.zcloud.service.dynamicAssessment.impl;

import com.google.common.collect.Lists;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.mapper.datasource.check.CheckRecordMapper;
import com.zcloud.mapper.datasource.check.ListCheckItemMapper;
import com.zcloud.mapper.datasource.check.ListManagerMapper;
import com.zcloud.mapper.datasource.dynamicAssessment.ReportDataMapper;
import com.zcloud.mapper.datasource.dynamicAssessment.ReportLogMapper;
import com.zcloud.mapper.datasource.dynamicAssessment.ReportMapper;
import com.zcloud.mapper.datasource.hidden.HiddenMapper;
import com.zcloud.mapper.datasource.risk.RiskPointMapper;
import com.zcloud.mapper.datasource.risk.RiskUnitMapper;
import com.zcloud.service.dynamicAssessment.ReportService;
import com.zcloud.service.system.DictionariesService;
import com.zcloud.util.DateUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.Warden;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 说明：报表模板
 * 作者：luoxiaobao
 * 时间：2023-04-24
 * 官网：www.zcloudchina.com
 */
@Service
@Transactional //开启事物
public class ReportServiceImpl implements ReportService {

    @Resource
    private ReportMapper reportMapper;

    @Resource
    private ReportLogMapper reportLogMapper;

    @Resource
    private ReportDataMapper reportDataMapper;

    /**
     * 新增
     *
     * @param pd
     * @throws Exception
     */
    public void save(PageData pd) throws Exception {
        reportMapper.save(pd);
    }

    /**
     * 删除
     *
     * @param pd
     * @throws Exception
     */
    public void delete(PageData pd) throws Exception {
        reportMapper.delete(pd);
    }

    /**
     * 修改
     *
     * @param pd
     * @throws Exception
     */
    public void edit(PageData pd) throws Exception {
        reportMapper.edit(pd);
    }

    /**
     * 列表
     *
     * @param page
     * @throws Exception
     */
    public List<PageData> list(Page page) throws Exception {
        return reportMapper.datalistPage(page);
    }

    /**
     * 列表(全部)
     *
     * @param pd
     * @throws Exception
     */
    public List<PageData> listAll(PageData pd) throws Exception {
        return reportMapper.listAll(pd);
    }

    /**
     * 通过id获取数据
     *
     * @param pd
     * @throws Exception
     */
    public PageData findById(PageData pd) throws Exception {
        return reportMapper.findById(pd);
    }

    /**
     * 批量删除
     *
     * @param ArrayDATA_IDS
     * @throws Exception
     */
    public void deleteAll(String[] ArrayDATA_IDS) throws Exception {
        reportMapper.deleteAll(ArrayDATA_IDS);
    }

    @Override
    public Map<String, Object> getForm(PageData request) throws Exception {
        Map<String, Object> map = new HashMap<>();
        PageData condition = new PageData();
        condition.put("FROM_ID", "b3ac1ba6d1fe4af29c40215a1d1ae3fc");
        List<PageData> _list = reportMapper.findByCondition(condition);
        List<List<PageData>> list = _list.stream()
                .collect(Collectors.groupingBy(n -> n.getString("SORT")))
                .values().stream()
                .sorted(Comparator.comparing(o -> new BigDecimal(o.get(0).getString("SORT"))))
                .collect(Collectors.toList());
        if (StringUtils.isNotBlank(request.getString("REPORT_LOG_ID"))) {
            condition.clear();
            condition.put("REPORT_LOG_ID", request.getString("REPORT_LOG_ID"));
            PageData log = reportLogMapper.findById(condition);
            if (log == null || log.size() <= 0) throw new RuntimeException("数据异常");
            map.put("log", log);

            List<PageData> data = reportDataMapper.findByMainId(condition);
            if (data != null && data.size() > 0) {
                Map<String, List<PageData>> data_map = data.stream().collect(Collectors.groupingBy(o -> o.getString("REPORT_ID")));
                for (List<PageData> x : list) {
                    for (PageData y : x) {
                        List<PageData> z = data_map.get(y.getString("REPORT_ID"));
                        if (z != null && z.size() > 0) {
                            y.put("DESCRITPTION", z.get(0).getString("DESCRITPTION"));
                        }
                    }
                }
            }
        } else {
            List<PageData> raw = _list.stream().filter(n -> "1".equals(n.getString("AUTOMATIC_FLAG"))).collect(Collectors.toList());
            for (PageData x : raw) {
                PageData info = getInfo(x);
                for (PageData y : _list) {
                    if (x.getString("REPORT_ID").equals(y.getString("REPORT_ID"))) {
                        x.put("DESCRITPTION", info.getString("score"));
                        break;
                    }
                }
            }
            list = _list.stream()
                    .collect(Collectors.groupingBy(n -> n.getString("SORT")))
                    .values().stream()
                    .sorted(Comparator.comparing(o -> new BigDecimal(o.get(0).getString("SORT"))))
                    .collect(Collectors.toList());
        }
        map.put("list", list);
        return map;
    }

    PageData getInfo(PageData x) throws Exception {
        PageData condition = new PageData();
        condition.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        condition.put("YEAR", Warden.getThisYear());
        switch (x.getString("REPORT_ID")) {
            case "119":
                List<PageData> _info = reportMapper.findTemplateOne(condition);
                PageData info = new PageData();
                int score = 2;
                for (PageData x_info : _info) {
                    if (1 > Integer.parseInt(x_info.get("score").toString())) {
                        score--;
                    }
                }
                if (score < 0) {
                    score = 0;
                }
                info.put("score", score + "");
                return info;
            case "128":
                return reportMapper.findTemplateTwo(condition);
            default:
                return new PageData();
        }
    }

    @Override
    public void init(PageData request) throws Exception {

        PageData info;
        if (StringUtils.isNotBlank(request.getString("info"))) {
            info = Warden.getPageData(request.getString("info"));
        } else {
            info = new PageData();
            info.put("REPORT_LOG_ID", "");
        }
        PageData condition = new PageData();
        PageData entity = new PageData();
        if (StringUtils.isEmpty(info.getString("REPORT_LOG_ID"))) {
            condition.put("YEAR", Warden.getThisYear());
            List<PageData> rule = reportLogMapper.findByCondition(condition);
            Warden.initDate(entity);
            entity.put("REPORT_LOG_ID", Warden.get32UUID());
            entity.put("REPORT_FORM_ID", "b3ac1ba6d1fe4af29c40215a1d1ae3fc");
            entity.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
            entity.put("DEPARTMENT_ID", Jurisdiction.getDEPARTMENT_ID());
            entity.put("YEAR", Warden.getThisYear());
            reportLogMapper.save(entity);
        } else {
            entity.putAll(info);
            Warden.updateDate(entity);
            reportLogMapper.edit(entity);

            condition.clear();
            condition.put("REPORT_LOG_ID", entity.getString("REPORT_LOG_ID"));
            reportDataMapper.deleteByMainId(condition);
        }

        List<PageData> list = Warden.getList(request.getString("list"));

        for (PageData ent : list) {
            PageData x = new PageData();
            x.putAll(ent);
            x.put("RREPORT_DATA_ID", Warden.get32UUID());
            x.put("REPORT_LOG_ID", entity.getString("REPORT_LOG_ID"));
            x.put("REPORT_FORM_ID", "b3ac1ba6d1fe4af29c40215a1d1ae3fc");
            x.put("DESCRITPTION", ent.get("DESCRITPTION") == null?"":ent.get("DESCRITPTION").toString());
            x.put("REPORT_ID", ent.getString("REPORT_ID"));
            reportDataMapper.save(x);
        }

    }

    @Override
    public Map<String, Object> getList(PageData request, Page page) throws Exception {
        PageData condition = new PageData();
        condition.put("YEAR", request.getString("YEAR"));
        condition.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        page.setPd(condition);
        List<PageData> list = reportLogMapper.datalistPage(page);

        Map<String, Object> map = new HashMap<>();
        map.put("list", list);

        map.put("page", page);
        return map;
    }

    @Resource
    private RiskPointMapper riskPointMapper;

    @Resource
    private ListCheckItemMapper listCheckItemMapper;

    @Resource
    private ListManagerMapper listManagerMapper;

    @Resource
    private CheckRecordMapper checkRecordMapper;

    @Resource
    private DictionariesService dictionariesService;

    @Resource
    private HiddenMapper hiddenMapper;

    @Resource
    private RiskUnitMapper riskUnitMapper;

    @Override
    public Map<String, Object> getBaoBaoReport(Page page, PageData request) throws Exception {
        Map<String, Object> map = new HashMap<>();

        PageData condition = new PageData();
        condition.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
        condition.put("NAME", request.getString("NAME"));
        condition.put("KEYWORDS",request.getString("NAME"));
        condition.put("isBaoBao", "1");
        page.setPd(condition);
        //1、查询出风险点
        List<PageData> raw_list = riskUnitMapper.datalistPage(page);
        List<String> riskUnitIds = raw_list.stream().map(n -> n.getString("RISKUNIT_ID")).collect(Collectors.toList());

        List<PageData> list = new ArrayList<>();
        for (PageData riskUnit : raw_list) {
            //2.1 将所有的风险点找出所有台账查出
            condition.clear();
            condition.put("RISK_UNIT_ID", riskUnit.getString("RISKUNIT_ID"));
            List<PageData> _riskPoints = riskPointMapper.getInfo(condition);
            if (_riskPoints.size() == 0) {
                list.add(nullEntity(riskUnit));
                continue;
            }
            List<String> riskPoints = _riskPoints.stream().map(n -> n.getString("RISKPOINT_ID")).collect(Collectors.toList());
            List<PageData> _list_manager_raw = new ArrayList<>();
            if (riskPoints.size() < 500) {
                condition.put("riskPoints", riskPoints);
                _list_manager_raw = listCheckItemMapper.findByRiskPointId(condition);
            } else {
                List<List<String>> ids = Lists.partition(riskPoints, 500);
                for (List<String> _ids : ids) {
                    condition.put("riskPoints", _ids);
                    _list_manager_raw.addAll(listCheckItemMapper.findByRiskPointId(condition));
                    condition.clear();
                }
            }

            if (_list_manager_raw.size() == 0) {
                list.add(nullEntity(riskUnit));
                continue;
            }

            // 2.2 查出所有相关的清单
            List<String> _list_manager = _list_manager_raw.stream().map(n -> n.getString("LISTMANAGER_ID")).distinct().collect(Collectors.toList());
            PageData util = new PageData();
            util.put("BAO_BAO_TYPE", "1");
            List<String> list_manager_ids;
            if (_list_manager.size() < 500) {
                util.put("ids", _list_manager);
                List<PageData> _list_managers = listManagerMapper.findByCondition(util);
                list_manager_ids = _list_managers.stream().map(n -> n.getString("LISTMANAGER_ID")).collect(Collectors.toList());
            } else {
                List<PageData> _list_managers = new ArrayList<>();
                List<List<String>> ids = Lists.partition(_list_manager, 500);
                for (List<String> _ids : ids) {
                    util.put("ids", _ids);
                    List<PageData> part = listManagerMapper.findByCondition(util);
                    _list_managers.addAll(part);
                }
                list_manager_ids = _list_managers.stream().map(n -> n.getString("LISTMANAGER_ID")).distinct().collect(Collectors.toList());
            }
            if (list_manager_ids.size() == 0) {
                list.add(nullEntity(riskUnit));
                continue;
            }

            // 获取清单执行次数总数
            List<PageData> result_all = analysis(list_manager_ids, "");
            // 获取清单执行已完成数
            List<PageData> result_finish = analysis(list_manager_ids, "1");
            //2.3 根据清单列表统计隐患数
            util.clear();
            PageData hidden_info;
            if (list_manager_ids.size() < 500) {
                util.put("ids", list_manager_ids);
                util.put("RISK_UNIT",riskUnit.getString("RISKUNITNAME"));
                List<PageData> hidden = hiddenMapper.anaysis(util);
                hidden_info = getSum(hidden);
            } else {
                List<List<String>> ids = Lists.partition(list_manager_ids, 500);
                hidden_info = new PageData();
                for (List<String> _ids : ids) {
                    util.put("ids", _ids);
                    List<PageData> part = hiddenMapper.anaysis(util);
                    if (hidden_info.size() == 0) {
                        hidden_info.putAll(getSum(part));
                    } else {
                        PageData info = getSum(part);
                        hidden_info.put("1", (Long) hidden_info.get("1") + (Long) info.get("1"));
                        hidden_info.put("0", (Long) hidden_info.get("0") + (Long) info.get("0"));
                    }
                }
            }

            //3、组织结果
            PageData entity = new PageData();
            //重大危险源名称
            entity.put("RISKUNITNAME", riskUnit.get("RISKUNITNAME"));

            long all_completion = result_finish.stream().mapToLong(n -> (Long) n.get("num")).sum();
            BigDecimal rate;
            if (all_completion == 0) {
                rate = BigDecimal.ZERO;
            } else {
                long all = result_all.stream().mapToLong(n -> (Long) n.get("num")).sum();
                rate = new BigDecimal(all_completion).divide(new BigDecimal(all), 2, RoundingMode.HALF_UP);
            }

            //总排查任务-完成任务数
            entity.put("all", all_completion);
            // 总排查任务-完成率
            entity.put("all_completion_rate", rate);

            //主要负责人-完成任务数
            Optional<PageData> mainPeople_completion = result_finish.stream().filter(n -> "7802cb11b98949f685ed581c33514c98".equals(n.getString("TASK_TYPE"))).findFirst();
            if (mainPeople_completion.isPresent()) {
                entity.put("mainPeople", mainPeople_completion.get().get("num"));
            } else {
                entity.put("mainPeople", 0L);
            }
            if ((Long) entity.get("mainPeople") == 0) {
                entity.put("mainPeople_rate", 0);
            } else {
                //主要负责人-完成率
                Optional<PageData> mainPeople_all = result_all.stream().filter(n -> "7802cb11b98949f685ed581c33514c98".equals(n.getString("TASK_TYPE"))).findFirst();
                if (mainPeople_all.isPresent()) {
                    BigDecimal mainPeople_rate = new BigDecimal((Long) entity.get("mainPeople")).divide(new BigDecimal((Long) mainPeople_all.get().get("num")), 2, RoundingMode.HALF_UP);
                    entity.put("mainPeople_rate", mainPeople_rate.doubleValue());
                } else {
                    entity.put("mainPeople_rate", 0);
                }
            }

            //技术负责人-完成任务数
            Optional<PageData> technicalDirector_completion = result_finish.stream().filter(n -> "6834bc080bbe4d749c8776d2af596c2c".equals(n.getString("TASK_TYPE"))).findFirst();
            if (technicalDirector_completion.isPresent()) {
                entity.put("technicalDirector", technicalDirector_completion.get().get("num"));
            } else {
                entity.put("technicalDirector", 0L);
            }
            if ((Long) entity.get("technicalDirector") == 0) {
                entity.put("technicalDirector_rate", 0);
            } else {
                //技术负责人-完成率
                Optional<PageData> technicalDirector_all = result_all.stream().filter(n -> "6834bc080bbe4d749c8776d2af596c2c".equals(n.getString("TASK_TYPE"))).findFirst();
                if (technicalDirector_all.isPresent()) {
                    BigDecimal technicalDirector_rate = new BigDecimal((Long) entity.get("technicalDirector")).divide(new BigDecimal((Long) technicalDirector_all.get().get("num")), 2, RoundingMode.HALF_UP);
                    entity.put("technicalDirector_rate", technicalDirector_rate.doubleValue());
                } else {
                    entity.put("technicalDirector_rate", 0);
                }
            }

            //操作负责人-完成任务数
            Optional<PageData> operations_completion = result_finish.stream().filter(n -> "e86095f09e67446f927b447337940ecf".equals(n.getString("TASK_TYPE"))).findFirst();
            if (operations_completion.isPresent()) {
                entity.put("operations", operations_completion.get().get("num"));
            } else {
                entity.put("operations", 0.0);
            }
            if ((Long) entity.get("operations") == 0) {
                entity.put("operations_rate", 0);
            } else {
                //操作负责人-完成率
                Optional<PageData> operations_all = result_all.stream().filter(n -> "e86095f09e67446f927b447337940ecf".equals(n.getString("TASK_TYPE"))).findFirst();
                if (operations_all.isPresent()) {
                    BigDecimal mainPeople_rate = new BigDecimal((Long) entity.get("operations")).divide(new BigDecimal((Long) operations_all.get().get("num")), 2, RoundingMode.HALF_UP);
                    entity.put("operations_rate", mainPeople_rate.doubleValue());
                } else {
                    entity.put("operations_rate", 0);
                }
            }

            // 隐患数量-发现隐患数量
            entity.put("hidden_all", hidden_info.get("0"));
            // 隐患数量-完成整改数量
            entity.put("hidden_completion", hidden_info.get("1"));

            list.add(entity);

        }
        condition.clear();
        condition.put("baoBaoFlag", "1");
        condition.put("riskUnitIds", riskUnitIds);

        map.put("page", page);
        map.put("list", list);
        return map;
    }

    private PageData nullEntity(PageData riskPoint) {
        PageData entity = new PageData();
        entity.put("RISKUNITNAME", riskPoint.getString("RISKUNITNAME"));
        entity.put("all", 0);
        entity.put("all_completion_rate", 0);
        entity.put("hidden_all", 0);
        entity.put("hidden_completion", 0);
        entity.put("mainPeople", 0);
        entity.put("mainPeople_rate", 0);
        entity.put("operations", 0);
        entity.put("operations_rate", 0);
        entity.put("technicalDirector", 0);
        entity.put("technicalDirector_rate", 0);
        return entity;
    }

    private List<PageData> analysis(List<String> list_manager_ids, String finishFlag) throws Exception {
        List<String> title = Arrays.asList("7802cb11b98949f685ed581c33514c98", "6834bc080bbe4d749c8776d2af596c2c", "e86095f09e67446f927b447337940ecf","d6f34dd36cca49468dd728df2445f5ae");
        List<String> _list = list_manager_ids.stream().distinct().collect(Collectors.toList());

        PageData condition = new PageData();
        List<PageData> result = new ArrayList<>();
        List<PageData> list = new ArrayList<>();
        if (_list.size() < 500) {
            condition.put("ids", _list);
            condition.put("BAO_BAO_TYPE", "1");
            list = listManagerMapper.findByCondition(condition);
        } else {
            List<List<String>> ids = Lists.partition(_list, 500);
            for (List<String> _ids : ids) {
                condition.put("ids", _ids);
                condition.put("BAO_BAO_TYPE", "1");
                list.addAll(listManagerMapper.findByCondition(condition));
                condition.clear();
            }
        }
        // 计算今年总数
        if ("1".equals(finishFlag)) {
            for (String vector : title) {
                PageData total = new PageData();
                if (list.size() <= 500) {
                    condition.put("date", Warden.getThisYear());
                    condition.put("ids", list.stream().map(n -> n.getString("LISTMANAGER_ID")).collect(Collectors.toList()));
                    condition.put("BAO_BAO_TYPE", "1");
                    condition.put("TASK_TYPE", vector);
                    total = checkRecordMapper.findByNumber(condition);
                } else {
                    total.put("num", 0L);
                    List<List<PageData>> ids = Lists.partition(list, 500);
                    for (List<PageData> _ids : ids) {
                        condition.put("date", Warden.getThisYear());
                        condition.put("ids", _ids.stream().map(n -> n.getString("LISTMANAGER_ID")).collect(Collectors.toList()));
                        condition.put("BAO_BAO_TYPE", "1");
                        condition.put("TASK_TYPE", vector);
                        PageData _total = checkRecordMapper.findByNumber(condition);
                        total.put("num", (Long) total.get("num") + (Long) _total.get("num"));
                        condition.clear();
                    }
                }
                PageData entity = new PageData();
                entity.put("TASK_TYPE", vector);
                entity.put("num", total.get("num"));
                result.add(entity);
            }
        } else {
            for (String vector : title) {
                PageData entity = new PageData();
                // 每日
                List<PageData> day = list.stream()
                        .filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0001".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int one = 0;
                for (PageData _day : day) {
                    Date _date = DateUtil.fomatDateTime(_day.getString("CREATTIME"));
                    Date date = DateUtil.fomatDate(DateUtil.date2Str(_date,"yyyy-MM-dd"));
                    if (Warden.getThisYear().equals(DateUtil.getYear(date))) {
                        one += Warden.getLimitDate(date);
                    } else {
                        one += Warden.getLimitDate();
                    }
                }

                // 每周
                List<PageData> week = list.stream()
                        .filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0002".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int two = 0;
                for (PageData _day : week) {
                    Date date = DateUtil.fomatDateTime(_day.getString("CREATTIME"));
                    if (Warden.getThisYear().equals(DateUtil.getYear(date))) {
                        two += Warden.getLimitDate(date) / 7 + Warden.getLimitDate(date) % 7 > 0 ? 1 : 0;
                    } else {
                        two += Warden.getLimitDate() / 7 + Warden.getLimitDate() % 7 > 0 ? 1 : 0;
                    }
                }
                // 每旬
                List<PageData> Ten_day = list.stream()
                        .filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0003".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int three = 0;
                for (PageData _day : Ten_day) {
                    Date date = DateUtil.fomatDateTime(_day.getString("CREATTIME"));
                    if (Warden.getThisYear().equals(DateUtil.getYear(date))) {
                        three += Warden.getLimitDate(date) / 10 + Warden.getLimitDate(date) % 10 > 0 ? 1 : 0;
                    } else {
                        three += Warden.getLimitDate() / 10 + Warden.getLimitDate() % 10 > 0 ? 1 : 0;
                    }
                }
                // 每月
                List<PageData> month = list.stream().
                        filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0004".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int four = 0;
                for (PageData _day : month) {
                    Date date = DateUtil.fomatDateTime(_day.getString("CREATTIME"));
                    if (Warden.getThisYear().equals(DateUtil.getYear(date))) {
                        four += Warden.getLimitDate(date) / 30 + Warden.getLimitDate(date) % 30 > 0 ? 1 : 0;
                    } else {
                        four += Warden.getLimitDate() / 30 + Warden.getLimitDate() % 30 > 0 ? 1 : 0;
                    }
                }
                // 每季
                List<PageData> season = list.stream()
                        .filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0005".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int five = 0;
                for (PageData _day : season) {
                    Date date = DateUtil.fomatDateTime(_day.getString("CREATTIME"));
                    if (Warden.getThisYear().equals(DateUtil.getYear(date))) {
                        five += Warden.getLimitDate(date) / 91 + Warden.getLimitDate(date) % 91 > 0 ? 1 : 0;
                    } else {
                        five += Warden.getLimitDate() / 91 + Warden.getLimitDate() % 91 > 0 ? 1 : 0;
                    }
                }
                // 每年
                List<PageData> year = list.stream()
                        .filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0006".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int six = year.size();
                // 半年
                List<PageData> half_year = list.stream()
                        .filter(n -> vector.equals(n.getString("TASK_TYPE")))
                        .filter(n -> "checkPeriod0007".equals(n.getString("PERIOD")))
                        .collect(Collectors.toList());
                int seven = 0;
                for (PageData _day : half_year) {
                    Date date = DateUtil.fomatDateTime(_day.getString("CREATTIME"));
                    if (Warden.getThisYear().equals(DateUtil.getYear(date))) {
                        seven += Warden.getLimitDate(date) / 183 + Warden.getLimitDate(date) % 183 > 0 ? 1 : 0;
                    } else {
                        seven += Warden.getLimitDate() / 183 + Warden.getLimitDate() % 183 > 0 ? 1 : 0;
                    }
                }

                int total = one + two + three + four + five + six + seven;
                entity.put("TASK_TYPE", vector);
                entity.put("num", (long) total);
                result.add(entity);
            }

        }
        return result;
    }

    private PageData getSum(List<PageData> entity) throws Exception {
        PageData bread = new PageData();
        bread.put("1", 0);
        Long num = 0L;
        for (PageData x : entity) {
            num += (Long) x.get("num");
            if ("4".equals(x.getString("STATE"))) {
                if (x.get("num") == null) {
                    bread.put("1", 0L);
                } else {
                    bread.put("1", x.get("num"));
                }
            }
        }
        bread.put("0", num);
        return bread;
    }

}

