|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.common.Arith; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.domain.dto.AxisBean; | 
|---|
|  |  |  | import com.zy.asrs.domain.dto.WorkChartAxis; | 
|---|
|  |  |  | import com.zy.asrs.domain.dto.LocChartPie; | 
|---|
|  |  |  | import com.zy.asrs.domain.dto.WrkDetl; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasDevp; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasShuttle; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasShuttleErr; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleErrService; | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleService; | 
|---|
|  |  |  | import com.zy.asrs.service.WrkMastService; | 
|---|
|  |  |  | import com.zy.common.model.MatDto; | 
|---|
|  |  |  | import com.zy.common.model.SearchLocParam; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.core.cache.SlaveConnection; | 
|---|
|  |  |  | import com.zy.core.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.core.model.ShuttleSlave; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.zy.core.properties.SlaveProperties; | 
|---|
|  |  |  | import com.zy.core.thread.ShuttleThread; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private SlaveProperties slaveProperties; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasShuttleErrService basShuttleErrService; | 
|---|
|  |  |  | @Value("${asrs.wmsUrl}") | 
|---|
|  |  |  | private String wmsUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取当前时间 | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取其他信息 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | //    @GetMapping("/led") | 
|---|
|  |  |  | //    public R monitorLed(@RequestParam("ledId") Integer ledId) { | 
|---|
|  |  |  | //        BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", ledId)); | 
|---|
|  |  |  | //        if (Cools.isEmpty(basDevp)) { | 
|---|
|  |  |  | //            return R.ok(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wrk_no", basDevp.getWrkNo())); | 
|---|
|  |  |  | //        if (Cools.isEmpty(wrkMast)) { | 
|---|
|  |  |  | //            return R.ok(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        List<LedCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        // 组装命令 | 
|---|
|  |  |  | //        LedCommand ledCommand = new LedCommand(); | 
|---|
|  |  |  | //        ledCommand.setWorkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | //        ledCommand.setIoType(wrkMast.getIoType()); | 
|---|
|  |  |  | //        // 出库模式 | 
|---|
|  |  |  | //        switch (wrkMast.getIoType()) { | 
|---|
|  |  |  | //            case 1: | 
|---|
|  |  |  | //                ledCommand.setTitle("全板入库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 10: | 
|---|
|  |  |  | //                ledCommand.setTitle("空板入库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 101: | 
|---|
|  |  |  | //                ledCommand.setTitle("全板出库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 103: | 
|---|
|  |  |  | //                ledCommand.setTitle("拣料出库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 104: | 
|---|
|  |  |  | //                ledCommand.setTitle("并板出库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 107: | 
|---|
|  |  |  | //                ledCommand.setTitle("盘点出库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 110: | 
|---|
|  |  |  | //                ledCommand.setTitle("空板出库"); | 
|---|
|  |  |  | //                ledCommand.setEmptyMk(true); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 53: | 
|---|
|  |  |  | //                ledCommand.setTitle("拣料入库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 57: | 
|---|
|  |  |  | //                ledCommand.setTitle("盘点入库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            case 54: | 
|---|
|  |  |  | //                ledCommand.setTitle("并板入库"); | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //            default: | 
|---|
|  |  |  | //                break; | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); | 
|---|
|  |  |  | //        ledCommand.setLocNo(wrkMast.getLocNo()); | 
|---|
|  |  |  | //        ledCommand.setStaNo(wrkMast.getStaNo()); | 
|---|
|  |  |  | ////                ledCommand.setSourceStaNo(wrkMast.getSourceStaNo()); | 
|---|
|  |  |  | //        if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) { | 
|---|
|  |  |  | //            List<WrkDetl> wrkDetls = wrkDetlService.selectByWrkNo(wrkMast.getWrkNo()); | 
|---|
|  |  |  | //            try { | 
|---|
|  |  |  | //                if (wrkMast.getIoType() > 100) { | 
|---|
|  |  |  | //                    for (WrkDetl wrkDetl : wrkDetls) { | 
|---|
|  |  |  | //                        LocDetl locDetl = locDetlService.selectMatnrSpecs(wrkDetl.getMatnr(), wrkDetl.getSpecs(), wrkMast.getSourceLocNo()); | 
|---|
|  |  |  | //                        wrkDetl.setWeight(locDetl.getAnfme()); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    for (WrkDetl wrkDetl : wrkDetls) { | 
|---|
|  |  |  | //                        wrkDetl.setWeight(wrkDetl.getAnfme()); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } catch (Exception e) { | 
|---|
|  |  |  | ////                log.error("工作档案明细输入电视机失败1:异常信息==》"+e); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getWeight(), wrkDetl.getSpecs(), wrkDetl.getModel()))); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        commands.add(ledCommand); | 
|---|
|  |  |  | //        return R.ok().add(commands); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | @GetMapping("/led") | 
|---|
|  |  |  | public R monitorLed(@RequestParam("ledId") Integer ledId) { | 
|---|
|  |  |  | BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("dev_no", ledId)); | 
|---|
|  |  |  | if (Cools.isEmpty(basDevp)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("wms_wrk_no", basDevp.getWrkNo())); | 
|---|
|  |  |  | if (Cools.isEmpty(wrkMast)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<LedCommand> commands = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 组装命令 | 
|---|
|  |  |  | LedCommand ledCommand = new LedCommand(); | 
|---|
|  |  |  | ledCommand.setWorkNo(wrkMast.getWmsWrkNo()); | 
|---|
|  |  |  | ledCommand.setIoType(wrkMast.getIoType()); | 
|---|
|  |  |  | // 出库模式 | 
|---|
|  |  |  | switch (wrkMast.getIoType()) { | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | ledCommand.setTitle("全板入库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 10: | 
|---|
|  |  |  | ledCommand.setTitle("空板入库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 101: | 
|---|
|  |  |  | ledCommand.setTitle("全板出库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 103: | 
|---|
|  |  |  | ledCommand.setTitle("拣料出库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 104: | 
|---|
|  |  |  | ledCommand.setTitle("并板出库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 107: | 
|---|
|  |  |  | ledCommand.setTitle("盘点出库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 110: | 
|---|
|  |  |  | ledCommand.setTitle("空板出库"); | 
|---|
|  |  |  | ledCommand.setEmptyMk(true); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 53: | 
|---|
|  |  |  | ledCommand.setTitle("拣料入库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 57: | 
|---|
|  |  |  | ledCommand.setTitle("盘点入库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 54: | 
|---|
|  |  |  | ledCommand.setTitle("并板入库"); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ledCommand.setSourceLocNo(wrkMast.getSourceLocNo()); | 
|---|
|  |  |  | ledCommand.setLocNo(wrkMast.getLocNo()); | 
|---|
|  |  |  | ledCommand.setStaNo(wrkMast.getStaNo()); | 
|---|
|  |  |  | if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) { | 
|---|
|  |  |  | Map<String, Object> param = new HashMap<>(); | 
|---|
|  |  |  | param.put("taskNo", wrkMast.getWmsWrkNo()); | 
|---|
|  |  |  | param.put("sta", wrkMast.getStaNo()); | 
|---|
|  |  |  | String response = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath("/rpc/led/getTask2") | 
|---|
|  |  |  | .setJson(JSON.toJSONString(param)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | Integer code = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if (code.equals(200)) { | 
|---|
|  |  |  | String data = jsonObject.getString("data"); | 
|---|
|  |  |  | List<LedCommand> wrkDetls = JSONArray.parseArray(data, LedCommand.class); | 
|---|
|  |  |  | commands.addAll(wrkDetls); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(commands); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 异常通知 | 
|---|
|  |  |  | 
|---|
|  |  |  | @GetMapping("/device/error") | 
|---|
|  |  |  | public R monitorDeviceError() { | 
|---|
|  |  |  | ArrayList<HashMap<String, Object>> list = new ArrayList<>(); | 
|---|
|  |  |  | List<BasShuttle> basCrnpLiset = shuttleService.selectList(new EntityWrapper<BasShuttle>()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { | 
|---|
|  |  |  | // 获取四向穿梭车信息 | 
|---|