use of com.eservice.api.model.order_detail.OrderDetail in project sinsim by WilsonHu.
the class OrderDetailController method list.
@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
PageHelper.startPage(page, size);
List<OrderDetail> list = orderDetailService.findAll();
PageInfo pageInfo = new PageInfo(list);
return ResultGenerator.genSuccessResult(pageInfo);
}
use of com.eservice.api.model.order_detail.OrderDetail 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);
}
Aggregations