package com.mortals.xhx.module.window.service.impl;
import com.mortals.xhx.module.window.model.WindowPerformSummaryQuery;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.function.Function;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.window.dao.WindowPerformSummaryDao;
import com.mortals.xhx.module.window.model.WindowPerformSummaryEntity;
import com.mortals.xhx.module.window.service.WindowPerformSummaryService;
import lombok.extern.slf4j.Slf4j;
/**
* WindowPerformSummaryService
* 窗口绩效汇总登记 service实现
*
* @author zxfei
* @date 2025-03-10
*/
@Service("windowPerformSummaryService")
@Slf4j
public class WindowPerformSummaryServiceImpl extends AbstractCRUDServiceImpl<WindowPerformSummaryDao, WindowPerformSummaryEntity, Long> implements WindowPerformSummaryService {

    @Override
    public void initWindowPerformSummary(int year, int month) {

        List<WindowPerformSummaryEntity> addList = new ArrayList<>();
        String[] depts = {"市公安局出入境管理支队", "市医保局", "市人力资源社会保障局", "市住房公积金中心叙州区管理部", "市应急管理局", "市公安局交警支队", "市市场监管局", "市不动产登记中心", "市交通运输局", "市住房城乡建设局", "市自然资源规划局", "市水利局", "宜宾市税务局", "宜宾市消防救援支队", "叙州区住房保障和房地产事务中心", "市民政局", "市生态环境局", "市卫生健康委", "市司法局", "市公安局治安（户政）支队", "市国动办", "市发展改革委", "中行宜宾叙府支行", "邮政公司叙州区分公司", "市合力公证处", "宜宾市商业银行", "市气象局", "国网叙州供电分公司", "市文广旅游局", "市退役军人局", "市商务局", "市科技局", "市邮政管理局", "市烟草专卖局", "市教育体育局", "市地震监测中心", "市委统战部（市民宗局、市侨务办）", "市宣传部（市新闻出版局﹤市版权局﹥）", "市委办（市档案局)", "市委编办", "市经济和信息化局", "市竹业林业局", "市农业农村局", "市残联", "市财政局", "市中医药管理局", "宜宾华润燃气有限公司", "宜宾农村商业银行", "市金融工作局"};
        for(String deptName:depts){
            WindowPerformSummaryEntity entity = new WindowPerformSummaryEntity();
            entity.initAttrValue();
            entity.setYear(year);
            entity.setMonth(month);
            entity.setDeptName(deptName);
            entity.setCreateTime(new Date());
            entity.setCreateUserId(1L);
            addList.add(entity);
        }
        this.save(addList);
    }

    @Override
    protected void validData(WindowPerformSummaryEntity entity, Context context) throws AppException {
        BigDecimal sum = BigDecimal.ZERO;
        if(entity.getCkjsdf()!=null){
            sum = sum.add(entity.getCkjsdf());
        }
        if(entity.getZdrwdf()!=null){
            sum = sum.add(entity.getZdrwdf());
        }
        if(entity.getAddTotalScore()!=null){
            sum = sum.add(entity.getAddTotalScore());
        }
        entity.setSumScore(sum);
    }
}