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

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

/**
 * UAS确认或不同意对账单时生成消息事件
 *
 */
public class PurchaseApCheckReplyReleaseEvent extends SaveReleaseEvent<PagingReleaseDetail, PurchaseApCheck> {

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

	public PurchaseApCheckReplyReleaseEvent(List<PurchaseApCheck> savedList) {
        super(savedList);
    }

    /**
     * 生成对应消息记录
     *
     * @param apCheck
     * @return
     */
    @Override
	public PagingReleaseDetail release(PurchaseApCheck apCheck) {
        Long enUU = apCheck.getCustUu();
        Date date = new Date();
        String codeValue = apCheck.getCode();
        String from = "ERP";
        String type = "确认对账单";
        String title = "B2B商务提醒";
        Short toVendor = Constant.YES;
        Short isReply = Constant.YES;
        String category = "sale";  // 对接收方来说，该单据类型
        String table = "purc$apcheck";
        Long sourceId = apCheck.getId();
        String url = "#/sale/apCheck/" + apCheck.getId();
        String context = "";
        if ("已确认".equals(apCheck.getCheckStatus())) {
            context = apCheck.getCustName() + "确认了您发出的对账单（" + codeValue + ")！";
        } else if ("不同意".equals(apCheck.getCheckStatus())) {
            context = apCheck.getCustName() + "因为" + apCheck.getReason() + "退回了您发出的对账单（" + codeValue + ")！";
        } else if ("未确认".equals(apCheck.getCheckStatus())) {
            context = apCheck.getCustName() + "取消确认了您发出的对账单（" + codeValue + ")！";
        } else if ("已作废".equals(apCheck.getCheckStatus())) {
            context = apCheck.getCustName() + "作废了您发出的对账单（" + codeValue + ")！";
        }
        PagingRelease release = new PagingRelease(null, null, enUU, date, codeValue, from, title, context, type, isReply, category, table, sourceId, null, toVendor, url);
        Long vendUU = apCheck.getEnUu();
        Long vendUserUU = apCheck.getRecorderUU();
        if (null == vendUserUU) {
            vendUserUU = 1L;
        }
        String vendUserName = apCheck.getRecorder();
        PagingReleaseDetail releaseDetail = new PagingReleaseDetail(vendUU, vendUserUU, vendUserName);
        releaseDetail.setPagingRelease(release);
        return releaseDetail;
    }
}
