Search in sources :

Example 6 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class TaskQualityRecordController method update.

/**
 * web在提交解决方案时“在用”,但是因为 app没有在用, 即没有提交质检结果的地方。所以实际上没有作用。
 * 三期采用新的质检体系,这些都不会再被用
 */
// /
@PostMapping("/update")
public Result update(String taskQualityRecord) {
    TaskQualityRecord taskQualityRecord1 = JSON.parseObject(taskQualityRecord, TaskQualityRecord.class);
    taskQualityRecord1.setSolveTime(new Date());
    // 修改对应工序的状态为“质检中”
    TaskQualityRecord completeInfo = taskQualityRecordService.findById(taskQualityRecord1.getId());
    Integer taskRecordId = completeInfo.getTaskRecordId();
    if (taskRecordId != null && taskRecordId > 0) {
        TaskRecord tr = taskRecordService.findById(taskRecordId);
        // MQTT 异常解决后,通知工序的质检员
        String taskName = tr.getTaskName();
        Condition condition = new Condition(Task.class);
        condition.createCriteria().andCondition("task_name = ", taskName);
        List<Task> taskList = taskService.findByCondition(condition);
        if (taskList == null || taskList.size() <= 0) {
            throw new RuntimeException();
        }
        tr.setStatus(Constant.TASK_QUALITY_DOING);
        taskRecordService.update(tr);
        // 更新task record状态时候,必须去更新process record中对应task的状态
        commonService.updateTaskRecordRelatedStatus(tr);
        ProcessRecord pr = processRecordService.findById(tr.getProcessRecordId());
        Machine machine = machineService.findById(pr.getMachineId());
        ServerToClientMsg msg = new ServerToClientMsg();
        MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
        msg.setOrderNum(machineOrder.getOrderNum());
        msg.setNameplate(machine.getNameplate());
        mqttMessageHelper.sendToClient(Constant.S2C_QUALITY_ABNORMAL_RESOLVE + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
    } else {
        throw new RuntimeException();
    }
    taskQualityRecordService.update(taskQualityRecord1);
    return ResultGenerator.genSuccessResult();
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) TaskQualityRecord(com.eservice.api.model.task_quality_record.TaskQualityRecord) Date(java.util.Date) Machine(com.eservice.api.model.machine.Machine) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 7 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class InstallPlanController method addAndsendInstallPlanNow.

/**
 * 添加并立即发送(MQTT) 该排产计划 给该计划所在组的所有安装组长
 */
@PostMapping("/addAndsendInstallPlanNow")
public Result addAndsendInstallPlanNow(String installPlan) {
    InstallPlan installPlan1 = JSON.parseObject(installPlan, InstallPlan.class);
    if (installPlan1 == null) {
        return ResultGenerator.genFailResult("installPlan 解析得到null");
    }
    installPlan1.setCreateDate(new Date());
    ServerToClientMsg msg = new ServerToClientMsg();
    String str = null;
    msg.setNameplate(machineService.findById(installPlan1.getMachineId()).getNameplate());
    msg.setOrderNum(machineOrderService.findById(installPlan1.getOrderId()).getOrderNum());
    msg.setType(ServerToClientMsg.MsgType.INSTALL_PLAN);
    msg.setCmtSend(installPlan1.getCmtSend());
    msg.setInstallDatePlan(installPlan1.getInstallDatePlan());
    mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_PLAN + installPlan1.getInstallGroupId(), JSON.toJSONString(msg));
    str = "MQTT SEND topic: " + Constant.S2C_INSTALL_PLAN + installPlan1.getInstallGroupId() + ", nameplate: " + msg.getNameplate();
    logger.info(str);
    /**
     * 即使没有安装组长,也安排排产
     */
    installPlan1.setSendTime(new Date());
    installPlanService.save(installPlan1);
    logger.info(str);
    return ResultGenerator.genSuccessResult(str);
}
Also used : ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) Date(java.util.Date) InstallPlan(com.eservice.api.model.install_plan.InstallPlan)

Example 8 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class CommonService method updateTaskRecordRelatedStatus.

public boolean updateTaskRecordRelatedStatus(TaskRecord tr) {
    if (tr == null || tr.getProcessRecordId() == null) {
        return false;
    } else {
        Integer prId = tr.getProcessRecordId();
        ProcessRecord pr = processRecordService.findById(prId);
        Machine machine = machineService.findById(pr.getMachineId());
        boolean isNeedUpdateMachine = false;
        if (pr != null) {
            String nodeData = pr.getNodeData();
            List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
            NodeDataModel ndItem = null;
            Integer index = -1;
            for (int i = 0; i < ndList.size(); i++) {
                if (Integer.parseInt(ndList.get(i).getKey()) == tr.getNodeKey()) {
                    index = i;
                    break;
                }
            }
            if (index > -1) {
                ndItem = ndList.get(index);
                ndItem.setTaskStatus(tr.getStatus().toString());
                if (tr.getStatus().intValue() == Constant.TASK_PLANED.intValue() || tr.getStatus().intValue() == Constant.TASK_INSTALL_WAITING.intValue()) {
                    if (tr.getInstallBeginTime() == null) {
                        String date = Utils.getFormatStringDate(new Date(), "yyyy-MM-dd HH:mm:ss");
                        ndItem.setBeginTime(date);
                    }
                }
                if (tr.getInstallBeginTime() != null) {
                    String date = Utils.getFormatStringDate(tr.getInstallBeginTime(), "yyyy-MM-dd HH:mm:ss");
                    ndItem.setBeginTime(date);
                }
                // 质检完成,工序才算完成
                if (tr.getQualityEndTime() != null) {
                    String date = Utils.getFormatStringDate(tr.getQualityEndTime(), "yyyy-MM-dd HH:mm:ss");
                    ndItem.setEndTime(date);
                }
                // 组长信息
                if (tr.getLeader() != null && tr.getLeader().length() > 0) {
                    ndItem.setLeader(tr.getLeader());
                }
                // 工作人员信息
                if (tr.getWorkerList() != null && tr.getWorkerList().length() > 0) {
                    ndItem.setWorkList(tr.getWorkerList());
                }
                ndList.set(index, ndItem);
                // 如果当前工序是质检完成状态或者跳过状态,需要检查其子节点是否可以开始 -->3期时,工序安装完成,状态不再是“质检完成”而是“安装完成”
                if (tr.getStatus().intValue() == Constant.TASK_QUALITY_DONE.intValue() || tr.getStatus().intValue() == Constant.TASK_INSTALLED.intValue() || tr.getStatus().intValue() == Constant.TASK_SKIP.intValue()) {
                    List<LinkDataModel> linkDataList = JSON.parseArray(pr.getLinkData(), LinkDataModel.class);
                    for (LinkDataModel item : linkDataList) {
                        if (String.valueOf(item.getFrom()).equals(String.valueOf(ndItem.getKey()))) {
                            for (NodeDataModel childNode : ndList) {
                                // 先找到子节点
                                if (childNode.getKey().equals(String.valueOf(item.getTo()))) {
                                    // 找到子节点的所有父节点
                                    boolean allParentFinished = true;
                                    for (LinkDataModel parentOfChild : linkDataList) {
                                        if (!allParentFinished) {
                                            break;
                                        }
                                        if (String.valueOf(parentOfChild.getTo()).equals(childNode.getKey())) {
                                            for (NodeDataModel parentOfChildNode : ndList) {
                                                if (!allParentFinished) {
                                                    break;
                                                }
                                                if (String.valueOf(parentOfChild.getFrom()).equals(parentOfChildNode.getKey())) {
                                                    if (parentOfChildNode.getCategory() != null && (parentOfChildNode.getCategory().equals("Start") || parentOfChildNode.getCategory().equals("End"))) {
                                                        break;
                                                    }
                                                    // 3期质检,安装完成是真的“安装完成”。3期之前,安装完成时,状态是“质检完成”
                                                    if ((Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue() && Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_INSTALLED.intValue()) && Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_SKIP.intValue()) {
                                                        allParentFinished = false;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    // 子节点的所有父节点都已经完成,则更新子节点的状态
                                    if (allParentFinished) {
                                        // 如果子工序不是结束“End”
                                        if (!"End".equals(childNode.getCategory())) {
                                            if (Integer.valueOf(childNode.getTaskStatus()) < Constant.TASK_INSTALL_WAITING.intValue()) {
                                                String dateStr = Utils.getFormatStringDate(new Date(), "yyyy-MM-dd HH:mm:ss");
                                                childNode.setBeginTime(dateStr);
                                                childNode.setTaskStatus(Constant.TASK_INSTALL_WAITING.toString());
                                                List<TaskRecord> taskRecordList = taskRecordService.getTaskRecordData(null, prId);
                                                for (TaskRecord record : taskRecordList) {
                                                    if (String.valueOf(record.getNodeKey().intValue()).equals(childNode.getKey())) {
                                                        record.setUpdateTime(new Date());
                                                        record.setStatus(Constant.TASK_INSTALL_WAITING);
                                                        taskRecordService.update(record);
                                                        // MQTT 通知下一道工序可以开始安装
                                                        ServerToClientMsg msg = new ServerToClientMsg();
                                                        MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
                                                        msg.setOrderNum(machineOrder.getOrderNum());
                                                        msg.setNameplate(machine.getNameplate());
                                                        // 找到工序对应的group_id
                                                        String taskName = record.getTaskName();
                                                        Condition condition = new Condition(Task.class);
                                                        condition.createCriteria().andCondition("task_name = ", taskName);
                                                        List<Task> taskList = taskService.findByCondition(condition);
                                                        if (taskList == null || taskList.size() <= 0) {
                                                            throw new RuntimeException();
                                                        }
                                                        mqttMessageHelper.sendToClient(Constant.S2C_TASK_INSTALL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
                                                    // 这个break需要去掉,因为存在多个子工序可以安装的情况
                                                    // break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Boolean isFinished = true;
            for (int i = 0; i < ndList.size() && isFinished; i++) {
                // 开始和结束节点不考虑在内
                if (ndList.get(i).getCategory() != null && (ndList.get(i).getCategory().equals("Start") || ndList.get(i).getCategory().equals("End"))) {
                    continue;
                }
                if (ndList.get(i).getTaskStatus() != null && (Integer.parseInt(ndList.get(i).getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue() && Integer.parseInt(ndList.get(i).getTaskStatus()) != Constant.TASK_INSTALLED.intValue())) {
                    isFinished = false;
                }
            }
            // 所有工序完成
            if (isFinished && (tr.getStatus() == Constant.TASK_QUALITY_DONE.intValue() || tr.getStatus() == Constant.TASK_INSTALLED.intValue())) {
                pr.setEndTime(new Date());
                // 安装完成
                machine.setStatus(Constant.MACHINE_INSTALLED);
                isNeedUpdateMachine = true;
            }
            if (machine.getStatus().equals(Constant.MACHINE_PLANING)) {
                // 安装中
                machine.setStatus(Constant.MACHINE_INSTALLING);
                isNeedUpdateMachine = true;
            }
            if (isNeedUpdateMachine) {
                machine.setUpdateTime(new Date());
                machineService.update(machine);
            }
            pr.setNodeData(JSON.toJSONString(ndList));
            processRecordService.update(pr);
            return true;
        } else {
            return false;
        }
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) Machine(com.eservice.api.model.machine.Machine) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder)

Example 9 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class TaskRecordController method updateTaskInfo.

/**
 * 比如app扫码&结束开始时调用该接口,开始/完成一个工序各调用一次。
 * (质检报正常也是调该接口,即无论是否质检都调这个接口 --原先的质检已经弃用了)
 *
 * app扫码报异常时,调用 addTrArAi (app报正常时,调用的是 updateTaskInfo, 少了两个参数)
 * (质检报正常也是调addTrArAi)
 *
 * 开始安装,eg:
 * [     {
 *     "cmtFeedback":"",
 *     "id":55531,
 *     "installBeginTime":"20210127141618",
 *     "leader":"",
 *     "machine":{
 *         "createTime":"1609394393000",
 *         "id":5756,
 *         "isUrgent":false,
 *         "location":"上C2",
 *         "machineStrId":"CBB142313294",
 *         "machineType":2,
 *         "nameplate":"2011201",
 *         "orderId":2872,
 *         "status":3,
 *         "updateTime":"1609739671000"
 *     },
 *     "machineOrder":{
 *         "contractShipDate":"1608652800000",
 *         "headNum":"24",
 *         "id":2872,
 *         "machineType":2,
 *         "needleNum":"9",
 *         "orderNum":"骆1417C",
 *         "planShipDate":1609862400000
 *     },
 *     "nodeKey":-19,
 *     "processRecordId":5367,
 *     "status":3,  ====> "3" --> 开始安装
 *     "task":{
 *         "id":2,
 *         "qualityUserId":0
 *     },
 *     "taskName":"下轴安装",
 *     "taskPlan":{
 *         "createTime":"1609394393000",
 *         "id":51821,
 *         "planTime":1609776000000,
 *         "planType":1,
 *         "taskRecordId":55531,
 *         "updateTime":"1609739671000",
 *         "userId":169
 *     },
 *     "workerList":""
 *     }     ]
 *     扫描结束安装:
 *     [     {
 *     "cmtFeedback":"拜拜拜拜布b",
 *     "id":55531,
 *     "installBeginTime":"20210127141618",
 *     "installEndTime":"20210127141958",
 *     "leader":"a1",
 *     "machine":{
 *         "createTime":"1609394393000",
 *         "id":5756,
 *         "isUrgent":false,
 *         "location":"上C2",
 *         "machineStrId":"CBB142313294",
 *         "machineType":2,
 *         "nameplate":"2011201",
 *         "orderId":2872,
 *         "status":3,
 *         "updateTime":"1609739671000"
 *     },
 *     "machineOrder":{
 *         "contractShipDate":"1608652800000",
 *         "headNum":"24",
 *         "id":2872,
 *         "machineType":2,
 *         "needleNum":"9",
 *         "orderNum":"骆1417C",
 *         "planShipDate":1609862400000
 *     },
 *     "nodeKey":-19,
 *     "processRecordId":5367,
 *     "qualityBeginTime":"20210127141958",
 *     "qualityEndTime":"20210127141958",
 *     "status":6,  ========> "6" --> 质检完成, 三期新质检,这里不再是6,改为4
 *     "task":{
 *         "id":2,
 *         "qualityUserId":0
 *     },
 *     "taskName":"下轴安装",
 *     "taskPlan":{
 *         "createTime":"1609394393000",
 *         "id":51821,
 *         "planTime":1609776000000,
 *         "planType":1,
 *         "taskRecordId":55531,
 *         "updateTime":"1609739671000",
 *         "userId":169
 *     },
 *     "workerList":"赵建富"
 *     }     ]
 */
@PostMapping("/updateTaskInfo")
@Transactional(rollbackFor = Exception.class)
public Result updateTaskInfo(String taskRecord) {
    TaskRecord tr = JSON.parseObject(taskRecord, TaskRecord.class);
    Integer id = tr.getId();
    if (id == null || id < 0) {
        return ResultGenerator.genFailResult("TaskRecord的ID为空,数据更新失败!");
    }
    // 防止开始安装时间为空的问题
    if (tr.getStatus().intValue() == Constant.TASK_INSTALLING.intValue()) {
        try {
            if (tr.getUpdateTime() != null) {
                Integer timespan = (int) ((new Date().getTime() - tr.getUpdateTime().getTime()) / (1000 * 60 * 60));
                tr.setWaitTimespan(timespan);
                // 同步更新到ProcessRecord对应的task中
                ProcessRecord processRecord = processRecordService.findById(tr.getProcessRecordId());
                String nodeData = processRecord.getNodeData();
                List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
                for (int i = 0; i < ndList.size(); i++) {
                    if (ndList.get(i).getKey().equals(String.valueOf(tr.getNodeKey()))) {
                        ndList.get(i).setWaitTimespan(timespan);
                        ndList.get(i).setBeginTime(new Date().toString());
                        break;
                    }
                }
                processRecord.setNodeData(JSON.toJSONString(ndList));
                processRecordService.update(processRecord);
            }
        } catch (Exception ex) {
            logger.warn("updateTaskInfo exception: " + ex.getMessage());
        }
        tr.setInstallBeginTime(new Date());
    } else if (tr.getStatus().intValue() == Constant.TASK_PLANED.intValue() || tr.getStatus().intValue() == Constant.TASK_INSTALL_WAITING.intValue()) {
        ProcessRecord pr = processRecordService.findById(tr.getProcessRecordId());
        String nData = pr.getNodeData();
        List<NodeDataModel> ndList = JSON.parseArray(nData, NodeDataModel.class);
        for (int i = 0; i < ndList.size(); i++) {
            if (ndList.get(i).getKey().equals(String.valueOf(tr.getNodeKey()))) {
                if (ndList.get(i).getBeginTime() == "" || ndList.get(i).getBeginTime() == null) {
                    ndList.get(i).setBeginTime(new Date().toString());
                }
                break;
            }
        }
        pr.setNodeData(JSON.toJSONString(ndList));
        processRecordService.update(pr);
    }
    taskRecordService.update(tr);
    Integer prId = tr.getProcessRecordId();
    if (prId == null || prId < 0) {
        Logger.getLogger("").log(Level.INFO, "processrecord Id 为空");
    } else {
        // Update task record相关的状态
        if (!commonService.updateTaskRecordRelatedStatus(tr)) {
            // 更新出错进行事务回退
            throw new RuntimeException();
        }
    }
    // 找到工序对应的quality_user_id
    String taskName = tr.getTaskName();
    Condition condition = new Condition(Task.class);
    condition.createCriteria().andCondition("task_name = ", taskName);
    List<Task> taskList = taskService.findByCondition(condition);
    if (taskList == null || taskList.size() <= 0) {
        throw new RuntimeException();
    }
    ProcessRecord pr = processRecordService.findById(prId);
    Machine machine = machineService.findById(pr.getMachineId());
    MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
    ServerToClientMsg msg = new ServerToClientMsg();
    msg.setOrderNum(machineOrder.getOrderNum());
    msg.setNameplate(machine.getNameplate());
    if (tr.getStatus().equals(Constant.TASK_INSTALLED)) {
        // MQTT 如果当前工序状态是安装完成等待质检的状态,则通知App
        mqttMessageHelper.sendToClient(Constant.S2C_TASK_QUALITY + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
    }
    if (tr.getStatus().equals(Constant.TASK_INSTALLED)) {
        createInstallPlanActual(tr);
    }
    return ResultGenerator.genSuccessResult();
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) Date(java.util.Date) Machine(com.eservice.api.model.machine.Machine) NodeDataModel(com.eservice.api.service.common.NodeDataModel) List(java.util.List) ArrayList(java.util.ArrayList) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class CommonService method sendMqttMsg.

/**
 * 发送MQTT消息给订阅的app(安装组)。
 * 实例:mqtt topic: /s2c/task_remind/1, msg: {"nameplate":"namePlate123"} 其中1是 taskName为上轴安装的安装组的groupId
 *
 * @param taskName:
 * @param topic : MQTT topic
 * @param nameplate
 * @return  结果信息
 */
public String sendMqttMsg(String taskName, String topic, String nameplate) {
    String resultMsg = null;
    // taskName转groupId, 一个安装组可以有多种任务。
    InstallGroup installGroup = installGroupService.getInstallGroupByTaskName(taskName);
    if (installGroup == null) {
        resultMsg = "错误,根据taskName " + taskName + " 找不到对应的安装组";
        return resultMsg;
    }
    ServerToClientMsg msg = new ServerToClientMsg();
    msg.setNameplate(nameplate);
    mqttMessageHelper.sendToClient(topic + installGroup.getId(), JSON.toJSONString(msg));
    resultMsg = "try to send mqtt: " + topic + installGroup.getId() + " with message " + msg.getNameplate();
    return resultMsg;
}
Also used : ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) InstallGroup(com.eservice.api.model.install_group.InstallGroup)

Aggregations

ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)13 Machine (com.eservice.api.model.machine.Machine)10 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)10 Date (java.util.Date)9 Task (com.eservice.api.model.task.Task)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 Condition (tk.mybatis.mapper.entity.Condition)8 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)7 TaskRecord (com.eservice.api.model.task_record.TaskRecord)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ArrayList (java.util.ArrayList)4 InstallPlan (com.eservice.api.model.install_plan.InstallPlan)3 AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)2 Contract (com.eservice.api.model.contract.Contract)2 MachineOrderWrapper (com.eservice.api.model.contract.MachineOrderWrapper)2 ContractSign (com.eservice.api.model.contract_sign.ContractSign)2 InstallGroup (com.eservice.api.model.install_group.InstallGroup)2 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)2 OrderDetail (com.eservice.api.model.order_detail.OrderDetail)2 OrderSign (com.eservice.api.model.order_sign.OrderSign)2