package cn.iocoder.yudao.module.wms.service.industrycategoryproperty;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.wms.controller.admin.industrycategoryproperty.vo.IndustryCategoryPropertyPageReqVO;
import cn.iocoder.yudao.module.wms.controller.admin.industrycategoryproperty.vo.IndustryCategoryPropertySaveReqVO;
import cn.iocoder.yudao.module.wms.dal.dataobject.industrycategoryproperty.IndustryCategoryPropertyDO;
import cn.iocoder.yudao.module.wms.dal.mysql.industrycategoryproperty.IndustryCategoryPropertyMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * 行业分类属性 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class IndustryCategoryPropertyServiceImpl implements IndustryCategoryPropertyService {

    @Resource
    private IndustryCategoryPropertyMapper industryCategoryPropertyMapper;

    @Override
    public Long createIndustryCategoryProperty(IndustryCategoryPropertySaveReqVO createReqVO) {
        // 插入
        IndustryCategoryPropertyDO industryCategoryProperty = BeanUtils.toBean(createReqVO, IndustryCategoryPropertyDO.class);
        industryCategoryPropertyMapper.insert(industryCategoryProperty);

        // 返回
        return industryCategoryProperty.getId();
    }

    @Override
    public void updateIndustryCategoryProperty(IndustryCategoryPropertySaveReqVO updateReqVO) {
        // 更新
        IndustryCategoryPropertyDO updateObj = BeanUtils.toBean(updateReqVO, IndustryCategoryPropertyDO.class);
        industryCategoryPropertyMapper.updateById(updateObj);
    }

    @Override
    public void deleteIndustryCategoryProperty(Long id) {
        // 删除
        industryCategoryPropertyMapper.deleteById(id);
    }

    @Override
    public IndustryCategoryPropertyDO getIndustryCategoryProperty(Long id) {
        return industryCategoryPropertyMapper.selectById(id);
    }

    @Override
    public PageResult<IndustryCategoryPropertyDO> getIndustryCategoryPropertyPage(IndustryCategoryPropertyPageReqVO pageReqVO) {
        return industryCategoryPropertyMapper.selectPage(pageReqVO);
    }

    @Override
    public List<IndustryCategoryPropertyDO> getByIndustryCategoryId(Long industryCategoryId) {
        return industryCategoryPropertyMapper.selectList(new LambdaQueryWrapper<IndustryCategoryPropertyDO>()
                .eq(IndustryCategoryPropertyDO::getIndustryCategoryId, industryCategoryId));
    }

}
