package com.yeejoin.amos.boot.module.jg.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import com.yeejoin.amos.boot.module.jg.biz.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 批量维护使用登记策略实现类
 */
@Component
public class BatchDataChangeProcessStrategy implements IChangeDataProcessStrategy {

    @Override
    public Map<String, List<ChangeDataDto>> handle(List<Map<String, Object>> changeData, String defaultChangeId) {
        List<ChangeDataDto> changeDataDtos = BeanUtil.copyToList(changeData, ChangeDataDto.class);
        changeDataDtos = changeDataDtos.stream().filter(c -> !StringUtils.equals(c.getColumnNewValue(), c.getColumnOldValue())).collect(Collectors.toList());
        return changeDataDtos.stream().collect(Collectors.groupingBy(ChangeDataDto::getChangeId));
    }

    @Override
    public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
        return IBizDataChangeHandleStrategy.ModelType.batch;
    }
}
