package com.qianwen.smartman.modules.cps.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; import com.qianwen.core.boot.ctrl.BladeController; import com.qianwen.core.datascope.props.DataScopeProperties; import com.qianwen.core.mp.intercept.QueryInterceptor; import com.qianwen.core.scanner.modular.annotation.GetResource; import com.qianwen.core.scanner.modular.stereotype.ApiResource; import com.qianwen.core.secure.annotation.PreAuth; import com.qianwen.core.tenant.annotation.NonDS; import com.qianwen.core.tool.api.R; import com.qianwen.core.tool.utils.SpringUtil; import com.qianwen.core.websocket.config.WebSocketMessageSender; import com.qianwen.core.websocket.distribute.MessageDO; import com.qianwen.core.websocket.distribute.RedisMessageDistributor; import com.qianwen.smartman.common.cache.cps.WorkstationCache; import com.qianwen.smartman.common.websocket.realtime.RealTimeDaraResponseJsonWebSocketMessage; import com.qianwen.smartman.modules.cps.message.dto.TelemetryDataResponseDTO; import com.qianwen.smartman.modules.cps.service.CollectDeviceTypeService; import com.qianwen.smartman.modules.cps.service.ICommonGroupService; import com.qianwen.smartman.modules.cps.service.WorkstationDatapointsService; import com.qianwen.smartman.modules.cps.vo.CollectDeviceTypeVO; import com.qianwen.smartman.modules.cps.vo.WorkstationDatapointsVO; import com.qianwen.smartman.modules.cps.vo.WorkstationGroupVO; import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO; import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper; import cn.hutool.json.JSONUtil; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @Api(value = "test", tags = {"test"}) @RestController @ApiResource({"smis/test"}) public class MyTestController {// extends BladeController @Autowired private WorkstationDatapointsService workstationDatapointsService; @Autowired private CollectDeviceTypeService typeService; @Autowired DataScopeProperties dsp; @Autowired QueryInterceptor qi; @Autowired SuperProcessParameterMapper pmapper; @GetMapping({"/dsp"}) @ApiOperation("dsp") public R showdsp() { Properties props = System.getProperties(); String appName = props.getProperty("spring.application.name"); return R.data(appName); } @GetMapping({"/realtimesend"}) @ApiOperation("realtimesend") public R realtimesend(String wid,String k,String v) { RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class); RealTimeDaraResponseJsonWebSocketMessage jsonWebSocketMessage = new RealTimeDaraResponseJsonWebSocketMessage(); jsonWebSocketMessage.setId(wid); Map map = WorkstationCache.getWorkstationRealTime(wid); map.keySet().forEach(key->{ if(key.equals(k)) { Object d = map.get(k); TelemetryDataResponseDTO a = (TelemetryDataResponseDTO)d; a.setV(v); System.out.println(d); } }); jsonWebSocketMessage.setData(map); MessageDO messageDO = new MessageDO(); messageDO.setNeedBroadcast(false); messageDO.setMessageText(JSONUtil.toJsonStr(jsonWebSocketMessage)); messageDistributor.distribute(messageDO); return R.data("1"); } @GetMapping({"/listDatapointsByWorkstationId"}) @ApiOperation("根据工位id获取数据点") public R listDatapointsByWorkstationId() { //InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("dp/dpstart.json"); String str; try { str = IOUtils.resourceToString("/dp/dpstart.json", Charset.forName("utf8")); } catch (IOException e) { str = "error"; e.printStackTrace(); } return R.data(str); } @GetMapping({"/typelist"}) @ApiOperation("采集类型列表") public R> typelist() { return R.data(typeService.typeList()); } @GetMapping({"/lastP"}) @ApiOperation("采集类型列表") public R lastP() {//1656818952295661569_DeviceStatus ProcessParameterVO vo = this.pmapper.lastParameterNotEqValue(1656818952295661569L, "DeviceStatus", "2"); ProcessParameterVO vo1 = this.pmapper.firstParameterEqValueGtTime(1656818952295661569L, "DeviceStatus", "2",System.currentTimeMillis()-20000); return R.data(vo); } }