package com.sifang.modules.order.dao;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.platform.controller.form.ComplaintReply;
import com.sifang.modules.order.entity.CrmOrder;
import com.sifang.modules.order.entity.CrmOrderOperationInfo;
import com.sifang.modules.order.utils.Target;
import com.sifang.modules.order.utils.WebPageFunUtils;
import com.sifang.modules.sys.common.persistence.BaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class OrderOperationInfoDao extends BaseDao<CrmOrderOperationInfo> {
    @Autowired
    private OrderDao orderDao;

    //过程信息
    public List<Target> getOrderDetail(String orderId){
        String sql = "SELECT process_detail FROM crm_order_operation_info WHERE order_id=? ";
        String detail = Db.queryStr(sql,orderId);
        List<Target> list = WebPageFunUtils.getOrderProcess(detail);
        return list;
    }

    public CrmOrderOperationInfo getOperaByOrderId(String orderId){
        Record rds = Db.findFirst(" SELECT * FROM crm_order_operation_info WHERE order_id=? ",orderId);
        CrmOrderOperationInfo info = new CrmOrderOperationInfo();
        if(rds != null){
            CrmOrder order = orderDao.get(rds.getStr("order_id"));
            info.setId(rds.getStr("id"));
            info.setOrder(order);
            info.setProcessDetail(rds.getStr("process_detail"));
            info.setTrackDetail(rds.getStr("track_detail"));
        }
        return info;
    }

    //跟进记录
    public List<ComplaintReply> getTrackDetail(String orderId){
        String sql = "SELECT track_detail FROM crm_order_operation_info WHERE order_id=? ";
        String track_detail = Db.queryStr(sql,orderId);
        List<ComplaintReply> list = WebPageFunUtils.getFittingProcess(track_detail);
        return list;
    }

}
