Search in sources :

Example 16 with TaskRecord

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

the class TaskRecordController method update.

@PostMapping("/update")
public Result update(String taskRecord) {
    TaskRecord taskRecord1 = JSON.parseObject(taskRecord, TaskRecord.class);
    taskRecordService.update(taskRecord1);
    return ResultGenerator.genSuccessResult();
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 17 with TaskRecord

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

the class TaskRecordController method add.

@PostMapping("/add")
public Result add(String taskRecord) {
    TaskRecord taskRecord1 = JSON.parseObject(taskRecord, TaskRecord.class);
    taskRecordService.save(taskRecord1);
    return ResultGenerator.genSuccessResult();
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 18 with TaskRecord

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

the class DashboardController method getStatistics.

/**
 * @return 返回dashboard中用到的安装中、改拆单等数据信息
 */
@PostMapping("/getStatistic")
public Result getStatistics() {
    Statistic statistic = new Statistic();
    Condition condition = new Condition(Machine.class);
    condition.createCriteria().andCondition("status !=", Constant.MACHINE_INITIAL).andCondition("status !=", Constant.MACHINE_CONFIGURED).andCondition("status !=", Constant.MACHINE_CANCELED).andCondition("status !=", Constant.MACHINE_INSTALLED);
    List<Machine> machineList = machineService.findByCondition(condition);
    int installingNum = machineList.size();
    int changeNum = 0;
    int splitNum = 0;
    for (Machine item : machineList) {
        if (item.getStatus().equals(Constant.MACHINE_CHANGED)) {
            changeNum++;
        } else if (item.getStatus().equals(Constant.MACHINE_SPLITED)) {
            splitNum++;
        }
    }
    statistic.setInstallingMachineNum(installingNum);
    statistic.setChangeMachineNum(changeNum);
    statistic.setSplitMachineNum(splitNum);
    // 获取异常工序数量
    Condition taskRecordCondition = new Condition(TaskRecord.class);
    taskRecordCondition.createCriteria().andCondition("status >= ", Constant.TASK_INSTALL_ABNORMAL).andCondition("status <= ", Constant.TASK_QUALITY_ABNORMAL);
    List<TaskRecord> abnormalTaskRecordList = taskRecordService.findByCondition(taskRecordCondition);
    statistic.setAbnormalTaskNum(abnormalTaskRecordList.size());
    return ResultGenerator.genSuccessResult(statistic);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Statistic(com.eservice.api.model.dashboard.Statistic) Machine(com.eservice.api.model.machine.Machine) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 19 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord 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());
    boolean firstCreate = true;
    try {
        // 已经保存过配置流程的,需要更新process
        if (prId != null && prId > 0) {
            firstCreate = false;
            processRecordService.update(pr);
        } else {
            processRecordService.save(pr);
        }
    } catch (Exception e) {
        e.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("processRecordService数据库操作失败");
    }
    try {
        if (firstCreate) {
            // trList只有在第一次创建时才会传递值,更新是为[]
            trList.forEach((item) -> {
                item.setProcessRecordId(pr.getId());
            });
            taskRecordService.save(trList);
        } else {
            // 更新时数据在process中
            List<NodeDataModel> nodeDataModelList = JSON.parseArray(pr.getNodeData(), NodeDataModel.class);
            // 找到之前属于该process ID的所有task, 对比传递进入的 task records
            Condition tempCondition = new Condition(TaskRecord.class);
            tempCondition.createCriteria().andCondition("process_record_id = ", prId);
            List<TaskRecord> existTaskRecords = taskRecordService.findByCondition(tempCondition);
            // 删除不存在的list
            List<TaskRecord> validTaskRecordList = new ArrayList<>();
            for (TaskRecord exist : existTaskRecords) {
                boolean same = false;
                for (int i = 0; i < nodeDataModelList.size() && !same; i++) {
                    if (nodeDataModelList.get(i).getKey().equals("-1") || nodeDataModelList.get(i).getKey().equals("-4")) {
                    } else {
                        // task name和key值必须一致,否则会导致不统一
                        if (nodeDataModelList.get(i).getText().equals(exist.getTaskName()) && nodeDataModelList.get(i).getKey().equals(String.valueOf(exist.getNodeKey()))) {
                            same = true;
                        }
                    }
                }
                if (!same) {
                    // 删除该节点,但是已经安装后的工序不能删除,业务需要
                    if (exist.getStatus().intValue() < Constant.TASK_INSTALLING.intValue()) {
                        if (exist.getStatus().intValue() != Constant.TASK_INITIAL) {
                            // 删除task plan中对应数据,否则外键关联会导致失败
                            Condition taskPlanCondition = new Condition(TaskPlan.class);
                            taskPlanCondition.createCriteria().andCondition("task_record_id = ", exist.getId());
                            List<TaskPlan> taskPlanList = taskPlanService.findByCondition(taskPlanCondition);
                            // 只能是一个
                            if (taskPlanList.size() == 1) {
                                taskPlanService.deleteById(taskPlanList.get(0).getId());
                            }
                        }
                        taskRecordService.deleteById(exist.getId());
                        logger.warn("删除Task Record: ==> Name: " + exist.getTaskName() + ", ID: " + exist.getId() + "Status: " + exist.getStatus() + "Process Record ID: " + pr.getId());
                    }
                } else {
                    validTaskRecordList.add(exist);
                }
            }
            // 添加新的task record
            List<TaskRecord> newAddedList = new ArrayList<>();
            for (NodeDataModel item : nodeDataModelList) {
                if (Integer.valueOf(item.getKey()).intValue() == -1 || Integer.valueOf(item.getKey()).intValue() == -4) {
                    continue;
                }
                boolean newAdded = true;
                for (int i = 0; i < validTaskRecordList.size() && newAdded; i++) {
                    if (Integer.valueOf(item.getKey()).intValue() == validTaskRecordList.get(i).getNodeKey().intValue()) {
                        newAdded = false;
                    }
                }
                if (newAdded) {
                    TaskRecord record = new TaskRecord();
                    record.setStatus(Byte.valueOf("0"));
                    record.setProcessRecordId(pr.getId());
                    record.setNodeKey(Byte.valueOf(item.getKey()));
                    record.setTaskName(item.getText());
                    newAddedList.add(record);
                }
            }
            if (newAddedList.size() > 0) {
                taskRecordService.save(newAddedList);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("taskRecordService数据库操作失败");
    }
    try {
        if (machineObj.getId() == 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return ResultGenerator.genFailResult("机器Id为空,数据更新失败");
        }
        // 如果机器处于初始化状态,则设置为“已配置”,如果已经是其他状态,则不需要更改机器状态
        if (machineObj.getStatus().equals(Constant.MACHINE_INITIAL)) {
            machineObj.setStatus(Constant.MACHINE_CONFIGURED);
        }
        machineService.update(machineObj);
    } catch (Exception e) {
        e.printStackTrace();
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("machineService数据库操作失败");
    }
    return ResultGenerator.genSuccessResult();
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) ArrayList(java.util.ArrayList) TaskPlan(com.eservice.api.model.task_plan.TaskPlan) Machine(com.eservice.api.model.machine.Machine) Date(java.util.Date) NodeDataModel(com.eservice.api.service.common.NodeDataModel) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with TaskRecord

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

the class AbnormalRecordController method updateAbnormalRecordDetail.

/**
 * 根据传入的strAbnormalRecordDetail,更新对应多表:
 * "machine_id":"", --> machine.machine_id
 * "安装是否异常":"", --> task_record.status  task状态,“1”==>未开始, “2”==>进行中,“3”==>安装完成, “4”==>质检完成,“5“===>异常
 * "异常类型":"",	--> abnormal_record.abnormal_type
 * "异常原因":"", --> abnormal_record.comment
 * "异常照片":"", -->abnormal_image.image
 * "安装完成":"",  -->   task_record.status或machine.status都可以,反正这两个表都更新
 * 注意:有外键的字段,需要上传实际存在的外键数据。
 * 一项update失败的情况下,全部update无效(事务OK)
 *
 * @param strAbnormalRecordDetail
 * @return
 */
@PostMapping("/updateAbnormalRecordDetail")
@Transactional
public Result updateAbnormalRecordDetail(@RequestParam String strAbnormalRecordDetail) {
    // 获取整体detail
    AbnormalRecordDetail abnormalRecordDetail1 = JSON.parseObject(strAbnormalRecordDetail, AbnormalRecordDetail.class);
    Integer abnormalRecordDetail_ID = abnormalRecordDetail1.getId();
    AbnormalRecord abnormalRecord = abnormalRecordService.findById(abnormalRecordDetail_ID);
    abnormalRecord.setAbnormalType(abnormalRecordDetail1.getAbnormalType());
    abnormalRecord.setTaskRecordId(abnormalRecordDetail1.getTaskRecordId());
    abnormalRecord.setSubmitUser(abnormalRecordDetail1.getSubmitUser());
    abnormalRecord.setSolutionUser(abnormalRecordDetail1.getSolutionUser());
    abnormalRecord.setComment(abnormalRecordDetail1.getComment());
    abnormalRecord.setSolution(abnormalRecordDetail1.getSolution());
    Abnormal abnormal = abnormalRecordDetail1.getAbnormal();
    AbnormalImage abnormalImage = abnormalRecordDetail1.getAbnormalImage();
    TaskRecord taskRecord = abnormalRecordDetail1.getTaskRecord();
    Machine machine = abnormalRecordDetail1.getMachine();
    abnormalRecordService.update(abnormalRecord);
    abnormalService.update(abnormal);
    abnormalImageService.update(abnormalImage);
    taskRecordService.update(taskRecord);
    machineService.update(machine);
    return ResultGenerator.genSuccessResult();
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) AbnormalRecord(com.eservice.api.model.abnormal_record.AbnormalRecord) AbnormalImage(com.eservice.api.model.abnormal_image.AbnormalImage) AbnormalRecordDetail(com.eservice.api.model.abnormal_record.AbnormalRecordDetail) Abnormal(com.eservice.api.model.abnormal.Abnormal) Machine(com.eservice.api.model.machine.Machine) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

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