package com.ygtx.gxt.service.impl;

import java.util.List;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ygtx.gxt.domain.GxtWorkOrderFlow;
import com.ygtx.gxt.mapper.GxtWorkOrderFlowMapper;
import com.ygtx.gxt.service.IGxtWorkOrderFlowService;
import com.ygtx.common.core.domain.entity.SysUser;
import com.ygtx.common.utils.SecurityUtils;

/**
 * 维修工单流转记录Service业务层处理
 *
 * @author ygtx
 * @date 2025-10-29
 */
@Service
public class GxtWorkOrderFlowServiceImpl implements IGxtWorkOrderFlowService 
{
    @Autowired
    private GxtWorkOrderFlowMapper gxtWorkOrderFlowMapper;

    /**
     * 查询维修工单流转记录
     *
     * @param id 维修工单流转记录主键
     * @return 维修工单流转记录
     */
    @Override
    public GxtWorkOrderFlow selectGxtWorkOrderFlowById(Long id)
    {
        return gxtWorkOrderFlowMapper.selectGxtWorkOrderFlowById(id);
    }

    /**
     * 查询维修工单流转记录列表
     *
     * @param gxtWorkOrderFlow 维修工单流转记录
     * @return 维修工单流转记录
     */
    @Override
    public List<GxtWorkOrderFlow> selectGxtWorkOrderFlowList(GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        return gxtWorkOrderFlowMapper.selectGxtWorkOrderFlowList(gxtWorkOrderFlow);
    }

    /**
     * 新增维修工单流转记录
     *
     * @param gxtWorkOrderFlow 维修工单流转记录
     * @return 结果
     */
    @Override
    public int insertGxtWorkOrderFlow(GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        gxtWorkOrderFlow.setCreateTime(new Date());
        gxtWorkOrderFlow.setCreateBy(SecurityUtils.getUsername());
        return gxtWorkOrderFlowMapper.insertGxtWorkOrderFlow(gxtWorkOrderFlow);
    }

    /**
     * 修改维修工单流转记录
     *
     * @param gxtWorkOrderFlow 维修工单流转记录
     * @return 结果
     */
    @Override
    public int updateGxtWorkOrderFlow(GxtWorkOrderFlow gxtWorkOrderFlow)
    {
        return gxtWorkOrderFlowMapper.updateGxtWorkOrderFlow(gxtWorkOrderFlow);
    }

    /**
     * 删除维修工单流转记录
     *
     * @param id 维修工单流转记录主键
     * @return 结果
     */
    @Override
    public int deleteGxtWorkOrderFlowById(Long id)
    {
        return gxtWorkOrderFlowMapper.deleteGxtWorkOrderFlowById(id);
    }

    /**
     * 批量删除维修工单流转记录
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    @Override
    public int deleteGxtWorkOrderFlowByIds(Long[] ids)
    {
        return gxtWorkOrderFlowMapper.deleteGxtWorkOrderFlowByIds(ids);
    }

    /**
     * 根据工单ID查询流转记录列表
     *
     * @param orderId 工单ID
     * @return 流转记录集合
     */
    @Override
    public List<GxtWorkOrderFlow> selectGxtWorkOrderFlowByOrderId(Long orderId)
    {
        return gxtWorkOrderFlowMapper.selectGxtWorkOrderFlowByOrderId(orderId);
    }

    /**
     * 记录工单流转
     *
     * @param orderId 工单ID
     * @param orderCode 工单编码
     * @param actionType 操作类型
     * @param fromStatus 原状态
     * @param toStatus 目标状态
     * @param operatorId 操作人ID
     * @param operatorName 操作人姓名
     * @param actionRemark 操作备注
     * @return 结果
     */
    @Override
    public int recordWorkOrderFlow(Long orderId, String orderCode, String actionType, String fromStatus, String toStatus, Long operatorId, String operatorName, String actionRemark)
    {
        GxtWorkOrderFlow flow = new GxtWorkOrderFlow();
        flow.setOrderId(orderId);
        flow.setOrderCode(orderCode);
        flow.setActionType(actionType);
        flow.setFromStatus(fromStatus);
        flow.setToStatus(toStatus);
        flow.setOperatorId(operatorId);
        flow.setOperatorName(operatorName);
        flow.setActionTime(new Date());
        flow.setActionRemark(actionRemark);
        return insertGxtWorkOrderFlow(flow);
    }
}
