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

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

/**
 * 招标单保存时生成消息事件
 *
 */
public class PurchaseTenderSaveReleaseEvent extends SaveReleaseEvent<PagingReleaseDetail, SaleTender> {

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

	public PurchaseTenderSaveReleaseEvent(List<SaleTender> savedList) {
        super(savedList);
    }

    /**
     * 生成对应消息记录
     *
     * @param saleTender
     * @return
     */
    @Override
	public PagingReleaseDetail release(SaleTender saleTender) {
        Long emUU = saleTender.getRecorderuu();
        String emName = "采购员";
        if (null != saleTender.getRecorder()) {
            emName = saleTender.getRecorder().getUserName();
        }
        Long enUU = saleTender.getEnUU();
        Date date = new Date();
        String codeValue = saleTender.getCode();
        String from = "B2B";
        String type = "新增招标单";
        String title = "B2B商务提醒";
        Short toVendor = Constant.YES;
        Short isReply = Constant.NO;
        String category = "sale";  // 对接收方来说，该单据类型
        String table = "v$purc$tender";
        Long sourceId = saleTender.getPtId();
        String url = "#/sale/tender/" + saleTender.getPtId();
        Short orderStatus = 200;
        String context = saleTender.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 = saleTender.getVendUU();
        Long vendUserUU = saleTender.getUseruu();
        if (null == vendUserUU) {
            vendUserUU = 1L;
        }
        String vendUserName = saleTender.getUser();
        PagingReleaseDetail releaseDetail = new PagingReleaseDetail(vendUU, vendUserUU, vendUserName);
        releaseDetail.setPagingRelease(release);
        return releaseDetail;
    }
}
