package com.zd.laboratory.service.impl;

import com.zd.common.core.domain.per.PerPrefix;
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.laboratory.domain.LabSafeBook;
import com.zd.laboratory.mapper.LabSafeBookMapper;
import com.zd.laboratory.service.ILabSafeBookService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 实验室安全制度Service业务层处理
 *
 * @author liubo
 * @date 2021-11-19
 */
@Service
public class LabSafeBookServiceImpl implements ILabSafeBookService {
    @Autowired
    private LabSafeBookMapper labSafeBookMapper;

    /**
     * 查询实验室安全制度
     *
     * @param id 实验室安全制度主键
     * @return 实验室安全制度
     */
    @Override
    public LabSafeBook selectLabSafeBookById(Long id) {
        LabSafeBook safeBook = labSafeBookMapper.selectLabSafeBookById(id);
        return safeBook;
    }

    /**
     * 查询实验室安全制度列表
     *
     * @param labSafeBook 实验室安全制度
     * @return 实验室安全制度
     */
    @Override
    @DataScope(deptAlias = "t" , userAlias = "t" , permi = PerPrefix.LABORATORY_SAFEBOOK)
    public List<LabSafeBook> selectLabSafeBookList(LabSafeBook labSafeBook) {
        List<LabSafeBook> list = labSafeBookMapper.selectLabSafeBookList(labSafeBook);
        return list;
    }

    /**
     * 新增实验室安全制度
     *
     * @param labSafeBook 实验室安全制度
     * @return 结果
     */
    @Override
    public int insertLabSafeBook(LabSafeBook labSafeBook) {
        //设置其他公共字段
        SaveUtil.setCommonAttr(labSafeBook);
        labSafeBookMapper.insertLabSafeBook(labSafeBook);
        return updateLabSafeBook(labSafeBook);
    }

    /**
     * 修改实验室安全制度
     *
     * @param labSafeBook 实验室安全制度
     * @return 结果
     */
    @Override
    public int updateLabSafeBook(LabSafeBook labSafeBook) {
        labSafeBook.setUpdateTime(DateUtils.getNowDate());
        labSafeBook.setUpdateBy(SecurityUtils.getUsername());
//        labSafeBook.setQrCodeUrl(qrUrl + "?id=" + labSafeBook.getId());
        return labSafeBookMapper.updateLabSafeBook(labSafeBook);
    }

    /**
     * 批量删除实验室安全制度
     *
     * @param ids 需要删除的实验室安全制度主键
     * @return 结果
     */
    @Override
    public int deleteLabSafeBookByIds(Long[] ids) {
        return labSafeBookMapper.deleteLabSafeBookByIds(ids);
    }

    /**
     * 删除实验室安全制度信息
     *
     * @param id 实验室安全制度主键
     * @return 结果
     */
    @Override
    public int deleteLabSafeBookById(Long id) {
        return labSafeBookMapper.deleteLabSafeBookById(id);
    }
}
