package com.jeesharp.business.modules.mall.service.impl;

import com.jeesharp.business.modules.mall.entity.MallOrderLog;
import com.jeesharp.business.modules.mall.mapper.MallOrderLogMapper;
import com.jeesharp.business.modules.mall.service.MallOrderLogService;
import com.jeesharp.business.modules.mall.vo.MallOrderLogQueryVO;
import com.jeesharp.framework.mybatis.core.service.CrudService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 订单状态日志 Service 实现类
 */
@Service
@Transactional(readOnly = true)
public class MallOrderLogServiceImpl extends CrudService<MallOrderLogMapper, MallOrderLog, MallOrderLogQueryVO> implements MallOrderLogService {

    private static final String IDS_SEPARATOR = ",";

    @Override
    @Transactional(readOnly = false)
    public void createOrderLog(MallOrderLog entity) {
        save(entity);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateOrderLog(MallOrderLog entity) {
        update(entity);
    }

    @Override
    @Transactional(readOnly = false)
    public void recordOrderStatusChange(String orderId, String orderNo, Integer beforeStatus,
                                        Integer afterStatus, String operateType, String operatorId,
                                        String operatorName, String remark) {
        MallOrderLog log = new MallOrderLog();
        log.setOrderId(orderId);
        log.setOrderNo(orderNo);
        log.setBeforeStatus(beforeStatus);
        log.setAfterStatus(afterStatus);
        log.setOperateType(operateType);
        log.setOperatorId(operatorId);
        log.setOperatorName(operatorName);
        log.setOperateTime(new Date());
        log.setRemark(remark);
        createOrderLog(log);
    }

    @Override
    public List<MallOrderLog> getOrderLogs(String orderId) {
        MallOrderLogQueryVO query = new MallOrderLogQueryVO();
        query.setOrderId(orderId);
        return findList(query);
    }
}
