package com.ruoyi.project.business.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.business.domain.dto.TqContractLiftSnDto;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.business.mapper.contract.TqContractLiftSnMapper;
import com.ruoyi.project.business.domain.TqContractLiftSn;
import com.ruoyi.project.business.service.ITqContractLiftSnService;

import static cn.afterturn.easypoi.excel.entity.enmus.CellValueType.Date;

/**
 * 合同电梯生产令号序列号字段维护Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-02
 */
@Service
public class TqContractLiftSnServiceImpl implements ITqContractLiftSnService 
{
    @Autowired
    private TqContractLiftSnMapper tqContractLiftSnMapper;

    /**
     * 查询合同电梯生产令号序列号字段维护
     * 
     * @param id 合同电梯生产令号序列号字段维护主键
     * @return 合同电梯生产令号序列号字段维护
     */
    @Override
    public TqContractLiftSn selectTqContractLiftSnById(Long id)
    {
        return tqContractLiftSnMapper.selectTqContractLiftSnById(id);
    }

    /**
     * 查询合同电梯生产令号序列号字段维护列表
     * 
     * @param tqContractLiftSn 合同电梯生产令号序列号字段维护
     * @return 合同电梯生产令号序列号字段维护
     */
    @Override
    public List<TqContractLiftSn> selectTqContractLiftSnList(TqContractLiftSnDto tqContractLiftSn)
    {
        return tqContractLiftSnMapper.selectTqContractLiftSnList(tqContractLiftSn);
    }

    /**
     * 新增合同电梯生产令号序列号字段维护
     * 
     * @param tqContractLiftSn 合同电梯生产令号序列号字段维护
     * @return 结果
     */
    @Override
    public int insertTqContractLiftSn(TqContractLiftSn tqContractLiftSn)
    {
        //如果没使用  则取人该月是否已经录入
        TqContractLiftSnDto searchTqContractLiftSn = new TqContractLiftSnDto();
        searchTqContractLiftSn.setSnEnterTime(new Date[]{tqContractLiftSn.getSnEnterTime()});
        List<TqContractLiftSn> tqContractLiftSnList =  tqContractLiftSnMapper.selectTqContractLiftSnList(searchTqContractLiftSn);
        //如果存在信息就更新
        if(CollectionUtils.isNotEmpty(tqContractLiftSnList)){
           return tqContractLiftSnMapper.updateTqContractLiftSnByEnterTime(tqContractLiftSn);
        }else{
            //否则新增
            tqContractLiftSn.setCreateTime(DateUtils.getNowDate());
            //tqContractLiftSn.setPermissionChar(SecurityUtils.getPermissionCharIns());
            return tqContractLiftSnMapper.insertTqContractLiftSn(tqContractLiftSn);
        }

    }

    /**
     * 修改合同电梯生产令号序列号字段维护
     * 
     * @param tqContractLiftSn 合同电梯生产令号序列号字段维护
     * @return 结果
     */
    @Override
    public int updateTqContractLiftSn(TqContractLiftSn tqContractLiftSn)
    {
        tqContractLiftSn.setUpdateTime(DateUtils.getNowDate());
        return tqContractLiftSnMapper.updateTqContractLiftSn(tqContractLiftSn);
    }

    /**
     * 批量删除合同电梯生产令号序列号字段维护
     * 
     * @param ids 需要删除的合同电梯生产令号序列号字段维护主键
     * @return 结果
     */
    @Override
    public int deleteTqContractLiftSnByIds(Long[] ids)
    {
        return tqContractLiftSnMapper.deleteTqContractLiftSnByIds(ids);
    }

    /**
     * 删除合同电梯生产令号序列号字段维护信息
     * 
     * @param id 合同电梯生产令号序列号字段维护主键
     * @return 结果
     */
    @Override
    public int deleteTqContractLiftSnById(Long id)
    {
        return tqContractLiftSnMapper.deleteTqContractLiftSnById(id);
    }
}
