package com.ruoyi.doubledefense.service.impl;

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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.constant.DeletedEnum;
import com.ruoyi.doubledefense.domain.Contractor;
import com.ruoyi.doubledefense.dto.ContractorDTO;
import com.ruoyi.doubledefense.dto.ContractorProfessionDTO;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.doubledefense.mapper.ContractorProfessionMapper;
import com.ruoyi.doubledefense.domain.ContractorProfession;
import com.ruoyi.doubledefense.service.IContractorProfessionService;
import org.springframework.util.CollectionUtils;

/**
 * 承包商工种Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-04
 */
@Service
public class ContractorProfessionServiceImpl implements IContractorProfessionService 
{
    @Autowired
    private ContractorProfessionMapper contractorProfessionMapper;

    /**
     * 查询承包商工种
     * 
     * @param id 承包商工种主键
     * @return 承包商工种
     */
    @Override
    public ContractorProfessionDTO selectContractorProfessionById(String id)
    {
        ContractorProfession contractorProfession = contractorProfessionMapper.selectById(id);
        if(Objects.nonNull(contractorProfession)){
            ContractorProfessionDTO contractorProfessionDTO = new ContractorProfessionDTO();
            BeanUtils.copyProperties(contractorProfession,contractorProfessionDTO);
            return contractorProfessionDTO;
        }
        return null;
    }

    /**
     * 查询承包商工种列表
     * 
     * @param contractorProfessionDTO 承包商工种
     * @return 承包商工种
     */
    @Override
    public List<ContractorProfessionDTO> selectContractorProfessionList(ContractorProfessionDTO contractorProfessionDTO)
    {
        ContractorProfession contractorProfession = new ContractorProfession();
        BeanUtils.copyProperties(contractorProfessionDTO,contractorProfession);
        contractorProfession.setIsDel(DeletedEnum.VALID.getValue());
        List<ContractorProfessionDTO> contractorProfessionList = contractorProfessionMapper.selectContractorProfessionList(contractorProfession);
        if(CollectionUtils.isEmpty(contractorProfessionList)){
            return Lists.newArrayList();
        }
        return contractorProfessionList;
    }

    /**
     * 新增承包商工种
     * 
     * @param contractorProfessionDTO 承包商工种
     * @return 结果
     */
    @Override
    public int insertContractorProfession(ContractorProfessionDTO contractorProfessionDTO)
    {
        ContractorProfession contractorProfession = new ContractorProfession();
        BeanUtils.copyProperties(contractorProfessionDTO,contractorProfession);
        contractorProfession.setCreateDefault();
        return contractorProfessionMapper.insert(contractorProfession);
    }

    /**
     * 修改承包商工种
     * 
     * @param contractorProfessionDTO 承包商工种
     * @return 结果
     */
    @Override
    public int updateContractorProfession(ContractorProfessionDTO contractorProfessionDTO)
    {
        ContractorProfession contractorProfession = new ContractorProfession();
        BeanUtils.copyProperties(contractorProfessionDTO,contractorProfession);
        contractorProfession.setUpdateDefault();
        return contractorProfessionMapper.updateById(contractorProfession);
    }

    /**
     * 批量删除承包商工种
     * 
     * @param ids 需要删除的承包商工种主键
     * @return 结果
     */
    @Override
    public int deleteContractorProfessionByIds(String[] ids)
    {
        ContractorProfession contractorProfession = new ContractorProfession();
        contractorProfession.setIsDel(DeletedEnum.INVALID.getValue());
        contractorProfession.setUpdateDefault();
        LambdaQueryWrapper<ContractorProfession> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(ContractorProfession::getId,ids);
        return contractorProfessionMapper.update(contractorProfession,queryWrapper);
    }

}
