package com.hw.dms.service.impl;

import java.util.List;
import com.hw.common.core.utils.DateUtils;
import com.hw.dms.domain.DmsRepairInstanceActivity;
import com.hw.dms.mapper.DmsRepairInstanceActivityMapper;
import com.hw.dms.service.IDmsRepairInstanceActivityService;
import com.hw.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hw.dms.mapper.DmsBillsFaultInstanceMapper;
import com.hw.dms.domain.DmsBillsFaultInstance;
import com.hw.dms.service.IDmsBillsFaultInstanceService;

/**
 * 报修工单Service业务层处理
 *
 * @author Open Platform
 * @date 2024-01-23
 */
@Service
public class DmsBillsFaultInstanceServiceImpl implements IDmsBillsFaultInstanceService
{
    @Autowired
    private DmsBillsFaultInstanceMapper dmsBillsFaultInstanceMapper;
    @Autowired
    private DmsRepairInstanceActivityMapper dmsRepairInstanceActivityMapper;

    /**
     * 查询报修工单
     *
     * @param repairInstanceId 报修工单主键
     * @return 报修工单
     */
    @Override
    public DmsBillsFaultInstance selectDmsBillsFaultInstanceByRepairInstanceId(Long repairInstanceId)
    {
        return dmsBillsFaultInstanceMapper.selectDmsBillsFaultInstanceByRepairInstanceId(repairInstanceId);
    }

    /**
     * 查询报修工单列表
     *
     * @param dmsBillsFaultInstance 报修工单
     * @return 报修工单
     */
    @Override
    public List<DmsBillsFaultInstance> selectDmsBillsFaultInstanceList(DmsBillsFaultInstance dmsBillsFaultInstance)
    {
        return dmsBillsFaultInstanceMapper.selectDmsBillsFaultInstanceList(dmsBillsFaultInstance);
    }

    /**
     * 新增报修工单
     *
     * @param dmsBillsFaultInstance 报修工单
     * @return 结果
     */
    @Override
    public int insertDmsBillsFaultInstance(DmsBillsFaultInstance dmsBillsFaultInstance)
    {
        LoginUser user = new LoginUser();
        int flag = dmsBillsFaultInstanceMapper.insertDmsBillsFaultInstance(dmsBillsFaultInstance);
        //新增报修工单时创建工单实例节点
        DmsRepairInstanceActivity dmsRepairInstanceActivity = new DmsRepairInstanceActivity();
        dmsRepairInstanceActivity.setRepairInstanceId(dmsBillsFaultInstance.getRepairInstanceId());
        //先写死只有两步/三步，后期进行更改
        dmsRepairInstanceActivity.setProcessActivityId(1l);
        dmsRepairInstanceActivity.setProcessHandleStatus("1");
        dmsRepairInstanceActivity.setProcessStepOrder(1l);
        dmsRepairInstanceActivity.setCreateBy(user.getUsername());
        dmsRepairInstanceActivity.setCreateTime(DateUtils.getNowDate());

        dmsRepairInstanceActivityMapper.insertDmsRepairInstanceActivity(dmsRepairInstanceActivity);

        dmsBillsFaultInstance.setCreateTime(DateUtils.getNowDate());


        return flag;
    }

    /**
     * 修改报修工单
     *
     * @param dmsBillsFaultInstance 报修工单
     * @return 结果
     */
    @Override
    public int updateDmsBillsFaultInstance(DmsBillsFaultInstance dmsBillsFaultInstance)
    {
        dmsBillsFaultInstance.setUpdateTime(DateUtils.getNowDate());
        return dmsBillsFaultInstanceMapper.updateDmsBillsFaultInstance(dmsBillsFaultInstance);
    }

    /**
     * 批量删除报修工单
     *
     * @param repairInstanceIds 需要删除的报修工单主键
     * @return 结果
     */
    @Override
    public int deleteDmsBillsFaultInstanceByRepairInstanceIds(Long[] repairInstanceIds)
    {
        return dmsBillsFaultInstanceMapper.deleteDmsBillsFaultInstanceByRepairInstanceIds(repairInstanceIds);
    }

    /**
     * 删除报修工单信息
     *
     * @param repairInstanceId 报修工单主键
     * @return 结果
     */
    @Override
    public int deleteDmsBillsFaultInstanceByRepairInstanceId(Long repairInstanceId)
    {
        return dmsBillsFaultInstanceMapper.deleteDmsBillsFaultInstanceByRepairInstanceId(repairInstanceId);
    }
}
