package com.hzs.system.base.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EFeedbackStatus;
import com.hzs.common.domain.system.base.BdFeedback;
import com.hzs.common.domain.system.base.BdFeedbackReply;
import com.hzs.system.base.mapper.BdFeedbackReplyMapper;
import com.hzs.system.base.service.IBdFeedbackReplyService;
import com.hzs.system.base.service.IBdFeedbackService;
import com.hzs.system.base.vo.BdFeedbackReplyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 意见反馈回复 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-04-25
 */
@Service
public class BdFeedbackReplyServiceImpl extends ServiceImpl<BdFeedbackReplyMapper, BdFeedbackReply> implements IBdFeedbackReplyService {
    @Autowired
    IBdFeedbackService bdFeedbackService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveFeedbackReplyInfo(BdFeedbackReplyVO feedbackReplyVO) {
        BdFeedback BdFeedback = bdFeedbackService.getById(feedbackReplyVO.getPkFeedbackId());
        if (BdFeedback.getStatus().equals(EFeedbackStatus.NO_FEEDBACK.getValue())) {
            bdFeedbackService.updateFeedbackById(feedbackReplyVO.getPkCreator(), feedbackReplyVO.getPkFeedbackId());
        }
        return save(BeanUtil.copyProperties(feedbackReplyVO, BdFeedbackReply.class));
    }

    @Override
    public List<BdFeedbackReplyVO> selectFeedbackReplyById(Long pkFeedbackId, Integer pkCountry) {
        QueryWrapper<BdFeedbackReply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_FEEDBACK_ID", pkFeedbackId);
        queryWrapper.eq("PK_COUNTRY", pkCountry);
        queryWrapper.orderByAsc("CREATION_TIME");
        return BeanUtil.copyToList(baseMapper.selectList(queryWrapper), BdFeedbackReplyVO.class);
    }


}
