use of com.eservice.api.model.machine.Machine in project sinsim by WilsonHu.
the class AbnormalRecordController method update.
@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String abnormalRecord) {
AbnormalRecord abnormalRecord1 = JSON.parseObject(abnormalRecord, AbnormalRecord.class);
abnormalRecord1.setSolveTime(new Date());
// 修改对应工序的状态为"安装中"或者“质检中”,需要检查安装开始时间和质检开始时间,质检已开始则状态为质检中
AbnormalRecord completeInfo = abnormalRecordService.findById(abnormalRecord1.getId());
Integer taskRecordId = completeInfo.getTaskRecordId();
if (taskRecordId != null && taskRecordId > 0) {
TaskRecord tr = taskRecordService.findById(taskRecordId);
// MQTT 异常解决后,通知工序的安装组长或者质检员,取决于之前是处于安装中还是质检中
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(tr.getProcessRecordId());
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
if (tr.getQualityBeginTime() != null) {
tr.setStatus(Constant.TASK_QUALITY_DOING);
mqttMessageHelper.sendToClient(Constant.S2C_QUALITY_ABNORMAL_RESOLVE + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
} else {
tr.setStatus(Constant.TASK_INSTALLING);
mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_ABNORMAL_RESOLVE + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
}
taskRecordService.update(tr);
} else {
throw new RuntimeException();
}
abnormalRecordService.update(abnormalRecord1);
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.machine.Machine 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) {
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);
// 新增的改单处理
List<MachineOrderWrapper> machineOrderWrapperList = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
MachineOrder machineOrder = orderItem.getMachineOrder();
if (machineOrder.getStatus().equals(Constant.ORDER_INITIAL) && machineOrder.getOriginalOrderId() != 0) {
// 插入新增改单项的detail
OrderDetail temp = orderItem.getOrderDetail();
orderDetailService.saveAndGetID(temp);
machineOrder.setOrderDetailId(temp.getId());
machineOrder.setContractId(contract1.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);
// 改单记录(插入或者修改)
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();
// 设置被改单的需求单状态(machine_order/order_sign)
if (machineOrder.getStatus().equals(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) {
// /改单前后机器数相等或者大于原需求单数中对应的机器数;多出部分机器在审核完成以后自动添加
for (Machine machine : machineList) {
// /初始化、取消状态,直接将机器的上的需求单号直接绑定到新需求单
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);
}
/* 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();
}
use of com.eservice.api.model.machine.Machine in project sinsim by WilsonHu.
the class MachineController method list.
@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
PageHelper.startPage(page, size);
List<Machine> list = machineService.findAll();
PageInfo pageInfo = new PageInfo(list);
return ResultGenerator.genSuccessResult(pageInfo);
}
use of com.eservice.api.model.machine.Machine in project sinsim by WilsonHu.
the class TaskPlanServiceImpl method addTaskPlans.
public boolean addTaskPlans(@RequestParam List<Integer> taskRecordIds, Integer planType, String machineStrId, Date planDate, Integer userId) {
for (int i = 0; i < taskRecordIds.size(); i++) {
Condition tempCondition = new Condition(TaskPlan.class);
tempCondition.createCriteria().andCondition("task_record_id = ", taskRecordIds.get(i));
List<TaskPlan> existPlans = findByCondition(tempCondition);
if (existPlans.size() > 0) {
return false;
}
TaskPlan plan = new TaskPlan();
plan.setCreateTime(new Date());
plan.setUserId(userId);
plan.setTaskRecordId(taskRecordIds.get(i));
plan.setPlanType(Constant.DAILY_PLAN);
if (planType.intValue() == Constant.DAILY_PLAN.intValue()) {
plan.setPlanTime(planDate);
} else if (planType.intValue() == Constant.FLEX_PLAN.intValue()) {
plan.setDeadline(planDate);
}
save(plan);
// 更改task record状态为已计划
TaskRecord taskRecord = taskRecordService.findById(taskRecordIds.get(i));
if (taskRecord != null) {
// 检查是否为第一个计划项,如果是,需要设置为待安装状态
Integer processRecordId = taskRecord.getProcessRecordId();
ProcessRecord processRecord = processRecordService.findById(processRecordId);
List<LinkDataModel> linkDataList = JSON.parseArray(processRecord.getLinkData(), LinkDataModel.class);
for (LinkDataModel item : linkDataList) {
if (item.getTo().equals(taskRecord.getNodeKey().intValue())) {
if (item.getFrom() == null || item.getFrom() == -1) {
taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
// MQTT 计划后,通知第一道的安装组长,可以进行安装
String taskName = taskRecord.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(taskRecord.getProcessRecordId());
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_INSTALL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
// / }
break;
}
}
}
if (taskRecord.getStatus().equals(Constant.TASK_INITIAL)) {
taskRecord.setStatus(Constant.TASK_PLANED);
}
taskRecordService.update(taskRecord);
// 更新task_record以外,但是跟task record相关的状态,机器状态,process_record中的task_status
commonService.updateTaskRecordRelatedStatus(taskRecord);
} else {
// 进行事务操作
throw new RuntimeException();
}
}
if (taskRecordIds.size() > 0 && machineStrId != null) {
List<Machine> machineList = machineService.selectMachines(null, null, machineStrId, null, null, null, null, null, null, false);
if (machineList.size() == 1) {
// 如果机器状态小于计划中,则更新为计划中
Machine machine = machineList.get(0);
if (machine.getStatus() < Constant.MACHINE_PLANING) {
machine.setStatus(Constant.MACHINE_PLANING);
machineService.update(machine);
}
} else {
// 进行事务rollback操作
throw new RuntimeException();
}
}
return true;
}
use of com.eservice.api.model.machine.Machine in project sinsim by WilsonHu.
the class CommonService method updateTaskRecordRelatedStatus.
public boolean updateTaskRecordRelatedStatus(TaskRecord tr) {
if (tr == null || tr.getProcessRecordId() == null) {
return false;
} else {
Integer prId = tr.getProcessRecordId();
ProcessRecord pr = processRecordService.findById(prId);
Machine machine = machineService.findById(pr.getMachineId());
boolean isNeedUpdateMachine = false;
if (pr != null) {
String nodeData = pr.getNodeData();
List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
NodeDataModel ndItem = null;
Integer index = -1;
for (int i = 0; i < ndList.size(); i++) {
if (Integer.parseInt(ndList.get(i).getKey()) == tr.getNodeKey()) {
index = i;
break;
}
}
if (index > -1) {
ndItem = ndList.get(index);
ndItem.setTaskStatus(tr.getStatus().toString());
if (tr.getInstallBeginTime() != null) {
String date = Utils.getFormatStringDate(tr.getInstallBeginTime(), "yyyy-MM-dd HH:mm:ss");
ndItem.setBeginTime(date);
}
// 质检完成,工序才算完成
if (tr.getQualityEndTime() != null) {
String date = Utils.getFormatStringDate(tr.getQualityEndTime(), "yyyy-MM-dd HH:mm:ss");
ndItem.setEndTime(date);
}
// 组长信息
if (tr.getLeader() != null && tr.getLeader().length() > 0) {
ndItem.setLeader(tr.getLeader());
}
// 工作人员信息
if (tr.getWorkerList() != null && tr.getWorkerList().length() > 0) {
ndItem.setWorkList(tr.getWorkerList());
}
ndList.set(index, ndItem);
// TODO:如果当前工序是质检完成状态,需要检查其子节点是否可以开始
if (tr.getStatus().intValue() == Constant.TASK_QUALITY_DONE.intValue()) {
List<LinkDataModel> linkDataList = JSON.parseArray(pr.getLinkData(), LinkDataModel.class);
for (LinkDataModel item : linkDataList) {
if (String.valueOf(item.getFrom()).equals(String.valueOf(ndItem.getKey()))) {
for (NodeDataModel childNode : ndList) {
// 先找到子节点
if (childNode.getKey().equals(String.valueOf(item.getTo()))) {
// 找到子节点的所有父节点
boolean allParentFinished = true;
for (LinkDataModel parentOfChild : linkDataList) {
if (!allParentFinished) {
break;
}
if (String.valueOf(parentOfChild.getTo()).equals(childNode.getKey())) {
for (NodeDataModel parentOfChildNode : ndList) {
if (parentOfChildNode.getCategory().equals("Start") || parentOfChildNode.getCategory().equals("End") || !allParentFinished) {
break;
}
if (Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue()) {
allParentFinished = false;
}
}
}
}
// 子节点的所有父节点都已经完成,则更新子节点的状态
if (allParentFinished) {
String dateStr = Utils.getFormatStringDate(new Date(), "yyyy-MM-dd HH:mm:ss");
childNode.setBeginTime(dateStr);
childNode.setTaskStatus(Constant.TASK_INSTALL_WAITING.toString());
List<TaskRecord> taskRecordList = taskRecordService.getTaskRecordData(null, prId);
for (TaskRecord record : taskRecordList) {
if (String.valueOf(record.getNodeKey().intValue()).equals(childNode.getKey())) {
record.setStatus(Constant.TASK_INSTALL_WAITING);
taskRecordService.update(record);
// MQTT 通知下一道工序可以开始安装
ServerToClientMsg msg = new ServerToClientMsg();
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
// 找到工序对应的group_id
String taskName = record.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();
}
mqttMessageHelper.sendToClient(Constant.S2C_TASK_INSTALL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
// 这个break需要去掉,因为存在多个子工序可以安装的情况
// break;
}
}
}
}
}
}
}
}
}
Boolean isFinished = true;
for (int i = 0; i < ndList.size(); i++) {
if (ndList.get(i).getTaskStatus() != null && Integer.parseInt(ndList.get(i).getTaskStatus()) == Constant.TASK_QUALITY_DONE.intValue()) {
isFinished = false;
}
}
// 所有工序完成
if (isFinished && tr.getStatus() == Constant.TASK_QUALITY_DONE.intValue()) {
pr.setEndTime(new Date());
// 安装完成
machine.setStatus(Constant.MACHINE_INSTALLED);
isNeedUpdateMachine = true;
}
if (machine.getStatus().equals(Constant.MACHINE_PLANING)) {
// 安装中
machine.setStatus(Constant.MACHINE_INSTALLING);
isNeedUpdateMachine = true;
}
if (isNeedUpdateMachine) {
machine.setUpdateTime(new Date());
machineService.update(machine);
}
pr.setNodeData(JSON.toJSONString(ndList));
processRecordService.update(pr);
return true;
} else {
return false;
}
}
}
Aggregations