package com.cool.store.dao.modify;

import com.cool.store.entity.modify.ModifyRecordDO;
import com.cool.store.enums.BusinessModuleEnum;
import com.cool.store.mapper.modify.ModifyRecordMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 业务修改记录DAO
 *
 * @author system
 */
@Repository
@RequiredArgsConstructor
public class ModifyRecordDAO {
    private final ModifyRecordMapper modifyRecordMapper;

    /**
     * 新增修改记录
     * @param module 业务模块
     * @param businessId 业务id
     * @param updateUserId 更新人id
     */
    public void insertRecord(BusinessModuleEnum module, Long businessId, String updateUserId) {
        ModifyRecordDO modifyRecord = new ModifyRecordDO(null, module.getCode(), businessId, updateUserId, null);
        modifyRecordMapper.insertSelective(modifyRecord);
    }

    /**
     * 根据模块及业务id查询
     * @param module 模块code
     * @param businessId 业务id
     * @return 记录列表
     */
    public List<ModifyRecordDO> getListByBusinessId(String module, Long businessId) {
        Example example = new Example(ModifyRecordDO.class);
        example.createCriteria()
                .andEqualTo("module", module)
                .andEqualTo("businessId", businessId);
        example.setOrderByClause("update_time desc");
        return modifyRecordMapper.selectByExample(example);
    }
}

