package com.zy.acs.manager.core; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.zy.acs.common.enums.AgvStatusType; import com.zy.acs.framework.common.R; import com.zy.acs.framework.common.SnowflakeIdWorker; import com.zy.acs.manager.core.service.*; import com.zy.acs.manager.core.service.astart.MapDataDispatcher; import com.zy.acs.manager.core.utils.RouteGenerator; import com.zy.acs.manager.manager.entity.*; import com.zy.acs.manager.manager.enums.FuncStaType; import com.zy.acs.manager.manager.enums.StatusType; import com.zy.acs.manager.manager.service.*; import com.zy.acs.manager.system.controller.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; /** * Created by vincent on 11/15/2024 */ @RestController @RequestMapping("/demo") public class DemoController extends BaseController { @Autowired private AgvService agvService; @Autowired private AgvDetailService agvDetailService; @Autowired private TaskService taskService; @Autowired private MainService mainService; @Autowired private MainLockWrapService mainLockWrapService; @Autowired private SnowflakeIdWorker snowflakeIdWorker; @Autowired private CodeService codeService; @Autowired private JdbcTemplate jdbcTemplate; @Autowired private LocService locService; @Autowired private TrafficService trafficService; @Autowired private ThreadPoolRegulator threadPoolRegulator; @Autowired private MapDataDispatcher mapDataDispatcher; @Autowired private AvoidWaveCalculator avoidWaveCalculator; @Autowired private PatrolService patrolService; @Autowired private RouteGenerator routeGenerator; @Autowired private FuncStaService funcStaService; @Autowired private AgvModelService agvModelService; @RequestMapping(value = "/system/info", method = {RequestMethod.GET, RequestMethod.POST}) public R systemInfo() { return R.ok("RCS-FLOW-1.0.0"); } // {"msg":"Success","code":200,"data":[[38,2],[38,3],[38,4],[38,5],[38,6],[37,6],[36,6],[35,6],[34,6],[33,6],[32,6],[31,6],[30,6],[29,6],[28,6],[27,6],[26,6],[25,6]]} // {"msg":"Success","code":200,"data":[[38,2],[38,3],[38,4],[38,5],[38,6],[37,6],[36,6],[35,6],[34,6],[33,6],[32,6],[31,6],[30,6],[29,6],[28,6],[27,6],[26,6],[25,6]]} @RequestMapping(value = "/system/demo", method = {RequestMethod.GET, RequestMethod.POST}) public R demo() { long startTime = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { this.demo1(); } System.out.println(System.currentTimeMillis() - startTime); return R.ok(); } private R demo1() { List path = new ArrayList<>(); path.add("00000035"); path.add("00000085"); path.add("00000135"); path.add("00000185"); path.add("00000235"); path.add("00000234"); path.add("00000233"); path.add("00000232"); path.add("00000231"); path.add("00000230"); path.add("00000229"); path.add("00000228"); path.add("00000227"); path.add("00000226"); path.add("00000225"); path.add("00000224"); path.add("00000223"); path.add("00000222"); // List codeMatrixIdxList = new ArrayList<>(); // for (String pathStr : path) { // int[] codeMatrixIdx = mapDataDispatcher.getCodeMatrixIdx(null, pathStr); // codeMatrixIdxList.add(codeMatrixIdx); // } // List codeMatrixIdxList = mapDataDispatcher.getCodeMatrixIdxList(null, path); // System.out.println(codeMatrixIdxList.toString()); // return R.ok().add(codeMatrixIdxList); for (String codeData : path) { Code code = codeService.getCacheByData(codeData); Code byId = codeService.getCacheById(code.getId()); } return R.ok(); } // @RequestMapping(value = "/system/route/generate", method = {RequestMethod.GET, RequestMethod.POST}) // public R generate() { // String[][] codeMatrix = mapDataDispatcher.getCodeMatrix(null); // List list = routeGenerator.generateRoutes(codeMatrix); // return R.ok(String.valueOf(list.size())).add(list); // } // http://localhost:8088/demo/auto/go/standby @GetMapping("/auto/go/standby") public R autoGoStandby() { List standbyFunStaList = funcStaService.list(new LambdaQueryWrapper() .eq(FuncSta::getStatus, StatusType.ENABLE.val) .eq(FuncSta::getType, FuncStaType.STANDBY.toString()) .orderByAsc(FuncSta::getId)); List agvList = agvService.list(new LambdaQueryWrapper().eq(Agv::getStatus, StatusType.ENABLE.val). orderByAsc(Agv::getId)); int size = Math.min(standbyFunStaList.size(), agvList.size()); for (int i = 0; i < size; i++) { FuncSta funcSta = standbyFunStaList.get(i); Code code = codeService.getCacheById(funcSta.getCode()); Agv agv = agvList.get(i); AgvDetail agvDetail = agvDetailService.selectByAgvId(agv.getId()); AgvModel agvModel = agvModelService.getByAgvId(agv.getId()); Double workDirection = agvModel.getWorkDirection(); agvDetail.setPos(1); agvDetail.setCode(code.getId()); agvDetail.setStatus(AgvStatusType.IDLE.val); agvDetail.setAgvAngle(workDirection); agvDetail.setVol(5000); agvDetailService.updateById(agvDetail); } avoidWaveCalculator.calcDynamicNodeWhenBoot(); // AgvDetail agvDetail11 = agvDetailService.selectByAgvNo("11"); // agvDetail11.setCode(codeService.getCacheByData("00000251").getId()); // agvDetailService.updateById(agvDetail11); // // AgvDetail agvDetail12 = agvDetailService.selectByAgvNo("12"); // agvDetail12.setCode(codeService.getCacheByData("00000204").getId()); // agvDetailService.updateById(agvDetail12); // // AgvDetail agvDetail14 = agvDetailService.selectByAgvNo("14"); // agvDetail14.setCode(codeService.getCacheByData("00000101").getId()); // agvDetailService.updateById(agvDetail14); // // avoidWaveCalculator.calcDynamicNodeWhenBoot(); // // mainLockWrapService.buildMinorTask(agvService.getById(agvDetail14.getAgvId()), TaskTypeType.MOVE, // codeService.getCacheByData("00000303").getData(), null); // mainLockWrapService.buildMinorTask(agvService.getById(agvDetail11.getAgvId()), TaskTypeType.MOVE, // codeService.getCacheByData("00000411").getData(), null); // mainLockWrapService.buildMinorTask(agvService.getById(agvDetail12.getAgvId()), TaskTypeType.MOVE, // codeService.getCacheByData("00000403").getData(), null); return R.ok(); } // http://localhost:8088/demo/auto/go/patrol?count=10 @GetMapping("/auto/go/patrol") public R autoGoPatrol(@RequestParam(required = false, defaultValue = "5") Integer count) { List list = agvService.list(new LambdaQueryWrapper().eq(Agv::getStatus, StatusType.ENABLE.val)); // stop if (count == 0) { for (String agvNo : list.stream().map(Agv::getUuid).collect(Collectors.toList())) { if (patrolService.isPatrolling(agvNo)) { patrolService.shutdownPatrol(agvNo); } } return R.ok(); } // start Collections.shuffle(list); if (list.size() > count) { list = list.subList(0, count); } int result = 0; for (Agv agv : list) { patrolService.startupPatrol(agv.getUuid()); result++; } return R.ok().add(result); } @Autowired private MapService mapService; @Autowired private SegmentService segmentService; @GetMapping("/astarDemo") // astar spend time: 3866, count:3855 public R astarDemo() { long startTime = System.currentTimeMillis(); List path = mapService.checkoutPath("18" , codeService.getCacheByData("00001318") , codeService.getCacheByData("00003447") , true , new ArrayList<>() , segmentService.getById(1390)); System.out.println("demo spend time: " + (System.currentTimeMillis() - startTime)); return R.ok().add(path); } }