package com.yunyan.business.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunyan.business.domain.FillTemplate;
import com.yunyan.business.mapper.FillTemplateMapper;
import com.yunyan.business.service.IFillTemplateService;
import com.yunyan.common.core.domain.AjaxResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 模板管理Service业务层处理
 *
 * @author yunyan
 * @date 2023-07-27
 */
@Slf4j
@Service
public class FillTemplateServiceImpl extends ServiceImpl<FillTemplateMapper, FillTemplate> implements IFillTemplateService
{
    @Autowired
    private FillTemplateMapper fillTemplateMapper;

    /**
     * 查询模板管理列表
     *
     * @param fillTemplate 模板管理
     * @return 模板管理
     */
    @Override
    public List<FillTemplate> selectFillTemplateList(FillTemplate fillTemplate)
    {
        return fillTemplateMapper.selectFillTemplateList(fillTemplate);
    }

    /**
    * 新增
    * @param
    * @return
    */
    @Override
    public AjaxResultVo add(FillTemplate dto) {
        FillTemplate entity = dto;

        this.save(entity);
        return AjaxResultVo.success();
    }

    /**
     * 编辑
     * @param
     * @return
     */
    @Override
    public AjaxResultVo edit(FillTemplate dto) {

        FillTemplate entity = this.getById(dto.getId());
        if(null == entity) {
            return AjaxResultVo.error("非法操作");
        }

        entity = new FillTemplate();
        BeanUtils.copyProperties(dto, entity);

        this.updateById(entity);
        return AjaxResultVo.success();
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @Override
    public AjaxResultVo info(Long id) {
        FillTemplate entity = this.getById(id);
        if(null == entity) {
            return AjaxResultVo.error("数据查询异常~");
        }

        return AjaxResultVo.success(entity);
    }

}
