| | |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.entity.param.ArmPrecomputeParam; |
| | | import com.zy.asrs.service.OpenService; |
| | | import com.zy.asrs.service.impl.WrkMastServiceImpl; |
| | | import com.zy.common.web.BaseController; |
| | | import com.zy.core.cache.RgvStatusCache; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.CrnSlave; |
| | | import com.zy.core.model.DevpSlave; |
| | | import com.zy.core.model.protocol.CrnProtocol; |
| | | import com.zy.core.model.protocol.RgvProtocol; |
| | | import com.zy.core.model.protocol.StaProtocol; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.SiemensCrnThread; |
| | | import com.zy.core.thread.SiemensDevpThread; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import com.zy.asrs.entity.param.TaskCreateParam; |
| | | |
| | | /** |
| | | * Created by vincent on 2024/10/16 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("open/hd") |
| | | @RequestMapping("open/") |
| | | public class OpenController extends BaseController { |
| | | |
| | | private static final boolean auth = true; |
| | |
| | | |
| | | @Autowired |
| | | private OpenService openService; |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkMastServiceImpl wrkMastService; |
| | | |
| | | /** |
| | | * 添加出库单 |
| | |
| | | return R.ok().add(param); |
| | | } |
| | | |
| | | /** |
| | | * 设备状态 |
| | | */ |
| | | @PostMapping("/deviceStatus") |
| | | @AppAuth(memo = "设备状态获取") |
| | | public R deviceStatus( |
| | | @RequestHeader(required = false) String appkey, |
| | | HttpServletRequest request) { |
| | | |
| | | try { |
| | | auth(appkey, null, request); |
| | | } catch (Exception e) { |
| | | return new R(403, e.getMessage()); |
| | | } |
| | | |
| | | // 1. 站点 |
| | | List<Map<String, Object>> devList = new ArrayList<>(); |
| | | if (slaveProperties.getDevp() != null) { |
| | | for (DevpSlave devpSlave : slaveProperties.getDevp()) { |
| | | SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devpSlave.getId()); |
| | | if (devpThread != null && devpThread.getStation() != null) { |
| | | for (StaProtocol staProtocol : devpThread.getStation().values()) { |
| | | Map<String, Object> dev = new HashMap<>(); |
| | | dev.put("devNo", staProtocol.getSiteId()); |
| | | dev.put("inEnable", staProtocol.isInEnable() ? "1" : "0"); |
| | | dev.put("outEnable", staProtocol.isOutEnable() ? "1" : "0"); |
| | | dev.put("autoing", staProtocol.isAutoing() ? "1" : "0"); |
| | | dev.put("loading", staProtocol.isLoading() ? "1" : "0"); |
| | | dev.put("wrkNo", staProtocol.getWorkNo()); |
| | | dev.put("barcode", staProtocol.getBarcode()); |
| | | dev.put("devErr", staProtocol.getErrorDev$()); |
| | | dev.put("devErrM", staProtocol.getExceptions()); |
| | | devList.add(dev); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | devList.sort(Comparator.comparingInt(m -> (Integer) m.get("devNo"))); |
| | | |
| | | // 2. 堆垛机 |
| | | List<Map<String, Object>> crnList = new ArrayList<>(); |
| | | if (slaveProperties.getCrn() != null) { |
| | | for (CrnSlave crnSlave : slaveProperties.getCrn()) { |
| | | SiemensCrnThread crnThread = (SiemensCrnThread) SlaveConnection.get(SlaveType.Crn, crnSlave.getId()); |
| | | if (crnThread != null && crnThread.getCrnProtocol() != null) { |
| | | CrnProtocol crnProtocol = crnThread.getCrnProtocol(); |
| | | Map<String, Object> crn = new HashMap<>(); |
| | | crn.put("crnNo", crnProtocol.getCrnNo()); |
| | | crn.put("crnNoH", crnProtocol.getCrnNo()); |
| | | crn.put("crnSts", crnProtocol.getMode()); |
| | | crn.put("wrkNo", crnProtocol.getTaskNo()); |
| | | crn.put("crnErr", crnProtocol.getAlarm()); |
| | | crn.put("crnErrM", crnProtocol.getExceptions()); |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no",crnProtocol.getTaskNo())); |
| | | crn.put("frmLocno",wrkMast != null ? wrkMast.getSourceLocNo():null); |
| | | crn.put("frmSta",wrkMast != null ? wrkMast.getSourceStaNo():0); |
| | | crn.put("toSta", wrkMast != null? wrkMast.getStaNo():0); |
| | | crn.put("toLocno", wrkMast != null ? wrkMast.getLocNo():null); |
| | | crnList.add(crn); |
| | | } |
| | | } |
| | | } |
| | | crnList.sort(Comparator.comparingInt(m -> (Integer) m.get("crnNo"))); |
| | | |
| | | // 3. 穿梭车 |
| | | List<Map<String, Object>> steList = new ArrayList<>(); |
| | | Map<Integer, RgvProtocol> rgvMap = RgvStatusCache.getAllRgvStatus(); |
| | | if (rgvMap != null) { |
| | | for (RgvProtocol rgvProtocol : rgvMap.values()) { |
| | | Map<String, Object> ste = new HashMap<>(); |
| | | ste.put("steNo", rgvProtocol.getRgvNo()); |
| | | ste.put("crnSts", rgvProtocol.getStatusType() != null ? rgvProtocol.getStatusType().id : 1); |
| | | ste.put("wrkNo", rgvProtocol.getTaskNo()); |
| | | ste.put("steErr", rgvProtocol.getAlarm$()); |
| | | ste.put("steErrM", rgvProtocol.getAlarmM()); |
| | | steList.add(ste); |
| | | } |
| | | } |
| | | steList.sort(Comparator.comparingInt(m -> (Integer) m.get("steNo"))); |
| | | |
| | | R r = R.ok(); |
| | | r.put("devList", devList); |
| | | r.put("crnList", crnList); |
| | | r.put("steList", steList); |
| | | return r; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 任务下发 |
| | | */ |
| | | @PostMapping("/taskCreate") |
| | | @AppAuth(memo = "任务下发") |
| | | public R taskCreate(@RequestHeader(required = false) String appkey, |
| | | @RequestBody TaskCreateParam param, |
| | | HttpServletRequest request) { |
| | | try { |
| | | auth(appkey, param, request); |
| | | } catch (Exception e) { |
| | | return new R(403, e.getMessage()); |
| | | } |
| | | |
| | | if (Cools.isEmpty(param)) { |
| | | return R.parse(BaseRes.PARAM); |
| | | } |
| | | |
| | | if (Cools.isEmpty(param.getTaskNo())) { |
| | | return R.error("工作号[taskNo]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getBarcode())) { |
| | | return R.error("容器编码[barcode]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getStartPoint())) { |
| | | return R.error("起点[startPoint]不能为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getTargetPoint())) { |
| | | return R.error("目标点[targetPoint]不能为空"); |
| | | } |
| | | |
| | | try { |
| | | boolean result = openService.taskCreate(param); |
| | | if (result) { |
| | | return R.ok("任务下发成功"); |
| | | } else { |
| | | return R.error("任务下发失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("任务下发异常", e); |
| | | return R.error("任务下发异常: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private void auth(String appkey, Object obj, HttpServletRequest request) { |
| | | // log.info("{}接口被访问;appkey:{};请求数据:{}", "open/sensorType/list/auth/v1", appkey, JSON.toJSONString(obj)); |