Search in sources :

Example 6 with MachineOrder

use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.

the class ContractController method changeOrder.

/**
 * 联系单审核通过才允许改单,
 * 改单后新生成的订单不用再审批,因为联系单已经审核过了。
 */
@PostMapping("/changeOrder")
@Transactional(rollbackFor = Exception.class)
public Result changeOrder(String contract, String contractSign, String requisitionForms) {
    logger.info("changeOrder=======:");
    logger.info(requisitionForms);
    if (contract == null || "".equals(contract)) {
        return ResultGenerator.genFailResult("合同信息为空!");
    }
    if (contractSign == null || "".equals(contractSign)) {
        return ResultGenerator.genFailResult("合同审核初始化信息为空!");
    }
    if (requisitionForms == null || "".equals(requisitionForms)) {
        return ResultGenerator.genFailResult("订单信息为空!");
    }
    Contract contract1 = JSONObject.parseObject(contract, Contract.class);
    if (contract1 == null) {
        return ResultGenerator.genFailResult("Contract对象JSON解析失败!");
    }
    // 更改合同的状态为“改单”
    contract1.setStatus(Constant.CONTRACT_CHANGED);
    contract1.setUpdateTime(new Date());
    contractService.update(contract1);
    Integer contractId = contract1.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);
    for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
        MachineOrder machineOrder = orderItem.getMachineOrder();
        // 检查时候存在有效的需求单,如果需求单中存在ID,则表示其已经在数据库中存在;修复同一个合同中多次改单(未提交审核)出现重复的需求单的问题
        if (machineOrder.getStatus().equals(Constant.ORDER_INITIAL) && machineOrder.getOriginalOrderId() != 0 && (machineOrder.getId() == null || machineOrder.getId() == 0)) {
            // 插入新增改单项的detail
            OrderDetail temp = orderItem.getOrderDetail();
            orderDetailService.saveAndGetID(temp);
            machineOrder.setOrderDetailId(temp.getId());
            machineOrder.setContractId(contract1.getId());
            // 改单的前提是原订单已审核完成,联系单已经审核通过,所以不需要再重新审核,
            machineOrder.setStatus(Constant.ORDER_CHANGE_FINISHED);
            machineOrder.setCreateTime(new Date());
            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);
            // 改单记录(插入或者修改)
            OrderChangeRecord changeRecord = orderItem.getOrderChangeRecord();
            if (changeRecord.getId() == null) {
                changeRecord.setChangeTime(new Date());
                orderChangeRecordService.save(changeRecord);
            } else {
                changeRecord.setChangeTime(new Date());
                orderChangeRecordService.update(changeRecord);
            }
        }
    }
    for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
        MachineOrder machineOrder = orderItem.getMachineOrder();
        /**
         * 一个合同下,多个订单,多个改单
         * 前面已经被改好的改单,状态为 ORDER_CHANGED, 改好后的订单 状态为 ORDER_CHANGE_FINISHED
         * 改单刚刚开始时(还在改单中),状态为 ORDER_CHANGE_ING, 由前端传过来,
         * 这种情况表示正在改单,要把状态设置为 ORDER_CHANGED,其他的照旧处理
         * 之所以分 ORDER_CHANGE_ING、ORDER_CHANGED,是因为为了修复 多个订单都改单的情况下,对应的机器数量会处理不对
         * 一个订单改单-不改机器数量:OK
         * 一个订单改单-新增机器数量:OK
         * 一个订单改单-减少机器数量:OK
         *
         * 2个订单都改单-不改机器数量:OK
         * 2个订单都改单-新增机器数量:ok
         * 2个订单都改单-减少机器数量:OK
         */
        if (machineOrder.getStatus().equals(Constant.ORDER_CHANGE_ING)) {
            // 更新了被改的需求单为“改单”,持久化至数据库
            machineOrder.setUpdateTime(new Date());
            machineOrder.setStatus(Constant.ORDER_CHANGED);
            machineOrderService.update(machineOrder);
            // 获取被改单对应机器,设置改单状态(machine)
            Condition tempCondition = new Condition(Machine.class);
            tempCondition.createCriteria().andCondition("order_id = ", machineOrder.getId());
            // /被改订单的
            List<Machine> machineList = machineService.findByCondition(tempCondition);
            // 寻找对应新生成的需求单,比较机器数
            MachineOrder newOrder = null;
            for (MachineOrderWrapper wrapper : machineOrderWrapperList) {
                if (wrapper.getMachineOrder().getOriginalOrderId().equals(machineOrder.getId())) {
                    newOrder = wrapper.getMachineOrder();
                    break;
                }
            }
            if (newOrder != null) {
                // 改单后,机器数量不变或者变少了,需要把这部分机器设置为取消(无论是否已生产)
                if (newOrder.getMachineNum() <= machineList.size()) {
                    logger.info("改单后,机器数量不变或者变少了, 新订单的机器数: " + newOrder.getMachineNum());
                    // step1 按新订单的机器数量,把 被改订单的机器 挂到新生成的订单
                    for (int m = 0; m < newOrder.getMachineNum(); m++) {
                        Machine machine = machineList.get(m);
                        // /初始化、取消状态,直接将机器的上的需求单号直接绑定到新需求单。 其他状态的机器则改为 改单
                        logger.info("新生成的订单号" + newOrder.getOrderNum() + "的 【实际的】 机器编号: " + machine.getNameplate() + ",状态: " + machine.getStatus());
                        if (machine.getStatus().equals(Constant.MACHINE_INITIAL) || machine.getStatus().equals(Constant.MACHINE_CANCELED)) {
                        } else {
                            machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
                            // /有改单状态的机器,通知全部安装组长
                            ServerToClientMsg msg = new ServerToClientMsg();
                            msg.setOrderNum(newOrder.getOrderNum());
                            msg.setNameplate(machine.getNameplate());
                            msg.setType(ServerToClientMsg.MsgType.ORDER_CHANGE);
                            mqttMessageHelper.sendToClient(Constant.S2C_MACHINE_STATUS_CHANGE, JSON.toJSONString(msg));
                        }
                        machine.setOrderId(newOrder.getId());
                        machine.setUpdateTime(new Date());
                        machineService.update(machine);
                    }
                    // //step2把被改订单里剩下的机器设置为取消
                    /**
                     * 因为在改单时不确定哪些机子在生产了,所以管理员根据需要可以在"生产管理"页面,根据实际情况调整机器铭牌号。
                     */
                    tempCondition.createCriteria().andCondition("order_id = ", machineOrder.getId());
                    List<Machine> machineToBeCancelledList = machineService.findByCondition(tempCondition);
                    for (Machine machine : machineToBeCancelledList) {
                        // 如果机器数量不变,这里为0
                        machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
                        machine.setUpdateTime(new Date());
                        logger.info("把剩下的机器设置为取消 " + machine.getNameplate());
                        machineService.update(machine);
                    }
                } else {
                    /**
                     * 改单后,机器数量增加了,需要新增机器 ,原先:多出部分机器在审核完成以后自动添加
                     * --> 2020-0409:有联系单后不再需要审核订单了,所以需要在此生成机器。
                     */
                    logger.info("改单前,原订单机器数量: " + machineList.size());
                    logger.info("改单后,机器数量增加到了: " + newOrder.getMachineNum());
                    // //step1  把 被改订单的机器 全部之间挂到新生成的订单,即旧订单就没机器了。
                    for (int n = 0; n < machineList.size(); n++) {
                        Machine machine = machineList.get(n);
                        // /初始化、取消状态,直接将机器的上的需求单号直接绑定到新需求单。 其他状态的机器则改为 改单 (为啥这样?全部改成改单不行吗)
                        logger.info("新生成的订单号" + newOrder.getOrderNum() + "的 【实际的】 机器编号: " + machine.getNameplate() + ",状态: " + machine.getStatus());
                        if (machine.getStatus().equals(Constant.MACHINE_INITIAL) || machine.getStatus().equals(Constant.MACHINE_CANCELED)) {
                        } else {
                            machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
                            // /有改单状态的机器,通知全部安装组长
                            ServerToClientMsg msg = new ServerToClientMsg();
                            msg.setOrderNum(newOrder.getOrderNum());
                            msg.setNameplate(machine.getNameplate());
                            msg.setType(ServerToClientMsg.MsgType.ORDER_CHANGE);
                            mqttMessageHelper.sendToClient(Constant.S2C_MACHINE_STATUS_CHANGE, JSON.toJSONString(msg));
                        }
                        machine.setOrderId(newOrder.getId());
                        machine.setUpdateTime(new Date());
                        machineService.update(machine);
                    }
                    // //step2 再补足 新增的机器
                    int haveToCreate = newOrder.getMachineNum() - machineList.size();
                    logger.info("订单" + newOrder.getOrderNum() + ",需要新增机器台数:" + haveToCreate);
                    for (int c = 0; c < haveToCreate; c++) {
                        Machine machine = new Machine();
                        machine.setMachineStrId(Utils.createMachineBasicId() + c);
                        machine.setOrderId(newOrder.getId());
                        machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_INITIAL)));
                        machine.setMachineType(newOrder.getMachineType());
                        machine.setCreateTime(new Date());
                        if (newOrder.getAllUrgent() == null || !newOrder.getAllUrgent()) {
                            machine.setIsUrgent(false);
                        } else {
                            machine.setIsUrgent(true);
                        }
                        machineService.save(machine);
                        logger.info("have created machine's id: " + machine.getId());
                    }
                }
            /* 20180323精简了算法,对于被改的需求单,除了初始化和取消状态的机器保持状态不变,其他机器都设置为该到为状态
                    if (newOrder.getMachineNum() >= machineOrder.getMachineNum()) {
                        for (Machine machine : machineList) {
                            ///初始化状态,直接将机器的上的需求单号直接绑定到新需求单
                            if (machine.getStatus().equals(Constant.MACHINE_INITIAL)) {
                            } else {
                                machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
                            }
                            machine.setOrderId(newOrder.getId());
                            machine.setUpdateTime(new Date());
                            machineService.update(machine);
                        }
                    } else {
                        List<Machine> originalInitialMachine = new ArrayList<>();
                        List<Machine> originalInitialedMachine = new ArrayList<>();
                        List<Machine> originalOtherMachine = new ArrayList<>();
                        for (Machine machine : machineList) {
                            if (machine.getStatus().equals(Constant.MACHINE_CONFIGURED)
                                    ||machine.getStatus().equals(Constant.MACHINE_PLANING)
                                    || machine.getStatus().equals( Constant.MACHINE_INSTALLING)
                                    || machine.getStatus().equals(Constant.MACHINE_INSTALLED)
                                    || machine.getStatus().equals(Constant.MACHINE_SPLITED)) {
                                ///查找已配置、计划中、生产中、被拆单、生产完成的机器
                                originalInitialedMachine.add(machine);
                            } else if (machine.getStatus().equals(Constant.MACHINE_INITIAL)) {
                                ///初始化状态,未开始计划
                                originalInitialMachine.add(machine);
                            } else {
                                originalOtherMachine.add(machine);
                            }
                        }
                        int addedNum = 0;
                        //生产中的机器优先处理
                        for (int i = 0; i < originalInitialedMachine.size(); i++) {
                            if (addedNum < newOrder.getMachineNum()) {
                                originalInitialedMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
                                addedNum++;
                            } else {
                                originalInitialedMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
                            }
                            originalInitialedMachine.get(i).setOrderId(newOrder.getId());
                            //更新
                            machineService.update(originalInitialedMachine.get(i));
                        }
                        //未计划的机器其次处理
                        for (int i = 0; i < originalInitialMachine.size(); i++) {
                            if (addedNum < newOrder.getMachineNum()) {
                                ///TODO:是否可以保持“MACHINE_INITIAL”状态不变,因为此时机器还没有计划,也就是说没有对其设置安装流程
                                //originalInitialMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
                                addedNum++;
                                originalInitialMachine.get(i).setOrderId(newOrder.getId());
                                machineService.update(originalInitialMachine.get(i));
                            } else {
                                //删除
                                machineService.deleteById(originalInitialMachine.get(i).getId());
                            }
                        }

                        //目前只有删除状态的机器(MACHINE_CANCELED)
                        for (int i = 0; i < originalOtherMachine.size(); i++) {
                            if (addedNum < newOrder.getMachineNum()) {
                                originalOtherMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
                                originalOtherMachine.get(i).setOrderId(newOrder.getId());
                                machineService.update(originalInitialMachine.get(i));
                                addedNum++;
                            } else {
                                originalOtherMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
                                machineService.update(originalInitialMachine.get(i));
                            }
                            ///对于删除状态的机器不做处理
//                            else {
//                                originalOtherMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
//                                machineService.update(originalInitialMachine.get(i));
//                            }
                        }
                    }
                    */
            } else {
                // /在同一个合同中没有找到新的需求单,抛出异常
                throw new RuntimeException();
            }
        }
    }
    return ResultGenerator.genSuccessResult(newMachineOrderId);
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) OrderChangeRecord(com.eservice.api.model.order_change_record.OrderChangeRecord) 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) OrderSign(com.eservice.api.model.order_sign.OrderSign) 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 7 with MachineOrder

use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.

the class MachineOrderController method add.

/*
        为保证 MachineOrder表和OrderDetail表的一致性,MachineOrder表和OrderDetail表,都在这里统一完成
     */
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
public Result add(String machineOrder, String orderDetail) {
    MachineOrder machineOrder1 = JSON.parseObject(machineOrder, MachineOrder.class);
    OrderDetail orderDetail1 = JSON.parseObject(orderDetail, OrderDetail.class);
    /**
     * 订单 不允许同名
     * 带下划线的字段,不能用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(), machineOrder1.getOrderNum());
        if (mo != null) {
            logger.error("/machine/order/add fail: 该 order_num 已存在 " + machineOrder1.getOrderNum());
            return ResultGenerator.genFailResult(machineOrder1.getOrderNum() + " 该 order_num 已存在");
        }
    } catch (ClassNotFoundException e) {
        logger.error("/machine/order/add fail: " + e.getMessage());
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        logger.error("/machine/order/add fail: " + e.getMessage());
        e.printStackTrace();
    }
    orderDetailService.saveAndGetID(orderDetail1);
    Integer savedOrderDetailID = orderDetail1.getId();
    // orderDetail里返回的id 就是machineOrder里的order_detail_id
    machineOrder1.setOrderDetailId(savedOrderDetailID);
    machineOrderService.saveAndGetID(machineOrder1);
    /**
     * 在产生订单时,自动生成设计单
     */
    commonService.createDesignDepInfo(machineOrder1);
    return ResultGenerator.genSuccessResult();
}
Also used : OrderDetail(com.eservice.api.model.order_detail.OrderDetail) MachineOrderDetail(com.eservice.api.model.machine_order.MachineOrderDetail) Field(java.lang.reflect.Field) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with MachineOrder

use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.

the class MachineOrderController method update.

@PostMapping("/update")
public Result update(String machineOrder) {
    MachineOrder machineOrder1 = JSON.parseObject(machineOrder, MachineOrder.class);
    machineOrderService.update(machineOrder1);
    return ResultGenerator.genSuccessResult();
}
Also used : MachineOrder(com.eservice.api.model.machine_order.MachineOrder) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 9 with MachineOrder

use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.

the class MachineOrderController method list.

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

Example 10 with MachineOrder

use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.

the class MachineOrderController method updateValid.

@PostMapping("/updateValid")
public Result updateValid(@RequestParam Integer orderId) {
    if (orderId == null || orderId <= 0) {
        return ResultGenerator.genFailResult("需求单对应ID不正确,请联系管理员!");
    }
    MachineOrder machineOrder = machineOrderService.findById(orderId);
    if (machineOrder == null) {
        return ResultGenerator.genFailResult("需求单编号不存在!");
    } else {
        // 检查需求单对应的机器是否生成,如果生成则不能删除
        List<Machine> machineList = machineService.selectMachines(null, orderId, null, null, null, null, null, null, null, null, false);
        if (machineList.size() > 0) {
            // 机器已经生成,则把机器status设为 MACHINE_CANCELED
            for (int i = 0; i < machineList.size(); i++) {
                machineList.get(i).setStatus(Constant.MACHINE_CANCELED);
                machineService.update(machineList.get(i));
                logger.warn("订单被删除,已生成的机器 " + machineList.get(i).getNameplate() + " 设置为取消");
            }
        }
        machineOrder.setValid(Constant.ValidEnum.INVALID.getValue());
        machineOrder.setUpdateTime(new Date());
        machineOrderService.update(machineOrder);
        logger.warn(machineOrder.getOrderNum() + " 订单被删除");
        return ResultGenerator.genSuccessResult();
    }
}
Also used : MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Machine(com.eservice.api.model.machine.Machine) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

MachineOrder (com.eservice.api.model.machine_order.MachineOrder)29 PostMapping (org.springframework.web.bind.annotation.PostMapping)25 Machine (com.eservice.api.model.machine.Machine)16 Condition (tk.mybatis.mapper.entity.Condition)15 Date (java.util.Date)14 Transactional (org.springframework.transaction.annotation.Transactional)13 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)10 OrderSign (com.eservice.api.model.order_sign.OrderSign)9 Contract (com.eservice.api.model.contract.Contract)8 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)8 Task (com.eservice.api.model.task.Task)8 ContractSign (com.eservice.api.model.contract_sign.ContractSign)7 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)7 TaskRecord (com.eservice.api.model.task_record.TaskRecord)7 OrderDetail (com.eservice.api.model.order_detail.OrderDetail)5 ArrayList (java.util.ArrayList)5 MachineOrderWrapper (com.eservice.api.model.contract.MachineOrderWrapper)4 SignContentItem (com.eservice.api.model.contract_sign.SignContentItem)4 SimpleDateFormat (java.text.SimpleDateFormat)4 MachineType (com.eservice.api.model.machine_type.MachineType)3