package com.cool.store.service.impl;

import com.cool.store.dao.TransferLogDAO;
import com.cool.store.dto.TransferLogDTO;
import com.cool.store.entity.LineInfoDO;
import com.cool.store.entity.TransferLogDO;
import com.cool.store.enums.OperationLogTypeEnum;
import com.cool.store.service.TransferLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author suzhuhong
 * @Date 2024/3/29 18:11
 * @Version 1.0
 */
@Service
public class TransferLogServiceImpl implements TransferLogService {

    @Resource
    private TransferLogDAO transferLogDAO;

    @Override
    public void addLog(LineInfoDO lineInfoDO, String formUserId, String toUserId, OperationLogTypeEnum operationLogTypeEnum) {
        TransferLogDO transferLogDO = new TransferLogDO();
        transferLogDO.setLineId(lineInfoDO.getId());
        transferLogDO.setPartnerId(lineInfoDO.getPartnerId());
        transferLogDO.setFromUserId(formUserId);
        transferLogDO.setToUserId(toUserId);
        transferLogDO.setType(operationLogTypeEnum.getCode());
        transferLogDO.setCreateUserId("create");
        transferLogDO.setUpdateUserId("update");
        // 添加操作日志
        transferLogDAO.add(transferLogDO);
    }

    @Override
    public PageInfo<TransferLogDTO> getTransferLogPage(Integer pageNum, Integer pageSize, Long lineId) {
        PageHelper.startPage(pageNum, pageSize);
        List<TransferLogDTO> transferLogList = transferLogDAO.getTransferLogList(lineId);
        PageInfo<TransferLogDTO> transferLogDTOPageInfo = new PageInfo<>(transferLogList);
        return transferLogDTOPageInfo;
    }
}
