use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.
the class TaskRecordController method updateStatus.
@PostMapping("/updateStatus")
@Transactional(rollbackFor = Exception.class)
public Result updateStatus(String taskRecord, String processRecord) {
TaskRecord tr = JSON.parseObject(taskRecord, TaskRecord.class);
Integer id = tr.getId();
if (id == null || id < 0) {
return ResultGenerator.genFailResult("TaskRecord的ID为空,数据更新失败!");
}
taskRecordService.update(tr);
ProcessRecord pr = JSON.parseObject(processRecord, ProcessRecord.class);
id = pr.getId();
if (id == null || id < 0) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResultGenerator.genFailResult("ProcessRecord的ID为空,数据更新失败!");
}
processRecordService.update(pr);
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.
the class TaskRecordController method updateTaskInfo.
@PostMapping("/updateTaskInfo")
@Transactional(rollbackFor = Exception.class)
public Result updateTaskInfo(String taskRecord) {
TaskRecord tr = JSON.parseObject(taskRecord, TaskRecord.class);
Integer id = tr.getId();
if (id == null || id < 0) {
return ResultGenerator.genFailResult("TaskRecord的ID为空,数据更新失败!");
}
taskRecordService.update(tr);
Integer prId = tr.getProcessRecordId();
if (prId == null || prId < 0) {
Logger.getLogger("").log(Level.INFO, "processrecord Id 为空");
} else {
// Update task record相关的状态
if (!commonService.updateTaskRecordRelatedStatus(tr)) {
// 更新出错进行事务回退
throw new RuntimeException();
}
}
if (tr.getStatus().equals(Constant.TASK_INSTALLED)) {
// MQTT 如果当前工序状态是安装完成等待质检的状态,则通知App
// 找到工序对应的quality_user_id
String taskName = tr.getTaskName();
Condition condition = new Condition(Task.class);
condition.createCriteria().andCondition("task_name = ", taskName);
List<Task> taskList = taskService.findByCondition(condition);
if (taskList == null || taskList.size() <= 0) {
throw new RuntimeException();
}
ProcessRecord pr = processRecordService.findById(prId);
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
mqttMessageHelper.sendToClient(Constant.S2C_TASK_QUALITY + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
}
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.process_record.ProcessRecord in project sinsim by WilsonHu.
the class ProcessRecordController method addProcessForMachine.
@PostMapping("/addProcessForMachine")
@Transactional(rollbackFor = Exception.class)
public Result addProcessForMachine(String taskRecords, String processRecord, String machine) {
ProcessRecord pr = JSON.parseObject(processRecord, ProcessRecord.class);
List<TaskRecord> trList = JSON.parseArray(taskRecords, TaskRecord.class);
Machine machineObj = JSON.parseObject(machine, Machine.class);
if (pr == null || trList == null) {
return ResultGenerator.genFailResult("提交到服务端的JSON数据解析错误");
}
Integer prId = pr.getId();
pr.setCreateTime(new Date());
try {
// 已经保存过配置流程的,需要更新
if (prId != null && prId > 0) {
processRecordService.update(pr);
try {
// 删除旧的taskrecorder表中对应的任务,根据process_recorder_id删除 status==0的
taskRecordService.deleteTaskRecordByCondition(null, prId, null, (byte) 0);
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResultGenerator.genFailResult("taskRecordService删除旧任务失败");
}
} else {
processRecordService.save(pr);
}
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResultGenerator.genFailResult("processRecordService数据库操作失败");
}
trList.forEach((item) -> {
item.setProcessRecordId(pr.getId());
});
try {
taskRecordService.save(trList);
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResultGenerator.genFailResult("taskRecordService数据库操作失败");
}
try {
// 如果机器处于初始化状态,则设置为“已配置”
if (machineObj.getStatus().equals(Constant.MACHINE_INITIAL)) {
// 如果已经是其他状态,则不需要更改机器状态
machineObj.setStatus(Constant.MACHINE_CONFIGURED);
if (machineObj.getId() == 0) {
return ResultGenerator.genFailResult("机器Id为空,数据更新失败");
}
machineService.update(machineObj);
}
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResultGenerator.genFailResult("machineService数据库操作失败");
}
return ResultGenerator.genSuccessResult();
}
Aggregations