package com.aucma.report.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.aucma.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.aucma.report.domain.DetailElectricalinspection;
import com.aucma.report.mapper.RecordElectricalInspectionMapper;
import com.aucma.report.domain.RecordElectricalInspection;
import com.aucma.report.service.IRecordElectricalInspectionService;

/**
 * 电检数据记录Service业务层处理
 * 
 * @author Yinq
 * @date 2023-11-09
 */
@Service
public class RecordElectricalInspectionServiceImpl implements IRecordElectricalInspectionService 
{
    @Autowired
    private RecordElectricalInspectionMapper recordElectricalInspectionMapper;

    /**
     * 查询电检数据记录
     * 
     * @param uuid 电检数据记录主键
     * @return 电检数据记录
     */
    @Override
    public RecordElectricalInspection selectRecordElectricalInspectionByUuid(String uuid)
    {
        return recordElectricalInspectionMapper.selectRecordElectricalInspectionByUuid(uuid);
    }

    /**
     * 查询电检数据记录列表
     * 
     * @param recordElectricalInspection 电检数据记录
     * @return 电检数据记录
     */
    @Override
    public List<RecordElectricalInspection> selectRecordElectricalInspectionList(RecordElectricalInspection recordElectricalInspection)
    {
        return recordElectricalInspectionMapper.selectRecordElectricalInspectionList(recordElectricalInspection);
    }

    /**
     * 新增电检数据记录
     * 
     * @param recordElectricalInspection 电检数据记录
     * @return 结果
     */
    @Transactional
    @Override
    public int insertRecordElectricalInspection(RecordElectricalInspection recordElectricalInspection)
    {
        int rows = recordElectricalInspectionMapper.insertRecordElectricalInspection(recordElectricalInspection);
        insertDetailElectricalinspection(recordElectricalInspection);
        return rows;
    }

    /**
     * 修改电检数据记录
     * 
     * @param recordElectricalInspection 电检数据记录
     * @return 结果
     */
    @Transactional
    @Override
    public int updateRecordElectricalInspection(RecordElectricalInspection recordElectricalInspection)
    {
        recordElectricalInspectionMapper.deleteDetailElectricalinspectionByUuid(recordElectricalInspection.getUuid());
        insertDetailElectricalinspection(recordElectricalInspection);
        return recordElectricalInspectionMapper.updateRecordElectricalInspection(recordElectricalInspection);
    }

    /**
     * 批量删除电检数据记录
     * 
     * @param uuids 需要删除的电检数据记录主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRecordElectricalInspectionByUuids(String[] uuids)
    {
        recordElectricalInspectionMapper.deleteDetailElectricalinspectionByUuids(uuids);
        return recordElectricalInspectionMapper.deleteRecordElectricalInspectionByUuids(uuids);
    }

    /**
     * 删除电检数据记录信息
     * 
     * @param uuid 电检数据记录主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRecordElectricalInspectionByUuid(String uuid)
    {
        recordElectricalInspectionMapper.deleteDetailElectricalinspectionByUuid(uuid);
        return recordElectricalInspectionMapper.deleteRecordElectricalInspectionByUuid(uuid);
    }

    /**
     * 新增电检数据明细信息
     * 
     * @param recordElectricalInspection 电检数据记录对象
     */
    public void insertDetailElectricalinspection(RecordElectricalInspection recordElectricalInspection)
    {
        List<DetailElectricalinspection> detailElectricalinspectionList = recordElectricalInspection.getDetailElectricalinspectionList();
        String uuid = recordElectricalInspection.getUuid();
        if (StringUtils.isNotNull(detailElectricalinspectionList))
        {
            List<DetailElectricalinspection> list = new ArrayList<DetailElectricalinspection>();
            for (DetailElectricalinspection detailElectricalinspection : detailElectricalinspectionList)
            {
                detailElectricalinspection.setUuid(uuid);
                list.add(detailElectricalinspection);
            }
            if (list.size() > 0)
            {
                recordElectricalInspectionMapper.batchDetailElectricalinspection(list);
            }
        }
    }
}
