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

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

/**
 * 采购验收单在平台保存时生成消息事件
 *
 */
public class PurchaseAcceptSaveReleaseEvent extends SaveReleaseEvent<PagingReleaseDetail, PurchaseAccept> {

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

	public PurchaseAcceptSaveReleaseEvent(List<PurchaseAccept> savedList) {
        super(savedList);
    }

    /**
     * 生成对应消息记录
     *
     * @param accept
     * @return
     */
    @Override
	public PagingReleaseDetail release(PurchaseAccept accept) {
        String emName = accept.getRecorder();
        Long enUU = accept.getEnUU();
        Date date = new Date();
        String codeValue = accept.getCode();
        String from = "B2B";
        if (accept.getErpId() != null) { // erp传到平台的单据，包含erpId字段记录来源
            from = "ERP";
        }
        String type = "新增采购验收单";
        String title = "B2B商务提醒";
        Short toVendor = Constant.YES;
        Short isReply = Constant.NO;
        String category = "sale";  // 对接收方来说，该单据类型
        String table = "purc$accept";
        Long sourceId = accept.getId();
        String url = "#/sale/accept/" + accept.getId();
        String context;
        if (null != accept.getSendCode()) {
            context = accept.getEnterprise().getEnName() + "的" + emName + "签收了您送货单（" + accept.getSendCode() + "）的产品！采购验收单号：" + codeValue;
        } else {
            context = accept.getEnterprise().getEnName() + "的" + emName + "签收了您的产品！采购验收单号：" + codeValue;
        }
        PagingRelease release = new PagingRelease(null, emName, enUU, date, codeValue, from, title, context, type, isReply,
                category, table, sourceId, null, toVendor, url);
        Long vendUU = accept.getVendUU();
        PagingReleaseDetail releaseDetail = new PagingReleaseDetail(vendUU, null, null);
        releaseDetail.setPagingRelease(release);
        return releaseDetail;
    }
}
