package com.mortals.xhx.module.api.handler.impl;

import com.alibaba.fastjson.JSONObject;
import com.mortals.xhx.module.api.model.AssetEventLog;
import com.mortals.xhx.module.asset.model.AssetEntity;
import com.mortals.xhx.module.asset.model.AssetFlowEventEntity;
import com.mortals.xhx.module.asset.service.AssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *
 * 业务码绑定事件处理类
 * 
 * @author luoshichao
 * @Description
 * @date 2021/1/8 15:04
 */
@Component
public class DeviceCodeBindEventHandler extends AbstractAssetFlowEventHandler {

	@Autowired
	private AssetService assetService;

	@Override
	public void handle(AssetEntity assetEntity, AssetFlowEventEntity eventEntity, AssetEventLog req) {
		JSONObject extInfo = new JSONObject(req.getEventExtInfo());
		String deviceNum = extInfo.getString("deviceNum");
		// 更新业务码
		assetEntity.setDeviceNum(deviceNum);
		assetEntity.setUpdateTime(new Date());
		assetEntity.setUpdateUser(req.getEventUser());
		assetService.update(assetEntity, null);

	}
}
