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

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

/**
 * 客户认定单保存时生成消息事件
 */
public class PurchaseProofingApprovalSaveReleaseEvent extends SaveReleaseEvent<PagingReleaseDetail, PurchaseProofingApproval> {

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

	public PurchaseProofingApprovalSaveReleaseEvent(List<PurchaseProofingApproval> savedList) {
        super(savedList);
    }

    /**
     * 生成对应消息记录
     *
     * @param approval
     * @return
     */
    @Override
	public PagingReleaseDetail release(PurchaseProofingApproval approval) {
        String emName = approval.getRecordor();
        Long enUU = approval.getEnUU();
        Date date = new Date();
        String codeValue = approval.getCode();
        String from = "ERP";
        String type = "新增认定单";
        String title = "B2B商务提醒";
        Short toVendor = Constant.YES;
        Short isReply = Constant.NO;
        String category = "sale";  // 对接收方来说，该单据类型
        String table = "purc$proofingapproval";
        Long sourceId = approval.getId();
        String url = "#/sale/approval";
        String context = approval.getEnterprise().getEnName() + "已经对物料“" + approval.getProdDetail() + " " + approval.getProdSpec() + "”进行了认定！";
        PagingRelease release = new PagingRelease(null, emName, enUU, date, codeValue, from, title, context, type, isReply, category, table, sourceId, null, toVendor, url);
        Long vendUU = approval.getVendUU();
        PagingReleaseDetail releaseDetail = new PagingReleaseDetail(vendUU, null, null);
        releaseDetail.setPagingRelease(release);
        return releaseDetail;
    }
}
