Search in sources :

Example 11 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord 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 12 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord 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 13 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord in project sinsim by WilsonHu.

the class TaskRecordController method selectNotPlanedTaskRecord.

// 根据机器的流程记录ID,返回未计划的作业任务(task plan)
@PostMapping("/selectNotPlanedTaskRecord")
public Result selectNotPlanedTaskRecord(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, Integer processRecordID) {
    PageHelper.startPage(page, size);
    List<TaskRecord> list = taskRecordService.selectNotPlanedTaskRecord(processRecordID);
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) PageInfo(com.github.pagehelper.PageInfo) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 14 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord 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 15 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord in project sinsim by WilsonHu.

the class TaskRecordController method list.

@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
    PageHelper.startPage(page, size);
    List<TaskRecord> list = taskRecordService.findAll();
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) PageInfo(com.github.pagehelper.PageInfo) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

TaskRecord (com.eservice.api.model.task_record.TaskRecord)20 PostMapping (org.springframework.web.bind.annotation.PostMapping)17 Machine (com.eservice.api.model.machine.Machine)10 Condition (tk.mybatis.mapper.entity.Condition)10 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)9 Transactional (org.springframework.transaction.annotation.Transactional)9 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)7 Task (com.eservice.api.model.task.Task)7 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 PageInfo (com.github.pagehelper.PageInfo)4 AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)3 TaskQualityRecord (com.eservice.api.model.task_quality_record.TaskQualityRecord)3 NodeDataModel (com.eservice.api.service.common.NodeDataModel)3 AbnormalImage (com.eservice.api.model.abnormal_image.AbnormalImage)2 QualityRecordImage (com.eservice.api.model.quality_record_image.QualityRecordImage)2 TaskPlan (com.eservice.api.model.task_plan.TaskPlan)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 Abnormal (com.eservice.api.model.abnormal.Abnormal)1