package com.bonus.zlpt.company.service.impl;

import com.bonus.zlpt.company.api.domain.ServiceGreementInfo;
import com.bonus.zlpt.company.api.domain.dto.ServiceDto;
import com.bonus.zlpt.company.api.domain.vo.ServiceGreementVo;
import com.bonus.zlpt.company.mapper.ServiceGreementInfoMapper;
import com.bonus.zlpt.company.service.ServiceGreementInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 服务协议表(ServiceGreementInfo)表服务实现类
 *
 * @author makejava
 * @since 2023-12-04 16:32:06
 */
@Service("serviceGreementInfoService")
public class ServiceGreementInfoServiceImpl implements ServiceGreementInfoService {

    @Resource
    private ServiceGreementInfoMapper mapper;

    /**
     * 获取隐私协议模板列表
     * @param dto
     * @return
     */
    @Override
    public List<ServiceGreementVo> selectGreementInfoList(ServiceDto dto) {
        return mapper.selectGreementInfoList(dto);
    }

    /**
     * 根据id查询隐私协议模板信息
     * @param id
     * @return
     */
    @Override
    public ServiceGreementVo selectListById(int id) {
        return mapper.selectListById(id);
    }

    /**
     * 新增隐私协议模板信息
     * @param dto
     * @return
     */
    @Override
    @Transactional
    public int insertConfig(ServiceGreementInfo dto) {

         mapper.insertConfig(dto.getServiceGreementDto());
         dto.getFileInfoDto().setModelId(dto.getServiceGreementDto().getServiceId());
         return mapper.insertAttachment(dto.getFileInfoDto());
    }

    /**
     * 编辑隐私协议模板信息
     * @param dto
     * @return
     */
    @Override
    @Transactional
    public int update(ServiceGreementInfo dto) {
         mapper.update(dto.getServiceGreementDto());
         return mapper.updateAttachment(dto.getFileInfoDto());
    }

    /**
     * 根据id删除隐私协议模板
     * @param id
     * @return
     */
    @Override
    @Transactional
    public void delete(int id) {
         mapper.delete(id);
         mapper.deleteById(id);
    }

}

