package com.younike.system.service.impl;

import java.util.List;
import java.time.LocalDateTime;
import com.younike.common.core.domain.AjaxResult;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.younike.system.mapper.PublishQuoteReplyMapper;
import com.younike.system.domain.PublishQuoteReply;
import com.younike.system.service.IPublishQuoteReplyService;

/**
 * 报价留言回复Service业务层处理
 *
 * @author elev
 * @date 2022-01-20
 */
@Service
public class PublishQuoteReplyServiceImpl implements IPublishQuoteReplyService {
    @Autowired
    private PublishQuoteReplyMapper publishQuoteReplyMapper;

    /**
     * 查询报价留言回复
     *
     * @param replyId 报价留言回复主键
     * @return 报价留言回复
     */
    @Override
    public PublishQuoteReply selectPublishQuoteReplyByReplyId(Long replyId) {
        return publishQuoteReplyMapper.selectPublishQuoteReplyByReplyId(replyId);
    }

    /**
     * 查询报价留言回复列表
     *
     * @param publishQuoteReply 报价留言回复
     * @return 报价留言回复
     */
    @Override
    public List<PublishQuoteReply> selectPublishQuoteReplyList(PublishQuoteReply publishQuoteReply) {
        return publishQuoteReplyMapper.selectPublishQuoteReplyList(publishQuoteReply);
    }

    /**
     * 新增报价留言回复
     *
     * @param publishQuoteReply 报价留言回复
     * @return 结果
     */
    @Override
    public int insertPublishQuoteReply(PublishQuoteReply publishQuoteReply) {
        publishQuoteReply.setCreateTime(LocalDateTime.now());
        return publishQuoteReplyMapper.insertPublishQuoteReply(publishQuoteReply);
    }

    /**
     * 修改报价留言回复
     *
     * @param publishQuoteReply 报价留言回复
     * @return 结果
     */
    @Override
    public int updatePublishQuoteReply(PublishQuoteReply publishQuoteReply) {
        publishQuoteReply.setUpdateTime(LocalDateTime.now());
        return publishQuoteReplyMapper.updatePublishQuoteReply(publishQuoteReply);
    }

    /**
     * 批量删除报价留言回复
     *
     * @param replyIds 需要删除的报价留言回复主键
     * @return 结果
     */
    @Override
    public int deletePublishQuoteReplyByReplyIds(Long[] replyIds) {
        return publishQuoteReplyMapper.deletePublishQuoteReplyByReplyIds(replyIds);
    }

    /**
     * 删除报价留言回复信息
     *
     * @param replyId 报价留言回复主键
     * @return 结果
     */
    @Override
    public int deletePublishQuoteReplyByReplyId(Long replyId)
    {
        return publishQuoteReplyMapper.deletePublishQuoteReplyByReplyId(replyId);
    }

    /**
     * 新增报价回复(顾客回复)
     * @param publish
     * @return
     */
    @Override
    public AjaxResult replyInsert(PublishQuoteReply publish) {

        publish.setCreateTime(LocalDateTime.now());
        if(publishQuoteReplyMapper.insertPublishQuoteReply(publish)<1){
           return AjaxResult.error("回复失败");
        }
        return AjaxResult.success();
    }

    /**
     * 服务人员删除报价回复
     * @param replyId
     * @return
     */
    @Override
    public AjaxResult delReply(Long replyId) {
        PublishQuoteReply publishQuoteReply = publishQuoteReplyMapper.selectPublishQuoteReplyByReplyId(replyId);
        if(ObjectUtils.isEmpty(publishQuoteReply)){
            return AjaxResult.error("留言不存在");
        }
        if(!publishQuoteReply.getReplyType().equals("1")){
            return AjaxResult.error("非服务人员留言，不可操作");
        }
        publishQuoteReply.setDelFlag("2");
        publishQuoteReply.setUpdateTime(LocalDateTime.now());
        if(publishQuoteReplyMapper.updatePublishQuoteReply(publishQuoteReply)>0){
            return AjaxResult.success();
        }
        return AjaxResult.error("删除留言失败");
    }

    /**
     * 顾客端删除报价回复
     * @param replyId
     * @return
     */
    @Override
    public AjaxResult delMemberReply(Long replyId) {
        PublishQuoteReply publishQuoteReply = publishQuoteReplyMapper.selectPublishQuoteReplyByReplyId(replyId);
        if(ObjectUtils.isEmpty(publishQuoteReply)){
            return AjaxResult.error("留言不存在");
        }
        if(!publishQuoteReply.getReplyType().equals("0")){
            return AjaxResult.error("非顾客留言，不可操作");
        }
        publishQuoteReply.setDelFlag("2");
        publishQuoteReply.setUpdateTime(LocalDateTime.now());
        if(publishQuoteReplyMapper.updatePublishQuoteReply(publishQuoteReply)>0){
            return AjaxResult.success();
        }
        return AjaxResult.error("删除留言失败");
    }
}
