package com.zm.order.tool.server.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.dozermapper.core.Mapper;
import com.zm.order.tool.server.enums.BizTypeEnum;
import com.zm.order.tool.server.model.BaseIndexComment;
import com.zm.order.tool.server.model.CateringIndexComment;
import com.zm.order.tool.server.model.Order;
import com.zm.order.tool.server.model.OrderItemComment;
import com.zm.order.tool.server.newdatasource.NewDataSourceOrderDao;

/**
 * 餐饮评价文档处理器
 *
 * @author nianchang
 * @date 2022/04/25 6:42 下午
 */
@Component
public class CateringCommentDocHandler implements CommentDocHandler {

    @Autowired
    private Mapper commentMapper;

    @Autowired
    private NewDataSourceOrderDao orderDao;

    @Override
    public Integer bizType() {
        return BizTypeEnum.CATERING.getType();
    }

    @Override
    public BaseIndexComment buildCommentDoc(OrderItemComment orderItemComment) {
        CateringIndexComment indexComment = commentMapper.map(orderItemComment, CateringIndexComment.class);
        buildBaseInfo(indexComment, orderItemComment);
        return indexComment;
    }

    private void buildBaseInfo(CateringIndexComment indexComment, OrderItemComment orderItemComment) {
        indexComment.setCommentId(orderItemComment.getId());

        Order order = orderDao.selectByOrderNo(orderItemComment.getOrderNo(), orderItemComment.getUserId());
        if (order != null) {
            indexComment.setMobile(order.getMobile());
            indexComment.setSource(order.getSource());
            indexComment.setOrderType(order.getOrderType());
            indexComment.setSourceNo(order.getSourceNo());
            indexComment.setPerformanceType(order.getPerformanceType());
            indexComment.setOrderAt(order.getOrderAt());
        }
    }
}
