Search in sources :

Example 1 with ProcessRecord

use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.

the class TaskPlanServiceImpl method addTaskPlans.

// 每新增1个工序,调用一次。
@Transactional(rollbackFor = Exception.class)
public boolean addTaskPlans(@RequestParam List<Integer> taskRecordIds, Integer planType, String machineStrId, Date planDate, Integer userId) {
    for (int i = 0; i < taskRecordIds.size(); i++) {
        Condition tempCondition = new Condition(TaskPlan.class);
        Integer id = taskRecordIds.get(i);
        tempCondition.createCriteria().andCondition("task_record_id = ", id);
        List<TaskPlan> existPlans = findByCondition(tempCondition);
        if (existPlans.size() > 0) {
            return false;
        }
        TaskPlan plan = new TaskPlan();
        plan.setCreateTime(new Date());
        plan.setUserId(userId);
        plan.setTaskRecordId(id);
        plan.setPlanType(Constant.DAILY_PLAN);
        if (planType.intValue() == Constant.DAILY_PLAN.intValue()) {
            plan.setPlanTime(planDate);
        } else if (planType.intValue() == Constant.FLEX_PLAN.intValue()) {
            plan.setDeadline(planDate);
        }
        save(plan);
        // 更改task record状态为已计划
        TaskRecord taskRecord = taskRecordService.findById(id);
        if (taskRecord != null) {
            // 检查是否为第一个计划项,如果是,需要设置为待安装状态
            Integer processRecordId = taskRecord.getProcessRecordId();
            ProcessRecord processRecord = processRecordService.findById(processRecordId);
            List<LinkDataModel> linkDataList = JSON.parseArray(processRecord.getLinkData(), LinkDataModel.class);
            for (LinkDataModel item : linkDataList) {
                if (item.getTo().equals(taskRecord.getNodeKey().intValue())) {
                    if (item.getFrom() == null || item.getFrom() == -1) {
                        taskRecord.setUpdateTime(new Date());
                        taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
                        break;
                    } else {
                        // TODO:如果是重新配置流程项,比如:改单、拆单以后再最后增加了安装项,则需要设置成待安装状态
                        List<Integer> parentNodeList = new ArrayList<>();
                        String nodeData = processRecord.getNodeData();
                        List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
                        for (LinkDataModel tmp : linkDataList) {
                            if (tmp.getTo() == taskRecord.getNodeKey().intValue()) {
                                parentNodeList.add(tmp.getFrom());
                            }
                        }
                        boolean allParentFinished = true;
                        for (Integer parentNodeKey : parentNodeList) {
                            for (NodeDataModel nodeDataModel : ndList) {
                                if (parentNodeKey.intValue() == Integer.valueOf(nodeDataModel.getKey())) {
                                    if (Integer.valueOf(nodeDataModel.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue()) {
                                        allParentFinished = false;
                                        break;
                                    }
                                }
                            }
                            if (!allParentFinished) {
                                break;
                            }
                        }
                        if (allParentFinished) {
                            taskRecord.setUpdateTime(new Date());
                            taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
                        }
                    }
                }
            }
            if (taskRecord.getStatus().equals(Constant.TASK_INITIAL)) {
                taskRecord.setStatus(Constant.TASK_PLANED);
            }
            taskRecordService.update(taskRecord);
            // 更新task_record以外,但是跟task record相关的状态,机器状态,process_record中的task_status
            commonService.updateTaskRecordRelatedStatus(taskRecord);
            if (taskRecord.getStatus().equals(Constant.TASK_INSTALL_WAITING)) {
                // MQTT 计划后,通知安装组长,可以进行安装
                String taskName = taskRecord.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(taskRecord.getProcessRecordId());
                Machine machine = machineService.findById(pr.getMachineId());
                MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
                ServerToClientMsg msg = new ServerToClientMsg();
                msg.setOrderNum(machineOrder.getOrderNum());
                msg.setNameplate(machine.getNameplate());
                mqttMessageHelper.sendToClient(Constant.S2C_TASK_INSTALL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
            }
            // /在”计划管理“中 添加计划安排时,自动添加了 总装排产 InstallPlan。 (InstallPlanActual则在app扫码完成工序时添加)
            // 因为把总装排产,合并到“计划管理”,所以需要在安排计划时 自动生成总装排产(这样在app上扫码完成时,才能有总装完成自动填充完成头数)
            InstallPlan installPlan1 = new InstallPlan();
            installPlan1.setType(Constant.STR_INSTALL_TYPE_WHOLE);
            InstallGroup installGroup = installGroupService.getInstallGroupByTaskName(taskRecord.getTaskName());
            installPlan1.setInstallGroupId(installGroup.getId());
            installPlan1.setInstallDatePlan(plan.getPlanTime());
            ProcessRecord pr = processRecordService.findById(taskRecord.getProcessRecordId());
            Machine machine = machineService.findById(pr.getMachineId());
            MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
            installPlan1.setOrderId(machineOrder.getId());
            installPlan1.setMachineId(machine.getId());
            installPlan1.setValid(Byte.valueOf("1"));
            installPlan1.setCreateDate(new Date());
            installPlanService.save(installPlan1);
            logger.info("自动添加了 总装排产 for 铭牌号: " + machine.getNameplate() + ", 工序: " + taskRecord.getTaskName());
        } else {
            // 进行事务操作
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException();
        }
    }
    if (taskRecordIds.size() > 0 && machineStrId != null) {
        List<Machine> machineList = machineService.selectMachines(null, null, null, machineStrId, null, null, null, null, null, null, false);
        if (machineList.size() == 1) {
            // 如果机器状态小于计划中,则更新为计划中
            Machine machine = machineList.get(0);
            if (machine.getStatus() < Constant.MACHINE_PLANING) {
                machine.setStatus(Constant.MACHINE_PLANING);
                machineService.update(machine);
            }
        } else {
            // 进行事务rollback操作
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new RuntimeException();
        }
    }
    return true;
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) TaskPlan(com.eservice.api.model.task_plan.TaskPlan) ArrayList(java.util.ArrayList) InstallGroup(com.eservice.api.model.install_group.InstallGroup) Machine(com.eservice.api.model.machine.Machine) NodeDataModel(com.eservice.api.service.common.NodeDataModel) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Condition(tk.mybatis.mapper.entity.Condition) LinkDataModel(com.eservice.api.service.common.LinkDataModel) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) Date(java.util.Date) InstallPlan(com.eservice.api.model.install_plan.InstallPlan) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ProcessRecord

use of com.eservice.api.model.process_record.ProcessRecord 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 3 with ProcessRecord

use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.

the class ProcessRecordController method list.

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

Example 4 with ProcessRecord

use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.

the class ProcessRecordController method update.

@PostMapping("/update")
public Result update(String processRecord) {
    ProcessRecord processRecord1 = JSON.parseObject(processRecord, ProcessRecord.class);
    processRecordService.update(processRecord1);
    return ResultGenerator.genSuccessResult();
}
Also used : ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with ProcessRecord

use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.

the class AbnormalRecordController method update.

@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String abnormalRecord) {
    AbnormalRecord abnormalRecord1 = JSON.parseObject(abnormalRecord, AbnormalRecord.class);
    abnormalRecord1.setSolveTime(new Date());
    if (abnormalRecord1.getSolution() == null || abnormalRecord1.getSolution().isEmpty()) {
        // abnormalRecord1.setSolution("空");
        return ResultGenerator.genFailResult("请填写解决内容");
    }
    // 修改对应工序的状态为"安装中"或者“质检中”,需要检查安装开始时间和质检开始时间,质检已开始则状态为质检中
    AbnormalRecord completeInfo = abnormalRecordService.findById(abnormalRecord1.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_INSTALLING);
        taskRecordService.update(tr);
        // 更新task record状态时候,必须去更新process record中对应task的状态
        commonService.updateTaskRecordRelatedStatus(tr);
        ProcessRecord pr = processRecordService.findById(tr.getProcessRecordId());
        Machine machine = machineService.findById(pr.getMachineId());
        MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
        ServerToClientMsg msg = new ServerToClientMsg();
        msg.setOrderNum(machineOrder.getOrderNum());
        msg.setNameplate(machine.getNameplate());
        mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_ABNORMAL_RESOLVE + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
    } else {
        throw new RuntimeException();
    }
    abnormalRecordService.update(abnormalRecord1);
    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) AbnormalRecord(com.eservice.api.model.abnormal_record.AbnormalRecord) 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)

Aggregations

ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)12 Machine (com.eservice.api.model.machine.Machine)9 TaskRecord (com.eservice.api.model.task_record.TaskRecord)9 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)8 Condition (tk.mybatis.mapper.entity.Condition)8 Task (com.eservice.api.model.task.Task)7 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 NodeDataModel (com.eservice.api.service.common.NodeDataModel)3 AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)2 InstallGroup (com.eservice.api.model.install_group.InstallGroup)2 InstallPlan (com.eservice.api.model.install_plan.InstallPlan)2 TaskPlan (com.eservice.api.model.task_plan.TaskPlan)2 TaskQualityRecord (com.eservice.api.model.task_quality_record.TaskQualityRecord)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 AbnormalImage (com.eservice.api.model.abnormal_image.AbnormalImage)1 InstallPlanActual (com.eservice.api.model.install_plan_actual.InstallPlanActual)1