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.PurchaseInquiryMould;
import com.uas.platform.core.model.Constant;

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

/**
 * 模具询价单保存时生成消息事件
 */
public class PurchaseInquiryMouldSaveReleaseEvent extends SaveReleaseEvent<PagingReleaseDetail, PurchaseInquiryMould> {

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

	public PurchaseInquiryMouldSaveReleaseEvent(List<PurchaseInquiryMould> savedList) {
        super(savedList);
    }

    /**
     * 生成对应消息记录
     *
     * @param mould
     * @return
     */
    @Override
	public PagingReleaseDetail release(PurchaseInquiryMould mould) {
        //TODO 保存新订单之后，触发新增消息事件。
        Long emUU = mould.getRecorderuu();
        String emName = mould.getRecorder();
        Long enUU = mould.getEnuu();
        Date date = new Date();
        String codeValue = mould.getCode();
        String from = "B2B";
        if (mould.getErpSourceId() != null) { // erp传到平台的单据，包含erpId字段记录来源
            from = "ERP";
        }
        String type = "新增模具询价单";
        String title = "B2B商务提醒";
        Short toVendor = Constant.YES;
        Short isReply = Constant.NO;
        String category = "sale";  // 对接收方来说，该单据类型
        String table = "v$purc$inquirymould";
        Long sourceId = mould.getId();
        String url = "#/sale/mould/" + mould.getId();
        Short orderStatus = mould.getStatus();
        String context = mould.getEnterprise().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 = mould.getVenduu();
        Long vendUserUU = mould.getVendUserUU();
        String vendUserName = "业务员";
        if (null == vendUserUU) {
            vendUserUU = 1L;
        }
        if (null != mould.getVendUser()) {
            vendUserName = mould.getVendUser().getUserName();
        }
        PagingReleaseDetail releaseDetail = new PagingReleaseDetail(vendUU, vendUserUU, vendUserName);
        releaseDetail.setPagingRelease(release);
        return releaseDetail;
    }
}
