Search in sources :

Example 1 with OrderSplitRecord

use of com.eservice.api.model.order_split_record.OrderSplitRecord 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);
    // 新增的改单处理
    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);
            machineOrderService.saveAndGetID(machineOrder);
            // 初始化需求单审核记录
            OrderSign orderSignData = orderItem.getOrderSign();
            OrderSign orderSign = new OrderSign();
            orderSign.setSignContent(orderSignData.getSignContent());
            orderSign.setOrderId(machineOrder.getId());
            orderSign.setCreateTime(new Date());
            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());
                machineService.update(splitMachine);
            }
            // 拆单记录(插入或者修改)
            OrderSplitRecord splitRecord = orderItem.getOrderSplitRecord();
            if (splitRecord.getId() == null) {
                splitRecord.setSplitTime(new Date());
                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();
}
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) 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 2 with OrderSplitRecord

use of com.eservice.api.model.order_split_record.OrderSplitRecord in project sinsim by WilsonHu.

the class OrderSplitRecordController method list.

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

Aggregations

OrderSplitRecord (com.eservice.api.model.order_split_record.OrderSplitRecord)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 Contract (com.eservice.api.model.contract.Contract)1 MachineOrderWrapper (com.eservice.api.model.contract.MachineOrderWrapper)1 ContractSign (com.eservice.api.model.contract_sign.ContractSign)1 Machine (com.eservice.api.model.machine.Machine)1 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)1 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)1 OrderDetail (com.eservice.api.model.order_detail.OrderDetail)1 OrderSign (com.eservice.api.model.order_sign.OrderSign)1 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)1 PageInfo (com.github.pagehelper.PageInfo)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1