package com.zy.asrs.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.zy.asrs.entity.BasCrnp; import com.zy.asrs.entity.BasDevp; import com.zy.asrs.entity.BasDualCrnp; import com.zy.asrs.entity.BasStation; import com.zy.asrs.entity.BasStationDevice; import com.zy.asrs.service.BasCrnpService; import com.zy.asrs.service.BasDevpService; import com.zy.asrs.service.BasDualCrnpService; import com.zy.asrs.service.BasStationDeviceService; import com.zy.asrs.service.BasStationService; import com.core.annotations.ManagerAuth; import com.core.common.R; import com.zy.common.web.BaseController; import com.zy.core.enums.SlaveType; import com.zy.core.model.StationObjModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/basStationDevice") public class BasStationDeviceController extends BaseController { @Autowired private BasStationDeviceService basStationDeviceService; @Autowired private BasDevpService basDevpService; @Autowired private BasStationService basStationService; @Autowired private BasCrnpService basCrnpService; @Autowired private BasDualCrnpService basDualCrnpService; @RequestMapping("/list/auth") @ManagerAuth public R list() { return R.ok(basStationDeviceService.selectList(new EntityWrapper<>())); } @RequestMapping("/save/auth") @ManagerAuth public R save(@RequestBody List list) { // Full replacement logic for simplicity in this specific UI case // First delete all existing, then insert new ones. // Note: In a production environment with high concurrency, this should be transactional and more granular. // But for a configuration page, this is acceptable. // However, to be safer, we should probably only delete for the stations involved or delete all if it's a full save. // Let's assume the UI sends the full current state of configuration. basStationDeviceService.delete(new EntityWrapper<>()); if (list != null && !list.isEmpty()) { basStationDeviceService.insertBatch(list); } return R.ok(); } @RequestMapping("/data/auth") @ManagerAuth public R getData() { Map data = new HashMap<>(); List stationList = new ArrayList<>(); List devps = basDevpService.selectList(new EntityWrapper().eq("status", 1)); for (BasDevp devp : devps) { for (StationObjModel stationObjModel : devp.getBarcodeStationList$()) { stationList.add(stationObjModel.getStationId()); } } List stations = basStationService.selectList(new EntityWrapper().in("station_id", stationList)); data.put("stations", stations); // Get Devices (Crn and DualCrn) List> devices = new ArrayList<>(); List crns = basCrnpService.selectList(new EntityWrapper().eq("status", 1)); for (BasCrnp crn : crns) { Map d = new HashMap<>(); d.put("deviceNo", crn.getCrnNo()); d.put("type", SlaveType.Crn.toString()); d.put("name", "堆垛机 " + crn.getCrnNo()); devices.add(d); } List dualCrns = basDualCrnpService.selectList(new EntityWrapper().eq("status", 1)); for (BasDualCrnp dualCrn : dualCrns) { Map d = new HashMap<>(); d.put("deviceNo", dualCrn.getCrnNo()); d.put("type", SlaveType.DualCrn.toString()); d.put("name", "双工位堆垛机 " + dualCrn.getCrnNo()); devices.add(d); } data.put("devices", devices); // Get existing relations List relations = basStationDeviceService.selectList(new EntityWrapper<>()); data.put("relations", relations); return R.ok(data); } }