package com.yida.data.form.apply.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yida.data.form.apply.mapper.CoreOfficialSealMapper;
import com.yida.data.form.apply.service.CoreOfficialSealService;
import com.yida.data.common.core.entity.applyForm.CoreOfficialSeal;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.customForm.dto.apply.OfficialSealSaveDTO;
import com.yida.data.customForm.dto.apply.OfficialSealSelectPageDTO;
import com.yida.data.customForm.vo.apply.OfficialSealInfoVO;
import com.yida.data.customForm.vo.apply.OfficialSealSelectPageVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * 学校公章 Service
 *
 * @author ZYJ
 * @date 2023/11/17
 */
@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class CoreOfficialSealServiceImpl extends ServiceImpl<CoreOfficialSealMapper, CoreOfficialSeal>
        implements CoreOfficialSealService {

    @Override
    public IPage<OfficialSealSelectPageVO> listOfficialSealPage(OfficialSealSelectPageDTO dto) {
        // TODO: 2023/11/17 此处暂时只有学校角色
        dto.setDeptId(FebsUtil.getDeptId());
        // TODO: 2023/11/17 需要查询对应的审核流程
        return baseMapper.listOfficialSealPage(dto.toPage(), dto);
    }

    @Override
    public OfficialSealInfoVO getOfficialSealInfo(Long id) {
        CoreOfficialSeal officialSeal = getById(id);
        // 返回数据
        OfficialSealInfoVO vo = new OfficialSealInfoVO();
        if (Objects.nonNull(officialSeal)) {
            BeanUtils.copyProperties(officialSeal, vo);
        }
        return vo;
    }

    @Override
    public void deleteOfficialSeal(Long id) {
        // TODO: 2023/11/17 需要判断能否删除
        removeById(id);
    }

    @Override
    public void saveOfficialSeal(OfficialSealSaveDTO dto) {
        // TODO: 2023/11/17 此处暂时只有学校角色
        CoreOfficialSeal coreOfficialSeal = new CoreOfficialSeal();
        BeanUtils.copyProperties(dto, coreOfficialSeal);
        coreOfficialSeal.setDeptId(FebsUtil.getDeptId());
        saveOrUpdate(coreOfficialSeal);
    }

    @Override
    public void updateEnableStatus(Long id, Integer enableStatus) {
        CoreOfficialSeal coreOfficialSeal = new CoreOfficialSeal();
        coreOfficialSeal.setId(id);
        coreOfficialSeal.setStatus(enableStatus);
        updateById(coreOfficialSeal);
    }
}
