package com.cool.store.service.modify.impl;

import cn.hutool.core.collection.CollStreamUtil;
import com.cool.store.dao.EnterpriseUserDAO;
import com.cool.store.dao.modify.ModifyRecordDAO;
import com.cool.store.entity.modify.ModifyRecordDO;
import com.cool.store.service.modify.ModifyRecordService;
import com.cool.store.vo.modify.ModifyRecordVO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 业务修改记录 服务实现类
 * </p>
 *
 * @author wangff
 * @since 2026/1/27
 */
@Service
@RequiredArgsConstructor
public class ModifyRecordServiceImpl implements ModifyRecordService {
    private final ModifyRecordDAO modifyRecordDAO;
    private final EnterpriseUserDAO enterpriseUserDAO;

    @Override
    public List<ModifyRecordVO> getModifyRecorsList(String module, Long businessId) {
        List<ModifyRecordDO> list = modifyRecordDAO.getListByBusinessId(module, businessId);
        Set<String> userIds = CollStreamUtil.toSet(list, ModifyRecordDO::getUpdateUserId);
        Map<String, String> userNameMap = enterpriseUserDAO.getUserNameMap(new ArrayList<>(userIds));
        return CollStreamUtil.toList(list, v -> new ModifyRecordVO(userNameMap.get(v.getUpdateUserId()), v.getUpdateTime()));
    }
}
