package com.zd.laboratory.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.exception.ServiceException;
import com.zd.common.core.utils.DateUtils;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.core.utils.StringUtils;
import com.zd.common.datascope.annotation.DataScope;
import com.zd.common.security.service.TokenService;
import com.zd.common.security.utils.SaveUtil;

import com.zd.laboratory.domain.LabHardware;
import com.zd.laboratory.domain.LabHazard;
import com.zd.laboratory.domain.LabSubject;
import com.zd.laboratory.domain.vo.LabHardwareVO;
import com.zd.laboratory.mapper.LabHardwareMapper;
import com.zd.laboratory.mapper.LabHazardMapper;
import com.zd.laboratory.mapper.LabSubjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zd.laboratory.mapper.LabRotationChartMapper;
import com.zd.laboratory.domain.LabRotationChart;
import com.zd.laboratory.service.ILabRotationChartService;

/**
 * 轮播图Service业务层处理
 *
 * @author zd
 * @date 2021-12-28
 */
@Service
public class LabRotationChartServiceImpl implements ILabRotationChartService
{
    @Autowired
    private LabRotationChartMapper labRotationChartMapper;

    @Autowired
    private TokenService tokenService;

    @Autowired
    private LabSubjectMapper labSubjectMapper;

    @Autowired
    private LabHardwareMapper labHardwareMapper;

    /**
     * 查询轮播图
     *
     * @param id 轮播图主键
     * @return 轮播图
     */
    @Override
    public LabRotationChart selectLabRotationChartById(Long id)
    {
        return labRotationChartMapper.selectLabRotationChartById(id);
    }

    /**
     * 查询轮播图列表
     *
     * @param labRotationChart 轮播图
     * @return 轮播图
     */
    @Override
    @DataScope(deptAlias = "c", permi = PerPrefix.LABORATORY_CHART)
    public List<LabRotationChart> selectLabRotationChartList(LabRotationChart labRotationChart)
    {
        return labRotationChartMapper.selectLabRotationChartList(labRotationChart);
    }

    /**
     * 查询轮播图列表
     *
     * @return 轮播图
     */
    @Override
    public List<LabRotationChart> selectChartFiveList(String hardwareNum)
    {
        LabHardware labHardware = new LabHardware();
        labHardware.setHardwareNum(hardwareNum);
        List<LabHardware> labHardwareVOList = labHardwareMapper.selectLabHardwareStatusByRelay(labHardware);
        if(labHardwareVOList.size()==0){
            return new ArrayList<LabRotationChart>();
        }
        LabSubject labSubject = labSubjectMapper.selectLabSubjectById(labHardwareVOList.get(0).getSubjectId());
        if(labSubject==null || labSubject.getDeptId()==null){
            return new ArrayList<LabRotationChart>();
        }
        LabRotationChart rotationChart = new LabRotationChart();
        rotationChart.setDeptId(labSubject.getDeptId());
        if(StringUtils.isNotNull(labHardwareVOList.get(0).getPcType()) && labHardwareVOList.get(0).getPcType()==0){
            rotationChart.setImgCategory(1);
        }else{
            rotationChart.setImgCategory(2);
        }

        return labRotationChartMapper.selectChartFiveList(rotationChart);
    }

    /**
     * 新增轮播图
     *
     * @param labRotationChart 轮播图
     * @return 结果
     */
    @Override
    public int insertLabRotationChart(LabRotationChart labRotationChart)
    {
        SaveUtil.setCommonAttr(labRotationChart);
        return labRotationChartMapper.insertLabRotationChart(labRotationChart);
    }

    /**
     * 修改轮播图
     *
     * @param labRotationChart 轮播图
     * @return 结果
     */
    @Override
    public int updateLabRotationChart(LabRotationChart labRotationChart)
    {
        return labRotationChartMapper.updateLabRotationChart(labRotationChart);
    }

    /**
     * 批量删除轮播图
     *
     * @param ids 需要删除的轮播图主键
     * @return 结果
     */
    @Override
    public int deleteLabRotationChartByIds(Long[] ids)
    {
        return labRotationChartMapper.deleteLabRotationChartByIds(ids);
    }

    /**
     * 删除轮播图信息
     *
     * @param id 轮播图主键
     * @return 结果
     */
    @Override
    public int deleteLabRotationChartById(Long id)
    {
        return labRotationChartMapper.deleteLabRotationChartById(id);
    }
}
