package com.fjhx.common.service.contract.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.common.entity.contract.dto.ContractTemplateDto;
import com.fjhx.common.entity.contract.dto.ContractTemplateSelectDto;
import com.fjhx.common.entity.contract.po.ContractTemplate;
import com.fjhx.common.entity.contract.vo.ContractTemplateVo;
import com.fjhx.common.mapper.contract.ContractTemplateMapper;
import com.fjhx.common.service.contract.ContractTemplateService;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.ruoyi.common.utils.wrapper.SqlField;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 合同模板 服务实现类
 * </p>
 *
 * @author
 * @since 2023-04-14
 */
@Service
public class ContractTemplateServiceImpl extends ServiceImpl<ContractTemplateMapper, ContractTemplate> implements ContractTemplateService {

    @Override
    public Page<ContractTemplateVo> getPage(ContractTemplateSelectDto dto) {
        IWrapper<ContractTemplate> wrapper = getWrapper();
        wrapper.eq("ct", ContractTemplate::getCorporationId, dto.getCorporationId());
        wrapper.keyword(dto, new SqlField("ct", ContractTemplate::getTemplateName));
        wrapper.orderByDesc("ct", ContractTemplate::getId);

        return this.baseMapper.getPage(dto.getPage(), wrapper);
    }

    @Override
    public ContractTemplateVo detail(Long id) {
        ContractTemplate ContractTemplate = this.getById(id);
        ContractTemplateVo result = BeanUtil.toBean(ContractTemplate, ContractTemplateVo.class);
        return result;
    }

    @Override
    public void add(ContractTemplateDto contractTemplateDto) {
        this.save(contractTemplateDto);
    }

    @Override
    public void edit(ContractTemplateDto contractTemplateDto) {
        this.updateById(contractTemplateDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

}
