package com.zd.laboratory.service.impl;

import java.text.SimpleDateFormat;
import java.util.List;
import com.zd.common.core.utils.DateUtils;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.security.utils.SaveUtil;

import com.zd.laboratory.domain.LabSemester;
import com.zd.laboratory.domain.vo.LabBlackdetailVO;
import com.zd.laboratory.mapper.LabSemesterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zd.laboratory.mapper.LabBlackdetailMapper;
import com.zd.laboratory.domain.LabBlackdetail;
import com.zd.laboratory.service.ILabBlackdetailService;

/**
 * 黑名单历史记录Service业务层处理
 *
 * @author zd
 * @date 2021-12-15
 */
@Service
public class LabBlackdetailServiceImpl implements ILabBlackdetailService
{
    @Autowired
    private LabBlackdetailMapper labBlackdetailMapper;
    @Autowired
    private LabSemesterMapper labSemesterMapper;

    /**
     * 查询黑名单历史记录
     *
     * @param id 黑名单历史记录主键
     * @return 黑名单历史记录
     */
    @Override
    public LabBlackdetail selectLabBlackdetailById(Long id)
    {
        return labBlackdetailMapper.selectLabBlackdetailById(id);
    }

    /**
     * 查询黑名单历史记录列表
     *
     * @param labBlackdetailVO 黑名单历史记录
     * @return 黑名单历史记录
     */
    @Override
    public List<LabBlackdetailVO> selectLabBlackdetailList(LabBlackdetailVO labBlackdetailVO)
    {
        if(labBlackdetailVO.getSemesterId()!=null){
            LabSemester labSemester = labSemesterMapper.selectLabSemesterById(labBlackdetailVO.getSemesterId());
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            if(labSemester.getSemesterStart()!=null){
                String startDate = formatter.format(labSemester.getSemesterStart());
                labBlackdetailVO.setBeginTime(startDate);
            }
            if(labSemester.getSemesterEnd()!=null){
                String endDate = formatter.format(labSemester.getSemesterEnd());
                labBlackdetailVO.setEndTime(endDate);
            }
        }

        return labBlackdetailMapper.selectLabBlackdetailList(labBlackdetailVO);
    }

    /**
     * 新增黑名单历史记录
     *
     * @param labBlackdetail 黑名单历史记录
     * @return 结果
     */
    @Override
    public int insertLabBlackdetail(LabBlackdetail labBlackdetail)
    {
        //设置其他公共字段
        SaveUtil.setCommonAttr(labBlackdetail);
        return labBlackdetailMapper.insertLabBlackdetail(labBlackdetail);
    }

    /**
     * 修改黑名单历史记录
     *
     * @param labBlackdetail 黑名单历史记录
     * @return 结果
     */
    @Override
    public int updateLabBlackdetail(LabBlackdetail labBlackdetail)
    {
        labBlackdetail.setUpdateTime(DateUtils.getNowDate());
        labBlackdetail.setUpdateBy(SecurityUtils.getUsername());
        return labBlackdetailMapper.updateLabBlackdetail(labBlackdetail);
    }

    /**
     * 批量删除黑名单历史记录
     *
     * @param ids 需要删除的黑名单历史记录主键
     * @return 结果
     */
    @Override
    public int deleteLabBlackdetailByIds(Long[] ids)
    {
        return labBlackdetailMapper.deleteLabBlackdetailByIds(ids);
    }

    /**
     * 删除黑名单历史记录信息
     *
     * @param id 黑名单历史记录主键
     * @return 结果
     */
    @Override
    public int deleteLabBlackdetailById(Long id)
    {
        return labBlackdetailMapper.deleteLabBlackdetailById(id);
    }
}
