Search in sources :

Example 6 with TaskRecord

use of com.eservice.api.model.task_record.TaskRecord 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为空,数据更新失败!");
    }
    logger.info(tr.getTaskName() + ", taskRecord的状态: " + tr.getStatus());
    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 TaskRecord

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

the class TaskRecordController method selectTaskReocords.

/**
 * 根据userAccount 返回该用户的 Tasks
 *
 * @param page
 * @param size
 * @param userAccount
 * @return 返回该用户的 Tasks
 */
@PostMapping("/selectTaskReocords")
public Result selectTaskReocords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, @RequestParam String userAccount) {
    PageHelper.startPage(page, size);
    List<TaskRecord> list = taskRecordService.selectTaskReocords(userAccount);
    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 8 with TaskRecord

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

the class TaskRecordController method addTrTqrQri.

/**
 * 3个表 task_record/TaskQualityRecord/QualityRecordImage 更新。
 * app端,上传质检异常状态,task_record(update),增加 TaskQualityRecord(add), QualityRecordImage (add)
 * 没有质检员了,这个接口没在用。
 */
@Transactional(rollbackFor = Exception.class)
@PostMapping("/addTrTqrQri")
public Result addTrTqrQri(@RequestParam String taskRecord, @RequestParam String taskQualityRecord, @RequestParam MultipartFile[] files) {
    // task_record(update)
    TaskRecord taskRecord1 = JSON.parseObject(taskRecord, TaskRecord.class);
    taskRecordService.update(taskRecord1);
    TaskQualityRecord taskQualityRecord1 = JSON.parseObject(taskQualityRecord, TaskQualityRecord.class);
    // 质检异常类型,目前未使用,default值为1
    taskQualityRecord1.setAbnormalType(1);
    taskQualityRecordService.saveAndGetID(taskQualityRecord1);
    // 获取保存后分配到的id
    Integer taskQualityRecordId = taskQualityRecord1.getId();
    // 构建 qualityRecordImage1
    QualityRecordImage qualityRecordImage1 = new QualityRecordImage();
    File dir = new File(qualityImagesSavedDir);
    if (!dir.exists()) {
        dir.mkdir();
    }
    String machineID = machineService.searchMachineByTaskQualityRecordId(taskQualityRecordId).getMachineStrId();
    Integer orderId = machineService.searchMachineByTaskQualityRecordId(taskQualityRecordId).getOrderId();
    String orderNum = machineOrderService.findById(orderId).getOrderNum();
    List<String> listResultPath = new ArrayList<>();
    for (int i = 0; i < files.length; i++) {
        try {
            listResultPath.add(commonService.saveFile(qualityImagesSavedDir, files[i], machineID, orderNum, Constant.QUALITY_IMAGE, i));
        } catch (IOException e) {
            e.printStackTrace();
            // 抛异常引发回滚,防止数据只更新了前面部分。
            throw new RuntimeException();
        }
    }
    if (listResultPath.size() != files.length) {
        throw new RuntimeException();
    } else {
        qualityRecordImage1.setTaskQualityRecordId(taskQualityRecordId);
        qualityRecordImage1.setImage(listResultPath.toString());
        qualityRecordImage1.setCreateTime(taskQualityRecord1.getCreateTime());
        qualityRecordImageService.save(qualityRecordImage1);
    }
    // 找到工序对应的quality_user_id
    String taskName = taskRecord1.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();
    }
    Integer prId = taskRecord1.getProcessRecordId();
    if (prId == null || prId < 0) {
        Logger.getLogger("").log(Level.INFO, "processrecord Id 为空");
    } else {
        // Update task record相关的状态
        if (!commonService.updateTaskRecordRelatedStatus(taskRecord1)) {
            // 更新出错进行事务回退
            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 (taskRecord1.getStatus().equals(Constant.TASK_QUALITY_ABNORMAL)) {
        // MQTT 发生质检异常时,通知安装组长以及生产部管理员
        mqttMessageHelper.sendToClient(Constant.S2C_QUALITY_ABNORMAL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
    }
    return ResultGenerator.genSuccessResult("3个表 task_record + TaskQualityRecord + QualityRecordImage 更新成功");
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) ArrayList(java.util.ArrayList) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) TaskQualityRecord(com.eservice.api.model.task_quality_record.TaskQualityRecord) QualityRecordImage(com.eservice.api.model.quality_record_image.QualityRecordImage) Machine(com.eservice.api.model.machine.Machine) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) MultipartFile(org.springframework.web.multipart.MultipartFile) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with TaskRecord

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

the class TaskRecordController method addTrArAi.

/**
 * task_record, abnormal_record, abnormal_image  3个表一起更新。
 * app端,在安装异常时需要更新task_record(update),增加 abnormal_record(add), abnormal_image (add)
 *
 * app扫码报异常时,调用addTrArAi (app报正常时,调用的是 updateTaskInfo, 少了异常记录和文件两个参数)
 */
@Transactional(rollbackFor = Exception.class)
@PostMapping("/addTrArAi")
public Result addTrArAi(@RequestParam String taskRecord, @RequestParam String abnormalRecord, @RequestParam MultipartFile[] files) {
    // task_record(update)
    TaskRecord taskRecord1 = JSON.parseObject(taskRecord, TaskRecord.class);
    taskRecordService.update(taskRecord1);
    // abnormal_record add:
    AbnormalRecord abnormalRecord1 = JSON.parseObject(abnormalRecord, AbnormalRecord.class);
    // 在安装异常时,并没有SolutionUser,即还不知道SolutionUser,所以这里设为null
    abnormalRecord1.setSolutionUser(null);
    // 在47服务器saveAndGetID执行成功,但是实际没有数据保存在数据库 --是因为数据库从5.7改为了最新的8,改回旧的mysql docker即可。
    abnormalRecordService.saveAndGetID(abnormalRecord1);
    // 获取保存后分配到的id
    Integer abnormalRecordId = abnormalRecord1.getId();
    // if(abnormalRecord1 !=null) {
    // logger.info("abnormalRecordId: " + abnormalRecordId);
    // AbnormalRecord abInserted = null;
    // abInserted = abnormalRecordService.findById(abnormalRecordId);
    // if(abInserted == null){
    // logger.info("刚刚尝试插入的数据,却没有在数据库里找到");
    // 
    // } else {   logger.info("刚刚尝试插入的数据,却没有在数据库里找到");
    // logger.info("刚刚尝试插入的数据,可以根据abnormalRecordId找到");
    // }
    // } else {
    // logger.error("异常,生成 abnormalRecord1 为null");
    // }
    /**
     * abnormal_image add
     * 因为此时从app端无法知道 abnormal_record_id,所以需要在服务端获取abnormal_record_id
     * abnormal_image的create_time和abnormal_record.create_time一样
     */
    AbnormalImage abnormalImage1 = new AbnormalImage();
    File dir = new File(imagesSavedDir);
    if (!dir.exists()) {
        dir.mkdir();
    }
    String machineID = machineService.searchMachineByAbnormalRecordId(abnormalRecordId).getMachineStrId();
    Integer orderId = machineService.searchMachineByAbnormalRecordId(abnormalRecordId).getOrderId();
    String orderNum = machineOrderService.findById(orderId).getOrderNum();
    List<String> listResultPath = new ArrayList<>();
    for (int i = 0; i < files.length; i++) {
        try {
            listResultPath.add(commonService.saveFile(imagesSavedDir, files[i], machineID, orderNum, Constant.ABNORMAL_IMAGE, i));
        } catch (IOException e) {
            e.printStackTrace();
            // 抛异常引发回滚,防止数据只更新了前面部分。
            throw new RuntimeException();
        }
    }
    if (listResultPath.size() != files.length) {
        throw new RuntimeException();
    } else {
        abnormalImage1.setImage(listResultPath.toString());
        abnormalImage1.setAbnormalRecordId(abnormalRecordId);
        abnormalImage1.setCreateTime(abnormalRecord1.getCreateTime());
        abnormalImageService.save(abnormalImage1);
    }
    // 找到工序对应的quality_user_id
    String taskName = taskRecord1.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();
    }
    Integer prId = taskRecord1.getProcessRecordId();
    if (prId == null || prId < 0) {
        Logger.getLogger("").log(Level.INFO, "processrecord Id 为空");
    } else {
        // Update task record相关的状态
        if (!commonService.updateTaskRecordRelatedStatus(taskRecord1)) {
            // 更新出错进行事务回退
            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 (taskRecord1.getStatus().equals(Constant.TASK_INSTALL_ABNORMAL)) {
        // MQTT 发生安装异常时,通知生产部管理员
        // mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_ABNORMAL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
        // MQTT 发生安装异常时,通知对应质检员
        mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_ABNORMAL_TO_QUALITY + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
    }
    // createInstallPlanActual(taskRecord1);
    return ResultGenerator.genSuccessResult("3个表 task_record + abnormal_record + abnormal_image更新成功");
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) AbnormalImage(com.eservice.api.model.abnormal_image.AbnormalImage) ArrayList(java.util.ArrayList) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) 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) MultipartFile(org.springframework.web.multipart.MultipartFile) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with TaskRecord

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

the class TaskRecordController method getTaskRecordData.

@PostMapping("/getTaskRecordData")
public Result getTaskRecordData(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, @RequestParam(defaultValue = "0") Integer id, @RequestParam(defaultValue = "0") Integer processRecordId) {
    PageHelper.startPage(page, size);
    List<TaskRecord> list = taskRecordService.getTaskRecordData(id, 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)

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