package com.uas.platform.b2b.event;

import com.uas.platform.b2b.model.PagingRelease;
import com.uas.platform.b2b.model.PagingReleaseDetail;
import com.uas.platform.b2b.model.SaleQuotation;
import com.uas.platform.core.model.Constant;

import java.util.Date;
import java.util.List;

/**
 * Created by dongbw
 * 17/07/26 17:22.
 */
public class SaleQuotationInvalidReleaseEvent extends SaveReleaseEvent<PagingReleaseDetail, SaleQuotation>{

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public SaleQuotationInvalidReleaseEvent(List<SaleQuotation> savedList) {
        super(savedList);
    }

    /**
     * 生成对应消息记录
     *
     * @param quotation
     * @return
     */
    @Override
    public PagingReleaseDetail release(SaleQuotation quotation) {
        //TODO ERP作废主动报价询价单之后，B2B产生消息
        Long emUU = quotation.getCustUserUU();
        String emName = "操作员";
        if (quotation.getCustUser() != null) {
            emName = quotation.getCustUser().getUserName();
        }
        Long enUU = quotation.getCustUU();
        Date date = new Date();
        String codeValue = quotation.getCode();
        String from = "B2B";
        if (quotation.getErpId() != null) { // erp传到平台的单据，包含erpId字段记录来源
            from = "ERP";
        }
        String type = "回复主动报价单";
        String title = "B2B商务提醒";
        Short toVendor = Constant.YES;
        Short isReply = Constant.YES;
        String category = "sale";  // 对接收方来说，该单据类型
        String table = "sale$quotation";
        Long sourceId = quotation.getId();
        String url = "#/sale/quotation/" + quotation.getId();
        Short orderStatus = quotation.getStatus();
        String context = quotation.getCust().getEnName() + "的" + emName + "作废了您的主动报价单（" + codeValue + ")！";
        PagingRelease release = new PagingRelease(emUU, emName, enUU, date, codeValue, from, title, context, type,
                isReply, category, table, sourceId, orderStatus, toVendor, url);
        Long vendUU = quotation.getEnUU();
        Long vendUserUU = quotation.getUserUU();
        if (null == vendUserUU) {
            vendUserUU = 1L;
        }
        String vendUserName = "业务员";
        if (null != quotation.getUser()) {
            vendUserName = quotation.getUser().getUserName();
        }
        PagingReleaseDetail releaseDetail = new PagingReleaseDetail(vendUU, vendUserUU, vendUserName);
        releaseDetail.setPagingRelease(release);
        return releaseDetail;
    }

}
