package com.zd.laboratory.service.impl;

import java.util.Collections;
import java.util.List;

import com.zd.common.core.utils.DateUtils;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.datascope.annotation.DataScope;
import com.zd.common.security.utils.SaveUtil;

import com.zd.system.api.laboratory.domain.SubAddrr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zd.laboratory.mapper.LabSubjectLayoutMapper;
import com.zd.laboratory.domain.LabSubjectLayout;
import com.zd.laboratory.service.ILabSubjectLayoutService;

/**
 * 实验室布局Service业务层处理
 *
 * @author zd
 * @date 2021-09-23
 */
@Service
public class LabSubjectLayoutServiceImpl implements ILabSubjectLayoutService {
    @Autowired
    private LabSubjectLayoutMapper labSubjectLayoutMapper;

    /**
     * 查询实验室布局
     *
     * @param id 实验室布局主键
     * @return 实验室布局
     */
    @Override
    public LabSubjectLayout selectLabSubjectLayoutById(Long id) {
        return labSubjectLayoutMapper.selectLabSubjectLayoutById(id);
    }

    /**
     * 查询实验室布局列表
     *
     * @param labSubjectLayout 实验室布局
     * @return 实验室布局
     */
    @Override
    @DataScope(deptAlias = "sl")
    public List<LabSubjectLayout> selectLabSubjectLayoutList(LabSubjectLayout labSubjectLayout) {
        return labSubjectLayoutMapper.selectLabSubjectLayoutList(labSubjectLayout);
    }


    /**
     * 查询实验室布局列表-未使用
     *
     * @return 实验室布局集合
     */
    @Override
    public List<LabSubjectLayout> selectLabSubjectLayoutNoUseList(LabSubjectLayout labSubjectLayout) {

        return labSubjectLayoutMapper.selectLabSubjectLayoutNoUseList(labSubjectLayout);
    }

    /**
     * 新增实验室布局
     *
     * @param labSubjectLayout 实验室布局
     * @return 结果
     */
    @Override
    public int insertLabSubjectLayout(LabSubjectLayout labSubjectLayout) {
        //设置其他公共字段
        SaveUtil.setCommonAttr(labSubjectLayout);
        return labSubjectLayoutMapper.insertLabSubjectLayout(labSubjectLayout);
    }

    /**
     * 修改实验室布局
     *
     * @param labSubjectLayout 实验室布局
     * @return 结果
     */
    @Override
    public int updateLabSubjectLayout(LabSubjectLayout labSubjectLayout) {
        labSubjectLayout.setUpdateTime(DateUtils.getNowDate());
        labSubjectLayout.setUpdateBy(SecurityUtils.getUsername());
        return labSubjectLayoutMapper.updateLabSubjectLayout(labSubjectLayout);
    }

    /**
     * 批量删除实验室布局
     *
     * @param ids 需要删除的实验室布局主键
     * @return 结果
     */
    @Override
    public int deleteLabSubjectLayoutByIds(Long[] ids) {
        return labSubjectLayoutMapper.deleteLabSubjectLayoutByIds(ids);
    }


    /**
     * 通过ID批量获取实验室布局
     *
     * @param ids 主键集合
     * @return 结果
     */
    @Override
    public List<SubAddrr> selectAddrrByLayoutIds(Long... ids) {
        if (ids == null || ids.length == 0) return Collections.emptyList();
        return labSubjectLayoutMapper.selectAddrrByLayoutIds(ids);
    }

    /**
     * 删除实验室布局信息
     *
     * @param id 实验室布局主键
     * @return 结果
     */
    @Override
    public int deleteLabSubjectLayoutById(Long id) {
        return labSubjectLayoutMapper.deleteLabSubjectLayoutById(id);
    }
}
