Search in sources :

Example 1 with AbnormalRecord

use of com.eservice.api.model.abnormal_record.AbnormalRecord 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)

Example 2 with AbnormalRecord

use of com.eservice.api.model.abnormal_record.AbnormalRecord in project sinsim by WilsonHu.

the class AbnormalRecordController method list.

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

Example 3 with AbnormalRecord

use of com.eservice.api.model.abnormal_record.AbnormalRecord 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 4 with AbnormalRecord

use of com.eservice.api.model.abnormal_record.AbnormalRecord in project sinsim by WilsonHu.

the class AbnormalRecordController method add.

@PostMapping("/add")
public Result add(String abnormalRecord) {
    AbnormalRecord abnormalRecord1 = JSON.parseObject(abnormalRecord, AbnormalRecord.class);
    abnormalRecordService.save(abnormalRecord1);
    return ResultGenerator.genSuccessResult();
}
Also used : AbnormalRecord(com.eservice.api.model.abnormal_record.AbnormalRecord) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with AbnormalRecord

use of com.eservice.api.model.abnormal_record.AbnormalRecord 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

AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 Machine (com.eservice.api.model.machine.Machine)3 TaskRecord (com.eservice.api.model.task_record.TaskRecord)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Condition (tk.mybatis.mapper.entity.Condition)3 AbnormalImage (com.eservice.api.model.abnormal_image.AbnormalImage)2 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)2 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)2 Task (com.eservice.api.model.task.Task)2 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)2 Abnormal (com.eservice.api.model.abnormal.Abnormal)1 AbnormalRecordDetail (com.eservice.api.model.abnormal_record.AbnormalRecordDetail)1 PageInfo (com.github.pagehelper.PageInfo)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1