Search in sources :

Example 6 with ProcessRecord

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

the class TaskRecordController method updateStatus.

@PostMapping("/updateStatus")
@Transactional(rollbackFor = Exception.class)
public Result updateStatus(String taskRecord, String processRecord) {
    TaskRecord tr = JSON.parseObject(taskRecord, TaskRecord.class);
    Integer id = tr.getId();
    if (id == null || id < 0) {
        return ResultGenerator.genFailResult("TaskRecord的ID为空,数据更新失败!");
    }
    taskRecordService.update(tr);
    ProcessRecord pr = JSON.parseObject(processRecord, ProcessRecord.class);
    id = pr.getId();
    if (id == null || id < 0) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("ProcessRecord的ID为空,数据更新失败!");
    }
    processRecordService.update(pr);
    return ResultGenerator.genSuccessResult();
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ProcessRecord

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

the class TaskRecordController method updateTaskInfo.

@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为空,数据更新失败!");
    }
    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();
        }
    }
    if (tr.getStatus().equals(Constant.TASK_INSTALLED)) {
        // MQTT 如果当前工序状态是安装完成等待质检的状态,则通知App
        // 找到工序对应的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());
        mqttMessageHelper.sendToClient(Constant.S2C_TASK_QUALITY + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
    }
    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) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Machine(com.eservice.api.model.machine.Machine) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ProcessRecord

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

the class ProcessRecordController method addProcessForMachine.

@PostMapping("/addProcessForMachine")
@Transactional(rollbackFor = Exception.class)
public Result addProcessForMachine(String taskRecords, String processRecord, String machine) {
    ProcessRecord pr = JSON.parseObject(processRecord, ProcessRecord.class);
    List<TaskRecord> trList = JSON.parseArray(taskRecords, TaskRecord.class);
    Machine machineObj = JSON.parseObject(machine, Machine.class);
    if (pr == null || trList == null) {
        return ResultGenerator.genFailResult("提交到服务端的JSON数据解析错误");
    }
    Integer prId = pr.getId();
    pr.setCreateTime(new Date());
    try {
        // 已经保存过配置流程的,需要更新
        if (prId != null && prId > 0) {
            processRecordService.update(pr);
            try {
                // 删除旧的taskrecorder表中对应的任务,根据process_recorder_id删除 status==0的
                taskRecordService.deleteTaskRecordByCondition(null, prId, null, (byte) 0);
            } catch (Exception e) {
                e.printStackTrace();
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ResultGenerator.genFailResult("taskRecordService删除旧任务失败");
            }
        } else {
            processRecordService.save(pr);
        }
    } catch (Exception e) {
        e.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("processRecordService数据库操作失败");
    }
    trList.forEach((item) -> {
        item.setProcessRecordId(pr.getId());
    });
    try {
        taskRecordService.save(trList);
    } catch (Exception e) {
        e.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("taskRecordService数据库操作失败");
    }
    try {
        // 如果机器处于初始化状态,则设置为“已配置”
        if (machineObj.getStatus().equals(Constant.MACHINE_INITIAL)) {
            // 如果已经是其他状态,则不需要更改机器状态
            machineObj.setStatus(Constant.MACHINE_CONFIGURED);
            if (machineObj.getId() == 0) {
                return ResultGenerator.genFailResult("机器Id为空,数据更新失败");
            }
            machineService.update(machineObj);
        }
    } catch (Exception e) {
        e.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("machineService数据库操作失败");
    }
    return ResultGenerator.genSuccessResult();
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) Machine(com.eservice.api.model.machine.Machine) Date(java.util.Date) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)8 TaskRecord (com.eservice.api.model.task_record.TaskRecord)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 Machine (com.eservice.api.model.machine.Machine)5 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)4 Task (com.eservice.api.model.task.Task)4 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Condition (tk.mybatis.mapper.entity.Condition)4 Date (java.util.Date)3 AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)1 TaskPlan (com.eservice.api.model.task_plan.TaskPlan)1 LinkDataModel (com.eservice.api.service.common.LinkDataModel)1 PageInfo (com.github.pagehelper.PageInfo)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1