Search in sources :

Example 16 with Condition

use of tk.mybatis.mapper.entity.Condition in project sinsim by WilsonHu.

the class TaskPlanServiceImpl method addTaskPlans.

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);
        tempCondition.createCriteria().andCondition("task_record_id = ", taskRecordIds.get(i));
        List<TaskPlan> existPlans = findByCondition(tempCondition);
        if (existPlans.size() > 0) {
            return false;
        }
        TaskPlan plan = new TaskPlan();
        plan.setCreateTime(new Date());
        plan.setUserId(userId);
        plan.setTaskRecordId(taskRecordIds.get(i));
        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(taskRecordIds.get(i));
        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.setStatus(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));
                        // /                            }
                        break;
                    }
                }
            }
            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);
        } else {
            // 进行事务操作
            throw new RuntimeException();
        }
    }
    if (taskRecordIds.size() > 0 && machineStrId != null) {
        List<Machine> machineList = machineService.selectMachines(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操作
            throw new RuntimeException();
        }
    }
    return true;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) LinkDataModel(com.eservice.api.service.common.LinkDataModel) TaskPlan(com.eservice.api.model.task_plan.TaskPlan) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) 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)

Example 17 with Condition

use of tk.mybatis.mapper.entity.Condition 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.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);
                // TODO:如果当前工序是质检完成状态,需要检查其子节点是否可以开始
                if (tr.getStatus().intValue() == Constant.TASK_QUALITY_DONE.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 (parentOfChildNode.getCategory().equals("Start") || parentOfChildNode.getCategory().equals("End") || !allParentFinished) {
                                                    break;
                                                }
                                                if (Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue()) {
                                                    allParentFinished = false;
                                                }
                                            }
                                        }
                                    }
                                    // 子节点的所有父节点都已经完成,则更新子节点的状态
                                    if (allParentFinished) {
                                        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.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(); i++) {
                if (ndList.get(i).getTaskStatus() != null && Integer.parseInt(ndList.get(i).getTaskStatus()) == Constant.TASK_QUALITY_DONE.intValue()) {
                    isFinished = false;
                }
            }
            // 所有工序完成
            if (isFinished && tr.getStatus() == Constant.TASK_QUALITY_DONE.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 18 with Condition

use of tk.mybatis.mapper.entity.Condition in project sinsim by WilsonHu.

the class CommonService method createMachineByContractId.

/**
 * 根据合同编号对应的需求单的机器
 *
 * @param contractId
 */
public void createMachineByContractId(Integer contractId) {
    Condition condition = new Condition(MachineOrder.class);
    condition.createCriteria().andCondition("contract_id = ", contractId);
    List<MachineOrder> orderList = machineOrderService.findByCondition(condition);
    for (MachineOrder orderItem : orderList) {
        // 选取有效需求单,无效需求单对应的机器数不cover在内
        if (orderItem.getStatus().equals(Constant.ORDER_CHECKING_FINISHED) || orderItem.getStatus().equals(Constant.ORDER_SPLITED)) {
            Condition tempCondition = new Condition(Machine.class);
            tempCondition.createCriteria().andCondition("order_id = ", orderItem.getId());
            List<Machine> machineExistList = machineService.findByCondition(tempCondition);
            int haveToCreate = orderItem.getMachineNum() - machineExistList.size();
            int i = 1;
            while (i <= haveToCreate) {
                Machine machine = new Machine();
                machine.setMachineStrId(Utils.createMachineBasicId() + i);
                machine.setOrderId(orderItem.getId());
                machine.setMachineType(orderItem.getMachineType());
                machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_INITIAL)));
                machine.setCreateTime(new Date());
                machineService.save(machine);
                i++;
            }
        }
    }
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Machine(com.eservice.api.model.machine.Machine)

Example 19 with Condition

use of tk.mybatis.mapper.entity.Condition in project sinsim by WilsonHu.

the class MachineServiceImpl method selectPlanningMachines.

public List<MachinePlan> selectPlanningMachines(String orderNum, String machine_strid, String nameplate, String location, Byte status, Integer machineType, Integer dateType, String query_start_time, String query_finish_time, Boolean is_fuzzy) {
    List<MachinePlan> machinePlanList = new ArrayList<>();
    if (is_fuzzy) {
        machinePlanList = machineMapper.selectPlanningMachinesFuzzy(orderNum, machine_strid, nameplate, location, status, machineType, dateType, query_start_time, query_finish_time);
    } else {
        machinePlanList = machineMapper.selectPlanningMachines(orderNum, machine_strid, nameplate, location, status, machineType, dateType, query_start_time, query_finish_time);
    }
    for (MachinePlan itemPlan : machinePlanList) {
        // 获取机器对应task record,
        Condition tempCondition = new Condition(TaskRecord.class);
        tempCondition.createCriteria().andCondition("process_record_id = ", itemPlan.getProcessRecordID());
        tempCondition.createCriteria().andGreaterThanOrEqualTo("status", Constant.TASK_INITIAL);
        List<TaskRecord> taskRecordList = taskRecordService.findByCondition(tempCondition);
        HashMap<Byte, Integer> taskStatusMap = new HashMap<>();
        for (TaskRecord record : taskRecordList) {
            if (record.getStatus().equals(Constant.TASK_PLANED)) {
                if (taskStatusMap.get(Constant.TASK_PLANED) != null) {
                    taskStatusMap.put(Constant.TASK_PLANED, taskStatusMap.get(Constant.TASK_PLANED) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_PLANED, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_INSTALL_WAITING)) {
                if (taskStatusMap.get(Constant.TASK_INSTALL_WAITING) != null) {
                    taskStatusMap.put(Constant.TASK_INSTALL_WAITING, taskStatusMap.get(Constant.TASK_INSTALL_WAITING) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_INSTALL_WAITING, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_INSTALLING)) {
                if (taskStatusMap.get(Constant.TASK_INSTALLING) != null) {
                    taskStatusMap.put(Constant.TASK_INSTALLING, taskStatusMap.get(Constant.TASK_INSTALLING) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_INSTALLING, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_INSTALLED)) {
                if (taskStatusMap.get(Constant.TASK_INSTALLED) != null) {
                    taskStatusMap.put(Constant.TASK_INSTALLED, taskStatusMap.get(Constant.TASK_INSTALLED) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_INSTALLED, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_QUALITY_DOING)) {
                if (taskStatusMap.get(Constant.TASK_QUALITY_DOING) != null) {
                    taskStatusMap.put(Constant.TASK_QUALITY_DOING, taskStatusMap.get(Constant.TASK_QUALITY_DOING) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_QUALITY_DOING, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_QUALITY_DONE)) {
                if (taskStatusMap.get(Constant.TASK_QUALITY_DONE) != null) {
                    taskStatusMap.put(Constant.TASK_QUALITY_DONE, taskStatusMap.get(Constant.TASK_QUALITY_DONE) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_QUALITY_DONE, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_INSTALL_ABNORMAL)) {
                if (taskStatusMap.get(Constant.TASK_INSTALL_ABNORMAL) != null) {
                    taskStatusMap.put(Constant.TASK_INSTALL_ABNORMAL, taskStatusMap.get(Constant.TASK_INSTALL_ABNORMAL) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_INSTALL_ABNORMAL, 1);
                }
            } else if (record.getStatus().equals(Constant.TASK_QUALITY_ABNORMAL)) {
                if (taskStatusMap.get(Constant.TASK_QUALITY_ABNORMAL) != null) {
                    taskStatusMap.put(Constant.TASK_QUALITY_ABNORMAL, taskStatusMap.get(Constant.TASK_QUALITY_ABNORMAL) + 1);
                } else {
                    taskStatusMap.put(Constant.TASK_QUALITY_ABNORMAL, 1);
                }
            }
        }
        itemPlan.setPlanedTaskNum(taskStatusMap.get(Constant.TASK_PLANED));
        itemPlan.setInstallWaitingTaskNum(taskStatusMap.get(Constant.TASK_INSTALL_WAITING));
        itemPlan.setInstalledTaskNum(taskStatusMap.get(Constant.TASK_INSTALLED));
        itemPlan.setInstallingTaskNum(taskStatusMap.get(Constant.TASK_INSTALLING));
        itemPlan.setInstallAbnormalTaskNum(taskStatusMap.get(Constant.TASK_INSTALL_ABNORMAL));
        itemPlan.setQualityDoingTaskNum(taskStatusMap.get(Constant.TASK_QUALITY_DOING));
        itemPlan.setQualityDoneTaskNum(taskStatusMap.get(Constant.TASK_QUALITY_DONE));
        itemPlan.setQualityAbnormalTaskNum(taskStatusMap.get(Constant.TASK_QUALITY_ABNORMAL));
    }
    return machinePlanList;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) HashMap(java.util.HashMap) MachinePlan(com.eservice.api.model.machine.MachinePlan) ArrayList(java.util.ArrayList)

Example 20 with Condition

use of tk.mybatis.mapper.entity.Condition in project new-cloud by xie-summer.

the class PanoramicIntoTheFactoryRecordsServiceImpl method count.

@Override
public Integer count(String date) {
    Condition condition = new Condition(PanoramicIntoTheFactoryRecords.class, false);
    condition.createCriteria().andCondition(" delete_flag=1 and err_msg is not null and status=1 and date_format(snapshot_time,'%Y%m%d') = date_format('" + date + "','%Y%m%d') ");
    Integer count = intoTheFactoryRecordsMapper.selectCountByCondition(condition);
    return count;
}
Also used : Condition(tk.mybatis.mapper.entity.Condition)

Aggregations

Condition (tk.mybatis.mapper.entity.Condition)59 Criteria (tk.mybatis.mapper.entity.Example.Criteria)25 Transactional (org.springframework.transaction.annotation.Transactional)17 PostMapping (org.springframework.web.bind.annotation.PostMapping)13 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)10 Machine (com.eservice.api.model.machine.Machine)8 PageInfo (com.github.pagehelper.PageInfo)8 TaskRecord (com.eservice.api.model.task_record.TaskRecord)6 PanoramicRealTimeConsumptionGather (com.monitor.model.realtimeconsumptiongather.PanoramicRealTimeConsumptionGather)6 Date (java.util.Date)6 Contract (com.eservice.api.model.contract.Contract)5 ContractSign (com.eservice.api.model.contract_sign.ContractSign)5 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)5 User (com.cas.sim.tis.entity.User)4 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)4 Task (com.eservice.api.model.task.Task)4 OrderSign (com.eservice.api.model.order_sign.OrderSign)3 Library (com.cas.sim.tis.entity.Library)2 Resource (com.cas.sim.tis.entity.Resource)2 ResourceMapper (com.cas.sim.tis.mapper.ResourceMapper)2