Search in sources :

Example 1 with MachineOrderWrapper

use of com.eservice.api.model.contract.MachineOrderWrapper in project sinsim by WilsonHu.

the class ContractController method add.

@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
public Result add(String contract, String contractSign, String 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解析失败!");
    }
    // Condition condition = new Condition(Contract.class);
    // condition.createCriteria().andCondition("contract_num = ", contract1.getContractNum());
    // List<Contract> list = contractService.findByCondition(condition);
    List<Contract> list = contractService.isContractExist(contract1.getContractNum());
    if (list.size() != 0) {
        logger.error("合同编号已存在");
        return ResultGenerator.genFailResult("合同编号已存在!请换一个编号");
    }
    contract1.setCreateTime(new Date());
    contractService.saveAndGetID(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);
    // 插入需求单记录
    List<MachineOrderWrapper> machineOrderWapperList = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
    if (machineOrderWapperList != null) {
        // 是内贸还是外贸的订单
        String salesDepartment = null;
        User machineOrderCreator = null;
        for (int i = 0; i < machineOrderWapperList.size(); i++) {
            OrderDetail temp = machineOrderWapperList.get(i).getOrderDetail();
            MachineOrder orderTemp = machineOrderWapperList.get(i).getMachineOrder();
            orderDetailService.saveAndGetID(temp);
            orderTemp.setOrderDetailId(temp.getId());
            orderTemp.setContractId(contractId);
            orderTemp.setStatus(Constant.ORDER_INITIAL);
            Condition condition2 = new Condition(Contract.class);
            condition2.createCriteria().andCondition("order_num = ", orderTemp.getOrderNum()).andCondition("valid = ", 1);
            List<MachineOrder> orderList = machineOrderService.findByCondition(condition2);
            if (orderList.size() != 0) {
                logger.error("订单号已存在!请换一个");
                return ResultGenerator.genFailResult("订单号已存在!请换一个");
            }
            machineOrderService.saveAndGetID(orderTemp);
            // 初始化需求单审核记录
            OrderSign orderSignData = machineOrderWapperList.get(i).getOrderSign();
            OrderSign orderSign = new OrderSign();
            orderSign.setSignContent(orderSignData.getSignContent());
            orderSign.setOrderId(orderTemp.getId());
            orderSign.setCreateTime(new Date());
            orderSign.setCurrentStep("");
            // 是内贸还是外贸 --> 因为要查询订单是哪个部门,所以要细化到外贸一部还是二部
            if (salesDepartment == null) {
                machineOrderCreator = userService.findById(orderTemp.getCreateUserId());
                if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_DOMESTIC)) {
                    salesDepartment = Constant.STR_DEPARTMENT_DOMESTIC;
                } else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_1)) {
                    salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
                } else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_2)) {
                    salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_2;
                } else if (machineOrderCreator.getRoleId() == Constant.ROLE_ID_FOREIGN_DIRECTOR) {
                    /**
                     * 外贸总监的MarketGroupName部门为空, 外贸总监录的订单,也算为一部的。
                     * 外贸经理的MarketGroupName部门为外贸二部
                     */
                    salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
                }
                orderSign.setSalesDepartment(salesDepartment);
            }
            orderSignService.saveAndGetID(orderSign);
        // 第一个轮到签核的人也发消息推送  --> 此时为未提交状态,不需要发推送
        }
    } else {
        // 手动回滚事务
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return ResultGenerator.genFailResult("需求单为空!");
    }
    // 返回ID给前端,前端新增合同时不关闭页面。
    return ResultGenerator.genSuccessResult(contract1.getId());
}
Also used : Condition(tk.mybatis.mapper.entity.Condition) User(com.eservice.api.model.user.User) MachineOrderWrapper(com.eservice.api.model.contract.MachineOrderWrapper) Date(java.util.Date) 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 2 with MachineOrderWrapper

use of com.eservice.api.model.contract.MachineOrderWrapper in project sinsim by WilsonHu.

the class ContractController method update.

@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String contract, String requisitionForms) {
    Contract contract1 = JSONObject.parseObject(contract, Contract.class);
    List<MachineOrderWrapper> machineOrderWapperlist = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
    // 先获取当前合同的所有订单
    List<MachineOrderDetail> originalOrderList = machineOrderService.selectOrder(null, contract1.getId(), null, null, null, null, null, null, null, null, null, null, null, null, null, false);
    // /删除该合同下,不在本次保存范围内的需求单
    for (MachineOrderDetail item : originalOrderList) {
        boolean exist = false;
        /**
         * web有时会发来有问题的requisitionForms
         */
        if (machineOrderWapperlist == null) {
            logger.error("machineOrderWapperlist is null, return;");
            return ResultGenerator.genFailResult("machineOrderWapperlist is null, nothing updated");
        }
        if (requisitionForms.isEmpty() || requisitionForms == null) {
            logger.error("requisitionForms is empty/null, return;");
            return ResultGenerator.genFailResult("requisitionForms is empty/null, nothing updated");
        }
        for (MachineOrderWrapper wapperItem : machineOrderWapperlist) {
            // null
            if (item.getId().equals(wapperItem.getMachineOrder().getId())) {
                exist = true;
                break;
            }
        }
        if (!exist) {
            // 删除需求单审核记录
            OrderSign orderSign = orderSignService.findBy("orderId", item.getId());
            if (orderSign != null) {
                orderSignService.deleteById(orderSign.getId());
            }
            // 删除需求单  ....
            /**
             *  同时要删除对应的设计单.
             *  比如,在更新订单时,改了订单号,旧的订单会被删除,此时如果没有删除对应设计单,会无法删除订单。
             *  后来改为订单审核完成才生成设计单,上述情形应该不存在了。
             */
            deleteDDIbyOrder(item);
            machineOrderService.deleteById(item.getId());
            // 删除detail
            orderDetailService.deleteById(item.getOrderDetailId());
        }
    }
    for (MachineOrderWrapper item : machineOrderWapperlist) {
        // 是内贸还是外贸的订单
        String salesDepartment = null;
        User machineOrderCreator = null;
        MachineOrder orderTemp = item.getMachineOrder();
        OrderChangeRecord changeRecord = item.getOrderChangeRecord();
        if (orderTemp.getId() != null && orderTemp.getId() != 0) {
            // 更新,只对initial和reject状态的需求单就是更新,其他状态的需求单不做更新
            OrderDetail temp = item.getOrderDetail();
            if (orderTemp.getStatus().equals(Constant.ORDER_REJECTED)) {
                orderTemp.setStatus(Constant.ORDER_INITIAL);
            }
            if (orderTemp.getStatus().equals(Constant.ORDER_INITIAL)) {
                orderDetailService.update(temp);
                machineOrderService.update(orderTemp);
                commonService.syncMachineOrderStatusInDesignDepInfo(orderTemp);
                // 在改单之后,在重新提交之前,允许修改改单原因,即:改单原因不仅仅在改单时允许修改,在上述情况下也允许修改。
                if (null != changeRecord) {
                    orderChangeRecordService.update(changeRecord);
                }
            }
        } else {
            // 新增
            OrderDetail temp = item.getOrderDetail();
            orderDetailService.saveAndGetID(temp);
            orderTemp.setOrderDetailId(temp.getId());
            orderTemp.setContractId(contract1.getId());
            orderTemp.setStatus(Constant.ORDER_INITIAL);
            machineOrderService.saveAndGetID(orderTemp);
            // 初始化需求单审核记录
            OrderSign orderSignData = item.getOrderSign();
            OrderSign orderSign = new OrderSign();
            orderSign.setSignContent(orderSignData.getSignContent());
            orderSign.setOrderId(orderTemp.getId());
            orderSign.setCreateTime(new Date());
            // 是内贸还是外贸一部,二部
            if (salesDepartment == null) {
                machineOrderCreator = userService.findById(orderTemp.getCreateUserId());
                if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_DOMESTIC)) {
                    salesDepartment = Constant.STR_DEPARTMENT_DOMESTIC;
                } else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_1)) {
                    salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
                } else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_2)) {
                    salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_2;
                } else if (machineOrderCreator.getRoleId() == Constant.ROLE_ID_FOREIGN_DIRECTOR) {
                    /**
                     * 外贸总监的MarketGroupName部门为空, 外贸总监录的订单,也算为一部的。
                     * 外贸经理的MarketGroupName部门为外贸二部
                     */
                    salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
                }
                orderSign.setSalesDepartment(salesDepartment);
            }
            orderSignService.save(orderSign);
        }
    }
    // 前端只要操作了“保存”,合同的状态回到“CONTRACT_INITIAL”状态
    contract1.setStatus(Constant.CONTRACT_INITIAL);
    contract1.setUpdateTime(new Date());
    contractService.update(contract1);
    // 检查需求单中的销售员和合同中销售员是否一致,如果不一致则更新需求单中的销售员
    for (MachineOrderWrapper item : machineOrderWapperlist) {
        if (!item.getMachineOrder().getSellman().equals(contract1.getSellman())) {
            MachineOrder order = new MachineOrder();
            order.setId(item.getMachineOrder().getId());
            // 只更新销售员
            order.setSellman(contract1.getSellman());
            machineOrderService.update(order);
        }
    }
    return ResultGenerator.genSuccessResult();
}
Also used : User(com.eservice.api.model.user.User) OrderChangeRecord(com.eservice.api.model.order_change_record.OrderChangeRecord) MachineOrderWrapper(com.eservice.api.model.contract.MachineOrderWrapper) MachineOrderDetail(com.eservice.api.model.machine_order.MachineOrderDetail) Date(java.util.Date) OrderDetail(com.eservice.api.model.order_detail.OrderDetail) MachineOrderDetail(com.eservice.api.model.machine_order.MachineOrderDetail) OrderSign(com.eservice.api.model.order_sign.OrderSign) 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 3 with MachineOrderWrapper

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

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

Aggregations

Contract (com.eservice.api.model.contract.Contract)4 MachineOrderWrapper (com.eservice.api.model.contract.MachineOrderWrapper)4 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)4 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)4 OrderDetail (com.eservice.api.model.order_detail.OrderDetail)4 OrderSign (com.eservice.api.model.order_sign.OrderSign)4 Date (java.util.Date)4 Transactional (org.springframework.transaction.annotation.Transactional)4 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 ContractSign (com.eservice.api.model.contract_sign.ContractSign)3 Machine (com.eservice.api.model.machine.Machine)2 OrderChangeRecord (com.eservice.api.model.order_change_record.OrderChangeRecord)2 User (com.eservice.api.model.user.User)2 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)2 Condition (tk.mybatis.mapper.entity.Condition)2 OrderSplitRecord (com.eservice.api.model.order_split_record.OrderSplitRecord)1 Field (java.lang.reflect.Field)1