package org.jeecg.modules.mes.material.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;
import org.jeecg.modules.mes.material.entity.MesMaterial;
import org.jeecg.modules.mes.material.mapper.MesMaterialMapper;
import org.jeecg.modules.mes.material.service.IMesMaterialService;
import org.jeecg.modules.message.websocket.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MesMaterialServiceImpl extends ServiceImpl<MesMaterialMapper, MesMaterial> implements IMesMaterialService {

  @Autowired private WebSocket webSocket;

  @Override
  public void notifyMaterialChanged(String eventType, MesMaterial material) {
    Map<String, Object> event = new HashMap<>();
    event.put("eventType", eventType);
    event.put("materialId", material.getId());
    event.put("materialCode", material.getMaterialCode());
    event.put("timestamp", System.currentTimeMillis());
    webSocket.sendMessage(JSON.toJSONString(event));
  }
}
