package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi.bu3;

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxProdDataPushNotifyStrategyFlagService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesAssistOutAndEnter;
import cn.estsh.i3plus.ext.mes.pojo.model.bu3.SxPushDataNotifyParamAssistModel;
import cn.estsh.i3plus.ext.mes.pojo.model.bu3.SxPushDataNotifyParamModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.pojo.model.platform.PushDataNotifyModel;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wangjie
 * @version 1.0
 * @date 2021/1/13 9:28
 **/
@Slf4j
@Service
public class SxProdDataPushNotifyStrategyAssistThreeService implements ISxProdDataPushNotifyStrategyFlagService {

    @Override
    public List<PushDataNotifyModel> exec(PushDataNotifyModel data, SxPushDataNotifyParamModel pushParam, Object... obj) {

        log.info("生产数据推送通知数据处理 --- SxProdDataPushNotifyStrategyAssistThreeService --- START --- DATA:{} --- THREAD:{}", JSONObject.toJSONString(data), Thread.currentThread().getName());

        SxPushDataNotifyParamAssistModel param = (SxPushDataNotifyParamAssistModel) pushParam;

        List<MesAssistOutAndEnter> dataDbList = (List<MesAssistOutAndEnter>) obj[0];
        dataDbList = CollectionUtils.isEmpty(dataDbList) ? dataDbList : dataDbList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getConfirmDatetime()))).collect(Collectors.toList());

        List<PushDataNotifyModel> resultList = new ArrayList<>();

        LinkedHashMap<String, String> dataMap = new LinkedHashMap<>();
        dataMap.put("月份", Integer.valueOf(param.getInfluenceDate().substring(5, 7)) + "月");
        dataMap.put("责任部门", param.getOwnerDepartmentName());
        dataMap.put("单次", CollectionUtils.isEmpty(dataDbList) ? MesExtConstWords.ZERO_STR : String.valueOf(dataDbList.size()));
        data.addListDing(dataMap).title("援进援出未确认信息统计");

        resultList.add(data);

        log.info("生产数据推送通知数据处理 --- SxProdDataPushNotifyStrategyAssistThreeService --- END --- DATA:{} --- THREAD:{}", JSONObject.toJSONString(data), Thread.currentThread().getName());

        return resultList;
    }

}
