Search in sources :

Example 1 with TaskPlan

use of com.eservice.api.model.task_plan.TaskPlan 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;
}
Also used : TaskRecord(com.eservice.api.model.task_record.TaskRecord) Task(com.eservice.api.model.task.Task) TaskPlan(com.eservice.api.model.task_plan.TaskPlan) ArrayList(java.util.ArrayList) InstallGroup(com.eservice.api.model.install_group.InstallGroup) Machine(com.eservice.api.model.machine.Machine) NodeDataModel(com.eservice.api.service.common.NodeDataModel) ProcessRecord(com.eservice.api.model.process_record.ProcessRecord) MachineOrder(com.eservice.api.model.machine_order.MachineOrder) Condition(tk.mybatis.mapper.entity.Condition) LinkDataModel(com.eservice.api.service.common.LinkDataModel) ServerToClientMsg(com.eservice.api.service.mqtt.ServerToClientMsg) Date(java.util.Date) InstallPlan(com.eservice.api.model.install_plan.InstallPlan) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with TaskPlan

use of com.eservice.api.model.task_plan.TaskPlan in project sinsim by WilsonHu.

the class TaskPlanController method list.

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

Example 3 with TaskPlan

use of com.eservice.api.model.task_plan.TaskPlan in project sinsim by WilsonHu.

the class TaskPlanController method update.

@PostMapping("/update")
public Result update(String taskPlan) {
    TaskPlan taskPlan1 = JSON.parseObject(taskPlan, TaskPlan.class);
    taskPlanService.update(taskPlan1);
    return ResultGenerator.genSuccessResult();
}
Also used : TaskPlan(com.eservice.api.model.task_plan.TaskPlan) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 4 with TaskPlan

use of com.eservice.api.model.task_plan.TaskPlan in project sinsim by WilsonHu.

the class TaskRecordController method selectTaskPlans.

/**
 * 根据 taskRecord.id 返回 task_plans
 *
 * @param page
 * @param size
 * @param taskRecordId
 * @return
 */
@PostMapping("/selectTaskPlans")
public Result selectTaskPlans(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, @RequestParam Integer taskRecordId) {
    PageHelper.startPage(page, size);
    List<TaskPlan> list = taskRecordService.selectTaskPlans(taskRecordId);
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : PageInfo(com.github.pagehelper.PageInfo) TaskPlan(com.eservice.api.model.task_plan.TaskPlan) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with TaskPlan

use of com.eservice.api.model.task_plan.TaskPlan in project sinsim by WilsonHu.

the class TaskPlanController method selectByUserAccount.

/**
 * 根据user账号返回其taskPlan列表
 * @param page
 * @param size
 * @param userAccount
 * @return
 */
@PostMapping("/selectByUserAccount")
public Result selectByUserAccount(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size, @RequestParam String userAccount) {
    PageHelper.startPage(page, size);
    List<TaskPlan> list = taskPlanService.selectByUserAccount(userAccount);
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : PageInfo(com.github.pagehelper.PageInfo) TaskPlan(com.eservice.api.model.task_plan.TaskPlan) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

TaskPlan (com.eservice.api.model.task_plan.TaskPlan)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 PageInfo (com.github.pagehelper.PageInfo)3 Machine (com.eservice.api.model.machine.Machine)2 ProcessRecord (com.eservice.api.model.process_record.ProcessRecord)2 TaskRecord (com.eservice.api.model.task_record.TaskRecord)2 NodeDataModel (com.eservice.api.service.common.NodeDataModel)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Condition (tk.mybatis.mapper.entity.Condition)2 InstallGroup (com.eservice.api.model.install_group.InstallGroup)1 InstallPlan (com.eservice.api.model.install_plan.InstallPlan)1 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)1 Task (com.eservice.api.model.task.Task)1 LinkDataModel (com.eservice.api.service.common.LinkDataModel)1 ServerToClientMsg (com.eservice.api.service.mqtt.ServerToClientMsg)1