Search in sources :

Example 11 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class InstallPlanServiceImpl method sendUnDeliveryInstallPlans.

public Result sendUnDeliveryInstallPlans() {
    /**
     * 通过MQTT 发送所有未发送的且排产日期为明天的排产计划
     */
    ServerToClientMsg msg = new ServerToClientMsg();
    List<InstallPlan> unSendInstallPlans = installPlanService.selectUnSendInstallPlans();
    int sendCount = 0;
    for (int i = 0; i < unSendInstallPlans.size(); i++) {
        Date now = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String nowDate = formatter.format(now);
        String installDatePlanDateString = formatter.format(unSendInstallPlans.get(i).getInstallDatePlan());
        if (getAfterDay(nowDate, 1).equals(installDatePlanDateString)) {
            logger.info(unSendInstallPlans.get(i).getInstallDatePlan() + " 明天要安装:" + machineService.findById(unSendInstallPlans.get(i).getMachineId()).getNameplate());
            msg.setNameplate(machineService.findById(unSendInstallPlans.get(i).getMachineId()).getNameplate());
            msg.setOrderNum(machineOrderService.findById(unSendInstallPlans.get(i).getOrderId()).getOrderNum());
            msg.setType(ServerToClientMsg.MsgType.INSTALL_PLAN);
            msg.setCmtSend(unSendInstallPlans.get(i).getCmtSend());
            msg.setInstallDatePlan(unSendInstallPlans.get(i).getInstallDatePlan());
            // topic结尾加安装组的groupId,并设置发送时间表示已发送。
            mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_PLAN + unSendInstallPlans.get(i).getInstallGroupId(), JSON.toJSONString(msg));
            logger.info("MQTT SEND topic: " + Constant.S2C_INSTALL_PLAN + unSendInstallPlans.get(i).getInstallGroupId() + ", nameplate: " + msg.getNameplate());
            sendCount++;
            unSendInstallPlans.get(i).setSendTime(new Date());
            installPlanService.update(unSendInstallPlans.get(i));
        } else {
        // logger.info("还未到安装提醒时间的机器:"
        // + machineService.findById(unSendInstallPlans.get(i).getMachineId()).getNameplate()
        // + " 安装时间为 " + installDatePlanDateString);
        }
    }
    String str = "还未到安装提醒时间的任务: " + unSendInstallPlans.size() + "条," + "刚刚发送提醒 " + sendCount + "条";
    logger.info(str);
    return ResultGenerator.genSuccessResult(str);
}
Also used : ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) InstallPlan(com.eservice.api.model.install_plan.InstallPlan)

Example 12 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class ContractController method splitOrder.

@PostMapping("/splitOrder")
@Transactional(rollbackFor = Exception.class)
public Result splitOrder(String contract, String contractSign, String requisitionForms, String splitMachines) {
    if (contract == null || "".equals(contract)) {
        return ResultGenerator.genFailResult("合同信息为空!");
    }
    if (contractSign == null || "".equals(contractSign)) {
        return ResultGenerator.genFailResult("合同审核初始化信息为空!");
    }
    if (requisitionForms == null || "".equals(requisitionForms)) {
        return ResultGenerator.genFailResult("订单信息为空!");
    }
    if (splitMachines == null || "".equals(splitMachines)) {
        return ResultGenerator.genFailResult("拆单机器信息为空!");
    }
    Contract contractObj = JSONObject.parseObject(contract, Contract.class);
    if (contractObj == null || contractSign == null || requisitionForms == null || splitMachines == null) {
        return ResultGenerator.genFailResult("JSON解析失败!");
    }
    // 更改合同的状态为“拆单”
    contractObj.setStatus(Constant.CONTRACT_SPLITED);
    contractObj.setUpdateTime(new Date());
    contractService.update(contractObj);
    Integer contractId = contractObj.getId();
    // /插入新的contract审核记录
    ContractSign contractSignObj = new ContractSign();
    contractSignObj.setContractId(contractId);
    contractSignObj.setCreateTime(new Date());
    contractSignObj.setSignContent(contractSign);
    // /插入空值
    contractSignObj.setCurrentStep("");
    contractSignService.save(contractSignObj);
    // 新增的拆单处理
    // 返回新增的拆单的ID号给前端,前端新增改单时不关闭页面。
    int newMachineOrderId = 0;
    List<MachineOrderWrapper> machineOrderWrapperList = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
    List<Machine> splitMachineList = JSONObject.parseArray(splitMachines, Machine.class);
    for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
        MachineOrder machineOrder = orderItem.getMachineOrder();
        if (machineOrder.getId() == null && machineOrder.getOriginalOrderId() != 0) {
            // 插入新增改单项的detail
            OrderDetail temp = orderItem.getOrderDetail();
            orderDetailService.saveAndGetID(temp);
            machineOrder.setOrderDetailId(temp.getId());
            machineOrder.setContractId(contractObj.getId());
            // 改单的前提是原订单已审核完成,联系单已经审核通过,所以不需要再重新审核,
            // machineOrder.setStatus(Constant.ORDER_INITIAL);
            machineOrder.setStatus(Constant.ORDER_SPLIT_FINISHED);
            machineOrder.setCreateTime(new Date());
            /**
             * 订单 不允许同名
             * 带下划线的字段,不能用findBy(fieldName,....)
             */
            try {
                Class cl = Class.forName("com.eservice.api.model.machine_order.MachineOrder");
                Field fieldOrderNum = cl.getDeclaredField("orderNum");
                MachineOrder mo = null;
                mo = machineOrderService.findBy(fieldOrderNum.getName(), machineOrder.getOrderNum());
                if (mo != null) {
                    logger.error(" splitOrder 该 订单号已存在,请确认是否重名 " + machineOrder.getOrderNum());
                    return ResultGenerator.genFailResult(machineOrder.getOrderNum() + " 该订单号已存在,请确认是否重名 ");
                }
            } catch (ClassNotFoundException e) {
                logger.error("splitOrder fail: " + e.getMessage());
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                logger.error("splitOrder fail: " + e.getMessage());
                e.printStackTrace();
            }
            machineOrderService.saveAndGetID(machineOrder);
            newMachineOrderId = machineOrder.getId();
            /**
             * 为了让 拆单后的新订单也能看到签核的时间等, 新生成的订单,也有对应的审核记录,
             * 审核内容和步骤,来自于旧的审核记录。
             */
            // 初始化需求单审核记录
            OrderSign orderSignData = orderItem.getOrderSign();
            OrderSign orderSign = new OrderSign();
            orderSign.setSignContent(orderSignData.getSignContent());
            orderSign.setOrderId(machineOrder.getId());
            orderSign.setCreateTime(orderSignData.getCreateTime());
            orderSign.setCurrentStep(orderSignData.getCurrentStep());
            orderSign.setUpdateTime(orderSignData.getUpdateTime());
            orderSignService.save(orderSign);
            // 被拆分出来的机器绑定到新的需求单
            for (Machine splitMachine : splitMachineList) {
                splitMachine.setOrderId(machineOrder.getId());
                splitMachine.setStatus(Constant.MACHINE_SPLITED);
                // /MQTT 有拆单状态的机器,通知全部安装组长
                ServerToClientMsg msg = new ServerToClientMsg();
                msg.setOrderNum(machineOrder.getOrderNum());
                msg.setNameplate(splitMachine.getNameplate());
                msg.setType(ServerToClientMsg.MsgType.ORDER_SPLIT);
                mqttMessageHelper.sendToClient(Constant.S2C_MACHINE_STATUS_CHANGE, JSON.toJSONString(msg));
                splitMachine.setUpdateTime(new Date());
                // 正常数据时是不需要设置
                // if(splitMachine.getIsUrgent().equals("")){
                // splitMachine.setIsUrgent(null);
                // }
                machineService.update(splitMachine);
            }
            // 拆单记录(插入或者修改)
            OrderSplitRecord splitRecord = orderItem.getOrderSplitRecord();
            if (splitRecord.getId() == null) {
                splitRecord.setSplitTime(new Date());
                splitRecord.setOrderId(machineOrder.getId());
                orderSplitRecordService.save(splitRecord);
            } else {
                splitRecord.setSplitTime(new Date());
                orderSplitRecordService.update(splitRecord);
            }
        }
    }
    // 处于拆单状态的需求单,更新状态成“ORDER_SPLIT”
    for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
        MachineOrder machineOrder = orderItem.getMachineOrder();
        // TODO:同一个合同中其他为“ORDER_SPLIT”状态的需求单也会被更新,需要完善
        if (machineOrder.getStatus().equals(Constant.ORDER_SPLITED)) {
            machineOrder.setUpdateTime(new Date());
            machineOrderService.update(machineOrder);
        }
    }
    return ResultGenerator.genSuccessResult(newMachineOrderId);
}
Also used : MachineOrderWrapper(com.eservice.api.model.contract.MachineOrderWrapper) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) Date(java.util.Date) Machine(com.eservice.api.model.machine.Machine) OrderDetail(com.eservice.api.model.order_detail.OrderDetail) MachineOrderDetail(com.eservice.api.model.machine_order.MachineOrderDetail) Field(java.lang.reflect.Field) OrderSign(com.eservice.api.model.order_sign.OrderSign) OrderSplitRecord(com.eservice.api.model.order_split_record.OrderSplitRecord) ContractSign(com.eservice.api.model.contract_sign.ContractSign) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Contract(com.eservice.api.model.contract.Contract) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with ServerToClientMsg

use of com.eservice.api.service.mqtt.ServerToClientMsg in project sinsim by WilsonHu.

the class MachineController method update.

@PostMapping("/update")
public Result update(String machine) {
    logger.info(machine);
    Machine machine1 = JSON.parseObject(machine, Machine.class);
    machine1.setUpdateTime(new Date());
    // 如果该机器有对应的工序是跳过未完成的,不允许设置为已完成。
    if (machine1.getNameplate() != null && !machine1.getNameplate().isEmpty()) {
        List<TaskRecordDetail> list = taskRecordService.selectTaskRecordByMachineNameplate(machine1.getNameplate());
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getStatus().equals(Constant.TASK_SKIP)) {
                return ResultGenerator.genFailResult("该机器还有处于跳过状态的工序:" + list.get(i).getTaskName() + ",不允许设置为完成!");
            }
        }
    }
    /**
     * 3期新质检:
     * 如果是设置了 机器位置(从无到有),则创建质检记录(状态为未质检),发消息给质检人员,表示要开始安装了,可以过来看了。
     * 大概是因为有些质检需要在安装过程中看。
     *
     * 创建该机器的所有工序对应的所有质检项, 注意: 如果工序没有包含质检项,则不会生成该工序的质检项。
     */
    Machine machineOld = machineService.findById(machine1.getId());
    if (machineOld != null) {
        if ((machineOld.getLocation() == null || machineOld.getLocation().isEmpty()) && (machine1.getLocation() != null)) {
            MachineOrder machineOrder = machineOrderService.getMachineOrderByNameplate(machine1.getNameplate());
            List<Task> taskList = taskService.getTaskByNameplate(machine1.getNameplate());
            if (taskList != null) {
                logger.info("该机器包含的工序数:" + taskList.size());
                for (int i = 0; i < taskList.size(); i++) {
                    // 找到该工序名下的质检项
                    List<QualityInspect> qualityInspectListlist = qualityInspectService.getQualityInspectByTaskName(taskList.get(i).getTaskName());
                    if (qualityInspectListlist != null) {
                        logger.info(taskList.get(i).getTaskName() + " 工序包含的质检项有:" + qualityInspectListlist.size());
                        for (int q = 0; q < qualityInspectListlist.size(); q++) {
                            QualityInspectRecord qualityInspectRecord = new QualityInspectRecord();
                            qualityInspectRecord.setCreateTime(new Date());
                            qualityInspectRecord.setTaskName(taskList.get(i).getTaskName());
                            qualityInspectRecord.setInspectName(qualityInspectListlist.get(q).getInspectName());
                            qualityInspectRecord.setMachineNameplate(machine1.getNameplate());
                            if (machineOrder != null) {
                                qualityInspectRecord.setOrderNumber(machineOrder.getOrderNum());
                            } else {
                                logger.warn("根据" + machine1.getNameplate() + " 找不到订单号");
                            }
                            /**
                             * 因为要和APP其他状态共用一些代码,所以这里不要用字符串,用数字
                             */
                            // qualityInspectRecord.setRecordStatus(Constant.STR_QUALITY_INSPECT_NOT_START);
                            qualityInspectRecord.setRecordStatus(Constant.TASK_QUALITY_INSPECT_NOT_STARTED.toString());
                            qualityInspectRecordService.save(qualityInspectRecord);
                            logger.info("生成qualityInspectRecord成功, 铭牌号:" + qualityInspectRecord.getMachineNameplate() + ",inspectName:" + qualityInspectRecord.getInspectName() + ",taskName:" + qualityInspectRecord.getTaskName() + ",状态:" + qualityInspectRecord.getRecordStatus());
                        }
                    }
                }
            }
            /**
             * 发MQTT消息给质检 (一个机器发一次,发给所有质检员/质检组长 谁订阅谁收到)
             */
            ServerToClientMsg msg = new ServerToClientMsg();
            msg.setOrderNum(machineOrder.getOrderNum());
            msg.setNameplate(machine1.getNameplate());
            msg.setType(ServerToClientMsg.MsgType.QUALITY_INSPECT);
            mqttMessageHelper.sendToClient(Constant.S2C_MACHINE_QUALITY_INSPECT, JSON.toJSONString(msg));
            logger.info("MQTT " + Constant.S2C_MACHINE_QUALITY_INSPECT + ", 铭牌号:" + msg.getNameplate() + "设置了区域位置");
        }
    }
    machineService.update(machine1);
    return ResultGenerator.genSuccessResult();
}
Also used : Task(com.eservice.api.model.task.Task) TaskRecordDetail(com.eservice.api.model.task_record.TaskRecordDetail) QualityInspect(com.eservice.api.model.quality_inspect.QualityInspect) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) QualityInspectRecord(com.eservice.api.model.quality_inspect_record.QualityInspectRecord) Machine(com.eservice.api.model.machine.Machine) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)13 Machine (com.eservice.api.model.machine.Machine)10 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)10 Date (java.util.Date)9 Task (com.eservice.api.model.task.Task)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 Condition (tk.mybatis.mapper.entity.Condition)8 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)7 TaskRecord (com.eservice.api.model.task_record.TaskRecord)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ArrayList (java.util.ArrayList)4 InstallPlan (com.eservice.api.model.install_plan.InstallPlan)3 AbnormalRecord (com.eservice.api.model.abnormal_record.AbnormalRecord)2 Contract (com.eservice.api.model.contract.Contract)2 MachineOrderWrapper (com.eservice.api.model.contract.MachineOrderWrapper)2 ContractSign (com.eservice.api.model.contract_sign.ContractSign)2 InstallGroup (com.eservice.api.model.install_group.InstallGroup)2 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)2 OrderDetail (com.eservice.api.model.order_detail.OrderDetail)2 OrderSign (com.eservice.api.model.order_sign.OrderSign)2