use of com.eservice.api.model.install_plan.InstallPlan in project sinsim by WilsonHu.
the class TaskPlanServiceImpl method addTaskPlans.
// 每新增1个工序,调用一次。
@Transactional(rollbackFor = Exception.class)
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);
Integer id = taskRecordIds.get(i);
tempCondition.createCriteria().andCondition("task_record_id = ", id);
List<TaskPlan> existPlans = findByCondition(tempCondition);
if (existPlans.size() > 0) {
return false;
}
TaskPlan plan = new TaskPlan();
plan.setCreateTime(new Date());
plan.setUserId(userId);
plan.setTaskRecordId(id);
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(id);
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.setUpdateTime(new Date());
taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
break;
} else {
// TODO:如果是重新配置流程项,比如:改单、拆单以后再最后增加了安装项,则需要设置成待安装状态
List<Integer> parentNodeList = new ArrayList<>();
String nodeData = processRecord.getNodeData();
List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
for (LinkDataModel tmp : linkDataList) {
if (tmp.getTo() == taskRecord.getNodeKey().intValue()) {
parentNodeList.add(tmp.getFrom());
}
}
boolean allParentFinished = true;
for (Integer parentNodeKey : parentNodeList) {
for (NodeDataModel nodeDataModel : ndList) {
if (parentNodeKey.intValue() == Integer.valueOf(nodeDataModel.getKey())) {
if (Integer.valueOf(nodeDataModel.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue()) {
allParentFinished = false;
break;
}
}
}
if (!allParentFinished) {
break;
}
}
if (allParentFinished) {
taskRecord.setUpdateTime(new Date());
taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
}
}
}
}
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);
if (taskRecord.getStatus().equals(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));
}
// /在”计划管理“中 添加计划安排时,自动添加了 总装排产 InstallPlan。 (InstallPlanActual则在app扫码完成工序时添加)
// 因为把总装排产,合并到“计划管理”,所以需要在安排计划时 自动生成总装排产(这样在app上扫码完成时,才能有总装完成自动填充完成头数)
InstallPlan installPlan1 = new InstallPlan();
installPlan1.setType(Constant.STR_INSTALL_TYPE_WHOLE);
InstallGroup installGroup = installGroupService.getInstallGroupByTaskName(taskRecord.getTaskName());
installPlan1.setInstallGroupId(installGroup.getId());
installPlan1.setInstallDatePlan(plan.getPlanTime());
ProcessRecord pr = processRecordService.findById(taskRecord.getProcessRecordId());
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
installPlan1.setOrderId(machineOrder.getId());
installPlan1.setMachineId(machine.getId());
installPlan1.setValid(Byte.valueOf("1"));
installPlan1.setCreateDate(new Date());
installPlanService.save(installPlan1);
logger.info("自动添加了 总装排产 for 铭牌号: " + machine.getNameplate() + ", 工序: " + taskRecord.getTaskName());
} else {
// 进行事务操作
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new RuntimeException();
}
}
if (taskRecordIds.size() > 0 && machineStrId != null) {
List<Machine> machineList = machineService.selectMachines(null, 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操作
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new RuntimeException();
}
}
return true;
}
use of com.eservice.api.model.install_plan.InstallPlan in project sinsim by WilsonHu.
the class InstallPlanController method selectUnSendInstallPlans.
// 获取所有未发送的排产计划
@PostMapping("/selectUnSendInstallPlans")
public Result selectUnSendInstallPlans(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
PageHelper.startPage(page, size);
List<InstallPlan> list = installPlanService.selectUnSendInstallPlans();
PageInfo pageInfo = new PageInfo(list);
return ResultGenerator.genSuccessResult(pageInfo);
}
use of com.eservice.api.model.install_plan.InstallPlan in project sinsim by WilsonHu.
the class InstallPlanController method addAndsendInstallPlanNow.
/**
* 添加并立即发送(MQTT) 该排产计划 给该计划所在组的所有安装组长
*/
@PostMapping("/addAndsendInstallPlanNow")
public Result addAndsendInstallPlanNow(String installPlan) {
InstallPlan installPlan1 = JSON.parseObject(installPlan, InstallPlan.class);
if (installPlan1 == null) {
return ResultGenerator.genFailResult("installPlan 解析得到null");
}
installPlan1.setCreateDate(new Date());
ServerToClientMsg msg = new ServerToClientMsg();
String str = null;
msg.setNameplate(machineService.findById(installPlan1.getMachineId()).getNameplate());
msg.setOrderNum(machineOrderService.findById(installPlan1.getOrderId()).getOrderNum());
msg.setType(ServerToClientMsg.MsgType.INSTALL_PLAN);
msg.setCmtSend(installPlan1.getCmtSend());
msg.setInstallDatePlan(installPlan1.getInstallDatePlan());
mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_PLAN + installPlan1.getInstallGroupId(), JSON.toJSONString(msg));
str = "MQTT SEND topic: " + Constant.S2C_INSTALL_PLAN + installPlan1.getInstallGroupId() + ", nameplate: " + msg.getNameplate();
logger.info(str);
/**
* 即使没有安装组长,也安排排产
*/
installPlan1.setSendTime(new Date());
installPlanService.save(installPlan1);
logger.info(str);
return ResultGenerator.genSuccessResult(str);
}
use of com.eservice.api.model.install_plan.InstallPlan in project sinsim by WilsonHu.
the class InstallPlanController method list.
@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
PageHelper.startPage(page, size);
List<InstallPlan> list = installPlanService.findAll();
PageInfo pageInfo = new PageInfo(list);
return ResultGenerator.genSuccessResult(pageInfo);
}
use of com.eservice.api.model.install_plan.InstallPlan in project sinsim by WilsonHu.
the class InstallPlanController method checkTheInstallPlanIsSet.
@PostMapping("/checkTheInstallPlanIsSet")
public Result checkTheInstallPlanIsSet(String installPlan) {
InstallPlan installPlan1 = JSON.parseObject(installPlan, InstallPlan.class);
if (installPlan1 == null) {
return ResultGenerator.genFailResult("参数installPlan1不能为null ");
}
/**
* 逐一检查各个必要参数的合法性
*/
if (installPlan1.getInstallGroupId() == null) {
return ResultGenerator.genFailResult("错误,getInstallGroupId 为 null!");
} else if (installGroupService.findById(installPlan1.getInstallGroupId()) == null) {
return ResultGenerator.genFailResult("错误,根据该InstallGroupId " + installPlan1.getInstallGroupId() + " 找不到对应的 installGroup!");
}
if (installPlan1.getInstallDatePlan() == null) {
return ResultGenerator.genFailResult("错误,InstallDatePlan 为 null!");
}
if (installPlan1.getOrderId() == null) {
return ResultGenerator.genFailResult("错误,orderId 为 null!");
} else if (machineOrderService.findById(installPlan1.getOrderId()) == null) {
return ResultGenerator.genFailResult("错误,根据该 orderId " + installPlan1.getOrderId() + " 找不到对应的 machineOrder !");
}
/**
* 检查machine是否存在,并且和订单匹配
*/
if (installPlan1.getMachineId() == null) {
return ResultGenerator.genFailResult("错误,machineId 为 null!");
} else if (machineService.findById(installPlan1.getMachineId()) == null) {
return ResultGenerator.genFailResult("错误,根据该 machineId " + installPlan1.getMachineId() + " 找不到对应的 machine !");
} else if (!isMachineInTheOrder(installPlan1.getMachineId(), installPlan1.getOrderId())) {
return ResultGenerator.genFailResult("错误, 该机器是不属于该订单");
}
// 检查该机器是否已经安排了该安装组的计划。
InstallGroup installGroup = installGroupService.findById(installPlan1.getInstallGroupId());
Machine machine = machineService.findById(installPlan1.getMachineId());
if (!isOKtoSetPlan(installGroup.getId(), machine.getId())) {
logger.warn("该机器 " + machine.getNameplate() + " 已经安排了 " + installGroup.getGroupName());
return ResultGenerator.genFailResult("该机器 " + machine.getNameplate() + " 已经安排了 " + installGroup.getGroupName());
}
return ResultGenerator.genSuccessResult("该排产允许添加");
}
Aggregations